Coverage Report

Created: 2026-05-11 07:54

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/binutils-gdb/bfd/coff64-rs6000.c
Line
Count
Source
1
/* BFD back-end for IBM RS/6000 "XCOFF64" files.
2
   Copyright (C) 2000-2026 Free Software Foundation, Inc.
3
   Written Clinton Popetz.
4
   Contributed by Cygnus Support.
5
6
   This file is part of BFD, the Binary File Descriptor library.
7
8
   This program is free software; you can redistribute it and/or modify
9
   it under the terms of the GNU General Public License as published by
10
   the Free Software Foundation; either version 3 of the License, or
11
   (at your option) any later version.
12
13
   This program is distributed in the hope that it will be useful,
14
   but WITHOUT ANY WARRANTY; without even the implied warranty of
15
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
   GNU General Public License for more details.
17
18
   You should have received a copy of the GNU General Public License
19
   along with this program; if not, write to the Free Software
20
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21
   MA 02110-1301, USA.  */
22
23
#include "sysdep.h"
24
#include "bfd.h"
25
#include "bfdlink.h"
26
#include "libbfd.h"
27
#include "coff/internal.h"
28
#include "coff/xcoff.h"
29
#include "coff/rs6k64.h"
30
#include "libcoff.h"
31
#include "libxcoff.h"
32
33
188k
#define GET_FILEHDR_SYMPTR H_GET_64
34
10
#define PUT_FILEHDR_SYMPTR H_PUT_64
35
721
#define GET_AOUTHDR_DATA_START H_GET_64
36
3
#define PUT_AOUTHDR_DATA_START H_PUT_64
37
721
#define GET_AOUTHDR_TEXT_START H_GET_64
38
3
#define PUT_AOUTHDR_TEXT_START H_PUT_64
39
721
#define GET_AOUTHDR_TSIZE H_GET_64
40
3
#define PUT_AOUTHDR_TSIZE H_PUT_64
41
721
#define GET_AOUTHDR_DSIZE H_GET_64
42
3
#define PUT_AOUTHDR_DSIZE H_PUT_64
43
721
#define GET_AOUTHDR_BSIZE H_GET_64
44
3
#define PUT_AOUTHDR_BSIZE H_PUT_64
45
721
#define GET_AOUTHDR_ENTRY H_GET_64
46
3
#define PUT_AOUTHDR_ENTRY H_PUT_64
47
47.0k
#define GET_SCNHDR_PADDR H_GET_64
48
70
#define PUT_SCNHDR_PADDR H_PUT_64
49
47.0k
#define GET_SCNHDR_VADDR H_GET_64
50
70
#define PUT_SCNHDR_VADDR H_PUT_64
51
47.0k
#define GET_SCNHDR_SIZE H_GET_64
52
70
#define PUT_SCNHDR_SIZE H_PUT_64
53
47.0k
#define GET_SCNHDR_SCNPTR H_GET_64
54
70
#define PUT_SCNHDR_SCNPTR H_PUT_64
55
47.0k
#define GET_SCNHDR_RELPTR H_GET_64
56
70
#define PUT_SCNHDR_RELPTR H_PUT_64
57
47.0k
#define GET_SCNHDR_LNNOPTR H_GET_64
58
70
#define PUT_SCNHDR_LNNOPTR H_PUT_64
59
47.0k
#define GET_SCNHDR_NRELOC H_GET_32
60
70
#define MAX_SCNHDR_NRELOC 0xffffffff
61
70
#define PUT_SCNHDR_NRELOC H_PUT_32
62
47.0k
#define GET_SCNHDR_NLNNO H_GET_32
63
70
#define MAX_SCNHDR_NLNNO 0xffffffff
64
70
#define PUT_SCNHDR_NLNNO H_PUT_32
65
#define GET_RELOC_VADDR H_GET_64
66
#define PUT_RELOC_VADDR H_PUT_64
67
68
#define COFF_FORCE_SYMBOLS_IN_STRINGS
69
#define COFF_DEBUG_STRING_WIDE_PREFIX
70
71
72
#define COFF_ADJUST_SCNHDR_OUT_POST(ABFD, INT, EXT)     \
73
70
  do                  \
74
70
    {                 \
75
70
      memset (((SCNHDR *) EXT)->s_pad, 0,       \
76
70
        sizeof (((SCNHDR *) EXT)->s_pad));      \
77
70
    }                  \
78
70
  while (0)
79
80
#define NO_COFF_LINENOS
81
82
#define coff_SWAP_lineno_in _bfd_xcoff64_swap_lineno_in
83
#define coff_SWAP_lineno_out _bfd_xcoff64_swap_lineno_out
84
85
static void _bfd_xcoff64_swap_lineno_in
86
  (bfd *, void *, void *);
87
static unsigned int _bfd_xcoff64_swap_lineno_out
88
  (bfd *, void *, void *);
89
static bool _bfd_xcoff64_put_symbol_name
90
  (struct bfd_link_info *, struct bfd_strtab_hash *,
91
   struct internal_syment *, const char *);
92
static bool _bfd_xcoff64_put_ldsymbol_name
93
  (bfd *, struct xcoff_loader_info *, struct internal_ldsym *, const char *);
94
static void _bfd_xcoff64_swap_sym_in
95
  (bfd *, void *, void *);
96
static unsigned int _bfd_xcoff64_swap_sym_out
97
  (bfd *, void *, void *);
98
static void _bfd_xcoff64_swap_aux_in
99
  (bfd *, void *, int, int, int, int, void *);
100
static unsigned int _bfd_xcoff64_swap_aux_out
101
  (bfd *, void *, int, int, int, int, void *);
102
static void xcoff64_swap_reloc_in
103
  (bfd *, void *, void *);
104
static unsigned int xcoff64_swap_reloc_out
105
  (bfd *, void *, void *);
106
extern bool _bfd_xcoff_mkobject
107
  (bfd *);
108
extern bool _bfd_xcoff_copy_private_bfd_data
109
  (bfd *, bfd *);
110
extern bool _bfd_xcoff_is_local_label_name
111
  (bfd *, const char *);
112
extern void xcoff64_rtype2howto
113
  (arelent *, struct internal_reloc *);
114
extern reloc_howto_type * xcoff64_reloc_type_lookup
115
  (bfd *, bfd_reloc_code_real_type);
116
extern bool _bfd_xcoff_slurp_armap
117
  (bfd *);
118
extern void *_bfd_xcoff_read_ar_hdr
119
  (bfd *);
120
extern bfd *_bfd_xcoff_openr_next_archived_file
121
  (bfd *, bfd *);
122
extern int _bfd_xcoff_stat_arch_elt
123
  (bfd *, struct stat *);
124
extern bool _bfd_xcoff_write_armap
125
  (bfd *, unsigned int, struct orl *, unsigned int, int);
126
extern bool _bfd_xcoff_write_archive_contents
127
  (bfd *);
128
extern int _bfd_xcoff_sizeof_headers
129
  (bfd *, struct bfd_link_info *);
130
extern void _bfd_xcoff_swap_sym_in
131
  (bfd *, void *, void *);
132
extern unsigned int _bfd_xcoff_swap_sym_out
133
  (bfd *, void *, void *);
134
extern void _bfd_xcoff_swap_aux_in
135
  (bfd *, void *, int, int, int, int, void *);
136
extern unsigned int _bfd_xcoff_swap_aux_out
137
  (bfd *, void *, int, int, int, int, void *);
138
static void xcoff64_swap_ldhdr_in
139
  (bfd *, const void *, struct internal_ldhdr *);
140
static void xcoff64_swap_ldhdr_out
141
  (bfd *, const struct internal_ldhdr *, void *d);
142
static void xcoff64_swap_ldsym_in
143
  (bfd *, const void *, struct internal_ldsym *);
144
static void xcoff64_swap_ldsym_out
145
  (bfd *, const struct internal_ldsym *, void *d);
146
static void xcoff64_swap_ldrel_in
147
  (bfd *, const void *, struct internal_ldrel *);
148
static void xcoff64_swap_ldrel_out
149
  (bfd *, const struct internal_ldrel *, void *d);
150
static bool xcoff64_ppc_relocate_section
151
  (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
152
   struct internal_reloc *, struct internal_syment *,
153
   asection **);
154
static bool xcoff64_slurp_armap
155
  (bfd *);
156
static bfd_cleanup xcoff64_archive_p
157
  (bfd *);
158
static bfd *xcoff64_openr_next_archived_file
159
  (bfd *, bfd *);
160
static int xcoff64_sizeof_headers
161
  (bfd *, struct bfd_link_info *);
162
static asection *xcoff64_create_csect_from_smclas
163
  (bfd *, union internal_auxent *, const char *);
164
static bool xcoff64_is_lineno_count_overflow
165
  (bfd *, bfd_vma);
166
static bool xcoff64_is_reloc_count_overflow
167
  (bfd *, bfd_vma);
168
static bfd_vma xcoff64_loader_symbol_offset
169
  (bfd *, struct internal_ldhdr *);
170
static bfd_vma xcoff64_loader_reloc_offset
171
  (bfd *, struct internal_ldhdr *);
172
static bool xcoff64_generate_rtinit
173
  (bfd *, const char *, const char *, bool);
174
static bool xcoff64_bad_format_hook
175
  (bfd *, void *);
176
177
/* Relocation functions */
178
static xcoff_reloc_function xcoff64_reloc_type_br;
179
180
xcoff_reloc_function *const xcoff64_calculate_relocation[] =
181
{
182
  xcoff_reloc_type_pos,  /* R_POS     (0x00) */
183
  xcoff_reloc_type_neg,  /* R_NEG     (0x01) */
184
  xcoff_reloc_type_rel,  /* R_REL     (0x02) */
185
  xcoff_reloc_type_toc,  /* R_TOC     (0x03) */
186
  xcoff_reloc_type_toc,  /* R_TRL     (0x04) */
187
  xcoff_reloc_type_toc,  /* R_GL      (0x05) */
188
  xcoff_reloc_type_toc,  /* R_TCL     (0x06) */
189
  xcoff_reloc_type_fail, /*           (0x07) */
190
  xcoff_reloc_type_ba,   /* R_BA      (0x08) */
191
  xcoff_reloc_type_fail, /*           (0x09) */
192
  xcoff64_reloc_type_br, /* R_BR      (0x0a) */
193
  xcoff_reloc_type_fail, /*           (0x0b) */
194
  xcoff_reloc_type_pos,  /* R_RL      (0x0c) */
195
  xcoff_reloc_type_pos,  /* R_RLA     (0x0d) */
196
  xcoff_reloc_type_fail, /*           (0x0e) */
197
  xcoff_reloc_type_noop, /* R_REF     (0x0f) */
198
  xcoff_reloc_type_fail, /*           (0x10) */
199
  xcoff_reloc_type_fail, /*           (0x11) */
200
  xcoff_reloc_type_fail, /*           (0x12) */
201
  xcoff_reloc_type_toc,  /* R_TRLA    (0x13) */
202
  xcoff_reloc_type_fail, /* R_RRTBI   (0x14) */
203
  xcoff_reloc_type_fail, /* R_RRTBA   (0x15) */
204
  xcoff_reloc_type_ba,   /* R_CAI     (0x16) */
205
  xcoff_reloc_type_crel, /* R_CREL    (0x17) */
206
  xcoff_reloc_type_ba,   /* R_RBA     (0x18) */
207
  xcoff_reloc_type_ba,   /* R_RBAC    (0x19) */
208
  xcoff64_reloc_type_br, /* R_RBR     (0x1a) */
209
  xcoff_reloc_type_ba,   /* R_RBRC    (0x1b) */
210
  xcoff_reloc_type_fail, /*           (0x1c) */
211
  xcoff_reloc_type_fail, /*           (0x1d) */
212
  xcoff_reloc_type_fail, /*           (0x1e) */
213
  xcoff_reloc_type_fail, /*           (0x1f) */
214
  xcoff_reloc_type_tls,  /* R_TLS     (0x20) */
215
  xcoff_reloc_type_tls,  /* R_TLS_IE  (0x21) */
216
  xcoff_reloc_type_tls,  /* R_TLS_LD  (0x22) */
217
  xcoff_reloc_type_tls,  /* R_TLS_LE  (0x23) */
218
  xcoff_reloc_type_tls,  /* R_TLSM    (0x24) */
219
  xcoff_reloc_type_tls,  /* R_TLSML   (0x25) */
220
  xcoff_reloc_type_fail, /*           (0x26) */
221
  xcoff_reloc_type_fail, /*           (0x27) */
222
  xcoff_reloc_type_fail, /*           (0x28) */
223
  xcoff_reloc_type_fail, /*           (0x29) */
224
  xcoff_reloc_type_fail, /*           (0x2a) */
225
  xcoff_reloc_type_fail, /*           (0x2b) */
226
  xcoff_reloc_type_fail, /*           (0x2c) */
227
  xcoff_reloc_type_fail, /*           (0x2d) */
228
  xcoff_reloc_type_fail, /*           (0x2e) */
229
  xcoff_reloc_type_fail, /*           (0x2f) */
230
  xcoff_reloc_type_toc, /* R_TOCU    (0x30) */
231
  xcoff_reloc_type_toc, /* R_TOCL    (0x31) */
232
};
233
234
/* coffcode.h needs these to be defined.  */
235
/* Internalcoff.h and coffcode.h modify themselves based on these flags.  */
236
#define XCOFF64
237
#define RS6000COFF_C 1
238
239
#define SELECT_RELOC(internal, howto)         \
240
0
  {                 \
241
0
    internal.r_type = howto->type;          \
242
0
    internal.r_size =             \
243
0
      ((howto->complain_on_overflow == complain_overflow_signed    \
244
0
  ? 0x80                \
245
0
  : 0)               \
246
0
       | (howto->bitsize - 1));           \
247
0
  }
248
249
94.4k
#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
250
#define COFF_LONG_FILENAMES
251
#define NO_COFF_SYMBOLS
252
5
#define RTYPE2HOWTO(cache_ptr, dst) xcoff64_rtype2howto (cache_ptr, dst)
253
1.71k
#define coff_mkobject _bfd_xcoff_mkobject
254
#define coff_bfd_copy_private_bfd_data _bfd_xcoff_copy_private_bfd_data
255
#define coff_bfd_is_local_label_name _bfd_xcoff_is_local_label_name
256
#define coff_bfd_reloc_type_lookup xcoff64_reloc_type_lookup
257
#define coff_bfd_reloc_name_lookup xcoff64_reloc_name_lookup
258
#ifdef AIX_CORE
259
extern bfd_cleanup rs6000coff_core_p
260
  (bfd *abfd);
261
extern bool rs6000coff_core_file_matches_executable_p
262
  (bfd *cbfd, bfd *ebfd);
263
extern char *rs6000coff_core_file_failing_command
264
  (bfd *abfd);
265
extern int rs6000coff_core_file_failing_signal
266
  (bfd *abfd);
267
#define CORE_FILE_P rs6000coff_core_p
268
#define coff_core_file_failing_command \
269
  rs6000coff_core_file_failing_command
270
#define coff_core_file_failing_signal \
271
  rs6000coff_core_file_failing_signal
272
#define coff_core_file_matches_executable_p \
273
  rs6000coff_core_file_matches_executable_p
274
#define coff_core_file_pid \
275
  _bfd_nocore_core_file_pid
276
#else
277
#define CORE_FILE_P _bfd_dummy_target
278
#define coff_core_file_failing_command \
279
  _bfd_nocore_core_file_failing_command
280
#define coff_core_file_failing_signal \
281
  _bfd_nocore_core_file_failing_signal
282
#define coff_core_file_matches_executable_p \
283
  _bfd_nocore_core_file_matches_executable_p
284
#define coff_core_file_pid \
285
  _bfd_nocore_core_file_pid
286
#endif
287
#define coff_SWAP_sym_in _bfd_xcoff64_swap_sym_in
288
#define coff_SWAP_sym_out _bfd_xcoff64_swap_sym_out
289
#define coff_SWAP_aux_in _bfd_xcoff64_swap_aux_in
290
#define coff_SWAP_aux_out _bfd_xcoff64_swap_aux_out
291
#define coff_swap_reloc_in xcoff64_swap_reloc_in
292
0
#define coff_swap_reloc_out xcoff64_swap_reloc_out
293
#define NO_COFF_RELOCS
294
295
#ifndef bfd_pe_print_pdata
296
#define bfd_pe_print_pdata  NULL
297
#endif
298
299
#include "coffcode.h"
300
301
/* For XCOFF64, the effective width of symndx changes depending on
302
   whether we are the first entry.  Sigh.  */
