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/elf.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    11/* ELF executable support for BFD.
    2    Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
    3    Free Software Foundation, Inc.
    4 
    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.  */
    20 
    21 /*
    22 
    23 SECTION
     2   Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
     3   2003 Free Software Foundation, Inc.
     4
     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.  */
     20
     21/*  SECTION
     22
    2423        ELF backends
    2524
     
    3029        Documentation of the internals of the support code still needs
    3130        to be written.  The code is changing quickly enough that we
    32         haven't bothered yet.
    33  */
     31        haven't bothered yet.  */
    3432
    3533/* For sparc64-cross-sparc32.  */
     
    4139#define ARCH_SIZE 0
    4240#include "elf-bfd.h"
     41#include "libiberty.h"
    4342
    4443static INLINE struct elf_segment_map *make_mapping
    45   PARAMS ((bfd *, asection **, unsigned int, unsigned int, boolean));
    46 static boolean map_sections_to_segments PARAMS ((bfd *));
    47 static int elf_sort_sections PARAMS ((const PTR, const PTR));
    48 static boolean assign_file_positions_for_segments PARAMS ((bfd *));
    49 static boolean assign_file_positions_except_relocs PARAMS ((bfd *));
    50 static boolean prep_headers PARAMS ((bfd *));
    51 static boolean swap_out_syms PARAMS ((bfd *, struct bfd_strtab_hash **, int));
    52 static boolean copy_private_bfd_data PARAMS ((bfd *, bfd *));
    53 static char *elf_read PARAMS ((bfd *, long, unsigned int));
    54 static void elf_fake_sections PARAMS ((bfd *, asection *, PTR));
    55 static boolean assign_section_numbers PARAMS ((bfd *));
    56 static INLINE int sym_is_global PARAMS ((bfd *, asymbol *));
    57 static boolean elf_map_symbols PARAMS ((bfd *));
    58 static bfd_size_type get_program_header_size PARAMS ((bfd *));
    59 static boolean elfcore_read_notes PARAMS ((bfd *, bfd_vma, bfd_vma));
    60 static boolean elf_find_function PARAMS ((bfd *, asection *,
    61                                          asymbol **,
    62                                          bfd_vma, const char **,
    63                                          const char **));
     44  PARAMS ((bfd *, asection **, unsigned int, unsigned int, bfd_boolean));
     45static bfd_boolean map_sections_to_segments
     46  PARAMS ((bfd *));
     47static int elf_sort_sections
     48  PARAMS ((const PTR, const PTR));
     49static bfd_boolean assign_file_positions_for_segments
     50  PARAMS ((bfd *));
     51static bfd_boolean assign_file_positions_except_relocs
     52  PARAMS ((bfd *));
     53static bfd_boolean prep_headers
     54  PARAMS ((bfd *));
     55static bfd_boolean swap_out_syms
     56  PARAMS ((bfd *, struct bfd_strtab_hash **, int));
     57static bfd_boolean copy_private_bfd_data
     58  PARAMS ((bfd *, bfd *));
     59static char *elf_read
     60  PARAMS ((bfd *, file_ptr, bfd_size_type));
     61static const char *group_signature
     62  PARAMS ((bfd *, Elf_Internal_Shdr *));
     63static bfd_boolean setup_group
     64  PARAMS ((bfd *, Elf_Internal_Shdr *, asection *));
     65static void merge_sections_remove_hook
     66  PARAMS ((bfd *, asection *));
     67static void elf_fake_sections
     68  PARAMS ((bfd *, asection *, PTR));
     69static bfd_boolean assign_section_numbers
     70  PARAMS ((bfd *));
     71static INLINE int sym_is_global
     72  PARAMS ((bfd *, asymbol *));
     73static bfd_boolean elf_map_symbols
     74  PARAMS ((bfd *));
     75static bfd_size_type get_program_header_size
     76  PARAMS ((bfd *));
     77static bfd_boolean elfcore_read_notes
     78  PARAMS ((bfd *, file_ptr, bfd_size_type));
     79static bfd_boolean elf_find_function
     80  PARAMS ((bfd *, asection *, asymbol **, bfd_vma, const char **,
     81           const char **));
     82static int elfcore_make_pid
     83  PARAMS ((bfd *));
     84static bfd_boolean elfcore_maybe_make_sect
     85  PARAMS ((bfd *, char *, asection *));
     86static bfd_boolean elfcore_make_note_pseudosection
     87  PARAMS ((bfd *, char *, Elf_Internal_Note *));
     88static bfd_boolean elfcore_grok_prfpreg
     89  PARAMS ((bfd *, Elf_Internal_Note *));
     90static bfd_boolean elfcore_grok_prxfpreg
     91  PARAMS ((bfd *, Elf_Internal_Note *));
     92static bfd_boolean elfcore_grok_note
     93  PARAMS ((bfd *, Elf_Internal_Note *));
     94static bfd_boolean elfcore_netbsd_get_lwpid
     95  PARAMS ((Elf_Internal_Note *, int *));
     96static bfd_boolean elfcore_grok_netbsd_procinfo
     97  PARAMS ((bfd *, Elf_Internal_Note *));
     98static bfd_boolean elfcore_grok_netbsd_note
     99  PARAMS ((bfd *, Elf_Internal_Note *));
     100static bfd_boolean elfcore_grok_nto_gregs
     101  PARAMS ((bfd *, Elf_Internal_Note *, pid_t));
     102static bfd_boolean elfcore_grok_nto_status
     103  PARAMS ((bfd *, Elf_Internal_Note *, pid_t *));
     104static bfd_boolean elfcore_grok_nto_note
     105  PARAMS ((bfd *, Elf_Internal_Note *));
    64106
    65107/* Swap version information in and out.  The version information is
     
    75117     Elf_Internal_Verdef *dst;
    76118{
    77   dst->vd_version = bfd_h_get_16 (abfd, src->vd_version);
    78   dst->vd_flags   = bfd_h_get_16 (abfd, src->vd_flags);
    79   dst->vd_ndx     = bfd_h_get_16 (abfd, src->vd_ndx);
    80   dst->vd_cnt     = bfd_h_get_16 (abfd, src->vd_cnt);
    81   dst->vd_hash    = bfd_h_get_32 (abfd, src->vd_hash);
    82   dst->vd_aux     = bfd_h_get_32 (abfd, src->vd_aux);
    83   dst->vd_next    = bfd_h_get_32 (abfd, src->vd_next);
     119  dst->vd_version = H_GET_16 (abfd, src->vd_version);
     120  dst->vd_flags   = H_GET_16 (abfd, src->vd_flags);
     121  dst->vd_ndx     = H_GET_16 (abfd, src->vd_ndx);
     122  dst->vd_cnt     = H_GET_16 (abfd, src->vd_cnt);
     123  dst->vd_hash    = H_GET_32 (abfd, src->vd_hash);
     124  dst->vd_aux     = H_GET_32 (abfd, src->vd_aux);
     125  dst->vd_next    = H_GET_32 (abfd, src->vd_next);
    84126}
    85127
     
    92134     Elf_External_Verdef *dst;
    93135{
    94   bfd_h_put_16 (abfd, src->vd_version, dst->vd_version);
    95   bfd_h_put_16 (abfd, src->vd_flags, dst->vd_flags);
    96   bfd_h_put_16 (abfd, src->vd_ndx, dst->vd_ndx);
    97   bfd_h_put_16 (abfd, src->vd_cnt, dst->vd_cnt);
    98   bfd_h_put_32 (abfd, src->vd_hash, dst->vd_hash);
    99   bfd_h_put_32 (abfd, src->vd_aux, dst->vd_aux);
    100   bfd_h_put_32 (abfd, src->vd_next, dst->vd_next);
     136  H_PUT_16 (abfd, src->vd_version, dst->vd_version);
     137  H_PUT_16 (abfd, src->vd_flags, dst->vd_flags);
     138  H_PUT_16 (abfd, src->vd_ndx, dst->vd_ndx);
     139  H_PUT_16 (abfd, src->vd_cnt, dst->vd_cnt);
     140  H_PUT_32 (abfd, src->vd_hash, dst->vd_hash);
     141  H_PUT_32 (abfd, src->vd_aux, dst->vd_aux);
     142  H_PUT_32 (abfd, src->vd_next, dst->vd_next);
    101143}
    102144
     
    109151     Elf_Internal_Verdaux *dst;
    110152{
    111   dst->vda_name = bfd_h_get_32 (abfd, src->vda_name);
    112   dst->vda_next = bfd_h_get_32 (abfd, src->vda_next);
     153  dst->vda_name = H_GET_32 (abfd, src->vda_name);
     154  dst->vda_next = H_GET_32 (abfd, src->vda_next);
    113155}
    114156
     
    121163     Elf_External_Verdaux *dst;
    122164{
    123   bfd_h_put_32 (abfd, src->vda_name, dst->vda_name);
    124   bfd_h_put_32 (abfd, src->vda_next, dst->vda_next);
     165  H_PUT_32 (abfd, src->vda_name, dst->vda_name);
     166  H_PUT_32 (abfd, src->vda_next, dst->vda_next);
    125167}
    126168
     
    133175     Elf_Internal_Verneed *dst;
    134176{
    135   dst->vn_version = bfd_h_get_16 (abfd, src->vn_version);
    136   dst->vn_cnt     = bfd_h_get_16 (abfd, src->vn_cnt);
    137   dst->vn_file    = bfd_h_get_32 (abfd, src->vn_file);
    138   dst->vn_aux     = bfd_h_get_32 (abfd, src->vn_aux);
    139   dst->vn_next    = bfd_h_get_32 (abfd, src->vn_next);
     177  dst->vn_version = H_GET_16 (abfd, src->vn_version);
     178  dst->vn_cnt     = H_GET_16 (abfd, src->vn_cnt);
     179  dst->vn_file    = H_GET_32 (abfd, src->vn_file);
     180  dst->vn_aux     = H_GET_32 (abfd, src->vn_aux);
     181  dst->vn_next    = H_GET_32 (abfd, src->vn_next);
    140182}
    141183
     
    148190     Elf_External_Verneed *dst;
    149191{
    150   bfd_h_put_16 (abfd, src->vn_version, dst->vn_version);
    151   bfd_h_put_16 (abfd, src->vn_cnt, dst->vn_cnt);
    152   bfd_h_put_32 (abfd, src->vn_file, dst->vn_file);
    153   bfd_h_put_32 (abfd, src->vn_aux, dst->vn_aux);
    154   bfd_h_put_32 (abfd, src->vn_next, dst->vn_next);
     192  H_PUT_16 (abfd, src->vn_version, dst->vn_version);
     193  H_PUT_16 (abfd, src->vn_cnt, dst->vn_cnt);
     194  H_PUT_32 (abfd, src->vn_file, dst->vn_file);
     195  H_PUT_32 (abfd, src->vn_aux, dst->vn_aux);
     196  H_PUT_32 (abfd, src->vn_next, dst->vn_next);
    155197}
    156198
     
    163205     Elf_Internal_Vernaux *dst;
    164206{
    165   dst->vna_hash  = bfd_h_get_32 (abfd, src->vna_hash);
    166   dst->vna_flags = bfd_h_get_16 (abfd, src->vna_flags);
    167   dst->vna_other = bfd_h_get_16 (abfd, src->vna_other);
    168   dst->vna_name  = bfd_h_get_32 (abfd, src->vna_name);
    169   dst->vna_next  = bfd_h_get_32 (abfd, src->vna_next);
     207  dst->vna_hash  = H_GET_32 (abfd, src->vna_hash);
     208  dst->vna_flags = H_GET_16 (abfd, src->vna_flags);
     209  dst->vna_other = H_GET_16 (abfd, src->vna_other);
     210  dst->vna_name  = H_GET_32 (abfd, src->vna_name);
     211  dst->vna_next  = H_GET_32 (abfd, src->vna_next);
    170212}
    171213
     
    178220     Elf_External_Vernaux *dst;
    179221{
    180   bfd_h_put_32 (abfd, src->vna_hash, dst->vna_hash);
    181   bfd_h_put_16 (abfd, src->vna_flags, dst->vna_flags);
    182   bfd_h_put_16 (abfd, src->vna_other, dst->vna_other);
    183   bfd_h_put_32 (abfd, src->vna_name, dst->vna_name);
    184   bfd_h_put_32 (abfd, src->vna_next, dst->vna_next);
     222  H_PUT_32 (abfd, src->vna_hash, dst->vna_hash);
     223  H_PUT_16 (abfd, src->vna_flags, dst->vna_flags);
     224  H_PUT_16 (abfd, src->vna_other, dst->vna_other);
     225  H_PUT_32 (abfd, src->vna_name, dst->vna_name);
     226  H_PUT_32 (abfd, src->vna_next, dst->vna_next);
    185227}
    186228
     
    193235     Elf_Internal_Versym *dst;
    194236{
    195   dst->vs_vers = bfd_h_get_16 (abfd, src->vs_vers);
     237  dst->vs_vers = H_GET_16 (abfd, src->vs_vers);
    196238}
    197239
     
    204246     Elf_External_Versym *dst;
    205247{
    206   bfd_h_put_16 (abfd, src->vs_vers, dst->vs_vers);
     248  H_PUT_16 (abfd, src->vs_vers, dst->vs_vers);
    207249}
    208250
     
    230272        }
    231273    }
    232   return h;
     274  return h & 0xffffffff;
    233275}
    234276
     
    240282elf_read (abfd, offset, size)
    241283     bfd *abfd;
    242      long offset;
    243      unsigned int size;
     284     file_ptr offset;
     285     bfd_size_type size;
    244286{
    245287  char *buf;
     
    247289  if ((buf = bfd_alloc (abfd, size)) == NULL)
    248290    return NULL;
    249   if (bfd_seek (abfd, offset, SEEK_SET) == -1)
     291  if (bfd_seek (abfd, offset, SEEK_SET) != 0)
    250292    return NULL;
    251   if (bfd_read ((PTR) buf, size, 1, abfd) != size)
     293  if (bfd_bread ((PTR) buf, size, abfd) != size)
    252294    {
    253295      if (bfd_get_error () != bfd_error_system_call)
     
    258300}
    259301
    260 boolean
     302bfd_boolean
    261303bfd_elf_mkobject (abfd)
    262304     bfd *abfd;
     
    264306  /* This just does initialization.  */
    265307  /* coff_mkobject zalloc's space for tdata.coff_obj_data ...  */
    266   elf_tdata (abfd) = (struct elf_obj_tdata *)
    267     bfd_zalloc (abfd, sizeof (struct elf_obj_tdata));
     308  bfd_size_type amt = sizeof (struct elf_obj_tdata);
     309  elf_tdata (abfd) = (struct elf_obj_tdata *) bfd_zalloc (abfd, amt);
    268310  if (elf_tdata (abfd) == 0)
    269     return false;
     311    return FALSE;
    270312  /* Since everything is done at close time, do we need any
    271313     initialization?  */
    272314
    273   return true;
    274 }
    275 
    276 boolean
     315  return TRUE;
     316}
     317
     318bfd_boolean
    277319bfd_elf_mkcorefile (abfd)
    278320     bfd *abfd;
     
    289331  Elf_Internal_Shdr **i_shdrp;
    290332  char *shstrtab = NULL;
    291   unsigned int offset;
    292   unsigned int shstrtabsize;
     333  file_ptr offset;
     334  bfd_size_type shstrtabsize;
    293335
    294336  i_shdrp = elf_elfsections (abfd);
     
    329371      (*_bfd_error_handler)
    330372        (_("%s: invalid string offset %u >= %lu for section `%s'"),
    331          bfd_get_filename (abfd), strindex, (unsigned long) hdr->sh_size,
     373         bfd_archive_filename (abfd), strindex, (unsigned long) hdr->sh_size,
    332374         ((shindex == elf_elfheader(abfd)->e_shstrndx
    333375           && strindex == hdr->sh_name)
     
    340382}
    341383
     384/* Read and convert symbols to internal format.
     385   SYMCOUNT specifies the number of symbols to read, starting from
     386   symbol SYMOFFSET.  If any of INTSYM_BUF, EXTSYM_BUF or EXTSHNDX_BUF
     387   are non-NULL, they are used to store the internal symbols, external
     388   symbols, and symbol section index extensions, respectively.  */
     389
     390Elf_Internal_Sym *
     391bfd_elf_get_elf_syms (ibfd, symtab_hdr, symcount, symoffset,
     392                      intsym_buf, extsym_buf, extshndx_buf)
     393     bfd *ibfd;
     394     Elf_Internal_Shdr *symtab_hdr;
     395     size_t symcount;
     396     size_t symoffset;
     397     Elf_Internal_Sym *intsym_buf;
     398     PTR extsym_buf;
     399     Elf_External_Sym_Shndx *extshndx_buf;
     400{
     401  Elf_Internal_Shdr *shndx_hdr;
     402  PTR alloc_ext;
     403  const bfd_byte *esym;
     404  Elf_External_Sym_Shndx *alloc_extshndx;
     405  Elf_External_Sym_Shndx *shndx;
     406  Elf_Internal_Sym *isym;
     407  Elf_Internal_Sym *isymend;
     408  struct elf_backend_data *bed;
     409  size_t extsym_size;
     410  bfd_size_type amt;
     411  file_ptr pos;
     412
     413  if (symcount == 0)
     414    return intsym_buf;
     415
     416  /* Normal syms might have section extension entries.  */
     417  shndx_hdr = NULL;
     418  if (symtab_hdr == &elf_tdata (ibfd)->symtab_hdr)
     419    shndx_hdr = &elf_tdata (ibfd)->symtab_shndx_hdr;
     420
     421  /* Read the symbols.  */
     422  alloc_ext = NULL;
     423  alloc_extshndx = NULL;
     424  bed = get_elf_backend_data (ibfd);
     425  extsym_size = bed->s->sizeof_sym;
     426  amt = symcount * extsym_size;
     427  pos = symtab_hdr->sh_offset + symoffset * extsym_size;
     428  if (extsym_buf == NULL)
     429    {
     430      alloc_ext = bfd_malloc (amt);
     431      extsym_buf = alloc_ext;
     432    }
     433  if (extsym_buf == NULL
     434      || bfd_seek (ibfd, pos, SEEK_SET) != 0
     435      || bfd_bread (extsym_buf, amt, ibfd) != amt)
     436    {
     437      intsym_buf = NULL;
     438      goto out;
     439    }
     440
     441  if (shndx_hdr == NULL || shndx_hdr->sh_size == 0)
     442    extshndx_buf = NULL;
     443  else
     444    {
     445      amt = symcount * sizeof (Elf_External_Sym_Shndx);
     446      pos = shndx_hdr->sh_offset + symoffset * sizeof (Elf_External_Sym_Shndx);
     447      if (extshndx_buf == NULL)
     448        {
     449          alloc_extshndx = (Elf_External_Sym_Shndx *) bfd_malloc (amt);
     450          extshndx_buf = alloc_extshndx;
     451        }
     452      if (extshndx_buf == NULL
     453          || bfd_seek (ibfd, pos, SEEK_SET) != 0
     454          || bfd_bread (extshndx_buf, amt, ibfd) != amt)
     455        {
     456          intsym_buf = NULL;
     457          goto out;
     458        }
     459    }
     460
     461  if (intsym_buf == NULL)
     462    {
     463      bfd_size_type amt = symcount * sizeof (Elf_Internal_Sym);
     464      intsym_buf = (Elf_Internal_Sym *) bfd_malloc (amt);
     465      if (intsym_buf == NULL)
     466        goto out;
     467    }
     468
     469  /* Convert the symbols to internal form.  */
     470  isymend = intsym_buf + symcount;
     471  for (esym = extsym_buf, isym = intsym_buf, shndx = extshndx_buf;
     472       isym < isymend;
     473       esym += extsym_size, isym++, shndx = shndx != NULL ? shndx + 1 : NULL)
     474    (*bed->s->swap_symbol_in) (ibfd, esym, (const PTR) shndx, isym);
     475
     476 out:
     477  if (alloc_ext != NULL)
     478    free (alloc_ext);
     479  if (alloc_extshndx != NULL)
     480    free (alloc_extshndx);
     481
     482  return intsym_buf;
     483}
     484
     485/* Look up a symbol name.  */
     486const char *
     487bfd_elf_local_sym_name (abfd, isym)
     488     bfd *abfd;
     489     Elf_Internal_Sym *isym;
     490{
     491  unsigned int iname = isym->st_name;
     492  unsigned int shindex = elf_tdata (abfd)->symtab_hdr.sh_link;
     493  if (iname == 0 && ELF_ST_TYPE (isym->st_info) == STT_SECTION)
     494    {
     495      iname = elf_elfsections (abfd)[isym->st_shndx]->sh_name;
     496      shindex = elf_elfheader (abfd)->e_shstrndx;
     497    }
     498
     499  return bfd_elf_string_from_elf_section (abfd, shindex, iname);
     500}
     501
     502/* Elf_Internal_Shdr->contents is an array of these for SHT_GROUP
     503   sections.  The first element is the flags, the rest are section
     504   pointers.  */
     505
     506typedef union elf_internal_group {
     507  Elf_Internal_Shdr *shdr;
     508  unsigned int flags;
     509} Elf_Internal_Group;
     510
     511/* Return the name of the group signature symbol.  Why isn't the
     512   signature just a string?  */
     513
     514static const char *
     515group_signature (abfd, ghdr)
     516     bfd *abfd;
     517     Elf_Internal_Shdr *ghdr;
     518{
     519  Elf_Internal_Shdr *hdr;
     520  unsigned char esym[sizeof (Elf64_External_Sym)];
     521  Elf_External_Sym_Shndx eshndx;
     522  Elf_Internal_Sym isym;
     523
     524  /* First we need to ensure the symbol table is available.  */
     525  if (! bfd_section_from_shdr (abfd, ghdr->sh_link))
     526    return NULL;
     527
     528  /* Go read the symbol.  */
     529  hdr = &elf_tdata (abfd)->symtab_hdr;
     530  if (bfd_elf_get_elf_syms (abfd, hdr, 1, ghdr->sh_info,
     531                            &isym, esym, &eshndx) == NULL)
     532    return NULL;
     533
     534  return bfd_elf_local_sym_name (abfd, &isym);
     535}
     536
     537/* Set next_in_group list pointer, and group name for NEWSECT.  */
     538
     539static bfd_boolean
     540setup_group (abfd, hdr, newsect)
     541     bfd *abfd;
     542     Elf_Internal_Shdr *hdr;
     543     asection *newsect;
     544{
     545  unsigned int num_group = elf_tdata (abfd)->num_group;
     546
     547  /* If num_group is zero, read in all SHT_GROUP sections.  The count
     548     is set to -1 if there are no SHT_GROUP sections.  */
     549  if (num_group == 0)
     550    {
     551      unsigned int i, shnum;
     552
     553      /* First count the number of groups.  If we have a SHT_GROUP
     554         section with just a flag word (ie. sh_size is 4), ignore it.  */
     555      shnum = elf_numsections (abfd);
     556      num_group = 0;
     557      for (i = 0; i < shnum; i++)
     558        {
     559          Elf_Internal_Shdr *shdr = elf_elfsections (abfd)[i];
     560          if (shdr->sh_type == SHT_GROUP && shdr->sh_size >= 8)
     561            num_group += 1;
     562        }
     563
     564      if (num_group == 0)
     565        num_group = (unsigned) -1;
     566      elf_tdata (abfd)->num_group = num_group;
     567
     568      if (num_group > 0)
     569        {
     570          /* We keep a list of elf section headers for group sections,
     571             so we can find them quickly.  */
     572          bfd_size_type amt = num_group * sizeof (Elf_Internal_Shdr *);
     573          elf_tdata (abfd)->group_sect_ptr = bfd_alloc (abfd, amt);
     574          if (elf_tdata (abfd)->group_sect_ptr == NULL)
     575            return FALSE;
     576
     577          num_group = 0;
     578          for (i = 0; i < shnum; i++)
     579            {
     580              Elf_Internal_Shdr *shdr = elf_elfsections (abfd)[i];
     581              if (shdr->sh_type == SHT_GROUP && shdr->sh_size >= 8)
     582                {
     583                  unsigned char *src;
     584                  Elf_Internal_Group *dest;
     585
     586                  /* Add to list of sections.  */
     587                  elf_tdata (abfd)->group_sect_ptr[num_group] = shdr;
     588                  num_group += 1;
     589
     590                  /* Read the raw contents.  */
     591                  BFD_ASSERT (sizeof (*dest) >= 4);
     592                  amt = shdr->sh_size * sizeof (*dest) / 4;
     593                  shdr->contents = bfd_alloc (abfd, amt);
     594                  if (shdr->contents == NULL
     595                      || bfd_seek (abfd, shdr->sh_offset, SEEK_SET) != 0
     596                      || (bfd_bread (shdr->contents, shdr->sh_size, abfd)
     597                          != shdr->sh_size))
     598                    return FALSE;
     599
     600                  /* Translate raw contents, a flag word followed by an
     601                     array of elf section indices all in target byte order,
     602                     to the flag word followed by an array of elf section
     603                     pointers.  */
     604                  src = shdr->contents + shdr->sh_size;
     605                  dest = (Elf_Internal_Group *) (shdr->contents + amt);
     606                  while (1)
     607                    {
     608                      unsigned int idx;
     609
     610                      src -= 4;
     611                      --dest;
     612                      idx = H_GET_32 (abfd, src);
     613                      if (src == shdr->contents)
     614                        {
     615                          dest->flags = idx;
     616                          if (shdr->bfd_section != NULL && (idx & GRP_COMDAT))
     617                            shdr->bfd_section->flags
     618                              |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
     619                          break;
     620                        }
     621                      if (idx >= shnum)
     622                        {
     623                          ((*_bfd_error_handler)
     624                           (_("%s: invalid SHT_GROUP entry"),
     625                            bfd_archive_filename (abfd)));
     626                          idx = 0;
     627                        }
     628                      dest->shdr = elf_elfsections (abfd)[idx];
     629                    }
     630                }
     631            }
     632        }
     633    }
     634
     635  if (num_group != (unsigned) -1)
     636    {
     637      unsigned int i;
     638
     639      for (i = 0; i < num_group; i++)
     640        {
     641          Elf_Internal_Shdr *shdr = elf_tdata (abfd)->group_sect_ptr[i];
     642          Elf_Internal_Group *idx = (Elf_Internal_Group *) shdr->contents;
     643          unsigned int n_elt = shdr->sh_size / 4;
     644
     645          /* Look through this group's sections to see if current
     646             section is a member.  */
     647          while (--n_elt != 0)
     648            if ((++idx)->shdr == hdr)
     649              {
     650                asection *s = NULL;
     651
     652                /* We are a member of this group.  Go looking through
     653                   other members to see if any others are linked via
     654                   next_in_group.  */
     655                idx = (Elf_Internal_Group *) shdr->contents;
     656                n_elt = shdr->sh_size / 4;
     657                while (--n_elt != 0)
     658                  if ((s = (++idx)->shdr->bfd_section) != NULL
     659                      && elf_next_in_group (s) != NULL)
     660                    break;
     661                if (n_elt != 0)
     662                  {
     663                    /* Snarf the group name from other member, and
     664                       insert current section in circular list.  */
     665                    elf_group_name (newsect) = elf_group_name (s);
     666                    elf_next_in_group (newsect) = elf_next_in_group (s);
     667                    elf_next_in_group (s) = newsect;
     668                  }
     669                else
     670                  {
     671                    const char *gname;
     672
     673                    gname = group_signature (abfd, shdr);
     674                    if (gname == NULL)
     675                      return FALSE;
     676                    elf_group_name (newsect) = gname;
     677
     678                    /* Start a circular list with one element.  */
     679                    elf_next_in_group (newsect) = newsect;
     680                  }
     681
     682                /* If the group section has been created, point to the
     683                   new member.  */
     684                if (shdr->bfd_section != NULL)
     685                  elf_next_in_group (shdr->bfd_section) = newsect;
     686
     687                i = num_group - 1;
     688                break;
     689              }
     690        }
     691    }
     692
     693  if (elf_group_name (newsect) == NULL)
     694    {
     695      (*_bfd_error_handler) (_("%s: no group info for section %s"),
     696                             bfd_archive_filename (abfd), newsect->name);
     697    }
     698  return TRUE;
     699}
     700
     701bfd_boolean
     702bfd_elf_discard_group (abfd, group)
     703     bfd *abfd ATTRIBUTE_UNUSED;
     704     asection *group;
     705{
     706  asection *first = elf_next_in_group (group);
     707  asection *s = first;
     708
     709  while (s != NULL)
     710    {
     711      s->output_section = bfd_abs_section_ptr;
     712      s = elf_next_in_group (s);
     713      /* These lists are circular.  */
     714      if (s == first)
     715        break;
     716    }
     717  return TRUE;
     718}
     719
    342720/* Make a BFD section from an ELF section.  We store a pointer to the
    343721   BFD section in the bfd_section field of the header.  */
    344722
    345 boolean
     723bfd_boolean
    346724_bfd_elf_make_section_from_shdr (abfd, hdr, name)
    347725     bfd *abfd;
     
    357735      BFD_ASSERT (strcmp (name,
    358736                          bfd_get_section_name (abfd, hdr->bfd_section)) == 0);
    359       return true;
     737      return TRUE;
    360738    }
    361739
    362740  newsect = bfd_make_section_anyway (abfd, name);
    363741  if (newsect == NULL)
    364     return false;
     742    return FALSE;
    365743
    366744  newsect->filepos = hdr->sh_offset;
     
    369747      || ! bfd_set_section_size (abfd, newsect, hdr->sh_size)
    370748      || ! bfd_set_section_alignment (abfd, newsect,
    371                                       bfd_log2 (hdr->sh_addralign)))
    372     return false;
     749                                      bfd_log2 ((bfd_vma) hdr->sh_addralign)))
     750    return FALSE;
    373751
    374752  flags = SEC_NO_FLAGS;
    375753  if (hdr->sh_type != SHT_NOBITS)
    376754    flags |= SEC_HAS_CONTENTS;
     755  if (hdr->sh_type == SHT_GROUP)
     756    flags |= SEC_GROUP | SEC_EXCLUDE;
    377757  if ((hdr->sh_flags & SHF_ALLOC) != 0)
    378758    {
     
    387767  else if ((flags & SEC_LOAD) != 0)
    388768    flags |= SEC_DATA;
     769  if ((hdr->sh_flags & SHF_MERGE) != 0)
     770    {
     771      flags |= SEC_MERGE;
     772      newsect->entsize = hdr->sh_entsize;
     773      if ((hdr->sh_flags & SHF_STRINGS) != 0)
     774        flags |= SEC_STRINGS;
     775    }
     776  if (hdr->sh_flags & SHF_GROUP)
     777    if (!setup_group (abfd, hdr, newsect))
     778      return FALSE;
     779  if ((hdr->sh_flags & SHF_TLS) != 0)
     780    flags |= SEC_THREAD_LOCAL;
    389781
    390782  /* The debugging sections appear to be recognized only by name, not
     
    400792    int i;
    401793
    402     for (i = sizeof (debug_sec_names) / sizeof (debug_sec_names[0]); i--;)
     794    for (i = ARRAY_SIZE (debug_sec_names); i--;)
    403795      if (strncmp (name, debug_sec_names[i], strlen (debug_sec_names[i])) == 0)
    404796        break;
     
    414806     are permitted.  The GNU linker extension is to actually discard
    415807     all but one of the sections.  */
    416   if (strncmp (name, ".gnu.linkonce", sizeof ".gnu.linkonce" - 1) == 0)
     808  if (strncmp (name, ".gnu.linkonce", sizeof ".gnu.linkonce" - 1) == 0
     809      && elf_next_in_group (newsect) == NULL)
    417810    flags |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
    418811
     
    420813  if (bed->elf_backend_section_flags)
    421814    if (! bed->elf_backend_section_flags (&flags, hdr))
    422       return false;
     815      return FALSE;
    423816
    424817  if (! bfd_set_section_flags (abfd, newsect, flags))
    425     return false;
     818    return FALSE;
    426819
    427820  if ((flags & SEC_ALLOC) != 0)
     
    444837          for (i = 0; i < elf_elfheader (abfd)->e_phnum; i++, phdr++)
    445838            {
     839              /* This section is part of this segment if its file
     840                 offset plus size lies within the segment's memory
     841                 span and, if the section is loaded, the extent of the
     842                 loaded data lies within the extent of the segment.
     843
     844                 Note - we used to check the p_paddr field as well, and
     845                 refuse to set the LMA if it was 0.  This is wrong
     846                 though, as a perfectly valid initialised segment can
     847                 have a p_paddr of zero.  Some architectures, eg ARM,
     848                 place special significance on the address 0 and
     849                 executables need to be able to have a segment which
     850                 covers this address.  */
    446851              if (phdr->p_type == PT_LOAD
    447                   && phdr->p_vaddr != phdr->p_paddr
    448                   && phdr->p_vaddr <= hdr->sh_addr
    449                   && (phdr->p_vaddr + phdr->p_memsz
    450                       >= hdr->sh_addr + hdr->sh_size)
     852                  && (bfd_vma) hdr->sh_offset >= phdr->p_offset
     853                  && (hdr->sh_offset + hdr->sh_size
     854                      <= phdr->p_offset + phdr->p_memsz)
    451855                  && ((flags & SEC_LOAD) == 0
    452                       || (phdr->p_offset <= (bfd_vma) hdr->sh_offset
    453                           && (phdr->p_offset + phdr->p_filesz
    454                               >= hdr->sh_offset + hdr->sh_size))))
     856                      || (hdr->sh_offset + hdr->sh_size
     857                          <= phdr->p_offset + phdr->p_filesz)))
    455858                {
    456                   newsect->lma += phdr->p_paddr - phdr->p_vaddr;
    457                   break;
     859                  if ((flags & SEC_LOAD) == 0)
     860                    newsect->lma = (phdr->p_paddr
     861                                    + hdr->sh_addr - phdr->p_vaddr);
     862                  else
     863                    /* We used to use the same adjustment for SEC_LOAD
     864                       sections, but that doesn't work if the segment
     865                       is packed with code from multiple VMAs.
     866                       Instead we calculate the section LMA based on
     867                       the segment LMA.  It is assumed that the
     868                       segment will contain sections with contiguous
     869                       LMAs, even if the VMAs are not.  */
     870                    newsect->lma = (phdr->p_paddr
     871                                    + hdr->sh_offset - phdr->p_offset);
     872
     873                  /* With contiguous segments, we can't tell from file
     874                     offsets whether a section with zero size should
     875                     be placed at the end of one segment or the
     876                     beginning of the next.  Decide based on vaddr.  */
     877                  if (hdr->sh_addr >= phdr->p_vaddr
     878                      && (hdr->sh_addr + hdr->sh_size
     879                          <= phdr->p_vaddr + phdr->p_memsz))
     880                    break;
    458881                }
    459882            }
     
    464887  elf_section_data (newsect)->this_hdr = *hdr;
    465888
    466   return true;
     889  return TRUE;
    467890}
    468891
     
    495918  if (i_shdrp != NULL)
    496919    {
    497       shstrtab = bfd_elf_get_str_section
    498         (abfd, elf_elfheader (abfd)->e_shstrndx);
     920      shstrtab = bfd_elf_get_str_section (abfd,
     921                                          elf_elfheader (abfd)->e_shstrndx);
    499922      if (shstrtab != NULL)
    500923        {
    501           max = elf_elfheader (abfd)->e_shnum;
     924          max = elf_numsections (abfd);
    502925          for (i = 1; i < max; i++)
    503926            if (!strcmp (&shstrtab[i_shdrp[i]->sh_name], name))
     
    553976
    554977
     978/* Make sure sec_info_type is cleared if sec_info is cleared too.  */
     979
     980static void
     981merge_sections_remove_hook (abfd, sec)
     982     bfd *abfd ATTRIBUTE_UNUSED;
     983     asection *sec;
     984{
     985  BFD_ASSERT (sec->sec_info_type == ELF_INFO_TYPE_MERGE);
     986  sec->sec_info_type = ELF_INFO_TYPE_NONE;
     987}
     988
     989/* Finish SHF_MERGE section merging.  */
     990
     991bfd_boolean
     992_bfd_elf_merge_sections (abfd, info)
     993     bfd *abfd;
     994     struct bfd_link_info *info;
     995{
     996  if (!is_elf_hash_table (info))
     997    return FALSE;
     998  if (elf_hash_table (info)->merge_info)
     999    _bfd_merge_sections (abfd, elf_hash_table (info)->merge_info,
     1000                         merge_sections_remove_hook);
     1001  return TRUE;
     1002}
     1003
     1004void
     1005_bfd_elf_link_just_syms (sec, info)
     1006     asection *sec;
     1007     struct bfd_link_info *info;
     1008{
     1009  sec->output_section = bfd_abs_section_ptr;
     1010  sec->output_offset = sec->vma;
     1011  if (!is_elf_hash_table (info))
     1012    return;
     1013
     1014  sec->sec_info_type = ELF_INFO_TYPE_JUST_SYMS;
     1015}
     1016
     1017
     1018/* Copy the program header and other data from one object module to
     1019   another.  */
     1020
     1021bfd_boolean
     1022_bfd_elf_copy_private_bfd_data (ibfd, obfd)
     1023     bfd *ibfd;
     1024     bfd *obfd;
     1025{
     1026  if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
     1027      || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
     1028    return TRUE;
     1029
     1030  BFD_ASSERT (!elf_flags_init (obfd)
     1031              || (elf_elfheader (obfd)->e_flags
     1032                  == elf_elfheader (ibfd)->e_flags));
     1033
     1034  elf_gp (obfd) = elf_gp (ibfd);
     1035  elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;
     1036  elf_flags_init (obfd) = TRUE;
     1037  return TRUE;
     1038}
     1039
    5551040/* Print out the program headers.  */
    5561041
    557 boolean
     1042bfd_boolean
    5581043_bfd_elf_print_private_bfd_data (abfd, farg)
    5591044     bfd *abfd;
     
    5741059      for (i = 0; i < c; i++, p++)
    5751060        {
    576           const char *s;
     1061          const char *pt;
    5771062          char buf[20];
    5781063
    5791064          switch (p->p_type)
    5801065            {
    581             case PT_NULL: s = "NULL"; break;
    582             case PT_LOAD: s = "LOAD"; break;
    583             case PT_DYNAMIC: s = "DYNAMIC"; break;
    584             case PT_INTERP: s = "INTERP"; break;
    585             case PT_NOTE: s = "NOTE"; break;
    586             case PT_SHLIB: s = "SHLIB"; break;
    587             case PT_PHDR: s = "PHDR"; break;
    588             default: sprintf (buf, "0x%lx", p->p_type); s = buf; break;
     1066            case PT_NULL: pt = "NULL"; break;
     1067            case PT_LOAD: pt = "LOAD"; break;
     1068            case PT_DYNAMIC: pt = "DYNAMIC"; break;
     1069            case PT_INTERP: pt = "INTERP"; break;
     1070            case PT_NOTE: pt = "NOTE"; break;
     1071            case PT_SHLIB: pt = "SHLIB"; break;
     1072            case PT_PHDR: pt = "PHDR"; break;
     1073            case PT_TLS: pt = "TLS"; break;
     1074            case PT_GNU_EH_FRAME: pt = "EH_FRAME"; break;
     1075            default: sprintf (buf, "0x%lx", p->p_type); pt = buf; break;
    5891076            }
    590           fprintf (f, "%8s off    0x", s);
    591           fprintf_vma (f, p->p_offset);
     1077          fprintf (f, "%8s off    0x", pt);
     1078          bfd_fprintf_vma (abfd, f, p->p_offset);
    5921079          fprintf (f, " vaddr 0x");
    593           fprintf_vma (f, p->p_vaddr);
     1080          bfd_fprintf_vma (abfd, f, p->p_vaddr);
    5941081          fprintf (f, " paddr 0x");
    595           fprintf_vma (f, p->p_paddr);
     1082          bfd_fprintf_vma (abfd, f, p->p_paddr);
    5961083          fprintf (f, " align 2**%u\n", bfd_log2 (p->p_align));
    5971084          fprintf (f, "         filesz 0x");
    598           fprintf_vma (f, p->p_filesz);
     1085          bfd_fprintf_vma (abfd, f, p->p_filesz);
    5991086          fprintf (f, " memsz 0x");
    600           fprintf_vma (f, p->p_memsz);
     1087          bfd_fprintf_vma (abfd, f, p->p_memsz);
    6011088          fprintf (f, " flags %c%c%c",
    6021089                   (p->p_flags & PF_R) != 0 ? 'r' : '-',
    6031090                   (p->p_flags & PF_W) != 0 ? 'w' : '-',
    6041091                   (p->p_flags & PF_X) != 0 ? 'x' : '-');
    605           if ((p->p_flags &~ (PF_R | PF_W | PF_X)) != 0)
    606             fprintf (f, " %lx", p->p_flags &~ (PF_R | PF_W | PF_X));
     1092          if ((p->p_flags &~ (unsigned) (PF_R | PF_W | PF_X)) != 0)
     1093            fprintf (f, " %lx", p->p_flags &~ (unsigned) (PF_R | PF_W | PF_X));
    6071094          fprintf (f, "\n");
    6081095        }
     
    6131100    {
    6141101      int elfsec;
    615       unsigned long link;
     1102      unsigned long shlink;
    6161103      bfd_byte *extdyn, *extdynend;
    6171104      size_t extdynsize;
     
    6301117      if (elfsec == -1)
    6311118        goto error_return;
    632       link = elf_elfsections (abfd)[elfsec]->sh_link;
     1119      shlink = elf_elfsections (abfd)[elfsec]->sh_link;
    6331120
    6341121      extdynsize = get_elf_backend_data (abfd)->s->sizeof_dyn;
     
    6421129          const char *name;
    6431130          char ab[20];
    644           boolean stringp;
     1131          bfd_boolean stringp;
    6451132
    6461133          (*swap_dyn_in) (abfd, (PTR) extdyn, &dyn);
     
    6491136            break;
    6501137
    651           stringp = false;
     1138          stringp = FALSE;
    6521139          switch (dyn.d_tag)
    6531140            {
     
    6571144              break;
    6581145
    659             case DT_NEEDED: name = "NEEDED"; stringp = true; break;
     1146            case DT_NEEDED: name = "NEEDED"; stringp = TRUE; break;
    6601147            case DT_PLTRELSZ: name = "PLTRELSZ"; break;
    6611148            case DT_PLTGOT: name = "PLTGOT"; break;
     
    6701157            case DT_INIT: name = "INIT"; break;
    6711158            case DT_FINI: name = "FINI"; break;
    672             case DT_SONAME: name = "SONAME"; stringp = true; break;
    673             case DT_RPATH: name = "RPATH"; stringp = true; break;
     1159            case DT_SONAME: name = "SONAME"; stringp = TRUE; break;
     1160            case DT_RPATH: name = "RPATH"; stringp = TRUE; break;
    6741161            case DT_SYMBOLIC: name = "SYMBOLIC"; break;
    6751162            case DT_REL: name = "REL"; break;
     
    6851172            case DT_INIT_ARRAYSZ: name = "INIT_ARRAYSZ"; break;
    6861173            case DT_FINI_ARRAYSZ: name = "FINI_ARRAYSZ"; break;
    687             case DT_RUNPATH: name = "RUNPATH"; stringp = true; break;
     1174            case DT_RUNPATH: name = "RUNPATH"; stringp = TRUE; break;
    6881175            case DT_FLAGS: name = "FLAGS"; break;
    6891176            case DT_PREINIT_ARRAY: name = "PREINIT_ARRAY"; break;
     
    6971184            case DT_SYMINSZ: name = "SYMINSZ"; break;
    6981185            case DT_SYMINENT: name = "SYMINENT"; break;
    699             case DT_CONFIG: name = "CONFIG"; stringp = true; break;
    700             case DT_DEPAUDIT: name = "DEPAUDIT"; stringp = true; break;
    701             case DT_AUDIT: name = "AUDIT"; stringp = true; break;
     1186            case DT_CONFIG: name = "CONFIG"; stringp = TRUE; break;
     1187            case DT_DEPAUDIT: name = "DEPAUDIT"; stringp = TRUE; break;
     1188            case DT_AUDIT: name = "AUDIT"; stringp = TRUE; break;
    7021189            case DT_PLTPAD: name = "PLTPAD"; break;
    7031190            case DT_MOVETAB: name = "MOVETAB"; break;
     
    7111198            case DT_VERNEED: name = "VERNEED"; break;
    7121199            case DT_VERNEEDNUM: name = "VERNEEDNUM"; break;
    713             case DT_AUXILIARY: name = "AUXILIARY"; stringp = true; break;
     1200            case DT_AUXILIARY: name = "AUXILIARY"; stringp = TRUE; break;
    7141201            case DT_USED: name = "USED"; break;
    715             case DT_FILTER: name = "FILTER"; stringp = true; break;
     1202            case DT_FILTER: name = "FILTER"; stringp = TRUE; break;
    7161203            }
    7171204
     
    7221209            {
    7231210              const char *string;
    724 
    725               string = bfd_elf_string_from_elf_section (abfd, link,
    726                                                         dyn.d_un.d_val);
     1211              unsigned int tagv = dyn.d_un.d_val;
     1212
     1213              string = bfd_elf_string_from_elf_section (abfd, shlink, tagv);
    7271214              if (string == NULL)
    7281215                goto error_return;
     
    7401227    {
    7411228      if (! _bfd_elf_slurp_version_tables (abfd))
    742         return false;
     1229        return FALSE;
    7431230    }
    7441231
     
    7821269    }
    7831270
    784   return true;
     1271  return TRUE;
    7851272
    7861273 error_return:
    7871274  if (dynbuf != NULL)
    7881275    free (dynbuf);
    789   return false;
     1276  return FALSE;
    7901277}
    7911278
     
    8071294    case bfd_print_symbol_more:
    8081295      fprintf (file, "elf ");
    809       fprintf_vma (file, symbol->value);
     1296      bfd_fprintf_vma (abfd, file, symbol->value);
    8101297      fprintf (file, " %lx", (long) symbol->flags);
    8111298      break;
     
    8161303        struct elf_backend_data *bed;
    8171304        unsigned char st_other;
     1305        bfd_vma val;
    8181306
    8191307        section_name = symbol->section ? symbol->section->name : "(*none*)";
     
    8261314          {
    8271315            name = symbol->name;
    828             bfd_print_symbol_vandf ((PTR) file, symbol);
     1316            bfd_print_symbol_vandf (abfd, (PTR) file, symbol);
    8291317          }
    8301318
     
    8341322           For other symbols, we have no specified alignment, and
    8351323           we've printed the address; now print the size.  */
    836         fprintf_vma (file,
    837                      (bfd_is_com_section (symbol->section)
    838                       ? ((elf_symbol_type *) symbol)->internal_elf_sym.st_value
    839                       : ((elf_symbol_type *) symbol)->internal_elf_sym.st_size));
     1324        if (bfd_is_com_section (symbol->section))
     1325          val = ((elf_symbol_type *) symbol)->internal_elf_sym.st_value;
     1326        else
     1327          val = ((elf_symbol_type *) symbol)->internal_elf_sym.st_size;
     1328        bfd_fprintf_vma (abfd, file, val);
    8401329
    8411330        /* If we have version information, print it.  */
     
    9201409     const char *string;
    9211410{
    922   struct elf_link_hash_entry *ret = (struct elf_link_hash_entry *) entry;
    923 
    9241411  /* Allocate the structure if it has not already been allocated by a
    9251412     subclass.  */
    926   if (ret == (struct elf_link_hash_entry *) NULL)
    927     ret = ((struct elf_link_hash_entry *)
    928            bfd_hash_allocate (table, sizeof (struct elf_link_hash_entry)));
    929   if (ret == (struct elf_link_hash_entry *) NULL)
    930     return (struct bfd_hash_entry *) ret;
     1413  if (entry == NULL)
     1414    {
     1415      entry = bfd_hash_allocate (table, sizeof (struct elf_link_hash_entry));
     1416      if (entry == NULL)
     1417        return entry;
     1418    }
    9311419
    9321420  /* Call the allocation method of the superclass.  */
    933   ret = ((struct elf_link_hash_entry *)
    934          _bfd_link_hash_newfunc ((struct bfd_hash_entry *) ret,
    935                                  table, string));
    936   if (ret != (struct elf_link_hash_entry *) NULL)
    937     {
     1421  entry = _bfd_link_hash_newfunc (entry, table, string);
     1422  if (entry != NULL)
     1423    {
     1424      struct elf_link_hash_entry *ret = (struct elf_link_hash_entry *) entry;
     1425      struct elf_link_hash_table *htab = (struct elf_link_hash_table *) table;
     1426
    9381427      /* Set local fields.  */
    9391428      ret->indx = -1;
    940       ret->size = 0;
    9411429      ret->dynindx = -1;
    9421430      ret->dynstr_index = 0;
     1431      ret->elf_hash_value = 0;
    9431432      ret->weakdef = NULL;
    944       ret->got.offset = (bfd_vma) -1;
    945       ret->plt.offset = (bfd_vma) -1;
    946       ret->linker_section_pointer = (elf_linker_section_pointers_t *)0;
     1433      ret->linker_section_pointer = NULL;
    9471434      ret->verinfo.verdef = NULL;
     1435      ret->vtable_entries_size = 0;
    9481436      ret->vtable_entries_used = NULL;
    949       ret->vtable_entries_size = 0;
    9501437      ret->vtable_parent = NULL;
     1438      ret->got = htab->init_refcount;
     1439      ret->plt = htab->init_refcount;
     1440      ret->size = 0;
    9511441      ret->type = STT_NOTYPE;
    9521442      ret->other = 0;
     
    9581448    }
    9591449
    960   return (struct bfd_hash_entry *) ret;
     1450  return entry;
    9611451}
    9621452
    9631453/* Copy data from an indirect symbol to its direct symbol, hiding the
    964    old indirect symbol.  */
     1454   old indirect symbol.  Also used for copying flags to a weakdef.  */
    9651455
    9661456void
    967 _bfd_elf_link_hash_copy_indirect (dir, ind)
     1457_bfd_elf_link_hash_copy_indirect (bed, dir, ind)
     1458     struct elf_backend_data *bed;
    9681459     struct elf_link_hash_entry *dir, *ind;
    9691460{
     1461  bfd_signed_vma tmp;
     1462  bfd_signed_vma lowest_valid = bed->can_refcount;
     1463
    9701464  /* Copy down any references that we may have already seen to the
    9711465     symbol which just became indirect.  */
     
    9781472        | ELF_LINK_NON_GOT_REF));
    9791473
    980   /* Copy over the global and procedure linkage table offset entries.
     1474  if (ind->root.type != bfd_link_hash_indirect)
     1475    return;
     1476
     1477  /* Copy over the global and procedure linkage table refcount entries.
    9811478     These may have been already set up by a check_relocs routine.  */
    982   if (dir->got.offset == (bfd_vma) -1)
    983     {
    984       dir->got.offset = ind->got.offset;
    985       ind->got.offset = (bfd_vma) -1;
    986     }
    987   BFD_ASSERT (ind->got.offset == (bfd_vma) -1);
    988 
    989   if (dir->plt.offset == (bfd_vma) -1)
    990     {
    991       dir->plt.offset = ind->plt.offset;
    992       ind->plt.offset = (bfd_vma) -1;
    993     }
    994   BFD_ASSERT (ind->plt.offset == (bfd_vma) -1);
     1479  tmp = dir->got.refcount;
     1480  if (tmp < lowest_valid)
     1481    {
     1482      dir->got.refcount = ind->got.refcount;
     1483      ind->got.refcount = tmp;
     1484    }
     1485  else
     1486    BFD_ASSERT (ind->got.refcount < lowest_valid);
     1487
     1488  tmp = dir->plt.refcount;
     1489  if (tmp < lowest_valid)
     1490    {
     1491      dir->plt.refcount = ind->plt.refcount;
     1492      ind->plt.refcount = tmp;
     1493    }
     1494  else
     1495    BFD_ASSERT (ind->plt.refcount < lowest_valid);
    9951496
    9961497  if (dir->dynindx == -1)
     
    10011502      ind->dynstr_index = 0;
    10021503    }
    1003   BFD_ASSERT (ind->dynindx == -1);
     1504  else
     1505    BFD_ASSERT (ind->dynindx == -1);
    10041506}
    10051507
    10061508void
    1007 _bfd_elf_link_hash_hide_symbol (info, h)
    1008      struct bfd_link_info *info ATTRIBUTE_UNUSED;
     1509_bfd_elf_link_hash_hide_symbol (info, h, force_local)
     1510     struct bfd_link_info *info;
    10091511     struct elf_link_hash_entry *h;
    1010 {
     1512     bfd_boolean force_local;
     1513{
     1514  h->plt = elf_hash_table (info)->init_offset;
    10111515  h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
    1012   h->plt.offset = (bfd_vma) -1;
    1013   if ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)
    1014     h->dynindx = -1;
     1516  if (force_local)
     1517    {
     1518      h->elf_link_hash_flags |= ELF_LINK_FORCED_LOCAL;
     1519      if (h->dynindx != -1)
     1520        {
     1521          h->dynindx = -1;
     1522          _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
     1523                                  h->dynstr_index);
     1524        }
     1525    }
    10151526}
    10161527
    10171528/* Initialize an ELF linker hash table.  */
    10181529
    1019 boolean
     1530bfd_boolean
    10201531_bfd_elf_link_hash_table_init (table, abfd, newfunc)
    10211532     struct elf_link_hash_table *table;
    10221533     bfd *abfd;
    1023      struct bfd_hash_entry *(*newfunc) PARAMS ((struct bfd_hash_entry *,
    1024                                                 struct bfd_hash_table *,
    1025                                                 const char *));
    1026 {
    1027   table->dynamic_sections_created = false;
     1534     struct bfd_hash_entry *(*newfunc)
     1535       PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *,
     1536                const char *));
     1537{
     1538  bfd_boolean ret;
     1539
     1540  table->dynamic_sections_created = FALSE;
    10281541  table->dynobj = NULL;
     1542  /* Make sure can_refcount is extended to the width and signedness of
     1543     init_refcount before we subtract one from it.  */
     1544  table->init_refcount.refcount = get_elf_backend_data (abfd)->can_refcount;
     1545  table->init_refcount.refcount -= 1;
     1546  table->init_offset.offset = -(bfd_vma) 1;
    10291547  /* The first dynamic symbol is a dummy.  */
    10301548  table->dynsymcount = 1;
     
    10321550  table->bucketcount = 0;
    10331551  table->needed = NULL;
    1034   table->runpath = NULL;
    10351552  table->hgot = NULL;
    10361553  table->stab_info = NULL;
     1554  table->merge_info = NULL;
     1555  memset (&table->eh_info, 0, sizeof (table->eh_info));
    10371556  table->dynlocal = NULL;
    1038   return _bfd_link_hash_table_init (&table->root, abfd, newfunc);
     1557  table->runpath = NULL;
     1558  table->tls_segment = NULL;
     1559  table->loaded = NULL;
     1560
     1561  ret = _bfd_link_hash_table_init (&table->root, abfd, newfunc);
     1562  table->root.type = bfd_link_elf_hash_table;
     1563
     1564  return ret;
    10391565}
    10401566
     
    10461572{
    10471573  struct elf_link_hash_table *ret;
    1048 
    1049   ret = ((struct elf_link_hash_table *)
    1050          bfd_alloc (abfd, sizeof (struct elf_link_hash_table)));
     1574  bfd_size_type amt = sizeof (struct elf_link_hash_table);
     1575
     1576  ret = (struct elf_link_hash_table *) bfd_malloc (amt);
    10511577  if (ret == (struct elf_link_hash_table *) NULL)
    10521578    return NULL;
     
    10541580  if (! _bfd_elf_link_hash_table_init (ret, abfd, _bfd_elf_link_hash_newfunc))
    10551581    {
    1056       bfd_release (abfd, ret);
     1582      free (ret);
    10571583      return NULL;
    10581584    }
     
    10941620     struct bfd_link_info *info;
    10951621{
    1096   if (info->hash->creator->flavour != bfd_target_elf_flavour)
     1622  if (! is_elf_hash_table (info))
    10971623    return NULL;
    10981624  return elf_hash_table (info)->needed;
     
    11071633     struct bfd_link_info *info;
    11081634{
    1109   if (info->hash->creator->flavour != bfd_target_elf_flavour)
     1635  if (! is_elf_hash_table (info))
    11101636    return NULL;
    11111637  return elf_hash_table (info)->runpath;
     
    11291655   the ELF linker emulation code.  */
    11301656
    1131 boolean
     1657bfd_boolean
    11321658bfd_elf_get_bfd_needed_list (abfd, pneeded)
    11331659     bfd *abfd;
     
    11371663  bfd_byte *dynbuf = NULL;
    11381664  int elfsec;
    1139   unsigned long link;
     1665  unsigned long shlink;
    11401666  bfd_byte *extdyn, *extdynend;
    11411667  size_t extdynsize;
     
    11461672  if (bfd_get_flavour (abfd) != bfd_target_elf_flavour
    11471673      || bfd_get_format (abfd) != bfd_object)
    1148     return true;
     1674    return TRUE;
    11491675
    11501676  s = bfd_get_section_by_name (abfd, ".dynamic");
    11511677  if (s == NULL || s->_raw_size == 0)
    1152     return true;
     1678    return TRUE;
    11531679
    11541680  dynbuf = (bfd_byte *) bfd_malloc (s->_raw_size);
     
    11641690    goto error_return;
    11651691
    1166   link = elf_elfsections (abfd)[elfsec]->sh_link;
     1692  shlink = elf_elfsections (abfd)[elfsec]->sh_link;
    11671693
    11681694  extdynsize = get_elf_backend_data (abfd)->s->sizeof_dyn;
     
    11841710          const char *string;
    11851711          struct bfd_link_needed_list *l;
    1186 
    1187           string = bfd_elf_string_from_elf_section (abfd, link,
    1188                                                     dyn.d_un.d_val);
     1712          unsigned int tagv = dyn.d_un.d_val;
     1713          bfd_size_type amt;
     1714
     1715          string = bfd_elf_string_from_elf_section (abfd, shlink, tagv);
    11891716          if (string == NULL)
    11901717            goto error_return;
    11911718
    1192           l = (struct bfd_link_needed_list *) bfd_alloc (abfd, sizeof *l);
     1719          amt = sizeof *l;
     1720          l = (struct bfd_link_needed_list *) bfd_alloc (abfd, amt);
    11931721          if (l == NULL)
    11941722            goto error_return;
     
    12031731  free (dynbuf);
    12041732
    1205   return true;
     1733  return TRUE;
    12061734
    12071735 error_return:
    12081736  if (dynbuf != NULL)
    12091737    free (dynbuf);
    1210   return false;
     1738  return FALSE;
    12111739}
    12121740
     
    12241752      bfd_size_type loc;
    12251753
    1226       loc = _bfd_stringtab_add (ret, "", true, false);
     1754      loc = _bfd_stringtab_add (ret, "", TRUE, FALSE);
    12271755      BFD_ASSERT (loc == 0 || loc == (bfd_size_type) -1);
    12281756      if (loc == (bfd_size_type) -1)
     
    12401768/* Create a new bfd section from an ELF section header.  */
    12411769
    1242 boolean
     1770bfd_boolean
    12431771bfd_section_from_shdr (abfd, shindex)
    12441772     bfd *abfd;
     
    12481776  Elf_Internal_Ehdr *ehdr = elf_elfheader (abfd);
    12491777  struct elf_backend_data *bed = get_elf_backend_data (abfd);
    1250   char *name;
     1778  const char *name;
    12511779
    12521780  name = elf_string_from_elf_strtab (abfd, hdr->sh_name);
     
    12561784    case SHT_NULL:
    12571785      /* Inactive section. Throw it away.  */
    1258       return true;
     1786      return TRUE;
    12591787
    12601788    case SHT_PROGBITS:  /* Normal section with contents.  */
    1261     case SHT_DYNAMIC:   /* Dynamic linking information.  */
    12621789    case SHT_NOBITS:    /* .bss section.  */
    12631790    case SHT_HASH:      /* .hash section.  */
    12641791    case SHT_NOTE:      /* .note section.  */
     1792    case SHT_INIT_ARRAY:        /* .init_array section.  */
     1793    case SHT_FINI_ARRAY:        /* .fini_array section.  */
     1794    case SHT_PREINIT_ARRAY:     /* .preinit_array section.  */
    12651795      return _bfd_elf_make_section_from_shdr (abfd, hdr, name);
     1796
     1797    case SHT_DYNAMIC:   /* Dynamic linking information.  */
     1798      if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
     1799        return FALSE;
     1800      if (elf_elfsections (abfd)[hdr->sh_link]->sh_type != SHT_STRTAB)
     1801        {
     1802          Elf_Internal_Shdr *dynsymhdr;
     1803
     1804          /* The shared libraries distributed with hpux11 have a bogus
     1805             sh_link field for the ".dynamic" section.  Find the
     1806             string table for the ".dynsym" section instead.  */
     1807          if (elf_dynsymtab (abfd) != 0)
     1808            {
     1809              dynsymhdr = elf_elfsections (abfd)[elf_dynsymtab (abfd)];
     1810              hdr->sh_link = dynsymhdr->sh_link;
     1811            }
     1812          else
     1813            {
     1814              unsigned int i, num_sec;
     1815
     1816              num_sec = elf_numsections (abfd);
     1817              for (i = 1; i < num_sec; i++)
     1818                {
     1819                  dynsymhdr = elf_elfsections (abfd)[i];
     1820                  if (dynsymhdr->sh_type == SHT_DYNSYM)
     1821                    {
     1822                      hdr->sh_link = dynsymhdr->sh_link;
     1823                      break;
     1824                    }
     1825                }
     1826            }
     1827        }
     1828      break;
    12661829
    12671830    case SHT_SYMTAB:            /* A symbol table */
    12681831      if (elf_onesymtab (abfd) == shindex)
    1269         return true;
     1832        return TRUE;
    12701833
    12711834      BFD_ASSERT (hdr->sh_entsize == bed->s->sizeof_sym);
     
    12851848          && (abfd->flags & DYNAMIC) != 0
    12861849          && ! _bfd_elf_make_section_from_shdr (abfd, hdr, name))
    1287         return false;
    1288 
    1289       return true;
     1850        return FALSE;
     1851
     1852      return TRUE;
    12901853
    12911854    case SHT_DYNSYM:            /* A dynamic symbol table */
    12921855      if (elf_dynsymtab (abfd) == shindex)
    1293         return true;
     1856        return TRUE;
    12941857
    12951858      BFD_ASSERT (hdr->sh_entsize == bed->s->sizeof_sym);
     
    13041867      return _bfd_elf_make_section_from_shdr (abfd, hdr, name);
    13051868
     1869    case SHT_SYMTAB_SHNDX:      /* Symbol section indices when >64k sections */
     1870      if (elf_symtab_shndx (abfd) == shindex)
     1871        return TRUE;
     1872
     1873      /* Get the associated symbol table.  */
     1874      if (! bfd_section_from_shdr (abfd, hdr->sh_link)
     1875          || hdr->sh_link != elf_onesymtab (abfd))
     1876        return FALSE;
     1877
     1878      elf_symtab_shndx (abfd) = shindex;
     1879      elf_tdata (abfd)->symtab_shndx_hdr = *hdr;
     1880      elf_elfsections (abfd)[shindex] = &elf_tdata (abfd)->symtab_shndx_hdr;
     1881      return TRUE;
     1882
    13061883    case SHT_STRTAB:            /* A string table */
    13071884      if (hdr->bfd_section != NULL)
    1308         return true;
     1885        return TRUE;
    13091886      if (ehdr->e_shstrndx == shindex)
    13101887        {
    13111888          elf_tdata (abfd)->shstrtab_hdr = *hdr;
    13121889          elf_elfsections (abfd)[shindex] = &elf_tdata (abfd)->shstrtab_hdr;
    1313           return true;
     1890          return TRUE;
    13141891        }
    13151892      {
    1316         unsigned int i;
    1317 
    1318         for (i = 1; i < ehdr->e_shnum; i++)
     1893        unsigned int i, num_sec;
     1894
     1895        num_sec = elf_numsections (abfd);
     1896        for (i = 1; i < num_sec; i++)
    13191897          {
    13201898            Elf_Internal_Shdr *hdr2 = elf_elfsections (abfd)[i];
     
    13221900              {
    13231901                if (! bfd_section_from_shdr (abfd, i))
    1324                   return false;
     1902                  return FALSE;
    13251903                if (elf_onesymtab (abfd) == i)
    13261904                  {
     
    13281906                    elf_elfsections (abfd)[shindex] =
    13291907                      &elf_tdata (abfd)->strtab_hdr;
    1330                     return true;
     1908                    return TRUE;
    13311909                  }
    13321910                if (elf_dynsymtab (abfd) == i)
     
    13621940        asection *target_sect;
    13631941        Elf_Internal_Shdr *hdr2;
     1942        unsigned int num_sec = elf_numsections (abfd);
    13641943
    13651944        /* Check for a bogus link to avoid crashing.  */
    1366         if (hdr->sh_link >= ehdr->e_shnum)
     1945        if ((hdr->sh_link >= SHN_LORESERVE && hdr->sh_link <= SHN_HIRESERVE)
     1946            || hdr->sh_link >= num_sec)
    13671947          {
    13681948            ((*_bfd_error_handler)
    13691949             (_("%s: invalid link %lu for reloc section %s (index %u)"),
    1370               bfd_get_filename (abfd), hdr->sh_link, name, shindex));
     1950              bfd_archive_filename (abfd), hdr->sh_link, name, shindex));
    13711951            return _bfd_elf_make_section_from_shdr (abfd, hdr, name);
    13721952          }
     
    13821962            && elf_elfsections (abfd)[hdr->sh_link]->sh_type != SHT_DYNSYM)
    13831963          {
    1384             int scan;
     1964            unsigned int scan;
    13851965            int found;
    13861966
    13871967            found = 0;
    1388             for (scan = 1; scan < ehdr->e_shnum; scan++)
     1968            for (scan = 1; scan < num_sec; scan++)
    13891969              {
    13901970                if (elf_elfsections (abfd)[scan]->sh_type == SHT_SYMTAB
     
    14061986        if (elf_elfsections (abfd)[hdr->sh_link]->sh_type == SHT_SYMTAB
    14071987            && ! bfd_section_from_shdr (abfd, hdr->sh_link))
    1408           return false;
     1988          return FALSE;
    14091989
    14101990        /* If this reloc section does not use the main symbol table we
     
    14181998
    14191999        if (! bfd_section_from_shdr (abfd, hdr->sh_info))
    1420           return false;
     2000          return FALSE;
    14212001        target_sect = bfd_section_from_elf_index (abfd, hdr->sh_info);
    14222002        if (target_sect == NULL)
    1423           return false;
     2003          return FALSE;
    14242004
    14252005        if ((target_sect->flags & SEC_RELOC) == 0
     
    14282008        else
    14292009          {
     2010            bfd_size_type amt;
    14302011            BFD_ASSERT (elf_section_data (target_sect)->rel_hdr2 == NULL);
    1431             hdr2 = (Elf_Internal_Shdr *) bfd_alloc (abfd, sizeof (*hdr2));
     2012            amt = sizeof (*hdr2);
     2013            hdr2 = (Elf_Internal_Shdr *) bfd_alloc (abfd, amt);
    14322014            elf_section_data (target_sect)->rel_hdr2 = hdr2;
    14332015          }
     
    14412023           its relocations are of the REL or RELA variety.  */
    14422024        if (hdr->sh_size != 0)
    1443           elf_section_data (target_sect)->use_rela_p
    1444             = (hdr->sh_type == SHT_RELA);
     2025          target_sect->use_rela_p = hdr->sh_type == SHT_RELA;
    14452026        abfd->flags |= HAS_RELOC;
    1446         return true;
     2027        return TRUE;
    14472028      }
    14482029      break;
     
    14672048
    14682049    case SHT_SHLIB:
    1469       return true;
     2050      return TRUE;
     2051
     2052    case SHT_GROUP:
     2053      /* We need a BFD section for objcopy and relocatable linking,
     2054         and it's handy to have the signature available as the section
     2055         name.  */
     2056      name = group_signature (abfd, hdr);
     2057      if (name == NULL)
     2058        return FALSE;
     2059      if (!_bfd_elf_make_section_from_shdr (abfd, hdr, name))
     2060        return FALSE;
     2061      if (hdr->contents != NULL)
     2062        {
     2063          Elf_Internal_Group *idx = (Elf_Internal_Group *) hdr->contents;
     2064          unsigned int n_elt = hdr->sh_size / 4;
     2065          asection *s;
     2066
     2067          if (idx->flags & GRP_COMDAT)
     2068            hdr->bfd_section->flags
     2069              |= SEC_LINK_ONCE | SEC_LINK_DUPLICATES_DISCARD;
     2070
     2071          while (--n_elt != 0)
     2072            if ((s = (++idx)->shdr->bfd_section) != NULL
     2073                && elf_next_in_group (s) != NULL)
     2074              {
     2075                elf_next_in_group (hdr->bfd_section) = s;
     2076                break;
     2077              }
     2078        }
     2079      break;
    14702080
    14712081    default:
     
    14782088    }
    14792089
    1480   return true;
     2090  return TRUE;
     2091}
     2092
     2093/* Return the section for the local symbol specified by ABFD, R_SYMNDX.
     2094   Return SEC for sections that have no elf section, and NULL on error.  */
     2095
     2096asection *
     2097bfd_section_from_r_symndx (abfd, cache, sec, r_symndx)
     2098     bfd *abfd;
     2099     struct sym_sec_cache *cache;
     2100     asection *sec;
     2101     unsigned long r_symndx;
     2102{
     2103  Elf_Internal_Shdr *symtab_hdr;
     2104  unsigned char esym[sizeof (Elf64_External_Sym)];
     2105  Elf_External_Sym_Shndx eshndx;
     2106  Elf_Internal_Sym isym;
     2107  unsigned int ent = r_symndx % LOCAL_SYM_CACHE_SIZE;
     2108
     2109  if (cache->abfd == abfd && cache->indx[ent] == r_symndx)
     2110    return cache->sec[ent];
     2111
     2112  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
     2113  if (bfd_elf_get_elf_syms (abfd, symtab_hdr, 1, r_symndx,
     2114                            &isym, esym, &eshndx) == NULL)
     2115    return NULL;
     2116
     2117  if (cache->abfd != abfd)
     2118    {
     2119      memset (cache->indx, -1, sizeof (cache->indx));
     2120      cache->abfd = abfd;
     2121    }
     2122  cache->indx[ent] = r_symndx;
     2123  cache->sec[ent] = sec;
     2124  if (isym.st_shndx < SHN_LORESERVE || isym.st_shndx > SHN_HIRESERVE)
     2125    {
     2126      asection *s;
     2127      s = bfd_section_from_elf_index (abfd, isym.st_shndx);
     2128      if (s != NULL)
     2129        cache->sec[ent] = s;
     2130    }
     2131  return cache->sec[ent];
    14812132}
    14822133
     
    14892140     unsigned int index;
    14902141{
    1491   BFD_ASSERT (index > 0 && index < SHN_LORESERVE);
    1492   if (index >= elf_elfheader (abfd)->e_shnum)
     2142  if (index >= elf_numsections (abfd))
    14932143    return NULL;
    14942144  return elf_elfsections (abfd)[index]->bfd_section;
    14952145}
    14962146
    1497 boolean
     2147bfd_boolean
    14982148_bfd_elf_new_section_hook (abfd, sec)
    14992149     bfd *abfd;
     
    15022152  struct bfd_elf_section_data *sdata;
    15032153
    1504   sdata = (struct bfd_elf_section_data *) bfd_zalloc (abfd, sizeof (*sdata));
    1505   if (!sdata)
    1506     return false;
    1507   sec->used_by_bfd = (PTR) sdata;
     2154  sdata = (struct bfd_elf_section_data *) sec->used_by_bfd;
     2155  if (sdata == NULL)
     2156    {
     2157      bfd_size_type amt = sizeof (*sdata);
     2158      sdata = (struct bfd_elf_section_data *) bfd_zalloc (abfd, amt);
     2159      if (sdata == NULL)
     2160        return FALSE;
     2161      sec->used_by_bfd = (PTR) sdata;
     2162    }
    15082163
    15092164  /* Indicate whether or not this section should use RELA relocations.  */
    1510   sdata->use_rela_p
    1511     = get_elf_backend_data (abfd)->default_use_rela_p;
    1512 
    1513   return true;
     2165  sec->use_rela_p = get_elf_backend_data (abfd)->default_use_rela_p;
     2166
     2167  return TRUE;
    15142168}
    15152169
     
    15362190 */
    15372191
    1538 boolean
     2192bfd_boolean
    15392193_bfd_elf_make_section_from_phdr (abfd, hdr, index, typename)
    15402194     bfd *abfd;
     
    15462200  char *name;
    15472201  char namebuf[64];
     2202  size_t len;
    15482203  int split;
    15492204
     
    15522207            && (hdr->p_memsz > hdr->p_filesz));
    15532208  sprintf (namebuf, "%s%d%s", typename, index, split ? "a" : "");
    1554   name = bfd_alloc (abfd, strlen (namebuf) + 1);
     2209  len = strlen (namebuf) + 1;
     2210  name = bfd_alloc (abfd, (bfd_size_type) len);
    15552211  if (!name)
    1556     return false;
    1557   strcpy (name, namebuf);
     2212    return FALSE;
     2213  memcpy (name, namebuf, len);
    15582214  newsect = bfd_make_section (abfd, name);
    15592215  if (newsect == NULL)
    1560     return false;
     2216    return FALSE;
    15612217  newsect->vma = hdr->p_vaddr;
    15622218  newsect->lma = hdr->p_paddr;
     
    15832239    {
    15842240      sprintf (namebuf, "%s%db", typename, index);
    1585       name = bfd_alloc (abfd, strlen (namebuf) + 1);
     2241      len = strlen (namebuf) + 1;
     2242      name = bfd_alloc (abfd, (bfd_size_type) len);
    15862243      if (!name)
    1587         return false;
    1588       strcpy (name, namebuf);
     2244        return FALSE;
     2245      memcpy (name, namebuf, len);
    15892246      newsect = bfd_make_section (abfd, name);
    15902247      if (newsect == NULL)
    1591         return false;
     2248        return FALSE;
    15922249      newsect->vma = hdr->p_vaddr + hdr->p_filesz;
    15932250      newsect->lma = hdr->p_paddr + hdr->p_filesz;
     
    16032260    }
    16042261
    1605   return true;
    1606 }
    1607 
    1608 boolean
     2262  return TRUE;
     2263}
     2264
     2265bfd_boolean
    16092266bfd_section_from_phdr (abfd, hdr, index)
    16102267     bfd *abfd;
     
    16302287    case PT_NOTE:
    16312288      if (! _bfd_elf_make_section_from_phdr (abfd, hdr, index, "note"))
    1632         return false;
    1633       if (! elfcore_read_notes (abfd, hdr->p_offset, hdr->p_filesz))
    1634         return false;
    1635       return true;
     2289        return FALSE;
     2290      if (! elfcore_read_notes (abfd, (file_ptr) hdr->p_offset, hdr->p_filesz))
     2291        return FALSE;
     2292      return TRUE;
    16362293
    16372294    case PT_SHLIB:
     
    16402297    case PT_PHDR:
    16412298      return _bfd_elf_make_section_from_phdr (abfd, hdr, index, "phdr");
     2299
     2300    case PT_GNU_EH_FRAME:
     2301      return _bfd_elf_make_section_from_phdr (abfd, hdr, index,
     2302                                              "eh_frame_hdr");
    16422303
    16432304    default:
     
    16532314
    16542315/* Initialize REL_HDR, the section-header for new section, containing
    1655    relocations against ASECT.  If USE_RELA_P is true, we use RELA
     2316   relocations against ASECT.  If USE_RELA_P is TRUE, we use RELA
    16562317   relocations; otherwise, we use REL relocations.  */
    16572318
    1658 boolean
     2319bfd_boolean
    16592320_bfd_elf_init_reloc_shdr (abfd, rel_hdr, asect, use_rela_p)
    16602321     bfd *abfd;
    16612322     Elf_Internal_Shdr *rel_hdr;
    16622323     asection *asect;
    1663      boolean use_rela_p;
     2324     bfd_boolean use_rela_p;
    16642325{
    16652326  char *name;
    1666   struct elf_backend_data *bed;
    1667 
    1668   bed = get_elf_backend_data (abfd);
    1669   name = bfd_alloc (abfd, sizeof ".rela" + strlen (asect->name));
     2327  struct elf_backend_data *bed = get_elf_backend_data (abfd);
     2328  bfd_size_type amt = sizeof ".rela" + strlen (asect->name);
     2329
     2330  name = bfd_alloc (abfd, amt);
    16702331  if (name == NULL)
    1671     return false;
     2332    return FALSE;
    16722333  sprintf (name, "%s%s", use_rela_p ? ".rela" : ".rel", asect->name);
    16732334  rel_hdr->sh_name =
    1674     (unsigned int) _bfd_stringtab_add (elf_shstrtab (abfd), name,
    1675                                        true, false);
     2335    (unsigned int) _bfd_elf_strtab_add (elf_shstrtab (abfd), name,
     2336                                        FALSE);
    16762337  if (rel_hdr->sh_name == (unsigned int) -1)
    1677     return false;
     2338    return FALSE;
    16782339  rel_hdr->sh_type = use_rela_p ? SHT_RELA : SHT_REL;
    16792340  rel_hdr->sh_entsize = (use_rela_p
     
    16862347  rel_hdr->sh_offset = 0;
    16872348
    1688   return true;
     2349  return TRUE;
    16892350}
    16902351
     
    16982359{
    16992360  struct elf_backend_data *bed = get_elf_backend_data (abfd);
    1700   boolean *failedptr = (boolean *) failedptrarg;
     2361  bfd_boolean *failedptr = (bfd_boolean *) failedptrarg;
    17012362  Elf_Internal_Shdr *this_hdr;
    17022363
     
    17102371  this_hdr = &elf_section_data (asect)->this_hdr;
    17112372
    1712   this_hdr->sh_name = (unsigned long) _bfd_stringtab_add (elf_shstrtab (abfd),
    1713                                                           asect->name,
    1714                                                           true, false);
    1715   if (this_hdr->sh_name == (unsigned long) -1)
    1716     {
    1717       *failedptr = true;
     2373  this_hdr->sh_name = (unsigned int) _bfd_elf_strtab_add (elf_shstrtab (abfd),
     2374                                                          asect->name, FALSE);
     2375  if (this_hdr->sh_name == (unsigned int) -1)
     2376    {
     2377      *failedptr = TRUE;
    17182378      return;
    17192379    }
     
    17672427      this_hdr->sh_entsize = bed->s->sizeof_rel;
    17682428    }
     2429  else if (strcmp (asect->name, ".init_array") == 0)
     2430    this_hdr->sh_type = SHT_INIT_ARRAY;
     2431  else if (strcmp (asect->name, ".fini_array") == 0)
     2432    this_hdr->sh_type = SHT_FINI_ARRAY;
     2433  else if (strcmp (asect->name, ".preinit_array") == 0)
     2434    this_hdr->sh_type = SHT_PREINIT_ARRAY;
    17692435  else if (strncmp (asect->name, ".note", 5) == 0)
    17702436    this_hdr->sh_type = SHT_NOTE;
     
    18032469                    || this_hdr->sh_info == elf_tdata (abfd)->cverrefs);
    18042470    }
     2471  else if ((asect->flags & SEC_GROUP) != 0)
     2472    {
     2473      this_hdr->sh_type = SHT_GROUP;
     2474      this_hdr->sh_entsize = 4;
     2475    }
    18052476  else if ((asect->flags & SEC_ALLOC) != 0
    1806            && ((asect->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0))
     2477           && (((asect->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
     2478               || (asect->flags & SEC_NEVER_LOAD) != 0))
    18072479    this_hdr->sh_type = SHT_NOBITS;
    18082480  else
     
    18152487  if ((asect->flags & SEC_CODE) != 0)
    18162488    this_hdr->sh_flags |= SHF_EXECINSTR;
     2489  if ((asect->flags & SEC_MERGE) != 0)
     2490    {
     2491      this_hdr->sh_flags |= SHF_MERGE;
     2492      this_hdr->sh_entsize = asect->entsize;
     2493      if ((asect->flags & SEC_STRINGS) != 0)
     2494        this_hdr->sh_flags |= SHF_STRINGS;
     2495    }
     2496  if ((asect->flags & SEC_GROUP) == 0 && elf_group_name (asect) != NULL)
     2497    this_hdr->sh_flags |= SHF_GROUP;
     2498  if ((asect->flags & SEC_THREAD_LOCAL) != 0)
     2499    {
     2500      this_hdr->sh_flags |= SHF_TLS;
     2501      if (asect->_raw_size == 0 && (asect->flags & SEC_HAS_CONTENTS) == 0)
     2502        {
     2503          struct bfd_link_order *o;
     2504
     2505          this_hdr->sh_size = 0;
     2506          for (o = asect->link_order_head; o != NULL; o = o->next)
     2507            if (this_hdr->sh_size < o->offset + o->size)
     2508              this_hdr->sh_size = o->offset + o->size;
     2509          if (this_hdr->sh_size)
     2510            this_hdr->sh_type = SHT_NOBITS;
     2511        }
     2512    }
    18172513
    18182514  /* Check for processor-specific section types.  */
    1819   if (bed->elf_backend_fake_sections)
    1820     (*bed->elf_backend_fake_sections) (abfd, this_hdr, asect);
     2515  if (bed->elf_backend_fake_sections
     2516      && !(*bed->elf_backend_fake_sections) (abfd, this_hdr, asect))
     2517    *failedptr = TRUE;
    18212518
    18222519  /* If the section has relocs, set up a section header for the
     
    18282525                                    &elf_section_data (asect)->rel_hdr,
    18292526                                    asect,
    1830                                     elf_section_data (asect)->use_rela_p))
    1831     *failedptr = true;
     2527                                    asect->use_rela_p))
     2528    *failedptr = TRUE;
     2529}
     2530
     2531/* Fill in the contents of a SHT_GROUP section.  */
     2532
     2533void
     2534bfd_elf_set_group_contents (abfd, sec, failedptrarg)
     2535     bfd *abfd;
     2536     asection *sec;
     2537     PTR failedptrarg;
     2538{
     2539  bfd_boolean *failedptr = (bfd_boolean *) failedptrarg;
     2540  unsigned long symindx;
     2541  asection *elt, *first;
     2542  unsigned char *loc;
     2543  struct bfd_link_order *l;
     2544  bfd_boolean gas;
     2545
     2546  if (elf_section_data (sec)->this_hdr.sh_type != SHT_GROUP
     2547      || *failedptr)
     2548    return;
     2549
     2550  symindx = 0;
     2551  if (elf_group_id (sec) != NULL)
     2552    symindx = elf_group_id (sec)->udata.i;
     2553
     2554  if (symindx == 0)
     2555    {
     2556      /* If called from the assembler, swap_out_syms will have set up
     2557         elf_section_syms;  If called for "ld -r", use target_index.  */
     2558      if (elf_section_syms (abfd) != NULL)
     2559        symindx = elf_section_syms (abfd)[sec->index]->udata.i;
     2560      else
     2561        symindx = sec->target_index;
     2562    }
     2563  elf_section_data (sec)->this_hdr.sh_info = symindx;
     2564
     2565  /* The contents won't be allocated for "ld -r" or objcopy.  */
     2566  gas = TRUE;
     2567  if (sec->contents == NULL)
     2568    {
     2569      gas = FALSE;
     2570      sec->contents = bfd_alloc (abfd, sec->_raw_size);
     2571
     2572      /* Arrange for the section to be written out.  */
     2573      elf_section_data (sec)->this_hdr.contents = sec->contents;
     2574      if (sec->contents == NULL)
     2575        {
     2576          *failedptr = TRUE;
     2577          return;
     2578        }
     2579    }
     2580
     2581  loc = sec->contents + sec->_raw_size;
     2582
     2583  /* Get the pointer to the first section in the group that gas
     2584     squirreled away here.  objcopy arranges for this to be set to the
     2585     start of the input section group.  */
     2586  first = elt = elf_next_in_group (sec);
     2587
     2588  /* First element is a flag word.  Rest of section is elf section
     2589     indices for all the sections of the group.  Write them backwards
     2590     just to keep the group in the same order as given in .section
     2591     directives, not that it matters.  */
     2592  while (elt != NULL)
     2593    {
     2594      asection *s;
     2595      unsigned int idx;
     2596
     2597      loc -= 4;
     2598      s = elt;
     2599      if (!gas)
     2600        s = s->output_section;
     2601      idx = 0;
     2602      if (s != NULL)
     2603        idx = elf_section_data (s)->this_idx;
     2604      H_PUT_32 (abfd, idx, loc);
     2605      elt = elf_next_in_group (elt);
     2606      if (elt == first)
     2607        break;
     2608    }
     2609
     2610  /* If this is a relocatable link, then the above did nothing because
     2611     SEC is the output section.  Look through the input sections
     2612     instead.  */
     2613  for (l = sec->link_order_head; l != NULL; l = l->next)
     2614    if (l->type == bfd_indirect_link_order
     2615        && (elt = elf_next_in_group (l->u.indirect.section)) != NULL)
     2616      do
     2617        {
     2618          loc -= 4;
     2619          H_PUT_32 (abfd,
     2620                    elf_section_data (elt->output_section)->this_idx, loc);
     2621          elt = elf_next_in_group (elt);
     2622          /* During a relocatable link, the lists are circular.  */
     2623        }
     2624      while (elt != elf_next_in_group (l->u.indirect.section));
     2625
     2626  /* With ld -r, merging SHT_GROUP sections results in wasted space
     2627     due to allowing for the flag word on each input.  We may well
     2628     duplicate entries too.  */
     2629  while ((loc -= 4) > sec->contents)
     2630    H_PUT_32 (abfd, 0, loc);
     2631
     2632  if (loc != sec->contents)
     2633    abort ();
     2634
     2635  H_PUT_32 (abfd, sec->flags & SEC_LINK_ONCE ? GRP_COMDAT : 0, loc);
    18322636}
    18332637
     
    18362640   in here too, while we're at it.  */
    18372641
    1838 static boolean
     2642static bfd_boolean
    18392643assign_section_numbers (abfd)
    18402644     bfd *abfd;
     
    18422646  struct elf_obj_tdata *t = elf_tdata (abfd);
    18432647  asection *sec;
    1844   unsigned int section_number;
     2648  unsigned int section_number, secn;
    18452649  Elf_Internal_Shdr **i_shdrp;
     2650  bfd_size_type amt;
    18462651
    18472652  section_number = 1;
    18482653
     2654  _bfd_elf_strtab_clear_all_refs (elf_shstrtab (abfd));
     2655
    18492656  for (sec = abfd->sections; sec; sec = sec->next)
    18502657    {
    18512658      struct bfd_elf_section_data *d = elf_section_data (sec);
    18522659
     2660      if (section_number == SHN_LORESERVE)
     2661        section_number += SHN_HIRESERVE + 1 - SHN_LORESERVE;
    18532662      d->this_idx = section_number++;
     2663      _bfd_elf_strtab_addref (elf_shstrtab (abfd), d->this_hdr.sh_name);
    18542664      if ((sec->flags & SEC_RELOC) == 0)
    18552665        d->rel_idx = 0;
    18562666      else
    1857         d->rel_idx = section_number++;
     2667        {
     2668          if (section_number == SHN_LORESERVE)
     2669            section_number += SHN_HIRESERVE + 1 - SHN_LORESERVE;
     2670          d->rel_idx = section_number++;
     2671          _bfd_elf_strtab_addref (elf_shstrtab (abfd), d->rel_hdr.sh_name);
     2672        }
    18582673
    18592674      if (d->rel_hdr2)
    1860         d->rel_idx2 = section_number++;
     2675        {
     2676          if (section_number == SHN_LORESERVE)
     2677            section_number += SHN_HIRESERVE + 1 - SHN_LORESERVE;
     2678          d->rel_idx2 = section_number++;
     2679          _bfd_elf_strtab_addref (elf_shstrtab (abfd), d->rel_hdr2->sh_name);
     2680        }
    18612681      else
    18622682        d->rel_idx2 = 0;
    18632683    }
    18642684
     2685  if (section_number == SHN_LORESERVE)
     2686    section_number += SHN_HIRESERVE + 1 - SHN_LORESERVE;
    18652687  t->shstrtab_section = section_number++;
     2688  _bfd_elf_strtab_addref (elf_shstrtab (abfd), t->shstrtab_hdr.sh_name);
    18662689  elf_elfheader (abfd)->e_shstrndx = t->shstrtab_section;
    1867   t->shstrtab_hdr.sh_size = _bfd_stringtab_size (elf_shstrtab (abfd));
    18682690
    18692691  if (bfd_get_symcount (abfd) > 0)
    18702692    {
     2693      if (section_number == SHN_LORESERVE)
     2694        section_number += SHN_HIRESERVE + 1 - SHN_LORESERVE;
    18712695      t->symtab_section = section_number++;
     2696      _bfd_elf_strtab_addref (elf_shstrtab (abfd), t->symtab_hdr.sh_name);
     2697      if (section_number > SHN_LORESERVE - 2)
     2698        {
     2699          if (section_number == SHN_LORESERVE)
     2700            section_number += SHN_HIRESERVE + 1 - SHN_LORESERVE;
     2701          t->symtab_shndx_section = section_number++;
     2702          t->symtab_shndx_hdr.sh_name
     2703            = (unsigned int) _bfd_elf_strtab_add (elf_shstrtab (abfd),
     2704                                                  ".symtab_shndx", FALSE);
     2705          if (t->symtab_shndx_hdr.sh_name == (unsigned int) -1)
     2706            return FALSE;
     2707        }
     2708      if (section_number == SHN_LORESERVE)
     2709        section_number += SHN_HIRESERVE + 1 - SHN_LORESERVE;
    18722710      t->strtab_section = section_number++;
    1873     }
    1874 
     2711      _bfd_elf_strtab_addref (elf_shstrtab (abfd), t->strtab_hdr.sh_name);
     2712    }
     2713
     2714  _bfd_elf_strtab_finalize (elf_shstrtab (abfd));
     2715  t->shstrtab_hdr.sh_size = _bfd_elf_strtab_size (elf_shstrtab (abfd));
     2716
     2717  elf_numsections (abfd) = section_number;
    18752718  elf_elfheader (abfd)->e_shnum = section_number;
     2719  if (section_number > SHN_LORESERVE)
     2720    elf_elfheader (abfd)->e_shnum -= SHN_HIRESERVE + 1 - SHN_LORESERVE;
    18762721
    18772722  /* Set up the list of section header pointers, in agreement with the
    18782723     indices.  */
    1879   i_shdrp = ((Elf_Internal_Shdr **)
    1880              bfd_alloc (abfd, section_number * sizeof (Elf_Internal_Shdr *)));
     2724  amt = section_number * sizeof (Elf_Internal_Shdr *);
     2725  i_shdrp = (Elf_Internal_Shdr **) bfd_zalloc (abfd, amt);
    18812726  if (i_shdrp == NULL)
    1882     return false;
    1883 
    1884   i_shdrp[0] = ((Elf_Internal_Shdr *)
    1885                 bfd_alloc (abfd, sizeof (Elf_Internal_Shdr)));
     2727    return FALSE;
     2728
     2729  amt = sizeof (Elf_Internal_Shdr);
     2730  i_shdrp[0] = (Elf_Internal_Shdr *) bfd_zalloc (abfd, amt);
    18862731  if (i_shdrp[0] == NULL)
    18872732    {
    18882733      bfd_release (abfd, i_shdrp);
    1889       return false;
    1890     }
    1891   memset (i_shdrp[0], 0, sizeof (Elf_Internal_Shdr));
     2734      return FALSE;
     2735    }
    18922736
    18932737  elf_elfsections (abfd) = i_shdrp;
     
    18972741    {
    18982742      i_shdrp[t->symtab_section] = &t->symtab_hdr;
     2743      if (elf_numsections (abfd) > SHN_LORESERVE)
     2744        {
     2745          i_shdrp[t->symtab_shndx_section] = &t->symtab_shndx_hdr;
     2746          t->symtab_shndx_hdr.sh_link = t->symtab_section;
     2747        }
    18992748      i_shdrp[t->strtab_section] = &t->strtab_hdr;
    19002749      t->symtab_hdr.sh_link = t->strtab_section;
     
    19652814
    19662815              len = strlen (sec->name);
    1967               alc = (char *) bfd_malloc (len - 2);
     2816              alc = (char *) bfd_malloc ((bfd_size_type) (len - 2));
    19682817              if (alc == NULL)
    1969                 return false;
    1970               strncpy (alc, sec->name, len - 3);
     2818                return FALSE;
     2819              memcpy (alc, sec->name, len - 3);
    19712820              alc[len - 3] = '\0';
    19722821              s = bfd_get_section_by_name (abfd, alc);
     
    19772826
    19782827                  /* This is a .stab section.  */
    1979                   elf_section_data (s)->this_hdr.sh_entsize =
    1980                     4 + 2 * bfd_get_arch_size (abfd) / 8;
     2828                  if (elf_section_data (s)->this_hdr.sh_entsize == 0)
     2829                    elf_section_data (s)->this_hdr.sh_entsize
     2830                      = 4 + 2 * bfd_get_arch_size (abfd) / 8;
    19812831                }
    19822832            }
     
    20032853            d->this_hdr.sh_link = elf_section_data (s)->this_idx;
    20042854          break;
    2005         }
    2006     }
    2007 
    2008   return true;
     2855
     2856        case SHT_GROUP:
     2857          d->this_hdr.sh_link = t->symtab_section;
     2858        }
     2859    }
     2860
     2861  for (secn = 1; secn < section_number; ++secn)
     2862    if (i_shdrp[secn] == NULL)
     2863      i_shdrp[secn] = i_shdrp[0];
     2864    else
     2865      i_shdrp[secn]->sh_name = _bfd_elf_strtab_offset (elf_shstrtab (abfd),
     2866                                                       i_shdrp[secn]->sh_name);
     2867  return TRUE;
    20092868}
    20102869
     
    20272886}
    20282887
    2029 static boolean
     2888static bfd_boolean
    20302889elf_map_symbols (abfd)
    20312890     bfd *abfd;
    20322891{
    2033   int symcount = bfd_get_symcount (abfd);
     2892  unsigned int symcount = bfd_get_symcount (abfd);
    20342893  asymbol **syms = bfd_get_outsymbols (abfd);
    20352894  asymbol **sect_syms;
    2036   int num_locals = 0;
    2037   int num_globals = 0;
    2038   int num_locals2 = 0;
    2039   int num_globals2 = 0;
     2895  unsigned int num_locals = 0;
     2896  unsigned int num_globals = 0;
     2897  unsigned int num_locals2 = 0;
     2898  unsigned int num_globals2 = 0;
    20402899  int max_index = 0;
    2041   int num_sections = 0;
    2042   int idx;
     2900  unsigned int idx;
    20432901  asection *asect;
    20442902  asymbol **new_syms;
    2045   asymbol *sym;
     2903  bfd_size_type amt;
    20462904
    20472905#ifdef DEBUG
     
    20502908#endif
    20512909
    2052   /* Add a section symbol for each BFD section.  FIXME: Is this really
    2053      necessary?  */
    20542910  for (asect = abfd->sections; asect; asect = asect->next)
    20552911    {
     
    20592915
    20602916  max_index++;
    2061   sect_syms = (asymbol **) bfd_zalloc (abfd, max_index * sizeof (asymbol *));
     2917  amt = max_index * sizeof (asymbol *);
     2918  sect_syms = (asymbol **) bfd_zalloc (abfd, amt);
    20622919  if (sect_syms == NULL)
    2063     return false;
     2920    return FALSE;
    20642921  elf_section_syms (abfd) = sect_syms;
    2065 
     2922  elf_num_section_syms (abfd) = max_index;
     2923
     2924  /* Init sect_syms entries for any section symbols we have already
     2925     decided to output.  */
    20662926  for (idx = 0; idx < symcount; idx++)
    20672927    {
    2068       sym = syms[idx];
     2928      asymbol *sym = syms[idx];
    20692929
    20702930      if ((sym->flags & BSF_SECTION_SYM) != 0
     
    20842944                  sec = sec->output_section;
    20852945
    2086                   /* Empty sections in the input files may have had a section
    2087                      symbol created for them.  (See the comment near the end of
    2088                      _bfd_generic_link_output_symbols in linker.c).  If the linker
    2089                      script discards such sections then we will reach this point.
    2090                      Since we know that we cannot avoid this case, we detect it
    2091                      and skip the abort and the assignment to the sect_syms array.
    2092                      To reproduce this particular case try running the linker
    2093                      testsuite test ld-scripts/weak.exp for an ELF port that uses
    2094                      the generic linker.  */
     2946                  /* Empty sections in the input files may have had a
     2947                     section symbol created for them.  (See the comment
     2948                     near the end of _bfd_generic_link_output_symbols in
     2949                     linker.c).  If the linker script discards such
     2950                     sections then we will reach this point.  Since we know
     2951                     that we cannot avoid this case, we detect it and skip
     2952                     the abort and the assignment to the sect_syms array.
     2953                     To reproduce this particular case try running the
     2954                     linker testsuite test ld-scripts/weak.exp for an ELF
     2955                     port that uses the generic linker.  */
    20952956                  if (sec->owner == NULL)
    20962957                    continue;
     
    21032964    }
    21042965
    2105   for (asect = abfd->sections; asect; asect = asect->next)
    2106     {
    2107       if (sect_syms[asect->index] != NULL)
    2108         continue;
    2109 
    2110       sym = bfd_make_empty_symbol (abfd);
    2111       if (sym == NULL)
    2112         return false;
    2113       sym->the_bfd = abfd;
    2114       sym->name = asect->name;
    2115       sym->value = 0;
    2116       /* Set the flags to 0 to indicate that this one was newly added.  */
    2117       sym->flags = 0;
    2118       sym->section = asect;
    2119       sect_syms[asect->index] = sym;
    2120       num_sections++;
    2121 #ifdef DEBUG
    2122       fprintf (stderr,
    2123  _("creating section symbol, name = %s, value = 0x%.8lx, index = %d, section = 0x%.8lx\n"),
    2124                asect->name, (long) asect->vma, asect->index, (long) asect);
    2125 #endif
    2126     }
    2127 
    21282966  /* Classify all of the symbols.  */
    21292967  for (idx = 0; idx < symcount; idx++)
     
    21342972        num_globals++;
    21352973    }
     2974
     2975  /* We will be adding a section symbol for each BFD section.  Most normal
     2976     sections will already have a section symbol in outsymbols, but
     2977     eg. SHT_GROUP sections will not, and we need the section symbol mapped
     2978     at least in that case.  */
    21362979  for (asect = abfd->sections; asect; asect = asect->next)
    21372980    {
    2138       if (sect_syms[asect->index] != NULL
    2139           && sect_syms[asect->index]->flags == 0)
    2140         {
    2141           sect_syms[asect->index]->flags = BSF_SECTION_SYM;
    2142           if (!sym_is_global (abfd, sect_syms[asect->index]))
     2981      if (sect_syms[asect->index] == NULL)
     2982        {
     2983          if (!sym_is_global (abfd, asect->symbol))
    21432984            num_locals++;
    21442985          else
    21452986            num_globals++;
    2146           sect_syms[asect->index]->flags = 0;
    21472987        }
    21482988    }
    21492989
    21502990  /* Now sort the symbols so the local symbols are first.  */
    2151   new_syms = ((asymbol **)
    2152               bfd_alloc (abfd,
    2153                          (num_locals + num_globals) * sizeof (asymbol *)));
     2991  amt = (num_locals + num_globals) * sizeof (asymbol *);
     2992  new_syms = (asymbol **) bfd_alloc (abfd, amt);
     2993
    21542994  if (new_syms == NULL)
    2155     return false;
     2995    return FALSE;
    21562996
    21572997  for (idx = 0; idx < symcount; idx++)
    21582998    {
    21592999      asymbol *sym = syms[idx];
    2160       int i;
     3000      unsigned int i;
    21613001
    21623002      if (!sym_is_global (abfd, sym))
     
    21693009  for (asect = abfd->sections; asect; asect = asect->next)
    21703010    {
    2171       if (sect_syms[asect->index] != NULL
    2172           && sect_syms[asect->index]->flags == 0)
    2173         {
    2174           asymbol *sym = sect_syms[asect->index];
    2175           int i;
    2176 
    2177           sym->flags = BSF_SECTION_SYM;
     3011      if (sect_syms[asect->index] == NULL)
     3012        {
     3013          asymbol *sym = asect->symbol;
     3014          unsigned int i;
     3015
     3016          sect_syms[asect->index] = sym;
    21783017          if (!sym_is_global (abfd, sym))
    21793018            i = num_locals2++;
     
    21893028  elf_num_locals (abfd) = num_locals;
    21903029  elf_num_globals (abfd) = num_globals;
    2191   return true;
     3030  return TRUE;
    21923031}
    21933032
     
    21953034   ELF data structure.  */
    21963035
    2197 static INLINE file_ptr align_file_position PARAMS ((file_ptr, int));
     3036static INLINE file_ptr align_file_position
     3037  PARAMS ((file_ptr, int));
    21983038static INLINE file_ptr
    21993039align_file_position (off, align)
     
    22113051     Elf_Internal_Shdr *i_shdrp;
    22123052     file_ptr offset;
    2213      boolean align;
     3053     bfd_boolean align;
    22143054{
    22153055  if (align)
     
    22333073   is not NULL, this is being called by the ELF backend linker.  */
    22343074
    2235 boolean
     3075bfd_boolean
    22363076_bfd_elf_compute_section_file_positions (abfd, link_info)
    22373077     bfd *abfd;
     
    22393079{
    22403080  struct elf_backend_data *bed = get_elf_backend_data (abfd);
    2241   boolean failed;
     3081  bfd_boolean failed;
    22423082  struct bfd_strtab_hash *strtab;
    22433083  Elf_Internal_Shdr *shstrtab_hdr;
    22443084
    22453085  if (abfd->output_has_begun)
    2246     return true;
     3086    return TRUE;
    22473087
    22483088  /* Do any elf backend specific processing first.  */
     
    22513091
    22523092  if (! prep_headers (abfd))
    2253     return false;
     3093    return FALSE;
    22543094
    22553095  /* Post process the headers if necessary.  */
     
    22573097    (*bed->elf_backend_post_process_headers) (abfd, link_info);
    22583098
    2259   failed = false;
     3099  failed = FALSE;
    22603100  bfd_map_over_sections (abfd, elf_fake_sections, &failed);
    22613101  if (failed)
    2262     return false;
     3102    return FALSE;
    22633103
    22643104  if (!assign_section_numbers (abfd))
    2265     return false;
     3105    return FALSE;
    22663106
    22673107  /* The backend linker builds symbol table information itself.  */
     
    22723112
    22733113      if (! swap_out_syms (abfd, &strtab, relocatable_p))
    2274         return false;
     3114        return FALSE;
     3115    }
     3116
     3117  if (link_info == NULL)
     3118    {
     3119      bfd_map_over_sections (abfd, bfd_elf_set_group_contents, &failed);
     3120      if (failed)
     3121        return FALSE;
    22753122    }
    22763123
     
    22803127  shstrtab_hdr->sh_flags = 0;
    22813128  shstrtab_hdr->sh_addr = 0;
    2282   shstrtab_hdr->sh_size = _bfd_stringtab_size (elf_shstrtab (abfd));
     3129  shstrtab_hdr->sh_size = _bfd_elf_strtab_size (elf_shstrtab (abfd));
    22833130  shstrtab_hdr->sh_entsize = 0;
    22843131  shstrtab_hdr->sh_link = 0;
     
    22883135
    22893136  if (!assign_file_positions_except_relocs (abfd))
    2290     return false;
     3137    return FALSE;
    22913138
    22923139  if (link_info == NULL && bfd_get_symcount (abfd) > 0)
     
    22983145
    22993146      hdr = &elf_tdata (abfd)->symtab_hdr;
    2300       off = _bfd_elf_assign_file_position_for_section (hdr, off, true);
     3147      off = _bfd_elf_assign_file_position_for_section (hdr, off, TRUE);
     3148
     3149      hdr = &elf_tdata (abfd)->symtab_shndx_hdr;
     3150      if (hdr->sh_size != 0)
     3151        off = _bfd_elf_assign_file_position_for_section (hdr, off, TRUE);
    23013152
    23023153      hdr = &elf_tdata (abfd)->strtab_hdr;
    2303       off = _bfd_elf_assign_file_position_for_section (hdr, off, true);
     3154      off = _bfd_elf_assign_file_position_for_section (hdr, off, TRUE);
    23043155
    23053156      elf_tdata (abfd)->next_file_pos = off;
     
    23093160      if (bfd_seek (abfd, hdr->sh_offset, SEEK_SET) != 0
    23103161          || ! _bfd_stringtab_emit (abfd, strtab))
    2311         return false;
     3162        return FALSE;
    23123163      _bfd_stringtab_free (strtab);
    23133164    }
    23143165
    2315   abfd->output_has_begun = true;
    2316 
    2317   return true;
     3166  abfd->output_has_begun = TRUE;
     3167
     3168  return TRUE;
    23183169}
    23193170
     
    23263177     unsigned int from;
    23273178     unsigned int to;
    2328      boolean phdr;
     3179     bfd_boolean phdr;
    23293180{
    23303181  struct elf_segment_map *m;
    23313182  unsigned int i;
    23323183  asection **hdrpp;
    2333 
    2334   m = ((struct elf_segment_map *)
    2335        bfd_zalloc (abfd,
    2336                    (sizeof (struct elf_segment_map)
    2337                     + (to - from - 1) * sizeof (asection *))));
     3184  bfd_size_type amt;
     3185
     3186  amt = sizeof (struct elf_segment_map);
     3187  amt += (to - from - 1) * sizeof (asection *);
     3188  m = (struct elf_segment_map *) bfd_zalloc (abfd, amt);
    23383189  if (m == NULL)
    23393190    return NULL;
     
    23563207/* Set up a mapping from BFD sections to program segments.  */
    23573208
    2358 static boolean
     3209static bfd_boolean
    23593210map_sections_to_segments (abfd)
    23603211     bfd *abfd;
     
    23713222  bfd_vma maxpagesize;
    23723223  asection **hdrpp;
    2373   boolean phdr_in_segment = true;
    2374   boolean writable;
    2375   asection *dynsec;
     3224  bfd_boolean phdr_in_segment = TRUE;
     3225  bfd_boolean writable;
     3226  int tls_count = 0;
     3227  asection *first_tls = NULL;
     3228  asection *dynsec, *eh_frame_hdr;
     3229  bfd_size_type amt;
    23763230
    23773231  if (elf_tdata (abfd)->segment_map != NULL)
    2378     return true;
     3232    return TRUE;
    23793233
    23803234  if (bfd_count_sections (abfd) == 0)
    2381     return true;
     3235    return TRUE;
    23823236
    23833237  /* Select the allocated sections, and sort them.  */
    23843238
    2385   sections = (asection **) bfd_malloc (bfd_count_sections (abfd)
    2386                                        * sizeof (asection *));
     3239  amt = bfd_count_sections (abfd) * sizeof (asection *);
     3240  sections = (asection **) bfd_malloc (amt);
    23873241  if (sections == NULL)
    23883242    goto error_return;
     
    24133267  if (s != NULL && (s->flags & SEC_LOAD) != 0)
    24143268    {
    2415       m = ((struct elf_segment_map *)
    2416            bfd_zalloc (abfd, sizeof (struct elf_segment_map)));
     3269      amt = sizeof (struct elf_segment_map);
     3270      m = (struct elf_segment_map *) bfd_zalloc (abfd, amt);
    24173271      if (m == NULL)
    24183272        goto error_return;
     
    24273281      pm = &m->next;
    24283282
    2429       m = ((struct elf_segment_map *)
    2430            bfd_zalloc (abfd, sizeof (struct elf_segment_map)));
     3283      amt = sizeof (struct elf_segment_map);
     3284      m = (struct elf_segment_map *) bfd_zalloc (abfd, amt);
    24313285      if (m == NULL)
    24323286        goto error_return;
     
    24463300  phdr_index = 0;
    24473301  maxpagesize = get_elf_backend_data (abfd)->maxpagesize;
    2448   writable = false;
     3302  writable = FALSE;
    24493303  dynsec = bfd_get_section_by_name (abfd, ".dynamic");
    24503304  if (dynsec != NULL
     
    24663320          || sections[0]->lma < phdr_size
    24673321          || sections[0]->lma % maxpagesize < phdr_size % maxpagesize)
    2468         phdr_in_segment = false;
     3322        phdr_in_segment = FALSE;
    24693323    }
    24703324
     
    24723326    {
    24733327      asection *hdr;
    2474       boolean new_segment;
     3328      bfd_boolean new_segment;
    24753329
    24763330      hdr = *hdrpp;
     
    24833337          /* If we don't have a segment yet, then we don't need a new
    24843338             one (we build the last one after this loop).  */
    2485           new_segment = false;
     3339          new_segment = FALSE;
    24863340        }
    24873341      else if (last_hdr->lma - last_hdr->vma != hdr->lma - hdr->vma)
     
    24903344             virtual address and the load address, then we need a new
    24913345             segment.  */
    2492           new_segment = true;
     3346          new_segment = TRUE;
    24933347        }
    24943348      else if (BFD_ALIGN (last_hdr->lma + last_hdr->_raw_size, maxpagesize)
     
    24973351          /* If putting this section in this segment would force us to
    24983352             skip a page in the segment, then we need a new segment.  */
    2499           new_segment = true;
     3353          new_segment = TRUE;
    25003354        }
    25013355      else if ((last_hdr->flags & SEC_LOAD) == 0
     
    25043358          /* We don't want to put a loadable section after a
    25053359             nonloadable section in the same segment.  */
    2506           new_segment = true;
     3360          new_segment = TRUE;
    25073361        }
    25083362      else if ((abfd->flags & D_PAGED) == 0)
     
    25113365             don't require the sections to be correctly aligned in the
    25123366             file, then there is no other reason for a new segment.  */
    2513           new_segment = false;
     3367          new_segment = FALSE;
    25143368        }
    25153369      else if (! writable
    25163370               && (hdr->flags & SEC_READONLY) == 0
    2517                && (BFD_ALIGN (last_hdr->lma + last_hdr->_raw_size, maxpagesize)
    2518                    == hdr->lma))
     3371               && (((last_hdr->lma + last_hdr->_raw_size - 1)
     3372                    & ~(maxpagesize - 1))
     3373                   != (hdr->lma & ~(maxpagesize - 1))))
    25193374        {
    25203375          /* We don't want to put a writable section in a read only
     
    25253380             page as the previous section is when the previous section
    25263381             ends precisely on a page boundary.  */
    2527           new_segment = true;
     3382          new_segment = TRUE;
    25283383        }
    25293384      else
    25303385        {
    25313386          /* Otherwise, we can use the same segment.  */
    2532           new_segment = false;
     3387          new_segment = FALSE;
    25333388        }
    25343389
     
    25363391        {
    25373392          if ((hdr->flags & SEC_READONLY) == 0)
    2538             writable = true;
     3393            writable = TRUE;
    25393394          last_hdr = hdr;
    25403395          continue;
     
    25523407
    25533408      if ((hdr->flags & SEC_READONLY) == 0)
    2554         writable = true;
     3409        writable = TRUE;
    25553410      else
    2556         writable = false;
     3411        writable = FALSE;
    25573412
    25583413      last_hdr = hdr;
    25593414      phdr_index = i;
    2560       phdr_in_segment = false;
     3415      phdr_in_segment = FALSE;
    25613416    }
    25623417
     
    25753430  if (dynsec != NULL)
    25763431    {
    2577       m = ((struct elf_segment_map *)
    2578            bfd_zalloc (abfd, sizeof (struct elf_segment_map)));
     3432      amt = sizeof (struct elf_segment_map);
     3433      m = (struct elf_segment_map *) bfd_zalloc (abfd, amt);
    25793434      if (m == NULL)
    25803435        goto error_return;
     
    25983453          && strncmp (s->name, ".note", 5) == 0)
    25993454        {
    2600           m = ((struct elf_segment_map *)
    2601                bfd_zalloc (abfd, sizeof (struct elf_segment_map)));
     3455          amt = sizeof (struct elf_segment_map);
     3456          m = (struct elf_segment_map *) bfd_zalloc (abfd, amt);
    26023457          if (m == NULL)
    26033458            goto error_return;
     
    26103465          pm = &m->next;
    26113466        }
     3467      if (s->flags & SEC_THREAD_LOCAL)
     3468        {
     3469          if (! tls_count)
     3470            first_tls = s;
     3471          tls_count++;
     3472        }
     3473    }
     3474
     3475  /* If there are any SHF_TLS output sections, add PT_TLS segment.  */
     3476  if (tls_count > 0)
     3477    {
     3478      int i;
     3479
     3480      amt = sizeof (struct elf_segment_map);
     3481      amt += (tls_count - 1) * sizeof (asection *);
     3482      m = (struct elf_segment_map *) bfd_zalloc (abfd, amt);
     3483      if (m == NULL)
     3484        goto error_return;
     3485      m->next = NULL;
     3486      m->p_type = PT_TLS;
     3487      m->count = tls_count;
     3488      /* Mandated PF_R.  */
     3489      m->p_flags = PF_R;
     3490      m->p_flags_valid = 1;
     3491      for (i = 0; i < tls_count; ++i)
     3492        {
     3493          BFD_ASSERT (first_tls->flags & SEC_THREAD_LOCAL);
     3494          m->sections[i] = first_tls;
     3495          first_tls = first_tls->next;
     3496        }
     3497
     3498      *pm = m;
     3499      pm = &m->next;
     3500    }
     3501
     3502  /* If there is a .eh_frame_hdr section, throw in a PT_GNU_EH_FRAME
     3503     segment.  */
     3504  eh_frame_hdr = elf_tdata (abfd)->eh_frame_hdr;
     3505  if (eh_frame_hdr != NULL
     3506      && (eh_frame_hdr->output_section->flags & SEC_LOAD) != 0)
     3507    {
     3508      amt = sizeof (struct elf_segment_map);
     3509      m = (struct elf_segment_map *) bfd_zalloc (abfd, amt);
     3510      if (m == NULL)
     3511        goto error_return;
     3512      m->next = NULL;
     3513      m->p_type = PT_GNU_EH_FRAME;
     3514      m->count = 1;
     3515      m->sections[0] = eh_frame_hdr->output_section;
     3516
     3517      *pm = m;
     3518      pm = &m->next;
    26123519    }
    26133520
     
    26163523
    26173524  elf_tdata (abfd)->segment_map = mfirst;
    2618   return true;
     3525  return TRUE;
    26193526
    26203527 error_return:
    26213528  if (sections != NULL)
    26223529    free (sections);
    2623   return false;
     3530  return FALSE;
    26243531}
    26253532
     
    26333540  const asection *sec1 = *(const asection **) arg1;
    26343541  const asection *sec2 = *(const asection **) arg2;
     3542  bfd_size_type size1, size2;
    26353543
    26363544  /* Sort by LMA first, since this is the address used to
     
    26503558  /* Put !SEC_LOAD sections after SEC_LOAD ones.  */
    26513559
    2652 #define TOEND(x) (((x)->flags & SEC_LOAD) == 0)
     3560#define TOEND(x) (((x)->flags & (SEC_LOAD | SEC_THREAD_LOCAL)) == 0)
    26533561
    26543562  if (TOEND (sec1))
    26553563    {
    26563564      if (TOEND (sec2))
    2657         return sec1->target_index - sec2->target_index;
     3565        {
     3566          /* If the indicies are the same, do not return 0
     3567             here, but continue to try the next comparison.  */
     3568          if (sec1->target_index - sec2->target_index != 0)
     3569            return sec1->target_index - sec2->target_index;
     3570        }
    26583571      else
    26593572        return 1;
    26603573    }
    2661 
    2662   if (TOEND (sec2))
     3574  else if (TOEND (sec2))
    26633575    return -1;
    26643576
    26653577#undef TOEND
    26663578
    2667   /* Sort by size, to put zero sized sections before others at the
    2668      same address.  */
    2669 
    2670   if (sec1->_raw_size < sec2->_raw_size)
     3579  /* Sort by size, to put zero sized sections
     3580     before others at the same address.  */
     3581
     3582  size1 = (sec1->flags & SEC_LOAD) ? sec1->_raw_size : 0;
     3583  size2 = (sec2->flags & SEC_LOAD) ? sec2->_raw_size : 0;
     3584
     3585  if (size1 < size2)
    26713586    return -1;
    2672   if (sec1->_raw_size > sec2->_raw_size)
     3587  if (size1 > size2)
    26733588    return 1;
    26743589
     
    26803595   the file header, and writes out the program headers.  */
    26813596
    2682 static boolean
     3597static bfd_boolean
    26833598assign_file_positions_for_segments (abfd)
    26843599     bfd *abfd;
     
    26933608  bfd_vma phdrs_vaddr, phdrs_paddr;
    26943609  Elf_Internal_Phdr *p;
     3610  bfd_size_type amt;
    26953611
    26963612  if (elf_tdata (abfd)->segment_map == NULL)
    26973613    {
    26983614      if (! map_sections_to_segments (abfd))
    2699         return false;
     3615        return FALSE;
     3616    }
     3617  else
     3618    {
     3619      /* The placement algorithm assumes that non allocated sections are
     3620         not in PT_LOAD segments.  We ensure this here by removing such
     3621         sections from the segment map.  */
     3622      for (m = elf_tdata (abfd)->segment_map;
     3623           m != NULL;
     3624           m = m->next)
     3625        {
     3626          unsigned int new_count;
     3627          unsigned int i;
     3628
     3629          if (m->p_type != PT_LOAD)
     3630            continue;
     3631
     3632          new_count = 0;
     3633          for (i = 0; i < m->count; i ++)
     3634            {
     3635              if ((m->sections[i]->flags & SEC_ALLOC) != 0)
     3636                {
     3637                  if (i != new_count)
     3638                    m->sections[new_count] = m->sections[i];
     3639
     3640                  new_count ++;
     3641                }
     3642            }
     3643
     3644          if (new_count != m->count)
     3645            m->count = new_count;
     3646        }
    27003647    }
    27013648
     
    27033650    {
    27043651      if (! (*bed->elf_backend_modify_segment_map) (abfd))
    2705         return false;
     3652        return FALSE;
    27063653    }
    27073654
     
    27153662
    27163663  if (count == 0)
    2717     return true;
     3664    return TRUE;
    27183665
    27193666  /* If we already counted the number of program segments, make sure
     
    27273674        bfd_get_filename (abfd), alloc, count));
    27283675      bfd_set_error (bfd_error_bad_value);
    2729       return false;
     3676      return FALSE;
    27303677    }
    27313678
     
    27333680    alloc = count;
    27343681
    2735   phdrs = ((Elf_Internal_Phdr *)
    2736            bfd_alloc (abfd, alloc * sizeof (Elf_Internal_Phdr)));
     3682  amt = alloc * sizeof (Elf_Internal_Phdr);
     3683  phdrs = (Elf_Internal_Phdr *) bfd_alloc (abfd, amt);
    27373684  if (phdrs == NULL)
    2738     return false;
     3685    return FALSE;
    27393686
    27403687  off = bed->s->sizeof_ehdr;
     
    27543701
    27553702      /* If elf_segment_map is not from map_sections_to_segments, the
    2756          sections may not be correctly ordered.  */
    2757       if (m->count > 0)
     3703         sections may not be correctly ordered.  NOTE: sorting should
     3704         not be done to the PT_NOTE section of a corefile, which may
     3705         contain several pseudo-sections artificially created by bfd.
     3706         Sorting these pseudo-sections breaks things badly.  */
     3707      if (m->count > 1
     3708          && !(elf_elfheader (abfd)->e_type == ET_CORE
     3709               && m->p_type == PT_NOTE))
    27583710        qsort (m->sections, (size_t) m->count, sizeof (asection *),
    27593711               elf_sort_sections);
     
    28233775              if (p->p_vaddr < (bfd_vma) off)
    28243776                {
    2825                   _bfd_error_handler (_("%s: Not enough room for program headers, try linking with -N"),
    2826                                       bfd_get_filename (abfd));
     3777                  (*_bfd_error_handler)
     3778                    (_("%s: Not enough room for program headers, try linking with -N"),
     3779                     bfd_get_filename (abfd));
    28273780                  bfd_set_error (bfd_error_bad_value);
    2828                   return false;
     3781                  return FALSE;
    28293782                }
    28303783
     
    29073860          /* The section may have artificial alignment forced by a
    29083861             link script.  Notice this case by the gap between the
    2909              cumulative phdr vma and the section's vma.  */
    2910           if (p->p_vaddr + p->p_memsz < sec->vma)
     3862             cumulative phdr lma and the section's lma.  */
     3863          if (p->p_paddr + p->p_memsz < sec->lma)
    29113864            {
    2912               bfd_vma adjust = sec->vma - (p->p_vaddr + p->p_memsz);
     3865              bfd_vma adjust = sec->lma - (p->p_paddr + p->p_memsz);
    29133866
    29143867              p->p_memsz += adjust;
    2915               off += adjust;
    2916               voff += adjust;
    2917               if ((flags & SEC_LOAD) != 0)
     3868              if (p->p_type == PT_LOAD
     3869                  || (p->p_type == PT_NOTE
     3870                      && bfd_get_format (abfd) == bfd_core))
     3871                {
     3872                  off += adjust;
     3873                  voff += adjust;
     3874                }
     3875              if ((flags & SEC_LOAD) != 0
     3876                  || (flags & SEC_THREAD_LOCAL) != 0)
    29183877                p->p_filesz += adjust;
    29193878            }
     
    29483907                  if (i == 0)
    29493908                    {
    2950                       (* _bfd_error_handler)
    2951                         (_("Error: First section in segment (%s) starts at 0x%x"),
    2952                          bfd_section_name (abfd, sec), sec->lma);
    2953                       (* _bfd_error_handler)
    2954                         (_("       whereas segment starts at 0x%x"),
    2955                          p->p_paddr);
    2956 
    2957                       return false;
     3909                      (* _bfd_error_handler) (_("\
     3910Error: First section in segment (%s) starts at 0x%x whereas the segment starts at 0x%x"),
     3911                                              bfd_section_name (abfd, sec),
     3912                                              sec->lma,
     3913                                              p->p_paddr);
     3914                      return FALSE;
    29583915                    }
    29593916                  p->p_memsz += adjust;
     
    29743931                off += sec->_raw_size;
    29753932
    2976               if ((flags & SEC_ALLOC) != 0)
     3933              if ((flags & SEC_ALLOC) != 0
     3934                  && ((flags & SEC_LOAD) != 0
     3935                      || (flags & SEC_THREAD_LOCAL) == 0))
    29773936                voff += sec->_raw_size;
    29783937            }
     
    30013960          else
    30023961            {
     3962              if ((sec->flags & SEC_LOAD) != 0
     3963                  || (sec->flags & SEC_THREAD_LOCAL) == 0
     3964                  || p->p_type == PT_TLS)
    30033965              p->p_memsz += sec->_raw_size;
    30043966
    30053967              if ((flags & SEC_LOAD) != 0)
    30063968                p->p_filesz += sec->_raw_size;
     3969
     3970              if (p->p_type == PT_TLS
     3971                  && sec->_raw_size == 0
     3972                  && (sec->flags & SEC_HAS_CONTENTS) == 0)
     3973                {
     3974                  struct bfd_link_order *o;
     3975                  bfd_vma tbss_size = 0;
     3976
     3977                  for (o = sec->link_order_head; o != NULL; o = o->next)
     3978                    if (tbss_size < o->offset + o->size)
     3979                      tbss_size = o->offset + o->size;
     3980
     3981                  p->p_memsz += tbss_size;
     3982                }
    30073983
    30083984              if (align > p->p_align
     
    30624038
    30634039  /* Write out the program headers.  */
    3064   if (bfd_seek (abfd, bed->s->sizeof_ehdr, SEEK_SET) != 0
     4040  if (bfd_seek (abfd, (bfd_signed_vma) bed->s->sizeof_ehdr, SEEK_SET) != 0
    30654041      || bed->s->write_out_phdrs (abfd, phdrs, alloc) != 0)
    3066     return false;
    3067 
    3068   return true;
     4042    return FALSE;
     4043
     4044  return TRUE;
    30694045}
    30704046
     
    31234099    }
    31244100
     4101  if (elf_tdata (abfd)->eh_frame_hdr)
     4102    {
     4103      /* We need a PT_GNU_EH_FRAME segment.  */
     4104      ++segs;
     4105    }
     4106
    31254107  for (s = abfd->sections; s != NULL; s = s->next)
    31264108    {
     
    31304112          /* We need a PT_NOTE segment.  */
    31314113          ++segs;
     4114        }
     4115    }
     4116
     4117  for (s = abfd->sections; s != NULL; s = s->next)
     4118    {
     4119      if (s->flags & SEC_THREAD_LOCAL)
     4120        {
     4121          /* We need a PT_TLS segment.  */
     4122          ++segs;
     4123          break;
    31324124        }
    31334125    }
     
    31594151   We also don't set the positions of the .symtab and .strtab here.  */
    31604152
    3161 static boolean
     4153static bfd_boolean
    31624154assign_file_positions_except_relocs (abfd)
    31634155     bfd *abfd;
     
    31664158  Elf_Internal_Ehdr * const i_ehdrp = elf_elfheader (abfd);
    31674159  Elf_Internal_Shdr ** const i_shdrpp = elf_elfsections (abfd);
     4160  unsigned int num_sec = elf_numsections (abfd);
    31684161  file_ptr off;
    31694162  struct elf_backend_data *bed = get_elf_backend_data (abfd);
     
    31814174         not creating a program header, and that the actual order of
    31824175         the sections in the file is unimportant.  */
    3183       for (i = 1, hdrpp = i_shdrpp + 1; i < i_ehdrp->e_shnum; i++, hdrpp++)
     4176      for (i = 1, hdrpp = i_shdrpp + 1; i < num_sec; i++, hdrpp++)
    31844177        {
    31854178          Elf_Internal_Shdr *hdr;
    31864179
    31874180          hdr = *hdrpp;
    3188           if (hdr->sh_type == SHT_REL || hdr->sh_type == SHT_RELA)
    3189             {
    3190               hdr->sh_offset = -1;
    3191               continue;
    3192             }
    3193           if (i == tdata->symtab_section
     4181          if (hdr->sh_type == SHT_REL
     4182              || hdr->sh_type == SHT_RELA
     4183              || i == tdata->symtab_section
     4184              || i == tdata->symtab_shndx_section
    31944185              || i == tdata->strtab_section)
    31954186            {
    31964187              hdr->sh_offset = -1;
    3197               continue;
    31984188            }
    3199 
    3200           off = _bfd_elf_assign_file_position_for_section (hdr, off, true);
     4189          else
     4190            off = _bfd_elf_assign_file_position_for_section (hdr, off, TRUE);
     4191
     4192          if (i == SHN_LORESERVE - 1)
     4193            {
     4194              i += SHN_HIRESERVE + 1 - SHN_LORESERVE;
     4195              hdrpp += SHN_HIRESERVE + 1 - SHN_LORESERVE;
     4196            }
    32014197        }
    32024198    }
     
    32094205         assignment of sections to segments.  */
    32104206      if (! assign_file_positions_for_segments (abfd))
    3211         return false;
     4207        return FALSE;
    32124208
    32134209      /* Assign file positions for the other sections.  */
    32144210
    32154211      off = elf_tdata (abfd)->next_file_pos;
    3216       for (i = 1, hdrpp = i_shdrpp + 1; i < i_ehdrp->e_shnum; i++, hdrpp++)
     4212      for (i = 1, hdrpp = i_shdrpp + 1; i < num_sec; i++, hdrpp++)
    32174213        {
    32184214          Elf_Internal_Shdr *hdr;
     
    32354231                off += (hdr->sh_addr - off) % hdr->sh_addralign;
    32364232              off = _bfd_elf_assign_file_position_for_section (hdr, off,
    3237                                                                false);
     4233                                                               FALSE);
    32384234            }
    32394235          else if (hdr->sh_type == SHT_REL
    32404236                   || hdr->sh_type == SHT_RELA
    32414237                   || hdr == i_shdrpp[tdata->symtab_section]
     4238                   || hdr == i_shdrpp[tdata->symtab_shndx_section]
    32424239                   || hdr == i_shdrpp[tdata->strtab_section])
    32434240            hdr->sh_offset = -1;
    32444241          else
    3245             off = _bfd_elf_assign_file_position_for_section (hdr, off, true);
     4242            off = _bfd_elf_assign_file_position_for_section (hdr, off, TRUE);
     4243
     4244          if (i == SHN_LORESERVE - 1)
     4245            {
     4246              i += SHN_HIRESERVE + 1 - SHN_LORESERVE;
     4247              hdrpp += SHN_HIRESERVE + 1 - SHN_LORESERVE;
     4248            }
    32464249        }
    32474250    }
     
    32544257  elf_tdata (abfd)->next_file_pos = off;
    32554258
    3256   return true;
    3257 }
    3258 
    3259 static boolean
     4259  return TRUE;
     4260}
     4261
     4262static bfd_boolean
    32604263prep_headers (abfd)
    32614264     bfd *abfd;
     
    32644267  Elf_Internal_Phdr *i_phdrp = 0; /* Program header table, internal form */
    32654268  Elf_Internal_Shdr **i_shdrp;  /* Section header table, internal form */
    3266   int count;
    3267   struct bfd_strtab_hash *shstrtab;
     4269  struct elf_strtab_hash *shstrtab;
    32684270  struct elf_backend_data *bed = get_elf_backend_data (abfd);
    32694271
     
    32714273  i_shdrp = elf_elfsections (abfd);
    32724274
    3273   shstrtab = _bfd_elf_stringtab_init ();
     4275  shstrtab = _bfd_elf_strtab_init ();
    32744276  if (shstrtab == NULL)
    3275     return false;
     4277    return FALSE;
    32764278
    32774279  elf_shstrtab (abfd) = shstrtab;
     
    32864288    bfd_big_endian (abfd) ? ELFDATA2MSB : ELFDATA2LSB;
    32874289  i_ehdrp->e_ident[EI_VERSION] = bed->s->ev_current;
    3288 
    3289   i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_NONE;
    3290   i_ehdrp->e_ident[EI_ABIVERSION] = 0;
    3291 
    3292   for (count = EI_PAD; count < EI_NIDENT; count++)
    3293     i_ehdrp->e_ident[count] = 0;
    32944290
    32954291  if ((abfd->flags & DYNAMIC) != 0)
     
    33074303      i_ehdrp->e_machine = EM_NONE;
    33084304      break;
    3309     case bfd_arch_sparc:
    3310       if (bfd_get_arch_size (abfd) == 64)
    3311         i_ehdrp->e_machine = EM_SPARCV9;
     4305
     4306      /* There used to be a long list of cases here, each one setting
     4307         e_machine to the same EM_* macro #defined as ELF_MACHINE_CODE
     4308         in the corresponding bfd definition.  To avoid duplication,
     4309         the switch was removed.  Machines that need special handling
     4310         can generally do it in elf_backend_final_write_processing(),
     4311         unless they need the information earlier than the final write.
     4312         Such need can generally be supplied by replacing the tests for
     4313         e_machine with the conditions used to determine it.  */
     4314    default:
     4315      if (get_elf_backend_data (abfd) != NULL)
     4316        i_ehdrp->e_machine = get_elf_backend_data (abfd)->elf_machine_code;
    33124317      else
    3313         i_ehdrp->e_machine = EM_SPARC;
    3314       break;
    3315     case bfd_arch_i370:
    3316       i_ehdrp->e_machine = EM_S370;
    3317       break;
    3318     case bfd_arch_i386:
    3319       if (bfd_get_arch_size (abfd) == 64)
    3320         i_ehdrp->e_machine = EM_X86_64;
    3321       else
    3322         i_ehdrp->e_machine = EM_386;
    3323       break;
    3324     case bfd_arch_ia64:
    3325       i_ehdrp->e_machine = EM_IA_64;
    3326       break;
    3327     case bfd_arch_m68hc11:
    3328       i_ehdrp->e_machine = EM_68HC11;
    3329       break;
    3330     case bfd_arch_m68hc12:
    3331       i_ehdrp->e_machine = EM_68HC12;
    3332       break;
    3333     case bfd_arch_m68k:
    3334       i_ehdrp->e_machine = EM_68K;
    3335       break;
    3336     case bfd_arch_m88k:
    3337       i_ehdrp->e_machine = EM_88K;
    3338       break;
    3339     case bfd_arch_i860:
    3340       i_ehdrp->e_machine = EM_860;
    3341       break;
    3342     case bfd_arch_i960:
    3343       i_ehdrp->e_machine = EM_960;
    3344       break;
    3345     case bfd_arch_mips: /* MIPS Rxxxx */
    3346       i_ehdrp->e_machine = EM_MIPS;     /* only MIPS R3000 */
    3347       break;
    3348     case bfd_arch_hppa:
    3349       i_ehdrp->e_machine = EM_PARISC;
    3350       break;
    3351     case bfd_arch_powerpc:
    3352       i_ehdrp->e_machine = EM_PPC;
    3353       break;
    3354     case bfd_arch_alpha:
    3355       i_ehdrp->e_machine = EM_ALPHA;
    3356       break;
    3357     case bfd_arch_sh:
    3358       i_ehdrp->e_machine = EM_SH;
    3359       break;
    3360     case bfd_arch_d10v:
    3361       i_ehdrp->e_machine = EM_CYGNUS_D10V;
    3362       break;
    3363     case bfd_arch_d30v:
    3364       i_ehdrp->e_machine = EM_CYGNUS_D30V;
    3365       break;
    3366     case bfd_arch_fr30:
    3367       i_ehdrp->e_machine = EM_CYGNUS_FR30;
    3368       break;
    3369     case bfd_arch_mcore:
    3370       i_ehdrp->e_machine = EM_MCORE;
    3371       break;
    3372     case bfd_arch_avr:
    3373       i_ehdrp->e_machine = EM_AVR;
    3374       break;
    3375     case bfd_arch_v850:
    3376       switch (bfd_get_mach (abfd))
    3377         {
    3378         default:
    3379         case 0:               i_ehdrp->e_machine = EM_CYGNUS_V850; break;
    3380         }
    3381       break;
    3382     case bfd_arch_arc:
    3383       i_ehdrp->e_machine = EM_CYGNUS_ARC;
    3384       break;
    3385     case bfd_arch_arm:
    3386       i_ehdrp->e_machine = EM_ARM;
    3387       break;
    3388     case bfd_arch_m32r:
    3389       i_ehdrp->e_machine = EM_CYGNUS_M32R;
    3390       break;
    3391     case bfd_arch_mn10200:
    3392       i_ehdrp->e_machine = EM_CYGNUS_MN10200;
    3393       break;
    3394     case bfd_arch_mn10300:
    3395       i_ehdrp->e_machine = EM_CYGNUS_MN10300;
    3396       break;
    3397     case bfd_arch_pj:
    3398       i_ehdrp->e_machine = EM_PJ;
    3399       break;
    3400     case bfd_arch_cris:
    3401       i_ehdrp->e_machine = EM_CRIS;
    3402       break;
    3403       /* Also note that EM_M32, AT&T WE32100 is unknown to bfd.  */
    3404     default:
    3405       i_ehdrp->e_machine = EM_NONE;
    3406     }
     4318        i_ehdrp->e_machine = EM_NONE;
     4319      }
     4320
    34074321  i_ehdrp->e_version = bed->s->ev_current;
    34084322  i_ehdrp->e_ehsize = bed->s->sizeof_ehdr;
     
    34394353
    34404354  elf_tdata (abfd)->symtab_hdr.sh_name =
    3441     (unsigned int) _bfd_stringtab_add (shstrtab, ".symtab", true, false);
     4355    (unsigned int) _bfd_elf_strtab_add (shstrtab, ".symtab", FALSE);
    34424356  elf_tdata (abfd)->strtab_hdr.sh_name =
    3443     (unsigned int) _bfd_stringtab_add (shstrtab, ".strtab", true, false);
     4357    (unsigned int) _bfd_elf_strtab_add (shstrtab, ".strtab", FALSE);
    34444358  elf_tdata (abfd)->shstrtab_hdr.sh_name =
    3445     (unsigned int) _bfd_stringtab_add (shstrtab, ".shstrtab", true, false);
     4359    (unsigned int) _bfd_elf_strtab_add (shstrtab, ".shstrtab", FALSE);
    34464360  if (elf_tdata (abfd)->symtab_hdr.sh_name == (unsigned int) -1
    34474361      || elf_tdata (abfd)->symtab_hdr.sh_name == (unsigned int) -1
    34484362      || elf_tdata (abfd)->shstrtab_hdr.sh_name == (unsigned int) -1)
    3449     return false;
    3450 
    3451   return true;
     4363    return FALSE;
     4364
     4365  return TRUE;
    34524366}
    34534367
     
    34604374{
    34614375  file_ptr off;
    3462   unsigned int i;
     4376  unsigned int i, num_sec;
    34634377  Elf_Internal_Shdr **shdrpp;
    34644378
    34654379  off = elf_tdata (abfd)->next_file_pos;
    34664380
    3467   for (i = 1, shdrpp = elf_elfsections (abfd) + 1;
    3468        i < elf_elfheader (abfd)->e_shnum;
    3469        i++, shdrpp++)
     4381  num_sec = elf_numsections (abfd);
     4382  for (i = 1, shdrpp = elf_elfsections (abfd) + 1; i < num_sec; i++, shdrpp++)
    34704383    {
    34714384      Elf_Internal_Shdr *shdrp;
     
    34744387      if ((shdrp->sh_type == SHT_REL || shdrp->sh_type == SHT_RELA)
    34754388          && shdrp->sh_offset == -1)
    3476         off = _bfd_elf_assign_file_position_for_section (shdrp, off, true);
     4389        off = _bfd_elf_assign_file_position_for_section (shdrp, off, TRUE);
    34774390    }
    34784391
     
    34804393}
    34814394
    3482 boolean
     4395bfd_boolean
    34834396_bfd_elf_write_object_contents (abfd)
    34844397     bfd *abfd;
     
    34874400  Elf_Internal_Ehdr *i_ehdrp;
    34884401  Elf_Internal_Shdr **i_shdrp;
    3489   boolean failed;
    3490   unsigned int count;
     4402  bfd_boolean failed;
     4403  unsigned int count, num_sec;
    34914404
    34924405  if (! abfd->output_has_begun
    34934406      && ! _bfd_elf_compute_section_file_positions
    34944407             (abfd, (struct bfd_link_info *) NULL))
    3495     return false;
     4408    return FALSE;
    34964409
    34974410  i_shdrp = elf_elfsections (abfd);
    34984411  i_ehdrp = elf_elfheader (abfd);
    34994412
    3500   failed = false;
     4413  failed = FALSE;
    35014414  bfd_map_over_sections (abfd, bed->s->write_relocs, &failed);
    35024415  if (failed)
    3503     return false;
     4416    return FALSE;
    35044417
    35054418  _bfd_elf_assign_file_positions_for_relocs (abfd);
    35064419
    35074420  /* After writing the headers, we need to write the sections too...  */
    3508   for (count = 1; count < i_ehdrp->e_shnum; count++)
     4421  num_sec = elf_numsections (abfd);
     4422  for (count = 1; count < num_sec; count++)
    35094423    {
    35104424      if (bed->elf_backend_section_processing)
     
    35124426      if (i_shdrp[count]->contents)
    35134427        {
     4428          bfd_size_type amt = i_shdrp[count]->sh_size;
     4429
    35144430          if (bfd_seek (abfd, i_shdrp[count]->sh_offset, SEEK_SET) != 0
    3515               || (bfd_write (i_shdrp[count]->contents, i_shdrp[count]->sh_size,
    3516                              1, abfd)
    3517                   != i_shdrp[count]->sh_size))
    3518             return false;
    3519         }
     4431              || bfd_bwrite (i_shdrp[count]->contents, amt, abfd) != amt)
     4432            return FALSE;
     4433        }
     4434      if (count == SHN_LORESERVE - 1)
     4435        count += SHN_HIRESERVE + 1 - SHN_LORESERVE;
    35204436    }
    35214437
    35224438  /* Write out the section header names.  */
    35234439  if (bfd_seek (abfd, elf_tdata (abfd)->shstrtab_hdr.sh_offset, SEEK_SET) != 0
    3524       || ! _bfd_stringtab_emit (abfd, elf_shstrtab (abfd)))
    3525     return false;
     4440      || ! _bfd_elf_strtab_emit (abfd, elf_shstrtab (abfd)))
     4441    return FALSE;
    35264442
    35274443  if (bed->elf_backend_final_write_processing)
     
    35324448}
    35334449
    3534 boolean
     4450bfd_boolean
    35354451_bfd_elf_write_corefile_contents (abfd)
    35364452     bfd *abfd;
     
    35474463     struct sec *asect;
    35484464{
    3549   struct elf_backend_data *bed = get_elf_backend_data (abfd);
    3550   Elf_Internal_Shdr **i_shdrp = elf_elfsections (abfd);
     4465  struct elf_backend_data *bed;
    35514466  int index;
    3552   Elf_Internal_Shdr *hdr;
    3553   int maxindex = elf_elfheader (abfd)->e_shnum;
    3554 
    3555   for (index = 0; index < maxindex; index++)
    3556     {
    3557       hdr = i_shdrp[index];
    3558       if (hdr->bfd_section == asect)
    3559         return index;
    3560     }
    3561 
     4467
     4468  if (elf_section_data (asect) != NULL
     4469      && elf_section_data (asect)->this_idx != 0)
     4470    return elf_section_data (asect)->this_idx;
     4471
     4472  if (bfd_is_abs_section (asect))
     4473    index = SHN_ABS;
     4474  else if (bfd_is_com_section (asect))
     4475    index = SHN_COMMON;
     4476  else if (bfd_is_und_section (asect))
     4477    index = SHN_UNDEF;
     4478  else
     4479    {
     4480      Elf_Internal_Shdr **i_shdrp = elf_elfsections (abfd);
     4481      int maxindex = elf_numsections (abfd);
     4482
     4483      for (index = 1; index < maxindex; index++)
     4484        {
     4485          Elf_Internal_Shdr *hdr = i_shdrp[index];
     4486
     4487          if (hdr != NULL && hdr->bfd_section == asect)
     4488            return index;
     4489        }
     4490      index = -1;
     4491    }
     4492
     4493  bed = get_elf_backend_data (abfd);
    35624494  if (bed->elf_backend_section_from_bfd_section)
    35634495    {
    3564       for (index = 0; index < maxindex; index++)
    3565         {
    3566           int retval;
    3567 
    3568           hdr = i_shdrp[index];
    3569           retval = index;
    3570           if ((*bed->elf_backend_section_from_bfd_section)
    3571               (abfd, hdr, asect, &retval))
    3572             return retval;
    3573         }
    3574     }
    3575 
    3576   if (bfd_is_abs_section (asect))
    3577     return SHN_ABS;
    3578   if (bfd_is_com_section (asect))
    3579     return SHN_COMMON;
    3580   if (bfd_is_und_section (asect))
    3581     return SHN_UNDEF;
    3582 
    3583   bfd_set_error (bfd_error_nonrepresentable_section);
    3584 
    3585   return -1;
     4496      int retval = index;
     4497
     4498      if ((*bed->elf_backend_section_from_bfd_section) (abfd, asect, &retval))
     4499        return retval;
     4500    }
     4501
     4502  if (index == -1)
     4503    bfd_set_error (bfd_error_nonrepresentable_section);
     4504
     4505  return index;
    35864506}
    35874507
     
    36134533      else
    36144534        indx = asym_ptr->section->index;
    3615       if (elf_section_syms (abfd)[indx])
     4535      if (indx < elf_num_section_syms (abfd)
     4536          && elf_section_syms (abfd)[indx] != NULL)
    36164537        asym_ptr->udata.i = elf_section_syms (abfd)[indx]->udata.i;
    36174538    }
     
    36254546      (*_bfd_error_handler)
    36264547        (_("%s: symbol `%s' required but not present"),
    3627          bfd_get_filename (abfd), bfd_asymbol_name (asym_ptr));
     4548         bfd_archive_filename (abfd), bfd_asymbol_name (asym_ptr));
    36284549      bfd_set_error (bfd_error_no_symbols);
    36294550      return -1;
     
    36334554  {
    36344555    fprintf (stderr,
    3635              _("elf_symbol_from_bfd_symbol 0x%.8lx, name = %s, sym num = %d, flags = 0x%.8lx%s\n"),
     4556             "elf_symbol_from_bfd_symbol 0x%.8lx, name = %s, sym num = %d, flags = 0x%.8lx%s\n",
    36364557             (long) asym_ptr, asym_ptr->name, idx, flags,
    36374558             elf_symbol_flags (flags));
     
    36454566/* Copy private BFD data.  This copies any program header information.  */
    36464567
    3647 static boolean
     4568static bfd_boolean
    36484569copy_private_bfd_data (ibfd, obfd)
    36494570     bfd *ibfd;
    36504571     bfd *obfd;
    36514572{
    3652   Elf_Internal_Ehdr *       iehdr;
    3653   struct elf_segment_map *  map;
    3654   struct elf_segment_map *  map_first;
    3655   struct elf_segment_map ** pointer_to_map;
    3656   Elf_Internal_Phdr *       segment;
    3657   asection *                section;
    3658   unsigned int              i;
    3659   unsigned int              num_segments;
    3660   boolean                   phdr_included = false;
    3661   bfd_vma                   maxpagesize;
    3662   struct elf_segment_map *  phdr_adjust_seg = NULL;
    3663   unsigned int              phdr_adjust_num = 0;
     4573  Elf_Internal_Ehdr *iehdr;
     4574  struct elf_segment_map *map;
     4575  struct elf_segment_map *map_first;
     4576  struct elf_segment_map **pointer_to_map;
     4577  Elf_Internal_Phdr *segment;
     4578  asection *section;
     4579  unsigned int i;
     4580  unsigned int num_segments;
     4581  bfd_boolean phdr_included = FALSE;
     4582  bfd_vma maxpagesize;
     4583  struct elf_segment_map *phdr_adjust_seg = NULL;
     4584  unsigned int phdr_adjust_num = 0;
     4585  struct elf_backend_data *bed;
    36644586
    36654587  if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
    36664588      || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
    3667     return true;
     4589    return TRUE;
    36684590
    36694591  if (elf_tdata (ibfd)->phdr == NULL)
    3670     return true;
    3671 
     4592    return TRUE;
     4593
     4594  bed = get_elf_backend_data (ibfd);
    36724595  iehdr = elf_elfheader (ibfd);
    36734596
     
    36794602
    36804603  /* Returns the end address of the segment + 1.  */
    3681 #define SEGMENT_END(segment, start)                     \
    3682   (start + (segment->p_memsz > segment->p_filesz        \
    3683    ? segment->p_memsz : segment->p_filesz))
    3684 
    3685   /* Returns true if the given section is contained within
     4604#define SEGMENT_END(segment, start)                                     \
     4605  (start + (segment->p_memsz > segment->p_filesz                        \
     4606            ? segment->p_memsz : segment->p_filesz))
     4607
     4608#define SECTION_SIZE(section, segment)                                  \
     4609  (((section->flags & (SEC_HAS_CONTENTS | SEC_THREAD_LOCAL))            \
     4610    != SEC_THREAD_LOCAL || segment->p_type == PT_TLS)                   \
     4611   ? section->_raw_size : 0)
     4612
     4613  /* Returns TRUE if the given section is contained within
    36864614     the given segment.  VMA addresses are compared.  */
    3687 #define IS_CONTAINED_BY_VMA(section, segment)           \
    3688   (section->vma >= segment->p_vaddr                     \
    3689    && (section->vma + section->_raw_size)               \
    3690    <= (SEGMENT_END (segment, segment->p_vaddr)))
    3691 
    3692   /* Returns true if the given section is contained within
     4615#define IS_CONTAINED_BY_VMA(section, segment)                           \
     4616  (section->vma >= segment->p_vaddr                                     \
     4617   && (section->vma + SECTION_SIZE (section, segment)                   \
     4618       <= (SEGMENT_END (segment, segment->p_vaddr))))
     4619
     4620  /* Returns TRUE if the given section is contained within
    36934621     the given segment.  LMA addresses are compared.  */
    3694 #define IS_CONTAINED_BY_LMA(section, segment, base)     \
    3695     (section->lma >= base                               \
    3696      && (section->lma + section->_raw_size)             \
    3697      <= SEGMENT_END (segment, base))
     4622#define IS_CONTAINED_BY_LMA(section, segment, base)                     \
     4623  (section->lma >= base                                                 \
     4624   && (section->lma + SECTION_SIZE (section, segment)                   \
     4625       <= SEGMENT_END (segment, base)))
    36984626
    36994627  /* Special case: corefile "NOTE" section containing regs, prpsinfo etc.  */
    3700 #define IS_COREFILE_NOTE(p, s)                          \
    3701             (p->p_type == PT_NOTE                       \
    3702              && bfd_get_format (ibfd) == bfd_core       \
    3703              && s->vma == 0 && s->lma == 0              \
    3704              && (bfd_vma) s->filepos >= p->p_offset     \
    3705              && (bfd_vma) s->filepos + s->_raw_size     \
    3706              <= p->p_offset + p->p_filesz)
     4628#define IS_COREFILE_NOTE(p, s)                                          \
     4629  (p->p_type == PT_NOTE                                                 \
     4630   && bfd_get_format (ibfd) == bfd_core                                 \
     4631   && s->vma == 0 && s->lma == 0                                        \
     4632   && (bfd_vma) s->filepos >= p->p_offset                               \
     4633   && ((bfd_vma) s->filepos + s->_raw_size                              \
     4634       <= p->p_offset + p->p_filesz))
    37074635
    37084636  /* The complicated case when p_vaddr is 0 is to handle the Solaris
    37094637     linker, which generates a PT_INTERP section with p_vaddr and
    37104638     p_memsz set to 0.  */
    3711 #define IS_SOLARIS_PT_INTERP(p, s)                      \
    3712             (   p->p_vaddr == 0                         \
    3713              && p->p_filesz > 0                         \
    3714              && (s->flags & SEC_HAS_CONTENTS) != 0      \
    3715              && s->_raw_size > 0                        \
    3716              && (bfd_vma) s->filepos >= p->p_offset     \
    3717              && ((bfd_vma) s->filepos + s->_raw_size    \
    3718                      <= p->p_offset + p->p_filesz))
     4639#define IS_SOLARIS_PT_INTERP(p, s)                                      \
     4640  (p->p_vaddr == 0                                                      \
     4641   && p->p_paddr == 0                                                   \
     4642   && p->p_memsz == 0                                                   \
     4643   && p->p_filesz > 0                                                   \
     4644   && (s->flags & SEC_HAS_CONTENTS) != 0                                \
     4645   && s->_raw_size > 0                                                  \
     4646   && (bfd_vma) s->filepos >= p->p_offset                               \
     4647   && ((bfd_vma) s->filepos + s->_raw_size                              \
     4648       <= p->p_offset + p->p_filesz))
    37194649
    37204650  /* Decide if the given section should be included in the given segment.
    37214651     A section will be included if:
    3722        1. It is within the address space of the segment,
     4652       1. It is within the address space of the segment -- we use the LMA
     4653          if that is set for the segment and the VMA otherwise,
    37234654       2. It is an allocated segment,
    37244655       3. There is an output section associated with it,
    3725        4. The section has not already been allocated to a previous segment.  */
    3726 #define INCLUDE_SECTION_IN_SEGMENT(section, segment)    \
    3727   ((((IS_CONTAINED_BY_VMA (section, segment)            \
    3728       || IS_SOLARIS_PT_INTERP (segment, section))       \
    3729      && (section->flags & SEC_ALLOC) != 0)              \
    3730     || IS_COREFILE_NOTE (segment, section))             \
    3731    && section->output_section != NULL                   \
    3732    && section->segment_mark == false)
    3733 
    3734   /* Returns true iff seg1 starts after the end of seg2.  */
    3735 #define SEGMENT_AFTER_SEGMENT(seg1, seg2)               \
    3736     (seg1->p_vaddr >= SEGMENT_END (seg2, seg2->p_vaddr))
    3737 
    3738   /* Returns true iff seg1 and seg2 overlap.  */
    3739 #define SEGMENT_OVERLAPS(seg1, seg2)                    \
    3740   (!(SEGMENT_AFTER_SEGMENT (seg1, seg2) || SEGMENT_AFTER_SEGMENT (seg2, seg1)))
     4656       4. The section has not already been allocated to a previous segment.
     4657       5. PT_TLS segment includes only SHF_TLS sections.
     4658       6. SHF_TLS sections are only in PT_TLS or PT_LOAD segments.  */
     4659#define INCLUDE_SECTION_IN_SEGMENT(section, segment, bed)               \
     4660  ((((segment->p_paddr                                                  \
     4661      ? IS_CONTAINED_BY_LMA (section, segment, segment->p_paddr)        \
     4662      : IS_CONTAINED_BY_VMA (section, segment))                         \
     4663     && (section->flags & SEC_ALLOC) != 0)                              \
     4664    || IS_COREFILE_NOTE (segment, section))                             \
     4665   && section->output_section != NULL                                   \
     4666   && (segment->p_type != PT_TLS                                        \
     4667       || (section->flags & SEC_THREAD_LOCAL))                          \
     4668   && (segment->p_type == PT_LOAD                                       \
     4669       || segment->p_type == PT_TLS                                     \
     4670       || (section->flags & SEC_THREAD_LOCAL) == 0)                     \
     4671   && ! section->segment_mark)
     4672
     4673  /* Returns TRUE iff seg1 starts after the end of seg2.  */
     4674#define SEGMENT_AFTER_SEGMENT(seg1, seg2, field)                        \
     4675  (seg1->field >= SEGMENT_END (seg2, seg2->field))
     4676
     4677  /* Returns TRUE iff seg1 and seg2 overlap. Segments overlap iff both
     4678     their VMA address ranges and their LMA address ranges overlap.
     4679     It is possible to have overlapping VMA ranges without overlapping LMA
     4680     ranges.  RedBoot images for example can have both .data and .bss mapped
     4681     to the same VMA range, but with the .data section mapped to a different
     4682     LMA.  */
     4683#define SEGMENT_OVERLAPS(seg1, seg2)                                    \
     4684  (   !(SEGMENT_AFTER_SEGMENT (seg1, seg2, p_vaddr)                     \
     4685        || SEGMENT_AFTER_SEGMENT (seg2, seg1, p_vaddr))                 \
     4686   && !(SEGMENT_AFTER_SEGMENT (seg1, seg2, p_paddr)                     \
     4687        || SEGMENT_AFTER_SEGMENT (seg2, seg1, p_paddr)))
    37414688
    37424689  /* Initialise the segment mark field.  */
    37434690  for (section = ibfd->sections; section != NULL; section = section->next)
    3744     section->segment_mark = false;
     4691    section->segment_mark = FALSE;
    37454692
    37464693  /* Scan through the segments specified in the program header
    37474694     of the input BFD.  For this first scan we look for overlaps
    3748      in the loadable segments.  These can be created by wierd
    3749      parameters to objcopy.  */
     4695     in the loadable segments.  These can be created by weird
     4696     parameters to objcopy.  Also, fix some solaris weirdness.  */
    37504697  for (i = 0, segment = elf_tdata (ibfd)->phdr;
    37514698       i < num_segments;
     
    37544701      unsigned int j;
    37554702      Elf_Internal_Phdr *segment2;
     4703
     4704      if (segment->p_type == PT_INTERP)
     4705        for (section = ibfd->sections; section; section = section->next)
     4706          if (IS_SOLARIS_PT_INTERP (segment, section))
     4707            {
     4708              /* Mininal change so that the normal section to segment
     4709                 assigment code will work.  */
     4710              segment->p_vaddr = section->vma;
     4711              break;
     4712            }
    37564713
    37574714      if (segment->p_type != PT_LOAD)
     
    38204777      bfd_vma       suggested_lma;
    38214778      unsigned int  j;
     4779      bfd_size_type amt;
    38224780
    38234781      if (segment->p_type == PT_NULL)
     
    38254783
    38264784      /* Compute how many sections might be placed into this segment.  */
    3827       section_count = 0;
    3828       for (section = ibfd->sections; section != NULL; section = section->next)
    3829         if (INCLUDE_SECTION_IN_SEGMENT (section, segment))
     4785      for (section = ibfd->sections, section_count = 0;
     4786           section != NULL;
     4787           section = section->next)
     4788        if (INCLUDE_SECTION_IN_SEGMENT (section, segment, bed))
    38304789          ++section_count;
    38314790
    3832       /* Allocate a segment map big enough to contain all of the
    3833          sections we have selected.  */
    3834       map = ((struct elf_segment_map *)
    3835            bfd_alloc (obfd,
    3836                       (sizeof (struct elf_segment_map)
    3837                        + ((size_t) section_count - 1) * sizeof (asection *))));
     4791      /* Allocate a segment map big enough to contain
     4792         all of the sections we have selected.  */
     4793      amt = sizeof (struct elf_segment_map);
     4794      amt += ((bfd_size_type) section_count - 1) * sizeof (asection *);
     4795      map = (struct elf_segment_map *) bfd_alloc (obfd, amt);
    38384796      if (map == NULL)
    3839         return false;
     4797        return FALSE;
    38404798
    38414799      /* Initialise the fields of the segment map.  Default to
     
    38644822
    38654823          if (segment->p_type == PT_LOAD && map->includes_phdrs)
    3866             phdr_included = true;
     4824            phdr_included = TRUE;
    38674825        }
    38684826
     
    38714829          /* Special segments, such as the PT_PHDR segment, may contain
    38724830             no sections, but ordinary, loadable segments should contain
    3873              something.  */
     4831             something.  They are allowed by the ELF spec however, so only
     4832             a warning is produced.  */
    38744833          if (segment->p_type == PT_LOAD)
    3875               _bfd_error_handler
    3876                 (_("%s: warning: Empty loadable segment detected\n"),
    3877                  bfd_get_filename (ibfd));
     4834            (*_bfd_error_handler)
     4835              (_("%s: warning: Empty loadable segment detected, is this intentional ?\n"),
     4836               bfd_archive_filename (ibfd));
    38784837
    38794838          map->count = 0;
     
    39034862            have to be created to contain the other sections.
    39044863
    3905          4. The sections have been moved, but not be the same amount.
     4864         4. The sections have been moved, but not by the same amount.
    39064865            In this case we can change the segment's LMA to match the LMA
    39074866            of the first section and we will have to create a new segment
     
    39124871         to a segment, they are removed from this array.  */
    39134872
    3914       sections = (asection **) bfd_malloc
    3915         (sizeof (asection *) * section_count);
     4873      /* Gcc 2.96 miscompiles this code on mips. Don't do casting here
     4874         to work around this long long bug.  */
     4875      amt = section_count * sizeof (asection *);
     4876      sections = (asection **) bfd_malloc (amt);
    39164877      if (sections == NULL)
    3917         return false;
     4878        return FALSE;
    39184879
    39194880      /* Step One: Scan for segment vs section LMA conflicts.
     
    39314892           section = section->next)
    39324893        {
    3933           if (INCLUDE_SECTION_IN_SEGMENT (section, segment))
     4894          if (INCLUDE_SECTION_IN_SEGMENT (section, segment, bed))
    39344895            {
    39354896              output_section = section->output_section;
     
    39394900              /* The Solaris native linker always sets p_paddr to 0.
    39404901                 We try to catch that case here, and set it to the
    3941                  correct value.  */
     4902                 correct value.  Note - some backends require that
     4903                 p_paddr be left as zero.  */
    39424904              if (segment->p_paddr == 0
    39434905                  && segment->p_vaddr != 0
     4906                  && (! bed->want_p_paddr_set_to_zero)
    39444907                  && isec == 0
    39454908                  && output_section->lma != 0
     
    39494912                                                 : 0)
    39504913                                              + (map->includes_phdrs
    3951                                                  ? iehdr->e_phnum * iehdr->e_phentsize
     4914                                                 ? (iehdr->e_phnum
     4915                                                    * iehdr->e_phentsize)
    39524916                                                 : 0))))
    39534917                map->p_paddr = segment->p_vaddr;
     
    39564920                 LMA address of the output section.  */
    39574921              if (IS_CONTAINED_BY_LMA (output_section, segment, map->p_paddr)
    3958                   || IS_COREFILE_NOTE (segment, section))
     4922                  || IS_COREFILE_NOTE (segment, section)
     4923                  || (bed->want_p_paddr_set_to_zero &&
     4924                      IS_CONTAINED_BY_VMA (output_section, segment))
     4925                )
    39594926                {
    39604927                  if (matching_lma == 0)
     
    40254992
    40264993      /* Step Three: Loop over the sections again, this time assigning
    4027          those that fit to the current segment and remvoing them from the
     4994         those that fit to the current segment and removing them from the
    40284995         sections array; but making sure not to leave large gaps.  Once all
    40294996         possible sections have been assigned to the current segment it is
     
    40745041                         and the start of this section is more than
    40755042                         maxpagesize then we need to start a new segment.  */
    4076                       if ((BFD_ALIGN (prev_sec->lma + prev_sec->_raw_size, maxpagesize)
    4077                           < BFD_ALIGN (output_section->lma, maxpagesize))
    4078                           || ((prev_sec->lma + prev_sec->_raw_size) > output_section->lma))
     5043                      if ((BFD_ALIGN (prev_sec->lma + prev_sec->_raw_size,
     5044                                      maxpagesize)
     5045                           < BFD_ALIGN (output_section->lma, maxpagesize))
     5046                          || ((prev_sec->lma + prev_sec->_raw_size)
     5047                              > output_section->lma))
    40795048                        {
    40805049                          if (suggested_lma == 0)
     
    40885057                  ++isec;
    40895058                  sections[j] = NULL;
    4090                   section->segment_mark = true;
     5059                  section->segment_mark = TRUE;
    40915060                }
    40925061              else if (suggested_lma == 0)
     
    41055074                 segments.  Create a new segment here, initialise it
    41065075                 and carry on looping.  */
    4107               map = ((struct elf_segment_map *)
    4108                      bfd_alloc (obfd,
    4109                                 (sizeof (struct elf_segment_map)
    4110                                  + ((size_t) section_count - 1)
    4111                                  * sizeof (asection *))));
     5076              amt = sizeof (struct elf_segment_map);
     5077              amt += ((bfd_size_type) section_count - 1) * sizeof (asection *);
     5078              map = (struct elf_segment_map *) bfd_alloc (obfd, amt);
    41125079              if (map == NULL)
    4113                 return false;
     5080                {
     5081                  free (sections);
     5082                  return FALSE;
     5083                }
    41145084
    41155085              /* Initialise the fields of the segment map.  Set the physical
     
    41395109      break;
    41405110  if (map == NULL)
    4141     {
    4142       for (map = map_first; map != NULL; map = map->next)
    4143         map->p_paddr_valid = 0;
    4144     }
     5111    for (map = map_first; map != NULL; map = map->next)
     5112      map->p_paddr_valid = 0;
    41455113
    41465114  elf_tdata (obfd)->segment_map = map_first;
    41475115
    41485116  /* If we had to estimate the number of program headers that were
    4149      going to be needed, then check our estimate know and adjust
     5117     going to be needed, then check our estimate now and adjust
    41505118     the offset if necessary.  */
    41515119  if (phdr_adjust_seg != NULL)
     
    41875155
    41885156#undef SEGMENT_END
     5157#undef SECTION_SIZE
    41895158#undef IS_CONTAINED_BY_VMA
    41905159#undef IS_CONTAINED_BY_LMA
     
    41945163#undef SEGMENT_AFTER_SEGMENT
    41955164#undef SEGMENT_OVERLAPS
    4196   return true;
     5165  return TRUE;
    41975166}
    41985167
     
    42005169   field, and sometimes the info field.  */
    42015170
    4202 boolean
     5171bfd_boolean
    42035172_bfd_elf_copy_private_section_data (ibfd, isec, obfd, osec)
    42045173     bfd *ibfd;
     
    42115180  if (ibfd->xvec->flavour != bfd_target_elf_flavour
    42125181      || obfd->xvec->flavour != bfd_target_elf_flavour)
    4213     return true;
    4214 
    4215   /* Copy over private BFD data if it has not already been copied.
    4216      This must be done here, rather than in the copy_private_bfd_data
    4217      entry point, because the latter is called after the section
    4218      contents have been set, which means that the program headers have
    4219      already been worked out.  */
    4220   if (elf_tdata (obfd)->segment_map == NULL
    4221       && elf_tdata (ibfd)->phdr != NULL)
    4222     {
    4223       asection *s;
    4224 
    4225       /* Only set up the segments if there are no more SEC_ALLOC
    4226          sections.  FIXME: This won't do the right thing if objcopy is
    4227          used to remove the last SEC_ALLOC section, since objcopy
    4228          won't call this routine in that case.  */
    4229       for (s = isec->next; s != NULL; s = s->next)
    4230         if ((s->flags & SEC_ALLOC) != 0)
    4231           break;
    4232       if (s == NULL)
    4233         {
    4234           if (! copy_private_bfd_data (ibfd, obfd))
    4235             return false;
    4236         }
     5182    return TRUE;
     5183
     5184  if (elf_tdata (obfd)->segment_map == NULL && elf_tdata (ibfd)->phdr != NULL)
     5185    {
     5186        asection *s;
     5187
     5188        /* Only set up the segments if there are no more SEC_ALLOC
     5189           sections.  FIXME: This won't do the right thing if objcopy is
     5190           used to remove the last SEC_ALLOC section, since objcopy
     5191           won't call this routine in that case.  */
     5192        for (s = isec->next; s != NULL; s = s->next)
     5193          if ((s->flags & SEC_ALLOC) != 0)
     5194            break;
     5195        if (s == NULL)
     5196          {
     5197            if (! copy_private_bfd_data (ibfd, obfd))
     5198              return FALSE;
     5199          }
    42375200    }
    42385201
     
    42485211    ohdr->sh_info = ihdr->sh_info;
    42495212
    4250   elf_section_data (osec)->use_rela_p
    4251     = elf_section_data (isec)->use_rela_p;
    4252 
    4253   return true;
     5213  /* Set things up for objcopy.  The output SHT_GROUP section will
     5214     have its elf_next_in_group pointing back to the input group
     5215     members.  */
     5216  elf_next_in_group (osec) = elf_next_in_group (isec);
     5217  elf_group_name (osec) = elf_group_name (isec);
     5218
     5219  osec->use_rela_p = isec->use_rela_p;
     5220
     5221  return TRUE;
    42545222}
    42555223
     
    42605228   swap_out_syms function.  */
    42615229
    4262 #define MAP_ONESYMTAB (SHN_LORESERVE - 1)
    4263 #define MAP_DYNSYMTAB (SHN_LORESERVE - 2)
    4264 #define MAP_STRTAB (SHN_LORESERVE - 3)
    4265 #define MAP_SHSTRTAB (SHN_LORESERVE - 4)
    4266 
    4267 boolean
     5230#define MAP_ONESYMTAB (SHN_HIOS + 1)
     5231#define MAP_DYNSYMTAB (SHN_HIOS + 2)
     5232#define MAP_STRTAB    (SHN_HIOS + 3)
     5233#define MAP_SHSTRTAB  (SHN_HIOS + 4)
     5234#define MAP_SYM_SHNDX (SHN_HIOS + 5)
     5235
     5236bfd_boolean
    42685237_bfd_elf_copy_private_symbol_data (ibfd, isymarg, obfd, osymarg)
    42695238     bfd *ibfd;
     
    42765245  if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
    42775246      || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
    4278     return true;
     5247    return TRUE;
    42795248
    42805249  isym = elf_symbol_from (ibfd, isymarg);
     
    42965265      else if (shndx == elf_tdata (ibfd)->shstrtab_section)
    42975266        shndx = MAP_SHSTRTAB;
     5267      else if (shndx == elf_tdata (ibfd)->symtab_shndx_section)
     5268        shndx = MAP_SYM_SHNDX;
    42985269      osym->internal_elf_sym.st_shndx = shndx;
    42995270    }
    43005271
    4301   return true;
     5272  return TRUE;
    43025273}
    43035274
    43045275/* Swap out the symbols.  */
    43055276
    4306 static boolean
     5277static bfd_boolean
    43075278swap_out_syms (abfd, sttp, relocatable_p)
    43085279     bfd *abfd;
     
    43105281     int relocatable_p;
    43115282{
    4312   struct elf_backend_data *bed = get_elf_backend_data (abfd);
     5283  struct elf_backend_data *bed;
     5284  int symcount;
     5285  asymbol **syms;
     5286  struct bfd_strtab_hash *stt;
     5287  Elf_Internal_Shdr *symtab_hdr;
     5288  Elf_Internal_Shdr *symtab_shndx_hdr;
     5289  Elf_Internal_Shdr *symstrtab_hdr;
     5290  char *outbound_syms;
     5291  char *outbound_shndx;
     5292  int idx;
     5293  bfd_size_type amt;
    43135294
    43145295  if (!elf_map_symbols (abfd))
    4315     return false;
     5296    return FALSE;
    43165297
    43175298  /* Dump out the symtabs.  */
     5299  stt = _bfd_elf_stringtab_init ();
     5300  if (stt == NULL)
     5301    return FALSE;
     5302
     5303  bed = get_elf_backend_data (abfd);
     5304  symcount = bfd_get_symcount (abfd);
     5305  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
     5306  symtab_hdr->sh_type = SHT_SYMTAB;
     5307  symtab_hdr->sh_entsize = bed->s->sizeof_sym;
     5308  symtab_hdr->sh_size = symtab_hdr->sh_entsize * (symcount + 1);
     5309  symtab_hdr->sh_info = elf_num_locals (abfd) + 1;
     5310  symtab_hdr->sh_addralign = bed->s->file_align;
     5311
     5312  symstrtab_hdr = &elf_tdata (abfd)->strtab_hdr;
     5313  symstrtab_hdr->sh_type = SHT_STRTAB;
     5314
     5315  amt = (bfd_size_type) (1 + symcount) * bed->s->sizeof_sym;
     5316  outbound_syms = bfd_alloc (abfd, amt);
     5317  if (outbound_syms == NULL)
     5318    {
     5319      _bfd_stringtab_free (stt);
     5320      return FALSE;
     5321    }
     5322  symtab_hdr->contents = (PTR) outbound_syms;
     5323
     5324  outbound_shndx = NULL;
     5325  symtab_shndx_hdr = &elf_tdata (abfd)->symtab_shndx_hdr;
     5326  if (symtab_shndx_hdr->sh_name != 0)
     5327    {
     5328      amt = (bfd_size_type) (1 + symcount) * sizeof (Elf_External_Sym_Shndx);
     5329      outbound_shndx = bfd_zalloc (abfd, amt);
     5330      if (outbound_shndx == NULL)
     5331        {
     5332          _bfd_stringtab_free (stt);
     5333          return FALSE;
     5334        }
     5335
     5336      symtab_shndx_hdr->contents = outbound_shndx;
     5337      symtab_shndx_hdr->sh_type = SHT_SYMTAB_SHNDX;
     5338      symtab_shndx_hdr->sh_size = amt;
     5339      symtab_shndx_hdr->sh_addralign = sizeof (Elf_External_Sym_Shndx);
     5340      symtab_shndx_hdr->sh_entsize = sizeof (Elf_External_Sym_Shndx);
     5341    }
     5342
     5343  /* Now generate the data (for "contents").  */
    43185344  {
    4319     int symcount = bfd_get_symcount (abfd);
    4320     asymbol **syms = bfd_get_outsymbols (abfd);
    4321     struct bfd_strtab_hash *stt;
    4322     Elf_Internal_Shdr *symtab_hdr;
    4323     Elf_Internal_Shdr *symstrtab_hdr;
    4324     char *outbound_syms;
    4325     int idx;
    4326 
    4327     stt = _bfd_elf_stringtab_init ();
    4328     if (stt == NULL)
    4329       return false;
    4330 
    4331     symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
    4332     symtab_hdr->sh_type = SHT_SYMTAB;
    4333     symtab_hdr->sh_entsize = bed->s->sizeof_sym;
    4334     symtab_hdr->sh_size = symtab_hdr->sh_entsize * (symcount + 1);
    4335     symtab_hdr->sh_info = elf_num_locals (abfd) + 1;
    4336     symtab_hdr->sh_addralign = bed->s->file_align;
    4337 
    4338     symstrtab_hdr = &elf_tdata (abfd)->strtab_hdr;
    4339     symstrtab_hdr->sh_type = SHT_STRTAB;
    4340 
    4341     outbound_syms = bfd_alloc (abfd,
    4342                                (1 + symcount) * bed->s->sizeof_sym);
    4343     if (outbound_syms == NULL)
    4344       return false;
    4345     symtab_hdr->contents = (PTR) outbound_syms;
    4346 
    4347     /* now generate the data (for "contents") */
    4348     {
    4349       /* Fill in zeroth symbol and swap it out.  */
     5345    /* Fill in zeroth symbol and swap it out.  */
     5346    Elf_Internal_Sym sym;
     5347    sym.st_name = 0;
     5348    sym.st_value = 0;
     5349    sym.st_size = 0;
     5350    sym.st_info = 0;
     5351    sym.st_other = 0;
     5352    sym.st_shndx = SHN_UNDEF;
     5353    bed->s->swap_symbol_out (abfd, &sym, outbound_syms, outbound_shndx);
     5354    outbound_syms += bed->s->sizeof_sym;
     5355    if (outbound_shndx != NULL)
     5356      outbound_shndx += sizeof (Elf_External_Sym_Shndx);
     5357  }
     5358
     5359  syms = bfd_get_outsymbols (abfd);
     5360  for (idx = 0; idx < symcount; idx++)
     5361    {
    43505362      Elf_Internal_Sym sym;
    4351       sym.st_name = 0;
    4352       sym.st_value = 0;
    4353       sym.st_size = 0;
    4354       sym.st_info = 0;
    4355       sym.st_other = 0;
    4356       sym.st_shndx = SHN_UNDEF;
    4357       bed->s->swap_symbol_out (abfd, &sym, (PTR) outbound_syms);
     5363      bfd_vma value = syms[idx]->value;
     5364      elf_symbol_type *type_ptr;
     5365      flagword flags = syms[idx]->flags;
     5366      int type;
     5367
     5368      if ((flags & (BSF_SECTION_SYM | BSF_GLOBAL)) == BSF_SECTION_SYM)
     5369        {
     5370          /* Local section symbols have no name.  */
     5371          sym.st_name = 0;
     5372        }
     5373      else
     5374        {
     5375          sym.st_name = (unsigned long) _bfd_stringtab_add (stt,
     5376                                                            syms[idx]->name,
     5377                                                            TRUE, FALSE);
     5378          if (sym.st_name == (unsigned long) -1)
     5379            {
     5380              _bfd_stringtab_free (stt);
     5381              return FALSE;
     5382            }
     5383        }
     5384
     5385      type_ptr = elf_symbol_from (abfd, syms[idx]);
     5386
     5387      if ((flags & BSF_SECTION_SYM) == 0
     5388          && bfd_is_com_section (syms[idx]->section))
     5389        {
     5390          /* ELF common symbols put the alignment into the `value' field,
     5391             and the size into the `size' field.  This is backwards from
     5392             how BFD handles it, so reverse it here.  */
     5393          sym.st_size = value;
     5394          if (type_ptr == NULL
     5395              || type_ptr->internal_elf_sym.st_value == 0)
     5396            sym.st_value = value >= 16 ? 16 : (1 << bfd_log2 (value));
     5397          else
     5398            sym.st_value = type_ptr->internal_elf_sym.st_value;
     5399          sym.st_shndx = _bfd_elf_section_from_bfd_section
     5400            (abfd, syms[idx]->section);
     5401        }
     5402      else
     5403        {
     5404          asection *sec = syms[idx]->section;
     5405          int shndx;
     5406
     5407          if (sec->output_section)
     5408            {
     5409              value += sec->output_offset;
     5410              sec = sec->output_section;
     5411            }
     5412
     5413          /* Don't add in the section vma for relocatable output.  */
     5414          if (! relocatable_p)
     5415            value += sec->vma;
     5416          sym.st_value = value;
     5417          sym.st_size = type_ptr ? type_ptr->internal_elf_sym.st_size : 0;
     5418
     5419          if (bfd_is_abs_section (sec)
     5420              && type_ptr != NULL
     5421              && type_ptr->internal_elf_sym.st_shndx != 0)
     5422            {
     5423              /* This symbol is in a real ELF section which we did
     5424                 not create as a BFD section.  Undo the mapping done
     5425                 by copy_private_symbol_data.  */
     5426              shndx = type_ptr->internal_elf_sym.st_shndx;
     5427              switch (shndx)
     5428                {
     5429                case MAP_ONESYMTAB:
     5430                  shndx = elf_onesymtab (abfd);
     5431                  break;
     5432                case MAP_DYNSYMTAB:
     5433                  shndx = elf_dynsymtab (abfd);
     5434                  break;
     5435                case MAP_STRTAB:
     5436                  shndx = elf_tdata (abfd)->strtab_section;
     5437                  break;
     5438                case MAP_SHSTRTAB:
     5439                  shndx = elf_tdata (abfd)->shstrtab_section;
     5440                  break;
     5441                case MAP_SYM_SHNDX:
     5442                  shndx = elf_tdata (abfd)->symtab_shndx_section;
     5443                  break;
     5444                default:
     5445                  break;
     5446                }
     5447            }
     5448          else
     5449            {
     5450              shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
     5451
     5452              if (shndx == -1)
     5453                {
     5454                  asection *sec2;
     5455
     5456                  /* Writing this would be a hell of a lot easier if
     5457                     we had some decent documentation on bfd, and
     5458                     knew what to expect of the library, and what to
     5459                     demand of applications.  For example, it
     5460                     appears that `objcopy' might not set the
     5461                     section of a symbol to be a section that is
     5462                     actually in the output file.  */
     5463                  sec2 = bfd_get_section_by_name (abfd, sec->name);
     5464                  if (sec2 == NULL)
     5465                    {
     5466                      _bfd_error_handler (_("\
     5467Unable to find equivalent output section for symbol '%s' from section '%s'"),
     5468                                          syms[idx]->name ? syms[idx]->name : "<Local sym>",
     5469                                          sec->name);
     5470                      bfd_set_error (bfd_error_invalid_operation);
     5471                      _bfd_stringtab_free (stt);
     5472                      return FALSE;
     5473                    }
     5474
     5475                  shndx = _bfd_elf_section_from_bfd_section (abfd, sec2);
     5476                  BFD_ASSERT (shndx != -1);
     5477                }
     5478            }
     5479
     5480          sym.st_shndx = shndx;
     5481        }
     5482
     5483      if ((flags & BSF_THREAD_LOCAL) != 0)
     5484        type = STT_TLS;
     5485      else if ((flags & BSF_FUNCTION) != 0)
     5486        type = STT_FUNC;
     5487      else if ((flags & BSF_OBJECT) != 0)
     5488        type = STT_OBJECT;
     5489      else
     5490        type = STT_NOTYPE;
     5491
     5492      if (syms[idx]->section->flags & SEC_THREAD_LOCAL)
     5493        type = STT_TLS;
     5494
     5495      /* Processor-specific types.  */
     5496      if (type_ptr != NULL
     5497          && bed->elf_backend_get_symbol_type)
     5498        type = ((*bed->elf_backend_get_symbol_type)
     5499                (&type_ptr->internal_elf_sym, type));
     5500
     5501      if (flags & BSF_SECTION_SYM)
     5502        {
     5503          if (flags & BSF_GLOBAL)
     5504            sym.st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
     5505          else
     5506            sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_SECTION);
     5507        }
     5508      else if (bfd_is_com_section (syms[idx]->section))
     5509        sym.st_info = ELF_ST_INFO (STB_GLOBAL, type);
     5510      else if (bfd_is_und_section (syms[idx]->section))
     5511        sym.st_info = ELF_ST_INFO (((flags & BSF_WEAK)
     5512                                    ? STB_WEAK
     5513                                    : STB_GLOBAL),
     5514                                   type);
     5515      else if (flags & BSF_FILE)
     5516        sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FILE);
     5517      else
     5518        {
     5519          int bind = STB_LOCAL;
     5520
     5521          if (flags & BSF_LOCAL)
     5522            bind = STB_LOCAL;
     5523          else if (flags & BSF_WEAK)
     5524            bind = STB_WEAK;
     5525          else if (flags & BSF_GLOBAL)
     5526            bind = STB_GLOBAL;
     5527
     5528          sym.st_info = ELF_ST_INFO (bind, type);
     5529        }
     5530
     5531      if (type_ptr != NULL)
     5532        sym.st_other = type_ptr->internal_elf_sym.st_other;
     5533      else
     5534        sym.st_other = 0;
     5535
     5536      bed->s->swap_symbol_out (abfd, &sym, outbound_syms, outbound_shndx);
    43585537      outbound_syms += bed->s->sizeof_sym;
    4359     }
    4360     for (idx = 0; idx < symcount; idx++)
    4361       {
    4362         Elf_Internal_Sym sym;
    4363         bfd_vma value = syms[idx]->value;
    4364         elf_symbol_type *type_ptr;
    4365         flagword flags = syms[idx]->flags;
    4366         int type;
    4367 
    4368         if ((flags & BSF_SECTION_SYM) != 0)
    4369           {
    4370             /* Section symbols have no name.  */
    4371             sym.st_name = 0;
    4372           }
    4373         else
    4374           {
    4375             sym.st_name = (unsigned long) _bfd_stringtab_add (stt,
    4376                                                               syms[idx]->name,
    4377                                                               true, false);
    4378             if (sym.st_name == (unsigned long) -1)
    4379               return false;
    4380           }
    4381 
    4382         type_ptr = elf_symbol_from (abfd, syms[idx]);
    4383 
    4384         if ((flags & BSF_SECTION_SYM) == 0
    4385             && bfd_is_com_section (syms[idx]->section))
    4386           {
    4387             /* ELF common symbols put the alignment into the `value' field,
    4388                and the size into the `size' field.  This is backwards from
    4389                how BFD handles it, so reverse it here.  */
    4390             sym.st_size = value;
    4391             if (type_ptr == NULL
    4392                 || type_ptr->internal_elf_sym.st_value == 0)
    4393               sym.st_value = value >= 16 ? 16 : (1 << bfd_log2 (value));
    4394             else
    4395               sym.st_value = type_ptr->internal_elf_sym.st_value;
    4396             sym.st_shndx = _bfd_elf_section_from_bfd_section
    4397               (abfd, syms[idx]->section);
    4398           }
    4399         else
    4400           {
    4401             asection *sec = syms[idx]->section;
    4402             int shndx;
    4403 
    4404             if (sec->output_section)
    4405               {
    4406                 value += sec->output_offset;
    4407                 sec = sec->output_section;
    4408               }
    4409             /* Don't add in the section vma for relocatable output.  */
    4410             if (! relocatable_p)
    4411               value += sec->vma;
    4412             sym.st_value = value;
    4413             sym.st_size = type_ptr ? type_ptr->internal_elf_sym.st_size : 0;
    4414 
    4415             if (bfd_is_abs_section (sec)
    4416                 && type_ptr != NULL
    4417                 && type_ptr->internal_elf_sym.st_shndx != 0)
    4418               {
    4419                 /* This symbol is in a real ELF section which we did
    4420                    not create as a BFD section.  Undo the mapping done
    4421                    by copy_private_symbol_data.  */
    4422                 shndx = type_ptr->internal_elf_sym.st_shndx;
    4423                 switch (shndx)
    4424                   {
    4425                   case MAP_ONESYMTAB:
    4426                     shndx = elf_onesymtab (abfd);
    4427                     break;
    4428                   case MAP_DYNSYMTAB:
    4429                     shndx = elf_dynsymtab (abfd);
    4430                     break;
    4431                   case MAP_STRTAB:
    4432                     shndx = elf_tdata (abfd)->strtab_section;
    4433                     break;
    4434                   case MAP_SHSTRTAB:
    4435                     shndx = elf_tdata (abfd)->shstrtab_section;
    4436                     break;
    4437                   default:
    4438                     break;
    4439                   }
    4440               }
    4441             else
    4442               {
    4443                 shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
    4444 
    4445                 if (shndx == -1)
    4446                   {
    4447                     asection *sec2;
    4448 
    4449                     /* Writing this would be a hell of a lot easier if
    4450                        we had some decent documentation on bfd, and
    4451                        knew what to expect of the library, and what to
    4452                        demand of applications.  For example, it
    4453                        appears that `objcopy' might not set the
    4454                        section of a symbol to be a section that is
    4455                        actually in the output file.  */
    4456                     sec2 = bfd_get_section_by_name (abfd, sec->name);
    4457                     BFD_ASSERT (sec2 != 0);
    4458                     shndx = _bfd_elf_section_from_bfd_section (abfd, sec2);
    4459                     BFD_ASSERT (shndx != -1);
    4460                   }
    4461               }
    4462 
    4463             sym.st_shndx = shndx;
    4464           }
    4465 
    4466         if ((flags & BSF_FUNCTION) != 0)
    4467           type = STT_FUNC;
    4468         else if ((flags & BSF_OBJECT) != 0)
    4469           type = STT_OBJECT;
    4470         else
    4471           type = STT_NOTYPE;
    4472 
    4473         /* Processor-specific types */
    4474         if (type_ptr != NULL
    4475             && bed->elf_backend_get_symbol_type)
    4476           type = (*bed->elf_backend_get_symbol_type) (&type_ptr->internal_elf_sym, type);
    4477 
    4478         if (flags & BSF_SECTION_SYM)
    4479           sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_SECTION);
    4480         else if (bfd_is_com_section (syms[idx]->section))
    4481           sym.st_info = ELF_ST_INFO (STB_GLOBAL, type);
    4482         else if (bfd_is_und_section (syms[idx]->section))
    4483           sym.st_info = ELF_ST_INFO (((flags & BSF_WEAK)
    4484                                       ? STB_WEAK
    4485                                       : STB_GLOBAL),
    4486                                      type);
    4487         else if (flags & BSF_FILE)
    4488           sym.st_info = ELF_ST_INFO (STB_LOCAL, STT_FILE);
    4489         else
    4490           {
    4491             int bind = STB_LOCAL;
    4492 
    4493             if (flags & BSF_LOCAL)
    4494               bind = STB_LOCAL;
    4495             else if (flags & BSF_WEAK)
    4496               bind = STB_WEAK;
    4497             else if (flags & BSF_GLOBAL)
    4498               bind = STB_GLOBAL;
    4499 
    4500             sym.st_info = ELF_ST_INFO (bind, type);
    4501           }
    4502 
    4503         if (type_ptr != NULL)
    4504           sym.st_other = type_ptr->internal_elf_sym.st_other;
    4505         else
    4506           sym.st_other = 0;
    4507 
    4508         bed->s->swap_symbol_out (abfd, &sym, (PTR) outbound_syms);
    4509         outbound_syms += bed->s->sizeof_sym;
    4510       }
    4511 
    4512     *sttp = stt;
    4513     symstrtab_hdr->sh_size = _bfd_stringtab_size (stt);
    4514     symstrtab_hdr->sh_type = SHT_STRTAB;
    4515 
    4516     symstrtab_hdr->sh_flags = 0;
    4517     symstrtab_hdr->sh_addr = 0;
    4518     symstrtab_hdr->sh_entsize = 0;
    4519     symstrtab_hdr->sh_link = 0;
    4520     symstrtab_hdr->sh_info = 0;
    4521     symstrtab_hdr->sh_addralign = 1;
    4522   }
    4523 
    4524   return true;
     5538      if (outbound_shndx != NULL)
     5539        outbound_shndx += sizeof (Elf_External_Sym_Shndx);
     5540    }
     5541
     5542  *sttp = stt;
     5543  symstrtab_hdr->sh_size = _bfd_stringtab_size (stt);
     5544  symstrtab_hdr->sh_type = SHT_STRTAB;
     5545
     5546  symstrtab_hdr->sh_flags = 0;
     5547  symstrtab_hdr->sh_addr = 0;
     5548  symstrtab_hdr->sh_entsize = 0;
     5549  symstrtab_hdr->sh_link = 0;
     5550  symstrtab_hdr->sh_info = 0;
     5551  symstrtab_hdr->sh_addralign = 1;
     5552
     5553  return TRUE;
    45255554}
    45265555
     
    45405569
    45415570  symcount = hdr->sh_size / get_elf_backend_data (abfd)->s->sizeof_sym;
    4542   symtab_size = (symcount - 1 + 1) * (sizeof (asymbol *));
     5571  symtab_size = (symcount + 1) * (sizeof (asymbol *));
     5572  if (symcount > 0)
     5573    symtab_size -= sizeof (asymbol *);
    45435574
    45445575  return symtab_size;
     
    45605591
    45615592  symcount = hdr->sh_size / get_elf_backend_data (abfd)->s->sizeof_sym;
    4562   symtab_size = (symcount - 1 + 1) * (sizeof (asymbol *));
     5593  symtab_size = (symcount + 1) * (sizeof (asymbol *));
     5594  if (symcount > 0)
     5595    symtab_size -= sizeof (asymbol *);
    45635596
    45645597  return symtab_size;
     
    45845617  arelent *tblptr;
    45855618  unsigned int i;
    4586 
    4587   if (! get_elf_backend_data (abfd)->s->slurp_reloc_table (abfd,
    4588                                                            section,
    4589                                                            symbols,
    4590                                                            false))
     5619  struct elf_backend_data *bed = get_elf_backend_data (abfd);
     5620
     5621  if (! bed->s->slurp_reloc_table (abfd, section, symbols, FALSE))
    45915622    return -1;
    45925623
     
    46055636     asymbol **alocation;
    46065637{
    4607   long symcount = get_elf_backend_data (abfd)->s->slurp_symbol_table
    4608     (abfd, alocation, false);
     5638  struct elf_backend_data *bed = get_elf_backend_data (abfd);
     5639  long symcount = bed->s->slurp_symbol_table (abfd, alocation, FALSE);
    46095640
    46105641  if (symcount >= 0)
     
    46185649     asymbol **alocation;
    46195650{
    4620   return get_elf_backend_data (abfd)->s->slurp_symbol_table
    4621     (abfd, alocation, true);
     5651  struct elf_backend_data *bed = get_elf_backend_data (abfd);
     5652  long symcount = bed->s->slurp_symbol_table (abfd, alocation, TRUE);
     5653
     5654  if (symcount >= 0)
     5655    bfd_get_dynamic_symcount (abfd) = symcount;
     5656  return symcount;
    46225657}
    46235658
     
    46665701     asymbol **syms;
    46675702{
    4668   boolean (*slurp_relocs) PARAMS ((bfd *, asection *, asymbol **, boolean));
     5703  bfd_boolean (*slurp_relocs)
     5704    PARAMS ((bfd *, asection *, asymbol **, bfd_boolean));
    46695705  asection *s;
    46705706  long ret;
     
    46875723          long count, i;
    46885724
    4689           if (! (*slurp_relocs) (abfd, s, syms, true))
     5725          if (! (*slurp_relocs) (abfd, s, syms, TRUE))
    46905726            return -1;
    46915727          count = s->_raw_size / elf_section_data (s)->this_hdr.sh_entsize;
     
    47055741/* Read in the version information.  */
    47065742
    4707 boolean
     5743bfd_boolean
    47085744_bfd_elf_slurp_version_tables (abfd)
    47095745     bfd *abfd;
    47105746{
    47115747  bfd_byte *contents = NULL;
     5748  bfd_size_type amt;
    47125749
    47135750  if (elf_dynverdef (abfd) != 0)
     
    47275764        goto error_return;
    47285765      if (bfd_seek (abfd, hdr->sh_offset, SEEK_SET) != 0
    4729           || bfd_read ((PTR) contents, 1, hdr->sh_size, abfd) != hdr->sh_size)
     5766          || bfd_bread ((PTR) contents, hdr->sh_size, abfd) != hdr->sh_size)
    47305767        goto error_return;
    47315768
     
    47465783        }
    47475784
    4748       elf_tdata (abfd)->verdef =
    4749         ((Elf_Internal_Verdef *)
    4750          bfd_zalloc (abfd, maxidx * sizeof (Elf_Internal_Verdef)));
     5785      amt = (bfd_size_type) maxidx * sizeof (Elf_Internal_Verdef);
     5786      elf_tdata (abfd)->verdef = (Elf_Internal_Verdef *) bfd_zalloc (abfd, amt);
    47515787      if (elf_tdata (abfd)->verdef == NULL)
    47525788        goto error_return;
     
    47695805          iverdef->vd_bfd = abfd;
    47705806
    4771           iverdef->vd_auxptr = ((Elf_Internal_Verdaux *)
    4772                                 bfd_alloc (abfd,
    4773                                            (iverdef->vd_cnt
    4774                                             * sizeof (Elf_Internal_Verdaux))));
     5807          amt = (bfd_size_type) iverdef->vd_cnt * sizeof (Elf_Internal_Verdaux);
     5808          iverdef->vd_auxptr = (Elf_Internal_Verdaux *) bfd_alloc (abfd, amt);
    47755809          if (iverdef->vd_auxptr == NULL)
    47765810            goto error_return;
     
    48225856      hdr = &elf_tdata (abfd)->dynverref_hdr;
    48235857
     5858      amt = (bfd_size_type) hdr->sh_info * sizeof (Elf_Internal_Verneed);
    48245859      elf_tdata (abfd)->verref =
    4825         ((Elf_Internal_Verneed *)
    4826          bfd_zalloc (abfd, hdr->sh_info * sizeof (Elf_Internal_Verneed)));
     5860        (Elf_Internal_Verneed *) bfd_zalloc (abfd, amt);
    48275861      if (elf_tdata (abfd)->verref == NULL)
    48285862        goto error_return;
     
    48345868        goto error_return;
    48355869      if (bfd_seek (abfd, hdr->sh_offset, SEEK_SET) != 0
    4836           || bfd_read ((PTR) contents, 1, hdr->sh_size, abfd) != hdr->sh_size)
     5870          || bfd_bread ((PTR) contents, hdr->sh_size, abfd) != hdr->sh_size)
    48375871        goto error_return;
    48385872
     
    48555889            goto error_return;
    48565890
    4857           iverneed->vn_auxptr =
    4858             ((Elf_Internal_Vernaux *)
    4859              bfd_alloc (abfd,
    4860                         iverneed->vn_cnt * sizeof (Elf_Internal_Vernaux)));
     5891          amt = iverneed->vn_cnt;
     5892          amt *= sizeof (Elf_Internal_Vernaux);
     5893          iverneed->vn_auxptr = (Elf_Internal_Vernaux *) bfd_alloc (abfd, amt);
    48615894
    48625895          evernaux = ((Elf_External_Vernaux *)
     
    48955928    }
    48965929
    4897   return true;
     5930  return TRUE;
    48985931
    48995932 error_return:
    4900   if (contents == NULL)
     5933  if (contents != NULL)
    49015934    free (contents);
    4902   return false;
     5935  return FALSE;
    49035936}
    49045937
     
    49095942{
    49105943  elf_symbol_type *newsym;
    4911 
    4912   newsym = (elf_symbol_type *) bfd_zalloc (abfd, sizeof (elf_symbol_type));
     5944  bfd_size_type amt = sizeof (elf_symbol_type);
     5945
     5946  newsym = (elf_symbol_type *) bfd_zalloc (abfd, amt);
    49135947  if (!newsym)
    49145948    return NULL;
     
    49335967   override it.  */
    49345968
    4935 boolean
     5969bfd_boolean
    49365970_bfd_elf_is_local_label_name (abfd, name)
    49375971     bfd *abfd ATTRIBUTE_UNUSED;
     
    49405974  /* Normal local symbols start with ``.L''.  */
    49415975  if (name[0] == '.' && name[1] == 'L')
    4942     return true;
     5976    return TRUE;
    49435977
    49445978  /* At least some SVR4 compilers (e.g., UnixWare 2.1 cc) generate
    49455979     DWARF debugging symbols starting with ``..''.  */
    49465980  if (name[0] == '.' && name[1] == '.')
    4947     return true;
     5981    return TRUE;
    49485982
    49495983  /* gcc will sometimes generate symbols beginning with ``_.L_'' when
     
    49545988     we treat such symbols as local.  */
    49555989  if (name[0] == '_' && name[1] == '.' && name[2] == 'L' && name[3] == '_')
    4956     return true;
    4957 
    4958   return false;
     5990    return TRUE;
     5991
     5992  return FALSE;
    49595993}
    49605994
     
    49686002}
    49696003
    4970 boolean
     6004bfd_boolean
    49716005_bfd_elf_set_arch_mach (abfd, arch, machine)
    49726006     bfd *abfd;
     
    49796013      && arch != bfd_arch_unknown
    49806014      && get_elf_backend_data (abfd)->arch != bfd_arch_unknown)
    4981     return false;
     6015    return FALSE;
    49826016
    49836017  return bfd_default_set_arch_mach (abfd, arch, machine);
     
    49876021   for error reporting.  */
    49886022
    4989 static boolean
     6023static bfd_boolean
    49906024elf_find_function (abfd, section, symbols, offset,
    49916025                   filename_ptr, functionname_ptr)
     
    50366070
    50376071  if (func == NULL)
    5038     return false;
     6072    return FALSE;
    50396073
    50406074  if (filename_ptr)
     
    50436077    *functionname_ptr = bfd_asymbol_name (func);
    50446078
    5045   return true;
     6079  return TRUE;
    50466080}
    50476081
     
    50496083   for error reporting.  */
    50506084
    5051 boolean
     6085bfd_boolean
    50526086_bfd_elf_find_nearest_line (abfd, section, symbols, offset,
    50536087                            filename_ptr, functionname_ptr, line_ptr)
     
    50606094     unsigned int *line_ptr;
    50616095{
    5062   boolean found;
     6096  bfd_boolean found;
    50636097
    50646098  if (_bfd_dwarf1_find_nearest_line (abfd, section, symbols, offset,
     
    50716105                           functionname_ptr);
    50726106
    5073       return true;
     6107      return TRUE;
    50746108    }
    50756109
     
    50846118                           functionname_ptr);
    50856119
    5086       return true;
     6120      return TRUE;
    50876121    }
    50886122
     
    50916125                                             functionname_ptr, line_ptr,
    50926126                                             &elf_tdata (abfd)->line_info))
    5093     return false;
    5094   if (found)
    5095     return true;
     6127    return FALSE;
     6128  if (found && (*functionname_ptr || *line_ptr))
     6129    return TRUE;
    50966130
    50976131  if (symbols == NULL)
    5098     return false;
     6132    return FALSE;
    50996133
    51006134  if (! elf_find_function (abfd, section, symbols, offset,
    51016135                           filename_ptr, functionname_ptr))
    5102     return false;
     6136    return FALSE;
    51036137
    51046138  *line_ptr = 0;
    5105   return true;
     6139  return TRUE;
    51066140}
    51076141
     
    51096143_bfd_elf_sizeof_headers (abfd, reloc)
    51106144     bfd *abfd;
    5111      boolean reloc;
     6145     bfd_boolean reloc;
    51126146{
    51136147  int ret;
     
    51196153}
    51206154
    5121 boolean
     6155bfd_boolean
    51226156_bfd_elf_set_section_contents (abfd, section, location, offset, count)
    51236157     bfd *abfd;
     
    51286162{
    51296163  Elf_Internal_Shdr *hdr;
     6164  bfd_signed_vma pos;
    51306165
    51316166  if (! abfd->output_has_begun
    5132       && ! _bfd_elf_compute_section_file_positions
    5133       (abfd, (struct bfd_link_info *) NULL))
    5134     return false;
     6167      && ! (_bfd_elf_compute_section_file_positions
     6168            (abfd, (struct bfd_link_info *) NULL)))
     6169    return FALSE;
    51356170
    51366171  hdr = &elf_section_data (section)->this_hdr;
    5137 
    5138   if (bfd_seek (abfd, hdr->sh_offset + offset, SEEK_SET) == -1)
    5139     return false;
    5140   if (bfd_write (location, 1, count, abfd) != count)
    5141     return false;
    5142 
    5143   return true;
     6172  pos = hdr->sh_offset + offset;
     6173  if (bfd_seek (abfd, pos, SEEK_SET) != 0
     6174      || bfd_bwrite (location, count, abfd) != count)
     6175    return FALSE;
     6176
     6177  return TRUE;
    51446178}
    51456179
     
    51536187}
    51546188
    5155 #if 0
    5156 void
    5157 _bfd_elf_no_info_to_howto_rel (abfd, cache_ptr, dst)
    5158      bfd *abfd;
    5159      arelent *cache_ptr;
    5160      Elf_Internal_Rel *dst;
    5161 {
    5162   abort ();
    5163 }
    5164 #endif
    5165 
    51666189/* Try to convert a non-ELF reloc into an ELF one.  */
    51676190
    5168 boolean
     6191bfd_boolean
    51696192_bfd_elf_validate_reloc (abfd, areloc)
    51706193     bfd *abfd;
     
    52526275    }
    52536276
    5254   return true;
     6277  return TRUE;
    52556278
    52566279 fail:
    52576280  (*_bfd_error_handler)
    52586281    (_("%s: unsupported relocation type %s"),
    5259      bfd_get_filename (abfd), areloc->howto->name);
     6282     bfd_archive_filename (abfd), areloc->howto->name);
    52606283  bfd_set_error (bfd_error_bad_value);
    5261   return false;
    5262 }
    5263 
    5264 boolean
     6284  return FALSE;
     6285}
     6286
     6287bfd_boolean
    52656288_bfd_elf_close_and_cleanup (abfd)
    52666289     bfd *abfd;
     
    52696292    {
    52706293      if (elf_shstrtab (abfd) != NULL)
    5271         _bfd_stringtab_free (elf_shstrtab (abfd));
     6294        _bfd_elf_strtab_free (elf_shstrtab (abfd));
    52726295    }
    52736296
     
    53036326#endif
    53046327
    5305 /* Define offsetof for those systems which lack it.  */
    5306 
    5307 #ifndef offsetof
    5308 # define offsetof(TYPE, MEMBER) ((unsigned long) &((TYPE *)0)->MEMBER)
    5309 #endif
    5310 
    53116328/* FIXME: this is kinda wrong, but it's what gdb wants.  */
    53126329
     
    53246341   overwrite it.  */
    53256342
    5326 static boolean
     6343static bfd_boolean
    53276344elfcore_maybe_make_sect (abfd, name, sect)
    53286345     bfd *abfd;
     
    53336350
    53346351  if (bfd_get_section_by_name (abfd, name) != NULL)
    5335     return true;
     6352    return TRUE;
    53366353
    53376354  sect2 = bfd_make_section (abfd, name);
    53386355  if (sect2 == NULL)
    5339     return false;
     6356    return FALSE;
    53406357
    53416358  sect2->_raw_size = sect->_raw_size;
     
    53436360  sect2->flags = sect->flags;
    53446361  sect2->alignment_power = sect->alignment_power;
    5345   return true;
     6362  return TRUE;
     6363}
     6364
     6365/* Create a pseudosection containing SIZE bytes at FILEPOS.  This
     6366   actually creates up to two pseudosections:
     6367   - For the single-threaded case, a section named NAME, unless
     6368     such a section already exists.
     6369   - For the multi-threaded case, a section named "NAME/PID", where
     6370     PID is elfcore_make_pid (abfd).
     6371   Both pseudosections have identical contents. */
     6372bfd_boolean
     6373_bfd_elfcore_make_pseudosection (abfd, name, size, filepos)
     6374     bfd *abfd;
     6375     char *name;
     6376     size_t size;
     6377     ufile_ptr filepos;
     6378{
     6379  char buf[100];
     6380  char *threaded_name;
     6381  size_t len;
     6382  asection *sect;
     6383
     6384  /* Build the section name.  */
     6385
     6386  sprintf (buf, "%s/%d", name, elfcore_make_pid (abfd));
     6387  len = strlen (buf) + 1;
     6388  threaded_name = bfd_alloc (abfd, (bfd_size_type) len);
     6389  if (threaded_name == NULL)
     6390    return FALSE;
     6391  memcpy (threaded_name, buf, len);
     6392
     6393  sect = bfd_make_section (abfd, threaded_name);
     6394  if (sect == NULL)
     6395    return FALSE;
     6396  sect->_raw_size = size;
     6397  sect->filepos = filepos;
     6398  sect->flags = SEC_HAS_CONTENTS;
     6399  sect->alignment_power = 2;
     6400
     6401  return elfcore_maybe_make_sect (abfd, name, sect);
    53466402}
    53476403
     
    53536409
    53546410#if defined (HAVE_PRSTATUS_T)
    5355 static boolean
     6411static bfd_boolean elfcore_grok_prstatus
     6412  PARAMS ((bfd *, Elf_Internal_Note *));
     6413
     6414static bfd_boolean
    53566415elfcore_grok_prstatus (abfd, note)
    53576416     bfd *abfd;
    53586417     Elf_Internal_Note *note;
    53596418{
    5360   char buf[100];
    5361   char *name;
    5362   asection *sect;
    5363   int raw_size;
     6419  size_t raw_size;
    53646420  int offset;
    53656421
     
    53726428      memcpy (&prstat, note->descdata, sizeof (prstat));
    53736429
    5374       elf_tdata (abfd)->core_signal = prstat.pr_cursig;
     6430      /* Do not overwrite the core signal if it
     6431         has already been set by another thread.  */
     6432      if (elf_tdata (abfd)->core_signal == 0)
     6433        elf_tdata (abfd)->core_signal = prstat.pr_cursig;
    53756434      elf_tdata (abfd)->core_pid = prstat.pr_pid;
    53766435
     
    53956454      memcpy (&prstat, note->descdata, sizeof (prstat));
    53966455
    5397       elf_tdata (abfd)->core_signal = prstat.pr_cursig;
     6456      /* Do not overwrite the core signal if it
     6457         has already been set by another thread.  */
     6458      if (elf_tdata (abfd)->core_signal == 0)
     6459        elf_tdata (abfd)->core_signal = prstat.pr_cursig;
    53986460      elf_tdata (abfd)->core_pid = prstat.pr_pid;
    53996461
     
    54136475      /* Fail - we don't know how to handle any other
    54146476         note size (ie. data object type).  */
    5415       return true;
    5416     }
    5417 
    5418   /* Make a ".reg/999" section.  */
    5419 
    5420   sprintf (buf, ".reg/%d", elfcore_make_pid (abfd));
    5421   name = bfd_alloc (abfd, strlen (buf) + 1);
    5422   if (name == NULL)
    5423     return false;
    5424   strcpy (name, buf);
    5425 
    5426   sect = bfd_make_section (abfd, name);
    5427   if (sect == NULL)
    5428     return false;
    5429 
    5430   sect->_raw_size = raw_size;
    5431   sect->filepos = note->descpos + offset;
    5432 
    5433   sect->flags = SEC_HAS_CONTENTS;
    5434   sect->alignment_power = 2;
    5435 
    5436   if (! elfcore_maybe_make_sect (abfd, ".reg", sect))
    5437     return false;
    5438 
    5439   return true;
     6477      return TRUE;
     6478    }
     6479
     6480  /* Make a ".reg/999" section and a ".reg" section.  */
     6481  return _bfd_elfcore_make_pseudosection (abfd, ".reg",
     6482                                          raw_size, note->descpos + offset);
    54406483}
    54416484#endif /* defined (HAVE_PRSTATUS_T) */
    54426485
    5443 /* Create a pseudosection containing the exact contents of NOTE.  This
    5444    actually creates up to two pseudosections:
    5445    - For the single-threaded case, a section named NAME, unless
    5446      such a section already exists.
    5447    - For the multi-threaded case, a section named "NAME/PID", where
    5448      PID is elfcore_make_pid (abfd).
    5449    Both pseudosections have identical contents: the contents of NOTE.  */
    5450 
    5451 static boolean
     6486/* Create a pseudosection containing the exact contents of NOTE.  */
     6487static bfd_boolean
    54526488elfcore_make_note_pseudosection (abfd, name, note)
    54536489     bfd *abfd;
     
    54556491     Elf_Internal_Note *note;
    54566492{
    5457   char buf[100];
    5458   char *threaded_name;
    5459   asection *sect;
    5460 
    5461   /* Build the section name.  */
    5462 
    5463   sprintf (buf, "%s/%d", name, elfcore_make_pid (abfd));
    5464   threaded_name = bfd_alloc (abfd, strlen (buf) + 1);
    5465   if (threaded_name == NULL)
    5466     return false;
    5467   strcpy (threaded_name, buf);
    5468 
    5469   sect = bfd_make_section (abfd, threaded_name);
    5470   if (sect == NULL)
    5471     return false;
    5472   sect->_raw_size = note->descsz;
    5473   sect->filepos = note->descpos;
    5474   sect->flags = SEC_HAS_CONTENTS;
    5475   sect->alignment_power = 2;
    5476 
    5477   if (! elfcore_maybe_make_sect (abfd, name, sect))
    5478     return false;
    5479 
    5480   return true;
     6493  return _bfd_elfcore_make_pseudosection (abfd, name,
     6494                                          note->descsz, note->descpos);
    54816495}
    54826496
     
    54856499   data structure apart.  */
    54866500
    5487 static boolean
     6501static bfd_boolean
    54886502elfcore_grok_prfpreg (abfd, note)
    54896503     bfd *abfd;
     
    54976511   literally.  */
    54986512
    5499 static boolean
     6513static bfd_boolean
    55006514elfcore_grok_prxfpreg (abfd, note)
    55016515     bfd *abfd;
     
    55196533#endif
    55206534
    5521 #if defined (HAVE_PRPSINFO_T) || defined (HAVE_PSINFO_T)
    5522 
    55236535/* return a malloc'ed copy of a string at START which is at
    55246536   most MAX bytes long, possibly without a terminating '\0'.
    55256537   the copy will always have a terminating '\0'.  */
    55266538
    5527 static char*
    5528 elfcore_strndup (abfd, start, max)
     6539char *
     6540_bfd_elfcore_strndup (abfd, start, max)
    55296541     bfd *abfd;
    55306542     char *start;
    5531      int max;
    5532 {
    5533   char *dup;
     6543     size_t max;
     6544{
     6545  char *dups;
    55346546  char *end = memchr (start, '\0', max);
    5535   int len;
     6547  size_t len;
    55366548
    55376549  if (end == NULL)
     
    55406552    len = end - start;
    55416553
    5542   dup = bfd_alloc (abfd, len + 1);
    5543   if (dup == NULL)
     6554  dups = bfd_alloc (abfd, (bfd_size_type) len + 1);
     6555  if (dups == NULL)
    55446556    return NULL;
    55456557
    5546   memcpy (dup, start, len);
    5547   dup[len] = '\0';
    5548 
    5549   return dup;
    5550 }
    5551 
    5552 static boolean
     6558  memcpy (dups, start, len);
     6559  dups[len] = '\0';
     6560
     6561  return dups;
     6562}
     6563
     6564#if defined (HAVE_PRPSINFO_T) || defined (HAVE_PSINFO_T)
     6565static bfd_boolean elfcore_grok_psinfo
     6566  PARAMS ((bfd *, Elf_Internal_Note *));
     6567
     6568static bfd_boolean
    55536569elfcore_grok_psinfo (abfd, note)
    55546570     bfd *abfd;
     
    55626578
    55636579      elf_tdata (abfd)->core_program
    5564         = elfcore_strndup (abfd, psinfo.pr_fname, sizeof (psinfo.pr_fname));
     6580        = _bfd_elfcore_strndup (abfd, psinfo.pr_fname,
     6581                                sizeof (psinfo.pr_fname));
    55656582
    55666583      elf_tdata (abfd)->core_command
    5567         = elfcore_strndup (abfd, psinfo.pr_psargs, sizeof (psinfo.pr_psargs));
     6584        = _bfd_elfcore_strndup (abfd, psinfo.pr_psargs,
     6585                                sizeof (psinfo.pr_psargs));
    55686586    }
    55696587#if defined (HAVE_PRPSINFO32_T) || defined (HAVE_PSINFO32_T)
     
    55766594
    55776595      elf_tdata (abfd)->core_program
    5578         = elfcore_strndup (abfd, psinfo.pr_fname, sizeof (psinfo.pr_fname));
     6596        = _bfd_elfcore_strndup (abfd, psinfo.pr_fname,
     6597                                sizeof (psinfo.pr_fname));
    55796598
    55806599      elf_tdata (abfd)->core_command
    5581         = elfcore_strndup (abfd, psinfo.pr_psargs, sizeof (psinfo.pr_psargs));
     6600        = _bfd_elfcore_strndup (abfd, psinfo.pr_psargs,
     6601                                sizeof (psinfo.pr_psargs));
    55826602    }
    55836603#endif
     
    55876607      /* Fail - we don't know how to handle any other
    55886608         note size (ie. data object type).  */
    5589       return true;
     6609      return TRUE;
    55906610    }
    55916611
     
    56026622  }
    56036623
    5604   return true;
     6624  return TRUE;
    56056625}
    56066626#endif /* defined (HAVE_PRPSINFO_T) || defined (HAVE_PSINFO_T) */
    56076627
    56086628#if defined (HAVE_PSTATUS_T)
    5609 static boolean
     6629static bfd_boolean elfcore_grok_pstatus
     6630  PARAMS ((bfd *, Elf_Internal_Note *));
     6631
     6632static bfd_boolean
    56106633elfcore_grok_pstatus (abfd, note)
    56116634     bfd *abfd;
     
    56396662     NT_LWPSTATUS note, presumably.  */
    56406663
    5641   return true;
     6664  return TRUE;
    56426665}
    56436666#endif /* defined (HAVE_PSTATUS_T) */
    56446667
    56456668#if defined (HAVE_LWPSTATUS_T)
    5646 static boolean
     6669static bfd_boolean elfcore_grok_lwpstatus
     6670  PARAMS ((bfd *, Elf_Internal_Note *));
     6671
     6672static bfd_boolean
    56476673elfcore_grok_lwpstatus (abfd, note)
    56486674     bfd *abfd;
     
    56526678  char buf[100];
    56536679  char *name;
     6680  size_t len;
    56546681  asection *sect;
    56556682
     
    56596686#endif
    56606687      )
    5661     return true;
     6688    return TRUE;
    56626689
    56636690  memcpy (&lwpstat, note->descdata, sizeof (lwpstat));
     
    56696696
    56706697  sprintf (buf, ".reg/%d", elfcore_make_pid (abfd));
    5671   name = bfd_alloc (abfd, strlen (buf) + 1);
     6698  len = strlen (buf) + 1;
     6699  name = bfd_alloc (abfd, (bfd_size_type) len);
    56726700  if (name == NULL)
    5673     return false;
    5674   strcpy (name, buf);
     6701    return FALSE;
     6702  memcpy (name, buf, len);
    56756703
    56766704  sect = bfd_make_section (abfd, name);
    56776705  if (sect == NULL)
    5678     return false;
     6706    return FALSE;
    56796707
    56806708#if defined (HAVE_LWPSTATUS_T_PR_CONTEXT)
     
    56936721
    56946722  if (!elfcore_maybe_make_sect (abfd, ".reg", sect))
    5695     return false;
     6723    return FALSE;
    56966724
    56976725  /* Make a ".reg2/999" section */
    56986726
    56996727  sprintf (buf, ".reg2/%d", elfcore_make_pid (abfd));
    5700   name = bfd_alloc (abfd, strlen (buf) + 1);
     6728  len = strlen (buf) + 1;
     6729  name = bfd_alloc (abfd, (bfd_size_type) len);
    57016730  if (name == NULL)
    5702     return false;
    5703   strcpy (name, buf);
     6731    return FALSE;
     6732  memcpy (name, buf, len);
    57046733
    57056734  sect = bfd_make_section (abfd, name);
    57066735  if (sect == NULL)
    5707     return false;
     6736    return FALSE;
    57086737
    57096738#if defined (HAVE_LWPSTATUS_T_PR_CONTEXT)
     
    57216750  sect->alignment_power = 2;
    57226751
    5723   if (!elfcore_maybe_make_sect (abfd, ".reg2", sect))
    5724     return false;
    5725 
    5726   return true;
     6752  return elfcore_maybe_make_sect (abfd, ".reg2", sect);
    57276753}
    57286754#endif /* defined (HAVE_LWPSTATUS_T) */
    57296755
    57306756#if defined (HAVE_WIN32_PSTATUS_T)
    5731 static boolean
     6757static bfd_boolean
    57326758elfcore_grok_win32pstatus (abfd, note)
    57336759     bfd *abfd;
     
    57366762  char buf[30];
    57376763  char *name;
     6764  size_t len;
    57386765  asection *sect;
    57396766  win32_pstatus_t pstatus;
    57406767
    57416768  if (note->descsz < sizeof (pstatus))
    5742     return true;
    5743 
    5744   memcpy (&pstatus, note->descdata, note->descsz);
     6769    return TRUE;
     6770
     6771  memcpy (&pstatus, note->descdata, sizeof (pstatus));
    57456772
    57466773  switch (pstatus.data_type)
     
    57566783      sprintf (buf, ".reg/%d", pstatus.data.thread_info.tid);
    57576784
    5758       name = bfd_alloc (abfd, strlen (buf) + 1);
     6785      len = strlen (buf) + 1;
     6786      name = bfd_alloc (abfd, (bfd_size_type) len);
    57596787      if (name == NULL)
    5760         return false;
    5761 
    5762       strcpy (name, buf);
     6788        return FALSE;
     6789
     6790      memcpy (name, buf, len);
    57636791
    57646792      sect = bfd_make_section (abfd, name);
    57656793      if (sect == NULL)
    5766         return false;
     6794        return FALSE;
    57676795
    57686796      sect->_raw_size = sizeof (pstatus.data.thread_info.thread_context);
    5769       sect->filepos = note->descpos + offsetof (struct win32_pstatus,
    5770                                                 data.thread_info.thread_context);
     6797      sect->filepos = (note->descpos
     6798                       + offsetof (struct win32_pstatus,
     6799                                   data.thread_info.thread_context));
    57716800      sect->flags = SEC_HAS_CONTENTS;
    57726801      sect->alignment_power = 2;
     
    57746803      if (pstatus.data.thread_info.is_active_thread)
    57756804        if (! elfcore_maybe_make_sect (abfd, ".reg", sect))
    5776           return false;
     6805          return FALSE;
    57776806      break;
    57786807
     
    57816810      sprintf (buf, ".module/%08x", pstatus.data.module_info.base_address);
    57826811
    5783       name = bfd_alloc (abfd, strlen (buf) + 1);
     6812      len = strlen (buf) + 1;
     6813      name = bfd_alloc (abfd, (bfd_size_type) len);
    57846814      if (name == NULL)
    5785         return false;
    5786 
    5787       strcpy (name, buf);
     6815        return FALSE;
     6816
     6817      memcpy (name, buf, len);
    57886818
    57896819      sect = bfd_make_section (abfd, name);
    57906820
    57916821      if (sect == NULL)
    5792         return false;
     6822        return FALSE;
    57936823
    57946824      sect->_raw_size = note->descsz;
     
    57996829
    58006830    default:
    5801       return true;
    5802     }
    5803 
    5804   return true;
     6831      return TRUE;
     6832    }
     6833
     6834  return TRUE;
    58056835}
    58066836#endif /* HAVE_WIN32_PSTATUS_T */
    58076837
    5808 static boolean
     6838static bfd_boolean
    58096839elfcore_grok_note (abfd, note)
    58106840     bfd *abfd;
    58116841     Elf_Internal_Note *note;
    58126842{
     6843  struct elf_backend_data *bed = get_elf_backend_data (abfd);
     6844
    58136845  switch (note->type)
    58146846    {
    58156847    default:
    5816       return true;
    5817 
     6848      return TRUE;
     6849
     6850    case NT_PRSTATUS:
     6851      if (bed->elf_backend_grok_prstatus)
     6852        if ((*bed->elf_backend_grok_prstatus) (abfd, note))
     6853          return TRUE;
    58186854#if defined (HAVE_PRSTATUS_T)
    5819     case NT_PRSTATUS:
    58206855      return elfcore_grok_prstatus (abfd, note);
     6856#else
     6857      return TRUE;
    58216858#endif
    58226859
     
    58406877
    58416878    case NT_PRXFPREG:           /* Linux SSE extension */
    5842       if (note->namesz == 5
    5843           && ! strcmp (note->namedata, "LINUX"))
     6879      if (note->namesz == 6
     6880          && strcmp (note->namedata, "LINUX") == 0)
    58446881        return elfcore_grok_prxfpreg (abfd, note);
    58456882      else
    5846         return true;
    5847 
    5848 #if defined (HAVE_PRPSINFO_T) || defined (HAVE_PSINFO_T)
     6883        return TRUE;
     6884
    58496885    case NT_PRPSINFO:
    58506886    case NT_PSINFO:
     6887      if (bed->elf_backend_grok_psinfo)
     6888        if ((*bed->elf_backend_grok_psinfo) (abfd, note))
     6889          return TRUE;
     6890#if defined (HAVE_PRPSINFO_T) || defined (HAVE_PSINFO_T)
    58516891      return elfcore_grok_psinfo (abfd, note);
     6892#else
     6893      return TRUE;
    58526894#endif
    58536895    }
    58546896}
    58556897
    5856 static boolean
     6898static bfd_boolean
     6899elfcore_netbsd_get_lwpid (note, lwpidp)
     6900     Elf_Internal_Note *note;
     6901     int *lwpidp;
     6902{
     6903  char *cp;
     6904
     6905  cp = strchr (note->namedata, '@');
     6906  if (cp != NULL)
     6907    {
     6908      *lwpidp = atoi(cp + 1);
     6909      return TRUE;
     6910    }
     6911  return FALSE;
     6912}
     6913
     6914static bfd_boolean
     6915elfcore_grok_netbsd_procinfo (abfd, note)
     6916     bfd *abfd;
     6917     Elf_Internal_Note *note;
     6918{
     6919
     6920  /* Signal number at offset 0x08. */
     6921  elf_tdata (abfd)->core_signal
     6922    = bfd_h_get_32 (abfd, (bfd_byte *) note->descdata + 0x08);
     6923
     6924  /* Process ID at offset 0x50. */
     6925  elf_tdata (abfd)->core_pid
     6926    = bfd_h_get_32 (abfd, (bfd_byte *) note->descdata + 0x50);
     6927
     6928  /* Command name at 0x7c (max 32 bytes, including nul). */
     6929  elf_tdata (abfd)->core_command
     6930    = _bfd_elfcore_strndup (abfd, note->descdata + 0x7c, 31);
     6931
     6932  return TRUE;
     6933}
     6934
     6935static bfd_boolean
     6936elfcore_grok_netbsd_note (abfd, note)
     6937     bfd *abfd;
     6938     Elf_Internal_Note *note;
     6939{
     6940  int lwp;
     6941
     6942  if (elfcore_netbsd_get_lwpid (note, &lwp))
     6943    elf_tdata (abfd)->core_lwpid = lwp;
     6944
     6945  if (note->type == NT_NETBSDCORE_PROCINFO)
     6946    {
     6947      /* NetBSD-specific core "procinfo".  Note that we expect to
     6948         find this note before any of the others, which is fine,
     6949         since the kernel writes this note out first when it
     6950         creates a core file.  */
     6951
     6952      return elfcore_grok_netbsd_procinfo (abfd, note);
     6953    }
     6954
     6955  /* As of Jan 2002 there are no other machine-independent notes
     6956     defined for NetBSD core files.  If the note type is less
     6957     than the start of the machine-dependent note types, we don't
     6958     understand it.  */
     6959
     6960  if (note->type < NT_NETBSDCORE_FIRSTMACH)
     6961    return TRUE;
     6962
     6963
     6964  switch (bfd_get_arch (abfd))
     6965    {
     6966    /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0 and
     6967       PT_GETFPREGS == mach+2.  */
     6968
     6969    case bfd_arch_alpha:
     6970    case bfd_arch_sparc:
     6971      switch (note->type)
     6972        {
     6973        case NT_NETBSDCORE_FIRSTMACH+0:
     6974          return elfcore_make_note_pseudosection (abfd, ".reg", note);
     6975
     6976        case NT_NETBSDCORE_FIRSTMACH+2:
     6977          return elfcore_make_note_pseudosection (abfd, ".reg2", note);
     6978
     6979        default:
     6980          return TRUE;
     6981        }
     6982
     6983    /* On all other arch's, PT_GETREGS == mach+1 and
     6984       PT_GETFPREGS == mach+3.  */
     6985
     6986    default:
     6987      switch (note->type)
     6988        {
     6989        case NT_NETBSDCORE_FIRSTMACH+1:
     6990          return elfcore_make_note_pseudosection (abfd, ".reg", note);
     6991
     6992        case NT_NETBSDCORE_FIRSTMACH+3:
     6993          return elfcore_make_note_pseudosection (abfd, ".reg2", note);
     6994
     6995        default:
     6996          return TRUE;
     6997        }
     6998    }
     6999    /* NOTREACHED */
     7000}
     7001
     7002static bfd_boolean
     7003elfcore_grok_nto_status (abfd, note, tid)
     7004     bfd *abfd;
     7005     Elf_Internal_Note *note;
     7006     pid_t *tid;
     7007{
     7008  void *ddata = note->descdata;
     7009  char buf[100];
     7010  char *name;
     7011  asection *sect;
     7012
     7013  /* nto_procfs_status 'pid' field is at offset 0.  */
     7014  elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, (bfd_byte *) ddata);
     7015
     7016  /* nto_procfs_status 'tid' field is at offset 4.  */
     7017  elf_tdata (abfd)->core_lwpid = bfd_get_32 (abfd, (bfd_byte *) ddata + 4);
     7018
     7019  /* nto_procfs_status 'what' field is at offset 14.  */
     7020  elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, (bfd_byte *) ddata + 14);
     7021
     7022  /* Pass tid back.  */
     7023  *tid = elf_tdata (abfd)->core_lwpid;
     7024
     7025  /* Make a ".qnx_core_status/%d" section.  */
     7026  sprintf (buf, ".qnx_core_status/%d", *tid);
     7027
     7028  name = bfd_alloc (abfd, (bfd_size_type) strlen (buf) + 1);
     7029  if (name == NULL)
     7030    return FALSE;
     7031  strcpy (name, buf);
     7032
     7033  sect = bfd_make_section (abfd, name);
     7034  if (sect == NULL)
     7035    return FALSE;
     7036
     7037  sect->_raw_size       = note->descsz;
     7038  sect->filepos         = note->descpos;
     7039  sect->flags           = SEC_HAS_CONTENTS;
     7040  sect->alignment_power = 2;
     7041
     7042  return (elfcore_maybe_make_sect (abfd, ".qnx_core_status", sect));
     7043}
     7044
     7045static bfd_boolean
     7046elfcore_grok_nto_gregs (abfd, note, tid)
     7047     bfd *abfd;
     7048     Elf_Internal_Note *note;
     7049     pid_t tid;
     7050{
     7051  char buf[100];
     7052  char *name;
     7053  asection *sect;
     7054
     7055  /* Make a ".reg/%d" section.  */
     7056  sprintf (buf, ".reg/%d", tid);
     7057
     7058  name = bfd_alloc (abfd, (bfd_size_type) strlen (buf) + 1);
     7059  if (name == NULL)
     7060    return FALSE;
     7061  strcpy (name, buf);
     7062
     7063  sect = bfd_make_section (abfd, name);
     7064  if (sect == NULL)
     7065    return FALSE;
     7066
     7067  sect->_raw_size       = note->descsz;
     7068  sect->filepos         = note->descpos;
     7069  sect->flags           = SEC_HAS_CONTENTS;
     7070  sect->alignment_power = 2;
     7071
     7072  return elfcore_maybe_make_sect (abfd, ".reg", sect);
     7073}
     7074
     7075#define BFD_QNT_CORE_INFO       7
     7076#define BFD_QNT_CORE_STATUS     8
     7077#define BFD_QNT_CORE_GREG       9
     7078#define BFD_QNT_CORE_FPREG      10
     7079
     7080static bfd_boolean
     7081elfcore_grok_nto_note (abfd, note)
     7082     bfd *abfd;
     7083     Elf_Internal_Note *note;
     7084{
     7085  /* Every GREG section has a STATUS section before it.  Store the
     7086     tid from the previous call to pass down to the next gregs
     7087     function.  */
     7088  static pid_t tid = 1;
     7089
     7090  switch (note->type)
     7091    {
     7092    case BFD_QNT_CORE_INFO:   return elfcore_make_note_pseudosection (abfd, ".qnx_core_info", note);
     7093    case BFD_QNT_CORE_STATUS: return elfcore_grok_nto_status (abfd, note, &tid);
     7094    case BFD_QNT_CORE_GREG:   return elfcore_grok_nto_gregs (abfd, note, tid);
     7095    case BFD_QNT_CORE_FPREG:  return elfcore_grok_prfpreg (abfd, note);
     7096    default:                  return TRUE;
     7097    }
     7098}
     7099
     7100/* Function: elfcore_write_note
     7101
     7102   Inputs:
     7103     buffer to hold note
     7104     name of note
     7105     type of note
     7106     data for note
     7107     size of data for note
     7108
     7109   Return:
     7110   End of buffer containing note.  */
     7111
     7112char *
     7113elfcore_write_note (abfd, buf, bufsiz, name, type, input, size)
     7114     bfd  *abfd;
     7115     char *buf;
     7116     int  *bufsiz;
     7117     const char *name;
     7118     int  type;
     7119     const PTR input;
     7120     int  size;
     7121{
     7122  Elf_External_Note *xnp;
     7123  size_t namesz;
     7124  size_t pad;
     7125  size_t newspace;
     7126  char *p, *dest;
     7127
     7128  namesz = 0;
     7129  pad = 0;
     7130  if (name != NULL)
     7131    {
     7132      struct elf_backend_data *bed;
     7133
     7134      namesz = strlen (name) + 1;
     7135      bed = get_elf_backend_data (abfd);
     7136      pad = -namesz & (bed->s->file_align - 1);
     7137    }
     7138
     7139  newspace = sizeof (Elf_External_Note) - 1 + namesz + pad + size;
     7140
     7141  p = realloc (buf, *bufsiz + newspace);
     7142  dest = p + *bufsiz;
     7143  *bufsiz += newspace;
     7144  xnp = (Elf_External_Note *) dest;
     7145  H_PUT_32 (abfd, namesz, xnp->namesz);
     7146  H_PUT_32 (abfd, size, xnp->descsz);
     7147  H_PUT_32 (abfd, type, xnp->type);
     7148  dest = xnp->name;
     7149  if (name != NULL)
     7150    {
     7151      memcpy (dest, name, namesz);
     7152      dest += namesz;
     7153      while (pad != 0)
     7154        {
     7155          *dest++ = '\0';
     7156          --pad;
     7157        }
     7158    }
     7159  memcpy (dest, input, size);
     7160  return p;
     7161}
     7162
     7163#if defined (HAVE_PRPSINFO_T) || defined (HAVE_PSINFO_T)
     7164char *
     7165elfcore_write_prpsinfo (abfd, buf, bufsiz, fname, psargs)
     7166     bfd  *abfd;
     7167     char *buf;
     7168     int  *bufsiz;
     7169     const char *fname;
     7170     const char *psargs;
     7171{
     7172  int note_type;
     7173  char *note_name = "CORE";
     7174
     7175#if defined (HAVE_PSINFO_T)
     7176  psinfo_t  data;
     7177  note_type = NT_PSINFO;
     7178#else
     7179  prpsinfo_t data;
     7180  note_type = NT_PRPSINFO;
     7181#endif
     7182
     7183  memset (&data, 0, sizeof (data));
     7184  strncpy (data.pr_fname, fname, sizeof (data.pr_fname));
     7185  strncpy (data.pr_psargs, psargs, sizeof (data.pr_psargs));
     7186  return elfcore_write_note (abfd, buf, bufsiz,
     7187                             note_name, note_type, &data, sizeof (data));
     7188}
     7189#endif  /* PSINFO_T or PRPSINFO_T */
     7190
     7191#if defined (HAVE_PRSTATUS_T)
     7192char *
     7193elfcore_write_prstatus (abfd, buf, bufsiz, pid, cursig, gregs)
     7194     bfd *abfd;
     7195     char *buf;
     7196     int *bufsiz;
     7197     long pid;
     7198     int cursig;
     7199     const PTR gregs;
     7200{
     7201  prstatus_t prstat;
     7202  char *note_name = "CORE";
     7203
     7204  memset (&prstat, 0, sizeof (prstat));
     7205  prstat.pr_pid = pid;
     7206  prstat.pr_cursig = cursig;
     7207  memcpy (&prstat.pr_reg, gregs, sizeof (prstat.pr_reg));
     7208  return elfcore_write_note (abfd, buf, bufsiz,
     7209                             note_name, NT_PRSTATUS, &prstat, sizeof (prstat));
     7210}
     7211#endif /* HAVE_PRSTATUS_T */
     7212
     7213#if defined (HAVE_LWPSTATUS_T)
     7214char *
     7215elfcore_write_lwpstatus (abfd, buf, bufsiz, pid, cursig, gregs)
     7216     bfd *abfd;
     7217     char *buf;
     7218     int *bufsiz;
     7219     long pid;
     7220     int cursig;
     7221     const PTR gregs;
     7222{
     7223  lwpstatus_t lwpstat;
     7224  char *note_name = "CORE";
     7225
     7226  memset (&lwpstat, 0, sizeof (lwpstat));
     7227  lwpstat.pr_lwpid  = pid >> 16;
     7228  lwpstat.pr_cursig = cursig;
     7229#if defined (HAVE_LWPSTATUS_T_PR_REG)
     7230  memcpy (lwpstat.pr_reg, gregs, sizeof (lwpstat.pr_reg));
     7231#elif defined (HAVE_LWPSTATUS_T_PR_CONTEXT)
     7232#if !defined(gregs)
     7233  memcpy (lwpstat.pr_context.uc_mcontext.gregs,
     7234          gregs, sizeof (lwpstat.pr_context.uc_mcontext.gregs));
     7235#else
     7236  memcpy (lwpstat.pr_context.uc_mcontext.__gregs,
     7237          gregs, sizeof (lwpstat.pr_context.uc_mcontext.__gregs));
     7238#endif
     7239#endif
     7240  return elfcore_write_note (abfd, buf, bufsiz, note_name,
     7241                             NT_LWPSTATUS, &lwpstat, sizeof (lwpstat));
     7242}
     7243#endif /* HAVE_LWPSTATUS_T */
     7244
     7245#if defined (HAVE_PSTATUS_T)
     7246char *
     7247elfcore_write_pstatus (abfd, buf, bufsiz, pid, cursig, gregs)
     7248     bfd *abfd;
     7249     char *buf;
     7250     int *bufsiz;
     7251     long pid;
     7252     int cursig;
     7253     const PTR gregs;
     7254{
     7255  pstatus_t pstat;
     7256  char *note_name = "CORE";
     7257
     7258  memset (&pstat, 0, sizeof (pstat));
     7259  pstat.pr_pid = pid & 0xffff;
     7260  buf = elfcore_write_note (abfd, buf, bufsiz, note_name,
     7261                            NT_PSTATUS, &pstat, sizeof (pstat));
     7262  return buf;
     7263}
     7264#endif /* HAVE_PSTATUS_T */
     7265
     7266char *
     7267elfcore_write_prfpreg (abfd, buf, bufsiz, fpregs, size)
     7268     bfd  *abfd;
     7269     char *buf;
     7270     int  *bufsiz;
     7271     const PTR fpregs;
     7272     int size;
     7273{
     7274  char *note_name = "CORE";
     7275  return elfcore_write_note (abfd, buf, bufsiz,
     7276                             note_name, NT_FPREGSET, fpregs, size);
     7277}
     7278
     7279char *
     7280elfcore_write_prxfpreg (abfd, buf, bufsiz, xfpregs, size)
     7281     bfd  *abfd;
     7282     char *buf;
     7283     int  *bufsiz;
     7284     const PTR xfpregs;
     7285     int size;
     7286{
     7287  char *note_name = "LINUX";
     7288  return elfcore_write_note (abfd, buf, bufsiz,
     7289                             note_name, NT_PRXFPREG, xfpregs, size);
     7290}
     7291
     7292static bfd_boolean
    58577293elfcore_read_notes (abfd, offset, size)
    58587294     bfd *abfd;
    5859      bfd_vma offset;
    5860      bfd_vma size;
     7295     file_ptr offset;
     7296     bfd_size_type size;
    58617297{
    58627298  char *buf;
     
    58647300
    58657301  if (size <= 0)
    5866     return true;
    5867 
    5868   if (bfd_seek (abfd, offset, SEEK_SET) == -1)
    5869     return false;
    5870 
    5871   buf = bfd_malloc ((size_t) size);
     7302    return TRUE;
     7303
     7304  if (bfd_seek (abfd, offset, SEEK_SET) != 0)
     7305    return FALSE;
     7306
     7307  buf = bfd_malloc (size);
    58727308  if (buf == NULL)
    5873     return false;
    5874 
    5875   if (bfd_read (buf, size, 1, abfd) != size)
     7309    return FALSE;
     7310
     7311  if (bfd_bread (buf, size, abfd) != size)
    58767312    {
    58777313    error:
    58787314      free (buf);
    5879       return false;
     7315      return FALSE;
    58807316    }
    58817317
     
    58877323      Elf_Internal_Note in;
    58887324
    5889       in.type = bfd_h_get_32 (abfd, (bfd_byte *) xnp->type);
    5890 
    5891       in.namesz = bfd_h_get_32 (abfd, (bfd_byte *) xnp->namesz);
     7325      in.type = H_GET_32 (abfd, xnp->type);
     7326
     7327      in.namesz = H_GET_32 (abfd, xnp->namesz);
    58927328      in.namedata = xnp->name;
    58937329
    5894       in.descsz = bfd_h_get_32 (abfd, (bfd_byte *) xnp->descsz);
     7330      in.descsz = H_GET_32 (abfd, xnp->descsz);
    58957331      in.descdata = in.namedata + BFD_ALIGN (in.namesz, 4);
    58967332      in.descpos = offset + (in.descdata - buf);
    58977333
    5898       if (! elfcore_grok_note (abfd, &in))
    5899         goto error;
     7334      if (strncmp (in.namedata, "NetBSD-CORE", 11) == 0)
     7335        {
     7336          if (! elfcore_grok_netbsd_note (abfd, &in))
     7337            goto error;
     7338        }
     7339      else if (strncmp (in.namedata, "QNX", 3) == 0)
     7340        {
     7341          if (! elfcore_grok_nto_note (abfd, &in))
     7342            goto error;
     7343        }
     7344      else
     7345        {
     7346          if (! elfcore_grok_note (abfd, &in))
     7347            goto error;
     7348        }
    59007349
    59017350      p = in.descdata + BFD_ALIGN (in.descsz, 4);
     
    59037352
    59047353  free (buf);
    5905   return true;
    5906 }
    5907 
    5908 /* FIXME: This function is now unnecessary.  Callers can just call
    5909    bfd_section_from_phdr directly.  */
    5910 
    5911 boolean
    5912 _bfd_elfcore_section_from_phdr (abfd, phdr, sec_num)
    5913      bfd *abfd;
    5914      Elf_Internal_Phdr* phdr;
    5915      int sec_num;
    5916 {
    5917   if (! bfd_section_from_phdr (abfd, phdr, sec_num))
    5918     return false;
    5919 
    5920   return true;
     7354  return TRUE;
    59217355}
    59227356
     
    59387372    }
    59397373
    5940   return (elf_elfheader (abfd)->e_phnum
    5941           * sizeof (Elf_Internal_Phdr));
     7374  return elf_elfheader (abfd)->e_phnum * sizeof (Elf_Internal_Phdr);
    59427375}
    59437376
     
    59697402  return num_phdrs;
    59707403}
     7404
     7405void
     7406_bfd_elf_sprintf_vma (abfd, buf, value)
     7407     bfd *abfd ATTRIBUTE_UNUSED;
     7408     char *buf;
     7409     bfd_vma value;
     7410{
     7411#ifdef BFD64
     7412  Elf_Internal_Ehdr *i_ehdrp;   /* Elf file header, internal form */
     7413
     7414  i_ehdrp = elf_elfheader (abfd);
     7415  if (i_ehdrp == NULL)
     7416    sprintf_vma (buf, value);
     7417  else
     7418    {
     7419      if (i_ehdrp->e_ident[EI_CLASS] == ELFCLASS64)
     7420        {
     7421#if BFD_HOST_64BIT_LONG
     7422          sprintf (buf, "%016lx", value);
     7423#else
     7424          sprintf (buf, "%08lx%08lx", _bfd_int64_high (value),
     7425                   _bfd_int64_low (value));
     7426#endif
     7427        }
     7428      else
     7429        sprintf (buf, "%08lx", (unsigned long) (value & 0xffffffff));
     7430    }
     7431#else
     7432  sprintf_vma (buf, value);
     7433#endif
     7434}
     7435
     7436void
     7437_bfd_elf_fprintf_vma (abfd, stream, value)
     7438     bfd *abfd ATTRIBUTE_UNUSED;
     7439     PTR stream;
     7440     bfd_vma value;
     7441{
     7442#ifdef BFD64
     7443  Elf_Internal_Ehdr *i_ehdrp;   /* Elf file header, internal form */
     7444
     7445  i_ehdrp = elf_elfheader (abfd);
     7446  if (i_ehdrp == NULL)
     7447    fprintf_vma ((FILE *) stream, value);
     7448  else
     7449    {
     7450      if (i_ehdrp->e_ident[EI_CLASS] == ELFCLASS64)
     7451        {
     7452#if BFD_HOST_64BIT_LONG
     7453          fprintf ((FILE *) stream, "%016lx", value);
     7454#else
     7455          fprintf ((FILE *) stream, "%08lx%08lx",
     7456                   _bfd_int64_high (value), _bfd_int64_low (value));
     7457#endif
     7458        }
     7459      else
     7460        fprintf ((FILE *) stream, "%08lx",
     7461                 (unsigned long) (value & 0xffffffff));
     7462    }
     7463#else
     7464  fprintf_vma ((FILE *) stream, value);
     7465#endif
     7466}
     7467
     7468enum elf_reloc_type_class
     7469_bfd_elf_reloc_type_class (rela)
     7470     const Elf_Internal_Rela *rela ATTRIBUTE_UNUSED;
     7471{
     7472  return reloc_class_normal;
     7473}
     7474
     7475/* For RELA architectures, return the relocation value for a
     7476   relocation against a local symbol.  */
     7477
     7478bfd_vma
     7479_bfd_elf_rela_local_sym (abfd, sym, sec, rel)
     7480     bfd *abfd;
     7481     Elf_Internal_Sym *sym;
     7482     asection *sec;
     7483     Elf_Internal_Rela *rel;
     7484{
     7485  bfd_vma relocation;
     7486
     7487  relocation = (sec->output_section->vma
     7488                + sec->output_offset
     7489                + sym->st_value);
     7490  if ((sec->flags & SEC_MERGE)
     7491      && ELF_ST_TYPE (sym->st_info) == STT_SECTION
     7492      && sec->sec_info_type == ELF_INFO_TYPE_MERGE)
     7493    {
     7494      asection *msec;
     7495
     7496      msec = sec;
     7497      rel->r_addend =
     7498        _bfd_merged_section_offset (abfd, &msec,
     7499                                    elf_section_data (sec)->sec_info,
     7500                                    sym->st_value + rel->r_addend,
     7501                                    (bfd_vma) 0)
     7502        - relocation;
     7503      rel->r_addend += msec->output_section->vma + msec->output_offset;
     7504    }
     7505  return relocation;
     7506}
     7507
     7508bfd_vma
     7509_bfd_elf_rel_local_sym (abfd, sym, psec, addend)
     7510     bfd *abfd;
     7511     Elf_Internal_Sym *sym;
     7512     asection **psec;
     7513     bfd_vma addend;
     7514{
     7515  asection *sec = *psec;
     7516
     7517  if (sec->sec_info_type != ELF_INFO_TYPE_MERGE)
     7518    return sym->st_value + addend;
     7519
     7520  return _bfd_merged_section_offset (abfd, psec,
     7521                                     elf_section_data (sec)->sec_info,
     7522                                     sym->st_value + addend, (bfd_vma) 0);
     7523}
     7524
     7525bfd_vma
     7526_bfd_elf_section_offset (abfd, info, sec, offset)
     7527     bfd *abfd;
     7528     struct bfd_link_info *info;
     7529     asection *sec;
     7530     bfd_vma offset;
     7531{
     7532  struct bfd_elf_section_data *sec_data;
     7533
     7534  sec_data = elf_section_data (sec);
     7535  switch (sec->sec_info_type)
     7536    {
     7537    case ELF_INFO_TYPE_STABS:
     7538      return _bfd_stab_section_offset (abfd,
     7539                                       &elf_hash_table (info)->merge_info,
     7540                                       sec, &sec_data->sec_info, offset);
     7541    case ELF_INFO_TYPE_EH_FRAME:
     7542      return _bfd_elf_eh_frame_section_offset (abfd, sec, offset);
     7543    default:
     7544      return offset;
     7545    }
     7546}
Note: See TracChangeset for help on using the changeset viewer.