2004-01-12 Michael Chastain <mec.gnu@mindspring.com>
[deliverable/binutils-gdb.git] / bfd / elflink.h
index c0b2468b7d895139acb8906b76d0d96ad94726b6..c37d7398d0113af7c59984a651e4219b7e04532d 100644 (file)
@@ -20,6 +20,8 @@
 
 /* ELF linker code.  */
 
+#include "safe-ctype.h"
+
 static bfd_boolean elf_link_add_object_symbols (bfd *, struct bfd_link_info *);
 static bfd_boolean elf_link_add_archive_symbols (bfd *,
                                                 struct bfd_link_info *);
@@ -415,7 +417,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
   Elf_Internal_Sym *isymbuf = NULL;
   Elf_Internal_Sym *isym;
   Elf_Internal_Sym *isymend;
-  struct elf_backend_data *bed;
+  const struct elf_backend_data *bed;
   bfd_boolean dt_needed;
   struct elf_link_hash_table * hash_table;
   bfd_size_type amt;
@@ -435,7 +437,9 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
       /* You can't use -r against a dynamic object.  Also, there's no
         hope of using a dynamic object which does not exactly match
         the format of the output file.  */
-      if (info->relocatable || info->hash->creator != abfd->xvec)
+      if (info->relocatable
+         || !is_elf_hash_table (hash_table)
+         || hash_table->root.creator != abfd->xvec)
        {
          bfd_set_error (bfd_error_invalid_operation);
          goto error_return;
@@ -473,7 +477,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
                 fix is to keep track of what warnings we are supposed
                 to emit, and then handle them all at the end of the
                 link.  */
-             if (dynamic && abfd->xvec == info->hash->creator)
+             if (dynamic)
                {
                  struct elf_link_hash_entry *h;
 
@@ -529,15 +533,15 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
         format.  FIXME: If there are no input BFD's of the same
         format as the output, we can't make a shared library.  */
       if (info->shared
-         && is_elf_hash_table (info)
-         && ! hash_table->dynamic_sections_created
-         && abfd->xvec == info->hash->creator)
+         && is_elf_hash_table (hash_table)
+         && hash_table->root.creator == abfd->xvec
+         && ! hash_table->dynamic_sections_created)
        {
          if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
            goto error_return;
        }
     }