303
static void
304
_bfd_xcoff64_swap_lineno_in (bfd *abfd, void *ext1, void *in1)
305
31.4k
{
306
31.4k
  LINENO *ext = (LINENO *) ext1;
307
31.4k
  struct internal_lineno *in = (struct internal_lineno *) in1;
308
309
31.4k
  in->l_lnno = H_GET_32 (abfd, (ext->l_lnno));
310
31.4k
  if (in->l_lnno == 0)
311
14.9k
    in->l_addr.l_symndx = H_GET_32 (abfd, ext->l_addr.l_symndx);
312
16.5k
  else
313
16.5k
    in->l_addr.l_paddr = H_GET_64 (abfd, ext->l_addr.l_paddr);
314
31.4k
}
315
316
static unsigned int
317
_bfd_xcoff64_swap_lineno_out (bfd *abfd, void *inp, void *outp)
318
0
{
319
0
  struct internal_lineno *in = (struct internal_lineno *) inp;
320
0
  struct external_lineno *ext = (struct external_lineno *) outp;
321
322
0
  H_PUT_32 (abfd, in->l_addr.l_symndx, ext->l_addr.l_symndx);
323
0
  H_PUT_32 (abfd, in->l_lnno, (ext->l_lnno));
324
325
0
  if (in->l_lnno == 0)
326
0
    H_PUT_32 (abfd, in->l_addr.l_symndx, ext->l_addr.l_symndx);
327
0
  else
328
0
    H_PUT_64 (abfd, in->l_addr.l_paddr, ext->l_addr.l_paddr);
329
330
0
  return bfd_coff_linesz (abfd);
331
0
}
332
333
static void
334
_bfd_xcoff64_swap_sym_in (bfd *abfd, void *ext1, void *in1)
335
11.8k
{
336
11.8k
  struct external_syment *ext = (struct external_syment *) ext1;
337
11.8k
  struct internal_syment *in = (struct internal_syment *) in1;
338
339
11.8k
  in->_n._n_n._n_zeroes = 0;
340
11.8k
  in->_n._n_n._n_offset = H_GET_32 (abfd, ext->e_offset);
341
11.8k
  in->n_value = H_GET_64 (abfd, ext->e_value);
342
11.8k
  in->n_scnum = (short) H_GET_16 (abfd, ext->e_scnum);
343
11.8k
  in->n_type = H_GET_16 (abfd, ext->e_type);
344
11.8k
  in->n_sclass = H_GET_8 (abfd, ext->e_sclass);
345
11.8k
  in->n_numaux = H_GET_8 (abfd, ext->e_numaux);
346
11.8k
}
347
348
static unsigned int
349
_bfd_xcoff64_swap_sym_out (bfd *abfd, void *inp, void *extp)
350
23
{
351
23
  struct internal_syment *in = (struct internal_syment *) inp;
352
23
  struct external_syment *ext = (struct external_syment *) extp;
353
354
23
  H_PUT_32 (abfd, in->_n._n_n._n_offset, ext->e_offset);
355
23
  H_PUT_64 (abfd, in->n_value, ext->e_value);
356
23
  H_PUT_16 (abfd, in->n_scnum, ext->e_scnum);
357
23
  H_PUT_16 (abfd, in->n_type, ext->e_type);
358
23
  H_PUT_8 (abfd, in->n_sclass, ext->e_sclass);
359
23
  H_PUT_8 (abfd, in->n_numaux, ext->e_numaux);
360
23
  return bfd_coff_symesz (abfd);
361
23
}
362
363
static void
364
_bfd_xcoff64_swap_aux_in (bfd *abfd, void *ext1, int type ATTRIBUTE_UNUSED,
365
        int in_class, int indx, int numaux, void *in1)
366
37.7k
{
367
37.7k
  union external_auxent *ext = (union external_auxent *) ext1;
368
37.7k
  union internal_auxent *in = (union internal_auxent *) in1;
369
37.7k
  unsigned char auxtype;
370
371
37.7k
  switch (in_class)
372
37.7k
    {
373
18.2k
    default:
374
18.2k
      _bfd_error_handler
375
  /* xgettext: c-format */
376
18.2k
  (_("%pB: unsupported swap_aux_in for storage class %#x"),
377
18.2k
   abfd, (unsigned int) in_class);
378
18.2k
      bfd_set_error (bfd_error_bad_value);
379
18.2k
      break;
380
381
4.50k
    case C_FILE:
382
4.50k
      auxtype = H_GET_8 (abfd, ext->x_file.x_auxtype);
383
4.50k
      if (auxtype != _AUX_FILE)
384
4.28k
  goto error;
385
386
224
      if (ext->x_file.x_n.x_n.x_zeroes[0] == 0)
387
53
  {
388
53
    in->x_file.x_n.x_n.x_zeroes = 0;
389
53
    in->x_file.x_n.x_n.x_offset =
390
53
      H_GET_32 (abfd, ext->x_file.x_n.x_n.x_offset);
391
53
  }
392
171
      else
393
171
  memcpy (in->x_file.x_n.x_fname, ext->x_file.x_n.x_fname, FILNMLEN);
394
224
      in->x_file.x_ftype = H_GET_8 (abfd, ext->x_file.x_ftype);
395
224
      break;
396
397
      /* RS/6000 "csect" auxents.
398
         There is always a CSECT auxiliary entry. But functions can
399
         have FCN and EXCEPT ones too. In this case, CSECT is always the last
400
         one.
401
         For now, we only support FCN types.  */
402
1.78k
    case C_EXT:
403
4.79k
    case C_AIX_WEAKEXT:
404
5.46k
    case C_HIDEXT:
405
5.46k
      if (indx + 1 == numaux)
406
416
  {
407
    /* C_EXT can have several aux enties. But the _AUX_CSECT is always
408
       the last one.  */
409
416
    auxtype = H_GET_8 (abfd, ext->x_csect.x_auxtype);
410
416
    if (auxtype != _AUX_CSECT)
411
411
      goto error;
412
413
5
    bfd_vma h = H_GET_32 (abfd, ext->x_csect.x_scnlen_hi);
414
5
    bfd_vma l = H_GET_32 (abfd, ext->x_csect.x_scnlen_lo);
415
416
5
    in->x_csect.x_scnlen.u64 = h << 32 | (l & 0xffffffff);
417
418
5
    in->x_csect.x_parmhash = H_GET_32 (abfd, ext->x_csect.x_parmhash);
419
5
    in->x_csect.x_snhash = H_GET_16 (abfd, ext->x_csect.x_snhash);
420
    /* We don't have to hack bitfields in x_smtyp because it's
421
       defined by shifts-and-ands, which are equivalent on all
422
       byte orders.  */
423
5
    in->x_csect.x_smtyp = H_GET_8 (abfd, ext->x_csect.x_smtyp);
424
5
    in->x_csect.x_smclas = H_GET_8 (abfd, ext->x_csect.x_smclas);
425
5
  }
426
5.05k
      else
427
5.05k
  {
428
    /* It can also be a _AUX_EXCEPT entry. But it's not supported
429
       for now. */
430
5.05k
    auxtype = H_GET_8 (abfd, ext->x_fcn.x_auxtype);
431
5.05k
    if (auxtype != _AUX_FCN)
432
5.00k
      goto error;
433
434
44
    in->x_sym.x_fcnary.x_fcn.x_lnnoptr
435
44
      = H_GET_64 (abfd, ext->x_fcn.x_lnnoptr);
436
44
    in->x_sym.x_misc.x_fsize
437
44
      = H_GET_32 (abfd, ext->x_fcn.x_fsize);
438
44
    in->x_sym.x_fcnary.x_fcn.x_endndx.u32
439
44
      = H_GET_32 (abfd, ext->x_fcn.x_endndx);
440
44
  }
441
49
      break;
442
443
1.20k
    case C_STAT:
444
1.20k
      _bfd_error_handler
445
  /* xgettext: c-format */
446
1.20k
  (_("%pB: C_STAT isn't supported by XCOFF64"),
447
1.20k
   abfd);
448
1.20k
      bfd_set_error (bfd_error_bad_value);
449
1.20k
      break;
450
451
2.64k
    case C_BLOCK:
452
4.55k
    case C_FCN:
453
4.55k
      auxtype = H_GET_8 (abfd, ext->x_sym.x_auxtype);
454
4.55k
      if (auxtype != _AUX_SYM)
455
4.33k
  goto error;
456
457
215
      in->x_sym.x_misc.x_lnsz.x_lnno
458
215
  = H_GET_32 (abfd, ext->x_sym.x_lnno);
459
215
      break;
460
461
3.83k
    case C_DWARF:
462
3.83k
      auxtype = H_GET_8 (abfd, ext->x_sect.x_auxtype);
463
3.83k
      if (auxtype != _AUX_SECT)
464
3.77k
  goto error;
465
466
59
      in->x_sect.x_scnlen = H_GET_64 (abfd, ext->x_sect.x_scnlen);
467
59
      in->x_sect.x_nreloc = H_GET_64 (abfd, ext->x_sect.x_nreloc);
468
59
      break;
469
37.7k
    }
470
471
19.9k
  return;
472
473
19.9k
 error:
474
17.8k
  _bfd_error_handler
475
    /* xgettext: c-format */
476
17.8k
    (_("%pB: wrong auxtype %#x for storage class %#x"),
477
17.8k
     abfd, auxtype, (unsigned int) in_class);
478
17.8k
  bfd_set_error (bfd_error_bad_value);
479
480
481
17.8k
}
482
483
static unsigned int
484
_bfd_xcoff64_swap_aux_out (bfd *abfd, void *inp, int type ATTRIBUTE_UNUSED,
485
         int in_class, int indx, int numaux, void *extp)
486
235
{
487
235
  union internal_auxent *in = (union internal_auxent *) inp;
488
235
  union external_auxent *ext = (union external_auxent *) extp;
489
490
235
  memset (ext, 0, bfd_coff_auxesz (abfd));
491
235
  switch (in_class)
492
235
    {
493
0
    default:
494
0
      _bfd_error_handler
495
  /* xgettext: c-format */
496
0
  (_("%pB: unsupported swap_aux_out for storage class %#x"),
497
0
   abfd, (unsigned int) in_class);
498
0
      bfd_set_error (bfd_error_bad_value);
499
0
      break;
500
501
0
    case C_FILE:
502
0
      if (in->x_file.x_n.x_n.x_zeroes == 0)
503
0
  {
504
0
    H_PUT_32 (abfd, 0, ext->x_file.x_n.x_n.x_zeroes);
505
0
    H_PUT_32 (abfd, in->x_file.x_n.x_n.x_offset,
506
0
        ext->x_file.x_n.x_n.x_offset);
507
0
  }
508
0
      else
509
0
  memcpy (ext->x_file.x_n.x_fname, in->x_file.x_n.x_fname, FILNMLEN);
510
0
      H_PUT_8 (abfd, in->x_file.x_ftype, ext->x_file.x_ftype);
511
0
      H_PUT_8 (abfd, _AUX_FILE, ext->x_file.x_auxtype);
512
0
      break;
513
514
      /* RS/6000 "csect" auxents.
515
         There is always a CSECT auxiliary entry. But functions can
516
         have FCN and EXCEPT ones too. In this case, CSECT is always the last
517
         one.
518
         For now, we only support FCN types.  */
519
0
    case C_EXT:
520
228
    case C_AIX_WEAKEXT:
521
228
    case C_HIDEXT:
522
228
      if (indx + 1 == numaux)
523
2
  {
524
2
    bfd_vma temp;
525
526
2
    temp = in->x_csect.x_scnlen.u64 & 0xffffffff;
527
2
    H_PUT_32 (abfd, temp, ext->x_csect.x_scnlen_lo);
528
2
    temp = in->x_csect.x_scnlen.u64 >> 32;
529
2
    H_PUT_32 (abfd, temp, ext->x_csect.x_scnlen_hi);
530
2
    H_PUT_32 (abfd, in->x_csect.x_parmhash, ext->x_csect.x_parmhash);
531
2
    H_PUT_16 (abfd, in->x_csect.x_snhash, ext->x_csect.x_snhash);
532
    /* We don't have to hack bitfields in x_smtyp because it's
533
       defined by shifts-and-ands, which are equivalent on all
534
       byte orders.  */
535
2
    H_PUT_8 (abfd, in->x_csect.x_smtyp, ext->x_csect.x_smtyp);
536
2
    H_PUT_8 (abfd, in->x_csect.x_smclas, ext->x_csect.x_smclas);
537
2
    H_PUT_8 (abfd, _AUX_CSECT, ext->x_csect.x_auxtype);
538
2
  }
539
226
      else
540
226
  {
541
226
    H_PUT_64 (abfd, in->x_sym.x_fcnary.x_fcn.x_lnnoptr,
542
226
        ext->x_fcn.x_lnnoptr);
543
226
    H_PUT_32 (abfd, in->x_sym.x_misc.x_fsize, ext->x_fcn.x_fsize);
544
226
    H_PUT_32 (abfd, in->x_sym.x_fcnary.x_fcn.x_endndx.u32,
545
226
        ext->x_fcn.x_endndx);
546
226
    H_PUT_8 (abfd, _AUX_FCN, ext->x_csect.x_auxtype);
547
226
  }
548
228
      break;
549
550
2
    case C_STAT:
551
2
      _bfd_error_handler
552
  /* xgettext: c-format */
553
2
  (_("%pB: C_STAT isn't supported by XCOFF64"),
554
2
   abfd);
555
2
      bfd_set_error (bfd_error_bad_value);
556
2
      break;
557
558
0
    case C_BLOCK:
559
0
    case C_FCN:
560
0
      H_PUT_32 (abfd, in->x_sym.x_misc.x_lnsz.x_lnno, ext->x_sym.x_lnno);
561
0
      H_PUT_8 (abfd, _AUX_SYM, ext->x_sym.x_auxtype);
562
0
      break;
563
564
5
    case C_DWARF:
565
5
      H_PUT_64 (abfd, in->x_sect.x_scnlen, ext->x_sect.x_scnlen);
566
5
      H_PUT_64 (abfd, in->x_sect.x_nreloc, ext->x_sect.x_nreloc);
567
5
      H_PUT_8 (abfd, _AUX_SECT, ext->x_sect.x_auxtype);
568
5
      break;
569
235
    }
570
571
235
  return bfd_coff_auxesz (abfd);
572
235
}
573
574
static bool
575
_bfd_xcoff64_put_symbol_name (struct bfd_link_info *info,
576
            struct bfd_strtab_hash *strtab,
577
            struct internal_syment *sym,
578
            const char *name)
579
0
{
580
0
  bool hash;
581
0
  bfd_size_type indx;
582
583
0
  hash = !info->traditional_format;
584
0
  indx = _bfd_stringtab_add (strtab, name, hash, false);
585
586
0
  if (indx == (bfd_size_type) -1)
587
0
    return false;
588
589
0
  sym->_n._n_n._n_zeroes = 0;
590
0
  sym->_n._n_n._n_offset = STRING_SIZE_SIZE + indx;
591
592
0
  return true;
593
0
}
594
595
static bool
596
_bfd_xcoff64_put_ldsymbol_name (bfd *abfd ATTRIBUTE_UNUSED,
597
        struct xcoff_loader_info *ldinfo,
598
        struct internal_ldsym *ldsym,
599
        const char *name)
