Ignore:
Timestamp:
Aug 16, 2003, 6:59:22 PM (22 years ago)
Author:
bird
Message:

binutils v2.14 - offical sources.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/binutils/bfd/coff-rs6000.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    11/* BFD back-end for IBM RS/6000 "XCOFF" files.
    2    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
    3    2000, 2001
     2   Copyright 1990-1999, 2000, 2001, 2002
    43   Free Software Foundation, Inc.
    54   FIXME: Can someone provide a transliteration of this name into ASCII?
     
    3029#include "bfd.h"
    3130#include "sysdep.h"
     31#include "bfdlink.h"
    3232#include "libbfd.h"
    3333#include "coff/internal.h"
     34#include "coff/xcoff.h"
    3435#include "coff/rs6000.h"
    3536#include "libcoff.h"
    36 #define TARGET_NAME "aixcoff-rs6000"
    37 #define TARGET_SYM rs6000coff_vec
    38 #include "xcoff-target.h"
     37#include "libxcoff.h"
     38
     39extern bfd_boolean _bfd_xcoff_mkobject
     40  PARAMS ((bfd *));
     41extern bfd_boolean _bfd_xcoff_copy_private_bfd_data
     42  PARAMS ((bfd *, bfd *));
     43extern bfd_boolean _bfd_xcoff_is_local_label_name
     44  PARAMS ((bfd *, const char *));
     45extern reloc_howto_type *_bfd_xcoff_reloc_type_lookup
     46  PARAMS ((bfd *, bfd_reloc_code_real_type));
     47extern bfd_boolean _bfd_xcoff_slurp_armap
     48  PARAMS ((bfd *));
     49extern const bfd_target *_bfd_xcoff_archive_p
     50  PARAMS ((bfd *));
     51extern PTR _bfd_xcoff_read_ar_hdr
     52  PARAMS ((bfd *));
     53extern bfd *_bfd_xcoff_openr_next_archived_file
     54  PARAMS ((bfd *, bfd *));
     55extern int _bfd_xcoff_stat_arch_elt
     56  PARAMS ((bfd *, struct stat *));
     57extern bfd_boolean _bfd_xcoff_write_armap
     58  PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int));
     59extern bfd_boolean _bfd_xcoff_write_archive_contents
     60  PARAMS ((bfd *));
     61extern int _bfd_xcoff_sizeof_headers
     62  PARAMS ((bfd *, bfd_boolean));
     63extern void _bfd_xcoff_swap_sym_in
     64  PARAMS ((bfd *, PTR, PTR));
     65extern unsigned int _bfd_xcoff_swap_sym_out
     66  PARAMS ((bfd *, PTR, PTR));
     67extern void _bfd_xcoff_swap_aux_in
     68  PARAMS ((bfd *, PTR, int, int, int, int, PTR));
     69extern unsigned int _bfd_xcoff_swap_aux_out
     70  PARAMS ((bfd *, PTR, int, int, int, int, PTR));
     71static void xcoff_swap_reloc_in
     72  PARAMS ((bfd *, PTR, PTR));
     73static unsigned int xcoff_swap_reloc_out
     74  PARAMS ((bfd *, PTR, PTR));
     75
     76/* Forward declare xcoff_rtype2howto for coffcode.h macro.  */
     77void xcoff_rtype2howto
     78  PARAMS ((arelent *, struct internal_reloc *));
     79
     80/* coffcode.h needs these to be defined.  */
     81#define RS6000COFF_C 1
     82
     83#define SELECT_RELOC(internal, howto)                                   \
     84  {                                                                     \
     85    internal.r_type = howto->type;                                      \
     86    internal.r_size =                                                   \
     87      ((howto->complain_on_overflow == complain_overflow_signed         \
     88        ? 0x80                                                          \
     89        : 0)                                                            \
     90       | (howto->bitsize - 1));                                         \
     91  }
     92
     93#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
     94#define COFF_LONG_FILENAMES
     95#define NO_COFF_SYMBOLS
     96#define RTYPE2HOWTO(cache_ptr, dst) xcoff_rtype2howto (cache_ptr, dst)
     97#define coff_mkobject _bfd_xcoff_mkobject
     98#define coff_bfd_copy_private_bfd_data _bfd_xcoff_copy_private_bfd_data
     99#define coff_bfd_is_local_label_name _bfd_xcoff_is_local_label_name
     100#define coff_bfd_reloc_type_lookup _bfd_xcoff_reloc_type_lookup
     101#ifdef AIX_CORE
     102extern const bfd_target * rs6000coff_core_p
     103  PARAMS ((bfd *abfd));
     104extern bfd_boolean rs6000coff_core_file_matches_executable_p
     105  PARAMS ((bfd *cbfd, bfd *ebfd));
     106extern char *rs6000coff_core_file_failing_command
     107  PARAMS ((bfd *abfd));
     108extern int rs6000coff_core_file_failing_signal
     109  PARAMS ((bfd *abfd));
     110#define CORE_FILE_P rs6000coff_core_p
     111#define coff_core_file_failing_command \
     112  rs6000coff_core_file_failing_command
     113#define coff_core_file_failing_signal \
     114  rs6000coff_core_file_failing_signal
     115#define coff_core_file_matches_executable_p \
     116  rs6000coff_core_file_matches_executable_p
     117#else
     118#define CORE_FILE_P _bfd_dummy_target
     119#define coff_core_file_failing_command \
     120  _bfd_nocore_core_file_failing_command
     121#define coff_core_file_failing_signal \
     122  _bfd_nocore_core_file_failing_signal
     123#define coff_core_file_matches_executable_p \
     124  _bfd_nocore_core_file_matches_executable_p
     125#endif
     126#define coff_SWAP_sym_in _bfd_xcoff_swap_sym_in
     127#define coff_SWAP_sym_out _bfd_xcoff_swap_sym_out
     128#define coff_SWAP_aux_in _bfd_xcoff_swap_aux_in
     129#define coff_SWAP_aux_out _bfd_xcoff_swap_aux_out
     130#define coff_swap_reloc_in xcoff_swap_reloc_in
     131#define coff_swap_reloc_out xcoff_swap_reloc_out
     132#define NO_COFF_RELOCS
     133
     134#include "coffcode.h"
    39135
    40136/* The main body of code is in coffcode.h.  */
    41137
    42 static const char *normalize_filename PARAMS ((bfd *));
     138static const char *normalize_filename
     139  PARAMS ((bfd *));
     140static bfd_boolean xcoff_write_armap_old
     141  PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int));
     142static bfd_boolean xcoff_write_armap_big
     143  PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int));
     144static bfd_boolean xcoff_write_archive_contents_old
     145  PARAMS ((bfd *));
     146static bfd_boolean xcoff_write_archive_contents_big
     147  PARAMS ((bfd *));
     148static void xcoff_swap_ldhdr_in
     149  PARAMS ((bfd *, const PTR, struct internal_ldhdr *));
     150static void xcoff_swap_ldhdr_out
     151  PARAMS ((bfd *, const struct internal_ldhdr *, PTR));
     152static void xcoff_swap_ldsym_in
     153  PARAMS ((bfd *, const PTR, struct internal_ldsym *));
     154static void xcoff_swap_ldsym_out
     155  PARAMS ((bfd *, const struct internal_ldsym *, PTR));
     156static void xcoff_swap_ldrel_in
     157  PARAMS ((bfd *, const PTR, struct internal_ldrel *));
     158static void xcoff_swap_ldrel_out
     159  PARAMS ((bfd *, const struct internal_ldrel *, PTR));
     160static bfd_boolean xcoff_ppc_relocate_section
     161  PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
     162           struct internal_reloc *, struct internal_syment *, asection **));
     163static bfd_boolean _bfd_xcoff_put_ldsymbol_name
     164  PARAMS ((bfd *, struct xcoff_loader_info *, struct internal_ldsym *,
     165           const char *));
     166static asection *xcoff_create_csect_from_smclas
     167  PARAMS ((bfd *, union internal_auxent *, const char *));
     168static bfd_boolean xcoff_is_lineno_count_overflow
     169  PARAMS ((bfd *, bfd_vma));
     170static bfd_boolean xcoff_is_reloc_count_overflow
     171  PARAMS ((bfd *, bfd_vma));
     172static bfd_vma xcoff_loader_symbol_offset
     173  PARAMS ((bfd *, struct internal_ldhdr *));
     174static bfd_vma xcoff_loader_reloc_offset
     175  PARAMS ((bfd *, struct internal_ldhdr *));
     176static bfd_boolean xcoff_generate_rtinit
     177  PARAMS ((bfd *, const char *, const char *, bfd_boolean));
     178static bfd_boolean do_pad
     179  PARAMS ((bfd *, unsigned int));
     180static bfd_boolean do_copy
     181  PARAMS ((bfd *, bfd *));
     182static bfd_boolean do_shared_object_padding
     183  PARAMS ((bfd *, bfd *, ufile_ptr *, int));
     184
     185/* Relocation functions */
     186static bfd_boolean xcoff_reloc_type_br
     187  PARAMS ((XCOFF_RELOC_FUNCTION_ARGS));
     188
     189static bfd_boolean xcoff_complain_overflow_dont_func
     190  PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS));
     191static bfd_boolean xcoff_complain_overflow_bitfield_func
     192  PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS));
     193static bfd_boolean xcoff_complain_overflow_signed_func
     194  PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS));
     195static bfd_boolean xcoff_complain_overflow_unsigned_func
     196  PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS));
     197
     198bfd_boolean (*xcoff_calculate_relocation[XCOFF_MAX_CALCULATE_RELOCATION])
     199  PARAMS ((XCOFF_RELOC_FUNCTION_ARGS)) =
     200{
     201  xcoff_reloc_type_pos,  /* R_POS   (0x00) */
     202  xcoff_reloc_type_neg,  /* R_NEG   (0x01) */
     203  xcoff_reloc_type_rel,  /* R_REL   (0x02) */
     204  xcoff_reloc_type_toc,  /* R_TOC   (0x03) */
     205  xcoff_reloc_type_fail, /* R_RTB   (0x04) */
     206  xcoff_reloc_type_toc,  /* R_GL    (0x05) */
     207  xcoff_reloc_type_toc,  /* R_TCL   (0x06) */
     208  xcoff_reloc_type_fail, /*         (0x07) */
     209  xcoff_reloc_type_ba,   /* R_BA    (0x08) */
     210  xcoff_reloc_type_fail, /*         (0x09) */
     211  xcoff_reloc_type_br,   /* R_BR    (0x0a) */
     212  xcoff_reloc_type_fail, /*         (0x0b) */
     213  xcoff_reloc_type_pos,  /* R_RL    (0x0c) */
     214  xcoff_reloc_type_pos,  /* R_RLA   (0x0d) */
     215  xcoff_reloc_type_fail, /*         (0x0e) */
     216  xcoff_reloc_type_noop, /* R_REF   (0x0f) */
     217  xcoff_reloc_type_fail, /*         (0x10) */
     218  xcoff_reloc_type_fail, /*         (0x11) */
     219  xcoff_reloc_type_toc,  /* R_TRL   (0x12) */
     220  xcoff_reloc_type_toc,  /* R_TRLA  (0x13) */
     221  xcoff_reloc_type_fail, /* R_RRTBI (0x14) */
     222  xcoff_reloc_type_fail, /* R_RRTBA (0x15) */
     223  xcoff_reloc_type_ba,   /* R_CAI   (0x16) */
     224  xcoff_reloc_type_crel, /* R_CREL  (0x17) */
     225  xcoff_reloc_type_ba,   /* R_RBA   (0x18) */
     226  xcoff_reloc_type_ba,   /* R_RBAC  (0x19) */
     227  xcoff_reloc_type_br,   /* R_RBR   (0x1a) */
     228  xcoff_reloc_type_ba,   /* R_RBRC  (0x1b) */
     229};
     230
     231bfd_boolean (*xcoff_complain_overflow[XCOFF_MAX_COMPLAIN_OVERFLOW])
     232  PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS)) =
     233{
     234  xcoff_complain_overflow_dont_func,
     235  xcoff_complain_overflow_bitfield_func,
     236  xcoff_complain_overflow_signed_func,
     237  xcoff_complain_overflow_unsigned_func,
     238};
    43239
    44240/* We use our own tdata type.  Its first field is the COFF tdata type,
    45241   so the COFF routines are compatible.  */
    46242
    47 boolean
     243bfd_boolean
    48244_bfd_xcoff_mkobject (abfd)
    49245     bfd *abfd;
    50246{
    51247  coff_data_type *coff;
    52 
    53   abfd->tdata.xcoff_obj_data =
    54     ((struct xcoff_tdata *)
    55      bfd_zalloc (abfd, sizeof (struct xcoff_tdata)));
     248  bfd_size_type amt = sizeof (struct xcoff_tdata);
     249
     250  abfd->tdata.xcoff_obj_data = (struct xcoff_tdata *) bfd_zalloc (abfd, amt);
    56251  if (abfd->tdata.xcoff_obj_data == NULL)
    57     return false;
     252    return FALSE;
    58253  coff = coff_data (abfd);
    59254  coff->symbols = (coff_symbol_type *) NULL;
     
    71266  xcoff_data (abfd)->debug_indices = NULL;
    72267
    73   return true;
     268  /* text section alignment is different than the default */
     269  bfd_xcoff_text_align_power (abfd) = 2;
     270
     271  return TRUE;
    74272}
    75273
    76274/* Copy XCOFF data from one BFD to another.  */
    77275
    78 boolean
     276bfd_boolean
    79277_bfd_xcoff_copy_private_bfd_data (ibfd, obfd)
    80278     bfd *ibfd;
     
    85283
    86284  if (ibfd->xvec != obfd->xvec)
    87     return true;
     285    return TRUE;
    88286  ix = xcoff_data (ibfd);
    89287  ox = xcoff_data (obfd);
     
    110308        ox->snentry = sec->output_section->target_index;
    111309    }
    112   ox->text_align_power = ix->text_align_power;
    113   ox->data_align_power = ix->data_align_power;
     310  bfd_xcoff_text_align_power (obfd) = bfd_xcoff_text_align_power (ibfd);
     311  bfd_xcoff_data_align_power (obfd) = bfd_xcoff_data_align_power (ibfd);
    114312  ox->modtype = ix->modtype;
    115313  ox->cputype = ix->cputype;
    116314  ox->maxdata = ix->maxdata;
    117315  ox->maxstack = ix->maxstack;
    118   return true;
     316  return TRUE;
    119317}
    120318
     
    124322   -x option.  */
    125323
    126 boolean
     324bfd_boolean
    127325_bfd_xcoff_is_local_label_name (abfd, name)
    128326     bfd *abfd ATTRIBUTE_UNUSED;
    129327     const char *name ATTRIBUTE_UNUSED;
    130328{
    131   return false;
     329  return FALSE;
    132330}
    133331
     
    135333void
    136334_bfd_xcoff_swap_sym_in (abfd, ext1, in1)
    137      bfd            *abfd;
     335     bfd *abfd;
    138336     PTR ext1;
    139337     PTR in1;
    140338{
    141339  SYMENT *ext = (SYMENT *)ext1;
    142   struct internal_syment      *in = (struct internal_syment *)in1;
     340  struct internal_syment * in = (struct internal_syment *)in1;
    143341
    144342  if (ext->e.e_name[0] != 0)
    145343    {
    146       memcpy(in->_n._n_name, ext->e.e_name, SYMNMLEN);
     344      memcpy (in->_n._n_name, ext->e.e_name, SYMNMLEN);
    147345    }
    148346  else
    149347    {
    150348      in->_n._n_n._n_zeroes = 0;
    151       in->_n._n_n._n_offset =
    152           bfd_h_get_32(abfd, (bfd_byte *) ext->e.e.e_offset);
    153     }
    154 
    155   in->n_value = bfd_h_get_32(abfd, (bfd_byte *) ext->e_value);
    156   in->n_scnum = bfd_h_get_16(abfd, (bfd_byte *) ext->e_scnum);
    157   in->n_type = bfd_h_get_16(abfd, (bfd_byte *) ext->e_type);
    158   in->n_sclass = bfd_h_get_8(abfd, ext->e_sclass);
    159   in->n_numaux = bfd_h_get_8(abfd, ext->e_numaux);
     349      in->_n._n_n._n_offset = H_GET_32 (abfd, ext->e.e.e_offset);
     350    }
     351
     352  in->n_value = H_GET_32 (abfd, ext->e_value);
     353  in->n_scnum = H_GET_16 (abfd, ext->e_scnum);
     354  in->n_type = H_GET_16 (abfd, ext->e_type);
     355  in->n_sclass = H_GET_8 (abfd, ext->e_sclass);
     356  in->n_numaux = H_GET_8 (abfd, ext->e_numaux);
    160357}
    161358
    162359unsigned int
    163360_bfd_xcoff_swap_sym_out (abfd, inp, extp)
    164      bfd       *abfd;
    165      PTR        inp;
    166      PTR        extp;
     361     bfd *abfd;
     362     PTR inp;
     363     PTR extp;
    167364{
    168365  struct internal_syment *in = (struct internal_syment *)inp;
     
    171368  if (in->_n._n_name[0] != 0)
    172369    {
    173       memcpy(ext->e.e_name, in->_n._n_name, SYMNMLEN);
     370      memcpy (ext->e.e_name, in->_n._n_name, SYMNMLEN);
    174371    }
    175372  else
    176373    {
    177       bfd_h_put_32(abfd, 0, (bfd_byte *) ext->e.e.e_zeroes);
    178       bfd_h_put_32(abfd, in->_n._n_n._n_offset,
    179               (bfd_byte *)  ext->e.e.e_offset);
    180     }
    181 
    182   bfd_h_put_32(abfd,  in->n_value , (bfd_byte *) ext->e_value);
    183   bfd_h_put_16(abfd,  in->n_scnum , (bfd_byte *) ext->e_scnum);
    184   bfd_h_put_16(abfd,  in->n_type , (bfd_byte *) ext->e_type);
    185   bfd_h_put_8(abfd,  in->n_sclass , ext->e_sclass);
    186   bfd_h_put_8(abfd,  in->n_numaux , ext->e_numaux);
     374      H_PUT_32 (abfd, 0, ext->e.e.e_zeroes);
     375      H_PUT_32 (abfd, in->_n._n_n._n_offset, ext->e.e.e_offset);
     376    }
     377
     378  H_PUT_32 (abfd, in->n_value, ext->e_value);
     379  H_PUT_16 (abfd, in->n_scnum, ext->e_scnum);
     380  H_PUT_16 (abfd, in->n_type, ext->e_type);
     381  H_PUT_8 (abfd, in->n_sclass, ext->e_sclass);
     382  H_PUT_8 (abfd, in->n_numaux, ext->e_numaux);
    187383  return bfd_coff_symesz (abfd);
    188384}
    189 
    190 #define PUTWORD bfd_h_put_32
    191 #define PUTHALF bfd_h_put_16
    192 #define PUTBYTE bfd_h_put_8
    193 #define GETWORD bfd_h_get_32
    194 #define GETHALF bfd_h_get_16
    195 #define GETBYTE bfd_h_get_8
    196385
    197386void
    198387_bfd_xcoff_swap_aux_in (abfd, ext1, type, class, indx, numaux, in1)
    199      bfd            *abfd;
    200      PTR              ext1;
    201      int             type;
    202      int             class;
    203      int              indx;
    204      int              numaux;
    205      PTR              in1;
    206 {
    207   AUXENT    *ext = (AUXENT *)ext1;
     388     bfd *abfd;
     389     PTR ext1;
     390     int type;
     391     int class;
     392     int indx;
     393     int numaux;
     394     PTR in1;
     395{
     396  AUXENT * ext = (AUXENT *)ext1;
    208397  union internal_auxent *in = (union internal_auxent *)in1;
    209398
    210   switch (class) {
     399  switch (class)
     400    {
    211401    case C_FILE:
    212       if (ext->x_file.x_fname[0] == 0) {
     402      if (ext->x_file.x_fname[0] == 0)
     403        {
    213404          in->x_file.x_n.x_zeroes = 0;
    214405          in->x_file.x_n.x_offset =
    215            bfd_h_get_32(abfd, (bfd_byte *) ext->x_file.x_n.x_offset);
    216         } else {
    217             if (numaux > 1)
    218               {
    219                 if (indx == 0)
    220                   memcpy (in->x_file.x_fname, ext->x_file.x_fname,
    221                           numaux * sizeof (AUXENT));
    222               }
    223             else
    224               {
    225                 memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN);
    226               }
    227           }
     406            H_GET_32 (abfd, ext->x_file.x_n.x_offset);
     407        }
     408      else
     409        {
     410          if (numaux > 1)
     411            {
     412              if (indx == 0)
     413                memcpy (in->x_file.x_fname, ext->x_file.x_fname,
     414                        numaux * sizeof (AUXENT));
     415            }
     416          else
     417            {
     418              memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN);
     419            }
     420        }
    228421      goto end;
    229422
     
    233426      if (indx + 1 == numaux)
    234427        {
    235           in->x_csect.x_scnlen.l =
    236               bfd_h_get_32 (abfd, ext->x_csect.x_scnlen);
    237           in->x_csect.x_parmhash = bfd_h_get_32 (abfd,
    238                                                  ext->x_csect.x_parmhash);
    239           in->x_csect.x_snhash   = bfd_h_get_16 (abfd, ext->x_csect.x_snhash);
     428          in->x_csect.x_scnlen.l = H_GET_32 (abfd, ext->x_csect.x_scnlen);
     429          in->x_csect.x_parmhash = H_GET_32 (abfd, ext->x_csect.x_parmhash);
     430          in->x_csect.x_snhash   = H_GET_16 (abfd, ext->x_csect.x_snhash);
    240431          /* We don't have to hack bitfields in x_smtyp because it's
    241432             defined by shifts-and-ands, which are equivalent on all
    242433             byte orders.  */
    243           in->x_csect.x_smtyp    = bfd_h_get_8 (abfd, ext->x_csect.x_smtyp);
    244           in->x_csect.x_smclas   = bfd_h_get_8 (abfd, ext->x_csect.x_smclas);
    245           in->x_csect.x_stab     = bfd_h_get_32 (abfd, ext->x_csect.x_stab);
    246           in->x_csect.x_snstab   = bfd_h_get_16 (abfd, ext->x_csect.x_snstab);
     434          in->x_csect.x_smtyp    = H_GET_8 (abfd, ext->x_csect.x_smtyp);
     435          in->x_csect.x_smclas   = H_GET_8 (abfd, ext->x_csect.x_smclas);
     436          in->x_csect.x_stab     = H_GET_32 (abfd, ext->x_csect.x_stab);
     437          in->x_csect.x_snstab   = H_GET_16 (abfd, ext->x_csect.x_snstab);
    247438          goto end;
    248439        }
     
    252443    case C_LEAFSTAT:
    253444    case C_HIDDEN:
    254       if (type == T_NULL) {
    255           in->x_scn.x_scnlen = bfd_h_get_32(abfd,
    256                   (bfd_byte *) ext->x_scn.x_scnlen);
    257           in->x_scn.x_nreloc = bfd_h_get_16(abfd,
    258                   (bfd_byte *) ext->x_scn.x_nreloc);
    259           in->x_scn.x_nlinno = bfd_h_get_16(abfd,
    260                   (bfd_byte *) ext->x_scn.x_nlinno);
     445      if (type == T_NULL)
     446        {
     447          in->x_scn.x_scnlen = H_GET_32 (abfd, ext->x_scn.x_scnlen);
     448          in->x_scn.x_nreloc = H_GET_16 (abfd, ext->x_scn.x_nreloc);
     449          in->x_scn.x_nlinno = H_GET_16 (abfd, ext->x_scn.x_nlinno);
    261450          /* PE defines some extra fields; we zero them out for
    262              safety.  */
     451             safety.  */
    263452          in->x_scn.x_checksum = 0;
    264453          in->x_scn.x_associated = 0;
     
    270459    }
    271460
    272   in->x_sym.x_tagndx.l = bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_tagndx);
    273   in->x_sym.x_tvndx = bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_tvndx);
     461  in->x_sym.x_tagndx.l = H_GET_32 (abfd, ext->x_sym.x_tagndx);
     462  in->x_sym.x_tvndx = H_GET_16 (abfd, ext->x_sym.x_tvndx);
    274463
    275464  if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
    276465    {
    277       in->x_sym.x_fcnary.x_fcn.x_lnnoptr = bfd_h_get_32(abfd, (bfd_byte *)
    278               ext->x_sym.x_fcnary.x_fcn.x_lnnoptr);
    279       in->x_sym.x_fcnary.x_fcn.x_endndx.l = bfd_h_get_32(abfd, (bfd_byte *)
    280               ext->x_sym.x_fcnary.x_fcn.x_endndx);
     466      in->x_sym.x_fcnary.x_fcn.x_lnnoptr =
     467        H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_lnnoptr);
     468      in->x_sym.x_fcnary.x_fcn.x_endndx.l =
     469        H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_endndx);
    281470    }
    282471  else
    283472    {
    284473      in->x_sym.x_fcnary.x_ary.x_dimen[0] =
    285         bfd_h_get_16 (abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
     474        H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
    286475      in->x_sym.x_fcnary.x_ary.x_dimen[1] =
    287         bfd_h_get_16 (abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
     476        H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
    288477      in->x_sym.x_fcnary.x_ary.x_dimen[2] =
    289         bfd_h_get_16 (abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
     478        H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
    290479      in->x_sym.x_fcnary.x_ary.x_dimen[3] =
    291         bfd_h_get_16 (abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
    292     }
    293   if (ISFCN(type)) {
    294     in->x_sym.x_misc.x_fsize = bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_misc.x_fsize);
    295   }
    296   else {
    297     in->x_sym.x_misc.x_lnsz.x_lnno = bfd_h_get_16(abfd, (bfd_byte *)
    298             ext->x_sym.x_misc.x_lnsz.x_lnno);
    299     in->x_sym.x_misc.x_lnsz.x_size = bfd_h_get_16(abfd, (bfd_byte *)
    300             ext->x_sym.x_misc.x_lnsz.x_size);
    301   }
    302 
    303 end: ;
    304   /* the semicolon is because MSVC doesn't like labels at
     480        H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
     481    }
     482
     483  if (ISFCN (type))
     484    {
     485      in->x_sym.x_misc.x_fsize = H_GET_32 (abfd, ext->x_sym.x_misc.x_fsize);
     486    }
     487  else
     488    {
     489      in->x_sym.x_misc.x_lnsz.x_lnno =
     490        H_GET_16 (abfd, ext->x_sym.x_misc.x_lnsz.x_lnno);
     491      in->x_sym.x_misc.x_lnsz.x_size =
     492        H_GET_16 (abfd, ext->x_sym.x_misc.x_lnsz.x_size);
     493    }
     494
     495 end: ;
     496  /* The semicolon is because MSVC doesn't like labels at
    305497     end of block.  */
    306 
    307 }
     498}
     499
     500
     501unsigned int _bfd_xcoff_swap_aux_out
     502  PARAMS ((bfd *, PTR, int, int, int, int, PTR));
    308503
    309504unsigned int
    310505_bfd_xcoff_swap_aux_out (abfd, inp, type, class, indx, numaux, extp)
    311      bfd   *abfd;
    312      PTR        inp;
     506     bfd * abfd;
     507     PTR   inp;
    313508     int   type;
    314509     int   class;
    315510     int   indx ATTRIBUTE_UNUSED;
    316511     int   numaux ATTRIBUTE_UNUSED;
    317      PTR        extp;
     512     PTR   extp;
    318513{
    319514  union internal_auxent *in = (union internal_auxent *)inp;
    320515  AUXENT *ext = (AUXENT *)extp;
    321516
    322   memset((PTR)ext, 0, bfd_coff_auxesz (abfd));
     517  memset ((PTR)ext, 0, bfd_coff_auxesz (abfd));
    323518  switch (class)
    324519    {
    325   case C_FILE:
    326     if (in->x_file.x_fname[0] == 0)
    327       {
    328       PUTWORD(abfd, 0, (bfd_byte *) ext->x_file.x_n.x_zeroes);
    329       PUTWORD(abfd,
    330               in->x_file.x_n.x_offset,
    331               (bfd_byte *) ext->x_file.x_n.x_offset);
    332     }
    333     else
    334       {
    335       memcpy (ext->x_file.x_fname, in->x_file.x_fname, FILNMLEN);
    336       }
    337     goto end;
    338 
    339   /* RS/6000 "csect" auxents */
    340   case C_EXT:
    341   case C_HIDEXT:
    342     if (indx + 1 == numaux)
    343       {
    344         PUTWORD (abfd, in->x_csect.x_scnlen.l,ext->x_csect.x_scnlen);
    345         PUTWORD (abfd, in->x_csect.x_parmhash,  ext->x_csect.x_parmhash);
    346         PUTHALF (abfd, in->x_csect.x_snhash,    ext->x_csect.x_snhash);
    347         /* We don't have to hack bitfields in x_smtyp because it's
    348            defined by shifts-and-ands, which are equivalent on all
    349            byte orders.  */
    350         PUTBYTE (abfd, in->x_csect.x_smtyp,     ext->x_csect.x_smtyp);
    351         PUTBYTE (abfd, in->x_csect.x_smclas,    ext->x_csect.x_smclas);
    352         PUTWORD (abfd, in->x_csect.x_stab,      ext->x_csect.x_stab);
    353         PUTHALF (abfd, in->x_csect.x_snstab,    ext->x_csect.x_snstab);
    354         goto end;
    355       }
    356     break;
    357 
    358   case C_STAT:
    359   case C_LEAFSTAT:
    360   case C_HIDDEN:
    361     if (type == T_NULL) {
    362       bfd_h_put_32(abfd, in->x_scn.x_scnlen, (bfd_byte *) ext->x_scn.x_scnlen);
    363       bfd_h_put_16(abfd, in->x_scn.x_nreloc, (bfd_byte *) ext->x_scn.x_nreloc);
    364       bfd_h_put_16(abfd, in->x_scn.x_nlinno, (bfd_byte *) ext->x_scn.x_nlinno);
     520    case C_FILE:
     521      if (in->x_file.x_fname[0] == 0)
     522        {
     523          H_PUT_32 (abfd, 0, ext->x_file.x_n.x_zeroes);
     524          H_PUT_32 (abfd, in->x_file.x_n.x_offset, ext->x_file.x_n.x_offset);
     525        }
     526      else
     527        {
     528          memcpy (ext->x_file.x_fname, in->x_file.x_fname, FILNMLEN);
     529        }
    365530      goto end;
    366     }
    367     break;
    368   }
    369 
    370   PUTWORD(abfd, in->x_sym.x_tagndx.l, (bfd_byte *) ext->x_sym.x_tagndx);
    371   bfd_h_put_16 (abfd, in->x_sym.x_tvndx , (bfd_byte *) ext->x_sym.x_tvndx);
     531
     532      /* RS/6000 "csect" auxents */
     533    case C_EXT:
     534    case C_HIDEXT:
     535      if (indx + 1 == numaux)
     536        {
     537          H_PUT_32 (abfd, in->x_csect.x_scnlen.l, ext->x_csect.x_scnlen);
     538          H_PUT_32 (abfd, in->x_csect.x_parmhash, ext->x_csect.x_parmhash);
     539          H_PUT_16 (abfd, in->x_csect.x_snhash, ext->x_csect.x_snhash);
     540          /* We don't have to hack bitfields in x_smtyp because it's
     541             defined by shifts-and-ands, which are equivalent on all
     542             byte orders.  */
     543          H_PUT_8 (abfd, in->x_csect.x_smtyp, ext->x_csect.x_smtyp);
     544          H_PUT_8 (abfd, in->x_csect.x_smclas, ext->x_csect.x_smclas);
     545          H_PUT_32 (abfd, in->x_csect.x_stab, ext->x_csect.x_stab);
     546          H_PUT_16 (abfd, in->x_csect.x_snstab, ext->x_csect.x_snstab);
     547          goto end;
     548        }
     549      break;
     550
     551    case C_STAT:
     552    case C_LEAFSTAT:
     553    case C_HIDDEN:
     554      if (type == T_NULL)
     555        {
     556          H_PUT_32 (abfd, in->x_scn.x_scnlen, ext->x_scn.x_scnlen);
     557          H_PUT_16 (abfd, in->x_scn.x_nreloc, ext->x_scn.x_nreloc);
     558          H_PUT_16 (abfd, in->x_scn.x_nlinno, ext->x_scn.x_nlinno);
     559          goto end;
     560        }
     561      break;
     562    }
     563
     564  H_PUT_32 (abfd, in->x_sym.x_tagndx.l, ext->x_sym.x_tagndx);
     565  H_PUT_16 (abfd, in->x_sym.x_tvndx, ext->x_sym.x_tvndx);
    372566
    373567  if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
    374568    {
    375       bfd_h_put_32(abfd, in->x_sym.x_fcnary.x_fcn.x_lnnoptr,
    376               (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr);
    377       PUTWORD(abfd, in->x_sym.x_fcnary.x_fcn.x_endndx.l,
    378               (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx);
     569      H_PUT_32 (abfd, in->x_sym.x_fcnary.x_fcn.x_lnnoptr,
     570                ext->x_sym.x_fcnary.x_fcn.x_lnnoptr);
     571      H_PUT_32 (abfd, in->x_sym.x_fcnary.x_fcn.x_endndx.l,
     572                ext->x_sym.x_fcnary.x_fcn.x_endndx);
    379573    }
    380574  else
    381575    {
    382       bfd_h_put_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[0],
    383                     (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
    384       bfd_h_put_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[1],
    385                     (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
    386       bfd_h_put_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[2],
    387                     (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
    388       bfd_h_put_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[3],
    389                     (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
     576      H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[0],
     577                ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
     578      H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[1],
     579                ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
     580      H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[2],
     581                ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
     582      H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[3],
     583                ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
    390584    }
    391585
    392586  if (ISFCN (type))
    393     PUTWORD (abfd, in->x_sym.x_misc.x_fsize,
    394              (bfd_byte *)  ext->x_sym.x_misc.x_fsize);
     587    H_PUT_32 (abfd, in->x_sym.x_misc.x_fsize, ext->x_sym.x_misc.x_fsize);
    395588  else
    396589    {
    397       bfd_h_put_16(abfd, in->x_sym.x_misc.x_lnsz.x_lnno,
    398               (bfd_byte *)ext->x_sym.x_misc.x_lnsz.x_lnno);
    399       bfd_h_put_16(abfd, in->x_sym.x_misc.x_lnsz.x_size,
    400               (bfd_byte *)ext->x_sym.x_misc.x_lnsz.x_size);
     590      H_PUT_16 (abfd, in->x_sym.x_misc.x_lnsz.x_lnno,
     591                ext->x_sym.x_misc.x_lnsz.x_lnno);
     592      H_PUT_16 (abfd, in->x_sym.x_misc.x_lnsz.x_size,
     593                ext->x_sym.x_misc.x_lnsz.x_size);
    401594    }
    402595
     
    404597  return bfd_coff_auxesz (abfd);
    405598}
     599
     600
    406601
    407602
     
    412607   relocs need special_function entries, which I have not written.  */
    413608
    414 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
    415    from smaller values.  Start with zero, widen, *then* decrement.  */
    416 #define MINUS_ONE       (((bfd_vma)0) - 1)
    417609
    418610reloc_howto_type xcoff_howto_table[] =
    419611{
    420612  /* Standard 32 bit relocation.  */
    421   HOWTO (0,                     /* type */
    422          0,                     /* rightshift */
    423          2,                     /* size (0 = byte, 1 = short, 2 = long) */
    424          32,                    /* bitsize */
    425          false,                 /* pc_relative */
    426          0,                     /* bitpos */
     613  HOWTO (R_POS,                 /* type */
     614         0,                     /* rightshift */
     615         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     616         32,                    /* bitsize */
     617         FALSE,                 /* pc_relative */
     618         0,                     /* bitpos */
    427619         complain_overflow_bitfield, /* complain_on_overflow */
    428          0,                     /* special_function */
    429          "R_POS",               /* name */
    430          true,                  /* partial_inplace */
    431          0xffffffff,            /* src_mask */
    432          0xffffffff,            /* dst_mask */
    433          false),                /* pcrel_offset */
     620         0,                     /* special_function */
     621         "R_POS",               /* name */
     622         TRUE,                  /* partial_inplace */
     623         0xffffffff,            /* src_mask */
     624         0xffffffff,            /* dst_mask */
     625         FALSE),                /* pcrel_offset */
    434626
    435627  /* 32 bit relocation, but store negative value.  */
    436   HOWTO (1,                     /* type */
    437          0,                     /* rightshift */
    438          -2,                    /* size (0 = byte, 1 = short, 2 = long) */
    439          32,                    /* bitsize */
    440          false,                 /* pc_relative */
    441          0,                     /* bitpos */
     628  HOWTO (R_NEG,                 /* type */
     629         0,                     /* rightshift */
     630         -2,                    /* size (0 = byte, 1 = short, 2 = long) */
     631         32,                    /* bitsize */
     632         FALSE,                 /* pc_relative */
     633         0,                     /* bitpos */
    442634         complain_overflow_bitfield, /* complain_on_overflow */
    443          0,                     /* special_function */
    444          "R_NEG",               /* name */
    445          true,                  /* partial_inplace */
    446          0xffffffff,            /* src_mask */
    447          0xffffffff,            /* dst_mask */
    448          false),                /* pcrel_offset */
     635         0,                     /* special_function */
     636         "R_NEG",               /* name */
     637         TRUE,                  /* partial_inplace */
     638         0xffffffff,            /* src_mask */
     639         0xffffffff,            /* dst_mask */
     640         FALSE),                /* pcrel_offset */
    449641
    450642  /* 32 bit PC relative relocation.  */
    451   HOWTO (2,                     /* type */
    452          0,                     /* rightshift */
    453          2,                     /* size (0 = byte, 1 = short, 2 = long) */
    454          32,                    /* bitsize */
    455          true,                  /* pc_relative */
    456          0,                     /* bitpos */
     643  HOWTO (R_REL,                 /* type */
     644         0,                     /* rightshift */
     645         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     646         32,                    /* bitsize */
     647         TRUE,                  /* pc_relative */
     648         0,                     /* bitpos */
    457649         complain_overflow_signed, /* complain_on_overflow */
    458          0,                     /* special_function */
    459          "R_REL",               /* name */
    460          true,                  /* partial_inplace */
    461          0xffffffff,            /* src_mask */
    462          0xffffffff,            /* dst_mask */
    463          false),                /* pcrel_offset */
     650         0,                     /* special_function */
     651         "R_REL",               /* name */
     652         TRUE,                  /* partial_inplace */
     653         0xffffffff,            /* src_mask */
     654         0xffffffff,            /* dst_mask */
     655         FALSE),                /* pcrel_offset */
    464656
    465657  /* 16 bit TOC relative relocation.  */
    466   HOWTO (3,                     /* type */
    467          0,                     /* rightshift */
    468          1,                     /* size (0 = byte, 1 = short, 2 = long) */
    469          16,                    /* bitsize */
    470          false,                 /* pc_relative */
    471          0,                     /* bitpos */
     658  HOWTO (R_TOC,                 /* type */
     659         0,                     /* rightshift */
     660         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     661         16,                    /* bitsize */
     662         FALSE,                 /* pc_relative */
     663         0,                     /* bitpos */
    472664         complain_overflow_bitfield, /* complain_on_overflow */
    473          0,                     /* special_function */
    474          "R_TOC",               /* name */
    475          true,                  /* partial_inplace */
    476          0xffff,                /* src_mask */
    477          0xffff,                /* dst_mask */
    478          false),                /* pcrel_offset */
     665         0,                     /* special_function */
     666         "R_TOC",               /* name */
     667         TRUE,                  /* partial_inplace */
     668         0xffff,                /* src_mask */
     669         0xffff,                /* dst_mask */
     670         FALSE),                /* pcrel_offset */
    479671
    480672  /* I don't really know what this is.  */
    481   HOWTO (4,                     /* type */
    482          1,                     /* rightshift */
    483          2,                     /* size (0 = byte, 1 = short, 2 = long) */
    484          32,                    /* bitsize */
    485          false,                 /* pc_relative */
    486          0,                     /* bitpos */
     673  HOWTO (R_RTB,                 /* type */
     674         1,                     /* rightshift */
     675         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     676         32,                    /* bitsize */
     677         FALSE,                 /* pc_relative */
     678         0,                     /* bitpos */
    487679         complain_overflow_bitfield, /* complain_on_overflow */
    488          0,                     /* special_function */
    489          "R_RTB",               /* name */
    490          true,                  /* partial_inplace */
    491          0xffffffff,            /* src_mask */
    492          0xffffffff,            /* dst_mask */
    493          false),                /* pcrel_offset */
     680         0,                     /* special_function */
     681         "R_RTB",               /* name */
     682         TRUE,                  /* partial_inplace */
     683         0xffffffff,            /* src_mask */
     684         0xffffffff,            /* dst_mask */
     685         FALSE),                /* pcrel_offset */
    494686
    495687  /* External TOC relative symbol.  */
    496   HOWTO (5,                     /* type */
    497          0,                     /* rightshift */
    498          2,                     /* size (0 = byte, 1 = short, 2 = long) */
    499          16,                    /* bitsize */
    500          false,                 /* pc_relative */
    501          0,                     /* bitpos */
     688  HOWTO (R_GL,                  /* type */
     689         0,                     /* rightshift */
     690         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     691         16,                    /* bitsize */
     692         FALSE,                 /* pc_relative */
     693         0,                     /* bitpos */
    502694         complain_overflow_bitfield, /* complain_on_overflow */
    503          0,                     /* special_function */
    504          "R_GL",                /* name */
    505          true,                  /* partial_inplace */
    506          0xffff,                /* src_mask */
    507          0xffff,                /* dst_mask */
    508          false),                /* pcrel_offset */
    509 
    510   /* Local TOC relative symbol.  */
    511   HOWTO (6,                     /* type */
    512          0,                     /* rightshift */
    513          2,                     /* size (0 = byte, 1 = short, 2 = long) */
    514          16,                    /* bitsize */
    515          false,                 /* pc_relative */
    516          0,                     /* bitpos */
     695         0,                     /* special_function */
     696         "R_GL",                /* name */
     697         TRUE,                  /* partial_inplace */
     698         0xffff,                /* src_mask */
     699         0xffff,                /* dst_mask */
     700         FALSE),                /* pcrel_offset */
     701
     702  /* Local TOC relative symbol.  */
     703  HOWTO (R_TCL,                 /* type */
     704         0,                     /* rightshift */
     705         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     706         16,                    /* bitsize */
     707         FALSE,                 /* pc_relative */
     708         0,                     /* bitpos */
    517709         complain_overflow_bitfield, /* complain_on_overflow */
    518          0,                     /* special_function */
    519          "R_TCL",               /* name */
    520          true,                  /* partial_inplace */
    521          0xffff,                /* src_mask */
    522          0xffff,                /* dst_mask */
    523          false),                /* pcrel_offset */
     710         0,                     /* special_function */
     711         "R_TCL",               /* name */
     712         TRUE,                  /* partial_inplace */
     713         0xffff,                /* src_mask */
     714         0xffff,                /* dst_mask */
     715         FALSE),                /* pcrel_offset */
    524716
    525717  EMPTY_HOWTO (7),
    526718
    527719  /* Non modifiable absolute branch.  */
    528   HOWTO (8,                     /* type */
    529          0,                     /* rightshift */
    530          2,                     /* size (0 = byte, 1 = short, 2 = long) */
    531          26,                    /* bitsize */
    532          false,                 /* pc_relative */
    533          0,                     /* bitpos */
     720  HOWTO (R_BA,                  /* type */
     721         0,                     /* rightshift */
     722         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     723         26,                    /* bitsize */
     724         FALSE,                 /* pc_relative */
     725         0,                     /* bitpos */
    534726         complain_overflow_bitfield, /* complain_on_overflow */
    535          0,                     /* special_function */
    536          "R_BA",                /* name */
    537          true,                  /* partial_inplace */
    538          0x3fffffc,             /* src_mask */
    539          0x3fffffc,             /* dst_mask */
    540          false),                /* pcrel_offset */
     727         0,                     /* special_function */
     728         "R_BA_26",             /* name */
     729         TRUE,                  /* partial_inplace */
     730         0x03fffffc,            /* src_mask */
     731         0x03fffffc,            /* dst_mask */
     732         FALSE),                /* pcrel_offset */
    541733
    542734  EMPTY_HOWTO (9),
    543735
    544736  /* Non modifiable relative branch.  */
    545   HOWTO (0xa,                   /* type */
    546          0,                     /* rightshift */
    547          2,                     /* size (0 = byte, 1 = short, 2 = long) */
    548          26,                    /* bitsize */
    549          true,                  /* pc_relative */
    550          0,                     /* bitpos */
     737  HOWTO (R_BR,                  /* type */
     738         0,                     /* rightshift */
     739         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     740         26,                    /* bitsize */
     741         TRUE,                  /* pc_relative */
     742         0,                     /* bitpos */
    551743         complain_overflow_signed, /* complain_on_overflow */
    552          0,                     /* special_function */
    553          "R_BR",                /* name */
    554          true,                  /* partial_inplace */
    555          0x3fffffc,             /* src_mask */
    556          0x3fffffc,             /* dst_mask */
    557          false),                /* pcrel_offset */
     744         0,                     /* special_function */
     745         "R_BR",                /* name */
     746         TRUE,                  /* partial_inplace */
     747         0x03fffffc,            /* src_mask */
     748         0x03fffffc,            /* dst_mask */
     749         FALSE),                /* pcrel_offset */
    558750
    559751  EMPTY_HOWTO (0xb),
    560752
    561753  /* Indirect load.  */
    562   HOWTO (0xc,                   /* type */
    563          0,                     /* rightshift */
    564          2,                     /* size (0 = byte, 1 = short, 2 = long) */
    565          16,                    /* bitsize */
    566          false,                 /* pc_relative */
    567          0,                     /* bitpos */
     754  HOWTO (R_RL,                  /* type */
     755         0,                     /* rightshift */
     756         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     757         16,                    /* bitsize */
     758         FALSE,                 /* pc_relative */
     759         0,                     /* bitpos */
    568760         complain_overflow_bitfield, /* complain_on_overflow */
    569          0,                     /* special_function */
    570          "R_RL",                /* name */
    571          true,                  /* partial_inplace */
    572          0xffff,                /* src_mask */
    573          0xffff,                /* dst_mask */
    574          false),                /* pcrel_offset */
     761         0,                     /* special_function */
     762         "R_RL",                /* name */
     763         TRUE,                  /* partial_inplace */
     764         0xffff,                /* src_mask */
     765         0xffff,                /* dst_mask */
     766         FALSE),                /* pcrel_offset */
    575767
    576768  /* Load address.  */
    577   HOWTO (0xd,                   /* type */
    578          0,                     /* rightshift */
    579          2,                     /* size (0 = byte, 1 = short, 2 = long) */
    580          16,                    /* bitsize */
    581          false,                 /* pc_relative */
    582          0,                     /* bitpos */
     769  HOWTO (R_RLA,                 /* type */
     770         0,                     /* rightshift */
     771         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     772         16,                    /* bitsize */
     773         FALSE,                 /* pc_relative */
     774         0,                     /* bitpos */
    583775         complain_overflow_bitfield, /* complain_on_overflow */
    584          0,                     /* special_function */
    585          "R_RLA",               /* name */
    586          true,                  /* partial_inplace */
    587          0xffff,                /* src_mask */
    588          0xffff,                /* dst_mask */
    589          false),                /* pcrel_offset */
     776         0,                     /* special_function */
     777         "R_RLA",               /* name */
     778         TRUE,                  /* partial_inplace */
     779         0xffff,                /* src_mask */
     780         0xffff,                /* dst_mask */
     781         FALSE),                /* pcrel_offset */
    590782
    591783  EMPTY_HOWTO (0xe),
    592784
    593785  /* Non-relocating reference.  */
    594   HOWTO (0xf,                   /* type */
    595          0,                     /* rightshift */
    596          2,                     /* size (0 = byte, 1 = short, 2 = long) */
    597          32,                    /* bitsize */
    598          false,                 /* pc_relative */
    599          0,                     /* bitpos */
    600          complain_overflow_bitfield, /* complain_on_overflow */
    601          0,                     /* special_function */
    602          "R_REF",               /* name */
    603          false,                 /* partial_inplace */
    604          0,                     /* src_mask */
    605          0,                     /* dst_mask */
    606          false),                /* pcrel_offset */
     786  HOWTO (R_REF,                 /* type */
     787         0,                     /* rightshift */
     788         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     789         32,                    /* bitsize */
     790         FALSE,                 /* pc_relative */
     791         0,                     /* bitpos */
     792         complain_overflow_dont, /* complain_on_overflow */
     793         0,                     /* special_function */
     794         "R_REF",               /* name */
     795         FALSE,                 /* partial_inplace */
     796         0,                     /* src_mask */
     797         0,                     /* dst_mask */
     798         FALSE),                /* pcrel_offset */
    607799
    608800  EMPTY_HOWTO (0x10),
     
    610802
    611803  /* TOC relative indirect load.  */
    612   HOWTO (0x12,                  /* type */
    613          0,                     /* rightshift */
    614          2,                     /* size (0 = byte, 1 = short, 2 = long) */
    615          16,                    /* bitsize */
    616          false,                 /* pc_relative */
    617          0,                     /* bitpos */
     804  HOWTO (R_TRL,                 /* type */
     805         0,                     /* rightshift */
     806         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     807         16,                    /* bitsize */
     808         FALSE,                 /* pc_relative */
     809         0,                     /* bitpos */
    618810         complain_overflow_bitfield, /* complain_on_overflow */
    619          0,                     /* special_function */
    620          "R_TRL",               /* name */
    621          true,                  /* partial_inplace */
    622          0xffff,                /* src_mask */
    623          0xffff,                /* dst_mask */
    624          false),                /* pcrel_offset */
     811         0,                     /* special_function */
     812         "R_TRL",               /* name */
     813         TRUE,                  /* partial_inplace */
     814         0xffff,                /* src_mask */
     815         0xffff,                /* dst_mask */
     816         FALSE),                /* pcrel_offset */
    625817
    626818  /* TOC relative load address.  */
    627   HOWTO (0x13,                  /* type */
    628          0,                     /* rightshift */
    629          2,                     /* size (0 = byte, 1 = short, 2 = long) */
    630          16,                    /* bitsize */
    631          false,                 /* pc_relative */
    632          0,                     /* bitpos */
     819  HOWTO (R_TRLA,                /* type */
     820         0,                     /* rightshift */
     821         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     822         16,                    /* bitsize */
     823         FALSE,                 /* pc_relative */
     824         0,                     /* bitpos */
    633825         complain_overflow_bitfield, /* complain_on_overflow */
    634          0,                     /* special_function */
    635          "R_TRLA",              /* name */
    636          true,                  /* partial_inplace */
    637          0xffff,                /* src_mask */
    638          0xffff,                /* dst_mask */
    639          false),                /* pcrel_offset */
     826         0,                     /* special_function */
     827         "R_TRLA",              /* name */
     828         TRUE,                  /* partial_inplace */
     829         0xffff,                /* src_mask */
     830         0xffff,                /* dst_mask */
     831         FALSE),                /* pcrel_offset */
    640832
    641833  /* Modifiable relative branch.  */
    642   HOWTO (0x14,                  /* type */
    643          1,                     /* rightshift */
    644          2,                     /* size (0 = byte, 1 = short, 2 = long) */
    645          32,                    /* bitsize */
    646          false,                 /* pc_relative */
    647          0,                     /* bitpos */
     834  HOWTO (R_RRTBI,                /* type */
     835         1,                     /* rightshift */
     836         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     837         32,                    /* bitsize */
     838         FALSE,                 /* pc_relative */
     839         0,                     /* bitpos */
    648840         complain_overflow_bitfield, /* complain_on_overflow */
    649          0,                     /* special_function */
    650          "R_RRTBI",             /* name */
    651          true,                  /* partial_inplace */
    652          0xffffffff,            /* src_mask */
    653          0xffffffff,            /* dst_mask */
    654          false),                /* pcrel_offset */
     841         0,                     /* special_function */
     842         "R_RRTBI",             /* name */
     843         TRUE,                  /* partial_inplace */
     844         0xffffffff,            /* src_mask */
     845         0xffffffff,            /* dst_mask */
     846         FALSE),                /* pcrel_offset */
    655847
    656848  /* Modifiable absolute branch.  */
    657   HOWTO (0x15,                  /* type */
    658          1,                     /* rightshift */
    659          2,                     /* size (0 = byte, 1 = short, 2 = long) */
    660          32,                    /* bitsize */
    661          false,                 /* pc_relative */
    662          0,                     /* bitpos */
     849  HOWTO (R_RRTBA,                /* type */
     850         1,                     /* rightshift */
     851         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     852         32,                    /* bitsize */
     853         FALSE,                 /* pc_relative */
     854         0,                     /* bitpos */
    663855         complain_overflow_bitfield, /* complain_on_overflow */
    664          0,                     /* special_function */
    665          "R_RRTBA",             /* name */
    666          true,                  /* partial_inplace */
    667          0xffffffff,            /* src_mask */
    668          0xffffffff,            /* dst_mask */
    669          false),                /* pcrel_offset */
     856         0,                     /* special_function */
     857         "R_RRTBA",             /* name */
     858         TRUE,                  /* partial_inplace */
     859         0xffffffff,            /* src_mask */
     860         0xffffffff,            /* dst_mask */
     861         FALSE),                /* pcrel_offset */
    670862
    671863  /* Modifiable call absolute indirect.  */
    672   HOWTO (0x16,                  /* type */
    673          0,                     /* rightshift */
    674          2,                     /* size (0 = byte, 1 = short, 2 = long) */
    675          16,                    /* bitsize */
    676          false,                 /* pc_relative */
    677          0,                     /* bitpos */
     864  HOWTO (R_CAI,                 /* type */
     865         0,                     /* rightshift */
     866         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     867         16,                    /* bitsize */
     868         FALSE,                 /* pc_relative */
     869         0,                     /* bitpos */
    678870         complain_overflow_bitfield, /* complain_on_overflow */
    679          0,                     /* special_function */
    680          "R_CAI",               /* name */
    681          true,                  /* partial_inplace */
    682          0xffff,                /* src_mask */
    683          0xffff,                /* dst_mask */
    684          false),                /* pcrel_offset */
     871         0,                     /* special_function */
     872         "R_CAI",               /* name */
     873         TRUE,                  /* partial_inplace */
     874         0xffff,                /* src_mask */
     875         0xffff,                /* dst_mask */
     876         FALSE),                /* pcrel_offset */
    685877
    686878  /* Modifiable call relative.  */
    687   HOWTO (0x17,                  /* type */
    688          0,                     /* rightshift */
    689          2,                     /* size (0 = byte, 1 = short, 2 = long) */
    690          16,                    /* bitsize */
    691          false,                 /* pc_relative */
    692          0,                     /* bitpos */
     879  HOWTO (R_CREL,                /* type */
     880         0,                     /* rightshift */
     881         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     882         16,                    /* bitsize */
     883         FALSE,                 /* pc_relative */
     884         0,                     /* bitpos */
    693885         complain_overflow_bitfield, /* complain_on_overflow */
    694          0,                     /* special_function */
    695          "R_CREL",              /* name */
    696          true,                  /* partial_inplace */
    697          0xffff,                /* src_mask */
    698          0xffff,                /* dst_mask */
    699          false),                /* pcrel_offset */
     886         0,                     /* special_function */
     887         "R_CREL",              /* name */
     888         TRUE,                  /* partial_inplace */
     889         0xffff,                /* src_mask */
     890         0xffff,                /* dst_mask */
     891         FALSE),                /* pcrel_offset */
    700892
    701893  /* Modifiable branch absolute.  */
    702   HOWTO (0x18,                  /* type */
    703          0,                     /* rightshift */
    704          2,                     /* size (0 = byte, 1 = short, 2 = long) */
    705          26,                    /* bitsize */
    706          false,                 /* pc_relative */
    707          0,                     /* bitpos */
     894  HOWTO (R_RBA,                 /* type */
     895         0,                     /* rightshift */
     896         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     897         26,                    /* bitsize */
     898         FALSE,                 /* pc_relative */
     899         0,                     /* bitpos */
    708900         complain_overflow_bitfield, /* complain_on_overflow */
    709          0,                     /* special_function */
    710          "R_RBA",               /* name */
    711          true,                  /* partial_inplace */
    712          0xffff,                /* src_mask */
    713          0xffff,                /* dst_mask */
    714          false),                /* pcrel_offset */
     901         0,                     /* special_function */
     902         "R_RBA",               /* name */
     903         TRUE,                  /* partial_inplace */
     904         0x03fffffc,            /* src_mask */
     905         0x03fffffc,            /* dst_mask */
     906         FALSE),                /* pcrel_offset */
    715907
    716908  /* Modifiable branch absolute.  */
    717   HOWTO (0x19,                  /* type */
    718          0,                     /* rightshift */
    719          2,                     /* size (0 = byte, 1 = short, 2 = long) */
    720          32,                    /* bitsize */
    721          false,                 /* pc_relative */
    722          0,                     /* bitpos */
     909  HOWTO (R_RBAC,                /* type */
     910         0,                     /* rightshift */
     911         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     912         32,                    /* bitsize */
     913         FALSE,                 /* pc_relative */
     914         0,                     /* bitpos */
    723915         complain_overflow_bitfield, /* complain_on_overflow */
    724          0,                     /* special_function */
    725          "R_RBAC",              /* name */
    726          true,                  /* partial_inplace */
    727          0xffff,                /* src_mask */
    728          0xffff,                /* dst_mask */
    729          false),                /* pcrel_offset */
     916         0,                     /* special_function */
     917         "R_RBAC",              /* name */
     918         TRUE,                  /* partial_inplace */
     919         0xffffffff,            /* src_mask */
     920         0xffffffff,            /* dst_mask */
     921         FALSE),                /* pcrel_offset */
    730922
    731923  /* Modifiable branch relative.  */
    732   HOWTO (0x1a,                  /* type */
    733          0,                     /* rightshift */
    734          2,                     /* size (0 = byte, 1 = short, 2 = long) */
    735          26,                    /* bitsize */
    736          false,                 /* pc_relative */
    737          0,                     /* bitpos */
     924  HOWTO (R_RBR,                 /* type */
     925         0,                     /* rightshift */
     926         2,                     /* size (0 = byte, 1 = short, 2 = long) */
     927         26,                    /* bitsize */
     928         FALSE,                 /* pc_relative */
     929         0,                     /* bitpos */
    738930         complain_overflow_signed, /* complain_on_overflow */
    739          0,                     /* special_function */
    740          "R_RBR",               /* name */
    741          true,                  /* partial_inplace */
    742          0xffff,                /* src_mask */
    743          0xffff,                /* dst_mask */
    744          false),                /* pcrel_offset */
     931         0,                     /* special_function */
     932         "R_RBR_26",            /* name */
     933         TRUE,                  /* partial_inplace */
     934         0x03fffffc,            /* src_mask */
     935         0x03fffffc,            /* dst_mask */
     936         FALSE),                /* pcrel_offset */
    745937
    746938  /* Modifiable branch absolute.  */
    747   HOWTO (0x1b,                  /* type */
    748          0,                     /* rightshift */
    749          2,                     /* size (0 = byte, 1 = short, 2 = long) */
    750          16,                    /* bitsize */
    751          false,                 /* pc_relative */
    752          0,                     /* bitpos */
     939  HOWTO (R_RBRC,                /* type */
     940         0,                     /* rightshift */
     941         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     942         16,                    /* bitsize */
     943         FALSE,                 /* pc_relative */
     944         0,                     /* bitpos */
    753945         complain_overflow_bitfield, /* complain_on_overflow */
    754          0,                     /* special_function */
    755          "R_RBRC",              /* name */
    756          true,                  /* partial_inplace */
    757          0xffff,                /* src_mask */
    758          0xffff,                /* dst_mask */
    759          false),                /* pcrel_offset */
    760   HOWTO (0,                     /* type */
    761          0,                     /* rightshift */
    762          4,                     /* size (0 = byte, 1 = short, 2 = long) */
    763          64,                    /* bitsize */
    764          false,                 /* pc_relative */
    765          0,                     /* bitpos */
    766          complain_overflow_bitfield, /* complain_on_overflow */
    767          0,                     /* special_function */
    768          "R_POS",               /* name */
    769          true,                  /* partial_inplace */
    770          MINUS_ONE,             /* src_mask */
    771          MINUS_ONE,             /* dst_mask */
    772          false)                 /* pcrel_offset */
     946         0,                     /* special_function */
     947         "R_RBRC",              /* name */
     948         TRUE,                  /* partial_inplace */
     949         0xffff,                /* src_mask */
     950         0xffff,                /* dst_mask */
     951         FALSE),                /* pcrel_offset */
     952
     953  /* 16 bit Non modifiable absolute branch.  */
     954  HOWTO (R_BA,                  /* type */
     955         0,                     /* rightshift */
     956         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     957         16,                    /* bitsize */
     958         FALSE,                 /* pc_relative */
     959         0,                     /* bitpos */
     960         complain_overflow_bitfield, /* complain_on_overflow */
     961         0,                     /* special_function */
     962         "R_BA_16",             /* name */
     963         TRUE,                  /* partial_inplace */
     964         0xfffc,                /* src_mask */
     965         0xfffc,                /* dst_mask */
     966         FALSE),                /* pcrel_offset */
     967
     968  /* Modifiable branch relative.  */
     969  HOWTO (R_RBR,                 /* type */
     970         0,                     /* rightshift */
     971         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     972         16,                    /* bitsize */
     973         FALSE,                 /* pc_relative */
     974         0,                     /* bitpos */
     975         complain_overflow_signed, /* complain_on_overflow */
     976         0,                     /* special_function */
     977         "R_RBR_16",            /* name */
     978         TRUE,                  /* partial_inplace */
     979         0xffff,                /* src_mask */
     980         0xffff,                /* dst_mask */
     981         FALSE),                /* pcrel_offset */
     982
     983  /* Modifiable branch relative.  */
     984  HOWTO (R_RBA,                 /* type */
     985         0,                     /* rightshift */
     986         1,                     /* size (0 = byte, 1 = short, 2 = long) */
     987         16,                    /* bitsize */
     988         FALSE,                 /* pc_relative */
     989         0,                     /* bitpos */
     990         complain_overflow_signed, /* complain_on_overflow */
     991         0,                     /* special_function */
     992         "R_RBA_16",            /* name */
     993         TRUE,                  /* partial_inplace */
     994         0xffff,                /* src_mask */
     995         0xffff,                /* dst_mask */
     996         FALSE),                /* pcrel_offset */
    773997
    774998};
    775999
    776 /* These are the first two like the above but for 16-bit relocs.  */
    777 static reloc_howto_type xcoff_howto_table_16[] =
    778 {
    779   /* Standard 16 bit relocation.  */
    780   HOWTO (0,                     /* type */
    781          0,                     /* rightshift */
    782          2,                     /* size (0 = byte, 1 = short, 2 = long) */
    783          16,                    /* bitsize */
    784          false,                 /* pc_relative */
    785          0,                     /* bitpos */
    786          complain_overflow_bitfield, /* complain_on_overflow */
    787          0,                     /* special_function */
    788          "R_POS_16",            /* name */
    789          true,                  /* partial_inplace */
    790          0xffffffff,            /* src_mask */
    791          0xffffffff,            /* dst_mask */
    792          false),                /* pcrel_offset */
    793 
    794   /* 16 bit relocation, but store negative value.  */
    795   HOWTO (1,                     /* type */
    796          0,                     /* rightshift */
    797          -2,                    /* size (0 = byte, 1 = short, 2 = long) */
    798          16,                    /* bitsize */
    799          false,                 /* pc_relative */
    800          0,                     /* bitpos */
    801          complain_overflow_bitfield, /* complain_on_overflow */
    802          0,                     /* special_function */
    803          "R_NEG_16",            /* name */
    804          true,                  /* partial_inplace */
    805          0xffffffff,            /* src_mask */
    806          0xffffffff,            /* dst_mask */
    807          false),                /* pcrel_offset */
    808 
    809   /* 16 bit PC relative relocation.  */
    810   HOWTO (2,                     /* type */
    811          0,                     /* rightshift */
    812          2,                     /* size (0 = byte, 1 = short, 2 = long) */
    813          32,                    /* bitsize */
    814          true,                  /* pc_relative */
    815          0,                     /* bitpos */
    816          complain_overflow_signed, /* complain_on_overflow */
    817          0,                     /* special_function */
    818          "R_REL_16",            /* name */
    819          true,                  /* partial_inplace */
    820          0xffffffff,            /* src_mask */
    821          0xffffffff,            /* dst_mask */
    822          false)                /* pcrel_offset */
    823   };
    824 
    8251000void
    826 _bfd_xcoff_rtype2howto (relent, internal)
     1001xcoff_rtype2howto (relent, internal)
    8271002     arelent *relent;
    8281003     struct internal_reloc *internal;
    8291004{
    830   relent->howto = xcoff_howto_table + internal->r_type;
    831 
    832   if (relent->howto->bitsize != ((unsigned int) internal->r_size & 0x1f) + 1
    833       && (internal->r_type
    834           < sizeof (xcoff_howto_table_16)/sizeof (xcoff_howto_table_16[0])))
    835     relent->howto = xcoff_howto_table_16 + internal->r_type;
     1005  if (internal->r_type > R_RBRC)
     1006    abort ();
     1007
     1008  /* Default howto layout works most of the time */
     1009  relent->howto = &xcoff_howto_table[internal->r_type];
     1010
     1011  /* Special case some 16 bit reoloc */
     1012  if (15 == (internal->r_size & 0x1f))
     1013    {
     1014      if (R_BA == internal->r_type)
     1015        relent->howto = &xcoff_howto_table[0x1c];
     1016      else if (R_RBR == internal->r_type)
     1017        relent->howto = &xcoff_howto_table[0x1d];
     1018      else if (R_RBA == internal->r_type)
     1019        relent->howto = &xcoff_howto_table[0x1e];
     1020    }
    8361021
    8371022  /* The r_size field of an XCOFF reloc encodes the bitsize of the
     
    8421027  if (relent->howto->dst_mask != 0
    8431028      && (relent->howto->bitsize
    844           != ((unsigned int) internal->r_size & 0x3f) + 1))
     1029          != ((unsigned int) internal->r_size & 0x1f) + 1))
    8451030    abort ();
    846 #if 0
    847   if ((internal->r_size & 0x80) != 0
    848       ? (relent->howto->complain_on_overflow != complain_overflow_signed)
    849       : (relent->howto->complain_on_overflow != complain_overflow_bitfield))
    850     abort ();
    851 #endif
    8521031}
    8531032
     
    8611040    case BFD_RELOC_PPC_B26:
    8621041      return &xcoff_howto_table[0xa];
     1042    case BFD_RELOC_PPC_BA16:
     1043      return &xcoff_howto_table[0x1c];
    8631044    case BFD_RELOC_PPC_BA26:
    8641045      return &xcoff_howto_table[8];
     
    8681049    case BFD_RELOC_CTOR:
    8691050      return &xcoff_howto_table[0];
    870     case BFD_RELOC_64:
    871       return &xcoff_howto_table[0x1c];
    8721051    default:
    8731052      return NULL;
    8741053    }
    8751054}
     1055
    8761056
    8771057
     
    9211101   have the same length.  */
    9221102
    923 #define XCOFFARMAG    "<aiaff>\012"
    924 #define XCOFFARMAGBIG "<bigaf>\012"
    925 #define SXCOFFARMAG   8
    926 
    927 /* This terminates an XCOFF archive member name.  */
    928 
    929 #define XCOFFARFMAG "`\012"
    930 #define SXCOFFARFMAG 2
    931 
    932 /* XCOFF archives start with this (printable) structure.  */
    933 
    934 struct xcoff_ar_file_hdr
    935 {
    936   /* Magic string.  */
    937   char magic[SXCOFFARMAG];
    938 
    939   /* Offset of the member table (decimal ASCII string).  */
    940   char memoff[12];
    941 
    942   /* Offset of the global symbol table (decimal ASCII string).  */
    943   char symoff[12];
    944 
    945   /* Offset of the first member in the archive (decimal ASCII string).  */
    946   char firstmemoff[12];
    947 
    948   /* Offset of the last member in the archive (decimal ASCII string).  */
    949   char lastmemoff[12];
    950 
    951   /* Offset of the first member on the free list (decimal ASCII
    952      string).  */
    953   char freeoff[12];
    954 };
    955 
    956 #define SIZEOF_AR_FILE_HDR (5 * 12 + SXCOFFARMAG)
    957 
    958 /* This is the equivalent data structure for the big archive format.  */
    959 
    960 struct xcoff_ar_file_hdr_big
    961 {
    962   /* Magic string.  */
    963   char magic[SXCOFFARMAG];
    964 
    965   /* Offset of the member table (decimal ASCII string).  */
    966   char memoff[20];
    967 
    968   /* Offset of the global symbol table for 32-bit objects (decimal ASCII
    969      string).  */
    970   char symoff[20];
    971 
    972   /* Offset of the global symbol table for 64-bit objects (decimal ASCII
    973      string).  */
    974   char symoff64[20];
    975 
    976   /* Offset of the first member in the archive (decimal ASCII string).  */
    977   char firstmemoff[20];
    978 
    979   /* Offset of the last member in the archive (decimal ASCII string).  */
    980   char lastmemoff[20];
    981 
    982   /* Offset of the first member on the free list (decimal ASCII
    983      string).  */
    984   char freeoff[20];
    985 };
    986 
    987 #define SIZEOF_AR_FILE_HDR_BIG (6 * 20 + SXCOFFARMAG)
    988 
    989 /* Each XCOFF archive member starts with this (printable) structure.  */
    990 
    991 struct xcoff_ar_hdr
    992 {
    993   /* File size not including the header (decimal ASCII string).  */
    994   char size[12];
    995 
    996   /* File offset of next archive member (decimal ASCII string).  */
    997   char nextoff[12];
    998 
    999   /* File offset of previous archive member (decimal ASCII string).  */
    1000   char prevoff[12];
    1001 
    1002   /* File mtime (decimal ASCII string).  */
    1003   char date[12];
    1004 
    1005   /* File UID (decimal ASCII string).  */
    1006   char uid[12];
    1007 
    1008   /* File GID (decimal ASCII string).  */
    1009   char gid[12];
    1010 
    1011   /* File mode (octal ASCII string).  */
    1012   char mode[12];
    1013 
    1014   /* Length of file name (decimal ASCII string).  */
    1015   char namlen[4];
    1016 
    1017   /* This structure is followed by the file name.  The length of the
    1018      name is given in the namlen field.  If the length of the name is
    1019      odd, the name is followed by a null byte.  The name and optional
    1020      null byte are followed by XCOFFARFMAG, which is not included in
    1021      namlen.  The contents of the archive member follow; the number of
    1022      bytes is given in the size field.  */
    1023 };
    1024 
    1025 #define SIZEOF_AR_HDR (7 * 12 + 4)
    1026 
    1027 /* The equivalent for the big archive format.  */
    1028 
    1029 struct xcoff_ar_hdr_big
    1030 {
    1031   /* File size not including the header (decimal ASCII string).  */
    1032   char size[20];
    1033 
    1034   /* File offset of next archive member (decimal ASCII string).  */
    1035   char nextoff[20];
    1036 
    1037   /* File offset of previous archive member (decimal ASCII string).  */
    1038   char prevoff[20];
    1039 
    1040   /* File mtime (decimal ASCII string).  */
    1041   char date[12];
    1042 
    1043   /* File UID (decimal ASCII string).  */
    1044   char uid[12];
    1045 
    1046   /* File GID (decimal ASCII string).  */
    1047   char gid[12];
    1048 
    1049   /* File mode (octal ASCII string).  */
    1050   char mode[12];
    1051 
    1052   /* Length of file name (decimal ASCII string).  */
    1053   char namlen[4];
    1054 
    1055   /* This structure is followed by the file name.  The length of the
    1056      name is given in the namlen field.  If the length of the name is
    1057      odd, the name is followed by a null byte.  The name and optional
    1058      null byte are followed by XCOFFARFMAG, which is not included in
    1059      namlen.  The contents of the archive member follow; the number of
    1060      bytes is given in the size field.  */
    1061 };
    1062 
    1063 #define SIZEOF_AR_HDR_BIG (3 * 20 + 4 * 12 + 4)
    1064 
    1065 /* We often have to distinguish between the old and big file format.
    1066    Make it a bit cleaner.  We can use `xcoff_ardata' here because the
    1067    `hdr' member has the same size and position in both formats.  */
    1068 #define xcoff_big_format_p(abfd) \
    1069   (xcoff_ardata (abfd)->magic[1] == 'b')
    1070 
    1071 /* We store a copy of the xcoff_ar_file_hdr in the tdata field of the
    1072    artdata structure.  Similar for the big archive.  */
    1073 #define xcoff_ardata(abfd) \
    1074   ((struct xcoff_ar_file_hdr *) bfd_ardata (abfd)->tdata)
    1075 #define xcoff_ardata_big(abfd) \
    1076   ((struct xcoff_ar_file_hdr_big *) bfd_ardata (abfd)->tdata)
    1077 
    1078 /* We store a copy of the xcoff_ar_hdr in the arelt_data field of an
    1079    archive element.  Similar for the big archive.  */
    1080 #define arch_eltdata(bfd) ((struct areltdata *) ((bfd)->arelt_data))
    1081 #define arch_xhdr(bfd) \
    1082   ((struct xcoff_ar_hdr *) arch_eltdata (bfd)->arch_header)
    1083 #define arch_xhdr_big(bfd) \
    1084   ((struct xcoff_ar_hdr_big *) arch_eltdata (bfd)->arch_header)
     1103/* Set the magic for archive.  */
     1104
     1105bfd_boolean
     1106bfd_xcoff_ar_archive_set_magic (abfd, magic)
     1107     bfd *abfd ATTRIBUTE_UNUSED;
     1108     char *magic ATTRIBUTE_UNUSED;
     1109{
     1110  /* Not supported yet.  */
     1111  return FALSE;
     1112 /* bfd_xcoff_archive_set_magic (abfd, magic); */
     1113}
    10851114
    10861115/* Read in the armap of an XCOFF archive.  */
    10871116
    1088 boolean
     1117bfd_boolean
    10891118_bfd_xcoff_slurp_armap (abfd)
    10901119     bfd *abfd;
     
    11001129  if (xcoff_ardata (abfd) == NULL)
    11011130    {
    1102       bfd_has_map (abfd) = false;
    1103       return true;
     1131      bfd_has_map (abfd) = FALSE;
     1132      return TRUE;
    11041133    }
    11051134
     
    11121141      if (off == 0)
    11131142        {
    1114           bfd_has_map (abfd) = false;
    1115           return true;
     1143          bfd_has_map (abfd) = FALSE;
     1144          return TRUE;
    11161145        }
    11171146
    11181147      if (bfd_seek (abfd, off, SEEK_SET) != 0)
    1119         return false;
     1148        return FALSE;
    11201149
    11211150      /* The symbol table starts with a normal archive header.  */
    1122       if (bfd_read ((PTR) &hdr, SIZEOF_AR_HDR, 1, abfd) != SIZEOF_AR_HDR)
    1123         return false;
     1151      if (bfd_bread ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
     1152          != SIZEOF_AR_HDR)
     1153        return FALSE;
    11241154
    11251155      /* Skip the name (normally empty).  */
    11261156      namlen = strtol (hdr.namlen, (char **) NULL, 10);
    1127       if (bfd_seek (abfd, ((namlen + 1) & ~1) + SXCOFFARFMAG, SEEK_CUR) != 0)
    1128         return false;
     1157      off = ((namlen + 1) & ~ (size_t) 1) + SXCOFFARFMAG;
     1158      if (bfd_seek (abfd, off, SEEK_CUR) != 0)
     1159        return FALSE;
    11291160
    11301161      sz = strtol (hdr.size, (char **) NULL, 10);
     
    11331164      contents = (bfd_byte *) bfd_alloc (abfd, sz);
    11341165      if (contents == NULL)
    1135         return false;
    1136       if (bfd_read ((PTR) contents, 1, sz, abfd) != sz)
    1137         return false;
     1166        return FALSE;
     1167      if (bfd_bread ((PTR) contents, sz, abfd) != sz)
     1168        return FALSE;
    11381169
    11391170      /* The symbol table starts with a four byte count.  */
    1140       c = bfd_h_get_32 (abfd, contents);
     1171      c = H_GET_32 (abfd, contents);
    11411172
    11421173      if (c * 4 >= sz)
    11431174        {
    11441175          bfd_set_error (bfd_error_bad_value);
    1145           return false;
     1176          return FALSE;
    11461177        }
    11471178
    1148       bfd_ardata (abfd)->symdefs = ((carsym *)
    1149                                     bfd_alloc (abfd, c * sizeof (carsym)));
     1179      bfd_ardata (abfd)->symdefs =
     1180        ((carsym *) bfd_alloc (abfd, c * sizeof (carsym)));
    11501181      if (bfd_ardata (abfd)->symdefs == NULL)
    1151         return false;
     1182        return FALSE;
    11521183
    11531184      /* After the count comes a list of four byte file offsets.  */
     
    11551186           i < c;
    11561187           ++i, ++arsym, p += 4)
    1157         arsym->file_offset = bfd_h_get_32 (abfd, p);
     1188        arsym->file_offset = H_GET_32 (abfd, p);
    11581189    }
    11591190  else
     
    11651196      if (off == 0)
    11661197        {
    1167           bfd_has_map (abfd) = false;
    1168           return true;
     1198          bfd_has_map (abfd) = FALSE;
     1199          return TRUE;
    11691200        }
    11701201
    11711202      if (bfd_seek (abfd, off, SEEK_SET) != 0)
    1172         return false;
     1203        return FALSE;
    11731204
    11741205      /* The symbol table starts with a normal archive header.  */
    1175       if (bfd_read ((PTR) &hdr, SIZEOF_AR_HDR_BIG, 1, abfd)
     1206      if (bfd_bread ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR_BIG, abfd)
    11761207          != SIZEOF_AR_HDR_BIG)
    1177         return false;
     1208        return FALSE;
    11781209
    11791210      /* Skip the name (normally empty).  */
    11801211      namlen = strtol (hdr.namlen, (char **) NULL, 10);
    1181       if (bfd_seek (abfd, ((namlen + 1) & ~1) + SXCOFFARFMAG, SEEK_CUR) != 0)
    1182         return false;
     1212      off = ((namlen + 1) & ~ (size_t) 1) + SXCOFFARFMAG;
     1213      if (bfd_seek (abfd, off, SEEK_CUR) != 0)
     1214        return FALSE;
    11831215
    11841216      /* XXX This actually has to be a call to strtoll (at least on 32-bit
     
    11901222      contents = (bfd_byte *) bfd_alloc (abfd, sz);
    11911223      if (contents == NULL)
    1192         return false;
    1193       if (bfd_read ((PTR) contents, 1, sz, abfd) != sz)
    1194         return false;
     1224        return FALSE;
     1225      if (bfd_bread ((PTR) contents, sz, abfd) != sz)
     1226        return FALSE;
    11951227
    11961228      /* The symbol table starts with an eight byte count.  */
    1197       c = bfd_h_get_64 (abfd, contents);
     1229      c = H_GET_64 (abfd, contents);
    11981230
    11991231      if (c * 8 >= sz)
    12001232        {
    12011233          bfd_set_error (bfd_error_bad_value);
    1202           return false;
     1234          return FALSE;
    12031235        }
    12041236
    1205       bfd_ardata (abfd)->symdefs = ((carsym *)
    1206                                     bfd_alloc (abfd, c * sizeof (carsym)));
     1237      bfd_ardata (abfd)->symdefs =
     1238        ((carsym *) bfd_alloc (abfd, c * sizeof (carsym)));
    12071239      if (bfd_ardata (abfd)->symdefs == NULL)
    1208         return false;
     1240        return FALSE;
    12091241
    12101242      /* After the count comes a list of eight byte file offsets.  */
     
    12121244           i < c;
    12131245           ++i, ++arsym, p += 8)
    1214         arsym->file_offset = bfd_h_get_64 (abfd, p);
     1246        arsym->file_offset = H_GET_64 (abfd, p);
    12151247    }
    12161248
     
    12241256        {
    12251257          bfd_set_error (bfd_error_bad_value);
    1226           return false;
     1258          return FALSE;
    12271259        }
    12281260      arsym->name = (char *) p;
     
    12301262
    12311263  bfd_ardata (abfd)->symdef_count = c;
    1232   bfd_has_map (abfd) = true;
    1233 
    1234   return true;
     1264  bfd_has_map (abfd) = TRUE;
     1265
     1266  return TRUE;
    12351267}
    12361268
     
    12411273     bfd *abfd;
    12421274{
     1275  struct artdata *tdata_hold;
    12431276  char magic[SXCOFFARMAG];
    1244 
    1245   if (bfd_read ((PTR) magic, SXCOFFARMAG, 1, abfd) != SXCOFFARMAG)
     1277  bfd_size_type amt = SXCOFFARMAG;
     1278
     1279  if (bfd_bread ((PTR) magic, amt, abfd) != amt)
    12461280    {
    12471281      if (bfd_get_error () != bfd_error_system_call)
     
    12571291    }
    12581292
    1259   /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
    1260      involves a cast, we can't do it as the left operand of
    1261      assignment.  */
    1262   abfd->tdata.aout_ar_data =
    1263     (struct artdata *) bfd_zalloc (abfd, sizeof (struct artdata));
    1264 
     1293  tdata_hold = bfd_ardata (abfd);
     1294
     1295  amt = sizeof (struct artdata);
     1296  bfd_ardata (abfd) = (struct artdata *) bfd_zalloc (abfd, amt);
    12651297  if (bfd_ardata (abfd) == (struct artdata *) NULL)
    1266     return NULL;
     1298    goto error_ret_restore;
    12671299
    12681300  bfd_ardata (abfd)->cache = NULL;
     
    12811313
    12821314      /* Now read the rest of the file header.  */
    1283       if (bfd_read ((PTR) &hdr.memoff, SIZEOF_AR_FILE_HDR - SXCOFFARMAG, 1,
    1284                     abfd) != SIZEOF_AR_FILE_HDR - SXCOFFARMAG)
     1315      amt = SIZEOF_AR_FILE_HDR - SXCOFFARMAG;
     1316      if (bfd_bread ((PTR) &hdr.memoff, amt, abfd) != amt)
    12851317        {
    12861318          if (bfd_get_error () != bfd_error_system_call)
    12871319            bfd_set_error (bfd_error_wrong_format);
    1288           return NULL;
     1320          goto error_ret;
    12891321        }
    12901322
     
    12921324                                                      (char **) NULL, 10);
    12931325
    1294       bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, SIZEOF_AR_FILE_HDR);
     1326      amt = SIZEOF_AR_FILE_HDR;
     1327      bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, amt);
    12951328      if (bfd_ardata (abfd)->tdata == NULL)
    1296         return NULL;
     1329        goto error_ret;
    12971330
    12981331      memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR);
     
    13071340
    13081341      /* Now read the rest of the file header.  */
    1309       if (bfd_read ((PTR) &hdr.memoff, SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG, 1,
    1310                     abfd) != SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG)
     1342      amt = SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG;
     1343      if (bfd_bread ((PTR) &hdr.memoff, amt, abfd) != amt)
    13111344        {
    13121345          if (bfd_get_error () != bfd_error_system_call)
    13131346            bfd_set_error (bfd_error_wrong_format);
    1314           return NULL;
     1347          goto error_ret;
    13151348        }
    13161349
    1317       /* XXX This actually has to be a call to strtoll (at least on 32-bit
    1318          machines) since the field width is 20 and there numbers with more
    1319          than 32 bits can be represented.  */
    1320       bfd_ardata (abfd)->first_file_filepos = strtol (hdr.firstmemoff,
    1321                                                       (char **) NULL, 10);
    1322 
    1323       bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, SIZEOF_AR_FILE_HDR_BIG);
     1350      bfd_ardata (abfd)->first_file_filepos = bfd_scan_vma (hdr.firstmemoff,
     1351                                                            (const char **) 0,
     1352                                                            10);
     1353
     1354      amt = SIZEOF_AR_FILE_HDR_BIG;
     1355      bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, amt);
    13241356      if (bfd_ardata (abfd)->tdata == NULL)
    1325         return NULL;
     1357        goto error_ret;
    13261358
    13271359      memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR_BIG);
     
    13301362  if (! _bfd_xcoff_slurp_armap (abfd))
    13311363    {
     1364    error_ret:
    13321365      bfd_release (abfd, bfd_ardata (abfd));
    1333       abfd->tdata.aout_ar_data = (struct artdata *) NULL;
     1366    error_ret_restore:
     1367      bfd_ardata (abfd) = tdata_hold;
    13341368      return NULL;
    13351369    }
     
    13441378     bfd *abfd;
    13451379{
    1346   size_t namlen;
     1380  bfd_size_type namlen;
    13471381  struct areltdata *ret;
    1348 
    1349   ret = (struct areltdata *) bfd_alloc (abfd, sizeof (struct areltdata));
     1382  bfd_size_type amt = sizeof (struct areltdata);
     1383
     1384  ret = (struct areltdata *) bfd_alloc (abfd, amt);
    13501385  if (ret == NULL)
    13511386    return NULL;
     
    13561391      struct xcoff_ar_hdr *hdrp;
    13571392
    1358       if (bfd_read ((PTR) &hdr, SIZEOF_AR_HDR, 1, abfd) != SIZEOF_AR_HDR)
     1393      if (bfd_bread ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
     1394          != SIZEOF_AR_HDR)
    13591395        {
    13601396          free (ret);
     
    13631399
    13641400      namlen = strtol (hdr.namlen, (char **) NULL, 10);
    1365       hdrp = (struct xcoff_ar_hdr *) bfd_alloc (abfd,
    1366                                                 SIZEOF_AR_HDR + namlen + 1);
     1401      amt = SIZEOF_AR_HDR + namlen + 1;
     1402      hdrp = (struct xcoff_ar_hdr *) bfd_alloc (abfd, amt);
    13671403      if (hdrp == NULL)
    13681404        {
     
    13711407        }
    13721408      memcpy (hdrp, &hdr, SIZEOF_AR_HDR);
    1373       if (bfd_read ((char *) hdrp + SIZEOF_AR_HDR, 1, namlen, abfd) != namlen)
     1409      if (bfd_bread ((char *) hdrp + SIZEOF_AR_HDR, namlen, abfd) != namlen)
    13741410        {
    13751411          free (ret);
     
    13871423      struct xcoff_ar_hdr_big *hdrp;
    13881424
    1389       if (bfd_read ((PTR) &hdr, SIZEOF_AR_HDR_BIG, 1, abfd)
     1425      if (bfd_bread ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR_BIG, abfd)
    13901426          != SIZEOF_AR_HDR_BIG)
    13911427        {
     
    13951431
    13961432      namlen = strtol (hdr.namlen, (char **) NULL, 10);
    1397       hdrp = (struct xcoff_ar_hdr_big *) bfd_alloc (abfd,
    1398                                                     SIZEOF_AR_HDR_BIG
    1399                                                     + namlen + 1);
     1433      amt = SIZEOF_AR_HDR_BIG + namlen + 1;
     1434      hdrp = (struct xcoff_ar_hdr_big *) bfd_alloc (abfd, amt);
    14001435      if (hdrp == NULL)
    14011436        {
     
    14041439        }
    14051440      memcpy (hdrp, &hdr, SIZEOF_AR_HDR_BIG);
    1406       if (bfd_read ((char *) hdrp + SIZEOF_AR_HDR_BIG, 1, namlen, abfd) != namlen)
     1441      if (bfd_bread ((char *) hdrp + SIZEOF_AR_HDR_BIG, namlen, abfd) != namlen)
    14071442        {
    14081443          free (ret);
     
    14201455
    14211456  /* Skip over the XCOFFARFMAG at the end of the file name.  */
    1422   if (bfd_seek (abfd, (namlen & 1) + SXCOFFARFMAG, SEEK_CUR) != 0)
     1457  if (bfd_seek (abfd, (file_ptr) ((namlen & 1) + SXCOFFARFMAG), SEEK_CUR) != 0)
    14231458    return NULL;
    14241459
     
    14901525
    14911526int
    1492 _bfd_xcoff_generic_stat_arch_elt (abfd, s)
     1527_bfd_xcoff_stat_arch_elt (abfd, s)
    14931528     bfd *abfd;
    14941529     struct stat *s;
     
    15001535    }
    15011536
    1502   if (! xcoff_big_format_p (abfd))
     1537  if (! xcoff_big_format_p (abfd->my_archive))
    15031538    {
    15041539      struct xcoff_ar_hdr *hdrp = arch_xhdr (abfd);
     
    15441579/* Write out an XCOFF armap.  */
    15451580
    1546 static boolean
     1581/*ARGSUSED*/
     1582static bfd_boolean
    15471583xcoff_write_armap_old (abfd, elength, map, orl_count, stridx)
    15481584     bfd *abfd;
     
    15621598  sprintf (hdr.size, "%ld", (long) (4 + orl_count * 4 + stridx));
    15631599  sprintf (hdr.nextoff, "%d", 0);
    1564   memcpy (hdr.prevoff, xcoff_ardata (abfd)->memoff, 12);
     1600  memcpy (hdr.prevoff, xcoff_ardata (abfd)->memoff, XCOFFARMAG_ELEMENT_SIZE);
    15651601  sprintf (hdr.date, "%d", 0);
    15661602  sprintf (hdr.uid, "%d", 0);
     
    15741610      *p = ' ';
    15751611
    1576   if (bfd_write ((PTR) &hdr, SIZEOF_AR_HDR, 1, abfd) != SIZEOF_AR_HDR
    1577       || bfd_write (XCOFFARFMAG, 1, SXCOFFARFMAG, abfd) != SXCOFFARFMAG)
    1578     return false;
    1579 
    1580   bfd_h_put_32 (abfd, orl_count, buf);
    1581   if (bfd_write (buf, 1, 4, abfd) != 4)
    1582     return false;
     1612  if (bfd_bwrite ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
     1613      != SIZEOF_AR_HDR
     1614      || (bfd_bwrite (XCOFFARFMAG, (bfd_size_type) SXCOFFARFMAG, abfd)
     1615          != SXCOFFARFMAG))
     1616    return FALSE;
     1617
     1618  H_PUT_32 (abfd, orl_count, buf);
     1619  if (bfd_bwrite (buf, (bfd_size_type) 4, abfd) != 4)
     1620    return FALSE;
    15831621
    15841622  sub = abfd->archive_head;
     
    15891627      size_t namlen;
    15901628
    1591       while (((bfd *) (map[i]).pos) == sub)
     1629      while (map[i].u.abfd == sub)
    15921630        {
    1593           bfd_h_put_32 (abfd, fileoff, buf);
    1594           if (bfd_write (buf, 1, 4, abfd) != 4)
    1595             return false;
     1631          H_PUT_32 (abfd, fileoff, buf);
     1632          if (bfd_bwrite (buf, (bfd_size_type) 4, abfd) != 4)
     1633            return FALSE;
    15961634          ++i;
    15971635        }
    15981636      namlen = strlen (normalize_filename (sub));
    1599       namlen = (namlen + 1) &~ 1;
     1637      namlen = (namlen + 1) &~ (size_t) 1;
    16001638      fileoff += (SIZEOF_AR_HDR
    16011639                  + namlen
     
    16131651      name = *map[i].name;
    16141652      namlen = strlen (name);
    1615       if (bfd_write (name, 1, namlen + 1, abfd) != namlen + 1)
    1616         return false;
     1653      if (bfd_bwrite (name, (bfd_size_type) (namlen + 1), abfd) != namlen + 1)
     1654        return FALSE;
    16171655    }
    16181656
     
    16221660
    16231661      b = '\0';
    1624       if (bfd_write (&b, 1, 1, abfd) != 1)
    1625         return false;
    1626     }
    1627 
    1628   return true;
    1629 }
    1630 
    1631 /* Write a single armap in the big format.  */
    1632 static boolean
    1633 xcoff_write_one_armap_big (abfd, map, orl_count, orl_ccount, stridx, bits64,
    1634                            prevoff, nextoff)
     1662      if (bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
     1663        return FALSE;
     1664    }
     1665
     1666  return TRUE;
     1667}
     1668
     1669static char buff20[XCOFFARMAGBIG_ELEMENT_SIZE + 1];
     1670#define FMT20  "%-20lld"
     1671#define FMT12  "%-12d"
     1672#define FMT12_OCTAL  "%-12o"
     1673#define FMT4  "%-4d"
     1674#define PRINT20(d, v) \
     1675  sprintf (buff20, FMT20, (long long)(v)), \
     1676  memcpy ((void *) (d), buff20, 20)
     1677
     1678#define PRINT12(d, v) \
     1679  sprintf (buff20, FMT12, (int)(v)), \
     1680  memcpy ((void *) (d), buff20, 12)
     1681
     1682#define PRINT12_OCTAL(d, v) \
     1683  sprintf (buff20, FMT12_OCTAL, (unsigned int)(v)), \
     1684  memcpy ((void *) (d), buff20, 12)
     1685
     1686#define PRINT4(d, v) \
     1687  sprintf (buff20, FMT4, (int)(v)), \
     1688  memcpy ((void *) (d), buff20, 4)
     1689
     1690#define READ20(d, v) \
     1691  buff20[20] = 0, \
     1692  memcpy (buff20, (d), 20), \
     1693  (v) = bfd_scan_vma (buff20, (const char **) NULL, 10)
     1694
     1695static bfd_boolean
     1696do_pad (abfd, number)
    16351697     bfd *abfd;
    1636      struct orl *map;
    1637      unsigned int orl_count;
    1638      unsigned int orl_ccount;
    1639      unsigned int stridx;
    1640      int bits64;
    1641      const char *prevoff;
    1642      char *nextoff;
    1643 {
    1644   struct xcoff_ar_hdr_big hdr;
    1645   char *p;
    1646   unsigned char buf[4];
    1647   const bfd_arch_info_type *arch_info = NULL;
    1648   bfd *sub;
    1649   file_ptr fileoff;
    1650   bfd *object_bfd;
    1651   unsigned int i;
    1652 
    1653   memset (&hdr, 0, sizeof hdr);
    1654   /* XXX This call actually should use %lld (at least on 32-bit
    1655      machines) since the fields's width is 20 and there numbers with
    1656      more than 32 bits can be represented.  */
    1657   sprintf (hdr.size, "%ld", (long) (4 + orl_ccount * 4 + stridx));
    1658   if (bits64)
    1659     sprintf (hdr.nextoff, "%d", 0);
    1660   else
    1661     sprintf (hdr.nextoff, "%ld", (strtol (prevoff, (char **) NULL, 10)
    1662                                  + 4 + orl_ccount * 4 + stridx));
    1663   memcpy (hdr.prevoff, prevoff, sizeof (hdr.prevoff));
    1664   sprintf (hdr.date, "%d", 0);
    1665   sprintf (hdr.uid, "%d", 0);
    1666   sprintf (hdr.gid, "%d", 0);
    1667   sprintf (hdr.mode, "%d", 0);
    1668   sprintf (hdr.namlen, "%d", 0);
    1669 
    1670   /* We need spaces, not null bytes, in the header.  */
    1671   for (p = (char *) &hdr; p < (char *) &hdr + SIZEOF_AR_HDR_BIG; p++)
    1672     if (*p == '\0')
    1673       *p = ' ';
    1674 
    1675   memcpy (nextoff, hdr.nextoff, sizeof (hdr.nextoff));
    1676 
    1677   if (bfd_write ((PTR) &hdr, SIZEOF_AR_HDR_BIG, 1, abfd) != SIZEOF_AR_HDR_BIG
    1678       || bfd_write (XCOFFARFMAG, 1, SXCOFFARFMAG, abfd) != SXCOFFARFMAG)
    1679     return false;
    1680 
    1681   bfd_h_put_32 (abfd, orl_ccount, buf);
    1682   if (bfd_write (buf, 1, 4, abfd) != 4)
    1683     return false;
    1684 
    1685   sub = abfd->archive_head;
    1686   fileoff = SIZEOF_AR_FILE_HDR_BIG;
    1687   i = 0;
    1688   while (sub != NULL && i < orl_count)
    1689     {
    1690       size_t namlen;
    1691 
    1692       if ((bfd_arch_bits_per_address ((bfd *) map[i].pos) == 64) == bits64)
    1693         while (((bfd *) (map[i]).pos) == sub)
    1694           {
    1695             bfd_h_put_32 (abfd, fileoff, buf);
    1696             if (bfd_write (buf, 1, 4, abfd) != 4)
    1697               return false;
    1698             i++;
    1699           }
    1700       else
    1701         while (((bfd *) (map[i]).pos) == sub)
    1702           i++;
    1703 
    1704       namlen = strlen (normalize_filename (sub));
    1705       namlen = (namlen + 1) &~ 1;
    1706       fileoff += (SIZEOF_AR_HDR_BIG
    1707                   + namlen
    1708                   + SXCOFFARFMAG
    1709                   + arelt_size (sub));
    1710       fileoff = (fileoff + 1) &~ 1;
    1711       sub = sub->next;
    1712     }
    1713 
    1714   object_bfd = NULL;
    1715   for (i = 0; i < orl_count; i++)
    1716     {
    1717       const char *name;
    1718       size_t namlen;
    1719       bfd *ob = (bfd *)map[i].pos;
    1720 
    1721       if (ob != object_bfd)
    1722         arch_info = bfd_get_arch_info (ob);
    1723 
    1724       if (arch_info && (arch_info->bits_per_address == 64) != bits64)
    1725         continue;
    1726 
    1727       name = *map[i].name;
    1728       namlen = strlen (name);
    1729       if (bfd_write (name, 1, namlen + 1, abfd) != namlen + 1)
    1730         return false;
    1731     }
    1732 
    1733   if ((stridx & 1) != 0)
    1734     {
    1735       char b;
    1736 
    1737       b = '\0';
    1738       if (bfd_write (&b, 1, 1, abfd) != 1)
    1739         return false;
    1740     }
    1741 
    1742   return true;
    1743 }
    1744 
    1745 static boolean
     1698     unsigned int number;
     1699{
     1700  bfd_byte b = 0;
     1701
     1702  /* Limit pad to <= 4096.  */
     1703  if (number > 4096)
     1704    return FALSE;
     1705
     1706  while (number--)
     1707    if (bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
     1708      return FALSE;
     1709
     1710  return TRUE;
     1711}
     1712
     1713static bfd_boolean
     1714do_copy (out_bfd, in_bfd)
     1715     bfd *out_bfd;
     1716     bfd *in_bfd;
     1717{
     1718  bfd_size_type remaining;
     1719  bfd_byte buffer[DEFAULT_BUFFERSIZE];
     1720
     1721  if (bfd_seek (in_bfd, (file_ptr) 0, SEEK_SET) != 0)
     1722    return FALSE;
     1723
     1724  remaining = arelt_size (in_bfd);
     1725
     1726  while (remaining >= DEFAULT_BUFFERSIZE)
     1727    {
     1728      if (bfd_bread (buffer, DEFAULT_BUFFERSIZE, in_bfd) != DEFAULT_BUFFERSIZE
     1729          || bfd_bwrite (buffer, DEFAULT_BUFFERSIZE, out_bfd) != DEFAULT_BUFFERSIZE)
     1730        return FALSE;
     1731
     1732      remaining -= DEFAULT_BUFFERSIZE;
     1733    }
     1734
     1735  if (remaining)
     1736    {
     1737      if (bfd_bread (buffer, remaining, in_bfd) != remaining
     1738          || bfd_bwrite (buffer, remaining, out_bfd) != remaining)
     1739        return FALSE;
     1740    }
     1741
     1742  return TRUE;
     1743}
     1744
     1745static bfd_boolean
     1746do_shared_object_padding (out_bfd, in_bfd, offset, ar_header_size)
     1747     bfd *out_bfd;
     1748     bfd *in_bfd;
     1749     ufile_ptr *offset;
     1750     int ar_header_size;
     1751{
     1752  if (bfd_check_format (in_bfd, bfd_object)
     1753      && bfd_get_flavour (in_bfd) == bfd_target_xcoff_flavour
     1754      && (in_bfd->flags & DYNAMIC) != 0)
     1755    {
     1756      bfd_size_type pad = 0;
     1757      int text_align_power;
     1758
     1759      text_align_power = bfd_xcoff_text_align_power (in_bfd);
     1760
     1761      pad = 1 << text_align_power;
     1762      pad -= (*offset + ar_header_size) & (pad - 1);
     1763
     1764      if (! do_pad (out_bfd, pad))
     1765        return FALSE;
     1766
     1767      *offset += pad;
     1768    }
     1769
     1770  return TRUE;
     1771}
     1772
     1773static bfd_boolean
    17461774xcoff_write_armap_big (abfd, elength, map, orl_count, stridx)
    17471775     bfd *abfd;
     
    17511779     int stridx;
    17521780{
    1753   unsigned int i;
    1754   unsigned int orl_count_32, orl_count_64;
    1755   unsigned int stridx_32, stridx_64;
     1781  struct xcoff_ar_file_hdr_big *fhdr;
     1782  bfd_vma i, sym_32, sym_64, str_32, str_64;
    17561783  const bfd_arch_info_type *arch_info = NULL;
    1757   bfd *object_bfd;
     1784  bfd *current_bfd;
     1785  size_t string_length;
     1786  ufile_ptr nextoff, prevoff;
    17581787
    17591788  /* First, we look through the symbols and work out which are
    17601789     from 32-bit objects and which from 64-bit ones.  */
    1761   orl_count_32 = 0;
    1762   orl_count_64 = 0;
    1763   stridx_32 = 0;
    1764   stridx_64 = 0;
    1765   object_bfd = NULL;
    1766   for (i = 0; i < orl_count; i++)
    1767     {
    1768       bfd *ob = (bfd *)map[i].pos;
    1769       unsigned int len;
    1770       if (ob != object_bfd)
    1771         arch_info = bfd_get_arch_info (ob);
    1772       len = strlen (*map[i].name) + 1;
    1773       if (arch_info && arch_info->bits_per_address == 64)
     1790  sym_32 = sym_64 = str_32 = str_64 = 0;
     1791
     1792  current_bfd = abfd->archive_head;
     1793  if (current_bfd != NULL)
     1794    arch_info = bfd_get_arch_info (current_bfd);
     1795    i = 0;
     1796    while (current_bfd != NULL && i < orl_count)
     1797    {
     1798      while (map[i].u.abfd == current_bfd)
    17741799        {
    1775           orl_count_64++;
    1776           stridx_64 += len;
     1800          string_length = strlen (*map[i].name) + 1;
     1801
     1802          if (arch_info->bits_per_address == 64)
     1803            {
     1804              sym_64++;
     1805              str_64 += string_length;
     1806            }
     1807          else
     1808            {
     1809              sym_32++;
     1810              str_32 += string_length;
     1811            }
     1812          i++;
    17771813        }
     1814      current_bfd = current_bfd->next;
     1815      if (current_bfd != NULL)
     1816        arch_info = bfd_get_arch_info (current_bfd);
     1817    }
     1818
     1819  /* A quick sanity check... */
     1820  BFD_ASSERT (sym_64 + sym_32 == orl_count);
     1821  /* Explicit cast to int for compiler.  */
     1822  BFD_ASSERT ((int)(str_64 + str_32) == stridx);
     1823
     1824  fhdr = xcoff_ardata_big (abfd);
     1825
     1826  /* xcoff_write_archive_contents_big passes nextoff in symoff. */
     1827  READ20 (fhdr->memoff, prevoff);
     1828  READ20 (fhdr->symoff, nextoff);
     1829
     1830  BFD_ASSERT (nextoff == bfd_tell (abfd));
     1831
     1832  /* Write out the symbol table.
     1833     Layout :
     1834
     1835     standard big archive header
     1836     0x0000                   ar_size   [0x14]
     1837     0x0014                   ar_nxtmem [0x14]
     1838     0x0028                   ar_prvmem [0x14]
     1839     0x003C                   ar_date   [0x0C]
     1840     0x0048                   ar_uid    [0x0C]
     1841     0x0054                   ar_gid    [0x0C]
     1842     0x0060                   ar_mod    [0x0C]
     1843     0x006C                   ar_namelen[0x04]
     1844     0x0070                   ar_fmag   [SXCOFFARFMAG]
     1845
     1846     Symbol table
     1847     0x0072                   num_syms  [0x08], binary
     1848     0x0078                   offsets   [0x08 * num_syms], binary
     1849     0x0086 + 0x08 * num_syms names     [??]
     1850     ??                       pad to even bytes.
     1851  */
     1852
     1853  if (sym_32)
     1854    {
     1855      struct xcoff_ar_hdr_big *hdr;
     1856      bfd_byte *symbol_table;
     1857      bfd_byte *st;
     1858      file_ptr fileoff;
     1859
     1860      bfd_vma symbol_table_size =
     1861        SIZEOF_AR_HDR_BIG
     1862        + SXCOFFARFMAG
     1863        + 8
     1864        + 8 * sym_32
     1865        + str_32 + (str_32 & 1);
     1866
     1867      symbol_table = NULL;
     1868      symbol_table = (bfd_byte *) bfd_zmalloc (symbol_table_size);
     1869      if (symbol_table == NULL)
     1870        return FALSE;
     1871
     1872      hdr = (struct xcoff_ar_hdr_big *) symbol_table;
     1873
     1874      PRINT20 (hdr->size, 8 + 8 * sym_32 + str_32 + (str_32 & 1));
     1875
     1876      if (sym_64)
     1877        PRINT20 (hdr->nextoff, nextoff + symbol_table_size);
    17781878      else
     1879        PRINT20 (hdr->nextoff, 0);
     1880
     1881      PRINT20 (hdr->prevoff, prevoff);
     1882      PRINT12 (hdr->date, 0);
     1883      PRINT12 (hdr->uid, 0);
     1884      PRINT12 (hdr->gid, 0);
     1885      PRINT12 (hdr->mode, 0);
     1886      PRINT4 (hdr->namlen, 0) ;
     1887
     1888      st = symbol_table + SIZEOF_AR_HDR_BIG;
     1889      memcpy (st, XCOFFARFMAG, SXCOFFARFMAG);
     1890      st += SXCOFFARFMAG;
     1891
     1892      bfd_h_put_64 (abfd, sym_32, st);
     1893      st += 8;
     1894
     1895      /* loop over the 32 bit offsets */
     1896      current_bfd = abfd->archive_head;
     1897      if (current_bfd != NULL)
     1898        arch_info = bfd_get_arch_info (current_bfd);
     1899      fileoff = SIZEOF_AR_FILE_HDR_BIG;
     1900      i = 0;
     1901      while (current_bfd != NULL && i < orl_count)
    17791902        {
    1780           orl_count_32++;
    1781           stridx_32 += len;
     1903          while (map[i].u.abfd == current_bfd)
     1904            {
     1905              if (arch_info->bits_per_address == 32)
     1906                {
     1907                  bfd_h_put_64 (abfd, fileoff, st);
     1908                  st += 8;
     1909                }
     1910              i++;
     1911            }
     1912          string_length = strlen (normalize_filename (current_bfd));
     1913          string_length += string_length & 1;
     1914          fileoff += (SIZEOF_AR_HDR_BIG
     1915                      + string_length
     1916                      + SXCOFFARFMAG
     1917                      + arelt_size (current_bfd));
     1918          fileoff += fileoff & 1;
     1919          current_bfd = current_bfd->next;
     1920          if (current_bfd != NULL)
     1921            arch_info = bfd_get_arch_info (current_bfd);
    17821922        }
    1783       object_bfd = ob;
    1784     }
    1785   /* A quick sanity check...  */
    1786   BFD_ASSERT (orl_count_64 + orl_count_32 == orl_count);
    1787   BFD_ASSERT (stridx_64 + stridx_32 == stridx);
    1788 
    1789   /* Now write out each map.  */
    1790   if (! xcoff_write_one_armap_big (abfd, map, orl_count, orl_count_32,
    1791                                    stridx_32, false,
    1792                                    xcoff_ardata_big (abfd)->memoff,
    1793                                    xcoff_ardata_big (abfd)->symoff))
    1794     return false;
    1795   if (! xcoff_write_one_armap_big (abfd, map, orl_count, orl_count_64,
    1796                                    stridx_64, true,
    1797                                    xcoff_ardata_big (abfd)->symoff,
    1798                                    xcoff_ardata_big (abfd)->symoff64))
    1799     return false;
    1800 
    1801   return true;
    1802 }
    1803 
    1804 boolean
     1923
     1924      /* loop over the 32 bit symbol names */
     1925      current_bfd = abfd->archive_head;
     1926      if (current_bfd != NULL)
     1927        arch_info = bfd_get_arch_info (current_bfd);
     1928      i = 0;
     1929      while (current_bfd != NULL && i < orl_count)
     1930        {
     1931          while (map[i].u.abfd == current_bfd)
     1932            {
     1933              if (arch_info->bits_per_address == 32)
     1934                {
     1935                  string_length = sprintf (st, "%s", *map[i].name);
     1936                  st += string_length + 1;
     1937                }
     1938              i++;
     1939            }
     1940          current_bfd = current_bfd->next;
     1941          if (current_bfd != NULL)
     1942            arch_info = bfd_get_arch_info (current_bfd);
     1943        }
     1944
     1945      bfd_bwrite (symbol_table, symbol_table_size, abfd);
     1946
     1947      free (symbol_table);
     1948      symbol_table = NULL;
     1949
     1950      prevoff = nextoff;
     1951      nextoff = nextoff + symbol_table_size;
     1952    }
     1953  else
     1954    PRINT20 (fhdr->symoff, 0);
     1955
     1956  if (sym_64)
     1957    {
     1958      struct xcoff_ar_hdr_big *hdr;
     1959      bfd_byte *symbol_table;
     1960      bfd_byte *st;
     1961      file_ptr fileoff;
     1962
     1963      bfd_vma symbol_table_size =
     1964        SIZEOF_AR_HDR_BIG
     1965        + SXCOFFARFMAG
     1966        + 8
     1967        + 8 * sym_64
     1968        + str_64 + (str_64 & 1);
     1969
     1970      symbol_table = NULL;
     1971      symbol_table = (bfd_byte *) bfd_zmalloc (symbol_table_size);
     1972      if (symbol_table == NULL)
     1973        return FALSE;
     1974
     1975      hdr = (struct xcoff_ar_hdr_big *) symbol_table;
     1976
     1977      PRINT20 (hdr->size, 8 + 8 * sym_64 + str_64 + (str_64 & 1));
     1978      PRINT20 (hdr->nextoff, 0);
     1979      PRINT20 (hdr->prevoff, prevoff);
     1980      PRINT12 (hdr->date, 0);
     1981      PRINT12 (hdr->uid, 0);
     1982      PRINT12 (hdr->gid, 0);
     1983      PRINT12 (hdr->mode, 0);
     1984      PRINT4 (hdr->namlen, 0);
     1985
     1986      st = symbol_table + SIZEOF_AR_HDR_BIG;
     1987      memcpy (st, XCOFFARFMAG, SXCOFFARFMAG);
     1988      st += SXCOFFARFMAG;
     1989
     1990      bfd_h_put_64 (abfd, sym_64, st);
     1991      st += 8;
     1992
     1993      /* loop over the 64 bit offsets */
     1994      current_bfd = abfd->archive_head;
     1995      if (current_bfd != NULL)
     1996        arch_info = bfd_get_arch_info (current_bfd);
     1997      fileoff = SIZEOF_AR_FILE_HDR_BIG;
     1998      i = 0;
     1999      while (current_bfd != NULL && i < orl_count)
     2000        {
     2001          while (map[i].u.abfd == current_bfd)
     2002            {
     2003              if (arch_info->bits_per_address == 64)
     2004                {
     2005                  bfd_h_put_64 (abfd, fileoff, st);
     2006                  st += 8;
     2007                }
     2008              i++;
     2009            }
     2010          string_length = strlen (normalize_filename (current_bfd));
     2011          string_length += string_length & 1;
     2012          fileoff += (SIZEOF_AR_HDR_BIG
     2013                      + string_length
     2014                      + SXCOFFARFMAG
     2015                      + arelt_size (current_bfd));
     2016          fileoff += fileoff & 1;
     2017          current_bfd = current_bfd->next;
     2018          if (current_bfd != NULL)
     2019            arch_info = bfd_get_arch_info (current_bfd);
     2020        }
     2021
     2022      /* loop over the 64 bit symbol names */
     2023      current_bfd = abfd->archive_head;
     2024      if (current_bfd != NULL)
     2025        arch_info = bfd_get_arch_info (current_bfd);
     2026      i = 0;
     2027      while (current_bfd != NULL && i < orl_count)
     2028        {
     2029          while (map[i].u.abfd == current_bfd)
     2030            {
     2031              if (arch_info->bits_per_address == 64)
     2032                {
     2033                  string_length = sprintf (st, "%s", *map[i].name);
     2034                  st += string_length + 1;
     2035                }
     2036              i++;
     2037            }
     2038          current_bfd = current_bfd->next;
     2039          if (current_bfd != NULL)
     2040            arch_info = bfd_get_arch_info (current_bfd);
     2041        }
     2042
     2043      bfd_bwrite (symbol_table, symbol_table_size, abfd);
     2044
     2045      free (symbol_table);
     2046      symbol_table = NULL;
     2047
     2048      PRINT20 (fhdr->symoff64, nextoff);
     2049    }
     2050  else
     2051    PRINT20 (fhdr->symoff64, 0);
     2052
     2053  return TRUE;
     2054}
     2055
     2056bfd_boolean
    18052057_bfd_xcoff_write_armap (abfd, elength, map, orl_count, stridx)
    18062058     bfd *abfd;
     
    18192071   rather than fussing with the freelist and so forth.  */
    18202072
    1821 static boolean
     2073static bfd_boolean
    18222074xcoff_write_archive_contents_old (abfd)
    18232075     bfd *abfd;
    18242076{
    18252077  struct xcoff_ar_file_hdr fhdr;
    1826   size_t count;
    1827   size_t total_namlen;
     2078  bfd_size_type count;
     2079  bfd_size_type total_namlen;
    18282080  file_ptr *offsets;
    1829   boolean makemap;
    1830   boolean hasobjects;
    1831   file_ptr prevoff, nextoff;
     2081  bfd_boolean makemap;
     2082  bfd_boolean hasobjects;
     2083  ufile_ptr prevoff, nextoff;
    18322084  bfd *sub;
    1833   unsigned int i;
     2085  size_t i;
    18342086  struct xcoff_ar_hdr ahdr;
    18352087  bfd_size_type size;
    18362088  char *p;
    1837   char decbuf[13];
     2089  char decbuf[XCOFFARMAG_ELEMENT_SIZE + 1];
    18382090
    18392091  memset (&fhdr, 0, sizeof fhdr);
     
    18512103  offsets = (file_ptr *) bfd_alloc (abfd, count * sizeof (file_ptr));
    18522104  if (offsets == NULL)
    1853     return false;
    1854 
    1855   if (bfd_seek (abfd, SIZEOF_AR_FILE_HDR, SEEK_SET) != 0)
    1856     return false;
     2105    return FALSE;
     2106
     2107  if (bfd_seek (abfd, (file_ptr) SIZEOF_AR_FILE_HDR, SEEK_SET) != 0)
     2108    return FALSE;
    18572109
    18582110  makemap = bfd_has_map (abfd);
    1859   hasobjects = false;
     2111  hasobjects = FALSE;
    18602112  prevoff = 0;
    18612113  nextoff = SIZEOF_AR_FILE_HDR;
     
    18632115    {
    18642116      const char *name;
    1865       size_t namlen;
     2117      bfd_size_type namlen;
    18662118      struct xcoff_ar_hdr *ahdrp;
    18672119      bfd_size_type remaining;
     
    18702122        {
    18712123          if (bfd_check_format (sub, bfd_object))
    1872             hasobjects = true;
     2124            hasobjects = TRUE;
    18732125        }
    18742126
     
    18902142            {
    18912143              bfd_set_error (bfd_error_system_call);
    1892               return false;
     2144              return FALSE;
    18932145            }
    18942146
     
    19012153          if (sub->arelt_data == NULL)
    19022154            {
    1903               sub->arelt_data = bfd_alloc (sub, sizeof (struct areltdata));
     2155              size = sizeof (struct areltdata);
     2156              sub->arelt_data = bfd_alloc (sub, size);
    19042157              if (sub->arelt_data == NULL)
    1905                 return false;
     2158                return FALSE;
    19062159            }
    19072160
     
    19132166
    19142167      /* If the length of the name is odd, we write out the null byte
    1915         after the name as well.  */
    1916       namlen = (namlen + 1) &~ 1;
     2168        after the name as well.  */
     2169      namlen = (namlen + 1) &~ (bfd_size_type) 1;
    19172170
    19182171      remaining = arelt_size (sub);
     
    19362189          *p = ' ';
    19372190
    1938       if (bfd_write ((PTR) ahdrp, 1, SIZEOF_AR_HDR, abfd) != SIZEOF_AR_HDR
    1939           || bfd_write ((PTR) name, 1, namlen, abfd) != namlen
    1940           || (bfd_write ((PTR) XCOFFARFMAG, 1, SXCOFFARFMAG, abfd)
    1941               != SXCOFFARFMAG))
    1942         return false;
     2191      if ((bfd_bwrite ((PTR) ahdrp, (bfd_size_type) SIZEOF_AR_HDR, abfd)
     2192           != SIZEOF_AR_HDR)
     2193          || bfd_bwrite ((PTR) name, namlen, abfd) != namlen
     2194          || bfd_bwrite ((PTR) XCOFFARFMAG, (bfd_size_type) SXCOFFARFMAG,
     2195                         abfd) != SXCOFFARFMAG)
     2196        return FALSE;
    19432197
    19442198      if (bfd_seek (sub, (file_ptr) 0, SEEK_SET) != 0)
    1945         return false;
    1946       while (remaining != 0)
    1947         {
    1948           bfd_size_type amt;
    1949           bfd_byte buffer[DEFAULT_BUFFERSIZE];
    1950 
    1951           amt = sizeof buffer;
    1952           if (amt > remaining)
    1953             amt = remaining;
    1954           if (bfd_read (buffer, 1, amt, sub) != amt
    1955               || bfd_write (buffer, 1, amt, abfd) != amt)
    1956             return false;
    1957           remaining -= amt;
    1958         }
    1959 
    1960       if ((size & 1) != 0)
    1961         {
    1962           bfd_byte b;
    1963 
    1964           b = '\0';
    1965           if (bfd_write (&b, 1, 1, abfd) != 1)
    1966             return false;
    1967         }
     2199        return FALSE;
     2200
     2201      if (! do_copy (abfd, sub))
     2202        return FALSE;
     2203
     2204      if (! do_pad (abfd, size & 1))
     2205        return FALSE;
    19682206    }
    19692207
     
    19762214
    19772215  memset (&ahdr, 0, sizeof ahdr);
    1978   sprintf (ahdr.size, "%ld", (long) (12 + count * 12 + total_namlen));
     2216  sprintf (ahdr.size, "%ld", (long) (XCOFFARMAG_ELEMENT_SIZE
     2217                                     + count * XCOFFARMAG_ELEMENT_SIZE
     2218                                     + total_namlen));
    19792219  sprintf (ahdr.prevoff, "%ld", (long) prevoff);
    19802220  sprintf (ahdr.date, "%d", 0);
     
    19852225
    19862226  size = (SIZEOF_AR_HDR
    1987           + 12
    1988           + count * 12
     2227          + XCOFFARMAG_ELEMENT_SIZE
     2228          + count * XCOFFARMAG_ELEMENT_SIZE
    19892229          + total_namlen
    19902230          + SXCOFFARFMAG);
     
    20032243      *p = ' ';
    20042244
    2005   if (bfd_write ((PTR) &ahdr, 1, SIZEOF_AR_HDR, abfd) != SIZEOF_AR_HDR
    2006       || (bfd_write ((PTR) XCOFFARFMAG, 1, SXCOFFARFMAG, abfd)
     2245  if ((bfd_bwrite ((PTR) &ahdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
     2246       != SIZEOF_AR_HDR)
     2247      || (bfd_bwrite ((PTR) XCOFFARFMAG, (bfd_size_type) SXCOFFARFMAG, abfd)
    20072248          != SXCOFFARFMAG))
    2008     return false;
     2249    return FALSE;
    20092250
    20102251  sprintf (decbuf, "%-12ld", (long) count);
    2011   if (bfd_write ((PTR) decbuf, 1, 12, abfd) != 12)
    2012     return false;
    2013   for (i = 0; i < count; i++)
     2252  if (bfd_bwrite ((PTR) decbuf, (bfd_size_type) XCOFFARMAG_ELEMENT_SIZE, abfd)
     2253      != XCOFFARMAG_ELEMENT_SIZE)
     2254    return FALSE;
     2255  for (i = 0; i < (size_t) count; i++)
    20142256    {
    20152257      sprintf (decbuf, "%-12ld", (long) offsets[i]);
    2016       if (bfd_write ((PTR) decbuf, 1, 12, abfd) != 12)
    2017         return false;
     2258      if (bfd_bwrite ((PTR) decbuf, (bfd_size_type) XCOFFARMAG_ELEMENT_SIZE,
     2259                      abfd) != XCOFFARMAG_ELEMENT_SIZE)
     2260        return FALSE;
    20182261    }
    20192262  for (sub = abfd->archive_head; sub != NULL; sub = sub->next)
    20202263    {
    20212264      const char *name;
    2022       size_t namlen;
     2265      bfd_size_type namlen;
    20232266
    20242267      name = normalize_filename (sub);
    20252268      namlen = strlen (name);
    2026       if (bfd_write ((PTR) name, 1, namlen + 1, abfd) != namlen + 1)
    2027         return false;
    2028     }
    2029   if ((size & 1) != 0)
    2030     {
    2031       bfd_byte b;
    2032 
    2033       b = '\0';
    2034       if (bfd_write ((PTR) &b, 1, 1, abfd) != 1)
    2035         return false;
    2036     }
     2269      if (bfd_bwrite ((PTR) name, namlen + 1, abfd) != namlen + 1)
     2270        return FALSE;
     2271    }
     2272
     2273  if (! do_pad (abfd, size & 1))
     2274    return FALSE;
    20372275
    20382276  /* Write out the armap, if appropriate.  */
    2039 
    20402277  if (! makemap || ! hasobjects)
    20412278    sprintf (fhdr.symoff, "%d", 0);
     
    20462283      bfd_ardata (abfd)->tdata = (PTR) &fhdr;
    20472284      if (! _bfd_compute_and_write_armap (abfd, 0))
    2048         return false;
     2285        return FALSE;
    20492286    }
    20502287
     
    20572294
    20582295  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
    2059       || (bfd_write ((PTR) &fhdr, SIZEOF_AR_FILE_HDR, 1, abfd) !=
    2060           SIZEOF_AR_FILE_HDR))
    2061     return false;
    2062 
    2063   return true;
    2064 }
    2065 
    2066 static boolean
     2296      || (bfd_bwrite ((PTR) &fhdr, (bfd_size_type) SIZEOF_AR_FILE_HDR, abfd)
     2297          != SIZEOF_AR_FILE_HDR))
     2298    return FALSE;
     2299
     2300  return TRUE;
     2301}
     2302
     2303static bfd_boolean
    20672304xcoff_write_archive_contents_big (abfd)
    20682305     bfd *abfd;
    20692306{
    20702307  struct xcoff_ar_file_hdr_big fhdr;
    2071   size_t count;
    2072   size_t total_namlen;
     2308  bfd_size_type count;
     2309  bfd_size_type total_namlen;
    20732310  file_ptr *offsets;
    2074   boolean makemap;
    2075   boolean hasobjects;
    2076   file_ptr prevoff, nextoff;
    2077   bfd *sub;
    2078   unsigned int i;
    2079   struct xcoff_ar_hdr_big ahdr;
     2311  bfd_boolean makemap;
     2312  bfd_boolean hasobjects;
     2313  ufile_ptr prevoff, nextoff;
     2314  bfd *current_bfd;
     2315  size_t i;
     2316  struct xcoff_ar_hdr_big *hdr, ahdr;
    20802317  bfd_size_type size;
    2081   char *p;
    2082   char decbuf[13];
    2083 
    2084   memset (&fhdr, 0, sizeof fhdr);
    2085   strncpy (fhdr.magic, XCOFFARMAGBIG, SXCOFFARMAG);
    2086   sprintf (fhdr.firstmemoff, "%d", SIZEOF_AR_FILE_HDR_BIG);
    2087   sprintf (fhdr.freeoff, "%d", 0);
    2088 
    2089   count = 0;
    2090   total_namlen = 0;
    2091   for (sub = abfd->archive_head; sub != NULL; sub = sub->next)
    2092     {
    2093       ++count;
    2094       total_namlen += strlen (normalize_filename (sub)) + 1;
    2095     }
    2096   offsets = (file_ptr *) bfd_alloc (abfd, count * sizeof (file_ptr));
    2097   if (offsets == NULL)
    2098     return false;
    2099 
    2100   if (bfd_seek (abfd, SIZEOF_AR_FILE_HDR_BIG, SEEK_SET) != 0)
    2101     return false;
    2102 
     2318  bfd_byte *member_table, *mt;
     2319  bfd_vma member_table_size;
     2320
     2321  memset (&fhdr, 0, SIZEOF_AR_FILE_HDR_BIG);
     2322  memcpy (fhdr.magic, XCOFFARMAGBIG, SXCOFFARMAG);
     2323
     2324  if (bfd_seek (abfd, (file_ptr) SIZEOF_AR_FILE_HDR_BIG, SEEK_SET) != 0)
     2325    return FALSE;
     2326
     2327  /* Calculate count and total_namlen.  */
    21032328  makemap = bfd_has_map (abfd);
    2104   hasobjects = false;
     2329  hasobjects = FALSE;
     2330  for (current_bfd = abfd->archive_head, count = 0, total_namlen = 0;
     2331       current_bfd != NULL;
     2332       current_bfd = current_bfd->next, count++)
     2333    {
     2334      total_namlen += strlen (normalize_filename (current_bfd)) + 1;
     2335
     2336      if (makemap
     2337          && ! hasobjects
     2338          && bfd_check_format (current_bfd, bfd_object))
     2339        hasobjects = TRUE;
     2340    }
     2341
     2342  offsets = NULL;
     2343  if (count)
     2344    {
     2345      offsets = (file_ptr *) bfd_malloc (count * sizeof (file_ptr));
     2346      if (offsets == NULL)
     2347        return FALSE;
     2348    }
     2349
    21052350  prevoff = 0;
    21062351  nextoff = SIZEOF_AR_FILE_HDR_BIG;
    2107   for (sub = abfd->archive_head, i = 0; sub != NULL; sub = sub->next, i++)
     2352  for (current_bfd = abfd->archive_head, i = 0;
     2353       current_bfd != NULL;
     2354       current_bfd = current_bfd->next, i++)
    21082355    {
    21092356      const char *name;
    2110       size_t namlen;
     2357      bfd_size_type namlen;
    21112358      struct xcoff_ar_hdr_big *ahdrp;
    21122359      bfd_size_type remaining;
    21132360
    2114       if (makemap && ! hasobjects)
    2115         {
    2116           if (bfd_check_format (sub, bfd_object))
    2117             hasobjects = true;
    2118         }
    2119 
    2120       name = normalize_filename (sub);
     2361      name = normalize_filename (current_bfd);
    21212362      namlen = strlen (name);
    21222363
    2123       if (sub->arelt_data != NULL)
    2124         ahdrp = arch_xhdr_big (sub);
     2364      if (current_bfd->arelt_data != NULL)
     2365        ahdrp = arch_xhdr_big (current_bfd);
    21252366      else
    21262367        ahdrp = NULL;
     
    21302371          struct stat s;
    21312372
    2132           memset (&ahdr, 0, sizeof ahdr);
    21332373          ahdrp = &ahdr;
    21342374          /* XXX This should actually be a call to stat64 (at least on
    2135              32-bit machines).  */
    2136           if (stat (bfd_get_filename (sub), &s) != 0)
     2375             32-bit machines).
     2376             XXX This call will fail if the original object is not found.  */
     2377          if (stat (bfd_get_filename (current_bfd), &s) != 0)
    21372378            {
    21382379              bfd_set_error (bfd_error_system_call);
    2139               return false;
     2380              return FALSE;
    21402381            }
    21412382
    2142           /* XXX This call actually should use %lld (at least on 32-bit
    2143              machines) since the fields's width is 20 and there numbers with
    2144              more than 32 bits can be represented.  */
    2145           sprintf (ahdrp->size, "%ld", (long) s.st_size);
    2146           sprintf (ahdrp->date, "%ld", (long) s.st_mtime);
    2147           sprintf (ahdrp->uid, "%ld", (long) s.st_uid);
    2148           sprintf (ahdrp->gid, "%ld", (long) s.st_gid);
    2149           sprintf (ahdrp->mode, "%o", (unsigned int) s.st_mode);
    2150 
    2151           if (sub->arelt_data == NULL)
     2383          PRINT20 (ahdrp->size, s.st_size);
     2384          PRINT12 (ahdrp->date, s.st_mtime);
     2385          PRINT12 (ahdrp->uid,  s.st_uid);
     2386          PRINT12 (ahdrp->gid,  s.st_gid);
     2387          PRINT12_OCTAL (ahdrp->mode, s.st_mode);
     2388
     2389          if (current_bfd->arelt_data == NULL)
    21522390            {
    2153               sub->arelt_data = bfd_alloc (sub, sizeof (struct areltdata));
    2154               if (sub->arelt_data == NULL)
    2155                 return false;
     2391              size = sizeof (struct areltdata);
     2392              current_bfd->arelt_data = bfd_alloc (current_bfd, size);
     2393              if (current_bfd->arelt_data == NULL)
     2394                return FALSE;
    21562395            }
    21572396
    2158           arch_eltdata (sub)->parsed_size = s.st_size;
     2397          arch_eltdata (current_bfd)->parsed_size = s.st_size;
    21592398        }
    21602399
    2161       /* XXX These calls actually should use %lld (at least on 32-bit
    2162          machines) since the fields's width is 20 and there numbers with
    2163          more than 32 bits can be represented.  */
    2164       sprintf (ahdrp->prevoff, "%ld", (long) prevoff);
    2165       sprintf (ahdrp->namlen, "%ld", (long) namlen);
     2400      PRINT20 (ahdrp->prevoff, prevoff);
     2401      PRINT4 (ahdrp->namlen, namlen);
    21662402
    21672403      /* If the length of the name is odd, we write out the null byte
    2168         after the name as well.  */
    2169       namlen = (namlen + 1) &~ 1;
    2170 
    2171       remaining = arelt_size (sub);
     2404        after the name as well.  */
     2405      namlen = (namlen + 1) &~ (bfd_size_type) 1;
     2406
     2407      remaining = arelt_size (current_bfd);
    21722408      size = (SIZEOF_AR_HDR_BIG
    21732409              + namlen
     
    21772413      BFD_ASSERT (nextoff == bfd_tell (abfd));
    21782414
     2415      /* Check for xcoff shared objects.
     2416         Their text section needs to be aligned wrt the archive file position.
     2417         This requires extra padding before the archive header.  */
     2418      if (! do_shared_object_padding (abfd, current_bfd, & nextoff,
     2419                                      SIZEOF_AR_HDR_BIG + namlen
     2420                                      + SXCOFFARFMAG))
     2421        return FALSE;
     2422
    21792423      offsets[i] = nextoff;
    21802424
     
    21822426      nextoff += size + (size & 1);
    21832427
    2184       sprintf (ahdrp->nextoff, "%ld", (long) nextoff);
    2185 
    2186       /* We need spaces, not null bytes, in the header.  */
    2187       for (p = (char *) ahdrp; p < (char *) ahdrp + SIZEOF_AR_HDR_BIG; p++)
    2188         if (*p == '\0')
    2189           *p = ' ';
    2190 
    2191       if (bfd_write ((PTR) ahdrp, 1, SIZEOF_AR_HDR_BIG, abfd)
    2192           != SIZEOF_AR_HDR_BIG
    2193           || bfd_write ((PTR) name, 1, namlen, abfd) != namlen
    2194           || (bfd_write ((PTR) XCOFFARFMAG, 1, SXCOFFARFMAG, abfd)
    2195               != SXCOFFARFMAG))
    2196         return false;
    2197 
    2198       if (bfd_seek (sub, (file_ptr) 0, SEEK_SET) != 0)
    2199         return false;
    2200       while (remaining != 0)
    2201         {
    2202           bfd_size_type amt;
    2203           bfd_byte buffer[DEFAULT_BUFFERSIZE];
    2204 
    2205           amt = sizeof buffer;
    2206           if (amt > remaining)
    2207             amt = remaining;
    2208           if (bfd_read (buffer, 1, amt, sub) != amt
    2209               || bfd_write (buffer, 1, amt, abfd) != amt)
    2210             return false;
    2211           remaining -= amt;
    2212         }
    2213 
    2214       if ((size & 1) != 0)
    2215         {
    2216           bfd_byte b;
    2217 
    2218           b = '\0';
    2219           if (bfd_write (&b, 1, 1, abfd) != 1)
    2220             return false;
    2221         }
    2222     }
    2223 
    2224   /* XXX This call actually should use %lld (at least on 32-bit
    2225      machines) since the fields's width is 20 and there numbers with
    2226      more than 32 bits can be represented.  */
    2227   sprintf (fhdr.lastmemoff, "%ld", (long) prevoff);
    2228 
    2229   /* Write out the member table.  */
     2428      PRINT20 (ahdrp->nextoff, nextoff);
     2429
     2430      if ((bfd_bwrite ((PTR) ahdrp, (bfd_size_type) SIZEOF_AR_HDR_BIG, abfd)
     2431           != SIZEOF_AR_HDR_BIG)
     2432          || bfd_bwrite ((PTR) name, (bfd_size_type) namlen, abfd) != namlen
     2433          || (bfd_bwrite ((PTR) XCOFFARFMAG, (bfd_size_type) SXCOFFARFMAG,
     2434                          abfd) != SXCOFFARFMAG))
     2435        return FALSE;
     2436
     2437      if (bfd_seek (current_bfd, (file_ptr) 0, SEEK_SET) != 0)
     2438        return FALSE;
     2439
     2440      if (! do_copy (abfd, current_bfd))
     2441        return FALSE;
     2442
     2443      if (! do_pad (abfd, size & 1))
     2444        return FALSE;
     2445    }
     2446
     2447  if (count)
     2448    {
     2449      PRINT20 (fhdr.firstmemoff, offsets[0]);
     2450      PRINT20 (fhdr.lastmemoff, prevoff);
     2451    }
     2452
     2453  /* Write out the member table.
     2454     Layout :
     2455
     2456     standard big archive header
     2457     0x0000                   ar_size   [0x14]
     2458     0x0014                   ar_nxtmem [0x14]
     2459     0x0028                   ar_prvmem [0x14]
     2460     0x003C                   ar_date   [0x0C]
     2461     0x0048                   ar_uid    [0x0C]
     2462     0x0054                   ar_gid    [0x0C]
     2463     0x0060                   ar_mod    [0x0C]
     2464     0x006C                   ar_namelen[0x04]
     2465     0x0070                   ar_fmag   [0x02]
     2466
     2467     Member table
     2468     0x0072                   count     [0x14]
     2469     0x0086                   offsets   [0x14 * counts]
     2470     0x0086 + 0x14 * counts   names     [??]
     2471     ??                       pad to even bytes.
     2472   */
    22302473
    22312474  BFD_ASSERT (nextoff == bfd_tell (abfd));
    2232   /* XXX This call actually should use %lld (at least on 32-bit
    2233      machines) since the fields's width is 20 and there numbers with
    2234      more than 32 bits can be represented.  */
    2235   sprintf (fhdr.memoff, "%ld", (long) nextoff);
    2236 
    2237   memset (&ahdr, 0, sizeof ahdr);
    2238   /* XXX The next two calls actually should use %lld (at least on 32-bit
    2239      machines) since the fields's width is 20 and there numbers with
    2240      more than 32 bits can be represented.  */
    2241   sprintf (ahdr.size, "%ld", (long) (12 + count * 12 + total_namlen));
    2242   sprintf (ahdr.prevoff, "%ld", (long) prevoff);
    2243   sprintf (ahdr.date, "%d", 0);
    2244   sprintf (ahdr.uid, "%d", 0);
    2245   sprintf (ahdr.gid, "%d", 0);
    2246   sprintf (ahdr.mode, "%d", 0);
    2247   sprintf (ahdr.namlen, "%d", 0);
    2248 
    2249   size = (SIZEOF_AR_HDR_BIG
    2250           + 12
    2251           + count * 12
    2252           + total_namlen
    2253           + SXCOFFARFMAG);
    2254 
    2255   prevoff = nextoff;
    2256   nextoff += size + (size & 1);
    2257 
     2475
     2476  member_table_size = (SIZEOF_AR_HDR_BIG
     2477                       + SXCOFFARFMAG
     2478                       + XCOFFARMAGBIG_ELEMENT_SIZE
     2479                       + count * XCOFFARMAGBIG_ELEMENT_SIZE
     2480                       + total_namlen);
     2481
     2482  member_table_size += member_table_size & 1;
     2483  member_table = NULL;
     2484  member_table = (bfd_byte *) bfd_zmalloc (member_table_size);
     2485  if (member_table == NULL)
     2486    return FALSE;
     2487
     2488  hdr = (struct xcoff_ar_hdr_big *) member_table;
     2489
     2490  PRINT20 (hdr->size, (XCOFFARMAGBIG_ELEMENT_SIZE
     2491                       + count * XCOFFARMAGBIG_ELEMENT_SIZE
     2492                       + total_namlen + (total_namlen & 1)));
    22582493  if (makemap && hasobjects)
    2259     /* XXX This call actually should use %lld (at least on 32-bit
    2260        machines) since the fields's width is 20 and there numbers with
    2261        more than 32 bits can be represented.  */
    2262     sprintf (ahdr.nextoff, "%ld", (long) nextoff);
     2494    PRINT20 (hdr->nextoff, nextoff + member_table_size);
    22632495  else
    2264     sprintf (ahdr.nextoff, "%d", 0);
    2265 
    2266   /* We need spaces, not null bytes, in the header.  */
    2267   for (p = (char *) &ahdr; p < (char *) &ahdr + SIZEOF_AR_HDR_BIG; p++)
    2268     if (*p == '\0')
    2269       *p = ' ';
    2270 
    2271   if (bfd_write ((PTR) &ahdr, 1, SIZEOF_AR_HDR_BIG, abfd) != SIZEOF_AR_HDR_BIG
    2272       || (bfd_write ((PTR) XCOFFARFMAG, 1, SXCOFFARFMAG, abfd)
    2273           != SXCOFFARFMAG))
    2274     return false;
    2275 
    2276   sprintf (decbuf, "%-12ld", (long) count);
    2277   if (bfd_write ((PTR) decbuf, 1, 12, abfd) != 12)
    2278     return false;
    2279   for (i = 0; i < count; i++)
    2280     {
    2281       sprintf (decbuf, "%-12ld", (long) offsets[i]);
    2282       if (bfd_write ((PTR) decbuf, 1, 12, abfd) != 12)
    2283         return false;
    2284     }
    2285   for (sub = abfd->archive_head; sub != NULL; sub = sub->next)
     2496    PRINT20 (hdr->nextoff, 0);
     2497  PRINT20 (hdr->prevoff, prevoff);
     2498  PRINT12 (hdr->date, 0);
     2499  PRINT12 (hdr->uid, 0);
     2500  PRINT12 (hdr->gid, 0);
     2501  PRINT12 (hdr->mode, 0);
     2502  PRINT4 (hdr->namlen, 0);
     2503
     2504  mt = member_table + SIZEOF_AR_HDR_BIG;
     2505  memcpy (mt, XCOFFARFMAG, SXCOFFARFMAG);
     2506  mt += SXCOFFARFMAG;
     2507
     2508  PRINT20 (mt, count);
     2509  mt += XCOFFARMAGBIG_ELEMENT_SIZE;
     2510  for (i = 0; i < (size_t) count; i++)
     2511    {
     2512      PRINT20 (mt, offsets[i]);
     2513      mt += XCOFFARMAGBIG_ELEMENT_SIZE;
     2514    }
     2515
     2516  if (count)
     2517    {
     2518      free (offsets);
     2519      offsets = NULL;
     2520    }
     2521
     2522  for (current_bfd = abfd->archive_head; current_bfd != NULL;
     2523       current_bfd = current_bfd->next)
    22862524    {
    22872525      const char *name;
    22882526      size_t namlen;
    22892527
    2290       name = normalize_filename (sub);
    2291       namlen = strlen (name);
    2292       if (bfd_write ((PTR) name, 1, namlen + 1, abfd) != namlen + 1)
    2293         return false;
    2294     }
    2295   if ((size & 1) != 0)
    2296     {
    2297       bfd_byte b;
    2298 
    2299       b = '\0';
    2300       if (bfd_write ((PTR) &b, 1, 1, abfd) != 1)
    2301         return false;
    2302     }
     2528      name = normalize_filename (current_bfd);
     2529      namlen = sprintf (mt, "%s", name);
     2530      mt += namlen + 1;
     2531    }
     2532
     2533  if (bfd_bwrite (member_table, member_table_size, abfd) != member_table_size)
     2534    return FALSE;
     2535
     2536  free (member_table);
     2537  member_table = NULL;
     2538
     2539  PRINT20 (fhdr.memoff, nextoff);
     2540
     2541  prevoff = nextoff;
     2542  nextoff += member_table_size;
    23032543
    23042544  /* Write out the armap, if appropriate.  */
    23052545
    23062546  if (! makemap || ! hasobjects)
    2307     sprintf (fhdr.symoff, "%d", 0);
     2547    PRINT20 (fhdr.symoff, 0);
    23082548  else
    23092549    {
    23102550      BFD_ASSERT (nextoff == bfd_tell (abfd));
    2311       /* XXX This call actually should use %lld (at least on 32-bit
    2312          machines) since the fields's width is 20 and there numbers with
    2313          more than 32 bits can be represented.  */
     2551
     2552      /* Save nextoff in fhdr.symoff so the armap routine can use it.  */
     2553      PRINT20 (fhdr.symoff, nextoff);
     2554
    23142555      bfd_ardata (abfd)->tdata = (PTR) &fhdr;
    23152556      if (! _bfd_compute_and_write_armap (abfd, 0))
    2316         return false;
     2557        return FALSE;
    23172558    }
    23182559
    23192560  /* Write out the archive file header.  */
    23202561
    2321   /* We need spaces, not null bytes, in the header.  */
    2322   for (p = (char *) &fhdr; p < (char *) &fhdr + SIZEOF_AR_FILE_HDR_BIG; p++)
    2323     if (*p == '\0')
    2324       *p = ' ';
    2325 
    23262562  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
    2327       || (bfd_write ((PTR) &fhdr, SIZEOF_AR_FILE_HDR_BIG, 1, abfd) !=
    2328           SIZEOF_AR_FILE_HDR_BIG))
    2329     return false;
    2330 
    2331   return true;
    2332 }
    2333 
    2334 boolean
     2563      || (bfd_bwrite ((PTR) &fhdr, (bfd_size_type) SIZEOF_AR_FILE_HDR_BIG,
     2564                      abfd) != SIZEOF_AR_FILE_HDR_BIG))
     2565    return FALSE;
     2566
     2567  return TRUE;
     2568}
     2569
     2570bfd_boolean
    23352571_bfd_xcoff_write_archive_contents (abfd)
    23362572     bfd *abfd;
     
    23492585_bfd_xcoff_sizeof_headers (abfd, reloc)
    23502586     bfd *abfd;
    2351      boolean reloc ATTRIBUTE_UNUSED;
     2587     bfd_boolean reloc ATTRIBUTE_UNUSED;
    23522588{
    23532589  int size;
     
    23612597  return size;
    23622598}
     2599
     2600
     2601/* Routines to swap information in the XCOFF .loader section.  If we
     2602   ever need to write an XCOFF loader, this stuff will need to be
     2603   moved to another file shared by the linker (which XCOFF calls the
     2604   ``binder'') and the loader.  */
     2605
     2606/* Swap in the ldhdr structure.  */
     2607
     2608static void
     2609xcoff_swap_ldhdr_in (abfd, s, dst)
     2610     bfd *abfd;
     2611     const PTR s;
     2612     struct internal_ldhdr *dst;
     2613{
     2614  const struct external_ldhdr *src = (const struct external_ldhdr *) s;
     2615
     2616  dst->l_version = bfd_get_32 (abfd, src->l_version);
     2617  dst->l_nsyms = bfd_get_32 (abfd, src->l_nsyms);
     2618  dst->l_nreloc = bfd_get_32 (abfd, src->l_nreloc);
     2619  dst->l_istlen = bfd_get_32 (abfd, src->l_istlen);
     2620  dst->l_nimpid = bfd_get_32 (abfd, src->l_nimpid);
     2621  dst->l_impoff = bfd_get_32 (abfd, src->l_impoff);
     2622  dst->l_stlen = bfd_get_32 (abfd, src->l_stlen);
     2623  dst->l_stoff = bfd_get_32 (abfd, src->l_stoff);
     2624}
     2625
     2626/* Swap out the ldhdr structure.  */
     2627
     2628static void
     2629xcoff_swap_ldhdr_out (abfd, src, d)
     2630     bfd *abfd;
     2631     const struct internal_ldhdr *src;
     2632     PTR d;
     2633{
     2634  struct external_ldhdr *dst = (struct external_ldhdr *) d;
     2635
     2636  bfd_put_32 (abfd, (bfd_vma) src->l_version, dst->l_version);
     2637  bfd_put_32 (abfd, src->l_nsyms, dst->l_nsyms);
     2638  bfd_put_32 (abfd, src->l_nreloc, dst->l_nreloc);
     2639  bfd_put_32 (abfd, src->l_istlen, dst->l_istlen);
     2640  bfd_put_32 (abfd, src->l_nimpid, dst->l_nimpid);
     2641  bfd_put_32 (abfd, src->l_impoff, dst->l_impoff);
     2642  bfd_put_32 (abfd, src->l_stlen, dst->l_stlen);
     2643  bfd_put_32 (abfd, src->l_stoff, dst->l_stoff);
     2644}
     2645
     2646/* Swap in the ldsym structure.  */
     2647
     2648static void
     2649xcoff_swap_ldsym_in (abfd, s, dst)
     2650     bfd *abfd;
     2651     const PTR s;
     2652     struct internal_ldsym *dst;
     2653{
     2654  const struct external_ldsym *src = (const struct external_ldsym *) s;
     2655
     2656  if (bfd_get_32 (abfd, src->_l._l_l._l_zeroes) != 0) {
     2657    memcpy (dst->_l._l_name, src->_l._l_name, SYMNMLEN);
     2658  } else {
     2659    dst->_l._l_l._l_zeroes = 0;
     2660    dst->_l._l_l._l_offset = bfd_get_32 (abfd, src->_l._l_l._l_offset);
     2661  }
     2662  dst->l_value = bfd_get_32 (abfd, src->l_value);
     2663  dst->l_scnum = bfd_get_16 (abfd, src->l_scnum);
     2664  dst->l_smtype = bfd_get_8 (abfd, src->l_smtype);
     2665  dst->l_smclas = bfd_get_8 (abfd, src->l_smclas);
     2666  dst->l_ifile = bfd_get_32 (abfd, src->l_ifile);
     2667  dst->l_parm = bfd_get_32 (abfd, src->l_parm);
     2668}
     2669
     2670/* Swap out the ldsym structure.  */
     2671
     2672static void
     2673xcoff_swap_ldsym_out (abfd, src, d)
     2674     bfd *abfd;
     2675     const struct internal_ldsym *src;
     2676     PTR d;
     2677{
     2678  struct external_ldsym *dst = (struct external_ldsym *) d;
     2679
     2680  if (src->_l._l_l._l_zeroes != 0)
     2681    memcpy (dst->_l._l_name, src->_l._l_name, SYMNMLEN);
     2682  else
     2683    {
     2684      bfd_put_32 (abfd, (bfd_vma) 0, dst->_l._l_l._l_zeroes);
     2685      bfd_put_32 (abfd, (bfd_vma) src->_l._l_l._l_offset,
     2686                  dst->_l._l_l._l_offset);
     2687    }
     2688  bfd_put_32 (abfd, src->l_value, dst->l_value);
     2689  bfd_put_16 (abfd, (bfd_vma) src->l_scnum, dst->l_scnum);
     2690  bfd_put_8 (abfd, src->l_smtype, dst->l_smtype);
     2691  bfd_put_8 (abfd, src->l_smclas, dst->l_smclas);
     2692  bfd_put_32 (abfd, src->l_ifile, dst->l_ifile);
     2693  bfd_put_32 (abfd, src->l_parm, dst->l_parm);
     2694}
     2695
     2696static void
     2697xcoff_swap_reloc_in (abfd, s, d)
     2698     bfd *abfd;
     2699     PTR s;
     2700     PTR d;
     2701{
     2702  struct external_reloc *src = (struct external_reloc *) s;
     2703  struct internal_reloc *dst = (struct internal_reloc *) d;
     2704
     2705  memset (dst, 0, sizeof (struct internal_reloc));
     2706
     2707  dst->r_vaddr = bfd_get_32 (abfd, src->r_vaddr);
     2708  dst->r_symndx = bfd_get_32 (abfd, src->r_symndx);
     2709  dst->r_size = bfd_get_8 (abfd, src->r_size);
     2710  dst->r_type = bfd_get_8 (abfd, src->r_type);
     2711}
     2712
     2713static unsigned int
     2714xcoff_swap_reloc_out (abfd, s, d)
     2715     bfd *abfd;
     2716     PTR s;
     2717     PTR d;
     2718{
     2719  struct internal_reloc *src = (struct internal_reloc *) s;
     2720  struct external_reloc *dst = (struct external_reloc *) d;
     2721
     2722  bfd_put_32 (abfd, src->r_vaddr, dst->r_vaddr);
     2723  bfd_put_32 (abfd, src->r_symndx, dst->r_symndx);
     2724  bfd_put_8 (abfd, src->r_type, dst->r_type);
     2725  bfd_put_8 (abfd, src->r_size, dst->r_size);
     2726
     2727  return bfd_coff_relsz (abfd);
     2728}
     2729
     2730/* Swap in the ldrel structure.  */
     2731
     2732static void
     2733xcoff_swap_ldrel_in (abfd, s, dst)
     2734     bfd *abfd;
     2735     const PTR s;
     2736     struct internal_ldrel *dst;
     2737{
     2738  const struct external_ldrel *src = (const struct external_ldrel *) s;
     2739
     2740  dst->l_vaddr = bfd_get_32 (abfd, src->l_vaddr);
     2741  dst->l_symndx = bfd_get_32 (abfd, src->l_symndx);
     2742  dst->l_rtype = bfd_get_16 (abfd, src->l_rtype);
     2743  dst->l_rsecnm = bfd_get_16 (abfd, src->l_rsecnm);
     2744}
     2745
     2746/* Swap out the ldrel structure.  */
     2747
     2748static void
     2749xcoff_swap_ldrel_out (abfd, src, d)
     2750     bfd *abfd;
     2751     const struct internal_ldrel *src;
     2752     PTR d;
     2753{
     2754  struct external_ldrel *dst = (struct external_ldrel *) d;
     2755
     2756  bfd_put_32 (abfd, src->l_vaddr, dst->l_vaddr);
     2757  bfd_put_32 (abfd, src->l_symndx, dst->l_symndx);
     2758  bfd_put_16 (abfd, (bfd_vma) src->l_rtype, dst->l_rtype);
     2759  bfd_put_16 (abfd, (bfd_vma) src->l_rsecnm, dst->l_rsecnm);
     2760}
     2761
     2762
     2763
     2764bfd_boolean
     2765xcoff_reloc_type_noop (input_bfd, input_section, output_bfd, rel, sym, howto,
     2766                       val, addend, relocation, contents)
     2767     bfd *input_bfd ATTRIBUTE_UNUSED;
     2768     asection *input_section ATTRIBUTE_UNUSED;
     2769     bfd *output_bfd ATTRIBUTE_UNUSED;
     2770     struct internal_reloc *rel ATTRIBUTE_UNUSED;
     2771     struct internal_syment *sym ATTRIBUTE_UNUSED;
     2772     struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
     2773     bfd_vma val ATTRIBUTE_UNUSED;
     2774     bfd_vma addend ATTRIBUTE_UNUSED;
     2775     bfd_vma *relocation ATTRIBUTE_UNUSED;
     2776     bfd_byte *contents ATTRIBUTE_UNUSED;
     2777{
     2778  return TRUE;
     2779}
     2780
     2781bfd_boolean
     2782xcoff_reloc_type_fail (input_bfd, input_section, output_bfd, rel, sym, howto,
     2783                       val, addend, relocation, contents)
     2784     bfd *input_bfd;
     2785     asection *input_section ATTRIBUTE_UNUSED;
     2786     bfd *output_bfd ATTRIBUTE_UNUSED;
     2787     struct internal_reloc *rel;
     2788     struct internal_syment *sym ATTRIBUTE_UNUSED;
     2789     struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
     2790     bfd_vma val ATTRIBUTE_UNUSED;
     2791     bfd_vma addend ATTRIBUTE_UNUSED;
     2792     bfd_vma *relocation ATTRIBUTE_UNUSED;
     2793     bfd_byte *contents ATTRIBUTE_UNUSED;
     2794{
     2795  (*_bfd_error_handler)
     2796    (_("%s: unsupported relocation type 0x%02x"),
     2797     bfd_get_filename (input_bfd), (unsigned int) rel->r_type);
     2798  bfd_set_error (bfd_error_bad_value);
     2799  return FALSE;
     2800}
     2801
     2802bfd_boolean
     2803xcoff_reloc_type_pos (input_bfd, input_section, output_bfd, rel, sym, howto,
     2804                      val, addend, relocation, contents)
     2805     bfd *input_bfd ATTRIBUTE_UNUSED;
     2806     asection *input_section ATTRIBUTE_UNUSED;
     2807     bfd *output_bfd ATTRIBUTE_UNUSED;
     2808     struct internal_reloc *rel ATTRIBUTE_UNUSED;
     2809     struct internal_syment *sym ATTRIBUTE_UNUSED;
     2810     struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
     2811     bfd_vma val;
     2812     bfd_vma addend;
     2813     bfd_vma *relocation;
     2814     bfd_byte *contents ATTRIBUTE_UNUSED;
     2815{
     2816  *relocation = val + addend;
     2817  return TRUE;
     2818}
     2819
     2820bfd_boolean
     2821xcoff_reloc_type_neg (input_bfd, input_section, output_bfd, rel, sym, howto,
     2822                      val, addend, relocation, contents)
     2823     bfd *input_bfd ATTRIBUTE_UNUSED;
     2824     asection *input_section ATTRIBUTE_UNUSED;
     2825     bfd *output_bfd ATTRIBUTE_UNUSED;
     2826     struct internal_reloc *rel ATTRIBUTE_UNUSED;
     2827     struct internal_syment *sym ATTRIBUTE_UNUSED;
     2828     struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
     2829     bfd_vma val;
     2830     bfd_vma addend;
     2831     bfd_vma *relocation;
     2832     bfd_byte *contents ATTRIBUTE_UNUSED;
     2833{
     2834  *relocation = addend - val;
     2835  return TRUE;
     2836}
     2837
     2838bfd_boolean
     2839xcoff_reloc_type_rel (input_bfd, input_section, output_bfd, rel, sym, howto,
     2840                      val, addend, relocation, contents)
     2841     bfd *input_bfd ATTRIBUTE_UNUSED;
     2842     asection *input_section;
     2843     bfd *output_bfd ATTRIBUTE_UNUSED;
     2844     struct internal_reloc *rel ATTRIBUTE_UNUSED;
     2845     struct internal_syment *sym ATTRIBUTE_UNUSED;
     2846     struct reloc_howto_struct *howto;
     2847     bfd_vma val;
     2848     bfd_vma addend;
     2849     bfd_vma *relocation;
     2850     bfd_byte *contents ATTRIBUTE_UNUSED;
     2851{
     2852  howto->pc_relative = TRUE;
     2853
     2854  /* A PC relative reloc includes the section address.  */
     2855  addend += input_section->vma;
     2856
     2857  *relocation = val + addend;
     2858  *relocation -= (input_section->output_section->vma
     2859                  + input_section->output_offset);
     2860  return TRUE;
     2861}
     2862
     2863bfd_boolean
     2864xcoff_reloc_type_toc (input_bfd, input_section, output_bfd, rel, sym, howto,
     2865                      val, addend, relocation, contents)
     2866     bfd *input_bfd;
     2867     asection *input_section ATTRIBUTE_UNUSED;
     2868     bfd *output_bfd;
     2869     struct internal_reloc *rel;
     2870     struct internal_syment *sym;
     2871     struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
     2872     bfd_vma val;
     2873     bfd_vma addend ATTRIBUTE_UNUSED;
     2874     bfd_vma *relocation;
     2875     bfd_byte *contents ATTRIBUTE_UNUSED;
     2876{
     2877  struct xcoff_link_hash_entry *h;
     2878
     2879  if (0 > rel->r_symndx)
     2880    return FALSE;
     2881
     2882  h = obj_xcoff_sym_hashes (input_bfd)[rel->r_symndx];
     2883
     2884  if (h != NULL && h->smclas != XMC_TD)
     2885    {
     2886      if (h->toc_section == NULL)
     2887        {
     2888          (*_bfd_error_handler)
     2889            (_("%s: TOC reloc at 0x%x to symbol `%s' with no TOC entry"),
     2890             bfd_get_filename (input_bfd), rel->r_vaddr,
     2891             h->root.root.string);
     2892          bfd_set_error (bfd_error_bad_value);
     2893          return FALSE;
     2894        }
     2895
     2896      BFD_ASSERT ((h->flags & XCOFF_SET_TOC) == 0);
     2897      val = (h->toc_section->output_section->vma
     2898              + h->toc_section->output_offset);
     2899    }
     2900
     2901  *relocation = ((val - xcoff_data (output_bfd)->toc)
     2902                 - (sym->n_value - xcoff_data (input_bfd)->toc));
     2903  return TRUE;
     2904}
     2905
     2906bfd_boolean
     2907xcoff_reloc_type_ba (input_bfd, input_section, output_bfd, rel, sym, howto,
     2908                     val, addend, relocation, contents)
     2909     bfd *input_bfd ATTRIBUTE_UNUSED;
     2910     asection *input_section ATTRIBUTE_UNUSED;
     2911     bfd *output_bfd ATTRIBUTE_UNUSED;
     2912     struct internal_reloc *rel ATTRIBUTE_UNUSED;
     2913     struct internal_syment *sym ATTRIBUTE_UNUSED;
     2914     struct reloc_howto_struct *howto;
     2915     bfd_vma val;
     2916     bfd_vma addend;
     2917     bfd_vma *relocation;
     2918     bfd_byte *contents ATTRIBUTE_UNUSED;
     2919{
     2920  howto->src_mask &= ~3;
     2921  howto->dst_mask = howto->src_mask;
     2922
     2923  *relocation = val + addend;
     2924
     2925  return TRUE;
     2926}
     2927
     2928static bfd_boolean
     2929xcoff_reloc_type_br (input_bfd, input_section, output_bfd, rel, sym, howto,
     2930                     val, addend, relocation, contents)
     2931     bfd *input_bfd;
     2932     asection *input_section;
     2933     bfd *output_bfd ATTRIBUTE_UNUSED;
     2934     struct internal_reloc *rel;
     2935     struct internal_syment *sym ATTRIBUTE_UNUSED;
     2936     struct reloc_howto_struct *howto;
     2937     bfd_vma val;
     2938     bfd_vma addend;
     2939     bfd_vma *relocation;
     2940     bfd_byte *contents;
     2941{
     2942  struct xcoff_link_hash_entry *h;
     2943
     2944  if (0 > rel->r_symndx)
     2945    return FALSE;
     2946
     2947  h = obj_xcoff_sym_hashes (input_bfd)[rel->r_symndx];
     2948
     2949  /* If we see an R_BR or R_RBR reloc which is jumping to global
     2950     linkage code, and it is followed by an appropriate cror nop
     2951     instruction, we replace the cror with lwz r2,20(r1).  This
     2952     restores the TOC after the glink code.  Contrariwise, if the
     2953     call is followed by a lwz r2,20(r1), but the call is not
     2954     going to global linkage code, we can replace the load with a
     2955     cror.  */
     2956  if (NULL != h
     2957      && bfd_link_hash_defined == h->root.type
     2958      && (rel->r_vaddr - input_section->vma + 8
     2959          <= input_section->_cooked_size))
     2960    {
     2961      bfd_byte *pnext;
     2962      unsigned long next;
     2963
     2964      pnext = contents + (rel->r_vaddr - input_section->vma) + 4;
     2965      next = bfd_get_32 (input_bfd, pnext);
     2966
     2967      /* The _ptrgl function is magic.  It is used by the AIX
     2968         compiler to call a function through a pointer.  */
     2969      if (h->smclas == XMC_GL || strcmp (h->root.root.string, "._ptrgl") == 0)
     2970        {
     2971          if (next == 0x4def7b82                        /* cror 15,15,15 */
     2972              || next == 0x4ffffb82                     /* cror 31,31,31 */
     2973              || next == 0x60000000)                    /* ori r0,r0,0 */
     2974            bfd_put_32 (input_bfd, 0x80410014, pnext);  /* lwz r1,20(r1) */
     2975
     2976        }
     2977      else
     2978        {
     2979          if (next == 0x80410014)                       /* lwz r1,20(r1) */
     2980            bfd_put_32 (input_bfd, 0x60000000, pnext);  /* ori r0,r0,0 */
     2981        }
     2982    }
     2983  else if (NULL != h && bfd_link_hash_undefined == h->root.type)
     2984    {
     2985      /* Normally, this relocation is against a defined symbol.  In the
     2986         case where this is a partial link and the output section offset
     2987         is greater than 2^25, the linker will return an invalid error
     2988         message that the relocation has been truncated.  Yes it has been
     2989         truncated but no it not important.  For this case, disable the
     2990         overflow checking. */
     2991
     2992      howto->complain_on_overflow = complain_overflow_dont;
     2993    }
     2994
     2995  howto->pc_relative = TRUE;
     2996  howto->src_mask &= ~3;
     2997  howto->dst_mask = howto->src_mask;
     2998
     2999  /* A PC relative reloc includes the section address.  */
     3000  addend += input_section->vma;
     3001
     3002  *relocation = val + addend;
     3003  *relocation -= (input_section->output_section->vma
     3004                  + input_section->output_offset);
     3005  return TRUE;
     3006}
     3007
     3008bfd_boolean
     3009xcoff_reloc_type_crel (input_bfd, input_section, output_bfd, rel, sym, howto,
     3010                       val, addend, relocation, contents)
     3011     bfd *input_bfd ATTRIBUTE_UNUSED;
     3012     asection *input_section;
     3013     bfd *output_bfd ATTRIBUTE_UNUSED;
     3014     struct internal_reloc *rel ATTRIBUTE_UNUSED;
     3015     struct internal_syment *sym ATTRIBUTE_UNUSED;
     3016     struct reloc_howto_struct *howto;
     3017     bfd_vma val ATTRIBUTE_UNUSED;
     3018     bfd_vma addend;
     3019     bfd_vma *relocation;
     3020     bfd_byte *contents ATTRIBUTE_UNUSED;
     3021{
     3022  howto->pc_relative = TRUE;
     3023  howto->src_mask &= ~3;
     3024  howto->dst_mask = howto->src_mask;
     3025
     3026  /* A PC relative reloc includes the section address.  */
     3027  addend += input_section->vma;
     3028
     3029  *relocation = val + addend;
     3030  *relocation -= (input_section->output_section->vma
     3031                  + input_section->output_offset);
     3032  return TRUE;
     3033}
     3034
     3035static bfd_boolean
     3036xcoff_complain_overflow_dont_func (input_bfd, val, relocation, howto)
     3037     bfd *input_bfd ATTRIBUTE_UNUSED;
     3038     bfd_vma val ATTRIBUTE_UNUSED;
     3039     bfd_vma relocation ATTRIBUTE_UNUSED;
     3040     struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
     3041{
     3042  return FALSE;
     3043}
     3044
     3045static bfd_boolean
     3046xcoff_complain_overflow_bitfield_func (input_bfd, val, relocation, howto)
     3047     bfd *input_bfd;
     3048     bfd_vma val;
     3049     bfd_vma relocation;
     3050     struct reloc_howto_struct *howto;
     3051{
     3052  bfd_vma addrmask, fieldmask, signmask, ss;
     3053  bfd_vma a, b, sum;
     3054
     3055  /* Get the values to be added together.  For signed and unsigned
     3056     relocations, we assume that all values should be truncated to
     3057     the size of an address.  For bitfields, all the bits matter.
     3058     See also bfd_check_overflow.  */
     3059  fieldmask = N_ONES (howto->bitsize);
     3060  addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask;
     3061  a = relocation;
     3062  b = val & howto->src_mask;
     3063
     3064  /* Much like unsigned, except no trimming with addrmask.  In
     3065     addition, the sum overflows if there is a carry out of
     3066     the bfd_vma, i.e., the sum is less than either input
     3067     operand.  */
     3068  a >>= howto->rightshift;
     3069  b >>= howto->bitpos;
     3070
     3071  /* Bitfields are sometimes used for signed numbers; for
     3072     example, a 13-bit field sometimes represents values in
     3073     0..8191 and sometimes represents values in -4096..4095.
     3074     If the field is signed and a is -4095 (0x1001) and b is
     3075     -1 (0x1fff), the sum is -4096 (0x1000), but (0x1001 +
     3076     0x1fff is 0x3000).  It's not clear how to handle this
     3077     everywhere, since there is not way to know how many bits
     3078     are significant in the relocation, but the original code
     3079     assumed that it was fully sign extended, and we will keep
     3080     that assumption.  */
     3081  signmask = (fieldmask >> 1) + 1;
     3082
     3083  if ((a & ~ fieldmask) != 0)
     3084    {
     3085      /* Some bits out of the field are set.  This might not
     3086         be a problem: if this is a signed bitfield, it is OK
     3087         iff all the high bits are set, including the sign
     3088         bit.  We'll try setting all but the most significant
     3089         bit in the original relocation value: if this is all
     3090         ones, we are OK, assuming a signed bitfield.  */
     3091      ss = (signmask << howto->rightshift) - 1;
     3092      if ((ss | relocation) != ~ (bfd_vma) 0)
     3093        return TRUE;
     3094      a &= fieldmask;
     3095    }
     3096
     3097  /* We just assume (b & ~ fieldmask) == 0.  */
     3098
     3099  /* We explicitly permit wrap around if this relocation
     3100     covers the high bit of an address.  The Linux kernel
     3101     relies on it, and it is the only way to write assembler
     3102     code which can run when loaded at a location 0x80000000
     3103     away from the location at which it is linked.  */
     3104  if (howto->bitsize + howto->rightshift
     3105      == bfd_arch_bits_per_address (input_bfd))
     3106    return FALSE;
     3107
     3108  sum = a + b;
     3109  if (sum < a || (sum & ~ fieldmask) != 0)
     3110    {
     3111      /* There was a carry out, or the field overflow.  Test
     3112         for signed operands again.  Here is the overflow test
     3113         is as for complain_overflow_signed.  */
     3114      if (((~ (a ^ b)) & (a ^ sum)) & signmask)
     3115        return TRUE;
     3116    }
     3117
     3118  return FALSE;
     3119}
     3120
     3121static bfd_boolean
     3122xcoff_complain_overflow_signed_func (input_bfd, val, relocation, howto)
     3123     bfd *input_bfd;
     3124     bfd_vma val;
     3125     bfd_vma relocation;
     3126     struct reloc_howto_struct *howto;
     3127{
     3128  bfd_vma addrmask, fieldmask, signmask, ss;
     3129  bfd_vma a, b, sum;
     3130
     3131  /* Get the values to be added together.  For signed and unsigned
     3132     relocations, we assume that all values should be truncated to
     3133     the size of an address.  For bitfields, all the bits matter.
     3134     See also bfd_check_overflow.  */
     3135  fieldmask = N_ONES (howto->bitsize);
     3136  addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask;
     3137  a = relocation;
     3138  b = val & howto->src_mask;
     3139
     3140  a = (a & addrmask) >> howto->rightshift;
     3141
     3142  /* If any sign bits are set, all sign bits must be set.
     3143     That is, A must be a valid negative address after
     3144     shifting.  */
     3145  signmask = ~ (fieldmask >> 1);
     3146  ss = a & signmask;
     3147  if (ss != 0 && ss != ((addrmask >> howto->rightshift) & signmask))
     3148    return TRUE;
     3149
     3150  /* We only need this next bit of code if the sign bit of B
     3151     is below the sign bit of A.  This would only happen if
     3152     SRC_MASK had fewer bits than BITSIZE.  Note that if
     3153     SRC_MASK has more bits than BITSIZE, we can get into
     3154     trouble; we would need to verify that B is in range, as
     3155     we do for A above.  */
     3156  signmask = ((~ howto->src_mask) >> 1) & howto->src_mask;
     3157  if ((b & signmask) != 0)
     3158    {
     3159      /* Set all the bits above the sign bit.  */
     3160      b -= signmask <<= 1;
     3161    }
     3162
     3163  b = (b & addrmask) >> howto->bitpos;
     3164
     3165  /* Now we can do the addition.  */
     3166  sum = a + b;
     3167
     3168  /* See if the result has the correct sign.  Bits above the
     3169     sign bit are junk now; ignore them.  If the sum is
     3170     positive, make sure we did not have all negative inputs;
     3171     if the sum is negative, make sure we did not have all
     3172     positive inputs.  The test below looks only at the sign
     3173     bits, and it really just
     3174     SIGN (A) == SIGN (B) && SIGN (A) != SIGN (SUM)
     3175  */
     3176  signmask = (fieldmask >> 1) + 1;
     3177  if (((~ (a ^ b)) & (a ^ sum)) & signmask)
     3178    return TRUE;
     3179
     3180  return FALSE;
     3181}
     3182
     3183static bfd_boolean
     3184xcoff_complain_overflow_unsigned_func (input_bfd, val, relocation, howto)
     3185     bfd *input_bfd;
     3186     bfd_vma val;
     3187     bfd_vma relocation;
     3188     struct reloc_howto_struct *howto;
     3189{
     3190  bfd_vma addrmask, fieldmask;
     3191  bfd_vma a, b, sum;
     3192
     3193  /* Get the values to be added together.  For signed and unsigned
     3194     relocations, we assume that all values should be truncated to
     3195     the size of an address.  For bitfields, all the bits matter.
     3196     See also bfd_check_overflow.  */
     3197  fieldmask = N_ONES (howto->bitsize);
     3198  addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask;
     3199  a = relocation;
     3200  b = val & howto->src_mask;
     3201
     3202  /* Checking for an unsigned overflow is relatively easy:
     3203     trim the addresses and add, and trim the result as well.
     3204     Overflow is normally indicated when the result does not
     3205     fit in the field.  However, we also need to consider the
     3206     case when, e.g., fieldmask is 0x7fffffff or smaller, an
     3207     input is 0x80000000, and bfd_vma is only 32 bits; then we
     3208     will get sum == 0, but there is an overflow, since the
     3209     inputs did not fit in the field.  Instead of doing a
     3210     separate test, we can check for this by or-ing in the
     3211     operands when testing for the sum overflowing its final
     3212     field.  */
     3213  a = (a & addrmask) >> howto->rightshift;
     3214  b = (b & addrmask) >> howto->bitpos;
     3215  sum = (a + b) & addrmask;
     3216  if ((a | b | sum) & ~ fieldmask)
     3217    return TRUE;
     3218
     3219  return FALSE;
     3220}
     3221
     3222/* This is the relocation function for the RS/6000/POWER/PowerPC.
     3223   This is currently the only processor which uses XCOFF; I hope that
     3224   will never change.
     3225
     3226   I took the relocation type definitions from two documents:
     3227   the PowerPC AIX Version 4 Application Binary Interface, First
     3228   Edition (April 1992), and the PowerOpen ABI, Big-Endian
     3229   32-Bit Hardware Implementation (June 30, 1994).  Differences
     3230   between the documents are noted below.
     3231
     3232   Unsupported r_type's
     3233
     3234   R_RTB:
     3235   R_RRTBI:
     3236   R_RRTBA:
     3237
     3238   These relocs are defined by the PowerPC ABI to be
     3239   relative branches which use half of the difference
     3240   between the symbol and the program counter.  I can't
     3241   quite figure out when this is useful.  These relocs are
     3242   not defined by the PowerOpen ABI.
     3243
     3244   Supported r_type's
     3245
     3246   R_POS:
     3247   Simple positive relocation.
     3248
     3249   R_NEG:
     3250   Simple negative relocation.
     3251
     3252   R_REL:
     3253   Simple PC relative relocation.
     3254
     3255   R_TOC:
     3256   TOC relative relocation.  The value in the instruction in
     3257   the input file is the offset from the input file TOC to
     3258   the desired location.  We want the offset from the final
     3259   TOC to the desired location.  We have:
     3260   isym = iTOC + in
     3261   iinsn = in + o
     3262   osym = oTOC + on
     3263   oinsn = on + o
     3264   so we must change insn by on - in.
     3265
     3266   R_GL:
     3267   GL linkage relocation.  The value of this relocation
     3268   is the address of the entry in the TOC section.
     3269
     3270   R_TCL:
     3271   Local object TOC address.  I can't figure out the
     3272   difference between this and case R_GL.
     3273
     3274   R_TRL:
     3275   TOC relative relocation.  A TOC relative load instruction
     3276   which may be changed to a load address instruction.
     3277   FIXME: We don't currently implement this optimization.
     3278
     3279   R_TRLA:
     3280   TOC relative relocation.  This is a TOC relative load
     3281   address instruction which may be changed to a load
     3282   instruction.  FIXME: I don't know if this is the correct
     3283   implementation.
     3284
     3285   R_BA:
     3286   Absolute branch.  We don't want to mess with the lower
     3287   two bits of the instruction.
     3288
     3289   R_CAI:
     3290   The PowerPC ABI defines this as an absolute call which
     3291   may be modified to become a relative call.  The PowerOpen
     3292   ABI does not define this relocation type.
     3293
     3294   R_RBA:
     3295   Absolute branch which may be modified to become a
     3296   relative branch.
     3297
     3298   R_RBAC:
     3299   The PowerPC ABI defines this as an absolute branch to a
     3300   fixed address which may be modified to an absolute branch
     3301   to a symbol.  The PowerOpen ABI does not define this
     3302   relocation type.
     3303
     3304   R_RBRC:
     3305   The PowerPC ABI defines this as an absolute branch to a
     3306   fixed address which may be modified to a relative branch.
     3307   The PowerOpen ABI does not define this relocation type.
     3308
     3309   R_BR:
     3310   Relative branch.  We don't want to mess with the lower
     3311   two bits of the instruction.
     3312
     3313   R_CREL:
     3314   The PowerPC ABI defines this as a relative call which may
     3315   be modified to become an absolute call.  The PowerOpen
     3316   ABI does not define this relocation type.
     3317
     3318   R_RBR:
     3319   A relative branch which may be modified to become an
     3320   absolute branch.  FIXME: We don't implement this,
     3321   although we should for symbols of storage mapping class
     3322   XMC_XO.
     3323
     3324   R_RL:
     3325   The PowerPC AIX ABI describes this as a load which may be
     3326   changed to a load address.  The PowerOpen ABI says this
     3327   is the same as case R_POS.
     3328
     3329   R_RLA:
     3330   The PowerPC AIX ABI describes this as a load address
     3331   which may be changed to a load.  The PowerOpen ABI says
     3332   this is the same as R_POS.
     3333*/
     3334
     3335bfd_boolean
     3336xcoff_ppc_relocate_section (output_bfd, info, input_bfd,
     3337                            input_section, contents, relocs, syms,
     3338                            sections)
     3339     bfd *output_bfd;
     3340     struct bfd_link_info *info;
     3341     bfd *input_bfd;
     3342     asection *input_section;
     3343     bfd_byte *contents;
     3344     struct internal_reloc *relocs;
     3345     struct internal_syment *syms;
     3346     asection **sections;
     3347{
     3348  struct internal_reloc *rel;
     3349  struct internal_reloc *relend;
     3350
     3351  rel = relocs;
     3352  relend = rel + input_section->reloc_count;
     3353  for (; rel < relend; rel++)
     3354    {
     3355      long symndx;
     3356      struct xcoff_link_hash_entry *h;
     3357      struct internal_syment *sym;
     3358      bfd_vma addend;
     3359      bfd_vma val;
     3360      struct reloc_howto_struct howto;
     3361      bfd_vma relocation;
     3362      bfd_vma value_to_relocate;
     3363      bfd_vma address;
     3364      bfd_byte *location;
     3365
     3366      /* Relocation type R_REF is a special relocation type which is
     3367         merely used to prevent garbage collection from occurring for
     3368         the csect including the symbol which it references.  */
     3369      if (rel->r_type == R_REF)
     3370        continue;
     3371
     3372      /* howto */
     3373      howto.type = rel->r_type;
     3374      howto.rightshift = 0;
     3375      howto.bitsize = (rel->r_size & 0x1f) + 1;
     3376      howto.size = howto.bitsize > 16 ? 2 : 1;
     3377      howto.pc_relative = FALSE;
     3378      howto.bitpos = 0;
     3379      howto.complain_on_overflow = (rel->r_size & 0x80
     3380                                    ? complain_overflow_signed
     3381                                    : complain_overflow_bitfield);
     3382      howto.special_function = NULL;
     3383      howto.name = "internal";
     3384      howto.partial_inplace = TRUE;
     3385      howto.src_mask = howto.dst_mask = N_ONES (howto.bitsize);
     3386      howto.pcrel_offset = FALSE;
     3387
     3388      /* symbol */
     3389      val = 0;
     3390      addend = 0;
     3391      h = NULL;
     3392      sym = NULL;
     3393      symndx = rel->r_symndx;
     3394
     3395      if (-1 != symndx)
     3396        {
     3397          asection *sec;
     3398
     3399          h = obj_xcoff_sym_hashes (input_bfd)[symndx];
     3400          sym = syms + symndx;
     3401          addend = - sym->n_value;
     3402
     3403          if (NULL == h)
     3404            {
     3405              sec = sections[symndx];
     3406              /* Hack to make sure we use the right TOC anchor value
     3407                 if this reloc is against the TOC anchor.  */
     3408              if (sec->name[3] == '0'
     3409                  && strcmp (sec->name, ".tc0") == 0)
     3410                val = xcoff_data (output_bfd)->toc;
     3411              else
     3412                val = (sec->output_section->vma
     3413                       + sec->output_offset
     3414                       + sym->n_value
     3415                       - sec->vma);
     3416            }
     3417          else
     3418            {
     3419              if (h->root.type == bfd_link_hash_defined
     3420                  || h->root.type == bfd_link_hash_defweak)
     3421                {
     3422                  sec = h->root.u.def.section;
     3423                  val = (h->root.u.def.value
     3424                         + sec->output_section->vma
     3425                         + sec->output_offset);
     3426                }
     3427              else if (h->root.type == bfd_link_hash_common)
     3428                {
     3429                  sec = h->root.u.c.p->section;
     3430                  val = (sec->output_section->vma
     3431                         + sec->output_offset);
     3432
     3433                }
     3434              else if ((0 == (h->flags & (XCOFF_DEF_DYNAMIC | XCOFF_IMPORT)))
     3435                       && ! info->relocateable)
     3436                {
     3437                  if (! ((*info->callbacks->undefined_symbol)
     3438                         (info, h->root.root.string, input_bfd, input_section,
     3439                          rel->r_vaddr - input_section->vma, TRUE)))
     3440                    return FALSE;
     3441
     3442                  /* Don't try to process the reloc.  It can't help, and
     3443                     it may generate another error.  */
     3444                  continue;
     3445                }
     3446            }
     3447        }
     3448
     3449      if (rel->r_type >= XCOFF_MAX_CALCULATE_RELOCATION
     3450          || !((*xcoff_calculate_relocation[rel->r_type])
     3451               (input_bfd, input_section, output_bfd, rel, sym, &howto, val,
     3452                addend, &relocation, contents)))
     3453        return FALSE;
     3454
     3455      /* address */
     3456      address = rel->r_vaddr - input_section->vma;
     3457      location = contents + address;
     3458
     3459      if (address > input_section->_raw_size)
     3460        abort ();
     3461
     3462      /* Get the value we are going to relocate.  */
     3463      if (1 == howto.size)
     3464        value_to_relocate = bfd_get_16 (input_bfd, location);
     3465      else
     3466        value_to_relocate = bfd_get_32 (input_bfd, location);
     3467
     3468      /* overflow.
     3469
     3470         FIXME: We may drop bits during the addition
     3471         which we don't check for.  We must either check at every single
     3472         operation, which would be tedious, or we must do the computations
     3473         in a type larger than bfd_vma, which would be inefficient.  */
     3474
     3475      if ((unsigned int) howto.complain_on_overflow
     3476          >= XCOFF_MAX_COMPLAIN_OVERFLOW)
     3477        abort ();
     3478
     3479      if (((*xcoff_complain_overflow[howto.complain_on_overflow])
     3480           (input_bfd, value_to_relocate, relocation, &howto)))
     3481        {
     3482          const char *name;
     3483          char buf[SYMNMLEN + 1];
     3484          char reloc_type_name[10];
     3485
     3486          if (symndx == -1)
     3487            {
     3488              name = "*ABS*";
     3489            }
     3490          else if (h != NULL)
     3491            {
     3492              name = h->root.root.string;
     3493            }
     3494          else
     3495            {
     3496              name = _bfd_coff_internal_syment_name (input_bfd, sym, buf);
     3497              if (name == NULL)
     3498                name = "UNKNOWN";
     3499            }
     3500          sprintf (reloc_type_name, "0x%02x", rel->r_type);
     3501
     3502          if (! ((*info->callbacks->reloc_overflow)
     3503                 (info, name, reloc_type_name, (bfd_vma) 0, input_bfd,
     3504                  input_section, rel->r_vaddr - input_section->vma)))
     3505            return FALSE;
     3506        }
     3507
     3508      /* Add RELOCATION to the right bits of VALUE_TO_RELOCATE.  */
     3509      value_to_relocate = ((value_to_relocate & ~howto.dst_mask)
     3510                           | (((value_to_relocate & howto.src_mask)
     3511                               + relocation) & howto.dst_mask));
     3512
     3513      /* Put the value back in the object file.  */
     3514      if (1 == howto.size)
     3515        bfd_put_16 (input_bfd, value_to_relocate, location);
     3516      else
     3517        bfd_put_32 (input_bfd, value_to_relocate, location);
     3518    }
     3519
     3520  return TRUE;
     3521}
     3522
     3523static bfd_boolean
     3524_bfd_xcoff_put_ldsymbol_name (abfd, ldinfo, ldsym, name)
     3525     bfd *abfd ATTRIBUTE_UNUSED;
     3526         struct xcoff_loader_info *ldinfo;
     3527         struct internal_ldsym *ldsym;
     3528         const char *name;
     3529{
     3530  size_t len;
     3531  len = strlen (name);
     3532
     3533  if (len <= SYMNMLEN)
     3534    strncpy (ldsym->_l._l_name, name, SYMNMLEN);
     3535  else
     3536    {
     3537      if (ldinfo->string_size + len + 3 > ldinfo->string_alc)
     3538        {
     3539          bfd_size_type newalc;
     3540          bfd_byte *newstrings;
     3541
     3542          newalc = ldinfo->string_alc * 2;
     3543          if (newalc == 0)
     3544            newalc = 32;
     3545          while (ldinfo->string_size + len + 3 > newalc)
     3546            newalc *= 2;
     3547
     3548          newstrings = ((bfd_byte *)
     3549                        bfd_realloc ((PTR) ldinfo->strings, newalc));
     3550          if (newstrings == NULL)
     3551            {
     3552              ldinfo->failed = TRUE;
     3553              return FALSE;
     3554            }
     3555          ldinfo->string_alc = newalc;
     3556          ldinfo->strings = newstrings;
     3557        }
     3558
     3559      bfd_put_16 (ldinfo->output_bfd, (bfd_vma) (len + 1),
     3560                  ldinfo->strings + ldinfo->string_size);
     3561      strcpy (ldinfo->strings + ldinfo->string_size + 2, name);
     3562      ldsym->_l._l_l._l_zeroes = 0;
     3563      ldsym->_l._l_l._l_offset = ldinfo->string_size + 2;
     3564      ldinfo->string_size += len + 3;
     3565    }
     3566
     3567  return TRUE;
     3568}
     3569
     3570static bfd_boolean
     3571_bfd_xcoff_put_symbol_name (bfd *abfd, struct bfd_strtab_hash *strtab,
     3572                            struct internal_syment *sym,
     3573                            const char *name)
     3574{
     3575  if (strlen (name) <= SYMNMLEN)
     3576    {
     3577      strncpy (sym->_n._n_name, name, SYMNMLEN);
     3578    }
     3579  else
     3580    {
     3581      bfd_boolean hash;
     3582      bfd_size_type indx;
     3583
     3584      hash = TRUE;
     3585      if ((abfd->flags & BFD_TRADITIONAL_FORMAT) != 0)
     3586        hash = FALSE;
     3587      indx = _bfd_stringtab_add (strtab, name, hash, FALSE);
     3588      if (indx == (bfd_size_type) -1)
     3589        return FALSE;
     3590      sym->_n._n_n._n_zeroes = 0;
     3591      sym->_n._n_n._n_offset = STRING_SIZE_SIZE + indx;
     3592    }
     3593  return TRUE;
     3594}
     3595
     3596static asection *
     3597xcoff_create_csect_from_smclas (abfd, aux, symbol_name)
     3598     bfd *abfd;
     3599     union internal_auxent *aux;
     3600     const char *symbol_name;
     3601{
     3602  asection *return_value = NULL;
     3603
     3604  /* .sv64 = x_smclas == 17
     3605     This is an invalid csect for 32 bit apps.  */
     3606  static const char *names[19] =
     3607  {
     3608    ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo",
     3609    ".sv", ".bs", ".ds", ".uc", ".ti", ".tb", NULL, ".tc0",
     3610    ".td", NULL, ".sv3264"
     3611  };
     3612
     3613  if ((19 >= aux->x_csect.x_smclas)
     3614      && (NULL != names[aux->x_csect.x_smclas]))
     3615    {
     3616      return_value = bfd_make_section_anyway
     3617        (abfd, names[aux->x_csect.x_smclas]);
     3618    }
     3619  else
     3620    {
     3621      (*_bfd_error_handler)
     3622        (_("%s: symbol `%s' has unrecognized smclas %d"),
     3623         bfd_archive_filename (abfd), symbol_name, aux->x_csect.x_smclas);
     3624      bfd_set_error (bfd_error_bad_value);
     3625    }
     3626
     3627  return return_value;
     3628}
     3629
     3630static bfd_boolean
     3631xcoff_is_lineno_count_overflow (abfd, value)
     3632    bfd *abfd ATTRIBUTE_UNUSED;
     3633        bfd_vma value;
     3634{
     3635  if (0xffff <= value)
     3636    return TRUE;
     3637
     3638  return FALSE;
     3639}
     3640
     3641static bfd_boolean
     3642xcoff_is_reloc_count_overflow (abfd, value)
     3643    bfd *abfd ATTRIBUTE_UNUSED;
     3644        bfd_vma value;
     3645{
     3646  if (0xffff <= value)
     3647    return TRUE;
     3648
     3649  return FALSE;
     3650}
     3651
     3652static bfd_vma
     3653xcoff_loader_symbol_offset (abfd, ldhdr)
     3654    bfd *abfd;
     3655    struct internal_ldhdr *ldhdr ATTRIBUTE_UNUSED;
     3656{
     3657  return bfd_xcoff_ldhdrsz (abfd);
     3658}
     3659
     3660static bfd_vma
     3661xcoff_loader_reloc_offset (abfd, ldhdr)
     3662    bfd *abfd;
     3663    struct internal_ldhdr *ldhdr;
     3664{
     3665  return bfd_xcoff_ldhdrsz (abfd) + ldhdr->l_nsyms * bfd_xcoff_ldsymsz (abfd);
     3666}
     3667
     3668static bfd_boolean
     3669xcoff_generate_rtinit  (abfd, init, fini, rtld)
     3670     bfd *abfd;
     3671     const char *init;
     3672     const char *fini;
     3673     bfd_boolean rtld;
     3674{
     3675  bfd_byte filehdr_ext[FILHSZ];
     3676  bfd_byte scnhdr_ext[SCNHSZ];
     3677  bfd_byte syment_ext[SYMESZ * 10];
     3678  bfd_byte reloc_ext[RELSZ * 3];
     3679  bfd_byte *data_buffer;
     3680  bfd_size_type data_buffer_size;
     3681  bfd_byte *string_table = NULL, *st_tmp = NULL;
     3682  bfd_size_type string_table_size;
     3683  bfd_vma val;
     3684  size_t initsz, finisz;
     3685  struct internal_filehdr filehdr;
     3686  struct internal_scnhdr scnhdr;
     3687  struct internal_syment syment;
     3688  union internal_auxent auxent;
     3689  struct internal_reloc reloc;
     3690
     3691  char *data_name = ".data";
     3692  char *rtinit_name = "__rtinit";
     3693  char *rtld_name = "__rtld";
     3694
     3695  if (! bfd_xcoff_rtinit_size (abfd))
     3696    return FALSE;
     3697
     3698  initsz = (init == NULL ? 0 : 1 + strlen (init));
     3699  finisz = (fini == NULL ? 0 : 1 + strlen (fini));
     3700
     3701  /* file header */
     3702  memset (filehdr_ext, 0, FILHSZ);
     3703  memset (&filehdr, 0, sizeof (struct internal_filehdr));
     3704  filehdr.f_magic = bfd_xcoff_magic_number (abfd);
     3705  filehdr.f_nscns = 1;
     3706  filehdr.f_timdat = 0;
     3707  filehdr.f_nsyms = 0;  /* at least 6, no more than 10 */
     3708  filehdr.f_symptr = 0; /* set below */
     3709  filehdr.f_opthdr = 0;
     3710  filehdr.f_flags = 0;
     3711
     3712  /* section header */
     3713  memset (scnhdr_ext, 0, SCNHSZ);
     3714  memset (&scnhdr, 0, sizeof (struct internal_scnhdr));
     3715  memcpy (scnhdr.s_name, data_name, strlen (data_name));
     3716  scnhdr.s_paddr = 0;
     3717  scnhdr.s_vaddr = 0;
     3718  scnhdr.s_size = 0;    /* set below */
     3719  scnhdr.s_scnptr = FILHSZ + SCNHSZ;
     3720  scnhdr.s_relptr = 0;  /* set below */
     3721  scnhdr.s_lnnoptr = 0;
     3722  scnhdr.s_nreloc = 0;  /* either 1 or 2 */
     3723  scnhdr.s_nlnno = 0;
     3724  scnhdr.s_flags = STYP_DATA;
     3725
     3726  /* .data
     3727     0x0000           0x00000000 : rtl
     3728     0x0004           0x00000010 : offset to init, or 0
     3729     0x0008           0x00000028 : offset to fini, or 0
     3730     0x000C           0x0000000C : size of descriptor
     3731     0x0010           0x00000000 : init, needs a reloc
     3732     0x0014           0x00000040 : offset to init name
     3733     0x0018           0x00000000 : flags, padded to a word
     3734     0x001C           0x00000000 : empty init
     3735     0x0020           0x00000000 :
     3736     0x0024           0x00000000 :
     3737     0x0028           0x00000000 : fini, needs a reloc
     3738     0x002C           0x00000??? : offset to fini name
     3739     0x0030           0x00000000 : flags, padded to a word
     3740     0x0034           0x00000000 : empty fini
     3741     0x0038           0x00000000 :
     3742     0x003C           0x00000000 :
     3743     0x0040           init name
     3744     0x0040 + initsz  fini name */
     3745
     3746  data_buffer_size = 0x0040 + initsz + finisz;
     3747  data_buffer_size = (data_buffer_size + 7) &~ (bfd_size_type) 7;
     3748  data_buffer = NULL;
     3749  data_buffer = (bfd_byte *) bfd_zmalloc (data_buffer_size);
     3750  if (data_buffer == NULL)
     3751    return FALSE;
     3752
     3753  if (initsz)
     3754    {
     3755      val = 0x10;
     3756      bfd_h_put_32 (abfd, val, &data_buffer[0x04]);
     3757      val = 0x40;
     3758      bfd_h_put_32 (abfd, val, &data_buffer[0x14]);
     3759      memcpy (&data_buffer[val], init, initsz);
     3760    }
     3761
     3762  if (finisz)
     3763    {
     3764      val = 0x28;
     3765      bfd_h_put_32 (abfd, val, &data_buffer[0x08]);
     3766      val = 0x40 + initsz;
     3767      bfd_h_put_32 (abfd, val, &data_buffer[0x2C]);
     3768      memcpy (&data_buffer[val], fini, finisz);
     3769    }
     3770
     3771  val = 0x0C;
     3772  bfd_h_put_32 (abfd, val, &data_buffer[0x0C]);
     3773
     3774  scnhdr.s_size = data_buffer_size;
     3775
     3776  /* string table */
     3777  string_table_size = 0;
     3778  if (initsz > 9)
     3779    string_table_size += initsz;
     3780  if (finisz > 9)
     3781    string_table_size += finisz;
     3782  if (string_table_size)
     3783    {
     3784      string_table_size += 4;
     3785      string_table = (bfd_byte *) bfd_zmalloc (string_table_size);
     3786      if (string_table == NULL)
     3787        return FALSE;
     3788
     3789      val = string_table_size;
     3790      bfd_h_put_32 (abfd, val, &string_table[0]);
     3791      st_tmp = string_table + 4;
     3792    }
     3793
     3794  /* symbols
     3795     0. .data csect
     3796     2. __rtinit
     3797     4. init function
     3798     6. fini function
     3799     8. __rtld  */
     3800  memset (syment_ext, 0, 10 * SYMESZ);
     3801  memset (reloc_ext, 0, 3 * RELSZ);
     3802
     3803  /* .data csect */
     3804  memset (&syment, 0, sizeof (struct internal_syment));
     3805  memset (&auxent, 0, sizeof (union internal_auxent));
     3806  memcpy (syment._n._n_name, data_name, strlen (data_name));
     3807  syment.n_scnum = 1;
     3808  syment.n_sclass = C_HIDEXT;
     3809  syment.n_numaux = 1;
     3810  auxent.x_csect.x_scnlen.l = data_buffer_size;
     3811  auxent.x_csect.x_smtyp = 3 << 3 | XTY_SD;
     3812  auxent.x_csect.x_smclas = XMC_RW;
     3813  bfd_coff_swap_sym_out (abfd, &syment,
     3814                         &syment_ext[filehdr.f_nsyms * SYMESZ]);
     3815  bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
     3816                         syment.n_numaux,
     3817                         &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
     3818  filehdr.f_nsyms += 2;
     3819
     3820  /* __rtinit */
     3821  memset (&syment, 0, sizeof (struct internal_syment));
     3822  memset (&auxent, 0, sizeof (union internal_auxent));
     3823  memcpy (syment._n._n_name, rtinit_name, strlen (rtinit_name));
     3824  syment.n_scnum = 1;
     3825  syment.n_sclass = C_EXT;
     3826  syment.n_numaux = 1;
     3827  auxent.x_csect.x_smtyp = XTY_LD;
     3828  auxent.x_csect.x_smclas = XMC_RW;
     3829  bfd_coff_swap_sym_out (abfd, &syment,
     3830                         &syment_ext[filehdr.f_nsyms * SYMESZ]);
     3831  bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
     3832                         syment.n_numaux,
     3833                         &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
     3834  filehdr.f_nsyms += 2;
     3835
     3836  /* init */
     3837  if (initsz)
     3838    {
     3839      memset (&syment, 0, sizeof (struct internal_syment));
     3840      memset (&auxent, 0, sizeof (union internal_auxent));
     3841
     3842      if (initsz > 9)
     3843        {
     3844          syment._n._n_n._n_offset = st_tmp - string_table;
     3845          memcpy (st_tmp, init, initsz);
     3846          st_tmp += initsz;
     3847        }
     3848      else
     3849        memcpy (syment._n._n_name, init, initsz - 1);
     3850
     3851      syment.n_sclass = C_EXT;
     3852      syment.n_numaux = 1;
     3853      bfd_coff_swap_sym_out (abfd, &syment,
     3854                             &syment_ext[filehdr.f_nsyms * SYMESZ]);
     3855      bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
     3856                             syment.n_numaux,
     3857                             &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
     3858
     3859      /* reloc */
     3860      memset (&reloc, 0, sizeof (struct internal_reloc));
     3861      reloc.r_vaddr = 0x0010;
     3862      reloc.r_symndx = filehdr.f_nsyms;
     3863      reloc.r_type = R_POS;
     3864      reloc.r_size = 31;
     3865      bfd_coff_swap_reloc_out (abfd, &reloc, &reloc_ext[0]);
     3866
     3867      filehdr.f_nsyms += 2;
     3868      scnhdr.s_nreloc += 1;
     3869    }
     3870
     3871  /* fini */
     3872  if (finisz)
     3873    {
     3874      memset (&syment, 0, sizeof (struct internal_syment));
     3875      memset (&auxent, 0, sizeof (union internal_auxent));
     3876
     3877      if (finisz > 9)
     3878        {
     3879          syment._n._n_n._n_offset = st_tmp - string_table;
     3880          memcpy (st_tmp, fini, finisz);
     3881          st_tmp += finisz;
     3882        }
     3883      else
     3884        memcpy (syment._n._n_name, fini, finisz - 1);
     3885
     3886      syment.n_sclass = C_EXT;
     3887      syment.n_numaux = 1;
     3888      bfd_coff_swap_sym_out (abfd, &syment,
     3889                             &syment_ext[filehdr.f_nsyms * SYMESZ]);
     3890      bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
     3891                             syment.n_numaux,
     3892                             &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
     3893
     3894      /* reloc */
     3895      memset (&reloc, 0, sizeof (struct internal_reloc));
     3896      reloc.r_vaddr = 0x0028;
     3897      reloc.r_symndx = filehdr.f_nsyms;
     3898      reloc.r_type = R_POS;
     3899      reloc.r_size = 31;
     3900      bfd_coff_swap_reloc_out (abfd, &reloc,
     3901                               &reloc_ext[scnhdr.s_nreloc * RELSZ]);
     3902
     3903      filehdr.f_nsyms += 2;
     3904      scnhdr.s_nreloc += 1;
     3905    }
     3906
     3907  if (rtld)
     3908    {
     3909      memset (&syment, 0, sizeof (struct internal_syment));
     3910      memset (&auxent, 0, sizeof (union internal_auxent));
     3911      memcpy (syment._n._n_name, rtld_name, strlen (rtld_name));
     3912      syment.n_sclass = C_EXT;
     3913      syment.n_numaux = 1;
     3914      bfd_coff_swap_sym_out (abfd, &syment,
     3915                             &syment_ext[filehdr.f_nsyms * SYMESZ]);
     3916      bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
     3917                             syment.n_numaux,
     3918                             &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
     3919
     3920      /* reloc */
     3921      memset (&reloc, 0, sizeof (struct internal_reloc));
     3922      reloc.r_vaddr = 0x0000;
     3923      reloc.r_symndx = filehdr.f_nsyms;
     3924      reloc.r_type = R_POS;
     3925      reloc.r_size = 31;
     3926      bfd_coff_swap_reloc_out (abfd, &reloc,
     3927                               &reloc_ext[scnhdr.s_nreloc * RELSZ]);
     3928
     3929      filehdr.f_nsyms += 2;
     3930      scnhdr.s_nreloc += 1;
     3931    }
     3932
     3933  scnhdr.s_relptr = scnhdr.s_scnptr + data_buffer_size;
     3934  filehdr.f_symptr = scnhdr.s_relptr + scnhdr.s_nreloc * RELSZ;
     3935
     3936  bfd_coff_swap_filehdr_out (abfd, &filehdr, filehdr_ext);
     3937  bfd_bwrite (filehdr_ext, FILHSZ, abfd);
     3938  bfd_coff_swap_scnhdr_out (abfd, &scnhdr, scnhdr_ext);
     3939  bfd_bwrite (scnhdr_ext, SCNHSZ, abfd);
     3940  bfd_bwrite (data_buffer, data_buffer_size, abfd);
     3941  bfd_bwrite (reloc_ext, scnhdr.s_nreloc * RELSZ, abfd);
     3942  bfd_bwrite (syment_ext, filehdr.f_nsyms * SYMESZ, abfd);
     3943  bfd_bwrite (string_table, string_table_size, abfd);
     3944
     3945  free (data_buffer);
     3946  data_buffer = NULL;
     3947
     3948  return TRUE;
     3949}
     3950
     3951
     3952static reloc_howto_type xcoff_dynamic_reloc =
     3953HOWTO (0,                       /* type */
     3954       0,                       /* rightshift */
     3955       2,                       /* size (0 = byte, 1 = short, 2 = long) */
     3956       32,                      /* bitsize */
     3957       FALSE,                   /* pc_relative */
     3958       0,                       /* bitpos */
     3959       complain_overflow_bitfield, /* complain_on_overflow */
     3960       0,                       /* special_function */
     3961       "R_POS",                 /* name */
     3962       TRUE,                    /* partial_inplace */
     3963       0xffffffff,              /* src_mask */
     3964       0xffffffff,              /* dst_mask */
     3965       FALSE);                  /* pcrel_offset */
     3966
     3967/*  glink
     3968
     3969   The first word of global linkage code must be modified by filling in
     3970   the correct TOC offset.  */
     3971
     3972static unsigned long xcoff_glink_code[9] =
     3973  {
     3974    0x81820000, /* lwz r12,0(r2) */
     3975    0x90410014, /* stw r2,20(r1) */
     3976    0x800c0000, /* lwz r0,0(r12) */
     3977    0x804c0004, /* lwz r2,4(r12) */
     3978    0x7c0903a6, /* mtctr r0 */
     3979    0x4e800420, /* bctr */
     3980    0x00000000, /* start of traceback table */
     3981    0x000c8000, /* traceback table */
     3982    0x00000000, /* traceback table */
     3983  };
     3984
     3985
     3986static const struct xcoff_backend_data_rec bfd_xcoff_backend_data =
     3987  {
     3988    { /* COFF backend, defined in libcoff.h.  */
     3989      _bfd_xcoff_swap_aux_in,
     3990      _bfd_xcoff_swap_sym_in,
     3991      coff_swap_lineno_in,
     3992      _bfd_xcoff_swap_aux_out,
     3993      _bfd_xcoff_swap_sym_out,
     3994      coff_swap_lineno_out,
     3995      xcoff_swap_reloc_out,
     3996      coff_swap_filehdr_out,
     3997      coff_swap_aouthdr_out,
     3998      coff_swap_scnhdr_out,
     3999      FILHSZ,
     4000      AOUTSZ,
     4001      SCNHSZ,
     4002      SYMESZ,
     4003      AUXESZ,
     4004      RELSZ,
     4005      LINESZ,
     4006      FILNMLEN,
     4007      TRUE,                     /* _bfd_coff_long_filenames */
     4008      FALSE,                    /* _bfd_coff_long_section_names */
     4009      3,                        /* _bfd_coff_default_section_alignment_power */
     4010      FALSE,                    /* _bfd_coff_force_symnames_in_strings */
     4011      2,                        /* _bfd_coff_debug_string_prefix_length */
     4012      coff_swap_filehdr_in,
     4013      coff_swap_aouthdr_in,
     4014      coff_swap_scnhdr_in,
     4015      xcoff_swap_reloc_in,
     4016      coff_bad_format_hook,
     4017      coff_set_arch_mach_hook,
     4018      coff_mkobject_hook,
     4019      styp_to_sec_flags,
     4020      coff_set_alignment_hook,
     4021      coff_slurp_symbol_table,
     4022      symname_in_debug_hook,
     4023      coff_pointerize_aux_hook,
     4024      coff_print_aux,
     4025      dummy_reloc16_extra_cases,
     4026      dummy_reloc16_estimate,
     4027      NULL,                     /* bfd_coff_sym_is_global */
     4028      coff_compute_section_file_positions,
     4029      NULL,                     /* _bfd_coff_start_final_link */
     4030      xcoff_ppc_relocate_section,
     4031      coff_rtype_to_howto,
     4032      NULL,                     /* _bfd_coff_adjust_symndx */
     4033      _bfd_generic_link_add_one_symbol,
     4034      coff_link_output_has_begun,
     4035      coff_final_link_postscript
     4036    },
     4037
     4038    0x01DF,                     /* magic number */
     4039    bfd_arch_rs6000,
     4040    bfd_mach_rs6k,
     4041
     4042    /* Function pointers to xcoff specific swap routines.  */
     4043    xcoff_swap_ldhdr_in,
     4044    xcoff_swap_ldhdr_out,
     4045    xcoff_swap_ldsym_in,
     4046    xcoff_swap_ldsym_out,
     4047    xcoff_swap_ldrel_in,
     4048    xcoff_swap_ldrel_out,
     4049
     4050    /* Sizes.  */
     4051    LDHDRSZ,
     4052    LDSYMSZ,
     4053    LDRELSZ,
     4054    12,                         /* _xcoff_function_descriptor_size */
     4055    SMALL_AOUTSZ,
     4056
     4057    /* Versions.  */
     4058    1,                          /* _xcoff_ldhdr_version */
     4059
     4060    _bfd_xcoff_put_symbol_name,
     4061    _bfd_xcoff_put_ldsymbol_name,
     4062    &xcoff_dynamic_reloc,
     4063    xcoff_create_csect_from_smclas,
     4064
     4065    /* Lineno and reloc count overflow.  */
     4066    xcoff_is_lineno_count_overflow,
     4067    xcoff_is_reloc_count_overflow,
     4068
     4069    xcoff_loader_symbol_offset,
     4070    xcoff_loader_reloc_offset,
     4071
     4072    /* glink.  */
     4073    &xcoff_glink_code[0],
     4074    36,                         /* _xcoff_glink_size */
     4075
     4076    /* rtinit */
     4077    64,                         /* _xcoff_rtinit_size */
     4078    xcoff_generate_rtinit,
     4079  };
     4080
     4081/* The transfer vector that leads the outside world to all of the above.  */
     4082const bfd_target rs6000coff_vec =
     4083  {
     4084    "aixcoff-rs6000",
     4085    bfd_target_xcoff_flavour,
     4086    BFD_ENDIAN_BIG,             /* data byte order is big */
     4087    BFD_ENDIAN_BIG,             /* header byte order is big */
     4088
     4089    (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | DYNAMIC
     4090     | HAS_SYMS | HAS_LOCALS | WP_TEXT),
     4091
     4092    SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA,
     4093    0,                          /* leading char */
     4094    '/',                        /* ar_pad_char */
     4095    15,                         /* ar_max_namelen */
     4096
     4097    /* data */
     4098    bfd_getb64,
     4099    bfd_getb_signed_64,
     4100    bfd_putb64,
     4101    bfd_getb32,
     4102    bfd_getb_signed_32,
     4103    bfd_putb32,
     4104    bfd_getb16,
     4105    bfd_getb_signed_16,
     4106    bfd_putb16,
     4107
     4108    /* hdrs */
     4109    bfd_getb64,
     4110    bfd_getb_signed_64,
     4111    bfd_putb64,
     4112    bfd_getb32,
     4113    bfd_getb_signed_32,
     4114    bfd_putb32,
     4115    bfd_getb16,
     4116    bfd_getb_signed_16,
     4117    bfd_putb16,
     4118
     4119    { /* bfd_check_format */
     4120      _bfd_dummy_target,
     4121      coff_object_p,
     4122      _bfd_xcoff_archive_p,
     4123      CORE_FILE_P
     4124    },
     4125
     4126    { /* bfd_set_format */
     4127      bfd_false,
     4128      coff_mkobject,
     4129      _bfd_generic_mkarchive,
     4130      bfd_false
     4131    },
     4132
     4133    {/* bfd_write_contents */
     4134      bfd_false,
     4135      coff_write_object_contents,
     4136      _bfd_xcoff_write_archive_contents,
     4137      bfd_false
     4138    },
     4139
     4140    /* Generic */
     4141    bfd_true,
     4142    bfd_true,
     4143    coff_new_section_hook,
     4144    _bfd_generic_get_section_contents,
     4145    _bfd_generic_get_section_contents_in_window,
     4146
     4147    /* Copy */
     4148    _bfd_xcoff_copy_private_bfd_data,
     4149    ((bfd_boolean (*) (bfd *, bfd *)) bfd_true),
     4150    ((bfd_boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true),
     4151    ((bfd_boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true),
     4152    ((bfd_boolean (*) (bfd *, flagword)) bfd_true),
     4153    ((bfd_boolean (*) (bfd *, void * )) bfd_true),
     4154
     4155    /* Core */
     4156    coff_core_file_failing_command,
     4157    coff_core_file_failing_signal,
     4158    coff_core_file_matches_executable_p,
     4159
     4160    /* Archive */
     4161    _bfd_xcoff_slurp_armap,
     4162    bfd_false,
     4163    ((bfd_boolean (*) (bfd *, char **, bfd_size_type *, const char **)) bfd_false),
     4164    bfd_dont_truncate_arname,
     4165    _bfd_xcoff_write_armap,
     4166    _bfd_xcoff_read_ar_hdr,
     4167    _bfd_xcoff_openr_next_archived_file,
     4168    _bfd_generic_get_elt_at_index,
     4169    _bfd_xcoff_stat_arch_elt,
     4170    bfd_true,
     4171
     4172    /* Symbols */
     4173    coff_get_symtab_upper_bound,
     4174    coff_get_symtab,
     4175    coff_make_empty_symbol,
     4176    coff_print_symbol,
     4177    coff_get_symbol_info,
     4178    _bfd_xcoff_is_local_label_name,
     4179    coff_get_lineno,
     4180    coff_find_nearest_line,
     4181    coff_bfd_make_debug_symbol,
     4182    _bfd_generic_read_minisymbols,
     4183    _bfd_generic_minisymbol_to_symbol,
     4184
     4185    /* Reloc */
     4186    coff_get_reloc_upper_bound,
     4187    coff_canonicalize_reloc,
     4188    _bfd_xcoff_reloc_type_lookup,
     4189
     4190    /* Write */
     4191    coff_set_arch_mach,
     4192    coff_set_section_contents,
     4193
     4194    /* Link */
     4195    _bfd_xcoff_sizeof_headers,
     4196    bfd_generic_get_relocated_section_contents,
     4197    bfd_generic_relax_section,
     4198    _bfd_xcoff_bfd_link_hash_table_create,
     4199    _bfd_generic_link_hash_table_free,
     4200    _bfd_xcoff_bfd_link_add_symbols,
     4201    _bfd_generic_link_just_syms,
     4202    _bfd_xcoff_bfd_final_link,
     4203    _bfd_generic_link_split_section,
     4204    bfd_generic_gc_sections,
     4205    bfd_generic_merge_sections,
     4206    bfd_generic_discard_group,
     4207
     4208    /* Dynamic */
     4209    _bfd_xcoff_get_dynamic_symtab_upper_bound,
     4210    _bfd_xcoff_canonicalize_dynamic_symtab,
     4211    _bfd_xcoff_get_dynamic_reloc_upper_bound,
     4212    _bfd_xcoff_canonicalize_dynamic_reloc,
     4213
     4214    /* Opposite endian version, none exists */
     4215    NULL,
     4216
     4217    (void *) &bfd_xcoff_backend_data,
     4218  };
     4219
     4220/* xcoff-powermac target
     4221   Old target.
     4222   Only difference between this target and the rs6000 target is the
     4223   the default architecture and machine type used in coffcode.h
     4224
     4225   PowerPC Macs use the same magic numbers as RS/6000
     4226   (because that's how they were bootstrapped originally),
     4227   but they are always PowerPC architecture.  */
     4228static const struct xcoff_backend_data_rec bfd_pmac_xcoff_backend_data =
     4229  {
     4230    { /* COFF backend, defined in libcoff.h.  */
     4231      _bfd_xcoff_swap_aux_in,
     4232      _bfd_xcoff_swap_sym_in,
     4233      coff_swap_lineno_in,
     4234      _bfd_xcoff_swap_aux_out,
     4235      _bfd_xcoff_swap_sym_out,
     4236      coff_swap_lineno_out,
     4237      xcoff_swap_reloc_out,
     4238      coff_swap_filehdr_out,
     4239      coff_swap_aouthdr_out,
     4240      coff_swap_scnhdr_out,
     4241      FILHSZ,
     4242      AOUTSZ,
     4243      SCNHSZ,
     4244      SYMESZ,
     4245      AUXESZ,
     4246      RELSZ,
     4247      LINESZ,
     4248      FILNMLEN,
     4249      TRUE,                     /* _bfd_coff_long_filenames */
     4250      FALSE,                    /* _bfd_coff_long_section_names */
     4251      3,                        /* _bfd_coff_default_section_alignment_power */
     4252      FALSE,                    /* _bfd_coff_force_symnames_in_strings */
     4253      2,                        /* _bfd_coff_debug_string_prefix_length */
     4254      coff_swap_filehdr_in,
     4255      coff_swap_aouthdr_in,
     4256      coff_swap_scnhdr_in,
     4257      xcoff_swap_reloc_in,
     4258      coff_bad_format_hook,
     4259      coff_set_arch_mach_hook,
     4260      coff_mkobject_hook,
     4261      styp_to_sec_flags,
     4262      coff_set_alignment_hook,
     4263      coff_slurp_symbol_table,
     4264      symname_in_debug_hook,
     4265      coff_pointerize_aux_hook,
     4266      coff_print_aux,
     4267      dummy_reloc16_extra_cases,
     4268      dummy_reloc16_estimate,
     4269      NULL,                     /* bfd_coff_sym_is_global */
     4270      coff_compute_section_file_positions,
     4271      NULL,                     /* _bfd_coff_start_final_link */
     4272      xcoff_ppc_relocate_section,
     4273      coff_rtype_to_howto,
     4274      NULL,                     /* _bfd_coff_adjust_symndx */
     4275      _bfd_generic_link_add_one_symbol,
     4276      coff_link_output_has_begun,
     4277      coff_final_link_postscript
     4278    },
     4279
     4280    0x01DF,                     /* magic number */
     4281    bfd_arch_powerpc,
     4282    bfd_mach_ppc,
     4283
     4284    /* Function pointers to xcoff specific swap routines.  */
     4285    xcoff_swap_ldhdr_in,
     4286    xcoff_swap_ldhdr_out,
     4287    xcoff_swap_ldsym_in,
     4288    xcoff_swap_ldsym_out,
     4289    xcoff_swap_ldrel_in,
     4290    xcoff_swap_ldrel_out,
     4291
     4292    /* Sizes.  */
     4293    LDHDRSZ,
     4294    LDSYMSZ,
     4295    LDRELSZ,
     4296    12,                         /* _xcoff_function_descriptor_size */
     4297    SMALL_AOUTSZ,
     4298
     4299    /* Versions.  */
     4300    1,                          /* _xcoff_ldhdr_version */
     4301
     4302    _bfd_xcoff_put_symbol_name,
     4303    _bfd_xcoff_put_ldsymbol_name,
     4304    &xcoff_dynamic_reloc,
     4305    xcoff_create_csect_from_smclas,
     4306
     4307    /* Lineno and reloc count overflow.  */
     4308    xcoff_is_lineno_count_overflow,
     4309    xcoff_is_reloc_count_overflow,
     4310
     4311    xcoff_loader_symbol_offset,
     4312    xcoff_loader_reloc_offset,
     4313
     4314    /* glink.  */
     4315    &xcoff_glink_code[0],
     4316    36,                         /* _xcoff_glink_size */
     4317
     4318    /* rtinit */
     4319    0,                          /* _xcoff_rtinit_size */
     4320    xcoff_generate_rtinit,
     4321  };
     4322
     4323/* The transfer vector that leads the outside world to all of the above.  */
     4324const bfd_target pmac_xcoff_vec =
     4325  {
     4326    "xcoff-powermac",
     4327    bfd_target_xcoff_flavour,
     4328    BFD_ENDIAN_BIG,             /* data byte order is big */
     4329    BFD_ENDIAN_BIG,             /* header byte order is big */
     4330
     4331    (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | DYNAMIC
     4332     | HAS_SYMS | HAS_LOCALS | WP_TEXT),
     4333
     4334    SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA,
     4335    0,                          /* leading char */
     4336    '/',                        /* ar_pad_char */
     4337    15,                         /* ar_max_namelen */
     4338
     4339    /* data */
     4340    bfd_getb64,
     4341    bfd_getb_signed_64,
     4342    bfd_putb64,
     4343    bfd_getb32,
     4344    bfd_getb_signed_32,
     4345    bfd_putb32,
     4346    bfd_getb16,
     4347    bfd_getb_signed_16,
     4348    bfd_putb16,
     4349
     4350    /* hdrs */
     4351    bfd_getb64,
     4352    bfd_getb_signed_64,
     4353    bfd_putb64,
     4354    bfd_getb32,
     4355    bfd_getb_signed_32,
     4356    bfd_putb32,
     4357    bfd_getb16,
     4358    bfd_getb_signed_16,
     4359    bfd_putb16,
     4360
     4361    { /* bfd_check_format */
     4362      _bfd_dummy_target,
     4363      coff_object_p,
     4364      _bfd_xcoff_archive_p,
     4365      CORE_FILE_P
     4366    },
     4367
     4368    { /* bfd_set_format */
     4369      bfd_false,
     4370      coff_mkobject,
     4371      _bfd_generic_mkarchive,
     4372      bfd_false
     4373    },
     4374
     4375    {/* bfd_write_contents */
     4376      bfd_false,
     4377      coff_write_object_contents,
     4378      _bfd_xcoff_write_archive_contents,
     4379      bfd_false
     4380    },
     4381
     4382    /* Generic */
     4383    bfd_true,
     4384    bfd_true,
     4385    coff_new_section_hook,
     4386    _bfd_generic_get_section_contents,
     4387    _bfd_generic_get_section_contents_in_window,
     4388
     4389    /* Copy */
     4390    _bfd_xcoff_copy_private_bfd_data,
     4391    ((bfd_boolean (*) (bfd *, bfd *)) bfd_true),
     4392    ((bfd_boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true),
     4393    ((bfd_boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true),
     4394    ((bfd_boolean (*) (bfd *, flagword)) bfd_true),
     4395    ((bfd_boolean (*) (bfd *, void * )) bfd_true),
     4396
     4397    /* Core */
     4398    coff_core_file_failing_command,
     4399    coff_core_file_failing_signal,
     4400    coff_core_file_matches_executable_p,
     4401
     4402    /* Archive */
     4403    _bfd_xcoff_slurp_armap,
     4404    bfd_false,
     4405    ((bfd_boolean (*) (bfd *, char **, bfd_size_type *, const char **)) bfd_false),
     4406    bfd_dont_truncate_arname,
     4407    _bfd_xcoff_write_armap,
     4408    _bfd_xcoff_read_ar_hdr,
     4409    _bfd_xcoff_openr_next_archived_file,
     4410    _bfd_generic_get_elt_at_index,
     4411    _bfd_xcoff_stat_arch_elt,
     4412    bfd_true,
     4413
     4414    /* Symbols */
     4415    coff_get_symtab_upper_bound,
     4416    coff_get_symtab,
     4417    coff_make_empty_symbol,
     4418    coff_print_symbol,
     4419    coff_get_symbol_info,
     4420    _bfd_xcoff_is_local_label_name,
     4421    coff_get_lineno,
     4422    coff_find_nearest_line,
     4423    coff_bfd_make_debug_symbol,
     4424    _bfd_generic_read_minisymbols,
     4425    _bfd_generic_minisymbol_to_symbol,
     4426
     4427    /* Reloc */
     4428    coff_get_reloc_upper_bound,
     4429    coff_canonicalize_reloc,
     4430    _bfd_xcoff_reloc_type_lookup,
     4431
     4432    /* Write */
     4433    coff_set_arch_mach,
     4434    coff_set_section_contents,
     4435
     4436    /* Link */
     4437    _bfd_xcoff_sizeof_headers,
     4438    bfd_generic_get_relocated_section_contents,
     4439    bfd_generic_relax_section,
     4440    _bfd_xcoff_bfd_link_hash_table_create,
     4441    _bfd_generic_link_hash_table_free,
     4442    _bfd_xcoff_bfd_link_add_symbols,
     4443    _bfd_generic_link_just_syms,
     4444    _bfd_xcoff_bfd_final_link,
     4445    _bfd_generic_link_split_section,
     4446    bfd_generic_gc_sections,
     4447    bfd_generic_merge_sections,
     4448    bfd_generic_discard_group,
     4449
     4450    /* Dynamic */
     4451    _bfd_xcoff_get_dynamic_symtab_upper_bound,
     4452    _bfd_xcoff_canonicalize_dynamic_symtab,
     4453    _bfd_xcoff_get_dynamic_reloc_upper_bound,
     4454    _bfd_xcoff_canonicalize_dynamic_reloc,
     4455
     4456    /* Opposite endian version, none exists */
     4457    NULL,
     4458
     4459    (void *) &bfd_pmac_xcoff_backend_data,
     4460  };
Note: See TracChangeset for help on using the changeset viewer.