Home | History | Annotate | Line # | Download | only in bfd
coff-rs6000.c revision 1.1.1.2
      1 /* BFD back-end for IBM RS/6000 "XCOFF" files.
      2    Copyright 1990-1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
      3    2008, 2009, 2010
      4    Free Software Foundation, Inc.
      5    Written by Metin G. Ozisik, Mimi Phuong-Thao Vo, and John Gilmore.
      6    Archive support from Damon A. Permezel.
      7    Contributed by IBM Corporation and Cygnus Support.
      8 
      9    This file is part of BFD, the Binary File Descriptor library.
     10 
     11    This program is free software; you can redistribute it and/or modify
     12    it under the terms of the GNU General Public License as published by
     13    the Free Software Foundation; either version 3 of the License, or
     14    (at your option) any later version.
     15 
     16    This program is distributed in the hope that it will be useful,
     17    but WITHOUT ANY WARRANTY; without even the implied warranty of
     18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     19    GNU General Public License for more details.
     20 
     21    You should have received a copy of the GNU General Public License
     22    along with this program; if not, write to the Free Software
     23    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
     24    MA 02110-1301, USA.  */
     25 
     26 #include "sysdep.h"
     27 #include "bfd.h"
     28 #include "bfdlink.h"
     29 #include "libbfd.h"
     30 #include "coff/internal.h"
     31 #include "coff/xcoff.h"
     32 #include "coff/rs6000.h"
     33 #include "libcoff.h"
     34 #include "libxcoff.h"
     35 
     36 extern bfd_boolean _bfd_xcoff_mkobject
     37   PARAMS ((bfd *));
     38 extern bfd_boolean _bfd_xcoff_copy_private_bfd_data
     39   PARAMS ((bfd *, bfd *));
     40 extern bfd_boolean _bfd_xcoff_is_local_label_name
     41   PARAMS ((bfd *, const char *));
     42 extern reloc_howto_type *_bfd_xcoff_reloc_type_lookup
     43   PARAMS ((bfd *, bfd_reloc_code_real_type));
     44 extern bfd_boolean _bfd_xcoff_slurp_armap
     45   PARAMS ((bfd *));
     46 extern const bfd_target *_bfd_xcoff_archive_p
     47   PARAMS ((bfd *));
     48 extern PTR _bfd_xcoff_read_ar_hdr
     49   PARAMS ((bfd *));
     50 extern bfd *_bfd_xcoff_openr_next_archived_file
     51   PARAMS ((bfd *, bfd *));
     52 extern int _bfd_xcoff_stat_arch_elt
     53   PARAMS ((bfd *, struct stat *));
     54 extern bfd_boolean _bfd_xcoff_write_armap
     55   PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int));
     56 extern bfd_boolean _bfd_xcoff_write_archive_contents
     57   PARAMS ((bfd *));
     58 extern int _bfd_xcoff_sizeof_headers
     59   PARAMS ((bfd *, struct bfd_link_info *));
     60 extern void _bfd_xcoff_swap_sym_in
     61   PARAMS ((bfd *, PTR, PTR));
     62 extern unsigned int _bfd_xcoff_swap_sym_out
     63   PARAMS ((bfd *, PTR, PTR));
     64 extern void _bfd_xcoff_swap_aux_in
     65   PARAMS ((bfd *, PTR, int, int, int, int, PTR));
     66 extern unsigned int _bfd_xcoff_swap_aux_out
     67   PARAMS ((bfd *, PTR, int, int, int, int, PTR));
     68 static void xcoff_swap_reloc_in
     69   PARAMS ((bfd *, PTR, PTR));
     70 static unsigned int xcoff_swap_reloc_out
     71   PARAMS ((bfd *, PTR, PTR));
     72 
     73 /* Forward declare xcoff_rtype2howto for coffcode.h macro.  */
     74 void xcoff_rtype2howto
     75   PARAMS ((arelent *, struct internal_reloc *));
     76 
     77 /* coffcode.h needs these to be defined.  */
     78 #define RS6000COFF_C 1
     79 
     80 #define SELECT_RELOC(internal, howto)					\
     81   {									\
     82     internal.r_type = howto->type;					\
     83     internal.r_size =							\
     84       ((howto->complain_on_overflow == complain_overflow_signed		\
     85 	? 0x80								\
     86 	: 0)								\
     87        | (howto->bitsize - 1));						\
     88   }
     89 
     90 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
     91 #define COFF_LONG_FILENAMES
     92 #define NO_COFF_SYMBOLS
     93 #define RTYPE2HOWTO(cache_ptr, dst) xcoff_rtype2howto (cache_ptr, dst)
     94 #define coff_mkobject _bfd_xcoff_mkobject
     95 #define coff_bfd_copy_private_bfd_data _bfd_xcoff_copy_private_bfd_data
     96 #define coff_bfd_is_local_label_name _bfd_xcoff_is_local_label_name
     97 #define coff_bfd_reloc_type_lookup _bfd_xcoff_reloc_type_lookup
     98 #define coff_bfd_reloc_name_lookup _bfd_xcoff_reloc_name_lookup
     99 #ifdef AIX_CORE
    100 extern const bfd_target * rs6000coff_core_p
    101   PARAMS ((bfd *abfd));
    102 extern bfd_boolean rs6000coff_core_file_matches_executable_p
    103   PARAMS ((bfd *cbfd, bfd *ebfd));
    104 extern char *rs6000coff_core_file_failing_command
    105   PARAMS ((bfd *abfd));
    106 extern int rs6000coff_core_file_failing_signal
    107   PARAMS ((bfd *abfd));
    108 #define CORE_FILE_P rs6000coff_core_p
    109 #define coff_core_file_failing_command \
    110   rs6000coff_core_file_failing_command
    111 #define coff_core_file_failing_signal \
    112   rs6000coff_core_file_failing_signal
    113 #define coff_core_file_matches_executable_p \
    114   rs6000coff_core_file_matches_executable_p
    115 #define coff_core_file_pid \
    116   _bfd_nocore_core_file_pid
    117 #else
    118 #define CORE_FILE_P _bfd_dummy_target
    119 #define coff_core_file_failing_command \
    120   _bfd_nocore_core_file_failing_command
    121 #define coff_core_file_failing_signal \
    122   _bfd_nocore_core_file_failing_signal
    123 #define coff_core_file_matches_executable_p \
    124   _bfd_nocore_core_file_matches_executable_p
    125 #define coff_core_file_pid \
    126   _bfd_nocore_core_file_pid
    127 #endif
    128 #define coff_SWAP_sym_in _bfd_xcoff_swap_sym_in
    129 #define coff_SWAP_sym_out _bfd_xcoff_swap_sym_out
    130 #define coff_SWAP_aux_in _bfd_xcoff_swap_aux_in
    131 #define coff_SWAP_aux_out _bfd_xcoff_swap_aux_out
    132 #define coff_swap_reloc_in xcoff_swap_reloc_in
    133 #define coff_swap_reloc_out xcoff_swap_reloc_out
    134 #define NO_COFF_RELOCS
    135 
    136 #ifndef bfd_pe_print_pdata
    137 #define bfd_pe_print_pdata	NULL
    138 #endif
    139 
    140 #include "coffcode.h"
    141 
    142 /* The main body of code is in coffcode.h.  */
    143 
    144 static const char *normalize_filename
    145   PARAMS ((bfd *));
    146 static bfd_boolean xcoff_write_armap_old
    147   PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int));
    148 static bfd_boolean xcoff_write_armap_big
    149   PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int));
    150 static bfd_boolean xcoff_write_archive_contents_old
    151   PARAMS ((bfd *));
    152 static bfd_boolean xcoff_write_archive_contents_big
    153   PARAMS ((bfd *));
    154 static void xcoff_swap_ldhdr_in
    155   PARAMS ((bfd *, const PTR, struct internal_ldhdr *));
    156 static void xcoff_swap_ldhdr_out
    157   PARAMS ((bfd *, const struct internal_ldhdr *, PTR));
    158 static void xcoff_swap_ldsym_in
    159   PARAMS ((bfd *, const PTR, struct internal_ldsym *));
    160 static void xcoff_swap_ldsym_out
    161   PARAMS ((bfd *, const struct internal_ldsym *, PTR));
    162 static void xcoff_swap_ldrel_in
    163   PARAMS ((bfd *, const PTR, struct internal_ldrel *));
    164 static void xcoff_swap_ldrel_out
    165   PARAMS ((bfd *, const struct internal_ldrel *, PTR));
    166 static bfd_boolean xcoff_ppc_relocate_section
    167   PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
    168 	   struct internal_reloc *, struct internal_syment *, asection **));
    169 static bfd_boolean _bfd_xcoff_put_ldsymbol_name
    170   PARAMS ((bfd *, struct xcoff_loader_info *, struct internal_ldsym *,
    171 	   const char *));
    172 static asection *xcoff_create_csect_from_smclas
    173   PARAMS ((bfd *, union internal_auxent *, const char *));
    174 static bfd_boolean xcoff_is_lineno_count_overflow
    175   PARAMS ((bfd *, bfd_vma));
    176 static bfd_boolean xcoff_is_reloc_count_overflow
    177   PARAMS ((bfd *, bfd_vma));
    178 static bfd_vma xcoff_loader_symbol_offset
    179   PARAMS ((bfd *, struct internal_ldhdr *));
    180 static bfd_vma xcoff_loader_reloc_offset
    181   PARAMS ((bfd *, struct internal_ldhdr *));
    182 static bfd_boolean xcoff_generate_rtinit
    183   PARAMS ((bfd *, const char *, const char *, bfd_boolean));
    184 static bfd_boolean do_pad
    185   PARAMS ((bfd *, unsigned int));
    186 static bfd_boolean do_copy
    187   PARAMS ((bfd *, bfd *));
    188 
    189 /* Relocation functions */
    190 static bfd_boolean xcoff_reloc_type_br
    191   PARAMS ((XCOFF_RELOC_FUNCTION_ARGS));
    192 
    193 static bfd_boolean xcoff_complain_overflow_dont_func
    194   PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS));
    195 static bfd_boolean xcoff_complain_overflow_bitfield_func
    196   PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS));
    197 static bfd_boolean xcoff_complain_overflow_signed_func
    198   PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS));
    199 static bfd_boolean xcoff_complain_overflow_unsigned_func
    200   PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS));
    201 
    202 bfd_boolean (*xcoff_calculate_relocation[XCOFF_MAX_CALCULATE_RELOCATION])
    203   PARAMS ((XCOFF_RELOC_FUNCTION_ARGS)) =
    204 {
    205   xcoff_reloc_type_pos,	 /* R_POS   (0x00) */
    206   xcoff_reloc_type_neg,	 /* R_NEG   (0x01) */
    207   xcoff_reloc_type_rel,	 /* R_REL   (0x02) */
    208   xcoff_reloc_type_toc,	 /* R_TOC   (0x03) */
    209   xcoff_reloc_type_fail, /* R_RTB   (0x04) */
    210   xcoff_reloc_type_toc,	 /* R_GL    (0x05) */
    211   xcoff_reloc_type_toc,	 /* R_TCL   (0x06) */
    212   xcoff_reloc_type_fail, /*	    (0x07) */
    213   xcoff_reloc_type_ba,	 /* R_BA    (0x08) */
    214   xcoff_reloc_type_fail, /*	    (0x09) */
    215   xcoff_reloc_type_br,	 /* R_BR    (0x0a) */
    216   xcoff_reloc_type_fail, /*	    (0x0b) */
    217   xcoff_reloc_type_pos,	 /* R_RL    (0x0c) */
    218   xcoff_reloc_type_pos,	 /* R_RLA   (0x0d) */
    219   xcoff_reloc_type_fail, /*	    (0x0e) */
    220   xcoff_reloc_type_noop, /* R_REF   (0x0f) */
    221   xcoff_reloc_type_fail, /*	    (0x10) */
    222   xcoff_reloc_type_fail, /*	    (0x11) */
    223   xcoff_reloc_type_toc,	 /* R_TRL   (0x12) */
    224   xcoff_reloc_type_toc,	 /* R_TRLA  (0x13) */
    225   xcoff_reloc_type_fail, /* R_RRTBI (0x14) */
    226   xcoff_reloc_type_fail, /* R_RRTBA (0x15) */
    227   xcoff_reloc_type_ba,	 /* R_CAI   (0x16) */
    228   xcoff_reloc_type_crel, /* R_CREL  (0x17) */
    229   xcoff_reloc_type_ba,	 /* R_RBA   (0x18) */
    230   xcoff_reloc_type_ba,	 /* R_RBAC  (0x19) */
    231   xcoff_reloc_type_br,	 /* R_RBR   (0x1a) */
    232   xcoff_reloc_type_ba,	 /* R_RBRC  (0x1b) */
    233 };
    234 
    235 bfd_boolean (*xcoff_complain_overflow[XCOFF_MAX_COMPLAIN_OVERFLOW])
    236   PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS)) =
    237 {
    238   xcoff_complain_overflow_dont_func,
    239   xcoff_complain_overflow_bitfield_func,
    240   xcoff_complain_overflow_signed_func,
    241   xcoff_complain_overflow_unsigned_func,
    242 };
    243 
    244 /* Information about one member of an archive.  */
    245 struct member_layout {
    246   /* The archive member that this structure describes.  */
    247   bfd *member;
    248 
    249   /* The number of bytes of padding that must be inserted before the
    250      start of the member in order to ensure that the section contents
    251      are correctly aligned.  */
    252   unsigned int leading_padding;
    253 
    254   /* The offset of MEMBER from the start of the archive (i.e. the end
    255      of the leading padding).  */
    256   file_ptr offset;
    257 
    258   /* The normalized name of MEMBER.  */
    259   const char *name;
    260 
    261   /* The length of NAME, without padding.  */
    262   bfd_size_type namlen;
    263 
    264   /* The length of NAME, with padding.  */
    265   bfd_size_type padded_namlen;
    266 
    267   /* The size of MEMBER's header, including the name and magic sequence.  */
    268   bfd_size_type header_size;
    269 
    270   /* The size of the MEMBER's contents.  */
    271   bfd_size_type contents_size;
    272 
    273   /* The number of bytes of padding that must be inserted after MEMBER
    274      in order to preserve even alignment.  */
    275   bfd_size_type trailing_padding;
    276 };
    277 
    278 /* A structure used for iterating over the members of an archive.  */
    279 struct archive_iterator {
    280   /* The archive itself.  */
    281   bfd *archive;
    282 
    283   /* Information about the current archive member.  */
    284   struct member_layout current;
    285 
    286   /* Information about the next archive member.  MEMBER is null if there
    287      are no more archive members, in which case OFFSET is the offset of
    288      the first unused byte.  */
    289   struct member_layout next;
    290 };
    291 
    292 /* Initialize INFO so that it describes member MEMBER of archive ARCHIVE.
    293    OFFSET is the even-padded offset of MEMBER, not including any leading
    294    padding needed for section alignment.  */
    295 
    296 static void
    297 member_layout_init (struct member_layout *info, bfd *archive,
    298 		    bfd *member, file_ptr offset)
    299 {
    300   info->member = member;
    301   info->leading_padding = 0;
    302   if (member)
    303     {
    304       info->name = normalize_filename (member);
    305       info->namlen = strlen (info->name);
    306       info->padded_namlen = info->namlen + (info->namlen & 1);
    307       if (xcoff_big_format_p (archive))
    308 	info->header_size = SIZEOF_AR_HDR_BIG;
    309       else
    310 	info->header_size = SIZEOF_AR_HDR;
    311       info->header_size += info->padded_namlen + SXCOFFARFMAG;
    312       info->contents_size = arelt_size (member);
    313       info->trailing_padding = info->contents_size & 1;
    314 
    315       if (bfd_check_format (member, bfd_object)
    316 	  && bfd_get_flavour (member) == bfd_target_xcoff_flavour
    317 	  && (member->flags & DYNAMIC) != 0)
    318 	info->leading_padding
    319 	  = (-(offset + info->header_size)
    320 	     & ((1 << bfd_xcoff_text_align_power (member)) - 1));
    321     }
    322   info->offset = offset + info->leading_padding;
    323 }
    324 
    325 /* Set up ITERATOR to iterate through archive ARCHIVE.  */
    326 
    327 static void
    328 archive_iterator_begin (struct archive_iterator *iterator,
    329 			bfd *archive)
    330 {
    331   iterator->archive = archive;
    332   member_layout_init (&iterator->next, archive, archive->archive_head,
    333 		      xcoff_big_format_p (archive)
    334 		      ? SIZEOF_AR_FILE_HDR_BIG
    335 		      : SIZEOF_AR_FILE_HDR);
    336 }
    337 
    338 /* Make ITERATOR visit the first unvisited archive member.  Return true
    339    on success; return false if all members have been visited.  */
    340 
    341 static bfd_boolean
    342 archive_iterator_next (struct archive_iterator *iterator)
    343 {
    344   if (!iterator->next.member)
    345     return FALSE;
    346 
    347   iterator->current = iterator->next;
    348   member_layout_init (&iterator->next, iterator->archive,
    349 		      iterator->current.member->archive_next,
    350 		      iterator->current.offset
    351 		      + iterator->current.header_size
    352 		      + iterator->current.contents_size
    353 		      + iterator->current.trailing_padding);
    354   return TRUE;
    355 }
    356 
    357 /* We use our own tdata type.  Its first field is the COFF tdata type,
    358    so the COFF routines are compatible.  */
    359 
    360 bfd_boolean
    361 _bfd_xcoff_mkobject (abfd)
    362      bfd *abfd;
    363 {
    364   coff_data_type *coff;
    365   bfd_size_type amt = sizeof (struct xcoff_tdata);
    366 
    367   abfd->tdata.xcoff_obj_data = (struct xcoff_tdata *) bfd_zalloc (abfd, amt);
    368   if (abfd->tdata.xcoff_obj_data == NULL)
    369     return FALSE;
    370   coff = coff_data (abfd);
    371   coff->symbols = (coff_symbol_type *) NULL;
    372   coff->conversion_table = (unsigned int *) NULL;
    373   coff->raw_syments = (struct coff_ptr_struct *) NULL;
    374   coff->relocbase = 0;
    375 
    376   xcoff_data (abfd)->modtype = ('1' << 8) | 'L';
    377 
    378   /* We set cputype to -1 to indicate that it has not been
    379      initialized.  */
    380   xcoff_data (abfd)->cputype = -1;
    381 
    382   xcoff_data (abfd)->csects = NULL;
    383   xcoff_data (abfd)->debug_indices = NULL;
    384 
    385   /* text section alignment is different than the default */
    386   bfd_xcoff_text_align_power (abfd) = 2;
    387 
    388   return TRUE;
    389 }
    390 
    391 /* Copy XCOFF data from one BFD to another.  */
    392 
    393 bfd_boolean
    394 _bfd_xcoff_copy_private_bfd_data (ibfd, obfd)
    395      bfd *ibfd;
    396      bfd *obfd;
    397 {
    398   struct xcoff_tdata *ix, *ox;
    399   asection *sec;
    400 
    401   if (ibfd->xvec != obfd->xvec)
    402     return TRUE;
    403   ix = xcoff_data (ibfd);
    404   ox = xcoff_data (obfd);
    405   ox->full_aouthdr = ix->full_aouthdr;
    406   ox->toc = ix->toc;
    407   if (ix->sntoc == 0)
    408     ox->sntoc = 0;
    409   else
    410     {
    411       sec = coff_section_from_bfd_index (ibfd, ix->sntoc);
    412       if (sec == NULL)
    413 	ox->sntoc = 0;
    414       else
    415 	ox->sntoc = sec->output_section->target_index;
    416     }
    417   if (ix->snentry == 0)
    418     ox->snentry = 0;
    419   else
    420     {
    421       sec = coff_section_from_bfd_index (ibfd, ix->snentry);
    422       if (sec == NULL)
    423 	ox->snentry = 0;
    424       else
    425 	ox->snentry = sec->output_section->target_index;
    426     }
    427   bfd_xcoff_text_align_power (obfd) = bfd_xcoff_text_align_power (ibfd);
    428   bfd_xcoff_data_align_power (obfd) = bfd_xcoff_data_align_power (ibfd);
    429   ox->modtype = ix->modtype;
    430   ox->cputype = ix->cputype;
    431   ox->maxdata = ix->maxdata;
    432   ox->maxstack = ix->maxstack;
    433   return TRUE;
    434 }
    435 
    436 /* I don't think XCOFF really has a notion of local labels based on
    437    name.  This will mean that ld -X doesn't actually strip anything.
    438    The AIX native linker does not have a -X option, and it ignores the
    439    -x option.  */
    440 
    441 bfd_boolean
    442 _bfd_xcoff_is_local_label_name (abfd, name)
    443      bfd *abfd ATTRIBUTE_UNUSED;
    444      const char *name ATTRIBUTE_UNUSED;
    445 {
    446   return FALSE;
    447 }
    448 
    449 void
    451 _bfd_xcoff_swap_sym_in (abfd, ext1, in1)
    452      bfd *abfd;
    453      PTR ext1;
    454      PTR in1;
    455 {
    456   SYMENT *ext = (SYMENT *)ext1;
    457   struct internal_syment * in = (struct internal_syment *)in1;
    458 
    459   if (ext->e.e_name[0] != 0)
    460     {
    461       memcpy (in->_n._n_name, ext->e.e_name, SYMNMLEN);
    462     }
    463   else
    464     {
    465       in->_n._n_n._n_zeroes = 0;
    466       in->_n._n_n._n_offset = H_GET_32 (abfd, ext->e.e.e_offset);
    467     }
    468 
    469   in->n_value = H_GET_32 (abfd, ext->e_value);
    470   in->n_scnum = H_GET_16 (abfd, ext->e_scnum);
    471   in->n_type = H_GET_16 (abfd, ext->e_type);
    472   in->n_sclass = H_GET_8 (abfd, ext->e_sclass);
    473   in->n_numaux = H_GET_8 (abfd, ext->e_numaux);
    474 }
    475 
    476 unsigned int
    477 _bfd_xcoff_swap_sym_out (abfd, inp, extp)
    478      bfd *abfd;
    479      PTR inp;
    480      PTR extp;
    481 {
    482   struct internal_syment *in = (struct internal_syment *)inp;
    483   SYMENT *ext =(SYMENT *)extp;
    484 
    485   if (in->_n._n_name[0] != 0)
    486     {
    487       memcpy (ext->e.e_name, in->_n._n_name, SYMNMLEN);
    488     }
    489   else
    490     {
    491       H_PUT_32 (abfd, 0, ext->e.e.e_zeroes);
    492       H_PUT_32 (abfd, in->_n._n_n._n_offset, ext->e.e.e_offset);
    493     }
    494 
    495   H_PUT_32 (abfd, in->n_value, ext->e_value);
    496   H_PUT_16 (abfd, in->n_scnum, ext->e_scnum);
    497   H_PUT_16 (abfd, in->n_type, ext->e_type);
    498   H_PUT_8 (abfd, in->n_sclass, ext->e_sclass);
    499   H_PUT_8 (abfd, in->n_numaux, ext->e_numaux);
    500   return bfd_coff_symesz (abfd);
    501 }
    502 
    503 void
    504 _bfd_xcoff_swap_aux_in (abfd, ext1, type, in_class, indx, numaux, in1)
    505      bfd *abfd;
    506      PTR ext1;
    507      int type;
    508      int in_class;
    509      int indx;
    510      int numaux;
    511      PTR in1;
    512 {
    513   AUXENT * ext = (AUXENT *)ext1;
    514   union internal_auxent *in = (union internal_auxent *)in1;
    515 
    516   switch (in_class)
    517     {
    518     case C_FILE:
    519       if (ext->x_file.x_fname[0] == 0)
    520 	{
    521 	  in->x_file.x_n.x_zeroes = 0;
    522 	  in->x_file.x_n.x_offset =
    523 	    H_GET_32 (abfd, ext->x_file.x_n.x_offset);
    524 	}
    525       else
    526 	{
    527 	  if (numaux > 1)
    528 	    {
    529 	      if (indx == 0)
    530 		memcpy (in->x_file.x_fname, ext->x_file.x_fname,
    531 			numaux * sizeof (AUXENT));
    532 	    }
    533 	  else
    534 	    {
    535 	      memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN);
    536 	    }
    537 	}
    538       goto end;
    539 
    540       /* RS/6000 "csect" auxents */
    541     case C_EXT:
    542     case C_AIX_WEAKEXT:
    543     case C_HIDEXT:
    544       if (indx + 1 == numaux)
    545 	{
    546 	  in->x_csect.x_scnlen.l = H_GET_32 (abfd, ext->x_csect.x_scnlen);
    547 	  in->x_csect.x_parmhash = H_GET_32 (abfd, ext->x_csect.x_parmhash);
    548 	  in->x_csect.x_snhash   = H_GET_16 (abfd, ext->x_csect.x_snhash);
    549 	  /* We don't have to hack bitfields in x_smtyp because it's
    550 	     defined by shifts-and-ands, which are equivalent on all
    551 	     byte orders.  */
    552 	  in->x_csect.x_smtyp    = H_GET_8 (abfd, ext->x_csect.x_smtyp);
    553 	  in->x_csect.x_smclas   = H_GET_8 (abfd, ext->x_csect.x_smclas);
    554 	  in->x_csect.x_stab     = H_GET_32 (abfd, ext->x_csect.x_stab);
    555 	  in->x_csect.x_snstab   = H_GET_16 (abfd, ext->x_csect.x_snstab);
    556 	  goto end;
    557 	}
    558       break;
    559 
    560     case C_STAT:
    561     case C_LEAFSTAT:
    562     case C_HIDDEN:
    563       if (type == T_NULL)
    564 	{
    565 	  in->x_scn.x_scnlen = H_GET_32 (abfd, ext->x_scn.x_scnlen);
    566 	  in->x_scn.x_nreloc = H_GET_16 (abfd, ext->x_scn.x_nreloc);
    567 	  in->x_scn.x_nlinno = H_GET_16 (abfd, ext->x_scn.x_nlinno);
    568 	  /* PE defines some extra fields; we zero them out for
    569 	     safety.  */
    570 	  in->x_scn.x_checksum = 0;
    571 	  in->x_scn.x_associated = 0;
    572 	  in->x_scn.x_comdat = 0;
    573 
    574 	  goto end;
    575 	}
    576       break;
    577     }
    578 
    579   in->x_sym.x_tagndx.l = H_GET_32 (abfd, ext->x_sym.x_tagndx);
    580   in->x_sym.x_tvndx = H_GET_16 (abfd, ext->x_sym.x_tvndx);
    581 
    582   if (in_class == C_BLOCK || in_class == C_FCN || ISFCN (type)
    583       || ISTAG (in_class))
    584     {
    585       in->x_sym.x_fcnary.x_fcn.x_lnnoptr =
    586 	H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_lnnoptr);
    587       in->x_sym.x_fcnary.x_fcn.x_endndx.l =
    588 	H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_endndx);
    589     }
    590   else
    591     {
    592       in->x_sym.x_fcnary.x_ary.x_dimen[0] =
    593 	H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
    594       in->x_sym.x_fcnary.x_ary.x_dimen[1] =
    595 	H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
    596       in->x_sym.x_fcnary.x_ary.x_dimen[2] =
    597 	H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
    598       in->x_sym.x_fcnary.x_ary.x_dimen[3] =
    599 	H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
    600     }
    601 
    602   if (ISFCN (type))
    603     {
    604       in->x_sym.x_misc.x_fsize = H_GET_32 (abfd, ext->x_sym.x_misc.x_fsize);
    605     }
    606   else
    607     {
    608       in->x_sym.x_misc.x_lnsz.x_lnno =
    609 	H_GET_16 (abfd, ext->x_sym.x_misc.x_lnsz.x_lnno);
    610       in->x_sym.x_misc.x_lnsz.x_size =
    611 	H_GET_16 (abfd, ext->x_sym.x_misc.x_lnsz.x_size);
    612     }
    613 
    614  end: ;
    615   /* The semicolon is because MSVC doesn't like labels at
    616      end of block.  */
    617 }
    618 
    619 
    620 unsigned int _bfd_xcoff_swap_aux_out
    621   PARAMS ((bfd *, PTR, int, int, int, int, PTR));
    622 
    623 unsigned int
    624 _bfd_xcoff_swap_aux_out (abfd, inp, type, in_class, indx, numaux, extp)
    625      bfd * abfd;
    626      PTR   inp;
    627      int   type;
    628      int   in_class;
    629      int   indx ATTRIBUTE_UNUSED;
    630      int   numaux ATTRIBUTE_UNUSED;
    631      PTR   extp;
    632 {
    633   union internal_auxent *in = (union internal_auxent *)inp;
    634   AUXENT *ext = (AUXENT *)extp;
    635 
    636   memset ((PTR)ext, 0, bfd_coff_auxesz (abfd));
    637   switch (in_class)
    638     {
    639     case C_FILE:
    640       if (in->x_file.x_fname[0] == 0)
    641 	{
    642 	  H_PUT_32 (abfd, 0, ext->x_file.x_n.x_zeroes);
    643 	  H_PUT_32 (abfd, in->x_file.x_n.x_offset, ext->x_file.x_n.x_offset);
    644 	}
    645       else
    646 	{
    647 	  memcpy (ext->x_file.x_fname, in->x_file.x_fname, FILNMLEN);
    648 	}
    649       goto end;
    650 
    651       /* RS/6000 "csect" auxents */
    652     case C_EXT:
    653     case C_AIX_WEAKEXT:
    654     case C_HIDEXT:
    655       if (indx + 1 == numaux)
    656 	{
    657 	  H_PUT_32 (abfd, in->x_csect.x_scnlen.l, ext->x_csect.x_scnlen);
    658 	  H_PUT_32 (abfd, in->x_csect.x_parmhash, ext->x_csect.x_parmhash);
    659 	  H_PUT_16 (abfd, in->x_csect.x_snhash, ext->x_csect.x_snhash);
    660 	  /* We don't have to hack bitfields in x_smtyp because it's
    661 	     defined by shifts-and-ands, which are equivalent on all
    662 	     byte orders.  */
    663 	  H_PUT_8 (abfd, in->x_csect.x_smtyp, ext->x_csect.x_smtyp);
    664 	  H_PUT_8 (abfd, in->x_csect.x_smclas, ext->x_csect.x_smclas);
    665 	  H_PUT_32 (abfd, in->x_csect.x_stab, ext->x_csect.x_stab);
    666 	  H_PUT_16 (abfd, in->x_csect.x_snstab, ext->x_csect.x_snstab);
    667 	  goto end;
    668 	}
    669       break;
    670 
    671     case C_STAT:
    672     case C_LEAFSTAT:
    673     case C_HIDDEN:
    674       if (type == T_NULL)
    675 	{
    676 	  H_PUT_32 (abfd, in->x_scn.x_scnlen, ext->x_scn.x_scnlen);
    677 	  H_PUT_16 (abfd, in->x_scn.x_nreloc, ext->x_scn.x_nreloc);
    678 	  H_PUT_16 (abfd, in->x_scn.x_nlinno, ext->x_scn.x_nlinno);
    679 	  goto end;
    680 	}
    681       break;
    682     }
    683 
    684   H_PUT_32 (abfd, in->x_sym.x_tagndx.l, ext->x_sym.x_tagndx);
    685   H_PUT_16 (abfd, in->x_sym.x_tvndx, ext->x_sym.x_tvndx);
    686 
    687   if (in_class == C_BLOCK || in_class == C_FCN || ISFCN (type)
    688       || ISTAG (in_class))
    689     {
    690       H_PUT_32 (abfd, in->x_sym.x_fcnary.x_fcn.x_lnnoptr,
    691 		ext->x_sym.x_fcnary.x_fcn.x_lnnoptr);
    692       H_PUT_32 (abfd, in->x_sym.x_fcnary.x_fcn.x_endndx.l,
    693 		ext->x_sym.x_fcnary.x_fcn.x_endndx);
    694     }
    695   else
    696     {
    697       H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[0],
    698 		ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
    699       H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[1],
    700 		ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
    701       H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[2],
    702 		ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
    703       H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[3],
    704 		ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
    705     }
    706 
    707   if (ISFCN (type))
    708     H_PUT_32 (abfd, in->x_sym.x_misc.x_fsize, ext->x_sym.x_misc.x_fsize);
    709   else
    710     {
    711       H_PUT_16 (abfd, in->x_sym.x_misc.x_lnsz.x_lnno,
    712 		ext->x_sym.x_misc.x_lnsz.x_lnno);
    713       H_PUT_16 (abfd, in->x_sym.x_misc.x_lnsz.x_size,
    714 		ext->x_sym.x_misc.x_lnsz.x_size);
    715     }
    716 
    717 end:
    718   return bfd_coff_auxesz (abfd);
    719 }
    720 
    721 
    722 
    723 /* The XCOFF reloc table.  Actually, XCOFF relocations specify the
    725    bitsize and whether they are signed or not, along with a
    726    conventional type.  This table is for the types, which are used for
    727    different algorithms for putting in the reloc.  Many of these
    728    relocs need special_function entries, which I have not written.  */
    729 
    730 
    731 reloc_howto_type xcoff_howto_table[] =
    732 {
    733   /* Standard 32 bit relocation.  */
    734   HOWTO (R_POS,			/* type */
    735 	 0,			/* rightshift */
    736 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    737 	 32,			/* bitsize */
    738 	 FALSE,			/* pc_relative */
    739 	 0,			/* bitpos */
    740 	 complain_overflow_bitfield, /* complain_on_overflow */
    741 	 0,			/* special_function */
    742 	 "R_POS",		/* name */
    743 	 TRUE,			/* partial_inplace */
    744 	 0xffffffff,		/* src_mask */
    745 	 0xffffffff,		/* dst_mask */
    746 	 FALSE),		/* pcrel_offset */
    747 
    748   /* 32 bit relocation, but store negative value.  */
    749   HOWTO (R_NEG,			/* type */
    750 	 0,			/* rightshift */
    751 	 -2,			/* size (0 = byte, 1 = short, 2 = long) */
    752 	 32,			/* bitsize */
    753 	 FALSE,			/* pc_relative */
    754 	 0,			/* bitpos */
    755 	 complain_overflow_bitfield, /* complain_on_overflow */
    756 	 0,			/* special_function */
    757 	 "R_NEG",		/* name */
    758 	 TRUE,			/* partial_inplace */
    759 	 0xffffffff,		/* src_mask */
    760 	 0xffffffff,		/* dst_mask */
    761 	 FALSE),		/* pcrel_offset */
    762 
    763   /* 32 bit PC relative relocation.  */
    764   HOWTO (R_REL,			/* type */
    765 	 0,			/* rightshift */
    766 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    767 	 32,			/* bitsize */
    768 	 TRUE,			/* pc_relative */
    769 	 0,			/* bitpos */
    770 	 complain_overflow_signed, /* complain_on_overflow */
    771 	 0,			/* special_function */
    772 	 "R_REL",		/* name */
    773 	 TRUE,			/* partial_inplace */
    774 	 0xffffffff,		/* src_mask */
    775 	 0xffffffff,		/* dst_mask */
    776 	 FALSE),		/* pcrel_offset */
    777 
    778   /* 16 bit TOC relative relocation.  */
    779   HOWTO (R_TOC,			/* type */
    780 	 0,			/* rightshift */
    781 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    782 	 16,			/* bitsize */
    783 	 FALSE,			/* pc_relative */
    784 	 0,			/* bitpos */
    785 	 complain_overflow_bitfield, /* complain_on_overflow */
    786 	 0,			/* special_function */
    787 	 "R_TOC",		/* name */
    788 	 TRUE,			/* partial_inplace */
    789 	 0xffff,		/* src_mask */
    790 	 0xffff,		/* dst_mask */
    791 	 FALSE),		/* pcrel_offset */
    792 
    793   /* I don't really know what this is.  */
    794   HOWTO (R_RTB,			/* type */
    795 	 1,			/* rightshift */
    796 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    797 	 32,			/* bitsize */
    798 	 FALSE,			/* pc_relative */
    799 	 0,			/* bitpos */
    800 	 complain_overflow_bitfield, /* complain_on_overflow */
    801 	 0,			/* special_function */
    802 	 "R_RTB",		/* name */
    803 	 TRUE,			/* partial_inplace */
    804 	 0xffffffff,		/* src_mask */
    805 	 0xffffffff,		/* dst_mask */
    806 	 FALSE),		/* pcrel_offset */
    807 
    808   /* External TOC relative symbol.  */
    809   HOWTO (R_GL,			/* type */
    810 	 0,			/* rightshift */
    811 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    812 	 16,			/* bitsize */
    813 	 FALSE,			/* pc_relative */
    814 	 0,			/* bitpos */
    815 	 complain_overflow_bitfield, /* complain_on_overflow */
    816 	 0,			/* special_function */
    817 	 "R_GL",		/* name */
    818 	 TRUE,			/* partial_inplace */
    819 	 0xffff,		/* src_mask */
    820 	 0xffff,		/* dst_mask */
    821 	 FALSE),		/* pcrel_offset */
    822 
    823   /* Local TOC relative symbol.	 */
    824   HOWTO (R_TCL,			/* type */
    825 	 0,			/* rightshift */
    826 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    827 	 16,			/* bitsize */
    828 	 FALSE,			/* pc_relative */
    829 	 0,			/* bitpos */
    830 	 complain_overflow_bitfield, /* complain_on_overflow */
    831 	 0,			/* special_function */
    832 	 "R_TCL",		/* name */
    833 	 TRUE,			/* partial_inplace */
    834 	 0xffff,		/* src_mask */
    835 	 0xffff,		/* dst_mask */
    836 	 FALSE),		/* pcrel_offset */
    837 
    838   EMPTY_HOWTO (7),
    839 
    840   /* Non modifiable absolute branch.  */
    841   HOWTO (R_BA,			/* type */
    842 	 0,			/* rightshift */
    843 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    844 	 26,			/* bitsize */
    845 	 FALSE,			/* pc_relative */
    846 	 0,			/* bitpos */
    847 	 complain_overflow_bitfield, /* complain_on_overflow */
    848 	 0,			/* special_function */
    849 	 "R_BA_26",		/* name */
    850 	 TRUE,			/* partial_inplace */
    851 	 0x03fffffc,		/* src_mask */
    852 	 0x03fffffc,		/* dst_mask */
    853 	 FALSE),		/* pcrel_offset */
    854 
    855   EMPTY_HOWTO (9),
    856 
    857   /* Non modifiable relative branch.  */
    858   HOWTO (R_BR,			/* type */
    859 	 0,			/* rightshift */
    860 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    861 	 26,			/* bitsize */
    862 	 TRUE,			/* pc_relative */
    863 	 0,			/* bitpos */
    864 	 complain_overflow_signed, /* complain_on_overflow */
    865 	 0,			/* special_function */
    866 	 "R_BR",		/* name */
    867 	 TRUE,			/* partial_inplace */
    868 	 0x03fffffc,		/* src_mask */
    869 	 0x03fffffc,		/* dst_mask */
    870 	 FALSE),		/* pcrel_offset */
    871 
    872   EMPTY_HOWTO (0xb),
    873 
    874   /* Indirect load.  */
    875   HOWTO (R_RL,			/* type */
    876 	 0,			/* rightshift */
    877 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    878 	 16,			/* bitsize */
    879 	 FALSE,			/* pc_relative */
    880 	 0,			/* bitpos */
    881 	 complain_overflow_bitfield, /* complain_on_overflow */
    882 	 0,			/* special_function */
    883 	 "R_RL",		/* name */
    884 	 TRUE,			/* partial_inplace */
    885 	 0xffff,		/* src_mask */
    886 	 0xffff,		/* dst_mask */
    887 	 FALSE),		/* pcrel_offset */
    888 
    889   /* Load address.  */
    890   HOWTO (R_RLA,			/* type */
    891 	 0,			/* rightshift */
    892 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    893 	 16,			/* bitsize */
    894 	 FALSE,			/* pc_relative */
    895 	 0,			/* bitpos */
    896 	 complain_overflow_bitfield, /* complain_on_overflow */
    897 	 0,			/* special_function */
    898 	 "R_RLA",		/* name */
    899 	 TRUE,			/* partial_inplace */
    900 	 0xffff,		/* src_mask */
    901 	 0xffff,		/* dst_mask */
    902 	 FALSE),		/* pcrel_offset */
    903 
    904   EMPTY_HOWTO (0xe),
    905 
    906   /* Non-relocating reference.  Bitsize is 1 so that r_rsize is 0.  */
    907   HOWTO (R_REF,			/* type */
    908 	 0,			/* rightshift */
    909 	 0,			/* size (0 = byte, 1 = short, 2 = long) */
    910 	 1,			/* bitsize */
    911 	 FALSE,			/* pc_relative */
    912 	 0,			/* bitpos */
    913 	 complain_overflow_dont, /* complain_on_overflow */
    914 	 0,			/* special_function */
    915 	 "R_REF",		/* name */
    916 	 FALSE,			/* partial_inplace */
    917 	 0,			/* src_mask */
    918 	 0,			/* dst_mask */
    919 	 FALSE),		/* pcrel_offset */
    920 
    921   EMPTY_HOWTO (0x10),
    922   EMPTY_HOWTO (0x11),
    923 
    924   /* TOC relative indirect load.  */
    925   HOWTO (R_TRL,			/* type */
    926 	 0,			/* rightshift */
    927 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    928 	 16,			/* bitsize */
    929 	 FALSE,			/* pc_relative */
    930 	 0,			/* bitpos */
    931 	 complain_overflow_bitfield, /* complain_on_overflow */
    932 	 0,			/* special_function */
    933 	 "R_TRL",		/* name */
    934 	 TRUE,			/* partial_inplace */
    935 	 0xffff,		/* src_mask */
    936 	 0xffff,		/* dst_mask */
    937 	 FALSE),		/* pcrel_offset */
    938 
    939   /* TOC relative load address.  */
    940   HOWTO (R_TRLA,		/* type */
    941 	 0,			/* rightshift */
    942 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    943 	 16,			/* bitsize */
    944 	 FALSE,			/* pc_relative */
    945 	 0,			/* bitpos */
    946 	 complain_overflow_bitfield, /* complain_on_overflow */
    947 	 0,			/* special_function */
    948 	 "R_TRLA",		/* name */
    949 	 TRUE,			/* partial_inplace */
    950 	 0xffff,		/* src_mask */
    951 	 0xffff,		/* dst_mask */
    952 	 FALSE),		/* pcrel_offset */
    953 
    954   /* Modifiable relative branch.  */
    955   HOWTO (R_RRTBI,		 /* type */
    956 	 1,			/* rightshift */
    957 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    958 	 32,			/* bitsize */
    959 	 FALSE,			/* pc_relative */
    960 	 0,			/* bitpos */
    961 	 complain_overflow_bitfield, /* complain_on_overflow */
    962 	 0,			/* special_function */
    963 	 "R_RRTBI",		/* name */
    964 	 TRUE,			/* partial_inplace */
    965 	 0xffffffff,		/* src_mask */
    966 	 0xffffffff,		/* dst_mask */
    967 	 FALSE),		/* pcrel_offset */
    968 
    969   /* Modifiable absolute branch.  */
    970   HOWTO (R_RRTBA,		 /* type */
    971 	 1,			/* rightshift */
    972 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
    973 	 32,			/* bitsize */
    974 	 FALSE,			/* pc_relative */
    975 	 0,			/* bitpos */
    976 	 complain_overflow_bitfield, /* complain_on_overflow */
    977 	 0,			/* special_function */
    978 	 "R_RRTBA",		/* name */
    979 	 TRUE,			/* partial_inplace */
    980 	 0xffffffff,		/* src_mask */
    981 	 0xffffffff,		/* dst_mask */
    982 	 FALSE),		/* pcrel_offset */
    983 
    984   /* Modifiable call absolute indirect.  */
    985   HOWTO (R_CAI,			/* type */
    986 	 0,			/* rightshift */
    987 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
    988 	 16,			/* bitsize */
    989 	 FALSE,			/* pc_relative */
    990 	 0,			/* bitpos */
    991 	 complain_overflow_bitfield, /* complain_on_overflow */
    992 	 0,			/* special_function */
    993 	 "R_CAI",		/* name */
    994 	 TRUE,			/* partial_inplace */
    995 	 0xffff,		/* src_mask */
    996 	 0xffff,		/* dst_mask */
    997 	 FALSE),		/* pcrel_offset */
    998 
    999   /* Modifiable call relative.  */
   1000   HOWTO (R_CREL,		/* type */
   1001 	 0,			/* rightshift */
   1002 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   1003 	 16,			/* bitsize */
   1004 	 FALSE,			/* pc_relative */
   1005 	 0,			/* bitpos */
   1006 	 complain_overflow_bitfield, /* complain_on_overflow */
   1007 	 0,			/* special_function */
   1008 	 "R_CREL",		/* name */
   1009 	 TRUE,			/* partial_inplace */
   1010 	 0xffff,		/* src_mask */
   1011 	 0xffff,		/* dst_mask */
   1012 	 FALSE),		/* pcrel_offset */
   1013 
   1014   /* Modifiable branch absolute.  */
   1015   HOWTO (R_RBA,			/* type */
   1016 	 0,			/* rightshift */
   1017 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1018 	 26,			/* bitsize */
   1019 	 FALSE,			/* pc_relative */
   1020 	 0,			/* bitpos */
   1021 	 complain_overflow_bitfield, /* complain_on_overflow */
   1022 	 0,			/* special_function */
   1023 	 "R_RBA",		/* name */
   1024 	 TRUE,			/* partial_inplace */
   1025 	 0x03fffffc,		/* src_mask */
   1026 	 0x03fffffc,		/* dst_mask */
   1027 	 FALSE),		/* pcrel_offset */
   1028 
   1029   /* Modifiable branch absolute.  */
   1030   HOWTO (R_RBAC,		/* type */
   1031 	 0,			/* rightshift */
   1032 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1033 	 32,			/* bitsize */
   1034 	 FALSE,			/* pc_relative */
   1035 	 0,			/* bitpos */
   1036 	 complain_overflow_bitfield, /* complain_on_overflow */
   1037 	 0,			/* special_function */
   1038 	 "R_RBAC",		/* name */
   1039 	 TRUE,			/* partial_inplace */
   1040 	 0xffffffff,		/* src_mask */
   1041 	 0xffffffff,		/* dst_mask */
   1042 	 FALSE),		/* pcrel_offset */
   1043 
   1044   /* Modifiable branch relative.  */
   1045   HOWTO (R_RBR,			/* type */
   1046 	 0,			/* rightshift */
   1047 	 2,			/* size (0 = byte, 1 = short, 2 = long) */
   1048 	 26,			/* bitsize */
   1049 	 FALSE,			/* pc_relative */
   1050 	 0,			/* bitpos */
   1051 	 complain_overflow_signed, /* complain_on_overflow */
   1052 	 0,			/* special_function */
   1053 	 "R_RBR_26",		/* name */
   1054 	 TRUE,			/* partial_inplace */
   1055 	 0x03fffffc,		/* src_mask */
   1056 	 0x03fffffc,		/* dst_mask */
   1057 	 FALSE),		/* pcrel_offset */
   1058 
   1059   /* Modifiable branch absolute.  */
   1060   HOWTO (R_RBRC,		/* type */
   1061 	 0,			/* rightshift */
   1062 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   1063 	 16,			/* bitsize */
   1064 	 FALSE,			/* pc_relative */
   1065 	 0,			/* bitpos */
   1066 	 complain_overflow_bitfield, /* complain_on_overflow */
   1067 	 0,			/* special_function */
   1068 	 "R_RBRC",		/* name */
   1069 	 TRUE,			/* partial_inplace */
   1070 	 0xffff,		/* src_mask */
   1071 	 0xffff,		/* dst_mask */
   1072 	 FALSE),		/* pcrel_offset */
   1073 
   1074   /* 16 bit Non modifiable absolute branch.  */
   1075   HOWTO (R_BA,			/* type */
   1076 	 0,			/* rightshift */
   1077 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   1078 	 16,			/* bitsize */
   1079 	 FALSE,			/* pc_relative */
   1080 	 0,			/* bitpos */
   1081 	 complain_overflow_bitfield, /* complain_on_overflow */
   1082 	 0,			/* special_function */
   1083 	 "R_BA_16",		/* name */
   1084 	 TRUE,			/* partial_inplace */
   1085 	 0xfffc,		/* src_mask */
   1086 	 0xfffc,		/* dst_mask */
   1087 	 FALSE),		/* pcrel_offset */
   1088 
   1089   /* Modifiable branch relative.  */
   1090   HOWTO (R_RBR,			/* type */
   1091 	 0,			/* rightshift */
   1092 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   1093 	 16,			/* bitsize */
   1094 	 FALSE,			/* pc_relative */
   1095 	 0,			/* bitpos */
   1096 	 complain_overflow_signed, /* complain_on_overflow */
   1097 	 0,			/* special_function */
   1098 	 "R_RBR_16",		/* name */
   1099 	 TRUE,			/* partial_inplace */
   1100 	 0xffff,		/* src_mask */
   1101 	 0xffff,		/* dst_mask */
   1102 	 FALSE),		/* pcrel_offset */
   1103 
   1104   /* Modifiable branch relative.  */
   1105   HOWTO (R_RBA,			/* type */
   1106 	 0,			/* rightshift */
   1107 	 1,			/* size (0 = byte, 1 = short, 2 = long) */
   1108 	 16,			/* bitsize */
   1109 	 FALSE,			/* pc_relative */
   1110 	 0,			/* bitpos */
   1111 	 complain_overflow_signed, /* complain_on_overflow */
   1112 	 0,			/* special_function */
   1113 	 "R_RBA_16",		/* name */
   1114 	 TRUE,			/* partial_inplace */
   1115 	 0xffff,		/* src_mask */
   1116 	 0xffff,		/* dst_mask */
   1117 	 FALSE),		/* pcrel_offset */
   1118 
   1119 };
   1120 
   1121 void
   1122 xcoff_rtype2howto (relent, internal)
   1123      arelent *relent;
   1124      struct internal_reloc *internal;
   1125 {
   1126   if (internal->r_type > R_RBRC)
   1127     abort ();
   1128 
   1129   /* Default howto layout works most of the time */
   1130   relent->howto = &xcoff_howto_table[internal->r_type];
   1131 
   1132   /* Special case some 16 bit reloc */
   1133   if (15 == (internal->r_size & 0x1f))
   1134     {
   1135       if (R_BA == internal->r_type)
   1136 	relent->howto = &xcoff_howto_table[0x1c];
   1137       else if (R_RBR == internal->r_type)
   1138 	relent->howto = &xcoff_howto_table[0x1d];
   1139       else if (R_RBA == internal->r_type)
   1140 	relent->howto = &xcoff_howto_table[0x1e];
   1141     }
   1142 
   1143   /* The r_size field of an XCOFF reloc encodes the bitsize of the
   1144      relocation, as well as indicating whether it is signed or not.
   1145      Doublecheck that the relocation information gathered from the
   1146      type matches this information.  The bitsize is not significant
   1147      for R_REF relocs.  */
   1148   if (relent->howto->dst_mask != 0
   1149       && (relent->howto->bitsize
   1150 	  != ((unsigned int) internal->r_size & 0x1f) + 1))
   1151     abort ();
   1152 }
   1153 
   1154 reloc_howto_type *
   1155 _bfd_xcoff_reloc_type_lookup (abfd, code)
   1156      bfd *abfd ATTRIBUTE_UNUSED;
   1157      bfd_reloc_code_real_type code;
   1158 {
   1159   switch (code)
   1160     {
   1161     case BFD_RELOC_PPC_B26:
   1162       return &xcoff_howto_table[0xa];
   1163     case BFD_RELOC_PPC_BA16:
   1164       return &xcoff_howto_table[0x1c];
   1165     case BFD_RELOC_PPC_BA26:
   1166       return &xcoff_howto_table[8];
   1167     case BFD_RELOC_PPC_TOC16:
   1168       return &xcoff_howto_table[3];
   1169     case BFD_RELOC_32:
   1170     case BFD_RELOC_CTOR:
   1171       return &xcoff_howto_table[0];
   1172     case BFD_RELOC_NONE:
   1173       return &xcoff_howto_table[0xf];
   1174     default:
   1175       return NULL;
   1176     }
   1177 }
   1178 
   1179 static reloc_howto_type *
   1180 _bfd_xcoff_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
   1181 			      const char *r_name)
   1182 {
   1183   unsigned int i;
   1184 
   1185   for (i = 0;
   1186        i < sizeof (xcoff_howto_table) / sizeof (xcoff_howto_table[0]);
   1187        i++)
   1188     if (xcoff_howto_table[i].name != NULL
   1189 	&& strcasecmp (xcoff_howto_table[i].name, r_name) == 0)
   1190       return &xcoff_howto_table[i];
   1191 
   1192   return NULL;
   1193 }
   1194 
   1195 /* XCOFF archive support.  The original version of this code was by
   1197    Damon A. Permezel.  It was enhanced to permit cross support, and
   1198    writing archive files, by Ian Lance Taylor, Cygnus Support.
   1199 
   1200    XCOFF uses its own archive format.  Everything is hooked together
   1201    with file offset links, so it is possible to rapidly update an
   1202    archive in place.  Of course, we don't do that.  An XCOFF archive
   1203    has a real file header, not just an ARMAG string.  The structure of
   1204    the file header and of each archive header appear below.
   1205 
   1206    An XCOFF archive also has a member table, which is a list of
   1207    elements in the archive (you can get that by looking through the
   1208    linked list, but you have to read a lot more of the file).  The
   1209    member table has a normal archive header with an empty name.  It is
   1210    normally (and perhaps must be) the second to last entry in the
   1211    archive.  The member table data is almost printable ASCII.  It
   1212    starts with a 12 character decimal string which is the number of
   1213    entries in the table.  For each entry it has a 12 character decimal
   1214    string which is the offset in the archive of that member.  These
   1215    entries are followed by a series of null terminated strings which
   1216    are the member names for each entry.
   1217 
   1218    Finally, an XCOFF archive has a global symbol table, which is what
   1219    we call the armap.  The global symbol table has a normal archive
   1220    header with an empty name.  It is normally (and perhaps must be)
   1221    the last entry in the archive.  The contents start with a four byte
   1222    binary number which is the number of entries.  This is followed by
   1223    a that many four byte binary numbers; each is the file offset of an
   1224    entry in the archive.  These numbers are followed by a series of
   1225    null terminated strings, which are symbol names.
   1226 
   1227    AIX 4.3 introduced a new archive format which can handle larger
   1228    files and also 32- and 64-bit objects in the same archive.  The
   1229    things said above remain true except that there is now more than
   1230    one global symbol table.  The one is used to index 32-bit objects,
   1231    the other for 64-bit objects.
   1232 
   1233    The new archives (recognizable by the new ARMAG string) has larger
   1234    field lengths so that we cannot really share any code.  Also we have
   1235    to take care that we are not generating the new form of archives
   1236    on AIX 4.2 or earlier systems.  */
   1237 
   1238 /* XCOFF archives use this as a magic string.  Note that both strings
   1239    have the same length.  */
   1240 
   1241 /* Set the magic for archive.  */
   1242 
   1243 bfd_boolean
   1244 bfd_xcoff_ar_archive_set_magic (abfd, magic)
   1245      bfd *abfd ATTRIBUTE_UNUSED;
   1246      char *magic ATTRIBUTE_UNUSED;
   1247 {
   1248   /* Not supported yet.  */
   1249   return FALSE;
   1250  /* bfd_xcoff_archive_set_magic (abfd, magic); */
   1251 }
   1252 
   1253 /* Read in the armap of an XCOFF archive.  */
   1254 
   1255 bfd_boolean
   1256 _bfd_xcoff_slurp_armap (abfd)
   1257      bfd *abfd;
   1258 {
   1259   file_ptr off;
   1260   size_t namlen;
   1261   bfd_size_type sz;
   1262   bfd_byte *contents, *cend;
   1263   bfd_vma c, i;
   1264   carsym *arsym;
   1265   bfd_byte *p;
   1266 
   1267   if (xcoff_ardata (abfd) == NULL)
   1268     {
   1269       bfd_has_map (abfd) = FALSE;
   1270       return TRUE;
   1271     }
   1272 
   1273   if (! xcoff_big_format_p (abfd))
   1274     {
   1275       /* This is for the old format.  */
   1276       struct xcoff_ar_hdr hdr;
   1277 
   1278       off = strtol (xcoff_ardata (abfd)->symoff, (char **) NULL, 10);
   1279       if (off == 0)
   1280 	{
   1281 	  bfd_has_map (abfd) = FALSE;
   1282 	  return TRUE;
   1283 	}
   1284 
   1285       if (bfd_seek (abfd, off, SEEK_SET) != 0)
   1286 	return FALSE;
   1287 
   1288       /* The symbol table starts with a normal archive header.  */
   1289       if (bfd_bread ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
   1290 	  != SIZEOF_AR_HDR)
   1291 	return FALSE;
   1292 
   1293       /* Skip the name (normally empty).  */
   1294       namlen = strtol (hdr.namlen, (char **) NULL, 10);
   1295       off = ((namlen + 1) & ~ (size_t) 1) + SXCOFFARFMAG;
   1296       if (bfd_seek (abfd, off, SEEK_CUR) != 0)
   1297 	return FALSE;
   1298 
   1299       sz = strtol (hdr.size, (char **) NULL, 10);
   1300 
   1301       /* Read in the entire symbol table.  */
   1302       contents = (bfd_byte *) bfd_alloc (abfd, sz);
   1303       if (contents == NULL)
   1304 	return FALSE;
   1305       if (bfd_bread ((PTR) contents, sz, abfd) != sz)
   1306 	return FALSE;
   1307 
   1308       /* The symbol table starts with a four byte count.  */
   1309       c = H_GET_32 (abfd, contents);
   1310 
   1311       if (c * 4 >= sz)
   1312 	{
   1313 	  bfd_set_error (bfd_error_bad_value);
   1314 	  return FALSE;
   1315 	}
   1316 
   1317       bfd_ardata (abfd)->symdefs =
   1318 	((carsym *) bfd_alloc (abfd, c * sizeof (carsym)));
   1319       if (bfd_ardata (abfd)->symdefs == NULL)
   1320 	return FALSE;
   1321 
   1322       /* After the count comes a list of four byte file offsets.  */
   1323       for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 4;
   1324 	   i < c;
   1325 	   ++i, ++arsym, p += 4)
   1326 	arsym->file_offset = H_GET_32 (abfd, p);
   1327     }
   1328   else
   1329     {
   1330       /* This is for the new format.  */
   1331       struct xcoff_ar_hdr_big hdr;
   1332 
   1333       off = strtol (xcoff_ardata_big (abfd)->symoff, (char **) NULL, 10);
   1334       if (off == 0)
   1335 	{
   1336 	  bfd_has_map (abfd) = FALSE;
   1337 	  return TRUE;
   1338 	}
   1339 
   1340       if (bfd_seek (abfd, off, SEEK_SET) != 0)
   1341 	return FALSE;
   1342 
   1343       /* The symbol table starts with a normal archive header.  */
   1344       if (bfd_bread ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR_BIG, abfd)
   1345 	  != SIZEOF_AR_HDR_BIG)
   1346 	return FALSE;
   1347 
   1348       /* Skip the name (normally empty).  */
   1349       namlen = strtol (hdr.namlen, (char **) NULL, 10);
   1350       off = ((namlen + 1) & ~ (size_t) 1) + SXCOFFARFMAG;
   1351       if (bfd_seek (abfd, off, SEEK_CUR) != 0)
   1352 	return FALSE;
   1353 
   1354       /* XXX This actually has to be a call to strtoll (at least on 32-bit
   1355 	 machines) since the field width is 20 and there numbers with more
   1356 	 than 32 bits can be represented.  */
   1357       sz = strtol (hdr.size, (char **) NULL, 10);
   1358 
   1359       /* Read in the entire symbol table.  */
   1360       contents = (bfd_byte *) bfd_alloc (abfd, sz);
   1361       if (contents == NULL)
   1362 	return FALSE;
   1363       if (bfd_bread ((PTR) contents, sz, abfd) != sz)
   1364 	return FALSE;
   1365 
   1366       /* The symbol table starts with an eight byte count.  */
   1367       c = H_GET_64 (abfd, contents);
   1368 
   1369       if (c * 8 >= sz)
   1370 	{
   1371 	  bfd_set_error (bfd_error_bad_value);
   1372 	  return FALSE;
   1373 	}
   1374 
   1375       bfd_ardata (abfd)->symdefs =
   1376 	((carsym *) bfd_alloc (abfd, c * sizeof (carsym)));
   1377       if (bfd_ardata (abfd)->symdefs == NULL)
   1378 	return FALSE;
   1379 
   1380       /* After the count comes a list of eight byte file offsets.  */
   1381       for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 8;
   1382 	   i < c;
   1383 	   ++i, ++arsym, p += 8)
   1384 	arsym->file_offset = H_GET_64 (abfd, p);
   1385     }
   1386 
   1387   /* After the file offsets come null terminated symbol names.  */
   1388   cend = contents + sz;
   1389   for (i = 0, arsym = bfd_ardata (abfd)->symdefs;
   1390        i < c;
   1391        ++i, ++arsym, p += strlen ((char *) p) + 1)
   1392     {
   1393       if (p >= cend)
   1394 	{
   1395 	  bfd_set_error (bfd_error_bad_value);
   1396 	  return FALSE;
   1397 	}
   1398       arsym->name = (char *) p;
   1399     }
   1400 
   1401   bfd_ardata (abfd)->symdef_count = c;
   1402   bfd_has_map (abfd) = TRUE;
   1403 
   1404   return TRUE;
   1405 }
   1406 
   1407 /* See if this is an XCOFF archive.  */
   1408 
   1409 const bfd_target *
   1410 _bfd_xcoff_archive_p (abfd)
   1411      bfd *abfd;
   1412 {
   1413   struct artdata *tdata_hold;
   1414   char magic[SXCOFFARMAG];
   1415   bfd_size_type amt = SXCOFFARMAG;
   1416 
   1417   if (bfd_bread ((PTR) magic, amt, abfd) != amt)
   1418     {
   1419       if (bfd_get_error () != bfd_error_system_call)
   1420 	bfd_set_error (bfd_error_wrong_format);
   1421       return NULL;
   1422     }
   1423 
   1424   if (strncmp (magic, XCOFFARMAG, SXCOFFARMAG) != 0
   1425       && strncmp (magic, XCOFFARMAGBIG, SXCOFFARMAG) != 0)
   1426     {
   1427       bfd_set_error (bfd_error_wrong_format);
   1428       return NULL;
   1429     }
   1430 
   1431   tdata_hold = bfd_ardata (abfd);
   1432 
   1433   amt = sizeof (struct artdata);
   1434   bfd_ardata (abfd) = (struct artdata *) bfd_zalloc (abfd, amt);
   1435   if (bfd_ardata (abfd) == (struct artdata *) NULL)
   1436     goto error_ret_restore;
   1437 
   1438   /* Cleared by bfd_zalloc above.
   1439      bfd_ardata (abfd)->cache = NULL;
   1440      bfd_ardata (abfd)->archive_head = NULL;
   1441      bfd_ardata (abfd)->symdefs = NULL;
   1442      bfd_ardata (abfd)->extended_names = NULL;
   1443      bfd_ardata (abfd)->extended_names_size = 0;  */
   1444 
   1445   /* Now handle the two formats.  */
   1446   if (magic[1] != 'b')
   1447     {
   1448       /* This is the old format.  */
   1449       struct xcoff_ar_file_hdr hdr;
   1450 
   1451       /* Copy over the magic string.  */
   1452       memcpy (hdr.magic, magic, SXCOFFARMAG);
   1453 
   1454       /* Now read the rest of the file header.  */
   1455       amt = SIZEOF_AR_FILE_HDR - SXCOFFARMAG;
   1456       if (bfd_bread ((PTR) &hdr.memoff, amt, abfd) != amt)
   1457 	{
   1458 	  if (bfd_get_error () != bfd_error_system_call)
   1459 	    bfd_set_error (bfd_error_wrong_format);
   1460 	  goto error_ret;
   1461 	}
   1462 
   1463       bfd_ardata (abfd)->first_file_filepos = strtol (hdr.firstmemoff,
   1464 						      (char **) NULL, 10);
   1465 
   1466       amt = SIZEOF_AR_FILE_HDR;
   1467       bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, amt);
   1468       if (bfd_ardata (abfd)->tdata == NULL)
   1469 	goto error_ret;
   1470 
   1471       memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR);
   1472     }
   1473   else
   1474     {
   1475       /* This is the new format.  */
   1476       struct xcoff_ar_file_hdr_big hdr;
   1477 
   1478       /* Copy over the magic string.  */
   1479       memcpy (hdr.magic, magic, SXCOFFARMAG);
   1480 
   1481       /* Now read the rest of the file header.  */
   1482       amt = SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG;
   1483       if (bfd_bread ((PTR) &hdr.memoff, amt, abfd) != amt)
   1484 	{
   1485 	  if (bfd_get_error () != bfd_error_system_call)
   1486 	    bfd_set_error (bfd_error_wrong_format);
   1487 	  goto error_ret;
   1488 	}
   1489 
   1490       bfd_ardata (abfd)->first_file_filepos = bfd_scan_vma (hdr.firstmemoff,
   1491 							    (const char **) 0,
   1492 							    10);
   1493 
   1494       amt = SIZEOF_AR_FILE_HDR_BIG;
   1495       bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, amt);
   1496       if (bfd_ardata (abfd)->tdata == NULL)
   1497 	goto error_ret;
   1498 
   1499       memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR_BIG);
   1500     }
   1501 
   1502   if (! _bfd_xcoff_slurp_armap (abfd))
   1503     {
   1504     error_ret:
   1505       bfd_release (abfd, bfd_ardata (abfd));
   1506     error_ret_restore:
   1507       bfd_ardata (abfd) = tdata_hold;
   1508       return NULL;
   1509     }
   1510 
   1511   return abfd->xvec;
   1512 }
   1513 
   1514 /* Read the archive header in an XCOFF archive.  */
   1515 
   1516 PTR
   1517 _bfd_xcoff_read_ar_hdr (abfd)
   1518      bfd *abfd;
   1519 {
   1520   bfd_size_type namlen;
   1521   struct areltdata *ret;
   1522   bfd_size_type amt = sizeof (struct areltdata);
   1523 
   1524   ret = (struct areltdata *) bfd_alloc (abfd, amt);
   1525   if (ret == NULL)
   1526     return NULL;
   1527 
   1528   if (! xcoff_big_format_p (abfd))
   1529     {
   1530       struct xcoff_ar_hdr hdr;
   1531       struct xcoff_ar_hdr *hdrp;
   1532 
   1533       if (bfd_bread ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
   1534 	  != SIZEOF_AR_HDR)
   1535 	{
   1536 	  free (ret);
   1537 	  return NULL;
   1538 	}
   1539 
   1540       namlen = strtol (hdr.namlen, (char **) NULL, 10);
   1541       amt = SIZEOF_AR_HDR + namlen + 1;
   1542       hdrp = (struct xcoff_ar_hdr *) bfd_alloc (abfd, amt);
   1543       if (hdrp == NULL)
   1544 	{
   1545 	  free (ret);
   1546 	  return NULL;
   1547 	}
   1548       memcpy (hdrp, &hdr, SIZEOF_AR_HDR);
   1549       if (bfd_bread ((char *) hdrp + SIZEOF_AR_HDR, namlen, abfd) != namlen)
   1550 	{
   1551 	  free (ret);
   1552 	  return NULL;
   1553 	}
   1554       ((char *) hdrp)[SIZEOF_AR_HDR + namlen] = '\0';
   1555 
   1556       ret->arch_header = (char *) hdrp;
   1557       ret->parsed_size = strtol (hdr.size, (char **) NULL, 10);
   1558       ret->filename = (char *) hdrp + SIZEOF_AR_HDR;
   1559     }
   1560   else
   1561     {
   1562       struct xcoff_ar_hdr_big hdr;
   1563       struct xcoff_ar_hdr_big *hdrp;
   1564 
   1565       if (bfd_bread ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR_BIG, abfd)
   1566 	  != SIZEOF_AR_HDR_BIG)
   1567 	{
   1568 	  free (ret);
   1569 	  return NULL;
   1570 	}
   1571 
   1572       namlen = strtol (hdr.namlen, (char **) NULL, 10);
   1573       amt = SIZEOF_AR_HDR_BIG + namlen + 1;
   1574       hdrp = (struct xcoff_ar_hdr_big *) bfd_alloc (abfd, amt);
   1575       if (hdrp == NULL)
   1576 	{
   1577 	  free (ret);
   1578 	  return NULL;
   1579 	}
   1580       memcpy (hdrp, &hdr, SIZEOF_AR_HDR_BIG);
   1581       if (bfd_bread ((char *) hdrp + SIZEOF_AR_HDR_BIG, namlen, abfd) != namlen)
   1582 	{
   1583 	  free (ret);
   1584 	  return NULL;
   1585 	}
   1586       ((char *) hdrp)[SIZEOF_AR_HDR_BIG + namlen] = '\0';
   1587 
   1588       ret->arch_header = (char *) hdrp;
   1589       /* XXX This actually has to be a call to strtoll (at least on 32-bit
   1590 	 machines) since the field width is 20 and there numbers with more
   1591 	 than 32 bits can be represented.  */
   1592       ret->parsed_size = strtol (hdr.size, (char **) NULL, 10);
   1593       ret->filename = (char *) hdrp + SIZEOF_AR_HDR_BIG;
   1594     }
   1595 
   1596   /* Skip over the XCOFFARFMAG at the end of the file name.  */
   1597   if (bfd_seek (abfd, (file_ptr) ((namlen & 1) + SXCOFFARFMAG), SEEK_CUR) != 0)
   1598     return NULL;
   1599 
   1600   return (PTR) ret;
   1601 }
   1602 
   1603 /* Open the next element in an XCOFF archive.  */
   1604 
   1605 bfd *
   1606 _bfd_xcoff_openr_next_archived_file (archive, last_file)
   1607      bfd *archive;
   1608      bfd *last_file;
   1609 {
   1610   file_ptr filestart;
   1611 
   1612   if (xcoff_ardata (archive) == NULL)
   1613     {
   1614       bfd_set_error (bfd_error_invalid_operation);
   1615       return NULL;
   1616     }
   1617 
   1618   if (! xcoff_big_format_p (archive))
   1619     {
   1620       if (last_file == NULL)
   1621 	filestart = bfd_ardata (archive)->first_file_filepos;
   1622       else
   1623 	filestart = strtol (arch_xhdr (last_file)->nextoff, (char **) NULL,
   1624 			    10);
   1625 
   1626       if (filestart == 0
   1627 	  || filestart == strtol (xcoff_ardata (archive)->memoff,
   1628 				  (char **) NULL, 10)
   1629 	  || filestart == strtol (xcoff_ardata (archive)->symoff,
   1630 				  (char **) NULL, 10))
   1631 	{
   1632 	  bfd_set_error (bfd_error_no_more_archived_files);
   1633 	  return NULL;
   1634 	}
   1635     }
   1636   else
   1637     {
   1638       if (last_file == NULL)
   1639 	filestart = bfd_ardata (archive)->first_file_filepos;
   1640       else
   1641 	/* XXX These actually have to be a calls to strtoll (at least
   1642 	   on 32-bit machines) since the fields's width is 20 and
   1643 	   there numbers with more than 32 bits can be represented.  */
   1644 	filestart = strtol (arch_xhdr_big (last_file)->nextoff, (char **) NULL,
   1645 			    10);
   1646 
   1647       /* XXX These actually have to be calls to strtoll (at least on 32-bit
   1648 	 machines) since the fields's width is 20 and there numbers with more
   1649 	 than 32 bits can be represented.  */
   1650       if (filestart == 0
   1651 	  || filestart == strtol (xcoff_ardata_big (archive)->memoff,
   1652 				  (char **) NULL, 10)
   1653 	  || filestart == strtol (xcoff_ardata_big (archive)->symoff,
   1654 				  (char **) NULL, 10))
   1655 	{
   1656 	  bfd_set_error (bfd_error_no_more_archived_files);
   1657 	  return NULL;
   1658 	}
   1659     }
   1660 
   1661   return _bfd_get_elt_at_filepos (archive, filestart);
   1662 }
   1663 
   1664 /* Stat an element in an XCOFF archive.  */
   1665 
   1666 int
   1667 _bfd_xcoff_stat_arch_elt (abfd, s)
   1668      bfd *abfd;
   1669      struct stat *s;
   1670 {
   1671   if (abfd->arelt_data == NULL)
   1672     {
   1673       bfd_set_error (bfd_error_invalid_operation);
   1674       return -1;
   1675     }
   1676 
   1677   if (! xcoff_big_format_p (abfd->my_archive))
   1678     {
   1679       struct xcoff_ar_hdr *hdrp = arch_xhdr (abfd);
   1680 
   1681       s->st_mtime = strtol (hdrp->date, (char **) NULL, 10);
   1682       s->st_uid = strtol (hdrp->uid, (char **) NULL, 10);
   1683       s->st_gid = strtol (hdrp->gid, (char **) NULL, 10);
   1684       s->st_mode = strtol (hdrp->mode, (char **) NULL, 8);
   1685       s->st_size = arch_eltdata (abfd)->parsed_size;
   1686     }
   1687   else
   1688     {
   1689       struct xcoff_ar_hdr_big *hdrp = arch_xhdr_big (abfd);
   1690 
   1691       s->st_mtime = strtol (hdrp->date, (char **) NULL, 10);
   1692       s->st_uid = strtol (hdrp->uid, (char **) NULL, 10);
   1693       s->st_gid = strtol (hdrp->gid, (char **) NULL, 10);
   1694       s->st_mode = strtol (hdrp->mode, (char **) NULL, 8);
   1695       s->st_size = arch_eltdata (abfd)->parsed_size;
   1696     }
   1697 
   1698   return 0;
   1699 }
   1700 
   1701 /* Normalize a file name for inclusion in an archive.  */
   1702 
   1703 static const char *
   1704 normalize_filename (abfd)
   1705      bfd *abfd;
   1706 {
   1707   const char *file;
   1708   const char *filename;
   1709 
   1710   file = bfd_get_filename (abfd);
   1711   filename = strrchr (file, '/');
   1712   if (filename != NULL)
   1713     filename++;
   1714   else
   1715     filename = file;
   1716   return filename;
   1717 }
   1718 
   1719 /* Write out an XCOFF armap.  */
   1720 
   1721 static bfd_boolean
   1722 xcoff_write_armap_old (abfd, elength, map, orl_count, stridx)
   1723      bfd *abfd;
   1724      unsigned int elength ATTRIBUTE_UNUSED;
   1725      struct orl *map;
   1726      unsigned int orl_count;
   1727      int stridx;
   1728 {
   1729   struct archive_iterator iterator;
   1730   struct xcoff_ar_hdr hdr;
   1731   char *p;
   1732   unsigned char buf[4];
   1733   unsigned int i;
   1734 
   1735   memset (&hdr, 0, sizeof hdr);
   1736   sprintf (hdr.size, "%ld", (long) (4 + orl_count * 4 + stridx));
   1737   sprintf (hdr.nextoff, "%d", 0);
   1738   memcpy (hdr.prevoff, xcoff_ardata (abfd)->memoff, XCOFFARMAG_ELEMENT_SIZE);
   1739   sprintf (hdr.date, "%d", 0);
   1740   sprintf (hdr.uid, "%d", 0);
   1741   sprintf (hdr.gid, "%d", 0);
   1742   sprintf (hdr.mode, "%d", 0);
   1743   sprintf (hdr.namlen, "%d", 0);
   1744 
   1745   /* We need spaces, not null bytes, in the header.  */
   1746   for (p = (char *) &hdr; p < (char *) &hdr + SIZEOF_AR_HDR; p++)
   1747     if (*p == '\0')
   1748       *p = ' ';
   1749 
   1750   if (bfd_bwrite ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
   1751       != SIZEOF_AR_HDR
   1752       || (bfd_bwrite (XCOFFARFMAG, (bfd_size_type) SXCOFFARFMAG, abfd)
   1753 	  != SXCOFFARFMAG))
   1754     return FALSE;
   1755 
   1756   H_PUT_32 (abfd, orl_count, buf);
   1757   if (bfd_bwrite (buf, (bfd_size_type) 4, abfd) != 4)
   1758     return FALSE;
   1759 
   1760   i = 0;
   1761   archive_iterator_begin (&iterator, abfd);
   1762   while (i < orl_count && archive_iterator_next (&iterator))
   1763     while (map[i].u.abfd == iterator.current.member)
   1764       {
   1765 	H_PUT_32 (abfd, iterator.current.offset, buf);
   1766 	if (bfd_bwrite (buf, (bfd_size_type) 4, abfd) != 4)
   1767 	  return FALSE;
   1768 	++i;
   1769       }
   1770 
   1771   for (i = 0; i < orl_count; i++)
   1772     {
   1773       const char *name;
   1774       size_t namlen;
   1775 
   1776       name = *map[i].name;
   1777       namlen = strlen (name);
   1778       if (bfd_bwrite (name, (bfd_size_type) (namlen + 1), abfd) != namlen + 1)
   1779 	return FALSE;
   1780     }
   1781 
   1782   if ((stridx & 1) != 0)
   1783     {
   1784       char b;
   1785 
   1786       b = '\0';
   1787       if (bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
   1788 	return FALSE;
   1789     }
   1790 
   1791   return TRUE;
   1792 }
   1793 
   1794 static char buff20[XCOFFARMAGBIG_ELEMENT_SIZE + 1];
   1795 #define FMT20  "%-20lld"
   1796 #define FMT12  "%-12d"
   1797 #define FMT12_OCTAL  "%-12o"
   1798 #define FMT4  "%-4d"
   1799 #define PRINT20(d, v) \
   1800   sprintf (buff20, FMT20, (long long)(v)), \
   1801   memcpy ((void *) (d), buff20, 20)
   1802 
   1803 #define PRINT12(d, v) \
   1804   sprintf (buff20, FMT12, (int)(v)), \
   1805   memcpy ((void *) (d), buff20, 12)
   1806 
   1807 #define PRINT12_OCTAL(d, v) \
   1808   sprintf (buff20, FMT12_OCTAL, (unsigned int)(v)), \
   1809   memcpy ((void *) (d), buff20, 12)
   1810 
   1811 #define PRINT4(d, v) \
   1812   sprintf (buff20, FMT4, (int)(v)), \
   1813   memcpy ((void *) (d), buff20, 4)
   1814 
   1815 #define READ20(d, v) \
   1816   buff20[20] = 0, \
   1817   memcpy (buff20, (d), 20), \
   1818   (v) = bfd_scan_vma (buff20, (const char **) NULL, 10)
   1819 
   1820 static bfd_boolean
   1821 do_pad (abfd, number)
   1822      bfd *abfd;
   1823      unsigned int number;
   1824 {
   1825   bfd_byte b = 0;
   1826 
   1827   /* Limit pad to <= 4096.  */
   1828   if (number > 4096)
   1829     return FALSE;
   1830 
   1831   while (number--)
   1832     if (bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
   1833       return FALSE;
   1834 
   1835   return TRUE;
   1836 }
   1837 
   1838 static bfd_boolean
   1839 do_copy (out_bfd, in_bfd)
   1840      bfd *out_bfd;
   1841      bfd *in_bfd;
   1842 {
   1843   bfd_size_type remaining;
   1844   bfd_byte buffer[DEFAULT_BUFFERSIZE];
   1845 
   1846   if (bfd_seek (in_bfd, (file_ptr) 0, SEEK_SET) != 0)
   1847     return FALSE;
   1848 
   1849   remaining = arelt_size (in_bfd);
   1850 
   1851   while (remaining >= DEFAULT_BUFFERSIZE)
   1852     {
   1853       if (bfd_bread (buffer, DEFAULT_BUFFERSIZE, in_bfd) != DEFAULT_BUFFERSIZE
   1854 	  || bfd_bwrite (buffer, DEFAULT_BUFFERSIZE, out_bfd) != DEFAULT_BUFFERSIZE)
   1855 	return FALSE;
   1856 
   1857       remaining -= DEFAULT_BUFFERSIZE;
   1858     }
   1859 
   1860   if (remaining)
   1861     {
   1862       if (bfd_bread (buffer, remaining, in_bfd) != remaining
   1863 	  || bfd_bwrite (buffer, remaining, out_bfd) != remaining)
   1864 	return FALSE;
   1865     }
   1866 
   1867   return TRUE;
   1868 }
   1869 
   1870 static bfd_boolean
   1871 xcoff_write_armap_big (abfd, elength, map, orl_count, stridx)
   1872      bfd *abfd;
   1873      unsigned int elength ATTRIBUTE_UNUSED;
   1874      struct orl *map;
   1875      unsigned int orl_count;
   1876      int stridx;
   1877 {
   1878   struct archive_iterator iterator;
   1879   struct xcoff_ar_file_hdr_big *fhdr;
   1880   bfd_vma i, sym_32, sym_64, str_32, str_64;
   1881   const bfd_arch_info_type *arch_info;
   1882   bfd *current_bfd;
   1883   size_t string_length;
   1884   file_ptr nextoff, prevoff;
   1885 
   1886   /* First, we look through the symbols and work out which are
   1887      from 32-bit objects and which from 64-bit ones.  */
   1888   sym_32 = sym_64 = str_32 = str_64 = 0;
   1889 
   1890   i = 0;
   1891   for (current_bfd = abfd->archive_head;
   1892        current_bfd != NULL && i < orl_count;
   1893        current_bfd = current_bfd->archive_next)
   1894     {
   1895       arch_info = bfd_get_arch_info (current_bfd);
   1896       while (map[i].u.abfd == current_bfd)
   1897 	{
   1898 	  string_length = strlen (*map[i].name) + 1;
   1899 	  if (arch_info->bits_per_address == 64)
   1900 	    {
   1901 	      sym_64++;
   1902 	      str_64 += string_length;
   1903 	    }
   1904 	  else
   1905 	    {
   1906 	      sym_32++;
   1907 	      str_32 += string_length;
   1908 	    }
   1909 	  i++;
   1910 	}
   1911     }
   1912 
   1913   /* A quick sanity check... */
   1914   BFD_ASSERT (sym_64 + sym_32 == orl_count);
   1915   /* Explicit cast to int for compiler.  */
   1916   BFD_ASSERT ((int)(str_64 + str_32) == stridx);
   1917 
   1918   fhdr = xcoff_ardata_big (abfd);
   1919 
   1920   /* xcoff_write_archive_contents_big passes nextoff in symoff. */
   1921   READ20 (fhdr->memoff, prevoff);
   1922   READ20 (fhdr->symoff, nextoff);
   1923 
   1924   BFD_ASSERT (nextoff == bfd_tell (abfd));
   1925 
   1926   /* Write out the symbol table.
   1927      Layout :
   1928 
   1929      standard big archive header
   1930      0x0000		      ar_size	[0x14]
   1931      0x0014		      ar_nxtmem [0x14]
   1932      0x0028		      ar_prvmem [0x14]
   1933      0x003C		      ar_date	[0x0C]
   1934      0x0048		      ar_uid	[0x0C]
   1935      0x0054		      ar_gid	[0x0C]
   1936      0x0060		      ar_mod	[0x0C]
   1937      0x006C		      ar_namelen[0x04]
   1938      0x0070		      ar_fmag	[SXCOFFARFMAG]
   1939 
   1940      Symbol table
   1941      0x0072		      num_syms	[0x08], binary
   1942      0x0078		      offsets	[0x08 * num_syms], binary
   1943      0x0086 + 0x08 * num_syms names	[??]
   1944      ??			      pad to even bytes.
   1945   */
   1946 
   1947   if (sym_32)
   1948     {
   1949       struct xcoff_ar_hdr_big *hdr;
   1950       char *symbol_table;
   1951       char *st;
   1952 
   1953       bfd_vma symbol_table_size =
   1954 	SIZEOF_AR_HDR_BIG
   1955 	+ SXCOFFARFMAG
   1956 	+ 8
   1957 	+ 8 * sym_32
   1958 	+ str_32 + (str_32 & 1);
   1959 
   1960       symbol_table = bfd_zmalloc (symbol_table_size);
   1961       if (symbol_table == NULL)
   1962 	return FALSE;
   1963 
   1964       hdr = (struct xcoff_ar_hdr_big *) symbol_table;
   1965 
   1966       PRINT20 (hdr->size, 8 + 8 * sym_32 + str_32 + (str_32 & 1));
   1967 
   1968       if (sym_64)
   1969 	PRINT20 (hdr->nextoff, nextoff + symbol_table_size);
   1970       else
   1971 	PRINT20 (hdr->nextoff, 0);
   1972 
   1973       PRINT20 (hdr->prevoff, prevoff);
   1974       PRINT12 (hdr->date, 0);
   1975       PRINT12 (hdr->uid, 0);
   1976       PRINT12 (hdr->gid, 0);
   1977       PRINT12 (hdr->mode, 0);
   1978       PRINT4 (hdr->namlen, 0) ;
   1979 
   1980       st = symbol_table + SIZEOF_AR_HDR_BIG;
   1981       memcpy (st, XCOFFARFMAG, SXCOFFARFMAG);
   1982       st += SXCOFFARFMAG;
   1983 
   1984       bfd_h_put_64 (abfd, sym_32, st);
   1985       st += 8;
   1986 
   1987       /* loop over the 32 bit offsets */
   1988       i = 0;
   1989       archive_iterator_begin (&iterator, abfd);
   1990       while (i < orl_count && archive_iterator_next (&iterator))
   1991 	{
   1992 	  arch_info = bfd_get_arch_info (iterator.current.member);
   1993 	  while (map[i].u.abfd == iterator.current.member)
   1994 	    {
   1995 	      if (arch_info->bits_per_address == 32)
   1996 		{
   1997 		  bfd_h_put_64 (abfd, iterator.current.offset, st);
   1998 		  st += 8;
   1999 		}
   2000 	      i++;
   2001 	    }
   2002 	}
   2003 
   2004       /* loop over the 32 bit symbol names */
   2005       i = 0;
   2006       for (current_bfd = abfd->archive_head;
   2007 	   current_bfd != NULL && i < orl_count;
   2008 	   current_bfd = current_bfd->archive_next)
   2009 	{
   2010 	  arch_info = bfd_get_arch_info (current_bfd);
   2011 	  while (map[i].u.abfd == current_bfd)
   2012 	    {
   2013 	      if (arch_info->bits_per_address == 32)
   2014 		{
   2015 		  string_length = sprintf (st, "%s", *map[i].name);
   2016 		  st += string_length + 1;
   2017 		}
   2018 	      i++;
   2019 	    }
   2020 	}
   2021 
   2022       bfd_bwrite (symbol_table, symbol_table_size, abfd);
   2023 
   2024       free (symbol_table);
   2025 
   2026       prevoff = nextoff;
   2027       nextoff = nextoff + symbol_table_size;
   2028     }
   2029   else
   2030     PRINT20 (fhdr->symoff, 0);
   2031 
   2032   if (sym_64)
   2033     {
   2034       struct xcoff_ar_hdr_big *hdr;
   2035       char *symbol_table;
   2036       char *st;
   2037 
   2038       bfd_vma symbol_table_size =
   2039 	SIZEOF_AR_HDR_BIG
   2040 	+ SXCOFFARFMAG
   2041 	+ 8
   2042 	+ 8 * sym_64
   2043 	+ str_64 + (str_64 & 1);
   2044 
   2045       symbol_table = bfd_zmalloc (symbol_table_size);
   2046       if (symbol_table == NULL)
   2047 	return FALSE;
   2048 
   2049       hdr = (struct xcoff_ar_hdr_big *) symbol_table;
   2050 
   2051       PRINT20 (hdr->size, 8 + 8 * sym_64 + str_64 + (str_64 & 1));
   2052       PRINT20 (hdr->nextoff, 0);
   2053       PRINT20 (hdr->prevoff, prevoff);
   2054       PRINT12 (hdr->date, 0);
   2055       PRINT12 (hdr->uid, 0);
   2056       PRINT12 (hdr->gid, 0);
   2057       PRINT12 (hdr->mode, 0);
   2058       PRINT4 (hdr->namlen, 0);
   2059 
   2060       st = symbol_table + SIZEOF_AR_HDR_BIG;
   2061       memcpy (st, XCOFFARFMAG, SXCOFFARFMAG);
   2062       st += SXCOFFARFMAG;
   2063 
   2064       bfd_h_put_64 (abfd, sym_64, st);
   2065       st += 8;
   2066 
   2067       /* loop over the 64 bit offsets */
   2068       i = 0;
   2069       archive_iterator_begin (&iterator, abfd);
   2070       while (i < orl_count && archive_iterator_next (&iterator))
   2071 	{
   2072 	  arch_info = bfd_get_arch_info (iterator.current.member);
   2073 	  while (map[i].u.abfd == iterator.current.member)
   2074 	    {
   2075 	      if (arch_info->bits_per_address == 64)
   2076 		{
   2077 		  bfd_h_put_64 (abfd, iterator.current.offset, st);
   2078 		  st += 8;
   2079 		}
   2080 	      i++;
   2081 	    }
   2082 	}
   2083 
   2084       /* loop over the 64 bit symbol names */
   2085       i = 0;
   2086       for (current_bfd = abfd->archive_head;
   2087 	   current_bfd != NULL && i < orl_count;
   2088 	   current_bfd = current_bfd->archive_next)
   2089 	{
   2090 	  arch_info = bfd_get_arch_info (current_bfd);
   2091 	  while (map[i].u.abfd == current_bfd)
   2092 	    {
   2093 	      if (arch_info->bits_per_address == 64)
   2094 		{
   2095 		  string_length = sprintf (st, "%s", *map[i].name);
   2096 		  st += string_length + 1;
   2097 		}
   2098 	      i++;
   2099 	    }
   2100 	}
   2101 
   2102       bfd_bwrite (symbol_table, symbol_table_size, abfd);
   2103 
   2104       free (symbol_table);
   2105 
   2106       PRINT20 (fhdr->symoff64, nextoff);
   2107     }
   2108   else
   2109     PRINT20 (fhdr->symoff64, 0);
   2110 
   2111   return TRUE;
   2112 }
   2113 
   2114 bfd_boolean
   2115 _bfd_xcoff_write_armap (abfd, elength, map, orl_count, stridx)
   2116      bfd *abfd;
   2117      unsigned int elength ATTRIBUTE_UNUSED;
   2118      struct orl *map;
   2119      unsigned int orl_count;
   2120      int stridx;
   2121 {
   2122   if (! xcoff_big_format_p (abfd))
   2123     return xcoff_write_armap_old (abfd, elength, map, orl_count, stridx);
   2124   else
   2125     return xcoff_write_armap_big (abfd, elength, map, orl_count, stridx);
   2126 }
   2127 
   2128 /* Write out an XCOFF archive.  We always write an entire archive,
   2129    rather than fussing with the freelist and so forth.  */
   2130 
   2131 static bfd_boolean
   2132 xcoff_write_archive_contents_old (abfd)
   2133      bfd *abfd;
   2134 {
   2135   struct archive_iterator iterator;
   2136   struct xcoff_ar_file_hdr fhdr;
   2137   bfd_size_type count;
   2138   bfd_size_type total_namlen;
   2139   file_ptr *offsets;
   2140   bfd_boolean makemap;
   2141   bfd_boolean hasobjects;
   2142   file_ptr prevoff, nextoff;
   2143   bfd *sub;
   2144   size_t i;
   2145   struct xcoff_ar_hdr ahdr;
   2146   bfd_size_type size;
   2147   char *p;
   2148   char decbuf[XCOFFARMAG_ELEMENT_SIZE + 1];
   2149 
   2150   memset (&fhdr, 0, sizeof fhdr);
   2151   (void) strncpy (fhdr.magic, XCOFFARMAG, SXCOFFARMAG);
   2152   sprintf (fhdr.firstmemoff, "%d", SIZEOF_AR_FILE_HDR);
   2153   sprintf (fhdr.freeoff, "%d", 0);
   2154 
   2155   count = 0;
   2156   total_namlen = 0;
   2157   for (sub = abfd->archive_head; sub != NULL; sub = sub->archive_next)
   2158     {
   2159       ++count;
   2160       total_namlen += strlen (normalize_filename (sub)) + 1;
   2161       if (sub->arelt_data == NULL)
   2162 	{
   2163 	  sub->arelt_data = bfd_zalloc (sub, sizeof (struct areltdata));
   2164 	  if (sub->arelt_data == NULL)
   2165 	    return FALSE;
   2166 	}
   2167       if (arch_xhdr (sub) == NULL)
   2168 	{
   2169 	  struct xcoff_ar_hdr *ahdrp;
   2170 	  struct stat s;
   2171 
   2172 	  if (stat (bfd_get_filename (sub), &s) != 0)
   2173 	    {
   2174 	      bfd_set_error (bfd_error_system_call);
   2175 	      return FALSE;
   2176 	    }
   2177 
   2178 	  ahdrp = bfd_zalloc (sub, sizeof (*ahdrp));
   2179 	  if (ahdrp == NULL)
   2180 	    return FALSE;
   2181 
   2182 	  sprintf (ahdrp->size, "%ld", (long) s.st_size);
   2183 	  sprintf (ahdrp->date, "%ld", (long) s.st_mtime);
   2184 	  sprintf (ahdrp->uid, "%ld", (long) s.st_uid);
   2185 	  sprintf (ahdrp->gid, "%ld", (long) s.st_gid);
   2186 	  sprintf (ahdrp->mode, "%o", (unsigned int) s.st_mode);
   2187 
   2188 	  arch_eltdata (sub)->arch_header = (char *) ahdrp;
   2189 	  arch_eltdata (sub)->parsed_size = s.st_size;
   2190 	}
   2191     }
   2192   offsets = (file_ptr *) bfd_alloc (abfd, count * sizeof (file_ptr));
   2193   if (offsets == NULL)
   2194     return FALSE;
   2195 
   2196   if (bfd_seek (abfd, (file_ptr) SIZEOF_AR_FILE_HDR, SEEK_SET) != 0)
   2197     return FALSE;
   2198 
   2199   makemap = bfd_has_map (abfd);
   2200   hasobjects = FALSE;
   2201   prevoff = 0;
   2202   for (archive_iterator_begin (&iterator, abfd), i = 0;
   2203        archive_iterator_next (&iterator);
   2204        i++)
   2205     {
   2206       bfd_size_type namlen;
   2207       struct xcoff_ar_hdr *ahdrp;
   2208 
   2209       if (makemap && ! hasobjects)
   2210 	{
   2211 	  if (bfd_check_format (iterator.current.member, bfd_object))
   2212 	    hasobjects = TRUE;
   2213 	}
   2214 
   2215       ahdrp = arch_xhdr (iterator.current.member);
   2216       sprintf (ahdrp->prevoff, "%ld", (long) prevoff);
   2217       sprintf (ahdrp->namlen, "%ld", (long) iterator.current.namlen);
   2218       sprintf (ahdrp->nextoff, "%ld", (long) iterator.next.offset);
   2219 
   2220       /* We need spaces, not null bytes, in the header.  */
   2221       for (p = (char *) ahdrp; p < (char *) ahdrp + SIZEOF_AR_HDR; p++)
   2222 	if (*p == '\0')
   2223 	  *p = ' ';
   2224 
   2225       if (!do_pad (abfd, iterator.current.leading_padding))
   2226 	return FALSE;
   2227 
   2228       BFD_ASSERT (iterator.current.offset == bfd_tell (abfd));
   2229       namlen = iterator.current.padded_namlen;
   2230       if (bfd_bwrite (ahdrp, SIZEOF_AR_HDR, abfd) != SIZEOF_AR_HDR
   2231 	  || bfd_bwrite (iterator.current.name, namlen, abfd) != namlen
   2232 	  || bfd_bwrite (XCOFFARFMAG, SXCOFFARFMAG, abfd) != SXCOFFARFMAG
   2233 	  || bfd_seek (iterator.current.member, 0, SEEK_SET) != 0
   2234 	  || !do_copy (abfd, iterator.current.member)
   2235 	  || !do_pad (abfd, iterator.current.trailing_padding))
   2236 	return FALSE;
   2237 
   2238       offsets[i] = iterator.current.offset;
   2239       prevoff = iterator.current.offset;
   2240     }
   2241 
   2242   sprintf (fhdr.lastmemoff, "%ld", (long) prevoff);
   2243 
   2244   /* Write out the member table.  */
   2245 
   2246   nextoff = iterator.next.offset;
   2247   BFD_ASSERT (nextoff == bfd_tell (abfd));
   2248   sprintf (fhdr.memoff, "%ld", (long) nextoff);
   2249 
   2250   memset (&ahdr, 0, sizeof ahdr);
   2251   sprintf (ahdr.size, "%ld", (long) (XCOFFARMAG_ELEMENT_SIZE
   2252 				     + count * XCOFFARMAG_ELEMENT_SIZE
   2253 				     + total_namlen));
   2254   sprintf (ahdr.prevoff, "%ld", (long) prevoff);
   2255   sprintf (ahdr.date, "%d", 0);
   2256   sprintf (ahdr.uid, "%d", 0);
   2257   sprintf (ahdr.gid, "%d", 0);
   2258   sprintf (ahdr.mode, "%d", 0);
   2259   sprintf (ahdr.namlen, "%d", 0);
   2260 
   2261   size = (SIZEOF_AR_HDR
   2262 	  + XCOFFARMAG_ELEMENT_SIZE
   2263 	  + count * XCOFFARMAG_ELEMENT_SIZE
   2264 	  + total_namlen
   2265 	  + SXCOFFARFMAG);
   2266 
   2267   prevoff = nextoff;
   2268   nextoff += size + (size & 1);
   2269 
   2270   if (makemap && hasobjects)
   2271     sprintf (ahdr.nextoff, "%ld", (long) nextoff);
   2272   else
   2273     sprintf (ahdr.nextoff, "%d", 0);
   2274 
   2275   /* We need spaces, not null bytes, in the header.  */
   2276   for (p = (char *) &ahdr; p < (char *) &ahdr + SIZEOF_AR_HDR; p++)
   2277     if (*p == '\0')
   2278       *p = ' ';
   2279 
   2280   if ((bfd_bwrite ((PTR) &ahdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
   2281        != SIZEOF_AR_HDR)
   2282       || (bfd_bwrite ((PTR) XCOFFARFMAG, (bfd_size_type) SXCOFFARFMAG, abfd)
   2283 	  != SXCOFFARFMAG))
   2284     return FALSE;
   2285 
   2286   sprintf (decbuf, "%-12ld", (long) count);
   2287   if (bfd_bwrite ((PTR) decbuf, (bfd_size_type) XCOFFARMAG_ELEMENT_SIZE, abfd)
   2288       != XCOFFARMAG_ELEMENT_SIZE)
   2289     return FALSE;
   2290   for (i = 0; i < (size_t) count; i++)
   2291     {
   2292       sprintf (decbuf, "%-12ld", (long) offsets[i]);
   2293       if (bfd_bwrite ((PTR) decbuf, (bfd_size_type) XCOFFARMAG_ELEMENT_SIZE,
   2294 		      abfd) != XCOFFARMAG_ELEMENT_SIZE)
   2295 	return FALSE;
   2296     }
   2297   for (sub = abfd->archive_head; sub != NULL; sub = sub->archive_next)
   2298     {
   2299       const char *name;
   2300       bfd_size_type namlen;
   2301 
   2302       name = normalize_filename (sub);
   2303       namlen = strlen (name);
   2304       if (bfd_bwrite ((PTR) name, namlen + 1, abfd) != namlen + 1)
   2305 	return FALSE;
   2306     }
   2307 
   2308   if (! do_pad (abfd, size & 1))
   2309     return FALSE;
   2310 
   2311   /* Write out the armap, if appropriate.  */
   2312   if (! makemap || ! hasobjects)
   2313     sprintf (fhdr.symoff, "%d", 0);
   2314   else
   2315     {
   2316       BFD_ASSERT (nextoff == bfd_tell (abfd));
   2317       sprintf (fhdr.symoff, "%ld", (long) nextoff);
   2318       bfd_ardata (abfd)->tdata = (PTR) &fhdr;
   2319       if (! _bfd_compute_and_write_armap (abfd, 0))
   2320 	return FALSE;
   2321     }
   2322 
   2323   /* Write out the archive file header.  */
   2324 
   2325   /* We need spaces, not null bytes, in the header.  */
   2326   for (p = (char *) &fhdr; p < (char *) &fhdr + SIZEOF_AR_FILE_HDR; p++)
   2327     if (*p == '\0')
   2328       *p = ' ';
   2329 
   2330   if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
   2331       || (bfd_bwrite ((PTR) &fhdr, (bfd_size_type) SIZEOF_AR_FILE_HDR, abfd)
   2332 	  != SIZEOF_AR_FILE_HDR))
   2333     return FALSE;
   2334 
   2335   return TRUE;
   2336 }
   2337 
   2338 static bfd_boolean
   2339 xcoff_write_archive_contents_big (abfd)
   2340      bfd *abfd;
   2341 {
   2342   struct xcoff_ar_file_hdr_big fhdr;
   2343   bfd_size_type count;
   2344   bfd_size_type total_namlen;
   2345   file_ptr *offsets;
   2346   bfd_boolean makemap;
   2347   bfd_boolean hasobjects;
   2348   file_ptr prevoff, nextoff;
   2349   bfd *current_bfd;
   2350   size_t i;
   2351   struct xcoff_ar_hdr_big *hdr;
   2352   bfd_size_type size;
   2353   char *member_table, *mt;
   2354   bfd_vma member_table_size;
   2355   struct archive_iterator iterator;
   2356 
   2357   memset (&fhdr, 0, SIZEOF_AR_FILE_HDR_BIG);
   2358   memcpy (fhdr.magic, XCOFFARMAGBIG, SXCOFFARMAG);
   2359 
   2360   if (bfd_seek (abfd, (file_ptr) SIZEOF_AR_FILE_HDR_BIG, SEEK_SET) != 0)
   2361     return FALSE;
   2362 
   2363   /* Calculate count and total_namlen.  */
   2364   makemap = bfd_has_map (abfd);
   2365   hasobjects = FALSE;
   2366   for (current_bfd = abfd->archive_head, count = 0, total_namlen = 0;
   2367        current_bfd != NULL;
   2368        current_bfd = current_bfd->archive_next, count++)
   2369     {
   2370       total_namlen += strlen (normalize_filename (current_bfd)) + 1;
   2371 
   2372       if (makemap
   2373 	  && ! hasobjects
   2374 	  && bfd_check_format (current_bfd, bfd_object))
   2375 	hasobjects = TRUE;
   2376 
   2377       if (current_bfd->arelt_data == NULL)
   2378 	{
   2379 	  size = sizeof (struct areltdata);
   2380 	  current_bfd->arelt_data = bfd_zalloc (current_bfd, size);
   2381 	  if (current_bfd->arelt_data == NULL)
   2382 	    return FALSE;
   2383 	}
   2384 
   2385       if (arch_xhdr_big (current_bfd) == NULL)
   2386 	{
   2387 	  struct xcoff_ar_hdr_big *ahdrp;
   2388 	  struct stat s;
   2389 
   2390 	  /* XXX This should actually be a call to stat64 (at least on
   2391 	     32-bit machines).
   2392 	     XXX This call will fail if the original object is not found.  */
   2393 	  if (stat (bfd_get_filename (current_bfd), &s) != 0)
   2394 	    {
   2395 	      bfd_set_error (bfd_error_system_call);
   2396 	      return FALSE;
   2397 	    }
   2398 
   2399 	  ahdrp = bfd_zalloc (current_bfd, sizeof (*ahdrp));
   2400 	  if (ahdrp == NULL)
   2401 	    return FALSE;
   2402 
   2403 	  PRINT20 (ahdrp->size, s.st_size);
   2404 	  PRINT12 (ahdrp->date, s.st_mtime);
   2405 	  PRINT12 (ahdrp->uid,  s.st_uid);
   2406 	  PRINT12 (ahdrp->gid,  s.st_gid);
   2407 	  PRINT12_OCTAL (ahdrp->mode, s.st_mode);
   2408 
   2409 	  arch_eltdata (current_bfd)->arch_header = (char *) ahdrp;
   2410 	  arch_eltdata (current_bfd)->parsed_size = s.st_size;
   2411 	}
   2412     }
   2413 
   2414   offsets = NULL;
   2415   if (count)
   2416     {
   2417       offsets = (file_ptr *) bfd_malloc (count * sizeof (file_ptr));
   2418       if (offsets == NULL)
   2419 	return FALSE;
   2420     }
   2421 
   2422   prevoff = 0;
   2423   for (archive_iterator_begin (&iterator, abfd), i = 0;
   2424        archive_iterator_next (&iterator);
   2425        i++)
   2426     {
   2427       bfd_size_type namlen;
   2428       struct xcoff_ar_hdr_big *ahdrp;
   2429 
   2430       ahdrp = arch_xhdr_big (iterator.current.member);
   2431       PRINT20 (ahdrp->prevoff, prevoff);
   2432       PRINT4 (ahdrp->namlen, iterator.current.namlen);
   2433       PRINT20 (ahdrp->nextoff, iterator.next.offset);
   2434 
   2435       if (!do_pad (abfd, iterator.current.leading_padding))
   2436 	return FALSE;
   2437 
   2438       BFD_ASSERT (iterator.current.offset == bfd_tell (abfd));
   2439       namlen = iterator.current.padded_namlen;
   2440       if (bfd_bwrite (ahdrp, SIZEOF_AR_HDR_BIG, abfd) != SIZEOF_AR_HDR_BIG
   2441 	  || bfd_bwrite (iterator.current.name, namlen, abfd) != namlen
   2442 	  || bfd_bwrite (XCOFFARFMAG, SXCOFFARFMAG, abfd) != SXCOFFARFMAG
   2443 	  || bfd_seek (iterator.current.member, 0, SEEK_SET) != 0
   2444 	  || !do_copy (abfd, iterator.current.member)
   2445 	  || !do_pad (abfd, iterator.current.trailing_padding))
   2446 	return FALSE;
   2447 
   2448       offsets[i] = iterator.current.offset;
   2449       prevoff = iterator.current.offset;
   2450     }
   2451 
   2452   if (count)
   2453     {
   2454       PRINT20 (fhdr.firstmemoff, offsets[0]);
   2455       PRINT20 (fhdr.lastmemoff, prevoff);
   2456     }
   2457 
   2458   /* Write out the member table.
   2459      Layout :
   2460 
   2461      standard big archive header
   2462      0x0000		      ar_size	[0x14]
   2463      0x0014		      ar_nxtmem [0x14]
   2464      0x0028		      ar_prvmem [0x14]
   2465      0x003C		      ar_date	[0x0C]
   2466      0x0048		      ar_uid	[0x0C]
   2467      0x0054		      ar_gid	[0x0C]
   2468      0x0060		      ar_mod	[0x0C]
   2469      0x006C		      ar_namelen[0x04]
   2470      0x0070		      ar_fmag	[0x02]
   2471 
   2472      Member table
   2473      0x0072		      count	[0x14]
   2474      0x0086		      offsets	[0x14 * counts]
   2475      0x0086 + 0x14 * counts   names	[??]
   2476      ??			      pad to even bytes.
   2477    */
   2478 
   2479   nextoff = iterator.next.offset;
   2480   BFD_ASSERT (nextoff == bfd_tell (abfd));
   2481 
   2482   member_table_size = (SIZEOF_AR_HDR_BIG
   2483 		       + SXCOFFARFMAG
   2484 		       + XCOFFARMAGBIG_ELEMENT_SIZE
   2485 		       + count * XCOFFARMAGBIG_ELEMENT_SIZE
   2486 		       + total_namlen);
   2487 
   2488   member_table_size += member_table_size & 1;
   2489   member_table = bfd_zmalloc (member_table_size);
   2490   if (member_table == NULL)
   2491     return FALSE;
   2492 
   2493   hdr = (struct xcoff_ar_hdr_big *) member_table;
   2494 
   2495   PRINT20 (hdr->size, (XCOFFARMAGBIG_ELEMENT_SIZE
   2496 		       + count * XCOFFARMAGBIG_ELEMENT_SIZE
   2497 		       + total_namlen + (total_namlen & 1)));
   2498   if (makemap && hasobjects)
   2499     PRINT20 (hdr->nextoff, nextoff + member_table_size);
   2500   else
   2501     PRINT20 (hdr->nextoff, 0);
   2502   PRINT20 (hdr->prevoff, prevoff);
   2503   PRINT12 (hdr->date, 0);
   2504   PRINT12 (hdr->uid, 0);
   2505   PRINT12 (hdr->gid, 0);
   2506   PRINT12 (hdr->mode, 0);
   2507   PRINT4 (hdr->namlen, 0);
   2508 
   2509   mt = member_table + SIZEOF_AR_HDR_BIG;
   2510   memcpy (mt, XCOFFARFMAG, SXCOFFARFMAG);
   2511   mt += SXCOFFARFMAG;
   2512 
   2513   PRINT20 (mt, count);
   2514   mt += XCOFFARMAGBIG_ELEMENT_SIZE;
   2515   for (i = 0; i < (size_t) count; i++)
   2516     {
   2517       PRINT20 (mt, offsets[i]);
   2518       mt += XCOFFARMAGBIG_ELEMENT_SIZE;
   2519     }
   2520 
   2521   if (count)
   2522     {
   2523       free (offsets);
   2524       offsets = NULL;
   2525     }
   2526 
   2527   for (current_bfd = abfd->archive_head;
   2528        current_bfd != NULL;
   2529        current_bfd = current_bfd->archive_next)
   2530     {
   2531       const char *name;
   2532       size_t namlen;
   2533 
   2534       name = normalize_filename (current_bfd);
   2535       namlen = sprintf (mt, "%s", name);
   2536       mt += namlen + 1;
   2537     }
   2538 
   2539   if (bfd_bwrite (member_table, member_table_size, abfd) != member_table_size)
   2540     return FALSE;
   2541 
   2542   free (member_table);
   2543 
   2544   PRINT20 (fhdr.memoff, nextoff);
   2545 
   2546   prevoff = nextoff;
   2547   nextoff += member_table_size;
   2548 
   2549   /* Write out the armap, if appropriate.  */
   2550 
   2551   if (! makemap || ! hasobjects)
   2552     PRINT20 (fhdr.symoff, 0);
   2553   else
   2554     {
   2555       BFD_ASSERT (nextoff == bfd_tell (abfd));
   2556 
   2557       /* Save nextoff in fhdr.symoff so the armap routine can use it.  */
   2558       PRINT20 (fhdr.symoff, nextoff);
   2559 
   2560       bfd_ardata (abfd)->tdata = (PTR) &fhdr;
   2561       if (! _bfd_compute_and_write_armap (abfd, 0))
   2562 	return FALSE;
   2563     }
   2564 
   2565   /* Write out the archive file header.  */
   2566 
   2567   if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
   2568       || (bfd_bwrite ((PTR) &fhdr, (bfd_size_type) SIZEOF_AR_FILE_HDR_BIG,
   2569 		      abfd) != SIZEOF_AR_FILE_HDR_BIG))
   2570     return FALSE;
   2571 
   2572   return TRUE;
   2573 }
   2574 
   2575 bfd_boolean
   2576 _bfd_xcoff_write_archive_contents (abfd)
   2577      bfd *abfd;
   2578 {
   2579   if (! xcoff_big_format_p (abfd))
   2580     return xcoff_write_archive_contents_old (abfd);
   2581   else
   2582     return xcoff_write_archive_contents_big (abfd);
   2583 }
   2584 
   2585 /* We can't use the usual coff_sizeof_headers routine, because AIX
   2587    always uses an a.out header.  */
   2588 
   2589 int
   2590 _bfd_xcoff_sizeof_headers (bfd *abfd,
   2591 			   struct bfd_link_info *info ATTRIBUTE_UNUSED)
   2592 {
   2593   int size;
   2594 
   2595   size = FILHSZ;
   2596   if (xcoff_data (abfd)->full_aouthdr)
   2597     size += AOUTSZ;
   2598   else
   2599     size += SMALL_AOUTSZ;
   2600   size += abfd->section_count * SCNHSZ;
   2601   return size;
   2602 }
   2603 
   2604 /* Routines to swap information in the XCOFF .loader section.  If we
   2606    ever need to write an XCOFF loader, this stuff will need to be
   2607    moved to another file shared by the linker (which XCOFF calls the
   2608    ``binder'') and the loader.  */
   2609 
   2610 /* Swap in the ldhdr structure.  */
   2611 
   2612 static void
   2613 xcoff_swap_ldhdr_in (abfd, s, dst)
   2614      bfd *abfd;
   2615      const PTR s;
   2616      struct internal_ldhdr *dst;
   2617 {
   2618   const struct external_ldhdr *src = (const struct external_ldhdr *) s;
   2619 
   2620   dst->l_version = bfd_get_32 (abfd, src->l_version);
   2621   dst->l_nsyms = bfd_get_32 (abfd, src->l_nsyms);
   2622   dst->l_nreloc = bfd_get_32 (abfd, src->l_nreloc);
   2623   dst->l_istlen = bfd_get_32 (abfd, src->l_istlen);
   2624   dst->l_nimpid = bfd_get_32 (abfd, src->l_nimpid);
   2625   dst->l_impoff = bfd_get_32 (abfd, src->l_impoff);
   2626   dst->l_stlen = bfd_get_32 (abfd, src->l_stlen);
   2627   dst->l_stoff = bfd_get_32 (abfd, src->l_stoff);
   2628 }
   2629 
   2630 /* Swap out the ldhdr structure.  */
   2631 
   2632 static void
   2633 xcoff_swap_ldhdr_out (abfd, src, d)
   2634      bfd *abfd;
   2635      const struct internal_ldhdr *src;
   2636      PTR d;
   2637 {
   2638   struct external_ldhdr *dst = (struct external_ldhdr *) d;
   2639 
   2640   bfd_put_32 (abfd, (bfd_vma) src->l_version, dst->l_version);
   2641   bfd_put_32 (abfd, src->l_nsyms, dst->l_nsyms);
   2642   bfd_put_32 (abfd, src->l_nreloc, dst->l_nreloc);
   2643   bfd_put_32 (abfd, src->l_istlen, dst->l_istlen);
   2644   bfd_put_32 (abfd, src->l_nimpid, dst->l_nimpid);
   2645   bfd_put_32 (abfd, src->l_impoff, dst->l_impoff);
   2646   bfd_put_32 (abfd, src->l_stlen, dst->l_stlen);
   2647   bfd_put_32 (abfd, src->l_stoff, dst->l_stoff);
   2648 }
   2649 
   2650 /* Swap in the ldsym structure.  */
   2651 
   2652 static void
   2653 xcoff_swap_ldsym_in (abfd, s, dst)
   2654      bfd *abfd;
   2655      const PTR s;
   2656      struct internal_ldsym *dst;
   2657 {
   2658   const struct external_ldsym *src = (const struct external_ldsym *) s;
   2659 
   2660   if (bfd_get_32 (abfd, src->_l._l_l._l_zeroes) != 0) {
   2661     memcpy (dst->_l._l_name, src->_l._l_name, SYMNMLEN);
   2662   } else {
   2663     dst->_l._l_l._l_zeroes = 0;
   2664     dst->_l._l_l._l_offset = bfd_get_32 (abfd, src->_l._l_l._l_offset);
   2665   }
   2666   dst->l_value = bfd_get_32 (abfd, src->l_value);
   2667   dst->l_scnum = bfd_get_16 (abfd, src->l_scnum);
   2668   dst->l_smtype = bfd_get_8 (abfd, src->l_smtype);
   2669   dst->l_smclas = bfd_get_8 (abfd, src->l_smclas);
   2670   dst->l_ifile = bfd_get_32 (abfd, src->l_ifile);
   2671   dst->l_parm = bfd_get_32 (abfd, src->l_parm);
   2672 }
   2673 
   2674 /* Swap out the ldsym structure.  */
   2675 
   2676 static void
   2677 xcoff_swap_ldsym_out (abfd, src, d)
   2678      bfd *abfd;
   2679      const struct internal_ldsym *src;
   2680      PTR d;
   2681 {
   2682   struct external_ldsym *dst = (struct external_ldsym *) d;
   2683 
   2684   if (src->_l._l_l._l_zeroes != 0)
   2685     memcpy (dst->_l._l_name, src->_l._l_name, SYMNMLEN);
   2686   else
   2687     {
   2688       bfd_put_32 (abfd, (bfd_vma) 0, dst->_l._l_l._l_zeroes);
   2689       bfd_put_32 (abfd, (bfd_vma) src->_l._l_l._l_offset,
   2690 		  dst->_l._l_l._l_offset);
   2691     }
   2692   bfd_put_32 (abfd, src->l_value, dst->l_value);
   2693   bfd_put_16 (abfd, (bfd_vma) src->l_scnum, dst->l_scnum);
   2694   bfd_put_8 (abfd, src->l_smtype, dst->l_smtype);
   2695   bfd_put_8 (abfd, src->l_smclas, dst->l_smclas);
   2696   bfd_put_32 (abfd, src->l_ifile, dst->l_ifile);
   2697   bfd_put_32 (abfd, src->l_parm, dst->l_parm);
   2698 }
   2699 
   2700 static void
   2701 xcoff_swap_reloc_in (abfd, s, d)
   2702      bfd *abfd;
   2703      PTR s;
   2704      PTR d;
   2705 {
   2706   struct external_reloc *src = (struct external_reloc *) s;
   2707   struct internal_reloc *dst = (struct internal_reloc *) d;
   2708 
   2709   memset (dst, 0, sizeof (struct internal_reloc));
   2710 
   2711   dst->r_vaddr = bfd_get_32 (abfd, src->r_vaddr);
   2712   dst->r_symndx = bfd_get_32 (abfd, src->r_symndx);
   2713   dst->r_size = bfd_get_8 (abfd, src->r_size);
   2714   dst->r_type = bfd_get_8 (abfd, src->r_type);
   2715 }
   2716 
   2717 static unsigned int
   2718 xcoff_swap_reloc_out (abfd, s, d)
   2719      bfd *abfd;
   2720      PTR s;
   2721      PTR d;
   2722 {
   2723   struct internal_reloc *src = (struct internal_reloc *) s;
   2724   struct external_reloc *dst = (struct external_reloc *) d;
   2725 
   2726   bfd_put_32 (abfd, src->r_vaddr, dst->r_vaddr);
   2727   bfd_put_32 (abfd, src->r_symndx, dst->r_symndx);
   2728   bfd_put_8 (abfd, src->r_type, dst->r_type);
   2729   bfd_put_8 (abfd, src->r_size, dst->r_size);
   2730 
   2731   return bfd_coff_relsz (abfd);
   2732 }
   2733 
   2734 /* Swap in the ldrel structure.  */
   2735 
   2736 static void
   2737 xcoff_swap_ldrel_in (abfd, s, dst)
   2738      bfd *abfd;
   2739      const PTR s;
   2740      struct internal_ldrel *dst;
   2741 {
   2742   const struct external_ldrel *src = (const struct external_ldrel *) s;
   2743 
   2744   dst->l_vaddr = bfd_get_32 (abfd, src->l_vaddr);
   2745   dst->l_symndx = bfd_get_32 (abfd, src->l_symndx);
   2746   dst->l_rtype = bfd_get_16 (abfd, src->l_rtype);
   2747   dst->l_rsecnm = bfd_get_16 (abfd, src->l_rsecnm);
   2748 }
   2749 
   2750 /* Swap out the ldrel structure.  */
   2751 
   2752 static void
   2753 xcoff_swap_ldrel_out (abfd, src, d)
   2754      bfd *abfd;
   2755      const struct internal_ldrel *src;
   2756      PTR d;
   2757 {
   2758   struct external_ldrel *dst = (struct external_ldrel *) d;
   2759 
   2760   bfd_put_32 (abfd, src->l_vaddr, dst->l_vaddr);
   2761   bfd_put_32 (abfd, src->l_symndx, dst->l_symndx);
   2762   bfd_put_16 (abfd, (bfd_vma) src->l_rtype, dst->l_rtype);
   2763   bfd_put_16 (abfd, (bfd_vma) src->l_rsecnm, dst->l_rsecnm);
   2764 }
   2765 
   2766 
   2768 bfd_boolean
   2769 xcoff_reloc_type_noop (input_bfd, input_section, output_bfd, rel, sym, howto,
   2770 		       val, addend, relocation, contents)
   2771      bfd *input_bfd ATTRIBUTE_UNUSED;
   2772      asection *input_section ATTRIBUTE_UNUSED;
   2773      bfd *output_bfd ATTRIBUTE_UNUSED;
   2774      struct internal_reloc *rel ATTRIBUTE_UNUSED;
   2775      struct internal_syment *sym ATTRIBUTE_UNUSED;
   2776      struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
   2777      bfd_vma val ATTRIBUTE_UNUSED;
   2778      bfd_vma addend ATTRIBUTE_UNUSED;
   2779      bfd_vma *relocation ATTRIBUTE_UNUSED;
   2780      bfd_byte *contents ATTRIBUTE_UNUSED;
   2781 {
   2782   return TRUE;
   2783 }
   2784 
   2785 bfd_boolean
   2786 xcoff_reloc_type_fail (input_bfd, input_section, output_bfd, rel, sym, howto,
   2787 		       val, addend, relocation, contents)
   2788      bfd *input_bfd;
   2789      asection *input_section ATTRIBUTE_UNUSED;
   2790      bfd *output_bfd ATTRIBUTE_UNUSED;
   2791      struct internal_reloc *rel;
   2792      struct internal_syment *sym ATTRIBUTE_UNUSED;
   2793      struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
   2794      bfd_vma val ATTRIBUTE_UNUSED;
   2795      bfd_vma addend ATTRIBUTE_UNUSED;
   2796      bfd_vma *relocation ATTRIBUTE_UNUSED;
   2797      bfd_byte *contents ATTRIBUTE_UNUSED;
   2798 {
   2799   (*_bfd_error_handler)
   2800     (_("%s: unsupported relocation type 0x%02x"),
   2801      bfd_get_filename (input_bfd), (unsigned int) rel->r_type);
   2802   bfd_set_error (bfd_error_bad_value);
   2803   return FALSE;
   2804 }
   2805 
   2806 bfd_boolean
   2807 xcoff_reloc_type_pos (input_bfd, input_section, output_bfd, rel, sym, howto,
   2808 		      val, addend, relocation, contents)
   2809      bfd *input_bfd ATTRIBUTE_UNUSED;
   2810      asection *input_section ATTRIBUTE_UNUSED;
   2811      bfd *output_bfd ATTRIBUTE_UNUSED;
   2812      struct internal_reloc *rel ATTRIBUTE_UNUSED;
   2813      struct internal_syment *sym ATTRIBUTE_UNUSED;
   2814      struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
   2815      bfd_vma val;
   2816      bfd_vma addend;
   2817      bfd_vma *relocation;
   2818      bfd_byte *contents ATTRIBUTE_UNUSED;
   2819 {
   2820   *relocation = val + addend;
   2821   return TRUE;
   2822 }
   2823 
   2824 bfd_boolean
   2825 xcoff_reloc_type_neg (input_bfd, input_section, output_bfd, rel, sym, howto,
   2826 		      val, addend, relocation, contents)
   2827      bfd *input_bfd ATTRIBUTE_UNUSED;
   2828      asection *input_section ATTRIBUTE_UNUSED;
   2829      bfd *output_bfd ATTRIBUTE_UNUSED;
   2830      struct internal_reloc *rel ATTRIBUTE_UNUSED;
   2831      struct internal_syment *sym ATTRIBUTE_UNUSED;
   2832      struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
   2833      bfd_vma val;
   2834      bfd_vma addend;
   2835      bfd_vma *relocation;
   2836      bfd_byte *contents ATTRIBUTE_UNUSED;
   2837 {
   2838   *relocation = addend - val;
   2839   return TRUE;
   2840 }
   2841 
   2842 bfd_boolean
   2843 xcoff_reloc_type_rel (input_bfd, input_section, output_bfd, rel, sym, howto,
   2844 		      val, addend, relocation, contents)
   2845      bfd *input_bfd ATTRIBUTE_UNUSED;
   2846      asection *input_section;
   2847      bfd *output_bfd ATTRIBUTE_UNUSED;
   2848      struct internal_reloc *rel ATTRIBUTE_UNUSED;
   2849      struct internal_syment *sym ATTRIBUTE_UNUSED;
   2850      struct reloc_howto_struct *howto;
   2851      bfd_vma val;
   2852      bfd_vma addend;
   2853      bfd_vma *relocation;
   2854      bfd_byte *contents ATTRIBUTE_UNUSED;
   2855 {
   2856   howto->pc_relative = TRUE;
   2857 
   2858   /* A PC relative reloc includes the section address.  */
   2859   addend += input_section->vma;
   2860 
   2861   *relocation = val + addend;
   2862   *relocation -= (input_section->output_section->vma
   2863 		  + input_section->output_offset);
   2864   return TRUE;
   2865 }
   2866 
   2867 bfd_boolean
   2868 xcoff_reloc_type_toc (input_bfd, input_section, output_bfd, rel, sym, howto,
   2869 		      val, addend, relocation, contents)
   2870      bfd *input_bfd;
   2871      asection *input_section ATTRIBUTE_UNUSED;
   2872      bfd *output_bfd;
   2873      struct internal_reloc *rel;
   2874      struct internal_syment *sym;
   2875      struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
   2876      bfd_vma val;
   2877      bfd_vma addend ATTRIBUTE_UNUSED;
   2878      bfd_vma *relocation;
   2879      bfd_byte *contents ATTRIBUTE_UNUSED;
   2880 {
   2881   struct xcoff_link_hash_entry *h;
   2882 
   2883   if (0 > rel->r_symndx)
   2884     return FALSE;
   2885 
   2886   h = obj_xcoff_sym_hashes (input_bfd)[rel->r_symndx];
   2887 
   2888   if (h != NULL && h->smclas != XMC_TD)
   2889     {
   2890       if (h->toc_section == NULL)
   2891 	{
   2892 	  (*_bfd_error_handler)
   2893 	    (_("%s: TOC reloc at 0x%x to symbol `%s' with no TOC entry"),
   2894 	     bfd_get_filename (input_bfd), rel->r_vaddr,
   2895 	     h->root.root.string);
   2896 	  bfd_set_error (bfd_error_bad_value);
   2897 	  return FALSE;
   2898 	}
   2899 
   2900       BFD_ASSERT ((h->flags & XCOFF_SET_TOC) == 0);
   2901       val = (h->toc_section->output_section->vma
   2902 	      + h->toc_section->output_offset);
   2903     }
   2904 
   2905   *relocation = ((val - xcoff_data (output_bfd)->toc)
   2906 		 - (sym->n_value - xcoff_data (input_bfd)->toc));
   2907   return TRUE;
   2908 }
   2909 
   2910 bfd_boolean
   2911 xcoff_reloc_type_ba (input_bfd, input_section, output_bfd, rel, sym, howto,
   2912 		     val, addend, relocation, contents)
   2913      bfd *input_bfd ATTRIBUTE_UNUSED;
   2914      asection *input_section ATTRIBUTE_UNUSED;
   2915      bfd *output_bfd ATTRIBUTE_UNUSED;
   2916      struct internal_reloc *rel ATTRIBUTE_UNUSED;
   2917      struct internal_syment *sym ATTRIBUTE_UNUSED;
   2918      struct reloc_howto_struct *howto;
   2919      bfd_vma val;
   2920      bfd_vma addend;
   2921      bfd_vma *relocation;
   2922      bfd_byte *contents ATTRIBUTE_UNUSED;
   2923 {
   2924   howto->src_mask &= ~3;
   2925   howto->dst_mask = howto->src_mask;
   2926 
   2927   *relocation = val + addend;
   2928 
   2929   return TRUE;
   2930 }
   2931 
   2932 static bfd_boolean
   2933 xcoff_reloc_type_br (input_bfd, input_section, output_bfd, rel, sym, howto,
   2934 		     val, addend, relocation, contents)
   2935      bfd *input_bfd;
   2936      asection *input_section;
   2937      bfd *output_bfd ATTRIBUTE_UNUSED;
   2938      struct internal_reloc *rel;
   2939      struct internal_syment *sym ATTRIBUTE_UNUSED;
   2940      struct reloc_howto_struct *howto;
   2941      bfd_vma val;
   2942      bfd_vma addend;
   2943      bfd_vma *relocation;
   2944      bfd_byte *contents;
   2945 {
   2946   struct xcoff_link_hash_entry *h;
   2947   bfd_vma section_offset;
   2948 
   2949   if (0 > rel->r_symndx)
   2950     return FALSE;
   2951 
   2952   h = obj_xcoff_sym_hashes (input_bfd)[rel->r_symndx];
   2953   section_offset = rel->r_vaddr - input_section->vma;
   2954 
   2955   /* If we see an R_BR or R_RBR reloc which is jumping to global
   2956      linkage code, and it is followed by an appropriate cror nop
   2957      instruction, we replace the cror with lwz r2,20(r1).  This
   2958      restores the TOC after the glink code.  Contrariwise, if the
   2959      call is followed by a lwz r2,20(r1), but the call is not
   2960      going to global linkage code, we can replace the load with a
   2961      cror.  */
   2962   if (NULL != h
   2963       && (bfd_link_hash_defined == h->root.type
   2964 	  || bfd_link_hash_defweak == h->root.type)
   2965       && section_offset + 8 <= input_section->size)
   2966     {
   2967       bfd_byte *pnext;
   2968       unsigned long next;
   2969 
   2970       pnext = contents + section_offset + 4;
   2971       next = bfd_get_32 (input_bfd, pnext);
   2972 
   2973       /* The _ptrgl function is magic.  It is used by the AIX
   2974 	 compiler to call a function through a pointer.  */
   2975       if (h->smclas == XMC_GL || strcmp (h->root.root.string, "._ptrgl") == 0)
   2976 	{
   2977 	  if (next == 0x4def7b82			/* cror 15,15,15 */
   2978 	      || next == 0x4ffffb82			/* cror 31,31,31 */
   2979 	      || next == 0x60000000)			/* ori r0,r0,0 */
   2980 	    bfd_put_32 (input_bfd, 0x80410014, pnext);	/* lwz r2,20(r1) */
   2981 
   2982 	}
   2983       else
   2984 	{
   2985 	  if (next == 0x80410014)			/* lwz r2,20(r1) */
   2986 	    bfd_put_32 (input_bfd, 0x60000000, pnext);	/* ori r0,r0,0 */
   2987 	}
   2988     }
   2989   else if (NULL != h && bfd_link_hash_undefined == h->root.type)
   2990     {
   2991       /* Normally, this relocation is against a defined symbol.  In the
   2992 	 case where this is a partial link and the output section offset
   2993 	 is greater than 2^25, the linker will return an invalid error
   2994 	 message that the relocation has been truncated.  Yes it has been
   2995 	 truncated but no it not important.  For this case, disable the
   2996 	 overflow checking. */
   2997 
   2998       howto->complain_on_overflow = complain_overflow_dont;
   2999     }
   3000 
   3001   /* The original PC-relative relocation is biased by -r_vaddr, so adding
   3002      the value below will give the absolute target address.  */
   3003   *relocation = val + addend + rel->r_vaddr;
   3004 
   3005   howto->src_mask &= ~3;
   3006   howto->dst_mask = howto->src_mask;
   3007 
   3008   if (h != NULL
   3009       && (h->root.type == bfd_link_hash_defined
   3010 	  || h->root.type == bfd_link_hash_defweak)
   3011       && bfd_is_abs_section (h->root.u.def.section)
   3012       && section_offset + 4 <= input_section->size)
   3013     {
   3014       bfd_byte *ptr;
   3015       bfd_vma insn;
   3016 
   3017       /* Turn the relative branch into an absolute one by setting the
   3018 	 AA bit.  */
   3019       ptr = contents + section_offset;
   3020       insn = bfd_get_32 (input_bfd, ptr);
   3021       insn |= 2;
   3022       bfd_put_32 (input_bfd, insn, ptr);
   3023 
   3024       /* Make the howto absolute too.  */
   3025       howto->pc_relative = FALSE;
   3026       howto->complain_on_overflow = complain_overflow_bitfield;
   3027     }
   3028   else
   3029     {
   3030       /* Use a PC-relative howto and subtract the instruction's address
   3031 	 from the target address we calculated above.  */
   3032       howto->pc_relative = TRUE;
   3033       *relocation -= (input_section->output_section->vma
   3034 		      + input_section->output_offset
   3035 		      + section_offset);
   3036     }
   3037   return TRUE;
   3038 }
   3039 
   3040 bfd_boolean
   3041 xcoff_reloc_type_crel (input_bfd, input_section, output_bfd, rel, sym, howto,
   3042 		       val, addend, relocation, contents)
   3043      bfd *input_bfd ATTRIBUTE_UNUSED;
   3044      asection *input_section;
   3045      bfd *output_bfd ATTRIBUTE_UNUSED;
   3046      struct internal_reloc *rel ATTRIBUTE_UNUSED;
   3047      struct internal_syment *sym ATTRIBUTE_UNUSED;
   3048      struct reloc_howto_struct *howto;
   3049      bfd_vma val ATTRIBUTE_UNUSED;
   3050      bfd_vma addend;
   3051      bfd_vma *relocation;
   3052      bfd_byte *contents ATTRIBUTE_UNUSED;
   3053 {
   3054   howto->pc_relative = TRUE;
   3055   howto->src_mask &= ~3;
   3056   howto->dst_mask = howto->src_mask;
   3057 
   3058   /* A PC relative reloc includes the section address.  */
   3059   addend += input_section->vma;
   3060 
   3061   *relocation = val + addend;
   3062   *relocation -= (input_section->output_section->vma
   3063 		  + input_section->output_offset);
   3064   return TRUE;
   3065 }
   3066 
   3067 static bfd_boolean
   3068 xcoff_complain_overflow_dont_func (input_bfd, val, relocation, howto)
   3069      bfd *input_bfd ATTRIBUTE_UNUSED;
   3070      bfd_vma val ATTRIBUTE_UNUSED;
   3071      bfd_vma relocation ATTRIBUTE_UNUSED;
   3072      struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
   3073 {
   3074   return FALSE;
   3075 }
   3076 
   3077 static bfd_boolean
   3078 xcoff_complain_overflow_bitfield_func (input_bfd, val, relocation, howto)
   3079      bfd *input_bfd;
   3080      bfd_vma val;
   3081      bfd_vma relocation;
   3082      struct reloc_howto_struct *howto;
   3083 {
   3084   bfd_vma fieldmask, signmask, ss;
   3085   bfd_vma a, b, sum;
   3086 
   3087   /* Get the values to be added together.  For signed and unsigned
   3088      relocations, we assume that all values should be truncated to
   3089      the size of an address.  For bitfields, all the bits matter.
   3090      See also bfd_check_overflow.  */
   3091   fieldmask = N_ONES (howto->bitsize);
   3092   a = relocation;
   3093   b = val & howto->src_mask;
   3094 
   3095   /* Much like unsigned, except no trimming with addrmask.  In
   3096      addition, the sum overflows if there is a carry out of
   3097      the bfd_vma, i.e., the sum is less than either input
   3098      operand.  */
   3099   a >>= howto->rightshift;
   3100   b >>= howto->bitpos;
   3101 
   3102   /* Bitfields are sometimes used for signed numbers; for
   3103      example, a 13-bit field sometimes represents values in
   3104      0..8191 and sometimes represents values in -4096..4095.
   3105      If the field is signed and a is -4095 (0x1001) and b is
   3106      -1 (0x1fff), the sum is -4096 (0x1000), but (0x1001 +
   3107      0x1fff is 0x3000).  It's not clear how to handle this
   3108      everywhere, since there is not way to know how many bits
   3109      are significant in the relocation, but the original code
   3110      assumed that it was fully sign extended, and we will keep
   3111      that assumption.  */
   3112   signmask = (fieldmask >> 1) + 1;
   3113 
   3114   if ((a & ~ fieldmask) != 0)
   3115     {
   3116       /* Some bits out of the field are set.  This might not
   3117 	 be a problem: if this is a signed bitfield, it is OK
   3118 	 iff all the high bits are set, including the sign
   3119 	 bit.  We'll try setting all but the most significant
   3120 	 bit in the original relocation value: if this is all
   3121 	 ones, we are OK, assuming a signed bitfield.  */
   3122       ss = (signmask << howto->rightshift) - 1;
   3123       if ((ss | relocation) != ~ (bfd_vma) 0)
   3124 	return TRUE;
   3125       a &= fieldmask;
   3126     }
   3127 
   3128   /* We just assume (b & ~ fieldmask) == 0.  */
   3129 
   3130   /* We explicitly permit wrap around if this relocation
   3131      covers the high bit of an address.  The Linux kernel
   3132      relies on it, and it is the only way to write assembler
   3133      code which can run when loaded at a location 0x80000000
   3134      away from the location at which it is linked.  */
   3135   if (howto->bitsize + howto->rightshift
   3136       == bfd_arch_bits_per_address (input_bfd))
   3137     return FALSE;
   3138 
   3139   sum = a + b;
   3140   if (sum < a || (sum & ~ fieldmask) != 0)
   3141     {
   3142       /* There was a carry out, or the field overflow.  Test
   3143 	 for signed operands again.  Here is the overflow test
   3144 	 is as for complain_overflow_signed.  */
   3145       if (((~ (a ^ b)) & (a ^ sum)) & signmask)
   3146 	return TRUE;
   3147     }
   3148 
   3149   return FALSE;
   3150 }
   3151 
   3152 static bfd_boolean
   3153 xcoff_complain_overflow_signed_func (input_bfd, val, relocation, howto)
   3154      bfd *input_bfd;
   3155      bfd_vma val;
   3156      bfd_vma relocation;
   3157      struct reloc_howto_struct *howto;
   3158 {
   3159   bfd_vma addrmask, fieldmask, signmask, ss;
   3160   bfd_vma a, b, sum;
   3161 
   3162   /* Get the values to be added together.  For signed and unsigned
   3163      relocations, we assume that all values should be truncated to
   3164      the size of an address.  For bitfields, all the bits matter.
   3165      See also bfd_check_overflow.  */
   3166   fieldmask = N_ONES (howto->bitsize);
   3167   addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask;
   3168   a = relocation;
   3169   b = val & howto->src_mask;
   3170 
   3171   a = (a & addrmask) >> howto->rightshift;
   3172 
   3173   /* If any sign bits are set, all sign bits must be set.
   3174      That is, A must be a valid negative address after
   3175      shifting.  */
   3176   signmask = ~ (fieldmask >> 1);
   3177   ss = a & signmask;
   3178   if (ss != 0 && ss != ((addrmask >> howto->rightshift) & signmask))
   3179     return TRUE;
   3180 
   3181   /* We only need this next bit of code if the sign bit of B
   3182      is below the sign bit of A.  This would only happen if
   3183      SRC_MASK had fewer bits than BITSIZE.  Note that if
   3184      SRC_MASK has more bits than BITSIZE, we can get into
   3185      trouble; we would need to verify that B is in range, as
   3186      we do for A above.  */
   3187   signmask = ((~ howto->src_mask) >> 1) & howto->src_mask;
   3188   if ((b & signmask) != 0)
   3189     {
   3190       /* Set all the bits above the sign bit.  */
   3191       b -= signmask <<= 1;
   3192     }
   3193 
   3194   b = (b & addrmask) >> howto->bitpos;
   3195 
   3196   /* Now we can do the addition.  */
   3197   sum = a + b;
   3198 
   3199   /* See if the result has the correct sign.  Bits above the
   3200      sign bit are junk now; ignore them.  If the sum is
   3201      positive, make sure we did not have all negative inputs;
   3202      if the sum is negative, make sure we did not have all
   3203      positive inputs.  The test below looks only at the sign
   3204      bits, and it really just
   3205      SIGN (A) == SIGN (B) && SIGN (A) != SIGN (SUM)
   3206   */
   3207   signmask = (fieldmask >> 1) + 1;
   3208   if (((~ (a ^ b)) & (a ^ sum)) & signmask)
   3209     return TRUE;
   3210 
   3211   return FALSE;
   3212 }
   3213 
   3214 static bfd_boolean
   3215 xcoff_complain_overflow_unsigned_func (input_bfd, val, relocation, howto)
   3216      bfd *input_bfd;
   3217      bfd_vma val;
   3218      bfd_vma relocation;
   3219      struct reloc_howto_struct *howto;
   3220 {
   3221   bfd_vma addrmask, fieldmask;
   3222   bfd_vma a, b, sum;
   3223 
   3224   /* Get the values to be added together.  For signed and unsigned
   3225      relocations, we assume that all values should be truncated to
   3226      the size of an address.  For bitfields, all the bits matter.
   3227      See also bfd_check_overflow.  */
   3228   fieldmask = N_ONES (howto->bitsize);
   3229   addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask;
   3230   a = relocation;
   3231   b = val & howto->src_mask;
   3232 
   3233   /* Checking for an unsigned overflow is relatively easy:
   3234      trim the addresses and add, and trim the result as well.
   3235      Overflow is normally indicated when the result does not
   3236      fit in the field.  However, we also need to consider the
   3237      case when, e.g., fieldmask is 0x7fffffff or smaller, an
   3238      input is 0x80000000, and bfd_vma is only 32 bits; then we
   3239      will get sum == 0, but there is an overflow, since the
   3240      inputs did not fit in the field.  Instead of doing a
   3241      separate test, we can check for this by or-ing in the
   3242      operands when testing for the sum overflowing its final
   3243      field.  */
   3244   a = (a & addrmask) >> howto->rightshift;
   3245   b = (b & addrmask) >> howto->bitpos;
   3246   sum = (a + b) & addrmask;
   3247   if ((a | b | sum) & ~ fieldmask)
   3248     return TRUE;
   3249 
   3250   return FALSE;
   3251 }
   3252 
   3253 /* This is the relocation function for the RS/6000/POWER/PowerPC.
   3254    This is currently the only processor which uses XCOFF; I hope that
   3255    will never change.
   3256 
   3257    I took the relocation type definitions from two documents:
   3258    the PowerPC AIX Version 4 Application Binary Interface, First
   3259    Edition (April 1992), and the PowerOpen ABI, Big-Endian
   3260    32-Bit Hardware Implementation (June 30, 1994).  Differences
   3261    between the documents are noted below.
   3262 
   3263    Unsupported r_type's
   3264 
   3265    R_RTB:
   3266    R_RRTBI:
   3267    R_RRTBA:
   3268 
   3269    These relocs are defined by the PowerPC ABI to be
   3270    relative branches which use half of the difference
   3271    between the symbol and the program counter.  I can't
   3272    quite figure out when this is useful.  These relocs are
   3273    not defined by the PowerOpen ABI.
   3274 
   3275    Supported r_type's
   3276 
   3277    R_POS:
   3278    Simple positive relocation.
   3279 
   3280    R_NEG:
   3281    Simple negative relocation.
   3282 
   3283    R_REL:
   3284    Simple PC relative relocation.
   3285 
   3286    R_TOC:
   3287    TOC relative relocation.  The value in the instruction in
   3288    the input file is the offset from the input file TOC to
   3289    the desired location.  We want the offset from the final
   3290    TOC to the desired location.  We have:
   3291    isym = iTOC + in
   3292    iinsn = in + o
   3293    osym = oTOC + on
   3294    oinsn = on + o
   3295    so we must change insn by on - in.
   3296 
   3297    R_GL:
   3298    GL linkage relocation.  The value of this relocation
   3299    is the address of the entry in the TOC section.
   3300 
   3301    R_TCL:
   3302    Local object TOC address.  I can't figure out the
   3303    difference between this and case R_GL.
   3304 
   3305    R_TRL:
   3306    TOC relative relocation.  A TOC relative load instruction
   3307    which may be changed to a load address instruction.
   3308    FIXME: We don't currently implement this optimization.
   3309 
   3310    R_TRLA:
   3311    TOC relative relocation.  This is a TOC relative load
   3312    address instruction which may be changed to a load
   3313    instruction.  FIXME: I don't know if this is the correct
   3314    implementation.
   3315 
   3316    R_BA:
   3317    Absolute branch.  We don't want to mess with the lower
   3318    two bits of the instruction.
   3319 
   3320    R_CAI:
   3321    The PowerPC ABI defines this as an absolute call which
   3322    may be modified to become a relative call.  The PowerOpen
   3323    ABI does not define this relocation type.
   3324 
   3325    R_RBA:
   3326    Absolute branch which may be modified to become a
   3327    relative branch.
   3328 
   3329    R_RBAC:
   3330    The PowerPC ABI defines this as an absolute branch to a
   3331    fixed address which may be modified to an absolute branch
   3332    to a symbol.  The PowerOpen ABI does not define this
   3333    relocation type.
   3334 
   3335    R_RBRC:
   3336    The PowerPC ABI defines this as an absolute branch to a
   3337    fixed address which may be modified to a relative branch.
   3338    The PowerOpen ABI does not define this relocation type.
   3339 
   3340    R_BR:
   3341    Relative branch.  We don't want to mess with the lower
   3342    two bits of the instruction.
   3343 
   3344    R_CREL:
   3345    The PowerPC ABI defines this as a relative call which may
   3346    be modified to become an absolute call.  The PowerOpen
   3347    ABI does not define this relocation type.
   3348 
   3349    R_RBR:
   3350    A relative branch which may be modified to become an
   3351    absolute branch.
   3352 
   3353    R_RL:
   3354    The PowerPC AIX ABI describes this as a load which may be
   3355    changed to a load address.  The PowerOpen ABI says this
   3356    is the same as case R_POS.
   3357 
   3358    R_RLA:
   3359    The PowerPC AIX ABI describes this as a load address
   3360    which may be changed to a load.  The PowerOpen ABI says
   3361    this is the same as R_POS.
   3362 */
   3363 
   3364 bfd_boolean
   3365 xcoff_ppc_relocate_section (output_bfd, info, input_bfd,
   3366 			    input_section, contents, relocs, syms,
   3367 			    sections)
   3368      bfd *output_bfd;
   3369      struct bfd_link_info *info;
   3370      bfd *input_bfd;
   3371      asection *input_section;
   3372      bfd_byte *contents;
   3373      struct internal_reloc *relocs;
   3374      struct internal_syment *syms;
   3375      asection **sections;
   3376 {
   3377   struct internal_reloc *rel;
   3378   struct internal_reloc *relend;
   3379 
   3380   rel = relocs;
   3381   relend = rel + input_section->reloc_count;
   3382   for (; rel < relend; rel++)
   3383     {
   3384       long symndx;
   3385       struct xcoff_link_hash_entry *h;
   3386       struct internal_syment *sym;
   3387       bfd_vma addend;
   3388       bfd_vma val;
   3389       struct reloc_howto_struct howto;
   3390       bfd_vma relocation;
   3391       bfd_vma value_to_relocate;
   3392       bfd_vma address;
   3393       bfd_byte *location;
   3394 
   3395       /* Relocation type R_REF is a special relocation type which is
   3396 	 merely used to prevent garbage collection from occurring for
   3397 	 the csect including the symbol which it references.  */
   3398       if (rel->r_type == R_REF)
   3399 	continue;
   3400 
   3401       /* howto */
   3402       howto.type = rel->r_type;
   3403       howto.rightshift = 0;
   3404       howto.bitsize = (rel->r_size & 0x1f) + 1;
   3405       howto.size = howto.bitsize > 16 ? 2 : 1;
   3406       howto.pc_relative = FALSE;
   3407       howto.bitpos = 0;
   3408       howto.complain_on_overflow = (rel->r_size & 0x80
   3409 				    ? complain_overflow_signed
   3410 				    : complain_overflow_bitfield);
   3411       howto.special_function = NULL;
   3412       howto.name = "internal";
   3413       howto.partial_inplace = TRUE;
   3414       howto.src_mask = howto.dst_mask = N_ONES (howto.bitsize);
   3415       howto.pcrel_offset = FALSE;
   3416 
   3417       /* symbol */
   3418       val = 0;
   3419       addend = 0;
   3420       h = NULL;
   3421       sym = NULL;
   3422       symndx = rel->r_symndx;
   3423 
   3424       if (-1 != symndx)
   3425 	{
   3426 	  asection *sec;
   3427 
   3428 	  h = obj_xcoff_sym_hashes (input_bfd)[symndx];
   3429 	  sym = syms + symndx;
   3430 	  addend = - sym->n_value;
   3431 
   3432 	  if (NULL == h)
   3433 	    {
   3434 	      sec = sections[symndx];
   3435 	      /* Hack to make sure we use the right TOC anchor value
   3436 		 if this reloc is against the TOC anchor.  */
   3437 	      if (sec->name[3] == '0'
   3438 		  && strcmp (sec->name, ".tc0") == 0)
   3439 		val = xcoff_data (output_bfd)->toc;
   3440 	      else
   3441 		val = (sec->output_section->vma
   3442 		       + sec->output_offset
   3443 		       + sym->n_value
   3444 		       - sec->vma);
   3445 	    }
   3446 	  else
   3447 	    {
   3448 	      if (info->unresolved_syms_in_objects != RM_IGNORE
   3449 		  && (h->flags & XCOFF_WAS_UNDEFINED) != 0)
   3450 		{
   3451 		  if (! ((*info->callbacks->undefined_symbol)
   3452 			 (info, h->root.root.string,
   3453 			  input_bfd, input_section,
   3454 			  rel->r_vaddr - input_section->vma,
   3455 			  (info->unresolved_syms_in_objects
   3456 			   == RM_GENERATE_ERROR))))
   3457 		    return FALSE;
   3458 		}
   3459 	      if (h->root.type == bfd_link_hash_defined
   3460 		  || h->root.type == bfd_link_hash_defweak)
   3461 		{
   3462 		  sec = h->root.u.def.section;
   3463 		  val = (h->root.u.def.value
   3464 			 + sec->output_section->vma
   3465 			 + sec->output_offset);
   3466 		}
   3467 	      else if (h->root.type == bfd_link_hash_common)
   3468 		{
   3469 		  sec = h->root.u.c.p->section;
   3470 		  val = (sec->output_section->vma
   3471 			 + sec->output_offset);
   3472 
   3473 		}
   3474 	      else
   3475 		{
   3476 		  BFD_ASSERT (info->relocatable
   3477 			      || (info->static_link
   3478 				  && (h->flags & XCOFF_WAS_UNDEFINED) != 0)
   3479 			      || (h->flags & XCOFF_DEF_DYNAMIC) != 0
   3480 			      || (h->flags & XCOFF_IMPORT) != 0);
   3481 		}
   3482 	    }
   3483 	}
   3484 
   3485       if (rel->r_type >= XCOFF_MAX_CALCULATE_RELOCATION
   3486 	  || !((*xcoff_calculate_relocation[rel->r_type])
   3487 	       (input_bfd, input_section, output_bfd, rel, sym, &howto, val,
   3488 		addend, &relocation, contents)))
   3489 	return FALSE;
   3490 
   3491       /* address */
   3492       address = rel->r_vaddr - input_section->vma;
   3493       location = contents + address;
   3494 
   3495       if (address > input_section->size)
   3496 	abort ();
   3497 
   3498       /* Get the value we are going to relocate.  */
   3499       if (1 == howto.size)
   3500 	value_to_relocate = bfd_get_16 (input_bfd, location);
   3501       else
   3502 	value_to_relocate = bfd_get_32 (input_bfd, location);
   3503 
   3504       /* overflow.
   3505 
   3506 	 FIXME: We may drop bits during the addition
   3507 	 which we don't check for.  We must either check at every single
   3508 	 operation, which would be tedious, or we must do the computations
   3509 	 in a type larger than bfd_vma, which would be inefficient.  */
   3510 
   3511       if ((unsigned int) howto.complain_on_overflow
   3512 	  >= XCOFF_MAX_COMPLAIN_OVERFLOW)
   3513 	abort ();
   3514 
   3515       if (((*xcoff_complain_overflow[howto.complain_on_overflow])
   3516 	   (input_bfd, value_to_relocate, relocation, &howto)))
   3517 	{
   3518 	  const char *name;
   3519 	  char buf[SYMNMLEN + 1];
   3520 	  char reloc_type_name[10];
   3521 
   3522 	  if (symndx == -1)
   3523 	    {
   3524 	      name = "*ABS*";
   3525 	    }
   3526 	  else if (h != NULL)
   3527 	    {
   3528 	      name = NULL;
   3529 	    }
   3530 	  else
   3531 	    {
   3532 	      name = _bfd_coff_internal_syment_name (input_bfd, sym, buf);
   3533 	      if (name == NULL)
   3534 		name = "UNKNOWN";
   3535 	    }
   3536 	  sprintf (reloc_type_name, "0x%02x", rel->r_type);
   3537 
   3538 	  if (! ((*info->callbacks->reloc_overflow)
   3539 		 (info, (h ? &h->root : NULL), name, reloc_type_name,
   3540 		  (bfd_vma) 0, input_bfd, input_section,
   3541 		  rel->r_vaddr - input_section->vma)))
   3542 	    return FALSE;
   3543 	}
   3544 
   3545       /* Add RELOCATION to the right bits of VALUE_TO_RELOCATE.  */
   3546       value_to_relocate = ((value_to_relocate & ~howto.dst_mask)
   3547 			   | (((value_to_relocate & howto.src_mask)
   3548 			       + relocation) & howto.dst_mask));
   3549 
   3550       /* Put the value back in the object file.  */
   3551       if (1 == howto.size)
   3552 	bfd_put_16 (input_bfd, value_to_relocate, location);
   3553       else
   3554 	bfd_put_32 (input_bfd, value_to_relocate, location);
   3555     }
   3556 
   3557   return TRUE;
   3558 }
   3559 
   3560 static bfd_boolean
   3561 _bfd_xcoff_put_ldsymbol_name (abfd, ldinfo, ldsym, name)
   3562      bfd *abfd ATTRIBUTE_UNUSED;
   3563 	 struct xcoff_loader_info *ldinfo;
   3564 	 struct internal_ldsym *ldsym;
   3565 	 const char *name;
   3566 {
   3567   size_t len;
   3568   len = strlen (name);
   3569 
   3570   if (len <= SYMNMLEN)
   3571     strncpy (ldsym->_l._l_name, name, SYMNMLEN);
   3572   else
   3573     {
   3574       if (ldinfo->string_size + len + 3 > ldinfo->string_alc)
   3575 	{
   3576 	  bfd_size_type newalc;
   3577 	  char *newstrings;
   3578 
   3579 	  newalc = ldinfo->string_alc * 2;
   3580 	  if (newalc == 0)
   3581 	    newalc = 32;
   3582 	  while (ldinfo->string_size + len + 3 > newalc)
   3583 	    newalc *= 2;
   3584 
   3585 	  newstrings = bfd_realloc (ldinfo->strings, newalc);
   3586 	  if (newstrings == NULL)
   3587 	    {
   3588 	      ldinfo->failed = TRUE;
   3589 	      return FALSE;
   3590 	    }
   3591 	  ldinfo->string_alc = newalc;
   3592 	  ldinfo->strings = newstrings;
   3593 	}
   3594 
   3595       bfd_put_16 (ldinfo->output_bfd, (bfd_vma) (len + 1),
   3596 		  ldinfo->strings + ldinfo->string_size);
   3597       strcpy (ldinfo->strings + ldinfo->string_size + 2, name);
   3598       ldsym->_l._l_l._l_zeroes = 0;
   3599       ldsym->_l._l_l._l_offset = ldinfo->string_size + 2;
   3600       ldinfo->string_size += len + 3;
   3601     }
   3602 
   3603   return TRUE;
   3604 }
   3605 
   3606 static bfd_boolean
   3607 _bfd_xcoff_put_symbol_name (bfd *abfd, struct bfd_strtab_hash *strtab,
   3608 			    struct internal_syment *sym,
   3609 			    const char *name)
   3610 {
   3611   if (strlen (name) <= SYMNMLEN)
   3612     {
   3613       strncpy (sym->_n._n_name, name, SYMNMLEN);
   3614     }
   3615   else
   3616     {
   3617       bfd_boolean hash;
   3618       bfd_size_type indx;
   3619 
   3620       hash = TRUE;
   3621       if ((abfd->flags & BFD_TRADITIONAL_FORMAT) != 0)
   3622 	hash = FALSE;
   3623       indx = _bfd_stringtab_add (strtab, name, hash, FALSE);
   3624       if (indx == (bfd_size_type) -1)
   3625 	return FALSE;
   3626       sym->_n._n_n._n_zeroes = 0;
   3627       sym->_n._n_n._n_offset = STRING_SIZE_SIZE + indx;
   3628     }
   3629   return TRUE;
   3630 }
   3631 
   3632 static asection *
   3633 xcoff_create_csect_from_smclas (abfd, aux, symbol_name)
   3634      bfd *abfd;
   3635      union internal_auxent *aux;
   3636      const char *symbol_name;
   3637 {
   3638   asection *return_value = NULL;
   3639 
   3640   /* .sv64 = x_smclas == 17
   3641      This is an invalid csect for 32 bit apps.  */
   3642   static const char *names[19] =
   3643   {
   3644     ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo",
   3645     ".sv", ".bs", ".ds", ".uc", ".ti", ".tb", NULL, ".tc0",
   3646     ".td", NULL, ".sv3264"
   3647   };
   3648 
   3649   if ((19 >= aux->x_csect.x_smclas)
   3650       && (NULL != names[aux->x_csect.x_smclas]))
   3651     {
   3652       return_value = bfd_make_section_anyway
   3653 	(abfd, names[aux->x_csect.x_smclas]);
   3654     }
   3655   else
   3656     {
   3657       (*_bfd_error_handler)
   3658 	(_("%B: symbol `%s' has unrecognized smclas %d"),
   3659 	 abfd, symbol_name, aux->x_csect.x_smclas);
   3660       bfd_set_error (bfd_error_bad_value);
   3661     }
   3662 
   3663   return return_value;
   3664 }
   3665 
   3666 static bfd_boolean
   3667 xcoff_is_lineno_count_overflow (abfd, value)
   3668     bfd *abfd ATTRIBUTE_UNUSED;
   3669 	bfd_vma value;
   3670 {
   3671   if (0xffff <= value)
   3672     return TRUE;
   3673 
   3674   return FALSE;
   3675 }
   3676 
   3677 static bfd_boolean
   3678 xcoff_is_reloc_count_overflow (abfd, value)
   3679     bfd *abfd ATTRIBUTE_UNUSED;
   3680 	bfd_vma value;
   3681 {
   3682   if (0xffff <= value)
   3683     return TRUE;
   3684 
   3685   return FALSE;
   3686 }
   3687 
   3688 static bfd_vma
   3689 xcoff_loader_symbol_offset (abfd, ldhdr)
   3690     bfd *abfd;
   3691     struct internal_ldhdr *ldhdr ATTRIBUTE_UNUSED;
   3692 {
   3693   return bfd_xcoff_ldhdrsz (abfd);
   3694 }
   3695 
   3696 static bfd_vma
   3697 xcoff_loader_reloc_offset (abfd, ldhdr)
   3698     bfd *abfd;
   3699     struct internal_ldhdr *ldhdr;
   3700 {
   3701   return bfd_xcoff_ldhdrsz (abfd) + ldhdr->l_nsyms * bfd_xcoff_ldsymsz (abfd);
   3702 }
   3703 
   3704 static bfd_boolean
   3705 xcoff_generate_rtinit  (abfd, init, fini, rtld)
   3706      bfd *abfd;
   3707      const char *init;
   3708      const char *fini;
   3709      bfd_boolean rtld;
   3710 {
   3711   bfd_byte filehdr_ext[FILHSZ];
   3712   bfd_byte scnhdr_ext[SCNHSZ];
   3713   bfd_byte syment_ext[SYMESZ * 10];
   3714   bfd_byte reloc_ext[RELSZ * 3];
   3715   bfd_byte *data_buffer;
   3716   bfd_size_type data_buffer_size;
   3717   bfd_byte *string_table = NULL, *st_tmp = NULL;
   3718   bfd_size_type string_table_size;
   3719   bfd_vma val;
   3720   size_t initsz, finisz;
   3721   struct internal_filehdr filehdr;
   3722   struct internal_scnhdr scnhdr;
   3723   struct internal_syment syment;
   3724   union internal_auxent auxent;
   3725   struct internal_reloc reloc;
   3726 
   3727   char *data_name = ".data";
   3728   char *rtinit_name = "__rtinit";
   3729   char *rtld_name = "__rtld";
   3730 
   3731   if (! bfd_xcoff_rtinit_size (abfd))
   3732     return FALSE;
   3733 
   3734   initsz = (init == NULL ? 0 : 1 + strlen (init));
   3735   finisz = (fini == NULL ? 0 : 1 + strlen (fini));
   3736 
   3737   /* file header */
   3738   memset (filehdr_ext, 0, FILHSZ);
   3739   memset (&filehdr, 0, sizeof (struct internal_filehdr));
   3740   filehdr.f_magic = bfd_xcoff_magic_number (abfd);
   3741   filehdr.f_nscns = 1;
   3742   filehdr.f_timdat = 0;
   3743   filehdr.f_nsyms = 0;  /* at least 6, no more than 10 */
   3744   filehdr.f_symptr = 0; /* set below */
   3745   filehdr.f_opthdr = 0;
   3746   filehdr.f_flags = 0;
   3747 
   3748   /* section header */
   3749   memset (scnhdr_ext, 0, SCNHSZ);
   3750   memset (&scnhdr, 0, sizeof (struct internal_scnhdr));
   3751   memcpy (scnhdr.s_name, data_name, strlen (data_name));
   3752   scnhdr.s_paddr = 0;
   3753   scnhdr.s_vaddr = 0;
   3754   scnhdr.s_size = 0;    /* set below */
   3755   scnhdr.s_scnptr = FILHSZ + SCNHSZ;
   3756   scnhdr.s_relptr = 0;  /* set below */
   3757   scnhdr.s_lnnoptr = 0;
   3758   scnhdr.s_nreloc = 0;  /* either 1 or 2 */
   3759   scnhdr.s_nlnno = 0;
   3760   scnhdr.s_flags = STYP_DATA;
   3761 
   3762   /* .data
   3763      0x0000	      0x00000000 : rtl
   3764      0x0004	      0x00000010 : offset to init, or 0
   3765      0x0008	      0x00000028 : offset to fini, or 0
   3766      0x000C	      0x0000000C : size of descriptor
   3767      0x0010	      0x00000000 : init, needs a reloc
   3768      0x0014	      0x00000040 : offset to init name
   3769      0x0018	      0x00000000 : flags, padded to a word
   3770      0x001C	      0x00000000 : empty init
   3771      0x0020	      0x00000000 :
   3772      0x0024	      0x00000000 :
   3773      0x0028	      0x00000000 : fini, needs a reloc
   3774      0x002C	      0x00000??? : offset to fini name
   3775      0x0030	      0x00000000 : flags, padded to a word
   3776      0x0034	      0x00000000 : empty fini
   3777      0x0038	      0x00000000 :
   3778      0x003C	      0x00000000 :
   3779      0x0040	      init name
   3780      0x0040 + initsz  fini name */
   3781 
   3782   data_buffer_size = 0x0040 + initsz + finisz;
   3783   data_buffer_size = (data_buffer_size + 7) &~ (bfd_size_type) 7;
   3784   data_buffer = NULL;
   3785   data_buffer = (bfd_byte *) bfd_zmalloc (data_buffer_size);
   3786   if (data_buffer == NULL)
   3787     return FALSE;
   3788 
   3789   if (initsz)
   3790     {
   3791       val = 0x10;
   3792       bfd_h_put_32 (abfd, val, &data_buffer[0x04]);
   3793       val = 0x40;
   3794       bfd_h_put_32 (abfd, val, &data_buffer[0x14]);
   3795       memcpy (&data_buffer[val], init, initsz);
   3796     }
   3797 
   3798   if (finisz)
   3799     {
   3800       val = 0x28;
   3801       bfd_h_put_32 (abfd, val, &data_buffer[0x08]);
   3802       val = 0x40 + initsz;
   3803       bfd_h_put_32 (abfd, val, &data_buffer[0x2C]);
   3804       memcpy (&data_buffer[val], fini, finisz);
   3805     }
   3806 
   3807   val = 0x0C;
   3808   bfd_h_put_32 (abfd, val, &data_buffer[0x0C]);
   3809 
   3810   scnhdr.s_size = data_buffer_size;
   3811 
   3812   /* string table */
   3813   string_table_size = 0;
   3814   if (initsz > 9)
   3815     string_table_size += initsz;
   3816   if (finisz > 9)
   3817     string_table_size += finisz;
   3818   if (string_table_size)
   3819     {
   3820       string_table_size += 4;
   3821       string_table = (bfd_byte *) bfd_zmalloc (string_table_size);
   3822       if (string_table == NULL)
   3823 	return FALSE;
   3824 
   3825       val = string_table_size;
   3826       bfd_h_put_32 (abfd, val, &string_table[0]);
   3827       st_tmp = string_table + 4;
   3828     }
   3829 
   3830   /* symbols
   3831      0. .data csect
   3832      2. __rtinit
   3833      4. init function
   3834      6. fini function
   3835      8. __rtld  */
   3836   memset (syment_ext, 0, 10 * SYMESZ);
   3837   memset (reloc_ext, 0, 3 * RELSZ);
   3838 
   3839   /* .data csect */
   3840   memset (&syment, 0, sizeof (struct internal_syment));
   3841   memset (&auxent, 0, sizeof (union internal_auxent));
   3842   memcpy (syment._n._n_name, data_name, strlen (data_name));
   3843   syment.n_scnum = 1;
   3844   syment.n_sclass = C_HIDEXT;
   3845   syment.n_numaux = 1;
   3846   auxent.x_csect.x_scnlen.l = data_buffer_size;
   3847   auxent.x_csect.x_smtyp = 3 << 3 | XTY_SD;
   3848   auxent.x_csect.x_smclas = XMC_RW;
   3849   bfd_coff_swap_sym_out (abfd, &syment,
   3850 			 &syment_ext[filehdr.f_nsyms * SYMESZ]);
   3851   bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
   3852 			 syment.n_numaux,
   3853 			 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
   3854   filehdr.f_nsyms += 2;
   3855 
   3856   /* __rtinit */
   3857   memset (&syment, 0, sizeof (struct internal_syment));
   3858   memset (&auxent, 0, sizeof (union internal_auxent));
   3859   memcpy (syment._n._n_name, rtinit_name, strlen (rtinit_name));
   3860   syment.n_scnum = 1;
   3861   syment.n_sclass = C_EXT;
   3862   syment.n_numaux = 1;
   3863   auxent.x_csect.x_smtyp = XTY_LD;
   3864   auxent.x_csect.x_smclas = XMC_RW;
   3865   bfd_coff_swap_sym_out (abfd, &syment,
   3866 			 &syment_ext[filehdr.f_nsyms * SYMESZ]);
   3867   bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
   3868 			 syment.n_numaux,
   3869 			 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
   3870   filehdr.f_nsyms += 2;
   3871 
   3872   /* init */
   3873   if (initsz)
   3874     {
   3875       memset (&syment, 0, sizeof (struct internal_syment));
   3876       memset (&auxent, 0, sizeof (union internal_auxent));
   3877 
   3878       if (initsz > 9)
   3879 	{
   3880 	  syment._n._n_n._n_offset = st_tmp - string_table;
   3881 	  memcpy (st_tmp, init, initsz);
   3882 	  st_tmp += initsz;
   3883 	}
   3884       else
   3885 	memcpy (syment._n._n_name, init, initsz - 1);
   3886 
   3887       syment.n_sclass = C_EXT;
   3888       syment.n_numaux = 1;
   3889       bfd_coff_swap_sym_out (abfd, &syment,
   3890 			     &syment_ext[filehdr.f_nsyms * SYMESZ]);
   3891       bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
   3892 			     syment.n_numaux,
   3893 			     &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
   3894 
   3895       /* reloc */
   3896       memset (&reloc, 0, sizeof (struct internal_reloc));
   3897       reloc.r_vaddr = 0x0010;
   3898       reloc.r_symndx = filehdr.f_nsyms;
   3899       reloc.r_type = R_POS;
   3900       reloc.r_size = 31;
   3901       bfd_coff_swap_reloc_out (abfd, &reloc, &reloc_ext[0]);
   3902 
   3903       filehdr.f_nsyms += 2;
   3904       scnhdr.s_nreloc += 1;
   3905     }
   3906 
   3907   /* fini */
   3908   if (finisz)
   3909     {
   3910       memset (&syment, 0, sizeof (struct internal_syment));
   3911       memset (&auxent, 0, sizeof (union internal_auxent));
   3912 
   3913       if (finisz > 9)
   3914 	{
   3915 	  syment._n._n_n._n_offset = st_tmp - string_table;
   3916 	  memcpy (st_tmp, fini, finisz);
   3917 	  st_tmp += finisz;
   3918 	}
   3919       else
   3920 	memcpy (syment._n._n_name, fini, finisz - 1);
   3921 
   3922       syment.n_sclass = C_EXT;
   3923       syment.n_numaux = 1;
   3924       bfd_coff_swap_sym_out (abfd, &syment,
   3925 			     &syment_ext[filehdr.f_nsyms * SYMESZ]);
   3926       bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
   3927 			     syment.n_numaux,
   3928 			     &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
   3929 
   3930       /* reloc */
   3931       memset (&reloc, 0, sizeof (struct internal_reloc));
   3932       reloc.r_vaddr = 0x0028;
   3933       reloc.r_symndx = filehdr.f_nsyms;
   3934       reloc.r_type = R_POS;
   3935       reloc.r_size = 31;
   3936       bfd_coff_swap_reloc_out (abfd, &reloc,
   3937 			       &reloc_ext[scnhdr.s_nreloc * RELSZ]);
   3938 
   3939       filehdr.f_nsyms += 2;
   3940       scnhdr.s_nreloc += 1;
   3941     }
   3942 
   3943   if (rtld)
   3944     {
   3945       memset (&syment, 0, sizeof (struct internal_syment));
   3946       memset (&auxent, 0, sizeof (union internal_auxent));
   3947       memcpy (syment._n._n_name, rtld_name, strlen (rtld_name));
   3948       syment.n_sclass = C_EXT;
   3949       syment.n_numaux = 1;
   3950       bfd_coff_swap_sym_out (abfd, &syment,
   3951 			     &syment_ext[filehdr.f_nsyms * SYMESZ]);
   3952       bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
   3953 			     syment.n_numaux,
   3954 			     &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
   3955 
   3956       /* reloc */
   3957       memset (&reloc, 0, sizeof (struct internal_reloc));
   3958       reloc.r_vaddr = 0x0000;
   3959       reloc.r_symndx = filehdr.f_nsyms;
   3960       reloc.r_type = R_POS;
   3961       reloc.r_size = 31;
   3962       bfd_coff_swap_reloc_out (abfd, &reloc,
   3963 			       &reloc_ext[scnhdr.s_nreloc * RELSZ]);
   3964 
   3965       filehdr.f_nsyms += 2;
   3966       scnhdr.s_nreloc += 1;
   3967     }
   3968 
   3969   scnhdr.s_relptr = scnhdr.s_scnptr + data_buffer_size;
   3970   filehdr.f_symptr = scnhdr.s_relptr + scnhdr.s_nreloc * RELSZ;
   3971 
   3972   bfd_coff_swap_filehdr_out (abfd, &filehdr, filehdr_ext);
   3973   bfd_bwrite (filehdr_ext, FILHSZ, abfd);
   3974   bfd_coff_swap_scnhdr_out (abfd, &scnhdr, scnhdr_ext);
   3975   bfd_bwrite (scnhdr_ext, SCNHSZ, abfd);
   3976   bfd_bwrite (data_buffer, data_buffer_size, abfd);
   3977   bfd_bwrite (reloc_ext, scnhdr.s_nreloc * RELSZ, abfd);
   3978   bfd_bwrite (syment_ext, filehdr.f_nsyms * SYMESZ, abfd);
   3979   bfd_bwrite (string_table, string_table_size, abfd);
   3980 
   3981   free (data_buffer);
   3982   data_buffer = NULL;
   3983 
   3984   return TRUE;
   3985 }
   3986 
   3987 
   3988 static reloc_howto_type xcoff_dynamic_reloc =
   3989 HOWTO (0,			/* type */
   3990        0,			/* rightshift */
   3991        2,			/* size (0 = byte, 1 = short, 2 = long) */
   3992        32,			/* bitsize */
   3993        FALSE,			/* pc_relative */
   3994        0,			/* bitpos */
   3995        complain_overflow_bitfield, /* complain_on_overflow */
   3996        0,			/* special_function */
   3997        "R_POS",			/* name */
   3998        TRUE,			/* partial_inplace */
   3999        0xffffffff,		/* src_mask */
   4000        0xffffffff,		/* dst_mask */
   4001        FALSE);			/* pcrel_offset */
   4002 
   4003 /*  glink
   4004 
   4005    The first word of global linkage code must be modified by filling in
   4006    the correct TOC offset.  */
   4007 
   4008 static unsigned long xcoff_glink_code[9] =
   4009   {
   4010     0x81820000,	/* lwz r12,0(r2) */
   4011     0x90410014,	/* stw r2,20(r1) */
   4012     0x800c0000,	/* lwz r0,0(r12) */
   4013     0x804c0004,	/* lwz r2,4(r12) */
   4014     0x7c0903a6,	/* mtctr r0 */
   4015     0x4e800420,	/* bctr */
   4016     0x00000000,	/* start of traceback table */
   4017     0x000c8000,	/* traceback table */
   4018     0x00000000,	/* traceback table */
   4019   };
   4020 
   4021 
   4022 static const struct xcoff_backend_data_rec bfd_xcoff_backend_data =
   4023   {
   4024     { /* COFF backend, defined in libcoff.h.  */
   4025       _bfd_xcoff_swap_aux_in,
   4026       _bfd_xcoff_swap_sym_in,
   4027       coff_swap_lineno_in,
   4028       _bfd_xcoff_swap_aux_out,
   4029       _bfd_xcoff_swap_sym_out,
   4030       coff_swap_lineno_out,
   4031       xcoff_swap_reloc_out,
   4032       coff_swap_filehdr_out,
   4033       coff_swap_aouthdr_out,
   4034       coff_swap_scnhdr_out,
   4035       FILHSZ,
   4036       AOUTSZ,
   4037       SCNHSZ,
   4038       SYMESZ,
   4039       AUXESZ,
   4040       RELSZ,
   4041       LINESZ,
   4042       FILNMLEN,
   4043       TRUE,			/* _bfd_coff_long_filenames */
   4044       XCOFF_NO_LONG_SECTION_NAMES,  /* _bfd_coff_long_section_names */
   4045       3,			/* _bfd_coff_default_section_alignment_power */
   4046       FALSE,			/* _bfd_coff_force_symnames_in_strings */
   4047       2,			/* _bfd_coff_debug_string_prefix_length */
   4048       coff_swap_filehdr_in,
   4049       coff_swap_aouthdr_in,
   4050       coff_swap_scnhdr_in,
   4051       xcoff_swap_reloc_in,
   4052       coff_bad_format_hook,
   4053       coff_set_arch_mach_hook,
   4054       coff_mkobject_hook,
   4055       styp_to_sec_flags,
   4056       coff_set_alignment_hook,
   4057       coff_slurp_symbol_table,
   4058       symname_in_debug_hook,
   4059       coff_pointerize_aux_hook,
   4060       coff_print_aux,
   4061       dummy_reloc16_extra_cases,
   4062       dummy_reloc16_estimate,
   4063       NULL,			/* bfd_coff_sym_is_global */
   4064       coff_compute_section_file_positions,
   4065       NULL,			/* _bfd_coff_start_final_link */
   4066       xcoff_ppc_relocate_section,
   4067       coff_rtype_to_howto,
   4068       NULL,			/* _bfd_coff_adjust_symndx */
   4069       _bfd_generic_link_add_one_symbol,
   4070       coff_link_output_has_begun,
   4071       coff_final_link_postscript,
   4072       NULL			/* print_pdata.  */
   4073     },
   4074 
   4075     0x01DF,			/* magic number */
   4076     bfd_arch_rs6000,
   4077     bfd_mach_rs6k,
   4078 
   4079     /* Function pointers to xcoff specific swap routines.  */
   4080     xcoff_swap_ldhdr_in,
   4081     xcoff_swap_ldhdr_out,
   4082     xcoff_swap_ldsym_in,
   4083     xcoff_swap_ldsym_out,
   4084     xcoff_swap_ldrel_in,
   4085     xcoff_swap_ldrel_out,
   4086 
   4087     /* Sizes.  */
   4088     LDHDRSZ,
   4089     LDSYMSZ,
   4090     LDRELSZ,
   4091     12,				/* _xcoff_function_descriptor_size */
   4092     SMALL_AOUTSZ,
   4093 
   4094     /* Versions.  */
   4095     1,				/* _xcoff_ldhdr_version */
   4096 
   4097     _bfd_xcoff_put_symbol_name,
   4098     _bfd_xcoff_put_ldsymbol_name,
   4099     &xcoff_dynamic_reloc,
   4100     xcoff_create_csect_from_smclas,
   4101 
   4102     /* Lineno and reloc count overflow.  */
   4103     xcoff_is_lineno_count_overflow,
   4104     xcoff_is_reloc_count_overflow,
   4105 
   4106     xcoff_loader_symbol_offset,
   4107     xcoff_loader_reloc_offset,
   4108 
   4109     /* glink.  */
   4110     &xcoff_glink_code[0],
   4111     36,				/* _xcoff_glink_size */
   4112 
   4113     /* rtinit */
   4114     64,				/* _xcoff_rtinit_size */
   4115     xcoff_generate_rtinit,
   4116   };
   4117 
   4118 /* The transfer vector that leads the outside world to all of the above.  */
   4119 const bfd_target rs6000coff_vec =
   4120   {
   4121     "aixcoff-rs6000",
   4122     bfd_target_xcoff_flavour,
   4123     BFD_ENDIAN_BIG,		/* data byte order is big */
   4124     BFD_ENDIAN_BIG,		/* header byte order is big */
   4125 
   4126     (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | DYNAMIC
   4127      | HAS_SYMS | HAS_LOCALS | WP_TEXT),
   4128 
   4129     SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA,
   4130     0,				/* leading char */
   4131     '/',			/* ar_pad_char */
   4132     15,				/* ar_max_namelen */
   4133 
   4134     /* data */
   4135     bfd_getb64,
   4136     bfd_getb_signed_64,
   4137     bfd_putb64,
   4138     bfd_getb32,
   4139     bfd_getb_signed_32,
   4140     bfd_putb32,
   4141     bfd_getb16,
   4142     bfd_getb_signed_16,
   4143     bfd_putb16,
   4144 
   4145     /* hdrs */
   4146     bfd_getb64,
   4147     bfd_getb_signed_64,
   4148     bfd_putb64,
   4149     bfd_getb32,
   4150     bfd_getb_signed_32,
   4151     bfd_putb32,
   4152     bfd_getb16,
   4153     bfd_getb_signed_16,
   4154     bfd_putb16,
   4155 
   4156     { /* bfd_check_format */
   4157       _bfd_dummy_target,
   4158       coff_object_p,
   4159       _bfd_xcoff_archive_p,
   4160       CORE_FILE_P
   4161     },
   4162 
   4163     { /* bfd_set_format */
   4164       bfd_false,
   4165       coff_mkobject,
   4166       _bfd_generic_mkarchive,
   4167       bfd_false
   4168     },
   4169 
   4170     {/* bfd_write_contents */
   4171       bfd_false,
   4172       coff_write_object_contents,
   4173       _bfd_xcoff_write_archive_contents,
   4174       bfd_false
   4175     },
   4176 
   4177     /* Generic */
   4178     bfd_true,
   4179     bfd_true,
   4180     coff_new_section_hook,
   4181     _bfd_generic_get_section_contents,
   4182     _bfd_generic_get_section_contents_in_window,
   4183 
   4184     /* Copy */
   4185     _bfd_xcoff_copy_private_bfd_data,
   4186     _bfd_generic_bfd_merge_private_bfd_data,
   4187     _bfd_generic_init_private_section_data,
   4188     _bfd_generic_bfd_copy_private_section_data,
   4189     _bfd_generic_bfd_copy_private_symbol_data,
   4190     _bfd_generic_bfd_copy_private_header_data,
   4191     _bfd_generic_bfd_set_private_flags,
   4192     _bfd_generic_bfd_print_private_bfd_data,
   4193 
   4194     /* Core */
   4195     BFD_JUMP_TABLE_CORE (coff),
   4196 
   4197     /* Archive */
   4198     _bfd_xcoff_slurp_armap,
   4199     _bfd_noarchive_slurp_extended_name_table,
   4200     _bfd_noarchive_construct_extended_name_table,
   4201     bfd_dont_truncate_arname,
   4202     _bfd_xcoff_write_armap,
   4203     _bfd_xcoff_read_ar_hdr,
   4204     _bfd_generic_write_ar_hdr,
   4205     _bfd_xcoff_openr_next_archived_file,
   4206     _bfd_generic_get_elt_at_index,
   4207     _bfd_xcoff_stat_arch_elt,
   4208     bfd_true,
   4209 
   4210     /* Symbols */
   4211     coff_get_symtab_upper_bound,
   4212     coff_canonicalize_symtab,
   4213     coff_make_empty_symbol,
   4214     coff_print_symbol,
   4215     coff_get_symbol_info,
   4216     _bfd_xcoff_is_local_label_name,
   4217     coff_bfd_is_target_special_symbol,
   4218     coff_get_lineno,
   4219     coff_find_nearest_line,
   4220     _bfd_generic_find_line,
   4221     coff_find_inliner_info,
   4222     coff_bfd_make_debug_symbol,
   4223     _bfd_generic_read_minisymbols,
   4224     _bfd_generic_minisymbol_to_symbol,
   4225 
   4226     /* Reloc */
   4227     coff_get_reloc_upper_bound,
   4228     coff_canonicalize_reloc,
   4229     _bfd_xcoff_reloc_type_lookup,
   4230     _bfd_xcoff_reloc_name_lookup,
   4231 
   4232     /* Write */
   4233     coff_set_arch_mach,
   4234     coff_set_section_contents,
   4235 
   4236     /* Link */
   4237     _bfd_xcoff_sizeof_headers,
   4238     bfd_generic_get_relocated_section_contents,
   4239     bfd_generic_relax_section,
   4240     _bfd_xcoff_bfd_link_hash_table_create,
   4241     _bfd_generic_link_hash_table_free,
   4242     _bfd_xcoff_bfd_link_add_symbols,
   4243     _bfd_generic_link_just_syms,
   4244     _bfd_generic_copy_link_hash_symbol_type,
   4245     _bfd_xcoff_bfd_final_link,
   4246     _bfd_generic_link_split_section,
   4247     bfd_generic_gc_sections,
   4248     bfd_generic_merge_sections,
   4249     bfd_generic_is_group_section,
   4250     bfd_generic_discard_group,
   4251     _bfd_generic_section_already_linked,
   4252     _bfd_xcoff_define_common_symbol,
   4253 
   4254     /* Dynamic */
   4255     _bfd_xcoff_get_dynamic_symtab_upper_bound,
   4256     _bfd_xcoff_canonicalize_dynamic_symtab,
   4257     _bfd_nodynamic_get_synthetic_symtab,
   4258     _bfd_xcoff_get_dynamic_reloc_upper_bound,
   4259     _bfd_xcoff_canonicalize_dynamic_reloc,
   4260 
   4261     /* Opposite endian version, none exists */
   4262     NULL,
   4263 
   4264     (void *) &bfd_xcoff_backend_data,
   4265   };
   4266 
   4267 /* xcoff-powermac target
   4268    Old target.
   4269    Only difference between this target and the rs6000 target is the
   4270    the default architecture and machine type used in coffcode.h
   4271 
   4272    PowerPC Macs use the same magic numbers as RS/6000
   4273    (because that's how they were bootstrapped originally),
   4274    but they are always PowerPC architecture.  */
   4275 static const struct xcoff_backend_data_rec bfd_pmac_xcoff_backend_data =
   4276   {
   4277     { /* COFF backend, defined in libcoff.h.  */
   4278       _bfd_xcoff_swap_aux_in,
   4279       _bfd_xcoff_swap_sym_in,
   4280       coff_swap_lineno_in,
   4281       _bfd_xcoff_swap_aux_out,
   4282       _bfd_xcoff_swap_sym_out,
   4283       coff_swap_lineno_out,
   4284       xcoff_swap_reloc_out,
   4285       coff_swap_filehdr_out,
   4286       coff_swap_aouthdr_out,
   4287       coff_swap_scnhdr_out,
   4288       FILHSZ,
   4289       AOUTSZ,
   4290       SCNHSZ,
   4291       SYMESZ,
   4292       AUXESZ,
   4293       RELSZ,
   4294       LINESZ,
   4295       FILNMLEN,
   4296       TRUE,			/* _bfd_coff_long_filenames */
   4297       XCOFF_NO_LONG_SECTION_NAMES,  /* _bfd_coff_long_section_names */
   4298       3,			/* _bfd_coff_default_section_alignment_power */
   4299       FALSE,			/* _bfd_coff_force_symnames_in_strings */
   4300       2,			/* _bfd_coff_debug_string_prefix_length */
   4301       coff_swap_filehdr_in,
   4302       coff_swap_aouthdr_in,
   4303       coff_swap_scnhdr_in,
   4304       xcoff_swap_reloc_in,
   4305       coff_bad_format_hook,
   4306       coff_set_arch_mach_hook,
   4307       coff_mkobject_hook,
   4308       styp_to_sec_flags,
   4309       coff_set_alignment_hook,
   4310       coff_slurp_symbol_table,
   4311       symname_in_debug_hook,
   4312       coff_pointerize_aux_hook,
   4313       coff_print_aux,
   4314       dummy_reloc16_extra_cases,
   4315       dummy_reloc16_estimate,
   4316       NULL,			/* bfd_coff_sym_is_global */
   4317       coff_compute_section_file_positions,
   4318       NULL,			/* _bfd_coff_start_final_link */
   4319       xcoff_ppc_relocate_section,
   4320       coff_rtype_to_howto,
   4321       NULL,			/* _bfd_coff_adjust_symndx */
   4322       _bfd_generic_link_add_one_symbol,
   4323       coff_link_output_has_begun,
   4324       coff_final_link_postscript,
   4325       NULL			/* print_pdata.  */
   4326     },
   4327 
   4328     0x01DF,			/* magic number */
   4329     bfd_arch_powerpc,
   4330     bfd_mach_ppc,
   4331 
   4332     /* Function pointers to xcoff specific swap routines.  */
   4333     xcoff_swap_ldhdr_in,
   4334     xcoff_swap_ldhdr_out,
   4335     xcoff_swap_ldsym_in,
   4336     xcoff_swap_ldsym_out,
   4337     xcoff_swap_ldrel_in,
   4338     xcoff_swap_ldrel_out,
   4339 
   4340     /* Sizes.  */
   4341     LDHDRSZ,
   4342     LDSYMSZ,
   4343     LDRELSZ,
   4344     12,				/* _xcoff_function_descriptor_size */
   4345     SMALL_AOUTSZ,
   4346 
   4347     /* Versions.  */
   4348     1,				/* _xcoff_ldhdr_version */
   4349 
   4350     _bfd_xcoff_put_symbol_name,
   4351     _bfd_xcoff_put_ldsymbol_name,
   4352     &xcoff_dynamic_reloc,
   4353     xcoff_create_csect_from_smclas,
   4354 
   4355     /* Lineno and reloc count overflow.  */
   4356     xcoff_is_lineno_count_overflow,
   4357     xcoff_is_reloc_count_overflow,
   4358 
   4359     xcoff_loader_symbol_offset,
   4360     xcoff_loader_reloc_offset,
   4361 
   4362     /* glink.  */
   4363     &xcoff_glink_code[0],
   4364     36,				/* _xcoff_glink_size */
   4365 
   4366     /* rtinit */
   4367     0,				/* _xcoff_rtinit_size */
   4368     xcoff_generate_rtinit,
   4369   };
   4370 
   4371 /* The transfer vector that leads the outside world to all of the above.  */
   4372 const bfd_target pmac_xcoff_vec =
   4373   {
   4374     "xcoff-powermac",
   4375     bfd_target_xcoff_flavour,
   4376     BFD_ENDIAN_BIG,		/* data byte order is big */
   4377     BFD_ENDIAN_BIG,		/* header byte order is big */
   4378 
   4379     (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | DYNAMIC
   4380      | HAS_SYMS | HAS_LOCALS | WP_TEXT),
   4381 
   4382     SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA,
   4383     0,				/* leading char */
   4384     '/',			/* ar_pad_char */
   4385     15,				/* ar_max_namelen */
   4386 
   4387     /* data */
   4388     bfd_getb64,
   4389     bfd_getb_signed_64,
   4390     bfd_putb64,
   4391     bfd_getb32,
   4392     bfd_getb_signed_32,
   4393     bfd_putb32,
   4394     bfd_getb16,
   4395     bfd_getb_signed_16,
   4396     bfd_putb16,
   4397 
   4398     /* hdrs */
   4399     bfd_getb64,
   4400     bfd_getb_signed_64,
   4401     bfd_putb64,
   4402     bfd_getb32,
   4403     bfd_getb_signed_32,
   4404     bfd_putb32,
   4405     bfd_getb16,
   4406     bfd_getb_signed_16,
   4407     bfd_putb16,
   4408 
   4409     { /* bfd_check_format */
   4410       _bfd_dummy_target,
   4411       coff_object_p,
   4412       _bfd_xcoff_archive_p,
   4413       CORE_FILE_P
   4414     },
   4415 
   4416     { /* bfd_set_format */
   4417       bfd_false,
   4418       coff_mkobject,
   4419       _bfd_generic_mkarchive,
   4420       bfd_false
   4421     },
   4422 
   4423     {/* bfd_write_contents */
   4424       bfd_false,
   4425       coff_write_object_contents,
   4426       _bfd_xcoff_write_archive_contents,
   4427       bfd_false
   4428     },
   4429 
   4430     /* Generic */
   4431     bfd_true,
   4432     bfd_true,
   4433     coff_new_section_hook,
   4434     _bfd_generic_get_section_contents,
   4435     _bfd_generic_get_section_contents_in_window,
   4436 
   4437     /* Copy */
   4438     _bfd_xcoff_copy_private_bfd_data,
   4439     _bfd_generic_bfd_merge_private_bfd_data,
   4440     _bfd_generic_init_private_section_data,
   4441     _bfd_generic_bfd_copy_private_section_data,
   4442     _bfd_generic_bfd_copy_private_symbol_data,
   4443     _bfd_generic_bfd_copy_private_header_data,
   4444     _bfd_generic_bfd_set_private_flags,
   4445     _bfd_generic_bfd_print_private_bfd_data,
   4446 
   4447     /* Core */
   4448     BFD_JUMP_TABLE_CORE (coff),
   4449 
   4450     /* Archive */
   4451     _bfd_xcoff_slurp_armap,
   4452     _bfd_noarchive_slurp_extended_name_table,
   4453     _bfd_noarchive_construct_extended_name_table,
   4454     bfd_dont_truncate_arname,
   4455     _bfd_xcoff_write_armap,
   4456     _bfd_xcoff_read_ar_hdr,
   4457     _bfd_generic_write_ar_hdr,
   4458     _bfd_xcoff_openr_next_archived_file,
   4459     _bfd_generic_get_elt_at_index,
   4460     _bfd_xcoff_stat_arch_elt,
   4461     bfd_true,
   4462 
   4463     /* Symbols */
   4464     coff_get_symtab_upper_bound,
   4465     coff_canonicalize_symtab,
   4466     coff_make_empty_symbol,
   4467     coff_print_symbol,
   4468     coff_get_symbol_info,
   4469     _bfd_xcoff_is_local_label_name,
   4470     coff_bfd_is_target_special_symbol,
   4471     coff_get_lineno,
   4472     coff_find_nearest_line,
   4473     _bfd_generic_find_line,
   4474     coff_find_inliner_info,
   4475     coff_bfd_make_debug_symbol,
   4476     _bfd_generic_read_minisymbols,
   4477     _bfd_generic_minisymbol_to_symbol,
   4478 
   4479     /* Reloc */
   4480     coff_get_reloc_upper_bound,
   4481     coff_canonicalize_reloc,
   4482     _bfd_xcoff_reloc_type_lookup,
   4483     _bfd_xcoff_reloc_name_lookup,
   4484 
   4485     /* Write */
   4486     coff_set_arch_mach,
   4487     coff_set_section_contents,
   4488 
   4489     /* Link */
   4490     _bfd_xcoff_sizeof_headers,
   4491     bfd_generic_get_relocated_section_contents,
   4492     bfd_generic_relax_section,
   4493     _bfd_xcoff_bfd_link_hash_table_create,
   4494     _bfd_generic_link_hash_table_free,
   4495     _bfd_xcoff_bfd_link_add_symbols,
   4496     _bfd_generic_link_just_syms,
   4497     _bfd_generic_copy_link_hash_symbol_type,
   4498     _bfd_xcoff_bfd_final_link,
   4499     _bfd_generic_link_split_section,
   4500     bfd_generic_gc_sections,
   4501     bfd_generic_merge_sections,
   4502     bfd_generic_is_group_section,
   4503     bfd_generic_discard_group,
   4504     _bfd_generic_section_already_linked,
   4505     _bfd_xcoff_define_common_symbol,
   4506 
   4507     /* Dynamic */
   4508     _bfd_xcoff_get_dynamic_symtab_upper_bound,
   4509     _bfd_xcoff_canonicalize_dynamic_symtab,
   4510     _bfd_nodynamic_get_synthetic_symtab,
   4511     _bfd_xcoff_get_dynamic_reloc_upper_bound,
   4512     _bfd_xcoff_canonicalize_dynamic_reloc,
   4513 
   4514     /* Opposite endian version, none exists */
   4515     NULL,
   4516 
   4517     (void *) &bfd_pmac_xcoff_backend_data,
   4518   };
   4519