600
0
{
601
0
  size_t len;
602
0
  len = strlen (name);
603
604
0
  if (ldinfo->string_size + len + 3 > ldinfo->string_alc)
605
0
    {
606
0
      bfd_size_type newalc;
607
0
      char *newstrings;
608
609
0
      newalc = ldinfo->string_alc * 2;
610
0
      if (newalc == 0)
611
0
  newalc = 32;
612
0
      while (ldinfo->string_size + len + 3 > newalc)
613
0
  newalc *= 2;
614
615
0
      newstrings = bfd_realloc (ldinfo->strings, newalc);
616
0
      if (newstrings == NULL)
617
0
  {
618
0
    ldinfo->failed = true;
619
0
    return false;
620
0
  }
621
0
      ldinfo->string_alc = newalc;
622
0
      ldinfo->strings = newstrings;
623
0
    }
624
625
0
  ldinfo->strings[ldinfo->string_size] = ((len + 1) >> 8) & 0xff;
626
0
  ldinfo->strings[ldinfo->string_size + 1] = ((len + 1)) & 0xff;
627
0
  strcpy (ldinfo->strings + ldinfo->string_size + 2, name);
628
0
  ldsym->_l._l_l._l_zeroes = 0;
629
0
  ldsym->_l._l_l._l_offset = ldinfo->string_size + 2;
630
0
  ldinfo->string_size += len + 3;
631
632
0
  return true;
633
0
}
634
635
/* Routines to swap information in the XCOFF .loader section.  If we
636
   ever need to write an XCOFF loader, this stuff will need to be
637
   moved to another file shared by the linker (which XCOFF calls the
638
   ``binder'') and the loader.  */
639
640
/* Swap in the ldhdr structure.  */
641
642
static void
643
xcoff64_swap_ldhdr_in (bfd *abfd,
644
           const void *s,
645
           struct internal_ldhdr *dst)
646
0
{
647
0
  const struct external_ldhdr *src = (const struct external_ldhdr *) s;
648
649
0
  dst->l_version = bfd_get_32 (abfd, src->l_version);
650
0
  dst->l_nsyms = bfd_get_32 (abfd, src->l_nsyms);
651
0
  dst->l_nreloc = bfd_get_32 (abfd, src->l_nreloc);
652
0
  dst->l_istlen = bfd_get_32 (abfd, src->l_istlen);
653
0
  dst->l_nimpid = bfd_get_32 (abfd, src->l_nimpid);
654
0
  dst->l_stlen = bfd_get_32 (abfd, src->l_stlen);
655
0
  dst->l_impoff = bfd_get_64 (abfd, src->l_impoff);
656
0
  dst->l_stoff = bfd_get_64 (abfd, src->l_stoff);
657
0
  dst->l_symoff = bfd_get_64 (abfd, src->l_symoff);
658
0
  dst->l_rldoff = bfd_get_64 (abfd, src->l_rldoff);
659
0
}
660
661
/* Swap out the ldhdr structure.  */
662
663
static void
664
xcoff64_swap_ldhdr_out (bfd *abfd, const struct internal_ldhdr *src, void *d)
665
0
{
666
0
  struct external_ldhdr *dst = (struct external_ldhdr *) d;
667
668
0
  bfd_put_32 (abfd, (bfd_vma) src->l_version, dst->l_version);
669
0
  bfd_put_32 (abfd, src->l_nsyms, dst->l_nsyms);
670
0
  bfd_put_32 (abfd, src->l_nreloc, dst->l_nreloc);
671
0
  bfd_put_32 (abfd, src->l_istlen, dst->l_istlen);
672
0
  bfd_put_32 (abfd, src->l_nimpid, dst->l_nimpid);
673
0
  bfd_put_32 (abfd, src->l_stlen, dst->l_stlen);
674
0
  bfd_put_64 (abfd, src->l_impoff, dst->l_impoff);
675
0
  bfd_put_64 (abfd, src->l_stoff, dst->l_stoff);
676
0
  bfd_put_64 (abfd, src->l_symoff, dst->l_symoff);
677
0
  bfd_put_64 (abfd, src->l_rldoff, dst->l_rldoff);
678
0
}
679
680
/* Swap in the ldsym structure.  */
681
682
static void
683
xcoff64_swap_ldsym_in (bfd *abfd, const void *s, struct internal_ldsym *dst)
684
0
{
685
0
  const struct external_ldsym *src = (const struct external_ldsym *) s;
686
  /* XCOFF64 does not use l_zeroes like XCOFF32
687
     Set the internal l_zeroes to 0 so the common 32/64 code uses l_value
688
     as an offset into the loader symbol table.  */
689
0
  dst->_l._l_l._l_zeroes = 0;
690
0
  dst->_l._l_l._l_offset = bfd_get_32 (abfd, src->l_offset);
691
0
  dst->l_value = bfd_get_64 (abfd, src->l_value);
692
0
  dst->l_scnum = bfd_get_16 (abfd, src->l_scnum);
693
0
  dst->l_smtype = bfd_get_8 (abfd, src->l_smtype);
694
0
  dst->l_smclas = bfd_get_8 (abfd, src->l_smclas);
695
0
  dst->l_ifile = bfd_get_32 (abfd, src->l_ifile);
696
0
  dst->l_parm = bfd_get_32 (abfd, src->l_parm);
697
0
}
698
699
/* Swap out the ldsym structure.  */
700
701
static void
702
xcoff64_swap_ldsym_out (bfd *abfd, const struct internal_ldsym *src, void *d)
703
0
{
704
0
  struct external_ldsym *dst = (struct external_ldsym *) d;
705
706
0
  bfd_put_64 (abfd, src->l_value, dst->l_value);
707
0
  bfd_put_32 (abfd, (bfd_vma) src->_l._l_l._l_offset, dst->l_offset);
708
0
  bfd_put_16 (abfd, (bfd_vma) src->l_scnum, dst->l_scnum);
709
0
  bfd_put_8 (abfd, src->l_smtype, dst->l_smtype);
710
0
  bfd_put_8 (abfd, src->l_smclas, dst->l_smclas);
711
0
  bfd_put_32 (abfd, src->l_ifile, dst->l_ifile);
712
0
  bfd_put_32 (abfd, src->l_parm, dst->l_parm);
713
0
}
714
715
static void
716
xcoff64_swap_reloc_in (bfd *abfd, void *s, void *d)
717
5
{
718
5
  struct external_reloc *src = (struct external_reloc *) s;
719
5
  struct internal_reloc *dst = (struct internal_reloc *) d;
720
721
5
  memset (dst, 0, sizeof (struct internal_reloc));
722
723
5
  dst->r_vaddr = bfd_get_64 (abfd, src->r_vaddr);
724
5
  dst->r_symndx = bfd_get_32 (abfd, src->r_symndx);
725
5
  dst->r_size = bfd_get_8 (abfd, src->r_size);
726
5
  dst->r_type = bfd_get_8 (abfd, src->r_type);
727
5
}
728
729
static unsigned int
730
xcoff64_swap_reloc_out (bfd *abfd, void *s, void *d)
731
0
{
732
0
  struct internal_reloc *src = (struct internal_reloc *) s;
733
0
  struct external_reloc *dst = (struct external_reloc *) d;
734
735
0
  bfd_put_64 (abfd, src->r_vaddr, dst->r_vaddr);
736
0
  bfd_put_32 (abfd, src->r_symndx, dst->r_symndx);
737
0
  bfd_put_8 (abfd, src->r_type, dst->r_type);
738
0
  bfd_put_8 (abfd, src->r_size, dst->r_size);
739
740
0
  return bfd_coff_relsz (abfd);
741
0
}
742
743
/* Swap in the ldrel structure.  */
744
745
static void
746
xcoff64_swap_ldrel_in (bfd *abfd, const void *s, struct internal_ldrel *dst)
747
0
{
748
0
  const struct external_ldrel *src = (const struct external_ldrel *) s;
749
750
0
  dst->l_vaddr = bfd_get_64 (abfd, src->l_vaddr);
751
0
  dst->l_symndx = bfd_get_32 (abfd, src->l_symndx);
752
0
  dst->l_rtype = bfd_get_16 (abfd, src->l_rtype);
753
0
  dst->l_rsecnm = bfd_get_16 (abfd, src->l_rsecnm);
754
0
}
755
756
/* Swap out the ldrel structure.  */
757
758
static void
759
xcoff64_swap_ldrel_out (bfd *abfd, const struct internal_ldrel *src, void *d)
760
0
{
761
0
  struct external_ldrel *dst = (struct external_ldrel *) d;
762
763
0
  bfd_put_64 (abfd, src->l_vaddr, dst->l_vaddr);
764
0
  bfd_put_16 (abfd, (bfd_vma) src->l_rtype, dst->l_rtype);
765
0
  bfd_put_16 (abfd, (bfd_vma) src->l_rsecnm, dst->l_rsecnm);
766
0
  bfd_put_32 (abfd, src->l_symndx, dst->l_symndx);
767
0
}
768
769
770
static bfd_reloc_status_type
771
xcoff64_reloc_type_br (bfd *input_bfd,
772
           asection *input_section,
773
           bfd *output_bfd ATTRIBUTE_UNUSED,
774
           struct internal_reloc *rel,
775
           struct internal_syment *sym ATTRIBUTE_UNUSED,
776
           struct reloc_howto_struct *howto,
777
           bfd_vma val,
778
           bfd_vma addend,
779
           bfd_vma *relocation,
780
           bfd_byte *contents,
781
           struct bfd_link_info *info)
782
0
{
783
0
  struct xcoff_link_hash_entry *h;
784
0
  bfd_vma section_offset;
785
0
  struct xcoff_stub_hash_entry *stub_entry = NULL;
786
0
  enum xcoff_stub_type stub_type;
787
788
0
  if ((unsigned long) rel->r_symndx >= obj_raw_syment_count (input_bfd))
789
0
    return bfd_reloc_undefined;
790
791
0
  h = obj_xcoff_sym_hashes (input_bfd)[rel->r_symndx];
792
0
  section_offset = rel->r_vaddr - input_section->vma;
793
794
  /* If we see an R_BR or R_RBR reloc which is jumping to global
795
     linkage code, and it is followed by an appropriate cror nop
796
     instruction, we replace the cror with ld r2,40(r1).  This
797
     restores the TOC after the glink code.  Contrariwise, if the
798
     call is followed by a ld r2,40(r1), but the call is not
799
     going to global linkage code, we can replace the load with a
800
     cror.  */
801
0
  if (NULL != h
802
0
      && (bfd_link_hash_defined == h->root.type
803
0
    || bfd_link_hash_defweak == h->root.type)
804
0
      && section_offset + 8 <= input_section->size)
805
0
    {
806
0
      bfd_byte *pnext;
807
0
      unsigned long next;
808
809
0
      pnext = contents + section_offset + 4;
810
0
      next = bfd_get_32 (input_bfd, pnext);
811
812
      /* The _ptrgl function is magic.  It is used by the AIX compiler to call
813
   a function through a pointer.  */
814
0
      if (h->smclas == XMC_GL || strcmp (h->root.root.string, "._ptrgl") == 0)
815
0
  {
816
0
    if (next == 0x4def7b82      /* cror 15,15,15  */
817
0
        || next == 0x4ffffb82      /* cror 31,31,31  */
818
0
        || next == 0x60000000)     /* ori  r0,r0,0   */
819
0
      bfd_put_32 (input_bfd, 0xe8410028, pnext);  /* ld r2,40(r1) */
820
0
  }
821
0
      else
822
0
  {
823
0
    if (next == 0xe8410028)     /* ld r2,40(r1)   */
824
0
      bfd_put_32 (input_bfd, 0x60000000, pnext);  /* ori r0,r0,0    */
825
0
  }
826
0
    }
827
0
  else if (NULL != h && bfd_link_hash_undefined == h->root.type)
828
0
    {
829
      /* Normally, this relocation is against a defined symbol.  In the
830
   case where this is a partial link and the output section offset
831
   is greater than 2^25, the linker will return an invalid error
832
   message that the relocation has been truncated.  Yes it has been
833
   truncated but no it not important.  For this case, disable the
834
   overflow checking. */
835
0
      howto->complain_on_overflow = complain_overflow_dont;
836
0
    }
837
838
  /* Check if a stub is needed.  */
839
0
  stub_type = bfd_xcoff_type_of_stub (input_section, rel, val, h);
840
0
  if (stub_type != xcoff_stub_none)
841
0
    {
842
0
      asection *stub_csect;
843
844
0
      stub_entry = bfd_xcoff_get_stub_entry (input_section, h, info);
845
0
      if (stub_entry == NULL)
846
0
  {
847
0
    _bfd_error_handler (_("Unable to find the stub entry targeting %s"),
848
0
            h->root.root.string);
849
0
    return bfd_reloc_undefined;
850
0
  }
851
852
0
      stub_csect = stub_entry->hcsect->root.u.def.section;
853
0
      val = (stub_entry->stub_offset
854
0
       + stub_csect->output_section->vma
855
0
       + stub_csect->output_offset);
856
0
    }
857
858
  /* The original PC-relative relocation is biased by -r_vaddr, so adding
859
     the value below will give the absolute target address.  */
860
0
  *relocation = val + addend + rel->r_vaddr;
861
862
0
  howto->src_mask &= ~3;
863
0
  howto->dst_mask = howto->src_mask;
864
865
0
  if (h != NULL
866
0
      && (h->root.type == bfd_link_hash_defined
867
0
    || h->root.type == bfd_link_hash_defweak)
868
0
      && bfd_is_abs_section (h->root.u.def.section)
869
0
      && section_offset + 4 <= input_section->size)
870
0
    {
871
0
      bfd_byte *ptr;
872
0
      bfd_vma insn;
873
874
      /* Turn the relative branch into an absolute one by setting the
875
   AA bit.  */
876
0
      ptr = contents + section_offset;
877
0
      insn = bfd_get_32 (input_bfd, ptr);
878
0
      insn |= 2;
879
0
      bfd_put_32 (input_bfd, insn, ptr);
880
881
      /* Make the howto absolute too.  */
882
0
      howto->pc_relative = false;
883
0
      howto->complain_on_overflow = complain_overflow_bitfield;
884
0
    }
885
0
  else
886
0
    {
887
      /* Use a PC-relative howto and subtract the instruction's address
888
   from the target address we calculated above.  */
889
0
      howto->pc_relative = true;
890
0
      *relocation -= (input_section->output_section->vma
891
0
          + input_section->output_offset
892
0
          + section_offset);
893
0
    }
894
0
  return bfd_reloc_ok;
895
0
}
896
897
898

899
/* The XCOFF reloc table.
900
   Cf xcoff_howto_table comments.  */
