Fix indentation of:
[deliverable/binutils-gdb.git] / bfd / elf64-x86-64.c
index 581d544013651e857523592ce0e90515f159d89d..274b8746b7df98c21de53626c839d1b996ab3a1c 100644 (file)
@@ -487,8 +487,8 @@ struct elf64_x86_64_link_hash_table
   /* The amount of space used by the jump slots in the GOT.  */
   bfd_vma sgotplt_jump_table_size;
 
-  /* Small local sym to section mapping cache.  */
-  struct sym_sec_cache sym_sec;
+  /* Small local sym cache.  */
+  struct sym_cache sym_cache;
 
   /* _TLS_MODULE_BASE_ symbol.  */
   struct bfd_link_hash_entry *tls_module_base;
@@ -629,7 +629,7 @@ elf64_x86_64_link_hash_table_create (bfd *abfd)
 
   ret->sdynbss = NULL;
   ret->srelbss = NULL;
-  ret->sym_sec.abfd = NULL;
+  ret->sym_cache.abfd = NULL;
   ret->tlsdesc_plt = 0;
   ret->tlsdesc_got = 0;
   ret->tls_ld_got.refcount = 0;
@@ -937,7 +937,8 @@ elf64_x86_64_tls_transition (struct bfd_link_info *info, bfd *abfd,
                             unsigned int *r_type, int tls_type,
                             const Elf_Internal_Rela *rel,
                             const Elf_Internal_Rela *relend,
-                            struct elf_link_hash_entry *h)
+                            struct elf_link_hash_entry *h,
+                            unsigned long r_symndx)
 {
   unsigned int from_type = *r_type;
   unsigned int to_type = from_type;
@@ -1007,15 +1008,27 @@ elf64_x86_64_tls_transition (struct bfd_link_info *info, bfd *abfd,
                                              from_type, rel, relend))
     {
       reloc_howto_type *from, *to;
+      const char *name;
 
       from = elf64_x86_64_rtype_to_howto (abfd, from_type);
       to = elf64_x86_64_rtype_to_howto (abfd, to_type);
 
+      if (h)
+       name = h->root.root.string;
+      else
+       {
+         Elf_Internal_Sym *isym;
+         struct elf64_x86_64_link_hash_table *htab;
+         htab = elf64_x86_64_hash_table (info);
+         isym = bfd_sym_from_r_symndx (&htab->sym_cache,
+                                       abfd, r_symndx);
+         name = bfd_elf_sym_name (abfd, symtab_hdr, isym, NULL);
+       }
+
       (*_bfd_error_handler)
        (_("%B: TLS transition from %s to %s against `%s' at 0x%lx "
           "in section `%A' failed"),
-        abfd, sec, from->name, to->name,
-        h ? h->root.root.string : "a local symbol",
+        abfd, sec, from->name, to->name, name,
         (unsigned long) rel->r_offset);
       bfd_set_error (bfd_error_bad_value);
       return FALSE;
@@ -1040,7 +1053,6 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
   const Elf_Internal_Rela *rel;
   const Elf_Internal_Rela *rel_end;
   asection *sreloc;
-  Elf_Internal_Sym *isymbuf;
 
   if (info->relocatable)
     return TRUE;
@@ -1049,7 +1061,6 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
 
   htab = elf64_x86_64_hash_table (info);
   symtab_hdr = &elf_symtab_hdr (abfd);
-  isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
   sym_hashes = elf_sym_hashes (abfd);
 
   sreloc = NULL;
@@ -1060,6 +1071,8 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
       unsigned int r_type;
       unsigned long r_symndx;
       struct elf_link_hash_entry *h;
+      Elf_Internal_Sym *isym;
+      const char *name;
 
       r_symndx = ELF64_R_SYM (rel->r_info);
       r_type = ELF64_R_TYPE (rel->r_info);
@@ -1074,27 +1087,18 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
       if (r_symndx < symtab_hdr->sh_info)
        {
          /* A local symbol.  */
-         Elf_Internal_Sym *isym;
-
-         /* Read this BFD's local symbols.  */
-         if (isymbuf == NULL)
-           {
-             if (isymbuf == NULL)
-               isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
-                                               symtab_hdr->sh_info, 0,
-                                               NULL, NULL, NULL);
-             if (isymbuf == NULL)
-                 return FALSE;
-           }
+         isym = bfd_sym_from_r_symndx (&htab->sym_cache,
+                                       abfd, r_symndx);
+         if (isym == NULL)
+           return FALSE;
 
          /* Check relocation against local STT_GNU_IFUNC symbol.  */
-         isym = isymbuf + r_symndx;
          if (ELF64_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
            {
              h = elf64_x86_64_get_local_sym_hash (htab, abfd, rel,
                                                   TRUE);
              if (h == NULL)
-               goto error_return;
+               return FALSE;
              
              /* Fake a STT_GNU_IFUNC symbol.  */
              h->type = STT_GNU_IFUNC;
@@ -1108,6 +1112,7 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
        }
       else
        {
+         isym = NULL;
          h = sym_hashes[r_symndx - symtab_hdr->sh_info];
          while (h->root.type == bfd_link_hash_indirect
                 || h->root.type == bfd_link_hash_warning)
@@ -1134,7 +1139,7 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
            case R_X86_64_GOTPCREL:
            case R_X86_64_GOTPCREL64:
              if (!_bfd_elf_create_ifunc_sections (abfd, info))
-               goto error_return;
+               return FALSE;
              break;
            }
 
@@ -1156,15 +1161,18 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
              switch (r_type)
                {
                default:
+                 if (h->root.root.string)
+                   name = h->root.root.string;
+                 else
+                   name = bfd_elf_sym_name (abfd, symtab_hdr, isym,
+                                            NULL);
                  (*_bfd_error_handler)
                    (_("%B: relocation %s against STT_GNU_IFUNC "
                       "symbol `%s' isn't handled by %s"), abfd,
                     x86_64_elf_howto_table[r_type].name,
-                    (h->root.root.string
-                     ? h->root.root.string : "a local symbol"),
-                    __FUNCTION__);
+                    name, __FUNCTION__);
                  bfd_set_error (bfd_error_bad_value);
-                 goto error_return;
+                 return FALSE;
 
                case R_X86_64_64:
                  h->non_got_ref = 1;
@@ -1178,7 +1186,7 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
                        (abfd, info, sec, sreloc,
                         &((struct elf64_x86_64_link_hash_entry *) h)->dyn_relocs);
                      if (sreloc == NULL)
-                       goto error_return;
+                       return FALSE;
                    }
                  break;
 
@@ -1201,7 +1209,7 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
                  if (htab->elf.sgot == NULL
                      && !_bfd_elf_create_got_section (htab->elf.dynobj,
                                                       info))
-                   goto error_return;
+                   return FALSE;
                  break;
                }
 
