2001-07-12 H.J. Lu <hjl@gnu.org>
[deliverable/binutils-gdb.git] / bfd / elf64-x86-64.c
index a92ba78c8005b495dec0b33c5d7685a507c2614d..7b37d9644338a86afc19e4bcca290cb7f1dc2d2d 100644 (file)
@@ -492,16 +492,17 @@ elf64_x86_64_check_relocs (abfd, info, sec, relocs)
          if (h == NULL)
            continue;
 
+         h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
          if (h->plt.refcount == -1)
-           {
-             h->plt.refcount = 1;
-             h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
-           }
+           h->plt.refcount = 1;
          else
            h->plt.refcount += 1;
          break;
 
+       case R_X86_64_8:
+       case R_X86_64_16:
        case R_X86_64_32:
+       case R_X86_64_64:
        case R_X86_64_32S:
        case R_X86_64_PC32:
          if (h != NULL)
@@ -523,7 +524,9 @@ elf64_x86_64_check_relocs (abfd, info, sec, relocs)
             and symbol visibility changes render the symbol local.  */
          if (info->shared
              && (sec->flags & SEC_ALLOC) != 0
-             && (ELF64_R_TYPE (rel->r_info) != R_X86_64_PC32
+             && (((ELF64_R_TYPE (rel->r_info) != R_X86_64_PC8)
+                 && (ELF64_R_TYPE (rel->r_info) != R_X86_64_PC16)
+                 && (ELF64_R_TYPE (rel->r_info) != R_X86_64_PC32))
                  || (h != NULL
                      && (! info->symbolic
                          || (h->elf_link_hash_flags
@@ -559,7 +562,7 @@ elf64_x86_64_check_relocs (abfd, info, sec, relocs)
                        flags |= SEC_ALLOC | SEC_LOAD;
                      if (sreloc == NULL
                          || ! bfd_set_section_flags (dynobj, sreloc, flags)
-                         || ! bfd_set_section_alignment (dynobj, sreloc, 2))
+                         || ! bfd_set_section_alignment (dynobj, sreloc, 3))
                        return false;
                    }
                }
@@ -572,7 +575,10 @@ elf64_x86_64_check_relocs (abfd, info, sec, relocs)
                 that this function is only called if we are using an
                 elf64_x86_64 linker hash table, which means that h is
                 really a pointer to an elf64_x86_64_link_hash_entry.  */
-             if (h != NULL && ELF64_R_TYPE (rel->r_info) == R_X86_64_PC32)
+             if (h != NULL
+                 && ((ELF64_R_TYPE (rel->r_info) == R_X86_64_PC8)
+                     || (ELF64_R_TYPE (rel->r_info) == R_X86_64_PC16)
+                     || (ELF64_R_TYPE (rel->r_info) == R_X86_64_PC32)))
                {
                  struct elf64_x86_64_link_hash_entry *eh;
                  struct elf64_x86_64_pcrel_relocs_copied *p;
@@ -610,7 +616,7 @@ elf64_x86_64_check_relocs (abfd, info, sec, relocs)
          /* This relocation describes which C++ vtable entries are actually
             used.  Record for later use during GC.  */
        case R_X86_64_GNU_VTENTRY:
-         if (!_bfd_elf64_gc_record_vtentry (abfd, sec, h, rel->r_offset))
+         if (!_bfd_elf64_gc_record_vtentry (abfd, sec, h, rel->r_addend))
            return false;
          break;
        }
@@ -1263,12 +1269,13 @@ elf64_x86_64_relocate_section (output_bfd, info, input_bfd, input_section,
                      && ((! info->symbolic && h->dynindx != -1)
                          || (h->elf_link_hash_flags
                              & ELF_LINK_HASH_DEF_REGULAR) == 0)
-                     && ( r_type == R_X86_64_8 ||
-                          r_type == R_X86_64_16 ||
-                           r_type == R_X86_64_32 ||
-                          r_type == R_X86_64_64 ||
-                           r_type == R_X86_64_PC16 ||
-                          r_type == R_X86_64_PC32)
+                     && (r_type == R_X86_64_8
+                         || r_type == R_X86_64_16
+                         || r_type == R_X86_64_32
+                         || r_type == R_X86_64_64
+                         || r_type == R_X86_64_PC8
+                         || r_type == R_X86_64_PC16
+                         || r_type == R_X86_64_PC32)
                       && ((input_section->flags & SEC_ALLOC) != 0
                           /* DWARF will emit R_X86_64_32 relocations in its
                              sections against symbols defined externally
@@ -1432,23 +1439,21 @@ elf64_x86_64_relocate_section (output_bfd, info, input_bfd, input_section,
                        + h->plt.offset);
          break;
 
-       case R_X86_64_8:
-       case R_X86_64_16:
-       case R_X86_64_32:
        case R_X86_64_PC8:
        case R_X86_64_PC16:
        case R_X86_64_PC32:
-         /* FIXME: The abi says the linker should make sure the value is
+         if (h == NULL || h->dynindx == -1
+             || (info->symbolic
+                 && h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
+           break;
+         /* Fall through.  */
+       case R_X86_64_8:
+       case R_X86_64_16:
+       case R_X86_64_32:
+       case R_X86_64_64:
+         /* FIXME: The ABI says the linker should make sure the value is
             the same when it's zeroextended to 64 bit.  */
-         if (info->shared
-             && (input_section->flags & SEC_ALLOC) != 0
-             && ((r_type != R_X86_64_PC8 && r_type != R_X86_64_PC16
-                  && r_type != R_X86_64_PC32)
-                 || (h != NULL
-                     && h->dynindx != -1
-                     && (! info->symbolic
-                         || (h->elf_link_hash_flags
-                             & ELF_LINK_HASH_DEF_REGULAR) == 0))))
+         if (info->shared && (input_section->flags & SEC_ALLOC) != 0)
            {
              Elf_Internal_Rela outrel;
              boolean skip, relocate;
@@ -1503,22 +1508,21 @@ elf64_x86_64_relocate_section (output_bfd, info, input_bfd, input_section,
                  memset (&outrel, 0, sizeof outrel);
                  relocate = false;
                }
-             else if ((r_type == R_X86_64_PC8) || (r_type == R_X86_64_PC16)
-                      || (r_type == R_X86_64_PC32))
+             /* h->dynindx may be -1 if this symbol was marked to
+                become local.  */
+             else if (h != NULL
+                      && ((! info->symbolic && h->dynindx != -1)
+                          || (h->elf_link_hash_flags
+                              & ELF_LINK_HASH_DEF_REGULAR) == 0))
                {
-                 BFD_ASSERT (h != NULL && h->dynindx != -1);
+                 BFD_ASSERT (h->dynindx != -1);
                  relocate = false;
                  outrel.r_info = ELF64_R_INFO (h->dynindx, r_type);
                  outrel.r_addend = relocation + rela->r_addend;
                }
              else
                {
-                 /* h->dynindx may be -1 if this symbol was marked to
-                    become local.  */
-                 if (h == NULL
-                     || ((info->symbolic || h->dynindx == -1)
-                         && (h->elf_link_hash_flags
-                             & ELF_LINK_HASH_DEF_REGULAR) != 0))
+                 if (r_type == R_X86_64_64)
                    {
                      relocate = true;
                      outrel.r_info = ELF64_R_INFO (0, R_X86_64_RELATIVE);
@@ -1526,11 +1530,38 @@ elf64_x86_64_relocate_section (output_bfd, info, input_bfd, input_section,
                    }
                  else
                    {
-                     BFD_ASSERT (h->dynindx != -1);
+                     long indx;
+
+                     if (h == NULL)
+                       sec = local_sections[r_symndx];
+                     else
+                       {
+                         BFD_ASSERT (h->root.type == bfd_link_hash_defined
+                                     || (h->root.type
+                                         == bfd_link_hash_defweak));
+                         sec = h->root.u.def.section;
+                       }
+                     if (sec != NULL && bfd_is_abs_section (sec))
+                       indx = 0;
+                     else if (sec == NULL || sec->owner == NULL)
+                       {
+                         bfd_set_error (bfd_error_bad_value);
+                         return false;
+                       }
+                     else
+                       {
+                         asection *osec;
+
+                         osec = sec->output_section;
+                         indx = elf_section_data (osec)->dynindx;
+                         BFD_ASSERT (indx > 0);
+                       }
+
                      relocate = false;
-                     outrel.r_info = ELF64_R_INFO (h->dynindx, R_X86_64_32);
+                     outrel.r_info = ELF64_R_INFO (indx, r_type);
                      outrel.r_addend = relocation + rela->r_addend;
                    }
+
                }
 
              bfd_elf64_swap_reloca_out (output_bfd, &outrel,
@@ -1720,6 +1751,7 @@ elf64_x86_64_finish_dynamic_symbol (output_bfd, info, h, sym)
              && (info->symbolic || h->dynindx == -1)
              && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
        {
+         BFD_ASSERT((h->got.offset & 1) != 0);
          rela.r_info = ELF64_R_INFO (0, R_X86_64_RELATIVE);
          rela.r_addend = (h->root.u.def.value
                           + h->root.u.def.section->output_section->vma
@@ -1906,49 +1938,12 @@ elf64_x86_64_finish_dynamic_sections (output_bfd, info)
   return true;
 }
 
-/*
- * Why was the hash table entry size definition changed from
- * ARCH_SIZE/8 to 4? This breaks the 64 bit dynamic linker and
- * this is the only reason for the elf64_x86_64_size_info structure.
- */
-
-const struct elf_size_info elf64_86_64_size_info =
-{
-  sizeof (Elf64_External_Ehdr),
-  sizeof (Elf64_External_Phdr),
-  sizeof (Elf64_External_Shdr),
-  sizeof (Elf64_External_Rel),
-  sizeof (Elf64_External_Rela),
-  sizeof (Elf64_External_Sym),
-  sizeof (Elf64_External_Dyn),
-  sizeof (Elf_External_Note),
-  8,           /* hash-table entry size */
-  1,           /* internal relocations per external relocations */
-  64,          /* arch_size */
-  8,           /* file_align */
-  ELFCLASS64, EV_CURRENT,
-  bfd_elf64_write_out_phdrs,
-  bfd_elf64_write_shdrs_and_ehdr,
-  bfd_elf64_write_relocs,
-  bfd_elf64_swap_symbol_out,
-  bfd_elf64_slurp_reloc_table,
-  bfd_elf64_slurp_symbol_table,
-  bfd_elf64_swap_dyn_in,
-  bfd_elf64_swap_dyn_out,
-  NULL,
-  NULL,
-  NULL,
-  NULL
-};
-
 #define TARGET_LITTLE_SYM                  bfd_elf64_x86_64_vec
 #define TARGET_LITTLE_NAME                 "elf64-x86-64"
 #define ELF_ARCH                           bfd_arch_i386
 #define ELF_MACHINE_CODE                   EM_X86_64
 #define ELF_MAXPAGESIZE                            0x100000
 
-#define elf_backend_size_info              elf64_86_64_size_info
-
 #define elf_backend_can_gc_sections        1
 #define elf_backend_want_got_plt           1
 #define elf_backend_plt_readonly           1
This page took 0.027206 seconds and 4 git commands to generate.