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