Coverage Report

Created: 2023-06-29 07:09

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