1 /* BFD back-end for IBM RS/6000 "XCOFF" files.
2 Copyright 1990-1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4 FIXME: Can someone provide a transliteration of this name into ASCII?
5 Using the following chars caused a compiler warning on HIUX (so I replaced
6 them with octal escapes), and isn't useful without an understanding of what
8 Written by Metin G. Ozisik, Mimi Ph\373\364ng-Th\345o V\365,
10 Archive support from Damon A. Permezel.
11 Contributed by IBM Corporation and Cygnus Support.
13 This file is part of BFD, the Binary File Descriptor library.
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or
18 (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
33 #include "coff/internal.h"
34 #include "coff/xcoff.h"
35 #include "coff/rs6000.h"
39 extern boolean _bfd_xcoff_mkobject PARAMS ((bfd *));
40 extern boolean _bfd_xcoff_copy_private_bfd_data PARAMS ((bfd *, bfd *));
41 extern boolean _bfd_xcoff_is_local_label_name PARAMS ((bfd *, const char *));
42 extern reloc_howto_type *_bfd_xcoff_reloc_type_lookup
43 PARAMS ((bfd *, bfd_reloc_code_real_type));
44 extern boolean _bfd_xcoff_slurp_armap PARAMS ((bfd *));
45 extern const bfd_target *_bfd_xcoff_archive_p PARAMS ((bfd *));
46 extern PTR _bfd_xcoff_read_ar_hdr PARAMS ((bfd *));
47 extern bfd *_bfd_xcoff_openr_next_archived_file PARAMS ((bfd *, bfd *));
48 extern int _bfd_xcoff_stat_arch_elt PARAMS ((bfd *, struct stat *));
49 extern boolean _bfd_xcoff_write_armap
50 PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int));
51 extern boolean _bfd_xcoff_write_archive_contents PARAMS ((bfd *));
52 extern int _bfd_xcoff_sizeof_headers PARAMS ((bfd *, boolean));
53 extern void _bfd_xcoff_swap_sym_in PARAMS ((bfd *, PTR, PTR));
54 extern unsigned int _bfd_xcoff_swap_sym_out PARAMS ((bfd *, PTR, PTR));
55 extern void _bfd_xcoff_swap_aux_in PARAMS ((bfd *, PTR, int, int, int, int, PTR));
56 extern unsigned int _bfd_xcoff_swap_aux_out PARAMS ((bfd *, PTR, int, int, int, int, PTR));
58 /* Forward declare _bfd_xcoff_rtype2howto for coffcode.h macro. */
59 void _bfd_xcoff_rtype2howto PARAMS ((arelent *, struct internal_reloc *));
61 /* coffcode.h needs these to be defined. */
62 #define RS6000COFF_C 1
64 #define SELECT_RELOC(internal, howto) \
66 internal.r_type = howto->type; \
68 ((howto->complain_on_overflow == complain_overflow_signed \
71 | (howto->bitsize - 1)); \
74 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
75 #define COFF_LONG_FILENAMES
76 #define NO_COFF_SYMBOLS
77 #define RTYPE2HOWTO(cache_ptr, dst) _bfd_xcoff_rtype2howto (cache_ptr, dst)
78 #define coff_mkobject _bfd_xcoff_mkobject
79 #define coff_bfd_copy_private_bfd_data _bfd_xcoff_copy_private_bfd_data
80 #define coff_bfd_is_local_label_name _bfd_xcoff_is_local_label_name
81 #define coff_bfd_reloc_type_lookup _bfd_xcoff_reloc_type_lookup
83 extern const bfd_target * rs6000coff_core_p PARAMS ((bfd *abfd));
84 extern boolean rs6000coff_core_file_matches_executable_p
85 PARAMS ((bfd *cbfd, bfd *ebfd));
86 extern char *rs6000coff_core_file_failing_command PARAMS ((bfd *abfd));
87 extern int rs6000coff_core_file_failing_signal PARAMS ((bfd *abfd));
88 #define CORE_FILE_P rs6000coff_core_p
89 #define coff_core_file_failing_command \
90 rs6000coff_core_file_failing_command
91 #define coff_core_file_failing_signal \
92 rs6000coff_core_file_failing_signal
93 #define coff_core_file_matches_executable_p \
94 rs6000coff_core_file_matches_executable_p
96 #define CORE_FILE_P _bfd_dummy_target
97 #define coff_core_file_failing_command \
98 _bfd_nocore_core_file_failing_command
99 #define coff_core_file_failing_signal \
100 _bfd_nocore_core_file_failing_signal
101 #define coff_core_file_matches_executable_p \
102 _bfd_nocore_core_file_matches_executable_p
104 #define coff_SWAP_sym_in _bfd_xcoff_swap_sym_in
105 #define coff_SWAP_sym_out _bfd_xcoff_swap_sym_out
106 #define coff_SWAP_aux_in _bfd_xcoff_swap_aux_in
107 #define coff_SWAP_aux_out _bfd_xcoff_swap_aux_out
109 #include "coffcode.h"
111 /* The main body of code is in coffcode.h. */
113 static const char *normalize_filename PARAMS ((bfd *));
114 static boolean xcoff_write_armap_old
115 PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int));
116 static boolean xcoff_write_armap_big
117 PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int));
118 static boolean xcoff_write_archive_contents_old PARAMS ((bfd *));
119 static boolean xcoff_write_archive_contents_big PARAMS ((bfd *));
120 static void xcoff_swap_ldhdr_in
121 PARAMS ((bfd *, const PTR, struct internal_ldhdr *));
122 static void xcoff_swap_ldhdr_out
123 PARAMS ((bfd *, const struct internal_ldhdr *, PTR));
124 static void xcoff_swap_ldsym_in
125 PARAMS ((bfd *, const PTR, struct internal_ldsym *));
126 static void xcoff_swap_ldsym_out
127 PARAMS ((bfd *, const struct internal_ldsym *, PTR));
128 static void xcoff_swap_ldrel_in
129 PARAMS ((bfd *, const PTR, struct internal_ldrel *));
130 static void xcoff_swap_ldrel_out
131 PARAMS ((bfd *, const struct internal_ldrel *, PTR));
132 static boolean xcoff_ppc_relocate_section
133 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
134 struct internal_reloc *, struct internal_syment *, asection **));
135 static boolean _bfd_xcoff_put_ldsymbol_name
136 PARAMS ((bfd *, struct xcoff_loader_info *, struct internal_ldsym *,
138 static asection *xcoff_create_csect_from_smclas
139 PARAMS ((bfd *, union internal_auxent *, const char *));
140 static boolean xcoff_is_lineno_count_overflow PARAMS ((bfd *, bfd_vma));
141 static boolean xcoff_is_reloc_count_overflow PARAMS ((bfd *, bfd_vma));
142 static bfd_vma xcoff_loader_symbol_offset
143 PARAMS ((bfd *, struct internal_ldhdr *));
144 static bfd_vma xcoff_loader_reloc_offset
145 PARAMS ((bfd *, struct internal_ldhdr *));
146 static boolean xcoff_generate_rtinit
147 PARAMS((bfd *, const char *, const char *, boolean));
148 static boolean do_pad PARAMS((bfd *, unsigned int));
149 static boolean do_copy PARAMS((bfd *, bfd *));
150 static boolean do_shared_object_padding PARAMS ((bfd *, bfd *, ufile_ptr *, int));
152 /* Relocation functions */
153 static boolean xcoff_reloc_type_noop PARAMS ((XCOFF_RELOC_FUNCTION_ARGS));
154 static boolean xcoff_reloc_type_fail PARAMS ((XCOFF_RELOC_FUNCTION_ARGS));
155 static boolean xcoff_reloc_type_pos PARAMS ((XCOFF_RELOC_FUNCTION_ARGS));
156 static boolean xcoff_reloc_type_neg PARAMS ((XCOFF_RELOC_FUNCTION_ARGS));
157 static boolean xcoff_reloc_type_rel PARAMS ((XCOFF_RELOC_FUNCTION_ARGS));
158 static boolean xcoff_reloc_type_toc PARAMS ((XCOFF_RELOC_FUNCTION_ARGS));
159 static boolean xcoff_reloc_type_ba PARAMS ((XCOFF_RELOC_FUNCTION_ARGS));
160 static boolean xcoff_reloc_type_br PARAMS ((XCOFF_RELOC_FUNCTION_ARGS));
161 static boolean xcoff_reloc_type_crel PARAMS ((XCOFF_RELOC_FUNCTION_ARGS));
163 static boolean xcoff_complain_overflow_dont_func
164 PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS));
165 static boolean xcoff_complain_overflow_bitfield_func
166 PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS));
167 static boolean xcoff_complain_overflow_signed_func
168 PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS));
169 static boolean xcoff_complain_overflow_unsigned_func
170 PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS));
172 boolean (*xcoff_calculate_relocation[XCOFF_MAX_CALCULATE_RELOCATION])
173 (XCOFF_RELOC_FUNCTION_ARGS) =
175 xcoff_reloc_type_pos, /* R_POS (0x00) */
176 xcoff_reloc_type_neg, /* R_NEG (0x01) */
177 xcoff_reloc_type_rel, /* R_REL (0x02) */
178 xcoff_reloc_type_toc, /* R_TOC (0x03) */
179 xcoff_reloc_type_fail, /* R_RTB (0x04) */
180 xcoff_reloc_type_toc, /* R_GL (0x05) */
181 xcoff_reloc_type_toc, /* R_TCL (0x06) */
182 xcoff_reloc_type_fail, /* (0x07) */
183 xcoff_reloc_type_ba, /* R_BA (0x08) */
184 xcoff_reloc_type_fail, /* (0x09) */
185 xcoff_reloc_type_br, /* R_BR (0x0a) */
186 xcoff_reloc_type_fail, /* (0x0b) */
187 xcoff_reloc_type_pos, /* R_RL (0x0c) */
188 xcoff_reloc_type_pos, /* R_RLA (0x0d) */
189 xcoff_reloc_type_fail, /* (0x0e) */
190 xcoff_reloc_type_noop, /* R_REF (0x0f) */
191 xcoff_reloc_type_fail, /* (0x10) */
192 xcoff_reloc_type_fail, /* (0x11) */
193 xcoff_reloc_type_toc, /* R_TRL (0x12) */
194 xcoff_reloc_type_toc, /* R_TRLA (0x13) */
195 xcoff_reloc_type_fail, /* R_RRTBI (0x14) */
196 xcoff_reloc_type_fail, /* R_RRTBA (0x15) */
197 xcoff_reloc_type_ba, /* R_CAI (0x16) */
198 xcoff_reloc_type_crel, /* R_CREL (0x17) */
199 xcoff_reloc_type_ba, /* R_RBA (0x18) */
200 xcoff_reloc_type_ba, /* R_RBAC (0x19) */
201 xcoff_reloc_type_br, /* R_RBR (0x1a) */
202 xcoff_reloc_type_ba, /* R_RBRC (0x1b) */
205 boolean (*xcoff_complain_overflow[XCOFF_MAX_COMPLAIN_OVERFLOW])
206 (XCOFF_COMPLAIN_FUNCTION_ARGS) =
208 xcoff_complain_overflow_dont_func,
209 xcoff_complain_overflow_bitfield_func,
210 xcoff_complain_overflow_signed_func,
211 xcoff_complain_overflow_unsigned_func,
214 /* We use our own tdata type. Its first field is the COFF tdata type,
215 so the COFF routines are compatible. */
218 _bfd_xcoff_mkobject (abfd)
221 coff_data_type *coff;
222 bfd_size_type amt = sizeof (struct xcoff_tdata);
224 abfd->tdata.xcoff_obj_data = (struct xcoff_tdata *) bfd_zalloc (abfd, amt);
225 if (abfd->tdata.xcoff_obj_data == NULL)
227 coff = coff_data (abfd);
228 coff->symbols = (coff_symbol_type *) NULL;
229 coff->conversion_table = (unsigned int *) NULL;
230 coff->raw_syments = (struct coff_ptr_struct *) NULL;
233 xcoff_data (abfd)->modtype = ('1' << 8) | 'L';
235 /* We set cputype to -1 to indicate that it has not been
237 xcoff_data (abfd)->cputype = -1;
239 xcoff_data (abfd)->csects = NULL;
240 xcoff_data (abfd)->debug_indices = NULL;
242 /* text section alignment is different than the default */
243 /* xcoff_data (abfd)->text_align_power = 5; */
248 /* Copy XCOFF data from one BFD to another. */
251 _bfd_xcoff_copy_private_bfd_data (ibfd, obfd)
255 struct xcoff_tdata *ix, *ox;
258 if (ibfd->xvec != obfd->xvec)
260 ix = xcoff_data (ibfd);
261 ox = xcoff_data (obfd);
262 ox->full_aouthdr = ix->full_aouthdr;
268 sec = coff_section_from_bfd_index (ibfd, ix->sntoc);
272 ox->sntoc = sec->output_section->target_index;
274 if (ix->snentry == 0)
278 sec = coff_section_from_bfd_index (ibfd, ix->snentry);
282 ox->snentry = sec->output_section->target_index;
284 ox->text_align_power = ix->text_align_power;
285 ox->data_align_power = ix->data_align_power;
286 ox->modtype = ix->modtype;
287 ox->cputype = ix->cputype;
288 ox->maxdata = ix->maxdata;
289 ox->maxstack = ix->maxstack;
293 /* I don't think XCOFF really has a notion of local labels based on
294 name. This will mean that ld -X doesn't actually strip anything.
295 The AIX native linker does not have a -X option, and it ignores the
299 _bfd_xcoff_is_local_label_name (abfd, name)
300 bfd *abfd ATTRIBUTE_UNUSED;
301 const char *name ATTRIBUTE_UNUSED;
307 _bfd_xcoff_swap_sym_in (abfd, ext1, in1)
312 SYMENT *ext = (SYMENT *)ext1;
313 struct internal_syment * in = (struct internal_syment *)in1;
315 if (ext->e.e_name[0] != 0)
317 memcpy(in->_n._n_name, ext->e.e_name, SYMNMLEN);
321 in->_n._n_n._n_zeroes = 0;
322 in->_n._n_n._n_offset = H_GET_32 (abfd, ext->e.e.e_offset);
325 in->n_value = H_GET_32 (abfd, ext->e_value);
326 in->n_scnum = H_GET_16 (abfd, ext->e_scnum);
327 in->n_type = H_GET_16 (abfd, ext->e_type);
328 in->n_sclass = H_GET_8 (abfd, ext->e_sclass);
329 in->n_numaux = H_GET_8 (abfd, ext->e_numaux);
333 _bfd_xcoff_swap_sym_out (abfd, inp, extp)
338 struct internal_syment *in = (struct internal_syment *)inp;
339 SYMENT *ext =(SYMENT *)extp;
341 if (in->_n._n_name[0] != 0)
343 memcpy(ext->e.e_name, in->_n._n_name, SYMNMLEN);
347 H_PUT_32 (abfd, 0, ext->e.e.e_zeroes);
348 H_PUT_32 (abfd, in->_n._n_n._n_offset, ext->e.e.e_offset);
351 H_PUT_32 (abfd, in->n_value, ext->e_value);
352 H_PUT_16 (abfd, in->n_scnum, ext->e_scnum);
353 H_PUT_16 (abfd, in->n_type, ext->e_type);
354 H_PUT_8 (abfd, in->n_sclass, ext->e_sclass);
355 H_PUT_8 (abfd, in->n_numaux, ext->e_numaux);
356 return bfd_coff_symesz (abfd);
360 _bfd_xcoff_swap_aux_in (abfd, ext1, type, class, indx, numaux, in1)
369 AUXENT * ext = (AUXENT *)ext1;
370 union internal_auxent *in = (union internal_auxent *)in1;
375 if (ext->x_file.x_fname[0] == 0)
377 in->x_file.x_n.x_zeroes = 0;
378 in->x_file.x_n.x_offset =
379 H_GET_32 (abfd, ext->x_file.x_n.x_offset);
386 memcpy (in->x_file.x_fname, ext->x_file.x_fname,
387 numaux * sizeof (AUXENT));
391 memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN);
396 /* RS/6000 "csect" auxents */
399 if (indx + 1 == numaux)
401 in->x_csect.x_scnlen.l = H_GET_32 (abfd, ext->x_csect.x_scnlen);
402 in->x_csect.x_parmhash = H_GET_32 (abfd, ext->x_csect.x_parmhash);
403 in->x_csect.x_snhash = H_GET_16 (abfd, ext->x_csect.x_snhash);
404 /* We don't have to hack bitfields in x_smtyp because it's
405 defined by shifts-and-ands, which are equivalent on all
407 in->x_csect.x_smtyp = H_GET_8 (abfd, ext->x_csect.x_smtyp);
408 in->x_csect.x_smclas = H_GET_8 (abfd, ext->x_csect.x_smclas);
409 in->x_csect.x_stab = H_GET_32 (abfd, ext->x_csect.x_stab);
410 in->x_csect.x_snstab = H_GET_16 (abfd, ext->x_csect.x_snstab);
420 in->x_scn.x_scnlen = H_GET_32 (abfd, ext->x_scn.x_scnlen);
421 in->x_scn.x_nreloc = H_GET_16 (abfd, ext->x_scn.x_nreloc);
422 in->x_scn.x_nlinno = H_GET_16 (abfd, ext->x_scn.x_nlinno);
423 /* PE defines some extra fields; we zero them out for
425 in->x_scn.x_checksum = 0;
426 in->x_scn.x_associated = 0;
427 in->x_scn.x_comdat = 0;
434 in->x_sym.x_tagndx.l = H_GET_32 (abfd, ext->x_sym.x_tagndx);
435 in->x_sym.x_tvndx = H_GET_16 (abfd, ext->x_sym.x_tvndx);
437 if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
439 in->x_sym.x_fcnary.x_fcn.x_lnnoptr =
440 H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_lnnoptr);
441 in->x_sym.x_fcnary.x_fcn.x_endndx.l =
442 H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_endndx);
446 in->x_sym.x_fcnary.x_ary.x_dimen[0] =
447 H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
448 in->x_sym.x_fcnary.x_ary.x_dimen[1] =
449 H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
450 in->x_sym.x_fcnary.x_ary.x_dimen[2] =
451 H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
452 in->x_sym.x_fcnary.x_ary.x_dimen[3] =
453 H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
458 in->x_sym.x_misc.x_fsize = H_GET_32 (abfd, ext->x_sym.x_misc.x_fsize);
462 in->x_sym.x_misc.x_lnsz.x_lnno =
463 H_GET_16 (abfd, ext->x_sym.x_misc.x_lnsz.x_lnno);
464 in->x_sym.x_misc.x_lnsz.x_size =
465 H_GET_16 (abfd, ext->x_sym.x_misc.x_lnsz.x_size);
469 /* The semicolon is because MSVC doesn't like labels at
474 unsigned int _bfd_xcoff_swap_aux_out PARAMS ((bfd *, PTR, int, int, int, int, PTR));
477 _bfd_xcoff_swap_aux_out (abfd, inp, type, class, indx, numaux, extp)
482 int indx ATTRIBUTE_UNUSED;
483 int numaux ATTRIBUTE_UNUSED;
486 union internal_auxent *in = (union internal_auxent *)inp;
487 AUXENT *ext = (AUXENT *)extp;
489 memset((PTR)ext, 0, bfd_coff_auxesz (abfd));
493 if (in->x_file.x_fname[0] == 0)
495 H_PUT_32 (abfd, 0, ext->x_file.x_n.x_zeroes);
496 H_PUT_32 (abfd, in->x_file.x_n.x_offset, ext->x_file.x_n.x_offset);
500 memcpy (ext->x_file.x_fname, in->x_file.x_fname, FILNMLEN);
504 /* RS/6000 "csect" auxents */
507 if (indx + 1 == numaux)
509 H_PUT_32 (abfd, in->x_csect.x_scnlen.l, ext->x_csect.x_scnlen);
510 H_PUT_32 (abfd, in->x_csect.x_parmhash, ext->x_csect.x_parmhash);
511 H_PUT_16 (abfd, in->x_csect.x_snhash, ext->x_csect.x_snhash);
512 /* We don't have to hack bitfields in x_smtyp because it's
513 defined by shifts-and-ands, which are equivalent on all
515 H_PUT_8 (abfd, in->x_csect.x_smtyp, ext->x_csect.x_smtyp);
516 H_PUT_8 (abfd, in->x_csect.x_smclas, ext->x_csect.x_smclas);
517 H_PUT_32 (abfd, in->x_csect.x_stab, ext->x_csect.x_stab);
518 H_PUT_16 (abfd, in->x_csect.x_snstab, ext->x_csect.x_snstab);
528 H_PUT_32 (abfd, in->x_scn.x_scnlen, ext->x_scn.x_scnlen);
529 H_PUT_16 (abfd, in->x_scn.x_nreloc, ext->x_scn.x_nreloc);
530 H_PUT_16 (abfd, in->x_scn.x_nlinno, ext->x_scn.x_nlinno);
536 H_PUT_32 (abfd, in->x_sym.x_tagndx.l, ext->x_sym.x_tagndx);
537 H_PUT_16 (abfd, in->x_sym.x_tvndx, ext->x_sym.x_tvndx);
539 if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class))
541 H_PUT_32 (abfd, in->x_sym.x_fcnary.x_fcn.x_lnnoptr,
542 ext->x_sym.x_fcnary.x_fcn.x_lnnoptr);
543 H_PUT_32 (abfd, in->x_sym.x_fcnary.x_fcn.x_endndx.l,
544 ext->x_sym.x_fcnary.x_fcn.x_endndx);
548 H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[0],
549 ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
550 H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[1],
551 ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
552 H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[2],
553 ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
554 H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[3],
555 ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
559 H_PUT_32 (abfd, in->x_sym.x_misc.x_fsize, ext->x_sym.x_misc.x_fsize);
562 H_PUT_16 (abfd, in->x_sym.x_misc.x_lnsz.x_lnno,
563 ext->x_sym.x_misc.x_lnsz.x_lnno);
564 H_PUT_16 (abfd, in->x_sym.x_misc.x_lnsz.x_size,
565 ext->x_sym.x_misc.x_lnsz.x_size);
569 return bfd_coff_auxesz (abfd);
574 /* The XCOFF reloc table. Actually, XCOFF relocations specify the
575 bitsize and whether they are signed or not, along with a
576 conventional type. This table is for the types, which are used for
577 different algorithms for putting in the reloc. Many of these
578 relocs need special_function entries, which I have not written. */
581 reloc_howto_type xcoff_howto_table[] =
583 /* Standard 32 bit relocation. */
584 HOWTO (R_POS, /* type */
586 2, /* size (0 = byte, 1 = short, 2 = long) */
588 false, /* pc_relative */
590 complain_overflow_bitfield, /* complain_on_overflow */
591 0, /* special_function */
593 true, /* partial_inplace */
594 0xffffffff, /* src_mask */
595 0xffffffff, /* dst_mask */
596 false), /* pcrel_offset */
598 /* 32 bit relocation, but store negative value. */
599 HOWTO (R_NEG, /* type */
601 -2, /* size (0 = byte, 1 = short, 2 = long) */
603 false, /* pc_relative */
605 complain_overflow_bitfield, /* complain_on_overflow */
606 0, /* special_function */
608 true, /* partial_inplace */
609 0xffffffff, /* src_mask */
610 0xffffffff, /* dst_mask */
611 false), /* pcrel_offset */
613 /* 32 bit PC relative relocation. */
614 HOWTO (R_REL, /* type */
616 2, /* size (0 = byte, 1 = short, 2 = long) */
618 true, /* pc_relative */
620 complain_overflow_signed, /* complain_on_overflow */
621 0, /* special_function */
623 true, /* partial_inplace */
624 0xffffffff, /* src_mask */
625 0xffffffff, /* dst_mask */
626 false), /* pcrel_offset */
628 /* 16 bit TOC relative relocation. */
629 HOWTO (R_TOC, /* type */
631 1, /* size (0 = byte, 1 = short, 2 = long) */
633 false, /* pc_relative */
635 complain_overflow_bitfield, /* complain_on_overflow */
636 0, /* special_function */
638 true, /* partial_inplace */
639 0xffff, /* src_mask */
640 0xffff, /* dst_mask */
641 false), /* pcrel_offset */
643 /* I don't really know what this is. */
644 HOWTO (R_RTB, /* type */
646 2, /* size (0 = byte, 1 = short, 2 = long) */
648 false, /* pc_relative */
650 complain_overflow_bitfield, /* complain_on_overflow */
651 0, /* special_function */
653 true, /* partial_inplace */
654 0xffffffff, /* src_mask */
655 0xffffffff, /* dst_mask */
656 false), /* pcrel_offset */
658 /* External TOC relative symbol. */
659 HOWTO (R_GL, /* type */
661 2, /* size (0 = byte, 1 = short, 2 = long) */
663 false, /* pc_relative */
665 complain_overflow_bitfield, /* complain_on_overflow */
666 0, /* special_function */
668 true, /* partial_inplace */
669 0xffff, /* src_mask */
670 0xffff, /* dst_mask */
671 false), /* pcrel_offset */
673 /* Local TOC relative symbol. */
674 HOWTO (R_TCL, /* type */
676 2, /* size (0 = byte, 1 = short, 2 = long) */
678 false, /* pc_relative */
680 complain_overflow_bitfield, /* complain_on_overflow */
681 0, /* special_function */
683 true, /* partial_inplace */
684 0xffff, /* src_mask */
685 0xffff, /* dst_mask */
686 false), /* pcrel_offset */
690 /* Non modifiable absolute branch. */
691 HOWTO (R_BA, /* type */
693 2, /* size (0 = byte, 1 = short, 2 = long) */
695 false, /* pc_relative */
697 complain_overflow_bitfield, /* complain_on_overflow */
698 0, /* special_function */
700 true, /* partial_inplace */
701 0x3fffffc, /* src_mask */
702 0x3fffffc, /* dst_mask */
703 false), /* pcrel_offset */
707 /* Non modifiable relative branch. */
708 HOWTO (R_BR, /* type */
710 2, /* size (0 = byte, 1 = short, 2 = long) */
712 true, /* pc_relative */
714 complain_overflow_signed, /* complain_on_overflow */
715 0, /* special_function */
717 true, /* partial_inplace */
718 0x3fffffc, /* src_mask */
719 0x3fffffc, /* dst_mask */
720 false), /* pcrel_offset */
725 HOWTO (R_RL, /* type */
727 2, /* size (0 = byte, 1 = short, 2 = long) */
729 false, /* pc_relative */
731 complain_overflow_bitfield, /* complain_on_overflow */
732 0, /* special_function */
734 true, /* partial_inplace */
735 0xffff, /* src_mask */
736 0xffff, /* dst_mask */
737 false), /* pcrel_offset */
740 HOWTO (R_RLA, /* type */
742 2, /* size (0 = byte, 1 = short, 2 = long) */
744 false, /* pc_relative */
746 complain_overflow_bitfield, /* complain_on_overflow */
747 0, /* special_function */
749 true, /* partial_inplace */
750 0xffff, /* src_mask */
751 0xffff, /* dst_mask */
752 false), /* pcrel_offset */
756 /* Non-relocating reference. */
757 HOWTO (R_REF, /* type */
759 2, /* size (0 = byte, 1 = short, 2 = long) */
761 false, /* pc_relative */
763 complain_overflow_bitfield, /* complain_on_overflow */
764 0, /* special_function */
766 false, /* partial_inplace */
769 false), /* pcrel_offset */
774 /* TOC relative indirect load. */
775 HOWTO (R_TRL, /* type */
777 2, /* size (0 = byte, 1 = short, 2 = long) */
779 false, /* pc_relative */
781 complain_overflow_bitfield, /* complain_on_overflow */
782 0, /* special_function */
784 true, /* partial_inplace */
785 0xffff, /* src_mask */
786 0xffff, /* dst_mask */
787 false), /* pcrel_offset */
789 /* TOC relative load address. */
790 HOWTO (R_TRLA, /* type */
792 2, /* size (0 = byte, 1 = short, 2 = long) */
794 false, /* pc_relative */
796 complain_overflow_bitfield, /* complain_on_overflow */
797 0, /* special_function */
799 true, /* partial_inplace */
800 0xffff, /* src_mask */
801 0xffff, /* dst_mask */
802 false), /* pcrel_offset */
804 /* Modifiable relative branch. */
805 HOWTO (R_RRTBI, /* type */
807 2, /* size (0 = byte, 1 = short, 2 = long) */
809 false, /* pc_relative */
811 complain_overflow_bitfield, /* complain_on_overflow */
812 0, /* special_function */
813 "R_RRTBI", /* name */
814 true, /* partial_inplace */
815 0xffffffff, /* src_mask */
816 0xffffffff, /* dst_mask */
817 false), /* pcrel_offset */
819 /* Modifiable absolute branch. */
820 HOWTO (R_RRTBA, /* type */
822 2, /* size (0 = byte, 1 = short, 2 = long) */
824 false, /* pc_relative */
826 complain_overflow_bitfield, /* complain_on_overflow */
827 0, /* special_function */
828 "R_RRTBA", /* name */
829 true, /* partial_inplace */
830 0xffffffff, /* src_mask */
831 0xffffffff, /* dst_mask */
832 false), /* pcrel_offset */
834 /* Modifiable call absolute indirect. */
835 HOWTO (R_CAI, /* type */
837 2, /* size (0 = byte, 1 = short, 2 = long) */
839 false, /* pc_relative */
841 complain_overflow_bitfield, /* complain_on_overflow */
842 0, /* special_function */
844 true, /* partial_inplace */
845 0xffff, /* src_mask */
846 0xffff, /* dst_mask */
847 false), /* pcrel_offset */
849 /* Modifiable call relative. */
850 HOWTO (R_CREL, /* type */
852 2, /* size (0 = byte, 1 = short, 2 = long) */
854 false, /* pc_relative */
856 complain_overflow_bitfield, /* complain_on_overflow */
857 0, /* special_function */
859 true, /* partial_inplace */
860 0xffff, /* src_mask */
861 0xffff, /* dst_mask */
862 false), /* pcrel_offset */
864 /* Modifiable branch absolute. */
865 HOWTO (R_RBA, /* type */
867 2, /* size (0 = byte, 1 = short, 2 = long) */
869 false, /* pc_relative */
871 complain_overflow_bitfield, /* complain_on_overflow */
872 0, /* special_function */
874 true, /* partial_inplace */
875 0xffff, /* src_mask */
876 0xffff, /* dst_mask */
877 false), /* pcrel_offset */
879 /* Modifiable branch absolute. */
880 HOWTO (R_RBAC, /* type */
882 2, /* size (0 = byte, 1 = short, 2 = long) */
884 false, /* pc_relative */
886 complain_overflow_bitfield, /* complain_on_overflow */
887 0, /* special_function */
889 true, /* partial_inplace */
890 0xffff, /* src_mask */
891 0xffff, /* dst_mask */
892 false), /* pcrel_offset */
894 /* Modifiable branch relative. */
895 HOWTO (R_RBR, /* type */
897 2, /* size (0 = byte, 1 = short, 2 = long) */
899 false, /* pc_relative */
901 complain_overflow_signed, /* complain_on_overflow */
902 0, /* special_function */
904 true, /* partial_inplace */
905 0xffff, /* src_mask */
906 0xffff, /* dst_mask */
907 false), /* pcrel_offset */
909 /* Modifiable branch absolute. */
910 HOWTO (R_RBRC, /* type */
912 2, /* size (0 = byte, 1 = short, 2 = long) */
914 false, /* pc_relative */
916 complain_overflow_bitfield, /* complain_on_overflow */
917 0, /* special_function */
919 true, /* partial_inplace */
920 0xffff, /* src_mask */
921 0xffff, /* dst_mask */
922 false), /* pcrel_offset */
924 HOWTO (R_POS, /* type */
926 4, /* size (0 = byte, 1 = short, 2 = long) */
928 false, /* pc_relative */
930 complain_overflow_bitfield, /* complain_on_overflow */
931 0, /* special_function */
933 true, /* partial_inplace */
934 MINUS_ONE, /* src_mask */
935 MINUS_ONE, /* dst_mask */
936 false), /* pcrel_offset */
938 /* 16 bit Non modifiable absolute branch. */
939 HOWTO (R_BA, /* type */
941 2, /* size (0 = byte, 1 = short, 2 = long) */
943 false, /* pc_relative */
945 complain_overflow_bitfield, /* complain_on_overflow */
946 0, /* special_function */
948 true, /* partial_inplace */
949 0xfffc, /* src_mask */
950 0xfffc, /* dst_mask */
951 false), /* pcrel_offset */
955 _bfd_xcoff_rtype2howto (relent, internal)
957 struct internal_reloc *internal;
959 relent->howto = xcoff_howto_table + internal->r_type;
961 /* Check for relocs we don't know of. */
963 >= sizeof (xcoff_howto_table) / sizeof (xcoff_howto_table[0]))
965 if (internal->r_type != relent->howto->type)
968 /* The r_size field of an XCOFF reloc encodes the bitsize of the
969 relocation, as well as indicating whether it is signed or not.
970 Doublecheck that the relocation information gathered from the
971 type matches this information. The bitsize is not significant
973 if (relent->howto->dst_mask != 0
974 && (relent->howto->bitsize
975 != ((unsigned int) internal->r_size & 0x3f) + 1))
978 if ((internal->r_size & 0x80) != 0
979 ? (relent->howto->complain_on_overflow != complain_overflow_signed)
980 : (relent->howto->complain_on_overflow != complain_overflow_bitfield))
986 _bfd_xcoff_reloc_type_lookup (abfd, code)
987 bfd *abfd ATTRIBUTE_UNUSED;
988 bfd_reloc_code_real_type code;
992 case BFD_RELOC_PPC_B26:
993 return &xcoff_howto_table[0xa];
994 case BFD_RELOC_PPC_BA16:
995 return &xcoff_howto_table[0x1d];
996 case BFD_RELOC_PPC_BA26:
997 return &xcoff_howto_table[8];
998 case BFD_RELOC_PPC_TOC16:
999 return &xcoff_howto_table[3];
1001 case BFD_RELOC_CTOR:
1002 return &xcoff_howto_table[0];
1004 return &xcoff_howto_table[0x1c];
1011 /* XCOFF archive support. The original version of this code was by
1012 Damon A. Permezel. It was enhanced to permit cross support, and
1013 writing archive files, by Ian Lance Taylor, Cygnus Support.
1015 XCOFF uses its own archive format. Everything is hooked together
1016 with file offset links, so it is possible to rapidly update an
1017 archive in place. Of course, we don't do that. An XCOFF archive
1018 has a real file header, not just an ARMAG string. The structure of
1019 the file header and of each archive header appear below.
1021 An XCOFF archive also has a member table, which is a list of
1022 elements in the archive (you can get that by looking through the
1023 linked list, but you have to read a lot more of the file). The
1024 member table has a normal archive header with an empty name. It is
1025 normally (and perhaps must be) the second to last entry in the
1026 archive. The member table data is almost printable ASCII. It
1027 starts with a 12 character decimal string which is the number of
1028 entries in the table. For each entry it has a 12 character decimal
1029 string which is the offset in the archive of that member. These
1030 entries are followed by a series of null terminated strings which
1031 are the member names for each entry.
1033 Finally, an XCOFF archive has a global symbol table, which is what
1034 we call the armap. The global symbol table has a normal archive
1035 header with an empty name. It is normally (and perhaps must be)
1036 the last entry in the archive. The contents start with a four byte
1037 binary number which is the number of entries. This is followed by
1038 a that many four byte binary numbers; each is the file offset of an
1039 entry in the archive. These numbers are followed by a series of
1040 null terminated strings, which are symbol names.
1042 AIX 4.3 introduced a new archive format which can handle larger
1043 files and also 32- and 64-bit objects in the same archive. The
1044 things said above remain true except that there is now more than
1045 one global symbol table. The one is used to index 32-bit objects,
1046 the other for 64-bit objects.
1048 The new archives (recognizable by the new ARMAG string) has larger
1049 field lengths so that we cannot really share any code. Also we have
1050 to take care that we are not generating the new form of archives
1051 on AIX 4.2 or earlier systems. */
1053 /* XCOFF archives use this as a magic string. Note that both strings
1054 have the same length. */
1056 /* Set the magic for archive. */
1059 bfd_xcoff_ar_archive_set_magic (abfd, magic)
1060 bfd *abfd ATTRIBUTE_UNUSED;
1061 char *magic ATTRIBUTE_UNUSED;
1063 /* Not supported yet. */
1065 /* bfd_xcoff_archive_set_magic (abfd, magic); */
1068 /* Read in the armap of an XCOFF archive. */
1071 _bfd_xcoff_slurp_armap (abfd)
1077 bfd_byte *contents, *cend;
1082 if (xcoff_ardata (abfd) == NULL)
1084 bfd_has_map (abfd) = false;
1088 if (! xcoff_big_format_p (abfd))
1090 /* This is for the old format. */
1091 struct xcoff_ar_hdr hdr;
1093 off = strtol (xcoff_ardata (abfd)->symoff, (char **) NULL, 10);
1096 bfd_has_map (abfd) = false;
1100 if (bfd_seek (abfd, off, SEEK_SET) != 0)
1103 /* The symbol table starts with a normal archive header. */
1104 if (bfd_bread ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
1108 /* Skip the name (normally empty). */
1109 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1110 off = ((namlen + 1) & ~ (size_t) 1) + SXCOFFARFMAG;
1111 if (bfd_seek (abfd, off, SEEK_CUR) != 0)
1114 sz = strtol (hdr.size, (char **) NULL, 10);
1116 /* Read in the entire symbol table. */
1117 contents = (bfd_byte *) bfd_alloc (abfd, sz);
1118 if (contents == NULL)
1120 if (bfd_bread ((PTR) contents, sz, abfd) != sz)
1123 /* The symbol table starts with a four byte count. */
1124 c = H_GET_32 (abfd, contents);
1128 bfd_set_error (bfd_error_bad_value);
1132 bfd_ardata (abfd)->symdefs =
1133 ((carsym *) bfd_alloc (abfd, c * sizeof (carsym)));
1134 if (bfd_ardata (abfd)->symdefs == NULL)
1137 /* After the count comes a list of four byte file offsets. */
1138 for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 4;
1140 ++i, ++arsym, p += 4)
1141 arsym->file_offset = H_GET_32 (abfd, p);
1145 /* This is for the new format. */
1146 struct xcoff_ar_hdr_big hdr;
1148 off = strtol (xcoff_ardata_big (abfd)->symoff, (char **) NULL, 10);
1151 bfd_has_map (abfd) = false;
1155 if (bfd_seek (abfd, off, SEEK_SET) != 0)
1158 /* The symbol table starts with a normal archive header. */
1159 if (bfd_bread ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR_BIG, abfd)
1160 != SIZEOF_AR_HDR_BIG)
1163 /* Skip the name (normally empty). */
1164 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1165 off = ((namlen + 1) & ~ (size_t) 1) + SXCOFFARFMAG;
1166 if (bfd_seek (abfd, off, SEEK_CUR) != 0)
1169 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1170 machines) since the field width is 20 and there numbers with more
1171 than 32 bits can be represented. */
1172 sz = strtol (hdr.size, (char **) NULL, 10);
1174 /* Read in the entire symbol table. */
1175 contents = (bfd_byte *) bfd_alloc (abfd, sz);
1176 if (contents == NULL)
1178 if (bfd_bread ((PTR) contents, sz, abfd) != sz)
1181 /* The symbol table starts with an eight byte count. */
1182 c = H_GET_64 (abfd, contents);
1186 bfd_set_error (bfd_error_bad_value);
1190 bfd_ardata (abfd)->symdefs =
1191 ((carsym *) bfd_alloc (abfd, c * sizeof (carsym)));
1192 if (bfd_ardata (abfd)->symdefs == NULL)
1195 /* After the count comes a list of eight byte file offsets. */
1196 for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 8;
1198 ++i, ++arsym, p += 8)
1199 arsym->file_offset = H_GET_64 (abfd, p);
1202 /* After the file offsets come null terminated symbol names. */
1203 cend = contents + sz;
1204 for (i = 0, arsym = bfd_ardata (abfd)->symdefs;
1206 ++i, ++arsym, p += strlen ((char *) p) + 1)
1210 bfd_set_error (bfd_error_bad_value);
1213 arsym->name = (char *) p;
1216 bfd_ardata (abfd)->symdef_count = c;
1217 bfd_has_map (abfd) = true;
1222 /* See if this is an XCOFF archive. */
1225 _bfd_xcoff_archive_p (abfd)
1228 char magic[SXCOFFARMAG];
1231 if (bfd_bread ((PTR) magic, (bfd_size_type) SXCOFFARMAG, abfd) != SXCOFFARMAG)
1233 if (bfd_get_error () != bfd_error_system_call)
1234 bfd_set_error (bfd_error_wrong_format);
1238 if (strncmp (magic, XCOFFARMAG, SXCOFFARMAG) != 0
1239 && strncmp (magic, XCOFFARMAGBIG, SXCOFFARMAG) != 0)
1241 bfd_set_error (bfd_error_wrong_format);
1245 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
1246 involves a cast, we can't do it as the left operand of
1248 amt = sizeof (struct artdata);
1249 abfd->tdata.aout_ar_data = (struct artdata *) bfd_zalloc (abfd, amt);
1250 if (bfd_ardata (abfd) == (struct artdata *) NULL)
1253 bfd_ardata (abfd)->cache = NULL;
1254 bfd_ardata (abfd)->archive_head = NULL;
1255 bfd_ardata (abfd)->symdefs = NULL;
1256 bfd_ardata (abfd)->extended_names = NULL;
1258 /* Now handle the two formats. */
1259 if (magic[1] != 'b')
1261 /* This is the old format. */
1262 struct xcoff_ar_file_hdr hdr;
1264 /* Copy over the magic string. */
1265 memcpy (hdr.magic, magic, SXCOFFARMAG);
1267 /* Now read the rest of the file header. */
1268 if (bfd_bread ((PTR) &hdr.memoff,
1269 (bfd_size_type) SIZEOF_AR_FILE_HDR - SXCOFFARMAG, abfd)
1270 != SIZEOF_AR_FILE_HDR - SXCOFFARMAG)
1272 if (bfd_get_error () != bfd_error_system_call)
1273 bfd_set_error (bfd_error_wrong_format);
1277 bfd_ardata (abfd)->first_file_filepos = strtol (hdr.firstmemoff,
1278 (char **) NULL, 10);
1280 amt = SIZEOF_AR_FILE_HDR;
1281 bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, amt);
1282 if (bfd_ardata (abfd)->tdata == NULL)
1285 memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR);
1289 /* This is the new format. */
1290 struct xcoff_ar_file_hdr_big hdr;
1292 /* Copy over the magic string. */
1293 memcpy (hdr.magic, magic, SXCOFFARMAG);
1295 /* Now read the rest of the file header. */
1296 if (bfd_bread ((PTR) &hdr.memoff,
1297 (bfd_size_type) SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG, abfd)
1298 != SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG)
1300 if (bfd_get_error () != bfd_error_system_call)
1301 bfd_set_error (bfd_error_wrong_format);
1305 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1306 machines) since the field width is 20 and there numbers with more
1307 than 32 bits can be represented. */
1308 bfd_ardata (abfd)->first_file_filepos = strtol (hdr.firstmemoff,
1309 (char **) NULL, 10);
1311 amt = SIZEOF_AR_FILE_HDR_BIG;
1312 bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, amt);
1313 if (bfd_ardata (abfd)->tdata == NULL)
1316 memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR_BIG);
1319 if (! _bfd_xcoff_slurp_armap (abfd))
1321 bfd_release (abfd, bfd_ardata (abfd));
1322 abfd->tdata.aout_ar_data = (struct artdata *) NULL;
1329 /* Read the archive header in an XCOFF archive. */
1332 _bfd_xcoff_read_ar_hdr (abfd)
1335 bfd_size_type namlen;
1336 struct areltdata *ret;
1337 bfd_size_type amt = sizeof (struct areltdata);
1339 ret = (struct areltdata *) bfd_alloc (abfd, amt);
1343 if (! xcoff_big_format_p (abfd))
1345 struct xcoff_ar_hdr hdr;
1346 struct xcoff_ar_hdr *hdrp;
1348 if (bfd_bread ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
1355 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1356 amt = SIZEOF_AR_HDR + namlen + 1;
1357 hdrp = (struct xcoff_ar_hdr *) bfd_alloc (abfd, amt);
1363 memcpy (hdrp, &hdr, SIZEOF_AR_HDR);
1364 if (bfd_bread ((char *) hdrp + SIZEOF_AR_HDR, namlen, abfd) != namlen)
1369 ((char *) hdrp)[SIZEOF_AR_HDR + namlen] = '\0';
1371 ret->arch_header = (char *) hdrp;
1372 ret->parsed_size = strtol (hdr.size, (char **) NULL, 10);
1373 ret->filename = (char *) hdrp + SIZEOF_AR_HDR;
1377 struct xcoff_ar_hdr_big hdr;
1378 struct xcoff_ar_hdr_big *hdrp;
1380 if (bfd_bread ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR_BIG, abfd)
1381 != SIZEOF_AR_HDR_BIG)
1387 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1388 amt = SIZEOF_AR_HDR_BIG + namlen + 1;
1389 hdrp = (struct xcoff_ar_hdr_big *) bfd_alloc (abfd, amt);
1395 memcpy (hdrp, &hdr, SIZEOF_AR_HDR_BIG);
1396 if (bfd_bread ((char *) hdrp + SIZEOF_AR_HDR_BIG, namlen, abfd) != namlen)
1401 ((char *) hdrp)[SIZEOF_AR_HDR_BIG + namlen] = '\0';
1403 ret->arch_header = (char *) hdrp;
1404 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1405 machines) since the field width is 20 and there numbers with more
1406 than 32 bits can be represented. */
1407 ret->parsed_size = strtol (hdr.size, (char **) NULL, 10);
1408 ret->filename = (char *) hdrp + SIZEOF_AR_HDR_BIG;
1411 /* Skip over the XCOFFARFMAG at the end of the file name. */
1412 if (bfd_seek (abfd, (file_ptr) ((namlen & 1) + SXCOFFARFMAG), SEEK_CUR) != 0)
1418 /* Open the next element in an XCOFF archive. */
1421 _bfd_xcoff_openr_next_archived_file (archive, last_file)
1427 if (xcoff_ardata (archive) == NULL)
1429 bfd_set_error (bfd_error_invalid_operation);
1433 if (! xcoff_big_format_p (archive))
1435 if (last_file == NULL)
1436 filestart = bfd_ardata (archive)->first_file_filepos;
1438 filestart = strtol (arch_xhdr (last_file)->nextoff, (char **) NULL,
1442 || filestart == strtol (xcoff_ardata (archive)->memoff,
1444 || filestart == strtol (xcoff_ardata (archive)->symoff,
1445 (char **) NULL, 10))
1447 bfd_set_error (bfd_error_no_more_archived_files);
1453 if (last_file == NULL)
1454 filestart = bfd_ardata (archive)->first_file_filepos;
1456 /* XXX These actually have to be a calls to strtoll (at least
1457 on 32-bit machines) since the fields's width is 20 and
1458 there numbers with more than 32 bits can be represented. */
1459 filestart = strtol (arch_xhdr_big (last_file)->nextoff, (char **) NULL,
1462 /* XXX These actually have to be calls to strtoll (at least on 32-bit
1463 machines) since the fields's width is 20 and there numbers with more
1464 than 32 bits can be represented. */
1466 || filestart == strtol (xcoff_ardata_big (archive)->memoff,
1468 || filestart == strtol (xcoff_ardata_big (archive)->symoff,
1469 (char **) NULL, 10))
1471 bfd_set_error (bfd_error_no_more_archived_files);
1476 return _bfd_get_elt_at_filepos (archive, filestart);
1479 /* Stat an element in an XCOFF archive. */
1482 _bfd_xcoff_stat_arch_elt (abfd, s)
1486 if (abfd->arelt_data == NULL)
1488 bfd_set_error (bfd_error_invalid_operation);
1492 if (! xcoff_big_format_p (abfd->my_archive))
1494 struct xcoff_ar_hdr *hdrp = arch_xhdr (abfd);
1496 s->st_mtime = strtol (hdrp->date, (char **) NULL, 10);
1497 s->st_uid = strtol (hdrp->uid, (char **) NULL, 10);
1498 s->st_gid = strtol (hdrp->gid, (char **) NULL, 10);
1499 s->st_mode = strtol (hdrp->mode, (char **) NULL, 8);
1500 s->st_size = arch_eltdata (abfd)->parsed_size;
1504 struct xcoff_ar_hdr_big *hdrp = arch_xhdr_big (abfd);
1506 s->st_mtime = strtol (hdrp->date, (char **) NULL, 10);
1507 s->st_uid = strtol (hdrp->uid, (char **) NULL, 10);
1508 s->st_gid = strtol (hdrp->gid, (char **) NULL, 10);
1509 s->st_mode = strtol (hdrp->mode, (char **) NULL, 8);
1510 s->st_size = arch_eltdata (abfd)->parsed_size;
1516 /* Normalize a file name for inclusion in an archive. */
1519 normalize_filename (abfd)
1523 const char *filename;
1525 file = bfd_get_filename (abfd);
1526 filename = strrchr (file, '/');
1527 if (filename != NULL)
1534 /* Write out an XCOFF armap. */
1538 xcoff_write_armap_old (abfd, elength, map, orl_count, stridx)
1540 unsigned int elength ATTRIBUTE_UNUSED;
1542 unsigned int orl_count;
1545 struct xcoff_ar_hdr hdr;
1547 unsigned char buf[4];
1552 memset (&hdr, 0, sizeof hdr);
1553 sprintf (hdr.size, "%ld", (long) (4 + orl_count * 4 + stridx));
1554 sprintf (hdr.nextoff, "%d", 0);
1555 memcpy (hdr.prevoff, xcoff_ardata (abfd)->memoff, XCOFFARMAG_ELEMENT_SIZE);
1556 sprintf (hdr.date, "%d", 0);
1557 sprintf (hdr.uid, "%d", 0);
1558 sprintf (hdr.gid, "%d", 0);
1559 sprintf (hdr.mode, "%d", 0);
1560 sprintf (hdr.namlen, "%d", 0);
1562 /* We need spaces, not null bytes, in the header. */
1563 for (p = (char *) &hdr; p < (char *) &hdr + SIZEOF_AR_HDR; p++)
1567 if (bfd_bwrite ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
1569 || (bfd_bwrite (XCOFFARFMAG, (bfd_size_type) SXCOFFARFMAG, abfd)
1573 H_PUT_32 (abfd, orl_count, buf);
1574 if (bfd_bwrite (buf, (bfd_size_type) 4, abfd) != 4)
1577 sub = abfd->archive_head;
1578 fileoff = SIZEOF_AR_FILE_HDR;
1580 while (sub != NULL && i < orl_count)
1584 while (map[i].u.abfd == sub)
1586 H_PUT_32 (abfd, fileoff, buf);
1587 if (bfd_bwrite (buf, (bfd_size_type) 4, abfd) != 4)
1591 namlen = strlen (normalize_filename (sub));
1592 namlen = (namlen + 1) &~ (size_t) 1;
1593 fileoff += (SIZEOF_AR_HDR
1596 + arelt_size (sub));
1597 fileoff = (fileoff + 1) &~ 1;
1601 for (i = 0; i < orl_count; i++)
1606 name = *map[i].name;
1607 namlen = strlen (name);
1608 if (bfd_bwrite (name, (bfd_size_type) (namlen + 1), abfd) != namlen + 1)
1612 if ((stridx & 1) != 0)
1617 if (bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
1624 static char buff20[XCOFFARMAGBIG_ELEMENT_SIZE + 1];
1625 #define FMT20 "%-20lld"
1626 #define FMT12 "%-12d"
1627 #define FMT12_OCTAL "%-12o"
1629 #define PRINT20(d, v) \
1630 sprintf (buff20, FMT20, (long long)(v)), \
1631 memcpy ((void *) (d), buff20, 20)
1633 #define PRINT12(d, v) \
1634 sprintf (buff20, FMT12, (int)(v)), \
1635 memcpy ((void *) (d), buff20, 12)
1637 #define PRINT12_OCTAL(d, v) \
1638 sprintf (buff20, FMT12_OCTAL, (unsigned int)(v)), \
1639 memcpy ((void *) (d), buff20, 12)
1641 #define PRINT4(d, v) \
1642 sprintf (buff20, FMT4, (int)(v)), \
1643 memcpy ((void *) (d), buff20, 4)
1645 #define READ20(d, v) \
1647 memcpy (buff20, (d), 20), \
1648 (v) = bfd_scan_vma (buff20, (const char **) NULL, 10)
1651 do_pad (abfd, number)
1653 unsigned int number;
1657 /* Limit pad to <= 4096. */
1662 if (bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
1669 do_copy (out_bfd, in_bfd)
1673 bfd_size_type remaining;
1674 bfd_byte buffer[DEFAULT_BUFFERSIZE];
1676 if (bfd_seek (in_bfd, (file_ptr) 0, SEEK_SET) != 0)
1679 remaining = arelt_size (in_bfd);
1681 while (remaining >= DEFAULT_BUFFERSIZE)
1683 if (bfd_bread (buffer, DEFAULT_BUFFERSIZE, in_bfd) != DEFAULT_BUFFERSIZE
1684 || bfd_bwrite (buffer, DEFAULT_BUFFERSIZE, out_bfd) != DEFAULT_BUFFERSIZE)
1687 remaining -= DEFAULT_BUFFERSIZE;
1692 if (bfd_bread (buffer, remaining, in_bfd) != remaining
1693 || bfd_bwrite (buffer, remaining, out_bfd) != remaining)
1701 do_shared_object_padding (out_bfd, in_bfd, offset, ar_header_size)
1707 if (bfd_check_format (in_bfd, bfd_object)
1708 && bfd_get_flavour (in_bfd) == bfd_target_xcoff_flavour
1709 && (in_bfd->flags & DYNAMIC) != 0)
1711 bfd_size_type pad = 0;
1712 int text_align_power;
1714 text_align_power = bfd_xcoff_text_align_power (in_bfd);
1715 BFD_ASSERT (2 < text_align_power);
1717 pad = 1 << text_align_power;
1718 pad -= (*offset + ar_header_size) & (pad - 1);
1720 if (! do_pad (out_bfd, pad))
1730 xcoff_write_armap_big (abfd, elength, map, orl_count, stridx)
1732 unsigned int elength ATTRIBUTE_UNUSED;
1734 unsigned int orl_count;
1737 struct xcoff_ar_file_hdr_big *fhdr;
1738 bfd_vma i, sym_32, sym_64, str_32, str_64;
1739 const bfd_arch_info_type *arch_info = NULL;
1741 size_t string_length;
1742 ufile_ptr nextoff, prevoff;
1744 /* First, we look through the symbols and work out which are
1745 from 32-bit objects and which from 64-bit ones. */
1746 sym_32 = sym_64 = str_32 = str_64 = 0;
1748 current_bfd = abfd->archive_head;
1749 if (current_bfd != NULL)
1750 arch_info = bfd_get_arch_info (current_bfd);
1752 while (current_bfd != NULL && i < orl_count)
1754 while (map[i].u.abfd == current_bfd)
1756 string_length = strlen (*map[i].name) + 1;
1758 if (arch_info->bits_per_address == 64)
1761 str_64 += string_length;
1766 str_32 += string_length;
1770 current_bfd = current_bfd->next;
1771 if (current_bfd != NULL)
1772 arch_info = bfd_get_arch_info (current_bfd);
1775 /* A quick sanity check... */
1776 BFD_ASSERT (sym_64 + sym_32 == orl_count);
1777 /* Explicit cast to int for compiler. */
1778 BFD_ASSERT ((int)(str_64 + str_32) == stridx);
1780 fhdr = xcoff_ardata_big (abfd);
1782 /* xcoff_write_archive_contents_big passes nextoff in symoff. */
1783 READ20 (fhdr->memoff, prevoff);
1784 READ20 (fhdr->symoff, nextoff);
1786 BFD_ASSERT (nextoff == bfd_tell (abfd));
1788 /* Write out the symbol table.
1791 standard big archive header
1792 0x0000 ar_size [0x14]
1793 0x0014 ar_nxtmem [0x14]
1794 0x0028 ar_prvmem [0x14]
1795 0x003C ar_date [0x0C]
1796 0x0048 ar_uid [0x0C]
1797 0x0054 ar_gid [0x0C]
1798 0x0060 ar_mod [0x0C]
1799 0x006C ar_namelen[0x04]
1800 0x0070 ar_fmag [SXCOFFARFMAG]
1803 0x0072 num_syms [0x08], binary
1804 0x0078 offsets [0x08 * num_syms], binary
1805 0x0086 + 0x08 * num_syms names [??]
1806 ?? pad to even bytes.
1811 struct xcoff_ar_hdr_big *hdr;
1812 bfd_byte *symbol_table;
1816 bfd_vma symbol_table_size =
1821 + str_32 + (str_32 & 1);
1823 symbol_table = NULL;
1824 symbol_table = (bfd_byte *) bfd_malloc (symbol_table_size);
1825 if (symbol_table == NULL)
1827 memset (symbol_table, 0, symbol_table_size);
1829 hdr = (struct xcoff_ar_hdr_big *) symbol_table;
1831 PRINT20 (hdr->size, 8 + 8 * sym_32 + str_32 + (str_32 & 1));
1834 PRINT20 (hdr->nextoff, nextoff + symbol_table_size);
1836 PRINT20 (hdr->nextoff, 0);
1838 PRINT20 (hdr->prevoff, prevoff);
1839 PRINT12 (hdr->date, 0);
1840 PRINT12 (hdr->uid, 0);
1841 PRINT12 (hdr->gid, 0);
1842 PRINT12 (hdr->mode, 0);
1843 PRINT4 (hdr->namlen, 0) ;
1845 st = symbol_table + SIZEOF_AR_HDR_BIG;
1846 memcpy (st, XCOFFARFMAG, SXCOFFARFMAG);
1849 bfd_h_put_64 (abfd, sym_32, st);
1852 /* loop over the 32 bit offsets */
1853 current_bfd = abfd->archive_head;
1854 if (current_bfd != NULL)
1855 arch_info = bfd_get_arch_info (current_bfd);
1856 fileoff = SIZEOF_AR_FILE_HDR_BIG;
1858 while (current_bfd != NULL && i < orl_count)
1860 while (map[i].u.abfd == current_bfd)
1862 if (arch_info->bits_per_address == 32)
1864 bfd_h_put_64 (abfd, fileoff, st);
1869 string_length = strlen (normalize_filename (current_bfd));
1870 string_length += string_length & 1;
1871 fileoff += (SIZEOF_AR_HDR_BIG
1874 + arelt_size (current_bfd));
1875 fileoff += fileoff & 1;
1876 current_bfd = current_bfd->next;
1877 if (current_bfd != NULL)
1878 arch_info = bfd_get_arch_info (current_bfd);
1881 /* loop over the 32 bit symbol names */
1882 current_bfd = abfd->archive_head;
1883 if (current_bfd != NULL)
1884 arch_info = bfd_get_arch_info (current_bfd);
1886 while (current_bfd != NULL && i < orl_count)
1888 while (map[i].u.abfd == current_bfd)
1890 if (arch_info->bits_per_address == 32)
1892 string_length = sprintf (st, "%s", *map[i].name);
1893 st += string_length + 1;
1897 current_bfd = current_bfd->next;
1898 if (current_bfd != NULL)
1899 arch_info = bfd_get_arch_info (current_bfd);
1902 bfd_bwrite (symbol_table, symbol_table_size, abfd);
1904 free (symbol_table);
1905 symbol_table = NULL;
1908 nextoff = nextoff + symbol_table_size;
1911 PRINT20 (fhdr->symoff, 0);
1915 struct xcoff_ar_hdr_big *hdr;
1916 bfd_byte *symbol_table;
1920 bfd_vma symbol_table_size =
1925 + str_64 + (str_64 & 1);
1927 symbol_table = NULL;
1928 symbol_table = (bfd_byte *) bfd_malloc (symbol_table_size);
1929 if (symbol_table == NULL)
1931 memset (symbol_table, 0, symbol_table_size);
1933 hdr = (struct xcoff_ar_hdr_big *) symbol_table;
1935 PRINT20 (hdr->size, 8 + 8 * sym_64 + str_64 + (str_64 & 1));
1936 PRINT20 (hdr->nextoff, 0);
1937 PRINT20 (hdr->prevoff, prevoff);
1938 PRINT12 (hdr->date, 0);
1939 PRINT12 (hdr->uid, 0);
1940 PRINT12 (hdr->gid, 0);
1941 PRINT12 (hdr->mode, 0);
1942 PRINT4 (hdr->namlen, 0);
1944 st = symbol_table + SIZEOF_AR_HDR_BIG;
1945 memcpy (st, XCOFFARFMAG, SXCOFFARFMAG);
1948 bfd_h_put_64 (abfd, sym_64, st);
1951 /* loop over the 64 bit offsets */
1952 current_bfd = abfd->archive_head;
1953 if (current_bfd != NULL)
1954 arch_info = bfd_get_arch_info (current_bfd);
1955 fileoff = SIZEOF_AR_FILE_HDR_BIG;
1957 while (current_bfd != NULL && i < orl_count)
1959 while (map[i].u.abfd == current_bfd)
1961 if (arch_info->bits_per_address == 64)
1963 bfd_h_put_64 (abfd, fileoff, st);
1968 string_length = strlen (normalize_filename (current_bfd));
1969 string_length += string_length & 1;
1970 fileoff += (SIZEOF_AR_HDR_BIG
1973 + arelt_size (current_bfd));
1974 fileoff += fileoff & 1;
1975 current_bfd = current_bfd->next;
1976 if (current_bfd != NULL)
1977 arch_info = bfd_get_arch_info (current_bfd);
1980 /* loop over the 64 bit symbol names */
1981 current_bfd = abfd->archive_head;
1982 if (current_bfd != NULL)
1983 arch_info = bfd_get_arch_info (current_bfd);
1985 while (current_bfd != NULL && i < orl_count)
1987 while (map[i].u.abfd == current_bfd)
1989 if (arch_info->bits_per_address == 64)
1991 string_length = sprintf (st, "%s", *map[i].name);
1992 st += string_length + 1;
1996 current_bfd = current_bfd->next;
1997 if (current_bfd != NULL)
1998 arch_info = bfd_get_arch_info (current_bfd);
2001 bfd_bwrite (symbol_table, symbol_table_size, abfd);
2003 free (symbol_table);
2004 symbol_table = NULL;
2006 PRINT20 (fhdr->symoff64, nextoff);
2009 PRINT20 (fhdr->symoff64, 0);
2015 _bfd_xcoff_write_armap (abfd, elength, map, orl_count, stridx)
2017 unsigned int elength ATTRIBUTE_UNUSED;
2019 unsigned int orl_count;
2022 if (! xcoff_big_format_p (abfd))
2023 return xcoff_write_armap_old (abfd, elength, map, orl_count, stridx);
2025 return xcoff_write_armap_big (abfd, elength, map, orl_count, stridx);
2028 /* Write out an XCOFF archive. We always write an entire archive,
2029 rather than fussing with the freelist and so forth. */
2032 xcoff_write_archive_contents_old (abfd)
2035 struct xcoff_ar_file_hdr fhdr;
2036 bfd_size_type count;
2037 bfd_size_type total_namlen;
2041 ufile_ptr prevoff, nextoff;
2044 struct xcoff_ar_hdr ahdr;
2047 char decbuf[XCOFFARMAG_ELEMENT_SIZE + 1];
2049 memset (&fhdr, 0, sizeof fhdr);
2050 strncpy (fhdr.magic, XCOFFARMAG, SXCOFFARMAG);
2051 sprintf (fhdr.firstmemoff, "%d", SIZEOF_AR_FILE_HDR);
2052 sprintf (fhdr.freeoff, "%d", 0);
2056 for (sub = abfd->archive_head; sub != NULL; sub = sub->next)
2059 total_namlen += strlen (normalize_filename (sub)) + 1;
2061 offsets = (file_ptr *) bfd_alloc (abfd, count * sizeof (file_ptr));
2062 if (offsets == NULL)
2065 if (bfd_seek (abfd, (file_ptr) SIZEOF_AR_FILE_HDR, SEEK_SET) != 0)
2068 makemap = bfd_has_map (abfd);
2071 nextoff = SIZEOF_AR_FILE_HDR;
2072 for (sub = abfd->archive_head, i = 0; sub != NULL; sub = sub->next, i++)
2075 bfd_size_type namlen;
2076 struct xcoff_ar_hdr *ahdrp;
2077 bfd_size_type remaining;
2079 if (makemap && ! hasobjects)
2081 if (bfd_check_format (sub, bfd_object))
2085 name = normalize_filename (sub);
2086 namlen = strlen (name);
2088 if (sub->arelt_data != NULL)
2089 ahdrp = arch_xhdr (sub);
2097 memset (&ahdr, 0, sizeof ahdr);
2099 if (stat (bfd_get_filename (sub), &s) != 0)
2101 bfd_set_error (bfd_error_system_call);
2105 sprintf (ahdrp->size, "%ld", (long) s.st_size);
2106 sprintf (ahdrp->date, "%ld", (long) s.st_mtime);
2107 sprintf (ahdrp->uid, "%ld", (long) s.st_uid);
2108 sprintf (ahdrp->gid, "%ld", (long) s.st_gid);
2109 sprintf (ahdrp->mode, "%o", (unsigned int) s.st_mode);
2111 if (sub->arelt_data == NULL)
2113 size = sizeof (struct areltdata);
2114 sub->arelt_data = bfd_alloc (sub, size);
2115 if (sub->arelt_data == NULL)
2119 arch_eltdata (sub)->parsed_size = s.st_size;
2122 sprintf (ahdrp->prevoff, "%ld", (long) prevoff);
2123 sprintf (ahdrp->namlen, "%ld", (long) namlen);
2125 /* If the length of the name is odd, we write out the null byte
2126 after the name as well. */
2127 namlen = (namlen + 1) &~ (bfd_size_type) 1;
2129 remaining = arelt_size (sub);
2130 size = (SIZEOF_AR_HDR
2135 BFD_ASSERT (nextoff == bfd_tell (abfd));
2137 offsets[i] = nextoff;
2140 nextoff += size + (size & 1);
2142 sprintf (ahdrp->nextoff, "%ld", (long) nextoff);
2144 /* We need spaces, not null bytes, in the header. */
2145 for (p = (char *) ahdrp; p < (char *) ahdrp + SIZEOF_AR_HDR; p++)
2149 if ((bfd_bwrite ((PTR) ahdrp, (bfd_size_type) SIZEOF_AR_HDR, abfd)
2151 || (bfd_bwrite ((PTR) name, namlen, abfd) != namlen)
2152 || (bfd_bwrite ((PTR) XCOFFARFMAG, (bfd_size_type) SXCOFFARFMAG, abfd)
2156 if (bfd_seek (sub, (file_ptr) 0, SEEK_SET) != 0)
2159 if (! do_copy (abfd, sub))
2162 if (! do_pad (abfd, size & 1))
2166 sprintf (fhdr.lastmemoff, "%ld", (long) prevoff);
2168 /* Write out the member table. */
2170 BFD_ASSERT (nextoff == bfd_tell (abfd));
2171 sprintf (fhdr.memoff, "%ld", (long) nextoff);
2173 memset (&ahdr, 0, sizeof ahdr);
2174 sprintf (ahdr.size, "%ld", (long) (XCOFFARMAG_ELEMENT_SIZE +
2175 count * XCOFFARMAG_ELEMENT_SIZE +
2177 sprintf (ahdr.prevoff, "%ld", (long) prevoff);
2178 sprintf (ahdr.date, "%d", 0);
2179 sprintf (ahdr.uid, "%d", 0);
2180 sprintf (ahdr.gid, "%d", 0);
2181 sprintf (ahdr.mode, "%d", 0);
2182 sprintf (ahdr.namlen, "%d", 0);
2184 size = (SIZEOF_AR_HDR
2185 + XCOFFARMAG_ELEMENT_SIZE
2186 + count * XCOFFARMAG_ELEMENT_SIZE
2191 nextoff += size + (size & 1);
2193 if (makemap && hasobjects)
2194 sprintf (ahdr.nextoff, "%ld", (long) nextoff);
2196 sprintf (ahdr.nextoff, "%d", 0);
2198 /* We need spaces, not null bytes, in the header. */
2199 for (p = (char *) &ahdr; p < (char *) &ahdr + SIZEOF_AR_HDR; p++)
2203 if ((bfd_bwrite ((PTR) &ahdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
2205 || (bfd_bwrite ((PTR) XCOFFARFMAG, (bfd_size_type) SXCOFFARFMAG, abfd)
2209 sprintf (decbuf, "%-12ld", (long) count);
2210 if (bfd_bwrite ((PTR) decbuf, (bfd_size_type) XCOFFARMAG_ELEMENT_SIZE, abfd)
2211 != XCOFFARMAG_ELEMENT_SIZE)
2213 for (i = 0; i < (size_t) count; i++)
2215 sprintf (decbuf, "%-12ld", (long) offsets[i]);
2216 if (bfd_bwrite ((PTR) decbuf, (bfd_size_type) XCOFFARMAG_ELEMENT_SIZE,
2217 abfd) != XCOFFARMAG_ELEMENT_SIZE)
2220 for (sub = abfd->archive_head; sub != NULL; sub = sub->next)
2223 bfd_size_type namlen;
2225 name = normalize_filename (sub);
2226 namlen = strlen (name);
2227 if (bfd_bwrite ((PTR) name, namlen + 1, abfd) != namlen + 1)
2231 if (! do_pad (abfd, size & 1))
2234 /* Write out the armap, if appropriate. */
2235 if (! makemap || ! hasobjects)
2236 sprintf (fhdr.symoff, "%d", 0);
2239 BFD_ASSERT (nextoff == bfd_tell (abfd));
2240 sprintf (fhdr.symoff, "%ld", (long) nextoff);
2241 bfd_ardata (abfd)->tdata = (PTR) &fhdr;
2242 if (! _bfd_compute_and_write_armap (abfd, 0))
2246 /* Write out the archive file header. */
2248 /* We need spaces, not null bytes, in the header. */
2249 for (p = (char *) &fhdr; p < (char *) &fhdr + SIZEOF_AR_FILE_HDR; p++)
2253 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
2254 || (bfd_bwrite ((PTR) &fhdr, (bfd_size_type) SIZEOF_AR_FILE_HDR, abfd)
2255 != SIZEOF_AR_FILE_HDR))
2262 xcoff_write_archive_contents_big (abfd)
2265 struct xcoff_ar_file_hdr_big fhdr;
2266 bfd_size_type count;
2267 bfd_size_type total_namlen;
2271 ufile_ptr prevoff, nextoff;
2274 struct xcoff_ar_hdr_big *hdr, ahdr;
2276 bfd_byte *member_table, *mt;
2277 bfd_vma member_table_size;
2279 memset (&fhdr, 0, SIZEOF_AR_FILE_HDR_BIG);
2280 memcpy (fhdr.magic, XCOFFARMAGBIG, SXCOFFARMAG);
2282 if (bfd_seek (abfd, (file_ptr) SIZEOF_AR_FILE_HDR_BIG, SEEK_SET) != 0)
2285 /* Calculate count and total_namlen. */
2286 makemap = bfd_has_map (abfd);
2288 for (current_bfd = abfd->archive_head, count = 0, total_namlen = 0;
2289 current_bfd != NULL;
2290 current_bfd = current_bfd->next, count++)
2292 total_namlen += strlen (normalize_filename (current_bfd)) + 1;
2296 && bfd_check_format (current_bfd, bfd_object))
2303 offsets = (file_ptr *) bfd_malloc (count * sizeof (file_ptr));
2304 if (offsets == NULL)
2309 nextoff = SIZEOF_AR_FILE_HDR_BIG;
2310 for (current_bfd = abfd->archive_head, i = 0;
2311 current_bfd != NULL;
2312 current_bfd = current_bfd->next, i++)
2315 bfd_size_type namlen;
2316 struct xcoff_ar_hdr_big *ahdrp;
2317 bfd_size_type remaining;
2319 name = normalize_filename (current_bfd);
2320 namlen = strlen (name);
2322 if (current_bfd->arelt_data != NULL)
2323 ahdrp = arch_xhdr_big (current_bfd);
2332 /* XXX This should actually be a call to stat64 (at least on
2334 XXX This call will fail if the original object is not found. */
2335 if (stat (bfd_get_filename (current_bfd), &s) != 0)
2337 bfd_set_error (bfd_error_system_call);
2341 PRINT20 (ahdrp->size, s.st_size);
2342 PRINT12 (ahdrp->date, s.st_mtime);
2343 PRINT12 (ahdrp->uid, s.st_uid);
2344 PRINT12 (ahdrp->gid, s.st_gid);
2345 PRINT12_OCTAL (ahdrp->mode, s.st_mode);
2347 if (current_bfd->arelt_data == NULL)
2349 size = sizeof (struct areltdata);
2350 current_bfd->arelt_data = bfd_alloc (current_bfd, size);
2351 if (current_bfd->arelt_data == NULL)
2355 arch_eltdata (current_bfd)->parsed_size = s.st_size;
2358 PRINT20 (ahdrp->prevoff, prevoff);
2359 PRINT4 (ahdrp->namlen, namlen);
2361 /* If the length of the name is odd, we write out the null byte
2362 after the name as well. */
2363 namlen = (namlen + 1) &~ (bfd_size_type) 1;
2365 remaining = arelt_size (current_bfd);
2366 size = (SIZEOF_AR_HDR_BIG
2371 BFD_ASSERT (nextoff == bfd_tell (abfd));
2373 /* Check for xcoff shared objects.
2374 Their text section needs to be aligned wrt the archive file position.
2375 This requires extra padding before the archive header. */
2376 if (! do_shared_object_padding (abfd, current_bfd, & nextoff,
2377 SIZEOF_AR_HDR_BIG + namlen
2381 offsets[i] = nextoff;
2384 nextoff += size + (size & 1);
2386 PRINT20 (ahdrp->nextoff, nextoff);
2388 if ((bfd_bwrite ((PTR) ahdrp, (bfd_size_type) SIZEOF_AR_HDR_BIG, abfd)
2389 != SIZEOF_AR_HDR_BIG)
2390 || bfd_bwrite ((PTR) name, (bfd_size_type) namlen, abfd) != namlen
2391 || (bfd_bwrite ((PTR) XCOFFARFMAG, (bfd_size_type) SXCOFFARFMAG,
2392 abfd) != SXCOFFARFMAG))
2395 if (bfd_seek (current_bfd, (file_ptr) 0, SEEK_SET) != 0)
2398 if (! do_copy (abfd, current_bfd))
2401 if (! do_pad (abfd, size & 1))
2407 PRINT20 (fhdr.firstmemoff, offsets[0]);
2408 PRINT20 (fhdr.lastmemoff, prevoff);
2411 /* Write out the member table.
2414 standard big archive header
2415 0x0000 ar_size [0x14]
2416 0x0014 ar_nxtmem [0x14]
2417 0x0028 ar_prvmem [0x14]
2418 0x003C ar_date [0x0C]
2419 0x0048 ar_uid [0x0C]
2420 0x0054 ar_gid [0x0C]
2421 0x0060 ar_mod [0x0C]
2422 0x006C ar_namelen[0x04]
2423 0x0070 ar_fmag [0x02]
2427 0x0086 offsets [0x14 * counts]
2428 0x0086 + 0x14 * counts names [??]
2429 ?? pad to even bytes.
2432 BFD_ASSERT (nextoff == bfd_tell (abfd));
2434 member_table_size = (SIZEOF_AR_HDR_BIG
2436 + XCOFFARMAGBIG_ELEMENT_SIZE
2437 + count * XCOFFARMAGBIG_ELEMENT_SIZE
2440 member_table_size += member_table_size & 1;
2441 member_table = NULL;
2442 member_table = (bfd_byte *) bfd_malloc (member_table_size);
2443 if (member_table == NULL)
2445 memset (member_table, 0, member_table_size);
2447 hdr = (struct xcoff_ar_hdr_big *) member_table;
2449 PRINT20 (hdr->size, (XCOFFARMAGBIG_ELEMENT_SIZE +
2450 count * XCOFFARMAGBIG_ELEMENT_SIZE +
2451 total_namlen + (total_namlen & 1)));
2452 if (makemap && hasobjects)
2453 PRINT20 (hdr->nextoff, nextoff + member_table_size);
2455 PRINT20 (hdr->nextoff, 0);
2456 PRINT20 (hdr->prevoff, prevoff);
2457 PRINT12 (hdr->date, 0);
2458 PRINT12 (hdr->uid, 0);
2459 PRINT12 (hdr->gid, 0);
2460 PRINT12 (hdr->mode, 0);
2461 PRINT4 (hdr->namlen, 0);
2463 mt = member_table + SIZEOF_AR_HDR_BIG;
2464 memcpy (mt, XCOFFARFMAG, SXCOFFARFMAG);
2467 PRINT20 (mt, count);
2468 mt += XCOFFARMAGBIG_ELEMENT_SIZE;
2469 for (i = 0; i < (size_t) count; i++)
2471 PRINT20 (mt, offsets[i]);
2472 mt += XCOFFARMAGBIG_ELEMENT_SIZE;
2481 for (current_bfd = abfd->archive_head; current_bfd != NULL;
2482 current_bfd = current_bfd->next)
2487 name = normalize_filename (current_bfd);
2488 namlen = sprintf(mt, "%s", name);
2492 if (bfd_bwrite (member_table, member_table_size, abfd) != member_table_size)
2495 free (member_table);
2496 member_table = NULL;
2498 PRINT20 (fhdr.memoff, nextoff);
2501 nextoff += member_table_size;
2503 /* Write out the armap, if appropriate. */
2505 if (! makemap || ! hasobjects)
2506 PRINT20 (fhdr.symoff, 0);
2509 BFD_ASSERT (nextoff == bfd_tell (abfd));
2511 /* Save nextoff in fhdr.symoff so the armap routine can use it. */
2512 PRINT20 (fhdr.symoff, nextoff);
2514 bfd_ardata (abfd)->tdata = (PTR) &fhdr;
2515 if (! _bfd_compute_and_write_armap (abfd, 0))
2519 /* Write out the archive file header. */
2521 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
2522 || (bfd_bwrite ((PTR) &fhdr, (bfd_size_type) SIZEOF_AR_FILE_HDR_BIG,
2523 abfd) != SIZEOF_AR_FILE_HDR_BIG))
2530 _bfd_xcoff_write_archive_contents (abfd)
2533 if (! xcoff_big_format_p (abfd))
2534 return xcoff_write_archive_contents_old (abfd);
2536 return xcoff_write_archive_contents_big (abfd);
2539 /* We can't use the usual coff_sizeof_headers routine, because AIX
2540 always uses an a.out header. */
2543 _bfd_xcoff_sizeof_headers (abfd, reloc)
2545 boolean reloc ATTRIBUTE_UNUSED;
2550 if (xcoff_data (abfd)->full_aouthdr)
2553 size += SMALL_AOUTSZ;
2554 size += abfd->section_count * SCNHSZ;
2558 /* Routines to swap information in the XCOFF .loader section. If we
2559 ever need to write an XCOFF loader, this stuff will need to be
2560 moved to another file shared by the linker (which XCOFF calls the
2561 ``binder'') and the loader. */
2563 /* Swap in the ldhdr structure. */
2566 xcoff_swap_ldhdr_in (abfd, s, dst)
2569 struct internal_ldhdr *dst;
2571 const struct external_ldhdr *src = (const struct external_ldhdr *) s;
2573 dst->l_version = bfd_get_32 (abfd, src->l_version);
2574 dst->l_nsyms = bfd_get_32 (abfd, src->l_nsyms);
2575 dst->l_nreloc = bfd_get_32 (abfd, src->l_nreloc);
2576 dst->l_istlen = bfd_get_32 (abfd, src->l_istlen);
2577 dst->l_nimpid = bfd_get_32 (abfd, src->l_nimpid);
2578 dst->l_impoff = bfd_get_32 (abfd, src->l_impoff);
2579 dst->l_stlen = bfd_get_32 (abfd, src->l_stlen);
2580 dst->l_stoff = bfd_get_32 (abfd, src->l_stoff);
2583 /* Swap out the ldhdr structure. */
2586 xcoff_swap_ldhdr_out (abfd, src, d)
2588 const struct internal_ldhdr *src;
2591 struct external_ldhdr *dst = (struct external_ldhdr *) d;
2593 bfd_put_32 (abfd, (bfd_vma) src->l_version, dst->l_version);
2594 bfd_put_32 (abfd, src->l_nsyms, dst->l_nsyms);
2595 bfd_put_32 (abfd, src->l_nreloc, dst->l_nreloc);
2596 bfd_put_32 (abfd, src->l_istlen, dst->l_istlen);
2597 bfd_put_32 (abfd, src->l_nimpid, dst->l_nimpid);
2598 bfd_put_32 (abfd, src->l_impoff, dst->l_impoff);
2599 bfd_put_32 (abfd, src->l_stlen, dst->l_stlen);
2600 bfd_put_32 (abfd, src->l_stoff, dst->l_stoff);
2603 /* Swap in the ldsym structure. */
2606 xcoff_swap_ldsym_in (abfd, s, dst)
2609 struct internal_ldsym *dst;
2611 const struct external_ldsym *src = (const struct external_ldsym *) s;
2613 if (bfd_get_32 (abfd, src->_l._l_l._l_zeroes) != 0) {
2614 memcpy (dst->_l._l_name, src->_l._l_name, SYMNMLEN);
2616 dst->_l._l_l._l_zeroes = 0;
2617 dst->_l._l_l._l_offset = bfd_get_32 (abfd, src->_l._l_l._l_offset);
2619 dst->l_value = bfd_get_32 (abfd, src->l_value);
2620 dst->l_scnum = bfd_get_16 (abfd, src->l_scnum);
2621 dst->l_smtype = bfd_get_8 (abfd, src->l_smtype);
2622 dst->l_smclas = bfd_get_8 (abfd, src->l_smclas);
2623 dst->l_ifile = bfd_get_32 (abfd, src->l_ifile);
2624 dst->l_parm = bfd_get_32 (abfd, src->l_parm);
2627 /* Swap out the ldsym structure. */
2630 xcoff_swap_ldsym_out (abfd, src, d)
2632 const struct internal_ldsym *src;
2635 struct external_ldsym *dst = (struct external_ldsym *) d;
2637 if (src->_l._l_l._l_zeroes != 0)
2638 memcpy (dst->_l._l_name, src->_l._l_name, SYMNMLEN);
2641 bfd_put_32 (abfd, (bfd_vma) 0, dst->_l._l_l._l_zeroes);
2642 bfd_put_32 (abfd, (bfd_vma) src->_l._l_l._l_offset,
2643 dst->_l._l_l._l_offset);
2645 bfd_put_32 (abfd, src->l_value, dst->l_value);
2646 bfd_put_16 (abfd, (bfd_vma) src->l_scnum, dst->l_scnum);
2647 bfd_put_8 (abfd, src->l_smtype, dst->l_smtype);
2648 bfd_put_8 (abfd, src->l_smclas, dst->l_smclas);
2649 bfd_put_32 (abfd, src->l_ifile, dst->l_ifile);
2650 bfd_put_32 (abfd, src->l_parm, dst->l_parm);
2653 /* Swap in the ldrel structure. */
2656 xcoff_swap_ldrel_in (abfd, s, dst)
2659 struct internal_ldrel *dst;
2661 const struct external_ldrel *src = (const struct external_ldrel *) s;
2663 dst->l_vaddr = bfd_get_32 (abfd, src->l_vaddr);
2664 dst->l_symndx = bfd_get_32 (abfd, src->l_symndx);
2665 dst->l_rtype = bfd_get_16 (abfd, src->l_rtype);
2666 dst->l_rsecnm = bfd_get_16 (abfd, src->l_rsecnm);
2669 /* Swap out the ldrel structure. */
2672 xcoff_swap_ldrel_out (abfd, src, d)
2674 const struct internal_ldrel *src;
2677 struct external_ldrel *dst = (struct external_ldrel *) d;
2679 bfd_put_32 (abfd, src->l_vaddr, dst->l_vaddr);
2680 bfd_put_32 (abfd, src->l_symndx, dst->l_symndx);
2681 bfd_put_16 (abfd, (bfd_vma) src->l_rtype, dst->l_rtype);
2682 bfd_put_16 (abfd, (bfd_vma) src->l_rsecnm, dst->l_rsecnm);
2687 xcoff_reloc_type_noop (input_bfd, input_section, output_bfd, rel, sym, howto,
2688 val, addend, relocation, contents)
2689 bfd *input_bfd ATTRIBUTE_UNUSED;
2690 asection *input_section ATTRIBUTE_UNUSED;
2691 bfd *output_bfd ATTRIBUTE_UNUSED;
2692 struct internal_reloc *rel ATTRIBUTE_UNUSED;
2693 struct internal_syment *sym ATTRIBUTE_UNUSED;
2694 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
2695 bfd_vma val ATTRIBUTE_UNUSED;
2696 bfd_vma addend ATTRIBUTE_UNUSED;
2697 bfd_vma *relocation ATTRIBUTE_UNUSED;
2698 bfd_byte *contents ATTRIBUTE_UNUSED;
2704 xcoff_reloc_type_fail (input_bfd, input_section, output_bfd, rel, sym, howto,
2705 val, addend, relocation, contents)
2707 asection *input_section ATTRIBUTE_UNUSED;
2708 bfd *output_bfd ATTRIBUTE_UNUSED;
2709 struct internal_reloc *rel;
2710 struct internal_syment *sym ATTRIBUTE_UNUSED;
2711 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
2712 bfd_vma val ATTRIBUTE_UNUSED;
2713 bfd_vma addend ATTRIBUTE_UNUSED;
2714 bfd_vma *relocation ATTRIBUTE_UNUSED;
2715 bfd_byte *contents ATTRIBUTE_UNUSED;
2717 (*_bfd_error_handler)
2718 (_("%s: unsupported relocation type 0x%02x"),
2719 bfd_get_filename (input_bfd), (unsigned int) rel->r_type);
2720 bfd_set_error (bfd_error_bad_value);
2725 xcoff_reloc_type_pos (input_bfd, input_section, output_bfd, rel, sym, howto,
2726 val, addend, relocation, contents)
2727 bfd *input_bfd ATTRIBUTE_UNUSED;
2728 asection *input_section ATTRIBUTE_UNUSED;
2729 bfd *output_bfd ATTRIBUTE_UNUSED;
2730 struct internal_reloc *rel ATTRIBUTE_UNUSED;
2731 struct internal_syment *sym ATTRIBUTE_UNUSED;
2732 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
2735 bfd_vma *relocation;
2736 bfd_byte *contents ATTRIBUTE_UNUSED;
2738 *relocation = val + addend;
2743 xcoff_reloc_type_neg (input_bfd, input_section, output_bfd, rel, sym, howto,
2744 val, addend, relocation, contents)
2745 bfd *input_bfd ATTRIBUTE_UNUSED;
2746 asection *input_section ATTRIBUTE_UNUSED;
2747 bfd *output_bfd ATTRIBUTE_UNUSED;
2748 struct internal_reloc *rel ATTRIBUTE_UNUSED;
2749 struct internal_syment *sym ATTRIBUTE_UNUSED;
2750 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
2753 bfd_vma *relocation;
2754 bfd_byte *contents ATTRIBUTE_UNUSED;
2756 *relocation = addend - val;
2761 xcoff_reloc_type_rel (input_bfd, input_section, output_bfd, rel, sym, howto,
2762 val, addend, relocation, contents)
2763 bfd *input_bfd ATTRIBUTE_UNUSED;
2764 asection *input_section;
2765 bfd *output_bfd ATTRIBUTE_UNUSED;
2766 struct internal_reloc *rel ATTRIBUTE_UNUSED;
2767 struct internal_syment *sym ATTRIBUTE_UNUSED;
2768 struct reloc_howto_struct *howto;
2771 bfd_vma *relocation;
2772 bfd_byte *contents ATTRIBUTE_UNUSED;
2774 howto->pc_relative = true;
2776 /* A PC relative reloc includes the section address. */
2777 addend += input_section->vma;
2779 *relocation = val + addend;
2780 *relocation -= (input_section->output_section->vma +
2781 input_section->output_offset);
2785 xcoff_reloc_type_toc (input_bfd, input_section, output_bfd, rel, sym, howto,
2786 val, addend, relocation, contents)
2788 asection *input_section ATTRIBUTE_UNUSED;
2790 struct internal_reloc *rel;
2791 struct internal_syment *sym;
2792 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
2794 bfd_vma addend ATTRIBUTE_UNUSED;
2795 bfd_vma *relocation;
2796 bfd_byte *contents ATTRIBUTE_UNUSED;
2798 struct xcoff_link_hash_entry *h;
2800 if (0 > rel->r_symndx)
2803 h = obj_xcoff_sym_hashes (input_bfd)[rel->r_symndx];
2805 if (h != NULL && h->smclas != XMC_TD)
2807 if (h->toc_section == NULL)
2809 (*_bfd_error_handler)
2810 (_("%s: TOC reloc at 0x%x to symbol `%s' with no TOC entry"),
2811 bfd_get_filename (input_bfd), rel->r_vaddr,
2812 h->root.root.string);
2813 bfd_set_error (bfd_error_bad_value);
2817 BFD_ASSERT ((h->flags & XCOFF_SET_TOC) == 0);
2818 val = (h->toc_section->output_section->vma
2819 + h->toc_section->output_offset);
2822 *relocation = ((val - xcoff_data (output_bfd)->toc) -
2823 (sym->n_value - xcoff_data (input_bfd)->toc));
2827 xcoff_reloc_type_ba (input_bfd, input_section, output_bfd, rel, sym, howto,
2828 val, addend, relocation, contents)
2829 bfd *input_bfd ATTRIBUTE_UNUSED;
2830 asection *input_section ATTRIBUTE_UNUSED;
2831 bfd *output_bfd ATTRIBUTE_UNUSED;
2832 struct internal_reloc *rel ATTRIBUTE_UNUSED;
2833 struct internal_syment *sym ATTRIBUTE_UNUSED;
2834 struct reloc_howto_struct *howto;
2837 bfd_vma *relocation;
2838 bfd_byte *contents ATTRIBUTE_UNUSED;
2840 howto->src_mask &= ~3;
2841 howto->dst_mask = howto->src_mask;
2843 *relocation = val + addend;
2849 xcoff_reloc_type_br (input_bfd, input_section, output_bfd, rel, sym, howto,
2850 val, addend, relocation, contents)
2852 asection *input_section;
2853 bfd *output_bfd ATTRIBUTE_UNUSED;
2854 struct internal_reloc *rel;
2855 struct internal_syment *sym ATTRIBUTE_UNUSED;
2856 struct reloc_howto_struct *howto;
2859 bfd_vma *relocation;
2862 struct xcoff_link_hash_entry *h;
2864 if (0 > rel->r_symndx)
2867 h = obj_xcoff_sym_hashes (input_bfd)[rel->r_symndx];
2869 /* If we see an R_BR or R_RBR reloc which is jumping to global
2870 linkage code, and it is followed by an appropriate cror nop
2871 instruction, we replace the cror with lwz r2,20(r1). This
2872 restores the TOC after the glink code. Contrariwise, if the
2873 call is followed by a lwz r2,20(r1), but the call is not
2874 going to global linkage code, we can replace the load with a
2877 && bfd_link_hash_defined == h->root.type
2878 && (rel->r_vaddr - input_section->vma + 8 <=
2879 input_section->_cooked_size))
2884 pnext = contents + (rel->r_vaddr - input_section->vma) + 4;
2885 next = bfd_get_32 (input_bfd, pnext);
2887 /* The _ptrgl function is magic. It is used by the AIX
2888 compiler to call a function through a pointer. */
2889 if (h->smclas == XMC_GL || strcmp (h->root.root.string, "._ptrgl") == 0)
2891 if (next == 0x4def7b82 /* cror 15,15,15 */
2892 || next == 0x4ffffb82 /* cror 31,31,31 */
2893 || next == 0x60000000) /* ori r0,r0,0 */
2894 bfd_put_32 (input_bfd, 0x80410014, pnext); /* lwz r1,20(r1) */
2898 if (next == 0x80410014) /* lwz r1,20(r1) */
2899 bfd_put_32 (input_bfd, 0x60000000, pnext); /* ori r0,r0,0 */
2902 else if (NULL != h && bfd_link_hash_undefined == h->root.type)
2904 /* Normally, this relocation is against a defined symbol. In the
2905 case where this is a partial link and the output section offset
2906 is greater than 2^25, the linker will return an invalid error
2907 message that the relocation has been truncated. Yes it has been
2908 truncated but no it not important. For this case, disable the
2909 overflow checking. */
2911 howto->complain_on_overflow = complain_overflow_dont;
2914 howto->pc_relative = true;
2915 howto->src_mask &= ~3;
2916 howto->dst_mask = howto->src_mask;
2918 /* A PC relative reloc includes the section address. */
2919 addend += input_section->vma;
2921 *relocation = val + addend;
2922 *relocation -= (input_section->output_section->vma +
2923 input_section->output_offset);
2928 xcoff_reloc_type_crel (input_bfd, input_section, output_bfd, rel, sym, howto,
2929 val, addend, relocation, contents)
2930 bfd *input_bfd ATTRIBUTE_UNUSED;
2931 asection *input_section;
2932 bfd *output_bfd ATTRIBUTE_UNUSED;
2933 struct internal_reloc *rel ATTRIBUTE_UNUSED;
2934 struct internal_syment *sym ATTRIBUTE_UNUSED;
2935 struct reloc_howto_struct *howto;
2936 bfd_vma val ATTRIBUTE_UNUSED;
2938 bfd_vma *relocation;
2939 bfd_byte *contents ATTRIBUTE_UNUSED;
2941 howto->pc_relative = true;
2942 howto->src_mask &= ~3;
2943 howto->dst_mask = howto->src_mask;
2945 /* A PC relative reloc includes the section address. */
2946 addend += input_section->vma;
2948 *relocation = val + addend;
2949 *relocation -= (input_section->output_section->vma +
2950 input_section->output_offset);
2955 xcoff_complain_overflow_dont_func (input_bfd, val, relocation, howto)
2956 bfd *input_bfd ATTRIBUTE_UNUSED;
2957 bfd_vma val ATTRIBUTE_UNUSED;
2958 bfd_vma relocation ATTRIBUTE_UNUSED;
2959 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED;
2965 xcoff_complain_overflow_bitfield_func (input_bfd, val, relocation, howto)
2969 struct reloc_howto_struct *howto;
2971 bfd_vma addrmask, fieldmask, signmask, ss;
2974 /* Get the values to be added together. For signed and unsigned
2975 relocations, we assume that all values should be truncated to
2976 the size of an address. For bitfields, all the bits matter.
2977 See also bfd_check_overflow. */
2978 fieldmask = N_ONES (howto->bitsize);
2979 addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask;
2981 b = val & howto->src_mask;
2983 /* Much like unsigned, except no trimming with addrmask. In
2984 addition, the sum overflows if there is a carry out of
2985 the bfd_vma, i.e., the sum is less than either input
2987 a >>= howto->rightshift;
2988 b >>= howto->bitpos;
2990 /* Bitfields are sometimes used for signed numbers; for
2991 example, a 13-bit field sometimes represents values in
2992 0..8191 and sometimes represents values in -4096..4095.
2993 If the field is signed and a is -4095 (0x1001) and b is
2994 -1 (0x1fff), the sum is -4096 (0x1000), but (0x1001 +
2995 0x1fff is 0x3000). It's not clear how to handle this
2996 everywhere, since there is not way to know how many bits
2997 are significant in the relocation, but the original code
2998 assumed that it was fully sign extended, and we will keep
3000 signmask = (fieldmask >> 1) + 1;
3002 if ((a & ~ fieldmask) != 0)
3004 /* Some bits out of the field are set. This might not
3005 be a problem: if this is a signed bitfield, it is OK
3006 iff all the high bits are set, including the sign
3007 bit. We'll try setting all but the most significant
3008 bit in the original relocation value: if this is all
3009 ones, we are OK, assuming a signed bitfield. */
3010 ss = (signmask << howto->rightshift) - 1;
3011 if ((ss | relocation) != ~ (bfd_vma) 0)
3016 /* We just assume (b & ~ fieldmask) == 0. */
3018 /* We explicitly permit wrap around if this relocation
3019 covers the high bit of an address. The Linux kernel
3020 relies on it, and it is the only way to write assembler
3021 code which can run when loaded at a location 0x80000000
3022 away from the location at which it is linked. */
3023 if (howto->bitsize + howto->rightshift
3024 == bfd_arch_bits_per_address (input_bfd))
3028 if (sum < a || (sum & ~ fieldmask) != 0)
3030 /* There was a carry out, or the field overflow. Test
3031 for signed operands again. Here is the overflow test
3032 is as for complain_overflow_signed. */
3033 if (((~ (a ^ b)) & (a ^ sum)) & signmask)
3041 xcoff_complain_overflow_signed_func (input_bfd, val, relocation, howto)
3045 struct reloc_howto_struct *howto;
3047 bfd_vma addrmask, fieldmask, signmask, ss;
3050 /* Get the values to be added together. For signed and unsigned
3051 relocations, we assume that all values should be truncated to
3052 the size of an address. For bitfields, all the bits matter.
3053 See also bfd_check_overflow. */
3054 fieldmask = N_ONES (howto->bitsize);
3055 addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask;
3057 b = val & howto->src_mask;
3059 a = (a & addrmask) >> howto->rightshift;
3061 /* If any sign bits are set, all sign bits must be set.
3062 That is, A must be a valid negative address after
3064 signmask = ~ (fieldmask >> 1);
3066 if (ss != 0 && ss != ((addrmask >> howto->rightshift) & signmask))
3069 /* We only need this next bit of code if the sign bit of B
3070 is below the sign bit of A. This would only happen if
3071 SRC_MASK had fewer bits than BITSIZE. Note that if
3072 SRC_MASK has more bits than BITSIZE, we can get into
3073 trouble; we would need to verify that B is in range, as
3074 we do for A above. */
3075 signmask = ((~ howto->src_mask) >> 1) & howto->src_mask;
3076 if ((b & signmask) != 0)
3078 /* Set all the bits above the sign bit. */
3079 b -= signmask <<= 1;
3082 b = (b & addrmask) >> howto->bitpos;
3084 /* Now we can do the addition. */
3087 /* See if the result has the correct sign. Bits above the
3088 sign bit are junk now; ignore them. If the sum is
3089 positive, make sure we did not have all negative inputs;
3090 if the sum is negative, make sure we did not have all
3091 positive inputs. The test below looks only at the sign
3092 bits, and it really just
3093 SIGN (A) == SIGN (B) && SIGN (A) != SIGN (SUM)
3095 signmask = (fieldmask >> 1) + 1;
3096 if (((~ (a ^ b)) & (a ^ sum)) & signmask)
3103 xcoff_complain_overflow_unsigned_func (input_bfd, val, relocation, howto)
3107 struct reloc_howto_struct *howto;
3109 bfd_vma addrmask, fieldmask;
3112 /* Get the values to be added together. For signed and unsigned
3113 relocations, we assume that all values should be truncated to
3114 the size of an address. For bitfields, all the bits matter.
3115 See also bfd_check_overflow. */
3116 fieldmask = N_ONES (howto->bitsize);
3117 addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask;
3119 b = val & howto->src_mask;
3121 /* Checking for an unsigned overflow is relatively easy:
3122 trim the addresses and add, and trim the result as well.
3123 Overflow is normally indicated when the result does not
3124 fit in the field. However, we also need to consider the
3125 case when, e.g., fieldmask is 0x7fffffff or smaller, an
3126 input is 0x80000000, and bfd_vma is only 32 bits; then we
3127 will get sum == 0, but there is an overflow, since the
3128 inputs did not fit in the field. Instead of doing a
3129 separate test, we can check for this by or-ing in the
3130 operands when testing for the sum overflowing its final
3132 a = (a & addrmask) >> howto->rightshift;
3133 b = (b & addrmask) >> howto->bitpos;
3134 sum = (a + b) & addrmask;
3135 if ((a | b | sum) & ~ fieldmask)
3141 /* This is the relocation function for the RS/6000/POWER/PowerPC.
3142 This is currently the only processor which uses XCOFF; I hope that
3145 I took the relocation type definitions from two documents:
3146 the PowerPC AIX Version 4 Application Binary Interface, First
3147 Edition (April 1992), and the PowerOpen ABI, Big-Endian
3148 32-Bit Hardware Implementation (June 30, 1994). Differences
3149 between the documents are noted below.
3151 Unsupported r_type's
3157 These relocs are defined by the PowerPC ABI to be
3158 relative branches which use half of the difference
3159 between the symbol and the program counter. I can't
3160 quite figure out when this is useful. These relocs are
3161 not defined by the PowerOpen ABI.
3166 Simple positive relocation.
3169 Simple negative relocation.
3172 Simple PC relative relocation.
3175 TOC relative relocation. The value in the instruction in
3176 the input file is the offset from the input file TOC to
3177 the desired location. We want the offset from the final
3178 TOC to the desired location. We have:
3183 so we must change insn by on - in.
3186 GL linkage relocation. The value of this relocation
3187 is the address of the entry in the TOC section.
3190 Local object TOC address. I can't figure out the
3191 difference between this and case R_GL.
3194 TOC relative relocation. A TOC relative load instruction
3195 which may be changed to a load address instruction.
3196 FIXME: We don't currently implement this optimization.
3199 TOC relative relocation. This is a TOC relative load
3200 address instruction which may be changed to a load
3201 instruction. FIXME: I don't know if this is the correct
3205 Absolute branch. We don't want to mess with the lower
3206 two bits of the instruction.
3209 The PowerPC ABI defines this as an absolute call which
3210 may be modified to become a relative call. The PowerOpen
3211 ABI does not define this relocation type.
3214 Absolute branch which may be modified to become a
3218 The PowerPC ABI defines this as an absolute branch to a
3219 fixed address which may be modified to an absolute branch
3220 to a symbol. The PowerOpen ABI does not define this
3224 The PowerPC ABI defines this as an absolute branch to a
3225 fixed address which may be modified to a relative branch.
3226 The PowerOpen ABI does not define this relocation type.
3229 Relative branch. We don't want to mess with the lower
3230 two bits of the instruction.
3233 The PowerPC ABI defines this as a relative call which may
3234 be modified to become an absolute call. The PowerOpen
3235 ABI does not define this relocation type.
3238 A relative branch which may be modified to become an
3239 absolute branch. FIXME: We don't implement this,
3240 although we should for symbols of storage mapping class
3244 The PowerPC AIX ABI describes this as a load which may be
3245 changed to a load address. The PowerOpen ABI says this
3246 is the same as case R_POS.
3249 The PowerPC AIX ABI describes this as a load address
3250 which may be changed to a load. The PowerOpen ABI says
3251 this is the same as R_POS.
3255 xcoff_ppc_relocate_section (output_bfd, info, input_bfd,
3256 input_section, contents, relocs, syms,
3259 struct bfd_link_info *info;
3261 asection *input_section;
3263 struct internal_reloc *relocs;
3264 struct internal_syment *syms;
3265 asection **sections;
3267 struct internal_reloc *rel;
3268 struct internal_reloc *relend;
3271 relend = rel + input_section->reloc_count;
3272 for (; rel < relend; rel++)
3275 struct xcoff_link_hash_entry *h;
3276 struct internal_syment *sym;
3279 struct reloc_howto_struct howto;
3281 bfd_vma value_to_relocate;
3285 /* Relocation type R_REF is a special relocation type which is
3286 merely used to prevent garbage collection from occurring for
3287 the csect including the symbol which it references. */
3288 if (rel->r_type == R_REF)
3292 howto.type = rel->r_type;
3293 howto.rightshift = 0;
3294 howto.bitsize = (rel->r_size & 0x1f) + 1;
3295 howto.size = howto.bitsize > 16 ? 2 : 1;
3296 howto.pc_relative = false;
3298 howto.complain_on_overflow = rel->r_size & 0x80 ?
3299 complain_overflow_signed : complain_overflow_bitfield;
3300 howto.special_function = NULL;
3301 howto.name = "internal";
3302 howto.partial_inplace = true;
3303 howto.src_mask = howto.dst_mask = N_ONES(howto.bitsize);
3304 howto.pcrel_offset = false;
3311 symndx = rel->r_symndx;
3317 h = obj_xcoff_sym_hashes (input_bfd)[symndx];
3318 sym = syms + symndx;
3319 addend = - sym->n_value;
3323 sec = sections[symndx];
3324 /* Hack to make sure we use the right TOC anchor value
3325 if this reloc is against the TOC anchor. */
3326 if (sec->name[3] == '0'
3327 && strcmp (sec->name, ".tc0") == 0)
3328 val = xcoff_data (output_bfd)->toc;
3330 val = (sec->output_section->vma
3331 + sec->output_offset
3337 if (h->root.type == bfd_link_hash_defined
3338 || h->root.type == bfd_link_hash_defweak)
3340 sec = h->root.u.def.section;
3341 val = (h->root.u.def.value
3342 + sec->output_section->vma
3343 + sec->output_offset);
3345 else if (h->root.type == bfd_link_hash_common)
3347 sec = h->root.u.c.p->section;
3348 val = (sec->output_section->vma
3349 + sec->output_offset);
3352 else if ((0 == (h->flags & (XCOFF_DEF_DYNAMIC | XCOFF_IMPORT)))
3353 && ! info->relocateable)
3355 if (! ((*info->callbacks->undefined_symbol)
3356 (info, h->root.root.string, input_bfd, input_section,
3357 rel->r_vaddr - input_section->vma, true)))
3360 /* Don't try to process the reloc. It can't help, and
3361 it may generate another error. */
3367 if (rel->r_type >= XCOFF_MAX_CALCULATE_RELOCATION
3368 || (false == xcoff_calculate_relocation[rel->r_type]
3369 (input_bfd, input_section, output_bfd, rel, sym, &howto, val,
3370 addend, &relocation, contents)))
3374 address = rel->r_vaddr - input_section->vma;
3375 location = contents + address;
3377 if (address > input_section->_raw_size)
3380 /* Get the value we are going to relocate. */
3381 if (1 == howto.size)
3382 value_to_relocate = bfd_get_16 (input_bfd, location);
3384 value_to_relocate = bfd_get_32 (input_bfd, location);
3388 FIXME: We may drop bits during the addition
3389 which we don't check for. We must either check at every single
3390 operation, which would be tedious, or we must do the computations
3391 in a type larger than bfd_vma, which would be inefficient. */
3393 if ((unsigned int) howto.complain_on_overflow >=
3394 XCOFF_MAX_COMPLAIN_OVERFLOW)
3397 if ((true == xcoff_complain_overflow[howto.complain_on_overflow]
3398 (input_bfd, value_to_relocate, relocation, &howto)))
3401 char buf[SYMNMLEN + 1];
3402 char reloc_type_name[10];
3410 name = h->root.root.string;
3414 name = _bfd_coff_internal_syment_name (input_bfd, sym, buf);
3418 sprintf (reloc_type_name, "0x%02x", rel->r_type);
3420 if (! ((*info->callbacks->reloc_overflow)
3421 (info, name, reloc_type_name, (bfd_vma) 0, input_bfd,
3422 input_section, rel->r_vaddr - input_section->vma)))
3426 /* Add RELOCATION to the right bits of VALUE_TO_RELOCATE. */
3427 value_to_relocate = ((value_to_relocate & ~howto.dst_mask) |
3428 (((value_to_relocate & howto.src_mask) +
3429 relocation) & howto.dst_mask));
3431 /* Put the value back in the object file. */
3432 if (1 == howto.size)
3433 bfd_put_16 (input_bfd, value_to_relocate, location);
3435 bfd_put_32 (input_bfd, value_to_relocate, location);
3442 _bfd_xcoff_put_ldsymbol_name (abfd, ldinfo, ldsym, name)
3443 bfd *abfd ATTRIBUTE_UNUSED;
3444 struct xcoff_loader_info *ldinfo;
3445 struct internal_ldsym *ldsym;
3449 len = strlen (name);
3451 if (len <= SYMNMLEN)
3452 strncpy (ldsym->_l._l_name, name, SYMNMLEN);
3455 if (ldinfo->string_size + len + 3 > ldinfo->string_alc)
3457 bfd_size_type newalc;
3458 bfd_byte *newstrings;
3460 newalc = ldinfo->string_alc * 2;
3463 while (ldinfo->string_size + len + 3 > newalc)
3466 newstrings = ((bfd_byte *)
3467 bfd_realloc ((PTR) ldinfo->strings, newalc));
3468 if (newstrings == NULL)
3470 ldinfo->failed = true;
3473 ldinfo->string_alc = newalc;
3474 ldinfo->strings = newstrings;
3477 bfd_put_16 (ldinfo->output_bfd, (bfd_vma) (len + 1),
3478 ldinfo->strings + ldinfo->string_size);
3479 strcpy (ldinfo->strings + ldinfo->string_size + 2, name);
3480 ldsym->_l._l_l._l_zeroes = 0;
3481 ldsym->_l._l_l._l_offset = ldinfo->string_size + 2;
3482 ldinfo->string_size += len + 3;
3489 _bfd_xcoff_put_symbol_name (bfd *abfd, struct bfd_strtab_hash *strtab,
3490 struct internal_syment *sym,
3493 if (strlen (name) <= SYMNMLEN)
3495 strncpy (sym->_n._n_name, name, SYMNMLEN);
3503 if ((abfd->flags & BFD_TRADITIONAL_FORMAT) != 0)
3505 indx = _bfd_stringtab_add (strtab, name, hash, false);
3506 if (indx == (bfd_size_type) -1)
3508 sym->_n._n_n._n_zeroes = 0;
3509 sym->_n._n_n._n_offset = STRING_SIZE_SIZE + indx;
3515 xcoff_create_csect_from_smclas (abfd, aux, symbol_name)
3517 union internal_auxent *aux;
3518 const char *symbol_name;
3520 asection *return_value = NULL;
3522 /* .sv64 = x_smclas == 17
3523 This is an invalid csect for 32 bit apps. */
3524 static const char *names[19] =
3526 ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo",
3527 ".sv", ".bs", ".ds", ".uc", ".ti", ".tb", NULL, ".tc0",
3528 ".td", NULL, ".sv3264"
3531 if ((19 >= aux->x_csect.x_smclas) &&
3532 (NULL != names[aux->x_csect.x_smclas]))
3534 return_value = bfd_make_section_anyway
3535 (abfd, names[aux->x_csect.x_smclas]);
3539 (*_bfd_error_handler)
3540 (_("%s: symbol `%s' has unrecognized smclas %d"),
3541 bfd_archive_filename (abfd), symbol_name, aux->x_csect.x_smclas);
3542 bfd_set_error (bfd_error_bad_value);
3545 return return_value;
3549 xcoff_is_lineno_count_overflow (abfd, value)
3550 bfd *abfd ATTRIBUTE_UNUSED;
3553 if (0xffff <= value)
3560 xcoff_is_reloc_count_overflow (abfd, value)
3561 bfd *abfd ATTRIBUTE_UNUSED;
3564 if (0xffff <= value)
3571 xcoff_loader_symbol_offset (abfd, ldhdr)
3573 struct internal_ldhdr *ldhdr ATTRIBUTE_UNUSED;
3575 return bfd_xcoff_ldhdrsz(abfd);
3579 xcoff_loader_reloc_offset (abfd, ldhdr)
3581 struct internal_ldhdr *ldhdr;
3583 return bfd_xcoff_ldhdrsz(abfd) +
3584 (ldhdr->l_nsyms * bfd_xcoff_ldsymsz(abfd));
3588 xcoff_generate_rtinit (abfd, init, fini, rtld)
3594 bfd_byte filehdr_ext[FILHSZ];
3595 bfd_byte scnhdr_ext[SCNHSZ];
3596 bfd_byte syment_ext[SYMESZ * 10];
3597 bfd_byte reloc_ext[RELSZ * 3];
3598 bfd_byte *data_buffer;
3599 bfd_size_type data_buffer_size;
3600 bfd_byte *string_table = NULL, *st_tmp = NULL;
3601 bfd_size_type string_table_size;
3603 size_t initsz, finisz;
3604 struct internal_filehdr filehdr;
3605 struct internal_scnhdr scnhdr;
3606 struct internal_syment syment;
3607 union internal_auxent auxent;
3608 struct internal_reloc reloc;
3610 char *data_name = ".data";
3611 char *rtinit_name = "__rtinit";
3612 char *rtld_name = "__rtld";
3614 if (! bfd_xcoff_rtinit_size (abfd))
3617 initsz = (init == NULL ? 0 : 1 + strlen (init));
3618 finisz = (fini == NULL ? 0 : 1 + strlen (fini));
3621 memset (filehdr_ext, 0, FILHSZ);
3622 memset (&filehdr, 0, sizeof (struct internal_filehdr));
3623 filehdr.f_magic = bfd_xcoff_magic_number (abfd);
3624 filehdr.f_nscns = 1;
3625 filehdr.f_timdat = 0;
3626 filehdr.f_nsyms = 0; /* at least 6, no more than 10 */
3627 filehdr.f_symptr = 0; /* set below */
3628 filehdr.f_opthdr = 0;
3629 filehdr.f_flags = 0;
3631 /* section header */
3632 memset (scnhdr_ext, 0, SCNHSZ);
3633 memset (&scnhdr, 0, sizeof (struct internal_scnhdr));
3634 memcpy (scnhdr.s_name, data_name, strlen (data_name));
3637 scnhdr.s_size = 0; /* set below */
3638 scnhdr.s_scnptr = FILHSZ + SCNHSZ;
3639 scnhdr.s_relptr = 0; /* set below */
3640 scnhdr.s_lnnoptr = 0;
3641 scnhdr.s_nreloc = 0; /* either 1 or 2 */
3643 scnhdr.s_flags = STYP_DATA;
3646 0x0000 0x00000000 : rtl
3647 0x0004 0x00000010 : offset to init, or 0
3648 0x0008 0x00000028 : offset to fini, or 0
3649 0x000C 0x0000000C : size of descriptor
3650 0x0010 0x00000000 : init, needs a reloc
3651 0x0014 0x00000040 : offset to init name
3652 0x0018 0x00000000 : flags, padded to a word
3653 0x001C 0x00000000 : empty init
3656 0x0028 0x00000000 : fini, needs a reloc
3657 0x002C 0x00000??? : offset to fini name
3658 0x0030 0x00000000 : flags, padded to a word
3659 0x0034 0x00000000 : empty fini
3663 0x0040 + initsz fini name */
3665 data_buffer_size = 0x0040 + initsz + finisz;
3666 data_buffer_size += (data_buffer_size & 7) ? 8 - (data_buffer_size & 7) : 0;
3668 data_buffer = (bfd_byte *) bfd_malloc (data_buffer_size);
3669 if (data_buffer == NULL)
3672 memset (data_buffer, 0, data_buffer_size);
3677 bfd_h_put_32 (abfd, val, &data_buffer[0x04]);
3679 bfd_h_put_32 (abfd, val, &data_buffer[0x14]);
3680 memcpy (&data_buffer[val], init, initsz);
3686 bfd_h_put_32 (abfd, val, &data_buffer[0x08]);
3687 val = 0x40 + initsz;
3688 bfd_h_put_32 (abfd, val, &data_buffer[0x2C]);
3689 memcpy (&data_buffer[val], fini, finisz);
3693 bfd_h_put_32 (abfd, val, &data_buffer[0x0C]);
3695 scnhdr.s_size = data_buffer_size;
3698 string_table_size = 0;
3700 string_table_size += initsz;
3702 string_table_size += finisz;
3703 if (string_table_size)
3705 string_table_size += 4;
3706 string_table = (bfd_byte *)bfd_malloc (string_table_size);
3707 memset (string_table, 0, string_table_size);
3708 val = string_table_size;
3709 bfd_h_put_32 (abfd, val, &string_table[0]);
3710 st_tmp = string_table + 4;
3719 memset (syment_ext, 0, 10 * SYMESZ);
3720 memset (reloc_ext, 0, 3 * RELSZ);
3723 memset (&syment, 0, sizeof (struct internal_syment));
3724 memset (&auxent, 0, sizeof (union internal_auxent));
3725 memcpy (syment._n._n_name, data_name, strlen (data_name));
3727 syment.n_sclass = C_HIDEXT;
3728 syment.n_numaux = 1;
3729 auxent.x_csect.x_scnlen.l = data_buffer_size;
3730 auxent.x_csect.x_smtyp = 3 << 3 | XTY_SD;
3731 auxent.x_csect.x_smclas = XMC_RW;
3732 bfd_coff_swap_sym_out (abfd, &syment,
3733 &syment_ext[filehdr.f_nsyms * SYMESZ]);
3734 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
3736 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
3737 filehdr.f_nsyms += 2;
3740 memset (&syment, 0, sizeof (struct internal_syment));
3741 memset (&auxent, 0, sizeof (union internal_auxent));
3742 memcpy (syment._n._n_name, rtinit_name, strlen (rtinit_name));
3744 syment.n_sclass = C_EXT;
3745 syment.n_numaux = 1;
3746 auxent.x_csect.x_smtyp = XTY_LD;
3747 auxent.x_csect.x_smclas = XMC_RW;
3748 bfd_coff_swap_sym_out (abfd, &syment,
3749 &syment_ext[filehdr.f_nsyms * SYMESZ]);
3750 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
3752 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
3753 filehdr.f_nsyms += 2;
3758 memset (&syment, 0, sizeof (struct internal_syment));
3759 memset (&auxent, 0, sizeof (union internal_auxent));
3763 syment._n._n_n._n_offset = st_tmp - string_table;
3764 memcpy (st_tmp, init, initsz);
3768 memcpy (syment._n._n_name, init, initsz - 1);
3770 syment.n_sclass = C_EXT;
3771 syment.n_numaux = 1;
3772 bfd_coff_swap_sym_out (abfd, &syment,
3773 &syment_ext[filehdr.f_nsyms * SYMESZ]);
3774 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
3776 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
3779 memset (&reloc, 0, sizeof (struct internal_reloc));
3780 reloc.r_vaddr = 0x0010;
3781 reloc.r_symndx = filehdr.f_nsyms;
3782 reloc.r_type = R_POS;
3784 bfd_coff_swap_reloc_out (abfd, &reloc, &reloc_ext[0]);
3786 filehdr.f_nsyms += 2;
3787 scnhdr.s_nreloc += 1;
3793 memset (&syment, 0, sizeof (struct internal_syment));
3794 memset (&auxent, 0, sizeof (union internal_auxent));
3798 syment._n._n_n._n_offset = st_tmp - string_table;
3799 memcpy (st_tmp, fini, finisz);
3803 memcpy (syment._n._n_name, fini, finisz - 1);
3805 syment.n_sclass = C_EXT;
3806 syment.n_numaux = 1;
3807 bfd_coff_swap_sym_out (abfd, &syment,
3808 &syment_ext[filehdr.f_nsyms * SYMESZ]);
3809 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
3811 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
3814 memset (&reloc, 0, sizeof (struct internal_reloc));
3815 reloc.r_vaddr = 0x0028;
3816 reloc.r_symndx = filehdr.f_nsyms;
3817 reloc.r_type = R_POS;
3819 bfd_coff_swap_reloc_out (abfd, &reloc,
3820 &reloc_ext[scnhdr.s_nreloc * RELSZ]);
3822 filehdr.f_nsyms += 2;
3823 scnhdr.s_nreloc += 1;
3828 memset (&syment, 0, sizeof (struct internal_syment));
3829 memset (&auxent, 0, sizeof (union internal_auxent));
3830 memcpy (syment._n._n_name, rtld_name, strlen (rtld_name));
3831 syment.n_sclass = C_EXT;
3832 syment.n_numaux = 1;
3833 bfd_coff_swap_sym_out (abfd, &syment,
3834 &syment_ext[filehdr.f_nsyms * SYMESZ]);
3835 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
3837 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
3840 memset (&reloc, 0, sizeof (struct internal_reloc));
3841 reloc.r_vaddr = 0x0000;
3842 reloc.r_symndx = filehdr.f_nsyms;
3843 reloc.r_type = R_POS;
3845 bfd_coff_swap_reloc_out (abfd, &reloc,
3846 &reloc_ext[scnhdr.s_nreloc * RELSZ]);
3848 filehdr.f_nsyms += 2;
3849 scnhdr.s_nreloc += 1;
3852 scnhdr.s_relptr = scnhdr.s_scnptr + data_buffer_size;
3853 filehdr.f_symptr = scnhdr.s_relptr + scnhdr.s_nreloc * RELSZ;
3855 bfd_coff_swap_filehdr_out (abfd, &filehdr, filehdr_ext);
3856 bfd_bwrite (filehdr_ext, FILHSZ, abfd);
3857 bfd_coff_swap_scnhdr_out (abfd, &scnhdr, scnhdr_ext);
3858 bfd_bwrite (scnhdr_ext, SCNHSZ, abfd);
3859 bfd_bwrite (data_buffer, data_buffer_size, abfd);
3860 bfd_bwrite (reloc_ext, scnhdr.s_nreloc * RELSZ, abfd);
3861 bfd_bwrite (syment_ext, filehdr.f_nsyms * SYMESZ, abfd);
3862 bfd_bwrite (string_table, string_table_size, abfd);
3871 static reloc_howto_type xcoff_dynamic_reloc =
3872 HOWTO (0, /* type */
3874 2, /* size (0 = byte, 1 = short, 2 = long) */
3876 false, /* pc_relative */
3878 complain_overflow_bitfield, /* complain_on_overflow */
3879 0, /* special_function */
3881 true, /* partial_inplace */
3882 0xffffffff, /* src_mask */
3883 0xffffffff, /* dst_mask */
3884 false); /* pcrel_offset */
3888 The first word of global linkage code must be modified by filling in
3889 the correct TOC offset. */
3891 static unsigned long xcoff_glink_code[9] =
3893 0x81820000, /* lwz r12,0(r2) */
3894 0x90410014, /* stw r2,20(r1) */
3895 0x800c0000, /* lwz r0,0(r12) */
3896 0x804c0004, /* lwz r2,4(r12) */
3897 0x7c0903a6, /* mtctr r0 */
3898 0x4e800420, /* bctr */
3899 0x00000000, /* start of traceback table */
3900 0x000c8000, /* traceback table */
3901 0x00000000, /* traceback table */
3905 static const struct xcoff_backend_data_rec bfd_xcoff_backend_data =
3907 { /* COFF backend, defined in libcoff.h. */
3908 _bfd_xcoff_swap_aux_in, /* _bfd_coff_swap_aux_in */
3909 _bfd_xcoff_swap_sym_in, /* _bfd_coff_swap_sym_in */
3910 coff_swap_lineno_in, /* _bfd_coff_swap_lineno_in */
3911 _bfd_xcoff_swap_aux_out, /* _bfd_swap_aux_out */
3912 _bfd_xcoff_swap_sym_out, /* _bfd_swap_sym_out */
3913 coff_swap_lineno_out, /* _bfd_swap_lineno_out */
3914 coff_swap_reloc_out, /* _bfd_swap_reloc_out */
3915 coff_swap_filehdr_out, /* _bfd_swap_filehdr_out */
3916 coff_swap_aouthdr_out, /* _bfd_swap_aouthdr_out */
3917 coff_swap_scnhdr_out, /* _bfd_swap_scnhdr_out */
3918 FILHSZ, /* _bfd_filhsz */
3919 AOUTSZ, /* _bfd_aoutsz */
3920 SCNHSZ, /* _bfd_scnhsz */
3921 SYMESZ, /* _bfd_symesz */
3922 AUXESZ, /* _bfd_auxesz */
3923 RELSZ, /* _bfd_relsz */
3924 LINESZ, /* _bfd_linesz */
3925 FILNMLEN, /* _bfd_filnmlen */
3926 true, /* _bfd_coff_long_filenames */
3927 false, /* _bfd_coff_long_section_names */
3928 (3), /* _bfd_coff_default_section_alignment_power */
3929 false, /* _bfd_coff_force_symnames_in_strings */
3930 2, /* _bfd_coff_debug_string_prefix_length */
3931 coff_swap_filehdr_in, /* _bfd_coff_swap_filehdr_in */
3932 coff_swap_aouthdr_in, /* _bfd_swap_aouthdr_in */
3933 coff_swap_scnhdr_in, /* _bfd_swap_scnhdr_in */
3934 coff_swap_reloc_in, /* _bfd_reloc_in */
3935 coff_bad_format_hook, /* _bfd_bad_format_hook */
3936 coff_set_arch_mach_hook, /* _bfd_set_arch_mach_hook */
3937 coff_mkobject_hook, /* _bfd_mkobject_hook */
3938 styp_to_sec_flags, /* _bfd_syp_to_sec_flags */
3939 coff_set_alignment_hook, /* _bfd_set_alignment_hook */
3940 coff_slurp_symbol_table, /* _bfd_coff_slurp_symbol_table */
3941 symname_in_debug_hook, /* _coff_symname_in_debug_hook */
3942 coff_pointerize_aux_hook, /* _bfd_coff_pointerize_aux_hook */
3943 coff_print_aux, /* bfd_coff_print_aux */
3944 dummy_reloc16_extra_cases, /* _bfd_coff_reloc16_extra_cases */
3945 dummy_reloc16_estimate, /* _bfd_coff_reloc16_estimate */
3946 NULL, /* bfd_coff_sym_is_global */
3947 coff_compute_section_file_positions, /* _bfd_coff_compute_section_file_positions */
3948 NULL, /* _bfd_coff_start_final_link */
3949 xcoff_ppc_relocate_section, /* _bfd_coff_relocate_section */
3950 coff_rtype_to_howto, /* _bfd_coff_rtype_to_howto */
3951 NULL, /* _bfd_coff_addust_symndx */
3952 _bfd_generic_link_add_one_symbol, /* _bfd_coff_add_one_symbol */
3953 coff_link_output_has_begun, /* _bfd_coff_link_output_has_begun */
3954 coff_final_link_postscript /* _bfd_coff_final_link_postscript */
3957 0x01DF, /* magic number */
3958 bfd_arch_rs6000, /* architecture */
3959 bfd_mach_rs6k, /* machine */
3961 /* Function pointers to xcoff specific swap routines. */
3962 xcoff_swap_ldhdr_in, /* _xcoff_swap_ldhdr_in */
3963 xcoff_swap_ldhdr_out, /* _xcoff_swap_ldhdr_out */
3964 xcoff_swap_ldsym_in, /* _xcoff_swap_ldsym_in */
3965 xcoff_swap_ldsym_out, /* _xcoff_swap_ldsym_out */
3966 xcoff_swap_ldrel_in, /* _xcoff_swap_ldrel_in */
3967 xcoff_swap_ldrel_out, /* _xcoff_swap_ldrel_out */
3970 LDHDRSZ, /* _xcoff_ldhdrsz */
3971 LDSYMSZ, /* _xcoff_ldsymsz */
3972 LDRELSZ, /* _xcoff_ldrelsz */
3973 12, /* _xcoff_function_descriptor_size */
3974 SMALL_AOUTSZ, /* _xcoff_small_aout_header_size */
3977 1, /* _xcoff_ldhdr_version */
3979 _bfd_xcoff_put_symbol_name, /* _xcoff_put_symbol_name */
3980 _bfd_xcoff_put_ldsymbol_name, /* _xcoff_put_ldsymbol_name */
3981 & xcoff_dynamic_reloc, /* dynamic reloc howto */
3982 xcoff_create_csect_from_smclas, /* _xcoff_create_csect_from_smclas */
3984 /* Lineno and reloc count overflow. */
3985 xcoff_is_lineno_count_overflow,
3986 xcoff_is_reloc_count_overflow,
3988 xcoff_loader_symbol_offset,
3989 xcoff_loader_reloc_offset,
3992 & xcoff_glink_code[0],
3993 (36), /* _xcoff_glink_size */
3996 64, /* _xcoff_rtinit_size */
3997 xcoff_generate_rtinit, /* _xcoff_generate_rtinit */
4000 /* The transfer vector that leads the outside world to all of the above. */
4001 const bfd_target rs6000coff_vec =
4004 bfd_target_xcoff_flavour,
4005 BFD_ENDIAN_BIG, /* data byte order is big */
4006 BFD_ENDIAN_BIG, /* header byte order is big */
4008 (HAS_RELOC | EXEC_P | /* object flags */
4009 HAS_LINENO | HAS_DEBUG | DYNAMIC |
4010 HAS_SYMS | HAS_LOCALS | WP_TEXT),
4012 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
4013 0, /* leading char */
4014 '/', /* ar_pad_char */
4015 15, /* ar_max_namelen??? FIXMEmgo */
4018 bfd_getb64, /* bfd_getx64 */
4019 bfd_getb_signed_64, /* bfd_getx_signed_64 */
4020 bfd_putb64, /* bfd_putx64 */
4021 bfd_getb32, /* bfd_getx32 */
4022 bfd_getb_signed_32, /* bfd_getx_signed_32 */
4023 bfd_putb32, /* bfd_putx32 */
4024 bfd_getb16, /* bfd_getx16 */
4025 bfd_getb_signed_16, /* bfd_getx_signed_16 */
4026 bfd_putb16, /* bfd_putx16 */
4029 bfd_getb64, /* bfd_h_getx64 */
4030 bfd_getb_signed_64, /* bfd_h_getx_signed_64 */
4031 bfd_putb64, /* bfd_h_putx64 */
4032 bfd_getb32, /* bfd_h_getx32 */
4033 bfd_getb_signed_32, /* bfd_h_getx_signed_32 */
4034 bfd_putb32, /* bfd_h_putx32 */
4035 bfd_getb16, /* bfd_h_getx16 */
4036 bfd_getb_signed_16, /* bfd_h_getx_signed_16 */
4037 bfd_putb16, /* bfd_h_putx16 */
4039 { /* bfd_check_format */
4042 _bfd_xcoff_archive_p,
4046 { /* bfd_set_format */
4049 _bfd_generic_mkarchive,
4053 {/* bfd_write_contents */
4055 coff_write_object_contents,
4056 _bfd_xcoff_write_archive_contents,
4061 bfd_true, /* _close_and_cleanup */
4062 bfd_true, /* _bfd_free_cached_info */
4063 coff_new_section_hook, /* _new_section_hook */
4064 _bfd_generic_get_section_contents, /* _bfd_get_section_contents */
4065 /* _bfd_get_section_contents_in_window */
4066 _bfd_generic_get_section_contents_in_window,
4069 _bfd_xcoff_copy_private_bfd_data, /* _bfd_copy_private_bfd */
4070 /* _bfd_merge_private_bfd_data */
4071 ((boolean (*) (bfd *, bfd *)) bfd_true),
4072 /* _bfd_copy_pivate_section_data */
4073 ((boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true),
4074 /* _bfd_copy_private_symbol_data */
4075 ((boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true),
4076 ((boolean (*) (bfd *, flagword)) bfd_true), /* _bfd_set_private_flags */
4077 ((boolean (*) (bfd *, void * )) bfd_true), /* _bfd_print_private_bfd_data */
4080 coff_core_file_failing_command, /* _core_file_failing_command */
4081 coff_core_file_failing_signal, /* _core_file_failing_signal */
4082 /* _core_file_matches_executable_p */
4083 coff_core_file_matches_executable_p,
4086 _bfd_xcoff_slurp_armap, /* _slurp_armap */
4087 /* XCOFF archives do not have
4088 anything which corresponds to
4089 an extended name table. */
4090 bfd_false, /* _slurp_extended_name_table */
4091 /* _construct_extended_name_table */
4092 ((boolean (*) (bfd *, char **, bfd_size_type *, const char **)) bfd_false),
4093 bfd_dont_truncate_arname, /* _truncate_arname */
4094 _bfd_xcoff_write_armap, /* _write_armap */
4095 _bfd_xcoff_read_ar_hdr, /* _read_ar_hdr */
4096 _bfd_xcoff_openr_next_archived_file, /* _openr_next_archived_file */
4097 _bfd_generic_get_elt_at_index, /* _get_elt_at_index */
4098 _bfd_xcoff_stat_arch_elt, /* _generic_stat_arch_elt */
4099 /* XCOFF archives do not have
4101 bfd_true, /* _update_armap_timestamp */
4104 coff_get_symtab_upper_bound, /* _get_symtab_upper_bound */
4105 coff_get_symtab, /* _get_symtab */
4106 coff_make_empty_symbol, /* _make_empty_symbol */
4107 coff_print_symbol, /* _print_symbol */
4108 coff_get_symbol_info, /* _get_symbol_info */
4109 _bfd_xcoff_is_local_label_name, /* _bfd_is_local_label_name */
4110 coff_get_lineno, /* _get_lineno */
4111 coff_find_nearest_line, /* _find_nearest_line */
4112 coff_bfd_make_debug_symbol, /* _bfd_make_debug_symbol */
4113 _bfd_generic_read_minisymbols, /* _read_minisymbols */
4114 _bfd_generic_minisymbol_to_symbol, /* _minsymbol_to_symbol */
4117 coff_get_reloc_upper_bound, /* _get_reloc_upper_bound */
4118 coff_canonicalize_reloc, /* _cononicalize_reloc */
4119 _bfd_xcoff_reloc_type_lookup, /* _bfd_reloc_type_lookup */
4122 coff_set_arch_mach, /* _set_arch_mach */
4123 coff_set_section_contents, /* _set_section_contents */
4126 _bfd_xcoff_sizeof_headers, /* _sizeof_headers */
4127 /* _bfd_get_relocated_section_contents */
4128 bfd_generic_get_relocated_section_contents,
4129 bfd_generic_relax_section, /* _bfd_relax_section */
4130 _bfd_xcoff_bfd_link_hash_table_create, /* _bfd_link_hash_table_create */
4131 _bfd_generic_link_hash_table_free, /* _bfd_link_hash_table_free */
4132 _bfd_xcoff_bfd_link_add_symbols, /* _bfd_link_add_symbols */
4133 _bfd_xcoff_bfd_final_link, /* _bfd_filnal_link */
4134 _bfd_generic_link_split_section, /* _bfd_link_split_section */
4135 bfd_generic_gc_sections, /* _bfd_gc_sections */
4136 bfd_generic_merge_sections, /* _bfd_merge_sections */
4139 /* _get_dynamic_symtab_upper_bound */
4140 _bfd_xcoff_get_dynamic_symtab_upper_bound,
4141 _bfd_xcoff_canonicalize_dynamic_symtab, /* _cononicalize_dynamic_symtab */
4142 _bfd_xcoff_get_dynamic_reloc_upper_bound,/* _get_dynamic_reloc_upper_bound */
4143 _bfd_xcoff_canonicalize_dynamic_reloc, /* _cononicalize_dynamic_reloc */
4145 /* Opposite endian version, none exists */
4149 (void *) &bfd_xcoff_backend_data,
4153 * xcoff-powermac target
4155 * Only difference between this target and the rs6000 target is the
4156 * the default architecture and machine type used in coffcode.h
4158 * PowerPC Macs use the same magic numbers as RS/6000
4159 * (because that's how they were bootstrapped originally),
4160 * but they are always PowerPC architecture.
4162 static const struct xcoff_backend_data_rec bfd_pmac_xcoff_backend_data =
4164 { /* COFF backend, defined in libcoff.h */
4165 _bfd_xcoff_swap_aux_in, /* _bfd_coff_swap_aux_in */
4166 _bfd_xcoff_swap_sym_in, /* _bfd_coff_swap_sym_in */
4167 coff_swap_lineno_in, /* _bfd_coff_swap_lineno_in */
4168 _bfd_xcoff_swap_aux_out, /* _bfd_swap_aux_out */
4169 _bfd_xcoff_swap_sym_out, /* _bfd_swap_sym_out */
4170 coff_swap_lineno_out, /* _bfd_swap_lineno_out */
4171 coff_swap_reloc_out, /* _bfd_swap_reloc_out */
4172 coff_swap_filehdr_out, /* _bfd_swap_filehdr_out */
4173 coff_swap_aouthdr_out, /* _bfd_swap_aouthdr_out */
4174 coff_swap_scnhdr_out, /* _bfd_swap_scnhdr_out */
4175 FILHSZ, /* _bfd_filhsz */
4176 AOUTSZ, /* _bfd_aoutsz */
4177 SCNHSZ, /* _bfd_scnhsz */
4178 SYMESZ, /* _bfd_symesz */
4179 AUXESZ, /* _bfd_auxesz */
4180 RELSZ, /* _bfd_relsz */
4181 LINESZ, /* _bfd_linesz */
4182 FILNMLEN, /* _bfd_filnmlen */
4183 true, /* _bfd_coff_long_filenames */
4184 false, /* _bfd_coff_long_section_names */
4185 (3), /* _bfd_coff_default_section_alignment_power */
4186 false, /* _bfd_coff_force_symnames_in_strings */
4187 2, /* _bfd_coff_debug_string_prefix_length */
4188 coff_swap_filehdr_in, /* _bfd_coff_swap_filehdr_in */
4189 coff_swap_aouthdr_in, /* _bfd_swap_aouthdr_in */
4190 coff_swap_scnhdr_in, /* _bfd_swap_scnhdr_in */
4191 coff_swap_reloc_in, /* _bfd_reloc_in */
4192 coff_bad_format_hook, /* _bfd_bad_format_hook */
4193 coff_set_arch_mach_hook, /* _bfd_set_arch_mach_hook */
4194 coff_mkobject_hook, /* _bfd_mkobject_hook */
4195 styp_to_sec_flags, /* _bfd_syp_to_sec_flags */
4196 coff_set_alignment_hook, /* _bfd_set_alignment_hook */
4197 coff_slurp_symbol_table, /* _bfd_coff_slurp_symbol_table */
4198 symname_in_debug_hook, /* _coff_symname_in_debug_hook */
4199 coff_pointerize_aux_hook, /* _bfd_coff_pointerize_aux_hook */
4200 coff_print_aux, /* bfd_coff_print_aux */
4201 dummy_reloc16_extra_cases, /* _bfd_coff_reloc16_extra_cases */
4202 dummy_reloc16_estimate, /* _bfd_coff_reloc16_estimate */
4203 NULL, /* bfd_coff_sym_is_global */
4204 /* _bfd_coff_compute_section_file_positions */
4205 coff_compute_section_file_positions,
4206 NULL, /* _bfd_coff_start_final_link */
4207 xcoff_ppc_relocate_section, /* _bfd_coff_relocate_section */
4208 coff_rtype_to_howto, /* _bfd_coff_rtype_to_howto */
4209 NULL, /* _bfd_coff_addust_symndx */
4210 _bfd_generic_link_add_one_symbol, /* _bfd_coff_add_one_symbol */
4211 coff_link_output_has_begun, /* _bfd_coff_link_output_has_begun */
4212 coff_final_link_postscript /* _bfd_coff_final_link_postscript */
4215 0x01DF, /* magic number */
4216 bfd_arch_powerpc, /* architecture */
4217 bfd_mach_ppc, /* machine */
4219 /* function pointers to xcoff specific swap routines */
4220 xcoff_swap_ldhdr_in, /* _xcoff_swap_ldhdr_in */
4221 xcoff_swap_ldhdr_out, /* _xcoff_swap_ldhdr_out */
4222 xcoff_swap_ldsym_in, /* _xcoff_swap_ldsym_in */
4223 xcoff_swap_ldsym_out, /* _xcoff_swap_ldsym_out */
4224 xcoff_swap_ldrel_in, /* _xcoff_swap_ldrel_in */
4225 xcoff_swap_ldrel_out, /* _xcoff_swap_ldrel_out */
4228 LDHDRSZ, /* _xcoff_ldhdrsz */
4229 LDSYMSZ, /* _xcoff_ldsymsz */
4230 LDRELSZ, /* _xcoff_ldrelsz */
4231 12, /* _xcoff_function_descriptor_size */
4232 SMALL_AOUTSZ, /* _xcoff_small_aout_header_size */
4235 1, /* _xcoff_ldhdr_version */
4237 /* xcoff vs xcoff64 putting symbol names */
4238 _bfd_xcoff_put_symbol_name, /* _xcoff_put_symbol_name */
4239 _bfd_xcoff_put_ldsymbol_name, /* _xcoff_put_ldsymbol_name */
4241 &xcoff_dynamic_reloc, /* dynamic reloc howto */
4243 xcoff_create_csect_from_smclas, /* _xcoff_create_csect_from_smclas */
4245 /* lineno and reloc count overflow */
4246 xcoff_is_lineno_count_overflow,
4247 xcoff_is_reloc_count_overflow,
4249 xcoff_loader_symbol_offset,
4250 xcoff_loader_reloc_offset,
4253 &xcoff_glink_code[0],
4254 (36), /* _xcoff_glink_size */
4257 0, /* _xcoff_rtinit_size */
4258 xcoff_generate_rtinit, /* _xcoff_generate_rtinit */
4261 /* The transfer vector that leads the outside world to all of the above. */
4262 const bfd_target pmac_xcoff_vec =
4265 bfd_target_xcoff_flavour,
4266 BFD_ENDIAN_BIG, /* data byte order is big */
4267 BFD_ENDIAN_BIG, /* header byte order is big */
4269 (HAS_RELOC | EXEC_P | /* object flags */
4270 HAS_LINENO | HAS_DEBUG | DYNAMIC |
4271 HAS_SYMS | HAS_LOCALS | WP_TEXT),
4273 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
4274 0, /* leading char */
4275 '/', /* ar_pad_char */
4276 15, /* ar_max_namelen??? FIXMEmgo */
4279 bfd_getb64, /* bfd_getx64 */
4280 bfd_getb_signed_64, /* bfd_getx_signed_64 */
4281 bfd_putb64, /* bfd_putx64 */
4282 bfd_getb32, /* bfd_getx32 */
4283 bfd_getb_signed_32, /* bfd_getx_signed_32 */
4284 bfd_putb32, /* bfd_putx32 */
4285 bfd_getb16, /* bfd_getx16 */
4286 bfd_getb_signed_16, /* bfd_getx_signed_16 */
4287 bfd_putb16, /* bfd_putx16 */
4290 bfd_getb64, /* bfd_h_getx64 */
4291 bfd_getb_signed_64, /* bfd_h_getx_signed_64 */
4292 bfd_putb64, /* bfd_h_putx64 */
4293 bfd_getb32, /* bfd_h_getx32 */
4294 bfd_getb_signed_32, /* bfd_h_getx_signed_32 */
4295 bfd_putb32, /* bfd_h_putx32 */
4296 bfd_getb16, /* bfd_h_getx16 */
4297 bfd_getb_signed_16, /* bfd_h_getx_signed_16 */
4298 bfd_putb16, /* bfd_h_putx16 */
4300 { /* bfd_check_format */
4303 _bfd_xcoff_archive_p,
4307 { /* bfd_set_format */
4310 _bfd_generic_mkarchive,
4314 {/* bfd_write_contents */
4316 coff_write_object_contents,
4317 _bfd_xcoff_write_archive_contents,
4322 bfd_true, /* _close_and_cleanup */
4323 bfd_true, /* _bfd_free_cached_info */
4324 coff_new_section_hook, /* _new_section_hook */
4325 _bfd_generic_get_section_contents, /* _bfd_get_section_contents */
4326 /* _bfd_get_section_contents_in_window */
4327 _bfd_generic_get_section_contents_in_window,
4330 _bfd_xcoff_copy_private_bfd_data, /* _bfd_copy_private_bfd */
4331 /* _bfd_merge_private_bfd_data */
4332 ((boolean (*) (bfd *, bfd *)) bfd_true),
4333 /* _bfd_copy_pivate_section_data */
4334 ((boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true),
4335 /* _bfd_copy_private_symbol_data */
4336 ((boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true),
4337 ((boolean (*) (bfd *, flagword)) bfd_true), /* _bfd_set_private_flags */
4338 ((boolean (*) (bfd *, void * )) bfd_true), /* _bfd_print_private_bfd_data */
4341 coff_core_file_failing_command, /* _core_file_failing_command */
4342 coff_core_file_failing_signal, /* _core_file_failing_signal */
4343 /* _core_file_matches_executable_p */
4344 coff_core_file_matches_executable_p,
4347 _bfd_xcoff_slurp_armap, /* _slurp_armap */
4348 /* XCOFF archives do not have
4349 anything which corresponds to
4350 an extended name table. */
4351 bfd_false, /* _slurp_extended_name_table */
4352 /* _construct_extended_name_table */
4353 ((boolean (*) (bfd *, char **, bfd_size_type *, const char **)) bfd_false),
4354 bfd_dont_truncate_arname, /* _truncate_arname */
4355 _bfd_xcoff_write_armap, /* _write_armap */
4356 _bfd_xcoff_read_ar_hdr, /* _read_ar_hdr */
4357 _bfd_xcoff_openr_next_archived_file, /* _openr_next_archived_file */
4358 _bfd_generic_get_elt_at_index, /* _get_elt_at_index */
4359 _bfd_xcoff_stat_arch_elt, /* _generic_stat_arch_elt */
4360 /* XCOFF archives do not have
4362 bfd_true, /* _update_armap_timestamp */
4365 coff_get_symtab_upper_bound, /* _get_symtab_upper_bound */
4366 coff_get_symtab, /* _get_symtab */
4367 coff_make_empty_symbol, /* _make_empty_symbol */
4368 coff_print_symbol, /* _print_symbol */
4369 coff_get_symbol_info, /* _get_symbol_info */
4370 _bfd_xcoff_is_local_label_name, /* _bfd_is_local_label_name */
4371 coff_get_lineno, /* _get_lineno */
4372 coff_find_nearest_line, /* _find_nearest_line */
4373 coff_bfd_make_debug_symbol, /* _bfd_make_debug_symbol */
4374 _bfd_generic_read_minisymbols, /* _read_minisymbols */
4375 _bfd_generic_minisymbol_to_symbol, /* _minsymbol_to_symbol */
4378 coff_get_reloc_upper_bound, /* _get_reloc_upper_bound */
4379 coff_canonicalize_reloc, /* _cononicalize_reloc */
4380 _bfd_xcoff_reloc_type_lookup, /* _bfd_reloc_type_lookup */
4383 coff_set_arch_mach, /* _set_arch_mach */
4384 coff_set_section_contents, /* _set_section_contents */
4387 _bfd_xcoff_sizeof_headers, /* _sizeof_headers */
4388 /* _bfd_get_relocated_section_contents */
4389 bfd_generic_get_relocated_section_contents,
4390 bfd_generic_relax_section, /* _bfd_relax_section */
4391 _bfd_xcoff_bfd_link_hash_table_create, /* _bfd_link_hash_table_create */
4392 _bfd_generic_link_hash_table_free, /* _bfd_link_hash_table_free */
4393 _bfd_xcoff_bfd_link_add_symbols, /* _bfd_link_add_symbols */
4394 _bfd_xcoff_bfd_final_link, /* _bfd_filnal_link */
4395 _bfd_generic_link_split_section, /* _bfd_link_split_section */
4396 bfd_generic_gc_sections, /* _bfd_gc_sections */
4397 bfd_generic_merge_sections, /* _bfd_merge_sections */
4400 /* _get_dynamic_symtab_upper_bound */
4401 _bfd_xcoff_get_dynamic_symtab_upper_bound,
4402 _bfd_xcoff_canonicalize_dynamic_symtab, /* _cononicalize_dynamic_symtab */
4403 _bfd_xcoff_get_dynamic_reloc_upper_bound,/* _get_dynamic_reloc_upper_bound */
4404 _bfd_xcoff_canonicalize_dynamic_reloc, /* _cononicalize_dynamic_reloc */
4406 /* Opposite endian version, none exists */
4410 (void *) &bfd_pmac_xcoff_backend_data,