2002-02-18 David O'Brien <obrien@FreeBSD.org>
[binutils.git] / bfd / coff64-rs6000.c
blobd66a70e71592ed24ecd881d0ec6d7cc4578161b2
1 /* BFD back-end for IBM RS/6000 "XCOFF64" files.
2 Copyright 2000, 2001
3 Free Software Foundation, Inc.
4 Written Clinton Popetz.
5 Contributed by Cygnus Support.
7 This file is part of BFD, the Binary File Descriptor library.
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.
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.
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. */
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"
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
68 #define COFF_FORCE_SYMBOLS_IN_STRINGS
69 #define COFF_DEBUG_STRING_WIDE_PREFIX
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)
80 #define NO_COFF_LINENOS
82 #define coff_SWAP_lineno_in _bfd_xcoff64_swap_lineno_in
83 #define coff_SWAP_lineno_out _bfd_xcoff64_swap_lineno_out
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_ldsymbol_name
88 PARAMS ((bfd *, struct xcoff_loader_info *, struct internal_ldsym *,
89 const char *));
90 static void _bfd_xcoff64_swap_sym_in PARAMS ((bfd *, PTR, PTR));
91 static unsigned int _bfd_xcoff64_swap_sym_out PARAMS ((bfd *, PTR, PTR));
92 static void _bfd_xcoff64_swap_aux_in
93 PARAMS ((bfd *, PTR, int, int, int, int, PTR));
94 static unsigned int _bfd_xcoff64_swap_aux_out
95 PARAMS ((bfd *, PTR, int, int, int, int, PTR));
96 extern boolean _bfd_xcoff_mkobject PARAMS ((bfd *));
97 extern boolean _bfd_xcoff_copy_private_bfd_data PARAMS ((bfd *, bfd *));
98 extern boolean _bfd_xcoff_is_local_label_name PARAMS ((bfd *, const char *));
99 extern void xcoff64_rtype2howto
100 PARAMS ((arelent *, struct internal_reloc *));
101 extern reloc_howto_type * xcoff64_reloc_type_lookup
102 PARAMS ((bfd *, bfd_reloc_code_real_type));
103 extern boolean _bfd_xcoff_slurp_armap PARAMS ((bfd *));
104 extern PTR _bfd_xcoff_read_ar_hdr PARAMS ((bfd *));
105 extern bfd *_bfd_xcoff_openr_next_archived_file PARAMS ((bfd *, bfd *));
106 extern int _bfd_xcoff_generic_stat_arch_elt PARAMS ((bfd *, struct stat *));
107 extern boolean _bfd_xcoff_write_armap
108 PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int));
109 extern boolean _bfd_xcoff_write_archive_contents PARAMS ((bfd *));
110 extern int _bfd_xcoff_sizeof_headers PARAMS ((bfd *, boolean));
111 extern void _bfd_xcoff_swap_sym_in PARAMS ((bfd *, PTR, PTR));
112 extern unsigned int _bfd_xcoff_swap_sym_out PARAMS ((bfd *, PTR, PTR));
113 extern void _bfd_xcoff_swap_aux_in
114 PARAMS ((bfd *, PTR, int, int, int, int, PTR));
115 extern unsigned int _bfd_xcoff_swap_aux_out
116 PARAMS ((bfd *, PTR, int, int, int, int, PTR));
117 static void xcoff64_swap_ldhdr_in
118 PARAMS ((bfd *, const PTR, struct internal_ldhdr *));
119 static void xcoff64_swap_ldhdr_out
120 PARAMS ((bfd *, const struct internal_ldhdr *, PTR d));
121 static void xcoff64_swap_ldsym_in
122 PARAMS ((bfd *, const PTR, struct internal_ldsym *));
123 static void xcoff64_swap_ldsym_out
124 PARAMS ((bfd *, const struct internal_ldsym *, PTR d));
125 static void xcoff64_swap_ldrel_in
126 PARAMS ((bfd *, const PTR, struct internal_ldrel *));
127 static void xcoff64_swap_ldrel_out
128 PARAMS ((bfd *, const struct internal_ldrel *, PTR d));
129 static boolean xcoff64_write_object_contents PARAMS ((bfd *));
130 static boolean xcoff64_ppc_relocate_section
131 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
132 struct internal_reloc *, struct internal_syment *,
133 asection **sections));
134 static boolean xcoff64_slurp_armap PARAMS ((bfd *));
135 static const bfd_target *xcoff64_archive_p PARAMS ((bfd *));
136 static bfd *xcoff64_openr_next_archived_file PARAMS ((bfd *, bfd *));
137 static int xcoff64_sizeof_headers PARAMS ((bfd *, boolean));
138 static asection *xcoff64_create_csect_from_smclas
139 PARAMS ((bfd *, union internal_auxent *, const char *));
140 static boolean xcoff64_is_lineno_count_overflow PARAMS ((bfd *, bfd_vma));
141 static boolean xcoff64_is_reloc_count_overflow PARAMS ((bfd *, bfd_vma));
142 static bfd_vma xcoff64_loader_symbol_offset
143 PARAMS ((bfd *, struct internal_ldhdr *));
144 static bfd_vma xcoff64_loader_reloc_offset
145 PARAMS ((bfd *, struct internal_ldhdr *));
146 static boolean xcoff64_generate_rtinit
147 PARAMS((bfd *, const char *, const char *));
150 /* coffcode.h needs these to be defined */
151 /* Internalcoff.h and coffcode.h modify themselves based on these flags. */
152 #define XCOFF64
153 #define RS6000COFF_C 1
155 #define SELECT_RELOC(internal, howto) \
157 internal.r_type = howto->type; \
158 internal.r_size = \
159 ((howto->complain_on_overflow == complain_overflow_signed \
160 ? 0x80 \
161 : 0) \
162 | (howto->bitsize - 1)); \
165 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
166 #define COFF_LONG_FILENAMES
167 #define NO_COFF_SYMBOLS
168 #define RTYPE2HOWTO(cache_ptr, dst) xcoff64_rtype2howto (cache_ptr, dst)
169 #define coff_mkobject _bfd_xcoff_mkobject
170 #define coff_bfd_copy_private_bfd_data _bfd_xcoff_copy_private_bfd_data
171 #define coff_bfd_is_local_label_name _bfd_xcoff_is_local_label_name
172 #define coff_bfd_reloc_type_lookup xcoff64_reloc_type_lookup
173 #ifdef AIX_CORE
174 extern const bfd_target * rs6000coff_core_p ();
175 extern boolean rs6000coff_core_file_matches_executable_p ();
176 extern char *rs6000coff_core_file_failing_command PARAMS ((bfd *abfd));
177 extern int rs6000coff_core_file_failing_signal PARAMS ((bfd *abfd));
178 #define CORE_FILE_P rs6000coff_core_p
179 #define coff_core_file_failing_command \
180 rs6000coff_core_file_failing_command
181 #define coff_core_file_failing_signal \
182 rs6000coff_core_file_failing_signal
183 #define coff_core_file_matches_executable_p \
184 rs6000coff_core_file_matches_executable_p
185 #else
186 #define CORE_FILE_P _bfd_dummy_target
187 #define coff_core_file_failing_command \
188 _bfd_nocore_core_file_failing_command
189 #define coff_core_file_failing_signal \
190 _bfd_nocore_core_file_failing_signal
191 #define coff_core_file_matches_executable_p \
192 _bfd_nocore_core_file_matches_executable_p
193 #endif
194 #define coff_SWAP_sym_in _bfd_xcoff64_swap_sym_in
195 #define coff_SWAP_sym_out _bfd_xcoff64_swap_sym_out
196 #define coff_SWAP_aux_in _bfd_xcoff64_swap_aux_in
197 #define coff_SWAP_aux_out _bfd_xcoff64_swap_aux_out
200 #include "coffcode.h"
202 /* For XCOFF64, the effective width of symndx changes depending on
203 whether we are the first entry. Sigh. */
204 static void
205 _bfd_xcoff64_swap_lineno_in (abfd, ext1, in1)
206 bfd *abfd;
207 PTR ext1;
208 PTR in1;
210 LINENO *ext = (LINENO *) ext1;
211 struct internal_lineno *in = (struct internal_lineno *) in1;
213 in->l_lnno = H_GET_32 (abfd, (ext->l_lnno));
214 if (in->l_lnno == 0)
215 in->l_addr.l_symndx = H_GET_32 (abfd, ext->l_addr.l_symndx);
216 else
217 in->l_addr.l_paddr = H_GET_64 (abfd, ext->l_addr.l_paddr);
220 static unsigned int
221 _bfd_xcoff64_swap_lineno_out (abfd, inp, outp)
222 bfd *abfd;
223 PTR inp;
224 PTR outp;
226 struct internal_lineno *in = (struct internal_lineno *) inp;
227 struct external_lineno *ext = (struct external_lineno *) outp;
229 H_PUT_32 (abfd, in->l_addr.l_symndx, ext->l_addr.l_symndx);
230 H_PUT_32 (abfd, in->l_lnno, (ext->l_lnno));
232 if (in->l_lnno == 0)
233 H_PUT_32 (abfd, in->l_addr.l_symndx, ext->l_addr.l_symndx);
234 else
235 H_PUT_64 (abfd, in->l_addr.l_paddr, ext->l_addr.l_paddr);
237 return bfd_coff_linesz (abfd);
240 static void
241 _bfd_xcoff64_swap_sym_in (abfd, ext1, in1)
242 bfd *abfd;
243 PTR ext1;
244 PTR in1;
246 struct external_syment *ext = (struct external_syment *) ext1;
247 struct internal_syment *in = (struct internal_syment *) in1;
249 in->_n._n_n._n_zeroes = 0;
250 in->_n._n_n._n_offset = H_GET_32 (abfd, ext->e_offset);
251 in->n_value = H_GET_64 (abfd, ext->e_value);
252 in->n_scnum = H_GET_16 (abfd, ext->e_scnum);
253 in->n_type = H_GET_16 (abfd, ext->e_type);
254 in->n_sclass = H_GET_8 (abfd, ext->e_sclass);
255 in->n_numaux = H_GET_8 (abfd, ext->e_numaux);
258 static unsigned int
259 _bfd_xcoff64_swap_sym_out (abfd, inp, extp)
260 bfd *abfd;
261 PTR inp;
262 PTR extp;
264 struct internal_syment *in = (struct internal_syment *) inp;
265 struct external_syment *ext = (struct external_syment *) extp;
267 H_PUT_32 (abfd, in->_n._n_n._n_offset, ext->e_offset);
268 H_PUT_64 (abfd, in->n_value, ext->e_value);
269 H_PUT_16 (abfd, in->n_scnum, ext->e_scnum);
270 H_PUT_16 (abfd, in->n_type, ext->e_type);
271 H_PUT_8 (abfd, in->n_sclass, ext->e_sclass);
272 H_PUT_8 (abfd, in->n_numaux, ext->e_numaux);
273 return bfd_coff_symesz (abfd);
276 static void
277 _bfd_xcoff64_swap_aux_in (abfd, ext1, type, class, indx, numaux, in1)
278 bfd *abfd;
279 PTR ext1;
280 int type;
281 int class;
282 int indx;
283 int numaux;
284 PTR in1;
286 union external_auxent *ext = (union external_auxent *) ext1;
287 union internal_auxent *in = (union internal_auxent *) in1;
289 switch (class)
291 case C_FILE:
292 if (ext->x_file.x_n.x_zeroes == 0)
294 in->x_file.x_n.x_zeroes = 0;
295 in->x_file.x_n.x_offset = H_GET_32 (abfd, ext->x_file.x_n.x_offset);
297 else
299 memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN);
301 goto end;
303 /* RS/6000 "csect" auxents */
304 case C_EXT:
305 case C_HIDEXT:
306 if (indx + 1 == numaux)
308 bfd_signed_vma h = 0;
309 bfd_vma l = 0;
311 h = H_GET_S32 (abfd, ext->x_csect.x_scnlen_hi);
312 l = H_GET_32 (abfd, ext->x_csect.x_scnlen_lo);
314 in->x_csect.x_scnlen.l = h << 32 | (l & 0xffffffff);
316 in->x_csect.x_parmhash = H_GET_32 (abfd, ext->x_csect.x_parmhash);
317 in->x_csect.x_snhash = H_GET_16 (abfd, ext->x_csect.x_snhash);
318 /* We don't have to hack bitfields in x_smtyp because it's
319 defined by shifts-and-ands, which are equivalent on all
320 byte orders. */
321 in->x_csect.x_smtyp = H_GET_8 (abfd, ext->x_csect.x_smtyp);
322 in->x_csect.x_smclas = H_GET_8 (abfd, ext->x_csect.x_smclas);
323 goto end;
325 break;
327 case C_STAT:
328 case C_LEAFSTAT:
329 case C_HIDDEN:
330 if (type == T_NULL)
332 /* PE defines some extra fields; we zero them out for
333 safety. */
334 in->x_scn.x_checksum = 0;
335 in->x_scn.x_associated = 0;
336 in->x_scn.x_comdat = 0;
338 goto end;
340 break;
343 if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
345 in->x_sym.x_fcnary.x_fcn.x_lnnoptr
346 = H_GET_64 (abfd, ext->x_sym.x_fcnary.x_fcn.x_lnnoptr);
347 in->x_sym.x_fcnary.x_fcn.x_endndx.l
348 = H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_endndx);
350 if (ISFCN (type))
352 in->x_sym.x_misc.x_fsize
353 = H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_fsize);
355 else
357 in->x_sym.x_misc.x_lnsz.x_lnno
358 = H_GET_32 (abfd, ext->x_sym.x_fcnary.x_lnsz.x_lnno);
359 in->x_sym.x_misc.x_lnsz.x_size
360 = H_GET_16 (abfd, ext->x_sym.x_fcnary.x_lnsz.x_size);
363 end: ;
366 static unsigned int
367 _bfd_xcoff64_swap_aux_out (abfd, inp, type, class, indx, numaux, extp)
368 bfd *abfd;
369 PTR inp;
370 int type;
371 int class;
372 int indx ATTRIBUTE_UNUSED;
373 int numaux ATTRIBUTE_UNUSED;
374 PTR extp;
376 union internal_auxent *in = (union internal_auxent *) inp;
377 union external_auxent *ext = (union external_auxent *) extp;
379 memset ((PTR) ext, 0, bfd_coff_auxesz (abfd));
380 switch (class)
382 case C_FILE:
383 if (ext->x_file.x_n.x_zeroes == 0)
385 H_PUT_32 (abfd, 0, ext->x_file.x_n.x_zeroes);
386 H_PUT_32 (abfd, in->x_file.x_n.x_offset, ext->x_file.x_n.x_offset);
388 else
390 memcpy (ext->x_file.x_fname, in->x_file.x_fname, FILNMLEN);
392 H_PUT_8 (abfd, _AUX_FILE, ext->x_auxtype.x_auxtype);
393 goto end;
395 /* RS/6000 "csect" auxents */
396 case C_EXT:
397 case C_HIDEXT:
398 if (indx + 1 == numaux)
400 bfd_vma temp;
402 temp = in->x_csect.x_scnlen.l & 0xffffffff;
403 H_PUT_32 (abfd, temp, ext->x_csect.x_scnlen_lo);
404 temp = in->x_csect.x_scnlen.l >> 32;
405 H_PUT_32 (abfd, temp, ext->x_csect.x_scnlen_hi);
406 H_PUT_32 (abfd, in->x_csect.x_parmhash, ext->x_csect.x_parmhash);
407 H_PUT_16 (abfd, in->x_csect.x_snhash, ext->x_csect.x_snhash);
408 /* We don't have to hack bitfields in x_smtyp because it's
409 defined by shifts-and-ands, which are equivalent on all
410 byte orders. */
411 H_PUT_8 (abfd, in->x_csect.x_smtyp, ext->x_csect.x_smtyp);
412 H_PUT_8 (abfd, in->x_csect.x_smclas, ext->x_csect.x_smclas);
413 H_PUT_8 (abfd, _AUX_CSECT, ext->x_auxtype.x_auxtype);
414 goto end;
416 break;
418 case C_STAT:
419 case C_LEAFSTAT:
420 case C_HIDDEN:
421 if (type == T_NULL)
423 goto end;
425 break;
428 if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
430 H_PUT_64 (abfd, in->x_sym.x_fcnary.x_fcn.x_lnnoptr,
431 ext->x_sym.x_fcnary.x_fcn.x_lnnoptr);
432 H_PUT_8 (abfd, _AUX_FCN,
433 ext->x_auxtype.x_auxtype);
434 H_PUT_32 (abfd, in->x_sym.x_fcnary.x_fcn.x_endndx.l,
435 ext->x_sym.x_fcnary.x_fcn.x_endndx);
437 if (ISFCN (type))
439 H_PUT_32 (abfd, in->x_sym.x_misc.x_fsize,
440 ext->x_sym.x_fcnary.x_fcn.x_fsize);
442 else
444 H_PUT_32 (abfd, in->x_sym.x_misc.x_lnsz.x_lnno,
445 ext->x_sym.x_fcnary.x_lnsz.x_lnno);
446 H_PUT_16 (abfd, in->x_sym.x_misc.x_lnsz.x_size,
447 ext->x_sym.x_fcnary.x_lnsz.x_size);
450 end:
452 return bfd_coff_auxesz (abfd);
455 static boolean
456 _bfd_xcoff64_put_symbol_name (bfd *abfd, struct bfd_strtab_hash *strtab,
457 struct internal_syment *sym,
458 const char *name) {
459 boolean hash;
460 bfd_size_type indx;
462 hash = true;
464 if ((abfd->flags & BFD_TRADITIONAL_FORMAT) != 0)
465 hash = false;
467 indx = _bfd_stringtab_add (strtab, name, hash, false);
469 if (indx == (bfd_size_type) -1)
470 return false;
472 sym->_n._n_n._n_zeroes = 0;
473 sym->_n._n_n._n_offset = STRING_SIZE_SIZE + indx;
475 return true;
478 static boolean
479 _bfd_xcoff64_put_ldsymbol_name (abfd, ldinfo, ldsym, name)
480 bfd *abfd ATTRIBUTE_UNUSED;
481 struct xcoff_loader_info *ldinfo;
482 struct internal_ldsym *ldsym;
483 const char *name;
486 size_t len;
487 len = strlen (name);
489 if (ldinfo->string_size + len + 3 > ldinfo->string_alc)
491 bfd_size_type newalc;
492 bfd_byte *newstrings;
494 newalc = ldinfo->string_alc * 2;
495 if (newalc == 0)
496 newalc = 32;
497 while (ldinfo->string_size + len + 3 > newalc)
498 newalc *= 2;
500 newstrings = ((bfd_byte *)
501 bfd_realloc ((PTR) ldinfo->strings, newalc));
502 if (newstrings == NULL)
504 ldinfo->failed = true;
505 return false;
507 ldinfo->string_alc = newalc;
508 ldinfo->strings = newstrings;
511 bfd_put_16 (ldinfo->output_bfd, (bfd_vma) (len + 1),
512 ldinfo->strings + ldinfo->string_size);
513 strcpy (ldinfo->strings + ldinfo->string_size + 2, name);
514 ldsym->_l._l_l._l_zeroes = 0;
515 ldsym->_l._l_l._l_offset = ldinfo->string_size + 2;
516 ldinfo->string_size += len + 3;
518 return true;
521 /* Routines to swap information in the XCOFF .loader section. If we
522 ever need to write an XCOFF loader, this stuff will need to be
523 moved to another file shared by the linker (which XCOFF calls the
524 ``binder'') and the loader. */
526 /* Swap in the ldhdr structure. */
528 static void
529 xcoff64_swap_ldhdr_in (abfd, s, dst)
530 bfd *abfd;
531 const PTR s;
532 struct internal_ldhdr *dst;
534 const struct external_ldhdr *src = (const struct external_ldhdr *) s;
536 dst->l_version = bfd_get_32 (abfd, src->l_version);
537 dst->l_nsyms = bfd_get_32 (abfd, src->l_nsyms);
538 dst->l_nreloc = bfd_get_32 (abfd, src->l_nreloc);
539 dst->l_istlen = bfd_get_32 (abfd, src->l_istlen);
540 dst->l_nimpid = bfd_get_32 (abfd, src->l_nimpid);
541 dst->l_stlen = bfd_get_32 (abfd, src->l_stlen);
542 dst->l_impoff = bfd_get_64 (abfd, src->l_impoff);
543 dst->l_stoff = bfd_get_64 (abfd, src->l_stoff);
544 dst->l_symoff = bfd_get_64 (abfd, src->l_symoff);
545 dst->l_rldoff = bfd_get_64 (abfd, src->l_rldoff);
548 /* Swap out the ldhdr structure. */
550 static void
551 xcoff64_swap_ldhdr_out (abfd, src, d)
552 bfd *abfd;
553 const struct internal_ldhdr *src;
554 PTR d;
556 struct external_ldhdr *dst = (struct external_ldhdr *) d;
558 bfd_put_32 (abfd, (bfd_vma) src->l_version, dst->l_version);
559 bfd_put_32 (abfd, src->l_nsyms, dst->l_nsyms);
560 bfd_put_32 (abfd, src->l_nreloc, dst->l_nreloc);
561 bfd_put_32 (abfd, src->l_istlen, dst->l_istlen);
562 bfd_put_32 (abfd, src->l_nimpid, dst->l_nimpid);
563 bfd_put_32 (abfd, src->l_stlen, dst->l_stlen);
564 bfd_put_64 (abfd, src->l_impoff, dst->l_impoff);
565 bfd_put_64 (abfd, src->l_stoff, dst->l_stoff);
566 bfd_put_64 (abfd, src->l_symoff, dst->l_symoff);
567 bfd_put_64 (abfd, src->l_rldoff, dst->l_rldoff);
570 /* Swap in the ldsym structure. */
572 static void
573 xcoff64_swap_ldsym_in (abfd, s, dst)
574 bfd *abfd;
575 const PTR s;
576 struct internal_ldsym *dst;
578 const struct external_ldsym *src = (const struct external_ldsym *) s;
579 /* XCOFF64 does not use l_zeroes like XCOFF32
580 Set the internal l_zeroes to 0 so the common 32/64 code uses l_value
581 as an offset into the loader symbol table. */
582 dst->_l._l_l._l_zeroes = 0;
583 dst->_l._l_l._l_offset = bfd_get_32 (abfd, src->l_offset);
584 dst->l_value = bfd_get_64 (abfd, src->l_value);
585 dst->l_scnum = bfd_get_16 (abfd, src->l_scnum);
586 dst->l_smtype = bfd_get_8 (abfd, src->l_smtype);
587 dst->l_smclas = bfd_get_8 (abfd, src->l_smclas);
588 dst->l_ifile = bfd_get_32 (abfd, src->l_ifile);
589 dst->l_parm = bfd_get_32 (abfd, src->l_parm);
592 /* Swap out the ldsym structure. */
594 static void
595 xcoff64_swap_ldsym_out (abfd, src, d)
596 bfd *abfd;
597 const struct internal_ldsym *src;
598 PTR d;
600 struct external_ldsym *dst = (struct external_ldsym *) d;
602 bfd_put_64 (abfd, src->l_value, dst->l_value);
603 bfd_put_32 (abfd, (bfd_vma) src->_l._l_l._l_offset, dst->l_offset);
604 bfd_put_16 (abfd, (bfd_vma) src->l_scnum, dst->l_scnum);
605 bfd_put_8 (abfd, src->l_smtype, dst->l_smtype);
606 bfd_put_8 (abfd, src->l_smclas, dst->l_smclas);
607 bfd_put_32 (abfd, src->l_ifile, dst->l_ifile);
608 bfd_put_32 (abfd, src->l_parm, dst->l_parm);
611 /* Swap in the ldrel structure. */
613 static void
614 xcoff64_swap_ldrel_in (abfd, s, dst)
615 bfd *abfd;
616 const PTR s;
617 struct internal_ldrel *dst;
619 const struct external_ldrel *src = (const struct external_ldrel *) s;
621 dst->l_vaddr = bfd_get_64 (abfd, src->l_vaddr);
622 dst->l_symndx = bfd_get_32 (abfd, src->l_symndx);
623 dst->l_rtype = bfd_get_16 (abfd, src->l_rtype);
624 dst->l_rsecnm = bfd_get_16 (abfd, src->l_rsecnm);
627 /* Swap out the ldrel structure. */
629 static void
630 xcoff64_swap_ldrel_out (abfd, src, d)
631 bfd *abfd;
632 const struct internal_ldrel *src;
633 PTR d;
635 struct external_ldrel *dst = (struct external_ldrel *) d;
637 bfd_put_64 (abfd, src->l_vaddr, dst->l_vaddr);
638 bfd_put_16 (abfd, (bfd_vma) src->l_rtype, dst->l_rtype);
639 bfd_put_16 (abfd, (bfd_vma) src->l_rsecnm, dst->l_rsecnm);
640 bfd_put_32 (abfd, src->l_symndx, dst->l_symndx);
643 static boolean
644 xcoff64_write_object_contents (abfd)
645 bfd * abfd;
647 asection *current;
648 boolean hasrelocs = false;
649 boolean haslinno = false;
650 file_ptr scn_base;
651 file_ptr reloc_base;
652 file_ptr lineno_base;
653 file_ptr sym_base;
654 unsigned long reloc_size = 0;
655 unsigned long lnno_size = 0;
656 boolean long_section_names;
657 asection *text_sec = ((void *) 0);
658 asection *data_sec = ((void *) 0);
659 asection *bss_sec = ((void *) 0);
660 struct internal_filehdr internal_f;
661 struct internal_aouthdr internal_a;
663 bfd_set_error (bfd_error_system_call);
665 if (abfd->output_has_begun == false)
667 if (! bfd_coff_compute_section_file_positions (abfd))
668 return false;
671 /* Work out the size of the reloc and linno areas */
672 reloc_base = obj_relocbase (abfd);
674 for (current = abfd->sections; current != NULL; current = current->next)
675 reloc_size += current->reloc_count * bfd_coff_relsz (abfd);
677 lineno_base = reloc_base + reloc_size;
679 /* Make a pass through the symbol table to count line number entries and
680 put them into the correct asections */
681 lnno_size = coff_count_linenumbers (abfd) * bfd_coff_linesz (abfd);
683 sym_base = lineno_base + lnno_size;
685 /* Indicate in each section->line_filepos its actual file address */
686 for (current = abfd->sections; current != NULL; current = current->next)
688 if (current->lineno_count)
690 current->line_filepos = lineno_base;
691 current->moving_line_filepos = lineno_base;
692 lineno_base += current->lineno_count * bfd_coff_linesz (abfd);
694 else
696 current->line_filepos = 0;
699 if (current->reloc_count)
701 current->rel_filepos = reloc_base;
702 reloc_base += current->reloc_count * bfd_coff_relsz (abfd);
704 else
706 current->rel_filepos = 0;
710 if ((abfd->flags & EXEC_P) != 0)
712 scn_base = bfd_coff_filhsz (abfd) + bfd_coff_aoutsz (abfd);
713 internal_f.f_opthdr = bfd_coff_aoutsz (abfd);
715 else
717 scn_base = bfd_coff_filhsz (abfd);
718 internal_f.f_opthdr = 0;
721 internal_f.f_nscns = 0;
723 if (bfd_seek (abfd, scn_base, SEEK_SET) != 0)
724 return false;
726 long_section_names = false;
727 for (current = abfd->sections; current != NULL; current = current->next)
729 struct internal_scnhdr section;
730 struct external_scnhdr buff;
731 bfd_size_type amount;
733 internal_f.f_nscns++;
735 strncpy (section.s_name, current->name, SCNNMLEN);
737 section.s_vaddr = current->vma;
738 section.s_paddr = current->lma;
739 section.s_size = current->_raw_size;
741 /* If this section has no size or is unloadable then the scnptr
742 will be 0 too. */
743 if (current->_raw_size == 0
744 || (current->flags & (SEC_LOAD | SEC_HAS_CONTENTS)) == 0)
746 section.s_scnptr = 0;
748 else
750 section.s_scnptr = current->filepos;
753 section.s_relptr = current->rel_filepos;
754 section.s_lnnoptr = current->line_filepos;
755 section.s_nreloc = current->reloc_count;
757 section.s_nlnno = current->lineno_count;
758 if (current->reloc_count != 0)
759 hasrelocs = true;
760 if (current->lineno_count != 0)
761 haslinno = true;
763 section.s_flags = sec_to_styp_flags (current->name, current->flags);
765 if (!strcmp (current->name, _TEXT))
767 text_sec = current;
769 else if (!strcmp (current->name, _DATA))
771 data_sec = current;
773 else if (!strcmp (current->name, _BSS))
775 bss_sec = current;
778 amount = bfd_coff_scnhsz (abfd);
779 if (bfd_coff_swap_scnhdr_out (abfd, &section, &buff) == 0
780 || bfd_bwrite ((PTR) (&buff), amount, abfd) != amount)
781 return false;
784 internal_f.f_timdat = 0;
786 internal_f.f_flags = 0;
788 if (!hasrelocs)
789 internal_f.f_flags |= F_RELFLG;
790 if (!haslinno)
791 internal_f.f_flags |= F_LNNO;
792 if (abfd->flags & EXEC_P)
793 internal_f.f_flags |= F_EXEC;
795 /* FIXME: this is wrong for PPC_PE! */
796 if (bfd_little_endian (abfd))
797 internal_f.f_flags |= F_AR32WR;
798 else
799 internal_f.f_flags |= F_AR32W;
801 if ((abfd->flags & DYNAMIC) != 0)
802 internal_f.f_flags |= F_SHROBJ;
803 if (bfd_get_section_by_name (abfd, _LOADER) != NULL)
804 internal_f.f_flags |= F_DYNLOAD;
806 memset (&internal_a, 0, sizeof internal_a);
809 /* This can only be called from the xcoff64 backend so the magic #
810 must be for xcoff64. */
811 internal_f.f_magic = 0757;
813 internal_a.magic = (abfd->flags & D_PAGED) ? RS6K_AOUTHDR_ZMAGIC :
814 (abfd->flags & WP_TEXT) ? RS6K_AOUTHDR_NMAGIC :
815 RS6K_AOUTHDR_OMAGIC;
817 /* FIXME: Does anybody ever set this to another value? */
818 internal_a.vstamp = 0;
820 /* Now should write relocs, strings, syms */
821 obj_sym_filepos (abfd) = sym_base;
823 internal_f.f_symptr = 0;
824 internal_f.f_nsyms = 0;
826 /* If bfd_get_symcount (abfd) != 0, then we are not using the COFF
827 backend linker, and obj_raw_syment_count is not valid until after
828 coff_write_symbols is called. */
829 if (bfd_get_symcount (abfd) != 0)
831 int firstundef;
833 if (!coff_renumber_symbols (abfd, &firstundef))
834 return false;
835 coff_mangle_symbols (abfd);
836 if (! coff_write_symbols (abfd))
837 return false;
838 if (! coff_write_linenumbers (abfd))
839 return false;
840 if (! coff_write_relocs (abfd, firstundef))
841 return false;
843 internal_f.f_symptr = sym_base;
844 internal_f.f_nsyms = bfd_get_symcount (abfd);
846 else if (obj_raw_syment_count (abfd) != 0)
848 internal_f.f_symptr = sym_base;
850 /* AIX appears to require that F_RELFLG not be set if there are
851 local symbols but no relocations. */
852 internal_f.f_flags &=~ F_RELFLG;
854 else
856 internal_f.f_flags |= F_LSYMS;
859 if (text_sec)
861 internal_a.tsize = bfd_get_section_size_before_reloc (text_sec);
862 internal_a.text_start = internal_a.tsize ? text_sec->vma : 0;
865 if (data_sec)
867 internal_a.dsize = bfd_get_section_size_before_reloc (data_sec);
868 internal_a.data_start = internal_a.dsize ? data_sec->vma : 0;
871 if (bss_sec)
873 internal_a.bsize = bfd_get_section_size_before_reloc (bss_sec);
874 if (internal_a.bsize && bss_sec->vma < internal_a.data_start)
875 internal_a.data_start = bss_sec->vma;
878 internal_a.entry = bfd_get_start_address (abfd);
879 internal_f.f_nsyms = obj_raw_syment_count (abfd);
881 if (xcoff_data (abfd)->full_aouthdr)
883 bfd_vma toc;
884 asection *loader_sec;
886 internal_a.vstamp = 1;
888 internal_a.o_snentry = xcoff_data (abfd)->snentry;
889 if (internal_a.o_snentry == 0)
890 internal_a.entry = (bfd_vma) -1;
892 if (text_sec != NULL)
894 internal_a.o_sntext = text_sec->target_index;
895 internal_a.o_algntext = bfd_get_section_alignment (abfd, text_sec);
897 else
899 internal_a.o_sntext = 0;
900 internal_a.o_algntext = 0;
903 if (data_sec != NULL)
905 internal_a.o_sndata = data_sec->target_index;
906 internal_a.o_algndata = bfd_get_section_alignment (abfd, data_sec);
908 else
910 internal_a.o_sndata = 0;
911 internal_a.o_algndata = 0;
914 loader_sec = bfd_get_section_by_name (abfd, ".loader");
915 if (loader_sec != NULL)
916 internal_a.o_snloader = loader_sec->target_index;
917 else
918 internal_a.o_snloader = 0;
919 if (bss_sec != NULL)
920 internal_a.o_snbss = bss_sec->target_index;
921 else
922 internal_a.o_snbss = 0;
924 toc = xcoff_data (abfd)->toc;
925 internal_a.o_toc = toc;
926 internal_a.o_sntoc = xcoff_data (abfd)->sntoc;
928 internal_a.o_modtype = xcoff_data (abfd)->modtype;
929 if (xcoff_data (abfd)->cputype != -1)
930 internal_a.o_cputype = xcoff_data (abfd)->cputype;
931 else
933 switch (bfd_get_arch (abfd))
935 case bfd_arch_rs6000:
936 internal_a.o_cputype = 4;
937 break;
938 case bfd_arch_powerpc:
939 if (bfd_get_mach (abfd) == 0)
940 internal_a.o_cputype = 3;
941 else
942 internal_a.o_cputype = 1;
943 break;
944 default:
945 abort ();
948 internal_a.o_maxstack = xcoff_data (abfd)->maxstack;
949 internal_a.o_maxdata = xcoff_data (abfd)->maxdata;
952 if (bfd_seek (abfd, (file_ptr) 0, 0) != 0)
953 return false;
956 char * buff;
957 bfd_size_type amount = bfd_coff_filhsz (abfd);
959 buff = bfd_malloc (amount);
960 if (buff == NULL)
961 return false;
963 bfd_coff_swap_filehdr_out (abfd, (PTR) &internal_f, (PTR) buff);
964 amount = bfd_bwrite ((PTR) buff, amount, abfd);
966 free (buff);
968 if (amount != bfd_coff_filhsz (abfd))
969 return false;
972 if (abfd->flags & EXEC_P)
974 char * buff;
975 bfd_size_type amount = bfd_coff_aoutsz (abfd);
977 buff = bfd_malloc (amount);
978 if (buff == NULL)
979 return false;
981 bfd_coff_swap_aouthdr_out (abfd, (PTR) & internal_a, (PTR) buff);
982 amount = bfd_bwrite ((PTR) buff, amount, abfd);
984 free (buff);
986 if (amount != bfd_coff_aoutsz (abfd))
987 return false;
990 return true;
993 /* This is the relocation function for the RS/6000/POWER/PowerPC.
994 This is currently the only processor which uses XCOFF; I hope that
995 will never change. */
997 static boolean
998 xcoff64_ppc_relocate_section (output_bfd, info, input_bfd,
999 input_section, contents, relocs, syms,
1000 sections)
1001 bfd *output_bfd;
1002 struct bfd_link_info *info;
1003 bfd *input_bfd;
1004 asection *input_section;
1005 bfd_byte *contents;
1006 struct internal_reloc *relocs;
1007 struct internal_syment *syms;
1008 asection **sections;
1010 struct internal_reloc *rel;
1011 struct internal_reloc *relend;
1013 rel = relocs;
1014 relend = rel + input_section->reloc_count;
1015 for (; rel < relend; rel++)
1017 long symndx;
1018 struct xcoff_link_hash_entry *h;
1019 struct internal_syment *sym;
1020 bfd_vma addend;
1021 bfd_vma val;
1022 struct reloc_howto_struct howto;
1023 bfd_reloc_status_type rstat;
1025 /* Relocation type R_REF is a special relocation type which is
1026 merely used to prevent garbage collection from occurring for
1027 the csect including the symbol which it references. */
1028 if (rel->r_type == R_REF)
1029 continue;
1031 symndx = rel->r_symndx;
1033 if (symndx == -1)
1035 h = NULL;
1036 sym = NULL;
1037 addend = 0;
1039 else
1041 h = obj_xcoff_sym_hashes (input_bfd)[symndx];
1042 sym = syms + symndx;
1043 addend = - sym->n_value;
1046 /* We build the howto information on the fly. */
1048 howto.type = rel->r_type;
1049 howto.rightshift = 0;
1050 howto.size = 4;
1051 howto.bitsize = (rel->r_size & 0x3f) + 1;
1052 howto.pc_relative = false;
1053 howto.bitpos = 0;
1054 if ((rel->r_size & 0x80) != 0)
1055 howto.complain_on_overflow = complain_overflow_signed;
1056 else
1057 howto.complain_on_overflow = complain_overflow_bitfield;
1058 howto.special_function = NULL;
1059 howto.name = "internal";
1060 howto.partial_inplace = true;
1062 if (howto.bitsize == 64)
1064 howto.src_mask = howto.dst_mask = MINUS_ONE;
1066 else if (howto.bitsize == 32)
1068 howto.src_mask = howto.dst_mask = 0xffffffff;
1070 else
1072 howto.src_mask = howto.dst_mask = (1 << howto.bitsize) - 1;
1073 if (howto.bitsize == 16)
1074 howto.size = 1;
1076 howto.pcrel_offset = false;
1078 val = 0;
1080 if (h == NULL)
1082 asection *sec;
1084 if (symndx == -1)
1086 sec = bfd_abs_section_ptr;
1087 val = 0;
1089 else
1091 sec = sections[symndx];
1092 /* Hack to make sure we use the right TOC anchor value
1093 if this reloc is against the TOC anchor. */
1094 if (sec->name[3] == '0'
1095 && strcmp (sec->name, ".tc0") == 0)
1096 val = xcoff_data (output_bfd)->toc;
1097 else
1098 val = (sec->output_section->vma
1099 + sec->output_offset
1100 + sym->n_value
1101 - sec->vma);
1105 else
1108 if (h->root.type == bfd_link_hash_defined
1109 || h->root.type == bfd_link_hash_defweak)
1111 asection *sec;
1113 sec = h->root.u.def.section;
1114 val = (h->root.u.def.value
1115 + sec->output_section->vma
1116 + sec->output_offset);
1119 else if (h->root.type == bfd_link_hash_common)
1121 asection *sec;
1123 sec = h->root.u.c.p->section;
1124 val = (sec->output_section->vma
1125 + sec->output_offset);
1127 else if ((h->flags & XCOFF_DEF_DYNAMIC) != 0
1128 || (h->flags & XCOFF_IMPORT) != 0)
1130 /* Every symbol in a shared object is defined somewhere. */
1131 val = 0;
1133 else if (! info->relocateable)
1135 if (! ((*info->callbacks->undefined_symbol)
1136 (info, h->root.root.string, input_bfd, input_section,
1137 rel->r_vaddr - input_section->vma, true)))
1138 return false;
1140 /* Don't try to process the reloc. It can't help, and
1141 it may generate another error. */
1142 continue;
1146 /* I took the relocation type definitions from two documents:
1147 the PowerPC AIX Version 4 Application Binary Interface, First
1148 Edition (April 1992), and the PowerOpen ABI, Big-Endian
1149 32-Bit Hardware Implementation (June 30, 1994). Differences
1150 between the documents are noted below. */
1152 switch (rel->r_type)
1154 case R_RTB:
1155 case R_RRTBI:
1156 case R_RRTBA:
1157 /* These relocs are defined by the PowerPC ABI to be
1158 relative branches which use half of the difference
1159 between the symbol and the program counter. I can't
1160 quite figure out when this is useful. These relocs are
1161 not defined by the PowerOpen ABI. */
1162 default:
1163 (*_bfd_error_handler)
1164 (_("%s: unsupported relocation type 0x%02x"),
1165 bfd_archive_filename (input_bfd), (unsigned int) rel->r_type);
1166 bfd_set_error (bfd_error_bad_value);
1167 return false;
1168 case R_POS:
1169 /* Simple positive relocation. */
1170 break;
1171 case R_NEG:
1172 /* Simple negative relocation. */
1173 val = - val;
1174 break;
1175 case R_REL:
1176 /* Simple PC relative relocation. */
1177 howto.pc_relative = true;
1178 break;
1179 case R_TOC:
1180 /* TOC relative relocation. The value in the instruction in
1181 the input file is the offset from the input file TOC to
1182 the desired location. We want the offset from the final
1183 TOC to the desired location. We have:
1184 isym = iTOC + in
1185 iinsn = in + o
1186 osym = oTOC + on
1187 oinsn = on + o
1188 so we must change insn by on - in.
1190 case R_GL:
1191 /* Global linkage relocation. The value of this relocation
1192 is the address of the entry in the TOC section. */
1193 case R_TCL:
1194 /* Local object TOC address. I can't figure out the
1195 difference between this and case R_GL. */
1196 case R_TRL:
1197 /* TOC relative relocation. A TOC relative load instruction
1198 which may be changed to a load address instruction.
1199 FIXME: We don't currently implement this optimization. */
1200 case R_TRLA:
1201 /* TOC relative relocation. This is a TOC relative load
1202 address instruction which may be changed to a load
1203 instruction. FIXME: I don't know if this is the correct
1204 implementation. */
1205 if (h != NULL && h->smclas != XMC_TD)
1207 if (h->toc_section == NULL)
1209 (*_bfd_error_handler)
1210 (_("%s: TOC reloc at 0x%x to symbol `%s' with no TOC entry"),
1211 bfd_archive_filename (input_bfd), rel->r_vaddr,
1212 h->root.root.string);
1213 bfd_set_error (bfd_error_bad_value);
1214 return false;
1217 BFD_ASSERT ((h->flags & XCOFF_SET_TOC) == 0);
1218 val = (h->toc_section->output_section->vma
1219 + h->toc_section->output_offset);
1222 val = ((val - xcoff_data (output_bfd)->toc)
1223 - (sym->n_value - xcoff_data (input_bfd)->toc));
1225 addend = 0;
1226 break;
1227 case R_BA:
1228 /* Absolute branch. We don't want to mess with the lower
1229 two bits of the instruction. */
1230 case R_CAI:
1231 /* The PowerPC ABI defines this as an absolute call which
1232 may be modified to become a relative call. The PowerOpen
1233 ABI does not define this relocation type. */
1234 case R_RBA:
1235 /* Absolute branch which may be modified to become a
1236 relative branch. */
1237 case R_RBAC:
1238 /* The PowerPC ABI defines this as an absolute branch to a
1239 fixed address which may be modified to an absolute branch
1240 to a symbol. The PowerOpen ABI does not define this
1241 relocation type. */
1242 case R_RBRC:
1243 /* The PowerPC ABI defines this as an absolute branch to a
1244 fixed address which may be modified to a relative branch.
1245 The PowerOpen ABI does not define this relocation type. */
1246 howto.src_mask &= ~3;
1247 howto.dst_mask = howto.src_mask;
1248 break;
1249 case R_BR:
1250 /* Relative branch. We don't want to mess with the lower
1251 two bits of the instruction. */
1252 case R_CREL:
1253 /* The PowerPC ABI defines this as a relative call which may
1254 be modified to become an absolute call. The PowerOpen
1255 ABI does not define this relocation type. */
1256 case R_RBR:
1257 /* A relative branch which may be modified to become an
1258 absolute branch. FIXME: We don't implement this,
1259 although we should for symbols of storage mapping class
1260 XMC_XO. */
1261 howto.pc_relative = true;
1262 howto.src_mask &= ~3;
1263 howto.dst_mask = howto.src_mask;
1264 howto.size = 2;
1265 howto.complain_on_overflow = complain_overflow_bitfield;
1266 break;
1267 case R_RL:
1268 /* The PowerPC AIX ABI describes this as a load which may be
1269 changed to a load address. The PowerOpen ABI says this
1270 is the same as case R_POS. */
1271 break;
1272 case R_RLA:
1273 /* The PowerPC AIX ABI describes this as a load address
1274 which may be changed to a load. The PowerOpen ABI says
1275 this is the same as R_POS. */
1276 break;
1279 /* If we see an R_BR or R_RBR reloc which is jumping to global
1280 linkage code, and it is followed by an appropriate cror nop
1281 instruction, we replace the cror with ld r2,40(r1). This
1282 restores the TOC after the glink code. Contrariwise, if the
1283 call is followed by a ld r2,40(r1), but the call is not
1284 going to global linkage code, we can replace the load with a
1285 cror. */
1286 if ((rel->r_type == R_BR || rel->r_type == R_RBR)
1287 && h != NULL
1288 && h->root.type == bfd_link_hash_defined
1289 && (rel->r_vaddr - input_section->vma + 8
1290 <= input_section->_cooked_size))
1292 bfd_byte *pnext;
1293 unsigned long next;
1295 pnext = contents + (rel->r_vaddr - input_section->vma) + 4;
1296 next = bfd_get_32 (input_bfd, pnext);
1299 /* The _ptrgl function is magic. It is used by the AIX
1300 * compiler to call a function through a pointer.
1302 * special case XMC_GL, global linkage
1304 if (h->smclas == XMC_GL
1305 || strcmp (h->root.root.string, "._ptrgl") == 0)
1307 if (next == 0x4def7b82 /* cror 15,15,15 */
1308 || next == 0x4ffffb82 /* cror 31,31,31 */
1309 || next == 0x60000000 /* ori r0,r0,0 */)
1310 bfd_put_32 (input_bfd, (bfd_vma) 0xe8410028 /* ld r2,40(r1) */,
1311 pnext);
1313 else
1315 if (next == 0xe8410028 /* ld r2,40(r1) */)
1316 bfd_put_32 (input_bfd, (bfd_vma) 0x60000000 /* ori r0,r0,0 */,
1317 pnext);
1321 /* A PC relative reloc includes the section address. */
1322 if (howto.pc_relative)
1323 addend += input_section->vma;
1325 rstat = _bfd_final_link_relocate (&howto, input_bfd, input_section,
1326 contents,
1327 rel->r_vaddr - input_section->vma,
1328 val, addend);
1330 switch (rstat)
1332 default:
1333 abort ();
1334 case bfd_reloc_ok:
1335 break;
1336 case bfd_reloc_overflow:
1338 const char *name;
1339 char buf[SYMNMLEN + 1];
1340 char howto_name[10];
1342 if (symndx == -1)
1343 name = "*ABS*";
1344 else if (h != NULL)
1345 name = h->root.root.string;
1346 else
1348 name = _bfd_coff_internal_syment_name (input_bfd, sym, buf);
1349 if (name == NULL)
1350 return false;
1352 sprintf (howto_name, "0x%02x", rel->r_type);
1354 if (! ((*info->callbacks->reloc_overflow)
1355 (info, name, howto_name, (bfd_vma) 0, input_bfd,
1356 input_section, rel->r_vaddr - input_section->vma)))
1357 return false;
1362 return true;
1367 /* The XCOFF reloc table. Actually, XCOFF relocations specify the
1368 bitsize and whether they are signed or not, along with a
1369 conventional type. This table is for the types, which are used for
1370 different algorithms for putting in the reloc. Many of these
1371 relocs need special_function entries, which I have not written. */
1374 reloc_howto_type xcoff64_howto_table[] =
1376 /* Standard 64 bit relocation. */
1377 HOWTO (0, /* type */
1378 0, /* rightshift */
1379 4, /* size (0 = byte, 1 = short, 2 = long) */
1380 64, /* bitsize */
1381 false, /* pc_relative */
1382 0, /* bitpos */
1383 complain_overflow_bitfield, /* complain_on_overflow */
1384 0, /* special_function */
1385 "R_POS", /* name */
1386 true, /* partial_inplace */
1387 MINUS_ONE, /* src_mask */
1388 MINUS_ONE, /* dst_mask */
1389 false), /* pcrel_offset */
1391 /* 64 bit relocation, but store negative value. */
1392 HOWTO (1, /* type */
1393 0, /* rightshift */
1394 -4, /* size (0 = byte, 1 = short, 2 = long) */
1395 64, /* bitsize */
1396 false, /* pc_relative */
1397 0, /* bitpos */
1398 complain_overflow_bitfield, /* complain_on_overflow */
1399 0, /* special_function */
1400 "R_NEG", /* name */
1401 true, /* partial_inplace */
1402 MINUS_ONE, /* src_mask */
1403 MINUS_ONE, /* dst_mask */
1404 false), /* pcrel_offset */
1406 /* 32 bit PC relative relocation. */
1407 HOWTO (2, /* type */
1408 0, /* rightshift */
1409 2, /* size (0 = byte, 1 = short, 2 = long) */
1410 32, /* bitsize */
1411 true, /* pc_relative */
1412 0, /* bitpos */
1413 complain_overflow_signed, /* complain_on_overflow */
1414 0, /* special_function */
1415 "R_REL", /* name */
1416 true, /* partial_inplace */
1417 0xffffffff, /* src_mask */
1418 0xffffffff, /* dst_mask */
1419 false), /* pcrel_offset */
1421 /* 16 bit TOC relative relocation. */
1422 HOWTO (3, /* type */
1423 0, /* rightshift */
1424 1, /* size (0 = byte, 1 = short, 2 = long) */
1425 16, /* bitsize */
1426 false, /* pc_relative */
1427 0, /* bitpos */
1428 complain_overflow_bitfield, /* complain_on_overflow */
1429 0, /* special_function */
1430 "R_TOC", /* name */
1431 true, /* partial_inplace */
1432 0xffff, /* src_mask */
1433 0xffff, /* dst_mask */
1434 false), /* pcrel_offset */
1436 /* I don't really know what this is. */
1437 HOWTO (4, /* type */
1438 1, /* rightshift */
1439 2, /* size (0 = byte, 1 = short, 2 = long) */
1440 32, /* bitsize */
1441 false, /* pc_relative */
1442 0, /* bitpos */
1443 complain_overflow_bitfield, /* complain_on_overflow */
1444 0, /* special_function */
1445 "R_RTB", /* name */
1446 true, /* partial_inplace */
1447 0xffffffff, /* src_mask */
1448 0xffffffff, /* dst_mask */
1449 false), /* pcrel_offset */
1451 /* External TOC relative symbol. */
1452 HOWTO (5, /* type */
1453 0, /* rightshift */
1454 2, /* size (0 = byte, 1 = short, 2 = long) */
1455 16, /* bitsize */
1456 false, /* pc_relative */
1457 0, /* bitpos */
1458 complain_overflow_bitfield, /* complain_on_overflow */
1459 0, /* special_function */
1460 "R_GL", /* name */
1461 true, /* partial_inplace */
1462 0xffff, /* src_mask */
1463 0xffff, /* dst_mask */
1464 false), /* pcrel_offset */
1466 /* Local TOC relative symbol. */
1467 HOWTO (6, /* type */
1468 0, /* rightshift */
1469 2, /* size (0 = byte, 1 = short, 2 = long) */
1470 16, /* bitsize */
1471 false, /* pc_relative */
1472 0, /* bitpos */
1473 complain_overflow_bitfield, /* complain_on_overflow */
1474 0, /* special_function */
1475 "R_TCL", /* name */
1476 true, /* partial_inplace */
1477 0xffff, /* src_mask */
1478 0xffff, /* dst_mask */
1479 false), /* pcrel_offset */
1481 EMPTY_HOWTO (7),
1483 /* Non modifiable absolute branch. */
1484 HOWTO (8, /* type */
1485 0, /* rightshift */
1486 2, /* size (0 = byte, 1 = short, 2 = long) */
1487 26, /* bitsize */
1488 false, /* pc_relative */
1489 0, /* bitpos */
1490 complain_overflow_bitfield, /* complain_on_overflow */
1491 0, /* special_function */
1492 "R_BA", /* name */
1493 true, /* partial_inplace */
1494 0x3fffffc, /* src_mask */
1495 0x3fffffc, /* dst_mask */
1496 false), /* pcrel_offset */
1498 EMPTY_HOWTO (9),
1500 /* Non modifiable relative branch. */
1501 HOWTO (0xa, /* type */
1502 0, /* rightshift */
1503 2, /* size (0 = byte, 1 = short, 2 = long) */
1504 26, /* bitsize */
1505 true, /* pc_relative */
1506 0, /* bitpos */
1507 complain_overflow_signed, /* complain_on_overflow */
1508 0, /* special_function */
1509 "R_BR", /* name */
1510 true, /* partial_inplace */
1511 0x3fffffc, /* src_mask */
1512 0x3fffffc, /* dst_mask */
1513 false), /* pcrel_offset */
1515 EMPTY_HOWTO (0xb),
1517 /* Indirect load. */
1518 HOWTO (0xc, /* type */
1519 0, /* rightshift */
1520 2, /* size (0 = byte, 1 = short, 2 = long) */
1521 16, /* bitsize */
1522 false, /* pc_relative */
1523 0, /* bitpos */
1524 complain_overflow_bitfield, /* complain_on_overflow */
1525 0, /* special_function */
1526 "R_RL", /* name */
1527 true, /* partial_inplace */
1528 0xffff, /* src_mask */
1529 0xffff, /* dst_mask */
1530 false), /* pcrel_offset */
1532 /* Load address. */
1533 HOWTO (0xd, /* type */
1534 0, /* rightshift */
1535 2, /* size (0 = byte, 1 = short, 2 = long) */
1536 16, /* bitsize */
1537 false, /* pc_relative */
1538 0, /* bitpos */
1539 complain_overflow_bitfield, /* complain_on_overflow */
1540 0, /* special_function */
1541 "R_RLA", /* name */
1542 true, /* partial_inplace */
1543 0xffff, /* src_mask */
1544 0xffff, /* dst_mask */
1545 false), /* pcrel_offset */
1547 EMPTY_HOWTO (0xe),
1549 /* Non-relocating reference. */
1550 HOWTO (0xf, /* type */
1551 0, /* rightshift */
1552 2, /* size (0 = byte, 1 = short, 2 = long) */
1553 32, /* bitsize */
1554 false, /* pc_relative */
1555 0, /* bitpos */
1556 complain_overflow_bitfield, /* complain_on_overflow */
1557 0, /* special_function */
1558 "R_REF", /* name */
1559 false, /* partial_inplace */
1560 0, /* src_mask */
1561 0, /* dst_mask */
1562 false), /* pcrel_offset */
1564 EMPTY_HOWTO (0x10),
1565 EMPTY_HOWTO (0x11),
1567 /* TOC relative indirect load. */
1568 HOWTO (0x12, /* type */
1569 0, /* rightshift */
1570 2, /* size (0 = byte, 1 = short, 2 = long) */
1571 16, /* bitsize */
1572 false, /* pc_relative */
1573 0, /* bitpos */
1574 complain_overflow_bitfield, /* complain_on_overflow */
1575 0, /* special_function */
1576 "R_TRL", /* name */
1577 true, /* partial_inplace */
1578 0xffff, /* src_mask */
1579 0xffff, /* dst_mask */
1580 false), /* pcrel_offset */
1582 /* TOC relative load address. */
1583 HOWTO (0x13, /* type */
1584 0, /* rightshift */
1585 2, /* size (0 = byte, 1 = short, 2 = long) */
1586 16, /* bitsize */
1587 false, /* pc_relative */
1588 0, /* bitpos */
1589 complain_overflow_bitfield, /* complain_on_overflow */
1590 0, /* special_function */
1591 "R_TRLA", /* name */
1592 true, /* partial_inplace */
1593 0xffff, /* src_mask */
1594 0xffff, /* dst_mask */
1595 false), /* pcrel_offset */
1597 /* Modifiable relative branch. */
1598 HOWTO (0x14, /* type */
1599 1, /* rightshift */
1600 2, /* size (0 = byte, 1 = short, 2 = long) */
1601 32, /* bitsize */
1602 false, /* pc_relative */
1603 0, /* bitpos */
1604 complain_overflow_bitfield, /* complain_on_overflow */
1605 0, /* special_function */
1606 "R_RRTBI", /* name */
1607 true, /* partial_inplace */
1608 0xffffffff, /* src_mask */
1609 0xffffffff, /* dst_mask */
1610 false), /* pcrel_offset */
1612 /* Modifiable absolute branch. */
1613 HOWTO (0x15, /* type */
1614 1, /* rightshift */
1615 2, /* size (0 = byte, 1 = short, 2 = long) */
1616 32, /* bitsize */
1617 false, /* pc_relative */
1618 0, /* bitpos */
1619 complain_overflow_bitfield, /* complain_on_overflow */
1620 0, /* special_function */
1621 "R_RRTBA", /* name */
1622 true, /* partial_inplace */
1623 0xffffffff, /* src_mask */
1624 0xffffffff, /* dst_mask */
1625 false), /* pcrel_offset */
1627 /* Modifiable call absolute indirect. */
1628 HOWTO (0x16, /* type */
1629 0, /* rightshift */
1630 2, /* size (0 = byte, 1 = short, 2 = long) */
1631 16, /* bitsize */
1632 false, /* pc_relative */
1633 0, /* bitpos */
1634 complain_overflow_bitfield, /* complain_on_overflow */
1635 0, /* special_function */
1636 "R_CAI", /* name */
1637 true, /* partial_inplace */
1638 0xffff, /* src_mask */
1639 0xffff, /* dst_mask */
1640 false), /* pcrel_offset */
1642 /* Modifiable call relative. */
1643 HOWTO (0x17, /* type */
1644 0, /* rightshift */
1645 2, /* size (0 = byte, 1 = short, 2 = long) */
1646 16, /* bitsize */
1647 false, /* pc_relative */
1648 0, /* bitpos */
1649 complain_overflow_bitfield, /* complain_on_overflow */
1650 0, /* special_function */
1651 "R_CREL", /* name */
1652 true, /* partial_inplace */
1653 0xffff, /* src_mask */
1654 0xffff, /* dst_mask */
1655 false), /* pcrel_offset */
1657 /* Modifiable branch absolute. */
1658 HOWTO (0x18, /* type */
1659 0, /* rightshift */
1660 2, /* size (0 = byte, 1 = short, 2 = long) */
1661 26, /* bitsize */
1662 false, /* pc_relative */
1663 0, /* bitpos */
1664 complain_overflow_bitfield, /* complain_on_overflow */
1665 0, /* special_function */
1666 "R_RBA", /* name */
1667 true, /* partial_inplace */
1668 0xffff, /* src_mask */
1669 0xffff, /* dst_mask */
1670 false), /* pcrel_offset */
1672 /* Modifiable branch absolute. */
1673 HOWTO (0x19, /* type */
1674 0, /* rightshift */
1675 2, /* size (0 = byte, 1 = short, 2 = long) */
1676 32, /* bitsize */
1677 false, /* pc_relative */
1678 0, /* bitpos */
1679 complain_overflow_bitfield, /* complain_on_overflow */
1680 0, /* special_function */
1681 "R_RBAC", /* name */
1682 true, /* partial_inplace */
1683 0xffff, /* src_mask */
1684 0xffff, /* dst_mask */
1685 false), /* pcrel_offset */
1687 /* Modifiable branch relative. */
1688 HOWTO (0x1a, /* type */
1689 0, /* rightshift */
1690 2, /* size (0 = byte, 1 = short, 2 = long) */
1691 26, /* bitsize */
1692 false, /* pc_relative */
1693 0, /* bitpos */
1694 complain_overflow_signed, /* complain_on_overflow */
1695 0, /* special_function */
1696 "R_RBR", /* name */
1697 true, /* partial_inplace */
1698 0xffff, /* src_mask */
1699 0xffff, /* dst_mask */
1700 false), /* pcrel_offset */
1702 /* Modifiable branch absolute. */
1703 HOWTO (0x1b, /* type */
1704 0, /* rightshift */
1705 2, /* size (0 = byte, 1 = short, 2 = long) */
1706 16, /* bitsize */
1707 false, /* pc_relative */
1708 0, /* bitpos */
1709 complain_overflow_bitfield, /* complain_on_overflow */
1710 0, /* special_function */
1711 "R_RBRC", /* name */
1712 true, /* partial_inplace */
1713 0xffff, /* src_mask */
1714 0xffff, /* dst_mask */
1715 false), /* pcrel_offset */
1717 HOWTO (0, /* type */
1718 0, /* rightshift */
1719 4, /* size (0 = byte, 1 = short, 2 = long) */
1720 64, /* bitsize */
1721 false, /* pc_relative */
1722 0, /* bitpos */
1723 complain_overflow_bitfield, /* complain_on_overflow */
1724 0, /* special_function */
1725 "R_POS", /* name */
1726 true, /* partial_inplace */
1727 MINUS_ONE, /* src_mask */
1728 MINUS_ONE, /* dst_mask */
1729 false) /* pcrel_offset */
1732 void
1733 xcoff64_rtype2howto (relent, internal)
1734 arelent *relent;
1735 struct internal_reloc *internal;
1737 relent->howto = xcoff64_howto_table + internal->r_type;
1739 /* Check for relocs we don't know of. */
1740 if (internal->r_type
1741 >= sizeof (xcoff64_howto_table) / sizeof (xcoff64_howto_table[0]))
1742 abort ();
1743 if (internal->r_type != relent->howto->type)
1744 abort ();
1746 /* The r_size field of an XCOFF reloc encodes the bitsize of the
1747 relocation, as well as indicating whether it is signed or not.
1748 Doublecheck that the relocation information gathered from the
1749 type matches this information. The bitsize is not significant
1750 for R_REF relocs. */
1751 if (relent->howto->dst_mask != 0
1752 && (relent->howto->bitsize
1753 != ((unsigned int) internal->r_size & 0x3f) + 1))
1754 abort ();
1755 #if 0
1756 if ((internal->r_size & 0x80) != 0
1757 ? (relent->howto->complain_on_overflow != complain_overflow_signed)
1758 : (relent->howto->complain_on_overflow != complain_overflow_bitfield))
1759 abort ();
1760 #endif
1763 reloc_howto_type *
1764 xcoff64_reloc_type_lookup (abfd, code)
1765 bfd *abfd ATTRIBUTE_UNUSED;
1766 bfd_reloc_code_real_type code;
1768 switch (code)
1770 case BFD_RELOC_PPC_B26:
1771 return &xcoff64_howto_table[0xa];
1772 case BFD_RELOC_PPC_BA26:
1773 return &xcoff64_howto_table[8];
1774 case BFD_RELOC_PPC_TOC16:
1775 return &xcoff64_howto_table[3];
1776 case BFD_RELOC_32:
1777 case BFD_RELOC_CTOR:
1778 return &xcoff64_howto_table[0];
1779 case BFD_RELOC_64:
1780 return &xcoff64_howto_table[0x1c];
1781 default:
1782 return NULL;
1788 /* Read in the armap of an XCOFF archive. */
1790 static boolean
1791 xcoff64_slurp_armap (abfd)
1792 bfd *abfd;
1794 file_ptr off;
1795 size_t namlen;
1796 bfd_size_type sz, amt;
1797 bfd_byte *contents, *cend;
1798 bfd_vma c, i;
1799 carsym *arsym;
1800 bfd_byte *p;
1801 file_ptr pos;
1803 /* This is for the new format. */
1804 struct xcoff_ar_hdr_big hdr;
1806 if (xcoff_ardata (abfd) == NULL)
1808 bfd_has_map (abfd) = false;
1809 return true;
1812 off = strtol (xcoff_ardata_big (abfd)->symoff64, (char **) NULL, 10);
1813 if (off == 0)
1815 bfd_has_map (abfd) = false;
1816 return true;
1819 if (bfd_seek (abfd, off, SEEK_SET) != 0)
1820 return false;
1822 /* The symbol table starts with a normal archive header. */
1823 if (bfd_bread ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR_BIG, abfd)
1824 != SIZEOF_AR_HDR_BIG)
1825 return false;
1827 /* Skip the name (normally empty). */
1828 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1829 pos = ((namlen + 1) & ~(size_t) 1) + SXCOFFARFMAG;
1830 if (bfd_seek (abfd, pos, SEEK_CUR) != 0)
1831 return false;
1833 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1834 machines) since the field width is 20 and there numbers with more
1835 than 32 bits can be represented. */
1836 sz = strtol (hdr.size, (char **) NULL, 10);
1838 /* Read in the entire symbol table. */
1839 contents = (bfd_byte *) bfd_alloc (abfd, sz);
1840 if (contents == NULL)
1841 return false;
1842 if (bfd_bread ((PTR) contents, sz, abfd) != sz)
1843 return false;
1845 /* The symbol table starts with an eight byte count. */
1846 c = H_GET_64 (abfd, contents);
1848 if (c * 8 >= sz)
1850 bfd_set_error (bfd_error_bad_value);
1851 return false;
1853 amt = c;
1854 amt *= sizeof (carsym);
1855 bfd_ardata (abfd)->symdefs = (carsym *) bfd_alloc (abfd, amt);
1856 if (bfd_ardata (abfd)->symdefs == NULL)
1857 return false;
1859 /* After the count comes a list of eight byte file offsets. */
1860 for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 8;
1861 i < c;
1862 ++i, ++arsym, p += 8)
1863 arsym->file_offset = H_GET_64 (abfd, p);
1865 /* After the file offsets come null terminated symbol names. */
1866 cend = contents + sz;
1867 for (i = 0, arsym = bfd_ardata (abfd)->symdefs;
1868 i < c;
1869 ++i, ++arsym, p += strlen ((char *) p) + 1)
1871 if (p >= cend)
1873 bfd_set_error (bfd_error_bad_value);
1874 return false;
1876 arsym->name = (char *) p;
1879 bfd_ardata (abfd)->symdef_count = c;
1880 bfd_has_map (abfd) = true;
1882 return true;
1886 /* See if this is an NEW XCOFF archive. */
1888 static const bfd_target *
1889 xcoff64_archive_p (abfd)
1890 bfd *abfd;
1892 char magic[SXCOFFARMAG];
1893 /* This is the new format. */
1894 struct xcoff_ar_file_hdr_big hdr;
1895 bfd_size_type amt = SXCOFFARMAG;
1897 if (bfd_bread ((PTR) magic, amt, abfd) != amt)
1899 if (bfd_get_error () != bfd_error_system_call)
1900 bfd_set_error (bfd_error_wrong_format);
1901 return NULL;
1904 if (strncmp (magic, XCOFFARMAGBIG, SXCOFFARMAG) != 0)
1906 bfd_set_error (bfd_error_wrong_format);
1907 return NULL;
1910 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
1911 involves a cast, we can't do it as the left operand of
1912 assignment. */
1913 amt = sizeof (struct artdata);
1914 abfd->tdata.aout_ar_data = (struct artdata *) bfd_zalloc (abfd, amt);
1916 if (bfd_ardata (abfd) == (struct artdata *) NULL)
1917 return NULL;
1919 bfd_ardata (abfd)->cache = NULL;
1920 bfd_ardata (abfd)->archive_head = NULL;
1921 bfd_ardata (abfd)->symdefs = NULL;
1922 bfd_ardata (abfd)->extended_names = NULL;
1924 /* Copy over the magic string. */
1925 memcpy (hdr.magic, magic, SXCOFFARMAG);
1927 /* Now read the rest of the file header. */
1928 if (bfd_bread ((PTR) &hdr.memoff,
1929 (bfd_size_type) (SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG),
1930 abfd) != SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG)
1932 if (bfd_get_error () != bfd_error_system_call)
1933 bfd_set_error (bfd_error_wrong_format);
1934 return NULL;
1937 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1938 machines) since the field width is 20 and there numbers with more
1939 than 32 bits can be represented. */
1940 bfd_ardata (abfd)->first_file_filepos = strtol (hdr.firstmemoff,
1941 (char **) NULL, 10);
1943 amt = SIZEOF_AR_FILE_HDR_BIG;
1944 bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, amt);
1945 if (bfd_ardata (abfd)->tdata == NULL)
1946 return NULL;
1948 memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR_BIG);
1950 if (! xcoff64_slurp_armap (abfd))
1952 bfd_release (abfd, bfd_ardata (abfd));
1953 abfd->tdata.aout_ar_data = (struct artdata *) NULL;
1954 return NULL;
1957 return abfd->xvec;
1961 /* Open the next element in an XCOFF archive. */
1963 static bfd *
1964 xcoff64_openr_next_archived_file (archive, last_file)
1965 bfd *archive;
1966 bfd *last_file;
1968 file_ptr filestart;
1970 if ((xcoff_ardata (archive) == NULL)
1971 || ! xcoff_big_format_p (archive))
1973 bfd_set_error (bfd_error_invalid_operation);
1974 return NULL;
1977 if (last_file == NULL)
1979 filestart = bfd_ardata (archive)->first_file_filepos;
1981 else
1983 /* XXX These actually have to be a calls to strtoll (at least
1984 on 32-bit machines) since the fields's width is 20 and
1985 there numbers with more than 32 bits can be represented. */
1986 filestart = strtol (arch_xhdr_big (last_file)->nextoff, (char **) NULL,
1987 10);
1989 /* XXX These actually have to be calls to strtoll (at least on 32-bit
1990 machines) since the fields's width is 20 and there numbers with more
1991 than 32 bits can be represented. */
1992 if (filestart == 0
1993 || filestart == strtol (xcoff_ardata_big (archive)->memoff,
1994 (char **) NULL, 10)
1995 || filestart == strtol (xcoff_ardata_big (archive)->symoff,
1996 (char **) NULL, 10))
1998 bfd_set_error (bfd_error_no_more_archived_files);
1999 return NULL;
2002 return _bfd_get_elt_at_filepos (archive, filestart);
2005 /* We can't use the usual coff_sizeof_headers routine, because AIX
2006 always uses an a.out header. */
2008 /*ARGSUSED*/
2009 static int
2010 xcoff64_sizeof_headers (abfd, reloc)
2011 bfd *abfd;
2012 boolean reloc ATTRIBUTE_UNUSED;
2014 int size;
2016 size = bfd_coff_filhsz (abfd);
2018 /* Don't think the small aout header can be used since some of the
2019 old elements have been reordered past the end of the old coff
2020 small aout size. */
2022 if (xcoff_data (abfd)->full_aouthdr)
2023 size += bfd_coff_aoutsz (abfd);
2025 size += abfd->section_count * bfd_coff_scnhsz (abfd);
2026 return size;
2031 static asection *
2032 xcoff64_create_csect_from_smclas (abfd, aux, symbol_name)
2033 bfd *abfd;
2034 union internal_auxent *aux;
2035 const char *symbol_name;
2037 asection *return_value = NULL;
2039 /* Changes from 32 :
2040 .sv == 8, is only for 32 bit programs
2041 .ti == 12 and .tb == 13 are now reserved. */
2042 static const char *names[19] =
2044 ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo",
2045 NULL, ".bs", ".ds", ".uc", NULL, NULL, NULL, ".tc0",
2046 ".td", ".sv64", ".sv3264"
2049 if ((19 >= aux->x_csect.x_smclas)
2050 && (NULL != names[aux->x_csect.x_smclas]))
2053 return_value = bfd_make_section_anyway
2054 (abfd, names[aux->x_csect.x_smclas]);
2057 else
2059 (*_bfd_error_handler)
2060 (_("%s: symbol `%s' has unrecognized smclas %d"),
2061 bfd_archive_filename (abfd), symbol_name, aux->x_csect.x_smclas);
2062 bfd_set_error (bfd_error_bad_value);
2065 return return_value;
2068 static boolean
2069 xcoff64_is_lineno_count_overflow (abfd, value)
2070 bfd *abfd ATTRIBUTE_UNUSED;
2071 bfd_vma value ATTRIBUTE_UNUSED;
2073 return false;
2076 static boolean
2077 xcoff64_is_reloc_count_overflow (abfd, value)
2078 bfd *abfd ATTRIBUTE_UNUSED;
2079 bfd_vma value ATTRIBUTE_UNUSED;
2081 return false;
2084 static bfd_vma
2085 xcoff64_loader_symbol_offset (abfd, ldhdr)
2086 bfd *abfd ATTRIBUTE_UNUSED;
2087 struct internal_ldhdr *ldhdr;
2089 return (ldhdr->l_symoff);
2092 static bfd_vma
2093 xcoff64_loader_reloc_offset (abfd, ldhdr)
2094 bfd *abfd ATTRIBUTE_UNUSED;
2095 struct internal_ldhdr *ldhdr;
2097 return (ldhdr->l_rldoff);
2100 static boolean
2101 xcoff64_generate_rtinit (abfd, init, fini)
2102 bfd *abfd;
2103 const char *init;
2104 const char *fini;
2106 bfd_byte filehdr_ext[FILHSZ];
2107 bfd_byte scnhdr_ext[SCNHSZ];
2108 bfd_byte syment_ext[SYMESZ * 8];
2109 bfd_byte reloc_ext[RELSZ * 2];
2110 bfd_byte *data_buffer;
2111 bfd_size_type data_buffer_size;
2112 bfd_byte *string_table, *st_tmp;
2113 bfd_size_type string_table_size;
2114 bfd_vma val;
2115 size_t initsz, finisz;
2116 struct internal_filehdr filehdr;
2117 struct internal_scnhdr scnhdr;
2118 struct internal_syment syment;
2119 union internal_auxent auxent;
2120 struct internal_reloc reloc;
2122 char *data_name = ".data";
2123 char *rtinit_name = "__rtinit";
2125 if (! bfd_xcoff_rtinit_size (abfd)
2126 || (init == NULL && fini == NULL))
2127 return false;
2129 initsz = (init == NULL ? 0 : 1 + strlen (init));
2130 finisz = (fini == NULL ? 0 : 1 + strlen (fini));
2132 /* file header */
2133 memset (filehdr_ext, 0, FILHSZ);
2134 memset (&filehdr, 0, sizeof (struct internal_filehdr));
2135 filehdr.f_magic = bfd_xcoff_magic_number (abfd);
2136 filehdr.f_nscns = 1;
2137 filehdr.f_timdat = 0;
2138 filehdr.f_nsyms = 0; /* at least 6, no more than 8 */
2139 filehdr.f_symptr = 0; /* set below */
2140 filehdr.f_opthdr = 0;
2141 filehdr.f_flags = 0;
2143 /* section header */
2144 memset (scnhdr_ext, 0, SCNHSZ);
2145 memset (&scnhdr, 0, sizeof (struct internal_scnhdr));
2146 memcpy (scnhdr.s_name, data_name, strlen (data_name));
2147 scnhdr.s_paddr = 0;
2148 scnhdr.s_vaddr = 0;
2149 scnhdr.s_size = 0; /* set below */
2150 scnhdr.s_scnptr = FILHSZ + SCNHSZ;
2151 scnhdr.s_relptr = 0; /* set below */
2152 scnhdr.s_lnnoptr = 0;
2153 scnhdr.s_nreloc = 0; /* either 1 or 2 */
2154 scnhdr.s_nlnno = 0;
2155 scnhdr.s_flags = STYP_DATA;
2157 /* .data
2158 0x0000 0x00000000 : rtl
2159 0x0004 0x00000000 :
2160 0x0008 0x00000018 : offset to init, or 0
2161 0x000C 0x00000038 : offset to fini, or 0
2162 0x0010 0x00000010 : size of descriptor
2163 0x0014 0x00000000 : pad
2164 0x0018 0x00000000 : init, needs a reloc
2165 0x001C 0x00000000 :
2166 0x0020 0x00000058 : offset to init name
2167 0x0024 0x00000000 : flags, padded to a word
2168 0x0028 0x00000000 : empty init
2169 0x002C 0x00000000 :
2170 0x0030 0x00000000 :
2171 0x0034 0x00000000 :
2172 0x0038 0x00000000 : fini, needs a reloc
2173 0x003C 0x00000000 :
2174 0x0040 0x00000??? : offset to fini name
2175 0x0044 0x00000000 : flags, padded to a word
2176 0x0048 0x00000000 : empty fini
2177 0x004C 0x00000000 :
2178 0x0050 0x00000000 :
2179 0x0054 0x00000000 :
2180 0x0058 init name
2181 0x0058 + initsz fini name */
2183 data_buffer_size = 0x0058 + initsz + finisz;
2184 data_buffer_size += (data_buffer_size & 7) ? 8 - (data_buffer_size & 7) : 0;
2185 data_buffer = NULL;
2186 data_buffer = (bfd_byte *)bfd_malloc (data_buffer_size);
2187 if (data_buffer == NULL)
2188 return false;
2190 memset (data_buffer, 0, data_buffer_size);
2192 if (initsz)
2194 val = 0x18;
2195 bfd_put_32 (abfd, val, &data_buffer[0x08]);
2196 val = 0x58;
2197 bfd_put_32 (abfd, val, &data_buffer[0x20]);
2198 memcpy (&data_buffer[val], init, initsz);
2201 if (finisz)
2203 val = 0x38;
2204 bfd_put_32 (abfd, val, &data_buffer[0x0C]);
2205 val = 0x58 + initsz;
2206 bfd_put_32 (abfd, val, &data_buffer[0x40]);
2207 memcpy (&data_buffer[val], fini, finisz);
2210 val = 0x10;
2211 bfd_put_32 (abfd, val, &data_buffer[0x10]);
2212 scnhdr.s_size = data_buffer_size;
2214 /* string table */
2215 string_table_size = 4;
2216 string_table_size += strlen (data_name) + 1;
2217 string_table_size += strlen (rtinit_name) + 1;
2218 string_table_size += initsz;
2219 string_table_size += finisz;
2221 string_table = (bfd_byte *)bfd_malloc (string_table_size);
2222 memset (string_table, 0, string_table_size);
2223 val = string_table_size;
2224 bfd_put_32 (abfd, val, &string_table[0]);
2225 st_tmp = string_table + 4;
2227 /* symbols
2228 0. .data csect
2229 2. __rtinit
2230 4. init function
2231 6. fini function */
2232 memset (syment_ext, 0, 8 * SYMESZ);
2233 memset (reloc_ext, 0, 2 * RELSZ);
2235 /* .data csect */
2236 memset (&syment, 0, sizeof (struct internal_syment));
2237 memset (&auxent, 0, sizeof (union internal_auxent));
2239 syment._n._n_n._n_offset = st_tmp - string_table;
2240 memcpy (st_tmp, data_name, strlen (data_name));
2241 st_tmp += strlen (data_name) + 1;
2243 syment.n_scnum = 1;
2244 syment.n_sclass = C_HIDEXT;
2245 syment.n_numaux = 1;
2246 auxent.x_csect.x_scnlen.l = data_buffer_size;
2247 auxent.x_csect.x_smtyp = 3 << 3 | XTY_SD;
2248 auxent.x_csect.x_smclas = XMC_RW;
2249 bfd_coff_swap_sym_out (abfd, &syment,
2250 &syment_ext[filehdr.f_nsyms * SYMESZ]);
2251 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
2252 syment.n_numaux,
2253 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
2254 filehdr.f_nsyms += 2;
2256 /* __rtinit */
2257 memset (&syment, 0, sizeof (struct internal_syment));
2258 memset (&auxent, 0, sizeof (union internal_auxent));
2259 syment._n._n_n._n_offset = st_tmp - string_table;
2260 memcpy (st_tmp, rtinit_name, strlen (rtinit_name));
2261 st_tmp += strlen (rtinit_name) + 1;
2263 syment.n_scnum = 1;
2264 syment.n_sclass = C_EXT;
2265 syment.n_numaux = 1;
2266 auxent.x_csect.x_smtyp = XTY_LD;
2267 auxent.x_csect.x_smclas = XMC_RW;
2268 bfd_coff_swap_sym_out (abfd, &syment,
2269 &syment_ext[filehdr.f_nsyms * SYMESZ]);
2270 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
2271 syment.n_numaux,
2272 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
2273 filehdr.f_nsyms += 2;
2275 /* init */
2276 if (initsz)
2278 memset (&syment, 0, sizeof (struct internal_syment));
2279 memset (&auxent, 0, sizeof (union internal_auxent));
2281 syment._n._n_n._n_offset = st_tmp - string_table;
2282 memcpy (st_tmp, init, initsz);
2283 st_tmp += initsz;
2285 syment.n_sclass = C_EXT;
2286 syment.n_numaux = 1;
2287 bfd_coff_swap_sym_out (abfd, &syment,
2288 &syment_ext[filehdr.f_nsyms * SYMESZ]);
2289 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
2290 syment.n_numaux,
2291 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
2292 /* reloc */
2293 memset (&reloc, 0, sizeof (struct internal_reloc));
2294 reloc.r_vaddr = 0x0018;
2295 reloc.r_symndx = filehdr.f_nsyms;
2296 reloc.r_type = R_POS;
2297 reloc.r_size = 63;
2298 bfd_coff_swap_reloc_out (abfd, &reloc, &reloc_ext[0]);
2300 filehdr.f_nsyms += 2;
2301 scnhdr.s_nreloc += 1;
2304 /* finit */
2305 if (finisz)
2307 memset (&syment, 0, sizeof (struct internal_syment));
2308 memset (&auxent, 0, sizeof (union internal_auxent));
2310 syment._n._n_n._n_offset = st_tmp - string_table;
2311 memcpy (st_tmp, fini, finisz);
2312 st_tmp += finisz;
2314 syment.n_sclass = C_EXT;
2315 syment.n_numaux = 1;
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]);
2322 /* reloc */
2323 memset (&reloc, 0, sizeof (struct internal_reloc));
2324 reloc.r_vaddr = 0x0038;
2325 reloc.r_symndx = filehdr.f_nsyms;
2326 reloc.r_type = R_POS;
2327 reloc.r_size = 63;
2328 bfd_coff_swap_reloc_out (abfd, &reloc,
2329 &reloc_ext[scnhdr.s_nreloc * RELSZ]);
2331 filehdr.f_nsyms += 2;
2332 scnhdr.s_nreloc += 1;
2335 scnhdr.s_relptr = scnhdr.s_scnptr + data_buffer_size;
2336 filehdr.f_symptr = scnhdr.s_relptr + scnhdr.s_nreloc * RELSZ;
2338 bfd_coff_swap_filehdr_out (abfd, &filehdr, filehdr_ext);
2339 bfd_bwrite (filehdr_ext, FILHSZ, abfd);
2340 bfd_coff_swap_scnhdr_out (abfd, &scnhdr, scnhdr_ext);
2341 bfd_bwrite (scnhdr_ext, SCNHSZ, abfd);
2342 bfd_bwrite (data_buffer, data_buffer_size, abfd);
2343 bfd_bwrite (reloc_ext, scnhdr.s_nreloc * RELSZ, abfd);
2344 bfd_bwrite (syment_ext, filehdr.f_nsyms * SYMESZ, abfd);
2345 bfd_bwrite (string_table, string_table_size, abfd);
2347 free (data_buffer);
2348 data_buffer = NULL;
2350 return true;
2353 /* The typical dynamic reloc. */
2355 static reloc_howto_type xcoff64_dynamic_reloc =
2356 HOWTO (0, /* type */
2357 0, /* rightshift */
2358 4, /* size (0 = byte, 1 = short, 2 = long) */
2359 64, /* bitsize */
2360 false, /* pc_relative */
2361 0, /* bitpos */
2362 complain_overflow_bitfield, /* complain_on_overflow */
2363 0, /* special_function */
2364 "R_POS", /* name */
2365 true, /* partial_inplace */
2366 MINUS_ONE, /* src_mask */
2367 MINUS_ONE, /* dst_mask */
2368 false); /* pcrel_offset */
2370 static unsigned long xcoff64_glink_code[10] =
2372 0xe9820000, /* ld r12,0(r2) */
2373 0xf8410028, /* std r2,40(r1) */
2374 0xe80c0000, /* ld r0,0(r12) */
2375 0xe84c0008, /* ld r0,8(r12) */
2376 0x7c0903a6, /* mtctr r0 */
2377 0x4e800420, /* bctr */
2378 0x00000000, /* start of traceback table */
2379 0x000ca000, /* traceback table */
2380 0x00000000, /* traceback table */
2381 0x00000018, /* ??? */
2384 static const struct xcoff_backend_data_rec bfd_xcoff_backend_data =
2386 { /* COFF backend, defined in libcoff.h */
2387 _bfd_xcoff64_swap_aux_in, /* _bfd_coff_swap_aux_in */
2388 _bfd_xcoff64_swap_sym_in, /* _bfd_coff_swap_sym_in */
2389 _bfd_xcoff64_swap_lineno_in, /* _bfd_coff_swap_lineno_in */
2390 _bfd_xcoff64_swap_aux_out, /* _bfd_swap_aux_out */
2391 _bfd_xcoff64_swap_sym_out, /* _bfd_swap_sym_out */
2392 _bfd_xcoff64_swap_lineno_out, /* _bfd_swap_lineno_out */
2393 coff_swap_reloc_out, /* _bfd_swap_reloc_out */
2394 coff_swap_filehdr_out, /* _bfd_swap_filehdr_out */
2395 coff_swap_aouthdr_out, /* _bfd_swap_aouthdr_out */
2396 coff_swap_scnhdr_out, /* _bfd_swap_scnhdr_out */
2397 FILHSZ, /* _bfd_filhsz */
2398 AOUTSZ, /* _bfd_aoutsz */
2399 SCNHSZ, /* _bfd_scnhsz */
2400 SYMESZ, /* _bfd_symesz */
2401 AUXESZ, /* _bfd_auxesz */
2402 RELSZ, /* _bfd_relsz */
2403 LINESZ, /* _bfd_linesz */
2404 FILNMLEN, /* _bfd_filnmlen */
2405 true, /* _bfd_coff_long_filenames */
2406 false, /* _bfd_coff_long_section_names */
2407 (3), /* _bfd_coff_default_section_alignment_power */
2408 true, /* _bfd_coff_force_symnames_in_strings */
2409 4, /* _bfd_coff_debug_string_prefix_length */
2410 coff_swap_filehdr_in, /* _bfd_coff_swap_filehdr_in */
2411 coff_swap_aouthdr_in, /* _bfd_swap_aouthdr_in */
2412 coff_swap_scnhdr_in, /* _bfd_swap_scnhdr_in */
2413 coff_swap_reloc_in, /* _bfd_reloc_in */
2414 coff_bad_format_hook, /* _bfd_bad_format_hook */
2415 coff_set_arch_mach_hook, /* _bfd_set_arch_mach_hook */
2416 coff_mkobject_hook, /* _bfd_mkobject_hook */
2417 styp_to_sec_flags, /* _bfd_syp_to_sec_flags */
2418 coff_set_alignment_hook, /* _bfd_set_alignment_hook */
2419 coff_slurp_symbol_table, /* _bfd_coff_slurp_symbol_table */
2420 symname_in_debug_hook, /* _coff_symname_in_debug_hook */
2421 coff_pointerize_aux_hook, /* _bfd_coff_pointerize_aux_hook */
2422 coff_print_aux, /* bfd_coff_print_aux */
2423 dummy_reloc16_extra_cases, /* _bfd_coff_reloc16_extra_cases */
2424 dummy_reloc16_estimate, /* _bfd_coff_reloc16_estimate */
2425 NULL, /* bfd_coff_sym_is_global */
2426 /* _bfd_coff_compute_section_file_positions */
2427 coff_compute_section_file_positions,
2428 NULL , /* _bfd_coff_start_final_link */
2429 xcoff64_ppc_relocate_section, /* _bfd_coff_relocate_section */
2430 coff_rtype_to_howto, /* _bfd_coff_rtype_to_howto */
2431 NULL , /* _bfd_coff_addust_symndx */
2432 _bfd_generic_link_add_one_symbol, /* _bfd_coff_add_one_symbol */
2433 coff_link_output_has_begun, /* _bfd_coff_link_output_has_begun */
2434 coff_final_link_postscript /* _bfd_coff_final_link_postscript */
2437 0x01EF, /* magic number */
2438 bfd_arch_powerpc, /* architecture */
2439 bfd_mach_ppc_620, /* machine */
2441 /* function pointers to xcoff specific swap routines */
2442 xcoff64_swap_ldhdr_in, /* _xcoff_swap_ldhdr_in */
2443 xcoff64_swap_ldhdr_out, /* _xcoff_swap_ldhdr_out */
2444 xcoff64_swap_ldsym_in, /* _xcoff_swap_ldsym_in */
2445 xcoff64_swap_ldsym_out, /* _xcoff_swap_ldsym_out */
2446 xcoff64_swap_ldrel_in, /* _xcoff_swap_ldrel_in */
2447 xcoff64_swap_ldrel_out, /* _xcoff_swap_ldrel_out */
2449 /* sizes */
2450 LDHDRSZ, /* _xcoff_ldhdrsz */
2451 LDSYMSZ, /* _xcoff_ldsymsz */
2452 LDRELSZ, /* _xcoff_ldrelsz */
2453 24, /* _xcoff_function_descriptor_size */
2454 0, /* _xcoff_small_aout_header_size */
2455 /* versions */
2456 2, /* _xcoff_ldhdr_version */
2458 /* xcoff vs xcoff64 putting symbol names */
2459 _bfd_xcoff64_put_symbol_name, /* _xcoff_put_symbol_name */
2460 _bfd_xcoff64_put_ldsymbol_name, /* _xcoff_put_ldsymbol_name */
2462 /* dynamic reloc howto */
2463 &xcoff64_dynamic_reloc,
2465 xcoff64_create_csect_from_smclas,
2467 /* lineno and reloc count overflow */
2468 xcoff64_is_lineno_count_overflow,
2469 xcoff64_is_reloc_count_overflow,
2471 xcoff64_loader_symbol_offset,
2472 xcoff64_loader_reloc_offset,
2474 /* glink */
2475 &xcoff64_glink_code[0],
2476 40, /* _xcoff_glink_size */
2478 /* rtinit */
2479 88, /* _xcoff_rtinit_size */
2480 xcoff64_generate_rtinit, /* _xcoff_generate_rtinit */
2484 /* The transfer vector that leads the outside world to all of the above. */
2485 const bfd_target rs6000coff64_vec =
2487 "aixcoff64-rs6000",
2488 bfd_target_xcoff_flavour,
2489 BFD_ENDIAN_BIG, /* data byte order is big */
2490 BFD_ENDIAN_BIG, /* header byte order is big */
2492 (HAS_RELOC | EXEC_P | /* object flags */
2493 HAS_LINENO | HAS_DEBUG | DYNAMIC |
2494 HAS_SYMS | HAS_LOCALS | WP_TEXT),
2496 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
2497 0, /* leading char */
2498 '/', /* ar_pad_char */
2499 15, /* ar_max_namelen??? FIXMEmgo */
2501 /* data */
2502 bfd_getb64, /* bfd_getx64 */
2503 bfd_getb_signed_64, /* bfd_getx_signed_64 */
2504 bfd_putb64, /* bfd_putx64 */
2505 bfd_getb32, /* bfd_getx32 */
2506 bfd_getb_signed_32, /* bfd_getx_signed_32 */
2507 bfd_putb32, /* bfd_putx32 */
2508 bfd_getb16, /* bfd_getx16 */
2509 bfd_getb_signed_16, /* bfd_getx_signed_16 */
2510 bfd_putb16, /* bfd_putx16 */
2512 /* hdrs */
2513 bfd_getb64, /* bfd_h_getx64 */
2514 bfd_getb_signed_64, /* bfd_h_getx_signed_64 */
2515 bfd_putb64, /* bfd_h_putx64 */
2516 bfd_getb32, /* bfd_h_getx32 */
2517 bfd_getb_signed_32, /* bfd_h_getx_signed_32 */
2518 bfd_putb32, /* bfd_h_putx32 */
2519 bfd_getb16, /* bfd_h_getx16 */
2520 bfd_getb_signed_16, /* bfd_h_getx_signed_16 */
2521 bfd_putb16, /* bfd_h_putx16 */
2523 { /* bfd_check_format */
2524 _bfd_dummy_target,
2525 coff_object_p,
2526 xcoff64_archive_p,
2527 CORE_FILE_P
2530 { /* bfd_set_format */
2531 bfd_false,
2532 coff_mkobject,
2533 _bfd_generic_mkarchive,
2534 bfd_false
2537 {/* bfd_write_contents */
2538 bfd_false,
2539 xcoff64_write_object_contents,
2540 _bfd_xcoff_write_archive_contents,
2541 bfd_false
2544 /* Generic */
2545 bfd_true, /* _close_and_cleanup */
2546 bfd_true, /* _bfd_free_cached_info */
2547 coff_new_section_hook, /* _new_section_hook */
2548 _bfd_generic_get_section_contents, /* _bfd_get_section_contents */
2549 /* _bfd_get_section_contents_in_window */
2550 _bfd_generic_get_section_contents_in_window,
2552 /* Copy */
2553 _bfd_xcoff_copy_private_bfd_data, /* _bfd_copy_private_bfd */
2554 /* _bfd_merge_private_bfd_data */
2555 ((boolean (*) (bfd *, bfd *)) bfd_true),
2556 /* _bfd_copy_pivate_section_data */
2557 ((boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true),
2558 /* _bfd_copy_private_symbol_data */
2559 ((boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true),
2560 ((boolean (*) (bfd *, flagword)) bfd_true), /* _bfd_set_private_flags */
2561 ((boolean (*) (bfd *, void * )) bfd_true), /* _bfd_print_private_bfd_data */
2563 /* Core */
2564 coff_core_file_failing_command, /* _core_file_failing_command */
2565 coff_core_file_failing_signal, /* _core_file_failing_signal */
2566 /* _core_file_matches_executable_p */
2567 coff_core_file_matches_executable_p,
2569 /* Archive */
2570 xcoff64_slurp_armap, /* _slurp_armap */
2571 /* XCOFF archives do not have
2572 anything which corresponds to
2573 an extended name table. */
2574 bfd_false, /* _slurp_extended_name_table */
2575 /* _construct_extended_name_table */
2576 ((boolean (*) (bfd *, char **, bfd_size_type *, const char **)) bfd_false),
2577 bfd_dont_truncate_arname, /* _truncate_arname */
2578 _bfd_xcoff_write_armap, /* _write_armap */
2579 _bfd_xcoff_read_ar_hdr, /* _read_ar_hdr */
2580 xcoff64_openr_next_archived_file, /* _openr_next_archived_file */
2581 _bfd_generic_get_elt_at_index, /* _get_elt_at_index */
2582 _bfd_xcoff_generic_stat_arch_elt, /* _generic_dtat_arch_elt */
2583 /* XCOFF archives do not have
2584 a timestamp. */
2585 bfd_true, /* _update_armap_timestamp */
2587 /* Symbols */
2588 coff_get_symtab_upper_bound, /* _get_symtab_upper_bound */
2589 coff_get_symtab, /* _get_symtab */
2590 coff_make_empty_symbol, /* _make_empty_symbol */
2591 coff_print_symbol, /* _print_symbol */
2592 coff_get_symbol_info, /* _get_symbol_info */
2593 _bfd_xcoff_is_local_label_name, /* _bfd_is_local_label_name */
2594 coff_get_lineno, /* _get_lineno */
2595 coff_find_nearest_line, /* _find_nearest_line */
2596 coff_bfd_make_debug_symbol, /* _bfd_make_debug_symbol */
2597 _bfd_generic_read_minisymbols, /* _read_minisymbols */
2598 _bfd_generic_minisymbol_to_symbol, /* _minsymbol_to_symbol */
2600 /* Reloc */
2601 coff_get_reloc_upper_bound, /* _get_reloc_upper_bound */
2602 coff_canonicalize_reloc, /* _cononicalize_reloc */
2603 xcoff64_reloc_type_lookup, /* _bfd_reloc_type_lookup */
2605 /* Write */
2606 coff_set_arch_mach, /* _set_arch_mach */
2607 coff_set_section_contents, /* _set_section_contents */
2609 /* Link */
2610 xcoff64_sizeof_headers, /* _sizeof_headers */
2611 /* _bfd_get_relocated_section_contents */
2612 bfd_generic_get_relocated_section_contents,
2613 bfd_generic_relax_section, /* _bfd_relax_section */
2614 _bfd_xcoff_bfd_link_hash_table_create, /* _bfd_link_hash_table_create */
2615 _bfd_xcoff_bfd_link_add_symbols, /* _bfd_link_add_symbols */
2616 _bfd_xcoff_bfd_final_link, /* _bfd_filnal_link */
2617 _bfd_generic_link_split_section, /* _bfd_link_split_section */
2618 bfd_generic_gc_sections, /* _bfd_gc_sections */
2619 bfd_generic_merge_sections, /* _bfd_merge_sections */
2621 /* Dynamic */
2622 /* _get_dynamic_symtab_upper_bound */
2623 _bfd_xcoff_get_dynamic_symtab_upper_bound,
2624 _bfd_xcoff_canonicalize_dynamic_symtab, /* _cononicalize_dynamic_symtab */
2625 _bfd_xcoff_get_dynamic_reloc_upper_bound,/* _get_dynamic_reloc_upper_bound */
2626 _bfd_xcoff_canonicalize_dynamic_reloc, /* _cononicalize_dynamic_reloc */
2628 /* Opposite endian version, none exists */
2629 NULL,
2631 /* back end data */
2632 (void *) &bfd_xcoff_backend_data,