include/elf
[deliverable/binutils-gdb.git] / bfd / elf64-x86-64.c
index 840e37a147d9bc05a0dc34d4aebcc0c36be03bd7..b82bcd11b768993134da4b75507fafd3254d3573 100644 (file)
@@ -1,5 +1,5 @@
 /* X86-64 specific support for 64-bit ELF
-   Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
+   Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
    Free Software Foundation, Inc.
    Contributed by Jan Hubicka <jh@suse.cz>.
 
@@ -161,6 +161,12 @@ static reloc_howto_type x86_64_elf_howto_table[] =
         FALSE)
 };
 
+#define IS_X86_64_PCREL_TYPE(TYPE)     \
+  (   ((TYPE) == R_X86_64_PC8)         \
+   || ((TYPE) == R_X86_64_PC16)                \
+   || ((TYPE) == R_X86_64_PC32)                \
+   || ((TYPE) == R_X86_64_PC64))
+
 /* Map BFD relocs to the x86_64 elf relocs.  */
 struct elf_reloc_map
 {
@@ -457,6 +463,18 @@ struct elf64_x86_64_obj_tdata
 #define elf64_x86_64_local_tlsdesc_gotent(abfd) \
   (elf64_x86_64_tdata (abfd)->local_tlsdesc_gotent)
 
+#define is_x86_64_elf(bfd)                             \
+  (bfd_get_flavour (bfd) == bfd_target_elf_flavour     \
+   && elf_tdata (bfd) != NULL                          \
+   && elf_object_id (bfd) == X86_64_ELF_TDATA)
+
+static bfd_boolean
+elf64_x86_64_mkobject (bfd *abfd)
+{
+  return bfd_elf_allocate_object (abfd, sizeof (struct elf64_x86_64_obj_tdata),
+                                 X86_64_ELF_TDATA);
+}
+
 /* x86-64 ELF linker hash table.  */
 
 struct elf64_x86_64_link_hash_table
@@ -491,6 +509,9 @@ struct elf64_x86_64_link_hash_table
 
   /* Small local sym to section mapping cache.  */
   struct sym_sec_cache sym_sec;
+
+  /* _TLS_MODULE_BASE_ symbol.  */
+  struct bfd_link_hash_entry *tls_module_base;
 };
 
 /* Get the x86-64 ELF linker hash table from a link_info structure.  */
@@ -563,6 +584,7 @@ elf64_x86_64_link_hash_table_create (bfd *abfd)
   ret->tlsdesc_got = 0;
   ret->tls_ld_got.refcount = 0;
   ret->sgotplt_jump_table_size = 0;
+  ret->tls_module_base = NULL;
 
   return &ret->elf.root;
 }
@@ -692,19 +714,6 @@ elf64_x86_64_copy_indirect_symbol (struct bfd_link_info *info,
     _bfd_elf_link_hash_copy_indirect (info, dir, ind);
 }
 