901
902
reloc_howto_type xcoff64_howto_table[] =
903
{
904
  /* 0x00: Standard 64 bit relocation.  */
905
  HOWTO (R_POS,     /* type */
906
   0,     /* rightshift */
907
   8,     /* size */
908
   64,      /* bitsize */
909
   false,     /* pc_relative */
910
   0,     /* bitpos */
911
   complain_overflow_bitfield, /* complain_on_overflow */
912
   0,     /* special_function */
913
   "R_POS_64",    /* name */
914
   true,      /* partial_inplace */
915
   MINUS_ONE,   /* src_mask */
916
   MINUS_ONE,   /* dst_mask */
917
   false),    /* pcrel_offset */
918
919
  /* 0x01: 64 bit relocation, but store negative value.  */
920
  HOWTO (R_NEG,     /* type */
921
   0,     /* rightshift */
922
   -8,      /* size */
923
   64,      /* bitsize */
924
   false,     /* pc_relative */
925
   0,     /* bitpos */
926
   complain_overflow_bitfield, /* complain_on_overflow */
927
   0,     /* special_function */
928
   "R_NEG",   /* name */
929
   true,      /* partial_inplace */
930
   MINUS_ONE,   /* src_mask */
931
   MINUS_ONE,   /* dst_mask */
932
   false),    /* pcrel_offset */
933
934
  /* 0x02: 64 bit PC relative relocation.  */
935
  HOWTO (R_REL,     /* type */
936
   0,     /* rightshift */
937
   8,     /* size */
938
   64,      /* bitsize */
939
   true,      /* pc_relative */
940
   0,     /* bitpos */
941
   complain_overflow_signed, /* complain_on_overflow */
942
   0,     /* special_function */
943
   "R_REL",   /* name */
944
   true,      /* partial_inplace */
945
   MINUS_ONE,   /* src_mask */
946
   MINUS_ONE,   /* dst_mask */
947
   false),    /* pcrel_offset */
948
949
  /* 0x03: 16 bit TOC relative relocation.  */
950
  HOWTO (R_TOC,     /* type */
951
   0,     /* rightshift */
952
   2,     /* size */
953
   16,      /* bitsize */
954
   false,     /* pc_relative */
955
   0,     /* bitpos */
956
   complain_overflow_bitfield, /* complain_on_overflow */
957
   0,     /* special_function */
958
   "R_TOC",   /* name */
959
   true,      /* partial_inplace */
960
   0,     /* src_mask */
961
   0xffff,    /* dst_mask */
962
   false),    /* pcrel_offset */
963
964
  /* 0x04: Same as R_TOC.  */
965
  HOWTO (R_TRL,     /* type */
966
   0,     /* rightshift */
967
   2,     /* size */
968
   16,      /* bitsize */
969
   false,     /* pc_relative */
970
   0,     /* bitpos */
971
   complain_overflow_bitfield, /* complain_on_overflow */
972
   0,     /* special_function */
973
   "R_TRL",   /* name */
974
   true,      /* partial_inplace */
975
   0,     /* src_mask */
976
   0xffff,    /* dst_mask */
977
   false),    /* pcrel_offset */
978
979
  /* 0x05: External TOC relative symbol.  */
980
  HOWTO (R_GL,      /* type */
981
   0,     /* rightshift */
982
   2,     /* size */
983
   16,      /* bitsize */
984
   false,     /* pc_relative */
985
   0,     /* bitpos */
986
   complain_overflow_bitfield, /* complain_on_overflow */
987
   0,     /* special_function */
988
   "R_GL",    /* name */
989
   true,      /* partial_inplace */
990
   0,     /* src_mask */
991
   0xffff,    /* dst_mask */
992
   false),    /* pcrel_offset */
993
994
  /* 0x06: Local TOC relative symbol.  */
995
  HOWTO (R_TCL,     /* type */
996
   0,     /* rightshift */
997
   2,     /* size */
998
   16,      /* bitsize */
999
   false,     /* pc_relative */
1000
   0,     /* bitpos */
1001
   complain_overflow_bitfield, /* complain_on_overflow */
1002
   0,     /* special_function */
1003
   "R_TCL",   /* name */
1004
   true,      /* partial_inplace */
1005
   0,     /* src_mask */
1006
   0xffff,    /* dst_mask */
1007
   false),    /* pcrel_offset */
1008
1009
  EMPTY_HOWTO (7),
1010
1011
  /* 0x08: Same as R_RBA.  */
1012
  HOWTO (R_BA,      /* type */
1013
   0,     /* rightshift */
1014
   4,     /* size */
1015
   26,      /* bitsize */
1016
   false,     /* pc_relative */
1017
   0,     /* bitpos */
1018
   complain_overflow_bitfield, /* complain_on_overflow */
1019
   0,     /* special_function */
1020
   "R_BA_26",   /* name */
1021
   true,      /* partial_inplace */
1022
   0x03fffffc,    /* src_mask */
1023
   0x03fffffc,    /* dst_mask */
1024
   false),    /* pcrel_offset */
1025
1026
  EMPTY_HOWTO (9),
1027
1028
  /* 0x0a: Same as R_RBR.  */
1029
  HOWTO (R_BR,      /* type */
1030
   0,     /* rightshift */
1031
   4,     /* size */
1032
   26,      /* bitsize */
1033
   true,      /* pc_relative */
1034
   0,     /* bitpos */
1035
   complain_overflow_signed, /* complain_on_overflow */
1036
   0,     /* special_function */
1037
   "R_BR",    /* name */
1038
   true,      /* partial_inplace */
1039
   0x03fffffc,    /* src_mask */
1040
   0x03fffffc,    /* dst_mask */
1041
   false),    /* pcrel_offset */
1042
1043
  EMPTY_HOWTO (0xb),
1044
1045
  /* 0x0c: Same as R_POS.  */
1046
  HOWTO (R_RL,      /* type */
1047
   0,     /* rightshift */
1048
   8,     /* size */
1049
   64,      /* bitsize */
1050
   false,     /* pc_relative */
1051
   0,     /* bitpos */
1052
   complain_overflow_bitfield, /* complain_on_overflow */
1053
   0,     /* special_function */
1054
   "R_RL",    /* name */
1055
   true,      /* partial_inplace */
1056
   MINUS_ONE,   /* src_mask */
1057
   MINUS_ONE,   /* dst_mask */
1058
   false),    /* pcrel_offset */
1059
1060
  /* 0x0d: Same as R_POS.  */
1061
  HOWTO (R_RLA,     /* type */
1062
   0,     /* rightshift */
1063
   8,     /* size */
1064
   64,      /* bitsize */
1065
   false,     /* pc_relative */
1066
   0,     /* bitpos */
1067
   complain_overflow_bitfield, /* complain_on_overflow */
1068
   0,     /* special_function */
1069
   "R_RLA",   /* name */
1070
   true,      /* partial_inplace */
1071
   MINUS_ONE,   /* src_mask */
1072
   MINUS_ONE,   /* dst_mask */
1073
   false),    /* pcrel_offset */
1074
1075
  EMPTY_HOWTO (0xe),
1076
1077
  /* 0x0f: Non-relocating reference.  Bitsize is 1 so that r_rsize is 0.  */
1078
  HOWTO (R_REF,     /* type */
1079
   0,     /* rightshift */
1080
   1,     /* size */
1081
   1,     /* bitsize */
1082
   false,     /* pc_relative */
1083
   0,     /* bitpos */
1084
   complain_overflow_dont, /* complain_on_overflow */
1085
   0,     /* special_function */
1086
   "R_REF",   /* name */
1087
   false,     /* partial_inplace */
1088
   0,     /* src_mask */
1089
   0,     /* dst_mask */
1090
   false),    /* pcrel_offset */
1091
1092
  EMPTY_HOWTO (0x10),
1093
  EMPTY_HOWTO (0x11),
1094
  EMPTY_HOWTO (0x12),
1095
1096
  /* 0x13: Same as R_TOC  */
1097
  HOWTO (R_TRLA,    /* type */
1098
   0,     /* rightshift */
1099
   2,     /* size */
1100
   16,      /* bitsize */
1101
   false,     /* pc_relative */
1102
   0,     /* bitpos */
1103
   complain_overflow_bitfield, /* complain_on_overflow */
1104
   0,     /* special_function */
1105
   "R_TRLA",    /* name */
1106
   true,      /* partial_inplace */
1107
   0xffff,    /* src_mask */
1108
   0xffff,    /* dst_mask */
1109
   false),    /* pcrel_offset */
1110
1111
  /* 0x14: Modifiable relative branch.  */
1112
  HOWTO (R_RRTBI,   /* type */
1113
   1,     /* rightshift */
1114
   4,     /* size */
1115
   32,      /* bitsize */
1116
   false,     /* pc_relative */
1117
   0,     /* bitpos */
1118
   complain_overflow_bitfield, /* complain_on_overflow */
1119
   0,     /* special_function */
1120
   "R_RRTBI",   /* name */
1121
   true,      /* partial_inplace */
1122
   0xffffffff,    /* src_mask */
1123
   0xffffffff,    /* dst_mask */
1124
   false),    /* pcrel_offset */
1125
1126
  /* 0x15: Modifiable absolute branch.  */
1127
  HOWTO (R_RRTBA,   /* type */
1128
   1,     /* rightshift */
1129
   4,     /* size */
1130
   32,      /* bitsize */
1131
   false,     /* pc_relative */
1132
   0,     /* bitpos */
1133
   complain_overflow_bitfield, /* complain_on_overflow */
1134
   0,     /* special_function */
1135
   "R_RRTBA",   /* name */
1136
   true,      /* partial_inplace */
1137
   0xffffffff,    /* src_mask */
1138
   0xffffffff,    /* dst_mask */
1139
   false),    /* pcrel_offset */
1140
1141
  /* 0x16: Modifiable call absolute indirect.  */
1142
  HOWTO (R_CAI,     /* type */
1143
   0,     /* rightshift */
1144
   2,     /* size */
1145
   16,      /* bitsize */
1146
   false,     /* pc_relative */
1147
   0,     /* bitpos */
1148
   complain_overflow_bitfield, /* complain_on_overflow */
1149
   0,     /* special_function */
1150
   "R_CAI",   /* name */
1151
   true,      /* partial_inplace */
1152
   0xffff,    /* src_mask */
1153
   0xffff,    /* dst_mask */
1154
   false),    /* pcrel_offset */
1155
1156
  /* 0x17: Modifiable call relative.  */
1157
  HOWTO (R_CREL,    /* type */
1158
   0,     /* rightshift */
1159
   2,     /* size */
1160
   16,      /* bitsize */
1161
   false,     /* pc_relative */
1162
   0,     /* bitpos */
1163
   complain_overflow_bitfield, /* complain_on_overflow */
1164
   0,     /* special_function */
1165
   "R_CREL",    /* name */
1166
   true,      /* partial_inplace */
1167
   0xffff,    /* src_mask */
1168
   0xffff,    /* dst_mask */
1169
   false),    /* pcrel_offset */
1170
1171
  /* 0x18: Modifiable branch absolute.  */
1172
  HOWTO (R_RBA,     /* type */
1173
   0,     /* rightshift */
1174
   4,     /* size */
1175
   26,      /* bitsize */
1176
   false,     /* pc_relative */
1177
   0,     /* bitpos */
1178
   complain_overflow_bitfield, /* complain_on_overflow */
1179
   0,     /* special_function */
1180
   "R_RBA",   /* name */
1181
   true,      /* partial_inplace */
1182
   0x03fffffc,    /* src_mask */
1183
   0x03fffffc,    /* dst_mask */
1184
   false),    /* pcrel_offset */
1185
1186
  /* 0x19: Modifiable branch absolute.  */
1187
  HOWTO (R_RBAC,    /* type */
1188
   0,     /* rightshift */
1189
   4,     /* size */
1190
   32,      /* bitsize */
1191
   false,     /* pc_relative */
1192
   0,     /* bitpos */
1193
   complain_overflow_bitfield, /* complain_on_overflow */
1194
   0,     /* special_function */
1195
   "R_RBAC",    /* name */
1196
   true,      /* partial_inplace */
1197
   0xffffffff,    /* src_mask */
1198
   0xffffffff,    /* dst_mask */
1199
   false),    /* pcrel_offset */
1200
1201
  /* 0x1a: Modifiable branch relative.  */
1202
  HOWTO (R_RBR,     /* type */
1203
   0,     /* rightshift */
1204
   4,     /* size */
1205
   26,      /* bitsize */
1206
   false,     /* pc_relative */
1207
   0,     /* bitpos */
1208
   complain_overflow_signed, /* complain_on_overflow */
1209
   0,     /* special_function */
1210
   "R_RBR_26",    /* name */
1211
   true,      /* partial_inplace */
1212
   0x03fffffc,    /* src_mask */
1213
   0x03fffffc,    /* dst_mask */
1214
   false),    /* pcrel_offset */
1215
1216
  /* 0x1b: Modifiable branch absolute.  */
1217
  HOWTO (R_RBRC,    /* type */
1218
   0,     /* rightshift */
1219
   2,     /* size */
1220
   16,      /* bitsize */
1221
   false,     /* pc_relative */
1222
   0,     /* bitpos */
1223
   complain_overflow_bitfield, /* complain_on_overflow */
1224
   0,     /* special_function */
1225
   "R_RBRC",    /* name */
1226
   true,      /* partial_inplace */
1227
   0xffff,    /* src_mask */
1228
   0xffff,    /* dst_mask */
1229
   false),    /* pcrel_offset */
1230
1231
  /* 0x1c: Standard 32 bit relocation.  */
1232
  HOWTO (R_POS,     /* type */
1233
   0,     /* rightshift */
1234
   4,     /* size */
1235
   32,      /* bitsize */
1236
   false,     /* pc_relative */
1237
   0,     /* bitpos */
1238
   complain_overflow_bitfield, /* complain_on_overflow */
1239
   0,     /* special_function */
1240
   "R_POS_32",    /* name */
1241
   true,      /* partial_inplace */
1242
   0xffffffff,    /* src_mask */
1243
   0xffffffff,    /* dst_mask */
1244
   false),    /* pcrel_offset */
1245
1246
  /* 0x1d: 16 bit Non modifiable absolute branch.  */
1247
  HOWTO (R_BA,      /* type */
1248
   0,     /* rightshift */
1249
   2,     /* size */
1250
   16,      /* bitsize */
1251
   false,     /* pc_relative */
1252
   0,     /* bitpos */
1253
   complain_overflow_bitfield, /* complain_on_overflow */
1254
   0,     /* special_function */
1255
   "R_BA_16",   /* name */
1256
   true,      /* partial_inplace */
1257
   0xfffc,    /* src_mask */
1258
   0xfffc,    /* dst_mask */
1259
   false),    /* pcrel_offset */
1260
1261
  /* 0x1e: Modifiable branch relative.  */
1262
  HOWTO (R_RBR,     /* type */
1263
   0,     /* rightshift */
1264
   2,     /* size */
1265
   16,      /* bitsize */
1266
   true,      /* pc_relative */
1267
   0,     /* bitpos */
1268
   complain_overflow_signed, /* complain_on_overflow */
1269
   0,     /* special_function */
1270
   "R_RBR_16",    /* name */
1271
   true,      /* partial_inplace */
1272
   0xfffc,    /* src_mask */
1273
   0xfffc,    /* dst_mask */
1274
   false),    /* pcrel_offset */
1275
1276
  /* 0x1f: Modifiable branch absolute.  */
1277
  HOWTO (R_RBA,     /* type */
1278
   0,     /* rightshift */
1279
   2,     /* size */
1280
   16,      /* bitsize */
1281
   false,     /* pc_relative */
1282
   0,     /* bitpos */
1283
   complain_overflow_bitfield, /* complain_on_overflow */
1284
   0,     /* special_function */
1285
   "R_RBA_16",    /* name */
1286
   true,      /* partial_inplace */
1287
   0xffff,    /* src_mask */
1288
   0xffff,    /* dst_mask */
1289
   false),    /* pcrel_offset */
1290
1291
  /* 0x20: General-dynamic TLS relocation.  */
1292
  HOWTO (R_TLS,     /* type */
1293
   0,     /* rightshift */
1294
   8,     /* size */
1295
   64,      /* bitsize */
1296
   false,     /* pc_relative */
1297
   0,     /* bitpos */
1298
   complain_overflow_bitfield, /* complain_on_overflow */
1299
   0,     /* special_function */
1300
   "R_TLS",   /* name */
1301
   true,      /* partial_inplace */
1302
   MINUS_ONE,   /* src_mask */
1303
   MINUS_ONE,   /* dst_mask */
1304
   false),    /* pcrel_offset */
1305
1306
  /* 0x21: Initial-exec TLS relocation.  */
1307
  HOWTO (R_TLS_IE,    /* type */
1308
   0,     /* rightshift */
1309
   8,     /* size */
1310
   64,      /* bitsize */
1311
   false,     /* pc_relative */
1312
   0,     /* bitpos */
1313
   complain_overflow_bitfield, /* complain_on_overflow */
1314
   0,     /* special_function */
1315
   "R_TLS_IE",    /* name */
1316
   true,      /* partial_inplace */
1317
   MINUS_ONE,   /* src_mask */
1318
   MINUS_ONE,   /* dst_mask */
1319
   false),    /* pcrel_offset */
1320
1321
  /* 0x22: Local-dynamic TLS relocation.  */
1322
  HOWTO (R_TLS_LD,    /* type */
1323
   0,     /* rightshift */
1324
   8,     /* size */
1325
   64,      /* bitsize */
1326
   false,     /* pc_relative */
1327
   0,     /* bitpos */
1328
   complain_overflow_bitfield, /* complain_on_overflow */
1329
   0,     /* special_function */
1330
   "R_TLS_LD",    /* name */
1331
   true,      /* partial_inplace */
1332
   MINUS_ONE,   /* src_mask */
1333
   MINUS_ONE,   /* dst_mask */
1334
   false),    /* pcrel_offset */
1335
1336
  /* 0x23: Local-exec TLS relocation.  */
1337
  HOWTO (R_TLS_LE,    /* type */
1338
   0,     /* rightshift */
1339
   8,     /* size */
1340
   64,      /* bitsize */
1341
   false,     /* pc_relative */
1342
   0,     /* bitpos */
1343
   complain_overflow_bitfield, /* complain_on_overflow */
1344
   0,     /* special_function */
1345
   "R_TLS_LE",    /* name */
1346
   true,      /* partial_inplace */
1347
   MINUS_ONE,   /* src_mask */
1348
   MINUS_ONE,   /* dst_mask */
1349
   false),    /* pcrel_offset */
1350
1351
  /* 0x24: TLS relocation.  */
1352
  HOWTO (R_TLSM,    /* type */
1353
   0,     /* rightshift */
1354
   8,     /* size */
1355
   64,      /* bitsize */
1356
   false,     /* pc_relative */
1357
   0,     /* bitpos */
1358
   complain_overflow_bitfield, /* complain_on_overflow */
1359
   0,     /* special_function */
1360
   "R_TLSM",    /* name */
1361
   true,      /* partial_inplace */
1362
   MINUS_ONE,   /* src_mask */
1363
   MINUS_ONE,   /* dst_mask */
1364
   false),    /* pcrel_offset */
1365
1366
  /* 0x25: TLS module relocation.  */
1367
  HOWTO (R_TLSML,   /* type */
1368
   0,     /* rightshift */
1369
   8,     /* size */
1370
   64,      /* bitsize */
1371
   false,     /* pc_relative */
1372
   0,     /* bitpos */
1373
   complain_overflow_bitfield, /* complain_on_overflow */
1374
   0,     /* special_function */
1375
   "R_TLSML",   /* name */
1376
   true,      /* partial_inplace */
1377
   MINUS_ONE,   /* src_mask */
1378
   MINUS_ONE,   /* dst_mask */
1379
   false),    /* pcrel_offset */
1380
1381
  /* 0x26: 32 bit relocation, but store negative value.  */
1382
  HOWTO (R_NEG,     /* type */
1383
   0,     /* rightshift */
1384
   -4,      /* size */
1385
   32,      /* bitsize */
1386
   false,     /* pc_relative */
1387
   0,     /* bitpos */
1388
   complain_overflow_bitfield, /* complain_on_overflow */
1389
   0,     /* special_function */
1390
   "R_NEG_32",    /* name */
1391
   true,      /* partial_inplace */
1392
   MINUS_ONE,   /* src_mask */
1393
   MINUS_ONE,   /* dst_mask */
1394
   false),    /* pcrel_offset */
1395
1396
  EMPTY_HOWTO(0x27),
1397
  EMPTY_HOWTO(0x28),
1398
  EMPTY_HOWTO(0x29),
1399
  EMPTY_HOWTO(0x2a),
1400
  EMPTY_HOWTO(0x2b),
1401
  EMPTY_HOWTO(0x2c),
1402
  EMPTY_HOWTO(0x2d),
1403
  EMPTY_HOWTO(0x2e),
1404
  EMPTY_HOWTO(0x2f),
1405
1406
  HOWTO (R_TOCU,    /* type */
1407
   16,      /* rightshift */
1408
   2,     /* size */
1409
   16,      /* bitsize */
1410
   false,     /* pc_relative */
1411
   0,     /* bitpos */
1412
   complain_overflow_bitfield, /* complain_on_overflow */
1413
   0,     /* special_function */
1414
   "R_TOCU",    /* name */
1415
   true,      /* partial_inplace */
1416
   0,     /* src_mask */
1417
   0xffff,    /* dst_mask */
1418
   false),    /* pcrel_offset */
1419
1420
  /* 0x31: Low-order 16 bit TOC relative relocation.  */
1421
  HOWTO (R_TOCL,    /* type */
1422
   0,     /* rightshift */
1423
   2,     /* size */
1424
   16,      /* bitsize */
1425
   false,     /* pc_relative */
1426
   0,     /* bitpos */
1427
   complain_overflow_dont, /* complain_on_overflow */
1428
   0,     /* special_function */
1429
   "R_TOCL",    /* name */
1430
   true,      /* partial_inplace */
1431
   0,     /* src_mask */
1432
   0xffff,    /* dst_mask */
1433
   false),    /* pcrel_offset */
1434
1435
};
1436
1437
void
1438
xcoff64_rtype2howto (arelent *relent, struct internal_reloc *internal)
1439
5
{
1440
5
  if (internal->r_type >= ARRAY_SIZE (xcoff64_howto_table))
1441
2
    {
1442
2
      relent->howto = NULL;
1443
2
      return;
1444
2
    }
1445
1446
  /* Default howto layout works most of the time */
1447
3
  relent->howto = &xcoff64_howto_table[internal->r_type];
1448
1449
  /* Special case some 16 bit reloc */
1450
3
  if (15 == (internal->r_size & 0x3f))
1451
0
    {
1452
0
      if (R_BA == internal->r_type)
1453
0
  relent->howto = &xcoff64_howto_table[0x1d];
1454
0
      else if (R_RBR == internal->r_type)
1455
0
  relent->howto = &xcoff64_howto_table[0x1e];
1456
0
      else if (R_RBA == internal->r_type)
1457
0
  relent->howto = &xcoff64_howto_table[0x1f];
1458
0
    }
1459
  /* Special case 32 bit */
1460
3
  else if (31 == (internal->r_size & 0x3f))
1461
0
    {
1462
0
      if (R_POS == internal->r_type)
1463
0
  relent->howto = &xcoff64_howto_table[0x1c];
1464
1465
0
      if (R_NEG == internal->r_type)
1466
0
  relent->howto = &xcoff64_howto_table[0x26];
1467
0
    }
1468
1469
  /* The r_size field of an XCOFF reloc encodes the bitsize of the
1470
     relocation, as well as indicating whether it is signed or not.
1471
     Doublecheck that the relocation information gathered from the
1472
     type matches this information.  The bitsize is not significant
1473
     for R_REF relocs.  */
1474
3
  if (relent->howto->dst_mask != 0
1475
2
      && (relent->howto->bitsize
1476
2
    != ((unsigned int) internal->r_size & 0x3f) + 1))
1477
2
    relent->howto = NULL;
1478
3
}
1479
1480
reloc_howto_type *
1481
xcoff64_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1482
         bfd_reloc_code_real_type code)
