bfd/
[deliverable/binutils-gdb.git] / bfd / elf64-x86-64.c
index f1cf825d29df4b7a1abe6bd784f4636ec910d42b..de6f6ecd242a2735dda536e73698b8e51e85bde5 100644 (file)
@@ -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;
@@ -949,7 +950,7 @@ elf64_x86_64_tls_transition (struct bfd_link_info *info, bfd *abfd,
     case R_X86_64_GOTPC32_TLSDESC:
     case R_X86_64_TLSDESC_CALL:
     case R_X86_64_GOTTPOFF:
-      if (!info->shared)
+      if (info->executable)
        {
          if (h == NULL)
            to_type = R_X86_64_TPOFF32;
@@ -964,7 +965,7 @@ elf64_x86_64_tls_transition (struct bfd_link_info *info, bfd *abfd,
        {
          unsigned int new_to_type = to_type;
 
-         if (!info->shared
+         if (info->executable
              && h != NULL
              && h->dynindx == -1
              && tls_type == GOT_TLS_IE)
@@ -988,7 +989,7 @@ elf64_x86_64_tls_transition (struct bfd_link_info *info, bfd *abfd,
       break;
 
     case R_X86_64_TLSLD:
-      if (!info->shared)
+      if (info->executable)
        to_type = R_X86_64_TPOFF32;
       break;
 
@@ -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;
            }
 
@@ -1145,6 +1150,7 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
            {
              /* It is referenced by a non-shared object. */
              h->ref_regular = 1;
+             h->needs_plt = 1;
  
              /* STT_GNU_IFUNC symbol must go through PLT.  */
              h->plt.refcount += 1;
@@ -1156,15 +1162,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 +1187,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 +1210,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 +1221,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)
        {
@@ -1222,20 +1231,24 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
          goto create_got;
 
        case R_X86_64_TPOFF32:
-         if (info->shared)
+         if (!info->executable)
            {
+             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;
 
        case R_X86_64_GOTTPOFF:
-         if (info->shared)
+         if (!info->executable)
            info->flags |= DF_STATIC_TLS;
          /* Fall through */
 
@@ -1290,7 +1303,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 +1328,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 +1360,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 +1403,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 +1487,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
@@ -1508,7 +1528,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;
@@ -1526,7 +1546,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
@@ -1535,7 +1555,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:
@@ -1543,25 +1563,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
@@ -1639,7 +1641,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)
@@ -1940,7 +1942,7 @@ elf64_x86_64_allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
   /* If R_X86_64_GOTTPOFF symbol is now local to the binary,
      make it a R_X86_64_TPOFF32 requiring no GOT entry.  */
   if (h->got.refcount > 0
-      && !info->shared
+      && info->executable
       && h->dynindx == -1
       && elf64_x86_64_hash_entry (h)->tls_type == GOT_TLS_IE)
     {
@@ -2610,7 +2612,8 @@ elf64_x86_64_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
                                                &sec, rel);
 
          /* Relocate against local STT_GNU_IFUNC symbol.  */
-         if (ELF64_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
+         if (!info->relocatable
+             && ELF64_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
            {
              h = elf64_x86_64_get_local_sym_hash (htab, input_bfd,
                                                   rel, FALSE);
@@ -2654,6 +2657,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)
@@ -2667,13 +2671,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;
 
@@ -2685,13 +2692,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;
                }
@@ -3236,7 +3246,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)
@@ -3570,7 +3580,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)
@@ -3622,14 +3632,14 @@ elf64_x86_64_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
          break;
 
        case R_X86_64_DTPOFF32:
-         if (info->shared || (input_section->flags & SEC_CODE) == 0)
+         if (!info->executable|| (input_section->flags & SEC_CODE) == 0)
            relocation -= elf64_x86_64_dtpoff_base (info);
          else
            relocation = elf64_x86_64_tpoff (info, relocation);
          break;
 
        case R_X86_64_TPOFF32:
-         BFD_ASSERT (! info->shared);
+         BFD_ASSERT (info->executable);
          relocation = elf64_x86_64_tpoff (info, relocation);
          break;
 
@@ -4473,3 +4483,53 @@ static const struct bfd_elf_special_section
 #define elf64_bed elf64_x86_64_fbsd_bed
 
 #include "elf64-target.h"
+
+/* Intel L1OM support.  */
+
+static bfd_boolean
+elf64_l1om_elf_object_p (bfd *abfd)
+{
+  /* Set the right machine number for an L1OM elf64 file.  */
+  bfd_default_set_arch_mach (abfd, bfd_arch_l1om, bfd_mach_l1om);
+  return TRUE;
+}
+
+#undef  TARGET_LITTLE_SYM
+#define TARGET_LITTLE_SYM                  bfd_elf64_l1om_vec
+#undef  TARGET_LITTLE_NAME
+#define TARGET_LITTLE_NAME                 "elf64-l1om"
+#undef ELF_ARCH
+#define ELF_ARCH                           bfd_arch_l1om
+
+#undef ELF_MACHINE_CODE
+#define ELF_MACHINE_CODE                   EM_L1OM
+
+#undef ELF_OSABI
+
+#undef  elf64_bed
+#define elf64_bed elf64_l1om_bed
+
+#undef elf_backend_object_p
+#define elf_backend_object_p               elf64_l1om_elf_object_p
+
+#undef  elf_backend_post_process_headers
+
+#include "elf64-target.h"
+
+/* FreeBSD L1OM support.  */
+
+#undef  TARGET_LITTLE_SYM
+#define TARGET_LITTLE_SYM                  bfd_elf64_l1om_freebsd_vec
+#undef  TARGET_LITTLE_NAME
+#define TARGET_LITTLE_NAME                 "elf64-l1om-freebsd"
+
+#undef ELF_OSABI
+#define        ELF_OSABI                           ELFOSABI_FREEBSD
+
+#undef  elf64_bed
+#define elf64_bed elf64_l1om_fbsd_bed
+
+#undef  elf_backend_post_process_headers
+#define elf_backend_post_process_headers  _bfd_elf_set_osabi
+
+#include "elf64-target.h"
This page took 0.032591 seconds and 4 git commands to generate.