* elfcode.h (elf_swap_ehdr_out): Adjust value written for e_shnum
[deliverable/binutils-gdb.git] / bfd / elf64-x86-64.c
index 0b8d345703a46d3b335a75ce6a400699694f7c5e..9f7fdd3dc3f645f49ba35c54168d53eacb711d74 100644 (file)
@@ -153,7 +153,8 @@ static boolean elf64_x86_64_finish_dynamic_symbol
           Elf_Internal_Sym *sym));
 static boolean elf64_x86_64_finish_dynamic_sections
   PARAMS ((bfd *, struct bfd_link_info *));
-static enum elf_reloc_type_class elf64_x86_64_reloc_type_class PARAMS ((int));
+static enum elf_reloc_type_class elf64_x86_64_reloc_type_class
+  PARAMS ((const Elf_Internal_Rela *));
 
 /* Given a BFD reloc type, return a HOWTO structure.  */
 static reloc_howto_type *
@@ -166,8 +167,7 @@ elf64_x86_64_reloc_type_lookup (abfd, code)
        i++)
     {
       if (x86_64_reloc_map[i].bfd_reloc_val == code)
-       return &x86_64_elf_howto_table[(int)
-                                      x86_64_reloc_map[i].elf_reloc_val];
+       return &x86_64_elf_howto_table[i];
     }
   return 0;
 }
@@ -441,10 +441,8 @@ elf64_x86_64_check_relocs (abfd, info, sec, relocs)
 
          if (h != NULL)
            {
-             if (h->got.refcount == -1)
+             if (h->got.refcount == 0)
                {
-                 h->got.refcount = 1;
-
                  /* Make sure this symbol is output as a dynamic symbol.  */
                  if (h->dynindx == -1)
                    {
@@ -455,8 +453,7 @@ elf64_x86_64_check_relocs (abfd, info, sec, relocs)
                  sgot->_raw_size += GOT_ENTRY_SIZE;
                  srelgot->_raw_size += sizeof (Elf64_External_Rela);
                }
-             else
-               h->got.refcount += 1;
+             h->got.refcount += 1;
            }
          else
            {
@@ -468,16 +465,13 @@ elf64_x86_64_check_relocs (abfd, info, sec, relocs)
                  size = symtab_hdr->sh_info;
                  size *= sizeof (bfd_signed_vma);
                  local_got_refcounts = ((bfd_signed_vma *)
-                                        bfd_alloc (abfd, size));
+                                        bfd_zalloc (abfd, size));
                  if (local_got_refcounts == NULL)
                    return false;
                  elf_local_got_refcounts (abfd) = local_got_refcounts;
-                 memset (local_got_refcounts, -1, (size_t) size);
                }
-             if (local_got_refcounts[r_symndx] == -1)
+             if (local_got_refcounts[r_symndx] == 0)
                {
-                 local_got_refcounts[r_symndx] = 1;
-
                  sgot->_raw_size += GOT_ENTRY_SIZE;
                  if (info->shared)
                    {
@@ -487,8 +481,7 @@ elf64_x86_64_check_relocs (abfd, info, sec, relocs)
                      srelgot->_raw_size += sizeof (Elf64_External_Rela);
                    }
                }
-             else
-               local_got_refcounts[r_symndx] += 1;
+             local_got_refcounts[r_symndx] += 1;
            }
          break;
 
@@ -506,10 +499,7 @@ elf64_x86_64_check_relocs (abfd, info, sec, relocs)
            continue;
 
          h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT;
-         if (h->plt.refcount == -1)
-           h->plt.refcount = 1;
-         else
-           h->plt.refcount += 1;
+         h->plt.refcount += 1;
          break;
 
        case R_X86_64_8:
@@ -864,6 +854,8 @@ elf64_x86_64_adjust_dynamic_symbol (info, h)
 
       return true;
     }
+  else
+    h->plt.offset = (bfd_vma) -1;
 
   /* If this is a weak symbol, and there is a real definition, the
      processor independent code will have arranged for us to see the
@@ -1237,9 +1229,7 @@ elf64_x86_64_relocate_section (output_bfd, info, input_bfd, input_section,
        {
          sym = local_syms + r_symndx;
          sec = local_sections[r_symndx];
-         relocation = (sec->output_section->vma
-                       + sec->output_offset
-                       + sym->st_value);
+         relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rela);
        }
       else
        {
@@ -1289,7 +1279,7 @@ elf64_x86_64_relocate_section (output_bfd, info, input_bfd, input_section,
                {
                  (*_bfd_error_handler)
                    (_("%s: warning: unresolvable relocation against symbol `%s' from %s section"),
-                    bfd_get_filename (input_bfd), h->root.root.string,
+                    bfd_archive_filename (input_bfd), h->root.root.string,
                     bfd_get_section_name (input_bfd, input_section));
                  relocation = 0;
                }
@@ -1450,7 +1440,9 @@ elf64_x86_64_relocate_section (output_bfd, info, input_bfd, input_section,
        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)
+         if (info->shared
+             && r_symndx != 0
+             && (input_section->flags & SEC_ALLOC) != 0)
            {
              Elf_Internal_Rela outrel;
              boolean skip, relocate;
@@ -1481,21 +1473,11 @@ elf64_x86_64_relocate_section (output_bfd, info, input_bfd, input_section,
 
              skip = false;
 
-             if (elf_section_data (input_section)->stab_info == NULL)
-               outrel.r_offset = rela->r_offset;
-             else
-               {
-                 bfd_vma off;
-
-                 off = (_bfd_stab_section_offset
-                        (output_bfd, &elf_hash_table (info)->stab_info,
-                         input_section,
-                         &elf_section_data (input_section)->stab_info,
-                         rela->r_offset));
-                 if (off == (bfd_vma) -1)
-                   skip = true;
-                 outrel.r_offset = off;
-               }
+             outrel.r_offset =
+               _bfd_elf_section_offset (output_bfd, info, input_section,
+                                        rela->r_offset);
+             if (outrel.r_offset == (bfd_vma) -1)
+               skip = true;
 
              outrel.r_offset += (input_section->output_section->vma
                                  + input_section->output_offset);
@@ -1936,10 +1918,10 @@ elf64_x86_64_finish_dynamic_sections (output_bfd, info)
 }
 
 static enum elf_reloc_type_class
-elf64_x86_64_reloc_type_class (type)
-     int type;
+elf64_x86_64_reloc_type_class (rela)
+     const Elf_Internal_Rela *rela;
 {
-  switch (type)
+  switch ((int) ELF64_R_TYPE (rela->r_info))
     {
     case R_X86_64_RELATIVE:
       return reloc_class_relative;
@@ -1959,6 +1941,7 @@ elf64_x86_64_reloc_type_class (type)
 #define ELF_MAXPAGESIZE                            0x100000
 
 #define elf_backend_can_gc_sections        1
+#define elf_backend_can_refcount           1
 #define elf_backend_want_got_plt           1
 #define elf_backend_plt_readonly           1
 #define elf_backend_want_plt_sym           0
This page took 0.026862 seconds and 4 git commands to generate.