* elfcode.h (elf_swap_ehdr_out): Adjust value written for e_shnum
[deliverable/binutils-gdb.git] / bfd / elf64-x86-64.c
index 0359b164ac4c7ab0d2f6c7867e3d63a9b9fc848d..9f7fdd3dc3f645f49ba35c54168d53eacb711d74 100644 (file)
@@ -167,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;
 }
@@ -442,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)
                    {
@@ -456,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
            {
@@ -469,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)
                    {
@@ -488,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;
 
@@ -507,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:
@@ -865,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
@@ -1238,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
        {
@@ -1451,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;
@@ -1482,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);
@@ -1960,6 +1941,7 @@ elf64_x86_64_reloc_type_class (rela)
 #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.024947 seconds and 4 git commands to generate.