Coverage Report

Created: 2026-04-04 08:16

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