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