@@ -1212,8 +1220,8 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
       if (! elf64_x86_64_tls_transition (info, abfd, sec, NULL,
                                         symtab_hdr, sym_hashes,
                                         &r_type, GOT_UNKNOWN,
-                                        rel, rel_end, h))
-       goto error_return;
+                                        rel, rel_end, h, r_symndx))
+       return FALSE;
 
       switch (r_type)
        {
@@ -1224,13 +1232,17 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
        case R_X86_64_TPOFF32:
          if (info->shared)
            {
+             if (h)
+               name = h->root.root.string;
+             else
+               name = bfd_elf_sym_name (abfd, symtab_hdr, isym,
+                                        NULL);
              (*_bfd_error_handler)
                (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
                 abfd,
-                x86_64_elf_howto_table[r_type].name,
-                (h) ? h->root.root.string : "a local symbol");
+                x86_64_elf_howto_table[r_type].name, name);
              bfd_set_error (bfd_error_bad_value);
-             goto error_return;
+             return FALSE;
            }
          break;
 
@@ -1290,7 +1302,7 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
                    local_got_refcounts = ((bfd_signed_vma *)
                                           bfd_zalloc (abfd, size));
                    if (local_got_refcounts == NULL)
-                     goto error_return;
+                     return FALSE;
                    elf_local_got_refcounts (abfd) = local_got_refcounts;
                    elf64_x86_64_local_tlsdesc_gotent (abfd)
                      = (bfd_vma *) (local_got_refcounts + symtab_hdr->sh_info);
@@ -1315,10 +1327,15 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
                  tls_type |= old_tls_type;
                else
                  {
+                   if (h)
+                     name = h->root.root.string;
+                   else
+                     name = bfd_elf_sym_name (abfd, symtab_hdr,
+                                              isym, NULL);
                    (*_bfd_error_handler)
                      (_("%B: '%s' accessed both as normal and thread local symbol"),
-                      abfd, h ? h->root.root.string : "<local>");
-                   goto error_return;
+                      abfd, name);
+                   return FALSE;
                  }
              }
 
@@ -1342,7 +1359,7 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
                htab->elf.dynobj = abfd;
              if (!_bfd_elf_create_got_section (htab->elf.dynobj,
                                                info))
-               goto error_return;
+               return FALSE;
            }
          break;
 
@@ -1385,13 +1402,15 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
              && (sec->flags & SEC_ALLOC) != 0
              && (sec->flags & SEC_READONLY) != 0)
            {
+             if (h)
+               name = h->root.root.string;
+             else
+               name = bfd_elf_sym_name (abfd, symtab_hdr, isym, NULL);
              (*_bfd_error_handler)
                (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
-                abfd,
-                x86_64_elf_howto_table[r_type].name,
-                (h) ? h->root.root.string : "a local symbol");
+                abfd, x86_64_elf_howto_table[r_type].name, name);
              bfd_set_error (bfd_error_bad_value);
-             goto error_return;
+             return FALSE;
            }
          /* Fall through.  */
 
@@ -1467,7 +1486,7 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
                    (sec, htab->elf.dynobj, 3, abfd, /*rela?*/ TRUE);
 
                  if (sreloc == NULL)
-                   goto error_return;
+                   return FALSE;
                }
 
              /* If this is a global symbol, we count the number of
@@ -1478,16 +1497,21 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
                }
              else
                {
-                 void **vpp;
                  /* Track dynamic relocs needed for local syms too.
                     We really need local syms available to do this
                     easily.  Oh well.  */