-static bfd_boolean
-elf64_x86_64_mkobject (bfd *abfd)
-{
-  if (abfd->tdata.any == NULL)
-    {
-      bfd_size_type amt = sizeof (struct elf64_x86_64_obj_tdata);
-      abfd->tdata.any = bfd_zalloc (abfd, amt);
-      if (abfd->tdata.any == NULL)
-       return FALSE;
-    }
-  return bfd_elf_mkobject (abfd);
-}
-
 static bfd_boolean
 elf64_x86_64_elf_object_p (bfd *abfd)
 {
@@ -807,11 +816,14 @@ elf64_x86_64_check_tls_transition (bfd *abfd, asection *sec,
        return FALSE;
 
       h = sym_hashes[r_symndx - symtab_hdr->sh_info];
+      /* Use strncmp to check __tls_get_addr since __tls_get_addr
+        may be versioned.  */ 
       return (h != NULL
              && h->root.root.string != NULL
              && (ELF64_R_TYPE (rel[1].r_info) == R_X86_64_PC32
                  || ELF64_R_TYPE (rel[1].r_info) == R_X86_64_PLT32)
-             && (strcmp (h->root.root.string, "__tls_get_addr") == 0));
+             && (strncmp (h->root.root.string,
+                          "__tls_get_addr", 14) == 0));
 
     case R_X86_64_GOTTPOFF:
       /* Check transition from IE access model:
@@ -952,7 +964,7 @@ elf64_x86_64_tls_transition (struct bfd_link_info *info, bfd *abfd,
                                              symtab_hdr, sym_hashes,
                                              from_type, rel, relend))
     {
-      const reloc_howto_type *from, *to;
+      reloc_howto_type *from, *to;
 
       from = elf64_x86_64_rtype_to_howto (abfd, from_type);
       to = elf64_x86_64_rtype_to_howto (abfd, to_type);
@@ -971,6 +983,25 @@ elf64_x86_64_tls_transition (struct bfd_link_info *info, bfd *abfd,
   return TRUE;
 }
 
+/* Returns true if the hash entry refers to a symbol
+   marked for indirect handling during reloc processing.  */
+
+static bfd_boolean
+is_indirect_symbol (bfd * abfd, struct elf_link_hash_entry * h)
+{
+  const struct elf_backend_data * bed;
+
+  if (abfd == NULL || h == NULL)
+    return FALSE;
+
+  bed = get_elf_backend_data (abfd);
+
+  return h->type == STT_GNU_IFUNC
+    && (bed->elf_osabi == ELFOSABI_LINUX
+       /* GNU/Linux is still using the default value 0.  */
+       || bed->elf_osabi == ELFOSABI_NONE);
+}
+
 /* Look through the relocs for a section during the first phase, and
    calculate needed space in the global offset table, procedure
    linkage table, and dynamic reloc sections.  */
@@ -990,12 +1021,14 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
   if (info->relocatable)
     return TRUE;
 
+  BFD_ASSERT (is_x86_64_elf (abfd));
+
   htab = elf64_x86_64_hash_table (info);
-  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
+  symtab_hdr = &elf_symtab_hdr (abfd);
   sym_hashes = elf_sym_hashes (abfd);
 
   sreloc = NULL;
-
+  
   rel_end = relocs + sec->reloc_count;
   for (rel = relocs; rel < rel_end; rel++)
     {
@@ -1130,7 +1163,7 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
                else
                  {
                    (*_bfd_error_handler)
-                     (_("%B: %s' accessed both as normal and thread local symbol"),
+                     (_("%B: '%s' accessed both as normal and thread local symbol"),
                       abfd, h ? h->root.root.string : "<local>");
                    return FALSE;
                  }
@@ -1253,10 +1286,7 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
             symbol.  */
          if ((info->shared
               && (sec->flags & SEC_ALLOC) != 0
-              && (((r_type != R_X86_64_PC8)
-                   && (r_type != R_X86_64_PC16)
-                   && (r_type != R_X86_64_PC32)
-                   && (r_type != R_X86_64_PC64))
+              && (! IS_X86_64_PCREL_TYPE (r_type)
                   || (h != NULL
                       && (! SYMBOLIC_BIND (info, h)
                           || h->root.type == bfd_link_hash_defweak
@@ -1276,47 +1306,20 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
                 this reloc.  */
              if (sreloc == NULL)
                {
-                 const char *name;
-                 bfd *dynobj;
-
-                 name = (bfd_elf_string_from_elf_section
-                         (abfd,
-                          elf_elfheader (abfd)->e_shstrndx,
-                          elf_section_data (sec)->rel_hdr.sh_name));
-                 if (name == NULL)
-                   return FALSE;
-
-                 if (! CONST_STRNEQ (name, ".rela")
-                     || strcmp (bfd_get_section_name (abfd, sec),
-                                name + 5) != 0)
-                   {
-                     (*_bfd_error_handler)
-                       (_("%B: bad relocation section name `%s\'"),
-                        abfd, name);
-                   }
-
                  if (htab->elf.dynobj == NULL)
                    htab->elf.dynobj = abfd;
 
-                 dynobj = htab->elf.dynobj;
+                 sreloc = _bfd_elf_make_dynamic_reloc_section
+                   (sec, htab->elf.dynobj, 3, abfd, /*rela?*/ TRUE);
 
-                 sreloc = bfd_get_section_by_name (dynobj, name);
                  if (sreloc == NULL)
-                   {
-                     flagword flags;
-
-                     flags = (SEC_HAS_CONTENTS | SEC_READONLY
-                              | SEC_IN_MEMORY | SEC_LINKER_CREATED);
-                     if ((sec->flags & SEC_ALLOC) != 0)
-                       flags |= SEC_ALLOC | SEC_LOAD;
-                     sreloc = bfd_make_section_with_flags (dynobj,
-                                                           name,
-                                                           flags);
-                     if (sreloc == NULL
-                         || ! bfd_set_section_alignment (dynobj, sreloc, 3))
-                       return FALSE;
-                   }
-                 elf_section_data (sec)->sreloc = sreloc;
+                   return FALSE;
+
+                 /* Create the ifunc section, even if we will not encounter an
+                    indirect function symbol.  We may not even see one in the input
+                    object file, but we can still encounter them in libraries.  */
+                 (void) _bfd_elf_make_ifunc_reloc_section
+                   (abfd, sec, htab->elf.dynobj, 2);
                }
 
              /* If this is a global symbol, we count the number of
@@ -1348,6 +1351,7 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
              if (p == NULL || p->sec != sec)
                {
                  bfd_size_type amt = sizeof *p;
+
                  p = ((struct elf64_x86_64_dyn_relocs *)
                       bfd_alloc (htab->elf.dynobj, amt));
                  if (p == NULL)
@@ -1360,10 +1364,7 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
                }
 
              p->count += 1;
-             if (r_type == R_X86_64_PC8
-                 || r_type == R_X86_64_PC16
-                 || r_type == R_X86_64_PC32
-                 || r_type == R_X86_64_PC64)
+             if (IS_X86_64_PCREL_TYPE (r_type))
                p->pc_count += 1;
            }
          break;
@@ -1378,7 +1379,9 @@ elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
          /* This relocation describes which C++ vtable entries are actually
             used.  Record for later use during GC.  */
        case R_X86_64_GNU_VTENTRY:
-         if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
+         BFD_ASSERT (h != NULL);
+         if (h != NULL
+             && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
            return FALSE;
          break;
 
@@ -1423,9 +1426,12 @@ elf64_x86_64_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info,
   bfd_signed_vma *local_got_refcounts;
   const Elf_Internal_Rela *rel, *relend;
 
+  if (info->relocatable)
+    return TRUE;
+
   elf_section_data (sec)->local_dynrel = NULL;
 
-  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
+  symtab_hdr = &elf_symtab_hdr (abfd);
   sym_hashes = elf_sym_hashes (abfd);
   local_got_refcounts = elf_local_got_refcounts (abfd);
 
@@ -1669,6 +1675,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
   struct elf64_x86_64_link_hash_table *htab;
   struct elf64_x86_64_link_hash_entry *eh;
   struct elf64_x86_64_dyn_relocs *p;
+  bfd_boolean use_indirect_section = FALSE;
 
   if (h->root.type == bfd_link_hash_indirect)
     return TRUE;
@@ -1747,7 +1754,9 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
       && !info->shared
       && h->dynindx == -1
       && elf64_x86_64_hash_entry (h)->tls_type == GOT_TLS_IE)
-    h->got.offset = (bfd_vma) -1;
+    {
+      h->got.offset = (bfd_vma) -1;
+    }
   else if (h->got.refcount > 0)
     {
       asection *s;
@@ -1846,13 +1855,21 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
          /* Make sure undefined weak symbols are output as a dynamic
             symbol in PIEs.  */
          else if (h->dynindx == -1
-                  && !h->forced_local)
-           {
-             if (! bfd_elf_link_record_dynamic_symbol (info, h))
-               return FALSE;
-           }
+                  && ! h->forced_local
+                  && ! bfd_elf_link_record_dynamic_symbol (info, h))
+           return FALSE;
        }
     }
+  else if (is_indirect_symbol (info->output_bfd, h)
+          && h->dynindx == -1
+          && ! h->forced_local)
+    {
+      if (bfd_elf_link_record_dynamic_symbol (info, h)
+         && h->dynindx != -1)
+       use_indirect_section = TRUE;
+      else
+       return FALSE;
+    }
   else if (ELIMINATE_COPY_RELOCS)
     {
       /* For the non-shared case, discard space for relocs against
@@ -1869,11 +1886,9 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
          /* Make sure this symbol is output as a dynamic symbol.
             Undefined weak syms won't yet be marked as dynamic.  */
          if (h->dynindx == -1
-             && !h->forced_local)
-           {
-             if (! bfd_elf_link_record_dynamic_symbol (info, h))
-               return FALSE;
-           }
+             && ! h->forced_local
+             && ! bfd_elf_link_record_dynamic_symbol (info, h))
+           return FALSE;
 
          /* If that succeeded, we know we'll be keeping all the
             relocs.  */
@@ -1889,7 +1904,15 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf)
   /* Finally, allocate space.  */
   for (p = eh->dyn_relocs; p != NULL; p = p->next)
     {
-      asection *sreloc = elf_section_data (p->sec)->sreloc;
+      asection * sreloc;
+
+      if (use_indirect_section)
+       sreloc = elf_section_data (p->sec)->indirect_relocs;
+      else
+       sreloc = elf_section_data (p->sec)->sreloc;
+
+      BFD_ASSERT (sreloc != NULL);
+
       sreloc->size += p->count * sizeof (Elf64_External_Rela);
     }
 
@@ -1967,7 +1990,7 @@ elf64_x86_64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
       Elf_Internal_Shdr *symtab_hdr;
       asection *srel;
 
-      if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour)
+      if (! is_x86_64_elf (ibfd))
        continue;
 
       for (s = ibfd->sections; s != NULL; s = s->next)
@@ -1993,7 +2016,6 @@ elf64_x86_64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
                  srel->size += p->count * sizeof (Elf64_External_Rela);
                  if ((p->sec->output_section->flags & SEC_READONLY) != 0)
                    info->flags |= DF_TEXTREL;
-
                }
            }
        }
@@ -2002,7 +2024,7 @@ elf64_x86_64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
       if (!local_got)
        continue;
 
-      symtab_hdr = &elf_tdata (ibfd)->symtab_hdr;
+      symtab_hdr = &elf_symtab_hdr (ibfd);
       locsymcount = symtab_hdr->sh_info;
       end_local_got = local_got + locsymcount;
       local_tls_type = elf64_x86_64_local_got_tls_type (ibfd);
@@ -2062,7 +2084,7 @@ elf64_x86_64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 
   /* Allocate global sym .plt and .got entries, and space for global
      sym dynamic relocs.  */
-  elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, (PTR) info);
+  elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, info);
 
   /* For every jump slot reserved in the sgotplt, reloc_count is
      incremented.  However, when we reserve space for TLS descriptors,
@@ -2193,8 +2215,7 @@ elf64_x86_64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
          /* If any dynamic relocs apply to a read-only section,
             then we need a DT_TEXTREL entry.  */
          if ((info->flags & DF_TEXTREL) == 0)
