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

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    11/* POWER/PowerPC XCOFF linker support.
    2    Copyright 1995, 1996, 1997, 1998, 1999, 2000
     2   Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
    33   Free Software Foundation, Inc.
    44   Written by Ian Lance Taylor <ian@cygnus.com>, Cygnus Support.
    55
    6 This file is part of BFD, the Binary File Descriptor library.
    7 
    8 This program is free software; you can redistribute it and/or modify
    9 it under the terms of the GNU General Public License as published by
    10 the Free Software Foundation; either version 2 of the License, or
    11 (at your option) any later version.
    12 
    13 This program is distributed in the hope that it will be useful,
    14 but WITHOUT ANY WARRANTY; without even the implied warranty of
    15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16 GNU General Public License for more details.
    17 
    18 You should have received a copy of the GNU General Public License
    19 along with this program; if not, write to the Free Software
    20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
     6   This file is part of BFD, the Binary File Descriptor library.
     7
     8   This program is free software; you can redistribute it and/or modify
     9   it under the terms of the GNU General Public License as published by
     10   the Free Software Foundation; either version 2 of the License, or
     11   (at your option) any later version.
     12
     13   This program is distributed in the hope that it will be useful,
     14   but WITHOUT ANY WARRANTY; without even the implied warranty of
     15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16   GNU General Public License for more details.
     17
     18   You should have received a copy of the GNU General Public License
     19   along with this program; if not, write to the Free Software
     20   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
    2121
    2222#include "bfd.h"
     
    2525#include "libbfd.h"
    2626#include "coff/internal.h"
     27#include "coff/xcoff.h"
    2728#include "libcoff.h"
     29#include "libxcoff.h"
    2830
    2931/* This file holds the XCOFF linker code.  */
    3032
    3133#define STRING_SIZE_SIZE (4)
    32 
    33 /* Get the XCOFF hash table entries for a BFD.  */
    34 #define obj_xcoff_sym_hashes(bfd) \
    35   ((struct xcoff_link_hash_entry **) obj_coff_sym_hashes (bfd))
    36 
    37 /* XCOFF relocation types.  These probably belong in a header file
    38    somewhere.  The relocations are described in the function
    39    _bfd_ppc_xcoff_relocate_section in this file.  */
    40 
    41 #define R_POS   (0x00)
    42 #define R_NEG   (0x01)
    43 #define R_REL   (0x02)
    44 #define R_TOC   (0x03)
    45 #define R_RTB   (0x04)
    46 #define R_GL    (0x05)
    47 #define R_TCL   (0x06)
    48 #define R_BA    (0x08)
    49 #define R_BR    (0x0a)
    50 #define R_RL    (0x0c)
    51 #define R_RLA   (0x0d)
    52 #define R_REF   (0x0f)
    53 #define R_TRL   (0x12)
    54 #define R_TRLA  (0x13)
    55 #define R_RRTBI (0x14)
    56 #define R_RRTBA (0x15)
    57 #define R_CAI   (0x16)
    58 #define R_CREL  (0x17)
    59 #define R_RBA   (0x18)
    60 #define R_RBAC  (0x19)
    61 #define R_RBR   (0x1a)
    62 #define R_RBRC  (0x1b)
    63 
    64 /* The first word of global linkage code.  This must be modified by
    65    filling in the correct TOC offset.  */
    66 
    67 #define XCOFF_GLINK_FIRST (0x81820000)  /* lwz r12,0(r2) */
    68 
    69 /* The remaining words of global linkage code.  */
    70 
    71 static unsigned long xcoff_glink_code[] = {
    72   0x90410014,   /* stw r2,20(r1) */
    73   0x800c0000,   /* lwz r0,0(r12) */
    74   0x804c0004,   /* lwz r2,4(r12) */
    75   0x7c0903a6,   /* mtctr r0 */
    76   0x4e800420,   /* bctr */
    77   0x0,          /* start of traceback table */
    78   0x000c8000,   /* traceback table */
    79   0x0           /* traceback table */
    80 };
    81 
    82 #define XCOFF_GLINK_SIZE \
    83   (((sizeof xcoff_glink_code / sizeof xcoff_glink_code[0]) * 4) + 4)
    8434
    8535/* We reuse the SEC_ROM flag as a mark flag for garbage collection.
     
    8838#define SEC_MARK (SEC_ROM)
    8939
    90 /* The ldhdr structure.  This appears at the start of the .loader
    91    section.  */
    92 
    93 struct internal_ldhdr {
    94   /* The version number: currently always 1.  */
    95   unsigned long l_version;
    96   /* The number of symbol table entries.  */
    97   bfd_size_type l_nsyms;
    98   /* The number of relocation table entries.  */
    99   bfd_size_type l_nreloc;
    100   /* The length of the import file string table.  */
    101   bfd_size_type l_istlen;
    102   /* The number of import files.  */
    103   bfd_size_type l_nimpid;
    104   /* The offset from the start of the .loader section to the first
    105      entry in the import file table.  */
    106   bfd_size_type l_impoff;
    107   /* The length of the string table.  */
    108   bfd_size_type l_stlen;
    109   /* The offset from the start of the .loader section to the first
    110      entry in the string table.  */
    111   bfd_size_type l_stoff;
    112 };
    113 
    114 struct external_ldhdr {
    115   bfd_byte l_version[4];
    116   bfd_byte l_nsyms[4];
    117   bfd_byte l_nreloc[4];
    118   bfd_byte l_istlen[4];
    119   bfd_byte l_nimpid[4];
    120   bfd_byte l_impoff[4];
    121   bfd_byte l_stlen[4];
    122   bfd_byte l_stoff[4];
    123 };
    124 
    125 #define LDHDRSZ (8 * 4)
    126 
    127 /* The ldsym structure.  This is used to represent a symbol in the
    128    .loader section.  */
    129 
    130 struct internal_ldsym {
    131   union {
    132     /* The symbol name if <= SYMNMLEN characters.  */
    133     char _l_name[SYMNMLEN];
    134     struct {
    135       /* Zero if the symbol name is more than SYMNMLEN characters.  */
    136       long _l_zeroes;
    137       /* The offset in the string table if the symbol name is more
    138          than SYMNMLEN characters.  */
    139       long _l_offset;
    140     } _l_l;
    141   } _l;
    142   /* The symbol value.  */
    143   bfd_vma l_value;
    144   /* The symbol section number.  */
    145   short l_scnum;
    146   /* The symbol type and flags.  */
    147   char l_smtype;
    148   /* The symbol storage class.  */
    149   char l_smclas;
    150   /* The import file ID.  */
    151   bfd_size_type l_ifile;
    152   /* Offset to the parameter type check string.  */
    153   bfd_size_type l_parm;
    154 };
    155 
    156 struct external_ldsym {
    157   union {
    158     bfd_byte _l_name[SYMNMLEN];
    159     struct {
    160       bfd_byte _l_zeroes[4];
    161       bfd_byte _l_offset[4];
    162     } _l_l;
    163   } _l;
    164   bfd_byte l_value[4];
    165   bfd_byte l_scnum[2];
    166   bfd_byte l_smtype[1];
    167   bfd_byte l_smclas[1];
    168   bfd_byte l_ifile[4];
    169   bfd_byte l_parm[4];
    170 };
    171 
    172 #define LDSYMSZ (8 + 3 * 4 + 2 + 2)
    173 
    174 /* These flags are for the l_smtype field (the lower three bits are an
    175    XTY_* value).  */
    176 
    177 /* Imported symbol.  */
    178 #define L_IMPORT (0x40)
    179 /* Entry point.  */
    180 #define L_ENTRY (0x20)
    181 /* Exported symbol.  */
    182 #define L_EXPORT (0x10)
    183 
    184 /* The ldrel structure.  This is used to represent a reloc in the
    185    .loader section.  */
    186 
    187 struct internal_ldrel {
    188   /* The reloc address.  */
    189   bfd_vma l_vaddr;
    190   /* The symbol table index in the .loader section symbol table.  */
    191   bfd_size_type l_symndx;
    192   /* The relocation type and size.  */
    193   short l_rtype;
    194   /* The section number this relocation applies to.  */
    195   short l_rsecnm;
    196 };
    197 
    198 struct external_ldrel {
    199   bfd_byte l_vaddr[4];
    200   bfd_byte l_symndx[4];
    201   bfd_byte l_rtype[2];
    202   bfd_byte l_rsecnm[2];
    203 };
    204 
    205 #define LDRELSZ (2 * 4 + 2 * 2)
    206 
    20740/* The list of import files.  */
    20841
    209 struct xcoff_import_file {
     42struct xcoff_import_file
     43{
    21044  /* The next entry in the list.  */
    21145  struct xcoff_import_file *next;
     
    21852};
    21953
    220 /* An entry in the XCOFF linker hash table.  */
    221 
    222 struct xcoff_link_hash_entry {
    223   struct bfd_link_hash_entry root;
    224 
    225   /* Symbol index in output file.  Set to -1 initially.  Set to -2 if
    226      there is a reloc against this symbol.  */
    227   long indx;
    228 
    229   /* If we have created a TOC entry for this symbol, this is the .tc
    230      section which holds it.  */
    231   asection *toc_section;
    232 
    233   union {
    234     /* If we have created a TOC entry (the XCOFF_SET_TOC flag is set),
    235        this is the offset in toc_section.  */
    236     bfd_vma toc_offset;
    237     /* If the TOC entry comes from an input file, this is set to the
    238        symbol index of the C_HIDEXT XMC_TC or XMC_TD symbol.  */
    239     long toc_indx;
    240   } u;
    241 
    242   /* If this symbol is a function entry point which is called, this
    243      field holds a pointer to the function descriptor.  If this symbol
    244      is a function descriptor, this field holds a pointer to the
    245      function entry point.  */
    246   struct xcoff_link_hash_entry *descriptor;
    247 
    248   /* The .loader symbol table entry, if there is one.  */
    249   struct internal_ldsym *ldsym;
    250 
    251   /* If XCOFF_BUILT_LDSYM is set, this is the .loader symbol table
    252      index.  If XCOFF_BUILD_LDSYM is clear, and XCOFF_IMPORT is set,
    253      this is the l_ifile value.  */
    254   long ldindx;
    255 
    256   /* Some linker flags.  */
    257   unsigned short flags;
    258   /* Symbol is referenced by a regular object.  */
    259 #define XCOFF_REF_REGULAR (01)
    260   /* Symbol is defined by a regular object.  */
    261 #define XCOFF_DEF_REGULAR (02)
    262   /* Symbol is defined by a dynamic object.  */
    263 #define XCOFF_DEF_DYNAMIC (04)
    264   /* Symbol is used in a reloc being copied into the .loader section.  */
    265 #define XCOFF_LDREL (010)
    266   /* Symbol is the entry point.  */
    267 #define XCOFF_ENTRY (020)
    268   /* Symbol is called; this is, it appears in a R_BR reloc.  */
    269 #define XCOFF_CALLED (040)
    270   /* Symbol needs the TOC entry filled in.  */
    271 #define XCOFF_SET_TOC (0100)
    272   /* Symbol is explicitly imported.  */
    273 #define XCOFF_IMPORT (0200)
    274   /* Symbol is explicitly exported.  */
    275 #define XCOFF_EXPORT (0400)
    276   /* Symbol has been processed by xcoff_build_ldsyms.  */
    277 #define XCOFF_BUILT_LDSYM (01000)
    278   /* Symbol is mentioned by a section which was not garbage collected.  */
    279 #define XCOFF_MARK (02000)
    280   /* Symbol size is recorded in size_list list from hash table.  */
    281 #define XCOFF_HAS_SIZE (04000)
    282   /* Symbol is a function descriptor.  */
    283 #define XCOFF_DESCRIPTOR (010000)
    284   /* Multiple definitions have been for the symbol.  */
    285 #define XCOFF_MULTIPLY_DEFINED (020000)
    286 
    287   /* The storage mapping class.  */
    288   unsigned char smclas;
    289 };
    290 
    291 /* The XCOFF linker hash table.  */
    292 
    293 struct xcoff_link_hash_table {
    294   struct bfd_link_hash_table root;
    295 
    296   /* The .debug string hash table.  We need to compute this while
    297      reading the input files, so that we know how large the .debug
    298      section will be before we assign section positions.  */
    299   struct bfd_strtab_hash *debug_strtab;
    300 
    301   /* The .debug section we will use for the final output.  */
    302   asection *debug_section;
    303 
    304   /* The .loader section we will use for the final output.  */
    305   asection *loader_section;
    306 
    307   /* A count of non TOC relative relocs which will need to be
    308      allocated in the .loader section.  */
    309   size_t ldrel_count;
    310 
    311   /* The .loader section header.  */
    312   struct internal_ldhdr ldhdr;
    313 
    314   /* The .gl section we use to hold global linkage code.  */
    315   asection *linkage_section;
    316 
    317   /* The .tc section we use to hold toc entries we build for global
    318      linkage code.  */
    319   asection *toc_section;
    320 
    321   /* The .ds section we use to hold function descriptors which we
    322      create for exported symbols.  */
    323   asection *descriptor_section;
    324 
    325   /* The list of import files.  */
    326   struct xcoff_import_file *imports;
    327 
    328   /* Required alignment of sections within the output file.  */
    329   unsigned long file_align;
    330 
    331   /* Whether the .text section must be read-only.  */
    332   boolean textro;
    333 
    334   /* Whether garbage collection was done.  */
    335   boolean gc;
    336 
    337   /* A linked list of symbols for which we have size information.  */
    338   struct xcoff_link_size_list {
    339     struct xcoff_link_size_list *next;
    340     struct xcoff_link_hash_entry *h;
    341     bfd_size_type size;
    342   } *size_list;
    343 
    344   /* Magic sections: _text, _etext, _data, _edata, _end, end.  */
    345   asection *special_sections[6];
    346 };
    347 
    34854/* Information we keep for each section in the output file during the
    34955   final link phase.  */
    35056
    351 struct xcoff_link_section_info {
     57struct xcoff_link_section_info
     58{
    35259  /* The relocs to be output.  */
    35360  struct internal_reloc *relocs;
     
    36875/* Information that we pass around while doing the final link step.  */
    36976
    370 struct xcoff_final_link_info {
     77struct xcoff_final_link_info
     78{
    37179  /* General link information.  */
    37280  struct bfd_link_info *info;
     
    38593  long toc_symindx;
    38694  /* Start of .loader symbols.  */
    387   struct external_ldsym *ldsym;
     95  bfd_byte *ldsym;
    38896  /* Next .loader reloc to swap out.  */
    389   struct external_ldrel *ldrel;
     97  bfd_byte *ldrel;
    39098  /* File position of start of line numbers.  */
    39199  file_ptr line_filepos;
     
    406114};
    407115
    408 static void xcoff_swap_ldhdr_in
    409   PARAMS ((bfd *, const struct external_ldhdr *, struct internal_ldhdr *));
    410 static void xcoff_swap_ldhdr_out
    411   PARAMS ((bfd *, const struct internal_ldhdr *, struct external_ldhdr *));
    412 static void xcoff_swap_ldsym_in
    413   PARAMS ((bfd *, const struct external_ldsym *, struct internal_ldsym *));
    414 static void xcoff_swap_ldsym_out
    415   PARAMS ((bfd *, const struct internal_ldsym *, struct external_ldsym *));
    416 static void xcoff_swap_ldrel_in
    417   PARAMS ((bfd *, const struct external_ldrel *, struct internal_ldrel *));
    418 static void xcoff_swap_ldrel_out
    419   PARAMS ((bfd *, const struct internal_ldrel *, struct external_ldrel *));
    420116static struct bfd_hash_entry *xcoff_link_hash_newfunc
    421117  PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
    422 static boolean xcoff_get_section_contents PARAMS ((bfd *, asection *));
     118static bfd_boolean xcoff_get_section_contents PARAMS ((bfd *, asection *));
    423119static struct internal_reloc *xcoff_read_internal_relocs
    424   PARAMS ((bfd *, asection *, boolean, bfd_byte *, boolean,
     120  PARAMS ((bfd *, asection *, bfd_boolean, bfd_byte *, bfd_boolean,
    425121           struct internal_reloc *));
    426 static boolean xcoff_link_add_object_symbols
     122static bfd_boolean xcoff_link_add_object_symbols
    427123  PARAMS ((bfd *, struct bfd_link_info *));
    428 static boolean xcoff_link_check_archive_element
    429   PARAMS ((bfd *, struct bfd_link_info *, boolean *));
    430 static boolean xcoff_link_check_ar_symbols
    431   PARAMS ((bfd *, struct bfd_link_info *, boolean *));
    432 static boolean xcoff_link_check_dynamic_ar_symbols
    433   PARAMS ((bfd *, struct bfd_link_info *, boolean *));
     124static bfd_boolean xcoff_link_check_archive_element
     125  PARAMS ((bfd *, struct bfd_link_info *, bfd_boolean *));
     126static bfd_boolean xcoff_link_check_ar_symbols
     127  PARAMS ((bfd *, struct bfd_link_info *, bfd_boolean *));
     128static bfd_boolean xcoff_link_check_dynamic_ar_symbols
     129  PARAMS ((bfd *, struct bfd_link_info *, bfd_boolean *));
    434130static bfd_size_type xcoff_find_reloc
    435131  PARAMS ((struct internal_reloc *, bfd_size_type, bfd_vma));
    436 static boolean xcoff_link_add_symbols PARAMS ((bfd *, struct bfd_link_info *));
    437 static boolean xcoff_link_add_dynamic_symbols
     132static bfd_boolean xcoff_link_add_symbols
    438133  PARAMS ((bfd *, struct bfd_link_info *));
    439 static boolean xcoff_mark_symbol
     134static bfd_boolean xcoff_link_add_dynamic_symbols
     135  PARAMS ((bfd *, struct bfd_link_info *));
     136static bfd_boolean xcoff_mark_symbol
    440137  PARAMS ((struct bfd_link_info *, struct xcoff_link_hash_entry *));
    441 static boolean xcoff_mark PARAMS ((struct bfd_link_info *, asection *));
     138static bfd_boolean xcoff_mark PARAMS ((struct bfd_link_info *, asection *));
    442139static void xcoff_sweep PARAMS ((struct bfd_link_info *));
    443 static boolean xcoff_build_ldsyms
     140static bfd_boolean xcoff_build_ldsyms
    444141  PARAMS ((struct xcoff_link_hash_entry *, PTR));
    445 static boolean xcoff_link_input_bfd
     142static bfd_boolean xcoff_link_input_bfd
    446143  PARAMS ((struct xcoff_final_link_info *, bfd *));
    447 static boolean xcoff_write_global_symbol
     144static bfd_boolean xcoff_write_global_symbol
    448145  PARAMS ((struct xcoff_link_hash_entry *, PTR));
    449 static boolean xcoff_reloc_link_order
     146static bfd_boolean xcoff_reloc_link_order
    450147  PARAMS ((bfd *, struct xcoff_final_link_info *, asection *,
    451148           struct bfd_link_order *));
     
    453150
    454151
    455 /* Routines to swap information in the XCOFF .loader section.  If we
    456    ever need to write an XCOFF loader, this stuff will need to be
    457    moved to another file shared by the linker (which XCOFF calls the
    458    ``binder'') and the loader.  */
    459 
    460 /* Swap in the ldhdr structure.  */
    461 
    462 static void
    463 xcoff_swap_ldhdr_in (abfd, src, dst)
    464      bfd *abfd;
    465      const struct external_ldhdr *src;
    466      struct internal_ldhdr *dst;
    467 {
    468   dst->l_version = bfd_get_32 (abfd, src->l_version);
    469   dst->l_nsyms = bfd_get_32 (abfd, src->l_nsyms);
    470   dst->l_nreloc = bfd_get_32 (abfd, src->l_nreloc);
    471   dst->l_istlen = bfd_get_32 (abfd, src->l_istlen);
    472   dst->l_nimpid = bfd_get_32 (abfd, src->l_nimpid);
    473   dst->l_impoff = bfd_get_32 (abfd, src->l_impoff);
    474   dst->l_stlen = bfd_get_32 (abfd, src->l_stlen);
    475   dst->l_stoff = bfd_get_32 (abfd, src->l_stoff);
    476 }
    477 
    478 /* Swap out the ldhdr structure.  */
    479 
    480 static void
    481 xcoff_swap_ldhdr_out (abfd, src, dst)
    482      bfd *abfd;
    483      const struct internal_ldhdr *src;
    484      struct external_ldhdr *dst;
    485 {
    486   bfd_put_32 (abfd, src->l_version, dst->l_version);
    487   bfd_put_32 (abfd, src->l_nsyms, dst->l_nsyms);
    488   bfd_put_32 (abfd, src->l_nreloc, dst->l_nreloc);
    489   bfd_put_32 (abfd, src->l_istlen, dst->l_istlen);
    490   bfd_put_32 (abfd, src->l_nimpid, dst->l_nimpid);
    491   bfd_put_32 (abfd, src->l_impoff, dst->l_impoff);
    492   bfd_put_32 (abfd, src->l_stlen, dst->l_stlen);
    493   bfd_put_32 (abfd, src->l_stoff, dst->l_stoff);
    494 }
    495 
    496 /* Swap in the ldsym structure.  */
    497 
    498 static void
    499 xcoff_swap_ldsym_in (abfd, src, dst)
    500      bfd *abfd;
    501      const struct external_ldsym *src;
    502      struct internal_ldsym *dst;
    503 {
    504   if (bfd_get_32 (abfd, src->_l._l_l._l_zeroes) != 0)
    505     memcpy (dst->_l._l_name, src->_l._l_name, SYMNMLEN);
    506   else
    507     {
    508       dst->_l._l_l._l_zeroes = 0;
    509       dst->_l._l_l._l_offset = bfd_get_32 (abfd, src->_l._l_l._l_offset);
    510     }
    511   dst->l_value = bfd_get_32 (abfd, src->l_value);
    512   dst->l_scnum = bfd_get_16 (abfd, src->l_scnum);
    513   dst->l_smtype = bfd_get_8 (abfd, src->l_smtype);
    514   dst->l_smclas = bfd_get_8 (abfd, src->l_smclas);
    515   dst->l_ifile = bfd_get_32 (abfd, src->l_ifile);
    516   dst->l_parm = bfd_get_32 (abfd, src->l_parm);
    517 }
    518 
    519 /* Swap out the ldsym structure.  */
    520 
    521 static void
    522 xcoff_swap_ldsym_out (abfd, src, dst)
    523      bfd *abfd;
    524      const struct internal_ldsym *src;
    525      struct external_ldsym *dst;
    526 {
    527   if (src->_l._l_l._l_zeroes != 0)
    528     memcpy (dst->_l._l_name, src->_l._l_name, SYMNMLEN);
    529   else
    530     {
    531       bfd_put_32 (abfd, 0, dst->_l._l_l._l_zeroes);
    532       bfd_put_32 (abfd, src->_l._l_l._l_offset, dst->_l._l_l._l_offset);
    533     }
    534   bfd_put_32 (abfd, src->l_value, dst->l_value);
    535   bfd_put_16 (abfd, src->l_scnum, dst->l_scnum);
    536   bfd_put_8 (abfd, src->l_smtype, dst->l_smtype);
    537   bfd_put_8 (abfd, src->l_smclas, dst->l_smclas);
    538   bfd_put_32 (abfd, src->l_ifile, dst->l_ifile);
    539   bfd_put_32 (abfd, src->l_parm, dst->l_parm);
    540 }
    541 
    542 /* Swap in the ldrel structure.  */
    543 
    544 static void
    545 xcoff_swap_ldrel_in (abfd, src, dst)
    546      bfd *abfd;
    547      const struct external_ldrel *src;
    548      struct internal_ldrel *dst;
    549 {
    550   dst->l_vaddr = bfd_get_32 (abfd, src->l_vaddr);
    551   dst->l_symndx = bfd_get_32 (abfd, src->l_symndx);
    552   dst->l_rtype = bfd_get_16 (abfd, src->l_rtype);
    553   dst->l_rsecnm = bfd_get_16 (abfd, src->l_rsecnm);
    554 }
    555 
    556 /* Swap out the ldrel structure.  */
    557 
    558 static void
    559 xcoff_swap_ldrel_out (abfd, src, dst)
    560      bfd *abfd;
    561      const struct internal_ldrel *src;
    562      struct external_ldrel *dst;
    563 {
    564   bfd_put_32 (abfd, src->l_vaddr, dst->l_vaddr);
    565   bfd_put_32 (abfd, src->l_symndx, dst->l_symndx);
    566   bfd_put_16 (abfd, src->l_rtype, dst->l_rtype);
    567   bfd_put_16 (abfd, src->l_rsecnm, dst->l_rsecnm);
    568 }
    569 
    570152
    571153/* Routines to read XCOFF dynamic information.  This don't really
     
    575157/* Read the contents of a section.  */
    576158
    577 static boolean
     159static bfd_boolean
    578160xcoff_get_section_contents (abfd, sec)
    579161     bfd *abfd;
    580162     asection *sec;
    581163{
     164
    582165  if (coff_section_data (abfd, sec) == NULL)
    583166    {
    584       sec->used_by_bfd = bfd_zalloc (abfd,
    585                                      sizeof (struct coff_section_tdata));
     167      bfd_size_type amt = sizeof (struct coff_section_tdata);
     168      sec->used_by_bfd = bfd_zalloc (abfd, amt);
    586169      if (sec->used_by_bfd == NULL)
    587         return false;
     170        return FALSE;
    588171    }
    589172
    590173  if (coff_section_data (abfd, sec)->contents == NULL)
    591174    {
    592       coff_section_data (abfd, sec)->contents =
    593         (bfd_byte *) bfd_malloc (sec->_raw_size);
     175      coff_section_data (abfd, sec)->contents = ((bfd_byte *)
     176                                                 bfd_malloc (sec->_raw_size));
    594177      if (coff_section_data (abfd, sec)->contents == NULL)
    595         return false;
     178        return FALSE;
    596179
    597180      if (! bfd_get_section_contents (abfd, sec,
    598181                                      coff_section_data (abfd, sec)->contents,
    599182                                      (file_ptr) 0, sec->_raw_size))
    600         return false;
    601     }
    602 
    603   return true;
     183        return FALSE;
     184    }
     185
     186  return TRUE;
    604187}
    605188
     
    631214  contents = coff_section_data (abfd, lsec)->contents;
    632215
    633   xcoff_swap_ldhdr_in (abfd, (struct external_ldhdr *) contents, &ldhdr);
     216  bfd_xcoff_swap_ldhdr_in (abfd, (PTR) contents, &ldhdr);
    634217
    635218  return (ldhdr.l_nsyms + 1) * sizeof (asymbol *);
     
    647230  struct internal_ldhdr ldhdr;
    648231  const char *strings;
    649   struct external_ldsym *elsym, *elsymend;
     232  bfd_byte *elsym, *elsymend;
    650233  coff_symbol_type *symbuf;
    651234
     
    667250  contents = coff_section_data (abfd, lsec)->contents;
    668251
    669   coff_section_data (abfd, lsec)->keep_contents = true;
    670 
    671   xcoff_swap_ldhdr_in (abfd, (struct external_ldhdr *) contents, &ldhdr);
     252  coff_section_data (abfd, lsec)->keep_contents = TRUE;
     253
     254  bfd_xcoff_swap_ldhdr_in (abfd, contents, &ldhdr);
    672255
    673256  strings = (char *) contents + ldhdr.l_stoff;
     
    678261    return -1;
    679262
    680   elsym = (struct external_ldsym *) (contents + LDHDRSZ);
    681   elsymend = elsym + ldhdr.l_nsyms;
    682   for (; elsym < elsymend; elsym++, symbuf++, psyms++)
     263  elsym = contents + bfd_xcoff_loader_symbol_offset(abfd, &ldhdr);
     264
     265  elsymend = elsym + ldhdr.l_nsyms * bfd_xcoff_ldsymsz(abfd);
     266  for (; elsym < elsymend; elsym += bfd_xcoff_ldsymsz(abfd), symbuf++, psyms++)
    683267    {
    684268      struct internal_ldsym ldsym;
    685269
    686       xcoff_swap_ldsym_in (abfd, elsym, &ldsym);
     270      bfd_xcoff_swap_ldsym_in (abfd, elsym, &ldsym);
    687271
    688272      symbuf->symbol.the_bfd = abfd;
     
    692276      else
    693277        {
    694           int i;
    695 
    696           for (i = 0; i < SYMNMLEN; i++)
    697             if (ldsym._l._l_name[i] == '\0')
    698               break;
    699           if (i < SYMNMLEN)
    700             symbuf->symbol.name = (char *) elsym->_l._l_name;
    701           else
    702             {
    703               char *c;
    704 
    705               c = bfd_alloc (abfd, SYMNMLEN + 1);
    706               if (c == NULL)
    707                 return -1;
    708               memcpy (c, ldsym._l._l_name, SYMNMLEN);
    709               c[SYMNMLEN] = '\0';
    710               symbuf->symbol.name = c;
    711             }
     278          char *c;
     279
     280          c = bfd_alloc (abfd, (bfd_size_type) SYMNMLEN + 1);
     281          if (c == NULL)
     282            return -1;
     283          memcpy (c, ldsym._l._l_name, SYMNMLEN);
     284          c[SYMNMLEN] = '\0';
     285          symbuf->symbol.name = c;
    712286        }
    713287
     
    724298
    725299      /* FIXME: We have no way to record the other information stored
    726         with the loader symbol.  */
     300        with the loader symbol.  */
    727301
    728302      *psyms = (asymbol *) symbuf;
     
    761335  contents = coff_section_data (abfd, lsec)->contents;
    762336
    763   xcoff_swap_ldhdr_in (abfd, (struct external_ldhdr *) contents, &ldhdr);
     337  bfd_xcoff_swap_ldhdr_in (abfd, (struct external_ldhdr *) contents, &ldhdr);
    764338
    765339  return (ldhdr.l_nreloc + 1) * sizeof (arelent *);
    766340}
    767 
    768 /* The typical dynamic reloc.  */
    769 
    770 static reloc_howto_type xcoff_dynamic_reloc =
    771   HOWTO (0,                     /* type */
    772          0,                     /* rightshift */
    773          2,                     /* size (0 = byte, 1 = short, 2 = long) */
    774          32,                    /* bitsize */
    775          false,                 /* pc_relative */
    776          0,                     /* bitpos */
    777          complain_overflow_bitfield, /* complain_on_overflow */
    778          0,                     /* special_function */
    779          "R_POS",               /* name */
    780          true,                  /* partial_inplace */
    781          0xffffffff,            /* src_mask */
    782          0xffffffff,            /* dst_mask */
    783          false);                /* pcrel_offset */
    784341
    785342/* Get the dynamic relocs.  */
     
    795352  struct internal_ldhdr ldhdr;
    796353  arelent *relbuf;
    797   struct external_ldrel *elrel, *elrelend;
     354  bfd_byte *elrel, *elrelend;
    798355
    799356  if ((abfd->flags & DYNAMIC) == 0)
     
    814371  contents = coff_section_data (abfd, lsec)->contents;
    815372
    816   xcoff_swap_ldhdr_in (abfd, (struct external_ldhdr *) contents, &ldhdr);
     373  bfd_xcoff_swap_ldhdr_in (abfd, contents, &ldhdr);
    817374
    818375  relbuf = (arelent *) bfd_alloc (abfd, ldhdr.l_nreloc * sizeof (arelent));
     
    820377    return -1;
    821378
    822   elrel = ((struct external_ldrel *)
    823            (contents + LDHDRSZ + ldhdr.l_nsyms * LDSYMSZ));
    824   elrelend = elrel + ldhdr.l_nreloc;
    825   for (; elrel < elrelend; elrel++, relbuf++, prelocs++)
     379  elrel = contents + bfd_xcoff_loader_reloc_offset(abfd, &ldhdr);
     380
     381  elrelend = elrel + ldhdr.l_nreloc * bfd_xcoff_ldrelsz(abfd);
     382  for (; elrel < elrelend; elrel += bfd_xcoff_ldrelsz(abfd), relbuf++,
     383         prelocs++)
    826384    {
    827385      struct internal_ldrel ldrel;
    828386
    829       xcoff_swap_ldrel_in (abfd, elrel, &ldrel);
     387      bfd_xcoff_swap_ldrel_in (abfd, elrel, &ldrel);
    830388
    831389      if (ldrel.l_symndx >= 3)
     
    866424
    867425      /* Most dynamic relocs have the same type.  FIXME: This is only
    868         correct if ldrel.l_rtype == 0.  In other cases, we should use
    869         a different howto.  */
    870       relbuf->howto = &xcoff_dynamic_reloc;
     426        correct if ldrel.l_rtype == 0.  In other cases, we should use
     427        a different howto.  */
     428      relbuf->howto = bfd_xcoff_dynamic_reloc_howto(abfd);
    871429
    872430      /* FIXME: We have no way to record the l_rsecnm field.  */
     
    926484{
    927485  struct xcoff_link_hash_table *ret;
    928 
    929   ret = ((struct xcoff_link_hash_table *)
    930          bfd_alloc (abfd, sizeof (struct xcoff_link_hash_table)));
     486  bfd_size_type amt = sizeof (struct xcoff_link_hash_table);
     487
     488  ret = (struct xcoff_link_hash_table *) bfd_malloc (amt);
    931489  if (ret == (struct xcoff_link_hash_table *) NULL)
    932490    return (struct bfd_link_hash_table *) NULL;
    933491  if (! _bfd_link_hash_table_init (&ret->root, abfd, xcoff_link_hash_newfunc))
    934492    {
    935       bfd_release (abfd, ret);
     493      free (ret);
    936494      return (struct bfd_link_hash_table *) NULL;
    937495    }
     
    947505  ret->imports = NULL;
    948506  ret->file_align = 0;
    949   ret->textro = false;
    950   ret->gc = false;
     507  ret->textro = FALSE;
     508  ret->gc = FALSE;
    951509  memset (ret->special_sections, 0, sizeof ret->special_sections);
    952510
     
    954512     record that fact now, before the sizeof_headers routine could be
    955513     called.  */
    956   xcoff_data (abfd)->full_aouthdr = true;
     514  xcoff_data (abfd)->full_aouthdr = TRUE;
    957515
    958516  return &ret->root;
    959517}
    960518
    961 /* Look up an entry in an XCOFF link hash table.  */
    962 
    963 #define xcoff_link_hash_lookup(table, string, create, copy, follow) \
    964   ((struct xcoff_link_hash_entry *) \
    965    bfd_link_hash_lookup (&(table)->root, (string), (create), (copy),\
    966                          (follow)))
    967 
    968 /* Traverse an XCOFF link hash table.  */
    969 
    970 #define xcoff_link_hash_traverse(table, func, info)                     \
    971   (bfd_link_hash_traverse                                               \
    972    (&(table)->root,                                                     \
    973     (boolean (*) PARAMS ((struct bfd_link_hash_entry *, PTR))) (func),  \
    974     (info)))
    975 
    976 /* Get the XCOFF link hash table from the info structure.  This is
    977    just a cast.  */
    978 
    979 #define xcoff_hash_table(p) ((struct xcoff_link_hash_table *) ((p)->hash))
     519/* Free a XCOFF link hash table.  */
     520
     521void
     522_bfd_xcoff_bfd_link_hash_table_free (hash)
     523     struct bfd_link_hash_table *hash;
     524{
     525  struct xcoff_link_hash_table *ret = (struct xcoff_link_hash_table *) hash;
     526
     527  _bfd_stringtab_free (ret->debug_strtab);
     528  bfd_hash_table_free (&ret->root.table);
     529  free (ret);
     530}
    980531
    981532
     
    989540     bfd *abfd;
    990541     asection *sec;
    991      boolean cache;
     542     bfd_boolean cache;
    992543     bfd_byte *external_relocs;
    993      boolean require_internal;
     544     bfd_boolean require_internal;
    994545     struct internal_reloc *internal_relocs;
    995546{
     547
    996548  if (coff_section_data (abfd, sec) != NULL
    997549      && coff_section_data (abfd, sec)->relocs == NULL
     
    1008560          && enclosing->reloc_count > 0)
    1009561        {
    1010           if (_bfd_coff_read_internal_relocs (abfd, enclosing, true,
    1011                                               external_relocs, false,
     562          if (_bfd_coff_read_internal_relocs (abfd, enclosing, TRUE,
     563                                              external_relocs, FALSE,
    1012564                                              (struct internal_reloc *) NULL)
    1013565              == NULL)
     
    1023575          off = ((sec->rel_filepos - enclosing->rel_filepos)
    1024576                 / bfd_coff_relsz (abfd));
     577
    1025578          if (! require_internal)
    1026579            return coff_section_data (abfd, enclosing)->relocs + off;
     
    1040593   appropriate.  */
    1041594
    1042 boolean
     595bfd_boolean
    1043596_bfd_xcoff_bfd_link_add_symbols (abfd, info)
    1044597     bfd *abfd;
    1045598     struct bfd_link_info *info;
    1046599{
     600
    1047601  switch (bfd_get_format (abfd))
    1048602    {
     
    1052606    case bfd_archive:
    1053607      /* If the archive has a map, do the usual search.  We then need
    1054          to check the archive for stripped dynamic objects, because
    1055          they will not appear in the archive map even though they
    1056          should, perhaps, be included.  If the archive has no map, we
    1057          just consider each object file in turn, since that apparently
    1058          is what the AIX native linker does.  */
     608         to check the archive for dynamic objects, because they may not
     609         appear in the archive map even though they should, perhaps, be
     610         included.  If the archive has no map, we just consider each object
     611         file in turn, since that apparently is what the AIX native linker
     612        does.  */
    1059613      if (bfd_has_map (abfd))
    1060614        {
    1061615          if (! (_bfd_generic_link_add_archive_symbols
    1062616                 (abfd, info, xcoff_link_check_archive_element)))
    1063             return false;
     617            return FALSE;
    1064618        }
    1065619
     
    1071625          {
    1072626            if (bfd_check_format (member, bfd_object)
    1073                 && (! bfd_has_map (abfd)
    1074                     || ((member->flags & DYNAMIC) != 0
    1075                         && (member->flags & HAS_SYMS) == 0)))
     627                && (info->hash->creator == member->xvec)
     628                && (! bfd_has_map (abfd) || (member->flags & DYNAMIC) != 0))
    1076629              {
    1077                 boolean needed;
    1078 
    1079                 if (! xcoff_link_check_archive_element (member, info, &needed))
    1080                   return false;
     630                bfd_boolean needed;
     631
     632                if (! xcoff_link_check_archive_element (member, info,
     633                                                        &needed))
     634                  return FALSE;
    1081635                if (needed)
    1082636                  member->archive_pass = -1;
     
    1086640      }
    1087641
    1088       return true;
     642      return TRUE;
    1089643
    1090644    default:
    1091645      bfd_set_error (bfd_error_wrong_format);
    1092       return false;
     646      return FALSE;
    1093647    }
    1094648}
     
    1096650/* Add symbols from an XCOFF object file.  */
    1097651
    1098 static boolean
     652static bfd_boolean
    1099653xcoff_link_add_object_symbols (abfd, info)
    1100654     bfd *abfd;
    1101655     struct bfd_link_info *info;
    1102656{
     657
    1103658  if (! _bfd_coff_get_external_symbols (abfd))
    1104     return false;
     659    return FALSE;
    1105660  if (! xcoff_link_add_symbols (abfd, info))
    1106     return false;
     661    return FALSE;
    1107662  if (! info->keep_memory)
    1108663    {
    1109664      if (! _bfd_coff_free_symbols (abfd))
    1110         return false;
    1111     }
    1112   return true;
     665        return FALSE;
     666    }
     667  return TRUE;
    1113668}
    1114669
     
    1118673   _bfd_generic_link_add_archive_symbols.  */
    1119674
    1120 static boolean
     675static bfd_boolean
    1121676xcoff_link_check_archive_element (abfd, info, pneeded)
    1122677     bfd *abfd;
    1123678     struct bfd_link_info *info;
    1124      boolean *pneeded;
     679     bfd_boolean *pneeded;
    1125680{
     681
    1126682  if (! _bfd_coff_get_external_symbols (abfd))
    1127     return false;
     683    return FALSE;
    1128684
    1129685  if (! xcoff_link_check_ar_symbols (abfd, info, pneeded))
    1130     return false;
     686    return FALSE;
    1131687
    1132688  if (*pneeded)
    1133689    {
    1134690      if (! xcoff_link_add_symbols (abfd, info))
    1135         return false;
     691        return FALSE;
    1136692    }
    1137693
     
    1139695    {
    1140696      if (! _bfd_coff_free_symbols (abfd))
    1141         return false;
    1142     }
    1143 
    1144   return true;
     697        return FALSE;
     698    }
     699
     700  return TRUE;
    1145701}
    1146702
     
    1148704   included in the link.  */
    1149705
    1150 static boolean
     706static bfd_boolean
    1151707xcoff_link_check_ar_symbols (abfd, info, pneeded)
    1152708     bfd *abfd;
    1153709     struct bfd_link_info *info;
    1154      boolean *pneeded;
     710     bfd_boolean *pneeded;
    1155711{
    1156712  bfd_size_type symesz;
     
    1158714  bfd_byte *esym_end;
    1159715
    1160   *pneeded = false;
     716  *pneeded = FALSE;
    1161717
    1162718  if ((abfd->flags & DYNAMIC) != 0
     
    1181737
    1182738          /* This symbol is externally visible, and is defined by this
    1183              object file.  */
     739             object file.  */
    1184740
    1185741          name = _bfd_coff_internal_syment_name (abfd, &sym, buf);
     742
    1186743          if (name == NULL)
    1187             return false;
    1188           h = bfd_link_hash_lookup (info->hash, name, false, false, true);
     744            return FALSE;
     745          h = bfd_link_hash_lookup (info->hash, name, FALSE, FALSE, TRUE);
    1189746
    1190747          /* We are only interested in symbols that are currently
     
    1195752          if (h != (struct bfd_link_hash_entry *) NULL
    1196753              && h->type == bfd_link_hash_undefined
    1197               && (info->hash->creator != abfd->xvec
     754              && (info->hash->creator != abfd->xvec
    1198755                  || (((struct xcoff_link_hash_entry *) h)->flags
    1199756                      & XCOFF_DEF_DYNAMIC) == 0))
    1200757            {
    1201758              if (! (*info->callbacks->add_archive_element) (info, abfd, name))
    1202                 return false;
    1203               *pneeded = true;
    1204               return true;
     759                return FALSE;
     760              *pneeded = TRUE;
     761              return TRUE;
    1205762            }
    1206763        }
     
    1210767
    1211768  /* We do not need this object file.  */
    1212   return true;
     769  return TRUE;
    1213770}
    1214771
     
    1217774   symbols, not the normal symbol table, so we do too.  */
    1218775
    1219 static boolean
     776static bfd_boolean
    1220777xcoff_link_check_dynamic_ar_symbols (abfd, info, pneeded)
    1221778     bfd *abfd;
    1222779     struct bfd_link_info *info;
    1223      boolean *pneeded;
     780     bfd_boolean *pneeded;
    1224781{
    1225782  asection *lsec;
    1226   bfd_byte *buf;
     783  bfd_byte *contents;
    1227784  struct internal_ldhdr ldhdr;
    1228785  const char *strings;
    1229   struct external_ldsym *elsym, *elsymend;
    1230 
    1231   *pneeded = false;
     786  bfd_byte *elsym, *elsymend;
     787
     788  *pneeded = FALSE;
    1232789
    1233790  lsec = bfd_get_section_by_name (abfd, ".loader");
     
    1235792    {
    1236793      /* There are no symbols, so don't try to include it.  */
    1237       return true;
     794      return TRUE;
    1238795    }
    1239796
    1240797  if (! xcoff_get_section_contents (abfd, lsec))
    1241     return false;
    1242   buf = coff_section_data (abfd, lsec)->contents;
    1243 
    1244   xcoff_swap_ldhdr_in (abfd, (struct external_ldhdr *) buf, &ldhdr);
    1245 
    1246   strings = (char *) buf + ldhdr.l_stoff;
    1247 
    1248   elsym = (struct external_ldsym *) (buf + LDHDRSZ);
    1249   elsymend = elsym + ldhdr.l_nsyms;
    1250   for (; elsym < elsymend; elsym++)
     798    return FALSE;
     799  contents = coff_section_data (abfd, lsec)->contents;
     800
     801  bfd_xcoff_swap_ldhdr_in (abfd, contents, &ldhdr);
     802
     803  strings = (char *) contents + ldhdr.l_stoff;
     804
     805  elsym = contents + bfd_xcoff_loader_symbol_offset(abfd, &ldhdr);
     806
     807  elsymend = elsym + ldhdr.l_nsyms * bfd_xcoff_ldsymsz(abfd);
     808  for (; elsym < elsymend; elsym += bfd_xcoff_ldsymsz(abfd))
    1251809    {
    1252810      struct internal_ldsym ldsym;
     
    1255813      struct bfd_link_hash_entry *h;
    1256814
    1257       xcoff_swap_ldsym_in (abfd, elsym, &ldsym);
     815      bfd_xcoff_swap_ldsym_in (abfd, elsym, &ldsym);
    1258816
    1259817      /* We are only interested in exported symbols.  */
     
    1270828        }
    1271829
    1272       h = bfd_link_hash_lookup (info->hash, name, false, false, true);
     830      h = bfd_link_hash_lookup (info->hash, name, FALSE, FALSE, TRUE);
    1273831
    1274832      /* We are only interested in symbols that are currently
    1275         undefined.  At this point we know that we are using an XCOFF
    1276         hash table.  */
     833        undefined.  At this point we know that we are using an XCOFF
     834        hash table.  */
    1277835      if (h != NULL
    1278836          && h->type == bfd_link_hash_undefined
     
    1281839        {
    1282840          if (! (*info->callbacks->add_archive_element) (info, abfd, name))
    1283             return false;
    1284           *pneeded = true;
    1285           return true;
     841            return FALSE;
     842          *pneeded = TRUE;
     843          return TRUE;
    1286844        }
    1287845    }
     
    1289847  /* We do not need this shared object.  */
    1290848
    1291   if (buf != NULL && ! coff_section_data (abfd, lsec)->keep_contents)
     849  if (contents != NULL && ! coff_section_data (abfd, lsec)->keep_contents)
    1292850    {
    1293851      free (coff_section_data (abfd, lsec)->contents);
     
    1295853    }
    1296854
    1297   return true;
     855  return TRUE;
    1298856}
    1299857
     
    1346904
    1347905  return min;
     906}
     907
     908
     909/* xcoff_link_create_extra_sections
     910
     911   Takes care of creating the .loader, .gl, .ds, .debug and sections.  */
     912
     913static bfd_boolean
     914xcoff_link_create_extra_sections(bfd * abfd, struct bfd_link_info *info)
     915{
     916
     917  bfd_boolean return_value = FALSE;
     918
     919  if (info->hash->creator == abfd->xvec)
     920    {
     921
     922      /* We need to build a .loader section, so we do it here.  This
     923         won't work if we're producing an XCOFF output file with no
     924         XCOFF input files.  FIXME.  */
     925
     926      if (xcoff_hash_table (info)->loader_section == NULL)
     927        {
     928          asection *lsec;
     929
     930          lsec = bfd_make_section_anyway (abfd, ".loader");
     931          if (lsec == NULL)
     932            {
     933              goto end_return;
     934            }
     935          xcoff_hash_table (info)->loader_section = lsec;
     936          lsec->flags |= SEC_HAS_CONTENTS | SEC_IN_MEMORY;
     937        }
     938
     939      /* Likewise for the linkage section.  */
     940      if (xcoff_hash_table (info)->linkage_section == NULL)
     941        {
     942          asection *lsec;
     943
     944          lsec = bfd_make_section_anyway (abfd, ".gl");
     945          if (lsec == NULL)
     946            {
     947              goto end_return;
     948            }
     949
     950          xcoff_hash_table (info)->linkage_section = lsec;
     951          lsec->flags |= (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
     952                          | SEC_IN_MEMORY);
     953          lsec->alignment_power = 2;
     954        }
     955
     956      /* Likewise for the TOC section.  */
     957      if (xcoff_hash_table (info)->toc_section == NULL)
     958        {
     959          asection *tsec;
     960
     961          tsec = bfd_make_section_anyway (abfd, ".tc");
     962          if (tsec == NULL)
     963            {
     964              goto end_return;
     965            }
     966
     967          xcoff_hash_table (info)->toc_section = tsec;
     968          tsec->flags |= (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
     969                          | SEC_IN_MEMORY);
     970          tsec->alignment_power = 2;
     971        }
     972
     973      /* Likewise for the descriptor section.  */
     974      if (xcoff_hash_table (info)->descriptor_section == NULL)
     975        {
     976          asection *dsec;
     977
     978          dsec = bfd_make_section_anyway (abfd, ".ds");
     979          if (dsec == NULL)
     980            {
     981              goto end_return;
     982            }
     983
     984          xcoff_hash_table (info)->descriptor_section = dsec;
     985          dsec->flags |= (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
     986                          | SEC_IN_MEMORY);
     987          dsec->alignment_power = 2;
     988        }
     989
     990      /* Likewise for the .debug section.  */
     991      if (xcoff_hash_table (info)->debug_section == NULL
     992          && info->strip != strip_all)
     993        {
     994          asection *dsec;
     995
     996          dsec = bfd_make_section_anyway (abfd, ".debug");
     997          if (dsec == NULL)
     998            {
     999              goto end_return;
     1000            }
     1001          xcoff_hash_table (info)->debug_section = dsec;
     1002          dsec->flags |= SEC_HAS_CONTENTS | SEC_IN_MEMORY;
     1003        }
     1004    }
     1005
     1006  return_value = TRUE;
     1007
     1008 end_return:
     1009
     1010  return return_value;
    13481011}
    13491012
     
    13661029   csect they belong to is to examine the address.  */
    13671030
    1368 static boolean
     1031static bfd_boolean
    13691032xcoff_link_add_symbols (abfd, info)
    13701033     bfd *abfd;
     
    13731036  unsigned int n_tmask;
    13741037  unsigned int n_btshft;
    1375   boolean default_copy;
     1038  bfd_boolean default_copy;
    13761039  bfd_size_type symcount;
    13771040  struct xcoff_link_hash_entry **sym_hash;
     
    13801043  asection *o;
    13811044  asection *last_real;
    1382   boolean keep_syms;
     1045  bfd_boolean keep_syms;
    13831046  asection *csect;
    13841047  unsigned int csect_index;
     
    13881051  bfd_byte *esym_end;
    13891052  struct reloc_info_struct
    1390     {
    1391       struct internal_reloc *relocs;
    1392       asection **csects;
    1393       bfd_byte *linenos;
    1394     } *reloc_info = NULL;
     1053  {
     1054    struct internal_reloc *relocs;
     1055    asection **csects;
     1056    bfd_byte *linenos;
     1057  } *reloc_info = NULL;
     1058  bfd_size_type amt;
    13951059
    13961060  keep_syms = obj_coff_keep_syms (abfd);
     
    14001064    {
    14011065      if (! xcoff_link_add_dynamic_symbols (abfd, info))
    1402         return false;
    1403     }
    1404 
    1405   if (info->hash->creator == abfd->xvec)
    1406     {
    1407       /* We need to build a .loader section, so we do it here.  This
    1408          won't work if we're producing an XCOFF output file with no
    1409          XCOFF input files.  FIXME.  */
    1410       if (xcoff_hash_table (info)->loader_section == NULL)
    1411         {
    1412           asection *lsec;
    1413 
    1414           lsec = bfd_make_section_anyway (abfd, ".loader");
    1415           if (lsec == NULL)
    1416             goto error_return;
    1417           xcoff_hash_table (info)->loader_section = lsec;
    1418           lsec->flags |= SEC_HAS_CONTENTS | SEC_IN_MEMORY;
    1419         }
    1420       /* Likewise for the linkage section.  */
    1421       if (xcoff_hash_table (info)->linkage_section == NULL)
    1422         {
    1423           asection *lsec;
    1424 
    1425           lsec = bfd_make_section_anyway (abfd, ".gl");
    1426           if (lsec == NULL)
    1427             goto error_return;
    1428           xcoff_hash_table (info)->linkage_section = lsec;
    1429           lsec->flags |= (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
    1430                           | SEC_IN_MEMORY);
    1431           lsec->alignment_power = 2;
    1432         }
    1433       /* Likewise for the TOC section.  */
    1434       if (xcoff_hash_table (info)->toc_section == NULL)
    1435         {
    1436           asection *tsec;
    1437 
    1438           tsec = bfd_make_section_anyway (abfd, ".tc");
    1439           if (tsec == NULL)
    1440             goto error_return;
    1441           xcoff_hash_table (info)->toc_section = tsec;
    1442           tsec->flags |= (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
    1443                           | SEC_IN_MEMORY);
    1444           tsec->alignment_power = 2;
    1445         }
    1446       /* Likewise for the descriptor section.  */
    1447       if (xcoff_hash_table (info)->descriptor_section == NULL)
    1448         {
    1449           asection *dsec;
    1450 
    1451           dsec = bfd_make_section_anyway (abfd, ".ds");
    1452           if (dsec == NULL)
    1453             goto error_return;
    1454           xcoff_hash_table (info)->descriptor_section = dsec;
    1455           dsec->flags |= (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
    1456                           | SEC_IN_MEMORY);
    1457           dsec->alignment_power = 2;
    1458         }
    1459       /* Likewise for the .debug section.  */
    1460       if (xcoff_hash_table (info)->debug_section == NULL
    1461           && info->strip != strip_all)
    1462         {
    1463           asection *dsec;
    1464 
    1465           dsec = bfd_make_section_anyway (abfd, ".debug");
    1466           if (dsec == NULL)
    1467             goto error_return;
    1468           xcoff_hash_table (info)->debug_section = dsec;
    1469           dsec->flags |= SEC_HAS_CONTENTS | SEC_IN_MEMORY;
    1470         }
    1471     }
     1066        return FALSE;
     1067    }
     1068
     1069  /* create the loader, toc, gl, ds and debug sections, if needed */
     1070  if (! xcoff_link_create_extra_sections (abfd, info))
     1071    goto error_return;
    14721072
    14731073  if ((abfd->flags & DYNAMIC) != 0
    14741074      && ! info->static_link)
    1475     return true;
     1075    return TRUE;
    14761076
    14771077  n_tmask = coff_data (abfd)->local_n_tmask;
     
    14831083
    14841084  if (info->keep_memory)
    1485     default_copy = false;
     1085    default_copy = FALSE;
    14861086  else
    1487     default_copy = true;
     1087    default_copy = TRUE;
    14881088
    14891089  symcount = obj_raw_syment_count (abfd);
     
    14911091  /* We keep a list of the linker hash table entries that correspond
    14921092     to each external symbol.  */
    1493   sym_hash = ((struct xcoff_link_hash_entry **)
    1494               bfd_alloc (abfd,
    1495                          (symcount
    1496                           * sizeof (struct xcoff_link_hash_entry *))));
     1093  amt = symcount * sizeof (struct xcoff_link_hash_entry *);
     1094  sym_hash = (struct xcoff_link_hash_entry **) bfd_zalloc (abfd, amt);
    14971095  if (sym_hash == NULL && symcount != 0)
    14981096    goto error_return;
    14991097  coff_data (abfd)->sym_hashes = (struct coff_link_hash_entry **) sym_hash;
    1500   memset (sym_hash, 0,
    1501           (size_t) symcount * sizeof (struct xcoff_link_hash_entry *));
    15021098
    15031099  /* Because of the weird stuff we are doing with XCOFF csects, we can
    15041100     not easily determine which section a symbol is in, so we store
    15051101     the information in the tdata for the input file.  */
    1506   csect_cache = ((asection **)
    1507                  bfd_alloc (abfd, symcount * sizeof (asection *)));
     1102  amt = symcount * sizeof (asection *);
     1103  csect_cache = (asection **) bfd_zalloc (abfd, amt);
    15081104  if (csect_cache == NULL && symcount != 0)
    15091105    goto error_return;
    15101106  xcoff_data (abfd)->csects = csect_cache;
    1511   memset (csect_cache, 0, (size_t) symcount * sizeof (asection *));
    15121107
    15131108  /* While splitting sections into csects, we need to assign the
     
    15161111     scanning along the relocs as we process the csects.  We index
    15171112     into reloc_info using the section target_index.  */
    1518   reloc_info = ((struct reloc_info_struct *)
    1519                 bfd_malloc ((abfd->section_count + 1)
    1520                             * sizeof (struct reloc_info_struct)));
     1113  amt = abfd->section_count + 1;
     1114  amt *= sizeof (struct reloc_info_struct);
     1115  reloc_info = (struct reloc_info_struct *) bfd_zmalloc (amt);
    15211116  if (reloc_info == NULL)
    15221117    goto error_return;
    1523   memset ((PTR) reloc_info, 0,
    1524           (abfd->section_count + 1) * sizeof (struct reloc_info_struct));
    15251118
    15261119  /* Read in the relocs and line numbers for each section.  */
     
    15291122  for (o = abfd->sections; o != NULL; o = o->next)
    15301123    {
     1124
    15311125      last_real = o;
    15321126      if ((o->flags & SEC_RELOC) != 0)
    15331127        {
     1128
    15341129          reloc_info[o->target_index].relocs =
    1535             xcoff_read_internal_relocs (abfd, o, true, (bfd_byte *) NULL,
    1536                                         false, (struct internal_reloc *) NULL);
    1537           reloc_info[o->target_index].csects =
    1538             (asection **) bfd_malloc (o->reloc_count * sizeof (asection *));
     1130            xcoff_read_internal_relocs (abfd, o, TRUE, (bfd_byte *) NULL,
     1131                                        FALSE, (struct internal_reloc *) NULL);
     1132          amt = o->reloc_count;
     1133          amt *= sizeof (asection *);
     1134          reloc_info[o->target_index].csects = (asection **) bfd_zmalloc (amt);
    15391135          if (reloc_info[o->target_index].csects == NULL)
    15401136            goto error_return;
    1541           memset (reloc_info[o->target_index].csects, 0,
    1542                   o->reloc_count * sizeof (asection *));
    15431137        }
    15441138
     
    15461140          && o->lineno_count > 0)
    15471141        {
     1142
    15481143          bfd_byte *linenos;
    15491144
    1550           linenos = (bfd_byte *) bfd_malloc (o->lineno_count * linesz);
     1145          amt = linesz * o->lineno_count;
     1146          linenos = (bfd_byte *) bfd_malloc (amt);
    15511147          if (linenos == NULL)
    15521148            goto error_return;
    15531149          reloc_info[o->target_index].linenos = linenos;
    15541150          if (bfd_seek (abfd, o->line_filepos, SEEK_SET) != 0
    1555               || (bfd_read (linenos, linesz, o->lineno_count, abfd)
    1556                   != linesz * o->lineno_count))
     1151              || bfd_bread (linenos, amt, abfd) != amt)
    15571152            goto error_return;
     1153
    15581154        }
    15591155    }
    15601156
    15611157  /* Don't let the linker relocation routines discard the symbols.  */
    1562   obj_coff_keep_syms (abfd) = true;
     1158  obj_coff_keep_syms (abfd) = TRUE;
    15631159
    15641160  csect = NULL;
     
    15701166  esym = (bfd_byte *) obj_coff_external_syms (abfd);
    15711167  esym_end = esym + symcount * symesz;
     1168
    15721169  while (esym < esym_end)
    15731170    {
     
    15851182
    15861183      /* In this pass we are only interested in symbols with csect
    1587         information.  */
     1184        information.  */
    15881185      if (sym.n_sclass != C_EXT && sym.n_sclass != C_HIDEXT)
    15891186        {
     1187
     1188          /* Set csect_cache,
     1189             Normally csect is a .pr, .rw  etc. created in the loop
     1190             If C_FILE or first time, handle special
     1191
     1192             Advance esym, sym_hash, csect_hash ptr's
     1193             Keep track of the last_symndx for the current file.  */
    15901194          if (sym.n_sclass == C_FILE && csect != NULL)
    15911195            {
     
    16061210          sym_hash += sym.n_numaux + 1;
    16071211          csect_cache += sym.n_numaux + 1;
     1212
    16081213          continue;
    16091214        }
    16101215
    16111216      name = _bfd_coff_internal_syment_name (abfd, &sym, buf);
     1217
    16121218      if (name == NULL)
    16131219        goto error_return;
    16141220
    16151221      /* If this symbol has line number information attached to it,
    1616         and we're not stripping it, count the number of entries and
    1617         add them to the count for this csect.  In the final link pass
    1618         we are going to attach line number information by symbol,
    1619         rather than by section, in order to more easily handle
    1620         garbage collection.  */
     1222        and we're not stripping it, count the number of entries and
     1223        add them to the count for this csect.  In the final link pass
     1224        we are going to attach line number information by symbol,
     1225        rather than by section, in order to more easily handle
     1226        garbage collection.  */
    16211227      if ((info->strip == strip_none || info->strip == strip_some)
    16221228          && sym.n_numaux > 1
     
    16241230          && ISFCN (sym.n_type))
    16251231        {
     1232
    16261233          union internal_auxent auxlin;
    16271234
     
    16291236                                sym.n_type, sym.n_sclass,
    16301237                                0, sym.n_numaux, (PTR) &auxlin);
     1238
    16311239          if (auxlin.x_sym.x_fcnary.x_fcn.x_lnnoptr != 0)
    16321240            {
    16331241              asection *enclosing;
    1634               bfd_size_type linoff;
     1242              bfd_signed_vma linoff;
    16351243
    16361244              enclosing = xcoff_section_data (abfd, csect)->enclosing;
     
    16391247                  (*_bfd_error_handler)
    16401248                    (_("%s: `%s' has line numbers but no enclosing section"),
    1641                      bfd_get_filename (abfd), name);
     1249                     bfd_archive_filename (abfd), name);
    16421250                  bfd_set_error (bfd_error_bad_value);
    16431251                  goto error_return;
     
    16451253              linoff = (auxlin.x_sym.x_fcnary.x_fcn.x_lnnoptr
    16461254                        - enclosing->line_filepos);
    1647               if (linoff < enclosing->lineno_count * linesz)
     1255              /* explict cast to bfd_signed_vma for compiler */
     1256              if (linoff < (bfd_signed_vma) (enclosing->lineno_count * linesz))
    16481257                {
    16491258                  struct internal_lineno lin;
     
    16741283                      csect->lineno_count += (linp - linpstart) / linesz;
    16751284                      /* The setting of line_filepos will only be
    1676                         useful if all the line number entries for a
    1677                         csect are contiguous; this only matters for
    1678                         error reporting.  */
     1285                        useful if all the line number entries for a
     1286                        csect are contiguous; this only matters for
     1287                        error reporting.  */
    16791288                      if (csect->line_filepos == 0)
    16801289                        csect->line_filepos =
     
    16911300          (*_bfd_error_handler)
    16921301            (_("%s: class %d symbol `%s' has no aux entries"),
    1693              bfd_get_filename (abfd), sym.n_sclass, name);
     1302             bfd_archive_filename (abfd), sym.n_sclass, name);
    16941303          bfd_set_error (bfd_error_bad_value);
    16951304          goto error_return;
     
    17141323          (*_bfd_error_handler)
    17151324            (_("%s: symbol `%s' has unrecognized csect type %d"),
    1716              bfd_get_filename (abfd), name, smtyp);
     1325             bfd_archive_filename (abfd), name, smtyp);
    17171326          bfd_set_error (bfd_error_bad_value);
    17181327          goto error_return;
     
    17261335              (*_bfd_error_handler)
    17271336                (_("%s: bad XTY_ER symbol `%s': class %d scnum %d scnlen %d"),
    1728                  bfd_get_filename (abfd), name, sym.n_sclass, sym.n_scnum,
     1337                 bfd_archive_filename (abfd), name, sym.n_sclass, sym.n_scnum,
    17291338                 aux.x_csect.x_scnlen.l);
    17301339              bfd_set_error (bfd_error_bad_value);
     
    17331342
    17341343          /* An XMC_XO external reference is actually a reference to
    1735              an absolute location.  */
     1344             an absolute location.  */
    17361345          if (aux.x_csect.x_smclas != XMC_XO)
    17371346            section = bfd_und_section_ptr;
     
    17451354        case XTY_SD:
    17461355          /* This is a csect definition.  */
    1747 
    17481356          if (csect != NULL)
    17491357            {
    17501358              xcoff_section_data (abfd, csect)->last_symndx =
    1751                 ((esym
    1752                   - (bfd_byte *) obj_coff_external_syms (abfd))
    1753                  / symesz);
     1359                ((esym - (bfd_byte *) obj_coff_external_syms (abfd)) / symesz);
    17541360            }
    17551361
    17561362          csect = NULL;
    1757           csect_index = -1;
     1363          csect_index = -(unsigned) 1;
    17581364
    17591365          /* When we see a TOC anchor, we record the TOC value.  */
     
    17651371                  (*_bfd_error_handler)
    17661372                    (_("%s: XMC_TC0 symbol `%s' is class %d scnlen %d"),
    1767                      bfd_get_filename (abfd), name, sym.n_sclass,
     1373                     bfd_archive_filename (abfd), name, sym.n_sclass,
    17681374                     aux.x_csect.x_scnlen.l);
    17691375                  bfd_set_error (bfd_error_bad_value);
     
    17751381          /* We must merge TOC entries for the same symbol.  We can
    17761382             merge two TOC entries if they are both C_HIDEXT, they
    1777              both have the same name, they are both 4 bytes long, and
     1383             both have the same name, they are both 4 or 8 bytes long, and
    17781384             they both have a relocation table entry for an external
    17791385             symbol with the same name.  Unfortunately, this means
    1780              that we must look through the relocations.  Ick.  */
     1386             that we must look through the relocations.  Ick.
     1387
     1388             Logic for 32 bit vs 64 bit.
     1389             32 bit has a csect length of 4 for TOC
     1390             64 bit has a csect length of 8 for TOC
     1391
     1392             The conditions to get past the if-check are not that bad.
     1393             They are what is used to create the TOC csects in the first
     1394             place.  */
    17811395          if (aux.x_csect.x_smclas == XMC_TC
    17821396              && sym.n_sclass == C_HIDEXT
    1783               && aux.x_csect.x_scnlen.l == 4
    1784               && info->hash->creator == abfd->xvec)
     1397              && info->hash->creator == abfd->xvec
     1398              && ((bfd_xcoff_is_xcoff32 (abfd)
     1399                   && aux.x_csect.x_scnlen.l == 4)
     1400                  || (bfd_xcoff_is_xcoff64 (abfd)
     1401                      && aux.x_csect.x_scnlen.l == 8)))
    17851402            {
    17861403              asection *enclosing;
     
    17941411
    17951412              relocs = reloc_info[enclosing->target_index].relocs;
    1796               relindx = xcoff_find_reloc (relocs, enclosing->reloc_count,
    1797                                           sym.n_value);
     1413              amt = enclosing->reloc_count;
     1414              relindx = xcoff_find_reloc (relocs, amt, sym.n_value);
    17981415              rel = relocs + relindx;
     1416
     1417              /* 32 bit R_POS r_size is 31
     1418                 64 bit R_POS r_size is 63  */
    17991419              if (relindx < enclosing->reloc_count
    18001420                  && rel->r_vaddr == (bfd_vma) sym.n_value
    1801                   && rel->r_size == 31
    1802                   && rel->r_type == R_POS)
     1421                  && rel->r_type == R_POS
     1422                  && ((bfd_xcoff_is_xcoff32 (abfd)
     1423                       && rel->r_size == 31)
     1424                      || (bfd_xcoff_is_xcoff64 (abfd)
     1425                          && rel->r_size == 63)))
    18031426                {
    18041427                  bfd_byte *erelsym;
     1428
    18051429                  struct internal_syment relsym;
    18061430
     
    18121436                      const char *relname;
    18131437                      char relbuf[SYMNMLEN + 1];
    1814                       boolean copy;
     1438                      bfd_boolean copy;
    18151439                      struct xcoff_link_hash_entry *h;
    18161440
    18171441                      /* At this point we know that the TOC entry is
    18181442                         for an externally visible symbol.  */
     1443
    18191444                      relname = _bfd_coff_internal_syment_name (abfd, &relsym,
    18201445                                                                relbuf);
     
    18231448
    18241449                      /* We only merge TOC entries if the TC name is
    1825                          the same as the symbol name.  This handles
    1826                          the normal case, but not common cases like
    1827                          SYM.P4 which gcc generates to store SYM + 4
    1828                          in the TOC.  FIXME.  */
     1450                         the same as the symbol name.  This handles
     1451                         the normal case, but not common cases like
     1452                         SYM.P4 which gcc generates to store SYM + 4
     1453                         in the TOC.  FIXME.  */
     1454
    18291455                      if (strcmp (name, relname) == 0)
    18301456                        {
     
    18331459                                  || relsym._n._n_n._n_offset == 0);
    18341460                          h = xcoff_link_hash_lookup (xcoff_hash_table (info),
    1835                                                       relname, true, copy,
    1836                                                       false);
     1461                                                      relname, TRUE, copy,
     1462                                                      FALSE);
    18371463                          if (h == NULL)
    18381464                            goto error_return;
     
    18651491                             this symbol.  */
    18661492                          set_toc = h;
    1867                         }
    1868                     }
    1869                 }
    1870             }
    1871 
    1872           /* We need to create a new section.  We get the name from
    1873              the csect storage mapping class, so that the linker can
    1874              accumulate similar csects together.  */
     1493                        } /* merge toc reloc */
     1494                    } /* c_ext */
     1495                } /* reloc */
     1496            } /* merge toc */
     1497
    18751498          {
    1876             static const char *csect_name_by_class[] = {
    1877               ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo",
    1878               ".sv", ".bs", ".ds", ".uc", ".ti", ".tb", NULL, ".tc0",
    1879               ".td"
    1880             };
    1881             const char *csect_name;
     1499
    18821500            asection *enclosing;
    18831501
    1884             if ((aux.x_csect.x_smclas >=
    1885                  sizeof csect_name_by_class / sizeof csect_name_by_class[0])
    1886                 || csect_name_by_class[aux.x_csect.x_smclas] == NULL)
     1502            /* We need to create a new section.  We get the name from
     1503               the csect storage mapping class, so that the linker can
     1504               accumulate similar csects together.  */
     1505
     1506            csect = bfd_xcoff_create_csect_from_smclas(abfd, &aux, name);
     1507            if (NULL == csect)
    18871508              {
    1888                 (*_bfd_error_handler)
    1889                   (_("%s: symbol `%s' has unrecognized smclas %d"),
    1890                    bfd_get_filename (abfd), name, aux.x_csect.x_smclas);
    1891                 bfd_set_error (bfd_error_bad_value);
    18921509                goto error_return;
    18931510              }
    18941511
    1895             csect_name = csect_name_by_class[aux.x_csect.x_smclas];
    1896             csect = bfd_make_section_anyway (abfd, csect_name);
    1897             if (csect == NULL)
    1898               goto error_return;
     1512            /* The enclosing section is the main section : .data, .text
     1513               or .bss that the csect is coming from.  */
    18991514            enclosing = coff_section_from_bfd_index (abfd, sym.n_scnum);
    19001515            if (enclosing == NULL)
    19011516              goto error_return;
     1517
    19021518            if (! bfd_is_abs_section (enclosing)
    19031519                && ((bfd_vma) sym.n_value < enclosing->vma
     
    19071523                (*_bfd_error_handler)
    19081524                  (_("%s: csect `%s' not in enclosing section"),
    1909                    bfd_get_filename (abfd), name);
     1525                   bfd_archive_filename (abfd), name);
    19101526                bfd_set_error (bfd_error_bad_value);
    19111527                goto error_return;
     
    19211537            /* Record the enclosing section in the tdata for this new
    19221538               section.  */
    1923             csect->used_by_bfd =
    1924               (PTR) bfd_zalloc (abfd, sizeof (struct coff_section_tdata));
     1539            amt = sizeof (struct coff_section_tdata);
     1540            csect->used_by_bfd = (PTR) bfd_zalloc (abfd, amt);
    19251541            if (csect->used_by_bfd == NULL)
    19261542              goto error_return;
    1927             coff_section_data (abfd, csect)->tdata =
    1928               bfd_zalloc (abfd, sizeof (struct xcoff_section_tdata));
     1543            amt = sizeof (struct xcoff_section_tdata);
     1544            coff_section_data (abfd, csect)->tdata = bfd_zalloc (abfd, amt);
    19291545            if (coff_section_data (abfd, csect)->tdata == NULL)
    19301546              goto error_return;
     
    19411557
    19421558                relocs = reloc_info[enclosing->target_index].relocs;
    1943                 relindx = xcoff_find_reloc (relocs, enclosing->reloc_count,
    1944                                             csect->vma);
     1559                amt = enclosing->reloc_count;
     1560                relindx = xcoff_find_reloc (relocs, amt, csect->vma);
     1561
    19451562                rel = relocs + relindx;
    19461563                rel_csect = (reloc_info[enclosing->target_index].csects
    19471564                             + relindx);
     1565
    19481566                csect->rel_filepos = (enclosing->rel_filepos
    19491567                                      + relindx * bfd_coff_relsz (abfd));
     
    19521570                       && rel->r_vaddr < csect->vma + csect->_raw_size)
    19531571                  {
     1572
    19541573                    *rel_csect = csect;
    19551574                    csect->flags |= SEC_RELOC;
     
    19891608        case XTY_LD:
    19901609          /* This is a label definition.  The x_scnlen field is the
    1991              symbol index of the csect.  I believe that this must
    1992              always follow the appropriate XTY_SD symbol, so I will
    1993              insist on it. */
     1610             symbol index of the csect.  Usually the XTY_LD symbol will
     1611             follow its appropriate XTY_SD symbol.  The .set pseudo op can
     1612             cause the XTY_LD to not follow the XTY_SD symbol. */
    19941613          {
    1995             boolean bad;
    1996 
    1997             bad = false;
     1614            bfd_boolean bad;
     1615
     1616            bad = FALSE;
    19981617            if (aux.x_csect.x_scnlen.l < 0
    19991618                || (aux.x_csect.x_scnlen.l
    20001619                    >= esym - (bfd_byte *) obj_coff_external_syms (abfd)))
    2001               bad = true;
     1620              bad = TRUE;
    20021621            if (! bad)
    20031622              {
     
    20051624                if (section == NULL
    20061625                    || (section->flags & SEC_HAS_CONTENTS) == 0)
    2007                   bad = true;
     1626                  bad = TRUE;
    20081627              }
    20091628            if (bad)
     
    20111630                (*_bfd_error_handler)
    20121631                  (_("%s: misplaced XTY_LD `%s'"),
    2013                    bfd_get_filename (abfd), name);
     1632                   bfd_archive_filename (abfd), name);
    20141633                bfd_set_error (bfd_error_bad_value);
    20151634                goto error_return;
    20161635              }
    2017 
     1636            csect = section;
    20181637            value = sym.n_value - csect->vma;
    20191638          }
     
    20221641        case XTY_CM:
    20231642          /* This is an unitialized csect.  We could base the name on
    2024              the storage mapping class, but we don't bother except for
    2025              an XMC_TD symbol.  If this csect is externally visible,
    2026              it is a common symbol.  We put XMC_TD symbols in sections
    2027              named .tocbss, and rely on the linker script to put that
    2028              in the TOC area.  */
     1643             the storage mapping class, but we don't bother except for
     1644             an XMC_TD symbol.  If this csect is externally visible,
     1645             it is a common symbol.  We put XMC_TD symbols in sections
     1646             named .tocbss, and rely on the linker script to put that
     1647             in the TOC area.  */
    20291648
    20301649          if (csect != NULL)
     
    20371656
    20381657          if (aux.x_csect.x_smclas == XMC_TD)
    2039             csect = bfd_make_section_anyway (abfd, ".tocbss");
     1658            {
     1659              /* The linker script puts the .td section in the data
     1660                 section after the .tc section.  */
     1661              csect = bfd_make_section_anyway (abfd, ".td");
     1662
     1663            }
    20401664          else
    2041             csect = bfd_make_section_anyway (abfd, ".bss");
     1665            {
     1666              csect = bfd_make_section_anyway (abfd, ".bss");
     1667            }
    20421668          if (csect == NULL)
    20431669            goto error_return;
     
    20531679                         / symesz);
    20541680
    2055           csect->used_by_bfd =
    2056             (PTR) bfd_zalloc (abfd, sizeof (struct coff_section_tdata));
     1681          amt = sizeof (struct coff_section_tdata);
     1682          csect->used_by_bfd = (PTR) bfd_zalloc (abfd, amt);
    20571683          if (csect->used_by_bfd == NULL)
    20581684            goto error_return;
    2059           coff_section_data (abfd, csect)->tdata =
    2060             bfd_zalloc (abfd, sizeof (struct xcoff_section_tdata));
     1685          amt = sizeof (struct xcoff_section_tdata);
     1686          coff_section_data (abfd, csect)->tdata = bfd_zalloc (abfd, amt);
    20611687          if (coff_section_data (abfd, csect)->tdata == NULL)
    20621688            goto error_return;
     
    20821708          && aux.x_csect.x_smclas != XMC_TD)
    20831709        {
    2084           int i;
    2085 
    2086           i = -1;
     1710
     1711          int i = -1;
     1712
    20871713          if (name[0] == '_')
    20881714            {
    20891715              if (strcmp (name, "_text") == 0)
    2090                 i = 0;
     1716                i = XCOFF_SPECIAL_SECTION_TEXT;
    20911717              else if (strcmp (name, "_etext") == 0)
    2092                 i = 1;
     1718                i = XCOFF_SPECIAL_SECTION_ETEXT;
    20931719              else if (strcmp (name, "_data") == 0)
    2094                 i = 2;
     1720                i = XCOFF_SPECIAL_SECTION_DATA;
    20951721              else if (strcmp (name, "_edata") == 0)
    2096                 i = 3;
     1722                i = XCOFF_SPECIAL_SECTION_EDATA;
    20971723              else if (strcmp (name, "_end") == 0)
    2098                 i = 4;
     1724                i = XCOFF_SPECIAL_SECTION_END;
    20991725            }
    21001726          else if (name[0] == 'e' && strcmp (name, "end") == 0)
    2101             i = 5;
     1727            {
     1728              i = XCOFF_SPECIAL_SECTION_END2;
     1729            }
    21021730
    21031731          if (i != -1)
    2104             xcoff_hash_table (info)->special_sections[i] = csect;
     1732            {
     1733              xcoff_hash_table (info)->special_sections[i] = csect;
     1734            }
    21051735        }
    21061736
    21071737      /* Now we have enough information to add the symbol to the
    2108         linker hash table.  */
     1738        linker hash table.  */
    21091739
    21101740      if (sym.n_sclass == C_EXT)
    21111741        {
    2112           boolean copy;
     1742          bfd_boolean copy;
    21131743
    21141744          BFD_ASSERT (section != NULL);
    21151745
    21161746          /* We must copy the name into memory if we got it from the
    2117              syment itself, rather than the string table.  */
     1747             syment itself, rather than the string table.  */
    21181748          copy = default_copy;
    21191749          if (sym._n._n_n._n_zeroes != 0
    21201750              || sym._n._n_n._n_offset == 0)
    2121             copy = true;
     1751            copy = TRUE;
    21221752
    21231753          /* The AIX linker appears to only detect multiple symbol
     
    21461776             although this is an easier case to detect.  */
    21471777
    2148           if (info->hash->creator == abfd->xvec)
     1778          if (info->hash->creator == abfd->xvec)
    21491779            {
    21501780              if (! bfd_is_und_section (section))
    2151                 *sym_hash = xcoff_link_hash_lookup (xcoff_hash_table (info),
    2152                                                     name, true, copy, false);
     1781                {
     1782                  *sym_hash = xcoff_link_hash_lookup (xcoff_hash_table (info),
     1783                                                      name, TRUE, copy, FALSE);
     1784                }
    21531785              else
    2154                 *sym_hash = ((struct xcoff_link_hash_entry *)
    2155                              bfd_wrapped_link_hash_lookup (abfd, info, name,
    2156                                                            true, copy, false));
     1786                {
     1787                  /* Make a copy of the symbol name to prevent problems with
     1788                     merging symbols.  */
     1789                  *sym_hash = ((struct xcoff_link_hash_entry *)
     1790                               bfd_wrapped_link_hash_lookup (abfd, info, name,
     1791                                                             TRUE, TRUE,
     1792                                                             FALSE));
     1793                }
    21571794              if (*sym_hash == NULL)
    21581795                goto error_return;
     
    21701807                    {
    21711808                      /* The new symbol is from a shared library, and
    2172                         either the existing symbol is not global
    2173                         linkage code or this symbol is global linkage
    2174                         code.  If the existing symbol is global
    2175                         linkage code and the new symbol is not, then
    2176                         we want to use the new symbol.  */
     1809                        either the existing symbol is not global
     1810                        linkage code or this symbol is global linkage
     1811                        code.  If the existing symbol is global
     1812                        linkage code and the new symbol is not, then
     1813                        we want to use the new symbol.  */
    21771814                      section = bfd_und_section_ptr;
    21781815                      value = 0;
     
    21821819                    {
    21831820                      /* The existing symbol is from a shared library.
    2184                         Replace it.  */
     1821                        Replace it.  */
    21851822                      (*sym_hash)->root.type = bfd_link_hash_undefined;
    21861823                      (*sym_hash)->root.u.undef.abfd =
     
    21901827                    {
    21911828                      /* This is a redefinition in an object contained
    2192                         in an archive.  Just ignore it.  See the
    2193                         comment above.  */
     1829                        in an archive.  Just ignore it.  See the
     1830                        comment above.  */
    21941831                      section = bfd_und_section_ptr;
    21951832                      value = 0;
     
    21991836                    {
    22001837                      /* This symbol has been referenced.  In this
    2201                         case, we just continue and permit the
    2202                         multiple definition error.  See the comment
    2203                         above about the behaviour of the AIX linker.  */
     1838                        case, we just continue and permit the
     1839                        multiple definition error.  See the comment
     1840                        above about the behaviour of the AIX linker.  */
    22041841                    }
    22051842                  else if ((*sym_hash)->smclas == aux.x_csect.x_smclas)
    22061843                    {
    22071844                      /* The symbols are both csects of the same
    2208                         class.  There is at least a chance that this
    2209                         is a semi-legitimate redefinition.  */
     1845                        class.  There is at least a chance that this
     1846                        is a semi-legitimate redefinition.  */
    22101847                      section = bfd_und_section_ptr;
    22111848                      value = 0;
     
    22281865                  if (! ((*info->callbacks->multiple_definition)
    22291866                         (info, (*sym_hash)->root.root.string,
    2230                           (bfd *) NULL, (asection *) NULL, 0,
     1867                          (bfd *) NULL, (asection *) NULL, (bfd_vma) 0,
    22311868                          (*sym_hash)->root.u.def.section->owner,
    22321869                          (*sym_hash)->root.u.def.section,
     
    22521889          if (! (_bfd_generic_link_add_one_symbol
    22531890                 (info, abfd, name, flags, section, value,
    2254                   (const char *) NULL, copy, true,
     1891                  (const char *) NULL, copy, TRUE,
    22551892                  (struct bfd_link_hash_entry **) sym_hash)))
    22561893            goto error_return;
     
    22721909            }
    22731910
    2274           if (info->hash->creator == abfd->xvec)
     1911          if (info->hash->creator == abfd->xvec)
    22751912            {
    22761913              int flag;
     
    23161953          rel = reloc_info[o->target_index].relocs;
    23171954          rel_csect = reloc_info[o->target_index].csects;
     1955
    23181956          for (i = 0; i < o->reloc_count; i++, rel++, rel_csect++)
    23191957            {
     1958
    23201959              if (*rel_csect == NULL)
    23211960                {
    23221961                  (*_bfd_error_handler)
    23231962                    (_("%s: reloc %s:%d not in csect"),
    2324                      bfd_get_filename (abfd), o->name, i);
     1963                     bfd_archive_filename (abfd), o->name, i);
    23251964                  bfd_set_error (bfd_error_bad_value);
    23261965                  goto error_return;
     
    23301969                 can create glue code for calls to functions imported
    23311970                 from dynamic objects.  */
    2332               if (info->hash->creator == abfd->xvec
     1971              if (info->hash->creator == abfd->xvec
    23331972                  && *rel_csect != bfd_und_section_ptr
    23341973                  && (rel->r_type == R_BR
     
    23411980                  h->flags |= XCOFF_CALLED;
    23421981                  /* If the symbol name starts with a period, it is
    2343                      the code of a function.  If the symbol is
    2344                      currently undefined, then add an undefined symbol
    2345                      for the function descriptor.  This should do no
    2346                      harm, because any regular object that defines the
    2347                      function should also define the function
    2348                      descriptor.  It helps, because it means that we
    2349                      will identify the function descriptor with a
    2350                      dynamic object if a dynamic object defines it.  */
     1982                     the code of a function.  If the symbol is
     1983                     currently undefined, then add an undefined symbol
     1984                     for the function descriptor.  This should do no
     1985                     harm, because any regular object that defines the
     1986                     function should also define the function
     1987                     descriptor.  It helps, because it means that we
     1988                     will identify the function descriptor with a
     1989                     dynamic object if a dynamic object defines it.  */
    23511990                  if (h->root.root.string[0] == '.'
    23521991                      && h->descriptor == NULL)
    23531992                    {
    23541993                      struct xcoff_link_hash_entry *hds;
     1994                      struct bfd_link_hash_entry *bh;
    23551995
    23561996                      hds = xcoff_link_hash_lookup (xcoff_hash_table (info),
    23571997                                                    h->root.root.string + 1,
    2358                                                     true, false, true);
     1998                                                    TRUE, FALSE, TRUE);
    23591999                      if (hds == NULL)
    23602000                        goto error_return;
    23612001                      if (hds->root.type == bfd_link_hash_new)
    23622002                        {
     2003                          bh = &hds->root;
    23632004                          if (! (_bfd_generic_link_add_one_symbol
    23642005                                 (info, abfd, hds->root.root.string,
    23652006                                  (flagword) 0, bfd_und_section_ptr,
    2366                                   (bfd_vma) 0, (const char *) NULL, false,
    2367                                   true,
    2368                                   (struct bfd_link_hash_entry **) &hds)))
     2007                                  (bfd_vma) 0, (const char *) NULL, FALSE,
     2008                                  TRUE, &bh)))
    23692009                            goto error_return;
     2010                          hds = (struct xcoff_link_hash_entry *) bh;
    23702011                        }
    23712012                      hds->flags |= XCOFF_DESCRIPTOR;
     
    23832024          /* Reset SEC_RELOC and the reloc_count, since the reloc
    23842025             information is now attached to the csects.  */
    2385           o->flags &= ~SEC_RELOC;
     2026          o->flags &=~ SEC_RELOC;
    23862027          o->reloc_count = 0;
    23872028
     
    23982039
    23992040      /* Free up the line numbers.  FIXME: We could cache these
    2400         somewhere for the final link, to avoid reading them again.  */
     2041        somewhere for the final link, to avoid reading them again.  */
    24012042      if (reloc_info[o->target_index].linenos != NULL)
    24022043        {
     
    24102051  obj_coff_keep_syms (abfd) = keep_syms;
    24112052
    2412   return true;
     2053  return TRUE;
    24132054
    24142055 error_return:
     
    24222063            free (reloc_info[o->target_index].linenos);
    24232064        }
    2424     free (reloc_info);
     2065      free (reloc_info);
    24252066    }
    24262067  obj_coff_keep_syms (abfd) = keep_syms;
    2427   return false;
     2068  return FALSE;
    24282069}
    24292070
     
    24342075   global symbol table.  */
    24352076
    2436 static boolean
     2077static bfd_boolean
    24372078xcoff_link_add_dynamic_symbols (abfd, info)
    24382079     bfd *abfd;
     
    24402081{
    24412082  asection *lsec;
    2442   bfd_byte *buf;
     2083  bfd_byte *contents;
    24432084  struct internal_ldhdr ldhdr;
    24442085  const char *strings;
    2445   struct external_ldsym *elsym, *elsymend;
     2086  bfd_byte *elsym, *elsymend;
    24462087  struct xcoff_import_file *n;
    24472088  const char *bname;
     
    24532094  /* We can only handle a dynamic object if we are generating an XCOFF
    24542095     output file.  */
    2455   if (info->hash->creator != abfd->xvec)
     2096   if (info->hash->creator != abfd->xvec)
    24562097    {
    24572098      (*_bfd_error_handler)
     
    24592100         bfd_get_filename (abfd));
    24602101      bfd_set_error (bfd_error_invalid_operation);
    2461       return false;
     2102      return FALSE;
    24622103    }
    24632104
     
    24802121         bfd_get_filename (abfd));
    24812122      bfd_set_error (bfd_error_no_symbols);
    2482       return false;
    2483     }
     2123      return FALSE;
     2124    }
     2125
    24842126
    24852127  if (! xcoff_get_section_contents (abfd, lsec))
    2486     return false;
    2487   buf = coff_section_data (abfd, lsec)->contents;
     2128    return FALSE;
     2129  contents = coff_section_data (abfd, lsec)->contents;
    24882130
    24892131  /* Remove the sections from this object, so that they do not get
    24902132     included in the link.  */
    2491   abfd->sections = NULL;
    2492 
    2493   xcoff_swap_ldhdr_in (abfd, (struct external_ldhdr *) buf, &ldhdr);
    2494 
    2495   strings = (char *) buf + ldhdr.l_stoff;
    2496 
    2497   elsym = (struct external_ldsym *) (buf + LDHDRSZ);
    2498   elsymend = elsym + ldhdr.l_nsyms;
    2499   BFD_ASSERT (sizeof (struct external_ldsym) == LDSYMSZ);
    2500   for (; elsym < elsymend; elsym++)
     2133  bfd_section_list_clear (abfd);
     2134
     2135  bfd_xcoff_swap_ldhdr_in (abfd, contents, &ldhdr);
     2136
     2137  strings = (char *) contents + ldhdr.l_stoff;
     2138
     2139  elsym = contents + bfd_xcoff_loader_symbol_offset(abfd, &ldhdr);
     2140
     2141  elsymend = elsym + ldhdr.l_nsyms * bfd_xcoff_ldsymsz(abfd);
     2142
     2143  for (; elsym < elsymend; elsym += bfd_xcoff_ldsymsz(abfd))
    25012144    {
    25022145      struct internal_ldsym ldsym;
     
    25052148      struct xcoff_link_hash_entry *h;
    25062149
    2507       xcoff_swap_ldsym_in (abfd, elsym, &ldsym);
     2150      bfd_xcoff_swap_ldsym_in (abfd, elsym, &ldsym);
    25082151
    25092152      /* We are only interested in exported symbols.  */
     
    25252168         hash table.  */
    25262169
    2527       h = xcoff_link_hash_lookup (xcoff_hash_table (info), name, true,
    2528                                   true, true);
     2170      h = xcoff_link_hash_lookup (xcoff_hash_table (info), name, TRUE,
     2171                                  TRUE, TRUE);
    25292172      if (h == NULL)
    2530         return false;
     2173        return FALSE;
    25312174
    25322175      h->flags |= XCOFF_DEF_DYNAMIC;
     
    25542197
    25552198      /* Unless this is an XMC_XO symbol, we don't bother to actually
    2556         define it, since we don't have a section to put it in anyhow.
    2557         Instead, the relocation routines handle the DEF_DYNAMIC flag
    2558         correctly.  */
     2199        define it, since we don't have a section to put it in anyhow.
     2200        Instead, the relocation routines handle the DEF_DYNAMIC flag
     2201        correctly.  */
    25592202
    25602203      if (h->smclas == XMC_XO
     
    25822225              char *dsnm;
    25832226
    2584               dsnm = bfd_malloc (strlen (name) + 2);
     2227              dsnm = bfd_malloc ((bfd_size_type) strlen (name) + 2);
    25852228              if (dsnm == NULL)
    2586                 return false;
     2229                return FALSE;
    25872230              dsnm[0] = '.';
    25882231              strcpy (dsnm + 1, name);
    25892232              hds = xcoff_link_hash_lookup (xcoff_hash_table (info), dsnm,
    2590                                             true, true, true);
     2233                                            TRUE, TRUE, TRUE);
    25912234              free (dsnm);
    25922235              if (hds == NULL)
    2593                 return false;
     2236                return FALSE;
    25942237
    25952238              if (hds->root.type == bfd_link_hash_new)
     
    25982241                  hds->root.u.undef.abfd = abfd;
    25992242                  /* We do not want to add this to the undefined
    2600                      symbol list.  */
     2243                     symbol list.  */
    26012244                }
    26022245
     
    26242267    }
    26252268
    2626   if (buf != NULL && ! coff_section_data (abfd, lsec)->keep_contents)
     2269  if (contents != NULL && ! coff_section_data (abfd, lsec)->keep_contents)
    26272270    {
    26282271      free (coff_section_data (abfd, lsec)->contents);
     
    26332276
    26342277  n = ((struct xcoff_import_file *)
    2635        bfd_alloc (abfd, sizeof (struct xcoff_import_file)));
     2278       bfd_alloc (abfd, (bfd_size_type) sizeof (struct xcoff_import_file)));
    26362279  if (n == NULL)
    2637     return false;
     2280    return FALSE;
    26382281  n->next = NULL;
    26392282
     
    26682311  xcoff_data (abfd)->import_file_id = c;
    26692312
    2670   return true;
     2313  return TRUE;
    26712314}
    26722315
     
    26782321   it is defined.  */
    26792322
    2680 static INLINE boolean
     2323static INLINE bfd_boolean
    26812324xcoff_mark_symbol (info, h)
    26822325     struct bfd_link_info *info;
    26832326     struct xcoff_link_hash_entry *h;
    26842327{
     2328
    26852329  if ((h->flags & XCOFF_MARK) != 0)
    2686     return true;
     2330    return TRUE;
    26872331
    26882332  h->flags |= XCOFF_MARK;
     
    26972341        {
    26982342          if (! xcoff_mark (info, hsec))
    2699             return false;
     2343            return FALSE;
    27002344        }
    27012345    }
     
    27052349    {
    27062350      if (! xcoff_mark (info, h->toc_section))
    2707         return false;
    2708     }
    2709 
    2710   return true;
     2351        return FALSE;
     2352    }
     2353
     2354  return TRUE;
    27112355}
    27122356
     
    27172361   section.  */
    27182362
    2719 static boolean
     2363static bfd_boolean
    27202364xcoff_mark (info, sec)
    27212365     struct bfd_link_info *info;
     
    27242368  if (bfd_is_abs_section (sec)
    27252369      || (sec->flags & SEC_MARK) != 0)
    2726     return true;
     2370    return TRUE;
    27272371
    27282372  sec->flags |= SEC_MARK;
     
    27502394            {
    27512395              if (! xcoff_mark_symbol (info, h))
    2752                 return false;
     2396                return FALSE;
    27532397            }
    27542398        }
     
    27592403          && sec->reloc_count > 0)
    27602404        {
    2761           rel = xcoff_read_internal_relocs (sec->owner, sec, true,
    2762                                             (bfd_byte *) NULL, false,
     2405          rel = xcoff_read_internal_relocs (sec->owner, sec, TRUE,
     2406                                            (bfd_byte *) NULL, FALSE,
    27632407                                            (struct internal_reloc *) NULL);
    27642408          if (rel == NULL)
    2765             return false;
     2409            return FALSE;
    27662410          relend = rel + sec->reloc_count;
    27672411          for (; rel < relend; rel++)
     
    27792423                {
    27802424                  if (! xcoff_mark_symbol (info, h))
    2781                     return false;
     2425                    return FALSE;
    27822426                }
    27832427
     
    27872431                {
    27882432                  if (! xcoff_mark (info, rsec))
    2789                     return false;
     2433                    return FALSE;
    27902434                }
    27912435
    27922436              /* See if this reloc needs to be copied into the .loader
    2793                 section.  */
     2437                section.  */
    27942438              switch (rel->r_type)
    27952439                {
     
    28402484    }
    28412485
    2842   return true;
     2486  return TRUE;
    28432487}
    28442488
     
    28612505            {
    28622506              /* Keep all sections from non-XCOFF input files.  Keep
    2863                 special sections.  Keep .debug sections for the
    2864                 moment.  */
     2507                special sections.  Keep .debug sections for the
     2508                moment.  */
    28652509              if (sub->xvec != info->hash->creator
    28662510                  || o == xcoff_hash_table (info)->debug_section
     
    28852529   correct csect length.  */
    28862530
    2887 boolean
     2531bfd_boolean
    28882532bfd_xcoff_link_record_set (output_bfd, info, harg, size)
    28892533     bfd *output_bfd;
     
    28942538  struct xcoff_link_hash_entry *h = (struct xcoff_link_hash_entry *) harg;
    28952539  struct xcoff_link_size_list *n;
     2540  bfd_size_type amt;
    28962541
    28972542  if (bfd_get_flavour (output_bfd) != bfd_target_xcoff_flavour)
    2898     return true;
     2543    return TRUE;
    28992544
    29002545  /* This will hardly ever be called.  I don't want to burn four bytes
     
    29022547     attached to the hash table.  */
    29032548
    2904   n = ((struct xcoff_link_size_list *)
    2905        bfd_alloc (output_bfd, sizeof (struct xcoff_link_size_list)));
     2549  amt = sizeof (struct xcoff_link_size_list);
     2550  n = (struct xcoff_link_size_list *) bfd_alloc (output_bfd, amt);
    29062551  if (n == NULL)
    2907     return false;
     2552    return FALSE;
    29082553  n->next = xcoff_hash_table (info)->size_list;
    29092554  n->h = h;
     
    29132558  h->flags |= XCOFF_HAS_SIZE;
    29142559
    2915   return true;
     2560  return TRUE;
    29162561}
    29172562
    29182563/* Import a symbol.  */
    29192564
    2920 boolean
     2565bfd_boolean
    29212566bfd_xcoff_import_symbol (output_bfd, info, harg, val, imppath, impfile,
    2922                          impmember)
     2567                         impmember, syscall_flag)
    29232568     bfd *output_bfd;
    29242569     struct bfd_link_info *info;
     
    29282573     const char *impfile;
    29292574     const char *impmember;
     2575     unsigned int syscall_flag;
    29302576{
    29312577  struct xcoff_link_hash_entry *h = (struct xcoff_link_hash_entry *) harg;
    29322578
    29332579  if (bfd_get_flavour (output_bfd) != bfd_target_xcoff_flavour)
    2934     return true;
     2580    return TRUE;
    29352581
    29362582  /* A symbol name which starts with a period is the code for a
     
    29482594          hds = xcoff_link_hash_lookup (xcoff_hash_table (info),
    29492595                                        h->root.root.string + 1,
    2950                                         true, false, true);
     2596                                        TRUE, FALSE, TRUE);
    29512597          if (hds == NULL)
    2952             return false;
     2598            return FALSE;
    29532599          if (hds->root.type == bfd_link_hash_new)
    29542600            {
     
    29642610
    29652611      /* Now, if the descriptor is undefined, import the descriptor
    2966         rather than the symbol we were told to import.  FIXME: Is
    2967         this correct in all cases?  */
     2612        rather than the symbol we were told to import.  FIXME: Is
     2613        this correct in all cases?  */
    29682614      if (hds->root.type == bfd_link_hash_undefined)
    29692615        h = hds;
    29702616    }
    29712617
    2972   h->flags |= XCOFF_IMPORT;
     2618  h->flags |= (XCOFF_IMPORT | syscall_flag);
    29732619
    29742620  if (val != (bfd_vma) -1)
     
    29822628                  h->root.u.def.section, h->root.u.def.value,
    29832629                  output_bfd, bfd_abs_section_ptr, val)))
    2984             return false;
     2630            return FALSE;
    29852631        }
    29862632
     
    30022648
    30032649      /* We start c at 1 because the first entry in the import list is
    3004         reserved for the library search path.  */
     2650        reserved for the library search path.  */
    30052651      for (pp = &xcoff_hash_table (info)->imports, c = 1;
    30062652           *pp != NULL;
     
    30162662        {
    30172663          struct xcoff_import_file *n;
    3018 
    3019           n = ((struct xcoff_import_file *)
    3020                bfd_alloc (output_bfd, sizeof (struct xcoff_import_file)));
     2664          bfd_size_type amt = sizeof (struct xcoff_import_file);
     2665
     2666          n = (struct xcoff_import_file *) bfd_alloc (output_bfd, amt);
    30212667          if (n == NULL)
    3022             return false;
     2668            return FALSE;
    30232669          n->next = NULL;
    30242670          n->path = imppath;
     
    30312677    }
    30322678
    3033   return true;
     2679  return TRUE;
    30342680}
    30352681
    30362682/* Export a symbol.  */
    30372683
    3038 boolean
    3039 bfd_xcoff_export_symbol (output_bfd, info, harg, syscall)
     2684bfd_boolean
     2685bfd_xcoff_export_symbol (output_bfd, info, harg)
    30402686     bfd *output_bfd;
    30412687     struct bfd_link_info *info;
    30422688     struct bfd_link_hash_entry *harg;
    3043      boolean syscall ATTRIBUTE_UNUSED;
    30442689{
    30452690  struct xcoff_link_hash_entry *h = (struct xcoff_link_hash_entry *) harg;
    30462691
    30472692  if (bfd_get_flavour (output_bfd) != bfd_target_xcoff_flavour)
    3048     return true;
     2693    return TRUE;
    30492694
    30502695  h->flags |= XCOFF_EXPORT;
     
    30602705      char *fnname;
    30612706      struct xcoff_link_hash_entry *hfn;
    3062 
    3063       fnname = (char *) bfd_malloc (strlen (h->root.root.string) + 2);
     2707      bfd_size_type amt = strlen (h->root.root.string) + 2;
     2708
     2709      fnname = (char *) bfd_malloc (amt);
    30642710      if (fnname == NULL)
    3065         return false;
     2711        return FALSE;
    30662712      fnname[0] = '.';
    30672713      strcpy (fnname + 1, h->root.root.string);
    30682714      hfn = xcoff_link_hash_lookup (xcoff_hash_table (info),
    3069                                     fnname, false, false, true);
     2715                                    fnname, FALSE, FALSE, TRUE);
    30702716      free (fnname);
    30712717      if (hfn != NULL
     
    30822728  /* Make sure we don't garbage collect this symbol.  */
    30832729  if (! xcoff_mark_symbol (info, h))
    3084     return false;
     2730    return FALSE;
    30852731
    30862732  /* If this is a function descriptor, make sure we don't garbage
     
    30922738    {
    30932739      if (! xcoff_mark_symbol (info, h->descriptor))
    3094         return false;
    3095     }
    3096 
    3097   return true;
     2740        return FALSE;
     2741    }
     2742
     2743  return TRUE;
    30982744}
    30992745
     
    31022748   and destructors.  */
    31032749
    3104 boolean
     2750bfd_boolean
    31052751bfd_xcoff_link_count_reloc (output_bfd, info, name)
    31062752     bfd *output_bfd;
     
    31112757
    31122758  if (bfd_get_flavour (output_bfd) != bfd_target_xcoff_flavour)
    3113     return true;
     2759    return TRUE;
    31142760
    31152761  h = ((struct xcoff_link_hash_entry *)
    3116        bfd_wrapped_link_hash_lookup (output_bfd, info, name, false, false,
    3117                                      false));
     2762       bfd_wrapped_link_hash_lookup (output_bfd, info, name, FALSE, FALSE,
     2763                                     FALSE));
    31182764  if (h == NULL)
    31192765    {
    31202766      (*_bfd_error_handler) (_("%s: no such symbol"), name);
    31212767      bfd_set_error (bfd_error_no_symbols);
    3122       return false;
     2768      return FALSE;
    31232769    }
    31242770
     
    31282774  /* Mark the symbol to avoid garbage collection.  */
    31292775  if (! xcoff_mark_symbol (info, h))
    3130     return false;
    3131 
    3132   return true;
     2776    return FALSE;
     2777
     2778  return TRUE;
    31332779}
    31342780
     
    31362782   assigns a value.  */
    31372783
    3138 boolean
     2784bfd_boolean
    31392785bfd_xcoff_record_link_assignment (output_bfd, info, name)
    31402786     bfd *output_bfd;
     
    31452791
    31462792  if (bfd_get_flavour (output_bfd) != bfd_target_xcoff_flavour)
    3147     return true;
    3148 
    3149   h = xcoff_link_hash_lookup (xcoff_hash_table (info), name, true, true,
    3150                               false);
     2793    return TRUE;
     2794
     2795  h = xcoff_link_hash_lookup (xcoff_hash_table (info), name, TRUE, TRUE,
     2796                              FALSE);
    31512797  if (h == NULL)
    3152     return false;
     2798    return FALSE;
    31532799
    31542800  h->flags |= XCOFF_DEF_REGULAR;
    31552801
    3156   return true;
     2802  return TRUE;
    31572803}
    3158 
    3159 /* This structure is used to pass information through
    3160    xcoff_link_hash_traverse.  */
    3161 
    3162 struct xcoff_loader_info {
    3163   /* Set if a problem occurred.  */
    3164   boolean failed;
    3165   /* Output BFD.  */
    3166   bfd *output_bfd;
    3167   /* Link information structure.  */
    3168   struct bfd_link_info *info;
    3169   /* Whether all defined symbols should be exported.  */
    3170   boolean export_defineds;
    3171   /* Number of ldsym structures.  */
    3172   size_t ldsym_count;
    3173   /* Size of string table.  */
    3174   size_t string_size;
    3175   /* String table.  */
    3176   bfd_byte *strings;
    3177   /* Allocated size of string table.  */
    3178   size_t string_alc;
    3179 };
    31802804
    31812805/* Build the .loader section.  This is called by the XCOFF linker
     
    31962820   magic names like _end.  */
    31972821
    3198 boolean
     2822bfd_boolean
    31992823bfd_xcoff_size_dynamic_sections (output_bfd, info, libpath, entry,
    32002824                                 file_align, maxstack, maxdata, gc,
    32012825                                 modtype, textro, export_defineds,
    3202                                  special_sections)
     2826                                 special_sections, rtld)
    32032827     bfd *output_bfd;
    32042828     struct bfd_link_info *info;
     
    32082832     unsigned long maxstack;
    32092833     unsigned long maxdata;
    3210      boolean gc;
     2834     bfd_boolean gc;
    32112835     int modtype;
    3212      boolean textro;
    3213      boolean export_defineds;
     2836     bfd_boolean textro;
     2837     bfd_boolean export_defineds;
    32142838     asection **special_sections;
     2839     bfd_boolean rtld;
    32152840{
    32162841  struct xcoff_link_hash_entry *hentry;
     
    32272852  struct bfd_strtab_hash *debug_strtab;
    32282853  bfd_byte *debug_contents = NULL;
     2854  bfd_size_type amt;
    32292855
    32302856  if (bfd_get_flavour (output_bfd) != bfd_target_xcoff_flavour)
    32312857    {
    3232       for (i = 0; i < 6; i++)
     2858      for (i = 0; i < XCOFF_NUMBER_OF_SPECIAL_SECTIONS; i++)
    32332859        special_sections[i] = NULL;
    3234       return true;
    3235     }
    3236 
    3237   ldinfo.failed = false;
     2860      return TRUE;
     2861    }
     2862
     2863  ldinfo.failed = FALSE;
    32382864  ldinfo.output_bfd = output_bfd;
    32392865  ldinfo.info = info;
     
    32512877  xcoff_hash_table (info)->textro = textro;
    32522878
    3253   if (entry == NULL)
    3254     hentry = NULL;
    3255   else
     2879  hentry = NULL;
     2880  if (entry != NULL)
    32562881    {
    32572882      hentry = xcoff_link_hash_lookup (xcoff_hash_table (info), entry,
    3258                                        false, false, true);
     2883                                       FALSE, FALSE, TRUE);
    32592884      if (hentry != NULL)
    32602885        hentry->flags |= XCOFF_ENTRY;
     2886    }
     2887
     2888  /* __rtinit */
     2889  if (info->init_function || info->fini_function || rtld)
     2890    {
     2891      struct xcoff_link_hash_entry *hsym;
     2892      struct internal_ldsym *ldsym;
     2893
     2894      hsym = xcoff_link_hash_lookup (xcoff_hash_table (info),
     2895                                     "__rtinit", FALSE, FALSE, TRUE);
     2896      if (hsym == NULL)
     2897        {
     2898          (*_bfd_error_handler)
     2899            (_("error: undefined symbol __rtinit"));
     2900          return FALSE;
     2901        }
     2902
     2903      xcoff_mark_symbol (info, hsym);
     2904      hsym->flags |= (XCOFF_DEF_REGULAR | XCOFF_RTINIT);
     2905
     2906      /* __rtinit initalized */
     2907      amt = sizeof (struct internal_ldsym);
     2908      ldsym = (struct internal_ldsym *) bfd_malloc (amt);
     2909
     2910      ldsym->l_value = 0;               /* will be filled in later */
     2911      ldsym->l_scnum = 2;               /* data section */
     2912      ldsym->l_smtype = XTY_SD;         /* csect section definition */
     2913      ldsym->l_smclas = 5;              /* .rw */
     2914      ldsym->l_ifile = 0;               /* special system loader symbol */
     2915      ldsym->l_parm = 0;                /* NA */
     2916
     2917      /* Force __rtinit to be the first symbol in the loader symbol table
     2918         See xcoff_build_ldsyms
     2919
     2920         The first 3 symbol table indices are reserved to indicate the data,
     2921         text and bss sections.  */
     2922      BFD_ASSERT (0 == ldinfo.ldsym_count);
     2923
     2924      hsym->ldindx = 3;
     2925      ldinfo.ldsym_count = 1;
     2926      hsym->ldsym = ldsym;
     2927
     2928      if (! bfd_xcoff_put_ldsymbol_name (ldinfo.output_bfd, &ldinfo,
     2929                                         hsym->ldsym, hsym->root.root.string))
     2930        return FALSE;
     2931
     2932      /* This symbol is written out by xcoff_write_global_symbol
     2933         Set stuff up so xcoff_write_global_symbol logic works.  */
     2934      hsym->flags |= XCOFF_DEF_REGULAR | XCOFF_MARK;
     2935      hsym->root.type = bfd_link_hash_defined;
     2936      hsym->root.u.def.value = 0;
    32612937    }
    32622938
     
    32682944          && hentry->root.type != bfd_link_hash_defweak))
    32692945    {
    3270       gc = false;
    3271       xcoff_hash_table (info)->gc = false;
     2946      gc = FALSE;
     2947      xcoff_hash_table (info)->gc = FALSE;
    32722948
    32732949      /* We still need to call xcoff_mark, in order to set ldrel_count
    3274         correctly.  */
     2950        correctly.  */
    32752951      for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
    32762952        {
     
    32922968        goto error_return;
    32932969      xcoff_sweep (info);
    3294       xcoff_hash_table (info)->gc = true;
     2970      xcoff_hash_table (info)->gc = TRUE;
    32952971    }
    32962972
    32972973  /* Return special sections to the caller.  */
    3298   for (i = 0; i < 6; i++)
    3299     {
    3300       asection *sec;
    3301 
     2974  for (i = 0; i < XCOFF_NUMBER_OF_SPECIAL_SECTIONS; i++)
     2975    {
    33022976      sec = xcoff_hash_table (info)->special_sections[i];
     2977
    33032978      if (sec != NULL
    33042979          && gc
    33052980          && (sec->flags & SEC_MARK) == 0)
    3306         sec = NULL;
     2981        {
     2982          sec = NULL;
     2983        }
    33072984      special_sections[i] = sec;
    33082985    }
     
    33112988    {
    33122989      /* I'm not sure what to do in this bizarre case.  */
    3313       return true;
     2990      return TRUE;
    33142991    }
    33152992
     
    33383015  /* Set up the .loader section header.  */
    33393016  ldhdr = &xcoff_hash_table (info)->ldhdr;
    3340   ldhdr->l_version = 1;
     3017  ldhdr->l_version = bfd_xcoff_ldhdr_version(output_bfd);
    33413018  ldhdr->l_nsyms = ldinfo.ldsym_count;
    33423019  ldhdr->l_nreloc = xcoff_hash_table (info)->ldrel_count;
    33433020  ldhdr->l_istlen = impsize;
    33443021  ldhdr->l_nimpid = impcount;
    3345   ldhdr->l_impoff = (LDHDRSZ
    3346                      + ldhdr->l_nsyms * LDSYMSZ
    3347                      + ldhdr->l_nreloc * LDRELSZ);
     3022  ldhdr->l_impoff = (bfd_xcoff_ldhdrsz(output_bfd)
     3023                     + ldhdr->l_nsyms * bfd_xcoff_ldsymsz(output_bfd)
     3024                     + ldhdr->l_nreloc * bfd_xcoff_ldrelsz(output_bfd));
    33483025  ldhdr->l_stlen = ldinfo.string_size;
    33493026  stoff = ldhdr->l_impoff + impsize;
     
    33523029  else
    33533030    ldhdr->l_stoff = stoff;
     3031
     3032  /* 64 bit elements to ldhdr
     3033     The swap out routine for 32 bit will ignore them.
     3034     Nothing fancy, symbols come after the header and relocs come
     3035     after symbols.  */
     3036  ldhdr->l_symoff = bfd_xcoff_ldhdrsz (output_bfd);
     3037  ldhdr->l_rldoff = (bfd_xcoff_ldhdrsz (output_bfd)
     3038                     + ldhdr->l_nsyms * bfd_xcoff_ldsymsz (output_bfd));
    33543039
    33553040  /* We now know the final size of the .loader section.  Allocate
     
    33623047
    33633048  /* Set up the header.  */
    3364   xcoff_swap_ldhdr_out (output_bfd, ldhdr,
    3365                         (struct external_ldhdr *) lsec->contents);
     3049  bfd_xcoff_swap_ldhdr_out (output_bfd, ldhdr, lsec->contents);
    33663050
    33673051  /* Set up the import file names.  */
     
    34023086     xcoff_write_global_symbol.  The .loader relocs are written out
    34033087     when the corresponding normal relocs are handled in
    3404      xcoff_link_input_bfd.  */
     3088     xcoff_link_input_bfd.
     3089  */
    34053090
    34063091  /* Allocate space for the magic sections.  */
     
    34783163      csectpp = xcoff_data (sub)->csects;
    34793164
    3480       symesz = bfd_coff_symesz (sub);
    3481       esym = (bfd_byte *) obj_coff_external_syms (sub);
    3482       esymend = esym + symcount * symesz;
    3483       while (esym < esymend)
    3484         {
    3485           struct internal_syment sym;
    3486 
    3487           bfd_coff_swap_sym_in (sub, (PTR) esym, (PTR) &sym);
    3488 
    3489           *debug_index = (unsigned long) -1;
    3490 
    3491           if (sym._n._n_n._n_zeroes == 0
    3492               && *csectpp != NULL
    3493               && (! gc
    3494                   || ((*csectpp)->flags & SEC_MARK) != 0
    3495                   || *csectpp == bfd_abs_section_ptr)
    3496               && bfd_coff_symname_in_debug (sub, &sym))
    3497             {
    3498               char *name;
    3499               bfd_size_type indx;
    3500 
    3501               name = (char *) debug_contents + sym._n._n_n._n_offset;
    3502               indx = _bfd_stringtab_add (debug_strtab, name, true, true);
    3503               if (indx == (bfd_size_type) -1)
    3504                 goto error_return;
    3505               *debug_index = indx;
    3506             }
    3507 
    3508           esym += (sym.n_numaux + 1) * symesz;
    3509           csectpp += sym.n_numaux + 1;
    3510           debug_index += sym.n_numaux + 1;
     3165      /* Dynamic object do not have csectpp's.  */
     3166      if (NULL != csectpp)
     3167        {
     3168          symesz = bfd_coff_symesz (sub);
     3169          esym = (bfd_byte *) obj_coff_external_syms (sub);
     3170          esymend = esym + symcount * symesz;
     3171
     3172          while (esym < esymend)
     3173            {
     3174              struct internal_syment sym;
     3175
     3176              bfd_coff_swap_sym_in (sub, (PTR) esym, (PTR) &sym);
     3177
     3178              *debug_index = (unsigned long) -1;
     3179
     3180              if (sym._n._n_n._n_zeroes == 0
     3181                  && *csectpp != NULL
     3182                  && (! gc
     3183                      || ((*csectpp)->flags & SEC_MARK) != 0
     3184                      || *csectpp == bfd_abs_section_ptr)
     3185                  && bfd_coff_symname_in_debug (sub, &sym))
     3186                {
     3187                  char *name;
     3188                  bfd_size_type indx;
     3189
     3190                  name = (char *) debug_contents + sym._n._n_n._n_offset;
     3191                  indx = _bfd_stringtab_add (debug_strtab, name, TRUE, TRUE);
     3192                  if (indx == (bfd_size_type) -1)
     3193                    goto error_return;
     3194                  *debug_index = indx;
     3195                }
     3196
     3197              esym += (sym.n_numaux + 1) * symesz;
     3198              csectpp += sym.n_numaux + 1;
     3199              debug_index += sym.n_numaux + 1;
     3200            }
    35113201        }
    35123202
     
    35293219      _bfd_stringtab_size (debug_strtab);
    35303220
    3531   return true;
     3221  return TRUE;
    35323222
    35333223 error_return:
     
    35363226  if (debug_contents != NULL)
    35373227    free (debug_contents);
    3538   return false;
     3228  return FALSE;
    35393229}
    35403230
     3231bfd_boolean
     3232bfd_xcoff_link_generate_rtinit (abfd, init, fini, rtld)
     3233     bfd *abfd;
     3234     const char *init;
     3235     const char *fini;
     3236     bfd_boolean rtld;
     3237{
     3238  struct bfd_in_memory *bim;
     3239
     3240  bim = ((struct bfd_in_memory *)
     3241         bfd_malloc ((bfd_size_type) sizeof (struct bfd_in_memory)));
     3242  if (bim == NULL)
     3243    return FALSE;
     3244
     3245  bim->size = 0;
     3246  bim->buffer = 0;
     3247
     3248  abfd->link_next = 0;
     3249  abfd->format = bfd_object;
     3250  abfd->iostream = (PTR) bim;
     3251  abfd->flags = BFD_IN_MEMORY;
     3252  abfd->direction = write_direction;
     3253  abfd->where = 0;
     3254
     3255  if (! bfd_xcoff_generate_rtinit (abfd, init, fini, rtld))
     3256    return FALSE;
     3257
     3258  /* need to reset to unknown or it will not be read back in correctly */
     3259  abfd->format = bfd_unknown;
     3260  abfd->direction = read_direction;
     3261  abfd->where = 0;
     3262
     3263  return TRUE;
     3264}
     3265
     3266
    35413267/* Add a symbol to the .loader symbols, if necessary.  */
    35423268
    3543 static boolean
     3269static bfd_boolean
    35443270xcoff_build_ldsyms (h, p)
    35453271     struct xcoff_link_hash_entry *h;
     
    35473273{
    35483274  struct xcoff_loader_info *ldinfo = (struct xcoff_loader_info *) p;
    3549   size_t len;
     3275  bfd_size_type amt;
     3276
     3277  if (h->root.type == bfd_link_hash_warning)
     3278    h = (struct xcoff_link_hash_entry *) h->root.u.i.link;
     3279
     3280  /* __rtinit, this symbol has special handling. */
     3281  if (h->flags & XCOFF_RTINIT)
     3282      return TRUE;
    35503283
    35513284  /* If this is a final link, and the symbol was defined as a common
     
    35693302      && h->root.root.string[0] != '.')
    35703303    {
    3571       boolean export;
     3304      bfd_boolean export;
    35723305
    35733306      /* We don't export a symbol which is being defined by an object
     
    35853318         a different approach.  Note that the symbols can, of course,
    35863319         be exported explicitly.  */
    3587       export = true;
     3320      export = TRUE;
    35883321      if ((h->root.type == bfd_link_hash_defined
    35893322           || h->root.type == bfd_link_hash_defweak)
     
    35993332              if ((member->flags & DYNAMIC) != 0)
    36003333                {
    3601                   export = false;
     3334                  export = FALSE;
    36023335                  break;
    36033336                }
     
    36453378      h->smclas = XMC_GL;
    36463379      h->flags |= XCOFF_DEF_REGULAR;
    3647       sec->_raw_size += XCOFF_GLINK_SIZE;
     3380      sec->_raw_size += bfd_xcoff_glink_code_size(ldinfo->output_bfd);
    36483381
    36493382      /* The global linkage code requires a TOC entry for the
    3650         descriptor.  */
     3383        descriptor.  */
    36513384      hds = h->descriptor;
    36523385      BFD_ASSERT ((hds->root.type == bfd_link_hash_undefined
     
    36563389      if (hds->toc_section == NULL)
    36573390        {
     3391          int byte_size;
     3392
     3393          /* 32 vs 64
     3394             xcoff32 uses 4 bytes in the toc.
     3395             xcoff64 uses 8 bytes in the toc.  */
     3396          if (bfd_xcoff_is_xcoff64 (ldinfo->output_bfd))
     3397            byte_size = 8;
     3398          else if (bfd_xcoff_is_xcoff32 (ldinfo->output_bfd))
     3399            byte_size = 4;
     3400          else
     3401            return FALSE;
     3402
    36583403          hds->toc_section = xcoff_hash_table (ldinfo->info)->toc_section;
    36593404          hds->u.toc_offset = hds->toc_section->_raw_size;
    3660           hds->toc_section->_raw_size += 4;
     3405          hds->toc_section->_raw_size += byte_size;
    36613406          ++xcoff_hash_table (ldinfo->info)->ldrel_count;
    36623407          ++hds->toc_section->reloc_count;
     
    36653410
    36663411          /* We need to call xcoff_build_ldsyms recursively here,
    3667              because we may already have passed hds on the traversal.  */
     3412             because we may already have passed hds on the traversal.  */
    36683413          xcoff_build_ldsyms (hds, p);
    36693414        }
     
    36863431
    36873432          /* This is an undefined function descriptor associated with
    3688              a defined entry point.  We can build up a function
    3689              descriptor ourselves.  Believe it or not, the AIX linker
    3690              actually does this, and there are cases where we need to
    3691              do it as well.  */
     3433             a defined entry point.  We can build up a function
     3434             descriptor ourselves.  Believe it or not, the AIX linker
     3435             actually does this, and there are cases where we need to
     3436             do it as well.  */
    36923437          sec = xcoff_hash_table (ldinfo->info)->descriptor_section;
    36933438          h->root.type = bfd_link_hash_defined;
     
    36963441          h->smclas = XMC_DS;
    36973442          h->flags |= XCOFF_DEF_REGULAR;
    3698           sec->_raw_size += 12;
     3443
     3444          /* The size of the function descriptor depends if this is an
     3445             xcoff32 (12) or xcoff64 (24).  */
     3446          sec->_raw_size +=
     3447            bfd_xcoff_function_descriptor_size(ldinfo->output_bfd);
    36993448
    37003449          /* A function descriptor uses two relocs: one for the
    3701              associated code, and one for the TOC address.  */
     3450             associated code, and one for the TOC address.  */
    37023451          xcoff_hash_table (ldinfo->info)->ldrel_count += 2;
    37033452          sec->reloc_count += 2;
    37043453
    37053454          /* We handle writing out the contents of the descriptor in
    3706              xcoff_write_global_symbol.  */
     3455             xcoff_write_global_symbol.  */
    37073456        }
    37083457      else
     
    37123461             h->root.root.string);
    37133462          h->ldsym = NULL;
    3714           return true;
     3463          return TRUE;
    37153464        }
    37163465    }
     
    37413490    {
    37423491      h->ldsym = NULL;
    3743       return true;
     3492      return TRUE;
    37443493    }
    37453494
     
    37503499    {
    37513500      h->ldsym = NULL;
    3752       return true;
     3501      return TRUE;
    37533502    }
    37543503
     
    37563505     call above.  */
    37573506  if ((h->flags & XCOFF_BUILT_LDSYM) != 0)
    3758     return true;
     3507    return TRUE;
    37593508
    37603509  /* We need to add this symbol to the .loader symbols.  */
    37613510
    37623511  BFD_ASSERT (h->ldsym == NULL);
    3763   h->ldsym = ((struct internal_ldsym *)
    3764               bfd_zalloc (ldinfo->output_bfd,
    3765                           sizeof (struct internal_ldsym)));
     3512  amt = sizeof (struct internal_ldsym);
     3513  h->ldsym = (struct internal_ldsym *) bfd_zalloc (ldinfo->output_bfd, amt);
    37663514  if (h->ldsym == NULL)
    37673515    {
    3768       ldinfo->failed = true;
    3769       return false;
     3516      ldinfo->failed = TRUE;
     3517      return FALSE;
    37703518    }
    37713519
     
    37743522
    37753523  /* The first 3 symbol table indices are reserved to indicate the
    3776      sections.  */
     3524     data, text and bss sections.  */
    37773525  h->ldindx = ldinfo->ldsym_count + 3;
    37783526
    37793527  ++ldinfo->ldsym_count;
    37803528
    3781   len = strlen (h->root.root.string);
    3782   if (len <= SYMNMLEN)
    3783     strncpy (h->ldsym->_l._l_name, h->root.root.string, SYMNMLEN);
    3784   else
    3785     {
    3786       if (ldinfo->string_size + len + 3 > ldinfo->string_alc)
    3787         {
    3788           size_t newalc;
    3789           bfd_byte *newstrings;
    3790 
    3791           newalc = ldinfo->string_alc * 2;
    3792           if (newalc == 0)
    3793             newalc = 32;
    3794           while (ldinfo->string_size + len + 3 > newalc)
    3795             newalc *= 2;
    3796 
    3797           newstrings = ((bfd_byte *)
    3798                         bfd_realloc ((PTR) ldinfo->strings, newalc));
    3799           if (newstrings == NULL)
    3800             {
    3801               ldinfo->failed = true;
    3802               return false;
    3803             }
    3804           ldinfo->string_alc = newalc;
    3805           ldinfo->strings = newstrings;
    3806         }
    3807 
    3808       bfd_put_16 (ldinfo->output_bfd, len + 1,
    3809                   ldinfo->strings + ldinfo->string_size);
    3810       strcpy (ldinfo->strings + ldinfo->string_size + 2, h->root.root.string);
    3811       h->ldsym->_l._l_l._l_zeroes = 0;
    3812       h->ldsym->_l._l_l._l_offset = ldinfo->string_size + 2;
    3813       ldinfo->string_size += len + 3;
     3529  if (! bfd_xcoff_put_ldsymbol_name (ldinfo->output_bfd, ldinfo,
     3530                                     h->ldsym, h->root.root.string))
     3531    {
     3532      return FALSE;
    38143533    }
    38153534
    38163535  h->flags |= XCOFF_BUILT_LDSYM;
    38173536
    3818   return true;
     3537  return TRUE;
    38193538}
    38203539
     
    38223541/* Do the final link step.  */
    38233542
    3824 boolean
     3543bfd_boolean
    38253544_bfd_xcoff_bfd_final_link (abfd, info)
    38263545     bfd *abfd;
     
    38313550  asection *o;
    38323551  struct bfd_link_order *p;
    3833   size_t max_contents_size;
    3834   size_t max_sym_count;
    3835   size_t max_lineno_count;
    3836   size_t max_reloc_count;
    3837   size_t max_output_reloc_count;
     3552  bfd_size_type max_contents_size;
     3553  bfd_size_type max_sym_count;
     3554  bfd_size_type max_lineno_count;
     3555  bfd_size_type max_reloc_count;
     3556  bfd_size_type max_output_reloc_count;
    38383557  file_ptr rel_filepos;
    38393558  unsigned int relsz;
     
    38433562  bfd_byte *external_relocs = NULL;
    38443563  char strbuf[STRING_SIZE_SIZE];
     3564  file_ptr pos;
     3565  bfd_size_type amt;
    38453566
    38463567  if (info->shared)
     
    38623583  finfo.external_relocs = NULL;
    38633584
    3864   finfo.ldsym = ((struct external_ldsym *)
    3865                  (xcoff_hash_table (info)->loader_section->contents
    3866                   + LDHDRSZ));
    3867   finfo.ldrel = ((struct external_ldrel *)
    3868                  (xcoff_hash_table (info)->loader_section->contents
    3869                   + LDHDRSZ
    3870                   + xcoff_hash_table (info)->ldhdr.l_nsyms * LDSYMSZ));
     3585  finfo.ldsym = (xcoff_hash_table (info)->loader_section->contents
     3586                 + bfd_xcoff_ldhdrsz (abfd));
     3587  finfo.ldrel = (xcoff_hash_table (info)->loader_section->contents
     3588                 + bfd_xcoff_ldhdrsz(abfd)
     3589                 + (xcoff_hash_table (info)->ldhdr.l_nsyms
     3590                    * bfd_xcoff_ldsymsz(abfd)));
    38713591
    38723592  xcoff_data (abfd)->coff.link_info = info;
     
    38973617                 to do this so that we can identify any sections which
    38983618                 the linker has decided to not include.  */
    3899               sec->linker_mark = true;
     3619              sec->linker_mark = TRUE;
    39003620
    39013621              if (info->strip == strip_none
     
    39373657      if (file_align != 0)
    39383658        {
    3939           boolean saw_contents;
     3659          bfd_boolean saw_contents;
    39403660          int indx;
    39413661          asection **op;
     
    39433663
    39443664          /* Insert .pad sections before every section which has
    3945              contents and is loaded, if it is preceded by some other
    3946              section which has contents and is loaded.  */
    3947           saw_contents = true;
     3665             contents and is loaded, if it is preceded by some other
     3666             section which has contents and is loaded.  */
     3667          saw_contents = TRUE;
    39483668          for (op = &abfd->sections; *op != NULL; op = &(*op)->next)
    39493669            {
    39503670              if (strcmp ((*op)->name, ".pad") == 0)
    3951                 saw_contents = false;
     3671                saw_contents = FALSE;
    39523672              else if (((*op)->flags & SEC_HAS_CONTENTS) != 0
    39533673                       && ((*op)->flags & SEC_LOAD) != 0)
    39543674                {
    39553675                  if (! saw_contents)
    3956                     saw_contents = true;
     3676                    saw_contents = TRUE;
    39573677                  else
    39583678                    {
    3959                       asection *n, *hold;
    3960 
    3961                       hold = *op;
    3962                       *op = NULL;
     3679                      asection *n, **st;
     3680
     3681                      /* Create a pad section and place it before the section
     3682                         that needs padding.  This requires unlinking and
     3683                         relinking the bfd's section list.  */
     3684
     3685                      st = abfd->section_tail;
    39633686                      n = bfd_make_section_anyway (abfd, ".pad");
    3964                       BFD_ASSERT (*op == n);
    3965                       n->next = hold;
    39663687                      n->flags = SEC_HAS_CONTENTS;
    39673688                      n->alignment_power = 0;
    3968                       saw_contents = false;
     3689
     3690                      BFD_ASSERT (*st == n);
     3691                      bfd_section_list_remove (abfd, st);
     3692                      bfd_section_list_insert (abfd, op, n);
     3693
     3694                      op = &n->next;
     3695                      saw_contents = FALSE;
    39693696                    }
    39703697                }
     
    39723699
    39733700          /* Reset the section indices after inserting the new
    3974              sections.  */
     3701             sections.  */
    39753702          indx = 0;
    39763703          for (o = abfd->sections; o != NULL; o = o->next)
     
    39823709
    39833710          /* Work out appropriate sizes for the .pad sections to force
    3984              each section to land on a page boundary.  This bit of
    3985              code knows what compute_section_file_positions is going
    3986              to do.  */
     3711             each section to land on a page boundary.  This bit of
     3712             code knows what compute_section_file_positions is going
     3713             to do.  */
    39873714          sofar = bfd_coff_filhsz (abfd);
    39883715          sofar += bfd_coff_aoutsz (abfd);
    39893716          sofar += abfd->section_count * bfd_coff_scnhsz (abfd);
    39903717          for (o = abfd->sections; o != NULL; o = o->next)
    3991             if (o->reloc_count >= 0xffff || o->lineno_count >= 0xffff)
     3718            if ((bfd_xcoff_is_reloc_count_overflow
     3719                 (abfd, (bfd_vma) o->reloc_count))
     3720                || (bfd_xcoff_is_lineno_count_overflow
     3721                    (abfd, (bfd_vma) o->lineno_count)))
     3722              /* 64 does not overflow, need to check if 32 does */
    39923723              sofar += bfd_coff_scnhsz (abfd);
    39933724
     
    40263757    /* We use section_count + 1, rather than section_count, because
    40273758       the target_index fields are 1 based.  */
    4028     finfo.section_info =
    4029       ((struct xcoff_link_section_info *)
    4030        bfd_malloc ((abfd->section_count + 1)
    4031                    * sizeof (struct xcoff_link_section_info)));
     3759    amt = abfd->section_count + 1;
     3760    amt *= sizeof (struct xcoff_link_section_info);
     3761    finfo.section_info = (struct xcoff_link_section_info *) bfd_malloc (amt);
    40323762    if (finfo.section_info == NULL)
    40333763      goto error_return;
     
    40513781        {
    40523782          /* A stripped file has no relocs.  However, we still
    4053              allocate the buffers, so that later code doesn't have to
    4054              worry about whether we are stripping or not.  */
     3783             allocate the buffers, so that later code doesn't have to
     3784             worry about whether we are stripping or not.  */
    40553785          if (info->strip == strip_all)
    40563786            o->rel_filepos = 0;
     
    40633793
    40643794          /* We don't know the indices of global symbols until we have
    4065              written out all the local symbols.  For each section in
    4066              the output file, we keep an array of pointers to hash
    4067              table entries.  Each entry in the array corresponds to a
    4068              reloc.  When we find a reloc against a global symbol, we
    4069              set the corresponding entry in this array so that we can
    4070              fix up the symbol index after we have written out all the
    4071              local symbols.
     3795             written out all the local symbols.  For each section in
     3796             the output file, we keep an array of pointers to hash
     3797             table entries.  Each entry in the array corresponds to a
     3798             reloc.  When we find a reloc against a global symbol, we
     3799             set the corresponding entry in this array so that we can
     3800             fix up the symbol index after we have written out all the
     3801             local symbols.
    40723802
    40733803             Because of this problem, we also keep the relocs in
     
    40753805             We could backpatch the file later, I suppose, although it
    40763806             would be slow.  */
     3807          amt = o->reloc_count;
     3808          amt *= sizeof (struct internal_reloc);
    40773809          finfo.section_info[o->target_index].relocs =
    4078             ((struct internal_reloc *)
    4079              bfd_malloc (o->reloc_count * sizeof (struct internal_reloc)));
     3810            (struct internal_reloc *) bfd_malloc (amt);
     3811
     3812          amt = o->reloc_count;
     3813          amt *= sizeof (struct xcoff_link_hash_entry *);
    40803814          finfo.section_info[o->target_index].rel_hashes =
    4081             ((struct xcoff_link_hash_entry **)
    4082              bfd_malloc (o->reloc_count
    4083                          * sizeof (struct xcoff_link_hash_entry *)));
     3815            (struct xcoff_link_hash_entry **) bfd_malloc (amt);
     3816
    40843817          if (finfo.section_info[o->target_index].relocs == NULL
    40853818              || finfo.section_info[o->target_index].rel_hashes == NULL)
     
    41213854  for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
    41223855    {
    4123       size_t sz;
    4124 
    4125       sub->output_has_begun = false;
     3856      bfd_size_type sz;
     3857
     3858      sub->output_has_begun = FALSE;
    41263859      sz = obj_raw_syment_count (sub);
    41273860      if (sz > max_sym_count)
     
    41303863
    41313864  /* Allocate some buffers used while linking.  */
    4132   finfo.internal_syms = ((struct internal_syment *)
    4133                          bfd_malloc (max_sym_count
    4134                                      * sizeof (struct internal_syment)));
    4135   finfo.sym_indices = (long *) bfd_malloc (max_sym_count * sizeof (long));
    4136   finfo.outsyms = ((bfd_byte *)
    4137                    bfd_malloc ((size_t) ((max_sym_count + 1) * symesz)));
    4138   finfo.linenos = (bfd_byte *) bfd_malloc (max_lineno_count
    4139                                            * bfd_coff_linesz (abfd));
    4140   finfo.contents = (bfd_byte *) bfd_malloc (max_contents_size);
    4141   finfo.external_relocs = (bfd_byte *) bfd_malloc (max_reloc_count * relsz);
     3865  amt = max_sym_count * sizeof (struct internal_syment);
     3866  finfo.internal_syms = (struct internal_syment *) bfd_malloc (amt);
     3867
     3868  amt = max_sym_count * sizeof (long);
     3869  finfo.sym_indices = (long *) bfd_malloc (amt);
     3870
     3871  amt = (max_sym_count + 1) * symesz;
     3872  finfo.outsyms = (bfd_byte *) bfd_malloc (amt);
     3873
     3874  amt = max_lineno_count * bfd_coff_linesz (abfd);
     3875  finfo.linenos = (bfd_byte *) bfd_malloc (amt);
     3876
     3877  amt = max_contents_size;
     3878  finfo.contents = (bfd_byte *) bfd_malloc (amt);
     3879
     3880  amt = max_reloc_count * relsz;
     3881  finfo.external_relocs = (bfd_byte *) bfd_malloc (amt);
     3882
    41423883  if ((finfo.internal_syms == NULL && max_sym_count > 0)
    41433884      || (finfo.sym_indices == NULL && max_sym_count > 0)
     
    41683909                  if (! xcoff_link_input_bfd (&finfo, sub))
    41693910                    goto error_return;
    4170                   sub->output_has_begun = true;
     3911                  sub->output_has_begun = TRUE;
    41713912                }
    41723913            }
     
    41843925        }
    41853926    }
     3927
    41863928
    41873929  /* Free up the buffers used by xcoff_link_input_bfd.  */
     
    42173959  if (finfo.last_file_index != -1)
    42183960    {
    4219       finfo.last_file.n_value = -1;
     3961      finfo.last_file.n_value = -(bfd_vma) 1;
    42203962      bfd_coff_swap_sym_out (abfd, (PTR) &finfo.last_file,
    42213963                             (PTR) finfo.outsyms);
    4222       if (bfd_seek (abfd,
    4223                     (obj_sym_filepos (abfd)
    4224                      + finfo.last_file_index * symesz),
    4225                     SEEK_SET) != 0
    4226           || bfd_write (finfo.outsyms, symesz, 1, abfd) != symesz)
     3964      pos = obj_sym_filepos (abfd) + finfo.last_file_index * symesz;
     3965      if (bfd_seek (abfd, pos, SEEK_SET) != 0
     3966          || bfd_bwrite (finfo.outsyms, symesz, abfd) != symesz)
    42273967        goto error_return;
    42283968    }
     
    42433983     symbol indices to use for relocs against them, and we can finally
    42443984     write out the relocs.  */
    4245   external_relocs = (bfd_byte *) bfd_malloc (max_output_reloc_count * relsz);
     3985  amt = max_output_reloc_count * relsz;
     3986  external_relocs = (bfd_byte *) bfd_malloc (amt);
    42463987  if (external_relocs == NULL && max_output_reloc_count != 0)
    42473988    goto error_return;
     
    42543995      struct xcoff_toc_rel_hash *toc_rel_hash;
    42553996      bfd_byte *erel;
     3997      bfd_size_type rel_size;
    42563998
    42573999      /* A stripped file has no relocs.  */
     
    43004042
    43014043      /* XCOFF requires that the relocs be sorted by address.  We tend
    4302         to produce them in the order in which their containing csects
    4303         appear in the symbol table, which is not necessarily by
    4304         address.  So we sort them here.  There may be a better way to
    4305         do this.  */
     4044        to produce them in the order in which their containing csects
     4045        appear in the symbol table, which is not necessarily by
     4046        address.  So we sort them here.  There may be a better way to
     4047        do this.  */
    43064048      qsort ((PTR) finfo.section_info[o->target_index].relocs,
    43074049             o->reloc_count, sizeof (struct internal_reloc),
     
    43144056        bfd_coff_swap_reloc_out (abfd, (PTR) irel, (PTR) erel);
    43154057
     4058      rel_size = relsz * o->reloc_count;
    43164059      if (bfd_seek (abfd, o->rel_filepos, SEEK_SET) != 0
    4317           || bfd_write ((PTR) external_relocs, relsz, o->reloc_count,
    4318                         abfd) != relsz * o->reloc_count)
     4060          || bfd_bwrite ((PTR) external_relocs, rel_size, abfd) != rel_size)
    43194061        goto error_return;
    43204062    }
     
    43474089                  + xcoff_hash_table (info)->ldhdr.l_impoff));
    43484090  o = xcoff_hash_table (info)->loader_section;
    4349   if (! bfd_set_section_contents (abfd, o->output_section,
    4350                                   o->contents, o->output_offset,
    4351                                   o->_raw_size))
     4091  if (! bfd_set_section_contents (abfd, o->output_section, o->contents,
     4092                                  (file_ptr) o->output_offset, o->_raw_size))
    43524093    goto error_return;
    43534094
     
    43564097  if (o->_raw_size > 0
    43574098      && ! bfd_set_section_contents (abfd, o->output_section, o->contents,
    4358                                      o->output_offset, o->_raw_size))
     4099                                     (file_ptr) o->output_offset,
     4100                                     o->_raw_size))
    43594101    goto error_return;
    43604102  o = xcoff_hash_table (info)->toc_section;
    43614103  if (o->_raw_size > 0
    43624104      && ! bfd_set_section_contents (abfd, o->output_section, o->contents,
    4363                                      o->output_offset, o->_raw_size))
     4105                                     (file_ptr) o->output_offset,
     4106                                     o->_raw_size))
    43644107    goto error_return;
    43654108  o = xcoff_hash_table (info)->descriptor_section;
    43664109  if (o->_raw_size > 0
    43674110      && ! bfd_set_section_contents (abfd, o->output_section, o->contents,
    4368                                      o->output_offset, o->_raw_size))
     4111                                     (file_ptr) o->output_offset,
     4112                                     o->_raw_size))
    43694113    goto error_return;
    43704114
    43714115  /* Write out the string table.  */
    4372   if (bfd_seek (abfd,
    4373                 (obj_sym_filepos (abfd)
    4374                  + obj_raw_syment_count (abfd) * symesz),
    4375                 SEEK_SET) != 0)
     4116  pos = obj_sym_filepos (abfd) + obj_raw_syment_count (abfd) * symesz;
     4117  if (bfd_seek (abfd, pos, SEEK_SET) != 0)
    43764118    goto error_return;
    4377   bfd_h_put_32 (abfd,
    4378                 _bfd_stringtab_size (finfo.strtab) + STRING_SIZE_SIZE,
    4379                 (bfd_byte *) strbuf);
    4380   if (bfd_write (strbuf, 1, STRING_SIZE_SIZE, abfd) != STRING_SIZE_SIZE)
     4119  H_PUT_32 (abfd,
     4120            _bfd_stringtab_size (finfo.strtab) + STRING_SIZE_SIZE,
     4121            strbuf);
     4122  amt = STRING_SIZE_SIZE;
     4123  if (bfd_bwrite (strbuf, amt, abfd) != amt)
    43814124    goto error_return;
    43824125  if (! _bfd_stringtab_emit (abfd, finfo.strtab))
     
    43944137      BFD_ASSERT (o->output_section->_raw_size - o->output_offset
    43954138                  >= _bfd_stringtab_size (debug_strtab));
    4396       if (bfd_seek (abfd,
    4397                     o->output_section->filepos + o->output_offset,
    4398                     SEEK_SET) != 0)
     4139      pos = o->output_section->filepos + o->output_offset;
     4140      if (bfd_seek (abfd, pos, SEEK_SET) != 0)
    43994141        goto error_return;
    44004142      if (! _bfd_stringtab_emit (abfd, debug_strtab))
     
    44064148  bfd_get_symcount (abfd) = 0;
    44074149
    4408   return true;
     4150  return TRUE;
    44094151
    44104152 error_return:
    44114153  if (finfo.strtab != NULL)
    44124154    _bfd_stringtab_free (finfo.strtab);
     4155
    44134156  if (finfo.section_info != NULL)
    44144157    {
     
    44244167      free (finfo.section_info);
    44254168    }
     4169
    44264170  if (finfo.internal_syms != NULL)
    44274171    free (finfo.internal_syms);
     
    44384182  if (external_relocs != NULL)
    44394183    free (external_relocs);
    4440   return false;
     4184  return FALSE;
    44414185}
    44424186
     
    44444188   handles all the sections and relocations of the input file at once.  */
    44454189
    4446 static boolean
     4190static bfd_boolean
    44474191xcoff_link_input_bfd (finfo, input_bfd)
    44484192     struct xcoff_final_link_info *finfo;
     
    44544198  unsigned int n_tmask;
    44554199  unsigned int n_btshft;
    4456   boolean copy, hash;
     4200  bfd_boolean copy, hash;
    44574201  bfd_size_type isymesz;
    44584202  bfd_size_type osymesz;
     
    44694213  unsigned int incls;
    44704214  asection *oline;
    4471   boolean keep_syms;
     4215  bfd_boolean keep_syms;
    44724216  asection *o;
    44734217
     
    44754219  if ((input_bfd->flags & DYNAMIC) != 0
    44764220      && ! finfo->info->static_link)
    4477     return true;
     4221    return TRUE;
    44784222
    44794223  /* Move all the symbols to the output file.  */
     
    44944238#define N_BTSHFT n_btshft
    44954239
    4496   copy = false;
     4240  copy = FALSE;
    44974241  if (! finfo->info->keep_memory)
    4498     copy = true;
    4499   hash = true;
     4242    copy = TRUE;
     4243  hash = TRUE;
    45004244  if ((output_bfd->flags & BFD_TRADITIONAL_FORMAT) != 0)
    4501     hash = false;
     4245    hash = FALSE;
    45024246
    45034247  if (! _bfd_coff_get_external_symbols (input_bfd))
    4504     return false;
     4248    return FALSE;
    45054249
    45064250  esym = (bfd_byte *) obj_coff_external_syms (input_bfd);
     
    45184262  while (esym < esym_end)
    45194263    {
     4264
    45204265      struct internal_syment isym;
    45214266      union internal_auxent aux;
    45224267      int smtyp = 0;
    4523       boolean skip;
    4524       boolean require;
     4268      bfd_boolean skip;
     4269      bfd_boolean require;
    45254270      int add;
    45264271
     
    45284273
    45294274      /* If this is a C_EXT or C_HIDEXT symbol, we need the csect
    4530         information.  */
     4275        information.  */
    45314276      if (isymp->n_sclass == C_EXT || isymp->n_sclass == C_HIDEXT)
    45324277        {
     
    45374282                                isymp->n_numaux - 1, isymp->n_numaux,
    45384283                                (PTR) &aux);
     4284
    45394285          smtyp = SMTYP_SMTYP (aux.x_csect.x_smtyp);
    45404286        }
     
    45474293
    45484294      /* If this symbol is in the .loader section, swap out the
    4549         .loader symbol information.  If this is an external symbol
    4550         reference to a defined symbol, though, then wait until we get
    4551         to the definition.  */
     4295        .loader symbol information.  If this is an external symbol
     4296        reference to a defined symbol, though, then wait until we get
     4297        to the definition.  */
    45524298      if (isym.n_sclass == C_EXT
    45534299          && *sym_hash != NULL
     
    46214367
    46224368          BFD_ASSERT (h->ldindx >= 0);
    4623           BFD_ASSERT (LDSYMSZ == sizeof (struct external_ldsym));
    4624           xcoff_swap_ldsym_out (finfo->output_bfd, ldsym,
    4625                                 finfo->ldsym + h->ldindx - 3);
     4369          bfd_xcoff_swap_ldsym_out (finfo->output_bfd, ldsym,
     4370                                    (finfo->ldsym
     4371                                     + ((h->ldindx - 3)
     4372                                        * bfd_xcoff_ldsymsz (finfo->output_bfd))));
    46264373          h->ldsym = NULL;
    46274374
     
    46304377              && (h->root.type == bfd_link_hash_defined
    46314378                  || h->root.type == bfd_link_hash_defweak))
    4632             xcoff_data (output_bfd)->snentry =
    4633               h->root.u.def.section->output_section->target_index;
     4379            {
     4380              xcoff_data (output_bfd)->snentry =
     4381                h->root.u.def.section->output_section->target_index;
     4382            }
    46344383        }
    46354384
    46364385      *indexp = -1;
    46374386
    4638       skip = false;
    4639       require = false;
     4387      skip = FALSE;
     4388      require = FALSE;
    46404389      add = 1 + isym.n_numaux;
    46414390
    46424391      /* If we are skipping this csect, we want to skip this symbol.  */
    46434392      if (*csectpp == NULL)
    4644         skip = true;
     4393        skip = TRUE;
    46454394
    46464395      /* If we garbage collected this csect, we want to skip this
    4647         symbol.  */
     4396        symbol.  */
    46484397      if (! skip
    46494398          && xcoff_hash_table (finfo->info)->gc
    46504399          && ((*csectpp)->flags & SEC_MARK) == 0
    46514400          && *csectpp != bfd_abs_section_ptr)
    4652         skip = true;
     4401        skip = TRUE;
    46534402
    46544403      /* An XCOFF linker always skips C_STAT symbols.  */
    46554404      if (! skip
    46564405          && isymp->n_sclass == C_STAT)
    4657         skip = true;
     4406        skip = TRUE;
    46584407
    46594408      /* We skip all but the first TOC anchor.  */
     
    46634412        {
    46644413          if (finfo->toc_symindx != -1)
    4665             skip = true;
     4414            skip = TRUE;
    46664415          else
    46674416            {
     
    46754424
    46764425              /* We want to find out if tocval is a good value to use
    4677                 as the TOC anchor--that is, whether we can access all
    4678                 of the TOC using a 16 bit offset from tocval.  This
    4679                 test assumes that the TOC comes at the end of the
    4680                 output section, as it does in the default linker
    4681                 script.  */
     4426                as the TOC anchor--that is, whether we can access all
     4427                of the TOC using a 16 bit offset from tocval.  This
     4428                test assumes that the TOC comes at the end of the
     4429                output section, as it does in the default linker
     4430                script.  */
    46824431              tocend = ((*csectpp)->output_section->vma
    46834432                        + (*csectpp)->output_section->_raw_size);
     
    46864435                   inp = inp->link_next)
    46874436                {
    4688                   asection *o;
    46894437
    46904438                  for (o = inp->sections; o != NULL; o = o->next)
     
    47074455                     (unsigned long) (tocend - tocval));
    47084456                  bfd_set_error (bfd_error_file_too_big);
    4709                   return false;
     4457                  return FALSE;
    47104458                }
    47114459
     
    47234471              xcoff_data (finfo->output_bfd)->sntoc =
    47244472                (*csectpp)->output_section->target_index;
    4725               require = true;
     4473              require = TRUE;
     4474
    47264475            }
    47274476        }
     
    47304479      if (! skip
    47314480          && finfo->info->strip == strip_all)
    4732         skip = true;
     4481        skip = TRUE;
    47334482
    47344483      /* We can skip resolved external references.  */
     
    47374486          && smtyp == XTY_ER
    47384487          && (*sym_hash)->root.type != bfd_link_hash_undefined)
    4739         skip = true;
     4488        skip = TRUE;
    47404489
    47414490      /* We can skip common symbols if they got defined somewhere
    4742         else.  */
     4491        else.  */
    47434492      if (! skip
    47444493          && isym.n_sclass == C_EXT
     
    47484497          && ((*sym_hash)->root.type != bfd_link_hash_defined
    47494498              || (*sym_hash)->root.u.def.section != *csectpp))
    4750         skip = true;
     4499        skip = TRUE;
    47514500
    47524501      /* Skip local symbols if we are discarding them.  */
     
    47564505          && (isym.n_sclass != C_HIDEXT
    47574506              || smtyp != XTY_SD))
    4758         skip = true;
     4507        skip = TRUE;
    47594508
    47604509      /* If we stripping debugging symbols, and this is a debugging
    4761         symbol, then skip it.  */
     4510        symbol, then skip it.  */
    47624511      if (! skip
    47634512          && finfo->info->strip == strip_debugger
    47644513          && isym.n_scnum == N_DEBUG)
    4765         skip = true;
     4514        skip = TRUE;
    47664515
    47674516      /* If some symbols are stripped based on the name, work out the
     
    47794528
    47804529          name = _bfd_coff_internal_syment_name (input_bfd, &isym, buf);
     4530
    47814531          if (name == NULL)
    4782             return false;
     4532            return FALSE;
    47834533
    47844534          if ((finfo->info->strip == strip_some
    4785                && (bfd_hash_lookup (finfo->info->keep_hash, name, false,
    4786                                     false) == NULL))
     4535               && (bfd_hash_lookup (finfo->info->keep_hash, name, FALSE,
     4536                                    FALSE) == NULL))
    47874537              || (finfo->info->discard == discard_l
    47884538                  && (isym.n_sclass != C_EXT
     
    47904540                          || smtyp != XTY_SD))
    47914541                  && bfd_is_local_label_name (input_bfd, name)))
    4792             skip = true;
     4542            skip = TRUE;
    47934543        }
    47944544
     
    47974547          && require
    47984548          && finfo->info->strip != strip_all)
    4799         skip = false;
     4549        skip = FALSE;
    48004550
    48014551      /* We now know whether we are to skip this symbol or not.  */
     
    48194569                  name = _bfd_coff_internal_syment_name (input_bfd, &isym,
    48204570                                                         (char *) NULL);
     4571
    48214572                  if (name == NULL)
    4822                     return false;
     4573                    return FALSE;
    48234574                  indx = _bfd_stringtab_add (finfo->strtab, name, hash, copy);
    48244575                  if (indx == (bfd_size_type) -1)
    4825                     return false;
     4576                    return FALSE;
    48264577                  isym._n._n_n._n_offset = STRING_SIZE_SIZE + indx;
    48274578                }
     
    48474598            {
    48484599              if (finfo->last_file_index != -1
    4849                   && finfo->last_file.n_value != (long) output_index)
     4600                  && finfo->last_file.n_value != (bfd_vma) output_index)
    48504601                {
    48514602                  /* We must correct the value of the last C_FILE entry.  */
     
    48664617                         symbol.  We need to write it out again.  We
    48674618                         borrow *outsym temporarily.  */
     4619                      file_ptr pos;
     4620
    48684621                      bfd_coff_swap_sym_out (output_bfd,
    48694622                                             (PTR) &finfo->last_file,
    48704623                                             (PTR) outsym);
    4871                       if (bfd_seek (output_bfd,
    4872                                     (obj_sym_filepos (output_bfd)
    4873                                      + finfo->last_file_index * osymesz),
    4874                                     SEEK_SET) != 0
    4875                           || (bfd_write (outsym, osymesz, 1, output_bfd)
     4624
     4625                      pos = obj_sym_filepos (output_bfd);
     4626                      pos += finfo->last_file_index * osymesz;
     4627                      if (bfd_seek (output_bfd, pos, SEEK_SET) != 0
     4628                          || (bfd_bwrite (outsym, osymesz, output_bfd)
    48764629                              != osymesz))
    4877                         return false;
     4630                        return FALSE;
    48784631                    }
    48794632                }
     
    48844637
    48854638          /* The value of a C_BINCL or C_EINCL symbol is a file offset
    4886              into the line numbers.  We update the symbol values when
    4887              we handle the line numbers.  */
     4639             into the line numbers.  We update the symbol values when
     4640             we handle the line numbers.  */
    48884641          if (isym.n_sclass == C_BINCL
    48894642              || isym.n_sclass == C_EINCL)
     
    49124665
    49134666          /* If this is a symbol in the TOC which we may have merged
    4914              (class XMC_TC), remember the symbol index of the TOC
    4915              symbol.  */
     4667             (class XMC_TC), remember the symbol index of the TOC
     4668             symbol.  */
    49164669          if (isym.n_sclass == C_HIDEXT
    49174670              && aux.x_csect.x_smclas == XMC_TC
     
    49644717            {
    49654718              struct internal_syment isym;
    4966               unsigned long indx;
     4719
     4720              bfd_vma indx;
    49674721
    49684722              /* The value of a C_BSTAT symbol is the symbol table
    4969                 index of the containing csect.  */
     4723                index of the containing csect.  */
    49704724              bfd_coff_swap_sym_in (output_bfd, (PTR) outsym, (PTR) &isym);
    49714725              indx = isym.n_value;
     
    50124766                          strings = _bfd_coff_read_string_table (input_bfd);
    50134767                          if (strings == NULL)
    5014                             return false;
     4768                            return FALSE;
    50154769                        }
    50164770                      filename = strings + aux.x_file.x_n.x_offset;
     
    50184772                                                 hash, copy);
    50194773                      if (indx == (bfd_size_type) -1)
    5020                         return false;
     4774                        return FALSE;
    50214775                      aux.x_file.x_n.x_offset = STRING_SIZE_SIZE + indx;
    50224776                    }
     
    50264780                       && i + 1 == isymp->n_numaux)
    50274781                {
     4782
    50284783                  /* We don't support type checking.  I don't know if
    5029                      anybody does.  */
     4784                     anybody does.  */
    50304785                  aux.x_csect.x_parmhash = 0;
    50314786                  /* I don't think anybody uses these fields, but we'd
    5032                      better clobber them just in case.  */
     4787                     better clobber them just in case.  */
    50334788                  aux.x_csect.x_stab = 0;
    50344789                  aux.x_csect.x_snstab = 0;
     4790
    50354791                  if (SMTYP_SMTYP (aux.x_csect.x_smtyp) == XTY_LD)
    50364792                    {
     
    50444800                          symindx = finfo->sym_indices[indx];
    50454801                          if (symindx < 0)
    5046                             aux.x_sym.x_tagndx.l = 0;
     4802                            {
     4803                              aux.x_csect.x_scnlen.l = 0;
     4804                            }
    50474805                          else
    5048                             aux.x_sym.x_tagndx.l = symindx;
     4806                            {
     4807                              aux.x_csect.x_scnlen.l = symindx;
     4808                            }
    50494809                        }
    50504810                    }
     
    50644824                        {
    50654825                          /* We look forward through the symbol for
    5066                              the index of the next symbol we are going
    5067                              to include.  I don't know if this is
    5068                              entirely right.  */
     4826                             the index of the next symbol we are going
     4827                             to include.  I don't know if this is
     4828                             entirely right.  */
    50694829                          while (finfo->sym_indices[indx] < 0
    50704830                                 && indx < obj_raw_syment_count (input_bfd))
     
    50754835                            indx = finfo->sym_indices[indx];
    50764836                          aux.x_sym.x_fcnary.x_fcn.x_endndx.l = indx;
     4837
    50774838                        }
    50784839                    }
     
    50894850                        aux.x_sym.x_tagndx.l = symindx;
    50904851                    }
     4852
    50914853                }
    50924854
     
    51084870                      asection *enclosing;
    51094871                      unsigned int enc_count;
    5110                       bfd_size_type linoff;
     4872                      bfd_signed_vma linoff;
    51114873                      struct internal_lineno lin;
    51124874
     
    51164878                      if (oline != enclosing)
    51174879                        {
    5118                           if (bfd_seek (input_bfd,
    5119                                         enclosing->line_filepos,
    5120                                         SEEK_SET) != 0
    5121                               || (bfd_read (finfo->linenos, linesz,
    5122                                             enc_count, input_bfd)
    5123                                   != linesz * enc_count))
    5124                             return false;
     4880                          file_ptr pos = enclosing->line_filepos;
     4881                          bfd_size_type amt = linesz * enc_count;
     4882                          if (bfd_seek (input_bfd, pos, SEEK_SET) != 0
     4883                              || (bfd_bread (finfo->linenos, amt, input_bfd)
     4884                                  != amt))
     4885                            return FALSE;
    51254886                          oline = enclosing;
    51264887                        }
     
    51794940                                        aux.x_sym.x_fcnary.x_fcn.x_lnnoptr,
    51804941                                        SEEK_SET) != 0
    5181                               || (bfd_write (finfo->linenos + linoff,
    5182                                              linesz, count, output_bfd)
     4942                              || (bfd_bwrite (finfo->linenos + linoff,
     4943                                             linesz * count, output_bfd)
    51834944                                  != linesz * count))
    5184                             return false;
     4945                            return FALSE;
    51854946
    51864947                          o->output_section->lineno_count += count;
     
    51944955
    51954956                              /* Update any C_BINCL or C_EINCL symbols
    5196                                 that refer to a line number in the
    5197                                 range we just output.  */
     4957                                that refer to a line number in the
     4958                                range we just output.  */
    51984959                              iisp = finfo->internal_syms;
    51994960                              iispend = (iisp
     
    52074968                                          || iisp->n_sclass == C_EINCL)
    52084969                                      && ((bfd_size_type) iisp->n_value
    5209                                           >= enclosing->line_filepos + linoff)
     4970                                          >= (bfd_size_type)(enclosing->line_filepos + linoff))
    52104971                                      && ((bfd_size_type) iisp->n_value
    52114972                                          < (enclosing->line_filepos
     
    52695030  if (outsym > finfo->outsyms)
    52705031    {
    5271       if (bfd_seek (output_bfd,
    5272                     obj_sym_filepos (output_bfd) + syment_base * osymesz,
    5273                     SEEK_SET) != 0
    5274           || (bfd_write (finfo->outsyms, outsym - finfo->outsyms, 1,
    5275                         output_bfd)
    5276               != (bfd_size_type) (outsym - finfo->outsyms)))
    5277         return false;
     5032      file_ptr pos = obj_sym_filepos (output_bfd) + syment_base * osymesz;
     5033      bfd_size_type amt = outsym - finfo->outsyms;
     5034      if (bfd_seek (output_bfd, pos, SEEK_SET) != 0
     5035          || bfd_bwrite (finfo->outsyms, amt, output_bfd) != amt)
     5036        return FALSE;
    52785037
    52795038      BFD_ASSERT ((obj_raw_syment_count (output_bfd)
     
    52865045  /* Don't let the linker relocation routines discard the symbols.  */
    52875046  keep_syms = obj_coff_keep_syms (input_bfd);
    5288   obj_coff_keep_syms (input_bfd) = true;
     5047  obj_coff_keep_syms (input_bfd) = TRUE;
    52895048
    52905049  /* Relocate the contents of each section.  */
    52915050  for (o = input_bfd->sections; o != NULL; o = o->next)
    52925051    {
     5052
    52935053      bfd_byte *contents;
    52945054
     
    53055065
    53065066      /* We have set filepos correctly for the sections we created to
    5307         represent csects, so bfd_get_section_contents should work.  */
     5067        represent csects, so bfd_get_section_contents should work.  */
    53085068      if (coff_section_data (input_bfd, o) != NULL
    53095069          && coff_section_data (input_bfd, o)->contents != NULL)
    53105070        contents = coff_section_data (input_bfd, o)->contents;
    5311       else
    5312         {
    5313           if (! bfd_get_section_contents (input_bfd, o, finfo->contents,
    5314                                           (file_ptr) 0, o->_raw_size))
    5315             return false;
    5316           contents = finfo->contents;
    5317         }
     5071      else {
     5072        if (! bfd_get_section_contents (input_bfd, o, finfo->contents,
     5073                                        (file_ptr) 0, o->_raw_size))
     5074          return FALSE;
     5075        contents = finfo->contents;
     5076      }
    53185077
    53195078      if ((o->flags & SEC_RELOC) != 0)
     
    53305089          target_index = o->output_section->target_index;
    53315090          internal_relocs = (xcoff_read_internal_relocs
    5332                              (input_bfd, o, false, finfo->external_relocs,
    5333                               true,
     5091                             (input_bfd, o, FALSE, finfo->external_relocs,
     5092                              TRUE,
    53345093                              (finfo->section_info[target_index].relocs
    53355094                               + o->output_section->reloc_count)));
    53365095          if (internal_relocs == NULL)
    5337             return false;
     5096            return FALSE;
    53385097
    53395098          /* Call processor specific code to relocate the section
    5340              contents.  */
     5099             contents.  */
    53415100          if (! bfd_coff_relocate_section (output_bfd, finfo->info,
    53425101                                           input_bfd, o,
     
    53455104                                           finfo->internal_syms,
    53465105                                           xcoff_data (input_bfd)->csects))
    5347             return false;
     5106            return FALSE;
    53485107
    53495108          offset = o->output_section->vma + o->output_offset - o->vma;
     
    53565115              struct xcoff_link_hash_entry *h = NULL;
    53575116              struct internal_ldrel ldrel;
    5358               boolean quiet;
     5117              bfd_boolean quiet;
    53595118
    53605119              *rel_hash = NULL;
     
    53825141                    {
    53835142                      /* This is a TOC relative reloc with a symbol
    5384                         attached.  The symbol should be the one which
    5385                         this reloc is for.  We want to make this
    5386                         reloc against the TOC address of the symbol,
    5387                         not the symbol itself.  */
     5143                        attached.  The symbol should be the one which
     5144                        this reloc is for.  We want to make this
     5145                        reloc against the TOC address of the symbol,
     5146                        not the symbol itself.  */
    53885147                      BFD_ASSERT (h->toc_section != NULL);
    53895148                      BFD_ASSERT ((h->flags & XCOFF_SET_TOC) == 0);
     
    53945153                          struct xcoff_toc_rel_hash *n;
    53955154                          struct xcoff_link_section_info *si;
    5396 
     5155                          bfd_size_type amt;
     5156
     5157                          amt = sizeof (struct xcoff_toc_rel_hash);
    53975158                          n = ((struct xcoff_toc_rel_hash *)
    5398                                bfd_alloc (finfo->output_bfd,
    5399                                           sizeof (struct xcoff_toc_rel_hash)));
     5159                               bfd_alloc (finfo->output_bfd, amt));
    54005160                          if (n == NULL)
    5401                             return false;
     5161                            return FALSE;
    54025162                          si = finfo->section_info + target_index;
    54035163                          n->next = si->toc_rel_hashes;
     
    54645224                      else
    54655225                        {
     5226
    54665227                          struct internal_syment *is;
     5228
    54675229                          const char *name;
    54685230                          char buf[SYMNMLEN + 1];
     
    54755237                          name = (_bfd_coff_internal_syment_name
    54765238                                  (input_bfd, is, buf));
     5239
    54775240                          if (name == NULL)
    5478                             return false;
     5241                            return FALSE;
    54795242
    54805243                          if (! ((*finfo->info->callbacks->unattached_reloc)
    54815244                                 (finfo->info, name, input_bfd, o,
    54825245                                  irel->r_vaddr)))
    5483                             return false;
     5246                            return FALSE;
    54845247                        }
    54855248                    }
    54865249                }
    54875250
    5488               quiet = false;
     5251              quiet = FALSE;
    54895252              switch (irel->r_type)
    54905253                {
     
    55045267                  ldrel.l_vaddr = irel->r_vaddr;
    55055268                  if (r_symndx == -1)
    5506                     ldrel.l_symndx = -1;
     5269                    ldrel.l_symndx = -(bfd_size_type ) 1;
    55075270                  else if (h == NULL
    55085271                           || (h->root.type == bfd_link_hash_defined
     
    55305293                          (*_bfd_error_handler)
    55315294                            (_("%s: loader reloc in unrecognized section `%s'"),
    5532                              bfd_get_filename (input_bfd),
     5295                             bfd_archive_filename (input_bfd),
    55335296                             sec->name);
    55345297                          bfd_set_error (bfd_error_nonrepresentable_section);
    5535                           return false;
     5298                          return FALSE;
    55365299                        }
    55375300                    }
     
    55465309                             _bfd_ppc_xcoff_relocate_section.  Don't
    55475310                             issue any more warnings.  */
    5548                           quiet = true;
     5311                          quiet = TRUE;
    55495312                        }
    55505313                      if (h->ldindx < 0 && ! quiet)
     
    55525315                          (*_bfd_error_handler)
    55535316                            (_("%s: `%s' in loader reloc but not loader sym"),
    5554                              bfd_get_filename (input_bfd),
     5317                             bfd_archive_filename (input_bfd),
    55555318                             h->root.root.string);
    55565319                          bfd_set_error (bfd_error_bad_value);
    5557                           return false;
     5320                          return FALSE;
    55585321                        }
    55595322                      ldrel.l_symndx = h->ldindx;
     
    55675330                      (*_bfd_error_handler)
    55685331                        (_("%s: loader reloc in read-only section %s"),
    5569                          bfd_get_filename (input_bfd),
     5332                         bfd_archive_filename (input_bfd),
    55705333                         bfd_get_section_name (finfo->output_bfd,
    55715334                                               o->output_section));
    55725335                      bfd_set_error (bfd_error_invalid_operation);
    5573                       return false;
     5336                      return FALSE;
    55745337                    }
    5575                   xcoff_swap_ldrel_out (output_bfd, &ldrel,
    5576                                         finfo->ldrel);
    5577                   BFD_ASSERT (sizeof (struct external_ldrel) == LDRELSZ);
    5578                   ++finfo->ldrel;
     5338                  bfd_xcoff_swap_ldrel_out (output_bfd, &ldrel,
     5339                                            finfo->ldrel);
     5340
     5341                  finfo->ldrel += bfd_xcoff_ldrelsz(output_bfd);
    55795342                  break;
    55805343
     
    55955358      /* Write out the modified section contents.  */
    55965359      if (! bfd_set_section_contents (output_bfd, o->output_section,
    5597                                       contents, o->output_offset,
     5360                                      contents, (file_ptr) o->output_offset,
    55985361                                      (o->_cooked_size != 0
    55995362                                       ? o->_cooked_size
    56005363                                       : o->_raw_size)))
    5601         return false;
     5364        return FALSE;
    56025365    }
    56035366
     
    56075370    {
    56085371      if (! _bfd_coff_free_symbols (input_bfd))
    5609         return false;
    5610     }
    5611 
    5612   return true;
     5372        return FALSE;
     5373    }
     5374
     5375  return TRUE;
    56135376}
    56145377
     
    56185381/* Write out a non-XCOFF global symbol.  */
    56195382
    5620 static boolean
    5621 xcoff_write_global_symbol (h, p)
     5383
     5384static bfd_boolean
     5385xcoff_write_global_symbol (h, inf)
    56225386     struct xcoff_link_hash_entry *h;
    5623      PTR p;
     5387     PTR inf;
    56245388{
    5625   struct xcoff_final_link_info *finfo = (struct xcoff_final_link_info *) p;
     5389  struct xcoff_final_link_info *finfo = (struct xcoff_final_link_info *) inf;
    56265390  bfd *output_bfd;
    56275391  bfd_byte *outsym;
    56285392  struct internal_syment isym;
    56295393  union internal_auxent aux;
     5394  bfd_boolean result;
     5395  file_ptr pos;
     5396  bfd_size_type amt;
    56305397
    56315398  output_bfd = finfo->output_bfd;
    56325399  outsym = finfo->outsyms;
     5400
     5401  if (h->root.type == bfd_link_hash_warning)
     5402    {
     5403      h = (struct xcoff_link_hash_entry *) h->root.u.i.link;
     5404      if (h->root.type == bfd_link_hash_new)
     5405        return TRUE;
     5406    }
    56335407
    56345408  /* If this symbol was garbage collected, just skip it.  */
    56355409  if (xcoff_hash_table (finfo->info)->gc
    56365410      && (h->flags & XCOFF_MARK) == 0)
    5637     return true;
     5411    return TRUE;
    56385412
    56395413  /* If we need a .loader section entry, write it out.  */
     
    56485422          || h->root.type == bfd_link_hash_undefweak)
    56495423        {
     5424
    56505425          ldsym->l_value = 0;
    56515426          ldsym->l_scnum = N_UNDEF;
    56525427          ldsym->l_smtype = XTY_ER;
    56535428          impbfd = h->root.u.undef.abfd;
     5429
    56545430        }
    56555431      else if (h->root.type == bfd_link_hash_defined
    56565432               || h->root.type == bfd_link_hash_defweak)
    56575433        {
     5434
    56585435          asection *sec;
    56595436
     
    56655442          ldsym->l_smtype = XTY_SD;
    56665443          impbfd = sec->owner;
     5444
    56675445        }
    56685446      else
     
    56725450           && (h->flags & XCOFF_DEF_DYNAMIC) != 0)
    56735451          || (h->flags & XCOFF_IMPORT) != 0)
    5674         ldsym->l_smtype |= L_IMPORT;
     5452        {
     5453          /* Clear l_smtype
     5454             Import symbols are defined so the check above will make
     5455             the l_smtype XTY_SD.  But this is not correct, it should
     5456             be cleared.  */
     5457          ldsym->l_smtype |= L_IMPORT;
     5458        }
     5459
    56755460      if (((h->flags & XCOFF_DEF_REGULAR) != 0
    56765461           && (h->flags & XCOFF_DEF_DYNAMIC) != 0)
    56775462          || (h->flags & XCOFF_EXPORT) != 0)
    5678         ldsym->l_smtype |= L_EXPORT;
     5463        {
     5464          ldsym->l_smtype |= L_EXPORT;
     5465        }
     5466
    56795467      if ((h->flags & XCOFF_ENTRY) != 0)
    5680         ldsym->l_smtype |= L_ENTRY;
     5468        {
     5469          ldsym->l_smtype |= L_ENTRY;
     5470        }
     5471
     5472      if ((h->flags & XCOFF_RTINIT) != 0)
     5473        {
     5474          ldsym->l_smtype = XTY_SD;
     5475        }
    56815476
    56825477      ldsym->l_smclas = h->smclas;
    56835478
    5684       if (ldsym->l_ifile == (bfd_size_type) -1)
    5685         ldsym->l_ifile = 0;
     5479      if (ldsym->l_smtype & L_IMPORT)
     5480        {
     5481          if ((h->root.type == bfd_link_hash_defined
     5482               || h->root.type == bfd_link_hash_defweak)
     5483              && (h->root.u.def.value != 0))
     5484            {
     5485              ldsym->l_smclas = XMC_XO;
     5486            }
     5487          else if ((h->flags & (XCOFF_SYSCALL32 | XCOFF_SYSCALL64)) ==
     5488                   (XCOFF_SYSCALL32 | XCOFF_SYSCALL64))
     5489            {
     5490              ldsym->l_smclas = XMC_SV3264;
     5491            }
     5492          else if (h->flags & XCOFF_SYSCALL32)
     5493            {
     5494              ldsym->l_smclas = XMC_SV;
     5495            }
     5496          else if (h->flags & XCOFF_SYSCALL64)
     5497            {
     5498              ldsym->l_smclas = XMC_SV64;
     5499            }
     5500        }
     5501
     5502      if (ldsym->l_ifile == -(bfd_size_type) 1)
     5503        {
     5504          ldsym->l_ifile = 0;
     5505        }
    56865506      else if (ldsym->l_ifile == 0)
    56875507        {
    56885508          if ((ldsym->l_smtype & L_IMPORT) == 0)
    5689             ldsym->l_ifile = 0;
     5509            {
     5510              ldsym->l_ifile = 0;
     5511            }
    56905512          else if (impbfd == NULL)
    5691             ldsym->l_ifile = 0;
     5513            {
     5514              ldsym->l_ifile = 0;
     5515            }
    56925516          else
    56935517            {
     
    57005524
    57015525      BFD_ASSERT (h->ldindx >= 0);
    5702       BFD_ASSERT (LDSYMSZ == sizeof (struct external_ldsym));
    5703       xcoff_swap_ldsym_out (output_bfd, ldsym, finfo->ldsym + h->ldindx - 3);
     5526
     5527      bfd_xcoff_swap_ldsym_out (output_bfd, ldsym,
     5528                                (finfo->ldsym +
     5529                                 (h->ldindx - 3)
     5530                                 * bfd_xcoff_ldsymsz(finfo->output_bfd)));
    57045531      h->ldsym = NULL;
    57055532    }
     
    57175544
    57185545      /* The first instruction in the global linkage code loads a
    5719         specific TOC element.  */
     5546        specific TOC element.  */
    57205547      tocoff = (h->descriptor->toc_section->output_section->vma
    57215548                + h->descriptor->toc_section->output_offset
    57225549                - xcoff_data (output_bfd)->toc);
     5550
    57235551      if ((h->descriptor->flags & XCOFF_SET_TOC) != 0)
    5724         tocoff += h->descriptor->u.toc_offset;
    5725       bfd_put_32 (output_bfd, XCOFF_GLINK_FIRST | (tocoff & 0xffff), p);
    5726       for (i = 0, p += 4;
    5727            i < sizeof xcoff_glink_code / sizeof xcoff_glink_code[0];
    5728            i++, p += 4)
    5729         bfd_put_32 (output_bfd, xcoff_glink_code[i], p);
     5552        {
     5553          tocoff += h->descriptor->u.toc_offset;
     5554        }
     5555
     5556
     5557      /* The first instruction in the glink code needs to be
     5558         cooked to to hold the correct offset in the toc.  The
     5559         rest are just output raw.  */
     5560      bfd_put_32 (output_bfd,
     5561                  bfd_xcoff_glink_code(output_bfd, 0) | (tocoff & 0xffff), p);
     5562
     5563      /* Start with i == 1 to get past the first instruction done above
     5564         The /4 is because the glink code is in bytes and we are going
     5565         4 at a pop.  */
     5566      for (i = 1; i < bfd_xcoff_glink_code_size(output_bfd) / 4; i++)
     5567        {
     5568          bfd_put_32 (output_bfd,
     5569                      (bfd_vma) bfd_xcoff_glink_code(output_bfd, i),
     5570                      &p[4 * i]);
     5571        }
    57305572    }
    57315573
     
    57495591                       + tocsec->output_offset
    57505592                       + h->u.toc_offset);
     5593
     5594
    57515595      if (h->indx >= 0)
    5752         irel->r_symndx = h->indx;
     5596        {
     5597          irel->r_symndx = h->indx;
     5598        }
    57535599      else
    57545600        {
     
    57565602          irel->r_symndx = obj_raw_syment_count (output_bfd);
    57575603        }
     5604
     5605      BFD_ASSERT (h->ldindx >= 0);
     5606
     5607      /* Initialize the aux union here instead of closer to when it is
     5608         written out below because the length of the csect depends on
     5609         whether the output is 32 or 64 bit.  */
     5610      memset (&iraux, 0, sizeof iraux);
     5611      iraux.x_csect.x_smtyp = XTY_SD;
     5612      /* iraux.x_csect.x_scnlen.l = 4 or 8, see below */
     5613      iraux.x_csect.x_smclas = XMC_TC;
     5614
     5615      /* 32 bit uses a 32 bit R_POS to do the relocations
     5616         64 bit uses a 64 bit R_POS to do the relocations
     5617
     5618         Also needs to change the csect size : 4 for 32 bit, 8 for 64 bit
     5619
     5620         Which one is determined by the backend.  */
     5621      if (bfd_xcoff_is_xcoff64 (output_bfd))
     5622        {
     5623          irel->r_size = 63;
     5624          iraux.x_csect.x_scnlen.l = 8;
     5625        }
     5626      else if (bfd_xcoff_is_xcoff32 (output_bfd))
     5627        {
     5628          irel->r_size = 31;
     5629          iraux.x_csect.x_scnlen.l = 4;
     5630        }
     5631      else
     5632        {
     5633          return FALSE;
     5634        }
    57585635      irel->r_type = R_POS;
    5759       irel->r_size = 31;
    57605636      finfo->section_info[oindx].rel_hashes[osec->reloc_count] = NULL;
    57615637      ++osec->reloc_count;
    57625638
    5763       BFD_ASSERT (h->ldindx >= 0);
    57645639      ldrel.l_vaddr = irel->r_vaddr;
    57655640      ldrel.l_symndx = h->ldindx;
    5766       ldrel.l_rtype = (31 << 8) | R_POS;
     5641      ldrel.l_rtype = (irel->r_size << 8) | R_POS;
    57675642      ldrel.l_rsecnm = oindx;
    5768       xcoff_swap_ldrel_out (output_bfd, &ldrel, finfo->ldrel);
    5769       ++finfo->ldrel;
    5770 
    5771       /* We need to emit a symbol to define a csect which holds the
    5772         reloc.  */
     5643      bfd_xcoff_swap_ldrel_out (output_bfd, &ldrel, finfo->ldrel);
     5644      finfo->ldrel += bfd_xcoff_ldrelsz(output_bfd);
     5645
     5646      /* We need to emit a symbol to define a csect which holds
     5647         the reloc.  */
    57735648      if (finfo->info->strip != strip_all)
    57745649        {
    5775           if (strlen (h->root.root.string) <= SYMNMLEN)
    5776             strncpy (irsym._n._n_name, h->root.root.string, SYMNMLEN);
    5777           else
    5778             {
    5779               boolean hash;
    5780               bfd_size_type indx;
    5781 
    5782               hash = true;
    5783               if ((output_bfd->flags & BFD_TRADITIONAL_FORMAT) != 0)
    5784                 hash = false;
    5785               indx = _bfd_stringtab_add (finfo->strtab, h->root.root.string,
    5786                                          hash, false);
    5787               if (indx == (bfd_size_type) -1)
    5788                 return false;
    5789               irsym._n._n_n._n_zeroes = 0;
    5790               irsym._n._n_n._n_offset = STRING_SIZE_SIZE + indx;
    5791             }
     5650
     5651          result = bfd_xcoff_put_symbol_name (output_bfd, finfo->strtab,
     5652                                              &irsym, h->root.root.string);
     5653          if (!result)
     5654            return FALSE;
    57925655
    57935656          irsym.n_value = irel->r_vaddr;
     
    58005663          outsym += bfd_coff_symesz (output_bfd);
    58015664
    5802           memset (&iraux, 0, sizeof iraux);
    5803           iraux.x_csect.x_smtyp = XTY_SD;
    5804           iraux.x_csect.x_scnlen.l = 4;
    5805           iraux.x_csect.x_smclas = XMC_TC;
    5806 
     5665          /* note : iraux is initialized above */
    58075666          bfd_coff_swap_aux_out (output_bfd, (PTR) &iraux, T_NULL, C_HIDEXT,
    58085667                                 0, 1, (PTR) outsym);
     
    58135672              /* We aren't going to write out the symbols below, so we
    58145673                 need to write them out now.  */
    5815               if (bfd_seek (output_bfd,
    5816                             (obj_sym_filepos (output_bfd)
    5817                              + (obj_raw_syment_count (output_bfd)
    5818                                 * bfd_coff_symesz (output_bfd))),
    5819                             SEEK_SET) != 0
    5820                   || (bfd_write (finfo->outsyms, outsym - finfo->outsyms, 1,
    5821                                  output_bfd)
    5822                       != (bfd_size_type) (outsym - finfo->outsyms)))
    5823                 return false;
     5674              pos = obj_sym_filepos (output_bfd);
     5675              pos += (obj_raw_syment_count (output_bfd)
     5676                      * bfd_coff_symesz (output_bfd));
     5677              amt = outsym - finfo->outsyms;
     5678              if (bfd_seek (output_bfd, pos, SEEK_SET) != 0
     5679                  || bfd_bwrite (finfo->outsyms, amt, output_bfd) != amt)
     5680                return FALSE;
    58245681              obj_raw_syment_count (output_bfd) +=
    58255682                (outsym - finfo->outsyms) / bfd_coff_symesz (output_bfd);
     
    58335690     it out.  The first word is the address of the function code
    58345691     itself, the second word is the address of the TOC, and the third
    5835      word is zero.  */
     5692     word is zero.
     5693
     5694     32 bit vs 64 bit
     5695     The addresses for the 32 bit will take 4 bytes and the addresses
     5696     for 64 bit will take 8 bytes.  Similar for the relocs.  This type
     5697     of logic was also done above to create a TOC entry in
     5698     xcoff_write_global_symbol.  */
    58365699  if ((h->flags & XCOFF_DESCRIPTOR) != 0
    58375700      && h->root.type == bfd_link_hash_defined
     
    58485711      struct internal_ldrel ldrel;
    58495712      asection *tsec;
     5713      unsigned int reloc_size, byte_size;
     5714
     5715      if (bfd_xcoff_is_xcoff64 (output_bfd))
     5716        {
     5717          reloc_size = 63;
     5718          byte_size = 8;
     5719        }
     5720      else if (bfd_xcoff_is_xcoff32 (output_bfd))
     5721        {
     5722          reloc_size = 31;
     5723          byte_size = 4;
     5724        }
     5725      else
     5726        {
     5727          return FALSE;
     5728        }
    58505729
    58515730      sec = h->root.u.def.section;
     
    58595738                      || hentry->root.type == bfd_link_hash_defweak));
    58605739      esec = hentry->root.u.def.section;
    5861       bfd_put_32 (output_bfd,
    5862                   (esec->output_section->vma
    5863                    + esec->output_offset
    5864                    + hentry->root.u.def.value),
    5865                   p);
    58665740
    58675741      irel = finfo->section_info[oindx].relocs + osec->reloc_count;
     
    58715745      irel->r_symndx = esec->output_section->target_index;
    58725746      irel->r_type = R_POS;
    5873       irel->r_size = 31;
     5747      irel->r_size = reloc_size;
    58745748      finfo->section_info[oindx].rel_hashes[osec->reloc_count] = NULL;
    58755749      ++osec->reloc_count;
     
    58895763             esec->output_section->name);
    58905764          bfd_set_error (bfd_error_nonrepresentable_section);
    5891           return false;
    5892         }
    5893       ldrel.l_rtype = (31 << 8) | R_POS;
     5765          return FALSE;
     5766        }
     5767      ldrel.l_rtype = (reloc_size << 8) | R_POS;
    58945768      ldrel.l_rsecnm = oindx;
    5895       xcoff_swap_ldrel_out (output_bfd, &ldrel, finfo->ldrel);
    5896       ++finfo->ldrel;
    5897 
    5898       bfd_put_32 (output_bfd, xcoff_data (output_bfd)->toc, p + 4);
     5769      bfd_xcoff_swap_ldrel_out (output_bfd, &ldrel, finfo->ldrel);
     5770      finfo->ldrel += bfd_xcoff_ldrelsz(output_bfd);
     5771
     5772      /* There are three items to write out,
     5773         the address of the code
     5774         the address of the toc anchor
     5775         the environment pointer.
     5776         We are ignoring the environment pointer.  So set it to zero.  */
     5777      if (bfd_xcoff_is_xcoff64 (output_bfd))
     5778        {
     5779          bfd_put_64 (output_bfd,
     5780                      (esec->output_section->vma + esec->output_offset
     5781                       + hentry->root.u.def.value),
     5782                      p);
     5783          bfd_put_64 (output_bfd, xcoff_data (output_bfd)->toc, p + 8);
     5784          bfd_put_64 (output_bfd, (bfd_vma) 0, p + 16);
     5785        }
     5786      else
     5787        {
     5788          /* 32 bit backend
     5789             This logic was already called above so the error case where
     5790             the backend is neither has already been checked.  */
     5791          bfd_put_32 (output_bfd,
     5792                      (esec->output_section->vma + esec->output_offset
     5793                       + hentry->root.u.def.value),
     5794                      p);
     5795          bfd_put_32 (output_bfd, xcoff_data (output_bfd)->toc, p + 4);
     5796          bfd_put_32 (output_bfd, (bfd_vma) 0, p + 8);
     5797        }
    58995798
    59005799      tsec = coff_section_from_bfd_index (output_bfd,
     
    59055804                       + sec->output_offset
    59065805                       + h->root.u.def.value
    5907                        + 4);
     5806                       + byte_size);
    59085807      irel->r_symndx = tsec->output_section->target_index;
    59095808      irel->r_type = R_POS;
    5910       irel->r_size = 31;
     5809      irel->r_size = reloc_size;
    59115810      finfo->section_info[oindx].rel_hashes[osec->reloc_count] = NULL;
    59125811      ++osec->reloc_count;
     
    59265825             tsec->output_section->name);
    59275826          bfd_set_error (bfd_error_nonrepresentable_section);
    5928           return false;
    5929         }
    5930       ldrel.l_rtype = (31 << 8) | R_POS;
     5827          return FALSE;
     5828        }
     5829      ldrel.l_rtype = (reloc_size << 8) | R_POS;
    59315830      ldrel.l_rsecnm = oindx;
    5932       xcoff_swap_ldrel_out (output_bfd, &ldrel, finfo->ldrel);
    5933       ++finfo->ldrel;
     5831      bfd_xcoff_swap_ldrel_out (output_bfd, &ldrel, finfo->ldrel);
     5832      finfo->ldrel += bfd_xcoff_ldrelsz(output_bfd);
    59345833    }
    59355834
     
    59375836    {
    59385837      BFD_ASSERT (outsym == finfo->outsyms);
    5939       return true;
     5838      return TRUE;
    59405839    }
    59415840
     
    59435842      && (finfo->info->strip == strip_all
    59445843          || (finfo->info->strip == strip_some
    5945               && (bfd_hash_lookup (finfo->info->keep_hash,
    5946                                    h->root.root.string, false, false)
    5947                   == NULL))))
     5844              && bfd_hash_lookup (finfo->info->keep_hash, h->root.root.string,
     5845                                  FALSE, FALSE) == NULL)))
    59485846    {
    59495847      BFD_ASSERT (outsym == finfo->outsyms);
    5950       return true;
     5848      return TRUE;
    59515849    }
    59525850
     
    59555853    {
    59565854      BFD_ASSERT (outsym == finfo->outsyms);
    5957       return true;
     5855      return TRUE;
    59585856    }
    59595857
     
    59625860  h->indx = obj_raw_syment_count (output_bfd);
    59635861
    5964   if (strlen (h->root.root.string) <= SYMNMLEN)
    5965     strncpy (isym._n._n_name, h->root.root.string, SYMNMLEN);
    5966   else
    5967     {
    5968       boolean hash;
    5969       bfd_size_type indx;
    5970 
    5971       hash = true;
    5972       if ((output_bfd->flags & BFD_TRADITIONAL_FORMAT) != 0)
    5973         hash = false;
    5974       indx = _bfd_stringtab_add (finfo->strtab, h->root.root.string, hash,
    5975                                  false);
    5976       if (indx == (bfd_size_type) -1)
    5977         return false;
    5978       isym._n._n_n._n_zeroes = 0;
    5979       isym._n._n_n._n_offset = STRING_SIZE_SIZE + indx;
    5980     }
     5862  result = bfd_xcoff_put_symbol_name (output_bfd, finfo->strtab, &isym,
     5863                                      h->root.root.string);
     5864  if (!result)
     5865    return FALSE;
    59815866
    59825867  if (h->root.type == bfd_link_hash_undefined
     
    60065891                      + h->root.u.def.section->output_offset
    60075892                      + h->root.u.def.value);
    6008       isym.n_scnum = h->root.u.def.section->output_section->target_index;
     5893      if (bfd_is_abs_section (h->root.u.def.section->output_section))
     5894        isym.n_scnum = N_ABS;
     5895      else
     5896        isym.n_scnum = h->root.u.def.section->output_section->target_index;
    60095897      isym.n_sclass = C_HIDEXT;
    60105898      aux.x_csect.x_smtyp = XTY_SD;
     
    60435931
    60445932  aux.x_csect.x_smclas = h->smclas;
    6045 
    60465933  bfd_coff_swap_aux_out (output_bfd, (PTR) &aux, T_NULL, isym.n_sclass, 0, 1,
    60475934                         (PTR) outsym);
     
    60625949      aux.x_csect.x_smtyp = XTY_LD;
    60635950      aux.x_csect.x_scnlen.l = obj_raw_syment_count (output_bfd);
    6064 
    60655951      bfd_coff_swap_aux_out (output_bfd, (PTR) &aux, T_NULL, C_EXT, 0, 1,
    60665952                             (PTR) outsym);
     
    60685954    }
    60695955
    6070   if (bfd_seek (output_bfd,
    6071                 (obj_sym_filepos (output_bfd)
    6072                  + (obj_raw_syment_count (output_bfd)
    6073                     * bfd_coff_symesz (output_bfd))),
    6074                 SEEK_SET) != 0
    6075       || (bfd_write (finfo->outsyms, outsym - finfo->outsyms, 1, output_bfd)
    6076           != (bfd_size_type) (outsym - finfo->outsyms)))
    6077     return false;
     5956  pos = obj_sym_filepos (output_bfd);
     5957  pos += obj_raw_syment_count (output_bfd) * bfd_coff_symesz (output_bfd);
     5958  amt = outsym - finfo->outsyms;
     5959  if (bfd_seek (output_bfd, pos, SEEK_SET) != 0
     5960      || bfd_bwrite (finfo->outsyms, amt, output_bfd) != amt)
     5961    return FALSE;
    60785962  obj_raw_syment_count (output_bfd) +=
    60795963    (outsym - finfo->outsyms) / bfd_coff_symesz (output_bfd);
    60805964
    6081   return true;
     5965  return TRUE;
    60825966}
    60835967
    60845968/* Handle a link order which is supposed to generate a reloc.  */
    60855969
    6086 static boolean
     5970static bfd_boolean
    60875971xcoff_reloc_link_order (output_bfd, finfo, output_section, link_order)
    60885972     bfd *output_bfd;
     
    61035987    {
    61045988      /* We need to somehow locate a symbol in the right section.  The
    6105         symbol must either have a value of zero, or we must adjust
    6106         the addend by the value of the symbol.  FIXME: Write this
    6107         when we need it.  The old linker couldn't handle this anyhow.  */
     5989        symbol must either have a value of zero, or we must adjust
     5990        the addend by the value of the symbol.  FIXME: Write this
     5991        when we need it.  The old linker couldn't handle this anyhow.  */
    61085992      abort ();
    61095993    }
     
    61135997    {
    61145998      bfd_set_error (bfd_error_bad_value);
    6115       return false;
     5999      return FALSE;
    61166000    }
    61176001
     
    61196003       bfd_wrapped_link_hash_lookup (output_bfd, finfo->info,
    61206004                                     link_order->u.reloc.p->u.name,
    6121                                      false, false, true));
     6005                                     FALSE, FALSE, TRUE));
    61226006  if (h == NULL)
    61236007    {
     
    61256009             (finfo->info, link_order->u.reloc.p->u.name, (bfd *) NULL,
    61266010              (asection *) NULL, (bfd_vma) 0)))
    6127         return false;
    6128       return true;
     6011        return FALSE;
     6012      return TRUE;
    61296013    }
    61306014
     
    61576041      bfd_byte *buf;
    61586042      bfd_reloc_status_type rstat;
    6159       boolean ok;
     6043      bfd_boolean ok;
    61606044
    61616045      size = bfd_get_reloc_size (howto);
    61626046      buf = (bfd_byte *) bfd_zmalloc (size);
    61636047      if (buf == NULL)
    6164         return false;
     6048        return FALSE;
    61656049
    61666050      rstat = _bfd_relocate_contents (howto, output_bfd, addend, buf);
     
    61796063            {
    61806064              free (buf);
    6181               return false;
     6065              return FALSE;
    61826066            }
    61836067          break;
     
    61876071      free (buf);
    61886072      if (! ok)
    6189         return false;
     6073        return FALSE;
    61906074    }
    61916075
     
    62426126             bfd_get_filename (output_bfd), secname);
    62436127          bfd_set_error (bfd_error_nonrepresentable_section);
    6244           return false;
     6128          return FALSE;
    62456129        }
    62466130    }
     
    62546138             h->root.root.string);
    62556139          bfd_set_error (bfd_error_bad_value);
    6256           return false;
     6140          return FALSE;
    62576141        }
    62586142      ldrel.l_symndx = h->ldindx;
     
    62616145  ldrel.l_rtype = (irel->r_size << 8) | irel->r_type;
    62626146  ldrel.l_rsecnm = output_section->target_index;
    6263   xcoff_swap_ldrel_out (output_bfd, &ldrel, finfo->ldrel);
    6264   ++finfo->ldrel;
    6265 
    6266   return true;
     6147  bfd_xcoff_swap_ldrel_out (output_bfd, &ldrel, finfo->ldrel);
     6148  finfo->ldrel += bfd_xcoff_ldrelsz(output_bfd);
     6149
     6150  return TRUE;
    62676151}
    62686152
     
    62856169}
    62866170
    6287 /* This is the relocation function for the RS/6000/POWER/PowerPC.
    6288    This is currently the only processor which uses XCOFF; I hope that
    6289    will never change.  */
    6290 
    6291 boolean
    6292 _bfd_ppc_xcoff_relocate_section (output_bfd, info, input_bfd,
    6293                                  input_section, contents, relocs, syms,
    6294                                  sections)
    6295      bfd *output_bfd;
    6296      struct bfd_link_info *info;
    6297      bfd *input_bfd;
    6298      asection *input_section;
    6299      bfd_byte *contents;
    6300      struct internal_reloc *relocs;
    6301      struct internal_syment *syms;
    6302      asection **sections;
    6303 {
    6304   struct internal_reloc *rel;
    6305   struct internal_reloc *relend;
    6306 
    6307   rel = relocs;
    6308   relend = rel + input_section->reloc_count;
    6309   for (; rel < relend; rel++)
    6310     {
    6311       long symndx;
    6312       struct xcoff_link_hash_entry *h;
    6313       struct internal_syment *sym;
    6314       bfd_vma addend;
    6315       bfd_vma val;
    6316       struct reloc_howto_struct howto;
    6317       bfd_reloc_status_type rstat;
    6318 
    6319       /* Relocation type R_REF is a special relocation type which is
    6320          merely used to prevent garbage collection from occurring for
    6321          the csect including the symbol which it references.  */
    6322       if (rel->r_type == R_REF)
    6323         continue;
    6324 
    6325       symndx = rel->r_symndx;
    6326 
    6327       if (symndx == -1)
    6328         {
    6329           h = NULL;
    6330           sym = NULL;
    6331           addend = 0;
    6332         }
    6333       else
    6334         {
    6335           h = obj_xcoff_sym_hashes (input_bfd)[symndx];
    6336           sym = syms + symndx;
    6337           addend = - sym->n_value;
    6338         }
    6339 
    6340       /* We build the howto information on the fly.  */
    6341 
    6342       howto.type = rel->r_type;
    6343       howto.rightshift = 0;
    6344       howto.size = 2;
    6345       howto.bitsize = (rel->r_size & 0x1f) + 1;
    6346       howto.pc_relative = false;
    6347       howto.bitpos = 0;
    6348       if ((rel->r_size & 0x80) != 0)
    6349         howto.complain_on_overflow = complain_overflow_signed;
    6350       else
    6351         howto.complain_on_overflow = complain_overflow_bitfield;
    6352       howto.special_function = NULL;
    6353       howto.name = "internal";
    6354       howto.partial_inplace = true;
    6355       if (howto.bitsize == 32)
    6356         howto.src_mask = howto.dst_mask = 0xffffffff;
    6357       else
    6358         {
    6359           howto.src_mask = howto.dst_mask = (1 << howto.bitsize) - 1;
    6360           if (howto.bitsize == 16)
    6361             howto.size = 1;
    6362         }
    6363       howto.pcrel_offset = false;
    6364 
    6365       val = 0;
    6366 
    6367       if (h == NULL)
    6368         {
    6369           asection *sec;
    6370 
    6371           if (symndx == -1)
    6372             {
    6373               sec = bfd_abs_section_ptr;
    6374               val = 0;
    6375             }
    6376           else
    6377             {
    6378               sec = sections[symndx];
    6379               /* Hack to make sure we use the right TOC anchor value
    6380                  if this reloc is against the TOC anchor.  */
    6381               if (sec->name[3] == '0'
    6382                   && strcmp (sec->name, ".tc0") == 0)
    6383                 val = xcoff_data (output_bfd)->toc;
    6384               else
    6385                 val = (sec->output_section->vma
    6386                        + sec->output_offset
    6387                        + sym->n_value
    6388                        - sec->vma);
    6389             }
    6390         }
    6391       else
    6392         {
    6393           if (h->root.type == bfd_link_hash_defined
    6394               || h->root.type == bfd_link_hash_defweak)
    6395             {
    6396               asection *sec;
    6397 
    6398               sec = h->root.u.def.section;
    6399               val = (h->root.u.def.value
    6400                      + sec->output_section->vma
    6401                      + sec->output_offset);
    6402             }
    6403           else if (h->root.type == bfd_link_hash_common)
    6404             {
    6405               asection *sec;
    6406 
    6407               sec = h->root.u.c.p->section;
    6408               val = (sec->output_section->vma
    6409                      + sec->output_offset);
    6410             }
    6411           else if ((h->flags & XCOFF_DEF_DYNAMIC) != 0
    6412                    || (h->flags & XCOFF_IMPORT) != 0)
    6413             {
    6414               /* Every symbol in a shared object is defined somewhere.  */
    6415               val = 0;
    6416             }
    6417           else if (! info->relocateable)
    6418             {
    6419               if (! ((*info->callbacks->undefined_symbol)
    6420                      (info, h->root.root.string, input_bfd, input_section,
    6421                       rel->r_vaddr - input_section->vma, true)))
    6422                 return false;
    6423 
    6424               /* Don't try to process the reloc.  It can't help, and
    6425                  it may generate another error.  */
    6426               continue;
    6427             }
    6428         }
    6429 
    6430       /* I took the relocation type definitions from two documents:
    6431          the PowerPC AIX Version 4 Application Binary Interface, First
    6432          Edition (April 1992), and the PowerOpen ABI, Big-Endian
    6433          32-Bit Hardware Implementation (June 30, 1994).  Differences
    6434          between the documents are noted below.  */
    6435 
    6436       switch (rel->r_type)
    6437         {
    6438         case R_RTB:
    6439         case R_RRTBI:
    6440         case R_RRTBA:
    6441           /* These relocs are defined by the PowerPC ABI to be
    6442              relative branches which use half of the difference
    6443              between the symbol and the program counter.  I can't
    6444              quite figure out when this is useful.  These relocs are
    6445              not defined by the PowerOpen ABI.  */
    6446         default:
    6447           (*_bfd_error_handler)
    6448             (_("%s: unsupported relocation type 0x%02x"),
    6449              bfd_get_filename (input_bfd), (unsigned int) rel->r_type);
    6450           bfd_set_error (bfd_error_bad_value);
    6451           return false;
    6452         case R_POS:
    6453           /* Simple positive relocation.  */
    6454           break;
    6455         case R_NEG:
    6456           /* Simple negative relocation.  */
    6457           val = - val;
    6458           break;
    6459         case R_REL:
    6460           /* Simple PC relative relocation.  */
    6461           howto.pc_relative = true;
    6462           break;
    6463         case R_TOC:
    6464           /* TOC relative relocation.  The value in the instruction in
    6465              the input file is the offset from the input file TOC to
    6466              the desired location.  We want the offset from the final
    6467              TOC to the desired location.  We have:
    6468                  isym = iTOC + in
    6469                  iinsn = in + o
    6470                  osym = oTOC + on
    6471                  oinsn = on + o
    6472              so we must change insn by on - in.
    6473              */
    6474         case R_GL:
    6475           /* Global linkage relocation.  The value of this relocation
    6476              is the address of the entry in the TOC section.  */
    6477         case R_TCL:
    6478           /* Local object TOC address.  I can't figure out the
    6479              difference between this and case R_GL.  */
    6480         case R_TRL:
    6481           /* TOC relative relocation.  A TOC relative load instruction
    6482              which may be changed to a load address instruction.
    6483              FIXME: We don't currently implement this optimization.  */
    6484         case R_TRLA:
    6485           /* TOC relative relocation.  This is a TOC relative load
    6486              address instruction which may be changed to a load
    6487              instruction.  FIXME: I don't know if this is the correct
    6488              implementation.  */
    6489           if (h != NULL && h->smclas != XMC_TD)
    6490             {
    6491               if (h->toc_section == NULL)
    6492                 {
    6493                   (*_bfd_error_handler)
    6494                     (_("%s: TOC reloc at 0x%x to symbol `%s' with no TOC entry"),
    6495                      bfd_get_filename (input_bfd), rel->r_vaddr,
    6496                      h->root.root.string);
    6497                   bfd_set_error (bfd_error_bad_value);
    6498                   return false;
    6499                 }
    6500 
    6501               BFD_ASSERT ((h->flags & XCOFF_SET_TOC) == 0);
    6502               val = (h->toc_section->output_section->vma
    6503                      + h->toc_section->output_offset);
    6504             }
    6505 
    6506           val = ((val - xcoff_data (output_bfd)->toc)
    6507                  - (sym->n_value - xcoff_data (input_bfd)->toc));
    6508           addend = 0;
    6509           break;
    6510         case R_BA:
    6511           /* Absolute branch.  We don't want to mess with the lower
    6512              two bits of the instruction.  */
    6513         case R_CAI:
    6514           /* The PowerPC ABI defines this as an absolute call which
    6515              may be modified to become a relative call.  The PowerOpen
    6516              ABI does not define this relocation type.  */
    6517         case R_RBA:
    6518           /* Absolute branch which may be modified to become a
    6519              relative branch.  */
    6520         case R_RBAC:
    6521           /* The PowerPC ABI defines this as an absolute branch to a
    6522              fixed address which may be modified to an absolute branch
    6523              to a symbol.  The PowerOpen ABI does not define this
    6524              relocation type.  */
    6525         case R_RBRC:
    6526           /* The PowerPC ABI defines this as an absolute branch to a
    6527              fixed address which may be modified to a relative branch.
    6528              The PowerOpen ABI does not define this relocation type.  */
    6529           howto.src_mask &= ~3;
    6530           howto.dst_mask = howto.src_mask;
    6531           break;
    6532         case R_BR:
    6533           /* Relative branch.  We don't want to mess with the lower
    6534              two bits of the instruction.  */
    6535         case R_CREL:
    6536           /* The PowerPC ABI defines this as a relative call which may
    6537              be modified to become an absolute call.  The PowerOpen
    6538              ABI does not define this relocation type.  */
    6539         case R_RBR:
    6540           /* A relative branch which may be modified to become an
    6541              absolute branch.  FIXME: We don't implement this,
    6542              although we should for symbols of storage mapping class
    6543              XMC_XO.  */
    6544           howto.pc_relative = true;
    6545           howto.src_mask &= ~3;
    6546           howto.dst_mask = howto.src_mask;
    6547           break;
    6548         case R_RL:
    6549           /* The PowerPC AIX ABI describes this as a load which may be
    6550              changed to a load address.  The PowerOpen ABI says this
    6551              is the same as case R_POS.  */
    6552           break;
    6553         case R_RLA:
    6554           /* The PowerPC AIX ABI describes this as a load address
    6555              which may be changed to a load.  The PowerOpen ABI says
    6556              this is the same as R_POS.  */
    6557           break;
    6558         }
    6559 
    6560       /* If we see an R_BR or R_RBR reloc which is jumping to global
    6561          linkage code, and it is followed by an appropriate cror nop
    6562          instruction, we replace the cror with lwz r2,20(r1).  This
    6563          restores the TOC after the glink code.  Contrariwise, if the
    6564          call is followed by a lwz r2,20(r1), but the call is not
    6565          going to global linkage code, we can replace the load with a
    6566          cror.  */
    6567       if ((rel->r_type == R_BR || rel->r_type == R_RBR)
    6568           && h != NULL
    6569           && h->root.type == bfd_link_hash_defined
    6570           && (rel->r_vaddr - input_section->vma + 8
    6571               <= input_section->_cooked_size))
    6572         {
    6573           bfd_byte *pnext;
    6574           unsigned long next;
    6575 
    6576           pnext = contents + (rel->r_vaddr - input_section->vma) + 4;
    6577           next = bfd_get_32 (input_bfd, pnext);
    6578 
    6579           /* The _ptrgl function is magic.  It is used by the AIX
    6580              compiler to call a function through a pointer.  */
    6581           if (h->smclas == XMC_GL
    6582               || strcmp (h->root.root.string, "._ptrgl") == 0)
    6583             {
    6584               if (next == 0x4def7b82            /* cror 15,15,15 */
    6585                   || next == 0x4ffffb82         /* cror 31,31,31 */
    6586                   || next == 0x60000000)        /* ori r0,r0,0 */
    6587                 bfd_put_32 (input_bfd, 0x80410014, pnext); /* lwz r1,20(r1) */
    6588             }
    6589           else
    6590             {
    6591               if (next == 0x80410014)           /* lwz r1,20(r1) */
    6592                 bfd_put_32 (input_bfd, 0x60000000, pnext); /* ori r0,r0,0 */
    6593             }
    6594         }
    6595 
    6596       /* A PC relative reloc includes the section address.  */
    6597       if (howto.pc_relative)
    6598         addend += input_section->vma;
    6599 
    6600       rstat = _bfd_final_link_relocate (&howto, input_bfd, input_section,
    6601                                         contents,
    6602                                         rel->r_vaddr - input_section->vma,
    6603                                         val, addend);
    6604 
    6605       switch (rstat)
    6606         {
    6607         default:
    6608           abort ();
    6609         case bfd_reloc_ok:
    6610           break;
    6611         case bfd_reloc_overflow:
    6612           {
    6613             const char *name;
    6614             char buf[SYMNMLEN + 1];
    6615             char howto_name[10];
    6616 
    6617             if (symndx == -1)
    6618               name = "*ABS*";
    6619             else if (h != NULL)
    6620               name = h->root.root.string;
    6621             else
    6622               {
    6623                 name = _bfd_coff_internal_syment_name (input_bfd, sym, buf);
    6624                 if (name == NULL)
    6625                   return false;
    6626               }
    6627             sprintf (howto_name, "0x%02x", rel->r_type);
    6628 
    6629             if (! ((*info->callbacks->reloc_overflow)
    6630                    (info, name, howto_name, (bfd_vma) 0, input_bfd,
    6631                     input_section, rel->r_vaddr - input_section->vma)))
    6632               return false;
    6633           }
    6634         }
    6635     }
    6636 
    6637   return true;
    6638 }
     6171
     6172
     6173
Note: See TracChangeset for help on using the changeset viewer.