-
                  asection *s;
-                 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec,
-                                                sec, r_symndx);
+                 void **vpp;
+                 Elf_Internal_Sym *isym;
+
+                 isym = bfd_sym_from_r_symndx (&htab->sym_cache,
+                                               abfd, r_symndx);
+                 if (isym == NULL)
+                   return FALSE;
+
+                 s = bfd_section_from_elf_index (abfd, isym->st_shndx);
                  if (s == NULL)
-                   goto error_return;
+                   s = sec;
 
                  /* Beware of type punned pointers vs strict aliasing
                     rules.  */
@@ -1503,7 +1527,7 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
                  p = ((struct elf_dyn_relocs *)
                       bfd_alloc (htab->elf.dynobj, amt));
                  if (p == NULL)
-                   goto error_return;
+                   return FALSE;
                  p->next = *head;
                  *head = p;
                  p->sec = sec;
@@ -1521,7 +1545,7 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
             Reconstruct it for later use during GC.  */
        case R_X86_64_GNU_VTINHERIT:
          if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
-           goto error_return;
+           return FALSE;
          break;
 
          /* This relocation describes which C++ vtable entries are actually
@@ -1530,7 +1554,7 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
          BFD_ASSERT (h != NULL);
          if (h != NULL
              && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
-           goto error_return;
+           return FALSE;
          break;
 
        default:
@@ -1538,25 +1562,7 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
        }
     }
 
-   if (isymbuf != NULL
-       && (unsigned char *) isymbuf != symtab_hdr->contents)
-    {
-      if (!info->keep_memory)
-       free (isymbuf);
-      else
-       {
-         /* Cache the symbols for elf_link_input_bfd.  */
-         symtab_hdr->contents = (unsigned char *) isymbuf;
-       }
-    }
-
   return TRUE;
-
-error_return:
-   if (isymbuf != NULL
-       && (unsigned char *) isymbuf != symtab_hdr->contents)
-     free (isymbuf);
-   return FALSE;
 }
 
 /* Return the section that should be marked against GC for a given
@@ -1634,7 +1640,7 @@ elf64_x86_64_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info,
       if (! elf64_x86_64_tls_transition (info, abfd, sec, NULL,
                                         symtab_hdr, sym_hashes,
                                         &r_type, GOT_UNKNOWN,
-                                        rel, relend, h))
+                                        rel, relend, h, r_symndx))
        return FALSE;
 
       switch (r_type)
@@ -2649,6 +2655,7 @@ elf64_x86_64_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
        {
          asection *plt;
          bfd_vma plt_index;
+         const char *name;
 
          if ((input_section->flags & SEC_ALLOC) == 0
              || h->plt.offset == (bfd_vma) -1)
@@ -2662,13 +2669,16 @@ elf64_x86_64_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
          switch (r_type)
            {
            default:
+             if (h->root.root.string)
+               name = h->root.root.string;
+             else
+               name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym,
+                                        NULL);
              (*_bfd_error_handler)
                (_("%B: relocation %s against STT_GNU_IFUNC "
                   "symbol `%s' isn't handled by %s"), input_bfd,
                 x86_64_elf_howto_table[r_type].name,
-                (h->root.root.string
-                 ? h->root.root.string : "a local symbol"),
-                __FUNCTION__);
+                name, __FUNCTION__);
              bfd_set_error (bfd_error_bad_value);
              return FALSE;
 
@@ -2680,13 +2690,16 @@ elf64_x86_64_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
            case R_X86_64_64: 
              if (rel->r_addend != 0)
                {
+                 if (h->root.root.string)
+                   name = h->root.root.string;
+                 else
+                   name = bfd_elf_sym_name (input_bfd, symtab_hdr,
+                                            sym, NULL);
                  (*_bfd_error_handler)
                    (_("%B: relocation %s against STT_GNU_IFUNC "
                       "symbol `%s' has non-zero addend: %d"),
                     input_bfd, x86_64_elf_howto_table[r_type].name,
-                    (h->root.root.string
-                     ? h->root.root.string : "a local symbol"),
-                    rel->r_addend);
+                    name, rel->r_addend);
                  bfd_set_error (bfd_error_bad_value);
                  return FALSE;
                }
@@ -3231,7 +3244,7 @@ elf64_x86_64_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
                                             input_section, contents,
                                             symtab_hdr, sym_hashes,
                                             &r_type, tls_type, rel,
-                                            relend, h))
+                                            relend, h, r_symndx))
            return FALSE;
 
          if (r_type == R_X86_64_TPOFF32)
@@ -3565,7 +3578,7 @@ elf64_x86_64_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
                                             input_section, contents,
                                             symtab_hdr, sym_hashes,
                                             &r_type, GOT_UNKNOWN,
-                                            rel, relend, h))
+                                            rel, relend, h, r_symndx))
            return FALSE;
 
          if (r_type != R_X86_64_TLSLD)
This page took 0.029991 seconds and 4 git commands to generate.