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