-           elf_link_hash_traverse (&htab->elf, readonly_dynrelocs,
-                                   (PTR) info);
+           elf_link_hash_traverse (&htab->elf, readonly_dynrelocs, info);
 
          if ((info->flags & DF_TEXTREL) != 0)
            {
@@ -2233,6 +2254,9 @@ elf64_x86_64_always_size_sections (bfd *output_bfd,
                 tls_sec, 0, NULL, FALSE,
                 bed->collect, &bh)))
            return FALSE;
+
+         elf64_x86_64_hash_table (info)->tls_module_base = bh;
+
          tlsbase = (struct elf_link_hash_entry *)bh;
          tlsbase->def_regular = 1;
          tlsbase->other = STV_HIDDEN;
@@ -2243,6 +2267,27 @@ elf64_x86_64_always_size_sections (bfd *output_bfd,
   return TRUE;
 }
 
+/* _TLS_MODULE_BASE_ needs to be treated especially when linking
+   executables.  Rather than setting it to the beginning of the TLS
+   section, we have to set it to the end.  This function may be called
+   multiple times, it is idempotent.  */
+
+static void
+set_tls_module_base (struct bfd_link_info *info)
+{
+  struct bfd_link_hash_entry *base;
+
+  if (!info->executable)
+    return;
+
+  base = elf64_x86_64_hash_table (info)->tls_module_base;
+
+  if (!base)
+    return;
+
+  base->u.def.value = elf_hash_table (info)->tls_size;
+}
+
 /* Return the base VMA address which should be subtracted from real addresses
    when resolving @dtpoff relocation.
    This is PT_TLS segment p_vaddr.  */