1483
0
{
1484
0
  switch (code)
1485
0
    {
1486
0
    case BFD_RELOC_PPC_B26:
1487
0
      return &xcoff64_howto_table[0xa];
1488
0
    case BFD_RELOC_PPC_BA16:
1489
0
      return &xcoff64_howto_table[0x1d];
1490
0
    case BFD_RELOC_PPC_BA26:
1491
0
      return &xcoff64_howto_table[8];
1492
0
    case BFD_RELOC_PPC_TOC16:
1493
0
      return &xcoff64_howto_table[3];
1494
0
    case BFD_RELOC_PPC_TOC16_HI:
1495
0
      return &xcoff64_howto_table[0x30];
1496
0
    case BFD_RELOC_PPC_TOC16_LO:
1497
0
      return &xcoff64_howto_table[0x31];
1498
0
    case BFD_RELOC_PPC_B16:
1499
0
      return &xcoff64_howto_table[0x1e];
1500
0
    case BFD_RELOC_32:
1501
0
    case BFD_RELOC_CTOR:
1502
0
      return &xcoff64_howto_table[0x1c];
1503
0
    case BFD_RELOC_64:
1504
0
      return &xcoff64_howto_table[0];
1505
0
    case BFD_RELOC_NONE:
1506
0
      return &xcoff64_howto_table[0xf];
1507
0
    case BFD_RELOC_PPC_NEG:
1508
0
      return &xcoff64_howto_table[0x1];
1509
0
    case BFD_RELOC_PPC64_TLSGD:
1510
0
      return &xcoff64_howto_table[0x20];
1511
0
    case BFD_RELOC_PPC64_TLSIE:
1512
0
      return &xcoff64_howto_table[0x21];
1513
0
    case BFD_RELOC_PPC64_TLSLD:
1514
0
      return &xcoff64_howto_table[0x22];
1515
0
    case BFD_RELOC_PPC64_TLSLE:
1516
0
      return &xcoff64_howto_table[0x23];
1517
0
    case BFD_RELOC_PPC64_TLSM:
1518
0
      return &xcoff64_howto_table[0x24];
1519
0
    case BFD_RELOC_PPC64_TLSML:
1520
0
      return &xcoff64_howto_table[0x25];
1521
0
    default:
1522
0
      return NULL;
1523
0
    }
1524
0
}
1525
1526
static reloc_howto_type *
1527
xcoff64_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1528
         const char *r_name)
1529
0
{
1530
0
  unsigned int i;
1531
1532
0
  for (i = 0; i < ARRAY_SIZE (xcoff64_howto_table); i++)
1533
0
    if (xcoff64_howto_table[i].name != NULL
1534
0
  && strcasecmp (xcoff64_howto_table[i].name, r_name) == 0)
1535
0
      return &xcoff64_howto_table[i];
1536
1537
0
  return NULL;
1538
0
}
1539
1540
/* This is the relocation function for the PowerPC64.
1541
   See xcoff_ppc_relocation_section for more information. */
1542
1543
static bool
1544
xcoff64_ppc_relocate_section (bfd *output_bfd,
1545
            struct bfd_link_info *info,
1546
            bfd *input_bfd,
1547
            asection *input_section,
1548
            bfd_byte *contents,
1549
            struct internal_reloc *relocs,
1550
            struct internal_syment *syms,
1551
            asection **sections)
1552
0
{
1553
0
  return _bfd_xcoff_relocate_section (output_bfd, info, input_bfd, input_section,
1554
0
              contents, relocs, syms, sections,
1555
0
              true, ARRAY_SIZE (xcoff64_howto_table),
1556
0
              xcoff64_howto_table,
1557
0
              xcoff64_calculate_relocation);
1558
0
}
1559
1560
/* PR 21786:  The PE/COFF standard does not require NUL termination for any of
1561
   the ASCII fields in the archive headers.  So in order to be able to extract
1562
   numerical values we provide our own versions of strtol and strtoll which
1563
   take a maximum length as an additional parameter.  Also - just to save space,
1564
   we omit the endptr return parameter, since we know that it is never used.  */
1565
1566
static long
1567
_bfd_strntol (const char * nptr, int base, unsigned int maxlen)
1568
1.30k
{
1569
1.30k
  char buf[24]; /* Should be enough.  */
1570
1571
1.30k
  BFD_ASSERT (maxlen < (sizeof (buf) - 1));
1572
1573
1.30k
  memcpy (buf, nptr, maxlen);
1574
1.30k
  buf[maxlen] = 0;
1575
1.30k
  return strtol (buf, NULL, base);
1576
1.30k
}
1577
1578
static long long
1579
_bfd_strntoll (const char * nptr, int base, unsigned int maxlen)
1580
0
{
1581
0
  char buf[32]; /* Should be enough.  */
1582
0
1583
0
  BFD_ASSERT (maxlen < (sizeof (buf) - 1));
1584
0
1585
0
  memcpy (buf, nptr, maxlen);
1586
0
  buf[maxlen] = 0;
1587
0
  return strtoll (buf, NULL, base);
1588
0
}
1589
1590
/* Macro to read an ASCII value stored in an archive header field.  */
1591
#define GET_VALUE_IN_FIELD(VAR, FIELD, BASE)      \
1592
1.30k
  do                \
1593
1.30k
    {               \
1594
1.30k
      (VAR) = (sizeof (VAR) > sizeof (long)      \
1595
1.30k
         ? _bfd_strntoll (FIELD, BASE, sizeof FIELD)  \
1596
1.30k
         : _bfd_strntol (FIELD, BASE, sizeof FIELD));  \
1597
1.30k
    }               \
1598
1.30k
  while (0)
1599
1600
/* Read in the armap of an XCOFF archive.  */
1601
1602
static bool
1603
xcoff64_slurp_armap (bfd *abfd)
1604
2.23k
{
1605
2.23k
  file_ptr off;
1606
2.23k
  size_t namlen;
1607
2.23k
  bfd_size_type sz, amt;
1608
2.23k
  bfd_byte *contents, *cend;
1609
2.23k
  bfd_vma c, i;
1610
2.23k
  carsym *arsym;
1611
2.23k
  bfd_byte *p;
1612
2.23k
  file_ptr pos;
1613
1614
  /* This is for the new format.  */
1615
2.23k
  struct xcoff_ar_hdr_big hdr;
1616
1617
2.23k
  if (x_artdata (abfd) == NULL)
1618
0
    {
1619
0
      abfd->has_armap = false;
1620
0
      return true;
1621
0
    }
1622
1623
2.23k
  off = bfd_scan_vma (x_artdata (abfd)->u.bhdr.symoff64,
1624
2.23k
          (const char **) NULL, 10);
1625
2.23k
  if (off == 0)
1626
360
    {
1627
360
      abfd->has_armap = false;
1628
360
      return true;
1629
360
    }
1630
1631
1.87k
  if (bfd_seek (abfd, off, SEEK_SET) != 0)
1632
276
    return false;
1633
1634
  /* The symbol table starts with a normal archive header.  */
1635
1.60k
  if (bfd_read (&hdr, SIZEOF_AR_HDR_BIG, abfd) != SIZEOF_AR_HDR_BIG)
1636
300
    return false;
1637
1638
  /* Skip the name (normally empty).  */
1639
1.30k
  GET_VALUE_IN_FIELD (namlen, hdr.namlen, 10);
1640
1.30k
  pos = ((namlen + 1) & ~(size_t) 1) + SXCOFFARFMAG;
1641
1.30k
  if (bfd_seek (abfd, pos, SEEK_CUR) != 0)
1642
8
    return false;
1643
1644
1.29k
  sz = bfd_scan_vma (hdr.size, (const char **) NULL, 10);
1645
1.29k
  if (sz + 1 < 9)
1646
98
    {
1647
98
      bfd_set_error (bfd_error_bad_value);
1648
98
      return false;
1649
98
    }
1650
1651
  /* Read in the entire symbol table.  */
1652
1.19k
  contents = (bfd_byte *) _bfd_alloc_and_read (abfd, sz + 1, sz);
1653
1.19k
  if (contents == NULL)
1654
658
    return false;
1655
1656
  /* Ensure strings are NULL terminated so we don't wander off the end
1657
     of the buffer.  */
1658
538
  contents[sz] = 0;
1659
1660
  /* The symbol table starts with an eight byte count.  */
1661
538
  c = H_GET_64 (abfd, contents);
1662
1663
538
  if (c >= sz / 8)
1664
480
    {
1665
480
      bfd_set_error (bfd_error_bad_value);
1666
480
      return false;
1667
480
    }
1668
58
  amt = c;
1669
58
  amt *= sizeof (carsym);
1670
58
  bfd_ardata (abfd)->symdefs = (carsym *) bfd_alloc (abfd, amt);
1671
58
  if (bfd_ardata (abfd)->symdefs == NULL)
1672
0
    return false;
1673
1674
  /* After the count comes a list of eight byte file offsets.  */
1675
58
  for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 8;
1676
1.19k
       i < c;
1677
1.13k
       ++i, ++arsym, p += 8)
1678
1.13k
    arsym->u.file_offset = H_GET_64 (abfd, p);
1679
1680
  /* After the file offsets come null terminated symbol names.  */
1681
58
  cend = contents + sz;
1682
58
  for (i = 0, arsym = bfd_ardata (abfd)->symdefs;
1683
660
       i < c;
1684
602
       ++i, ++arsym, p += strlen ((char *) p) + 1)
1685
632
    {
1686
632
      if (p >= cend)
1687
30
  {
1688
30
    bfd_set_error (bfd_error_bad_value);
1689
30
    return false;
1690
30
  }
1691
602
      arsym->name = (char *) p;
1692
602
    }
1693
1694
28
  bfd_ardata (abfd)->symdef_count = c;
1695
28
  abfd->has_armap = true;
1696
1697
28
  return true;
