Ignore:
Timestamp:
Aug 16, 2003, 6:59:22 PM (22 years ago)
Author:
bird
Message:

binutils v2.14 - offical sources.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/binutils/bfd/elflink.h

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    11/* ELF linker support.
    2    Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001
     2   Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
    33   Free Software Foundation, Inc.
    44
    5 This file is part of BFD, the Binary File Descriptor library.
    6 
    7 This program is free software; you can redistribute it and/or modify
    8 it under the terms of the GNU General Public License as published by
    9 the Free Software Foundation; either version 2 of the License, or
    10 (at your option) any later version.
    11 
    12 This program is distributed in the hope that it will be useful,
    13 but WITHOUT ANY WARRANTY; without even the implied warranty of
    14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15 GNU General Public License for more details.
    16 
    17 You should have received a copy of the GNU General Public License
    18 along with this program; if not, write to the Free Software
    19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
     5   This file is part of BFD, the Binary File Descriptor library.
     6
     7   This program is free software; you can redistribute it and/or modify
     8   it under the terms of the GNU General Public License as published by
     9   the Free Software Foundation; either version 2 of the License, or
     10   (at your option) any later version.
     11
     12   This program is distributed in the hope that it will be useful,
     13   but WITHOUT ANY WARRANTY; without even the implied warranty of
     14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15   GNU General Public License for more details.
     16
     17   You should have received a copy of the GNU General Public License
     18   along with this program; if not, write to the Free Software
     19   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
    2020
    2121/* ELF linker code.  */
     
    2626struct elf_info_failed
    2727{
    28   boolean failed;
     28  bfd_boolean failed;
    2929  struct bfd_link_info *info;
     30  struct bfd_elf_version_tree *verdefs;
    3031};
    3132
    32 static boolean elf_link_add_object_symbols
     33static bfd_boolean is_global_data_symbol_definition
     34  PARAMS ((bfd *, Elf_Internal_Sym *));
     35static bfd_boolean elf_link_is_defined_archive_symbol
     36  PARAMS ((bfd *, carsym *));
     37static bfd_boolean elf_link_add_object_symbols
    3338  PARAMS ((bfd *, struct bfd_link_info *));
    34 static boolean elf_link_add_archive_symbols
     39static bfd_boolean elf_link_add_archive_symbols
    3540  PARAMS ((bfd *, struct bfd_link_info *));
    36 static boolean elf_merge_symbol
    37   PARAMS ((bfd *, struct bfd_link_info *, const char *, Elf_Internal_Sym *,
    38            asection **, bfd_vma *, struct elf_link_hash_entry **,
    39            boolean *, boolean *, boolean *, boolean));
    40 static boolean elf_export_symbol
     41static bfd_boolean elf_merge_symbol
     42  PARAMS ((bfd *, struct bfd_link_info *, const char *,
     43           Elf_Internal_Sym *, asection **, bfd_vma *,
     44           struct elf_link_hash_entry **, bfd_boolean *, bfd_boolean *,
     45           bfd_boolean *, bfd_boolean *, bfd_boolean));
     46static bfd_boolean elf_add_default_symbol
     47  PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
     48           const char *, Elf_Internal_Sym *, asection **, bfd_vma *,
     49           bfd_boolean *, bfd_boolean, bfd_boolean));
     50static bfd_boolean elf_export_symbol
    4151  PARAMS ((struct elf_link_hash_entry *, PTR));
    42 static boolean elf_fix_symbol_flags
     52static bfd_boolean elf_finalize_dynstr
     53  PARAMS ((bfd *, struct bfd_link_info *));
     54static bfd_boolean elf_fix_symbol_flags
    4355  PARAMS ((struct elf_link_hash_entry *, struct elf_info_failed *));
    44 static boolean elf_adjust_dynamic_symbol
     56static bfd_boolean elf_adjust_dynamic_symbol
    4557  PARAMS ((struct elf_link_hash_entry *, PTR));
    46 static boolean elf_link_find_version_dependencies
     58static bfd_boolean elf_link_find_version_dependencies
    4759  PARAMS ((struct elf_link_hash_entry *, PTR));
    48 static boolean elf_link_find_version_dependencies
     60static bfd_boolean elf_link_assign_sym_version
    4961  PARAMS ((struct elf_link_hash_entry *, PTR));
    50 static boolean elf_link_assign_sym_version
     62static bfd_boolean elf_collect_hash_codes
    5163  PARAMS ((struct elf_link_hash_entry *, PTR));
    52 static boolean elf_collect_hash_codes
    53   PARAMS ((struct elf_link_hash_entry *, PTR));
    54 static boolean elf_link_read_relocs_from_section
     64static bfd_boolean elf_link_read_relocs_from_section
    5565  PARAMS ((bfd *, Elf_Internal_Shdr *, PTR, Elf_Internal_Rela *));
    56 static void elf_link_output_relocs
     66static size_t compute_bucket_count
     67  PARAMS ((struct bfd_link_info *));
     68static bfd_boolean elf_link_output_relocs
    5769  PARAMS ((bfd *, asection *, Elf_Internal_Shdr *, Elf_Internal_Rela *));
    58 static boolean elf_link_size_reloc_section
     70static bfd_boolean elf_link_size_reloc_section
    5971  PARAMS ((bfd *, Elf_Internal_Shdr *, asection *));
    6072static void elf_link_adjust_relocs
    6173  PARAMS ((bfd *, Elf_Internal_Shdr *, unsigned int,
    6274           struct elf_link_hash_entry **));
     75static int elf_link_sort_cmp1
     76  PARAMS ((const void *, const void *));
     77static int elf_link_sort_cmp2
     78  PARAMS ((const void *, const void *));
     79static size_t elf_link_sort_relocs
     80  PARAMS ((bfd *, struct bfd_link_info *, asection **));
     81static bfd_boolean elf_section_ignore_discarded_relocs
     82  PARAMS ((asection *));
    6383
    6484/* Given an ELF BFD, add symbols to the global hash table as
    6585   appropriate.  */
    6686
    67 boolean
     87bfd_boolean
    6888elf_bfd_link_add_symbols (abfd, info)
    6989     bfd *abfd;
     
    7898    default:
    7999      bfd_set_error (bfd_error_wrong_format);
    80       return false;
     100      return FALSE;
    81101    }
    82102}
    83103
    84104
    85 /* Return true iff this is a non-common, definition of a non-function symbol.  */
    86 static boolean
     105/* Return TRUE iff this is a non-common, definition of a non-function symbol.  */
     106static bfd_boolean
    87107is_global_data_symbol_definition (abfd, sym)
    88108     bfd * abfd ATTRIBUTE_UNUSED;
     
    92112  if (ELF_ST_BIND (sym->st_info) != STB_GLOBAL
    93113      && ELF_ST_BIND (sym->st_info) < STB_LOOS)
    94     return false;
     114    return FALSE;
    95115
    96116  /* Function symbols do not count.  */
    97117  if (ELF_ST_TYPE (sym->st_info) == STT_FUNC)
    98     return false;
     118    return FALSE;
    99119
    100120  /* If the section is undefined, then so is the symbol.  */
    101121  if (sym->st_shndx == SHN_UNDEF)
    102     return false;
     122    return FALSE;
    103123
    104124  /* If the symbol is defined in the common section, then
    105125     it is a common definition and so does not count.  */
    106126  if (sym->st_shndx == SHN_COMMON)
    107     return false;
     127    return FALSE;
    108128
    109129  /* If the symbol is in a target specific section then we
     
    117137       Even if this is wrong, at least the linker will behave
    118138       in the same way that it used to do.  */
    119     return false;
    120 
    121   return true;
     139    return FALSE;
     140
     141  return TRUE;
    122142}
    123143
     
    125145   whose archive map contains a mention of SYMDEF, and determine if
    126146   the symbol is defined in this element.  */
    127 static boolean
     147static bfd_boolean
    128148elf_link_is_defined_archive_symbol (abfd, symdef)
    129149     bfd * abfd;
     
    131151{
    132152  Elf_Internal_Shdr * hdr;
    133   Elf_External_Sym *  esym;
    134   Elf_External_Sym *  esymend;
    135   Elf_External_Sym *  buf = NULL;
    136   size_t symcount;
    137   size_t extsymcount;
    138   size_t extsymoff;
    139   boolean result = false;
     153  bfd_size_type symcount;
     154  bfd_size_type extsymcount;
     155  bfd_size_type extsymoff;
     156  Elf_Internal_Sym *isymbuf;
     157  Elf_Internal_Sym *isym;
     158  Elf_Internal_Sym *isymend;
     159  bfd_boolean result;
    140160
    141161  abfd = _bfd_get_elt_at_filepos (abfd, symdef->file_offset);
    142162  if (abfd == (bfd *) NULL)
    143     return false;
     163    return FALSE;
    144164
    145165  if (! bfd_check_format (abfd, bfd_object))
    146     return false;
     166    return FALSE;
    147167
    148168  /* If we have already included the element containing this symbol in the
     
    151171     (re)include this element.  */
    152172  if (abfd->archive_pass)
    153     return false;
     173    return FALSE;
    154174
    155175  /* Select the appropriate symbol table.  */
     
    174194    }
    175195
    176   buf = ((Elf_External_Sym *)
    177          bfd_malloc (extsymcount * sizeof (Elf_External_Sym)));
    178   if (buf == NULL && extsymcount != 0)
    179     return false;
    180 
    181   /* Read in the symbol table.
    182      FIXME:  This ought to be cached somewhere.  */
    183   if (bfd_seek (abfd,
    184                 hdr->sh_offset + extsymoff * sizeof (Elf_External_Sym),
    185                 SEEK_SET) != 0
    186       || (bfd_read ((PTR) buf, sizeof (Elf_External_Sym), extsymcount, abfd)
    187           != extsymcount * sizeof (Elf_External_Sym)))
    188     {
    189       free (buf);
    190       return false;
    191     }
     196  if (extsymcount == 0)
     197    return FALSE;
     198
     199  /* Read in the symbol table.  */
     200  isymbuf = bfd_elf_get_elf_syms (abfd, hdr, extsymcount, extsymoff,
     201                                  NULL, NULL, NULL);
     202  if (isymbuf == NULL)
     203    return FALSE;
    192204
    193205  /* Scan the symbol table looking for SYMDEF.  */
    194   esymend = buf + extsymcount;
    195   for (esym = buf;
    196        esym < esymend;
    197        esym++)
    198     {
    199       Elf_Internal_Sym sym;
    200       const char * name;
    201 
    202       elf_swap_symbol_in (abfd, esym, & sym);
    203 
    204       name = bfd_elf_string_from_elf_section (abfd, hdr->sh_link, sym.st_name);
     206  result = FALSE;
     207  for (isym = isymbuf, isymend = isymbuf + extsymcount; isym < isymend; isym++)
     208    {
     209      const char *name;
     210
     211      name = bfd_elf_string_from_elf_section (abfd, hdr->sh_link,
     212                                              isym->st_name);
    205213      if (name == (const char *) NULL)
    206214        break;
     
    208216      if (strcmp (name, symdef->name) == 0)
    209217        {
    210           result = is_global_data_symbol_definition (abfd, & sym);
     218          result = is_global_data_symbol_definition (abfd, isym);
    211219          break;
    212220        }
    213221    }
    214222
    215   free (buf);
     223  free (isymbuf);
    216224
    217225  return result;
     
    244252   table until nothing further is resolved.  */
    245253
    246 static boolean
     254static bfd_boolean
    247255elf_link_add_archive_symbols (abfd, info)
    248256     bfd *abfd;
     
    250258{
    251259  symindex c;
    252   boolean *defined = NULL;
    253   boolean *included = NULL;
     260  bfd_boolean *defined = NULL;
     261  bfd_boolean *included = NULL;
    254262  carsym *symdefs;
    255   boolean loop;
     263  bfd_boolean loop;
     264  bfd_size_type amt;
    256265
    257266  if (! bfd_has_map (abfd))
     
    259268      /* An empty archive is a special case.  */
    260269      if (bfd_openr_next_archived_file (abfd, (bfd *) NULL) == NULL)
    261         return true;
     270        return TRUE;
    262271      bfd_set_error (bfd_error_no_armap);
    263       return false;
     272      return FALSE;
    264273    }
    265274
     
    269278  c = bfd_ardata (abfd)->symdef_count;
    270279  if (c == 0)
    271     return true;
    272   defined = (boolean *) bfd_malloc (c * sizeof (boolean));
    273   included = (boolean *) bfd_malloc (c * sizeof (boolean));
    274   if (defined == (boolean *) NULL || included == (boolean *) NULL)
     280    return TRUE;
     281  amt = c;
     282  amt *= sizeof (bfd_boolean);
     283  defined = (bfd_boolean *) bfd_zmalloc (amt);
     284  included = (bfd_boolean *) bfd_zmalloc (amt);
     285  if (defined == (bfd_boolean *) NULL || included == (bfd_boolean *) NULL)
    275286    goto error_return;
    276   memset (defined, 0, c * sizeof (boolean));
    277   memset (included, 0, c * sizeof (boolean));
    278287
    279288  symdefs = bfd_ardata (abfd)->symdefs;
     
    286295      carsym *symdefend;
    287296
    288       loop = false;
     297      loop = FALSE;
    289298      last = -1;
    290299
     
    302311          if (symdef->file_offset == last)
    303312            {
    304               included[i] = true;
     313              included[i] = TRUE;
    305314              continue;
    306315            }
    307316
    308317          h = elf_link_hash_lookup (elf_hash_table (info), symdef->name,
    309                                     false, false, false);
     318                                    FALSE, FALSE, FALSE);
    310319
    311320          if (h == NULL)
    312321            {
    313322              char *p, *copy;
     323              size_t len, first;
    314324
    315325              /* If this is a default version (the name contains @@),
    316                  look up the symbol again without the version.  The
    317                  effect is that references to the symbol without the
    318                  version will be matched by the default symbol in the
    319                  archive.  */
     326                 look up the symbol again with only one `@' as well
     327                 as without the version.  The effect is that references
     328                 to the symbol with and without the version will be
     329                 matched by the default symbol in the archive.  */
    320330
    321331              p = strchr (symdef->name, ELF_VER_CHR);
     
    323333                continue;
    324334
    325               copy = bfd_alloc (abfd, p - symdef->name + 1);
     335              /* First check with only one `@'.  */
     336              len = strlen (symdef->name);
     337              copy = bfd_alloc (abfd, (bfd_size_type) len);
    326338              if (copy == NULL)
    327339                goto error_return;
    328               memcpy (copy, symdef->name, p - symdef->name);
    329               copy[p - symdef->name] = '\0';
     340              first = p - symdef->name + 1;
     341              memcpy (copy, symdef->name, first);
     342              memcpy (copy + first, symdef->name + first + 1, len - first);
    330343
    331344              h = elf_link_hash_lookup (elf_hash_table (info), copy,
    332                                         false, false, false);
     345                                        FALSE, FALSE, FALSE);
     346
     347              if (h == NULL)
     348                {
     349                  /* We also need to check references to the symbol
     350                     without the version.  */
     351
     352                  copy[first - 1] = '\0';
     353                  h = elf_link_hash_lookup (elf_hash_table (info),
     354                                            copy, FALSE, FALSE, FALSE);
     355                }
    333356
    334357              bfd_release (abfd, copy);
     
    358381            {
    359382              if (h->root.type != bfd_link_hash_undefweak)
    360                 defined[i] = true;
     383                defined[i] = TRUE;
    361384              continue;
    362385            }
     
    396419             does make the code less efficient than it could be.  */
    397420          if (undefs_tail != info->hash->undefs_tail)
    398             loop = true;
     421            loop = TRUE;
    399422
    400423          /* Look backward to mark all symbols from this object file
     
    403426          do
    404427            {
    405               included[mark] = true;
     428              included[mark] = TRUE;
    406429              if (mark == 0)
    407430                break;
     
    420443  free (included);
    421444
    422   return true;
     445  return TRUE;
    423446
    424447 error_return:
    425   if (defined != (boolean *) NULL)
     448  if (defined != (bfd_boolean *) NULL)
    426449    free (defined);
    427   if (included != (boolean *) NULL)
     450  if (included != (bfd_boolean *) NULL)
    428451    free (included);
    429   return false;
     452  return FALSE;
    430453}
    431454
     
    442465   a shared object.  */
    443466
    444 static boolean
    445 elf_merge_symbol (abfd, info, name, sym, psec, pvalue, sym_hash,
     467static bfd_boolean
     468elf_merge_symbol (abfd, info, name, sym, psec, pvalue, sym_hash, skip,
    446469                  override, type_change_ok, size_change_ok, dt_needed)
    447470     bfd *abfd;
     
    452475     bfd_vma *pvalue;
    453476     struct elf_link_hash_entry **sym_hash;
    454      boolean *override;
    455      boolean *type_change_ok;
    456      boolean *size_change_ok;
    457      boolean dt_needed;
     477     bfd_boolean *skip;
     478     bfd_boolean *override;
     479     bfd_boolean *type_change_ok;
     480     bfd_boolean *size_change_ok;
     481     bfd_boolean dt_needed;
    458482{
    459483  asection *sec;
    460484  struct elf_link_hash_entry *h;
     485  struct elf_link_hash_entry *flip;
    461486  int bind;
    462487  bfd *oldbfd;
    463   boolean newdyn, olddyn, olddef, newdef, newdyncommon, olddyncommon;
    464 
    465   *override = false;
     488  bfd_boolean newdyn, olddyn, olddef, newdef, newdyncommon, olddyncommon;
     489  bfd_boolean newweakdef, oldweakdef, newweakundef, oldweakundef;
     490
     491  *skip = FALSE;
     492  *override = FALSE;
    466493
    467494  sec = *psec;
     
    469496
    470497  if (! bfd_is_und_section (sec))
    471     h = elf_link_hash_lookup (elf_hash_table (info), name, true, false, false);
     498    h = elf_link_hash_lookup (elf_hash_table (info), name, TRUE, FALSE, FALSE);
    472499  else
    473500    h = ((struct elf_link_hash_entry *)
    474          bfd_wrapped_link_hash_lookup (abfd, info, name, true, false, false));
     501         bfd_wrapped_link_hash_lookup (abfd, info, name, TRUE, FALSE, FALSE));
    475502  if (h == NULL)
    476     return false;
     503    return FALSE;
    477504  *sym_hash = h;
    478505
     
    480507     if we are doing an ELF link.  */
    481508  if (info->hash->creator != abfd->xvec)
    482     return true;
     509    return TRUE;
    483510
    484511  /* For merging, we only care about real symbols.  */
     
    495522    {
    496523      h->elf_link_hash_flags &=~ ELF_LINK_NON_ELF;
    497       return true;
     524      return TRUE;
    498525    }
    499526
     
    530557      && ((abfd->flags & DYNAMIC) == 0
    531558          || (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0))
    532     return true;
     559    return TRUE;
    533560
    534561  /* NEWDYN and OLDDYN indicate whether the new or old symbol,
     
    536563
    537564  if ((abfd->flags & DYNAMIC) != 0)
    538     newdyn = true;
     565    newdyn = TRUE;
    539566  else
    540     newdyn = false;
     567    newdyn = FALSE;
    541568
    542569  if (oldbfd != NULL)
     
    547574
    548575      /* This code handles the special SHN_MIPS_{TEXT,DATA} section
    549         indices used by MIPS ELF.  */
     576        indices used by MIPS ELF.  */
    550577      switch (h->root.type)
    551578        {
     
    565592
    566593      if (hsec == NULL)
    567         olddyn = false;
     594        olddyn = FALSE;
    568595      else
    569596        olddyn = (hsec->symbol->flags & BSF_DYNAMIC) != 0;
     
    574601
    575602  if (bfd_is_und_section (sec) || bfd_is_com_section (sec))
    576     newdef = false;
     603    newdef = FALSE;
    577604  else
    578     newdef = true;
     605    newdef = TRUE;
    579606
    580607  if (h->root.type == bfd_link_hash_undefined
    581608      || h->root.type == bfd_link_hash_undefweak
    582609      || h->root.type == bfd_link_hash_common)
    583     olddef = false;
     610    olddef = FALSE;
    584611  else
    585     olddef = true;
     612    olddef = TRUE;
     613
     614  /* We need to rememeber if a symbol has a definition in a dynamic
     615     object or is weak in all dynamic objects. Internal and hidden
     616     visibility will make it unavailable to dynamic objects.  */
     617  if (newdyn && (h->elf_link_hash_flags & ELF_LINK_DYNAMIC_DEF) == 0)
     618    {
     619      if (!bfd_is_und_section (sec))
     620        h->elf_link_hash_flags |= ELF_LINK_DYNAMIC_DEF;
     621      else
     622        {
     623          /* Check if this symbol is weak in all dynamic objects. If it
     624             is the first time we see it in a dynamic object, we mark
     625             if it is weak. Otherwise, we clear it.  */
     626          if ((h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0)
     627            {
     628              if (bind == STB_WEAK)
     629                h->elf_link_hash_flags |= ELF_LINK_DYNAMIC_WEAK;
     630            }
     631          else if (bind != STB_WEAK)
     632            h->elf_link_hash_flags &= ~ELF_LINK_DYNAMIC_WEAK;
     633        }
     634    }
     635
     636  /* If the old symbol has non-default visibility, we ignore the new
     637     definition from a dynamic object.  */
     638  if (newdyn
     639      && ELF_ST_VISIBILITY (h->other)
     640      && !bfd_is_und_section (sec))
     641    {
     642      *skip = TRUE;
     643      /* Make sure this symbol is dynamic.  */
     644      h->elf_link_hash_flags |= ELF_LINK_HASH_REF_DYNAMIC;
     645      /* A protected symbol has external availability. Make sure it is
     646         recorded as dynamic.
     647
     648         FIXME: Should we check type and size for protected symbol?  */
     649      if (ELF_ST_VISIBILITY (h->other) == STV_PROTECTED)
     650        return _bfd_elf_link_record_dynamic_symbol (info, h);
     651      else
     652        return TRUE;
     653    }
     654  else if (!newdyn
     655           && ELF_ST_VISIBILITY (sym->st_other)
     656           && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0)
     657    {
     658      /* If the new symbol with non-default visibility comes from a
     659         relocatable file and the old definition comes from a dynamic
     660         object, we remove the old definition.  */
     661      if ((*sym_hash)->root.type == bfd_link_hash_indirect)
     662        h = *sym_hash;
     663      h->root.type = bfd_link_hash_new;
     664      h->root.u.undef.abfd = NULL;
     665      if (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)
     666        {
     667          h->elf_link_hash_flags &= ~ELF_LINK_HASH_DEF_DYNAMIC;
     668          h->elf_link_hash_flags |= (ELF_LINK_HASH_REF_DYNAMIC
     669                                     | ELF_LINK_DYNAMIC_DEF);
     670        }
     671      /* FIXME: Should we check type and size for protected symbol?  */
     672      h->size = 0;
     673      h->type = 0;
     674      return TRUE;
     675    }
     676
     677  /* We need to treat weak definiton right, depending on if there is a
     678     definition from a dynamic object.  */
     679  if (bind == STB_WEAK)
     680    {
     681      if (olddef)
     682        {
     683           newweakdef = TRUE;
     684           newweakundef = FALSE;
     685        }
     686      else
     687        {
     688           newweakdef = FALSE;
     689           newweakundef = TRUE;
     690        }
     691    }
     692  else
     693    newweakdef = newweakundef = FALSE;
     694
     695  /* If the new weak definition comes from a relocatable file and the
     696     old symbol comes from a dynamic object, we treat the new one as
     697     strong.  */
     698  if (newweakdef && !newdyn && olddyn)
     699    newweakdef = FALSE;
     700
     701  if (h->root.type == bfd_link_hash_defweak)
     702    {
     703      oldweakdef = TRUE;
     704      oldweakundef = FALSE;
     705    }
     706  else if (h->root.type == bfd_link_hash_undefweak)
     707    {
     708      oldweakdef = FALSE;
     709      oldweakundef = TRUE;
     710    }
     711  else
     712    oldweakdef = oldweakundef = FALSE;
     713
     714  /* If the old weak definition comes from a relocatable file and the
     715     new symbol comes from a dynamic object, we treat the old one as
     716     strong.  */
     717  if (oldweakdef && !olddyn && newdyn)
     718    oldweakdef = FALSE;
    586719
    587720  /* NEWDYNCOMMON and OLDDYNCOMMON indicate whether the new or old
     
    613746      && (sec->flags & SEC_LOAD) == 0
    614747      && sym->st_size > 0
    615       && bind != STB_WEAK
     748      && !newweakdef
     749      && !newweakundef
    616750      && ELF_ST_TYPE (sym->st_info) != STT_FUNC)
    617     newdyncommon = true;
     751    newdyncommon = TRUE;
    618752  else
    619     newdyncommon = false;
     753    newdyncommon = FALSE;
    620754
    621755  if (olddyn
     
    627761      && h->size > 0
    628762      && h->type != STT_FUNC)
    629     olddyncommon = true;
     763    olddyncommon = TRUE;
    630764  else
    631     olddyncommon = false;
     765    olddyncommon = FALSE;
    632766
    633767  /* It's OK to change the type if either the existing symbol or the
     
    636770     required at the run time.  */
    637771
    638   if ((! dt_needed && h->root.type == bfd_link_hash_defweak)
    639       || h->root.type == bfd_link_hash_undefweak
    640       || bind == STB_WEAK)
    641     *type_change_ok = true;
     772  if ((! dt_needed && oldweakdef)
     773      || oldweakundef
     774      || newweakdef
     775      || newweakundef)
     776    *type_change_ok = TRUE;
    642777
    643778  /* It's OK to change the size if either the existing symbol or the
     
    646781  if (*type_change_ok
    647782      || h->root.type == bfd_link_hash_undefined)
    648     *size_change_ok = true;
     783    *size_change_ok = TRUE;
    649784
    650785  /* If both the old and the new symbols look like common symbols in a
     
    657792    {
    658793      /* Since we think we have two common symbols, issue a multiple
    659         common warning if desired.  Note that we only warn if the
    660         size is different.  If the size is the same, we simply let
    661         the old symbol override the new one as normally happens with
    662         symbols defined in dynamic objects.  */
     794        common warning if desired.  Note that we only warn if the
     795        size is different.  If the size is the same, we simply let
     796        the old symbol override the new one as normally happens with
     797        symbols defined in dynamic objects.  */
    663798
    664799      if (! ((*info->callbacks->multiple_common)
    665800             (info, h->root.root.string, oldbfd, bfd_link_hash_common,
    666801              h->size, abfd, bfd_link_hash_common, sym->st_size)))
    667         return false;
     802        return FALSE;
    668803
    669804      if (sym->st_size > h->size)
    670805        h->size = sym->st_size;
    671806
    672       *size_change_ok = true;
     807      *size_change_ok = TRUE;
    673808    }
    674809
     
    696831      && (olddef
    697832          || (h->root.type == bfd_link_hash_common
    698               && (bind == STB_WEAK
     833              && (newweakdef
     834                  || newweakundef
    699835                  || ELF_ST_TYPE (sym->st_info) == STT_FUNC)))
    700       && (h->root.type != bfd_link_hash_defweak
     836      && (!oldweakdef
    701837          || dt_needed
    702           || bind == STB_WEAK))
    703     {
    704       *override = true;
    705       newdef = false;
    706       newdyncommon = false;
     838          || newweakdef
     839          || newweakundef))
     840    {
     841      *override = TRUE;
     842      newdef = FALSE;
     843      newdyncommon = FALSE;
    707844
    708845      *psec = sec = bfd_und_section_ptr;
    709       *size_change_ok = true;
     846      *size_change_ok = TRUE;
    710847
    711848      /* If we get here when the old symbol is a common symbol, then
    712         we are explicitly letting it override a weak symbol or
    713         function in a dynamic object, and we don't want to warn about
    714         a type change.  If the old symbol is a defined symbol, a type
    715         change warning may still be appropriate.  */
     849        we are explicitly letting it override a weak symbol or
     850        function in a dynamic object, and we don't want to warn about
     851        a type change.  If the old symbol is a defined symbol, a type
     852        change warning may still be appropriate.  */
    716853
    717854      if (h->root.type == bfd_link_hash_common)
    718         *type_change_ok = true;
     855        *type_change_ok = TRUE;
    719856    }
    720857
     
    728865      && h->root.type == bfd_link_hash_common)
    729866    {
    730       *override = true;
    731       newdef = false;
    732       newdyncommon = false;
     867      *override = TRUE;
     868      newdef = FALSE;
     869      newdyncommon = FALSE;
    733870      *pvalue = sym->st_size;
    734871      *psec = sec = bfd_com_section_ptr;
    735       *size_change_ok = true;
     872      *size_change_ok = TRUE;
    736873    }
    737874
     
    749886     override a weak definition in a regular object.  */
    750887
     888  flip = NULL;
    751889  if (! newdyn
    752890      && (newdef
    753891          || (bfd_is_com_section (sec)
    754               && (h->root.type == bfd_link_hash_defweak
    755                   || h->type == STT_FUNC)))
     892              && (oldweakdef || h->type == STT_FUNC)))
    756893      && olddyn
    757894      && olddef
    758895      && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
    759       && (bind != STB_WEAK
    760           || h->root.type == bfd_link_hash_defweak))
     896      && ((!newweakdef && !newweakundef) || oldweakdef))
    761897    {
    762898      /* Change the hash table entry to undefined, and let
     
    766902      h->root.type = bfd_link_hash_undefined;
    767903      h->root.u.undef.abfd = h->root.u.def.section->owner;
    768       *size_change_ok = true;
    769 
    770       olddef = false;
    771       olddyncommon = false;
     904      *size_change_ok = TRUE;
     905
     906      olddef = FALSE;
     907      olddyncommon = FALSE;
    772908
    773909      /* We again permit a type change when a common symbol may be
    774         overriding a function.  */
     910        overriding a function.  */
    775911
    776912      if (bfd_is_com_section (sec))
    777         *type_change_ok = true;
    778 
    779       /* This union may have been set to be non-NULL when this symbol
    780          was seen in a dynamic object.  We must force the union to be
    781          NULL, so that it is correct for a regular symbol.  */
    782 
    783       h->verinfo.vertree = NULL;
    784 
    785       /* In this special case, if H is the target of an indirection,
    786          we want the caller to frob with H rather than with the
    787          indirect symbol.  That will permit the caller to redefine the
    788          target of the indirection, rather than the indirect symbol
    789          itself.  FIXME: This will break the -y option if we store a
    790          symbol with a different name.  */
    791       *sym_hash = h;
     913        *type_change_ok = TRUE;
     914
     915      if ((*sym_hash)->root.type == bfd_link_hash_indirect)
     916        flip = *sym_hash;
     917      else
     918        /* This union may have been set to be non-NULL when this symbol
     919           was seen in a dynamic object.  We must force the union to be
     920           NULL, so that it is correct for a regular symbol.  */
     921        h->verinfo.vertree = NULL;
    792922    }
    793923
     
    808938             (info, h->root.root.string, oldbfd, bfd_link_hash_common,
    809939              h->size, abfd, bfd_link_hash_common, sym->st_size)))
    810         return false;
     940        return FALSE;
    811941
    812942      /* If the predumed common symbol in the dynamic object is
    813         larger, pretend that the new symbol has its size.  */
     943        larger, pretend that the new symbol has its size.  */
    814944
    815945      if (h->size > *pvalue)
     
    820950         the regular object.  */
    821951
    822       olddef = false;
    823       olddyncommon = false;
     952      olddef = FALSE;
     953      olddyncommon = FALSE;
    824954
    825955      h->root.type = bfd_link_hash_undefined;
    826956      h->root.u.undef.abfd = h->root.u.def.section->owner;
    827957
    828       *size_change_ok = true;
    829       *type_change_ok = true;
    830 
    831       h->verinfo.vertree = NULL;
     958      *size_change_ok = TRUE;
     959      *type_change_ok = TRUE;
     960
     961      if ((*sym_hash)->root.type == bfd_link_hash_indirect)
     962        flip = *sym_hash;
     963      else
     964        h->verinfo.vertree = NULL;
     965    }
     966
     967  if (flip != NULL)
     968    {
     969      /* Handle the case where we had a versioned symbol in a dynamic
     970         library and now find a definition in a normal object.  In this
     971         case, we make the versioned symbol point to the normal one.  */
     972      struct elf_backend_data *bed = get_elf_backend_data (abfd);
     973      flip->root.type = h->root.type;
     974      h->root.type = bfd_link_hash_indirect;
     975      h->root.u.i.link = (struct bfd_link_hash_entry *) flip;
     976      (*bed->elf_backend_copy_indirect_symbol) (bed, flip, h);
     977      flip->root.u.undef.abfd = h->root.u.undef.abfd;
     978      if (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)
     979        {
     980          h->elf_link_hash_flags &= ~ELF_LINK_HASH_DEF_DYNAMIC;
     981          flip->elf_link_hash_flags |= ELF_LINK_HASH_REF_DYNAMIC;
     982        }
    832983    }
    833984
     
    839990  if (olddef
    840991      && ! dt_needed
    841       && h->root.type == bfd_link_hash_defweak
     992      && oldweakdef
    842993      && newdef
    843994      && newdyn
    844       && bind != STB_WEAK)
     995      && !newweakdef
     996      && !newweakundef)
    845997    {
    846998      /* To make this work we have to frob the flags so that the rest
    847         of the code does not think we are using the regular
    848         definition.  */
     999        of the code does not think we are using the regular
     1000        definition.  */
    8491001      if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0)
    8501002        h->elf_link_hash_flags |= ELF_LINK_HASH_REF_REGULAR;
     
    8551007
    8561008      /* If H is the target of an indirection, we want the caller to
    857         use H rather than the indirect symbol.  Otherwise if we are
    858         defining a new indirect symbol we will wind up attaching it
    859         to the entry we are overriding.  */
     1009        use H rather than the indirect symbol.  Otherwise if we are
     1010        defining a new indirect symbol we will wind up attaching it
     1011        to the entry we are overriding.  */
    8601012      *sym_hash = h;
    8611013    }
     
    8631015  /* Handle the special case of a non-weak definition in a shared
    8641016     object followed by a weak definition in a regular object.  In
    865      this case we prefer to definition in the shared object.  To make
     1017     this case we prefer the definition in the shared object.  To make
    8661018     this work we have to tell the caller to not treat the new symbol
    8671019     as a definition.  */
    8681020  if (olddef
    8691021      && olddyn
    870       && h->root.type != bfd_link_hash_defweak
     1022      && !oldweakdef
    8711023      && newdef
    8721024      && ! newdyn
    873       && bind == STB_WEAK)
    874     *override = true;
    875 
    876   return true;
     1025      && (newweakdef || newweakundef))
     1026    *override = TRUE;
     1027
     1028  return TRUE;
    8771029}
    8781030
     1031/* This function is called to create an indirect symbol from the
     1032   default for the symbol with the default version if needed. The
     1033   symbol is described by H, NAME, SYM, PSEC, VALUE, and OVERRIDE.  We
     1034   set DYNSYM if the new indirect symbol is dynamic. DT_NEEDED
     1035   indicates if it comes from a DT_NEEDED entry of a shared object.  */
     1036
     1037static bfd_boolean
     1038elf_add_default_symbol (abfd, info, h, name, sym, psec, value,
     1039                        dynsym, override, dt_needed)
     1040     bfd *abfd;
     1041     struct bfd_link_info *info;
     1042     struct elf_link_hash_entry *h;
     1043     const char *name;
     1044     Elf_Internal_Sym *sym;
     1045     asection **psec;
     1046     bfd_vma *value;
     1047     bfd_boolean *dynsym;
     1048     bfd_boolean override;
     1049     bfd_boolean dt_needed;
     1050{
     1051  bfd_boolean type_change_ok;
     1052  bfd_boolean size_change_ok;
     1053  bfd_boolean skip;
     1054  char *shortname;
     1055  struct elf_link_hash_entry *hi;
     1056  struct bfd_link_hash_entry *bh;
     1057  struct elf_backend_data *bed;
     1058  bfd_boolean collect;
     1059  bfd_boolean dynamic;
     1060  char *p;
     1061  size_t len, shortlen;
     1062  asection *sec;
     1063
     1064  /* If this symbol has a version, and it is the default version, we
     1065     create an indirect symbol from the default name to the fully
     1066     decorated name.  This will cause external references which do not
     1067     specify a version to be bound to this version of the symbol.  */
     1068  p = strchr (name, ELF_VER_CHR);
     1069  if (p == NULL || p[1] != ELF_VER_CHR)
     1070    return TRUE;
     1071
     1072  if (override)
     1073    {
     1074      /* We are overridden by an old defition. We need to check if we
     1075         need to create the indirect symbol from the default name.  */
     1076      hi = elf_link_hash_lookup (elf_hash_table (info), name, TRUE,
     1077                                 FALSE, FALSE);
     1078      BFD_ASSERT (hi != NULL);
     1079      if (hi == h)
     1080        return TRUE;
     1081      while (hi->root.type == bfd_link_hash_indirect
     1082             || hi->root.type == bfd_link_hash_warning)
     1083        {
     1084          hi = (struct elf_link_hash_entry *) hi->root.u.i.link;
     1085          if (hi == h)
     1086            return TRUE;
     1087        }
     1088    }
     1089
     1090  bed = get_elf_backend_data (abfd);
     1091  collect = bed->collect;
     1092  dynamic = (abfd->flags & DYNAMIC) != 0;
     1093
     1094  shortlen = p - name;
     1095  shortname = bfd_hash_allocate (&info->hash->table, shortlen + 1);
     1096  if (shortname == NULL)
     1097    return FALSE;
     1098  memcpy (shortname, name, shortlen);
     1099  shortname[shortlen] = '\0';
     1100
     1101  /* We are going to create a new symbol.  Merge it with any existing
     1102     symbol with this name.  For the purposes of the merge, act as
     1103     though we were defining the symbol we just defined, although we
     1104     actually going to define an indirect symbol.  */
     1105  type_change_ok = FALSE;
     1106  size_change_ok = FALSE;
     1107  sec = *psec;
     1108  if (! elf_merge_symbol (abfd, info, shortname, sym, &sec, value,
     1109                          &hi, &skip, &override, &type_change_ok,
     1110                          &size_change_ok, dt_needed))
     1111    return FALSE;
     1112
     1113  if (skip)
     1114    goto nondefault;
     1115
     1116  if (! override)
     1117    {
     1118      bh = &hi->root;
     1119      if (! (_bfd_generic_link_add_one_symbol
     1120             (info, abfd, shortname, BSF_INDIRECT, bfd_ind_section_ptr,
     1121              (bfd_vma) 0, name, FALSE, collect, &bh)))
     1122        return FALSE;
     1123      hi = (struct elf_link_hash_entry *) bh;
     1124    }
     1125  else
     1126    {
     1127      /* In this case the symbol named SHORTNAME is overriding the
     1128         indirect symbol we want to add.  We were planning on making
     1129         SHORTNAME an indirect symbol referring to NAME.  SHORTNAME
     1130         is the name without a version.  NAME is the fully versioned
     1131         name, and it is the default version.
     1132
     1133         Overriding means that we already saw a definition for the
     1134         symbol SHORTNAME in a regular object, and it is overriding
     1135         the symbol defined in the dynamic object.
     1136
     1137         When this happens, we actually want to change NAME, the
     1138         symbol we just added, to refer to SHORTNAME.  This will cause
     1139         references to NAME in the shared object to become references
     1140         to SHORTNAME in the regular object.  This is what we expect
     1141         when we override a function in a shared object: that the
     1142         references in the shared object will be mapped to the
     1143         definition in the regular object.  */
     1144
     1145      while (hi->root.type == bfd_link_hash_indirect
     1146             || hi->root.type == bfd_link_hash_warning)
     1147        hi = (struct elf_link_hash_entry *) hi->root.u.i.link;
     1148
     1149      h->root.type = bfd_link_hash_indirect;
     1150      h->root.u.i.link = (struct bfd_link_hash_entry *) hi;
     1151      if (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)
     1152        {
     1153          h->elf_link_hash_flags &=~ ELF_LINK_HASH_DEF_DYNAMIC;
     1154          hi->elf_link_hash_flags |= ELF_LINK_HASH_REF_DYNAMIC;
     1155          if (hi->elf_link_hash_flags
     1156              & (ELF_LINK_HASH_REF_REGULAR
     1157                 | ELF_LINK_HASH_DEF_REGULAR))
     1158            {
     1159              if (! _bfd_elf_link_record_dynamic_symbol (info, hi))
     1160                return FALSE;
     1161            }
     1162        }
     1163
     1164      /* Now set HI to H, so that the following code will set the
     1165         other fields correctly.  */
     1166      hi = h;
     1167    }
     1168
     1169  /* If there is a duplicate definition somewhere, then HI may not
     1170     point to an indirect symbol.  We will have reported an error to
     1171     the user in that case.  */
     1172
     1173  if (hi->root.type == bfd_link_hash_indirect)
     1174    {
     1175      struct elf_link_hash_entry *ht;
     1176
     1177      /* If the symbol became indirect, then we assume that we have
     1178         not seen a definition before.  */
     1179      BFD_ASSERT ((hi->elf_link_hash_flags
     1180                   & (ELF_LINK_HASH_DEF_DYNAMIC
     1181                      | ELF_LINK_HASH_DEF_REGULAR)) == 0);
     1182
     1183      ht = (struct elf_link_hash_entry *) hi->root.u.i.link;
     1184      (*bed->elf_backend_copy_indirect_symbol) (bed, ht, hi);
     1185
     1186      /* See if the new flags lead us to realize that the symbol must
     1187         be dynamic.  */
     1188      if (! *dynsym)
     1189        {
     1190          if (! dynamic)
     1191            {
     1192              if (info->shared
     1193                  || ((hi->elf_link_hash_flags
     1194                       & ELF_LINK_HASH_REF_DYNAMIC) != 0))
     1195                *dynsym = TRUE;
     1196            }
     1197          else
     1198            {
     1199              if ((hi->elf_link_hash_flags
     1200                   & ELF_LINK_HASH_REF_REGULAR) != 0)
     1201                *dynsym = TRUE;
     1202            }
     1203        }
     1204    }
     1205
     1206  /* We also need to define an indirection from the nondefault version
     1207     of the symbol.  */
     1208
     1209nondefault:
     1210  len = strlen (name);
     1211  shortname = bfd_hash_allocate (&info->hash->table, len);
     1212  if (shortname == NULL)
     1213    return FALSE;
     1214  memcpy (shortname, name, shortlen);
     1215  memcpy (shortname + shortlen, p + 1, len - shortlen);
     1216
     1217  /* Once again, merge with any existing symbol.  */
     1218  type_change_ok = FALSE;
     1219  size_change_ok = FALSE;
     1220  sec = *psec;
     1221  if (! elf_merge_symbol (abfd, info, shortname, sym, &sec, value,
     1222                          &hi, &skip, &override, &type_change_ok,
     1223                          &size_change_ok, dt_needed))
     1224    return FALSE;
     1225
     1226  if (skip)
     1227    return TRUE;
     1228
     1229  if (override)
     1230    {
     1231      /* Here SHORTNAME is a versioned name, so we don't expect to see
     1232         the type of override we do in the case above unless it is
     1233         overridden by a versioned definiton.  */
     1234      if (hi->root.type != bfd_link_hash_defined
     1235          && hi->root.type != bfd_link_hash_defweak)
     1236        (*_bfd_error_handler)
     1237          (_("%s: warning: unexpected redefinition of indirect versioned symbol `%s'"),
     1238           bfd_archive_filename (abfd), shortname);
     1239    }
     1240  else
     1241    {
     1242      bh = &hi->root;
     1243      if (! (_bfd_generic_link_add_one_symbol
     1244             (info, abfd, shortname, BSF_INDIRECT,
     1245              bfd_ind_section_ptr, (bfd_vma) 0, name, FALSE, collect, &bh)))
     1246        return FALSE;
     1247      hi = (struct elf_link_hash_entry *) bh;
     1248
     1249      /* If there is a duplicate definition somewhere, then HI may not
     1250         point to an indirect symbol.  We will have reported an error
     1251         to the user in that case.  */
     1252
     1253      if (hi->root.type == bfd_link_hash_indirect)
     1254        {
     1255          /* If the symbol became indirect, then we assume that we have
     1256             not seen a definition before.  */
     1257          BFD_ASSERT ((hi->elf_link_hash_flags
     1258                       & (ELF_LINK_HASH_DEF_DYNAMIC
     1259                          | ELF_LINK_HASH_DEF_REGULAR)) == 0);
     1260
     1261          (*bed->elf_backend_copy_indirect_symbol) (bed, h, hi);
     1262
     1263          /* See if the new flags lead us to realize that the symbol
     1264             must be dynamic.  */
     1265          if (! *dynsym)
     1266            {
     1267              if (! dynamic)
     1268                {
     1269                  if (info->shared
     1270                      || ((hi->elf_link_hash_flags
     1271                           & ELF_LINK_HASH_REF_DYNAMIC) != 0))
     1272                    *dynsym = TRUE;
     1273                }
     1274              else
     1275                {
     1276                  if ((hi->elf_link_hash_flags
     1277                       & ELF_LINK_HASH_REF_REGULAR) != 0)
     1278                    *dynsym = TRUE;
     1279                }
     1280            }
     1281        }
     1282    }
     1283
     1284  return TRUE;
     1285}
     1286
    8791287/* Add symbols from an ELF object file to the linker hash table.  */
    8801288
    881 static boolean
     1289static bfd_boolean
    8821290elf_link_add_object_symbols (abfd, info)
    8831291     bfd *abfd;
    8841292     struct bfd_link_info *info;
    8851293{
    886   boolean (*add_symbol_hook) PARAMS ((bfd *, struct bfd_link_info *,
    887                                       const Elf_Internal_Sym *,
    888                                       const char **, flagword *,
    889                                       asection **, bfd_vma *));
    890   boolean (*check_relocs) PARAMS ((bfd *, struct bfd_link_info *,
    891                                    asection *, const Elf_Internal_Rela *));
    892   boolean collect;
     1294  bfd_boolean (*add_symbol_hook)
     1295    PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Sym *,
     1296             const char **, flagword *, asection **, bfd_vma *));
     1297  bfd_boolean (*check_relocs)
     1298    PARAMS ((bfd *, struct bfd_link_info *, asection *,
     1299            const Elf_Internal_Rela *));
     1300  bfd_boolean collect;
    8931301  Elf_Internal_Shdr *hdr;
    894   size_t symcount;
    895   size_t extsymcount;
    896   size_t extsymoff;
    897   Elf_External_Sym *buf = NULL;
     1302  bfd_size_type symcount;
     1303  bfd_size_type extsymcount;
     1304  bfd_size_type extsymoff;
    8981305  struct elf_link_hash_entry **sym_hash;
    899   boolean dynamic;
     1306  bfd_boolean dynamic;
    9001307  Elf_External_Versym *extversym = NULL;
    9011308  Elf_External_Versym *ever;
    902   Elf_External_Dyn *dynbuf = NULL;
    9031309  struct elf_link_hash_entry *weaks;
    904   Elf_External_Sym *esym;
    905   Elf_External_Sym *esymend;
     1310  struct elf_link_hash_entry **nondeflt_vers = NULL;
     1311  bfd_size_type nondeflt_vers_cnt = 0;
     1312  Elf_Internal_Sym *isymbuf = NULL;
     1313  Elf_Internal_Sym *isym;
     1314  Elf_Internal_Sym *isymend;
    9061315  struct elf_backend_data *bed;
    907   boolean dt_needed;
     1316  bfd_boolean dt_needed;
     1317  struct elf_link_hash_table * hash_table;
     1318  bfd_size_type amt;
     1319
     1320  hash_table = elf_hash_table (info);
    9081321
    9091322  bed = get_elf_backend_data (abfd);
     
    9121325
    9131326  if ((abfd->flags & DYNAMIC) == 0)
    914     dynamic = false;
     1327    dynamic = FALSE;
    9151328  else
    9161329    {
    917       dynamic = true;
     1330      dynamic = TRUE;
    9181331
    9191332      /* You can't use -r against a dynamic object.  Also, there's no
     
    9601373                  struct elf_link_hash_entry *h;
    9611374
    962                   h = elf_link_hash_lookup (elf_hash_table (info), name,
    963                                             false, false, true);
     1375                  h = elf_link_hash_lookup (hash_table, name,
     1376                                            FALSE, FALSE, TRUE);
    9641377
    9651378                  /* FIXME: What about bfd_link_hash_common?  */
     
    9691382                    {
    9701383                      /* We don't want to issue this warning.  Clobber
    971                         the section size so that the warning does not
    972                         get copied into the output file.  */
     1384                        the section size so that the warning does not
     1385                        get copied into the output file.  */
    9731386                      s->_raw_size = 0;
    9741387                      continue;
     
    9881401              if (! (_bfd_generic_link_add_one_symbol
    9891402                     (info, abfd, name, BSF_WARNING, s, (bfd_vma) 0, msg,
    990                       false, collect, (struct bfd_link_hash_entry **) NULL)))
     1403                      FALSE, collect, (struct bfd_link_hash_entry **) NULL)))
    9911404                goto error_return;
    9921405
     
    9941407                {
    9951408                  /* Clobber the section size so that the warning does
    996                      not get copied into the output file.  */
     1409                     not get copied into the output file.  */
    9971410                  s->_raw_size = 0;
    9981411                }
     
    10011414    }
    10021415
    1003   /* If this is a dynamic object, we always link against the .dynsym
    1004      symbol table, not the .symtab symbol table.  The dynamic linker
    1005      will only see the .dynsym symbol table, so there is no reason to
    1006      look at .symtab for a dynamic object.  */
    1007 
    1008   if (! dynamic || elf_dynsymtab (abfd) == 0)
    1009     hdr = &elf_tdata (abfd)->symtab_hdr;
    1010   else
    1011     hdr = &elf_tdata (abfd)->dynsymtab_hdr;
    1012 
    1013   if (dynamic)
    1014     {
    1015       /* Read in any version definitions.  */
    1016 
    1017       if (! _bfd_elf_slurp_version_tables (abfd))
    1018         goto error_return;
    1019 
    1020       /* Read in the symbol versions, but don't bother to convert them
    1021          to internal format.  */
    1022       if (elf_dynversym (abfd) != 0)
    1023         {
    1024           Elf_Internal_Shdr *versymhdr;
    1025 
    1026           versymhdr = &elf_tdata (abfd)->dynversym_hdr;
    1027           extversym = (Elf_External_Versym *) bfd_malloc (versymhdr->sh_size);
    1028           if (extversym == NULL)
    1029             goto error_return;
    1030           if (bfd_seek (abfd, versymhdr->sh_offset, SEEK_SET) != 0
    1031               || (bfd_read ((PTR) extversym, 1, versymhdr->sh_size, abfd)
    1032                   != versymhdr->sh_size))
    1033             goto error_return;
    1034         }
    1035     }
    1036 
    1037   symcount = hdr->sh_size / sizeof (Elf_External_Sym);
    1038 
    1039   /* The sh_info field of the symtab header tells us where the
    1040      external symbols start.  We don't care about the local symbols at
    1041      this point.  */
    1042   if (elf_bad_symtab (abfd))
    1043     {
    1044       extsymcount = symcount;
    1045       extsymoff = 0;
    1046     }
    1047   else
    1048     {
    1049       extsymcount = symcount - hdr->sh_info;
    1050       extsymoff = hdr->sh_info;
    1051     }
    1052 
    1053   buf = ((Elf_External_Sym *)
    1054          bfd_malloc (extsymcount * sizeof (Elf_External_Sym)));
    1055   if (buf == NULL && extsymcount != 0)
    1056     goto error_return;
    1057 
    1058   /* We store a pointer to the hash table entry for each external
    1059      symbol.  */
    1060   sym_hash = ((struct elf_link_hash_entry **)
    1061               bfd_alloc (abfd,
    1062                          extsymcount * sizeof (struct elf_link_hash_entry *)));
    1063   if (sym_hash == NULL)
    1064     goto error_return;
    1065   elf_sym_hashes (abfd) = sym_hash;
    1066 
    1067   dt_needed = false;
    1068 
     1416  dt_needed = FALSE;
    10691417  if (! dynamic)
    10701418    {
    10711419      /* If we are creating a shared library, create all the dynamic
    1072         sections immediately.  We need to attach them to something,
    1073         so we attach them to this BFD, provided it is the right
    1074         format.  FIXME: If there are no input BFD's of the same
    1075         format as the output, we can't make a shared library.  */
     1420        sections immediately.  We need to attach them to something,
     1421        so we attach them to this BFD, provided it is the right
     1422        format.  FIXME: If there are no input BFD's of the same
     1423        format as the output, we can't make a shared library.  */
    10761424      if (info->shared
    1077           && ! elf_hash_table (info)->dynamic_sections_created
     1425          && is_elf_hash_table (info)
     1426          && ! hash_table->dynamic_sections_created
    10781427          && abfd->xvec == info->hash->creator)
    10791428        {
     
    10821431        }
    10831432    }
     1433  else if (! is_elf_hash_table (info))
     1434    goto error_return;
    10841435  else
    10851436    {
    10861437      asection *s;
    1087       boolean add_needed;
     1438      bfd_boolean add_needed;
    10881439      const char *name;
    10891440      bfd_size_type oldsize;
    10901441      bfd_size_type strindex;
     1442      struct bfd_link_needed_list *rpath = NULL, *runpath = NULL;
     1443
     1444      /* ld --just-symbols and dynamic objects don't mix very well.
     1445         Test for --just-symbols by looking at info set up by
     1446         _bfd_elf_link_just_syms.  */
     1447      if ((s = abfd->sections) != NULL
     1448          && s->sec_info_type == ELF_INFO_TYPE_JUST_SYMS)
     1449        goto error_return;
    10911450
    10921451      /* Find the name to use in a DT_NEEDED entry that refers to this
     
    10971456         elf_dt_name, we don't make a DT_NEEDED entry at all, even if
    10981457         there is a DT_SONAME entry.  */
    1099       add_needed = true;
     1458      add_needed = TRUE;
    11001459      name = bfd_get_filename (abfd);
    11011460      if (elf_dt_name (abfd) != NULL)
     
    11051464            {
    11061465              if (elf_dt_soname (abfd) != NULL)
    1107                 dt_needed = true;
    1108 
    1109               add_needed = false;
     1466                dt_needed = TRUE;
     1467
     1468              add_needed = FALSE;
    11101469            }
    11111470        }
     
    11131472      if (s != NULL)
    11141473        {
     1474          Elf_External_Dyn *dynbuf = NULL;
    11151475          Elf_External_Dyn *extdyn;
    11161476          Elf_External_Dyn *extdynend;
    11171477          int elfsec;
    1118           unsigned long link;
    1119           int rpath;
    1120           int runpath;
    1121 
    1122           dynbuf = (Elf_External_Dyn *) bfd_malloc ((size_t) s->_raw_size);
     1478          unsigned long shlink;
     1479
     1480          dynbuf = (Elf_External_Dyn *) bfd_malloc (s->_raw_size);
    11231481          if (dynbuf == NULL)
    11241482            goto error_return;
     
    11261484          if (! bfd_get_section_contents (abfd, s, (PTR) dynbuf,
    11271485                                          (file_ptr) 0, s->_raw_size))
    1128             goto error_return;
     1486            goto error_free_dyn;
    11291487
    11301488          elfsec = _bfd_elf_section_from_bfd_section (abfd, s);
    11311489          if (elfsec == -1)
    1132             goto error_return;
    1133           link = elf_elfsections (abfd)[elfsec]->sh_link;
    1134 
    1135           {
    1136             /* The shared libraries distributed with hpux11 have a bogus
    1137                sh_link field for the ".dynamic" section.  This code detects
    1138                when LINK refers to a section that is not a string table and
    1139                tries to find the string table for the ".dynsym" section
    1140                instead.  */
    1141             Elf_Internal_Shdr *hdr = elf_elfsections (abfd)[link];
    1142             if (hdr->sh_type != SHT_STRTAB)
    1143               {
    1144                 asection *s = bfd_get_section_by_name (abfd, ".dynsym");
    1145                 int elfsec = _bfd_elf_section_from_bfd_section (abfd, s);
    1146                 if (elfsec == -1)
    1147                   goto error_return;
    1148                 link = elf_elfsections (abfd)[elfsec]->sh_link;
    1149               }
    1150           }
     1490            goto error_free_dyn;
     1491          shlink = elf_elfsections (abfd)[elfsec]->sh_link;
    11511492
    11521493          extdyn = dynbuf;
    11531494          extdynend = extdyn + s->_raw_size / sizeof (Elf_External_Dyn);
    1154           rpath = 0;
    1155           runpath = 0;
    11561495          for (; extdyn < extdynend; extdyn++)
    11571496            {
     
    11611500              if (dyn.d_tag == DT_SONAME)
    11621501                {
    1163                   name = bfd_elf_string_from_elf_section (abfd, link,
    1164                                                           dyn.d_un.d_val);
     1502                  unsigned int tagv = dyn.d_un.d_val;
     1503                  name = bfd_elf_string_from_elf_section (abfd, shlink, tagv);
    11651504                  if (name == NULL)
    1166                     goto error_return;
     1505                    goto error_free_dyn;
    11671506                }
    11681507              if (dyn.d_tag == DT_NEEDED)
     
    11701509                  struct bfd_link_needed_list *n, **pn;
    11711510                  char *fnm, *anm;
    1172 
    1173                   n = ((struct bfd_link_needed_list *)
    1174                        bfd_alloc (abfd, sizeof (struct bfd_link_needed_list)));
    1175                   fnm = bfd_elf_string_from_elf_section (abfd, link,
    1176                                                          dyn.d_un.d_val);
     1511                  unsigned int tagv = dyn.d_un.d_val;
     1512
     1513                  amt = sizeof (struct bfd_link_needed_list);
     1514                  n = (struct bfd_link_needed_list *) bfd_alloc (abfd, amt);
     1515                  fnm = bfd_elf_string_from_elf_section (abfd, shlink, tagv);
    11771516                  if (n == NULL || fnm == NULL)
    1178                     goto error_return;
    1179                   anm = bfd_alloc (abfd, strlen (fnm) + 1);
     1517                    goto error_free_dyn;
     1518                  amt = strlen (fnm) + 1;
     1519                  anm = bfd_alloc (abfd, amt);
    11801520                  if (anm == NULL)
    1181                     goto error_return;
    1182                   strcpy (anm, fnm);
     1521                    goto error_free_dyn;
     1522                  memcpy (anm, fnm, (size_t) amt);
    11831523                  n->name = anm;
    11841524                  n->by = abfd;
    11851525                  n->next = NULL;
    1186                   for (pn = &elf_hash_table (info)->needed;
     1526                  for (pn = & hash_table->needed;
    11871527                       *pn != NULL;
    11881528                       pn = &(*pn)->next)
     
    11941534                  struct bfd_link_needed_list *n, **pn;
    11951535                  char *fnm, *anm;
    1196 
    1197                   /* When we see DT_RPATH before DT_RUNPATH, we have
    1198                      to clear runpath.  Do _NOT_ bfd_release, as that
    1199                      frees all more recently bfd_alloc'd blocks as
    1200                      well.  */
    1201                   if (rpath && elf_hash_table (info)->runpath)
    1202                     elf_hash_table (info)->runpath = NULL;
    1203 
    1204                   n = ((struct bfd_link_needed_list *)
    1205                        bfd_alloc (abfd, sizeof (struct bfd_link_needed_list)));
    1206                   fnm = bfd_elf_string_from_elf_section (abfd, link,
    1207                                                          dyn.d_un.d_val);
     1536                  unsigned int tagv = dyn.d_un.d_val;
     1537
     1538                  amt = sizeof (struct bfd_link_needed_list);
     1539                  n = (struct bfd_link_needed_list *) bfd_alloc (abfd, amt);
     1540                  fnm = bfd_elf_string_from_elf_section (abfd, shlink, tagv);
    12081541                  if (n == NULL || fnm == NULL)
    1209                     goto error_return;
    1210                   anm = bfd_alloc (abfd, strlen (fnm) + 1);
     1542                    goto error_free_dyn;
     1543                  amt = strlen (fnm) + 1;
     1544                  anm = bfd_alloc (abfd, amt);
    12111545                  if (anm == NULL)
    1212                     goto error_return;
    1213                   strcpy (anm, fnm);
     1546                    goto error_free_dyn;
     1547                  memcpy (anm, fnm, (size_t) amt);
    12141548                  n->name = anm;
    12151549                  n->by = abfd;
    12161550                  n->next = NULL;
    1217                   for (pn = &elf_hash_table (info)->runpath;
     1551                  for (pn = & runpath;
    12181552                       *pn != NULL;
    12191553                       pn = &(*pn)->next)
    12201554                    ;
    12211555                  *pn = n;
    1222                   runpath = 1;
    1223                   rpath = 0;
    12241556                }
    12251557              /* Ignore DT_RPATH if we have seen DT_RUNPATH.  */
    12261558              if (!runpath && dyn.d_tag == DT_RPATH)
    1227                 {
     1559                {
    12281560                  struct bfd_link_needed_list *n, **pn;
    12291561                  char *fnm, *anm;
    1230 
    1231                   n = ((struct bfd_link_needed_list *)
    1232                        bfd_alloc (abfd, sizeof (struct bfd_link_needed_list)));
    1233                   fnm = bfd_elf_string_from_elf_section (abfd, link,
    1234                                                          dyn.d_un.d_val);
     1562                  unsigned int tagv = dyn.d_un.d_val;
     1563
     1564                  amt = sizeof (struct bfd_link_needed_list);
     1565                  n = (struct bfd_link_needed_list *) bfd_alloc (abfd, amt);
     1566                  fnm = bfd_elf_string_from_elf_section (abfd, shlink, tagv);
    12351567                  if (n == NULL || fnm == NULL)
    1236                     goto error_return;
    1237                   anm = bfd_alloc (abfd, strlen (fnm) + 1);
     1568                    goto error_free_dyn;
     1569                  amt = strlen (fnm) + 1;
     1570                  anm = bfd_alloc (abfd, amt);
    12381571                  if (anm == NULL)
    1239                     goto error_return;
    1240                   strcpy (anm, fnm);
     1572                    {
     1573                    error_free_dyn:
     1574                      free (dynbuf);
     1575                      goto error_return;
     1576                    }
     1577                  memcpy (anm, fnm, (size_t) amt);
    12411578                  n->name = anm;
    12421579                  n->by = abfd;
    12431580                  n->next = NULL;
    1244                   for (pn = &elf_hash_table (info)->runpath;
     1581                  for (pn = & rpath;
    12451582                       *pn != NULL;
    12461583                       pn = &(*pn)->next)
    12471584                    ;
    12481585                  *pn = n;
    1249                   rpath = 1;
    12501586                }
    12511587            }
    12521588
    12531589          free (dynbuf);
    1254           dynbuf = NULL;
     1590        }
     1591
     1592      /* DT_RUNPATH overrides DT_RPATH.  Do _NOT_ bfd_release, as that
     1593         frees all more recently bfd_alloc'd blocks as well.  */
     1594      if (runpath)
     1595        rpath = runpath;
     1596
     1597      if (rpath)
     1598        {
     1599          struct bfd_link_needed_list **pn;
     1600          for (pn = & hash_table->runpath;
     1601               *pn != NULL;
     1602               pn = &(*pn)->next)
     1603            ;
     1604          *pn = rpath;
    12551605        }
    12561606
     
    12621612         still implies that the section takes up space in the output
    12631613         file.  */
    1264       abfd->sections = NULL;
    1265       abfd->section_count = 0;
     1614      bfd_section_list_clear (abfd);
    12661615
    12671616      /* If this is the first dynamic object found in the link, create
    12681617         the special sections required for dynamic linking.  */
    1269       if (! elf_hash_table (info)->dynamic_sections_created)
    1270         {
    1271           if (! elf_link_create_dynamic_sections (abfd, info))
    1272             goto error_return;
    1273         }
     1618      if (! hash_table->dynamic_sections_created)
     1619        if (! elf_link_create_dynamic_sections (abfd, info))
     1620          goto error_return;
    12741621
    12751622      if (add_needed)
    12761623        {
    12771624          /* Add a DT_NEEDED entry for this dynamic object.  */
    1278           oldsize = _bfd_stringtab_size (elf_hash_table (info)->dynstr);
    1279           strindex = _bfd_stringtab_add (elf_hash_table (info)->dynstr, name,
    1280                                          true, false);
     1625          oldsize = _bfd_elf_strtab_size (hash_table->dynstr);
     1626          strindex = _bfd_elf_strtab_add (hash_table->dynstr, name, FALSE);
    12811627          if (strindex == (bfd_size_type) -1)
    12821628            goto error_return;
    12831629
    1284           if (oldsize == _bfd_stringtab_size (elf_hash_table (info)->dynstr))
     1630          if (oldsize == _bfd_elf_strtab_size (hash_table->dynstr))
    12851631            {
    12861632              asection *sdyn;
     
    12921638                 link, just ignore it.  There is no reason to include
    12931639                 a particular dynamic object more than once.  */
    1294               sdyn = bfd_get_section_by_name (elf_hash_table (info)->dynobj,
    1295                                               ".dynamic");
     1640              sdyn = bfd_get_section_by_name (hash_table->dynobj, ".dynamic");
    12961641              BFD_ASSERT (sdyn != NULL);
    12971642
     
    13031648                  Elf_Internal_Dyn dyn;
    13041649
    1305                   elf_swap_dyn_in (elf_hash_table (info)->dynobj, dyncon,
    1306                                    &dyn);
     1650                  elf_swap_dyn_in (hash_table->dynobj, dyncon, & dyn);
    13071651                  if (dyn.d_tag == DT_NEEDED
    13081652                      && dyn.d_un.d_val == strindex)
    13091653                    {
    1310                       if (buf != NULL)
    1311                         free (buf);
    1312                       if (extversym != NULL)
    1313                         free (extversym);
    1314                       return true;
     1654                      _bfd_elf_strtab_delref (hash_table->dynstr, strindex);
     1655                      return TRUE;
    13151656                    }
    13161657                }
    13171658            }
    13181659
    1319           if (! elf_add_dynamic_entry (info, DT_NEEDED, strindex))
     1660          if (! elf_add_dynamic_entry (info, (bfd_vma) DT_NEEDED, strindex))
    13201661            goto error_return;
    13211662        }
    13221663
    13231664      /* Save the SONAME, if there is one, because sometimes the
    1324         linker emulation code will need to know it.  */
     1665        linker emulation code will need to know it.  */
    13251666      if (*name == '\0')
    1326         name = bfd_get_filename (abfd);
     1667        name = basename (bfd_get_filename (abfd));
    13271668      elf_dt_name (abfd) = name;
    13281669    }
    13291670
    1330   if (bfd_seek (abfd,
    1331                 hdr->sh_offset + extsymoff * sizeof (Elf_External_Sym),
    1332                 SEEK_SET) != 0
    1333       || (bfd_read ((PTR) buf, sizeof (Elf_External_Sym), extsymcount, abfd)
    1334           != extsymcount * sizeof (Elf_External_Sym)))
    1335     goto error_return;
     1671  /* If this is a dynamic object, we always link against the .dynsym
     1672     symbol table, not the .symtab symbol table.  The dynamic linker
     1673     will only see the .dynsym symbol table, so there is no reason to
     1674     look at .symtab for a dynamic object.  */
     1675
     1676  if (! dynamic || elf_dynsymtab (abfd) == 0)
     1677    hdr = &elf_tdata (abfd)->symtab_hdr;
     1678  else
     1679    hdr = &elf_tdata (abfd)->dynsymtab_hdr;
     1680
     1681  symcount = hdr->sh_size / sizeof (Elf_External_Sym);
     1682
     1683  /* The sh_info field of the symtab header tells us where the
     1684     external symbols start.  We don't care about the local symbols at
     1685     this point.  */
     1686  if (elf_bad_symtab (abfd))
     1687    {
     1688      extsymcount = symcount;
     1689      extsymoff = 0;
     1690    }
     1691  else
     1692    {
     1693      extsymcount = symcount - hdr->sh_info;
     1694      extsymoff = hdr->sh_info;
     1695    }
     1696
     1697  sym_hash = NULL;
     1698  if (extsymcount != 0)
     1699    {
     1700      isymbuf = bfd_elf_get_elf_syms (abfd, hdr, extsymcount, extsymoff,
     1701                                      NULL, NULL, NULL);
     1702      if (isymbuf == NULL)
     1703        goto error_return;
     1704
     1705      /* We store a pointer to the hash table entry for each external
     1706         symbol.  */
     1707      amt = extsymcount * sizeof (struct elf_link_hash_entry *);
     1708      sym_hash = (struct elf_link_hash_entry **) bfd_alloc (abfd, amt);
     1709      if (sym_hash == NULL)
     1710        goto error_free_sym;
     1711      elf_sym_hashes (abfd) = sym_hash;
     1712    }
     1713
     1714  if (dynamic)
     1715    {
     1716      /* Read in any version definitions.  */
     1717      if (! _bfd_elf_slurp_version_tables (abfd))
     1718        goto error_free_sym;
     1719
     1720      /* Read in the symbol versions, but don't bother to convert them
     1721         to internal format.  */
     1722      if (elf_dynversym (abfd) != 0)
     1723        {
     1724          Elf_Internal_Shdr *versymhdr;
     1725
     1726          versymhdr = &elf_tdata (abfd)->dynversym_hdr;
     1727          extversym = (Elf_External_Versym *) bfd_malloc (versymhdr->sh_size);
     1728          if (extversym == NULL)
     1729            goto error_free_sym;
     1730          amt = versymhdr->sh_size;
     1731          if (bfd_seek (abfd, versymhdr->sh_offset, SEEK_SET) != 0
     1732              || bfd_bread ((PTR) extversym, amt, abfd) != amt)
     1733            goto error_free_vers;
     1734        }
     1735    }
    13361736
    13371737  weaks = NULL;
    13381738
    13391739  ever = extversym != NULL ? extversym + extsymoff : NULL;
    1340   esymend = buf + extsymcount;
    1341   for (esym = buf;
    1342        esym < esymend;
    1343        esym++, sym_hash++, ever = (ever != NULL ? ever + 1 : NULL))
    1344     {
    1345       Elf_Internal_Sym sym;
     1740  for (isym = isymbuf, isymend = isymbuf + extsymcount;
     1741       isym < isymend;
     1742       isym++, sym_hash++, ever = (ever != NULL ? ever + 1 : NULL))
     1743    {
    13461744      int bind;
    13471745      bfd_vma value;
     
    13501748      const char *name;
    13511749      struct elf_link_hash_entry *h;
    1352       boolean definition;
    1353       boolean size_change_ok, type_change_ok;
    1354       boolean new_weakdef;
     1750      bfd_boolean definition;
     1751      bfd_boolean size_change_ok;
     1752      bfd_boolean type_change_ok;
     1753      bfd_boolean new_weakdef;
     1754      bfd_boolean override;
    13551755      unsigned int old_alignment;
    1356 
    1357       elf_swap_symbol_in (abfd, esym, &sym);
     1756      bfd *old_bfd;
     1757
     1758      override = FALSE;
    13581759
    13591760      flags = BSF_NO_FLAGS;
    13601761      sec = NULL;
    1361       value = sym.st_value;
     1762      value = isym->st_value;
    13621763      *sym_hash = NULL;
    13631764
    1364       bind = ELF_ST_BIND (sym.st_info);
     1765      bind = ELF_ST_BIND (isym->st_info);
    13651766      if (bind == STB_LOCAL)
    13661767        {
     
    13731774      else if (bind == STB_GLOBAL)
    13741775        {
    1375           if (sym.st_shndx != SHN_UNDEF
    1376               && sym.st_shndx != SHN_COMMON)
     1776          if (isym->st_shndx != SHN_UNDEF
     1777              && isym->st_shndx != SHN_COMMON)
    13771778            flags = BSF_GLOBAL;
    13781779        }
     
    13841785        }
    13851786
    1386       if (sym.st_shndx == SHN_UNDEF)
     1787      if (isym->st_shndx == SHN_UNDEF)
    13871788        sec = bfd_und_section_ptr;
    1388       else if (sym.st_shndx > 0 && sym.st_shndx < SHN_LORESERVE)
    1389         {
    1390           sec = section_from_elf_index (abfd, sym.st_shndx);
     1789      else if (isym->st_shndx < SHN_LORESERVE || isym->st_shndx > SHN_HIRESERVE)
     1790        {
     1791          sec = section_from_elf_index (abfd, isym->st_shndx);
    13911792          if (sec == NULL)
    13921793            sec = bfd_abs_section_ptr;
     
    13941795            value -= sec->vma;
    13951796        }
    1396       else if (sym.st_shndx == SHN_ABS)
     1797      else if (isym->st_shndx == SHN_ABS)
    13971798        sec = bfd_abs_section_ptr;
    1398       else if (sym.st_shndx == SHN_COMMON)
     1799      else if (isym->st_shndx == SHN_COMMON)
    13991800        {
    14001801          sec = bfd_com_section_ptr;
    14011802          /* What ELF calls the size we call the value.  What ELF
    14021803             calls the value we call the alignment.  */
    1403           value = sym.st_size;
     1804          value = isym->st_size;
    14041805        }
    14051806      else
     
    14081809        }
    14091810
    1410       name = bfd_elf_string_from_elf_section (abfd, hdr->sh_link, sym.st_name);
     1811      name = bfd_elf_string_from_elf_section (abfd, hdr->sh_link,
     1812                                              isym->st_name);
    14111813      if (name == (const char *) NULL)
    1412         goto error_return;
    1413 
    1414       if (add_symbol_hook)
    1415         {
    1416           if (! (*add_symbol_hook) (abfd, info, &sym, &name, &flags, &sec,
     1814        goto error_free_vers;
     1815
     1816      if (isym->st_shndx == SHN_COMMON
     1817          && ELF_ST_TYPE (isym->st_info) == STT_TLS)
     1818        {
     1819          asection *tcomm = bfd_get_section_by_name (abfd, ".tcommon");
     1820
     1821          if (tcomm == NULL)
     1822            {
     1823              tcomm = bfd_make_section (abfd, ".tcommon");
     1824              if (tcomm == NULL
     1825                  || !bfd_set_section_flags (abfd, tcomm, (SEC_ALLOC
     1826                                                           | SEC_IS_COMMON
     1827                                                           | SEC_LINKER_CREATED
     1828                                                           | SEC_THREAD_LOCAL)))
     1829                goto error_free_vers;
     1830            }
     1831          sec = tcomm;
     1832        }
     1833      else if (add_symbol_hook)
     1834        {
     1835          if (! (*add_symbol_hook) (abfd, info, isym, &name, &flags, &sec,
    14171836                                    &value))
    1418             goto error_return;
     1837            goto error_free_vers;
    14191838
    14201839          /* The hook function sets the name to NULL if this symbol
     
    14281847        {
    14291848          bfd_set_error (bfd_error_bad_value);
    1430           goto error_return;
     1849          goto error_free_vers;
    14311850        }
    14321851
    14331852      if (bfd_is_und_section (sec)
    14341853          || bfd_is_com_section (sec))
    1435         definition = false;
     1854        definition = FALSE;
    14361855      else
    1437         definition = true;
    1438 
    1439       size_change_ok = false;
     1856        definition = TRUE;
     1857
     1858      size_change_ok = FALSE;
    14401859      type_change_ok = get_elf_backend_data (abfd)->type_change_ok;
    14411860      old_alignment = 0;
     1861      old_bfd = NULL;
     1862
    14421863      if (info->hash->creator->flavour == bfd_target_elf_flavour)
    14431864        {
    14441865          Elf_Internal_Versym iver;
    14451866          unsigned int vernum = 0;
    1446           boolean override;
     1867          bfd_boolean skip;
    14471868
    14481869          if (ever != NULL)
     
    14521873
    14531874              /* If this is a hidden symbol, or if it is not version
    1454                 1, we append the version name to the symbol name.
    1455                 However, we do not modify a non-hidden absolute
    1456                 symbol, because it might be the version symbol
    1457                 itself.  FIXME: What if it isn't?  */
     1875                1, we append the version name to the symbol name.
     1876                However, we do not modify a non-hidden absolute
     1877                symbol, because it might be the version symbol
     1878                itself.  FIXME: What if it isn't?  */
    14581879              if ((iver.vs_vers & VERSYM_HIDDEN) != 0
    14591880                  || (vernum > 1 && ! bfd_is_abs_section (sec)))
    14601881                {
    14611882                  const char *verstr;
    1462                   int namelen, newlen;
     1883                  size_t namelen, verlen, newlen;
    14631884                  char *newname, *p;
    14641885
    1465                   if (sym.st_shndx != SHN_UNDEF)
     1886                  if (isym->st_shndx != SHN_UNDEF)
    14661887                    {
    14671888                      if (vernum > elf_tdata (abfd)->dynverdef_hdr.sh_info)
     
    14691890                          (*_bfd_error_handler)
    14701891                            (_("%s: %s: invalid version %u (max %d)"),
    1471                              bfd_get_filename (abfd), name, vernum,
     1892                             bfd_archive_filename (abfd), name, vernum,
    14721893                             elf_tdata (abfd)->dynverdef_hdr.sh_info);
    14731894                          bfd_set_error (bfd_error_bad_value);
    1474                           goto error_return;
     1895                          goto error_free_vers;
    14751896                        }
    14761897                      else if (vernum > 1)
     
    15101931                          (*_bfd_error_handler)
    15111932                            (_("%s: %s: invalid needed version %d"),
    1512                              bfd_get_filename (abfd), name, vernum);
     1933                             bfd_archive_filename (abfd), name, vernum);
    15131934                          bfd_set_error (bfd_error_bad_value);
    1514                           goto error_return;
     1935                          goto error_free_vers;
    15151936                        }
    15161937                    }
    15171938
    15181939                  namelen = strlen (name);
    1519                   newlen = namelen + strlen (verstr) + 2;
    1520                   if ((iver.vs_vers & VERSYM_HIDDEN) == 0)
     1940                  verlen = strlen (verstr);
     1941                  newlen = namelen + verlen + 2;
     1942                  if ((iver.vs_vers & VERSYM_HIDDEN) == 0
     1943                      && isym->st_shndx != SHN_UNDEF)
    15211944                    ++newlen;
    15221945
    1523                   newname = (char *) bfd_alloc (abfd, newlen);
     1946                  newname = (char *) bfd_alloc (abfd, (bfd_size_type) newlen);
    15241947                  if (newname == NULL)
    1525                     goto error_return;
    1526                   strcpy (newname, name);
     1948                    goto error_free_vers;
     1949                  memcpy (newname, name, namelen);
    15271950                  p = newname + namelen;
    15281951                  *p++ = ELF_VER_CHR;
     
    15311954                     default version of the symbol.  */
    15321955                  if ((iver.vs_vers & VERSYM_HIDDEN) == 0
    1533                       && sym.st_shndx != SHN_UNDEF)
     1956                      && isym->st_shndx != SHN_UNDEF)
    15341957                    *p++ = ELF_VER_CHR;
    1535                   strcpy (p, verstr);
     1958                  memcpy (p, verstr, verlen + 1);
    15361959
    15371960                  name = newname;
     
    15391962            }
    15401963
    1541           if (! elf_merge_symbol (abfd, info, name, &sym, &sec, &value,
    1542                                   sym_hash, &override, &type_change_ok,
    1543                                   &size_change_ok, dt_needed))
    1544             goto error_return;
     1964          if (! elf_merge_symbol (abfd, info, name, isym, &sec, &value,
     1965                                  sym_hash, &skip, &override,
     1966                                  &type_change_ok, &size_change_ok,
     1967                                  dt_needed))
     1968            goto error_free_vers;
     1969
     1970          if (skip)
     1971            continue;
    15451972
    15461973          if (override)
    1547             definition = false;
     1974            definition = FALSE;
    15481975
    15491976          h = *sym_hash;
     
    15531980
    15541981          /* Remember the old alignment if this is a common symbol, so
    1555              that we don't reduce the alignment later on.  We can't
    1556              check later, because _bfd_generic_link_add_one_symbol
    1557              will set a default for the alignment which we want to
    1558              override.  */
    1559           if (h->root.type == bfd_link_hash_common)
    1560             old_alignment = h->root.u.c.p->alignment_power;
     1982             that we don't reduce the alignment later on.  We can't
     1983             check later, because _bfd_generic_link_add_one_symbol
     1984             will set a default for the alignment which we want to
     1985             override. We also remember the old bfd where the existing
     1986             definition comes from.  */
     1987          switch (h->root.type)
     1988            {
     1989            default:
     1990              break;
     1991
     1992            case bfd_link_hash_defined:
     1993            case bfd_link_hash_defweak:
     1994              old_bfd = h->root.u.def.section->owner;
     1995              break;
     1996           
     1997            case bfd_link_hash_common:
     1998              old_bfd = h->root.u.c.p->section->owner;
     1999              old_alignment = h->root.u.c.p->alignment_power;
     2000              break;
     2001            }
    15612002
    15622003          if (elf_tdata (abfd)->verdef != NULL
     
    15692010      if (! (_bfd_generic_link_add_one_symbol
    15702011             (info, abfd, name, flags, sec, value, (const char *) NULL,
    1571               false, collect, (struct bfd_link_hash_entry **) sym_hash)))
    1572         goto error_return;
     2012              FALSE, collect, (struct bfd_link_hash_entry **) sym_hash)))
     2013        goto error_free_vers;
    15732014
    15742015      h = *sym_hash;
     
    15782019      *sym_hash = h;
    15792020
    1580       new_weakdef = false;
     2021      new_weakdef = FALSE;
    15812022      if (dynamic
    15822023          && definition
    15832024          && (flags & BSF_WEAK) != 0
    1584           && ELF_ST_TYPE (sym.st_info) != STT_FUNC
     2025          && ELF_ST_TYPE (isym->st_info) != STT_FUNC
    15852026          && info->hash->creator->flavour == bfd_target_elf_flavour
    15862027          && h->weakdef == NULL)
     
    16002041          h->weakdef = weaks;
    16012042          weaks = h;
    1602           new_weakdef = true;
     2043          new_weakdef = TRUE;
    16032044        }
    16042045
    16052046      /* Set the alignment of a common symbol.  */
    1606       if (sym.st_shndx == SHN_COMMON
     2047      if (isym->st_shndx == SHN_COMMON
    16072048          && h->root.type == bfd_link_hash_common)
    16082049        {
    16092050          unsigned int align;
    16102051
    1611           align = bfd_log2 (sym.st_value);
     2052          align = bfd_log2 (isym->st_value);
    16122053          if (align > old_alignment
    16132054              /* Permit an alignment power of zero if an alignment of one
    16142055                 is specified and no other alignments have been specified.  */
    1615               || (sym.st_value == 1 && old_alignment == 0))
     2056              || (isym->st_value == 1 && old_alignment == 0))
    16162057            h->root.u.c.p->alignment_power = align;
     2058          else
     2059            h->root.u.c.p->alignment_power = old_alignment;
    16172060        }
    16182061
     
    16202063        {
    16212064          int old_flags;
    1622           boolean dynsym;
     2065          bfd_boolean dynsym;
    16232066          int new_flag;
    16242067
     2068          /* Check the alignment when a common symbol is involved. This
     2069             can change when a common symbol is overriden by a normal
     2070             definition or a common symbol is ignored due to the old
     2071             normal definition. We need to make sure the maximum
     2072             alignment is maintained.  */
     2073          if ((old_alignment || isym->st_shndx == SHN_COMMON)
     2074              && h->root.type != bfd_link_hash_common)
     2075            {
     2076              unsigned int common_align;
     2077              unsigned int normal_align;
     2078              unsigned int symbol_align;
     2079              bfd *normal_bfd;
     2080              bfd *common_bfd;
     2081
     2082              symbol_align = ffs (h->root.u.def.value) - 1;
     2083              if ((h->root.u.def.section->owner->flags & DYNAMIC) == 0)
     2084                {
     2085                  normal_align = h->root.u.def.section->alignment_power;
     2086                  if (normal_align > symbol_align)
     2087                    normal_align = symbol_align;
     2088                }
     2089              else
     2090                normal_align = symbol_align;
     2091
     2092              if (old_alignment)
     2093                {
     2094                  common_align = old_alignment;
     2095                  common_bfd = old_bfd;
     2096                  normal_bfd = abfd;
     2097                }
     2098              else
     2099                {
     2100                  common_align = bfd_log2 (isym->st_value);
     2101                  common_bfd = abfd;
     2102                  normal_bfd = old_bfd;
     2103                }
     2104
     2105              if (normal_align < common_align)
     2106                (*_bfd_error_handler)
     2107                  (_("Warning: alignment %u of symbol `%s' in %s is smaller than %u in %s"),
     2108                   1 << normal_align,
     2109                   name,
     2110                   bfd_archive_filename (normal_bfd),
     2111                   1 << common_align,
     2112                   bfd_archive_filename (common_bfd));
     2113            }
     2114
    16252115          /* Remember the symbol size and type.  */
    1626           if (sym.st_size != 0
     2116          if (isym->st_size != 0
    16272117              && (definition || h->size == 0))
    16282118            {
    1629               if (h->size != 0 && h->size != sym.st_size && ! size_change_ok)
     2119              if (h->size != 0 && h->size != isym->st_size && ! size_change_ok)
    16302120                (*_bfd_error_handler)
    1631                   (_("Warning: size of symbol `%s' changed from %lu to %lu in %s"),
    1632                    name, (unsigned long) h->size, (unsigned long) sym.st_size,
    1633                    bfd_get_filename (abfd));
    1634 
    1635               h->size = sym.st_size;
     2121                  (_("Warning: size of symbol `%s' changed from %lu in %s to %lu in %s"),
     2122                   name, (unsigned long) h->size,
     2123                   bfd_archive_filename (old_bfd),
     2124                   (unsigned long) isym->st_size,
     2125                   bfd_archive_filename (abfd));
     2126
     2127              h->size = isym->st_size;
    16362128            }
    16372129
    16382130          /* If this is a common symbol, then we always want H->SIZE
    1639              to be the size of the common symbol.  The code just above
    1640              won't fix the size if a common symbol becomes larger.  We
    1641              don't warn about a size change here, because that is
    1642              covered by --warn-common.  */
     2131             to be the size of the common symbol.  The code just above
     2132             won't fix the size if a common symbol becomes larger.  We
     2133             don't warn about a size change here, because that is
     2134             covered by --warn-common.  */
    16432135          if (h->root.type == bfd_link_hash_common)
    16442136            h->size = h->root.u.c.size;
    16452137
    1646           if (ELF_ST_TYPE (sym.st_info) != STT_NOTYPE
     2138          if (ELF_ST_TYPE (isym->st_info) != STT_NOTYPE
    16472139              && (definition || h->type == STT_NOTYPE))
    16482140            {
    16492141              if (h->type != STT_NOTYPE
    1650                   && h->type != ELF_ST_TYPE (sym.st_info)
     2142                  && h->type != ELF_ST_TYPE (isym->st_info)
    16512143                  && ! type_change_ok)
    16522144                (*_bfd_error_handler)
    16532145                  (_("Warning: type of symbol `%s' changed from %d to %d in %s"),
    1654                    name, h->type, ELF_ST_TYPE (sym.st_info),
    1655                    bfd_get_filename (abfd));
    1656 
    1657               h->type = ELF_ST_TYPE (sym.st_info);
     2146                   name, h->type, ELF_ST_TYPE (isym->st_info),
     2147                   bfd_archive_filename (abfd));
     2148
     2149              h->type = ELF_ST_TYPE (isym->st_info);
    16582150            }
    16592151
    1660           /* If st_other has a processor-specific meaning, specific code
    1661              might be needed here.  */
    1662           if (sym.st_other != 0)
     2152          /* If st_other has a processor-specific meaning, specific
     2153             code might be needed here. We never merge the visibility
     2154             attribute with the one from a dynamic object.  */
     2155          if (isym->st_other != 0 && !dynamic)
    16632156            {
     2157              unsigned char hvis, symvis, other, nvis;
     2158
     2159              /* Take the balance of OTHER from the definition.  */
     2160              other = (definition ? isym->st_other : h->other);
     2161              other &= ~ ELF_ST_VISIBILITY (-1);
     2162
    16642163              /* Combine visibilities, using the most constraining one.  */
    1665               unsigned char hvis   = ELF_ST_VISIBILITY (h->other);
    1666               unsigned char symvis = ELF_ST_VISIBILITY (sym.st_other);
    1667 
    1668               if (symvis && (hvis > symvis || hvis == 0))
    1669                 h->other = sym.st_other;
    1670 
    1671               /* If neither has visibility, use the st_other of the
    1672                  definition.  This is an arbitrary choice, since the
    1673                  other bits have no general meaning.  */
    1674               if (!symvis && !hvis
    1675                   && (definition || h->other == 0))
    1676                 h->other = sym.st_other;
     2164              hvis   = ELF_ST_VISIBILITY (h->other);
     2165              symvis = ELF_ST_VISIBILITY (isym->st_other);
     2166              if (! hvis)
     2167                nvis = symvis;
     2168              else if (! symvis)
     2169                nvis = hvis;
     2170              else
     2171                nvis = hvis < symvis ? hvis : symvis;
     2172
     2173              h->other = other | nvis;
    16772174            }
    16782175
     
    16832180             object and a shared object.  */
    16842181          old_flags = h->elf_link_hash_flags;
    1685           dynsym = false;
     2182          dynsym = FALSE;
    16862183          if (! dynamic)
    16872184            {
     
    16972194                  || (old_flags & (ELF_LINK_HASH_DEF_DYNAMIC
    16982195                                   | ELF_LINK_HASH_REF_DYNAMIC)) != 0)
    1699                 dynsym = true;
     2196                dynsym = TRUE;
    17002197            }
    17012198          else
     
    17102207                      && ! new_weakdef
    17112208                      && h->weakdef->dynindx != -1))
    1712                 dynsym = true;
     2209                dynsym = TRUE;
    17132210            }
    17142211
    17152212          h->elf_link_hash_flags |= new_flag;
    17162213
    1717           /* If this symbol has a version, and it is the default
    1718              version, we create an indirect symbol from the default
    1719              name to the fully decorated name.  This will cause
    1720              external references which do not specify a version to be
    1721              bound to this version of the symbol.  */
     2214          /* Check to see if we need to add an indirect symbol for
     2215             the default name.  */
    17222216          if (definition || h->root.type == bfd_link_hash_common)
     2217            if (! elf_add_default_symbol (abfd, info, h, name, isym,
     2218                                          &sec, &value, &dynsym,
     2219                                          override, dt_needed))
     2220              goto error_free_vers;
     2221
     2222          if (definition && !dynamic)
    17232223            {
    1724               char *p;
    1725 
    1726               p = strchr (name, ELF_VER_CHR);
    1727               if (p != NULL && p[1] == ELF_VER_CHR)
     2224              char *p = strchr (name, ELF_VER_CHR);
     2225              if (p != NULL && p[1] != ELF_VER_CHR)
    17282226                {
    1729                   char *shortname;
    1730                   struct elf_link_hash_entry *hi;
    1731                   boolean override;
    1732 
    1733                   shortname = bfd_hash_allocate (&info->hash->table,
    1734                                                  p - name + 1);
    1735                   if (shortname == NULL)
    1736                     goto error_return;
    1737                   strncpy (shortname, name, p - name);
    1738                   shortname[p - name] = '\0';
    1739 
    1740                   /* We are going to create a new symbol.  Merge it
    1741                      with any existing symbol with this name.  For the
    1742                      purposes of the merge, act as though we were
    1743                      defining the symbol we just defined, although we
    1744                      actually going to define an indirect symbol.  */
    1745                   type_change_ok = false;
    1746                   size_change_ok = false;
    1747                   if (! elf_merge_symbol (abfd, info, shortname, &sym, &sec,
    1748                                           &value, &hi, &override,
    1749                                           &type_change_ok,
    1750                                           &size_change_ok, dt_needed))
    1751                     goto error_return;
    1752 
    1753                   if (! override)
     2227                  /* Queue non-default versions so that .symver x, x@FOO
     2228                     aliases can be checked.  */
     2229                  if (! nondeflt_vers)
    17542230                    {
    1755                       if (! (_bfd_generic_link_add_one_symbol
    1756                              (info, abfd, shortname, BSF_INDIRECT,
    1757                               bfd_ind_section_ptr, (bfd_vma) 0, name, false,
    1758                               collect, (struct bfd_link_hash_entry **) &hi)))
    1759                         goto error_return;
     2231                      amt = (isymend - isym + 1)
     2232                            * sizeof (struct elf_link_hash_entry *);
     2233                      nondeflt_vers = bfd_malloc (amt);
    17602234                    }
    1761                   else
    1762                     {
    1763                       /* In this case the symbol named SHORTNAME is
    1764                          overriding the indirect symbol we want to
    1765                          add.  We were planning on making SHORTNAME an
    1766                          indirect symbol referring to NAME.  SHORTNAME
    1767                          is the name without a version.  NAME is the
    1768                          fully versioned name, and it is the default
    1769                          version.
    1770 
    1771                          Overriding means that we already saw a
    1772                          definition for the symbol SHORTNAME in a
    1773                          regular object, and it is overriding the
    1774                          symbol defined in the dynamic object.
    1775 
    1776                          When this happens, we actually want to change
    1777                          NAME, the symbol we just added, to refer to
    1778                          SHORTNAME.  This will cause references to
    1779                          NAME in the shared object to become
    1780                          references to SHORTNAME in the regular
    1781                          object.  This is what we expect when we
    1782                          override a function in a shared object: that
    1783                          the references in the shared object will be
    1784                          mapped to the definition in the regular
    1785                          object.  */
    1786 
    1787                       while (hi->root.type == bfd_link_hash_indirect
    1788                              || hi->root.type == bfd_link_hash_warning)
    1789                         hi = (struct elf_link_hash_entry *) hi->root.u.i.link;
    1790 
    1791                       h->root.type = bfd_link_hash_indirect;
    1792                       h->root.u.i.link = (struct bfd_link_hash_entry *) hi;
    1793                       if (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)
    1794                         {
    1795                           h->elf_link_hash_flags &=~ ELF_LINK_HASH_DEF_DYNAMIC;
    1796                           hi->elf_link_hash_flags |= ELF_LINK_HASH_REF_DYNAMIC;
    1797                           if (hi->elf_link_hash_flags
    1798                               & (ELF_LINK_HASH_REF_REGULAR
    1799                                  | ELF_LINK_HASH_DEF_REGULAR))
    1800                             {
    1801                               if (! _bfd_elf_link_record_dynamic_symbol (info,
    1802                                                                          hi))
    1803                                 goto error_return;
    1804                             }
    1805                         }
    1806 
    1807                       /* Now set HI to H, so that the following code
    1808                          will set the other fields correctly.  */
    1809                       hi = h;
    1810                     }
    1811 
    1812                   /* If there is a duplicate definition somewhere,
    1813                      then HI may not point to an indirect symbol.  We
    1814                      will have reported an error to the user in that
    1815                      case.  */
    1816 
    1817                   if (hi->root.type == bfd_link_hash_indirect)
    1818                     {
    1819                       struct elf_link_hash_entry *ht;
    1820 
    1821                       /* If the symbol became indirect, then we assume
    1822                          that we have not seen a definition before.  */
    1823                       BFD_ASSERT ((hi->elf_link_hash_flags
    1824                                    & (ELF_LINK_HASH_DEF_DYNAMIC
    1825                                       | ELF_LINK_HASH_DEF_REGULAR))
    1826                                   == 0);
    1827 
    1828                       ht = (struct elf_link_hash_entry *) hi->root.u.i.link;
    1829                       (*bed->elf_backend_copy_indirect_symbol) (ht, hi);
    1830 
    1831                       /* See if the new flags lead us to realize that
    1832                          the symbol must be dynamic.  */
    1833                       if (! dynsym)
    1834                         {
    1835                           if (! dynamic)
    1836                             {
    1837                               if (info->shared
    1838                                   || ((hi->elf_link_hash_flags
    1839                                        & ELF_LINK_HASH_REF_DYNAMIC)
    1840                                       != 0))
    1841                                 dynsym = true;
    1842                             }
    1843                           else
    1844                             {
    1845                               if ((hi->elf_link_hash_flags
    1846                                    & ELF_LINK_HASH_REF_REGULAR) != 0)
    1847                                 dynsym = true;
    1848                             }
    1849                         }
    1850                     }
    1851 
    1852                   /* We also need to define an indirection from the
    1853                      nondefault version of the symbol.  */
    1854 
    1855                   shortname = bfd_hash_allocate (&info->hash->table,
    1856                                                  strlen (name));
    1857                   if (shortname == NULL)
    1858                     goto error_return;
    1859                   strncpy (shortname, name, p - name);
    1860                   strcpy (shortname + (p - name), p + 1);
    1861 
    1862                   /* Once again, merge with any existing symbol.  */
    1863                   type_change_ok = false;
    1864                   size_change_ok = false;
    1865                   if (! elf_merge_symbol (abfd, info, shortname, &sym, &sec,
    1866                                           &value, &hi, &override,
    1867                                           &type_change_ok,
    1868                                           &size_change_ok, dt_needed))
    1869                     goto error_return;
    1870 
    1871                   if (override)
    1872                     {
    1873                       /* Here SHORTNAME is a versioned name, so we
    1874                          don't expect to see the type of override we
    1875                          do in the case above.  */
    1876                       (*_bfd_error_handler)
    1877                         (_("%s: warning: unexpected redefinition of `%s'"),
    1878                          bfd_get_filename (abfd), shortname);
    1879                     }
    1880                   else
    1881                     {
    1882                       if (! (_bfd_generic_link_add_one_symbol
    1883                              (info, abfd, shortname, BSF_INDIRECT,
    1884                               bfd_ind_section_ptr, (bfd_vma) 0, name, false,
    1885                               collect, (struct bfd_link_hash_entry **) &hi)))
    1886                         goto error_return;
    1887 
    1888                       /* If there is a duplicate definition somewhere,
    1889                          then HI may not point to an indirect symbol.
    1890                          We will have reported an error to the user in
    1891                          that case.  */
    1892 
    1893                       if (hi->root.type == bfd_link_hash_indirect)
    1894                         {
    1895                           /* If the symbol became indirect, then we
    1896                              assume that we have not seen a definition
    1897                              before.  */
    1898                           BFD_ASSERT ((hi->elf_link_hash_flags
    1899                                        & (ELF_LINK_HASH_DEF_DYNAMIC
    1900                                           | ELF_LINK_HASH_DEF_REGULAR))
    1901                                       == 0);
    1902 
    1903                           (*bed->elf_backend_copy_indirect_symbol) (h, hi);
    1904 
    1905                           /* See if the new flags lead us to realize
    1906                              that the symbol must be dynamic.  */
    1907                           if (! dynsym)
    1908                             {
    1909                               if (! dynamic)
    1910                                 {
    1911                                   if (info->shared
    1912                                       || ((hi->elf_link_hash_flags
    1913                                            & ELF_LINK_HASH_REF_DYNAMIC)
    1914                                           != 0))
    1915                                     dynsym = true;
    1916                                 }
    1917                               else
    1918                                 {
    1919                                   if ((hi->elf_link_hash_flags
    1920                                        & ELF_LINK_HASH_REF_REGULAR) != 0)
    1921                                     dynsym = true;
    1922                                 }
    1923                             }
    1924                         }
    1925                     }
     2235                  nondeflt_vers [nondeflt_vers_cnt++] = h;
    19262236                }
    19272237            }
     
    19302240            {
    19312241              if (! _bfd_elf_link_record_dynamic_symbol (info, h))
    1932                 goto error_return;
     2242                goto error_free_vers;
    19332243              if (h->weakdef != NULL
    19342244                  && ! new_weakdef
    19352245                  && h->weakdef->dynindx == -1)
    19362246                {
    1937                   if (! _bfd_elf_link_record_dynamic_symbol (info,
    1938                                                              h->weakdef))
    1939                     goto error_return;
     2247                  if (! _bfd_elf_link_record_dynamic_symbol (info, h->weakdef))
     2248                    goto error_free_vers;
    19402249                }
    19412250            }
     
    19482257              case STV_INTERNAL:
    19492258              case STV_HIDDEN:
    1950                 h->elf_link_hash_flags |= ELF_LINK_FORCED_LOCAL;
    1951                 (*bed->elf_backend_hide_symbol) (info, h);
     2259                (*bed->elf_backend_hide_symbol) (info, h, TRUE);
    19522260                break;
    19532261              }
     
    19602268              bfd_size_type strindex;
    19612269
     2270              if (! is_elf_hash_table (info))
     2271                goto error_free_vers;
     2272
    19622273              /* The symbol from a DT_NEEDED object is referenced from
    1963                 the regular object to create a dynamic executable. We
     2274                the regular object to create a dynamic executable. We
    19642275                 have to make sure there is a DT_NEEDED entry for it.  */
    19652276
    1966               dt_needed = false;
    1967               oldsize = _bfd_stringtab_size (elf_hash_table (info)->dynstr);
    1968               strindex = _bfd_stringtab_add (elf_hash_table (info)->dynstr,
    1969                                              elf_dt_soname (abfd),
    1970                                              true, false);
     2277              dt_needed = FALSE;
     2278              oldsize = _bfd_elf_strtab_size (hash_table->dynstr);
     2279              strindex = _bfd_elf_strtab_add (hash_table->dynstr,
     2280                                              elf_dt_soname (abfd), FALSE);
    19712281              if (strindex == (bfd_size_type) -1)
    1972                 goto error_return;
    1973 
    1974               if (oldsize
    1975                   == _bfd_stringtab_size (elf_hash_table (info)->dynstr))
     2282                goto error_free_vers;
     2283
     2284              if (oldsize == _bfd_elf_strtab_size (hash_table->dynstr))
    19762285                {
    19772286                  asection *sdyn;
    19782287                  Elf_External_Dyn *dyncon, *dynconend;
    19792288
    1980                   sdyn = bfd_get_section_by_name (elf_hash_table (info)->dynobj,
     2289                  sdyn = bfd_get_section_by_name (hash_table->dynobj,
    19812290                                                  ".dynamic");
    19822291                  BFD_ASSERT (sdyn != NULL);
     
    19892298                      Elf_Internal_Dyn dyn;
    19902299
    1991                       elf_swap_dyn_in (elf_hash_table (info)->dynobj,
     2300                      elf_swap_dyn_in (hash_table->dynobj,
    19922301                                       dyncon, &dyn);
    19932302                      BFD_ASSERT (dyn.d_tag != DT_NEEDED ||
     
    19962305                }
    19972306
    1998               if (! elf_add_dynamic_entry (info, DT_NEEDED, strindex))
    1999                 goto error_return;
     2307              if (! elf_add_dynamic_entry (info, (bfd_vma) DT_NEEDED, strindex))
     2308                goto error_free_vers;
    20002309            }
    20012310        }
    20022311    }
     2312
     2313  /* Now that all the symbols from this input file are created, handle
     2314     .symver foo, foo@BAR such that any relocs against foo become foo@BAR.  */
     2315  if (nondeflt_vers != NULL)
     2316    {
     2317      bfd_size_type cnt, symidx;
     2318
     2319      for (cnt = 0; cnt < nondeflt_vers_cnt; ++cnt)
     2320        {
     2321          struct elf_link_hash_entry *h = nondeflt_vers[cnt], *hi;
     2322          char *shortname, *p;
     2323
     2324          p = strchr (h->root.root.string, ELF_VER_CHR);
     2325          if (p == NULL
     2326              || (h->root.type != bfd_link_hash_defined
     2327                  && h->root.type != bfd_link_hash_defweak))
     2328            continue;
     2329
     2330          amt = p - h->root.root.string;
     2331          shortname = bfd_malloc (amt + 1);
     2332          memcpy (shortname, h->root.root.string, amt);
     2333          shortname[amt] = '\0';
     2334
     2335          hi = (struct elf_link_hash_entry *)
     2336               bfd_link_hash_lookup (info->hash, shortname,
     2337                                     FALSE, FALSE, FALSE);
     2338          if (hi != NULL
     2339              && hi->root.type == h->root.type
     2340              && hi->root.u.def.value == h->root.u.def.value
     2341              && hi->root.u.def.section == h->root.u.def.section)
     2342            {
     2343              (*bed->elf_backend_hide_symbol) (info, hi, TRUE);
     2344              hi->root.type = bfd_link_hash_indirect;
     2345              hi->root.u.i.link = (struct bfd_link_hash_entry *) h;
     2346              (*bed->elf_backend_copy_indirect_symbol) (bed, h, hi);
     2347              sym_hash = elf_sym_hashes (abfd);
     2348              if (sym_hash)
     2349                for (symidx = 0; symidx < extsymcount; ++symidx)
     2350                  if (sym_hash[symidx] == hi)
     2351                    {
     2352                      sym_hash[symidx] = h;
     2353                      break;
     2354                    }
     2355            }
     2356          free (shortname);
     2357        }
     2358      free (nondeflt_vers);
     2359      nondeflt_vers = NULL;
     2360    }
     2361
     2362  if (extversym != NULL)
     2363    {
     2364      free (extversym);
     2365      extversym = NULL;
     2366    }
     2367
     2368  if (isymbuf != NULL)
     2369    free (isymbuf);
     2370  isymbuf = NULL;
    20032371
    20042372  /* Now set the weakdefs field correctly for all the weak defined
     
    20592427
    20602428              /* If the real definition is in the list of dynamic
    2061                 symbols, make sure the weak definition is put there
    2062                 as well.  If we don't do this, then the dynamic
    2063                 loader might not merge the entries for the real
    2064                 definition and the weak definition.  */
     2429                symbols, make sure the weak definition is put there
     2430                as well.  If we don't do this, then the dynamic
     2431                loader might not merge the entries for the real
     2432                definition and the weak definition.  */
    20652433              if (h->dynindx != -1
    20662434                  && hlook->dynindx == -1)
     
    20692437                    goto error_return;
    20702438                }
    2071 
    20722439              break;
    20732440            }
    20742441        }
    2075     }
    2076 
    2077   if (buf != NULL)
    2078     {
    2079       free (buf);
    2080       buf = NULL;
    2081     }
    2082 
    2083   if (extversym != NULL)
    2084     {
    2085       free (extversym);
    2086       extversym = NULL;
    20872442    }
    20882443
     
    21142469        {
    21152470          Elf_Internal_Rela *internal_relocs;
    2116           boolean ok;
     2471          bfd_boolean ok;
    21172472
    21182473          if ((o->flags & SEC_RELOC) == 0
     
    21322487          ok = (*check_relocs) (abfd, info, o, internal_relocs);
    21332488
    2134           if (! info->keep_memory)
     2489          if (elf_section_data (o)->relocs != internal_relocs)
    21352490            free (internal_relocs);
    21362491
     
    21402495    }
    21412496
    2142   /* If this is a non-traditional, non-relocateable link, try to
    2143      optimize the handling of the .stab/.stabstr sections.  */
     2497  /* If this is a non-traditional link, try to optimize the handling
     2498     of the .stab/.stabstr sections.  */
    21442499  if (! dynamic
    2145       && ! info->relocateable
    21462500      && ! info->traditional_format
    21472501      && info->hash->creator->flavour == bfd_target_elf_flavour
     2502      && is_elf_hash_table (info)
    21482503      && (info->strip != strip_all && info->strip != strip_debugger))
    21492504    {
     
    21512506
    21522507      stab = bfd_get_section_by_name (abfd, ".stab");
    2153       if (stab != NULL)
     2508      if (stab != NULL
     2509          && (stab->flags & SEC_MERGE) == 0
     2510          && !bfd_is_abs_section (stab->output_section))
    21542511        {
    21552512          stabstr = bfd_get_section_by_name (abfd, ".stabstr");
     
    21612518              secdata = elf_section_data (stab);
    21622519              if (! _bfd_link_section_stabs (abfd,
    2163                                              &elf_hash_table (info)->stab_info,
     2520                                             & hash_table->stab_info,
    21642521                                             stab, stabstr,
    2165                                              &secdata->stab_info))
     2522                                             &secdata->sec_info))
    21662523                goto error_return;
     2524              if (secdata->sec_info)
     2525                stab->sec_info_type = ELF_INFO_TYPE_STABS;
    21672526            }
    21682527        }
    21692528    }
    21702529
    2171   return true;
    2172 
    2173  error_return:
    2174   if (buf != NULL)
    2175     free (buf);
    2176   if (dynbuf != NULL)
    2177     free (dynbuf);
     2530  if (! info->relocateable && ! dynamic
     2531      && is_elf_hash_table (info))
     2532    {
     2533      asection *s;
     2534
     2535      for (s = abfd->sections; s != NULL; s = s->next)
     2536        if ((s->flags & SEC_MERGE) != 0
     2537            && !bfd_is_abs_section (s->output_section))
     2538          {
     2539            struct bfd_elf_section_data *secdata;
     2540
     2541            secdata = elf_section_data (s);
     2542            if (! _bfd_merge_section (abfd,
     2543                                      & hash_table->merge_info,
     2544                                      s, &secdata->sec_info))
     2545              goto error_return;
     2546            else if (secdata->sec_info)
     2547              s->sec_info_type = ELF_INFO_TYPE_MERGE;
     2548          }
     2549    }
     2550
     2551  if (is_elf_hash_table (info))
     2552    {
     2553      /* Add this bfd to the loaded list.  */
     2554      struct elf_link_loaded_list *n;
     2555
     2556      n = ((struct elf_link_loaded_list *)
     2557           bfd_alloc (abfd, sizeof (struct elf_link_loaded_list)));
     2558      if (n == NULL)
     2559        goto error_return;
     2560      n->abfd = abfd;
     2561      n->next = hash_table->loaded;
     2562      hash_table->loaded = n;
     2563    }
     2564
     2565  return TRUE;
     2566
     2567 error_free_vers:
     2568  if (nondeflt_vers != NULL)
     2569    free (nondeflt_vers);
    21782570  if (extversym != NULL)
    21792571    free (extversym);
    2180   return false;
     2572 error_free_sym:
     2573  if (isymbuf != NULL)
     2574    free (isymbuf);
     2575 error_return:
     2576  return FALSE;
    21812577}
    21822578
     
    21882584   actual contents and size of these sections later.  */
    21892585
    2190 boolean
     2586bfd_boolean
    21912587elf_link_create_dynamic_sections (abfd, info)
    21922588     bfd *abfd;
     
    21962592  register asection *s;
    21972593  struct elf_link_hash_entry *h;
     2594  struct bfd_link_hash_entry *bh;
    21982595  struct elf_backend_data *bed;
    21992596
     2597  if (! is_elf_hash_table (info))
     2598    return FALSE;
     2599
    22002600  if (elf_hash_table (info)->dynamic_sections_created)
    2201     return true;
     2601    return TRUE;
    22022602
    22032603  /* Make sure that all dynamic sections use the same input BFD.  */
     
    22192619      if (s == NULL
    22202620          || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY))
    2221         return false;
     2621        return FALSE;
     2622    }
     2623
     2624  if (! info->traditional_format
     2625      && info->hash->creator->flavour == bfd_target_elf_flavour)
     2626    {
     2627      s = bfd_make_section (abfd, ".eh_frame_hdr");
     2628      if (s == NULL
     2629          || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
     2630          || ! bfd_set_section_alignment (abfd, s, 2))
     2631        return FALSE;
     2632      elf_hash_table (info)->eh_info.hdr_sec = s;
    22222633    }
    22232634
     
    22282639      || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
    22292640      || ! bfd_set_section_alignment (abfd, s, LOG_FILE_ALIGN))
    2230     return false;
     2641    return FALSE;
    22312642
    22322643  s = bfd_make_section (abfd, ".gnu.version");
     
    22342645      || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
    22352646      || ! bfd_set_section_alignment (abfd, s, 1))
    2236     return false;
     2647    return FALSE;
    22372648
    22382649  s = bfd_make_section (abfd, ".gnu.version_r");
     
    22402651      || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
    22412652      || ! bfd_set_section_alignment (abfd, s, LOG_FILE_ALIGN))
    2242     return false;
     2653    return FALSE;
    22432654
    22442655  s = bfd_make_section (abfd, ".dynsym");
     
    22462657      || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
    22472658      || ! bfd_set_section_alignment (abfd, s, LOG_FILE_ALIGN))
    2248     return false;
     2659    return FALSE;
    22492660
    22502661  s = bfd_make_section (abfd, ".dynstr");
    22512662  if (s == NULL
    22522663      || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY))
    2253     return false;
     2664    return FALSE;
    22542665
    22552666  /* Create a strtab to hold the dynamic symbol names.  */
    22562667  if (elf_hash_table (info)->dynstr == NULL)
    22572668    {
    2258       elf_hash_table (info)->dynstr = elf_stringtab_init ();
     2669      elf_hash_table (info)->dynstr = _bfd_elf_strtab_init ();
    22592670      if (elf_hash_table (info)->dynstr == NULL)
    2260         return false;
     2671        return FALSE;
    22612672    }
    22622673
     
    22652676      || ! bfd_set_section_flags (abfd, s, flags)
    22662677      || ! bfd_set_section_alignment (abfd, s, LOG_FILE_ALIGN))
    2267     return false;
     2678    return FALSE;
    22682679
    22692680  /* The special symbol _DYNAMIC is always set to the start of the
     
    22752686     is no .dynamic section, since on some ELF platforms the start up
    22762687     code examines it to decide how to initialize the process.  */
    2277   h = NULL;
     2688  bh = NULL;
    22782689  if (! (_bfd_generic_link_add_one_symbol
    22792690         (info, abfd, "_DYNAMIC", BSF_GLOBAL, s, (bfd_vma) 0,
    2280           (const char *) NULL, false, get_elf_backend_data (abfd)->collect,
    2281           (struct bfd_link_hash_entry **) &h)))
    2282     return false;
     2691          (const char *) 0, FALSE, get_elf_backend_data (abfd)->collect, &bh)))
     2692    return FALSE;
     2693  h = (struct elf_link_hash_entry *) bh;
    22832694  h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
    22842695  h->type = STT_OBJECT;
     
    22862697  if (info->shared
    22872698      && ! _bfd_elf_link_record_dynamic_symbol (info, h))
    2288     return false;
     2699    return FALSE;
    22892700
    22902701  bed = get_elf_backend_data (abfd);
     
    22942705      || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
    22952706      || ! bfd_set_section_alignment (abfd, s, LOG_FILE_ALIGN))
    2296     return false;
     2707    return FALSE;
    22972708  elf_section_data (s)->this_hdr.sh_entsize = bed->s->sizeof_hash_entry;
    22982709
     
    23012712     the .got and .plt sections.  */
    23022713  if (! (*bed->elf_backend_create_dynamic_sections) (abfd, info))
    2303     return false;
    2304 
    2305   elf_hash_table (info)->dynamic_sections_created = true;
    2306 
    2307   return true;
     2714    return FALSE;
     2715
     2716  elf_hash_table (info)->dynamic_sections_created = TRUE;
     2717
     2718  return TRUE;
    23082719}
    23092720
    23102721/* Add an entry to the .dynamic table.  */
    23112722
    2312 boolean
     2723bfd_boolean
    23132724elf_add_dynamic_entry (info, tag, val)
    23142725     struct bfd_link_info *info;
     
    23192730  bfd *dynobj;
    23202731  asection *s;
    2321   size_t newsize;
     2732  bfd_size_type newsize;
    23222733  bfd_byte *newcontents;
     2734
     2735  if (! is_elf_hash_table (info))
     2736    return FALSE;
    23232737
    23242738  dynobj = elf_hash_table (info)->dynobj;
     
    23302744  newcontents = (bfd_byte *) bfd_realloc (s->contents, newsize);
    23312745  if (newcontents == NULL)
    2332     return false;
     2746    return FALSE;
    23332747
    23342748  dyn.d_tag = tag;
     
    23402754  s->contents = newcontents;
    23412755
    2342   return true;
    2343 }
    2344 
    2345 /* Record a new local dynamic symbol.  */
    2346 
    2347 boolean
    2348 elf_link_record_local_dynamic_symbol (info, input_bfd, input_indx)
    2349      struct bfd_link_info *info;
    2350      bfd *input_bfd;
    2351      long input_indx;
    2352 {
    2353   struct elf_link_local_dynamic_entry *entry;
    2354   struct elf_link_hash_table *eht;
    2355   struct bfd_strtab_hash *dynstr;
    2356   Elf_External_Sym esym;
    2357   unsigned long dynstr_index;
    2358   char *name;
    2359 
    2360   /* See if the entry exists already.  */
    2361   for (entry = elf_hash_table (info)->dynlocal; entry ; entry = entry->next)
    2362     if (entry->input_bfd == input_bfd && entry->input_indx == input_indx)
    2363       return true;
    2364 
    2365   entry = (struct elf_link_local_dynamic_entry *)
    2366     bfd_alloc (input_bfd, sizeof (*entry));
    2367   if (entry == NULL)
    2368     return false;
    2369 
    2370   /* Go find the symbol, so that we can find it's name.  */
    2371   if (bfd_seek (input_bfd,
    2372                 (elf_tdata (input_bfd)->symtab_hdr.sh_offset
    2373                  + input_indx * sizeof (Elf_External_Sym)),
    2374                 SEEK_SET) != 0
    2375       || (bfd_read (&esym, sizeof (Elf_External_Sym), 1, input_bfd)
    2376           != sizeof (Elf_External_Sym)))
    2377     return false;
    2378   elf_swap_symbol_in (input_bfd, &esym, &entry->isym);
    2379 
    2380   name = (bfd_elf_string_from_elf_section
    2381           (input_bfd, elf_tdata (input_bfd)->symtab_hdr.sh_link,
    2382            entry->isym.st_name));
    2383 
    2384   dynstr = elf_hash_table (info)->dynstr;
    2385   if (dynstr == NULL)
    2386     {
    2387       /* Create a strtab to hold the dynamic symbol names.  */
    2388       elf_hash_table (info)->dynstr = dynstr = _bfd_elf_stringtab_init ();
    2389       if (dynstr == NULL)
    2390         return false;
    2391     }
    2392 
    2393   dynstr_index = _bfd_stringtab_add (dynstr, name, true, false);
    2394   if (dynstr_index == (unsigned long) -1)
    2395     return false;
    2396   entry->isym.st_name = dynstr_index;
    2397 
    2398   eht = elf_hash_table (info);
    2399 
    2400   entry->next = eht->dynlocal;
    2401   eht->dynlocal = entry;
    2402   entry->input_bfd = input_bfd;
    2403   entry->input_indx = input_indx;
    2404   eht->dynsymcount++;
    2405 
    2406   /* Whatever binding the symbol had before, it's now local.  */
    2407   entry->isym.st_info
    2408     = ELF_ST_INFO (STB_LOCAL, ELF_ST_TYPE (entry->isym.st_info));
    2409 
    2410   /* The dynindx will be set at the end of size_dynamic_sections.  */
    2411 
    2412   return true;
     2756  return TRUE;
    24132757}
    24142758
     
    24212765   relocations should be stored.
    24222766
    2423    Returns false if something goes wrong.  */
    2424 
    2425 static boolean
     2767   Returns FALSE if something goes wrong.  */
     2768
     2769static bfd_boolean
    24262770elf_link_read_relocs_from_section (abfd, shdr, external_relocs,
    24272771                                   internal_relocs)
     
    24322776{
    24332777  struct elf_backend_data *bed;
     2778  void (*swap_in) PARAMS ((bfd *, const bfd_byte *, Elf_Internal_Rela *));
     2779  const bfd_byte *erela;
     2780  const bfd_byte *erelaend;
     2781  Elf_Internal_Rela *irela;
    24342782
    24352783  /* If there aren't any relocations, that's OK.  */
    24362784  if (!shdr)
    2437     return true;
     2785    return TRUE;
    24382786
    24392787  /* Position ourselves at the start of the section.  */
    24402788  if (bfd_seek (abfd, shdr->sh_offset, SEEK_SET) != 0)
    2441     return false;
     2789    return FALSE;
    24422790
    24432791  /* Read the relocations.  */
    2444   if (bfd_read (external_relocs, 1, shdr->sh_size, abfd)
    2445       != shdr->sh_size)
    2446     return false;
     2792  if (bfd_bread (external_relocs, shdr->sh_size, abfd) != shdr->sh_size)
     2793    return FALSE;
    24472794
    24482795  bed = get_elf_backend_data (abfd);
     
    24502797  /* Convert the external relocations to the internal format.  */
    24512798  if (shdr->sh_entsize == sizeof (Elf_External_Rel))
    2452     {
    2453       Elf_External_Rel *erel;
    2454       Elf_External_Rel *erelend;
    2455       Elf_Internal_Rela *irela;
    2456       Elf_Internal_Rel *irel;
    2457 
    2458       erel = (Elf_External_Rel *) external_relocs;
    2459       erelend = erel + NUM_SHDR_ENTRIES (shdr);
    2460       irela = internal_relocs;
    2461       irel = bfd_alloc (abfd, (bed->s->int_rels_per_ext_rel
    2462                                * sizeof (Elf_Internal_Rel)));
    2463       for (; erel < erelend; erel++, irela += bed->s->int_rels_per_ext_rel)
    2464         {
    2465           unsigned int i;
    2466 
    2467           if (bed->s->swap_reloc_in)
    2468             (*bed->s->swap_reloc_in) (abfd, (bfd_byte *) erel, irel);
    2469           else
    2470             elf_swap_reloc_in (abfd, erel, irel);
    2471 
    2472           for (i = 0; i < bed->s->int_rels_per_ext_rel; ++i)
    2473             {
    2474               irela[i].r_offset = irel[i].r_offset;
    2475               irela[i].r_info = irel[i].r_info;
    2476               irela[i].r_addend = 0;
    2477             }
    2478         }
    2479     }
     2799    swap_in = bed->s->swap_reloc_in;
     2800  else if (shdr->sh_entsize == sizeof (Elf_External_Rela))
     2801    swap_in = bed->s->swap_reloca_in;
    24802802  else
    24812803    {
    2482       Elf_External_Rela *erela;
    2483       Elf_External_Rela *erelaend;
    2484       Elf_Internal_Rela *irela;
    2485 
    2486       BFD_ASSERT (shdr->sh_entsize == sizeof (Elf_External_Rela));
    2487 
    2488       erela = (Elf_External_Rela *) external_relocs;
    2489       erelaend = erela + NUM_SHDR_ENTRIES (shdr);
    2490       irela = internal_relocs;
    2491       for (; erela < erelaend; erela++, irela += bed->s->int_rels_per_ext_rel)
    2492         {
    2493           if (bed->s->swap_reloca_in)
    2494             (*bed->s->swap_reloca_in) (abfd, (bfd_byte *) erela, irela);
    2495           else
    2496             elf_swap_reloca_in (abfd, erela, irela);
    2497         }
    2498     }
    2499 
    2500   return true;
     2804      bfd_set_error (bfd_error_wrong_format);
     2805      return FALSE;
     2806    }
     2807
     2808  erela = external_relocs;
     2809  erelaend = erela + NUM_SHDR_ENTRIES (shdr) * shdr->sh_entsize;
     2810  irela = internal_relocs;
     2811  while (erela < erelaend)
     2812    {
     2813      (*swap_in) (abfd, erela, irela);
     2814      irela += bed->s->int_rels_per_ext_rel;
     2815      erela += shdr->sh_entsize;
     2816    }
     2817
     2818  return TRUE;
    25012819}
    25022820
     
    25182836     PTR external_relocs;
    25192837     Elf_Internal_Rela *internal_relocs;
    2520      boolean keep_memory;
     2838     bfd_boolean keep_memory;
    25212839{
    25222840  Elf_Internal_Shdr *rel_hdr;
     
    25352853  if (internal_relocs == NULL)
    25362854    {
    2537       size_t size;
    2538 
    2539       size = (o->reloc_count * bed->s->int_rels_per_ext_rel
    2540               * sizeof (Elf_Internal_Rela));
     2855      bfd_size_type size;
     2856
     2857      size = o->reloc_count;
     2858      size *= bed->s->int_rels_per_ext_rel * sizeof (Elf_Internal_Rela);
    25412859      if (keep_memory)
    25422860        internal_relocs = (Elf_Internal_Rela *) bfd_alloc (abfd, size);
     
    25492867  if (external_relocs == NULL)
    25502868    {
    2551       size_t size = (size_t) rel_hdr->sh_size;
     2869      bfd_size_type size = rel_hdr->sh_size;
    25522870
    25532871      if (elf_section_data (o)->rel_hdr2)
    2554         size += (size_t) elf_section_data (o)->rel_hdr2->sh_size;
     2872        size += elf_section_data (o)->rel_hdr2->sh_size;
    25552873      alloc1 = (PTR) bfd_malloc (size);
    25562874      if (alloc1 == NULL)
     
    25952913   this in case some dynamic object refers to this symbol.  */
    25962914
    2597 /*ARGSUSED*/
    2598 boolean
     2915bfd_boolean
    25992916NAME(bfd_elf,record_link_assignment) (output_bfd, info, name, provide)
    26002917     bfd *output_bfd ATTRIBUTE_UNUSED;
    26012918     struct bfd_link_info *info;
    26022919     const char *name;
    2603      boolean provide;
     2920     bfd_boolean provide;
    26042921{
    26052922  struct elf_link_hash_entry *h;
    26062923
    26072924  if (info->hash->creator->flavour != bfd_target_elf_flavour)
    2608     return true;
    2609 
    2610   h = elf_link_hash_lookup (elf_hash_table (info), name, true, true, false);
     2925    return TRUE;
     2926
     2927  h = elf_link_hash_lookup (elf_hash_table (info), name, TRUE, TRUE, FALSE);
    26112928  if (h == NULL)
    2612     return false;
     2929    return FALSE;
    26132930
    26142931  if (h->root.type == bfd_link_hash_new)
    2615     h->elf_link_hash_flags &=~ ELF_LINK_NON_ELF;
     2932    h->elf_link_hash_flags &= ~ELF_LINK_NON_ELF;
    26162933
    26172934  /* If this symbol is being provided by the linker script, and it is
     
    26352952  h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
    26362953
    2637   /* When possible, keep the original type of the symbol */
    2638   if (h->type == STT_NOTYPE)
    2639     h->type = STT_OBJECT;
    2640 
    26412954  if (((h->elf_link_hash_flags & (ELF_LINK_HASH_DEF_DYNAMIC
    26422955                                  | ELF_LINK_HASH_REF_DYNAMIC)) != 0
     
    26452958    {
    26462959      if (! _bfd_elf_link_record_dynamic_symbol (info, h))
    2647         return false;
     2960        return FALSE;
    26482961
    26492962      /* If this is a weak defined symbol, and we know a corresponding
     
    26542967        {
    26552968          if (! _bfd_elf_link_record_dynamic_symbol (info, h->weakdef))
    2656             return false;
    2657         }
    2658     }
    2659 
    2660   return true;
     2969            return FALSE;
     2970        }
     2971    }
     2972
     2973  return TRUE;
    26612974}
    26622975
     
    26732986  /* Version tree.  */
    26742987  struct bfd_elf_version_tree *verdefs;
    2675   /* Whether we are exporting all dynamic symbols.  */
    2676   boolean export_dynamic;
    26772988  /* Whether we had a failure.  */
    2678   boolean failed;
     2989  bfd_boolean failed;
    26792990};
    26802991
     
    26913002  unsigned int vers;
    26923003  /* Whether we had a failure.  */
    2693   boolean failed;
     3004  bfd_boolean failed;
    26943005};
    26953006
     
    27233034  unsigned long int *hashcodesp;
    27243035  unsigned long int i;
     3036  bfd_size_type amt;
    27253037
    27263038  /* Compute the hash values for all exported symbols.  At the same
    27273039     time store the values in an array so that we could use them for
    27283040     optimizations.  */
    2729   hashcodes = (unsigned long int *) bfd_malloc (dynsymcount
    2730                                                 * sizeof (unsigned long int));
     3041  amt = dynsymcount;
     3042  amt *= sizeof (unsigned long int);
     3043  hashcodes = (unsigned long int *) bfd_malloc (amt);
    27313044  if (hashcodes == NULL)
    27323045    return 0;
     
    27373050                          elf_collect_hash_codes, &hashcodesp);
    27383051
    2739 /* We have a problem here.  The following code to optimize the table
    2740    size requires an integer type with more the 32 bits.  If
    2741    BFD_HOST_U_64_BIT is set we know about such a type.  */
     3052  /* We have a problem here.  The following code to optimize the table
     3053     size requires an integer type with more the 32 bits.  If
     3054     BFD_HOST_U_64_BIT is set we know about such a type.  */
    27423055#ifdef BFD_HOST_U_64_BIT
    2743   if (info->optimize == true)
     3056  if (info->optimize)
    27443057    {
    27453058      unsigned long int nsyms = hashcodesp - hashcodes;
     
    27593072      /* Create array where we count the collisions in.  We must use bfd_malloc
    27603073         since the size could be large.  */
    2761       counts = (unsigned long int *) bfd_malloc (maxsize
    2762                                                  * sizeof (unsigned long int));
     3074      amt = maxsize;
     3075      amt *= sizeof (unsigned long int);
     3076      counts = (unsigned long int *) bfd_malloc (amt);
    27633077      if (counts == NULL)
    27643078        {
     
    28543168   addresses of the various sections.  */
    28553169
    2856 boolean
     3170bfd_boolean
    28573171NAME(bfd_elf,size_dynamic_sections) (output_bfd, soname, rpath,
    2858                                      export_dynamic, filter_shlib,
     3172                                     filter_shlib,
    28593173                                     auxiliary_filters, info, sinterpptr,
    28603174                                     verdefs)
     
    28623176     const char *soname;
    28633177     const char *rpath;
    2864      boolean export_dynamic;
    28653178     const char *filter_shlib;
    28663179     const char * const *auxiliary_filters;
     
    28793192
    28803193  if (info->hash->creator->flavour != bfd_target_elf_flavour)
    2881     return true;
     3194    return TRUE;
     3195
     3196  if (! is_elf_hash_table (info))
     3197    return TRUE;
     3198
     3199  /* Any syms created from now on start with -1 in
     3200     got.refcount/offset and plt.refcount/offset.  */
     3201  elf_hash_table (info)->init_refcount = elf_hash_table (info)->init_offset;
    28823202
    28833203  /* The backend may have to create some sections regardless of whether
     
    28863206  if (bed->elf_backend_always_size_sections
    28873207      && ! (*bed->elf_backend_always_size_sections) (output_bfd, info))
    2888     return false;
     3208    return FALSE;
    28893209
    28903210  dynobj = elf_hash_table (info)->dynobj;
     
    28933213     do here.  */
    28943214  if (dynobj == NULL)
    2895     return true;
     3215    return TRUE;
     3216
     3217  if (! _bfd_elf_maybe_strip_eh_frame_hdr (info))
     3218    return FALSE;
    28963219
    28973220  if (elf_hash_table (info)->dynamic_sections_created)
     
    29003223      struct elf_link_hash_entry *h;
    29013224      asection *dynstr;
     3225      struct bfd_elf_version_tree *t;
     3226      struct bfd_elf_version_expr *d;
     3227      bfd_boolean all_defined;
    29023228
    29033229      *sinterpptr = bfd_get_section_by_name (dynobj, ".interp");
     
    29063232      if (soname != NULL)
    29073233        {
    2908           soname_indx = _bfd_stringtab_add (elf_hash_table (info)->dynstr,
    2909                                             soname, true, true);
     3234          soname_indx = _bfd_elf_strtab_add (elf_hash_table (info)->dynstr,
     3235                                             soname, TRUE);
    29103236          if (soname_indx == (bfd_size_type) -1
    2911               || ! elf_add_dynamic_entry (info, DT_SONAME, soname_indx))
    2912             return false;
     3237              || ! elf_add_dynamic_entry (info, (bfd_vma) DT_SONAME,
     3238                                          soname_indx))
     3239            return FALSE;
    29133240        }
    29143241
    29153242      if (info->symbolic)
    29163243        {
    2917           if (! elf_add_dynamic_entry (info, DT_SYMBOLIC, 0))
    2918             return false;
     3244          if (! elf_add_dynamic_entry (info, (bfd_vma) DT_SYMBOLIC,
     3245                                       (bfd_vma) 0))
     3246            return FALSE;
    29193247          info->flags |= DF_SYMBOLIC;
    29203248        }
     
    29243252          bfd_size_type indx;
    29253253
    2926           indx = _bfd_stringtab_add (elf_hash_table (info)->dynstr, rpath,
    2927                                      true, true);
     3254          indx = _bfd_elf_strtab_add (elf_hash_table (info)->dynstr, rpath,
     3255                                      TRUE);
     3256          if (info->new_dtags)
     3257            _bfd_elf_strtab_addref (elf_hash_table (info)->dynstr, indx);
    29283258          if (indx == (bfd_size_type) -1
    2929               || ! elf_add_dynamic_entry (info, DT_RPATH, indx)
     3259              || ! elf_add_dynamic_entry (info, (bfd_vma) DT_RPATH, indx)
    29303260              || (info->new_dtags
    2931                   && ! elf_add_dynamic_entry (info, DT_RUNPATH, indx)))
    2932             return false;
     3261                  && ! elf_add_dynamic_entry (info, (bfd_vma) DT_RUNPATH,
     3262                                              indx)))
     3263            return FALSE;
    29333264        }
    29343265
     
    29373268          bfd_size_type indx;
    29383269
    2939           indx = _bfd_stringtab_add (elf_hash_table (info)->dynstr,
    2940                                      filter_shlib, true, true);
     3270          indx = _bfd_elf_strtab_add (elf_hash_table (info)->dynstr,
     3271                                      filter_shlib, TRUE);
    29413272          if (indx == (bfd_size_type) -1
    2942               || ! elf_add_dynamic_entry (info, DT_FILTER, indx))
    2943             return false;
     3273              || ! elf_add_dynamic_entry (info, (bfd_vma) DT_FILTER, indx))
     3274            return FALSE;
    29443275        }
    29453276
     
    29523283              bfd_size_type indx;
    29533284
    2954               indx = _bfd_stringtab_add (elf_hash_table (info)->dynstr,
    2955                                          *p, true, true);
     3285              indx = _bfd_elf_strtab_add (elf_hash_table (info)->dynstr,
     3286                                          *p, TRUE);
    29563287              if (indx == (bfd_size_type) -1
    2957                   || ! elf_add_dynamic_entry (info, DT_AUXILIARY, indx))
    2958                 return false;
     3288                  || ! elf_add_dynamic_entry (info, (bfd_vma) DT_AUXILIARY,
     3289                                              indx))
     3290                return FALSE;
    29593291            }
    29603292        }
    29613293
    29623294      eif.info = info;
    2963       eif.failed = false;
     3295      eif.verdefs = verdefs;
     3296      eif.failed = FALSE;
    29643297
    29653298      /* If we are supposed to export all symbols into the dynamic symbol
    2966         table (this is not the normal case), then do so.  */
    2967       if (export_dynamic)
     3299        table (this is not the normal case), then do so.  */
     3300      if (info->export_dynamic)
    29683301        {
    29693302          elf_link_hash_traverse (elf_hash_table (info), elf_export_symbol,
    2970                                   (PTR) &eif);
     3303                                  (PTR) &eif);
    29713304          if (eif.failed)
    2972             return false;
    2973         }
     3305            return FALSE;
     3306        }
     3307
     3308      /* Make all global versions with definiton.  */
     3309      for (t = verdefs; t != NULL; t = t->next)
     3310        for (d = t->globals; d != NULL; d = d->next)
     3311          if (!d->symver && strchr (d->pattern, '*') == NULL)
     3312            {
     3313              const char *verstr, *name;
     3314              size_t namelen, verlen, newlen;
     3315              char *newname, *p;
     3316              struct elf_link_hash_entry *newh;
     3317
     3318              name = d->pattern;
     3319              namelen = strlen (name);
     3320              verstr = t->name;
     3321              verlen = strlen (verstr);
     3322              newlen = namelen + verlen + 3;
     3323
     3324              newname = (char *) bfd_malloc ((bfd_size_type) newlen);
     3325              if (newname == NULL)
     3326                return FALSE;
     3327              memcpy (newname, name, namelen);
     3328
     3329              /* Check the hidden versioned definition.  */
     3330              p = newname + namelen;
     3331              *p++ = ELF_VER_CHR;
     3332              memcpy (p, verstr, verlen + 1);
     3333              newh = elf_link_hash_lookup (elf_hash_table (info),
     3334                                           newname, FALSE, FALSE,
     3335                                           FALSE);
     3336              if (newh == NULL
     3337                  || (newh->root.type != bfd_link_hash_defined
     3338                      && newh->root.type != bfd_link_hash_defweak))
     3339                {
     3340                  /* Check the default versioned definition.  */
     3341                  *p++ = ELF_VER_CHR;
     3342                  memcpy (p, verstr, verlen + 1);
     3343                  newh = elf_link_hash_lookup (elf_hash_table (info),
     3344                                               newname, FALSE, FALSE,
     3345                                               FALSE);
     3346                }
     3347              free (newname);
     3348
     3349              /* Mark this version if there is a definition and it is
     3350                 not defined in a shared object.  */
     3351              if (newh != NULL
     3352                  && ((newh->elf_link_hash_flags
     3353                       & ELF_LINK_HASH_DEF_DYNAMIC) == 0)
     3354                  && (newh->root.type == bfd_link_hash_defined
     3355                      || newh->root.type == bfd_link_hash_defweak))
     3356                d->symver = 1;
     3357            }
    29743358
    29753359      /* Attach all the symbols to their version information.  */
     
    29773361      asvinfo.info = info;
    29783362      asvinfo.verdefs = verdefs;
    2979       asvinfo.export_dynamic = export_dynamic;
    2980       asvinfo.failed = false;
     3363      asvinfo.failed = FALSE;
    29813364
    29823365      elf_link_hash_traverse (elf_hash_table (info),
     
    29843367                              (PTR) &asvinfo);
    29853368      if (asvinfo.failed)
    2986         return false;
     3369        return FALSE;
     3370
     3371      if (!info->allow_undefined_version)
     3372        {
     3373          /* Check if all global versions have a definiton.  */
     3374          all_defined = TRUE;
     3375          for (t = verdefs; t != NULL; t = t->next)
     3376            for (d = t->globals; d != NULL; d = d->next)
     3377              if (!d->symver && !d->script
     3378                  && strchr (d->pattern, '*') == NULL)
     3379                {
     3380                  (*_bfd_error_handler)
     3381                    (_("%s: undefined version: %s"),
     3382                     d->pattern, t->name);
     3383                  all_defined = FALSE;
     3384                }
     3385
     3386          if (!all_defined)
     3387            {
     3388              bfd_set_error (bfd_error_bad_value);
     3389              return FALSE;
     3390            }
     3391        }
    29873392
    29883393      /* Find all symbols which were defined in a dynamic object and make
     
    29923397                              (PTR) &eif);
    29933398      if (eif.failed)
    2994         return false;
     3399        return FALSE;
    29953400
    29963401      /* Add some entries to the .dynamic section.  We fill in some of the
     
    30023407      h = (info->init_function
    30033408           ? elf_link_hash_lookup (elf_hash_table (info),
    3004                                    info->init_function, false,
    3005                                    false, false)
     3409                                   info->init_function, FALSE,
     3410                                   FALSE, FALSE)
    30063411           : NULL);
    30073412      if (h != NULL
     
    30093414                                        | ELF_LINK_HASH_DEF_REGULAR)) != 0)
    30103415        {
    3011           if (! elf_add_dynamic_entry (info, DT_INIT, 0))
    3012             return false;
     3416          if (! elf_add_dynamic_entry (info, (bfd_vma) DT_INIT, (bfd_vma) 0))
     3417            return FALSE;
    30133418        }
    30143419      h = (info->fini_function
    30153420           ? elf_link_hash_lookup (elf_hash_table (info),
    3016                                    info->fini_function, false,
    3017                                    false, false)
     3421                                   info->fini_function, FALSE,
     3422                                   FALSE, FALSE)
    30183423           : NULL);
    30193424      if (h != NULL
     
    30213426                                        | ELF_LINK_HASH_DEF_REGULAR)) != 0)
    30223427        {
    3023           if (! elf_add_dynamic_entry (info, DT_FINI, 0))
    3024             return false;
     3428          if (! elf_add_dynamic_entry (info, (bfd_vma) DT_FINI, (bfd_vma) 0))
     3429            return FALSE;
     3430        }
     3431
     3432      if (bfd_get_section_by_name (output_bfd, ".preinit_array") != NULL)
     3433        {
     3434          /* DT_PREINIT_ARRAY is not allowed in shared library.  */
     3435          if (info->shared)
     3436            {
     3437              bfd *sub;
     3438              asection *o;
     3439
     3440              for (sub = info->input_bfds; sub != NULL;
     3441                   sub = sub->link_next)
     3442                for (o = sub->sections; o != NULL; o = o->next)
     3443                  if (elf_section_data (o)->this_hdr.sh_type
     3444                      == SHT_PREINIT_ARRAY)
     3445                    {
     3446                      (*_bfd_error_handler)
     3447                        (_("%s: .preinit_array section is not allowed in DSO"),
     3448                         bfd_archive_filename (sub));
     3449                      break;
     3450                    }
     3451
     3452              bfd_set_error (bfd_error_nonrepresentable_section);
     3453              return FALSE;
     3454            }
     3455
     3456          if (!elf_add_dynamic_entry (info, (bfd_vma) DT_PREINIT_ARRAY,
     3457                                      (bfd_vma) 0)
     3458              || !elf_add_dynamic_entry (info, (bfd_vma) DT_PREINIT_ARRAYSZ,
     3459                                         (bfd_vma) 0))
     3460            return FALSE;
     3461        }
     3462      if (bfd_get_section_by_name (output_bfd, ".init_array") != NULL)
     3463        {
     3464          if (!elf_add_dynamic_entry (info, (bfd_vma) DT_INIT_ARRAY,
     3465                                      (bfd_vma) 0)
     3466              || !elf_add_dynamic_entry (info, (bfd_vma) DT_INIT_ARRAYSZ,
     3467                                         (bfd_vma) 0))
     3468            return FALSE;
     3469        }
     3470      if (bfd_get_section_by_name (output_bfd, ".fini_array") != NULL)
     3471        {
     3472          if (!elf_add_dynamic_entry (info, (bfd_vma) DT_FINI_ARRAY,
     3473                                      (bfd_vma) 0)
     3474              || !elf_add_dynamic_entry (info, (bfd_vma) DT_FINI_ARRAYSZ,
     3475                                         (bfd_vma) 0))
     3476            return FALSE;
    30253477        }
    30263478
     
    30343486          bfd_size_type strsize;
    30353487
    3036           strsize = _bfd_stringtab_size (elf_hash_table (info)->dynstr);
    3037           if (! elf_add_dynamic_entry (info, DT_HASH, 0)
    3038               || ! elf_add_dynamic_entry (info, DT_STRTAB, 0)
    3039               || ! elf_add_dynamic_entry (info, DT_SYMTAB, 0)
    3040               || ! elf_add_dynamic_entry (info, DT_STRSZ, strsize)
    3041               || ! elf_add_dynamic_entry (info, DT_SYMENT,
    3042                                           sizeof (Elf_External_Sym)))
    3043             return false;
     3488          strsize = _bfd_elf_strtab_size (elf_hash_table (info)->dynstr);
     3489          if (! elf_add_dynamic_entry (info, (bfd_vma) DT_HASH, (bfd_vma) 0)
     3490              || ! elf_add_dynamic_entry (info, (bfd_vma) DT_STRTAB, (bfd_vma) 0)
     3491              || ! elf_add_dynamic_entry (info, (bfd_vma) DT_SYMTAB, (bfd_vma) 0)
     3492              || ! elf_add_dynamic_entry (info, (bfd_vma) DT_STRSZ, strsize)
     3493              || ! elf_add_dynamic_entry (info, (bfd_vma) DT_SYMENT,
     3494                                          (bfd_vma) sizeof (Elf_External_Sym)))
     3495            return FALSE;
    30443496        }
    30453497    }
     
    30493501  if (bed->elf_backend_size_dynamic_sections
    30503502      && ! (*bed->elf_backend_size_dynamic_sections) (output_bfd, info))
    3051     return false;
     3503    return FALSE;
    30523504
    30533505  if (elf_hash_table (info)->dynamic_sections_created)
    30543506    {
    3055       size_t dynsymcount;
     3507      bfd_size_type dynsymcount;
    30563508      asection *s;
    30573509      size_t bucketcount = 0;
    30583510      size_t hash_entry_size;
     3511      unsigned int dtagcount;
    30593512
    30603513      /* Set up the version definition section.  */
     
    30633516
    30643517      /* We may have created additional version definitions if we are
    3065         just linking a regular application.  */
     3518        just linking a regular application.  */
    30663519      verdefs = asvinfo.verdefs;
     3520
     3521      /* Skip anonymous version tag.  */
     3522      if (verdefs != NULL && verdefs->vernum == 0)
     3523        verdefs = verdefs->next;
    30673524
    30683525      if (verdefs == NULL)
     
    31003557          s->contents = (bfd_byte *) bfd_alloc (output_bfd, s->_raw_size);
    31013558          if (s->contents == NULL && s->_raw_size != 0)
    3102             return false;
     3559            return FALSE;
    31033560
    31043561          /* Fill in the version definition section.  */
     
    31163573          if (soname_indx != (bfd_size_type) -1)
    31173574            {
     3575              _bfd_elf_strtab_addref (elf_hash_table (info)->dynstr,
     3576                                      soname_indx);
    31183577              def.vd_hash = bfd_elf_hash (soname);
    31193578              defaux.vda_name = soname_indx;
     
    31243583              bfd_size_type indx;
    31253584
    3126               name = output_bfd->filename;
     3585              name = basename (output_bfd->filename);
    31273586              def.vd_hash = bfd_elf_hash (name);
    3128               indx = _bfd_stringtab_add (elf_hash_table (info)->dynstr,
    3129                                             name, true, false);
     3587              indx = _bfd_elf_strtab_add (elf_hash_table (info)->dynstr,
     3588                                          name, FALSE);
    31303589              if (indx == (bfd_size_type) -1)
    3131                 return false;
     3590                return FALSE;
    31323591              defaux.vda_name = indx;
    31333592            }
     
    31353594
    31363595          _bfd_elf_swap_verdef_out (output_bfd, &def,
    3137                                     (Elf_External_Verdef *)p);
     3596                                    (Elf_External_Verdef *) p);
    31383597          p += sizeof (Elf_External_Verdef);
    31393598          _bfd_elf_swap_verdaux_out (output_bfd, &defaux,
     
    31463605              struct bfd_elf_version_deps *n;
    31473606              struct elf_link_hash_entry *h;
     3607              struct bfd_link_hash_entry *bh;
    31483608
    31493609              cdeps = 0;
     
    31523612
    31533613              /* Add a symbol representing this version.  */
    3154               h = NULL;
     3614              bh = NULL;
    31553615              if (! (_bfd_generic_link_add_one_symbol
    31563616                     (info, dynobj, t->name, BSF_GLOBAL, bfd_abs_section_ptr,
    3157                       (bfd_vma) 0, (const char *) NULL, false,
    3158                       get_elf_backend_data (dynobj)->collect,
    3159                       (struct bfd_link_hash_entry **) &h)))
    3160                 return false;
     3617                      (bfd_vma) 0, (const char *) NULL, FALSE,
     3618                      get_elf_backend_data (dynobj)->collect, &bh)))
     3619                return FALSE;
     3620              h = (struct elf_link_hash_entry *) bh;
    31613621              h->elf_link_hash_flags &= ~ ELF_LINK_NON_ELF;
    31623622              h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
     
    31653625
    31663626              if (! _bfd_elf_link_record_dynamic_symbol (info, h))
    3167                 return false;
     3627                return FALSE;
    31683628
    31693629              def.vd_version = VER_DEF_CURRENT;
     
    31863646
    31873647              defaux.vda_name = h->dynstr_index;
     3648              _bfd_elf_strtab_addref (elf_hash_table (info)->dynstr,
     3649                                      h->dynstr_index);
    31883650              if (t->deps == NULL)
    31893651                defaux.vda_next = 0;
     
    32053667                    }
    32063668                  else
    3207                     defaux.vda_name = n->version_needed->name_indx;
     3669                    {
     3670                      defaux.vda_name = n->version_needed->name_indx;
     3671                      _bfd_elf_strtab_addref (elf_hash_table (info)->dynstr,
     3672                                              defaux.vda_name);
     3673                    }
    32083674                  if (n->next == NULL)
    32093675                    defaux.vda_next = 0;
     
    32173683            }
    32183684
    3219           if (! elf_add_dynamic_entry (info, DT_VERDEF, 0)
    3220               || ! elf_add_dynamic_entry (info, DT_VERDEFNUM, cdefs))
    3221             return false;
     3685          if (! elf_add_dynamic_entry (info, (bfd_vma) DT_VERDEF, (bfd_vma) 0)
     3686              || ! elf_add_dynamic_entry (info, (bfd_vma) DT_VERDEFNUM,
     3687                                          (bfd_vma) cdefs))
     3688            return FALSE;
    32223689
    32233690          elf_tdata (output_bfd)->cverdefs = cdefs;
    32243691        }
    32253692
    3226       if (info->new_dtags && info->flags)
    3227         {
    3228           if (! elf_add_dynamic_entry (info, DT_FLAGS, info->flags))
    3229             return false;
     3693      if ((info->new_dtags && info->flags) || (info->flags & DF_STATIC_TLS))
     3694        {
     3695          if (! elf_add_dynamic_entry (info, (bfd_vma) DT_FLAGS, info->flags))
     3696            return FALSE;
    32303697        }
    32313698
     
    32363703                                | DF_1_NODELETE
    32373704                                | DF_1_NOOPEN);
    3238           if (! elf_add_dynamic_entry (info, DT_FLAGS_1, info->flags_1))
    3239             return false;
     3705          if (! elf_add_dynamic_entry (info, (bfd_vma) DT_FLAGS_1,
     3706                                       info->flags_1))
     3707            return FALSE;
    32403708        }
    32413709
     
    32523720        if (sinfo.vers == 0)
    32533721          sinfo.vers = 1;
    3254         sinfo.failed = false;
     3722        sinfo.failed = FALSE;
    32553723
    32563724        elf_link_hash_traverse (elf_hash_table (info),
     
    32833751
    32843752            s->_raw_size = size;
    3285             s->contents = (bfd_byte *) bfd_alloc (output_bfd, size);
     3753            s->contents = (bfd_byte *) bfd_alloc (output_bfd, s->_raw_size);
    32863754            if (s->contents == NULL)
    3287               return false;
     3755              return FALSE;
    32883756
    32893757            p = s->contents;
     
    33023770                t->vn_version = VER_NEED_CURRENT;
    33033771                t->vn_cnt = caux;
    3304                 if (elf_dt_name (t->vn_bfd) != NULL)
    3305                   indx = _bfd_stringtab_add (elf_hash_table (info)->dynstr,
    3306                                              elf_dt_name (t->vn_bfd),
    3307                                              true, false);
    3308                 else
    3309                   indx = _bfd_stringtab_add (elf_hash_table (info)->dynstr,
    3310                                              t->vn_bfd->filename, true, false);
     3772                indx = _bfd_elf_strtab_add (elf_hash_table (info)->dynstr,
     3773                                            elf_dt_name (t->vn_bfd) != NULL
     3774                                            ? elf_dt_name (t->vn_bfd)
     3775                                            : basename (t->vn_bfd->filename),
     3776                                            FALSE);
    33113777                if (indx == (bfd_size_type) -1)
    3312                   return false;
     3778                  return FALSE;
    33133779                t->vn_file = indx;
    33143780                t->vn_aux = sizeof (Elf_External_Verneed);
     
    33263792                  {
    33273793                    a->vna_hash = bfd_elf_hash (a->vna_nodename);
    3328                     indx = _bfd_stringtab_add (elf_hash_table (info)->dynstr,
    3329                                                a->vna_nodename, true, false);
     3794                    indx = _bfd_elf_strtab_add (elf_hash_table (info)->dynstr,
     3795                                                a->vna_nodename, FALSE);
    33303796                    if (indx == (bfd_size_type) -1)
    3331                       return false;
     3797                      return FALSE;
    33323798                    a->vna_name = indx;
    33333799                    if (a->vna_nextptr == NULL)
     
    33423808              }
    33433809
    3344             if (! elf_add_dynamic_entry (info, DT_VERNEED, 0)
    3345                 || ! elf_add_dynamic_entry (info, DT_VERNEEDNUM, crefs))
    3346               return false;
     3810            if (! elf_add_dynamic_entry (info, (bfd_vma) DT_VERNEED,
     3811                                         (bfd_vma) 0)
     3812                || ! elf_add_dynamic_entry (info, (bfd_vma) DT_VERNEEDNUM,
     3813                                            (bfd_vma) crefs))
     3814              return FALSE;
    33473815
    33483816            elf_tdata (output_bfd)->cverrefs = crefs;
     
    33733841          s->contents = (bfd_byte *) bfd_zalloc (output_bfd, s->_raw_size);
    33743842          if (s->contents == NULL)
    3375             return false;
    3376 
    3377           if (! elf_add_dynamic_entry (info, DT_VERSYM, 0))
    3378             return false;
     3843            return FALSE;
     3844
     3845          if (! elf_add_dynamic_entry (info, (bfd_vma) DT_VERSYM, (bfd_vma) 0))
     3846            return FALSE;
    33793847        }
    33803848
     
    33903858      s->contents = (bfd_byte *) bfd_alloc (output_bfd, s->_raw_size);
    33913859      if (s->contents == NULL && s->_raw_size != 0)
    3392         return false;
     3860        return FALSE;
    33933861
    33943862      if (dynsymcount != 0)
     
    34033871          isym.st_other = 0;
    34043872          isym.st_shndx = 0;
    3405           elf_swap_symbol_out (output_bfd, &isym,
    3406                                (PTR) (Elf_External_Sym *) s->contents);
     3873          elf_swap_symbol_out (output_bfd, &isym, (PTR) s->contents, (PTR) 0);
    34073874        }
    34083875
     
    34153882      hash_entry_size = elf_section_data (s)->this_hdr.sh_entsize;
    34163883      s->_raw_size = ((2 + bucketcount + dynsymcount) * hash_entry_size);
    3417       s->contents = (bfd_byte *) bfd_alloc (output_bfd, s->_raw_size);
     3884      s->contents = (bfd_byte *) bfd_zalloc (output_bfd, s->_raw_size);
    34183885      if (s->contents == NULL)
    3419         return false;
    3420       memset (s->contents, 0, (size_t) s->_raw_size);
    3421 
    3422       bfd_put (8 * hash_entry_size, output_bfd, bucketcount, s->contents);
    3423       bfd_put (8 * hash_entry_size, output_bfd, dynsymcount,
     3886        return FALSE;
     3887
     3888      bfd_put (8 * hash_entry_size, output_bfd, (bfd_vma) bucketcount,
     3889              s->contents);
     3890      bfd_put (8 * hash_entry_size, output_bfd, (bfd_vma) dynsymcount,
    34243891               s->contents + hash_entry_size);
    34253892
     
    34283895      s = bfd_get_section_by_name (dynobj, ".dynstr");
    34293896      BFD_ASSERT (s != NULL);
    3430       s->_raw_size = _bfd_stringtab_size (elf_hash_table (info)->dynstr);
    3431 
    3432       if (! elf_add_dynamic_entry (info, DT_NULL, 0))
    3433         return false;
    3434     }
    3435 
    3436   return true;
     3897
     3898      elf_finalize_dynstr (output_bfd, info);
     3899
     3900      s->_raw_size = _bfd_elf_strtab_size (elf_hash_table (info)->dynstr);
     3901
     3902      for (dtagcount = 0; dtagcount <= info->spare_dynamic_tags; ++dtagcount)
     3903        if (! elf_add_dynamic_entry (info, (bfd_vma) DT_NULL, (bfd_vma) 0))
     3904          return FALSE;
     3905    }
     3906
     3907  return TRUE;
    34373908}
    34383909
     3910
     3911/* This function is used to adjust offsets into .dynstr for
     3912   dynamic symbols.  This is called via elf_link_hash_traverse.  */
     3913
     3914static bfd_boolean elf_adjust_dynstr_offsets
     3915  PARAMS ((struct elf_link_hash_entry *, PTR));
     3916
     3917static bfd_boolean
     3918elf_adjust_dynstr_offsets (h, data)
     3919     struct elf_link_hash_entry *h;
     3920     PTR data;
     3921{
     3922  struct elf_strtab_hash *dynstr = (struct elf_strtab_hash *) data;
     3923
     3924  if (h->root.type == bfd_link_hash_warning)
     3925    h = (struct elf_link_hash_entry *) h->root.u.i.link;
     3926
     3927  if (h->dynindx != -1)
     3928    h->dynstr_index = _bfd_elf_strtab_offset (dynstr, h->dynstr_index);
     3929  return TRUE;
     3930}
     3931
     3932/* Assign string offsets in .dynstr, update all structures referencing
     3933   them.  */
     3934
     3935static bfd_boolean
     3936elf_finalize_dynstr (output_bfd, info)
     3937     bfd *output_bfd;
     3938     struct bfd_link_info *info;
     3939{
     3940  struct elf_link_local_dynamic_entry *entry;
     3941  struct elf_strtab_hash *dynstr = elf_hash_table (info)->dynstr;
     3942  bfd *dynobj = elf_hash_table (info)->dynobj;
     3943  asection *sdyn;
     3944  bfd_size_type size;
     3945  Elf_External_Dyn *dyncon, *dynconend;
     3946
     3947  _bfd_elf_strtab_finalize (dynstr);
     3948  size = _bfd_elf_strtab_size (dynstr);
     3949
     3950  /* Update all .dynamic entries referencing .dynstr strings.  */
     3951  sdyn = bfd_get_section_by_name (dynobj, ".dynamic");
     3952  BFD_ASSERT (sdyn != NULL);
     3953
     3954  dyncon = (Elf_External_Dyn *) sdyn->contents;
     3955  dynconend = (Elf_External_Dyn *) (sdyn->contents +
     3956                                    sdyn->_raw_size);
     3957  for (; dyncon < dynconend; dyncon++)
     3958    {
     3959      Elf_Internal_Dyn dyn;
     3960
     3961      elf_swap_dyn_in (dynobj, dyncon, & dyn);
     3962      switch (dyn.d_tag)
     3963        {
     3964        case DT_STRSZ:
     3965          dyn.d_un.d_val = size;
     3966          elf_swap_dyn_out (dynobj, & dyn, dyncon);
     3967          break;
     3968        case DT_NEEDED:
     3969        case DT_SONAME:
     3970        case DT_RPATH:
     3971        case DT_RUNPATH:
     3972        case DT_FILTER:
     3973        case DT_AUXILIARY:
     3974          dyn.d_un.d_val = _bfd_elf_strtab_offset (dynstr, dyn.d_un.d_val);
     3975          elf_swap_dyn_out (dynobj, & dyn, dyncon);
     3976          break;
     3977        default:
     3978          break;
     3979        }
     3980    }
     3981
     3982  /* Now update local dynamic symbols.  */
     3983  for (entry = elf_hash_table (info)->dynlocal; entry ; entry = entry->next)
     3984    entry->isym.st_name = _bfd_elf_strtab_offset (dynstr,
     3985                                                  entry->isym.st_name);
     3986
     3987  /* And the rest of dynamic symbols.  */
     3988  elf_link_hash_traverse (elf_hash_table (info),
     3989                          elf_adjust_dynstr_offsets, dynstr);
     3990
     3991  /* Adjust version definitions.  */
     3992  if (elf_tdata (output_bfd)->cverdefs)
     3993    {
     3994      asection *s;
     3995      bfd_byte *p;
     3996      bfd_size_type i;
     3997      Elf_Internal_Verdef def;
     3998      Elf_Internal_Verdaux defaux;
     3999
     4000      s = bfd_get_section_by_name (dynobj, ".gnu.version_d");
     4001      p = (bfd_byte *) s->contents;
     4002      do
     4003        {
     4004          _bfd_elf_swap_verdef_in (output_bfd, (Elf_External_Verdef *) p,
     4005                                   &def);
     4006          p += sizeof (Elf_External_Verdef);
     4007          for (i = 0; i < def.vd_cnt; ++i)
     4008            {
     4009              _bfd_elf_swap_verdaux_in (output_bfd,
     4010                                        (Elf_External_Verdaux *) p, &defaux);
     4011              defaux.vda_name = _bfd_elf_strtab_offset (dynstr,
     4012                                                        defaux.vda_name);
     4013              _bfd_elf_swap_verdaux_out (output_bfd,
     4014                                         &defaux, (Elf_External_Verdaux *) p);
     4015              p += sizeof (Elf_External_Verdaux);
     4016            }
     4017        }
     4018      while (def.vd_next);
     4019    }
     4020
     4021  /* Adjust version references.  */
     4022  if (elf_tdata (output_bfd)->verref)
     4023    {
     4024      asection *s;
     4025      bfd_byte *p;
     4026      bfd_size_type i;
     4027      Elf_Internal_Verneed need;
     4028      Elf_Internal_Vernaux needaux;
     4029
     4030      s = bfd_get_section_by_name (dynobj, ".gnu.version_r");
     4031      p = (bfd_byte *) s->contents;
     4032      do
     4033        {
     4034          _bfd_elf_swap_verneed_in (output_bfd, (Elf_External_Verneed *) p,
     4035                                    &need);
     4036          need.vn_file = _bfd_elf_strtab_offset (dynstr, need.vn_file);
     4037          _bfd_elf_swap_verneed_out (output_bfd, &need,
     4038                                     (Elf_External_Verneed *) p);
     4039          p += sizeof (Elf_External_Verneed);
     4040          for (i = 0; i < need.vn_cnt; ++i)
     4041            {
     4042              _bfd_elf_swap_vernaux_in (output_bfd,
     4043                                        (Elf_External_Vernaux *) p, &needaux);
     4044              needaux.vna_name = _bfd_elf_strtab_offset (dynstr,
     4045                                                         needaux.vna_name);
     4046              _bfd_elf_swap_vernaux_out (output_bfd,
     4047                                         &needaux,
     4048                                         (Elf_External_Vernaux *) p);
     4049              p += sizeof (Elf_External_Vernaux);
     4050            }
     4051        }
     4052      while (need.vn_next);
     4053    }
     4054
     4055  return TRUE;
     4056}
    34394057
    34404058/* Fix up the flags for a symbol.  This handles various cases which
     
    34444062   the face of future changes.  */
    34454063
    3446 static boolean
     4064static bfd_boolean
    34474065elf_fix_symbol_flags (h, eif)
    34484066     struct elf_link_hash_entry *h;
     
    34794097          if (! _bfd_elf_link_record_dynamic_symbol (eif->info, h))
    34804098            {
    3481               eif->failed = true;
    3482               return false;
     4099              eif->failed = TRUE;
     4100              return FALSE;
    34834101            }
    34844102        }
     
    34874105    {
    34884106      /* Unfortunately, ELF_LINK_NON_ELF is only correct if the symbol
    3489         was first seen in a non-ELF file.  Fortunately, if the symbol
    3490         was first seen in an ELF file, we're probably OK unless the
    3491         symbol was defined in a non-ELF file.  Catch that case here.
    3492         FIXME: We're still in trouble if the symbol was first seen in
    3493         a dynamic object, and then later in a non-ELF regular object.  */
     4107        was first seen in a non-ELF file.  Fortunately, if the symbol
     4108        was first seen in an ELF file, we're probably OK unless the
     4109        symbol was defined in a non-ELF file.  Catch that case here.
     4110        FIXME: We're still in trouble if the symbol was first seen in
     4111        a dynamic object, and then later in a non-ELF regular object.  */
    34944112      if ((h->root.type == bfd_link_hash_defined
    34954113           || h->root.type == bfd_link_hash_defweak)
     
    35264144  if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0
    35274145      && eif->info->shared
     4146      && is_elf_hash_table (eif->info)
    35284147      && (eif->info->symbolic
    35294148          || ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
     
    35324151    {
    35334152      struct elf_backend_data *bed;
     4153      bfd_boolean force_local;
     4154
    35344155      bed = get_elf_backend_data (elf_hash_table (eif->info)->dynobj);
    3535       if (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
    3536           || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)
    3537         h->elf_link_hash_flags |= ELF_LINK_FORCED_LOCAL;
    3538       (*bed->elf_backend_hide_symbol) (eif->info, h);
     4156
     4157      force_local = (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
     4158                     || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN);
     4159      (*bed->elf_backend_hide_symbol) (eif->info, h, force_local);
    35394160    }
    35404161
     
    35464167      struct elf_link_hash_entry *weakdef;
    35474168
     4169      weakdef = h->weakdef;
     4170      if (h->root.type == bfd_link_hash_indirect)
     4171        h = (struct elf_link_hash_entry *) h->root.u.i.link;
     4172
    35484173      BFD_ASSERT (h->root.type == bfd_link_hash_defined
    35494174                  || h->root.type == bfd_link_hash_defweak);
    3550       weakdef = h->weakdef;
    35514175      BFD_ASSERT (weakdef->root.type == bfd_link_hash_defined
    35524176                  || weakdef->root.type == bfd_link_hash_defweak);
     
    35594183        h->weakdef = NULL;
    35604184      else
    3561         weakdef->elf_link_hash_flags |=
    3562           (h->elf_link_hash_flags
    3563            & (ELF_LINK_HASH_REF_REGULAR
    3564               | ELF_LINK_HASH_REF_REGULAR_NONWEAK
    3565               | ELF_LINK_NON_GOT_REF));
    3566     }
    3567 
    3568   return true;
     4185        {
     4186          struct elf_backend_data *bed;
     4187
     4188          bed = get_elf_backend_data (elf_hash_table (eif->info)->dynobj);
     4189          (*bed->elf_backend_copy_indirect_symbol) (bed, weakdef, h);
     4190        }
     4191    }
     4192
     4193  return TRUE;
    35694194}
    35704195
     
    35734198   recursively.  */
    35744199
    3575 static boolean
     4200static bfd_boolean
    35764201elf_adjust_dynamic_symbol (h, data)
    35774202     struct elf_link_hash_entry *h;
     
    35824207  struct elf_backend_data *bed;
    35834208
     4209  if (! is_elf_hash_table (eif->info))
     4210    return FALSE;
     4211
     4212  if (h->root.type == bfd_link_hash_warning)
     4213    {
     4214      h->plt = elf_hash_table (eif->info)->init_offset;
     4215      h->got = elf_hash_table (eif->info)->init_offset;
     4216
     4217      /* When warning symbols are created, they **replace** the "real"
     4218         entry in the hash table, thus we never get to see the real
     4219         symbol in a hash traversal.  So look at it now.  */
     4220      h = (struct elf_link_hash_entry *) h->root.u.i.link;
     4221    }
     4222
    35844223  /* Ignore indirect symbols.  These are added by the versioning code.  */
    35854224  if (h->root.type == bfd_link_hash_indirect)
    3586     return true;
     4225    return TRUE;
    35874226
    35884227  /* Fix the symbol flags.  */
    35894228  if (! elf_fix_symbol_flags (h, eif))
    3590     return false;
     4229    return FALSE;
    35914230
    35924231  /* If this symbol does not require a PLT entry, and it is not
     
    36034242              && (h->weakdef == NULL || h->weakdef->dynindx == -1))))
    36044243    {
    3605       h->plt.offset = (bfd_vma) -1;
    3606       return true;
     4244      h->plt = elf_hash_table (eif->info)->init_offset;
     4245      return TRUE;
    36074246    }
    36084247
     
    36104249     can happen via a recursive call.  */
    36114250  if ((h->elf_link_hash_flags & ELF_LINK_HASH_DYNAMIC_ADJUSTED) != 0)
    3612     return true;
     4251    return TRUE;
    36134252
    36144253  /* Don't look at this symbol again.  Note that we must set this
     
    36554294
    36564295      if (! elf_adjust_dynamic_symbol (h->weakdef, (PTR) eif))
    3657         return false;
     4296        return FALSE;
    36584297    }
    36594298
     
    36684307    (*_bfd_error_handler)
    36694308      (_("warning: type and size of dynamic symbol `%s' are not defined"),
    3670         h->root.root.string);
     4309      h->root.root.string);
    36714310
    36724311  dynobj = elf_hash_table (eif->info)->dynobj;
     
    36744313  if (! (*bed->elf_backend_adjust_dynamic_symbol) (eif->info, h))
    36754314    {
    3676       eif->failed = true;
    3677       return false;
    3678     }
    3679 
    3680   return true;
     4315      eif->failed = TRUE;
     4316      return FALSE;
     4317    }
     4318
     4319  return TRUE;
    36814320}
    36824321
     
    36854324   symbol table.  It is called via elf_link_hash_traverse.  */
    36864325
    3687 static boolean
     4326static bfd_boolean
    36884327elf_export_symbol (h, data)
    36894328     struct elf_link_hash_entry *h;
     
    36944333  /* Ignore indirect symbols.  These are added by the versioning code.  */
    36954334  if (h->root.type == bfd_link_hash_indirect)
    3696     return true;
     4335    return TRUE;
     4336
     4337  if (h->root.type == bfd_link_hash_warning)
     4338    h = (struct elf_link_hash_entry *) h->root.u.i.link;
    36974339
    36984340  if (h->dynindx == -1
     
    37004342          & (ELF_LINK_HASH_DEF_REGULAR | ELF_LINK_HASH_REF_REGULAR)) != 0)
    37014343    {
    3702       if (! _bfd_elf_link_record_dynamic_symbol (eif->info, h))
    3703         {
    3704           eif->failed = true;
    3705           return false;
    3706         }
    3707     }
    3708 
    3709   return true;
     4344      struct bfd_elf_version_tree *t;
     4345      struct bfd_elf_version_expr *d;
     4346
     4347      for (t = eif->verdefs; t != NULL; t = t->next)
     4348        {
     4349          if (t->globals != NULL)
     4350            {
     4351              for (d = t->globals; d != NULL; d = d->next)
     4352                {
     4353                  if ((*d->match) (d, h->root.root.string))
     4354                    goto doit;
     4355                }
     4356            }
     4357
     4358          if (t->locals != NULL)
     4359            {
     4360              for (d = t->locals ; d != NULL; d = d->next)
     4361                {
     4362                  if ((*d->match) (d, h->root.root.string))
     4363                    return TRUE;
     4364                }
     4365            }
     4366        }
     4367
     4368      if (!eif->verdefs)
     4369        {
     4370        doit:
     4371          if (! _bfd_elf_link_record_dynamic_symbol (eif->info, h))
     4372            {
     4373              eif->failed = TRUE;
     4374              return FALSE;
     4375            }
     4376        }
     4377    }
     4378
     4379  return TRUE;
    37104380}
    37114381
     
    37164386   This function is called via elf_link_hash_traverse.  */
    37174387
    3718 static boolean
     4388static bfd_boolean
    37194389elf_link_find_version_dependencies (h, data)
    37204390     struct elf_link_hash_entry *h;
     
    37244394  Elf_Internal_Verneed *t;
    37254395  Elf_Internal_Vernaux *a;
     4396  bfd_size_type amt;
     4397
     4398  if (h->root.type == bfd_link_hash_warning)
     4399    h = (struct elf_link_hash_entry *) h->root.u.i.link;
    37264400
    37274401  /* We only care about symbols defined in shared objects with version
     
    37314405      || h->dynindx == -1
    37324406      || h->verinfo.verdef == NULL)
    3733     return true;
     4407    return TRUE;
    37344408
    37354409  /* See if we already know about this version.  */
     
    37414415      for (a = t->vn_auxptr; a != NULL; a = a->vna_nextptr)
    37424416        if (a->vna_nodename == h->verinfo.verdef->vd_nodename)
    3743           return true;
     4417          return TRUE;
    37444418
    37454419      break;
     
    37504424  if (t == NULL)
    37514425    {
    3752       t = (Elf_Internal_Verneed *) bfd_zalloc (rinfo->output_bfd, sizeof *t);
     4426      amt = sizeof *t;
     4427      t = (Elf_Internal_Verneed *) bfd_zalloc (rinfo->output_bfd, amt);
    37534428      if (t == NULL)
    37544429        {
    3755           rinfo->failed = true;
    3756           return false;
     4430          rinfo->failed = TRUE;
     4431          return FALSE;
    37574432        }
    37584433
     
    37624437    }
    37634438
    3764   a = (Elf_Internal_Vernaux *) bfd_zalloc (rinfo->output_bfd, sizeof *a);
     4439  amt = sizeof *a;
     4440  a = (Elf_Internal_Vernaux *) bfd_zalloc (rinfo->output_bfd, amt);
    37654441
    37664442  /* Note that we are copying a string pointer here, and testing it
     
    37804456  t->vn_auxptr = a;
    37814457
    3782   return true;
     4458  return TRUE;
    37834459}
    37844460
     
    37884464   local.  This function is called via elf_link_hash_traverse.  */
    37894465
    3790 static boolean
     4466static bfd_boolean
    37914467elf_link_assign_sym_version (h, data)
    37924468     struct elf_link_hash_entry *h;
    37934469     PTR data;
    37944470{
    3795   struct elf_assign_sym_version_info *sinfo =
    3796     (struct elf_assign_sym_version_info *) data;
    3797   struct bfd_link_info *info = sinfo->info;
     4471  struct elf_assign_sym_version_info *sinfo;
     4472  struct bfd_link_info *info;
    37984473  struct elf_backend_data *bed;
    37994474  struct elf_info_failed eif;
    38004475  char *p;
     4476  bfd_size_type amt;
     4477
     4478  sinfo = (struct elf_assign_sym_version_info *) data;
     4479  info = sinfo->info;
     4480
     4481  if (h->root.type == bfd_link_hash_warning)
     4482    h = (struct elf_link_hash_entry *) h->root.u.i.link;
    38014483
    38024484  /* Fix the symbol flags.  */
    3803   eif.failed = false;
     4485  eif.failed = FALSE;
    38044486  eif.info = info;
    38054487  if (! elf_fix_symbol_flags (h, &eif))
    38064488    {
    38074489      if (eif.failed)
    3808         sinfo->failed = true;
    3809       return false;
     4490        sinfo->failed = TRUE;
     4491      return FALSE;
    38104492    }
    38114493
     
    38134495     objects.  */
    38144496  if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
    3815     return true;
     4497    return TRUE;
    38164498
    38174499  bed = get_elf_backend_data (sinfo->output_bfd);
     
    38204502    {
    38214503      struct bfd_elf_version_tree *t;
    3822       boolean hidden;
    3823 
    3824       hidden = true;
     4504      bfd_boolean hidden;
     4505
     4506      hidden = TRUE;
    38254507
    38264508      /* There are two consecutive ELF_VER_CHR characters if this is
    3827         not a hidden symbol.  */
     4509        not a hidden symbol.  */
    38284510      ++p;
    38294511      if (*p == ELF_VER_CHR)
    38304512        {
    3831           hidden = false;
     4513          hidden = FALSE;
    38324514          ++p;
    38334515        }
     
    38384520          if (hidden)
    38394521            h->elf_link_hash_flags |= ELF_LINK_HIDDEN;
    3840           return true;
     4522          return TRUE;
    38414523        }
    38424524
     
    38464528          if (strcmp (t->name, p) == 0)
    38474529            {
    3848               int len;
     4530              size_t len;
    38494531              char *alc;
    38504532              struct bfd_elf_version_expr *d;
    38514533
    38524534              len = p - h->root.root.string;
    3853               alc = bfd_alloc (sinfo->output_bfd, len);
     4535              alc = bfd_malloc ((bfd_size_type) len);
    38544536              if (alc == NULL)
    3855                 return false;
    3856               strncpy (alc, h->root.root.string, len - 1);
     4537                return FALSE;
     4538              memcpy (alc, h->root.root.string, len - 1);
    38574539              alc[len - 1] = '\0';
    38584540              if (alc[len - 2] == ELF_VER_CHR)
    3859                 alc[len - 2] = '\0';
     4541                alc[len - 2] = '\0';
    38604542
    38614543              h->verinfo.vertree = t;
    3862               t->used = true;
     4544              t->used = TRUE;
    38634545              d = NULL;
    38644546
     
    38714553
    38724554              /* See if there is anything to force this symbol to
    3873                 local scope.  */
     4555                local scope.  */
    38744556              if (d == NULL && t->locals != NULL)
    38754557                {
     
    38804562                          if (h->dynindx != -1
    38814563                              && info->shared
    3882                               && ! sinfo->export_dynamic)
     4564                              && ! info->export_dynamic)
    38834565                            {
    3884                               h->elf_link_hash_flags |= ELF_LINK_FORCED_LOCAL;
    3885                               (*bed->elf_backend_hide_symbol) (info, h);
    3886                               /* FIXME: The name of the symbol has
    3887                                  already been recorded in the dynamic
    3888                                  string table section.  */
     4566                              (*bed->elf_backend_hide_symbol) (info, h, TRUE);
    38894567                            }
    38904568
     
    38944572                }
    38954573
    3896               bfd_release (sinfo->output_bfd, alc);
     4574              free (alc);
    38974575              break;
    38984576            }
     
    39004578
    39014579      /* If we are building an application, we need to create a
    3902         version node for this version.  */
     4580        version node for this version.  */
    39034581      if (t == NULL && ! info->shared)
    39044582        {
     
    39074585
    39084586          /* If we aren't going to export this symbol, we don't need
    3909              to worry about it.  */
     4587             to worry about it.  */
    39104588          if (h->dynindx == -1)
    3911             return true;
    3912 
     4589            return TRUE;
     4590
     4591          amt = sizeof *t;
    39134592          t = ((struct bfd_elf_version_tree *)
    3914                bfd_alloc (sinfo->output_bfd, sizeof *t));
     4593               bfd_alloc (sinfo->output_bfd, amt));
    39154594          if (t == NULL)
    39164595            {
    3917               sinfo->failed = true;
    3918               return false;
     4596              sinfo->failed = TRUE;
     4597              return FALSE;
    39194598            }
    39204599
     
    39254604          t->deps = NULL;
    39264605          t->name_indx = (unsigned int) -1;
    3927           t->used = true;
     4606          t->used = TRUE;
    39284607
    39294608          version_index = 1;
     4609          /* Don't count anonymous version tag.  */
     4610          if (sinfo->verdefs != NULL && sinfo->verdefs->vernum == 0)
     4611            version_index = 0;
    39304612          for (pp = &sinfo->verdefs; *pp != NULL; pp = &(*pp)->next)
    39314613            ++version_index;
     
    39394621        {
    39404622          /* We could not find the version for a symbol when
    3941              generating a shared archive.  Return an error.  */
     4623             generating a shared archive.  Return an error.  */
    39424624          (*_bfd_error_handler)
    39434625            (_("%s: undefined versioned symbol name %s"),
    39444626             bfd_get_filename (sinfo->output_bfd), h->root.root.string);
    39454627          bfd_set_error (bfd_error_bad_value);
    3946           sinfo->failed = true;
    3947           return false;
     4628          sinfo->failed = TRUE;
     4629          return FALSE;
    39484630        }
    39494631
     
    39574639    {
    39584640      struct bfd_elf_version_tree *t;
    3959       struct bfd_elf_version_tree *deflt;
     4641      struct bfd_elf_version_tree *local_ver;
    39604642      struct bfd_elf_version_expr *d;
    39614643
    39624644      /* See if can find what version this symbol is in.  If the
    3963         symbol is supposed to be local, then don't actually register
    3964         it.  */
    3965       deflt = NULL;
     4645        symbol is supposed to be local, then don't actually register
     4646        it.  */
     4647      local_ver = NULL;
    39664648      for (t = sinfo->verdefs; t != NULL; t = t->next)
    39674649        {
    39684650          if (t->globals != NULL)
    39694651            {
     4652              bfd_boolean matched;
     4653
     4654              matched = FALSE;
    39704655              for (d = t->globals; d != NULL; d = d->next)
    39714656                {
    39724657                  if ((*d->match) (d, h->root.root.string))
    39734658                    {
    3974                       h->verinfo.vertree = t;
    3975                       break;
     4659                      if (d->symver)
     4660                        matched = TRUE;
     4661                      else
     4662                        {
     4663                          /* There is a version without definition.  Make
     4664                             the symbol the default definition for this
     4665                             version.  */
     4666                          h->verinfo.vertree = t;
     4667                          local_ver = NULL;
     4668                          d->script = 1;
     4669                          break;
     4670                        }
    39764671                    }
    39774672                }
     
    39794674              if (d != NULL)
    39804675                break;
     4676              else if (matched)
     4677                /* There is no undefined version for this symbol. Hide the
     4678                   default one.  */
     4679                (*bed->elf_backend_hide_symbol) (info, h, TRUE);
    39814680            }
    39824681
     
    39854684              for (d = t->locals; d != NULL; d = d->next)
    39864685                {
     4686                  /* If the match is "*", keep looking for a more
     4687                     explicit, perhaps even global, match.  */
    39874688                  if (d->pattern[0] == '*' && d->pattern[1] == '\0')
    3988                     deflt = t;
     4689                    local_ver = t;
    39894690                  else if ((*d->match) (d, h->root.root.string))
    39904691                    {
    3991                       h->verinfo.vertree = t;
    3992                       if (h->dynindx != -1
    3993                           && info->shared
    3994                           && ! sinfo->export_dynamic)
    3995                         {
    3996                           h->elf_link_hash_flags |= ELF_LINK_FORCED_LOCAL;
    3997                           (*bed->elf_backend_hide_symbol) (info, h);
    3998                           /* FIXME: The name of the symbol has already
    3999                              been recorded in the dynamic string table
    4000                              section.  */
    4001                         }
     4692                      local_ver = t;
    40024693                      break;
    40034694                    }
     
    40094700        }
    40104701
    4011       if (deflt != NULL && h->verinfo.vertree == NULL)
    4012         {
    4013           h->verinfo.vertree = deflt;
     4702      if (local_ver != NULL)
     4703        {
     4704          h->verinfo.vertree = local_ver;
    40144705          if (h->dynindx != -1
    40154706              && info->shared
    4016               && ! sinfo->export_dynamic)
     4707              && ! info->export_dynamic)
    40174708            {
    4018               h->elf_link_hash_flags |= ELF_LINK_FORCED_LOCAL;
    4019               (*bed->elf_backend_hide_symbol) (info, h);
    4020               /* FIXME: The name of the symbol has already been
    4021                  recorded in the dynamic string table section.  */
     4709              (*bed->elf_backend_hide_symbol) (info, h, TRUE);
    40224710            }
    40234711        }
    40244712    }
    40254713
    4026   return true;
     4714  return TRUE;
    40274715}
    40284716
     
    40464734  /* symbol version section (.gnu.version).  */
    40474735  asection *symver_sec;
     4736  /* first SHF_TLS section (if any).  */
     4737  asection *first_tls_sec;
    40484738  /* Buffer large enough to hold contents of any section.  */
    40494739  bfd_byte *contents;
     
    40554745     BFD.  */
    40564746  Elf_External_Sym *external_syms;
     4747  /* And a buffer for symbol section indices.  */
     4748  Elf_External_Sym_Shndx *locsym_shndx;
    40574749  /* Buffer large enough to hold internal local symbols of any input
    40584750     BFD.  */
     
    40664758  /* Buffer to hold swapped out symbols.  */
    40674759  Elf_External_Sym *symbuf;
     4760  /* And one for symbol section indices.  */
     4761  Elf_External_Sym_Shndx *symshndxbuf;
    40684762  /* Number of swapped out symbols in buffer.  */
    40694763  size_t symbuf_count;
    40704764  /* Number of symbols which fit in symbuf.  */
    40714765  size_t symbuf_size;
     4766  /* And same for symshndxbuf.  */
     4767  size_t shndxbuf_size;
    40724768};
    40734769
    4074 static boolean elf_link_output_sym
     4770static bfd_boolean elf_link_output_sym
    40754771  PARAMS ((struct elf_final_link_info *, const char *,
    40764772           Elf_Internal_Sym *, asection *));
    4077 static boolean elf_link_flush_output_syms
     4773static bfd_boolean elf_link_flush_output_syms
    40784774  PARAMS ((struct elf_final_link_info *));
    4079 static boolean elf_link_output_extsym
     4775static bfd_boolean elf_link_output_extsym
    40804776  PARAMS ((struct elf_link_hash_entry *, PTR));
    4081 static boolean elf_link_input_bfd
     4777static bfd_boolean elf_link_sec_merge_syms
     4778  PARAMS ((struct elf_link_hash_entry *, PTR));
     4779static bfd_boolean elf_link_check_versioned_symbol
     4780  PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
     4781static bfd_boolean elf_link_input_bfd
    40824782  PARAMS ((struct elf_final_link_info *, bfd *));
    4083 static boolean elf_reloc_link_order
     4783static bfd_boolean elf_reloc_link_order
    40844784  PARAMS ((bfd *, struct bfd_link_info *, asection *,
    40854785           struct bfd_link_order *));
     
    40894789struct elf_outext_info
    40904790{
    4091   boolean failed;
    4092   boolean localsyms;
     4791  bfd_boolean failed;
     4792  bfd_boolean localsyms;
    40934793  struct elf_final_link_info *finfo;
    40944794};
     
    40974797   section header for a section containing relocations for O.  */
    40984798
    4099 static boolean
     4799static bfd_boolean
    41004800elf_link_size_reloc_section (abfd, rel_hdr, o)
    41014801     bfd *abfd;
     
    41034803     asection *o;
    41044804{
    4105   unsigned reloc_count;
     4805  bfd_size_type reloc_count;
     4806  bfd_size_type num_rel_hashes;
    41064807
    41074808  /* Figure out how many relocations there will be.  */
     
    41104811  else
    41114812    reloc_count = elf_section_data (o)->rel_count2;
     4813
     4814  num_rel_hashes = o->reloc_count;
     4815  if (num_rel_hashes < reloc_count)
     4816    num_rel_hashes = reloc_count;
    41124817
    41134818  /* That allows us to calculate the size of the section.  */
     
    41204825  rel_hdr->contents = (PTR) bfd_zalloc (abfd, rel_hdr->sh_size);
    41214826  if (rel_hdr->contents == NULL && rel_hdr->sh_size != 0)
    4122     return false;
     4827    return FALSE;
    41234828
    41244829  /* We only allocate one set of hash entries, so we only do it the
    41254830     first time we are called.  */
    4126   if (elf_section_data (o)->rel_hashes == NULL)
     4831  if (elf_section_data (o)->rel_hashes == NULL
     4832      && num_rel_hashes)
    41274833    {
    41284834      struct elf_link_hash_entry **p;
    41294835
    41304836      p = ((struct elf_link_hash_entry **)
    4131            bfd_zmalloc (o->reloc_count
     4837           bfd_zmalloc (num_rel_hashes
    41324838                        * sizeof (struct elf_link_hash_entry *)));
    4133       if (p == NULL && o->reloc_count != 0)
    4134         return false;
     4839      if (p == NULL)
     4840        return FALSE;
    41354841
    41364842      elf_section_data (o)->rel_hashes = p;
    41374843    }
    41384844
    4139   return true;
     4845  return TRUE;
    41404846}
    41414847
     
    41544860  unsigned int i;
    41554861  struct elf_backend_data *bed = get_elf_backend_data (abfd);
    4156   Elf_Internal_Rel *irel;
    4157   Elf_Internal_Rela *irela;
    4158 
    4159   irel = (Elf_Internal_Rel *) bfd_zmalloc (sizeof (Elf_Internal_Rel)
    4160                                            * bed->s->int_rels_per_ext_rel);
    4161   if (irel == NULL)
    4162     {
    4163       (*_bfd_error_handler) (_("Error: out of memory"));
    4164       abort ();
    4165     }
    4166 
    4167   irela = (Elf_Internal_Rela *) bfd_zmalloc (sizeof (Elf_Internal_Rela)
    4168                                              * bed->s->int_rels_per_ext_rel);
    4169   if (irela == NULL)
    4170     {
    4171       (*_bfd_error_handler) (_("Error: out of memory"));
    4172       abort ();
    4173     }
    4174 
    4175   for (i = 0; i < count; i++, rel_hash++)
    4176     {
     4862  bfd_byte *erela;
     4863  void (*swap_in) PARAMS ((bfd *, const bfd_byte *, Elf_Internal_Rela *));
     4864  void (*swap_out) PARAMS ((bfd *, const Elf_Internal_Rela *, bfd_byte *));
     4865
     4866  if (rel_hdr->sh_entsize == sizeof (Elf_External_Rel))
     4867    {
     4868      swap_in = bed->s->swap_reloc_in;
     4869      swap_out = bed->s->swap_reloc_out;
     4870    }
     4871  else if (rel_hdr->sh_entsize == sizeof (Elf_External_Rela))
     4872    {
     4873      swap_in = bed->s->swap_reloca_in;
     4874      swap_out = bed->s->swap_reloca_out;
     4875    }
     4876  else
     4877    abort ();
     4878
     4879  if (bed->s->int_rels_per_ext_rel > MAX_INT_RELS_PER_EXT_REL)
     4880    abort ();
     4881
     4882  erela = rel_hdr->contents;
     4883  for (i = 0; i < count; i++, rel_hash++, erela += rel_hdr->sh_entsize)
     4884    {
     4885      Elf_Internal_Rela irela[MAX_INT_RELS_PER_EXT_REL];
     4886      unsigned int j;
     4887
    41774888      if (*rel_hash == NULL)
    41784889        continue;
     
    41804891      BFD_ASSERT ((*rel_hash)->indx >= 0);
    41814892
    4182       if (rel_hdr->sh_entsize == sizeof (Elf_External_Rel))
    4183         {
    4184           Elf_External_Rel *erel;
    4185           unsigned int j;
    4186 
    4187           erel = (Elf_External_Rel *) rel_hdr->contents + i;
    4188           if (bed->s->swap_reloc_in)
    4189             (*bed->s->swap_reloc_in) (abfd, (bfd_byte *) erel, irel);
    4190           else
    4191             elf_swap_reloc_in (abfd, erel, irel);
    4192 
    4193           for (j = 0; j < bed->s->int_rels_per_ext_rel; j++)
    4194             irel[j].r_info = ELF_R_INFO ((*rel_hash)->indx,
    4195                                          ELF_R_TYPE (irel[j].r_info));
    4196 
    4197           if (bed->s->swap_reloc_out)
    4198             (*bed->s->swap_reloc_out) (abfd, irel, (bfd_byte *) erel);
    4199           else
    4200             elf_swap_reloc_out (abfd, irel, erel);
    4201         }
    4202       else
    4203         {
    4204           Elf_External_Rela *erela;
    4205           unsigned int j;
    4206 
    4207           BFD_ASSERT (rel_hdr->sh_entsize
    4208                       == sizeof (Elf_External_Rela));
    4209 
    4210           erela = (Elf_External_Rela *) rel_hdr->contents + i;
    4211           if (bed->s->swap_reloca_in)
    4212             (*bed->s->swap_reloca_in) (abfd, (bfd_byte *) erela, irela);
    4213           else
    4214             elf_swap_reloca_in (abfd, erela, irela);
    4215 
    4216           for (j = 0; j < bed->s->int_rels_per_ext_rel; j++)
    4217             irela[j].r_info = ELF_R_INFO ((*rel_hash)->indx,
    4218                                        ELF_R_TYPE (irela[j].r_info));
    4219 
    4220           if (bed->s->swap_reloca_out)
    4221             (*bed->s->swap_reloca_out) (abfd, irela, (bfd_byte *) erela);
    4222           else
    4223             elf_swap_reloca_out (abfd, irela, erela);
    4224         }
    4225     }
    4226 
    4227   free (irel);
    4228   free (irela);
     4893      (*swap_in) (abfd, erela, irela);
     4894      for (j = 0; j < bed->s->int_rels_per_ext_rel; j++)
     4895        irela[j].r_info = ELF_R_INFO ((*rel_hash)->indx,
     4896                                      ELF_R_TYPE (irela[j].r_info));
     4897      (*swap_out) (abfd, irela, erela);
     4898    }
    42294899}
    42304900
     4901struct elf_link_sort_rela
     4902{
     4903  bfd_vma offset;
     4904  enum elf_reloc_type_class type;
     4905  /* We use this as an array of size int_rels_per_ext_rel.  */
     4906  Elf_Internal_Rela rela[1];
     4907};
     4908
     4909static int
     4910elf_link_sort_cmp1 (A, B)
     4911     const PTR A;
     4912     const PTR B;
     4913{
     4914  struct elf_link_sort_rela *a = (struct elf_link_sort_rela *) A;
     4915  struct elf_link_sort_rela *b = (struct elf_link_sort_rela *) B;
     4916  int relativea, relativeb;
     4917
     4918  relativea = a->type == reloc_class_relative;
     4919  relativeb = b->type == reloc_class_relative;
     4920
     4921  if (relativea < relativeb)
     4922    return 1;
     4923  if (relativea > relativeb)
     4924    return -1;
     4925  if (ELF_R_SYM (a->rela->r_info) < ELF_R_SYM (b->rela->r_info))
     4926    return -1;
     4927  if (ELF_R_SYM (a->rela->r_info) > ELF_R_SYM (b->rela->r_info))
     4928    return 1;
     4929  if (a->rela->r_offset < b->rela->r_offset)
     4930    return -1;
     4931  if (a->rela->r_offset > b->rela->r_offset)
     4932    return 1;
     4933  return 0;
     4934}
     4935
     4936static int
     4937elf_link_sort_cmp2 (A, B)
     4938     const PTR A;
     4939     const PTR B;
     4940{
     4941  struct elf_link_sort_rela *a = (struct elf_link_sort_rela *) A;
     4942  struct elf_link_sort_rela *b = (struct elf_link_sort_rela *) B;
     4943  int copya, copyb;
     4944
     4945  if (a->offset < b->offset)
     4946    return -1;
     4947  if (a->offset > b->offset)
     4948    return 1;
     4949  copya = (a->type == reloc_class_copy) * 2 + (a->type == reloc_class_plt);
     4950  copyb = (b->type == reloc_class_copy) * 2 + (b->type == reloc_class_plt);
     4951  if (copya < copyb)
     4952    return -1;
     4953  if (copya > copyb)
     4954    return 1;
     4955  if (a->rela->r_offset < b->rela->r_offset)
     4956    return -1;
     4957  if (a->rela->r_offset > b->rela->r_offset)
     4958    return 1;
     4959  return 0;
     4960}
     4961
     4962static size_t
     4963elf_link_sort_relocs (abfd, info, psec)
     4964     bfd *abfd;
     4965     struct bfd_link_info *info;
     4966     asection **psec;
     4967{
     4968  bfd *dynobj = elf_hash_table (info)->dynobj;
     4969  asection *reldyn, *o;
     4970  bfd_size_type count, size;
     4971  size_t i, ret, sort_elt, ext_size;
     4972  bfd_byte *sort, *s_non_relative, *p;
     4973  struct elf_link_sort_rela *sq;
     4974  struct elf_backend_data *bed = get_elf_backend_data (abfd);
     4975  int i2e = bed->s->int_rels_per_ext_rel;
     4976  void (*swap_in) PARAMS ((bfd *, const bfd_byte *, Elf_Internal_Rela *));
     4977  void (*swap_out) PARAMS ((bfd *, const Elf_Internal_Rela *, bfd_byte *));
     4978
     4979  reldyn = bfd_get_section_by_name (abfd, ".rela.dyn");
     4980  if (reldyn == NULL || reldyn->_raw_size == 0)
     4981    {
     4982      reldyn = bfd_get_section_by_name (abfd, ".rel.dyn");
     4983      if (reldyn == NULL || reldyn->_raw_size == 0)
     4984        return 0;
     4985      ext_size = sizeof (Elf_External_Rel);
     4986      swap_in = bed->s->swap_reloc_in;
     4987      swap_out = bed->s->swap_reloc_out;
     4988    }
     4989  else
     4990    {
     4991      ext_size = sizeof (Elf_External_Rela);
     4992      swap_in = bed->s->swap_reloca_in;
     4993      swap_out = bed->s->swap_reloca_out;
     4994    }
     4995  count = reldyn->_raw_size / ext_size;
     4996
     4997  size = 0;
     4998  for (o = dynobj->sections; o != NULL; o = o->next)
     4999    if ((o->flags & (SEC_HAS_CONTENTS|SEC_LINKER_CREATED))
     5000        == (SEC_HAS_CONTENTS|SEC_LINKER_CREATED)
     5001        && o->output_section == reldyn)
     5002      size += o->_raw_size;
     5003
     5004  if (size != reldyn->_raw_size)
     5005    return 0;
     5006
     5007  sort_elt = (sizeof (struct elf_link_sort_rela)
     5008              + (i2e - 1) * sizeof (Elf_Internal_Rela));
     5009  sort = bfd_zmalloc (sort_elt * count);
     5010  if (sort == NULL)
     5011    {
     5012      (*info->callbacks->warning)
     5013        (info, _("Not enough memory to sort relocations"), 0, abfd, 0,
     5014         (bfd_vma) 0);
     5015      return 0;
     5016    }
     5017
     5018  for (o = dynobj->sections; o != NULL; o = o->next)
     5019    if ((o->flags & (SEC_HAS_CONTENTS|SEC_LINKER_CREATED))
     5020        == (SEC_HAS_CONTENTS|SEC_LINKER_CREATED)
     5021        && o->output_section == reldyn)
     5022      {
     5023        bfd_byte *erel, *erelend;
     5024
     5025        erel = o->contents;
     5026        erelend = o->contents + o->_raw_size;
     5027        p = sort + o->output_offset / ext_size * sort_elt;
     5028        while (erel < erelend)
     5029          {
     5030            struct elf_link_sort_rela *s = (struct elf_link_sort_rela *) p;
     5031            (*swap_in) (abfd, erel, s->rela);
     5032            s->type = (*bed->elf_backend_reloc_type_class) (s->rela);
     5033            p += sort_elt;
     5034            erel += ext_size;
     5035          }
     5036      }
     5037
     5038  qsort (sort, (size_t) count, sort_elt, elf_link_sort_cmp1);
     5039
     5040  for (i = 0, p = sort; i < count; i++, p += sort_elt)
     5041    {
     5042      struct elf_link_sort_rela *s = (struct elf_link_sort_rela *) p;
     5043      if (s->type != reloc_class_relative)
     5044        break;
     5045    }
     5046  ret = i;
     5047  s_non_relative = p;
     5048
     5049  sq = (struct elf_link_sort_rela *) s_non_relative;
     5050  for (; i < count; i++, p += sort_elt)
     5051    {
     5052      struct elf_link_sort_rela *sp = (struct elf_link_sort_rela *) p;
     5053      if (ELF_R_SYM (sp->rela->r_info) != ELF_R_SYM (sq->rela->r_info))
     5054        sq = sp;
     5055      sp->offset = sq->rela->r_offset;
     5056    }
     5057
     5058  qsort (s_non_relative, (size_t) count - ret, sort_elt, elf_link_sort_cmp2);
     5059
     5060  for (o = dynobj->sections; o != NULL; o = o->next)
     5061    if ((o->flags & (SEC_HAS_CONTENTS|SEC_LINKER_CREATED))
     5062        == (SEC_HAS_CONTENTS|SEC_LINKER_CREATED)
     5063        && o->output_section == reldyn)
     5064      {
     5065        bfd_byte *erel, *erelend;
     5066
     5067        erel = o->contents;
     5068        erelend = o->contents + o->_raw_size;
     5069        p = sort + o->output_offset / ext_size * sort_elt;
     5070        while (erel < erelend)
     5071          {
     5072            struct elf_link_sort_rela *s = (struct elf_link_sort_rela *) p;
     5073            (*swap_out) (abfd, s->rela, erel);
     5074            p += sort_elt;
     5075            erel += ext_size;
     5076          }
     5077      }
     5078
     5079  free (sort);
     5080  *psec = reldyn;
     5081  return ret;
     5082}
     5083
    42315084/* Do the final step of an ELF link.  */
    42325085
    4233 boolean
     5086bfd_boolean
    42345087elf_bfd_final_link (abfd, info)
    42355088     bfd *abfd;
    42365089     struct bfd_link_info *info;
    42375090{
    4238   boolean dynamic;
     5091  bfd_boolean dynamic;
     5092  bfd_boolean emit_relocs;
    42395093  bfd *dynobj;
    42405094  struct elf_final_link_info finfo;
     
    42425096  register struct bfd_link_order *p;
    42435097  register bfd *sub;
    4244   size_t max_contents_size;
    4245   size_t max_external_reloc_size;
    4246   size_t max_internal_reloc_count;
    4247   size_t max_sym_count;
     5098  bfd_size_type max_contents_size;
     5099  bfd_size_type max_external_reloc_size;
     5100  bfd_size_type max_internal_reloc_count;
     5101  bfd_size_type max_sym_count;
     5102  bfd_size_type max_sym_shndx_count;
    42485103  file_ptr off;
    42495104  Elf_Internal_Sym elfsym;
    42505105  unsigned int i;
    42515106  Elf_Internal_Shdr *symtab_hdr;
     5107  Elf_Internal_Shdr *symtab_shndx_hdr;
    42525108  Elf_Internal_Shdr *symstrtab_hdr;
    42535109  struct elf_backend_data *bed = get_elf_backend_data (abfd);
    42545110  struct elf_outext_info eoinfo;
     5111  bfd_boolean merged;
     5112  size_t relativecount = 0;
     5113  asection *reldyn = 0;
     5114  bfd_size_type amt;
     5115
     5116  if (! is_elf_hash_table (info))
     5117    return FALSE;
    42555118
    42565119  if (info->shared)
     
    42595122  dynamic = elf_hash_table (info)->dynamic_sections_created;
    42605123  dynobj = elf_hash_table (info)->dynobj;
     5124
     5125  emit_relocs = (info->relocateable
     5126                 || info->emitrelocations
     5127                 || bed->elf_backend_emit_relocs);
    42615128
    42625129  finfo.info = info;
     
    42645131  finfo.symstrtab = elf_stringtab_init ();
    42655132  if (finfo.symstrtab == NULL)
    4266     return false;
     5133    return FALSE;
    42675134
    42685135  if (! dynamic)
     
    42855152  finfo.internal_relocs = NULL;
    42865153  finfo.external_syms = NULL;
     5154  finfo.locsym_shndx = NULL;
    42875155  finfo.internal_syms = NULL;
    42885156  finfo.indices = NULL;
    42895157  finfo.sections = NULL;
    42905158  finfo.symbuf = NULL;
     5159  finfo.symshndxbuf = NULL;
    42915160  finfo.symbuf_count = 0;
     5161  finfo.shndxbuf_size = 0;
     5162  finfo.first_tls_sec = NULL;
     5163  for (o = abfd->sections; o != (asection *) NULL; o = o->next)
     5164    if ((o->flags & SEC_THREAD_LOCAL) != 0
     5165        && (o->flags & SEC_LOAD) != 0)
     5166      {
     5167        finfo.first_tls_sec = o;
     5168        break;
     5169      }
    42925170
    42935171  /* Count up the number of relocations we will output for each output
     
    42985176  max_internal_reloc_count = 0;
    42995177  max_sym_count = 0;
     5178  max_sym_shndx_count = 0;
     5179  merged = FALSE;
    43005180  for (o = abfd->sections; o != (asection *) NULL; o = o->next)
    43015181    {
     5182      struct bfd_elf_section_data *esdo = elf_section_data (o);
    43025183      o->reloc_count = 0;
    43035184
    43045185      for (p = o->link_order_head; p != NULL; p = p->next)
    43055186        {
     5187          unsigned int reloc_count = 0;
     5188          struct bfd_elf_section_data *esdi = NULL;
     5189          unsigned int *rel_count1;
     5190
    43065191          if (p->type == bfd_section_reloc_link_order
    43075192              || p->type == bfd_symbol_reloc_link_order)
    4308             ++o->reloc_count;
     5193            reloc_count = 1;
    43095194          else if (p->type == bfd_indirect_link_order)
    43105195            {
     
    43125197
    43135198              sec = p->u.indirect.section;
     5199              esdi = elf_section_data (sec);
    43145200
    43155201              /* Mark all sections which are to be included in the
     
    43175203                 to do this so that we can identify any sections which
    43185204                 the linker has decided to not include.  */
    4319               sec->linker_mark = true;
     5205              sec->linker_mark = TRUE;
     5206
     5207              if (sec->flags & SEC_MERGE)
     5208                merged = TRUE;
    43205209
    43215210              if (info->relocateable || info->emitrelocations)
    4322                 o->reloc_count += sec->reloc_count;
     5211                reloc_count = sec->reloc_count;
     5212              else if (bed->elf_backend_count_relocs)
     5213                {
     5214                  Elf_Internal_Rela * relocs;
     5215
     5216                  relocs = (NAME(_bfd_elf,link_read_relocs)
     5217                            (abfd, sec, (PTR) NULL,
     5218                             (Elf_Internal_Rela *) NULL, info->keep_memory));
     5219
     5220                  reloc_count = (*bed->elf_backend_count_relocs) (sec, relocs);
     5221
     5222                  if (elf_section_data (o)->relocs != relocs)
     5223                    free (relocs);
     5224                }
    43235225
    43245226              if (sec->_raw_size > max_contents_size)
     
    43425244                  if (sym_count > max_sym_count)
    43435245                    max_sym_count = sym_count;
     5246
     5247                  if (sym_count > max_sym_shndx_count
     5248                      && elf_symtab_shndx (sec->owner) != 0)
     5249                    max_sym_shndx_count = sym_count;
    43445250
    43455251                  if ((sec->flags & SEC_RELOC) != 0)
     
    43555261                }
    43565262            }
     5263
     5264          if (reloc_count == 0)
     5265            continue;
     5266
     5267          o->reloc_count += reloc_count;
     5268
     5269          /* MIPS may have a mix of REL and RELA relocs on sections.
     5270             To support this curious ABI we keep reloc counts in
     5271             elf_section_data too.  We must be careful to add the
     5272             relocations from the input section to the right output
     5273             count.  FIXME: Get rid of one count.  We have
     5274             o->reloc_count == esdo->rel_count + esdo->rel_count2.  */
     5275          rel_count1 = &esdo->rel_count;
     5276          if (esdi != NULL)
     5277            {
     5278              bfd_boolean same_size;
     5279              bfd_size_type entsize1;
     5280
     5281              entsize1 = esdi->rel_hdr.sh_entsize;
     5282              BFD_ASSERT (entsize1 == sizeof (Elf_External_Rel)
     5283                          || entsize1 == sizeof (Elf_External_Rela));
     5284              same_size = (!o->use_rela_p
     5285                           == (entsize1 == sizeof (Elf_External_Rel)));
     5286
     5287              if (!same_size)
     5288                rel_count1 = &esdo->rel_count2;
     5289
     5290              if (esdi->rel_hdr2 != NULL)
     5291                {
     5292                  bfd_size_type entsize2 = esdi->rel_hdr2->sh_entsize;
     5293                  unsigned int alt_count;
     5294                  unsigned int *rel_count2;
     5295
     5296                  BFD_ASSERT (entsize2 != entsize1
     5297                              && (entsize2 == sizeof (Elf_External_Rel)
     5298                                  || entsize2 == sizeof (Elf_External_Rela)));
     5299
     5300                  rel_count2 = &esdo->rel_count2;
     5301                  if (!same_size)
     5302                    rel_count2 = &esdo->rel_count;
     5303
     5304                  /* The following is probably too simplistic if the
     5305                     backend counts output relocs unusually.  */
     5306                  BFD_ASSERT (bed->elf_backend_count_relocs == NULL);
     5307                  alt_count = NUM_SHDR_ENTRIES (esdi->rel_hdr2);
     5308                  *rel_count2 += alt_count;
     5309                  reloc_count -= alt_count;
     5310                }
     5311            }
     5312          *rel_count1 += reloc_count;
    43575313        }
    43585314
     
    43765332    }
    43775333
     5334  if (! info->relocateable && merged)
     5335    elf_link_hash_traverse (elf_hash_table (info),
     5336                            elf_link_sec_merge_syms, (PTR) abfd);
     5337
    43785338  /* Figure out the file positions for everything but the symbol table
    43795339     and the relocs.  We set symcount to force assign_section_numbers
     
    43835343  if (! _bfd_elf_compute_section_file_positions (abfd, info))
    43845344    goto error_return;
    4385 
    4386   /* Figure out how many relocations we will have in each section.
    4387      Just using RELOC_COUNT isn't good enough since that doesn't
    4388      maintain a separate value for REL vs. RELA relocations.  */
    4389   if (info->relocateable || info->emitrelocations)
    4390     for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
    4391       for (o = sub->sections; o != NULL; o = o->next)
    4392         {
    4393           asection *output_section;
    4394 
    4395           if (! o->linker_mark)
    4396             {
    4397               /* This section was omitted from the link.  */
    4398               continue;
    4399             }
    4400 
    4401           output_section = o->output_section;
    4402 
    4403           if (output_section != NULL
    4404               && (o->flags & SEC_RELOC) != 0)
    4405             {
    4406               struct bfd_elf_section_data *esdi
    4407                 = elf_section_data (o);
    4408               struct bfd_elf_section_data *esdo
    4409                 = elf_section_data (output_section);
    4410               unsigned int *rel_count;
    4411               unsigned int *rel_count2;
    4412 
    4413               /* We must be careful to add the relocation froms the
    4414                  input section to the right output count.  */
    4415               if (esdi->rel_hdr.sh_entsize == esdo->rel_hdr.sh_entsize)
    4416                 {
    4417                   rel_count = &esdo->rel_count;
    4418                   rel_count2 = &esdo->rel_count2;
    4419                 }
    4420               else
    4421                 {
    4422                   rel_count = &esdo->rel_count2;
    4423                   rel_count2 = &esdo->rel_count;
    4424                 }
    4425 
    4426               *rel_count += NUM_SHDR_ENTRIES (& esdi->rel_hdr);
    4427               if (esdi->rel_hdr2)
    4428                 *rel_count2 += NUM_SHDR_ENTRIES (esdi->rel_hdr2);
    4429             }
    4430         }
    44315345
    44325346  /* That created the reloc sections.  Set their sizes, and assign
     
    44645378  /* sh_name is set in prep_headers.  */
    44655379  symtab_hdr->sh_type = SHT_SYMTAB;
    4466   symtab_hdr->sh_flags = 0;
    4467   symtab_hdr->sh_addr = 0;
    4468   symtab_hdr->sh_size = 0;
     5380  /* sh_flags, sh_addr and sh_size all start off zero.  */
    44695381  symtab_hdr->sh_entsize = sizeof (Elf_External_Sym);
    44705382  /* sh_link is set in assign_section_numbers.  */
     
    44745386
    44755387  off = elf_tdata (abfd)->next_file_pos;
    4476   off = _bfd_elf_assign_file_position_for_section (symtab_hdr, off, true);
     5388  off = _bfd_elf_assign_file_position_for_section (symtab_hdr, off, TRUE);
    44775389
    44785390  /* Note that at this point elf_tdata (abfd)->next_file_pos is
     
    44865398  else
    44875399    finfo.symbuf_size = max_sym_count;
    4488   finfo.symbuf = ((Elf_External_Sym *)
    4489                   bfd_malloc (finfo.symbuf_size * sizeof (Elf_External_Sym)));
     5400  amt = finfo.symbuf_size;
     5401  amt *= sizeof (Elf_External_Sym);
     5402  finfo.symbuf = (Elf_External_Sym *) bfd_malloc (amt);
    44905403  if (finfo.symbuf == NULL)
    44915404    goto error_return;
     5405  if (elf_numsections (abfd) > SHN_LORESERVE)
     5406    {
     5407      /* Wild guess at number of output symbols.  realloc'd as needed.  */
     5408      amt = 2 * max_sym_count + elf_numsections (abfd) + 1000;
     5409      finfo.shndxbuf_size = amt;
     5410      amt *= sizeof (Elf_External_Sym_Shndx);
     5411      finfo.symshndxbuf = (Elf_External_Sym_Shndx *) bfd_zmalloc (amt);
     5412      if (finfo.symshndxbuf == NULL)
     5413        goto error_return;
     5414    }
    44925415
    44935416  /* Start writing out the symbol table.  The first symbol is always a
    44945417     dummy symbol.  */
    4495   if (info->strip != strip_all || info->relocateable || info->emitrelocations)
     5418  if (info->strip != strip_all
     5419      || emit_relocs)
    44965420    {
    44975421      elfsym.st_value = 0;
     
    45265450     index field of the section, so that we can find it again when
    45275451     outputting relocs.  */
    4528   if (info->strip != strip_all || info->relocateable || info->emitrelocations)
     5452  if (info->strip != strip_all
     5453      || emit_relocs)
    45295454    {
    45305455      elfsym.st_size = 0;
    45315456      elfsym.st_info = ELF_ST_INFO (STB_LOCAL, STT_SECTION);
    45325457      elfsym.st_other = 0;
    4533       for (i = 1; i < elf_elfheader (abfd)->e_shnum; i++)
     5458      for (i = 1; i < elf_numsections (abfd); i++)
    45345459        {
    45355460          o = section_from_elf_index (abfd, i);
     
    45445469                                     &elfsym, o))
    45455470            goto error_return;
     5471          if (i == SHN_LORESERVE - 1)
     5472            i += SHN_HIRESERVE + 1 - SHN_LORESERVE;
    45465473        }
    45475474    }
     
    45495476  /* Allocate some memory to hold information read in from the input
    45505477     files.  */
    4551   finfo.contents = (bfd_byte *) bfd_malloc (max_contents_size);
    4552   finfo.external_relocs = (PTR) bfd_malloc (max_external_reloc_size);
    4553   finfo.internal_relocs = ((Elf_Internal_Rela *)
    4554                            bfd_malloc (max_internal_reloc_count
    4555                                        * sizeof (Elf_Internal_Rela)
    4556                                        * bed->s->int_rels_per_ext_rel));
    4557   finfo.external_syms = ((Elf_External_Sym *)
    4558                          bfd_malloc (max_sym_count
    4559                                      * sizeof (Elf_External_Sym)));
    4560   finfo.internal_syms = ((Elf_Internal_Sym *)
    4561                          bfd_malloc (max_sym_count
    4562                                      * sizeof (Elf_Internal_Sym)));
    4563   finfo.indices = (long *) bfd_malloc (max_sym_count * sizeof (long));
    4564   finfo.sections = ((asection **)
    4565                     bfd_malloc (max_sym_count * sizeof (asection *)));
    4566   if ((finfo.contents == NULL && max_contents_size != 0)
    4567       || (finfo.external_relocs == NULL && max_external_reloc_size != 0)
    4568       || (finfo.internal_relocs == NULL && max_internal_reloc_count != 0)
    4569       || (finfo.external_syms == NULL && max_sym_count != 0)
    4570       || (finfo.internal_syms == NULL && max_sym_count != 0)
    4571       || (finfo.indices == NULL && max_sym_count != 0)
    4572       || (finfo.sections == NULL && max_sym_count != 0))
    4573     goto error_return;
     5478  if (max_contents_size != 0)
     5479    {
     5480      finfo.contents = (bfd_byte *) bfd_malloc (max_contents_size);
     5481      if (finfo.contents == NULL)
     5482        goto error_return;
     5483    }
     5484
     5485  if (max_external_reloc_size != 0)
     5486    {
     5487      finfo.external_relocs = (PTR) bfd_malloc (max_external_reloc_size);
     5488      if (finfo.external_relocs == NULL)
     5489        goto error_return;
     5490    }
     5491
     5492  if (max_internal_reloc_count != 0)
     5493    {
     5494      amt = max_internal_reloc_count * bed->s->int_rels_per_ext_rel;
     5495      amt *= sizeof (Elf_Internal_Rela);
     5496      finfo.internal_relocs = (Elf_Internal_Rela *) bfd_malloc (amt);
     5497      if (finfo.internal_relocs == NULL)
     5498        goto error_return;
     5499    }
     5500
     5501  if (max_sym_count != 0)
     5502    {
     5503      amt = max_sym_count * sizeof (Elf_External_Sym);
     5504      finfo.external_syms = (Elf_External_Sym *) bfd_malloc (amt);
     5505      if (finfo.external_syms == NULL)
     5506        goto error_return;
     5507
     5508      amt = max_sym_count * sizeof (Elf_Internal_Sym);
     5509      finfo.internal_syms = (Elf_Internal_Sym *) bfd_malloc (amt);
     5510      if (finfo.internal_syms == NULL)
     5511        goto error_return;
     5512
     5513      amt = max_sym_count * sizeof (long);
     5514      finfo.indices = (long *) bfd_malloc (amt);
     5515      if (finfo.indices == NULL)
     5516        goto error_return;
     5517
     5518      amt = max_sym_count * sizeof (asection *);
     5519      finfo.sections = (asection **) bfd_malloc (amt);
     5520      if (finfo.sections == NULL)
     5521        goto error_return;
     5522    }
     5523
     5524  if (max_sym_shndx_count != 0)
     5525    {
     5526      amt = max_sym_shndx_count * sizeof (Elf_External_Sym_Shndx);
     5527      finfo.locsym_shndx = (Elf_External_Sym_Shndx *) bfd_malloc (amt);
     5528      if (finfo.locsym_shndx == NULL)
     5529        goto error_return;
     5530    }
     5531
     5532  if (finfo.first_tls_sec)
     5533    {
     5534      unsigned int align = 0;
     5535      bfd_vma base = finfo.first_tls_sec->vma, end = 0;
     5536      asection *sec;
     5537
     5538      for (sec = finfo.first_tls_sec;
     5539           sec && (sec->flags & SEC_THREAD_LOCAL);
     5540           sec = sec->next)
     5541        {
     5542          bfd_vma size = sec->_raw_size;
     5543
     5544          if (bfd_get_section_alignment (abfd, sec) > align)
     5545            align = bfd_get_section_alignment (abfd, sec);
     5546          if (sec->_raw_size == 0 && (sec->flags & SEC_HAS_CONTENTS) == 0)
     5547            {
     5548              struct bfd_link_order *o;
     5549
     5550              size = 0;
     5551              for (o = sec->link_order_head; o != NULL; o = o->next)
     5552                if (size < o->offset + o->size)
     5553                  size = o->offset + o->size;
     5554            }
     5555          end = sec->vma + size;
     5556        }
     5557      elf_hash_table (info)->tls_segment
     5558        = bfd_zalloc (abfd, sizeof (struct elf_link_tls_segment));
     5559      if (elf_hash_table (info)->tls_segment == NULL)
     5560        goto error_return;
     5561      elf_hash_table (info)->tls_segment->start = base;
     5562      elf_hash_table (info)->tls_segment->size = end - base;
     5563      elf_hash_table (info)->tls_segment->align = align;
     5564    }
    45745565
    45755566  /* Since ELF permits relocations to be against local symbols, we
     
    45945585
    45955586  for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
    4596     sub->output_has_begun = false;
     5587    sub->output_has_begun = FALSE;
    45975588  for (o = abfd->sections; o != NULL; o = o->next)
    45985589    {
     
    46005591        {
    46015592          if (p->type == bfd_indirect_link_order
    4602               && (bfd_get_flavour (p->u.indirect.section->owner)
    4603                   == bfd_target_elf_flavour))
     5593              && (bfd_get_flavour ((sub = p->u.indirect.section->owner))
     5594                  == bfd_target_elf_flavour)
     5595              && elf_elfheader (sub)->e_ident[EI_CLASS] == bed->s->elfclass)
    46045596            {
    4605               sub = p->u.indirect.section->owner;
    46065597              if (! sub->output_has_begun)
    46075598                {
    46085599                  if (! elf_link_input_bfd (&finfo, sub))
    46095600                    goto error_return;
    4610                   sub->output_has_begun = true;
     5601                  sub->output_has_begun = TRUE;
    46115602                }
    46125603            }
     
    46255616    }
    46265617
     5618  /* Output any global symbols that got converted to local in a
     5619     version script or due to symbol visibility.  We do this in a
     5620     separate step since ELF requires all local symbols to appear
     5621     prior to any global symbols.  FIXME: We should only do this if
     5622     some global symbols were, in fact, converted to become local.
     5623     FIXME: Will this work correctly with the Irix 5 linker?  */
     5624  eoinfo.failed = FALSE;
     5625  eoinfo.finfo = &finfo;
     5626  eoinfo.localsyms = TRUE;
     5627  elf_link_hash_traverse (elf_hash_table (info), elf_link_output_extsym,
     5628                          (PTR) &eoinfo);
     5629  if (eoinfo.failed)
     5630    return FALSE;
     5631
    46275632  /* That wrote out all the local symbols.  Finish up the symbol table
    46285633     with the global symbols. Even if we want to strip everything we
     
    46305635     converted to local in a version script.  */
    46315636
    4632   if (info->shared)
    4633     {
    4634       /* Output any global symbols that got converted to local in a
    4635          version script.  We do this in a separate step since ELF
    4636          requires all local symbols to appear prior to any global
    4637          symbols.  FIXME: We should only do this if some global
    4638          symbols were, in fact, converted to become local.  FIXME:
    4639          Will this work correctly with the Irix 5 linker?  */
    4640       eoinfo.failed = false;
    4641       eoinfo.finfo = &finfo;
    4642       eoinfo.localsyms = true;
    4643       elf_link_hash_traverse (elf_hash_table (info), elf_link_output_extsym,
    4644                               (PTR) &eoinfo);
    4645       if (eoinfo.failed)
    4646         return false;
    4647     }
    4648 
    46495637  /* The sh_info field records the index of the first non local symbol.  */
    46505638  symtab_hdr->sh_info = bfd_get_symcount (abfd);
     
    46555643      Elf_Internal_Sym sym;
    46565644      Elf_External_Sym *dynsym =
    4657         (Elf_External_Sym *)finfo.dynsym_sec->contents;
     5645        (Elf_External_Sym *) finfo.dynsym_sec->contents;
    46585646      long last_local = 0;
    46595647
     
    46715659            {
    46725660              int indx;
     5661              Elf_External_Sym *dest;
     5662
    46735663              indx = elf_section_data (s)->this_idx;
    46745664              BFD_ASSERT (indx > 0);
    46755665              sym.st_shndx = indx;
    46765666              sym.st_value = s->vma;
    4677 
    4678               elf_swap_symbol_out (abfd, &sym,
    4679                                    dynsym + elf_section_data (s)->dynindx);
     5667              dest = dynsym + elf_section_data (s)->dynindx;
     5668              elf_swap_symbol_out (abfd, &sym, (PTR) dest, (PTR) 0);
    46805669            }
    46815670
     
    46905679            {
    46915680              asection *s;
     5681              Elf_External_Sym *dest;
    46925682
    46935683              sym.st_size = e->isym.st_size;
     
    46965686              /* Copy the internal symbol as is.
    46975687                 Note that we saved a word of storage and overwrote
    4698                  the original st_name with the dynstr_index.  */
    4699               sym = e->isym;
    4700 
    4701               if (e->isym.st_shndx > 0 && e->isym.st_shndx < SHN_LORESERVE)
     5688                 the original st_name with the dynstr_index.  */
     5689              sym = e->isym;
     5690
     5691              if (e->isym.st_shndx != SHN_UNDEF
     5692                  && (e->isym.st_shndx < SHN_LORESERVE
     5693                      || e->isym.st_shndx > SHN_HIRESERVE))
    47025694                {
    47035695                  s = bfd_section_from_elf_index (e->input_bfd,
     
    47145706                last_local = e->dynindx;
    47155707
    4716               elf_swap_symbol_out (abfd, &sym, dynsym + e->dynindx);
     5708              dest = dynsym + e->dynindx;
     5709              elf_swap_symbol_out (abfd, &sym, (PTR) dest, (PTR) 0);
    47175710            }
    47185711        }
     
    47235716
    47245717  /* We get the global symbols from the hash table.  */
    4725   eoinfo.failed = false;
    4726   eoinfo.localsyms = false;
     5718  eoinfo.failed = FALSE;
     5719  eoinfo.localsyms = FALSE;
    47275720  eoinfo.finfo = &finfo;
    47285721  elf_link_hash_traverse (elf_hash_table (info), elf_link_output_extsym,
    47295722                          (PTR) &eoinfo);
    47305723  if (eoinfo.failed)
    4731     return false;
     5724    return FALSE;
    47325725
    47335726  /* If backend needs to output some symbols not present in the hash
     
    47355728  if (bed->elf_backend_output_arch_syms)
    47365729    {
    4737       if (! (*bed->elf_backend_output_arch_syms)
    4738               (abfd, info, (PTR) &finfo,
    4739                (boolean (*) PARAMS ((PTR, const char *,
    4740                             Elf_Internal_Sym *, asection *)))
    4741                elf_link_output_sym))
    4742         return false;
     5730      typedef bfd_boolean (*out_sym_func)
     5731        PARAMS ((PTR, const char *, Elf_Internal_Sym *, asection *));
     5732
     5733      if (! ((*bed->elf_backend_output_arch_syms)
     5734             (abfd, info, (PTR) &finfo, (out_sym_func) elf_link_output_sym)))
     5735        return FALSE;
    47435736    }
    47445737
    47455738  /* Flush all symbols to the file.  */
    47465739  if (! elf_link_flush_output_syms (&finfo))
    4747     return false;
     5740    return FALSE;
    47485741
    47495742  /* Now we know the size of the symtab section.  */
    47505743  off += symtab_hdr->sh_size;
     5744
     5745  symtab_shndx_hdr = &elf_tdata (abfd)->symtab_shndx_hdr;
     5746  if (symtab_shndx_hdr->sh_name != 0)
     5747    {
     5748      symtab_shndx_hdr->sh_type = SHT_SYMTAB_SHNDX;
     5749      symtab_shndx_hdr->sh_entsize = sizeof (Elf_External_Sym_Shndx);
     5750      symtab_shndx_hdr->sh_addralign = sizeof (Elf_External_Sym_Shndx);
     5751      amt = bfd_get_symcount (abfd) * sizeof (Elf_External_Sym_Shndx);
     5752      symtab_shndx_hdr->sh_size = amt;
     5753
     5754      off = _bfd_elf_assign_file_position_for_section (symtab_shndx_hdr,
     5755                                                       off, TRUE);
     5756
     5757      if (bfd_seek (abfd, symtab_shndx_hdr->sh_offset, SEEK_SET) != 0
     5758          || (bfd_bwrite ((PTR) finfo.symshndxbuf, amt, abfd) != amt))
     5759        return FALSE;
     5760    }
     5761
    47515762
    47525763  /* Finish up and write out the symbol string table (.strtab)
     
    47645775  symstrtab_hdr->sh_addralign = 1;
    47655776
    4766   off = _bfd_elf_assign_file_position_for_section (symstrtab_hdr, off, true);
     5777  off = _bfd_elf_assign_file_position_for_section (symstrtab_hdr, off, TRUE);
    47675778  elf_tdata (abfd)->next_file_pos = off;
    47685779
     
    47715782      if (bfd_seek (abfd, symstrtab_hdr->sh_offset, SEEK_SET) != 0
    47725783          || ! _bfd_stringtab_emit (abfd, finfo.symstrtab))
    4773         return false;
     5784        return FALSE;
    47745785    }
    47755786
     
    47945805    }
    47955806
     5807  if (dynamic && info->combreloc && dynobj != NULL)
     5808    relativecount = elf_link_sort_relocs (abfd, info, &reldyn);
     5809
    47965810  /* If we are linking against a dynamic object, or generating a
    47975811     shared library, finish up the dynamic linking information.  */
     
    48175831            {
    48185832            default:
     5833              break;
     5834            case DT_NULL:
     5835              if (relativecount > 0 && dyncon + 1 < dynconend)
     5836                {
     5837                  switch (elf_section_data (reldyn)->this_hdr.sh_type)
     5838                    {
     5839                    case SHT_REL: dyn.d_tag = DT_RELCOUNT; break;
     5840                    case SHT_RELA: dyn.d_tag = DT_RELACOUNT; break;
     5841                    default: break;
     5842                    }
     5843                  if (dyn.d_tag != DT_NULL)
     5844                    {
     5845                      dyn.d_un.d_val = relativecount;
     5846                      elf_swap_dyn_out (dynobj, &dyn, dyncon);
     5847                      relativecount = 0;
     5848                    }
     5849                }
    48195850              break;
    48205851            case DT_INIT:
     
    48285859
    48295860                h = elf_link_hash_lookup (elf_hash_table (info), name,
    4830                                           false, false, true);
     5861                                          FALSE, FALSE, TRUE);
    48315862                if (h != NULL
    48325863                    && (h->root.type == bfd_link_hash_defined
     
    48495880              }
    48505881              break;
     5882
     5883            case DT_PREINIT_ARRAYSZ:
     5884              name = ".preinit_array";
     5885              goto get_size;
     5886            case DT_INIT_ARRAYSZ:
     5887              name = ".init_array";
     5888              goto get_size;
     5889            case DT_FINI_ARRAYSZ:
     5890              name = ".fini_array";
     5891            get_size:
     5892              o = bfd_get_section_by_name (abfd, name);
     5893              if (o == NULL)
     5894                {
     5895                  (*_bfd_error_handler)
     5896                    (_("%s: could not find output section %s"),
     5897                     bfd_get_filename (abfd), name);
     5898                  goto error_return;
     5899                }
     5900              if (o->_raw_size == 0)
     5901                (*_bfd_error_handler)
     5902                  (_("warning: %s section has zero size"), name);
     5903              dyn.d_un.d_val = o->_raw_size;
     5904              elf_swap_dyn_out (dynobj, &dyn, dyncon);
     5905              break;
     5906
     5907            case DT_PREINIT_ARRAY:
     5908              name = ".preinit_array";
     5909              goto get_vma;
     5910            case DT_INIT_ARRAY:
     5911              name = ".init_array";
     5912              goto get_vma;
     5913            case DT_FINI_ARRAY:
     5914              name = ".fini_array";
     5915              goto get_vma;
    48515916
    48525917            case DT_HASH:
     
    48695934            get_vma:
    48705935              o = bfd_get_section_by_name (abfd, name);
    4871               BFD_ASSERT (o != NULL);
     5936              if (o == NULL)
     5937                {
     5938                  (*_bfd_error_handler)
     5939                    (_("%s: could not find output section %s"),
     5940                     bfd_get_filename (abfd), name);
     5941                  goto error_return;
     5942                }
    48725943              dyn.d_un.d_ptr = o->vma;
    48735944              elf_swap_dyn_out (dynobj, &dyn, dyncon);
     
    48835954                type = SHT_RELA;
    48845955              dyn.d_un.d_val = 0;
    4885               for (i = 1; i < elf_elfheader (abfd)->e_shnum; i++)
     5956              for (i = 1; i < elf_numsections (abfd); i++)
    48865957                {
    48875958                  Elf_Internal_Shdr *hdr;
     
    49225993            {
    49235994              /* At this point, we are only interested in sections
    4924                 created by elf_link_create_dynamic_sections.  */
     5995                created by elf_link_create_dynamic_sections.  */
    49255996              continue;
    49265997            }
     
    49306001            {
    49316002              if (! bfd_set_section_contents (abfd, o->output_section,
    4932                                               o->contents, o->output_offset,
     6003                                              o->contents,
     6004                                              (file_ptr) o->output_offset,
    49336005                                              o->_raw_size))
    49346006                goto error_return;
     
    49366008          else
    49376009            {
    4938               file_ptr off;
    4939 
    49406010              /* The contents of the .dynstr section are actually in a
    4941                 stringtab.  */
     6011                stringtab.  */
    49426012              off = elf_section_data (o->output_section)->this_hdr.sh_offset;
    49436013              if (bfd_seek (abfd, off, SEEK_SET) != 0
    4944                   || ! _bfd_stringtab_emit (abfd,
    4945                                             elf_hash_table (info)->dynstr))
     6014                  || ! _bfd_elf_strtab_emit (abfd,
     6015                                             elf_hash_table (info)->dynstr))
    49466016                goto error_return;
    49476017            }
     
    49496019    }
    49506020
     6021  if (info->relocateable)
     6022    {
     6023      bfd_boolean failed = FALSE;
     6024
     6025      bfd_map_over_sections (abfd, bfd_elf_set_group_contents, &failed);
     6026      if (failed)
     6027        goto error_return;
     6028    }
     6029
    49516030  /* If we have optimized stabs strings, output them.  */
    49526031  if (elf_hash_table (info)->stab_info != NULL)
    49536032    {
    49546033      if (! _bfd_write_stab_strings (abfd, &elf_hash_table (info)->stab_info))
     6034        goto error_return;
     6035    }
     6036
     6037  if (info->eh_frame_hdr)
     6038    {
     6039      if (! _bfd_elf_write_section_eh_frame_hdr (abfd, info))
    49556040        goto error_return;
    49566041    }
     
    49666051  if (finfo.external_syms != NULL)
    49676052    free (finfo.external_syms);
     6053  if (finfo.locsym_shndx != NULL)
     6054    free (finfo.locsym_shndx);
    49686055  if (finfo.internal_syms != NULL)
    49696056    free (finfo.internal_syms);
     
    49746061  if (finfo.symbuf != NULL)
    49756062    free (finfo.symbuf);
     6063  if (finfo.symshndxbuf != NULL)
     6064    free (finfo.symshndxbuf);
    49766065  for (o = abfd->sections; o != NULL; o = o->next)
    49776066    {
     
    49816070    }
    49826071
    4983   elf_tdata (abfd)->linker = true;
    4984 
    4985   return true;
     6072  elf_tdata (abfd)->linker = TRUE;
     6073
     6074  return TRUE;
    49866075
    49876076 error_return:
     
    49966085  if (finfo.external_syms != NULL)
    49976086    free (finfo.external_syms);
     6087  if (finfo.locsym_shndx != NULL)
     6088    free (finfo.locsym_shndx);
    49986089  if (finfo.internal_syms != NULL)
    49996090    free (finfo.internal_syms);
     
    50046095  if (finfo.symbuf != NULL)
    50056096    free (finfo.symbuf);
     6097  if (finfo.symshndxbuf != NULL)
     6098    free (finfo.symshndxbuf);
    50066099  for (o = abfd->sections; o != NULL; o = o->next)
    50076100    {
     
    50116104    }
    50126105
    5013   return false;
     6106  return FALSE;
    50146107}
    50156108
    50166109/* Add a symbol to the output symbol table.  */
    50176110
    5018 static boolean
     6111static bfd_boolean
    50196112elf_link_output_sym (finfo, name, elfsym, input_sec)
    50206113     struct elf_final_link_info *finfo;
     
    50236116     asection *input_sec;
    50246117{
    5025   boolean (*output_symbol_hook) PARAMS ((bfd *,
    5026                                          struct bfd_link_info *info,
    5027                                          const char *,
    5028                                          Elf_Internal_Sym *,
    5029                                         asection *));
     6118  Elf_External_Sym *dest;
     6119  Elf_External_Sym_Shndx *destshndx;
     6120  bfd_boolean (*output_symbol_hook)
     6121    PARAMS ((bfd *, struct bfd_link_info *info, const char *,
     6122             Elf_Internal_Sym *, asection *));
    50306123
    50316124  output_symbol_hook = get_elf_backend_data (finfo->output_bfd)->
     
    50356128      if (! ((*output_symbol_hook)
    50366129             (finfo->output_bfd, finfo->info, name, elfsym, input_sec)))
    5037         return false;
     6130        return FALSE;
    50386131    }
    50396132
     
    50456138    {
    50466139      elfsym->st_name = (unsigned long) _bfd_stringtab_add (finfo->symstrtab,
    5047                                                             name, true,
    5048                                                             false);
     6140                                                            name, TRUE, FALSE);
    50496141      if (elfsym->st_name == (unsigned long) -1)
    5050         return false;
     6142        return FALSE;
    50516143    }
    50526144
     
    50546146    {
    50556147      if (! elf_link_flush_output_syms (finfo))
    5056         return false;
    5057     }
    5058 
    5059   elf_swap_symbol_out (finfo->output_bfd, elfsym,
    5060                        (PTR) (finfo->symbuf + finfo->symbuf_count));
    5061   ++finfo->symbuf_count;
    5062 
    5063   ++ bfd_get_symcount (finfo->output_bfd);
    5064 
    5065   return true;
     6148        return FALSE;
     6149    }
     6150
     6151  dest = finfo->symbuf + finfo->symbuf_count;
     6152  destshndx = finfo->symshndxbuf;
     6153  if (destshndx != NULL)
     6154    {
     6155      if (bfd_get_symcount (finfo->output_bfd) >= finfo->shndxbuf_size)
     6156        {
     6157          bfd_size_type amt;
     6158
     6159          amt = finfo->shndxbuf_size * sizeof (Elf_External_Sym_Shndx);
     6160          finfo->symshndxbuf = destshndx = bfd_realloc (destshndx, amt * 2);
     6161          if (destshndx == NULL)
     6162            return FALSE;
     6163          memset ((char *) destshndx + amt, 0, amt);
     6164          finfo->shndxbuf_size *= 2;
     6165        }
     6166      destshndx += bfd_get_symcount (finfo->output_bfd);
     6167    }
     6168
     6169  elf_swap_symbol_out (finfo->output_bfd, elfsym, (PTR) dest, (PTR) destshndx);
     6170  finfo->symbuf_count += 1;
     6171  bfd_get_symcount (finfo->output_bfd) += 1;
     6172
     6173  return TRUE;
    50666174}
    50676175
    50686176/* Flush the output symbols to the file.  */
    50696177
    5070 static boolean
     6178static bfd_boolean
    50716179elf_link_flush_output_syms (finfo)
    50726180     struct elf_final_link_info *finfo;
     
    50746182  if (finfo->symbuf_count > 0)
    50756183    {
    5076       Elf_Internal_Shdr *symtab;
    5077 
    5078       symtab = &elf_tdata (finfo->output_bfd)->symtab_hdr;
    5079 
    5080       if (bfd_seek (finfo->output_bfd, symtab->sh_offset + symtab->sh_size,
    5081                     SEEK_SET) != 0
    5082           || (bfd_write ((PTR) finfo->symbuf, finfo->symbuf_count,
    5083                          sizeof (Elf_External_Sym), finfo->output_bfd)
    5084               != finfo->symbuf_count * sizeof (Elf_External_Sym)))
    5085         return false;
    5086 
    5087       symtab->sh_size += finfo->symbuf_count * sizeof (Elf_External_Sym);
    5088 
     6184      Elf_Internal_Shdr *hdr;
     6185      file_ptr pos;
     6186      bfd_size_type amt;
     6187
     6188      hdr = &elf_tdata (finfo->output_bfd)->symtab_hdr;
     6189      pos = hdr->sh_offset + hdr->sh_size;
     6190      amt = finfo->symbuf_count * sizeof (Elf_External_Sym);
     6191      if (bfd_seek (finfo->output_bfd, pos, SEEK_SET) != 0
     6192          || bfd_bwrite ((PTR) finfo->symbuf, amt, finfo->output_bfd) != amt)
     6193        return FALSE;
     6194
     6195      hdr->sh_size += amt;
    50896196      finfo->symbuf_count = 0;
    50906197    }
    50916198
    5092   return true;
     6199  return TRUE;
     6200}
     6201
     6202/* Adjust all external symbols pointing into SEC_MERGE sections
     6203   to reflect the object merging within the sections.  */
     6204
     6205static bfd_boolean
     6206elf_link_sec_merge_syms (h, data)
     6207     struct elf_link_hash_entry *h;
     6208     PTR data;
     6209{
     6210  asection *sec;
     6211
     6212  if (h->root.type == bfd_link_hash_warning)
     6213    h = (struct elf_link_hash_entry *) h->root.u.i.link;
     6214
     6215  if ((h->root.type == bfd_link_hash_defined
     6216       || h->root.type == bfd_link_hash_defweak)
     6217      && ((sec = h->root.u.def.section)->flags & SEC_MERGE)
     6218      && sec->sec_info_type == ELF_INFO_TYPE_MERGE)
     6219    {
     6220      bfd *output_bfd = (bfd *) data;
     6221
     6222      h->root.u.def.value =
     6223        _bfd_merged_section_offset (output_bfd,
     6224                                    &h->root.u.def.section,
     6225                                    elf_section_data (sec)->sec_info,
     6226                                    h->root.u.def.value, (bfd_vma) 0);
     6227    }
     6228
     6229  return TRUE;
     6230}
     6231
     6232/* For DSOs loaded in via a DT_NEEDED entry, emulate ld.so in
     6233   allowing an unsatisfied unversioned symbol in the DSO to match a
     6234   versioned symbol that would normally require an explicit version.
     6235   We also handle the case that a DSO references a hidden symbol
     6236   which may be satisfied by a versioned symbol in another DSO.  */
     6237
     6238static bfd_boolean
     6239elf_link_check_versioned_symbol (info, h)
     6240     struct bfd_link_info *info;
     6241     struct elf_link_hash_entry *h;
     6242{
     6243  bfd *abfd;
     6244  struct elf_link_loaded_list *loaded;
     6245
     6246  if (info->hash->creator->flavour != bfd_target_elf_flavour)
     6247    return FALSE;
     6248
     6249  switch (h->root.type)
     6250    {
     6251    default:
     6252      abfd = NULL;
     6253      break;
     6254
     6255    case bfd_link_hash_undefined:
     6256    case bfd_link_hash_undefweak:
     6257      abfd = h->root.u.undef.abfd;
     6258      if ((abfd->flags & DYNAMIC) == 0 || elf_dt_soname (abfd) == NULL)
     6259        return FALSE;
     6260      break;
     6261
     6262    case bfd_link_hash_defined:
     6263    case bfd_link_hash_defweak:
     6264      abfd = h->root.u.def.section->owner;
     6265      break;
     6266
     6267    case bfd_link_hash_common:
     6268      abfd = h->root.u.c.p->section->owner;
     6269      break;
     6270    }
     6271  BFD_ASSERT (abfd != NULL);
     6272
     6273  for (loaded = elf_hash_table (info)->loaded;
     6274       loaded != NULL;
     6275       loaded = loaded->next)
     6276    {
     6277      bfd *input;
     6278      Elf_Internal_Shdr *hdr;
     6279      bfd_size_type symcount;
     6280      bfd_size_type extsymcount;
     6281      bfd_size_type extsymoff;
     6282      Elf_Internal_Shdr *versymhdr;
     6283      Elf_Internal_Sym *isym;
     6284      Elf_Internal_Sym *isymend;
     6285      Elf_Internal_Sym *isymbuf;
     6286      Elf_External_Versym *ever;
     6287      Elf_External_Versym *extversym;
     6288
     6289      input = loaded->abfd;
     6290
     6291      /* We check each DSO for a possible hidden versioned definition.  */
     6292      if (input == abfd
     6293          || (input->flags & DYNAMIC) == 0
     6294          || elf_dynversym (input) == 0)
     6295        continue;
     6296
     6297      hdr = &elf_tdata (input)->dynsymtab_hdr;
     6298
     6299      symcount = hdr->sh_size / sizeof (Elf_External_Sym);
     6300      if (elf_bad_symtab (input))
     6301        {
     6302          extsymcount = symcount;
     6303          extsymoff = 0;
     6304        }
     6305      else
     6306        {
     6307          extsymcount = symcount - hdr->sh_info;
     6308          extsymoff = hdr->sh_info;
     6309        }
     6310
     6311      if (extsymcount == 0)
     6312        continue;
     6313
     6314      isymbuf = bfd_elf_get_elf_syms (input, hdr, extsymcount, extsymoff,
     6315                                      NULL, NULL, NULL);
     6316      if (isymbuf == NULL)
     6317        return FALSE;
     6318
     6319      /* Read in any version definitions.  */
     6320      versymhdr = &elf_tdata (input)->dynversym_hdr;
     6321      extversym = (Elf_External_Versym *) bfd_malloc (versymhdr->sh_size);
     6322      if (extversym == NULL)
     6323        goto error_ret;
     6324
     6325      if (bfd_seek (input, versymhdr->sh_offset, SEEK_SET) != 0
     6326          || (bfd_bread ((PTR) extversym, versymhdr->sh_size, input)
     6327              != versymhdr->sh_size))
     6328        {
     6329          free (extversym);
     6330        error_ret:
     6331          free (isymbuf);
     6332          return FALSE;
     6333        }
     6334
     6335      ever = extversym + extsymoff;
     6336      isymend = isymbuf + extsymcount;
     6337      for (isym = isymbuf; isym < isymend; isym++, ever++)
     6338        {
     6339          const char *name;
     6340          Elf_Internal_Versym iver;
     6341
     6342          if (ELF_ST_BIND (isym->st_info) == STB_LOCAL
     6343              || isym->st_shndx == SHN_UNDEF)
     6344            continue;
     6345
     6346          name = bfd_elf_string_from_elf_section (input,
     6347                                                  hdr->sh_link,
     6348                                                  isym->st_name);
     6349          if (strcmp (name, h->root.root.string) != 0)
     6350            continue;
     6351
     6352          _bfd_elf_swap_versym_in (input, ever, &iver);
     6353
     6354          if ((iver.vs_vers & VERSYM_HIDDEN) == 0)
     6355            {
     6356              /* If we have a non-hidden versioned sym, then it should
     6357                 have provided a definition for the undefined sym.  */
     6358              abort ();
     6359            }
     6360
     6361          if ((iver.vs_vers & VERSYM_VERSION) == 2)
     6362            {
     6363              /* This is the oldest (default) sym.  We can use it.  */
     6364              free (extversym);
     6365              free (isymbuf);
     6366              return TRUE;
     6367            }
     6368        }
     6369
     6370      free (extversym);
     6371      free (isymbuf);
     6372    }
     6373
     6374  return FALSE;
    50936375}
    50946376
     
    51006382   global symbols.  */
    51016383
    5102 static boolean
     6384static bfd_boolean
    51036385elf_link_output_extsym (h, data)
    51046386     struct elf_link_hash_entry *h;
     
    51076389  struct elf_outext_info *eoinfo = (struct elf_outext_info *) data;
    51086390  struct elf_final_link_info *finfo = eoinfo->finfo;
    5109   boolean strip;
     6391  bfd_boolean strip;
    51106392  Elf_Internal_Sym sym;
    51116393  asection *input_sec;
    51126394
     6395  if (h->root.type == bfd_link_hash_warning)
     6396    {
     6397      h = (struct elf_link_hash_entry *) h->root.u.i.link;
     6398      if (h->root.type == bfd_link_hash_new)
     6399        return TRUE;
     6400    }
     6401
    51136402  /* Decide whether to output this symbol in this pass.  */
    51146403  if (eoinfo->localsyms)
    51156404    {
    51166405      if ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
    5117         return true;
     6406        return TRUE;
    51186407    }
    51196408  else
    51206409    {
    51216410      if ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)
    5122         return true;
     6411        return TRUE;
    51236412    }
    51246413
     
    51316420     warnings for them.  */
    51326421  if (! finfo->info->relocateable
    5133       && ! finfo->info->allow_shlib_undefined
    5134       && ! (finfo->info->shared
    5135             && !finfo->info->no_undefined)
     6422      && (! finfo->info->shared || ! finfo->info->allow_shlib_undefined)
    51366423      && h->root.type == bfd_link_hash_undefined
    51376424      && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0
    5138       && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0)
     6425      && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0
     6426      && ! elf_link_check_versioned_symbol (finfo->info, h))
    51396427    {
    51406428      if (! ((*finfo->info->callbacks->undefined_symbol)
    51416429             (finfo->info, h->root.root.string, h->root.u.undef.abfd,
    5142               (asection *) NULL, 0, true)))
    5143         {
    5144           eoinfo->failed = true;
    5145           return false;
    5146         }
     6430              (asection *) NULL, (bfd_vma) 0, TRUE)))
     6431        {
     6432          eoinfo->failed = TRUE;
     6433          return FALSE;
     6434        }
     6435    }
     6436
     6437  /* We should also warn if a forced local symbol is referenced from
     6438     shared libraries.  */
     6439  if (! finfo->info->relocateable
     6440      && (! finfo->info->shared || ! finfo->info->allow_shlib_undefined)
     6441      && (h->elf_link_hash_flags
     6442          & (ELF_LINK_FORCED_LOCAL | ELF_LINK_HASH_REF_DYNAMIC
     6443             | ELF_LINK_DYNAMIC_DEF | ELF_LINK_DYNAMIC_WEAK))
     6444         == (ELF_LINK_FORCED_LOCAL | ELF_LINK_HASH_REF_DYNAMIC)
     6445      && ! elf_link_check_versioned_symbol (finfo->info, h))
     6446    {
     6447      (*_bfd_error_handler)
     6448        (_("%s: %s symbol `%s' in %s is referenced by DSO"),
     6449         bfd_get_filename (finfo->output_bfd),
     6450         ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
     6451         ? "internal"
     6452         : ELF_ST_VISIBILITY (h->other) == STV_HIDDEN
     6453           ? "hidden" : "local",
     6454         h->root.root.string,
     6455         bfd_archive_filename (h->root.u.def.section->owner));
     6456      eoinfo->failed = TRUE;
     6457      return FALSE;
    51476458    }
    51486459
     
    51526463     output it.  */
    51536464  if (h->indx == -2)
    5154     strip = false;
     6465    strip = FALSE;
    51556466  else if (((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
    51566467            || (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0)
    51576468           && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0
    51586469           && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0)
    5159     strip = true;
    5160   else if (finfo->info->strip == strip_all
    5161            || (finfo->info->strip == strip_some
    5162                && bfd_hash_lookup (finfo->info->keep_hash,
    5163                                    h->root.root.string,
    5164                                    false, false) == NULL))
    5165     strip = true;
     6470    strip = TRUE;
     6471  else if (finfo->info->strip == strip_all)
     6472    strip = TRUE;
     6473  else if (finfo->info->strip == strip_some
     6474           && bfd_hash_lookup (finfo->info->keep_hash,
     6475                               h->root.root.string, FALSE, FALSE) == NULL)
     6476    strip = TRUE;
     6477  else if (finfo->info->strip_discarded
     6478           && (h->root.type == bfd_link_hash_defined
     6479               || h->root.type == bfd_link_hash_defweak)
     6480           && elf_discarded_section (h->root.u.def.section))
     6481    strip = TRUE;
    51666482  else
    5167     strip = false;
     6483    strip = FALSE;
    51686484
    51696485  /* If we're stripping it, and it's not a dynamic symbol, there's
     
    51726488      && h->dynindx == -1
    51736489      && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
    5174     return true;
     6490    return TRUE;
    51756491
    51766492  sym.st_value = 0;
     
    51896505    default:
    51906506    case bfd_link_hash_new:
     6507    case bfd_link_hash_warning:
    51916508      abort ();
    5192       return false;
     6509      return FALSE;
    51936510
    51946511    case bfd_link_hash_undefined:
    5195       input_sec = bfd_und_section_ptr;
    5196       sym.st_shndx = SHN_UNDEF;
    5197       break;
    5198 
    51996512    case bfd_link_hash_undefweak:
    52006513      input_sec = bfd_und_section_ptr;
     
    52116524              _bfd_elf_section_from_bfd_section (finfo->output_bfd,
    52126525                                                 input_sec->output_section);
    5213             if (sym.st_shndx == (unsigned short) -1)
     6526            if (sym.st_shndx == SHN_BAD)
    52146527              {
    52156528                (*_bfd_error_handler)
     
    52186531                   input_sec->output_section->name,
    52196532                   input_sec->name);
    5220                 eoinfo->failed = true;
    5221                 return false;
     6533                eoinfo->failed = TRUE;
     6534                return FALSE;
    52226535              }
    52236536
     
    52276540            sym.st_value = h->root.u.def.value + input_sec->output_offset;
    52286541            if (! finfo->info->relocateable)
    5229               sym.st_value += input_sec->output_section->vma;
     6542              {
     6543                sym.st_value += input_sec->output_section->vma;
     6544                if (h->type == STT_TLS)
     6545                  {
     6546                    /* STT_TLS symbols are relative to PT_TLS segment
     6547                       base.  */
     6548                    BFD_ASSERT (finfo->first_tls_sec != NULL);
     6549                    sym.st_value -= finfo->first_tls_sec->vma;
     6550                  }
     6551              }
    52306552          }
    52316553        else
     
    52476569    case bfd_link_hash_indirect:
    52486570      /* These symbols are created by symbol versioning.  They point
    5249          to the decorated version of the name.  For example, if the
    5250          symbol foo@@GNU_1.2 is the default, which should be used when
    5251          foo is used with no version, then we add an indirect symbol
    5252          foo which points to foo@@GNU_1.2.  We ignore these symbols,
    5253          since the indirected symbol is already in the hash table.  */
    5254       return true;
    5255 
    5256     case bfd_link_hash_warning:
    5257       /* We can't represent these symbols in ELF, although a warning
    5258          symbol may have come from a .gnu.warning.SYMBOL section.  We
    5259          just put the target symbol in the hash table.  If the target
    5260          symbol does not really exist, don't do anything.  */
    5261       if (h->root.u.i.link->type == bfd_link_hash_new)
    5262         return true;
    5263       return (elf_link_output_extsym
    5264               ((struct elf_link_hash_entry *) h->root.u.i.link, data));
     6571         to the decorated version of the name.  For example, if the
     6572         symbol foo@@GNU_1.2 is the default, which should be used when
     6573         foo is used with no version, then we add an indirect symbol
     6574         foo which points to foo@@GNU_1.2.  We ignore these symbols,
     6575         since the indirected symbol is already in the hash table.  */
     6576      return TRUE;
    52656577    }
    52666578
    52676579  /* Give the processor backend a chance to tweak the symbol value,
    52686580     and also to finish up anything that needs to be done for this
    5269      symbol.  */
     6581     symbol.  FIXME: Not calling elf_backend_finish_dynamic_symbol for
     6582     forced local syms when non-shared is due to a historical quirk.  */
    52706583  if ((h->dynindx != -1
    52716584       || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)
     6585      && (finfo->info->shared
     6586          || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
    52726587      && elf_hash_table (finfo->info)->dynamic_sections_created)
    52736588    {
     
    52786593             (finfo->output_bfd, finfo->info, h, &sym)))
    52796594        {
    5280           eoinfo->failed = true;
    5281           return false;
     6595          eoinfo->failed = TRUE;
     6596          return FALSE;
    52826597        }
    52836598    }
     
    52916606  if (sym.st_shndx == SHN_UNDEF
    52926607      && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) != 0
    5293       && (ELF_ST_BIND(sym.st_info) == STB_GLOBAL
    5294           || ELF_ST_BIND(sym.st_info) == STB_WEAK))
     6608      && (ELF_ST_BIND (sym.st_info) == STB_GLOBAL
     6609          || ELF_ST_BIND (sym.st_info) == STB_WEAK))
    52956610    {
    52966611      int bindtype;
     
    53036618    }
    53046619
    5305   /* If a symbol is not defined locally, we clear the visibility
    5306      field.  */
    5307   if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
    5308     sym.st_other ^= ELF_ST_VISIBILITY(sym.st_other);
     6620  /* If a non-weak symbol with non-default visibility is not defined
     6621     locally, it is a fatal error.  */
     6622  if (! finfo->info->relocateable
     6623      && ELF_ST_VISIBILITY (sym.st_other)
     6624      && ELF_ST_BIND (sym.st_info) != STB_WEAK
     6625      && h->root.type == bfd_link_hash_undefined
     6626      && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
     6627    {
     6628      (*_bfd_error_handler)
     6629        (_("%s: %s symbol `%s' isn't defined"),
     6630          bfd_get_filename (finfo->output_bfd),
     6631          ELF_ST_VISIBILITY (sym.st_other) == STV_PROTECTED
     6632          ? "protected"
     6633          : ELF_ST_VISIBILITY (sym.st_other) == STV_INTERNAL
     6634            ? "internal" : "hidden",
     6635          h->root.root.string);
     6636      eoinfo->failed = TRUE;
     6637      return FALSE;
     6638    }
    53096639
    53106640  /* If this symbol should be put in the .dynsym section, then put it
    5311      there now.  We have already know the symbol index.  We also fill
    5312      in the entry in the .hash section.  */
     6641     there now.  We already know the symbol index.  We also fill in
     6642     the entry in the .hash section.  */
    53136643  if (h->dynindx != -1
    53146644      && elf_hash_table (finfo->info)->dynamic_sections_created)
     
    53196649      bfd_byte *bucketpos;
    53206650      bfd_vma chain;
     6651      Elf_External_Sym *esym;
    53216652
    53226653      sym.st_name = h->dynstr_index;
    5323 
    5324       elf_swap_symbol_out (finfo->output_bfd, &sym,
    5325                            (PTR) (((Elf_External_Sym *)
    5326                                    finfo->dynsym_sec->contents)
    5327                                   + h->dynindx));
     6654      esym = (Elf_External_Sym *) finfo->dynsym_sec->contents + h->dynindx;
     6655      elf_swap_symbol_out (finfo->output_bfd, &sym, (PTR) esym, (PTR) 0);
    53286656
    53296657      bucketcount = elf_hash_table (finfo->info)->bucketcount;
     
    53346662                   + (bucket + 2) * hash_entry_size);
    53356663      chain = bfd_get (8 * hash_entry_size, finfo->output_bfd, bucketpos);
    5336       bfd_put (8 * hash_entry_size, finfo->output_bfd, h->dynindx, bucketpos);
     6664      bfd_put (8 * hash_entry_size, finfo->output_bfd, (bfd_vma) h->dynindx,
     6665               bucketpos);
    53376666      bfd_put (8 * hash_entry_size, finfo->output_bfd, chain,
    53386667               ((bfd_byte *) finfo->hash_sec->contents
     
    53426671        {
    53436672          Elf_Internal_Versym iversym;
     6673          Elf_External_Versym *eversym;
    53446674
    53456675          if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
     
    53616691            iversym.vs_vers |= VERSYM_HIDDEN;
    53626692
    5363           _bfd_elf_swap_versym_out (finfo->output_bfd, &iversym,
    5364                                     (((Elf_External_Versym *)
    5365                                       finfo->symver_sec->contents)
    5366                                      + h->dynindx));
     6693          eversym = (Elf_External_Versym *) finfo->symver_sec->contents;
     6694          eversym += h->dynindx;
     6695          _bfd_elf_swap_versym_out (finfo->output_bfd, &iversym, eversym);
    53676696        }
    53686697    }
     
    53706699  /* If we're stripping it, then it was just a dynamic symbol, and
    53716700     there's nothing else to do.  */
    5372   if (strip)
    5373     return true;
     6701  if (strip || (input_sec->flags & SEC_EXCLUDE) != 0)
     6702    return TRUE;
    53746703
    53756704  h->indx = bfd_get_symcount (finfo->output_bfd);
     
    53776706  if (! elf_link_output_sym (finfo, h->root.root.string, &sym, input_sec))
    53786707    {
    5379       eoinfo->failed = true;
    5380       return false;
    5381     }
    5382 
    5383   return true;
     6708      eoinfo->failed = TRUE;
     6709      return FALSE;
     6710    }
     6711
     6712  return TRUE;
    53846713}
    53856714
     
    53886717   OUTPUT_BFD.  */
    53896718
    5390 static void
     6719static bfd_boolean
    53916720elf_link_output_relocs (output_bfd, input_section, input_rel_hdr,
    53926721                        internal_relocs)
     
    53986727  Elf_Internal_Rela *irela;
    53996728  Elf_Internal_Rela *irelaend;
     6729  bfd_byte *erel;
    54006730  Elf_Internal_Shdr *output_rel_hdr;
    54016731  asection *output_section;
    54026732  unsigned int *rel_countp = NULL;
    54036733  struct elf_backend_data *bed;
     6734  void (*swap_out) PARAMS ((bfd *, const Elf_Internal_Rela *, bfd_byte *));
    54046735
    54056736  output_section = input_section->output_section;
     
    54196750      rel_countp = &elf_section_data (output_section)->rel_count2;
    54206751    }
    5421 
    5422   BFD_ASSERT (output_rel_hdr != NULL);
     6752  else
     6753    {
     6754      (*_bfd_error_handler)
     6755        (_("%s: relocation size mismatch in %s section %s"),
     6756         bfd_get_filename (output_bfd),
     6757         bfd_archive_filename (input_section->owner),
     6758         input_section->name);
     6759      bfd_set_error (bfd_error_wrong_object_format);
     6760      return FALSE;
     6761    }
    54236762
    54246763  bed = get_elf_backend_data (output_bfd);
     6764  if (input_rel_hdr->sh_entsize == sizeof (Elf_External_Rel))
     6765    swap_out = bed->s->swap_reloc_out;
     6766  else if (input_rel_hdr->sh_entsize == sizeof (Elf_External_Rela))
     6767    swap_out = bed->s->swap_reloca_out;
     6768  else
     6769    abort ();
     6770
     6771  erel = output_rel_hdr->contents;
     6772  erel += *rel_countp * input_rel_hdr->sh_entsize;
    54256773  irela = internal_relocs;
    5426   irelaend = irela + NUM_SHDR_ENTRIES (input_rel_hdr)
    5427                      * bed->s->int_rels_per_ext_rel;
    5428 
    5429   if (input_rel_hdr->sh_entsize == sizeof (Elf_External_Rel))
    5430     {
    5431       Elf_External_Rel *erel;
    5432       Elf_Internal_Rel *irel;
    5433      
    5434       irel = (Elf_Internal_Rel *) bfd_zmalloc (bed->s->int_rels_per_ext_rel
    5435                                                * sizeof (Elf_Internal_Rel));
    5436       if (irel == NULL)
    5437         {
    5438           (*_bfd_error_handler) (_("Error: out of memory"));
    5439           abort ();
    5440         }
    5441 
    5442       erel = ((Elf_External_Rel *) output_rel_hdr->contents + *rel_countp);
    5443       for (; irela < irelaend; irela += bed->s->int_rels_per_ext_rel, erel++)
    5444         {
    5445           unsigned int i;
    5446          
    5447           for (i = 0; i < bed->s->int_rels_per_ext_rel; i++)
    5448             {
    5449               irel[i].r_offset = irela[i].r_offset;
    5450               irel[i].r_info = irela[i].r_info;
    5451               BFD_ASSERT (irela[i].r_addend == 0);
    5452             }
    5453 
    5454           if (bed->s->swap_reloc_out)
    5455             (*bed->s->swap_reloc_out) (output_bfd, irel, (PTR) erel);
    5456           else
    5457             elf_swap_reloc_out (output_bfd, irel, erel);
    5458         }
    5459 
    5460       free (irel);
    5461     }
    5462   else
    5463     {
    5464       Elf_External_Rela *erela;
    5465 
    5466       BFD_ASSERT (input_rel_hdr->sh_entsize == sizeof (Elf_External_Rela));
    5467 
    5468       erela = ((Elf_External_Rela *) output_rel_hdr->contents + *rel_countp);
    5469       for (; irela < irelaend; irela += bed->s->int_rels_per_ext_rel, erela++)
    5470         if (bed->s->swap_reloca_out)
    5471           (*bed->s->swap_reloca_out) (output_bfd, irela, (PTR) erela);
    5472         else
    5473           elf_swap_reloca_out (output_bfd, irela, erela);
     6774  irelaend = irela + (NUM_SHDR_ENTRIES (input_rel_hdr)
     6775                      * bed->s->int_rels_per_ext_rel);
     6776  while (irela < irelaend)
     6777    {
     6778      (*swap_out) (output_bfd, irela, erel);
     6779      irela += bed->s->int_rels_per_ext_rel;
     6780      erel += input_rel_hdr->sh_entsize;
    54746781    }
    54756782
     
    54776784     relocations.  */
    54786785  *rel_countp += NUM_SHDR_ENTRIES (input_rel_hdr);
     6786
     6787  return TRUE;
    54796788}
    54806789
     
    54846793   don't have to keep them in memory.  */
    54856794
    5486 static boolean
     6795static bfd_boolean
    54876796elf_link_input_bfd (finfo, input_bfd)
    54886797     struct elf_final_link_info *finfo;
    54896798     bfd *input_bfd;
    54906799{
    5491   boolean (*relocate_section) PARAMS ((bfd *, struct bfd_link_info *,
    5492                                        bfd *, asection *, bfd_byte *,
    5493                                        Elf_Internal_Rela *,
    5494                                        Elf_Internal_Sym *, asection **));
     6800  bfd_boolean (*relocate_section)
     6801    PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
     6802             Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
    54956803  bfd *output_bfd;
    54966804  Elf_Internal_Shdr *symtab_hdr;
    54976805  size_t locsymcount;
    54986806  size_t extsymoff;
    5499   Elf_External_Sym *external_syms;
    5500   Elf_External_Sym *esym;
    5501   Elf_External_Sym *esymend;
     6807  Elf_Internal_Sym *isymbuf;
    55026808  Elf_Internal_Sym *isym;
     6809  Elf_Internal_Sym *isymend;
    55036810  long *pindex;
    55046811  asection **ppsection;
    55056812  asection *o;
    55066813  struct elf_backend_data *bed;
     6814  bfd_boolean emit_relocs;
     6815  struct elf_link_hash_entry **sym_hashes;
    55076816
    55086817  output_bfd = finfo->output_bfd;
     
    55146823     contents.  */
    55156824  if ((input_bfd->flags & DYNAMIC) != 0)
    5516     return true;
     6825    return TRUE;
     6826
     6827  emit_relocs = (finfo->info->relocateable
     6828                 || finfo->info->emitrelocations
     6829                 || bed->elf_backend_emit_relocs);
    55176830
    55186831  symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
     
    55296842
    55306843  /* Read the local symbols.  */
    5531   if (symtab_hdr->contents != NULL)
    5532     external_syms = (Elf_External_Sym *) symtab_hdr->contents;
    5533   else if (locsymcount == 0)
    5534     external_syms = NULL;
    5535   else
    5536     {
    5537       external_syms = finfo->external_syms;
    5538       if (bfd_seek (input_bfd, symtab_hdr->sh_offset, SEEK_SET) != 0
    5539           || (bfd_read (external_syms, sizeof (Elf_External_Sym),
    5540                         locsymcount, input_bfd)
    5541               != locsymcount * sizeof (Elf_External_Sym)))
    5542         return false;
    5543     }
    5544 
    5545   /* Swap in the local symbols and write out the ones which we know
    5546      are going into the output file.  */
    5547   esym = external_syms;
    5548   esymend = esym + locsymcount;
    5549   isym = finfo->internal_syms;
    5550   pindex = finfo->indices;
    5551   ppsection = finfo->sections;
    5552   for (; esym < esymend; esym++, isym++, pindex++, ppsection++)
     6844  isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
     6845  if (isymbuf == NULL && locsymcount != 0)
     6846    {
     6847      isymbuf = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, locsymcount, 0,
     6848                                      finfo->internal_syms,
     6849                                      finfo->external_syms,
     6850                                      finfo->locsym_shndx);
     6851      if (isymbuf == NULL)
     6852        return FALSE;
     6853    }
     6854
     6855  /* Find local symbol sections and adjust values of symbols in
     6856     SEC_MERGE sections.  Write out those local symbols we know are
     6857     going into the output file.  */
     6858  isymend = isymbuf + locsymcount;
     6859  for (isym = isymbuf, pindex = finfo->indices, ppsection = finfo->sections;
     6860       isym < isymend;
     6861       isym++, pindex++, ppsection++)
    55536862    {
    55546863      asection *isec;
     
    55566865      Elf_Internal_Sym osym;
    55576866
    5558       elf_swap_symbol_in (input_bfd, esym, isym);
    55596867      *pindex = -1;
    55606868
     
    55686876        }
    55696877
    5570       name = NULL;
    55716878      if (isym->st_shndx == SHN_UNDEF)
    5572         {
    5573           isec = bfd_und_section_ptr;
    5574           name = isec->name;
    5575         }
    5576       else if (isym->st_shndx > 0 && isym->st_shndx < SHN_LORESERVE)
    5577         isec = section_from_elf_index (input_bfd, isym->st_shndx);
     6879        isec = bfd_und_section_ptr;
     6880      else if (isym->st_shndx < SHN_LORESERVE
     6881               || isym->st_shndx > SHN_HIRESERVE)
     6882        {
     6883          isec = section_from_elf_index (input_bfd, isym->st_shndx);
     6884          if (isec
     6885              && isec->sec_info_type == ELF_INFO_TYPE_MERGE
     6886              && ELF_ST_TYPE (isym->st_info) != STT_SECTION)
     6887            isym->st_value =
     6888              _bfd_merged_section_offset (output_bfd, &isec,
     6889                                          elf_section_data (isec)->sec_info,
     6890                                          isym->st_value, (bfd_vma) 0);
     6891        }
    55786892      else if (isym->st_shndx == SHN_ABS)
    5579         {
    5580           isec = bfd_abs_section_ptr;
    5581           name = isec->name;
    5582         }
     6893        isec = bfd_abs_section_ptr;
    55836894      else if (isym->st_shndx == SHN_COMMON)
    5584         {
    5585           isec = bfd_com_section_ptr;
    5586           name = isec->name;
    5587         }
     6895        isec = bfd_com_section_ptr;
    55886896      else
    55896897        {
     
    55956903
    55966904      /* Don't output the first, undefined, symbol.  */
    5597       if (esym == external_syms)
     6905      if (ppsection == finfo->sections)
    55986906        continue;
    55996907
    56006908      if (ELF_ST_TYPE (isym->st_info) == STT_SECTION)
    56016909        {
    5602           asection *ksec;
    5603 
    5604           /* Save away all section symbol values.  */
    5605           if (isec != NULL)
    5606             {
    5607               if (name)
    5608                 {
    5609                   if (isec->symbol->value != isym->st_value)
    5610                     (*_bfd_error_handler)
    5611                       (_("%s: invalid section symbol index 0x%x (%s) ingored"),
    5612                        bfd_get_filename (input_bfd), isym->st_shndx,
    5613                        name);
    5614                   continue;
    5615                 }
    5616               isec->symbol->value = isym->st_value;
    5617             }
    5618 
    5619           /* If this is a discarded link-once section symbol, update
    5620              it's value to that of the kept section symbol.  The
    5621              linker will keep the first of any matching link-once
    5622              sections, so we should have already seen it's section
    5623              symbol.  I trust no-one will have the bright idea of
    5624              re-ordering the bfd list...  */
    5625           if (isec != NULL
    5626               && (bfd_get_section_flags (input_bfd, isec) & SEC_LINK_ONCE) != 0
    5627               && (ksec = isec->kept_section) != NULL)
    5628             {
    5629               isym->st_value = ksec->symbol->value;
    5630 
    5631               /* That put the value right, but the section info is all
    5632                  wrong.  I hope this works.  */
    5633               isec->output_offset = ksec->output_offset;
    5634               isec->output_section = ksec->output_section;
    5635             }
    5636 
    56376910          /* We never output section symbols.  Instead, we use the
    56386911             section symbol of the corresponding section in the output
     
    56556928
    56566929      /* If this symbol is defined in a section which we are
    5657          discarding, we don't need to keep it, but note that
    5658          linker_mark is only reliable for sections that have contents.
    5659          For the benefit of the MIPS ELF linker, we check SEC_EXCLUDE
    5660          as well as linker_mark.  */
    5661       if (isym->st_shndx > 0
    5662           && isym->st_shndx < SHN_LORESERVE
     6930         discarding, we don't need to keep it, but note that
     6931         linker_mark is only reliable for sections that have contents.
     6932         For the benefit of the MIPS ELF linker, we check SEC_EXCLUDE
     6933         as well as linker_mark.  */
     6934      if ((isym->st_shndx < SHN_LORESERVE || isym->st_shndx > SHN_HIRESERVE)
    56636935          && isec != NULL
    56646936          && ((! isec->linker_mark && (isec->flags & SEC_HAS_CONTENTS) != 0)
     
    56716943                                              isym->st_name);
    56726944      if (name == NULL)
    5673         return false;
     6945        return FALSE;
    56746946
    56756947      /* See if we are discarding symbols with this name.  */
    56766948      if ((finfo->info->strip == strip_some
    5677            && (bfd_hash_lookup (finfo->info->keep_hash, name, false, false)
     6949           && (bfd_hash_lookup (finfo->info->keep_hash, name, FALSE, FALSE)
    56786950               == NULL))
    5679           || (finfo->info->discard == discard_l
     6951          || (((finfo->info->discard == discard_sec_merge
     6952                && (isec->flags & SEC_MERGE) && ! finfo->info->relocateable)
     6953               || finfo->info->discard == discard_l)
    56806954              && bfd_is_local_label_name (input_bfd, name)))
    56816955        continue;
     
    56886962      osym.st_shndx = _bfd_elf_section_from_bfd_section (output_bfd,
    56896963                                                         isec->output_section);
    5690       if (osym.st_shndx == (unsigned short) -1)
    5691         return false;
     6964      if (osym.st_shndx == SHN_BAD)
     6965        return FALSE;
    56926966
    56936967      *pindex = bfd_get_symcount (output_bfd);
     
    57026976      osym.st_value += isec->output_offset;
    57036977      if (! finfo->info->relocateable)
    5704         osym.st_value += isec->output_section->vma;
     6978        {
     6979          osym.st_value += isec->output_section->vma;
     6980          if (ELF_ST_TYPE (osym.st_info) == STT_TLS)
     6981            {
     6982              /* STT_TLS symbols are relative to PT_TLS segment base.  */
     6983              BFD_ASSERT (finfo->first_tls_sec != NULL);
     6984              osym.st_value -= finfo->first_tls_sec->vma;
     6985            }
     6986        }
    57056987
    57066988      if (! elf_link_output_sym (finfo, name, &osym, isec))
    5707         return false;
     6989        return FALSE;
    57086990    }
    57096991
    57106992  /* Relocate the contents of each section.  */
     6993  sym_hashes = elf_sym_hashes (input_bfd);
    57116994  for (o = input_bfd->sections; o != NULL; o = o->next)
    57126995    {
     
    57317014
    57327015      /* Get the contents of the section.  They have been cached by a
    5733         relaxation routine.  Note that o is a section in an input
    5734         file, so the contents field will not have been set by any of
    5735         the routines which work on output files.  */
     7016        relaxation routine.  Note that o is a section in an input
     7017        file, so the contents field will not have been set by any of
     7018        the routines which work on output files.  */
    57367019      if (elf_section_data (o)->this_hdr.contents != NULL)
    57377020        contents = elf_section_data (o)->this_hdr.contents;
     
    57417024          if (! bfd_get_section_contents (input_bfd, o, contents,
    57427025                                          (file_ptr) 0, o->_raw_size))
    5743             return false;
     7026            return FALSE;
    57447027        }
    57457028
     
    57517034          internal_relocs = (NAME(_bfd_elf,link_read_relocs)
    57527035                             (input_bfd, o, finfo->external_relocs,
    5753                               finfo->internal_relocs, false));
     7036                              finfo->internal_relocs, FALSE));
    57547037          if (internal_relocs == NULL
    57557038              && o->reloc_count > 0)
    5756             return false;
     7039            return FALSE;
     7040
     7041          /* Run through the relocs looking for any against symbols
     7042             from discarded sections and section symbols from
     7043             removed link-once sections.  Complain about relocs
     7044             against discarded sections.  Zero relocs against removed
     7045             link-once sections.  */
     7046          if (!finfo->info->relocateable
     7047              && !elf_section_ignore_discarded_relocs (o))
     7048            {
     7049              Elf_Internal_Rela *rel, *relend;
     7050
     7051              rel = internal_relocs;
     7052              relend = rel + o->reloc_count * bed->s->int_rels_per_ext_rel;
     7053              for ( ; rel < relend; rel++)
     7054                {
     7055                  unsigned long r_symndx = ELF_R_SYM (rel->r_info);
     7056
     7057                  if (r_symndx >= locsymcount
     7058                      || (elf_bad_symtab (input_bfd)
     7059                          && finfo->sections[r_symndx] == NULL))
     7060                    {
     7061                      struct elf_link_hash_entry *h;
     7062
     7063                      h = sym_hashes[r_symndx - extsymoff];
     7064                      while (h->root.type == bfd_link_hash_indirect
     7065                             || h->root.type == bfd_link_hash_warning)
     7066                        h = (struct elf_link_hash_entry *) h->root.u.i.link;
     7067
     7068                      /* Complain if the definition comes from a
     7069                         discarded section.  */
     7070                      if ((h->root.type == bfd_link_hash_defined
     7071                           || h->root.type == bfd_link_hash_defweak)
     7072                          && elf_discarded_section (h->root.u.def.section))
     7073                        {
     7074                          if ((o->flags & SEC_DEBUGGING) != 0)
     7075                            {
     7076                              BFD_ASSERT (r_symndx != 0);
     7077                              memset (rel, 0, sizeof (*rel));
     7078                            }
     7079                          else
     7080                            {
     7081                              if (! ((*finfo->info->callbacks->undefined_symbol)
     7082                                     (finfo->info, h->root.root.string,
     7083                                      input_bfd, o, rel->r_offset,
     7084                                      TRUE)))
     7085                                return FALSE;
     7086                            }
     7087                        }
     7088                    }
     7089                  else
     7090                    {
     7091                      asection *sec = finfo->sections[r_symndx];
     7092
     7093                      if (sec != NULL && elf_discarded_section (sec))
     7094                        {
     7095                          if ((o->flags & SEC_DEBUGGING) != 0
     7096                              || (sec->flags & SEC_LINK_ONCE) != 0)
     7097                            {
     7098                              BFD_ASSERT (r_symndx != 0);
     7099                              rel->r_info
     7100                                = ELF_R_INFO (0, ELF_R_TYPE (rel->r_info));
     7101                              rel->r_addend = 0;
     7102                            }
     7103                          else
     7104                            {
     7105                              bfd_boolean ok;
     7106                              const char *msg
     7107                                = _("local symbols in discarded section %s");
     7108                              bfd_size_type amt
     7109                                = strlen (sec->name) + strlen (msg) - 1;
     7110                              char *buf = (char *) bfd_malloc (amt);
     7111
     7112                              if (buf != NULL)
     7113                                sprintf (buf, msg, sec->name);
     7114                              else
     7115                                buf = (char *) sec->name;
     7116                              ok = (*finfo->info->callbacks
     7117                                    ->undefined_symbol) (finfo->info, buf,
     7118                                                         input_bfd, o,
     7119                                                         rel->r_offset,
     7120                                                         TRUE);
     7121                              if (buf != sec->name)
     7122                                free (buf);
     7123                              if (!ok)
     7124                                return FALSE;
     7125                            }
     7126                        }
     7127                    }
     7128                }
     7129            }
    57577130
    57587131          /* Relocate the section by invoking a back end routine.
     
    57797152                                     input_bfd, o, contents,
    57807153                                     internal_relocs,
    5781                                      finfo->internal_syms,
     7154                                     isymbuf,
    57827155                                     finfo->sections))
    5783             return false;
    5784 
    5785           if (finfo->info->relocateable || finfo->info->emitrelocations)
     7156            return FALSE;
     7157
     7158          if (emit_relocs)
    57867159            {
    57877160              Elf_Internal_Rela *irela;
    57887161              Elf_Internal_Rela *irelaend;
     7162              bfd_vma last_offset;
    57897163              struct elf_link_hash_entry **rel_hash;
    5790               Elf_Internal_Shdr *input_rel_hdr;
     7164              Elf_Internal_Shdr *input_rel_hdr, *input_rel_hdr2;
    57917165              unsigned int next_erel;
     7166              bfd_boolean (*reloc_emitter)
     7167                PARAMS ((bfd *, asection *, Elf_Internal_Shdr *,
     7168                         Elf_Internal_Rela *));
     7169              bfd_boolean rela_normal;
     7170
     7171              input_rel_hdr = &elf_section_data (o)->rel_hdr;
     7172              rela_normal = (bed->rela_normal
     7173                             && (input_rel_hdr->sh_entsize
     7174                                 == sizeof (Elf_External_Rela)));
    57927175
    57937176              /* Adjust the reloc addresses and symbol indices.  */
    57947177
    57957178              irela = internal_relocs;
    5796               irelaend = irela
    5797                          + o->reloc_count * bed->s->int_rels_per_ext_rel;
     7179              irelaend = irela + o->reloc_count * bed->s->int_rels_per_ext_rel;
    57987180              rel_hash = (elf_section_data (o->output_section)->rel_hashes
    57997181                          + elf_section_data (o->output_section)->rel_count
    58007182                          + elf_section_data (o->output_section)->rel_count2);
     7183              last_offset = o->output_offset;
     7184              if (!finfo->info->relocateable)
     7185                last_offset += o->output_section->vma;
    58017186              for (next_erel = 0; irela < irelaend; irela++, next_erel++)
    58027187                {
    58037188                  unsigned long r_symndx;
    5804                   Elf_Internal_Sym *isym;
    58057189                  asection *sec;
     7190                  Elf_Internal_Sym sym;
    58067191
    58077192                  if (next_erel == bed->s->int_rels_per_ext_rel)
     
    58117196                    }
    58127197
     7198                  irela->r_offset = _bfd_elf_section_offset (output_bfd,
     7199                                                             finfo->info, o,
     7200                                                             irela->r_offset);
     7201                  if (irela->r_offset >= (bfd_vma) -2)
     7202                    {
     7203                      /* This is a reloc for a deleted entry or somesuch.
     7204                         Turn it into an R_*_NONE reloc, at the same
     7205                         offset as the last reloc.  elf_eh_frame.c and
     7206                         elf_bfd_discard_info rely on reloc offsets
     7207                         being ordered.  */
     7208                      irela->r_offset = last_offset;
     7209                      irela->r_info = 0;
     7210                      irela->r_addend = 0;
     7211                      continue;
     7212                    }
     7213
    58137214                  irela->r_offset += o->output_offset;
    58147215
    58157216                  /* Relocs in an executable have to be virtual addresses.  */
    5816                   if (finfo->info->emitrelocations)
     7217                  if (!finfo->info->relocateable)
    58177218                    irela->r_offset += o->output_section->vma;
    58187219
     7220                  last_offset = irela->r_offset;
     7221
    58197222                  r_symndx = ELF_R_SYM (irela->r_info);
    5820 
    5821                   if (r_symndx == 0)
     7223                  if (r_symndx == STN_UNDEF)
    58227224                    continue;
    58237225
     
    58567258
    58577259                  *rel_hash = NULL;
    5858                   isym = finfo->internal_syms + r_symndx;
     7260                  sym = isymbuf[r_symndx];
    58597261                  sec = finfo->sections[r_symndx];
    5860                   if (ELF_ST_TYPE (isym->st_info) == STT_SECTION)
     7262                  if (ELF_ST_TYPE (sym.st_info) == STT_SECTION)
    58617263                    {
    58627264                      /* I suppose the backend ought to fill in the
     
    58657267                         discarded a section, the output_section will
    58667268                         be the absolute section.  */
    5867                       if (sec != NULL
    5868                           && (bfd_is_abs_section (sec)
    5869                               || (sec->output_section != NULL
    5870                                   && bfd_is_abs_section (sec->output_section))))
     7269                      if (bfd_is_abs_section (sec)
     7270                          || (sec != NULL
     7271                              && bfd_is_abs_section (sec->output_section)))
    58717272                        r_symndx = 0;
    58727273                      else if (sec == NULL || sec->owner == NULL)
    58737274                        {
    58747275                          bfd_set_error (bfd_error_bad_value);
    5875                           return false;
     7276                          return FALSE;
    58767277                        }
    58777278                      else
     
    58807281                          BFD_ASSERT (r_symndx != 0);
    58817282                        }
     7283
     7284                      /* Adjust the addend according to where the
     7285                         section winds up in the output section.  */
     7286                      if (rela_normal)
     7287                        irela->r_addend += sec->output_offset;
    58827288                    }
    58837289                  else
     
    58857291                      if (finfo->indices[r_symndx] == -1)
    58867292                        {
    5887                           unsigned long link;
     7293                          unsigned long shlink;
    58887294                          const char *name;
    58897295                          asection *osec;
     
    58937299                              /* You can't do ld -r -s.  */
    58947300                              bfd_set_error (bfd_error_invalid_operation);
    5895                               return false;
     7301                              return FALSE;
    58967302                            }
    58977303
     
    58997305                             since it is needed by a reloc, we
    59007306                             must output it now.  */
    5901                           link = symtab_hdr->sh_link;
    5902                           name = bfd_elf_string_from_elf_section (input_bfd,
    5903                                                                   link,
    5904                                                                   isym->st_name);
     7307                          shlink = symtab_hdr->sh_link;
     7308                          name = (bfd_elf_string_from_elf_section
     7309                                  (input_bfd, shlink, sym.st_name));
    59057310                          if (name == NULL)
    5906                             return false;
     7311                            return FALSE;
    59077312
    59087313                          osec = sec->output_section;
    5909                           isym->st_shndx =
     7314                          sym.st_shndx =
    59107315                            _bfd_elf_section_from_bfd_section (output_bfd,
    59117316                                                               osec);
    5912                           if (isym->st_shndx == (unsigned short) -1)
    5913                             return false;
    5914 
    5915                           isym->st_value += sec->output_offset;
     7317                          if (sym.st_shndx == SHN_BAD)
     7318                            return FALSE;
     7319
     7320                          sym.st_value += sec->output_offset;
    59167321                          if (! finfo->info->relocateable)
    5917                             isym->st_value += osec->vma;
    5918 
    5919                           finfo->indices[r_symndx] = bfd_get_symcount (output_bfd);
    5920 
    5921                           if (! elf_link_output_sym (finfo, name, isym, sec))
    5922                             return false;
     7322                            {
     7323                              sym.st_value += osec->vma;
     7324                              if (ELF_ST_TYPE (sym.st_info) == STT_TLS)
     7325                                {
     7326                                  /* STT_TLS symbols are relative to PT_TLS
     7327                                     segment base.  */
     7328                                  BFD_ASSERT (finfo->first_tls_sec != NULL);
     7329                                  sym.st_value -= finfo->first_tls_sec->vma;
     7330                                }
     7331                            }
     7332
     7333                          finfo->indices[r_symndx]
     7334                            = bfd_get_symcount (output_bfd);
     7335
     7336                          if (! elf_link_output_sym (finfo, name, &sym, sec))
     7337                            return FALSE;
    59237338                        }
    59247339
     
    59317346
    59327347              /* Swap out the relocs.  */
    5933               input_rel_hdr = &elf_section_data (o)->rel_hdr;
    5934               elf_link_output_relocs (output_bfd, o,
    5935                                       input_rel_hdr,
    5936                                       internal_relocs);
    5937               internal_relocs += NUM_SHDR_ENTRIES (input_rel_hdr)
    5938                                  * bed->s->int_rels_per_ext_rel;
    5939               input_rel_hdr = elf_section_data (o)->rel_hdr2;
    5940               if (input_rel_hdr)
    5941                 elf_link_output_relocs (output_bfd, o,
    5942                                         input_rel_hdr,
    5943                                         internal_relocs);
     7348              if (bed->elf_backend_emit_relocs
     7349                  && !(finfo->info->relocateable
     7350                       || finfo->info->emitrelocations))
     7351                reloc_emitter = bed->elf_backend_emit_relocs;
     7352              else
     7353                reloc_emitter = elf_link_output_relocs;
     7354
     7355              if (input_rel_hdr->sh_size != 0
     7356                  && ! (*reloc_emitter) (output_bfd, o, input_rel_hdr,
     7357                                         internal_relocs))
     7358                return FALSE;
     7359
     7360              input_rel_hdr2 = elf_section_data (o)->rel_hdr2;
     7361              if (input_rel_hdr2 && input_rel_hdr2->sh_size != 0)
     7362                {
     7363                  internal_relocs += (NUM_SHDR_ENTRIES (input_rel_hdr)
     7364                                      * bed->s->int_rels_per_ext_rel);
     7365                  if (! (*reloc_emitter) (output_bfd, o, input_rel_hdr2,
     7366                                          internal_relocs))
     7367                    return FALSE;
     7368                }
    59447369            }
    59457370        }
    59467371
    59477372      /* Write out the modified section contents.  */
    5948       if (elf_section_data (o)->stab_info == NULL)
    5949         {
    5950           if (! (o->flags & SEC_EXCLUDE) &&
    5951               ! bfd_set_section_contents (output_bfd, o->output_section,
    5952                                           contents, o->output_offset,
    5953                                           (o->_cooked_size != 0
    5954                                            ? o->_cooked_size
    5955                                            : o->_raw_size)))
    5956             return false;
    5957         }
    5958       else
    5959         {
     7373      if (bed->elf_backend_write_section
     7374          && (*bed->elf_backend_write_section) (output_bfd, o, contents))
     7375        {
     7376          /* Section written out.  */
     7377        }
     7378      else switch (o->sec_info_type)
     7379        {
     7380        case ELF_INFO_TYPE_STABS:
    59607381          if (! (_bfd_write_section_stabs
    5961                  (output_bfd, &elf_hash_table (finfo->info)->stab_info,
    5962                   o, &elf_section_data (o)->stab_info, contents)))
    5963             return false;
    5964         }
    5965     }
    5966 
    5967   return true;
     7382                 (output_bfd,
     7383                  &elf_hash_table (finfo->info)->stab_info,
     7384                  o, &elf_section_data (o)->sec_info, contents)))
     7385            return FALSE;
     7386          break;
     7387        case ELF_INFO_TYPE_MERGE:
     7388          if (! _bfd_write_merged_section (output_bfd, o,
     7389                                           elf_section_data (o)->sec_info))
     7390            return FALSE;
     7391          break;
     7392        case ELF_INFO_TYPE_EH_FRAME:
     7393          {
     7394            if (! _bfd_elf_write_section_eh_frame (output_bfd, finfo->info,
     7395                                                   o, contents))
     7396              return FALSE;
     7397          }
     7398          break;
     7399        default:
     7400          {
     7401            bfd_size_type sec_size;
     7402
     7403            sec_size = (o->_cooked_size != 0 ? o->_cooked_size : o->_raw_size);
     7404            if (! (o->flags & SEC_EXCLUDE)
     7405                && ! bfd_set_section_contents (output_bfd, o->output_section,
     7406                                               contents,
     7407                                               (file_ptr) o->output_offset,
     7408                                               sec_size))
     7409              return FALSE;
     7410          }
     7411          break;
     7412        }
     7413    }
     7414
     7415  return TRUE;
    59687416}
    59697417
     
    59737421   with -Ur.  */
    59747422
    5975 static boolean
     7423static bfd_boolean
    59767424elf_reloc_link_order (output_bfd, info, output_section, link_order)
    59777425     bfd *output_bfd;
     
    59877435  Elf_Internal_Shdr *rel_hdr;
    59887436  struct elf_backend_data *bed = get_elf_backend_data (output_bfd);
     7437  Elf_Internal_Rela irel[MAX_INT_RELS_PER_EXT_REL];
     7438  bfd_byte *erel;
     7439  unsigned int i;
    59897440
    59907441  howto = bfd_reloc_type_lookup (output_bfd, link_order->u.reloc.p->reloc);
     
    59927443    {
    59937444      bfd_set_error (bfd_error_bad_value);
    5994       return false;
     7445      return FALSE;
    59957446    }
    59967447
     
    60127463
    60137464      /* Treat a reloc against a defined symbol as though it were
    6014         actually against the section.  */
     7465        actually against the section.  */
    60157466      h = ((struct elf_link_hash_entry *)
    60167467           bfd_wrapped_link_hash_lookup (output_bfd, info,
    60177468                                         link_order->u.reloc.p->u.name,
    6018                                          false, false, true));
     7469                                         FALSE, FALSE, TRUE));
    60197470      if (h != NULL
    60207471          && (h->root.type == bfd_link_hash_defined
     
    60277478          *rel_hash_ptr = NULL;
    60287479          /* It seems that we ought to add the symbol value to the
    6029              addend here, but in practice it has already been added
    6030              because it was passed to constructor_callback.  */
     7480             addend here, but in practice it has already been added
     7481             because it was passed to constructor_callback.  */
    60317482          addend += section->output_section->vma + section->output_offset;
    60327483        }
     
    60447495                 (info, link_order->u.reloc.p->u.name, (bfd *) NULL,
    60457496                  (asection *) NULL, (bfd_vma) 0)))
    6046             return false;
     7497            return FALSE;
    60477498          indx = 0;
    60487499        }
     
    60567507      bfd_reloc_status_type rstat;
    60577508      bfd_byte *buf;
    6058       boolean ok;
     7509      bfd_boolean ok;
     7510      const char *sym_name;
    60597511
    60607512      size = bfd_get_reloc_size (howto);
    60617513      buf = (bfd_byte *) bfd_zmalloc (size);
    60627514      if (buf == (bfd_byte *) NULL)
    6063         return false;
    6064       rstat = _bfd_relocate_contents (howto, output_bfd, addend, buf);
     7515        return FALSE;
     7516      rstat = _bfd_relocate_contents (howto, output_bfd, (bfd_vma) addend, buf);
    60657517      switch (rstat)
    60667518        {
    60677519        case bfd_reloc_ok:
    60687520          break;
     7521
    60697522        default:
    60707523        case bfd_reloc_outofrange:
    60717524          abort ();
     7525
    60727526        case bfd_reloc_overflow:
     7527          if (link_order->type == bfd_section_reloc_link_order)
     7528            sym_name = bfd_section_name (output_bfd,
     7529                                         link_order->u.reloc.p->u.section);
     7530          else
     7531            sym_name = link_order->u.reloc.p->u.name;
    60737532          if (! ((*info->callbacks->reloc_overflow)
    6074                  (info,
    6075                   (link_order->type == bfd_section_reloc_link_order
    6076                    ? bfd_section_name (output_bfd,
    6077                                        link_order->u.reloc.p->u.section)
    6078                    : link_order->u.reloc.p->u.name),
    6079                   howto->name, addend, (bfd *) NULL, (asection *) NULL,
    6080                   (bfd_vma) 0)))
     7533                 (info, sym_name, howto->name, addend,
     7534                  (bfd *) NULL, (asection *) NULL, (bfd_vma) 0)))
    60817535            {
    60827536              free (buf);
    6083               return false;
     7537              return FALSE;
    60847538            }
    60857539          break;
     
    60897543      free (buf);
    60907544      if (! ok)
    6091         return false;
     7545        return FALSE;
    60927546    }
    60937547
     
    60997553    offset += output_section->vma;
    61007554
     7555  for (i = 0; i < bed->s->int_rels_per_ext_rel; i++)
     7556    {
     7557      irel[i].r_offset = offset;
     7558      irel[i].r_info = 0;
     7559      irel[i].r_addend = 0;
     7560    }
     7561  irel[0].r_info = ELF_R_INFO (indx, howto->type);
     7562
    61017563  rel_hdr = &elf_section_data (output_section)->rel_hdr;
    6102 
     7564  erel = rel_hdr->contents;
    61037565  if (rel_hdr->sh_type == SHT_REL)
    61047566    {
    6105       Elf_Internal_Rel *irel;
    6106       Elf_External_Rel *erel;
    6107       unsigned int i;
    6108      
    6109       irel = (Elf_Internal_Rel *) bfd_zmalloc (bed->s->int_rels_per_ext_rel
    6110                                                * sizeof (Elf_Internal_Rel));
    6111       if (irel == NULL)
    6112         return false;
    6113      
    6114       for (i = 0; i < bed->s->int_rels_per_ext_rel; i++)
    6115         irel[i].r_offset = offset;
    6116       irel[0].r_info = ELF_R_INFO (indx, howto->type);
    6117 
    6118       erel = ((Elf_External_Rel *) rel_hdr->contents
    6119               + elf_section_data (output_section)->rel_count);
    6120 
    6121       if (bed->s->swap_reloc_out)
    6122         (*bed->s->swap_reloc_out) (output_bfd, irel, (bfd_byte *) erel);
    6123       else
    6124         elf_swap_reloc_out (output_bfd, irel, erel);
    6125 
    6126       free (irel);
     7567      erel += (elf_section_data (output_section)->rel_count
     7568               * sizeof (Elf_External_Rel));
     7569      (*bed->s->swap_reloc_out) (output_bfd, irel, erel);
    61277570    }
    61287571  else
    61297572    {
    6130       Elf_Internal_Rela *irela;
    6131       Elf_External_Rela *erela;
    6132       unsigned int i;
    6133      
    6134       irela = (Elf_Internal_Rela *) bfd_zmalloc (bed->s->int_rels_per_ext_rel
    6135                                                  * sizeof (Elf_Internal_Rela));
    6136       if (irela == NULL)
    6137         return false;
    6138 
    6139       for (i = 0; i < bed->s->int_rels_per_ext_rel; i++)
    6140         irela[i].r_offset = offset;
    6141       irela[0].r_info = ELF_R_INFO (indx, howto->type);
    6142       irela[0].r_addend = addend;
    6143 
    6144       erela = ((Elf_External_Rela *) rel_hdr->contents
    6145                + elf_section_data (output_section)->rel_count);
    6146 
    6147       if (bed->s->swap_reloca_out)
    6148         (*bed->s->swap_reloca_out) (output_bfd, irela, (bfd_byte *) erela);
    6149       else
    6150         elf_swap_reloca_out (output_bfd, irela, erela);
     7573      irel[0].r_addend = addend;
     7574      erel += (elf_section_data (output_section)->rel_count
     7575               * sizeof (Elf_External_Rela));
     7576      (*bed->s->swap_reloca_out) (output_bfd, irel, erel);
    61517577    }
    61527578
    61537579  ++elf_section_data (output_section)->rel_count;
    61547580
    6155   return true;
     7581  return TRUE;
    61567582}
    61577583
     
    61597585/* Allocate a pointer to live in a linker created section.  */
    61607586
    6161 boolean
     7587bfd_boolean
    61627588elf_create_pointer_linker_section (abfd, info, lsect, h, rel)
    61637589     bfd *abfd;
     
    61697595  elf_linker_section_pointers_t **ptr_linker_section_ptr = NULL;
    61707596  elf_linker_section_pointers_t *linker_section_ptr;
    6171   unsigned long r_symndx = ELF_R_SYM (rel->r_info);;
     7597  unsigned long r_symndx = ELF_R_SYM (rel->r_info);
     7598  bfd_size_type amt;
    61727599
    61737600  BFD_ASSERT (lsect != NULL);
    61747601
    6175   /* Is this a global symbol? */
     7602  /* Is this a global symbol?  */
    61767603  if (h != NULL)
    61777604    {
    6178       /* Has this symbol already been allocated, if so, our work is done */
     7605      /* Has this symbol already been allocated?  If so, our work is done. */
    61797606      if (_bfd_elf_find_pointer_linker_section (h->linker_section_pointer,
    61807607                                                rel->r_addend,
    61817608                                                lsect->which))
    6182         return true;
     7609        return TRUE;
    61837610
    61847611      ptr_linker_section_ptr = &h->linker_section_pointer;
     
    61877614        {
    61887615          if (! elf_link_record_dynamic_symbol (info, h))
    6189             return false;
     7616            return FALSE;
    61907617        }
    61917618
     
    61937620        lsect->rel_section->_raw_size += sizeof (Elf_External_Rela);
    61947621    }
    6195 
    6196   else  /* Allocation of a pointer to a local symbol */
    6197     {
     7622  else
     7623    {
     7624      /* Allocation of a pointer to a local symbol.  */
    61987625      elf_linker_section_pointers_t **ptr = elf_local_ptr_offsets (abfd);
    61997626
    6200       /* Allocate a table to hold the local symbols if first time */
     7627      /* Allocate a table to hold the local symbols if first time. */
    62017628      if (!ptr)
    62027629        {
     
    62047631          register unsigned int i;
    62057632
    6206           ptr = (elf_linker_section_pointers_t **)
    6207             bfd_alloc (abfd, num_symbols * sizeof (elf_linker_section_pointers_t *));
     7633          amt = num_symbols;
     7634          amt *= sizeof (elf_linker_section_pointers_t *);
     7635          ptr = (elf_linker_section_pointers_t **) bfd_alloc (abfd, amt);
    62087636
    62097637          if (!ptr)
    6210             return false;
     7638            return FALSE;
    62117639
    62127640          elf_local_ptr_offsets (abfd) = ptr;
    62137641          for (i = 0; i < num_symbols; i++)
    6214             ptr[i] = (elf_linker_section_pointers_t *)0;
    6215         }
    6216 
    6217       /* Has this symbol already been allocated, if so, our work is done */
     7642            ptr[i] = (elf_linker_section_pointers_t *) 0;
     7643        }
     7644
     7645      /* Has this symbol already been allocated?  If so, our work is done. */
    62187646      if (_bfd_elf_find_pointer_linker_section (ptr[r_symndx],
    62197647                                                rel->r_addend,
    62207648                                                lsect->which))
    6221         return true;
     7649        return TRUE;
    62227650
    62237651      ptr_linker_section_ptr = &ptr[r_symndx];
     
    62337661    }
    62347662
    6235   /* Allocate space for a pointer in the linker section, and allocate a new pointer record
    6236      from internal memory.  */
     7663  /* Allocate space for a pointer in the linker section, and allocate
     7664     a new pointer record from internal memory.  */
    62377665  BFD_ASSERT (ptr_linker_section_ptr != NULL);
    6238   linker_section_ptr = (elf_linker_section_pointers_t *)
    6239     bfd_alloc (abfd, sizeof (elf_linker_section_pointers_t));
     7666  amt = sizeof (elf_linker_section_pointers_t);
     7667  linker_section_ptr = (elf_linker_section_pointers_t *) bfd_alloc (abfd, amt);
    62407668
    62417669  if (!linker_section_ptr)
    6242     return false;
     7670    return FALSE;
    62437671
    62447672  linker_section_ptr->next = *ptr_linker_section_ptr;
    62457673  linker_section_ptr->addend = rel->r_addend;
    62467674  linker_section_ptr->which = lsect->which;
    6247   linker_section_ptr->written_address_p = false;
     7675  linker_section_ptr->written_address_p = FALSE;
    62487676  *ptr_linker_section_ptr = linker_section_ptr;
    62497677
     
    62517679  if (lsect->hole_size && lsect->hole_offset < lsect->max_hole_offset)
    62527680    {
    6253       linker_section_ptr->offset = lsect->section->_raw_size - lsect->hole_size + (ARCH_SIZE / 8);
     7681      linker_section_ptr->offset = (lsect->section->_raw_size
     7682                                    - lsect->hole_size + (ARCH_SIZE / 8));
    62547683      lsect->hole_offset += ARCH_SIZE / 8;
    62557684      lsect->sym_offset  += ARCH_SIZE / 8;
    6256       if (lsect->sym_hash)      /* Bump up symbol value if needed */
    6257         {
     7685      if (lsect->sym_hash)
     7686        {
     7687          /* Bump up symbol value if needed.  */
    62587688          lsect->sym_hash->root.u.def.value += ARCH_SIZE / 8;
    62597689#ifdef DEBUG
    62607690          fprintf (stderr, "Bump up %s by %ld, current value = %ld\n",
    62617691                   lsect->sym_hash->root.root.string,
    6262                    (long)ARCH_SIZE / 8,
    6263                    (long)lsect->sym_hash->root.u.def.value);
     7692                   (long) ARCH_SIZE / 8,
     7693                   (long) lsect->sym_hash->root.u.def.value);
    62647694#endif
    62657695        }
     
    62727702
    62737703#ifdef DEBUG
    6274   fprintf (stderr, "Create pointer in linker section %s, offset = %ld, section size = %ld\n",
    6275            lsect->name, (long)linker_section_ptr->offset, (long)lsect->section->_raw_size);
     7704  fprintf (stderr,
     7705           "Create pointer in linker section %s, offset = %ld, section size = %ld\n",
     7706           lsect->name, (long) linker_section_ptr->offset,
     7707           (long) lsect->section->_raw_size);
    62767708#endif
    62777709
    6278   return true;
     7710  return TRUE;
    62797711}
    62807712
     
    62907722
    62917723bfd_vma
    6292 elf_finish_pointer_linker_section (output_bfd, input_bfd, info, lsect, h, relocation, rel, relative_reloc)
     7724elf_finish_pointer_linker_section (output_bfd, input_bfd, info, lsect, h,
     7725                                   relocation, rel, relative_reloc)
    62937726     bfd *output_bfd;
    62947727     bfd *input_bfd;
     
    63047737  BFD_ASSERT (lsect != NULL);
    63057738
    6306   if (h != NULL)                /* global symbol */
    6307     {
    6308       linker_section_ptr = _bfd_elf_find_pointer_linker_section (h->linker_section_pointer,
    6309                                                                  rel->r_addend,
    6310                                                                  lsect->which);
     7739  if (h != NULL)
     7740    {
     7741      /* Handle global symbol.  */
     7742      linker_section_ptr = (_bfd_elf_find_pointer_linker_section
     7743                            (h->linker_section_pointer,
     7744                             rel->r_addend,
     7745                             lsect->which));
    63117746
    63127747      BFD_ASSERT (linker_section_ptr != NULL);
     
    63277762          if (!linker_section_ptr->written_address_p)
    63287763            {
    6329               linker_section_ptr->written_address_p = true;
    6330               bfd_put_ptr (output_bfd, relocation + linker_section_ptr->addend,
    6331                           lsect->section->contents + linker_section_ptr->offset);
     7764              linker_section_ptr->written_address_p = TRUE;
     7765              bfd_put_ptr (output_bfd,
     7766                           relocation + linker_section_ptr->addend,
     7767                           (lsect->section->contents
     7768                            + linker_section_ptr->offset));
    63327769            }
    63337770        }
    63347771    }
    6335   else                          /* local symbol */
    6336     {
     7772  else
     7773    {
     7774      /* Handle local symbol.  */
    63377775      unsigned long r_symndx = ELF_R_SYM (rel->r_info);
    63387776      BFD_ASSERT (elf_local_ptr_offsets (input_bfd) != NULL);
    63397777      BFD_ASSERT (elf_local_ptr_offsets (input_bfd)[r_symndx] != NULL);
    6340       linker_section_ptr = _bfd_elf_find_pointer_linker_section (elf_local_ptr_offsets (input_bfd)[r_symndx],
    6341                                                                  rel->r_addend,
    6342                                                                  lsect->which);
     7778      linker_section_ptr = (_bfd_elf_find_pointer_linker_section
     7779                            (elf_local_ptr_offsets (input_bfd)[r_symndx],
     7780                             rel->r_addend,
     7781                             lsect->which));
    63437782
    63447783      BFD_ASSERT (linker_section_ptr != NULL);
    63457784
    6346       /* Write out pointer if it hasn't been rewritten out before */
     7785      /* Write out pointer if it hasn't been rewritten out before. */
    63477786      if (!linker_section_ptr->written_address_p)
    63487787        {
    6349           linker_section_ptr->written_address_p = true;
     7788          linker_section_ptr->written_address_p = TRUE;
    63507789          bfd_put_ptr (output_bfd, relocation + linker_section_ptr->addend,
    63517790                       lsect->section->contents + linker_section_ptr->offset);
     
    63547793            {
    63557794              asection *srel = lsect->rel_section;
    6356               Elf_Internal_Rela *outrel;
     7795              Elf_Internal_Rela outrel[MAX_INT_RELS_PER_EXT_REL];
     7796              bfd_byte *erel;
    63577797              struct elf_backend_data *bed = get_elf_backend_data (output_bfd);
    63587798              unsigned int i;
    63597799
    6360               outrel = (Elf_Internal_Rela *) bfd_zmalloc (sizeof (Elf_Internal_Rela)
    6361                                                           * bed->s->int_rels_per_ext_rel);
    6362               if (outrel == NULL)
     7800              /* We need to generate a relative reloc for the dynamic
     7801                 linker.  */
     7802              if (!srel)
    63637803                {
    6364                   (*_bfd_error_handler) (_("Error: out of memory"));
    6365                   return 0;
     7804                  srel = bfd_get_section_by_name (elf_hash_table (info)->dynobj,
     7805                                                  lsect->rel_name);
     7806                  lsect->rel_section = srel;
    63667807                }
    63677808
    6368               /* We need to generate a relative reloc for the dynamic linker.  */
    6369               if (!srel)
    6370                 lsect->rel_section = srel = bfd_get_section_by_name (elf_hash_table (info)->dynobj,
    6371                                                                      lsect->rel_name);
    6372 
    63737809              BFD_ASSERT (srel != NULL);
    63747810
    63757811              for (i = 0; i < bed->s->int_rels_per_ext_rel; i++)
    6376                 outrel[i].r_offset = (lsect->section->output_section->vma
    6377                                       + lsect->section->output_offset
    6378                                       + linker_section_ptr->offset);
     7812                {
     7813                  outrel[i].r_offset = (lsect->section->output_section->vma
     7814                                        + lsect->section->output_offset
     7815                                        + linker_section_ptr->offset);
     7816                  outrel[i].r_info = 0;
     7817                  outrel[i].r_addend = 0;
     7818                }
    63797819              outrel[0].r_info = ELF_R_INFO (0, relative_reloc);
    6380               outrel[0].r_addend = 0;
    6381               elf_swap_reloca_out (output_bfd, outrel,
    6382                                    (((Elf_External_Rela *)
    6383                                      lsect->section->contents)
    6384                                     + elf_section_data (lsect->section)->rel_count));
    6385               ++elf_section_data (lsect->section)->rel_count;
    6386              
    6387               free (outrel);
     7820              erel = lsect->section->contents;
     7821              erel += (elf_section_data (lsect->section)->rel_count++
     7822                       * sizeof (Elf_External_Rela));
     7823              elf_swap_reloca_out (output_bfd, outrel, erel);
    63887824            }
    63897825        }
     
    63967832
    63977833#ifdef DEBUG
    6398   fprintf (stderr, "Finish pointer in linker section %s, offset = %ld (0x%lx)\n",
    6399            lsect->name, (long)relocation, (long)relocation);
     7834  fprintf (stderr,
     7835           "Finish pointer in linker section %s, offset = %ld (0x%lx)\n",
     7836           lsect->name, (long) relocation, (long) relocation);
    64007837#endif
    64017838
     
    64087845/* Garbage collect unused sections.  */
    64097846
    6410 static boolean elf_gc_mark
    6411   PARAMS ((struct bfd_link_info *info, asection *sec,
    6412            asection * (*gc_mark_hook)
    6413              PARAMS ((bfd *, struct bfd_link_info *, Elf_Internal_Rela *,
    6414                       struct elf_link_hash_entry *, Elf_Internal_Sym *))));
    6415 
    6416 static boolean elf_gc_sweep
    6417   PARAMS ((struct bfd_link_info *info,
    6418            boolean (*gc_sweep_hook)
    6419              PARAMS ((bfd *abfd, struct bfd_link_info *info, asection *o,
    6420                       const Elf_Internal_Rela *relocs))));
    6421 
    6422 static boolean elf_gc_sweep_symbol
    6423   PARAMS ((struct elf_link_hash_entry *h, PTR idxptr));
    6424 
    6425 static boolean elf_gc_allocate_got_offsets
    6426   PARAMS ((struct elf_link_hash_entry *h, PTR offarg));
    6427 
    6428 static boolean elf_gc_propagate_vtable_entries_used
    6429   PARAMS ((struct elf_link_hash_entry *h, PTR dummy));
    6430 
    6431 static boolean elf_gc_smash_unused_vtentry_relocs
    6432   PARAMS ((struct elf_link_hash_entry *h, PTR dummy));
     7847static bfd_boolean elf_gc_mark
     7848  PARAMS ((struct bfd_link_info *, asection *,
     7849           asection * (*) (asection *, struct bfd_link_info *,
     7850                           Elf_Internal_Rela *, struct elf_link_hash_entry *,
     7851                           Elf_Internal_Sym *)));
     7852
     7853static bfd_boolean elf_gc_sweep
     7854  PARAMS ((struct bfd_link_info *,
     7855           bfd_boolean (*) (bfd *, struct bfd_link_info *, asection *,
     7856                            const Elf_Internal_Rela *)));
     7857
     7858static bfd_boolean elf_gc_sweep_symbol
     7859  PARAMS ((struct elf_link_hash_entry *, PTR));
     7860
     7861static bfd_boolean elf_gc_allocate_got_offsets
     7862  PARAMS ((struct elf_link_hash_entry *, PTR));
     7863
     7864static bfd_boolean elf_gc_propagate_vtable_entries_used
     7865  PARAMS ((struct elf_link_hash_entry *, PTR));
     7866
     7867static bfd_boolean elf_gc_smash_unused_vtentry_relocs
     7868  PARAMS ((struct elf_link_hash_entry *, PTR));
    64337869
    64347870/* The mark phase of garbage collection.  For a given section, mark
    6435    it, and all the sections which define symbols to which it refers.  */
    6436 
    6437 static boolean
     7871   it and any sections in this section's group, and all the sections
     7872   which define symbols to which it refers.  */
     7873
     7874typedef asection * (*gc_mark_hook_fn)
     7875  PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *,
     7876           struct elf_link_hash_entry *, Elf_Internal_Sym *));
     7877
     7878static bfd_boolean
    64387879elf_gc_mark (info, sec, gc_mark_hook)
    64397880     struct bfd_link_info *info;
    64407881     asection *sec;
    6441      asection * (*gc_mark_hook)
    6442        PARAMS ((bfd *, struct bfd_link_info *, Elf_Internal_Rela *,
    6443                 struct elf_link_hash_entry *, Elf_Internal_Sym *));
     7882     gc_mark_hook_fn gc_mark_hook;
    64447883{
    6445   boolean ret = true;
     7884  bfd_boolean ret;
     7885  asection *group_sec;
    64467886
    64477887  sec->gc_mark = 1;
    64487888
     7889  /* Mark all the sections in the group.  */
     7890  group_sec = elf_section_data (sec)->next_in_group;
     7891  if (group_sec && !group_sec->gc_mark)
     7892    if (!elf_gc_mark (info, group_sec, gc_mark_hook))
     7893      return FALSE;
     7894
    64497895  /* Look through the section relocs.  */
    6450 
     7896  ret = TRUE;
    64517897  if ((sec->flags & SEC_RELOC) != 0 && sec->reloc_count > 0)
    64527898    {
     
    64567902      size_t nlocsyms;
    64577903      size_t extsymoff;
    6458       Elf_External_Sym *locsyms, *freesyms = NULL;
    64597904      bfd *input_bfd = sec->owner;
    64607905      struct elf_backend_data *bed = get_elf_backend_data (input_bfd);
    6461 
    6462       /* GCFIXME: how to arrange so that relocs and symbols are not
    6463          reread continually?  */
     7906      Elf_Internal_Sym *isym = NULL;
    64647907
    64657908      symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
     
    64707913        {
    64717914          nlocsyms = symtab_hdr->sh_size / sizeof (Elf_External_Sym);
    6472           extsymoff = 0;
     7915          extsymoff = 0;
    64737916        }
    64747917      else
    64757918        extsymoff = nlocsyms = symtab_hdr->sh_info;
    6476       if (symtab_hdr->contents)
    6477         locsyms = (Elf_External_Sym *) symtab_hdr->contents;
    6478       else if (nlocsyms == 0)
    6479         locsyms = NULL;
    6480       else
    6481         {
    6482           locsyms = freesyms =
    6483             bfd_malloc (nlocsyms * sizeof (Elf_External_Sym));
    6484           if (freesyms == NULL
    6485               || bfd_seek (input_bfd, symtab_hdr->sh_offset, SEEK_SET) != 0
    6486               || (bfd_read (locsyms, sizeof (Elf_External_Sym),
    6487                             nlocsyms, input_bfd)
    6488                   != nlocsyms * sizeof (Elf_External_Sym)))
    6489             {
    6490               ret = false;
    6491               goto out1;
    6492             }
     7919
     7920      isym = (Elf_Internal_Sym *) symtab_hdr->contents;
     7921      if (isym == NULL && nlocsyms != 0)
     7922        {
     7923          isym = bfd_elf_get_elf_syms (input_bfd, symtab_hdr, nlocsyms, 0,
     7924                                       NULL, NULL, NULL);
     7925          if (isym == NULL)
     7926            return FALSE;
    64937927        }
    64947928
    64957929      /* Read the relocations.  */
    64967930      relstart = (NAME(_bfd_elf,link_read_relocs)
    6497                   (sec->owner, sec, NULL, (Elf_Internal_Rela *) NULL,
     7931                  (input_bfd, sec, NULL, (Elf_Internal_Rela *) NULL,
    64987932                   info->keep_memory));
    64997933      if (relstart == NULL)
    65007934        {
    6501           ret = false;
     7935          ret = FALSE;
    65027936          goto out1;
    65037937        }
     
    65097943          asection *rsec;
    65107944          struct elf_link_hash_entry *h;
    6511           Elf_Internal_Sym s;
    65127945
    65137946          r_symndx = ELF_R_SYM (rel->r_info);
     
    65157948            continue;
    65167949
    6517           if (elf_bad_symtab (sec->owner))
    6518             {
    6519               elf_swap_symbol_in (input_bfd, &locsyms[r_symndx], &s);
    6520               if (ELF_ST_BIND (s.st_info) == STB_LOCAL)
    6521                 rsec = (*gc_mark_hook) (sec->owner, info, rel, NULL, &s);
    6522               else
    6523                 {
    6524                   h = sym_hashes[r_symndx - extsymoff];
    6525                   rsec = (*gc_mark_hook) (sec->owner, info, rel, h, NULL);
    6526                 }
    6527             }
    6528           else if (r_symndx >= nlocsyms)
     7950          if (r_symndx >= nlocsyms
     7951              || ELF_ST_BIND (isym[r_symndx].st_info) != STB_LOCAL)
    65297952            {
    65307953              h = sym_hashes[r_symndx - extsymoff];
    6531               rsec = (*gc_mark_hook) (sec->owner, info, rel, h, NULL);
     7954              rsec = (*gc_mark_hook) (sec, info, rel, h, NULL);
    65327955            }
    65337956          else
    65347957            {
    6535               elf_swap_symbol_in (input_bfd, &locsyms[r_symndx], &s);
    6536               rsec = (*gc_mark_hook) (sec->owner, info, rel, NULL, &s);
     7958              rsec = (*gc_mark_hook) (sec, info, rel, NULL, &isym[r_symndx]);
    65377959            }
    65387960
    65397961          if (rsec && !rsec->gc_mark)
    6540             if (!elf_gc_mark (info, rsec, gc_mark_hook))
    6541               {
    6542                 ret = false;
    6543                 goto out2;
    6544               }
     7962            {
     7963              if (bfd_get_flavour (rsec->owner) != bfd_target_elf_flavour)
     7964                rsec->gc_mark = 1;
     7965              else if (!elf_gc_mark (info, rsec, gc_mark_hook))
     7966                {
     7967                  ret = FALSE;
     7968                  goto out2;
     7969                }
     7970            }
    65457971        }
    65467972
    65477973    out2:
    6548       if (!info->keep_memory)
     7974      if (elf_section_data (sec)->relocs != relstart)
    65497975        free (relstart);
    65507976    out1:
    6551       if (freesyms)
    6552         free (freesyms);
     7977      if (isym != NULL && symtab_hdr->contents != (unsigned char *) isym)
     7978        {
     7979          if (! info->keep_memory)
     7980            free (isym);
     7981          else
     7982            symtab_hdr->contents = (unsigned char *) isym;
     7983        }
    65537984    }
    65547985
     
    65587989/* The sweep phase of garbage collection.  Remove all garbage sections.  */
    65597990
    6560 static boolean
     7991typedef bfd_boolean (*gc_sweep_hook_fn)
     7992  PARAMS ((bfd *, struct bfd_link_info *, asection *,
     7993           const Elf_Internal_Rela *));
     7994
     7995static bfd_boolean
    65617996elf_gc_sweep (info, gc_sweep_hook)
    65627997     struct bfd_link_info *info;
    6563      boolean (*gc_sweep_hook)
    6564        PARAMS ((bfd *abfd, struct bfd_link_info *info, asection *o,
    6565                 const Elf_Internal_Rela *relocs));
     7998     gc_sweep_hook_fn gc_sweep_hook;
    65667999{
    65678000  bfd *sub;
     
    65988031            {
    65998032              Elf_Internal_Rela *internal_relocs;
    6600               boolean r;
     8033              bfd_boolean r;
    66018034
    66028035              internal_relocs = (NAME(_bfd_elf,link_read_relocs)
    66038036                                 (o->owner, o, NULL, NULL, info->keep_memory));
    66048037              if (internal_relocs == NULL)
    6605                 return false;
     8038                return FALSE;
    66068039
    66078040              r = (*gc_sweep_hook) (o->owner, info, o, internal_relocs);
    66088041
    6609               if (!info->keep_memory)
     8042              if (elf_section_data (o)->relocs != internal_relocs)
    66108043                free (internal_relocs);
    66118044
    66128045              if (!r)
    6613                 return false;
     8046                return FALSE;
    66148047            }
    66158048        }
     
    66298062  }
    66308063
    6631   return true;
     8064  return TRUE;
    66328065}
    66338066
    66348067/* Sweep symbols in swept sections.  Called via elf_link_hash_traverse.  */
    66358068
    6636 static boolean
     8069static bfd_boolean
    66378070elf_gc_sweep_symbol (h, idxptr)
    66388071     struct elf_link_hash_entry *h;
     
    66418074  int *idx = (int *) idxptr;
    66428075
     8076  if (h->root.type == bfd_link_hash_warning)
     8077    h = (struct elf_link_hash_entry *) h->root.u.i.link;
     8078
    66438079  if (h->dynindx != -1
    66448080      && ((h->root.type != bfd_link_hash_defined
     
    66478083    h->dynindx = (*idx)++;
    66488084
    6649   return true;
     8085  return TRUE;
    66508086}
    66518087
     
    66538089   elf_link_hash_traverse.  */
    66548090
    6655 static boolean
     8091static bfd_boolean
    66568092elf_gc_propagate_vtable_entries_used (h, okp)
    66578093     struct elf_link_hash_entry *h;
    66588094     PTR okp;
    66598095{
     8096  if (h->root.type == bfd_link_hash_warning)
     8097    h = (struct elf_link_hash_entry *) h->root.u.i.link;
     8098
    66608099  /* Those that are not vtables.  */
    66618100  if (h->vtable_parent == NULL)
    6662     return true;
     8101    return TRUE;
    66638102
    66648103  /* Those vtables that do not have parents, we cannot merge.  */
    66658104  if (h->vtable_parent == (struct elf_link_hash_entry *) -1)
    6666     return true;
     8105    return TRUE;
    66678106
    66688107  /* If we've already been done, exit.  */
    66698108  if (h->vtable_entries_used && h->vtable_entries_used[-1])
    6670     return true;
     8109    return TRUE;
    66718110
    66728111  /* Make sure the parent's table is up to date.  */
     
    66838122    {
    66848123      size_t n;
    6685       boolean *cu, *pu;
     8124      bfd_boolean *cu, *pu;
    66868125
    66878126      /* Or the parent's entries into ours.  */
    66888127      cu = h->vtable_entries_used;
    6689       cu[-1] = true;
     8128      cu[-1] = TRUE;
    66908129      pu = h->vtable_parent->vtable_entries_used;
    66918130      if (pu != NULL)
    66928131        {
    6693           n = h->vtable_parent->vtable_entries_size / FILE_ALIGN;
    6694           while (--n != 0)
     8132          asection *sec = h->root.u.def.section;
     8133          struct elf_backend_data *bed = get_elf_backend_data (sec->owner);
     8134          int file_align = bed->s->file_align;
     8135
     8136          n = h->vtable_parent->vtable_entries_size / file_align;
     8137          while (n--)
    66958138            {
    6696               if (*pu) *cu = true;
    6697               pu++, cu++;
     8139              if (*pu)
     8140                *cu = TRUE;
     8141              pu++;
     8142              cu++;
    66988143            }
    66998144        }
    67008145    }
    67018146
    6702   return true;
     8147  return TRUE;
    67038148}
    67048149
    6705 static boolean
     8150static bfd_boolean
    67068151elf_gc_smash_unused_vtentry_relocs (h, okp)
    67078152     struct elf_link_hash_entry *h;
     
    67128157  Elf_Internal_Rela *relstart, *relend, *rel;
    67138158  struct elf_backend_data *bed;
     8159  int file_align;
     8160
     8161  if (h->root.type == bfd_link_hash_warning)
     8162    h = (struct elf_link_hash_entry *) h->root.u.i.link;
    67148163
    67158164  /* Take care of both those symbols that do not describe vtables as
    67168165     well as those that are not loaded.  */
    67178166  if (h->vtable_parent == NULL)
    6718     return true;
     8167    return TRUE;
    67198168
    67208169  BFD_ASSERT (h->root.type == bfd_link_hash_defined
     
    67268175
    67278176  relstart = (NAME(_bfd_elf,link_read_relocs)
    6728               (sec->owner, sec, NULL, (Elf_Internal_Rela *) NULL, true));
     8177              (sec->owner, sec, NULL, (Elf_Internal_Rela *) NULL, TRUE));
    67298178  if (!relstart)
    6730     return *(boolean *)okp = false;
     8179    return *(bfd_boolean *) okp = FALSE;
    67318180  bed = get_elf_backend_data (sec->owner);
     8181  file_align = bed->s->file_align;
     8182
    67328183  relend = relstart + sec->reloc_count * bed->s->int_rels_per_ext_rel;
    67338184
     
    67398190            && (rel->r_offset - hstart) < h->vtable_entries_size)
    67408191          {
    6741             bfd_vma entry = (rel->r_offset - hstart) / FILE_ALIGN;
     8192            bfd_vma entry = (rel->r_offset - hstart) / file_align;
    67428193            if (h->vtable_entries_used[entry])
    67438194              continue;
     
    67478198      }
    67488199
    6749   return true;
     8200  return TRUE;
    67508201}
    67518202
    67528203/* Do mark and sweep of unused sections.  */
    67538204
    6754 boolean
     8205bfd_boolean
    67558206elf_gc_sections (abfd, info)
    67568207     bfd *abfd;
    67578208     struct bfd_link_info *info;
    67588209{
    6759   boolean ok = true;
     8210  bfd_boolean ok = TRUE;
    67608211  bfd *sub;
    67618212  asection * (*gc_mark_hook)
    6762     PARAMS ((bfd *abfd, struct bfd_link_info *, Elf_Internal_Rela *,
    6763              struct elf_link_hash_entry *h, Elf_Internal_Sym *));
     8213    PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *,
     8214             struct elf_link_hash_entry *h, Elf_Internal_Sym *));
    67648215
    67658216  if (!get_elf_backend_data (abfd)->can_gc_sections
    67668217      || info->relocateable || info->emitrelocations
    67678218      || elf_hash_table (info)->dynamic_sections_created)
    6768     return true;
     8219    return TRUE;
    67698220
    67708221  /* Apply transitive closure to the vtable entry usage info.  */
     
    67738224                          (PTR) &ok);
    67748225  if (!ok)
    6775     return false;
     8226    return FALSE;
    67768227
    67778228  /* Kill the vtable relocations that were not used.  */
     
    67808231                          (PTR) &ok);
    67818232  if (!ok)
    6782     return false;
     8233    return FALSE;
    67838234
    67848235  /* Grovel through relocs to find out who stays ...  */
     
    67958246        {
    67968247          if (o->flags & SEC_KEEP)
    6797             if (!elf_gc_mark (info, o, gc_mark_hook))
    6798               return false;
     8248            if (!elf_gc_mark (info, o, gc_mark_hook))
     8249              return FALSE;
    67998250        }
    68008251    }
    68018252
    68028253  /* ... and mark SEC_EXCLUDE for those that go.  */
    6803   if (!elf_gc_sweep(info, get_elf_backend_data (abfd)->gc_sweep_hook))
    6804     return false;
    6805 
    6806   return true;
     8254  if (!elf_gc_sweep (info, get_elf_backend_data (abfd)->gc_sweep_hook))
     8255    return FALSE;
     8256
     8257  return TRUE;
    68078258}
    68088259
     
    68108261/* Called from check_relocs to record the existance of a VTINHERIT reloc.  */
    68118262
    6812 boolean
     8263bfd_boolean
    68138264elf_gc_record_vtinherit (abfd, sec, h, offset)
    68148265     bfd *abfd;
     
    68448295
    68458296  (*_bfd_error_handler) ("%s: %s+%lu: No symbol found for INHERIT",
    6846                          bfd_get_filename (abfd), sec->name,
    6847                          (unsigned long)offset);
     8297                         bfd_archive_filename (abfd), sec->name,
     8298                         (unsigned long) offset);
    68488299  bfd_set_error (bfd_error_invalid_operation);
    6849   return false;
    6850 
    6851 win:
     8300  return FALSE;
     8301
     8302 win:
    68528303  if (!h)
    68538304    {
     
    68628313    child->vtable_parent = h;
    68638314
    6864   return true;
     8315  return TRUE;
    68658316}
    68668317
    68678318/* Called from check_relocs to record the existance of a VTENTRY reloc.  */
    68688319
    6869 boolean
     8320bfd_boolean
    68708321elf_gc_record_vtentry (abfd, sec, h, addend)
    68718322     bfd *abfd ATTRIBUTE_UNUSED;
     
    68748325     bfd_vma addend;
    68758326{
     8327  struct elf_backend_data *bed = get_elf_backend_data (abfd);
     8328  int file_align = bed->s->file_align;
     8329
    68768330  if (addend >= h->vtable_entries_size)
    68778331    {
    68788332      size_t size, bytes;
    6879       boolean *ptr = h->vtable_entries_used;
     8333      bfd_boolean *ptr = h->vtable_entries_used;
    68808334
    68818335      /* While the symbol is undefined, we have to be prepared to handle
     
    68968350      /* Allocate one extra entry for use as a "done" flag for the
    68978351         consolidation pass.  */
    6898       bytes = (size / FILE_ALIGN + 1) * sizeof (boolean);
     8352      bytes = (size / file_align + 1) * sizeof (bfd_boolean);
    68998353
    69008354      if (ptr)
    69018355        {
    6902           ptr = bfd_realloc (ptr - 1, bytes);
     8356          ptr = bfd_realloc (ptr - 1, (bfd_size_type) bytes);
    69038357
    69048358          if (ptr != NULL)
     
    69068360              size_t oldbytes;
    69078361
    6908               oldbytes = (h->vtable_entries_size/FILE_ALIGN + 1) * sizeof (boolean);
    6909               memset (((char *)ptr) + oldbytes, 0, bytes - oldbytes);
     8362              oldbytes = ((h->vtable_entries_size / file_align + 1)
     8363                          * sizeof (bfd_boolean));
     8364              memset (((char *) ptr) + oldbytes, 0, bytes - oldbytes);
    69108365            }
    69118366        }
    69128367      else
    6913         ptr = bfd_zmalloc (bytes);
     8368        ptr = bfd_zmalloc ((bfd_size_type) bytes);
    69148369
    69158370      if (ptr == NULL)
    6916         return false;
     8371        return FALSE;
    69178372
    69188373      /* And arrange for that done flag to be at index -1.  */
     
    69218376    }
    69228377
    6923   h->vtable_entries_used[addend / FILE_ALIGN] = true;
    6924 
    6925   return true;
     8378  h->vtable_entries_used[addend / file_align] = TRUE;
     8379
     8380  return TRUE;
    69268381}
    69278382
     
    69298384   we're done.  Should be called from final_link.  */
    69308385
    6931 boolean
     8386bfd_boolean
    69328387elf_gc_common_finalize_got_offsets (abfd, info)
    69338388     bfd *abfd;
     
    69828437                          elf_gc_allocate_got_offsets,
    69838438                          (PTR) &gotoff);
    6984   return true;
     8439  return TRUE;
    69858440}
    69868441
     
    69888443   to real got offsets.  */
    69898444
    6990 static boolean
     8445static bfd_boolean
    69918446elf_gc_allocate_got_offsets (h, offarg)
    69928447     struct elf_link_hash_entry *h;
     
    69958450  bfd_vma *off = (bfd_vma *) offarg;
    69968451
     8452  if (h->root.type == bfd_link_hash_warning)
     8453    h = (struct elf_link_hash_entry *) h->root.u.i.link;
     8454
    69978455  if (h->got.refcount > 0)
    69988456    {
     
    70038461    h->got.offset = (bfd_vma) -1;
    70048462
    7005   return true;
     8463  return TRUE;
    70068464}
    70078465
     
    70098467   got entry reference counting is enabled.  */
    70108468
    7011 boolean
     8469bfd_boolean
    70128470elf_gc_common_final_link (abfd, info)
    70138471     bfd *abfd;
     
    70158473{
    70168474  if (!elf_gc_common_finalize_got_offsets (abfd, info))
    7017     return false;
     8475    return FALSE;
    70188476
    70198477  /* Invoke the regular ELF backend linker to do all the work.  */
     
    70248482   all hash value of the exported symbols in an array.  */
    70258483
    7026 static boolean
     8484static bfd_boolean
    70278485elf_collect_hash_codes (h, data)
    70288486     struct elf_link_hash_entry *h;
     
    70358493  char *alc = NULL;
    70368494
     8495  if (h->root.type == bfd_link_hash_warning)
     8496    h = (struct elf_link_hash_entry *) h->root.u.i.link;
     8497
    70378498  /* Ignore indirect symbols.  These are added by the versioning code.  */
    70388499  if (h->dynindx == -1)
    7039     return true;
     8500    return TRUE;
    70408501
    70418502  name = h->root.root.string;
     
    70438504  if (p != NULL)
    70448505    {
    7045       alc = bfd_malloc (p - name + 1);
    7046       memcpy (alc, name, p - name);
     8506      alc = bfd_malloc ((bfd_size_type) (p - name + 1));
     8507      memcpy (alc, name, (size_t) (p - name));
    70478508      alc[p - name] = '\0';
    70488509      name = alc;
     
    70628523    free (alc);
    70638524
    7064   return true;
     8525  return TRUE;
    70658526}
     8527
     8528bfd_boolean
     8529elf_reloc_symbol_deleted_p (offset, cookie)
     8530     bfd_vma offset;
     8531     PTR cookie;
     8532{
     8533  struct elf_reloc_cookie *rcookie = (struct elf_reloc_cookie *) cookie;
     8534
     8535  if (rcookie->bad_symtab)
     8536    rcookie->rel = rcookie->rels;
     8537
     8538  for (; rcookie->rel < rcookie->relend; rcookie->rel++)
     8539    {
     8540      unsigned long r_symndx;
     8541
     8542      if (! rcookie->bad_symtab)
     8543        if (rcookie->rel->r_offset > offset)
     8544          return FALSE;
     8545      if (rcookie->rel->r_offset != offset)
     8546        continue;
     8547
     8548      r_symndx = ELF_R_SYM (rcookie->rel->r_info);
     8549      if (r_symndx == SHN_UNDEF)
     8550        return TRUE;
     8551
     8552      if (r_symndx >= rcookie->locsymcount
     8553          || ELF_ST_BIND (rcookie->locsyms[r_symndx].st_info) != STB_LOCAL)
     8554        {
     8555          struct elf_link_hash_entry *h;
     8556
     8557          h = rcookie->sym_hashes[r_symndx - rcookie->extsymoff];
     8558
     8559          while (h->root.type == bfd_link_hash_indirect
     8560                 || h->root.type == bfd_link_hash_warning)
     8561            h = (struct elf_link_hash_entry *) h->root.u.i.link;
     8562
     8563          if ((h->root.type == bfd_link_hash_defined
     8564               || h->root.type == bfd_link_hash_defweak)
     8565              && elf_discarded_section (h->root.u.def.section))
     8566            return TRUE;
     8567          else
     8568            return FALSE;
     8569        }
     8570      else
     8571        {
     8572          /* It's not a relocation against a global symbol,
     8573             but it could be a relocation against a local
     8574             symbol for a discarded section.  */
     8575          asection *isec;
     8576          Elf_Internal_Sym *isym;
     8577
     8578          /* Need to: get the symbol; get the section.  */
     8579          isym = &rcookie->locsyms[r_symndx];
     8580          if (isym->st_shndx < SHN_LORESERVE || isym->st_shndx > SHN_HIRESERVE)
     8581            {
     8582              isec = section_from_elf_index (rcookie->abfd, isym->st_shndx);
     8583              if (isec != NULL && elf_discarded_section (isec))
     8584                return TRUE;
     8585            }
     8586        }
     8587      return FALSE;
     8588    }
     8589  return FALSE;
     8590}
     8591
     8592/* Discard unneeded references to discarded sections.
     8593   Returns TRUE if any section's size was changed.  */
     8594/* This function assumes that the relocations are in sorted order,
     8595   which is true for all known assemblers.  */
     8596
     8597bfd_boolean
     8598elf_bfd_discard_info (output_bfd, info)
     8599     bfd *output_bfd;
     8600     struct bfd_link_info *info;
     8601{
     8602  struct elf_reloc_cookie cookie;
     8603  asection *stab, *eh;
     8604  Elf_Internal_Shdr *symtab_hdr;
     8605  struct elf_backend_data *bed;
     8606  bfd *abfd;
     8607  unsigned int count;
     8608  bfd_boolean ret = FALSE;
     8609
     8610  if (info->traditional_format
     8611      || info->hash->creator->flavour != bfd_target_elf_flavour
     8612      || ! is_elf_hash_table (info))
     8613    return FALSE;
     8614
     8615  for (abfd = info->input_bfds; abfd != NULL; abfd = abfd->link_next)
     8616    {
     8617      if (bfd_get_flavour (abfd) != bfd_target_elf_flavour)
     8618        continue;
     8619
     8620      bed = get_elf_backend_data (abfd);
     8621
     8622      if ((abfd->flags & DYNAMIC) != 0)
     8623        continue;
     8624
     8625      eh = bfd_get_section_by_name (abfd, ".eh_frame");
     8626      if (info->relocateable
     8627          || (eh != NULL
     8628              && (eh->_raw_size == 0
     8629                  || bfd_is_abs_section (eh->output_section))))
     8630        eh = NULL;
     8631
     8632      stab = bfd_get_section_by_name (abfd, ".stab");
     8633      if (stab != NULL
     8634          && (stab->_raw_size == 0
     8635              || bfd_is_abs_section (stab->output_section)
     8636              || stab->sec_info_type != ELF_INFO_TYPE_STABS))
     8637        stab = NULL;
     8638
     8639      if (stab == NULL
     8640          && eh == NULL
     8641          && bed->elf_backend_discard_info == NULL)
     8642        continue;
     8643
     8644      symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
     8645      cookie.abfd = abfd;
     8646      cookie.sym_hashes = elf_sym_hashes (abfd);
     8647      cookie.bad_symtab = elf_bad_symtab (abfd);
     8648      if (cookie.bad_symtab)
     8649        {
     8650          cookie.locsymcount = symtab_hdr->sh_size / sizeof (Elf_External_Sym);
     8651          cookie.extsymoff = 0;
     8652        }
     8653      else
     8654        {
     8655          cookie.locsymcount = symtab_hdr->sh_info;
     8656          cookie.extsymoff = symtab_hdr->sh_info;
     8657        }
     8658
     8659      cookie.locsyms = (Elf_Internal_Sym *) symtab_hdr->contents;
     8660      if (cookie.locsyms == NULL && cookie.locsymcount != 0)
     8661        {
     8662          cookie.locsyms = bfd_elf_get_elf_syms (abfd, symtab_hdr,
     8663                                                 cookie.locsymcount, 0,
     8664                                                 NULL, NULL, NULL);
     8665          if (cookie.locsyms == NULL)
     8666            return FALSE;
     8667        }
     8668
     8669      if (stab != NULL)
     8670        {
     8671          cookie.rels = NULL;
     8672          count = stab->reloc_count;
     8673          if (count != 0)
     8674            cookie.rels = (NAME(_bfd_elf,link_read_relocs)
     8675                           (abfd, stab, (PTR) NULL, (Elf_Internal_Rela *) NULL,
     8676                            info->keep_memory));
     8677          if (cookie.rels != NULL)
     8678            {
     8679              cookie.rel = cookie.rels;
     8680              cookie.relend = cookie.rels;
     8681              cookie.relend += count * bed->s->int_rels_per_ext_rel;
     8682              if (_bfd_discard_section_stabs (abfd, stab,
     8683                                              elf_section_data (stab)->sec_info,
     8684                                              elf_reloc_symbol_deleted_p,
     8685                                              &cookie))
     8686                ret = TRUE;
     8687              if (elf_section_data (stab)->relocs != cookie.rels)
     8688                free (cookie.rels);
     8689            }
     8690        }
     8691
     8692      if (eh != NULL)
     8693        {
     8694          cookie.rels = NULL;
     8695          count = eh->reloc_count;
     8696          if (count != 0)
     8697            cookie.rels = (NAME(_bfd_elf,link_read_relocs)
     8698                           (abfd, eh, (PTR) NULL, (Elf_Internal_Rela *) NULL,
     8699                            info->keep_memory));
     8700          cookie.rel = cookie.rels;
     8701          cookie.relend = cookie.rels;
     8702          if (cookie.rels != NULL)
     8703            cookie.relend += count * bed->s->int_rels_per_ext_rel;
     8704
     8705          if (_bfd_elf_discard_section_eh_frame (abfd, info, eh,
     8706                                                 elf_reloc_symbol_deleted_p,
     8707                                                 &cookie))
     8708            ret = TRUE;
     8709
     8710          if (cookie.rels != NULL
     8711              && elf_section_data (eh)->relocs != cookie.rels)
     8712            free (cookie.rels);
     8713        }
     8714
     8715      if (bed->elf_backend_discard_info != NULL
     8716          && (*bed->elf_backend_discard_info) (abfd, &cookie, info))
     8717        ret = TRUE;
     8718
     8719      if (cookie.locsyms != NULL
     8720          && symtab_hdr->contents != (unsigned char *) cookie.locsyms)
     8721        {
     8722          if (! info->keep_memory)
     8723            free (cookie.locsyms);
     8724          else
     8725            symtab_hdr->contents = (unsigned char *) cookie.locsyms;
     8726        }
     8727    }
     8728
     8729  if (info->eh_frame_hdr
     8730      && !info->relocateable
     8731      && _bfd_elf_discard_section_eh_frame_hdr (output_bfd, info))
     8732    ret = TRUE;
     8733
     8734  return ret;
     8735}
     8736
     8737static bfd_boolean
     8738elf_section_ignore_discarded_relocs (sec)
     8739     asection *sec;
     8740{
     8741  struct elf_backend_data *bed;
     8742
     8743  switch (sec->sec_info_type)
     8744    {
     8745    case ELF_INFO_TYPE_STABS:
     8746    case ELF_INFO_TYPE_EH_FRAME:
     8747      return TRUE;
     8748    default:
     8749      break;
     8750    }
     8751
     8752  bed = get_elf_backend_data (sec->owner);
     8753  if (bed->elf_backend_ignore_discarded_relocs != NULL
     8754      && (*bed->elf_backend_ignore_discarded_relocs) (sec))
     8755    return TRUE;
     8756
     8757  return FALSE;
     8758}
Note: See TracChangeset for help on using the changeset viewer.