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