1698
58
}
1699
1700
1701
/* See if this is an NEW XCOFF archive.  */
1702
1703
static bfd_cleanup
1704
xcoff64_archive_p (bfd *abfd)
1705
220k
{
1706
220k
  char magic[SXCOFFARMAG];
1707
  /* This is the new format.  */
1708
220k
  struct xcoff_ar_file_hdr_big hdr;
1709
220k
  size_t amt = SXCOFFARMAG;
1710
1711
220k
  BFD_ASSERT (!bfd_is_fake_archive (abfd));
1712
1713
220k
  if (bfd_read (magic, amt, abfd) != amt)
1714
1.12k
    {
1715
1.12k
      if (bfd_get_error () != bfd_error_system_call)
1716
522
  bfd_set_error (bfd_error_wrong_format);
1717
1.12k
      return NULL;
1718
1.12k
    }
1719
1720
219k
  if (strncmp (magic, XCOFFARMAGBIG, SXCOFFARMAG) != 0)
1721
216k
    {
1722
216k
      bfd_set_error (bfd_error_wrong_format);
1723
216k
      return NULL;
1724
216k
    }
1725
1726
  /* Copy over the magic string.  */
1727
2.29k
  memcpy (hdr.magic, magic, SXCOFFARMAG);
1728
1729
  /* Now read the rest of the file header.  */
1730
2.29k
  amt = SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG;
1731
2.29k
  if (bfd_read (&hdr.memoff, amt, abfd) != amt)
1732
56
    {
1733
56
      if (bfd_get_error () != bfd_error_system_call)
1734
56
  bfd_set_error (bfd_error_wrong_format);
1735
56
      return NULL;
1736
56
    }
1737
1738
2.23k
  amt = sizeof (struct artdata) + sizeof (struct xcoff_artdata);
1739
2.23k
  bfd_ardata (abfd) = bfd_zalloc (abfd, amt);
1740
2.23k
  if (bfd_ardata (abfd) == NULL)
1741
0
    return NULL;
1742
1743
2.23k
  bfd_ardata (abfd)->tdata = (void *) ((struct artdata *) bfd_ardata (abfd) + 1);
1744
1745
2.23k
  bfd_ardata (abfd)->first_file.file_offset
1746
2.23k
    = bfd_scan_vma (hdr.firstmemoff, (const char **) NULL, 10);
1747
1748
2.23k
  memcpy (&x_artdata (abfd)->u.bhdr, &hdr, SIZEOF_AR_FILE_HDR_BIG);
1749
1750
2.23k
  if (! xcoff64_slurp_armap (abfd))
1751
1.85k
    {
1752
1.85k
      bfd_release (abfd, bfd_ardata (abfd));
1753
1.85k
      return NULL;
1754
1.85k
    }
1755
1756
388
  return _bfd_no_cleanup;
1757
2.23k
}
1758
1759
1760
/* Open the next element in an XCOFF archive.  */
1761
1762
static bfd *
1763
xcoff64_openr_next_archived_file (bfd *archive, bfd *last_file)
1764
0
{
1765
0
  if (x_artdata (archive) == NULL
1766
0
      || ! xcoff_big_format_p (archive))
1767
0
    {
1768
0
      bfd_set_error (bfd_error_invalid_operation);
1769
0
      return NULL;
1770
0
    }
1771
1772
0
  return _bfd_xcoff_openr_next_archived_file (archive, last_file);
1773
0
}
1774
1775
/* We can't use the usual coff_sizeof_headers routine, because AIX
1776
   always uses an a.out header.  */
1777
1778
static int
1779
xcoff64_sizeof_headers (bfd *abfd,
1780
      struct bfd_link_info *info ATTRIBUTE_UNUSED)
1781
0
{
1782
0
  int size;
1783
1784
0
  size = bfd_coff_filhsz (abfd);
1785
1786
  /* Don't think the small aout header can be used since some of the
1787
     old elements have been reordered past the end of the old coff
1788
     small aout size.  */
1789
1790
0
  if (xcoff_data (abfd)->full_aouthdr)
1791
0
    size += bfd_coff_aoutsz (abfd);
1792
1793
0
  size += abfd->section_count * bfd_coff_scnhsz (abfd);
1794
0
  return size;
1795
0
}
1796
1797
static asection *
1798
xcoff64_create_csect_from_smclas (bfd *abfd, union internal_auxent *aux,
1799
          const char *symbol_name)
1800
0
{
1801
0
  asection *return_value = NULL;
1802
1803
  /* Changes from 32 :
1804
     .sv == 8, is only for 32 bit programs
1805
     .ti == 12 and .tb == 13 are now reserved.  */
1806
0
  static const char * const names[] =
1807
0
  {
1808
0
    ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo",
1809
0
    NULL, ".bs", ".ds", ".uc", NULL,  NULL,  NULL,  ".tc0",
1810
0
    ".td", ".sv64", ".sv3264", NULL, ".tl", ".ul", ".te"
1811
0
  };
1812
1813
0
  if ((aux->x_csect.x_smclas < ARRAY_SIZE (names))
1814
0
      && (NULL != names[aux->x_csect.x_smclas]))
1815
0
    {
1816
1817
0
      return_value = bfd_make_section_anyway
1818
0
  (abfd, names[aux->x_csect.x_smclas]);
1819
1820
0
    }
1821
0
  else
1822
0
    {
1823
0
      _bfd_error_handler
1824
  /* xgettext: c-format */
1825
0
  (_("%pB: symbol `%s' has unrecognized smclas %d"),
1826
0
   abfd, symbol_name, aux->x_csect.x_smclas);
1827
0
      bfd_set_error (bfd_error_bad_value);
1828
0
    }
1829
1830
0
  return return_value;
1831
0
}
1832
1833
static bool
1834
xcoff64_is_lineno_count_overflow (bfd *abfd ATTRIBUTE_UNUSED,
1835
          bfd_vma value ATTRIBUTE_UNUSED)
1836
0
{
1837
0
  return false;
1838
0
}
1839
1840
static bool
1841
xcoff64_is_reloc_count_overflow (bfd *abfd ATTRIBUTE_UNUSED,
1842
         bfd_vma value ATTRIBUTE_UNUSED)
1843
0
{
1844
0
  return false;
1845
0
}
1846
1847
static bfd_vma
1848
xcoff64_loader_symbol_offset (bfd *abfd ATTRIBUTE_UNUSED,
1849
            struct internal_ldhdr *ldhdr)
1850
0
{
1851
0
  return (ldhdr->l_symoff);
1852
0
}
1853
1854
static bfd_vma
1855
xcoff64_loader_reloc_offset (bfd *abfd ATTRIBUTE_UNUSED,
1856
           struct internal_ldhdr *ldhdr)
1857
0
{
1858
0
  return (ldhdr->l_rldoff);
1859
0
}
1860
1861
static bool
1862
xcoff64_bad_format_hook (bfd * abfd, void *filehdr)
1863
188k
{
1864
188k
  struct internal_filehdr *internal_f = (struct internal_filehdr *) filehdr;
1865
1866
  /* Check flavor first.  */
1867
188k
  if (bfd_get_flavour (abfd) != bfd_target_xcoff_flavour)
1868
0
    return false;
1869
1870
188k
  if (bfd_xcoff_magic_number (abfd) != internal_f->f_magic)
1871
186k
    return false;
1872
1873
1.71k
  return true;
1874
188k
}
1875
1876
static bool
1877
xcoff64_generate_rtinit (bfd *abfd, const char *init, const char *fini,
1878
       bool rtld)
1879
0
{
1880
0
  bfd_byte filehdr_ext[FILHSZ];
1881
0
  bfd_byte scnhdr_ext[SCNHSZ * 3];
1882
0
  bfd_byte syment_ext[SYMESZ * 10];
1883
0
  bfd_byte reloc_ext[RELSZ * 3];
1884
0
  bfd_byte *data_buffer;
1885
0
  bfd_size_type data_buffer_size;
1886
0
  bfd_byte *string_table, *st_tmp;
1887
0
  bfd_size_type string_table_size;
1888
0
  bfd_vma val;
1889
0
  size_t initsz, finisz;
1890
0
  struct internal_filehdr filehdr;
1891
0
  struct internal_scnhdr text_scnhdr;
1892
0
  struct internal_scnhdr data_scnhdr;
1893
0
  struct internal_scnhdr bss_scnhdr;
1894
0
  struct internal_syment syment;
1895
0
  union internal_auxent auxent;
1896
0
  struct internal_reloc reloc;
1897
1898
0
  char *text_name = ".text";
1899
0
  char *data_name = ".data";
1900
0
  char *bss_name = ".bss";
1901
0
  char *rtinit_name = "__rtinit";
1902
0
  char *rtld_name = "__rtld";
1903
1904
0
  if (! bfd_xcoff_rtinit_size (abfd))
1905
0
    return false;
1906
1907
0
  initsz = (init == NULL ? 0 : 1 + strlen (init));
1908
0
  finisz = (fini == NULL ? 0 : 1 + strlen (fini));
1909
1910
  /* File header.  */
1911
0
  memset (filehdr_ext, 0, FILHSZ);
1912
0
  memset (&filehdr, 0, sizeof (struct internal_filehdr));
1913
0
  filehdr.f_magic = bfd_xcoff_magic_number (abfd);
1914
0
  filehdr.f_nscns = 3;
1915
0
  filehdr.f_timdat = 0;
1916
0
  filehdr.f_nsyms = 0;  /* at least 6, no more than 8 */
1917
0
  filehdr.f_symptr = 0; /* set below */
1918
0
  filehdr.f_opthdr = 0;
1919
0
  filehdr.f_flags = 0;
1920
1921
  /* Section headers.  */
1922
0
  memset (scnhdr_ext, 0, 3 * SCNHSZ);
1923
1924
  /* Text.  */
1925
0
  memset (&text_scnhdr, 0, sizeof (struct internal_scnhdr));
1926
0
  memcpy (text_scnhdr.s_name, text_name, strlen (text_name));
1927
0
  text_scnhdr.s_paddr = 0;
1928
0
  text_scnhdr.s_vaddr = 0;
1929
0
  text_scnhdr.s_size = 0;
1930
0
  text_scnhdr.s_scnptr = 0;
1931
0
  text_scnhdr.s_relptr = 0;
1932
0
  text_scnhdr.s_lnnoptr = 0;
1933
0
  text_scnhdr.s_nreloc = 0;
1934
0
  text_scnhdr.s_nlnno = 0;
1935
0
  text_scnhdr.s_flags = STYP_TEXT;
1936
1937
  /* Data.  */
1938
0
  memset (&data_scnhdr, 0, sizeof (struct internal_scnhdr));
1939
0
  memcpy (data_scnhdr.s_name, data_name, strlen (data_name));
1940
0
  data_scnhdr.s_paddr = 0;
1941
0
  data_scnhdr.s_vaddr = 0;
1942
0
  data_scnhdr.s_size = 0;    /* set below */
1943
0
  data_scnhdr.s_scnptr = FILHSZ + 3 * SCNHSZ;
1944
0
  data_scnhdr.s_relptr = 0;  /* set below */
1945
0
  data_scnhdr.s_lnnoptr = 0;
1946
0
  data_scnhdr.s_nreloc = 0;  /* either 1 or 2 */
1947
0
  data_scnhdr.s_nlnno = 0;
1948
0
  data_scnhdr.s_flags = STYP_DATA;
1949
1950
  /* Bss.  */
1951
0
  memset (&bss_scnhdr, 0, sizeof (struct internal_scnhdr));
1952
0
  memcpy (bss_scnhdr.s_name, bss_name, strlen (bss_name));
1953
0
  bss_scnhdr.s_paddr = 0; /* set below */
1954
0
  bss_scnhdr.s_vaddr = 0; /* set below */
1955
0
  bss_scnhdr.s_size = 0;  /* set below */
1956
0
  bss_scnhdr.s_scnptr = 0;
1957
0
  bss_scnhdr.s_relptr = 0;
1958
0
  bss_scnhdr.s_lnnoptr = 0;
1959
0
  bss_scnhdr.s_nreloc = 0;
1960
0
  bss_scnhdr.s_nlnno = 0;
1961
0
  bss_scnhdr.s_flags = STYP_BSS;
1962
1963
  /* .data
1964
     0x0000       0x00000000 : rtl
1965
     0x0004       0x00000000 :
1966
     0x0008       0x00000018 : offset to init, or 0
1967
     0x000C       0x00000038 : offset to fini, or 0
1968
     0x0010       0x00000010 : size of descriptor
1969
     0x0014       0x00000000 : pad
1970
     0x0018       0x00000000 : init, needs a reloc
1971
     0x001C       0x00000000 :
1972
     0x0020       0x00000058 : offset to init name
1973
     0x0024       0x00000000 : flags, padded to a word
1974
     0x0028       0x00000000 : empty init
1975
     0x002C       0x00000000 :
1976
     0x0030       0x00000000 :
1977
     0x0034       0x00000000 :
1978
     0x0038       0x00000000 : fini, needs a reloc
1979
     0x003C       0x00000000 :
1980
     0x0040       0x00000??? : offset to fini name
1981
     0x0044       0x00000000 : flags, padded to a word
1982
     0x0048       0x00000000 : empty fini
1983
     0x004C       0x00000000 :
1984
     0x0050       0x00000000 :
1985
     0x0054       0x00000000 :
1986
     0x0058       init name
1987
     0x0058 + initsz  fini name */
1988
1989
0
  data_buffer_size = 0x0058 + initsz + finisz;
1990
0
  data_buffer_size = (data_buffer_size + 7) &~ (bfd_size_type) 7;
1991
0
  data_buffer = NULL;
1992
0
  data_buffer = (bfd_byte *) bfd_zmalloc (data_buffer_size);
1993
0
  if (data_buffer == NULL)
1994
0
    return false;
1995
1996
0
  if (initsz)
1997
0
    {
1998
0
      val = 0x18;
1999
0
      bfd_put_32 (abfd, val, &data_buffer[0x08]);
2000
0
      val = 0x58;
2001
0
      bfd_put_32 (abfd, val, &data_buffer[0x20]);
2002
0
      memcpy (&data_buffer[val], init, initsz);
2003
0
    }
2004
2005
0
  if (finisz)
2006
0
    {
2007
0
      val = 0x38;
2008
0
      bfd_put_32 (abfd, val, &data_buffer[0x0C]);
2009
0
      val = 0x58 + initsz;
2010
0
      bfd_put_32 (abfd, val, &data_buffer[0x40]);
2011
0
      memcpy (&data_buffer[val], fini, finisz);
2012
0
    }
2013
2014
0
  val = 0x10;
2015
0
  bfd_put_32 (abfd, val, &data_buffer[0x10]);
2016
0
  data_scnhdr.s_size = data_buffer_size;
2017
0
  bss_scnhdr.s_paddr = bss_scnhdr.s_vaddr = data_scnhdr.s_size;
2018
2019
  /* String table.  */
2020
0
  string_table_size = 4;
2021
0
  string_table_size += strlen (data_name) + 1;
2022
0
  string_table_size += strlen (rtinit_name) + 1;
2023
0
  string_table_size += initsz;
2024
0
  string_table_size += finisz;
2025
0
  if (rtld)
2026
0
    string_table_size += strlen (rtld_name) + 1;
2027
2028
0
  string_table = (bfd_byte *) bfd_zmalloc (string_table_size);
2029
0
  if (string_table == NULL)
2030
0
    {
2031
0
      free (data_buffer);
2032
0
      return false;
2033
0
    }
2034
2035
0
  val = string_table_size;
2036
0
  bfd_put_32 (abfd, val, &string_table[0]);
2037
0
  st_tmp = string_table + 4;
2038
2039
  /* symbols
2040
     0. .data csect
2041
     2. __rtinit
2042
     4. init function
2043
     6. fini function
2044
     8. __rtld  */
2045
0
  memset (syment_ext, 0, 10 * SYMESZ);
2046
0
  memset (reloc_ext, 0, 3 * RELSZ);
2047
2048
  /* .data csect */
2049
0
  memset (&syment, 0, sizeof (struct internal_syment));
2050
0
  memset (&auxent, 0, sizeof (union internal_auxent));
2051
2052
0
  syment._n._n_n._n_offset = st_tmp - string_table;
2053
0
  memcpy (st_tmp, data_name, strlen (data_name));
2054
0
  st_tmp += strlen (data_name) + 1;
2055
2056
0
  syment.n_scnum = 2;
2057
0
  syment.n_sclass = C_HIDEXT;
2058
0
  syment.n_numaux = 1;
2059
0
  auxent.x_csect.x_scnlen.u64 = data_buffer_size;
2060
0
  auxent.x_csect.x_smtyp = 3 << 3 | XTY_SD;
2061
0
  auxent.x_csect.x_smclas = XMC_RW;
2062
0
  bfd_coff_swap_sym_out (abfd, &syment,
2063
0
       &syment_ext[filehdr.f_nsyms * SYMESZ]);
2064
0
  bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
2065
0
       syment.n_numaux,
2066
0
       &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
2067
0
  filehdr.f_nsyms += 2;
2068
2069
  /* __rtinit */
2070
0
  memset (&syment, 0, sizeof (struct internal_syment));
2071
0
  memset (&auxent, 0, sizeof (union internal_auxent));
2072
0
  syment._n._n_n._n_offset = st_tmp - string_table;
2073
0
  memcpy (st_tmp, rtinit_name, strlen (rtinit_name));
2074
0
  st_tmp += strlen (rtinit_name) + 1;
2075
2076
0
  syment.n_scnum = 2;
2077
0
  syment.n_sclass = C_EXT;
2078
0
  syment.n_numaux = 1;
2079
0
  auxent.x_csect.x_smtyp = XTY_LD;
2080
0
  auxent.x_csect.x_smclas = XMC_RW;
2081
0
  bfd_coff_swap_sym_out (abfd, &syment,
2082
0
       &syment_ext[filehdr.f_nsyms * SYMESZ]);
2083
0
  bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
2084
0
       syment.n_numaux,
2085
0
       &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
2086
0
  filehdr.f_nsyms += 2;
2087
2088
  /* Init.  */
2089
0
  if (initsz)
2090
0
    {
2091
0
      memset (&syment, 0, sizeof (struct internal_syment));
2092
0
      memset (&auxent, 0, sizeof (union internal_auxent));
2093
2094
0
      syment._n._n_n._n_offset = st_tmp - string_table;
2095
0
      memcpy (st_tmp, init, initsz);
2096
0
      st_tmp += initsz;
2097
2098
0
      syment.n_sclass = C_EXT;
2099
0
      syment.n_numaux = 1;
2100
0
      bfd_coff_swap_sym_out (abfd, &syment,
2101
0
           &syment_ext[filehdr.f_nsyms * SYMESZ]);
2102
0
      bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
2103
0
           syment.n_numaux,
2104
0
           &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
2105
      /* Reloc.  */
2106
0
      memset (&reloc, 0, sizeof (struct internal_reloc));
2107
0
      reloc.r_vaddr = 0x0018;
2108
0
      reloc.r_symndx = filehdr.f_nsyms;
2109
0
      reloc.r_type = R_POS;
2110
0
      reloc.r_size = 63;
2111
0
      bfd_coff_swap_reloc_out (abfd, &reloc, &reloc_ext[0]);
2112
2113
0
      filehdr.f_nsyms += 2;
2114
0
      data_scnhdr.s_nreloc += 1;
2115
0
    }
2116
2117
  /* Finit.  */
2118
0
  if (finisz)
2119
0
    {
2120
0
      memset (&syment, 0, sizeof (struct internal_syment));
2121
0
      memset (&auxent, 0, sizeof (union internal_auxent));
2122
2123
0
      syment._n._n_n._n_offset = st_tmp - string_table;
2124
0
      memcpy (st_tmp, fini, finisz);
2125
0
      st_tmp += finisz;
2126
2127
0
      syment.n_sclass = C_EXT;
2128
0
      syment.n_numaux = 1;
2129
0
      bfd_coff_swap_sym_out (abfd, &syment,
2130
0
           &syment_ext[filehdr.f_nsyms * SYMESZ]);
2131
0
      bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
2132
0
           syment.n_numaux,
2133
0
           &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
2134
2135
      /* Reloc.  */
2136
0
      memset (&reloc, 0, sizeof (struct internal_reloc));
2137
0
      reloc.r_vaddr = 0x0038;
2138
0
      reloc.r_symndx = filehdr.f_nsyms;
2139
0
      reloc.r_type = R_POS;
2140
0
      reloc.r_size = 63;
2141
0
      bfd_coff_swap_reloc_out (abfd, &reloc,
2142
0
             &reloc_ext[data_scnhdr.s_nreloc * RELSZ]);
2143
2144
0
      filehdr.f_nsyms += 2;
2145
0
      data_scnhdr.s_nreloc += 1;
2146
0
    }
2147
2148
0
  if (rtld)
2149
0
    {
2150
0
      memset (&syment, 0, sizeof (struct internal_syment));
2151
0
      memset (&auxent, 0, sizeof (union internal_auxent));
2152
2153
0
      syment._n._n_n._n_offset = st_tmp - string_table;
2154
0
      memcpy (st_tmp, rtld_name, strlen (rtld_name));
2155
0
      st_tmp += strlen (rtld_name) + 1;
2156
2157
0
      syment.n_sclass = C_EXT;
2158
0
      syment.n_numaux = 1;
2159
0
      bfd_coff_swap_sym_out (abfd, &syment,
2160
0
           &syment_ext[filehdr.f_nsyms * SYMESZ]);
2161
0
      bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
2162
0
           syment.n_numaux,
2163
0
           &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
2164
2165
      /* Reloc.  */
2166
0
      memset (&reloc, 0, sizeof (struct internal_reloc));
2167
0
      reloc.r_vaddr = 0x0000;
2168
0
      reloc.r_symndx = filehdr.f_nsyms;
2169
0
      reloc.r_type = R_POS;
2170
0
      reloc.r_size = 63;
2171
0
      bfd_coff_swap_reloc_out (abfd, &reloc,
2172
0
             &reloc_ext[data_scnhdr.s_nreloc * RELSZ]);
2173
2174
0
      filehdr.f_nsyms += 2;
2175
0
      data_scnhdr.s_nreloc += 1;
2176
2177
0
      bss_scnhdr.s_size = 0;
2178
0
    }
2179
2180
0
  data_scnhdr.s_relptr = data_scnhdr.s_scnptr + data_buffer_size;
2181
0
  filehdr.f_symptr = data_scnhdr.s_relptr + data_scnhdr.s_nreloc * RELSZ;
2182
2183
0
  bfd_coff_swap_filehdr_out (abfd, &filehdr, filehdr_ext);
2184
0
  bfd_coff_swap_scnhdr_out (abfd, &text_scnhdr, &scnhdr_ext[SCNHSZ * 0], NULL);
2185
0
  bfd_coff_swap_scnhdr_out (abfd, &data_scnhdr, &scnhdr_ext[SCNHSZ * 1], NULL);
2186
0
  bfd_coff_swap_scnhdr_out (abfd, &bss_scnhdr, &scnhdr_ext[SCNHSZ * 2], NULL);
2187
0
  bool ret = true;
2188
0
  if (bfd_write (filehdr_ext, FILHSZ, abfd) != FILHSZ
2189
0
      || bfd_write (scnhdr_ext, 3 * SCNHSZ, abfd) != 3 * SCNHSZ
2190
0
      || bfd_write (data_buffer, data_buffer_size, abfd) != data_buffer_size
2191
0
      || (bfd_write (reloc_ext, data_scnhdr.s_nreloc * RELSZ, abfd)
2192
0
    != data_scnhdr.s_nreloc * RELSZ)
2193
0
      || (bfd_write (syment_ext, filehdr.f_nsyms * SYMESZ, abfd)
2194
0
    != (bfd_size_type) filehdr.f_nsyms * SYMESZ)
2195
0
      || bfd_write (string_table, string_table_size, abfd) != string_table_size)
2196
0
    ret = false;
2197
2198
0
  free (string_table);
2199
0
  free (data_buffer);
2200
0
  return ret;
2201
0
}
2202
2203
/* The typical dynamic reloc.  */
2204
2205
static reloc_howto_type xcoff64_dynamic_reloc =
2206
HOWTO (0,     /* type */
2207
       0,     /* rightshift */
2208
       8,     /* size */
2209
       64,      /* bitsize */
2210
       false,     /* pc_relative */
2211
       0,     /* bitpos */
2212
       complain_overflow_bitfield, /* complain_on_overflow */
2213
       0,     /* special_function */
2214
       "R_POS",     /* name */
2215
       true,      /* partial_inplace */
2216
       MINUS_ONE,   /* src_mask */
2217
       MINUS_ONE,   /* dst_mask */
2218
       false);      /* pcrel_offset */
