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