-  else if (! is_elf_hash_table (info))
+  else if (!is_elf_hash_table (hash_table))
     goto error_return;
   else
     {
@@ -721,9 +725,8 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
 
       /* If this is the first dynamic object found in the link, create
         the special sections required for dynamic linking.  */
-      if (! hash_table->dynamic_sections_created)
-       if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
-         goto error_return;
+      if (! _bfd_elf_link_create_dynamic_sections (abfd, info))
+       goto error_return;
 
       if (add_needed)
        {
@@ -873,7 +876,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
        {
          /* This should be impossible, since ELF requires that all
             global symbols follow all local symbols, and that sh_info
-            point to the first global symbol.  Unfortunatealy, Irix 5
+            point to the first global symbol.  Unfortunately, Irix 5
             screws this up.  */
          continue;
        }
@@ -966,7 +969,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
       old_alignment = 0;
       old_bfd = NULL;
 
-      if (info->hash->creator->flavour == bfd_target_elf_flavour)
+      if (is_elf_hash_table (hash_table))
        {
          Elf_Internal_Versym iver;
          unsigned int vernum = 0;
@@ -1129,7 +1132,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
          && definition
          && (flags & BSF_WEAK) != 0
          && ELF_ST_TYPE (isym->st_info) != STT_FUNC
-         && info->hash->creator->flavour == bfd_target_elf_flavour
+         && is_elf_hash_table (hash_table)
          && h->weakdef == NULL)
        {
          /* Keep a list of all weak defined non function symbols from
@@ -1165,14 +1168,14 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
            h->root.u.c.p->alignment_power = old_alignment;
        }
 
-      if (info->hash->creator->flavour == bfd_target_elf_flavour)
+      if (is_elf_hash_table (hash_table))
        {
          int old_flags;
          bfd_boolean dynsym;
          int new_flag;
 
          /* Check the alignment when a common symbol is involved. This
-            can change when a common symbol is overriden by a normal
+            can change when a common symbol is overridden by a normal
             definition or a common symbol is ignored due to the old
             normal definition. We need to make sure the maximum
             alignment is maintained.  */
@@ -1186,7 +1189,8 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
              bfd *common_bfd;
 
              symbol_align = ffs (h->root.u.def.value) - 1;
-             if ((h->root.u.def.section->owner->flags & DYNAMIC) == 0)
+             if (h->root.u.def.section->owner != NULL
+                 && (h->root.u.def.section->owner->flags & DYNAMIC) == 0)
                {
                  normal_align = h->root.u.def.section->alignment_power;
                  if (normal_align > symbol_align)
@@ -1258,6 +1262,10 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
          /* If st_other has a processor-specific meaning, specific
             code might be needed here. We never merge the visibility
             attribute with the one from a dynamic object.  */
+         if (bed->elf_backend_merge_symbol_attribute)
+           (*bed->elf_backend_merge_symbol_attribute) (h, isym, definition,
+                                                       dynamic);
+
          if (isym->st_other != 0 && !dynamic)
            {
              unsigned char hvis, symvis, other, nvis;
@@ -1373,9 +1381,6 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
              bfd_size_type oldsize;
              bfd_size_type strindex;
 
-             if (! is_elf_hash_table (info))
-               goto error_free_vers;
-
              /* The symbol from a DT_NEEDED object is referenced from
                 the regular object to create a dynamic executable. We
                 have to make sure there is a DT_NEEDED entry for it.  */
@@ -1439,7 +1444,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
          shortname[amt] = '\0';
 
          hi = (struct elf_link_hash_entry *)
-              bfd_link_hash_lookup (info->hash, shortname,
+              bfd_link_hash_lookup (&hash_table->root, shortname,
                                     FALSE, FALSE, FALSE);
          if (hi != NULL
              && hi->root.type == h->root.type
@@ -1566,7 +1571,8 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
      different format.  It probably can't be done.  */
   check_relocs = get_elf_backend_data (abfd)->check_relocs;
   if (! dynamic
-      && abfd->xvec == info->hash->creator
+      && is_elf_hash_table (hash_table)
+      && hash_table->root.creator == abfd->xvec
       && check_relocs != NULL)
     {
       asection *o;
@@ -1602,37 +1608,42 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
      of the .stab/.stabstr sections.  */
   if (! dynamic
       && ! info->traditional_format
-      && info->hash->creator->flavour == bfd_target_elf_flavour
-      && is_elf_hash_table (info)
+      && is_elf_hash_table (hash_table)
       && (info->strip != strip_all && info->strip != strip_debugger))
     {
-      asection *stab, *stabstr;
-
-      stab = bfd_get_section_by_name (abfd, ".stab");
-      if (stab != NULL
-         && (stab->flags & SEC_MERGE) == 0
-         && !bfd_is_abs_section (stab->output_section))
+      asection *stabstr;
+      
+      stabstr = bfd_get_section_by_name (abfd, ".stabstr");
+      if (stabstr != NULL)
        {
-         stabstr = bfd_get_section_by_name (abfd, ".stabstr");
-
-         if (stabstr != NULL)
-           {
-             struct bfd_elf_section_data *secdata;
-
-             secdata = elf_section_data (stab);
-             if (! _bfd_link_section_stabs (abfd,
-                                            & hash_table->stab_info,
-                                            stab, stabstr,
-                                            &secdata->sec_info))
-               goto error_return;
-             if (secdata->sec_info)
-               stab->sec_info_type = ELF_INFO_TYPE_STABS;
+         bfd_size_type string_offset = 0;
+         asection *stab;
+
+         for (stab = abfd->sections; stab; stab = stab->next)
+           if (strncmp (".stab", stab->name, 5) == 0
+               && (!stab->name[5] ||
+                   (stab->name[5] == '.' && ISDIGIT (stab->name[6])))
+               && (stab->flags & SEC_MERGE) == 0
+               && !bfd_is_abs_section (stab->output_section))
+             {
+               struct bfd_elf_section_data *secdata;
+               
+               secdata = elf_section_data (stab);
+               if (! _bfd_link_section_stabs (abfd,
+                                              & hash_table->stab_info,
+                                              stab, stabstr,
+                                              &secdata->sec_info,
+                                              &string_offset))
+                 goto error_return;
+               if (secdata->sec_info)
+                 stab->sec_info_type = ELF_INFO_TYPE_STABS;
            }
        }
     }
 
-  if (! info->relocatable && ! dynamic
-      && is_elf_hash_table (info))
+  if (! info->relocatable
+      && ! dynamic
+      && is_elf_hash_table (hash_table))
     {
       asection *s;
 
@@ -1652,7 +1663,7 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
          }
     }
 
-  if (is_elf_hash_table (info))
+  if (is_elf_hash_table (hash_table))
     {
       /* Add this bfd to the loaded list.  */
       struct elf_link_loaded_list *n;
@@ -1690,7 +1701,7 @@ elf_add_dynamic_entry (struct bfd_link_info *info, bfd_vma tag, bfd_vma val)
   bfd_size_type newsize;
   bfd_byte *newcontents;
 
-  if (! is_elf_hash_table (info))
+  if (! is_elf_hash_table (info->hash))
     return FALSE;
 
   dynobj = elf_hash_table (info)->dynobj;
@@ -1820,7 +1831,7 @@ compute_bucket_count (struct bfd_link_info *info)
 
 # if 1
          /* Variant 1: optimize for short chains.  We add the squares
-            of all the chain lengths (which favous many small chain
+            of all the chain lengths (which favors many small chain
             over a few long chains).  */
          for (j = 0; j < i; ++j)
            max += counts[j] * counts[j];
@@ -1888,17 +1899,14 @@ NAME(bfd_elf,size_dynamic_sections) (bfd *output_bfd,
 {
   bfd_size_type soname_indx;
   bfd *dynobj;
-  struct elf_backend_data *bed;
+  const struct elf_backend_data *bed;
   struct elf_assign_sym_version_info asvinfo;
 
   *sinterpptr = NULL;
 
   soname_indx = (bfd_size_type) -1;
 
-  if (info->hash->creator->flavour != bfd_target_elf_flavour)
-    return TRUE;
-
-  if (! is_elf_hash_table (info))
+  if (!is_elf_hash_table (info->hash))
     return TRUE;
 
   if (info->execstack)
@@ -1969,7 +1977,7 @@ NAME(bfd_elf,size_dynamic_sections) (bfd *output_bfd,
       bfd_boolean all_defined;
 
       *sinterpptr = bfd_get_section_by_name (dynobj, ".interp");
-      BFD_ASSERT (*sinterpptr != NULL || info->shared);
+      BFD_ASSERT (*sinterpptr != NULL || !info->executable);
 
       if (soname != NULL)
        {
@@ -2044,17 +2052,17 @@ NAME(bfd_elf,size_dynamic_sections) (bfd *output_bfd,
            return FALSE;
        }
 
-      /* Make all global versions with definiton.  */
+      /* Make all global versions with definition.  */
       for (t = verdefs; t != NULL; t = t->next)
-       for (d = t->globals; d != NULL; d = d->next)
-         if (!d->symver && strchr (d->pattern, '*') == NULL)
+       for (d = t->globals.list; d != NULL; d = d->next)
+         if (!d->symver && d->symbol)
            {
              const char *verstr, *name;
              size_t namelen, verlen, newlen;
              char *newname, *p;
              struct elf_link_hash_entry *newh;
 
-             name = d->pattern;
+             name = d->symbol;
              namelen = strlen (name);
              verstr = t->name;
              verlen = strlen (verstr);
@@ -2109,12 +2117,11 @@ NAME(bfd_elf,size_dynamic_sections) (bfd *output_bfd,
 
       if (!info->allow_undefined_version)
        {
-         /* Check if all global versions have a definiton.  */
+         /* Check if all global versions have a definition.  */
          all_defined = TRUE;
          for (t = verdefs; t != NULL; t = t->next)
-           for (d = t->globals; d != NULL; d = d->next)
-             if (!d->symver && !d->script
-                 && strchr (d->pattern, '*') == NULL)
+           for (d = t->globals.list; d != NULL; d = d->next)
+             if (!d->symver && !d->script)
                {
                  (*_bfd_error_handler)
                    (_("%s: undefined version: %s"),
@@ -2361,7 +2368,7 @@ NAME(bfd_elf,size_dynamic_sections) (bfd *output_bfd,
 
              def.vd_version = VER_DEF_CURRENT;
              def.vd_flags = 0;
-             if (t->globals == NULL && t->locals == NULL && ! t->used)
+             if (t->globals.list == NULL && t->locals.list == NULL && ! t->used)
                def.vd_flags |= VER_FLG_WEAK;
              def.vd_ndx = t->vernum + 1;
              def.vd_cnt = cdeps + 1;
@@ -2793,8 +2800,6 @@ struct elf_final_link_info
   asection *hash_sec;
   /* symbol version section (.gnu.version).  */
   asection *symver_sec;
-  /* first SHF_TLS section (if any).  */
-  asection *first_tls_sec;
   /* Buffer large enough to hold contents of any section.  */
   bfd_byte *contents;
   /* Buffer large enough to hold external relocs of any section.  */
@@ -2828,7 +2833,8 @@ struct elf_final_link_info
 };
 
 static bfd_boolean elf_link_output_sym
-  (struct elf_final_link_info *, const char *, Elf_Internal_Sym *, asection *);
+  (struct elf_final_link_info *, const char *, Elf_Internal_Sym *, asection *,
+   struct elf_link_hash_entry *);
 static bfd_boolean elf_link_flush_output_syms
   (struct elf_final_link_info *);
 static bfd_boolean elf_link_output_extsym
@@ -2859,7 +2865,7 @@ elf_link_adjust_relocs (bfd *abfd,
                        struct elf_link_hash_entry **rel_hash)
 {
   unsigned int i;
-  struct elf_backend_data *bed = get_elf_backend_data (abfd);
+  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
   bfd_byte *erela;
   void (*swap_in) (bfd *, const bfd_byte *, Elf_Internal_Rela *);
   void (*swap_out) (bfd *, const Elf_Internal_Rela *, bfd_byte *);
@@ -2964,7 +2970,7 @@ elf_link_sort_relocs (bfd *abfd, struct bfd_link_info *info, asection **psec)
   size_t i, ret, sort_elt, ext_size;
   bfd_byte *sort, *s_non_relative, *p;
   struct elf_link_sort_rela *sq;
-  struct elf_backend_data *bed = get_elf_backend_data (abfd);
+  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
   int i2e = bed->s->int_rels_per_ext_rel;
   void (*swap_in) (bfd *, const bfd_byte *, Elf_Internal_Rela *);
   void (*swap_out) (bfd *, const Elf_Internal_Rela *, bfd_byte *);
@@ -3096,14 +3102,14 @@ elf_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
   Elf_Internal_Shdr *symtab_hdr;
   Elf_Internal_Shdr *symtab_shndx_hdr;
   Elf_Internal_Shdr *symstrtab_hdr;
-  struct elf_backend_data *bed = get_elf_backend_data (abfd);
+  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
   struct elf_outext_info eoinfo;
   bfd_boolean merged;
   size_t relativecount = 0;
   asection *reldyn = 0;
   bfd_size_type amt;
 
-  if (! is_elf_hash_table (info))
+  if (! is_elf_hash_table (info->hash))
     return FALSE;
 
   if (info->shared)
@@ -3149,14 +3155,6 @@ elf_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
   finfo.symshndxbuf = NULL;
   finfo.symbuf_count = 0;
   finfo.shndxbuf_size = 0;
-  finfo.first_tls_sec = NULL;
-  for (o = abfd->sections; o != NULL; o = o->next)
-    if ((o->flags & SEC_THREAD_LOCAL) != 0
-       && (o->flags & SEC_LOAD) != 0)
-      {
-       finfo.first_tls_sec = o;
-       break;
-      }
 
   /* Count up the number of relocations we will output for each output
      section, so that we know the sizes of the reloc sections.  We
@@ -3410,7 +3408,8 @@ elf_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
       elfsym.st_info = 0;
       elfsym.st_other = 0;
       elfsym.st_shndx = SHN_UNDEF;
-      if (! elf_link_output_sym (&finfo, NULL, &elfsym, bfd_und_section_ptr))
+      if (! elf_link_output_sym (&finfo, NULL, &elfsym, bfd_und_section_ptr,
+                                NULL))
        goto error_return;
     }
 
@@ -3426,7 +3425,7 @@ elf_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
   elfsym.st_other = 0;
   elfsym.st_shndx = SHN_ABS;
   if (! elf_link_output_sym (&finfo, bfd_get_filename (abfd),
-                            &elfsym, bfd_abs_section_ptr))
+                            &elfsym, bfd_abs_section_ptr, NULL))
     goto error_return;
 #endif
 
@@ -3451,7 +3450,7 @@ elf_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
            elfsym.st_value = 0;
          else
            elfsym.st_value = o->vma;
-         if (! elf_link_output_sym (&finfo, NULL, &elfsym, o))
+         if (! elf_link_output_sym (&finfo, NULL, &elfsym, o, NULL))
            goto error_return;
          if (i == SHN_LORESERVE - 1)
            i += SHN_HIRESERVE + 1 - SHN_LORESERVE;
@@ -3514,38 +3513,30 @@ elf_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
        goto error_return;
     }
 
-  if (finfo.first_tls_sec)
+  if (elf_hash_table (info)->tls_sec)
     {
-      unsigned int align = 0;
-      bfd_vma base = finfo.first_tls_sec->vma, end = 0;
+      bfd_vma base, end = 0;
       asection *sec;
 
-      for (sec = finfo.first_tls_sec;
+      for (sec = elf_hash_table (info)->tls_sec;
           sec && (sec->flags & SEC_THREAD_LOCAL);
           sec = sec->next)
        {
          bfd_vma size = sec->_raw_size;
 
-         if (bfd_get_section_alignment (abfd, sec) > align)
-           align = bfd_get_section_alignment (abfd, sec);
-         if (sec->_raw_size == 0 && (sec->flags & SEC_HAS_CONTENTS) == 0)
+         if (size == 0 && (sec->flags & SEC_HAS_CONTENTS) == 0)
            {
              struct bfd_link_order *o;
 
-             size = 0;
              for (o = sec->link_order_head; o != NULL; o = o->next)
                if (size < o->offset + o->size)
                  size = o->offset + o->size;
            }
          end = sec->vma + size;
        }
-      elf_hash_table (info)->tls_segment
-       = bfd_zalloc (abfd, sizeof (struct elf_link_tls_segment));
-      if (elf_hash_table (info)->tls_segment == NULL)
-       goto error_return;
-      elf_hash_table (info)->tls_segment->start = base;
-      elf_hash_table (info)->tls_segment->size = end - base;
-      elf_hash_table (info)->tls_segment->align = align;
+      base = elf_hash_table (info)->tls_sec->vma;
+      end = align_power (end, elf_hash_table (info)->tls_sec->alignment_power);
+      elf_hash_table (info)->tls_size = end - base;
     }
 
   /* Since ELF permits relocations to be against local symbols, we
@@ -3713,7 +3704,8 @@ elf_bfd_final_link (bfd *abfd, struct bfd_link_info *info)
   if (bed->elf_backend_output_arch_syms)
     {
       typedef bfd_boolean (*out_sym_func)
-       (void *, const char *, Elf_Internal_Sym *, asection *);
+       (void *, const char *, Elf_Internal_Sym *, asection *,
+        struct elf_link_hash_entry *);
 
       if (! ((*bed->elf_backend_output_arch_syms)
             (abfd, info, &finfo, (out_sym_func) elf_link_output_sym)))
@@ -4097,20 +4089,20 @@ static bfd_boolean
 elf_link_output_sym (struct elf_final_link_info *finfo,
                     const char *name,
                     Elf_Internal_Sym *elfsym,
-                    asection *input_sec)
+                    asection *input_sec,
+                    struct elf_link_hash_entry *h)
 {
   Elf_External_Sym *dest;
   Elf_External_Sym_Shndx *destshndx;
   bfd_boolean (*output_symbol_hook)
-    (bfd *, struct bfd_link_info *info, const char *,
-     Elf_Internal_Sym *, asection *);
+    (struct bfd_link_info *, const char *, Elf_Internal_Sym *, asection *,
+     struct elf_link_hash_entry *);
 
   output_symbol_hook = get_elf_backend_data (finfo->output_bfd)->
     elf_backend_link_output_symbol_hook;
   if (output_symbol_hook != NULL)
     {
-      if (! ((*output_symbol_hook)
-            (finfo->output_bfd, finfo->info, name, elfsym, input_sec)))
+      if (! (*output_symbol_hook) (finfo->info, name, elfsym, input_sec, h))
        return FALSE;
     }
 
@@ -4195,7 +4187,7 @@ elf_link_check_versioned_symbol (struct bfd_link_info *info,
   bfd *abfd;
   struct elf_link_loaded_list *loaded;
 
-  if (info->hash->creator->flavour != bfd_target_elf_flavour)
+  if (!is_elf_hash_table (info->hash))
     return FALSE;
 
   switch (h->root.type)
@@ -4363,24 +4355,19 @@ elf_link_output_extsym (struct elf_link_hash_entry *h, void *data)
        return TRUE;
     }
 
-  /* If we are not creating a shared library, and this symbol is
-     referenced by a shared library but is not defined anywhere, then
-     warn that it is undefined.  If we do not do this, the runtime
-     linker will complain that the symbol is undefined when the
-     program is run.  We don't have to worry about symbols that are
-     referenced by regular files, because we will already have issued
-     warnings for them.  */
-  if (! finfo->info->relocatable
-      && (finfo->info->executable
-         || ! finfo->info->allow_shlib_undefined)
-      && h->root.type == bfd_link_hash_undefined
+  /* If we have an undefined symbol reference here then it must have
+     come from a shared library that is being linked in.  (Undefined
+     references in regular files have already been handled).  If we
+     are reporting errors for this situation then do so now.  */
+  if (h->root.type == bfd_link_hash_undefined
       && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0
       && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0
-      && ! elf_link_check_versioned_symbol (finfo->info, h))
+      && ! elf_link_check_versioned_symbol (finfo->info, h)
+      && finfo->info->unresolved_syms_in_shared_libs != RM_IGNORE)
     {
       if (! ((*finfo->info->callbacks->undefined_symbol)
             (finfo->info, h->root.root.string, h->root.u.undef.abfd,
-             NULL, 0, TRUE)))
+             NULL, 0, finfo->info->unresolved_syms_in_shared_libs == RM_GENERATE_ERROR)))
        {
          eoinfo->failed = TRUE;
          return FALSE;
@@ -4390,10 +4377,9 @@ elf_link_output_extsym (struct elf_link_hash_entry *h, void *data)
   /* We should also warn if a forced local symbol is referenced from
      shared libraries.  */
   if (! finfo->info->relocatable
-      && (! finfo->info->shared || ! finfo->info->allow_shlib_undefined)
+      && (! finfo->info->shared)
       && (h->elf_link_hash_flags
-         & (ELF_LINK_FORCED_LOCAL | ELF_LINK_HASH_REF_DYNAMIC
-            | ELF_LINK_DYNAMIC_DEF | ELF_LINK_DYNAMIC_WEAK))
+         & (ELF_LINK_FORCED_LOCAL | ELF_LINK_HASH_REF_DYNAMIC | ELF_LINK_DYNAMIC_DEF | ELF_LINK_DYNAMIC_WEAK))
         == (ELF_LINK_FORCED_LOCAL | ELF_LINK_HASH_REF_DYNAMIC)
       && ! elf_link_check_versioned_symbol (finfo->info, h))
     {
@@ -4498,8 +4484,8 @@ elf_link_output_extsym (struct elf_link_hash_entry *h, void *data)
                  {
                    /* STT_TLS symbols are relative to PT_TLS segment
                       base.  */
-                   BFD_ASSERT (finfo->first_tls_sec != NULL);
-                   sym.st_value -= finfo->first_tls_sec->vma;
+                   BFD_ASSERT (elf_hash_table (finfo->info)->tls_sec != NULL);
+                   sym.st_value -= elf_hash_table (finfo->info)->tls_sec->vma;
                  }
              }
          }
@@ -4541,7 +4527,7 @@ elf_link_output_extsym (struct elf_link_hash_entry *h, void *data)
          || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
       && elf_hash_table (finfo->info)->dynamic_sections_created)
     {
-      struct elf_backend_data *bed;
+      const struct elf_backend_data *bed;
 
       bed = get_elf_backend_data (finfo->output_bfd);
       if (! ((*bed->elf_backend_finish_dynamic_symbol)
@@ -4657,7 +4643,7 @@ elf_link_output_extsym (struct elf_link_hash_entry *h, void *data)
 
   h->indx = bfd_get_symcount (finfo->output_bfd);
 
-  if (! elf_link_output_sym (finfo, h->root.root.string, &sym, input_sec))
+  if (! elf_link_output_sym (finfo, h->root.root.string, &sym, input_sec, h))
     {
       eoinfo->failed = TRUE;
       return FALSE;
@@ -4687,7 +4673,7 @@ elf_link_input_bfd (struct elf_final_link_info *finfo, bfd *input_bfd)
   long *pindex;
   asection **ppsection;
   asection *o;
-  struct elf_backend_data *bed;
+  const struct elf_backend_data *bed;
   bfd_boolean emit_relocs;
   struct elf_link_hash_entry **sym_hashes;
 
@@ -4857,12 +4843,12 @@ elf_link_input_bfd (struct elf_final_link_info *finfo, bfd *input_bfd)
          if (ELF_ST_TYPE (osym.st_info) == STT_TLS)
            {
              /* STT_TLS symbols are relative to PT_TLS segment base.  */
-             BFD_ASSERT (finfo->first_tls_sec != NULL);
-             osym.st_value -= finfo->first_tls_sec->vma;
+             BFD_ASSERT (elf_hash_table (finfo->info)->tls_sec != NULL);
+             osym.st_value -= elf_hash_table (finfo->info)->tls_sec->vma;
            }
        }
 
-      if (! elf_link_output_sym (finfo, name, &osym, isec))
+      if (! elf_link_output_sym (finfo, name, &osym, isec, NULL))
        return FALSE;
     }
 
@@ -5214,15 +5200,18 @@ elf_link_input_bfd (struct elf_final_link_info *finfo, bfd *input_bfd)
                                {
                                  /* STT_TLS symbols are relative to PT_TLS
                                     segment base.  */
-                                 BFD_ASSERT (finfo->first_tls_sec != NULL);
-                                 sym.st_value -= finfo->first_tls_sec->vma;
+                                 BFD_ASSERT (elf_hash_table (finfo->info)
+                                             ->tls_sec != NULL);
+                                 sym.st_value -= (elf_hash_table (finfo->info)
+                                                  ->tls_sec->vma);
                                }
                            }
 
                          finfo->indices[r_symndx]
                            = bfd_get_symcount (output_bfd);
 
-                         if (! elf_link_output_sym (finfo, name, &sym, sec))
+                         if (! elf_link_output_sym (finfo, name, &sym, sec,
+                                                    NULL))
                            return FALSE;
                        }
 
@@ -5321,7 +5310,7 @@ elf_reloc_link_order (bfd *output_bfd,
   bfd_vma addend;
   struct elf_link_hash_entry **rel_hash_ptr;
   Elf_Internal_Shdr *rel_hdr;
-  struct elf_backend_data *bed = get_elf_backend_data (output_bfd);
+  const struct elf_backend_data *bed = get_elf_backend_data (output_bfd);
   Elf_Internal_Rela irel[MAX_INT_RELS_PER_EXT_REL];
   bfd_byte *erel;
   unsigned int i;
@@ -5509,7 +5498,7 @@ elf_gc_mark (struct bfd_link_info *info,
       size_t nlocsyms;
       size_t extsymoff;
       bfd *input_bfd = sec->owner;
-      struct elf_backend_data *bed = get_elf_backend_data (input_bfd);
+      const struct elf_backend_data *bed = get_elf_backend_data (input_bfd);
       Elf_Internal_Sym *isym = NULL;
 
       symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
@@ -5685,7 +5674,7 @@ elf_gc_sweep_symbol (struct elf_link_hash_entry *h, void *idxptr)
   return TRUE;
 }
 
-/* Propogate collected vtable information.  This is called through
+/* Propagate collected vtable information.  This is called through
    elf_link_hash_traverse.  */
 
 static bfd_boolean
@@ -5727,10 +5716,11 @@ elf_gc_propagate_vtable_entries_used (struct elf_link_hash_entry *h, void *okp)
       pu = h->vtable_parent->vtable_entries_used;
       if (pu != NULL)
        {
-         asection *sec = h->root.u.def.section;
-         struct elf_backend_data *bed = get_elf_backend_data (sec->owner);
-         unsigned int log_file_align = bed->s->log_file_align;
+         const struct elf_backend_data *bed;
+         unsigned int log_file_align;
 
+         bed = get_elf_backend_data (h->root.u.def.section->owner);
+         log_file_align = bed->s->log_file_align;
          n = h->vtable_parent->vtable_entries_size >> log_file_align;
          while (n--)
            {
@@ -5751,7 +5741,7 @@ elf_gc_smash_unused_vtentry_relocs (struct elf_link_hash_entry *h, void *okp)
   asection *sec;
   bfd_vma hstart, hend;
   Elf_Internal_Rela *relstart, *relend, *rel;
-  struct elf_backend_data *bed;
+  const struct elf_backend_data *bed;
   unsigned int log_file_align;
 
   if (h->root.type == bfd_link_hash_warning)
@@ -5807,9 +5797,14 @@ elf_gc_sections (bfd *abfd, struct bfd_link_info *info)
      struct elf_link_hash_entry *h, Elf_Internal_Sym *);
 
   if (!get_elf_backend_data (abfd)->can_gc_sections
-      || info->relocatable || info->emitrelocations
+      || info->relocatable
+      || info->emitrelocations
+      || !is_elf_hash_table (info->hash)
       || elf_hash_table (info)->dynamic_sections_created)
-    return TRUE;
+    {
+      (*_bfd_error_handler)(_("Warning: gc-sections option ignored"));
+      return TRUE;
+    }
 
   /* Apply transitive closure to the vtable entry usage info.  */
   elf_link_hash_traverse (elf_hash_table (info),
@@ -5850,7 +5845,7 @@ elf_gc_sections (bfd *abfd, struct bfd_link_info *info)
   return TRUE;
 }
 \f
-/* Called from check_relocs to record the existance of a VTINHERIT reloc.  */
+/* Called from check_relocs to record the existence of a VTINHERIT reloc.  */
 
 bfd_boolean
 elf_gc_record_vtinherit (bfd *abfd,
@@ -5906,7 +5901,7 @@ elf_gc_record_vtinherit (bfd *abfd,
   return TRUE;
 }
 
-/* Called from check_relocs to record the existance of a VTENTRY reloc.  */
+/* Called from check_relocs to record the existence of a VTENTRY reloc.  */
 
 bfd_boolean
 elf_gc_record_vtentry (bfd *abfd ATTRIBUTE_UNUSED,
@@ -5914,7 +5909,7 @@ elf_gc_record_vtentry (bfd *abfd ATTRIBUTE_UNUSED,
                       struct elf_link_hash_entry *h,
                       bfd_vma addend)
 {
-  struct elf_backend_data *bed = get_elf_backend_data (abfd);
+  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
   unsigned int log_file_align = bed->s->log_file_align;
 
   if (addend >= h->vtable_entries_size)
@@ -5980,9 +5975,12 @@ elf_gc_common_finalize_got_offsets (bfd *abfd,
                                    struct bfd_link_info *info)
 {
   bfd *i;
-  struct elf_backend_data *bed = get_elf_backend_data (abfd);
+  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
   bfd_vma gotoff;
 
+  if (! is_elf_hash_table (info->hash))
+    return FALSE;
+
   /* The GOT offset is relative to the .got section, but the GOT header is
      put into the .got.plt section, if the backend uses it.  */
   if (bed->want_got_plt)
@@ -6183,14 +6181,13 @@ elf_bfd_discard_info (bfd *output_bfd, struct bfd_link_info *info)
   struct elf_reloc_cookie cookie;
   asection *stab, *eh;
   Elf_Internal_Shdr *symtab_hdr;
-  struct elf_backend_data *bed;
+  const struct elf_backend_data *bed;
   bfd *abfd;
   unsigned int count;
   bfd_boolean ret = FALSE;
 
   if (info->traditional_format
-      || info->hash->creator->flavour != bfd_target_elf_flavour
-      || ! is_elf_hash_table (info))
+      || !is_elf_hash_table (info->hash))
     return FALSE;
 
   for (abfd = info->input_bfds; abfd != NULL; abfd = abfd->link_next)
@@ -6316,7 +6313,7 @@ elf_bfd_discard_info (bfd *output_bfd, struct bfd_link_info *info)
 static bfd_boolean
 elf_section_ignore_discarded_relocs (asection *sec)
 {
-  struct elf_backend_data *bed;
+  const struct elf_backend_data *bed;
 
   switch (sec->sec_info_type)
     {
This page took 0.033515 seconds and 4 git commands to generate.