@@ -2305,12 +2350,16 @@ elf64_x86_64_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
   Elf_Internal_Rela *rel;
   Elf_Internal_Rela *relend;
 
+  BFD_ASSERT (is_x86_64_elf (input_bfd));
+
   htab = elf64_x86_64_hash_table (info);
-  symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
+  symtab_hdr = &elf_symtab_hdr (input_bfd);
   sym_hashes = elf_sym_hashes (input_bfd);
   local_got_offsets = elf_local_got_offsets (input_bfd);
   local_tlsdesc_gotents = elf64_x86_64_local_tlsdesc_gotent (input_bfd);
 
+  set_tls_module_base (info);
+
   rel = relocs;
   relend = relocs + input_section->reloc_count;
   for (; rel < relend; rel++)
@@ -2587,30 +2636,63 @@ elf64_x86_64_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
        case R_X86_64_PC16:
        case R_X86_64_PC32:
          if (info->shared
-             && !SYMBOL_REFERENCES_LOCAL (info, h)
              && (input_section->flags & SEC_ALLOC) != 0
              && (input_section->flags & SEC_READONLY) != 0
-             && (!h->def_regular
-                 || r_type != R_X86_64_PC32
-                 || h->type != STT_FUNC
-                 || ELF_ST_VISIBILITY (h->other) != STV_PROTECTED
-                 || !is_32bit_relative_branch (contents,
-                                               rel->r_offset)))
+             && h != NULL)
            {
-             if (h->def_regular
-                 && r_type == R_X86_64_PC32
-                 && h->type == STT_FUNC
-                 && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED)
-               (*_bfd_error_handler)
-                  (_("%B: relocation R_X86_64_PC32 against protected function `%s' can not be used when making a shared object"),
-                   input_bfd, h->root.root.string);
+             bfd_boolean fail = FALSE;
+             bfd_boolean branch
+               = (r_type == R_X86_64_PC32
+                  && is_32bit_relative_branch (contents, rel->r_offset));
+
+             if (SYMBOL_REFERENCES_LOCAL (info, h))
+               {
+                 /* Symbol is referenced locally.  Make sure it is
+                    defined locally or for a branch.  */
+                 fail = !h->def_regular && !branch;
+               }
              else
-               (*_bfd_error_handler)
-                 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
-                  input_bfd, x86_64_elf_howto_table[r_type].name,
-                  h->root.root.string);
-             bfd_set_error (bfd_error_bad_value);
-             return FALSE;
+               {
+                 /* Symbol isn't referenced locally.  We only allow
+                    branch to symbol with non-default visibility. */
+                 fail = (!branch
+                         || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT);
+               }
+
+             if (fail)
+               {
+                 const char *fmt;
+                 const char *v;
+                 const char *pic = "";
+
+                 switch (ELF_ST_VISIBILITY (h->other))
+                   {
+                   case STV_HIDDEN:
+                     v = _("hidden symbol");
+                     break;
+                   case STV_INTERNAL:
+                     v = _("internal symbol");
+                     break;
+                   case STV_PROTECTED:
+                     v = _("protected symbol");
+                     break;
+                   default:
+                     v = _("symbol");
+                     pic = _("; recompile with -fPIC");
+                     break;
+                   }
+
+                 if (h->def_regular)
+                   fmt = _("%B: relocation %s against %s `%s' can not be used when making a shared object%s");
+                 else
+                   fmt = _("%B: relocation %s against undefined %s `%s' can not be used when making a shared object%s");
+
+                 (*_bfd_error_handler) (fmt, input_bfd,
+                                        x86_64_elf_howto_table[r_type].name,
+                                        v,  h->root.root.string, pic);
+                 bfd_set_error (bfd_error_bad_value);
+                 return FALSE;
+               }
            }
          /* Fall through.  */
 