2219
2220
/* Indirect call stub */
2221
static const unsigned long xcoff64_stub_indirect_call_code[4] =
2222
  {
2223
    0xe9820000, /* ld r12,0(r2) */
2224
    0xe80c0000, /* ld r0,0(r12) */
2225
    0x7c0903a6, /* mtctr r0 */
2226
    0x4e800420, /* bctr */
2227
  };
2228
2229
/* Shared call stub */
2230
static const unsigned long xcoff64_stub_shared_call_code[6] =
2231
  {
2232
    0xe9820000, /* ld r12,0(r2) */
2233
    0xf8410028, /* std r2,40(r1) */
2234
    0xe80c0000, /* ld r0,0(r12) */
2235
    0xe84c0008, /* ld r2,8(r12) */
2236
    0x7c0903a6, /* mtctr r0 */
2237
    0x4e800420, /* bctr */
2238
  };
2239
2240
static const unsigned long xcoff64_glink_code[10] =
2241
{
2242
  0xe9820000, /* ld r12,0(r2) */
2243
  0xf8410028, /* std r2,40(r1) */
2244
  0xe80c0000, /* ld r0,0(r12) */
2245
  0xe84c0008, /* ld r2,8(r12) */
2246
  0x7c0903a6, /* mtctr r0 */
2247
  0x4e800420, /* bctr */
2248
  0x00000000, /* start of traceback table */
2249
  0x000ca000, /* traceback table */
2250
  0x00000000, /* traceback table */
2251
  0x00000018, /* ??? */
2252
};
2253
2254
static const struct xcoff_backend_data_rec bfd_xcoff_backend_data =
2255
  {
2256
    { /* COFF backend, defined in libcoff.h.  */
2257
      _bfd_xcoff64_swap_aux_in,
2258
      _bfd_xcoff64_swap_sym_in,
2259
      _bfd_xcoff64_swap_lineno_in,
2260
      _bfd_xcoff64_swap_aux_out,
2261
      _bfd_xcoff64_swap_sym_out,
2262
      _bfd_xcoff64_swap_lineno_out,
2263
      xcoff64_swap_reloc_out,
2264
      coff_swap_filehdr_out,
2265
      coff_swap_aouthdr_out,
2266
      coff_swap_scnhdr_out,
2267
      FILHSZ,
2268
      AOUTSZ,
2269
      SCNHSZ,
2270
      SYMESZ,
2271
      AUXESZ,
2272
      RELSZ,
2273
      LINESZ,
2274
      FILNMLEN,
2275
      true,     /* _bfd_coff_long_filenames */
2276
      XCOFF_NO_LONG_SECTION_NAMES,  /* _bfd_coff_long_section_names */
2277
      3,      /* _bfd_coff_default_section_alignment_power */
2278
      true,     /* _bfd_coff_force_symnames_in_strings */
2279
      4,      /* _bfd_coff_debug_string_prefix_length */
2280
      32768,      /* _bfd_coff_max_nscns */
2281
      coff_swap_filehdr_in,
2282
      coff_swap_aouthdr_in,
2283
      coff_swap_scnhdr_in,
2284
      xcoff64_swap_reloc_in,
2285
      xcoff64_bad_format_hook,
2286
      coff_set_arch_mach_hook,
2287
      coff_mkobject_hook,
2288
      styp_to_sec_flags,
2289
      coff_set_alignment_hook,
2290
      coff_slurp_symbol_table,
2291
      symname_in_debug_hook,
2292
      coff_pointerize_aux_hook,
2293
      coff_print_aux,
2294
      dummy_reloc16_extra_cases,
2295
      dummy_reloc16_estimate,
2296
      NULL,     /* bfd_coff_symbol_classification */
2297
      coff_compute_section_file_positions,
2298
      NULL,     /* _bfd_coff_start_final_link */
2299
      xcoff64_ppc_relocate_section,
2300
      coff_rtype_to_howto,
2301
      NULL,     /* _bfd_coff_adjust_symndx */
2302
      coff_link_output_has_begun,
2303
      coff_final_link_postscript,
2304
      NULL      /* print_pdata.  */
2305
    },
2306
2307
    0x01EF,     /* magic number */
2308
    bfd_arch_powerpc,
2309
    bfd_mach_ppc_620,
2310
2311
    /* Function pointers to xcoff specific swap routines.  */
2312
    xcoff64_swap_ldhdr_in,
2313
    xcoff64_swap_ldhdr_out,
2314
    xcoff64_swap_ldsym_in,
2315
    xcoff64_swap_ldsym_out,
2316
    xcoff64_swap_ldrel_in,
2317
    xcoff64_swap_ldrel_out,
2318
2319
    /* Sizes.  */
2320
    LDHDRSZ,
2321
    LDSYMSZ,
2322
    LDRELSZ,
2323
    24,       /* _xcoff_function_descriptor_size */
2324
    0,        /* _xcoff_small_aout_header_size */
2325
2326
    /* Versions.  */
2327
    2,        /* _xcoff_ldhdr_version */
2328
2329
    _bfd_xcoff64_put_symbol_name,
2330
    _bfd_xcoff64_put_ldsymbol_name,
2331
    &xcoff64_dynamic_reloc,
2332
    xcoff64_create_csect_from_smclas,
2333
2334
    /* Lineno and reloc count overflow.  */
2335
    xcoff64_is_lineno_count_overflow,
2336
    xcoff64_is_reloc_count_overflow,
2337
2338
    xcoff64_loader_symbol_offset,
2339
    xcoff64_loader_reloc_offset,
2340
2341
    /* glink.  */
2342
    &xcoff64_glink_code[0],
2343
    40,       /* _xcoff_glink_size */
2344
2345
    /* rtinit.  */
2346
    88,       /* _xcoff_rtinit_size */
2347
    xcoff64_generate_rtinit,
2348
2349
    /* Stub indirect call.  */
2350
    &xcoff64_stub_indirect_call_code[0],
2351
    16,       /* _xcoff_stub_indirect_call_size */
2352
2353
    /* Stub shared call.  */
2354
    &xcoff64_stub_shared_call_code[0],
2355
    24,       /* _xcoff_stub_shared_call_size */
2356
  };