@@ -2629,11 +2711,14 @@ elf64_x86_64_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
               && (h == NULL
                   || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
                   || h->root.type != bfd_link_hash_undefweak)
-              && ((r_type != R_X86_64_PC8
-                   && r_type != R_X86_64_PC16
-                   && r_type != R_X86_64_PC32
-                   && r_type != R_X86_64_PC64)
-                  || !SYMBOL_CALLS_LOCAL (info, h)))
+              && (! IS_X86_64_PCREL_TYPE (r_type)
+                  || ! SYMBOL_CALLS_LOCAL (info, h)))
+             || (! info->shared
+                 && h != NULL
+                 && h->dynindx != -1
+                 && ! h->forced_local
+                 && ((struct elf64_x86_64_link_hash_entry *) h)->dyn_relocs != NULL
+                 && is_indirect_symbol (output_bfd, h))
              || (ELIMINATE_COPY_RELOCS
                  && !info->shared
                  && h != NULL
@@ -2673,13 +2758,10 @@ elf64_x86_64_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
                 become local.  */
              else if (h != NULL
                       && h->dynindx != -1
-                      && (r_type == R_X86_64_PC8
-                          || r_type == R_X86_64_PC16
-                          || r_type == R_X86_64_PC32
-                          || r_type == R_X86_64_PC64
-                          || !info->shared
-                          || !SYMBOLIC_BIND (info, h)
-                          || !h->def_regular))
+                      && (IS_X86_64_PCREL_TYPE (r_type)
+                          || ! info->shared
+                          || ! SYMBOLIC_BIND (info, h)
+                          || ! h->def_regular))
                {
                  outrel.r_info = ELF64_R_INFO (h->dynindx, r_type);
                  outrel.r_addend = rel->r_addend;
@@ -2728,9 +2810,18 @@ elf64_x86_64_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
                    }
                }
 