2357
2358
/* The transfer vector that leads the outside world to all of the above.  */
2359
const bfd_target rs6000_xcoff64_vec =
2360
  {
2361
    "aixcoff64-rs6000",
2362
    bfd_target_xcoff_flavour,
2363
    BFD_ENDIAN_BIG,   /* data byte order is big */
2364
    BFD_ENDIAN_BIG,   /* header byte order is big */
2365
2366
    (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | DYNAMIC
2367
     | HAS_SYMS | HAS_LOCALS | WP_TEXT),
2368
2369
    SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA,
2370
    0,        /* leading char */
2371
    '/',      /* ar_pad_char */
2372
    15,       /* ar_max_namelen */
2373
    0,        /* match priority.  */
2374
    TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols.  */
2375
    TARGET_MERGE_SECTIONS,
2376
2377
    /* data */
2378
    bfd_getb64,
2379
    bfd_getb_signed_64,
2380
    bfd_putb64,
2381
    bfd_getb32,
2382
    bfd_getb_signed_32,
2383
    bfd_putb32,
2384
    bfd_getb16,
2385
    bfd_getb_signed_16,
2386
    bfd_putb16,
2387
2388
    /* hdrs */
2389
    bfd_getb64,
2390
    bfd_getb_signed_64,
2391
    bfd_putb64,
2392
    bfd_getb32,
2393
    bfd_getb_signed_32,
2394
    bfd_putb32,
2395
    bfd_getb16,
2396
    bfd_getb_signed_16,
2397
    bfd_putb16,
2398
2399
    { /* bfd_check_format */
2400
      _bfd_dummy_target,
2401
      coff_object_p,
2402
      xcoff64_archive_p,
2403
      CORE_FILE_P
2404
    },
2405
2406
    { /* bfd_set_format */
2407
      _bfd_bool_bfd_false_error,
2408
      coff_mkobject,
2409
      _bfd_generic_mkarchive,
2410
      _bfd_bool_bfd_false_error
2411
    },
2412
2413
    {/* bfd_write_contents */
2414
      _bfd_bool_bfd_false_error,
2415
      coff_write_object_contents,
2416
      _bfd_xcoff_write_archive_contents,
2417
      _bfd_bool_bfd_false_error
2418
    },
2419
2420
    /* Generic */
2421
    coff_close_and_cleanup,
2422
    _bfd_xcoff_bfd_free_cached_info,
2423
    coff_new_section_hook,
2424
    _bfd_generic_get_section_contents,
2425
2426
    /* Copy */
2427
    _bfd_xcoff_copy_private_bfd_data,
2428
    _bfd_generic_bfd_merge_private_bfd_data,
2429
    _bfd_generic_bfd_copy_private_section_data,
2430
    _bfd_generic_bfd_copy_private_symbol_data,
2431
    _bfd_generic_bfd_copy_private_header_data,
2432
    _bfd_generic_bfd_set_private_flags,
2433
    _bfd_generic_bfd_print_private_bfd_data,
2434
2435
    /* Core */
2436
    BFD_JUMP_TABLE_CORE (coff),
2437
2438
    /* Archive */
2439
    xcoff64_slurp_armap,
2440
    _bfd_noarchive_slurp_extended_name_table,
2441
    _bfd_noarchive_construct_extended_name_table,
2442
    bfd_dont_truncate_arname,
2443
    _bfd_xcoff_write_armap,
2444
    _bfd_xcoff_read_ar_hdr,
2445
    _bfd_generic_write_ar_hdr,
2446
    xcoff64_openr_next_archived_file,
2447
    _bfd_generic_get_elt_at_index,
2448
    _bfd_xcoff_stat_arch_elt,
2449
    _bfd_bool_bfd_true,
2450
2451
    /* Symbols */
2452
    coff_get_symtab_upper_bound,
2453
    coff_canonicalize_symtab,
2454
    coff_make_empty_symbol,
2455
    coff_print_symbol,
2456
    coff_get_symbol_info,
2457
    coff_get_symbol_version_string,
2458
    _bfd_xcoff_is_local_label_name,
2459
    coff_bfd_is_target_special_symbol,
2460
    coff_get_lineno,
2461
    coff_find_nearest_line,
2462
    coff_find_nearest_line_with_alt,
2463
    coff_find_line,
2464
    coff_find_inliner_info,
2465
    coff_bfd_make_debug_symbol,
2466
    _bfd_generic_read_minisymbols,
2467
    _bfd_generic_minisymbol_to_symbol,
2468
2469
    /* Reloc */
2470
    coff_get_reloc_upper_bound,
2471
    coff_canonicalize_reloc,
2472
    _bfd_generic_finalize_section_relocs,
2473
    xcoff64_reloc_type_lookup,
2474
    xcoff64_reloc_name_lookup,
2475
2476
    /* Write */
2477
    coff_set_arch_mach,
2478
    coff_set_section_contents,
2479
2480
    /* Link */
2481
    xcoff64_sizeof_headers,
2482
    bfd_generic_get_relocated_section_contents,
2483
    bfd_generic_relax_section,
2484
    _bfd_xcoff_bfd_link_hash_table_create,
2485
    _bfd_xcoff_bfd_link_add_symbols,
2486
    _bfd_generic_link_just_syms,
2487
    _bfd_generic_copy_link_hash_symbol_type,
2488
    _bfd_xcoff_bfd_final_link,
2489
    _bfd_generic_link_split_section,
2490
    _bfd_generic_link_check_relocs,
2491
    bfd_generic_gc_sections,
2492
    bfd_generic_lookup_section_flags,
2493
    bfd_generic_is_group_section,
2494
    bfd_generic_group_name,
2495
    bfd_generic_discard_group,
2496
    _bfd_generic_section_already_linked,
2497
    _bfd_xcoff_define_common_symbol,
2498
    _bfd_generic_link_hide_symbol,
2499
    bfd_generic_define_start_stop,
2500
2501
    /* Dynamic */
2502
    _bfd_xcoff_get_dynamic_symtab_upper_bound,
2503
    _bfd_xcoff_canonicalize_dynamic_symtab,
2504
    _bfd_nodynamic_get_synthetic_symtab,
2505
    _bfd_xcoff_get_dynamic_reloc_upper_bound,
2506
    _bfd_xcoff_canonicalize_dynamic_reloc,
2507
2508
    /* Opposite endian version, none exists */
2509
    NULL,
2510
2511
    &bfd_xcoff_backend_data,
2512
  };
2513
2514
extern bfd_cleanup xcoff64_core_p
2515
  (bfd *);
2516
extern bool xcoff64_core_file_matches_executable_p
2517
  (bfd *, bfd *);
2518
extern char *xcoff64_core_file_failing_command
2519
  (bfd *);
2520
extern int xcoff64_core_file_failing_signal
2521
  (bfd *);
2522
#define xcoff64_core_file_pid _bfd_nocore_core_file_pid
2523
2524
/* AIX 5 */
2525
static const struct xcoff_backend_data_rec bfd_xcoff_aix5_backend_data =
2526
  {
2527
    { /* COFF backend, defined in libcoff.h.  */
2528
      _bfd_xcoff64_swap_aux_in,
2529
      _bfd_xcoff64_swap_sym_in,
2530
      _bfd_xcoff64_swap_lineno_in,
2531
      _bfd_xcoff64_swap_aux_out,
2532
      _bfd_xcoff64_swap_sym_out,
2533
      _bfd_xcoff64_swap_lineno_out,
2534
      xcoff64_swap_reloc_out,
2535
      coff_swap_filehdr_out,
2536
      coff_swap_aouthdr_out,
2537
      coff_swap_scnhdr_out,
2538
      FILHSZ,
2539
      AOUTSZ,
2540
      SCNHSZ,
2541
      SYMESZ,
2542
      AUXESZ,
2543
      RELSZ,
2544
      LINESZ,
2545
      FILNMLEN,
2546
      true,     /* _bfd_coff_long_filenames */
2547
      XCOFF_NO_LONG_SECTION_NAMES,  /* _bfd_coff_long_section_names */
2548
      3,      /* _bfd_coff_default_section_alignment_power */
2549
      true,     /* _bfd_coff_force_symnames_in_strings */
2550
      4,      /* _bfd_coff_debug_string_prefix_length */
2551
      32768,      /* _bfd_coff_max_nscns */
2552
      coff_swap_filehdr_in,
2553
      coff_swap_aouthdr_in,
2554
      coff_swap_scnhdr_in,
2555
      xcoff64_swap_reloc_in,
2556
      xcoff64_bad_format_hook,
2557
      coff_set_arch_mach_hook,
2558
      coff_mkobject_hook,
2559
      styp_to_sec_flags,
2560
      coff_set_alignment_hook,
2561
      coff_slurp_symbol_table,
2562
      symname_in_debug_hook,
2563
      coff_pointerize_aux_hook,
2564
      coff_print_aux,
2565
      dummy_reloc16_extra_cases,
2566
      dummy_reloc16_estimate,
2567
      NULL,     /* bfd_coff_sym_is_global */
2568
      coff_compute_section_file_positions,
2569
      NULL,     /* _bfd_coff_start_final_link */
2570
      xcoff64_ppc_relocate_section,
2571
      coff_rtype_to_howto,
2572
      NULL,     /* _bfd_coff_adjust_symndx */
2573
      coff_link_output_has_begun,
2574
      coff_final_link_postscript,
2575
      NULL      /* print_pdata.  */
2576
    },
2577
2578
    U64_TOCMAGIC,   /* magic number */
2579
    bfd_arch_powerpc,
2580
    bfd_mach_ppc_620,
2581
2582
    /* Function pointers to xcoff specific swap routines.  */
2583
    xcoff64_swap_ldhdr_in,
2584
    xcoff64_swap_ldhdr_out,
2585
    xcoff64_swap_ldsym_in,
2586
    xcoff64_swap_ldsym_out,
2587
    xcoff64_swap_ldrel_in,
2588
    xcoff64_swap_ldrel_out,
2589
2590
    /* Sizes.  */
2591
    LDHDRSZ,
2592
    LDSYMSZ,
2593
    LDRELSZ,
2594
    24,       /* _xcoff_function_descriptor_size */
2595
    0,        /* _xcoff_small_aout_header_size */
2596
    /* Versions.  */
2597
    2,        /* _xcoff_ldhdr_version */
2598
2599
    _bfd_xcoff64_put_symbol_name,
2600
    _bfd_xcoff64_put_ldsymbol_name,
2601
    &xcoff64_dynamic_reloc,
2602
    xcoff64_create_csect_from_smclas,
2603
2604
    /* Lineno and reloc count overflow.  */
2605
    xcoff64_is_lineno_count_overflow,
2606
    xcoff64_is_reloc_count_overflow,
2607
2608
    xcoff64_loader_symbol_offset,
2609
    xcoff64_loader_reloc_offset,
2610
2611
    /* glink.  */
2612
    &xcoff64_glink_code[0],
2613
    40,       /* _xcoff_glink_size */
2614
2615
    /* rtinit.  */
2616
    88,       /* _xcoff_rtinit_size */
2617
    xcoff64_generate_rtinit,
2618
2619
    /* Stub indirect call.  */
2620
    &xcoff64_stub_indirect_call_code[0],
2621
    16,       /* _xcoff_stub_indirect_call_size */
2622
2623
    /* Stub shared call.  */
2624
    &xcoff64_stub_shared_call_code[0],
2625
    24,       /* _xcoff_stub_shared_call_size */
2626
  };
2627
2628
/* The transfer vector that leads the outside world to all of the above.  */
2629
const bfd_target rs6000_xcoff64_aix_vec =
2630
  {
2631
    "aix5coff64-rs6000",
2632
    bfd_target_xcoff_flavour,
2633
    BFD_ENDIAN_BIG,   /* data byte order is big */
2634
    BFD_ENDIAN_BIG,   /* header byte order is big */
2635
2636
    (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | DYNAMIC
2637
     | HAS_SYMS | HAS_LOCALS | WP_TEXT),
2638
2639
    SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA,
2640
    0,        /* leading char */
2641
    '/',      /* ar_pad_char */
2642
    15,       /* ar_max_namelen */
2643
    0,        /* match priority.  */
2644
    TARGET_KEEP_UNUSED_SECTION_SYMBOLS, /* keep unused section symbols.  */
2645
    TARGET_MERGE_SECTIONS,
2646
2647
    /* data */
2648
    bfd_getb64,
2649
    bfd_getb_signed_64,
2650
    bfd_putb64,
2651
    bfd_getb32,
2652
    bfd_getb_signed_32,
2653
    bfd_putb32,
2654
    bfd_getb16,
2655
    bfd_getb_signed_16,
2656
    bfd_putb16,
2657
2658
    /* hdrs */
2659
    bfd_getb64,
2660
    bfd_getb_signed_64,
2661
    bfd_putb64,
2662
    bfd_getb32,
2663
    bfd_getb_signed_32,
2664
    bfd_putb32,
2665
    bfd_getb16,
2666
    bfd_getb_signed_16,
2667
    bfd_putb16,
2668
2669
    { /* bfd_check_format */
2670
      _bfd_dummy_target,
2671
      coff_object_p,
2672
      xcoff64_archive_p,
2673
      xcoff64_core_p
2674
    },
2675
2676
    { /* bfd_set_format */
2677
      _bfd_bool_bfd_false_error,
2678
      coff_mkobject,
2679
      _bfd_generic_mkarchive,
2680
      _bfd_bool_bfd_false_error
2681
    },
2682
2683
    {/* bfd_write_contents */
2684
      _bfd_bool_bfd_false_error,
2685
      coff_write_object_contents,
2686
      _bfd_xcoff_write_archive_contents,
2687
      _bfd_bool_bfd_false_error
2688
    },
2689
2690
    /* Generic */
2691
    coff_close_and_cleanup,
2692
    _bfd_xcoff_bfd_free_cached_info,
2693
    coff_new_section_hook,
2694
    _bfd_generic_get_section_contents,
2695
2696
    /* Copy */
2697
    _bfd_xcoff_copy_private_bfd_data,
2698
    _bfd_generic_bfd_merge_private_bfd_data,
2699
    _bfd_generic_bfd_copy_private_section_data,
2700
    _bfd_generic_bfd_copy_private_symbol_data,
2701
    _bfd_generic_bfd_copy_private_header_data,
2702
    _bfd_generic_bfd_set_private_flags,
2703
    _bfd_generic_bfd_print_private_bfd_data,
2704
2705
    /* Core */
2706
    BFD_JUMP_TABLE_CORE (xcoff64),
2707
2708
    /* Archive */
2709
    xcoff64_slurp_armap,
2710
    _bfd_noarchive_slurp_extended_name_table,
2711
    _bfd_noarchive_construct_extended_name_table,
2712
    bfd_dont_truncate_arname,
2713
    _bfd_xcoff_write_armap,
2714
    _bfd_xcoff_read_ar_hdr,
2715
    _bfd_generic_write_ar_hdr,
2716
    xcoff64_openr_next_archived_file,
2717
    _bfd_generic_get_elt_at_index,
2718
    _bfd_xcoff_stat_arch_elt,
2719
    _bfd_bool_bfd_true,
2720
2721
    /* Symbols */
2722
    coff_get_symtab_upper_bound,
2723
    coff_canonicalize_symtab,
2724
    coff_make_empty_symbol,
2725
    coff_print_symbol,
2726
    coff_get_symbol_info,
2727
    coff_get_symbol_version_string,
2728
    _bfd_xcoff_is_local_label_name,
2729
    coff_bfd_is_target_special_symbol,
2730
    coff_get_lineno,
2731
    coff_find_nearest_line,
2732
    coff_find_nearest_line_with_alt,
2733
    coff_find_line,
2734
    coff_find_inliner_info,
2735
    coff_bfd_make_debug_symbol,
2736
    _bfd_generic_read_minisymbols,
2737
    _bfd_generic_minisymbol_to_symbol,
2738
2739
    /* Reloc */
2740
    coff_get_reloc_upper_bound,
2741
    coff_canonicalize_reloc,
2742
    _bfd_generic_finalize_section_relocs,
2743
    xcoff64_reloc_type_lookup,
2744
    xcoff64_reloc_name_lookup,
2745
2746
    /* Write */
2747
    coff_set_arch_mach,
2748
    coff_set_section_contents,
2749
2750
    /* Link */
2751
    xcoff64_sizeof_headers,
2752
    bfd_generic_get_relocated_section_contents,
2753
    bfd_generic_relax_section,
2754
    _bfd_xcoff_bfd_link_hash_table_create,
2755
    _bfd_xcoff_bfd_link_add_symbols,
2756
    _bfd_generic_link_just_syms,
2757
    _bfd_generic_copy_link_hash_symbol_type,
2758
    _bfd_xcoff_bfd_final_link,
2759
    _bfd_generic_link_split_section,
2760
    _bfd_generic_link_check_relocs,
2761
    bfd_generic_gc_sections,
2762
    bfd_generic_lookup_section_flags,
2763
    bfd_generic_is_group_section,
2764
    bfd_generic_group_name,
2765
    bfd_generic_discard_group,
2766
    _bfd_generic_section_already_linked,
2767
    _bfd_xcoff_define_common_symbol,
2768
    _bfd_generic_link_hide_symbol,
2769
    bfd_generic_define_start_stop,
2770
2771
    /* Dynamic */
2772
    _bfd_xcoff_get_dynamic_symtab_upper_bound,
2773
    _bfd_xcoff_canonicalize_dynamic_symtab,
2774
    _bfd_nodynamic_get_synthetic_symtab,
2775
    _bfd_xcoff_get_dynamic_reloc_upper_bound,
2776
    _bfd_xcoff_canonicalize_dynamic_reloc,
2777
2778
    /* Opposite endian version, none exists.  */
2779
    NULL,
2780
2781
    & bfd_xcoff_aix5_backend_data,
2782
  };