-             sreloc = elf_section_data (input_section)->sreloc;
-             if (sreloc == NULL)
-               abort ();
+             if (! info->shared
+                 && h != NULL
+                 && h->dynindx != -1
+                 && ! h->forced_local
+                 && is_indirect_symbol (output_bfd, h)
+                 && elf_section_data (input_section)->indirect_relocs != NULL
+                 && elf_section_data (input_section)->indirect_relocs->contents != NULL)
+               sreloc = elf_section_data (input_section)->indirect_relocs;
+             else
+               sreloc = elf_section_data (input_section)->sreloc;
+
+             BFD_ASSERT (sreloc != NULL && sreloc->contents != NULL);
 
              loc = sreloc->contents;
              loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela);
@@ -3335,6 +3426,8 @@ elf64_x86_64_finish_dynamic_symbol (bfd *output_bfd,
       if (info->shared
          && SYMBOL_REFERENCES_LOCAL (info, h))
        {
+         if (!h->def_regular)
+           return FALSE;
          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
@@ -3613,11 +3706,12 @@ elf64_x86_64_section_from_shdr (bfd *abfd,
 
 static bfd_boolean
 elf64_x86_64_add_symbol_hook (bfd *abfd,
-                             struct bfd_link_info *info ATTRIBUTE_UNUSED,
+                             struct bfd_link_info *info,
                              Elf_Internal_Sym *sym,
                              const char **namep ATTRIBUTE_UNUSED,
                              flagword *flagsp ATTRIBUTE_UNUSED,
-                             asection **secp, bfd_vma *valp)
+                             asection **secp,
+                             bfd_vma *valp)
 {
   asection *lcomm;
 
@@ -3640,6 +3734,10 @@ elf64_x86_64_add_symbol_hook (bfd *abfd,
       *valp = sym->st_size;
       break;
     }
+
+  if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
+    elf_tdata (info->output_bfd)->has_ifunc_symbols = TRUE;
+
   return TRUE;
 }
 
@@ -3824,6 +3922,7 @@ static const struct bfd_elf_special_section
   elf64_x86_64_reloc_name_lookup
 
 #define elf_backend_adjust_dynamic_symbol   elf64_x86_64_adjust_dynamic_symbol
+#define elf_backend_relocs_compatible      _bfd_elf_relocs_compatible
 #define elf_backend_check_relocs           elf64_x86_64_check_relocs
 #define elf_backend_copy_indirect_symbol    elf64_x86_64_copy_indirect_symbol
 #define elf_backend_create_dynamic_sections elf64_x86_64_create_dynamic_sections
@@ -3866,6 +3965,9 @@ static const struct bfd_elf_special_section
 #define elf_backend_hash_symbol \
   elf64_x86_64_hash_symbol
 
+#undef  elf_backend_post_process_headers
+#define elf_backend_post_process_headers  _bfd_elf_set_osabi
+
 #include "elf64-target.h"
 
 /* FreeBSD support.  */
@@ -3878,9 +3980,6 @@ static const struct bfd_elf_special_section
 #undef ELF_OSABI
 #define        ELF_OSABI                           ELFOSABI_FREEBSD
 
-#undef  elf_backend_post_process_headers
-#define elf_backend_post_process_headers  _bfd_elf_set_osabi
-
 #undef  elf64_bed
 #define elf64_bed elf64_x86_64_fbsd_bed
 
This page took 0.032292 seconds and 4 git commands to generate.