1 /* BFD back-end for IBM RS/6000 "XCOFF" files.
2 Copyright 1990-1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 2008, 2009 Free Software Foundation, Inc.
4 Written by Metin G. Ozisik, Mimi Phuong-Thao Vo, and John Gilmore.
5 Archive support from Damon A. Permezel.
6 Contributed by IBM Corporation and Cygnus Support.
8 This file is part of BFD, the Binary File Descriptor library.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
23 MA 02110-1301, USA. */
29 #include "coff/internal.h"
30 #include "coff/xcoff.h"
31 #include "coff/rs6000.h"
35 extern bfd_boolean _bfd_xcoff_mkobject
37 extern bfd_boolean _bfd_xcoff_copy_private_bfd_data
38 PARAMS ((bfd
*, bfd
*));
39 extern bfd_boolean _bfd_xcoff_is_local_label_name
40 PARAMS ((bfd
*, const char *));
41 extern reloc_howto_type
*_bfd_xcoff_reloc_type_lookup
42 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
43 extern bfd_boolean _bfd_xcoff_slurp_armap
45 extern const bfd_target
*_bfd_xcoff_archive_p
47 extern PTR _bfd_xcoff_read_ar_hdr
49 extern bfd
*_bfd_xcoff_openr_next_archived_file
50 PARAMS ((bfd
*, bfd
*));
51 extern int _bfd_xcoff_stat_arch_elt
52 PARAMS ((bfd
*, struct stat
*));
53 extern bfd_boolean _bfd_xcoff_write_armap
54 PARAMS ((bfd
*, unsigned int, struct orl
*, unsigned int, int));
55 extern bfd_boolean _bfd_xcoff_write_archive_contents
57 extern int _bfd_xcoff_sizeof_headers
58 PARAMS ((bfd
*, struct bfd_link_info
*));
59 extern void _bfd_xcoff_swap_sym_in
60 PARAMS ((bfd
*, PTR
, PTR
));
61 extern unsigned int _bfd_xcoff_swap_sym_out
62 PARAMS ((bfd
*, PTR
, PTR
));
63 extern void _bfd_xcoff_swap_aux_in
64 PARAMS ((bfd
*, PTR
, int, int, int, int, PTR
));
65 extern unsigned int _bfd_xcoff_swap_aux_out
66 PARAMS ((bfd
*, PTR
, int, int, int, int, PTR
));
67 static void xcoff_swap_reloc_in
68 PARAMS ((bfd
*, PTR
, PTR
));
69 static unsigned int xcoff_swap_reloc_out
70 PARAMS ((bfd
*, PTR
, PTR
));
72 /* Forward declare xcoff_rtype2howto for coffcode.h macro. */
73 void xcoff_rtype2howto
74 PARAMS ((arelent
*, struct internal_reloc
*));
76 /* coffcode.h needs these to be defined. */
77 #define RS6000COFF_C 1
79 #define SELECT_RELOC(internal, howto) \
81 internal.r_type = howto->type; \
83 ((howto->complain_on_overflow == complain_overflow_signed \
86 | (howto->bitsize - 1)); \
89 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
90 #define COFF_LONG_FILENAMES
91 #define NO_COFF_SYMBOLS
92 #define RTYPE2HOWTO(cache_ptr, dst) xcoff_rtype2howto (cache_ptr, dst)
93 #define coff_mkobject _bfd_xcoff_mkobject
94 #define coff_bfd_copy_private_bfd_data _bfd_xcoff_copy_private_bfd_data
95 #define coff_bfd_is_local_label_name _bfd_xcoff_is_local_label_name
96 #define coff_bfd_reloc_type_lookup _bfd_xcoff_reloc_type_lookup
97 #define coff_bfd_reloc_name_lookup _bfd_xcoff_reloc_name_lookup
99 extern const bfd_target
* rs6000coff_core_p
100 PARAMS ((bfd
*abfd
));
101 extern bfd_boolean rs6000coff_core_file_matches_executable_p
102 PARAMS ((bfd
*cbfd
, bfd
*ebfd
));
103 extern char *rs6000coff_core_file_failing_command
104 PARAMS ((bfd
*abfd
));
105 extern int rs6000coff_core_file_failing_signal
106 PARAMS ((bfd
*abfd
));
107 #define CORE_FILE_P rs6000coff_core_p
108 #define coff_core_file_failing_command \
109 rs6000coff_core_file_failing_command
110 #define coff_core_file_failing_signal \
111 rs6000coff_core_file_failing_signal
112 #define coff_core_file_matches_executable_p \
113 rs6000coff_core_file_matches_executable_p
115 #define CORE_FILE_P _bfd_dummy_target
116 #define coff_core_file_failing_command \
117 _bfd_nocore_core_file_failing_command
118 #define coff_core_file_failing_signal \
119 _bfd_nocore_core_file_failing_signal
120 #define coff_core_file_matches_executable_p \
121 _bfd_nocore_core_file_matches_executable_p
123 #define coff_SWAP_sym_in _bfd_xcoff_swap_sym_in
124 #define coff_SWAP_sym_out _bfd_xcoff_swap_sym_out
125 #define coff_SWAP_aux_in _bfd_xcoff_swap_aux_in
126 #define coff_SWAP_aux_out _bfd_xcoff_swap_aux_out
127 #define coff_swap_reloc_in xcoff_swap_reloc_in
128 #define coff_swap_reloc_out xcoff_swap_reloc_out
129 #define NO_COFF_RELOCS
131 #ifndef bfd_pe_print_pdata
132 #define bfd_pe_print_pdata NULL
135 #include "coffcode.h"
137 /* The main body of code is in coffcode.h. */
139 static const char *normalize_filename
141 static bfd_boolean xcoff_write_armap_old
142 PARAMS ((bfd
*, unsigned int, struct orl
*, unsigned int, int));
143 static bfd_boolean xcoff_write_armap_big
144 PARAMS ((bfd
*, unsigned int, struct orl
*, unsigned int, int));
145 static bfd_boolean xcoff_write_archive_contents_old
147 static bfd_boolean xcoff_write_archive_contents_big
149 static void xcoff_swap_ldhdr_in
150 PARAMS ((bfd
*, const PTR
, struct internal_ldhdr
*));
151 static void xcoff_swap_ldhdr_out
152 PARAMS ((bfd
*, const struct internal_ldhdr
*, PTR
));
153 static void xcoff_swap_ldsym_in
154 PARAMS ((bfd
*, const PTR
, struct internal_ldsym
*));
155 static void xcoff_swap_ldsym_out
156 PARAMS ((bfd
*, const struct internal_ldsym
*, PTR
));
157 static void xcoff_swap_ldrel_in
158 PARAMS ((bfd
*, const PTR
, struct internal_ldrel
*));
159 static void xcoff_swap_ldrel_out
160 PARAMS ((bfd
*, const struct internal_ldrel
*, PTR
));
161 static bfd_boolean xcoff_ppc_relocate_section
162 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
163 struct internal_reloc
*, struct internal_syment
*, asection
**));
164 static bfd_boolean _bfd_xcoff_put_ldsymbol_name
165 PARAMS ((bfd
*, struct xcoff_loader_info
*, struct internal_ldsym
*,
167 static asection
*xcoff_create_csect_from_smclas
168 PARAMS ((bfd
*, union internal_auxent
*, const char *));
169 static bfd_boolean xcoff_is_lineno_count_overflow
170 PARAMS ((bfd
*, bfd_vma
));
171 static bfd_boolean xcoff_is_reloc_count_overflow
172 PARAMS ((bfd
*, bfd_vma
));
173 static bfd_vma xcoff_loader_symbol_offset
174 PARAMS ((bfd
*, struct internal_ldhdr
*));
175 static bfd_vma xcoff_loader_reloc_offset
176 PARAMS ((bfd
*, struct internal_ldhdr
*));
177 static bfd_boolean xcoff_generate_rtinit
178 PARAMS ((bfd
*, const char *, const char *, bfd_boolean
));
179 static bfd_boolean do_pad
180 PARAMS ((bfd
*, unsigned int));
181 static bfd_boolean do_copy
182 PARAMS ((bfd
*, bfd
*));
183 static bfd_boolean do_shared_object_padding
184 PARAMS ((bfd
*, bfd
*, file_ptr
*, int));
186 /* Relocation functions */
187 static bfd_boolean xcoff_reloc_type_br
188 PARAMS ((XCOFF_RELOC_FUNCTION_ARGS
));
190 static bfd_boolean xcoff_complain_overflow_dont_func
191 PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS
));
192 static bfd_boolean xcoff_complain_overflow_bitfield_func
193 PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS
));
194 static bfd_boolean xcoff_complain_overflow_signed_func
195 PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS
));
196 static bfd_boolean xcoff_complain_overflow_unsigned_func
197 PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS
));
199 bfd_boolean (*xcoff_calculate_relocation
[XCOFF_MAX_CALCULATE_RELOCATION
])
200 PARAMS ((XCOFF_RELOC_FUNCTION_ARGS
)) =
202 xcoff_reloc_type_pos
, /* R_POS (0x00) */
203 xcoff_reloc_type_neg
, /* R_NEG (0x01) */
204 xcoff_reloc_type_rel
, /* R_REL (0x02) */
205 xcoff_reloc_type_toc
, /* R_TOC (0x03) */
206 xcoff_reloc_type_fail
, /* R_RTB (0x04) */
207 xcoff_reloc_type_toc
, /* R_GL (0x05) */
208 xcoff_reloc_type_toc
, /* R_TCL (0x06) */
209 xcoff_reloc_type_fail
, /* (0x07) */
210 xcoff_reloc_type_ba
, /* R_BA (0x08) */
211 xcoff_reloc_type_fail
, /* (0x09) */
212 xcoff_reloc_type_br
, /* R_BR (0x0a) */
213 xcoff_reloc_type_fail
, /* (0x0b) */
214 xcoff_reloc_type_pos
, /* R_RL (0x0c) */
215 xcoff_reloc_type_pos
, /* R_RLA (0x0d) */
216 xcoff_reloc_type_fail
, /* (0x0e) */
217 xcoff_reloc_type_noop
, /* R_REF (0x0f) */
218 xcoff_reloc_type_fail
, /* (0x10) */
219 xcoff_reloc_type_fail
, /* (0x11) */
220 xcoff_reloc_type_toc
, /* R_TRL (0x12) */
221 xcoff_reloc_type_toc
, /* R_TRLA (0x13) */
222 xcoff_reloc_type_fail
, /* R_RRTBI (0x14) */
223 xcoff_reloc_type_fail
, /* R_RRTBA (0x15) */
224 xcoff_reloc_type_ba
, /* R_CAI (0x16) */
225 xcoff_reloc_type_crel
, /* R_CREL (0x17) */
226 xcoff_reloc_type_ba
, /* R_RBA (0x18) */
227 xcoff_reloc_type_ba
, /* R_RBAC (0x19) */
228 xcoff_reloc_type_br
, /* R_RBR (0x1a) */
229 xcoff_reloc_type_ba
, /* R_RBRC (0x1b) */
232 bfd_boolean (*xcoff_complain_overflow
[XCOFF_MAX_COMPLAIN_OVERFLOW
])
233 PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS
)) =
235 xcoff_complain_overflow_dont_func
,
236 xcoff_complain_overflow_bitfield_func
,
237 xcoff_complain_overflow_signed_func
,
238 xcoff_complain_overflow_unsigned_func
,
241 /* We use our own tdata type. Its first field is the COFF tdata type,
242 so the COFF routines are compatible. */
245 _bfd_xcoff_mkobject (abfd
)
248 coff_data_type
*coff
;
249 bfd_size_type amt
= sizeof (struct xcoff_tdata
);
251 abfd
->tdata
.xcoff_obj_data
= (struct xcoff_tdata
*) bfd_zalloc (abfd
, amt
);
252 if (abfd
->tdata
.xcoff_obj_data
== NULL
)
254 coff
= coff_data (abfd
);
255 coff
->symbols
= (coff_symbol_type
*) NULL
;
256 coff
->conversion_table
= (unsigned int *) NULL
;
257 coff
->raw_syments
= (struct coff_ptr_struct
*) NULL
;
260 xcoff_data (abfd
)->modtype
= ('1' << 8) | 'L';
262 /* We set cputype to -1 to indicate that it has not been
264 xcoff_data (abfd
)->cputype
= -1;
266 xcoff_data (abfd
)->csects
= NULL
;
267 xcoff_data (abfd
)->debug_indices
= NULL
;
269 /* text section alignment is different than the default */
270 bfd_xcoff_text_align_power (abfd
) = 2;
275 /* Copy XCOFF data from one BFD to another. */
278 _bfd_xcoff_copy_private_bfd_data (ibfd
, obfd
)
282 struct xcoff_tdata
*ix
, *ox
;
285 if (ibfd
->xvec
!= obfd
->xvec
)
287 ix
= xcoff_data (ibfd
);
288 ox
= xcoff_data (obfd
);
289 ox
->full_aouthdr
= ix
->full_aouthdr
;
295 sec
= coff_section_from_bfd_index (ibfd
, ix
->sntoc
);
299 ox
->sntoc
= sec
->output_section
->target_index
;
301 if (ix
->snentry
== 0)
305 sec
= coff_section_from_bfd_index (ibfd
, ix
->snentry
);
309 ox
->snentry
= sec
->output_section
->target_index
;
311 bfd_xcoff_text_align_power (obfd
) = bfd_xcoff_text_align_power (ibfd
);
312 bfd_xcoff_data_align_power (obfd
) = bfd_xcoff_data_align_power (ibfd
);
313 ox
->modtype
= ix
->modtype
;
314 ox
->cputype
= ix
->cputype
;
315 ox
->maxdata
= ix
->maxdata
;
316 ox
->maxstack
= ix
->maxstack
;
320 /* I don't think XCOFF really has a notion of local labels based on
321 name. This will mean that ld -X doesn't actually strip anything.
322 The AIX native linker does not have a -X option, and it ignores the
326 _bfd_xcoff_is_local_label_name (abfd
, name
)
327 bfd
*abfd ATTRIBUTE_UNUSED
;
328 const char *name ATTRIBUTE_UNUSED
;
334 _bfd_xcoff_swap_sym_in (abfd
, ext1
, in1
)
339 SYMENT
*ext
= (SYMENT
*)ext1
;
340 struct internal_syment
* in
= (struct internal_syment
*)in1
;
342 if (ext
->e
.e_name
[0] != 0)
344 memcpy (in
->_n
._n_name
, ext
->e
.e_name
, SYMNMLEN
);
348 in
->_n
._n_n
._n_zeroes
= 0;
349 in
->_n
._n_n
._n_offset
= H_GET_32 (abfd
, ext
->e
.e
.e_offset
);
352 in
->n_value
= H_GET_32 (abfd
, ext
->e_value
);
353 in
->n_scnum
= H_GET_16 (abfd
, ext
->e_scnum
);
354 in
->n_type
= H_GET_16 (abfd
, ext
->e_type
);
355 in
->n_sclass
= H_GET_8 (abfd
, ext
->e_sclass
);
356 in
->n_numaux
= H_GET_8 (abfd
, ext
->e_numaux
);
360 _bfd_xcoff_swap_sym_out (abfd
, inp
, extp
)
365 struct internal_syment
*in
= (struct internal_syment
*)inp
;
366 SYMENT
*ext
=(SYMENT
*)extp
;
368 if (in
->_n
._n_name
[0] != 0)
370 memcpy (ext
->e
.e_name
, in
->_n
._n_name
, SYMNMLEN
);
374 H_PUT_32 (abfd
, 0, ext
->e
.e
.e_zeroes
);
375 H_PUT_32 (abfd
, in
->_n
._n_n
._n_offset
, ext
->e
.e
.e_offset
);
378 H_PUT_32 (abfd
, in
->n_value
, ext
->e_value
);
379 H_PUT_16 (abfd
, in
->n_scnum
, ext
->e_scnum
);
380 H_PUT_16 (abfd
, in
->n_type
, ext
->e_type
);
381 H_PUT_8 (abfd
, in
->n_sclass
, ext
->e_sclass
);
382 H_PUT_8 (abfd
, in
->n_numaux
, ext
->e_numaux
);
383 return bfd_coff_symesz (abfd
);
387 _bfd_xcoff_swap_aux_in (abfd
, ext1
, type
, class, indx
, numaux
, in1
)
396 AUXENT
* ext
= (AUXENT
*)ext1
;
397 union internal_auxent
*in
= (union internal_auxent
*)in1
;
402 if (ext
->x_file
.x_fname
[0] == 0)
404 in
->x_file
.x_n
.x_zeroes
= 0;
405 in
->x_file
.x_n
.x_offset
=
406 H_GET_32 (abfd
, ext
->x_file
.x_n
.x_offset
);
413 memcpy (in
->x_file
.x_fname
, ext
->x_file
.x_fname
,
414 numaux
* sizeof (AUXENT
));
418 memcpy (in
->x_file
.x_fname
, ext
->x_file
.x_fname
, FILNMLEN
);
423 /* RS/6000 "csect" auxents */
427 if (indx
+ 1 == numaux
)
429 in
->x_csect
.x_scnlen
.l
= H_GET_32 (abfd
, ext
->x_csect
.x_scnlen
);
430 in
->x_csect
.x_parmhash
= H_GET_32 (abfd
, ext
->x_csect
.x_parmhash
);
431 in
->x_csect
.x_snhash
= H_GET_16 (abfd
, ext
->x_csect
.x_snhash
);
432 /* We don't have to hack bitfields in x_smtyp because it's
433 defined by shifts-and-ands, which are equivalent on all
435 in
->x_csect
.x_smtyp
= H_GET_8 (abfd
, ext
->x_csect
.x_smtyp
);
436 in
->x_csect
.x_smclas
= H_GET_8 (abfd
, ext
->x_csect
.x_smclas
);
437 in
->x_csect
.x_stab
= H_GET_32 (abfd
, ext
->x_csect
.x_stab
);
438 in
->x_csect
.x_snstab
= H_GET_16 (abfd
, ext
->x_csect
.x_snstab
);
448 in
->x_scn
.x_scnlen
= H_GET_32 (abfd
, ext
->x_scn
.x_scnlen
);
449 in
->x_scn
.x_nreloc
= H_GET_16 (abfd
, ext
->x_scn
.x_nreloc
);
450 in
->x_scn
.x_nlinno
= H_GET_16 (abfd
, ext
->x_scn
.x_nlinno
);
451 /* PE defines some extra fields; we zero them out for
453 in
->x_scn
.x_checksum
= 0;
454 in
->x_scn
.x_associated
= 0;
455 in
->x_scn
.x_comdat
= 0;
462 in
->x_sym
.x_tagndx
.l
= H_GET_32 (abfd
, ext
->x_sym
.x_tagndx
);
463 in
->x_sym
.x_tvndx
= H_GET_16 (abfd
, ext
->x_sym
.x_tvndx
);
465 if (class == C_BLOCK
|| class == C_FCN
|| ISFCN (type
) || ISTAG (class))
467 in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
=
468 H_GET_32 (abfd
, ext
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
469 in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
=
470 H_GET_32 (abfd
, ext
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
474 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0] =
475 H_GET_16 (abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
476 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1] =
477 H_GET_16 (abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
478 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2] =
479 H_GET_16 (abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
480 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3] =
481 H_GET_16 (abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
486 in
->x_sym
.x_misc
.x_fsize
= H_GET_32 (abfd
, ext
->x_sym
.x_misc
.x_fsize
);
490 in
->x_sym
.x_misc
.x_lnsz
.x_lnno
=
491 H_GET_16 (abfd
, ext
->x_sym
.x_misc
.x_lnsz
.x_lnno
);
492 in
->x_sym
.x_misc
.x_lnsz
.x_size
=
493 H_GET_16 (abfd
, ext
->x_sym
.x_misc
.x_lnsz
.x_size
);
497 /* The semicolon is because MSVC doesn't like labels at
502 unsigned int _bfd_xcoff_swap_aux_out
503 PARAMS ((bfd
*, PTR
, int, int, int, int, PTR
));
506 _bfd_xcoff_swap_aux_out (abfd
, inp
, type
, class, indx
, numaux
, extp
)
511 int indx ATTRIBUTE_UNUSED
;
512 int numaux ATTRIBUTE_UNUSED
;
515 union internal_auxent
*in
= (union internal_auxent
*)inp
;
516 AUXENT
*ext
= (AUXENT
*)extp
;
518 memset ((PTR
)ext
, 0, bfd_coff_auxesz (abfd
));
522 if (in
->x_file
.x_fname
[0] == 0)
524 H_PUT_32 (abfd
, 0, ext
->x_file
.x_n
.x_zeroes
);
525 H_PUT_32 (abfd
, in
->x_file
.x_n
.x_offset
, ext
->x_file
.x_n
.x_offset
);
529 memcpy (ext
->x_file
.x_fname
, in
->x_file
.x_fname
, FILNMLEN
);
533 /* RS/6000 "csect" auxents */
537 if (indx
+ 1 == numaux
)
539 H_PUT_32 (abfd
, in
->x_csect
.x_scnlen
.l
, ext
->x_csect
.x_scnlen
);
540 H_PUT_32 (abfd
, in
->x_csect
.x_parmhash
, ext
->x_csect
.x_parmhash
);
541 H_PUT_16 (abfd
, in
->x_csect
.x_snhash
, ext
->x_csect
.x_snhash
);
542 /* We don't have to hack bitfields in x_smtyp because it's
543 defined by shifts-and-ands, which are equivalent on all
545 H_PUT_8 (abfd
, in
->x_csect
.x_smtyp
, ext
->x_csect
.x_smtyp
);
546 H_PUT_8 (abfd
, in
->x_csect
.x_smclas
, ext
->x_csect
.x_smclas
);
547 H_PUT_32 (abfd
, in
->x_csect
.x_stab
, ext
->x_csect
.x_stab
);
548 H_PUT_16 (abfd
, in
->x_csect
.x_snstab
, ext
->x_csect
.x_snstab
);
558 H_PUT_32 (abfd
, in
->x_scn
.x_scnlen
, ext
->x_scn
.x_scnlen
);
559 H_PUT_16 (abfd
, in
->x_scn
.x_nreloc
, ext
->x_scn
.x_nreloc
);
560 H_PUT_16 (abfd
, in
->x_scn
.x_nlinno
, ext
->x_scn
.x_nlinno
);
566 H_PUT_32 (abfd
, in
->x_sym
.x_tagndx
.l
, ext
->x_sym
.x_tagndx
);
567 H_PUT_16 (abfd
, in
->x_sym
.x_tvndx
, ext
->x_sym
.x_tvndx
);
569 if (class == C_BLOCK
|| class == C_FCN
|| ISFCN (type
) || ISTAG (class))
571 H_PUT_32 (abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
,
572 ext
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
573 H_PUT_32 (abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
,
574 ext
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
578 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0],
579 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
580 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1],
581 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
582 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2],
583 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
584 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3],
585 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
589 H_PUT_32 (abfd
, in
->x_sym
.x_misc
.x_fsize
, ext
->x_sym
.x_misc
.x_fsize
);
592 H_PUT_16 (abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_lnno
,
593 ext
->x_sym
.x_misc
.x_lnsz
.x_lnno
);
594 H_PUT_16 (abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_size
,
595 ext
->x_sym
.x_misc
.x_lnsz
.x_size
);
599 return bfd_coff_auxesz (abfd
);
604 /* The XCOFF reloc table. Actually, XCOFF relocations specify the
605 bitsize and whether they are signed or not, along with a
606 conventional type. This table is for the types, which are used for
607 different algorithms for putting in the reloc. Many of these
608 relocs need special_function entries, which I have not written. */
611 reloc_howto_type xcoff_howto_table
[] =
613 /* Standard 32 bit relocation. */
614 HOWTO (R_POS
, /* type */
616 2, /* size (0 = byte, 1 = short, 2 = long) */
618 FALSE
, /* pc_relative */
620 complain_overflow_bitfield
, /* complain_on_overflow */
621 0, /* special_function */
623 TRUE
, /* partial_inplace */
624 0xffffffff, /* src_mask */
625 0xffffffff, /* dst_mask */
626 FALSE
), /* pcrel_offset */
628 /* 32 bit relocation, but store negative value. */
629 HOWTO (R_NEG
, /* type */
631 -2, /* 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 0xffffffff, /* src_mask */
640 0xffffffff, /* dst_mask */
641 FALSE
), /* pcrel_offset */
643 /* 32 bit PC relative relocation. */
644 HOWTO (R_REL
, /* type */
646 2, /* size (0 = byte, 1 = short, 2 = long) */
648 TRUE
, /* pc_relative */
650 complain_overflow_signed
, /* complain_on_overflow */
651 0, /* special_function */
653 TRUE
, /* partial_inplace */
654 0xffffffff, /* src_mask */
655 0xffffffff, /* dst_mask */
656 FALSE
), /* pcrel_offset */
658 /* 16 bit TOC relative relocation. */
659 HOWTO (R_TOC
, /* type */
661 1, /* 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 /* I don't really know what this is. */
674 HOWTO (R_RTB
, /* 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 0xffffffff, /* src_mask */
685 0xffffffff, /* dst_mask */
686 FALSE
), /* pcrel_offset */
688 /* External TOC relative symbol. */
689 HOWTO (R_GL
, /* type */
691 1, /* size (0 = byte, 1 = short, 2 = long) */
693 FALSE
, /* pc_relative */
695 complain_overflow_bitfield
, /* complain_on_overflow */
696 0, /* special_function */
698 TRUE
, /* partial_inplace */
699 0xffff, /* src_mask */
700 0xffff, /* dst_mask */
701 FALSE
), /* pcrel_offset */
703 /* Local TOC relative symbol. */
704 HOWTO (R_TCL
, /* type */
706 1, /* size (0 = byte, 1 = short, 2 = long) */
708 FALSE
, /* pc_relative */
710 complain_overflow_bitfield
, /* complain_on_overflow */
711 0, /* special_function */
713 TRUE
, /* partial_inplace */
714 0xffff, /* src_mask */
715 0xffff, /* dst_mask */
716 FALSE
), /* pcrel_offset */
720 /* Non modifiable absolute branch. */
721 HOWTO (R_BA
, /* type */
723 2, /* size (0 = byte, 1 = short, 2 = long) */
725 FALSE
, /* pc_relative */
727 complain_overflow_bitfield
, /* complain_on_overflow */
728 0, /* special_function */
729 "R_BA_26", /* name */
730 TRUE
, /* partial_inplace */
731 0x03fffffc, /* src_mask */
732 0x03fffffc, /* dst_mask */
733 FALSE
), /* pcrel_offset */
737 /* Non modifiable relative branch. */
738 HOWTO (R_BR
, /* type */
740 2, /* size (0 = byte, 1 = short, 2 = long) */
742 TRUE
, /* pc_relative */
744 complain_overflow_signed
, /* complain_on_overflow */
745 0, /* special_function */
747 TRUE
, /* partial_inplace */
748 0x03fffffc, /* src_mask */
749 0x03fffffc, /* dst_mask */
750 FALSE
), /* pcrel_offset */
755 HOWTO (R_RL
, /* type */
757 1, /* size (0 = byte, 1 = short, 2 = long) */
759 FALSE
, /* pc_relative */
761 complain_overflow_bitfield
, /* complain_on_overflow */
762 0, /* special_function */
764 TRUE
, /* partial_inplace */
765 0xffff, /* src_mask */
766 0xffff, /* dst_mask */
767 FALSE
), /* pcrel_offset */
770 HOWTO (R_RLA
, /* type */
772 1, /* size (0 = byte, 1 = short, 2 = long) */
774 FALSE
, /* pc_relative */
776 complain_overflow_bitfield
, /* complain_on_overflow */
777 0, /* special_function */
779 TRUE
, /* partial_inplace */
780 0xffff, /* src_mask */
781 0xffff, /* dst_mask */
782 FALSE
), /* pcrel_offset */
786 /* Non-relocating reference. */
787 HOWTO (R_REF
, /* type */
789 2, /* size (0 = byte, 1 = short, 2 = long) */
791 FALSE
, /* pc_relative */
793 complain_overflow_dont
, /* complain_on_overflow */
794 0, /* special_function */
796 FALSE
, /* partial_inplace */
799 FALSE
), /* pcrel_offset */
804 /* TOC relative indirect load. */
805 HOWTO (R_TRL
, /* type */
807 1, /* size (0 = byte, 1 = short, 2 = long) */
809 FALSE
, /* pc_relative */
811 complain_overflow_bitfield
, /* complain_on_overflow */
812 0, /* special_function */
814 TRUE
, /* partial_inplace */
815 0xffff, /* src_mask */
816 0xffff, /* dst_mask */
817 FALSE
), /* pcrel_offset */
819 /* TOC relative load address. */
820 HOWTO (R_TRLA
, /* type */
822 1, /* size (0 = byte, 1 = short, 2 = long) */
824 FALSE
, /* pc_relative */
826 complain_overflow_bitfield
, /* complain_on_overflow */
827 0, /* special_function */
829 TRUE
, /* partial_inplace */
830 0xffff, /* src_mask */
831 0xffff, /* dst_mask */
832 FALSE
), /* pcrel_offset */
834 /* Modifiable relative branch. */
835 HOWTO (R_RRTBI
, /* 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 */
843 "R_RRTBI", /* name */
844 TRUE
, /* partial_inplace */
845 0xffffffff, /* src_mask */
846 0xffffffff, /* dst_mask */
847 FALSE
), /* pcrel_offset */
849 /* Modifiable absolute branch. */
850 HOWTO (R_RRTBA
, /* 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 */
858 "R_RRTBA", /* name */
859 TRUE
, /* partial_inplace */
860 0xffffffff, /* src_mask */
861 0xffffffff, /* dst_mask */
862 FALSE
), /* pcrel_offset */
864 /* Modifiable call absolute indirect. */
865 HOWTO (R_CAI
, /* type */
867 1, /* 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 call relative. */
880 HOWTO (R_CREL
, /* type */
882 1, /* 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 absolute. */
895 HOWTO (R_RBA
, /* type */
897 2, /* size (0 = byte, 1 = short, 2 = long) */
899 FALSE
, /* pc_relative */
901 complain_overflow_bitfield
, /* complain_on_overflow */
902 0, /* special_function */
904 TRUE
, /* partial_inplace */
905 0x03fffffc, /* src_mask */
906 0x03fffffc, /* dst_mask */
907 FALSE
), /* pcrel_offset */
909 /* Modifiable branch absolute. */
910 HOWTO (R_RBAC
, /* 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 0xffffffff, /* src_mask */
921 0xffffffff, /* dst_mask */
922 FALSE
), /* pcrel_offset */
924 /* Modifiable branch relative. */
925 HOWTO (R_RBR
, /* type */
927 2, /* size (0 = byte, 1 = short, 2 = long) */
929 FALSE
, /* pc_relative */
931 complain_overflow_signed
, /* complain_on_overflow */
932 0, /* special_function */
933 "R_RBR_26", /* name */
934 TRUE
, /* partial_inplace */
935 0x03fffffc, /* src_mask */
936 0x03fffffc, /* dst_mask */
937 FALSE
), /* pcrel_offset */
939 /* Modifiable branch absolute. */
940 HOWTO (R_RBRC
, /* type */
942 1, /* size (0 = byte, 1 = short, 2 = long) */
944 FALSE
, /* pc_relative */
946 complain_overflow_bitfield
, /* complain_on_overflow */
947 0, /* special_function */
949 TRUE
, /* partial_inplace */
950 0xffff, /* src_mask */
951 0xffff, /* dst_mask */
952 FALSE
), /* pcrel_offset */
954 /* 16 bit Non modifiable absolute branch. */
955 HOWTO (R_BA
, /* type */
957 1, /* size (0 = byte, 1 = short, 2 = long) */
959 FALSE
, /* pc_relative */
961 complain_overflow_bitfield
, /* complain_on_overflow */
962 0, /* special_function */
963 "R_BA_16", /* name */
964 TRUE
, /* partial_inplace */
965 0xfffc, /* src_mask */
966 0xfffc, /* dst_mask */
967 FALSE
), /* pcrel_offset */
969 /* Modifiable branch relative. */
970 HOWTO (R_RBR
, /* type */
972 1, /* size (0 = byte, 1 = short, 2 = long) */
974 FALSE
, /* pc_relative */
976 complain_overflow_signed
, /* complain_on_overflow */
977 0, /* special_function */
978 "R_RBR_16", /* name */
979 TRUE
, /* partial_inplace */
980 0xffff, /* src_mask */
981 0xffff, /* dst_mask */
982 FALSE
), /* pcrel_offset */
984 /* Modifiable branch relative. */
985 HOWTO (R_RBA
, /* type */
987 1, /* size (0 = byte, 1 = short, 2 = long) */
989 FALSE
, /* pc_relative */
991 complain_overflow_signed
, /* complain_on_overflow */
992 0, /* special_function */
993 "R_RBA_16", /* name */
994 TRUE
, /* partial_inplace */
995 0xffff, /* src_mask */
996 0xffff, /* dst_mask */
997 FALSE
), /* pcrel_offset */
1002 xcoff_rtype2howto (relent
, internal
)
1004 struct internal_reloc
*internal
;
1006 if (internal
->r_type
> R_RBRC
)
1009 /* Default howto layout works most of the time */
1010 relent
->howto
= &xcoff_howto_table
[internal
->r_type
];
1012 /* Special case some 16 bit reloc */
1013 if (15 == (internal
->r_size
& 0x1f))
1015 if (R_BA
== internal
->r_type
)
1016 relent
->howto
= &xcoff_howto_table
[0x1c];
1017 else if (R_RBR
== internal
->r_type
)
1018 relent
->howto
= &xcoff_howto_table
[0x1d];
1019 else if (R_RBA
== internal
->r_type
)
1020 relent
->howto
= &xcoff_howto_table
[0x1e];
1023 /* The r_size field of an XCOFF reloc encodes the bitsize of the
1024 relocation, as well as indicating whether it is signed or not.
1025 Doublecheck that the relocation information gathered from the
1026 type matches this information. The bitsize is not significant
1027 for R_REF relocs. */
1028 if (relent
->howto
->dst_mask
!= 0
1029 && (relent
->howto
->bitsize
1030 != ((unsigned int) internal
->r_size
& 0x1f) + 1))
1035 _bfd_xcoff_reloc_type_lookup (abfd
, code
)
1036 bfd
*abfd ATTRIBUTE_UNUSED
;
1037 bfd_reloc_code_real_type code
;
1041 case BFD_RELOC_PPC_B26
:
1042 return &xcoff_howto_table
[0xa];
1043 case BFD_RELOC_PPC_BA16
:
1044 return &xcoff_howto_table
[0x1c];
1045 case BFD_RELOC_PPC_BA26
:
1046 return &xcoff_howto_table
[8];
1047 case BFD_RELOC_PPC_TOC16
:
1048 return &xcoff_howto_table
[3];
1050 case BFD_RELOC_CTOR
:
1051 return &xcoff_howto_table
[0];
1057 static reloc_howto_type
*
1058 _bfd_xcoff_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1064 i
< sizeof (xcoff_howto_table
) / sizeof (xcoff_howto_table
[0]);
1066 if (xcoff_howto_table
[i
].name
!= NULL
1067 && strcasecmp (xcoff_howto_table
[i
].name
, r_name
) == 0)
1068 return &xcoff_howto_table
[i
];
1073 /* XCOFF archive support. The original version of this code was by
1074 Damon A. Permezel. It was enhanced to permit cross support, and
1075 writing archive files, by Ian Lance Taylor, Cygnus Support.
1077 XCOFF uses its own archive format. Everything is hooked together
1078 with file offset links, so it is possible to rapidly update an
1079 archive in place. Of course, we don't do that. An XCOFF archive
1080 has a real file header, not just an ARMAG string. The structure of
1081 the file header and of each archive header appear below.
1083 An XCOFF archive also has a member table, which is a list of
1084 elements in the archive (you can get that by looking through the
1085 linked list, but you have to read a lot more of the file). The
1086 member table has a normal archive header with an empty name. It is
1087 normally (and perhaps must be) the second to last entry in the
1088 archive. The member table data is almost printable ASCII. It
1089 starts with a 12 character decimal string which is the number of
1090 entries in the table. For each entry it has a 12 character decimal
1091 string which is the offset in the archive of that member. These
1092 entries are followed by a series of null terminated strings which
1093 are the member names for each entry.
1095 Finally, an XCOFF archive has a global symbol table, which is what
1096 we call the armap. The global symbol table has a normal archive
1097 header with an empty name. It is normally (and perhaps must be)
1098 the last entry in the archive. The contents start with a four byte
1099 binary number which is the number of entries. This is followed by
1100 a that many four byte binary numbers; each is the file offset of an
1101 entry in the archive. These numbers are followed by a series of
1102 null terminated strings, which are symbol names.
1104 AIX 4.3 introduced a new archive format which can handle larger
1105 files and also 32- and 64-bit objects in the same archive. The
1106 things said above remain true except that there is now more than
1107 one global symbol table. The one is used to index 32-bit objects,
1108 the other for 64-bit objects.
1110 The new archives (recognizable by the new ARMAG string) has larger
1111 field lengths so that we cannot really share any code. Also we have
1112 to take care that we are not generating the new form of archives
1113 on AIX 4.2 or earlier systems. */
1115 /* XCOFF archives use this as a magic string. Note that both strings
1116 have the same length. */
1118 /* Set the magic for archive. */
1121 bfd_xcoff_ar_archive_set_magic (abfd
, magic
)
1122 bfd
*abfd ATTRIBUTE_UNUSED
;
1123 char *magic ATTRIBUTE_UNUSED
;
1125 /* Not supported yet. */
1127 /* bfd_xcoff_archive_set_magic (abfd, magic); */
1130 /* Read in the armap of an XCOFF archive. */
1133 _bfd_xcoff_slurp_armap (abfd
)
1139 bfd_byte
*contents
, *cend
;
1144 if (xcoff_ardata (abfd
) == NULL
)
1146 bfd_has_map (abfd
) = FALSE
;
1150 if (! xcoff_big_format_p (abfd
))
1152 /* This is for the old format. */
1153 struct xcoff_ar_hdr hdr
;
1155 off
= strtol (xcoff_ardata (abfd
)->symoff
, (char **) NULL
, 10);
1158 bfd_has_map (abfd
) = FALSE
;
1162 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0)
1165 /* The symbol table starts with a normal archive header. */
1166 if (bfd_bread ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1170 /* Skip the name (normally empty). */
1171 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1172 off
= ((namlen
+ 1) & ~ (size_t) 1) + SXCOFFARFMAG
;
1173 if (bfd_seek (abfd
, off
, SEEK_CUR
) != 0)
1176 sz
= strtol (hdr
.size
, (char **) NULL
, 10);
1178 /* Read in the entire symbol table. */
1179 contents
= (bfd_byte
*) bfd_alloc (abfd
, sz
);
1180 if (contents
== NULL
)
1182 if (bfd_bread ((PTR
) contents
, sz
, abfd
) != sz
)
1185 /* The symbol table starts with a four byte count. */
1186 c
= H_GET_32 (abfd
, contents
);
1190 bfd_set_error (bfd_error_bad_value
);
1194 bfd_ardata (abfd
)->symdefs
=
1195 ((carsym
*) bfd_alloc (abfd
, c
* sizeof (carsym
)));
1196 if (bfd_ardata (abfd
)->symdefs
== NULL
)
1199 /* After the count comes a list of four byte file offsets. */
1200 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
, p
= contents
+ 4;
1202 ++i
, ++arsym
, p
+= 4)
1203 arsym
->file_offset
= H_GET_32 (abfd
, p
);
1207 /* This is for the new format. */
1208 struct xcoff_ar_hdr_big hdr
;
1210 off
= strtol (xcoff_ardata_big (abfd
)->symoff
, (char **) NULL
, 10);
1213 bfd_has_map (abfd
) = FALSE
;
1217 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0)
1220 /* The symbol table starts with a normal archive header. */
1221 if (bfd_bread ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR_BIG
, abfd
)
1222 != SIZEOF_AR_HDR_BIG
)
1225 /* Skip the name (normally empty). */
1226 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1227 off
= ((namlen
+ 1) & ~ (size_t) 1) + SXCOFFARFMAG
;
1228 if (bfd_seek (abfd
, off
, SEEK_CUR
) != 0)
1231 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1232 machines) since the field width is 20 and there numbers with more
1233 than 32 bits can be represented. */
1234 sz
= strtol (hdr
.size
, (char **) NULL
, 10);
1236 /* Read in the entire symbol table. */
1237 contents
= (bfd_byte
*) bfd_alloc (abfd
, sz
);
1238 if (contents
== NULL
)
1240 if (bfd_bread ((PTR
) contents
, sz
, abfd
) != sz
)
1243 /* The symbol table starts with an eight byte count. */
1244 c
= H_GET_64 (abfd
, contents
);
1248 bfd_set_error (bfd_error_bad_value
);
1252 bfd_ardata (abfd
)->symdefs
=
1253 ((carsym
*) bfd_alloc (abfd
, c
* sizeof (carsym
)));
1254 if (bfd_ardata (abfd
)->symdefs
== NULL
)
1257 /* After the count comes a list of eight byte file offsets. */
1258 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
, p
= contents
+ 8;
1260 ++i
, ++arsym
, p
+= 8)
1261 arsym
->file_offset
= H_GET_64 (abfd
, p
);
1264 /* After the file offsets come null terminated symbol names. */
1265 cend
= contents
+ sz
;
1266 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
;
1268 ++i
, ++arsym
, p
+= strlen ((char *) p
) + 1)
1272 bfd_set_error (bfd_error_bad_value
);
1275 arsym
->name
= (char *) p
;
1278 bfd_ardata (abfd
)->symdef_count
= c
;
1279 bfd_has_map (abfd
) = TRUE
;
1284 /* See if this is an XCOFF archive. */
1287 _bfd_xcoff_archive_p (abfd
)
1290 struct artdata
*tdata_hold
;
1291 char magic
[SXCOFFARMAG
];
1292 bfd_size_type amt
= SXCOFFARMAG
;
1294 if (bfd_bread ((PTR
) magic
, amt
, abfd
) != amt
)
1296 if (bfd_get_error () != bfd_error_system_call
)
1297 bfd_set_error (bfd_error_wrong_format
);
1301 if (strncmp (magic
, XCOFFARMAG
, SXCOFFARMAG
) != 0
1302 && strncmp (magic
, XCOFFARMAGBIG
, SXCOFFARMAG
) != 0)
1304 bfd_set_error (bfd_error_wrong_format
);
1308 tdata_hold
= bfd_ardata (abfd
);
1310 amt
= sizeof (struct artdata
);
1311 bfd_ardata (abfd
) = (struct artdata
*) bfd_zalloc (abfd
, amt
);
1312 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
1313 goto error_ret_restore
;
1315 /* Cleared by bfd_zalloc above.
1316 bfd_ardata (abfd)->cache = NULL;
1317 bfd_ardata (abfd)->archive_head = NULL;
1318 bfd_ardata (abfd)->symdefs = NULL;
1319 bfd_ardata (abfd)->extended_names = NULL;
1320 bfd_ardata (abfd)->extended_names_size = 0; */
1322 /* Now handle the two formats. */
1323 if (magic
[1] != 'b')
1325 /* This is the old format. */
1326 struct xcoff_ar_file_hdr hdr
;
1328 /* Copy over the magic string. */
1329 memcpy (hdr
.magic
, magic
, SXCOFFARMAG
);
1331 /* Now read the rest of the file header. */
1332 amt
= SIZEOF_AR_FILE_HDR
- SXCOFFARMAG
;
1333 if (bfd_bread ((PTR
) &hdr
.memoff
, amt
, abfd
) != amt
)
1335 if (bfd_get_error () != bfd_error_system_call
)
1336 bfd_set_error (bfd_error_wrong_format
);
1340 bfd_ardata (abfd
)->first_file_filepos
= strtol (hdr
.firstmemoff
,
1341 (char **) NULL
, 10);
1343 amt
= SIZEOF_AR_FILE_HDR
;
1344 bfd_ardata (abfd
)->tdata
= bfd_zalloc (abfd
, amt
);
1345 if (bfd_ardata (abfd
)->tdata
== NULL
)
1348 memcpy (bfd_ardata (abfd
)->tdata
, &hdr
, SIZEOF_AR_FILE_HDR
);
1352 /* This is the new format. */
1353 struct xcoff_ar_file_hdr_big hdr
;
1355 /* Copy over the magic string. */
1356 memcpy (hdr
.magic
, magic
, SXCOFFARMAG
);
1358 /* Now read the rest of the file header. */
1359 amt
= SIZEOF_AR_FILE_HDR_BIG
- SXCOFFARMAG
;
1360 if (bfd_bread ((PTR
) &hdr
.memoff
, amt
, abfd
) != amt
)
1362 if (bfd_get_error () != bfd_error_system_call
)
1363 bfd_set_error (bfd_error_wrong_format
);
1367 bfd_ardata (abfd
)->first_file_filepos
= bfd_scan_vma (hdr
.firstmemoff
,
1371 amt
= SIZEOF_AR_FILE_HDR_BIG
;
1372 bfd_ardata (abfd
)->tdata
= bfd_zalloc (abfd
, amt
);
1373 if (bfd_ardata (abfd
)->tdata
== NULL
)
1376 memcpy (bfd_ardata (abfd
)->tdata
, &hdr
, SIZEOF_AR_FILE_HDR_BIG
);
1379 if (! _bfd_xcoff_slurp_armap (abfd
))
1382 bfd_release (abfd
, bfd_ardata (abfd
));
1384 bfd_ardata (abfd
) = tdata_hold
;
1391 /* Read the archive header in an XCOFF archive. */
1394 _bfd_xcoff_read_ar_hdr (abfd
)
1397 bfd_size_type namlen
;
1398 struct areltdata
*ret
;
1399 bfd_size_type amt
= sizeof (struct areltdata
);
1401 ret
= (struct areltdata
*) bfd_alloc (abfd
, amt
);
1405 if (! xcoff_big_format_p (abfd
))
1407 struct xcoff_ar_hdr hdr
;
1408 struct xcoff_ar_hdr
*hdrp
;
1410 if (bfd_bread ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1417 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1418 amt
= SIZEOF_AR_HDR
+ namlen
+ 1;
1419 hdrp
= (struct xcoff_ar_hdr
*) bfd_alloc (abfd
, amt
);
1425 memcpy (hdrp
, &hdr
, SIZEOF_AR_HDR
);
1426 if (bfd_bread ((char *) hdrp
+ SIZEOF_AR_HDR
, namlen
, abfd
) != namlen
)
1431 ((char *) hdrp
)[SIZEOF_AR_HDR
+ namlen
] = '\0';
1433 ret
->arch_header
= (char *) hdrp
;
1434 ret
->parsed_size
= strtol (hdr
.size
, (char **) NULL
, 10);
1435 ret
->filename
= (char *) hdrp
+ SIZEOF_AR_HDR
;
1439 struct xcoff_ar_hdr_big hdr
;
1440 struct xcoff_ar_hdr_big
*hdrp
;
1442 if (bfd_bread ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR_BIG
, abfd
)
1443 != SIZEOF_AR_HDR_BIG
)
1449 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1450 amt
= SIZEOF_AR_HDR_BIG
+ namlen
+ 1;
1451 hdrp
= (struct xcoff_ar_hdr_big
*) bfd_alloc (abfd
, amt
);
1457 memcpy (hdrp
, &hdr
, SIZEOF_AR_HDR_BIG
);
1458 if (bfd_bread ((char *) hdrp
+ SIZEOF_AR_HDR_BIG
, namlen
, abfd
) != namlen
)
1463 ((char *) hdrp
)[SIZEOF_AR_HDR_BIG
+ namlen
] = '\0';
1465 ret
->arch_header
= (char *) hdrp
;
1466 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1467 machines) since the field width is 20 and there numbers with more
1468 than 32 bits can be represented. */
1469 ret
->parsed_size
= strtol (hdr
.size
, (char **) NULL
, 10);
1470 ret
->filename
= (char *) hdrp
+ SIZEOF_AR_HDR_BIG
;
1473 /* Skip over the XCOFFARFMAG at the end of the file name. */
1474 if (bfd_seek (abfd
, (file_ptr
) ((namlen
& 1) + SXCOFFARFMAG
), SEEK_CUR
) != 0)
1480 /* Open the next element in an XCOFF archive. */
1483 _bfd_xcoff_openr_next_archived_file (archive
, last_file
)
1489 if (xcoff_ardata (archive
) == NULL
)
1491 bfd_set_error (bfd_error_invalid_operation
);
1495 if (! xcoff_big_format_p (archive
))
1497 if (last_file
== NULL
)
1498 filestart
= bfd_ardata (archive
)->first_file_filepos
;
1500 filestart
= strtol (arch_xhdr (last_file
)->nextoff
, (char **) NULL
,
1504 || filestart
== strtol (xcoff_ardata (archive
)->memoff
,
1506 || filestart
== strtol (xcoff_ardata (archive
)->symoff
,
1507 (char **) NULL
, 10))
1509 bfd_set_error (bfd_error_no_more_archived_files
);
1515 if (last_file
== NULL
)
1516 filestart
= bfd_ardata (archive
)->first_file_filepos
;
1518 /* XXX These actually have to be a calls to strtoll (at least
1519 on 32-bit machines) since the fields's width is 20 and
1520 there numbers with more than 32 bits can be represented. */
1521 filestart
= strtol (arch_xhdr_big (last_file
)->nextoff
, (char **) NULL
,
1524 /* XXX These actually have to be calls to strtoll (at least on 32-bit
1525 machines) since the fields's width is 20 and there numbers with more
1526 than 32 bits can be represented. */
1528 || filestart
== strtol (xcoff_ardata_big (archive
)->memoff
,
1530 || filestart
== strtol (xcoff_ardata_big (archive
)->symoff
,
1531 (char **) NULL
, 10))
1533 bfd_set_error (bfd_error_no_more_archived_files
);
1538 return _bfd_get_elt_at_filepos (archive
, filestart
);
1541 /* Stat an element in an XCOFF archive. */
1544 _bfd_xcoff_stat_arch_elt (abfd
, s
)
1548 if (abfd
->arelt_data
== NULL
)
1550 bfd_set_error (bfd_error_invalid_operation
);
1554 if (! xcoff_big_format_p (abfd
->my_archive
))
1556 struct xcoff_ar_hdr
*hdrp
= arch_xhdr (abfd
);
1558 s
->st_mtime
= strtol (hdrp
->date
, (char **) NULL
, 10);
1559 s
->st_uid
= strtol (hdrp
->uid
, (char **) NULL
, 10);
1560 s
->st_gid
= strtol (hdrp
->gid
, (char **) NULL
, 10);
1561 s
->st_mode
= strtol (hdrp
->mode
, (char **) NULL
, 8);
1562 s
->st_size
= arch_eltdata (abfd
)->parsed_size
;
1566 struct xcoff_ar_hdr_big
*hdrp
= arch_xhdr_big (abfd
);
1568 s
->st_mtime
= strtol (hdrp
->date
, (char **) NULL
, 10);
1569 s
->st_uid
= strtol (hdrp
->uid
, (char **) NULL
, 10);
1570 s
->st_gid
= strtol (hdrp
->gid
, (char **) NULL
, 10);
1571 s
->st_mode
= strtol (hdrp
->mode
, (char **) NULL
, 8);
1572 s
->st_size
= arch_eltdata (abfd
)->parsed_size
;
1578 /* Normalize a file name for inclusion in an archive. */
1581 normalize_filename (abfd
)
1585 const char *filename
;
1587 file
= bfd_get_filename (abfd
);
1588 filename
= strrchr (file
, '/');
1589 if (filename
!= NULL
)
1596 /* Write out an XCOFF armap. */
1599 xcoff_write_armap_old (abfd
, elength
, map
, orl_count
, stridx
)
1601 unsigned int elength ATTRIBUTE_UNUSED
;
1603 unsigned int orl_count
;
1606 struct xcoff_ar_hdr hdr
;
1608 unsigned char buf
[4];
1613 memset (&hdr
, 0, sizeof hdr
);
1614 sprintf (hdr
.size
, "%ld", (long) (4 + orl_count
* 4 + stridx
));
1615 sprintf (hdr
.nextoff
, "%d", 0);
1616 memcpy (hdr
.prevoff
, xcoff_ardata (abfd
)->memoff
, XCOFFARMAG_ELEMENT_SIZE
);
1617 sprintf (hdr
.date
, "%d", 0);
1618 sprintf (hdr
.uid
, "%d", 0);
1619 sprintf (hdr
.gid
, "%d", 0);
1620 sprintf (hdr
.mode
, "%d", 0);
1621 sprintf (hdr
.namlen
, "%d", 0);
1623 /* We need spaces, not null bytes, in the header. */
1624 for (p
= (char *) &hdr
; p
< (char *) &hdr
+ SIZEOF_AR_HDR
; p
++)
1628 if (bfd_bwrite ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1630 || (bfd_bwrite (XCOFFARFMAG
, (bfd_size_type
) SXCOFFARFMAG
, abfd
)
1634 H_PUT_32 (abfd
, orl_count
, buf
);
1635 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
1638 sub
= abfd
->archive_head
;
1639 fileoff
= SIZEOF_AR_FILE_HDR
;
1641 while (sub
!= NULL
&& i
< orl_count
)
1645 while (map
[i
].u
.abfd
== sub
)
1647 H_PUT_32 (abfd
, fileoff
, buf
);
1648 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
1652 namlen
= strlen (normalize_filename (sub
));
1653 namlen
= (namlen
+ 1) &~ (size_t) 1;
1654 fileoff
+= (SIZEOF_AR_HDR
1657 + arelt_size (sub
));
1658 fileoff
= (fileoff
+ 1) &~ 1;
1659 sub
= sub
->archive_next
;
1662 for (i
= 0; i
< orl_count
; i
++)
1667 name
= *map
[i
].name
;
1668 namlen
= strlen (name
);
1669 if (bfd_bwrite (name
, (bfd_size_type
) (namlen
+ 1), abfd
) != namlen
+ 1)
1673 if ((stridx
& 1) != 0)
1678 if (bfd_bwrite (&b
, (bfd_size_type
) 1, abfd
) != 1)
1685 static char buff20
[XCOFFARMAGBIG_ELEMENT_SIZE
+ 1];
1686 #define FMT20 "%-20lld"
1687 #define FMT12 "%-12d"
1688 #define FMT12_OCTAL "%-12o"
1690 #define PRINT20(d, v) \
1691 sprintf (buff20, FMT20, (long long)(v)), \
1692 memcpy ((void *) (d), buff20, 20)
1694 #define PRINT12(d, v) \
1695 sprintf (buff20, FMT12, (int)(v)), \
1696 memcpy ((void *) (d), buff20, 12)
1698 #define PRINT12_OCTAL(d, v) \
1699 sprintf (buff20, FMT12_OCTAL, (unsigned int)(v)), \
1700 memcpy ((void *) (d), buff20, 12)
1702 #define PRINT4(d, v) \
1703 sprintf (buff20, FMT4, (int)(v)), \
1704 memcpy ((void *) (d), buff20, 4)
1706 #define READ20(d, v) \
1708 memcpy (buff20, (d), 20), \
1709 (v) = bfd_scan_vma (buff20, (const char **) NULL, 10)
1712 do_pad (abfd
, number
)
1714 unsigned int number
;
1718 /* Limit pad to <= 4096. */
1723 if (bfd_bwrite (&b
, (bfd_size_type
) 1, abfd
) != 1)
1730 do_copy (out_bfd
, in_bfd
)
1734 bfd_size_type remaining
;
1735 bfd_byte buffer
[DEFAULT_BUFFERSIZE
];
1737 if (bfd_seek (in_bfd
, (file_ptr
) 0, SEEK_SET
) != 0)
1740 remaining
= arelt_size (in_bfd
);
1742 while (remaining
>= DEFAULT_BUFFERSIZE
)
1744 if (bfd_bread (buffer
, DEFAULT_BUFFERSIZE
, in_bfd
) != DEFAULT_BUFFERSIZE
1745 || bfd_bwrite (buffer
, DEFAULT_BUFFERSIZE
, out_bfd
) != DEFAULT_BUFFERSIZE
)
1748 remaining
-= DEFAULT_BUFFERSIZE
;
1753 if (bfd_bread (buffer
, remaining
, in_bfd
) != remaining
1754 || bfd_bwrite (buffer
, remaining
, out_bfd
) != remaining
)
1762 do_shared_object_padding (out_bfd
, in_bfd
, offset
, ar_header_size
)
1768 if (bfd_check_format (in_bfd
, bfd_object
)
1769 && bfd_get_flavour (in_bfd
) == bfd_target_xcoff_flavour
1770 && (in_bfd
->flags
& DYNAMIC
) != 0)
1772 bfd_size_type pad
= 0;
1773 int text_align_power
;
1775 text_align_power
= bfd_xcoff_text_align_power (in_bfd
);
1777 pad
= 1 << text_align_power
;
1778 pad
-= (*offset
+ ar_header_size
) & (pad
- 1);
1780 if (! do_pad (out_bfd
, pad
))
1790 xcoff_write_armap_big (abfd
, elength
, map
, orl_count
, stridx
)
1792 unsigned int elength ATTRIBUTE_UNUSED
;
1794 unsigned int orl_count
;
1797 struct xcoff_ar_file_hdr_big
*fhdr
;
1798 bfd_vma i
, sym_32
, sym_64
, str_32
, str_64
;
1799 const bfd_arch_info_type
*arch_info
= NULL
;
1801 size_t string_length
;
1802 file_ptr nextoff
, prevoff
;
1804 /* First, we look through the symbols and work out which are
1805 from 32-bit objects and which from 64-bit ones. */
1806 sym_32
= sym_64
= str_32
= str_64
= 0;
1808 current_bfd
= abfd
->archive_head
;
1809 if (current_bfd
!= NULL
)
1810 arch_info
= bfd_get_arch_info (current_bfd
);
1812 while (current_bfd
!= NULL
&& i
< orl_count
)
1814 while (map
[i
].u
.abfd
== current_bfd
)
1816 string_length
= strlen (*map
[i
].name
) + 1;
1818 if (arch_info
->bits_per_address
== 64)
1821 str_64
+= string_length
;
1826 str_32
+= string_length
;
1830 current_bfd
= current_bfd
->archive_next
;
1831 if (current_bfd
!= NULL
)
1832 arch_info
= bfd_get_arch_info (current_bfd
);
1835 /* A quick sanity check... */
1836 BFD_ASSERT (sym_64
+ sym_32
== orl_count
);
1837 /* Explicit cast to int for compiler. */
1838 BFD_ASSERT ((int)(str_64
+ str_32
) == stridx
);
1840 fhdr
= xcoff_ardata_big (abfd
);
1842 /* xcoff_write_archive_contents_big passes nextoff in symoff. */
1843 READ20 (fhdr
->memoff
, prevoff
);
1844 READ20 (fhdr
->symoff
, nextoff
);
1846 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
1848 /* Write out the symbol table.
1851 standard big archive header
1852 0x0000 ar_size [0x14]
1853 0x0014 ar_nxtmem [0x14]
1854 0x0028 ar_prvmem [0x14]
1855 0x003C ar_date [0x0C]
1856 0x0048 ar_uid [0x0C]
1857 0x0054 ar_gid [0x0C]
1858 0x0060 ar_mod [0x0C]
1859 0x006C ar_namelen[0x04]
1860 0x0070 ar_fmag [SXCOFFARFMAG]
1863 0x0072 num_syms [0x08], binary
1864 0x0078 offsets [0x08 * num_syms], binary
1865 0x0086 + 0x08 * num_syms names [??]
1866 ?? pad to even bytes.
1871 struct xcoff_ar_hdr_big
*hdr
;
1876 bfd_vma symbol_table_size
=
1881 + str_32
+ (str_32
& 1);
1883 symbol_table
= bfd_zmalloc (symbol_table_size
);
1884 if (symbol_table
== NULL
)
1887 hdr
= (struct xcoff_ar_hdr_big
*) symbol_table
;
1889 PRINT20 (hdr
->size
, 8 + 8 * sym_32
+ str_32
+ (str_32
& 1));
1892 PRINT20 (hdr
->nextoff
, nextoff
+ symbol_table_size
);
1894 PRINT20 (hdr
->nextoff
, 0);
1896 PRINT20 (hdr
->prevoff
, prevoff
);
1897 PRINT12 (hdr
->date
, 0);
1898 PRINT12 (hdr
->uid
, 0);
1899 PRINT12 (hdr
->gid
, 0);
1900 PRINT12 (hdr
->mode
, 0);
1901 PRINT4 (hdr
->namlen
, 0) ;
1903 st
= symbol_table
+ SIZEOF_AR_HDR_BIG
;
1904 memcpy (st
, XCOFFARFMAG
, SXCOFFARFMAG
);
1907 bfd_h_put_64 (abfd
, sym_32
, st
);
1910 /* loop over the 32 bit offsets */
1911 current_bfd
= abfd
->archive_head
;
1912 if (current_bfd
!= NULL
)
1913 arch_info
= bfd_get_arch_info (current_bfd
);
1914 fileoff
= SIZEOF_AR_FILE_HDR_BIG
;
1916 while (current_bfd
!= NULL
&& i
< orl_count
)
1918 while (map
[i
].u
.abfd
== current_bfd
)
1920 if (arch_info
->bits_per_address
== 32)
1922 bfd_h_put_64 (abfd
, fileoff
, st
);
1927 string_length
= strlen (normalize_filename (current_bfd
));
1928 string_length
+= string_length
& 1;
1929 fileoff
+= (SIZEOF_AR_HDR_BIG
1932 + arelt_size (current_bfd
));
1933 fileoff
+= fileoff
& 1;
1934 current_bfd
= current_bfd
->archive_next
;
1935 if (current_bfd
!= NULL
)
1936 arch_info
= bfd_get_arch_info (current_bfd
);
1939 /* loop over the 32 bit symbol names */
1940 current_bfd
= abfd
->archive_head
;
1941 if (current_bfd
!= NULL
)
1942 arch_info
= bfd_get_arch_info (current_bfd
);
1944 while (current_bfd
!= NULL
&& i
< orl_count
)
1946 while (map
[i
].u
.abfd
== current_bfd
)
1948 if (arch_info
->bits_per_address
== 32)
1950 string_length
= sprintf (st
, "%s", *map
[i
].name
);
1951 st
+= string_length
+ 1;
1955 current_bfd
= current_bfd
->archive_next
;
1956 if (current_bfd
!= NULL
)
1957 arch_info
= bfd_get_arch_info (current_bfd
);
1960 bfd_bwrite (symbol_table
, symbol_table_size
, abfd
);
1962 free (symbol_table
);
1965 nextoff
= nextoff
+ symbol_table_size
;
1968 PRINT20 (fhdr
->symoff
, 0);
1972 struct xcoff_ar_hdr_big
*hdr
;
1977 bfd_vma symbol_table_size
=
1982 + str_64
+ (str_64
& 1);
1984 symbol_table
= bfd_zmalloc (symbol_table_size
);
1985 if (symbol_table
== NULL
)
1988 hdr
= (struct xcoff_ar_hdr_big
*) symbol_table
;
1990 PRINT20 (hdr
->size
, 8 + 8 * sym_64
+ str_64
+ (str_64
& 1));
1991 PRINT20 (hdr
->nextoff
, 0);
1992 PRINT20 (hdr
->prevoff
, prevoff
);
1993 PRINT12 (hdr
->date
, 0);
1994 PRINT12 (hdr
->uid
, 0);
1995 PRINT12 (hdr
->gid
, 0);
1996 PRINT12 (hdr
->mode
, 0);
1997 PRINT4 (hdr
->namlen
, 0);
1999 st
= symbol_table
+ SIZEOF_AR_HDR_BIG
;
2000 memcpy (st
, XCOFFARFMAG
, SXCOFFARFMAG
);
2003 bfd_h_put_64 (abfd
, sym_64
, st
);
2006 /* loop over the 64 bit offsets */
2007 current_bfd
= abfd
->archive_head
;
2008 if (current_bfd
!= NULL
)
2009 arch_info
= bfd_get_arch_info (current_bfd
);
2010 fileoff
= SIZEOF_AR_FILE_HDR_BIG
;
2012 while (current_bfd
!= NULL
&& i
< orl_count
)
2014 while (map
[i
].u
.abfd
== current_bfd
)
2016 if (arch_info
->bits_per_address
== 64)
2018 bfd_h_put_64 (abfd
, fileoff
, st
);
2023 string_length
= strlen (normalize_filename (current_bfd
));
2024 string_length
+= string_length
& 1;
2025 fileoff
+= (SIZEOF_AR_HDR_BIG
2028 + arelt_size (current_bfd
));
2029 fileoff
+= fileoff
& 1;
2030 current_bfd
= current_bfd
->archive_next
;
2031 if (current_bfd
!= NULL
)
2032 arch_info
= bfd_get_arch_info (current_bfd
);
2035 /* loop over the 64 bit symbol names */
2036 current_bfd
= abfd
->archive_head
;
2037 if (current_bfd
!= NULL
)
2038 arch_info
= bfd_get_arch_info (current_bfd
);
2040 while (current_bfd
!= NULL
&& i
< orl_count
)
2042 while (map
[i
].u
.abfd
== current_bfd
)
2044 if (arch_info
->bits_per_address
== 64)
2046 string_length
= sprintf (st
, "%s", *map
[i
].name
);
2047 st
+= string_length
+ 1;
2051 current_bfd
= current_bfd
->archive_next
;
2052 if (current_bfd
!= NULL
)
2053 arch_info
= bfd_get_arch_info (current_bfd
);
2056 bfd_bwrite (symbol_table
, symbol_table_size
, abfd
);
2058 free (symbol_table
);
2060 PRINT20 (fhdr
->symoff64
, nextoff
);
2063 PRINT20 (fhdr
->symoff64
, 0);
2069 _bfd_xcoff_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
2071 unsigned int elength ATTRIBUTE_UNUSED
;
2073 unsigned int orl_count
;
2076 if (! xcoff_big_format_p (abfd
))
2077 return xcoff_write_armap_old (abfd
, elength
, map
, orl_count
, stridx
);
2079 return xcoff_write_armap_big (abfd
, elength
, map
, orl_count
, stridx
);
2082 /* Write out an XCOFF archive. We always write an entire archive,
2083 rather than fussing with the freelist and so forth. */
2086 xcoff_write_archive_contents_old (abfd
)
2089 struct xcoff_ar_file_hdr fhdr
;
2090 bfd_size_type count
;
2091 bfd_size_type total_namlen
;
2093 bfd_boolean makemap
;
2094 bfd_boolean hasobjects
;
2095 file_ptr prevoff
, nextoff
;
2098 struct xcoff_ar_hdr ahdr
;
2101 char decbuf
[XCOFFARMAG_ELEMENT_SIZE
+ 1];
2103 memset (&fhdr
, 0, sizeof fhdr
);
2104 (void) strncpy (fhdr
.magic
, XCOFFARMAG
, SXCOFFARMAG
);
2105 sprintf (fhdr
.firstmemoff
, "%d", SIZEOF_AR_FILE_HDR
);
2106 sprintf (fhdr
.freeoff
, "%d", 0);
2110 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->archive_next
)
2113 total_namlen
+= strlen (normalize_filename (sub
)) + 1;
2115 offsets
= (file_ptr
*) bfd_alloc (abfd
, count
* sizeof (file_ptr
));
2116 if (offsets
== NULL
)
2119 if (bfd_seek (abfd
, (file_ptr
) SIZEOF_AR_FILE_HDR
, SEEK_SET
) != 0)
2122 makemap
= bfd_has_map (abfd
);
2125 nextoff
= SIZEOF_AR_FILE_HDR
;
2126 for (sub
= abfd
->archive_head
, i
= 0;
2128 sub
= sub
->archive_next
, i
++)
2131 bfd_size_type namlen
;
2132 struct xcoff_ar_hdr
*ahdrp
;
2133 bfd_size_type remaining
;
2135 if (makemap
&& ! hasobjects
)
2137 if (bfd_check_format (sub
, bfd_object
))
2141 name
= normalize_filename (sub
);
2142 namlen
= strlen (name
);
2144 if (sub
->arelt_data
!= NULL
)
2145 ahdrp
= arch_xhdr (sub
);
2153 memset (&ahdr
, 0, sizeof ahdr
);
2155 if (stat (bfd_get_filename (sub
), &s
) != 0)
2157 bfd_set_error (bfd_error_system_call
);
2161 sprintf (ahdrp
->size
, "%ld", (long) s
.st_size
);
2162 sprintf (ahdrp
->date
, "%ld", (long) s
.st_mtime
);
2163 sprintf (ahdrp
->uid
, "%ld", (long) s
.st_uid
);
2164 sprintf (ahdrp
->gid
, "%ld", (long) s
.st_gid
);
2165 sprintf (ahdrp
->mode
, "%o", (unsigned int) s
.st_mode
);
2167 if (sub
->arelt_data
== NULL
)
2169 size
= sizeof (struct areltdata
);
2170 sub
->arelt_data
= bfd_alloc (sub
, size
);
2171 if (sub
->arelt_data
== NULL
)
2175 arch_eltdata (sub
)->parsed_size
= s
.st_size
;
2178 sprintf (ahdrp
->prevoff
, "%ld", (long) prevoff
);
2179 sprintf (ahdrp
->namlen
, "%ld", (long) namlen
);
2181 /* If the length of the name is odd, we write out the null byte
2182 after the name as well. */
2183 namlen
= (namlen
+ 1) &~ (bfd_size_type
) 1;
2185 remaining
= arelt_size (sub
);
2186 size
= (SIZEOF_AR_HDR
2191 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2193 offsets
[i
] = nextoff
;
2196 nextoff
+= size
+ (size
& 1);
2198 sprintf (ahdrp
->nextoff
, "%ld", (long) nextoff
);
2200 /* We need spaces, not null bytes, in the header. */
2201 for (p
= (char *) ahdrp
; p
< (char *) ahdrp
+ SIZEOF_AR_HDR
; p
++)
2205 if ((bfd_bwrite ((PTR
) ahdrp
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
2207 || bfd_bwrite ((PTR
) name
, namlen
, abfd
) != namlen
2208 || bfd_bwrite ((PTR
) XCOFFARFMAG
, (bfd_size_type
) SXCOFFARFMAG
,
2209 abfd
) != SXCOFFARFMAG
)
2212 if (bfd_seek (sub
, (file_ptr
) 0, SEEK_SET
) != 0)
2215 if (! do_copy (abfd
, sub
))
2218 if (! do_pad (abfd
, size
& 1))
2222 sprintf (fhdr
.lastmemoff
, "%ld", (long) prevoff
);
2224 /* Write out the member table. */
2226 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2227 sprintf (fhdr
.memoff
, "%ld", (long) nextoff
);
2229 memset (&ahdr
, 0, sizeof ahdr
);
2230 sprintf (ahdr
.size
, "%ld", (long) (XCOFFARMAG_ELEMENT_SIZE
2231 + count
* XCOFFARMAG_ELEMENT_SIZE
2233 sprintf (ahdr
.prevoff
, "%ld", (long) prevoff
);
2234 sprintf (ahdr
.date
, "%d", 0);
2235 sprintf (ahdr
.uid
, "%d", 0);
2236 sprintf (ahdr
.gid
, "%d", 0);
2237 sprintf (ahdr
.mode
, "%d", 0);
2238 sprintf (ahdr
.namlen
, "%d", 0);
2240 size
= (SIZEOF_AR_HDR
2241 + XCOFFARMAG_ELEMENT_SIZE
2242 + count
* XCOFFARMAG_ELEMENT_SIZE
2247 nextoff
+= size
+ (size
& 1);
2249 if (makemap
&& hasobjects
)
2250 sprintf (ahdr
.nextoff
, "%ld", (long) nextoff
);
2252 sprintf (ahdr
.nextoff
, "%d", 0);
2254 /* We need spaces, not null bytes, in the header. */
2255 for (p
= (char *) &ahdr
; p
< (char *) &ahdr
+ SIZEOF_AR_HDR
; p
++)
2259 if ((bfd_bwrite ((PTR
) &ahdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
2261 || (bfd_bwrite ((PTR
) XCOFFARFMAG
, (bfd_size_type
) SXCOFFARFMAG
, abfd
)
2265 sprintf (decbuf
, "%-12ld", (long) count
);
2266 if (bfd_bwrite ((PTR
) decbuf
, (bfd_size_type
) XCOFFARMAG_ELEMENT_SIZE
, abfd
)
2267 != XCOFFARMAG_ELEMENT_SIZE
)
2269 for (i
= 0; i
< (size_t) count
; i
++)
2271 sprintf (decbuf
, "%-12ld", (long) offsets
[i
]);
2272 if (bfd_bwrite ((PTR
) decbuf
, (bfd_size_type
) XCOFFARMAG_ELEMENT_SIZE
,
2273 abfd
) != XCOFFARMAG_ELEMENT_SIZE
)
2276 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->archive_next
)
2279 bfd_size_type namlen
;
2281 name
= normalize_filename (sub
);
2282 namlen
= strlen (name
);
2283 if (bfd_bwrite ((PTR
) name
, namlen
+ 1, abfd
) != namlen
+ 1)
2287 if (! do_pad (abfd
, size
& 1))
2290 /* Write out the armap, if appropriate. */
2291 if (! makemap
|| ! hasobjects
)
2292 sprintf (fhdr
.symoff
, "%d", 0);
2295 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2296 sprintf (fhdr
.symoff
, "%ld", (long) nextoff
);
2297 bfd_ardata (abfd
)->tdata
= (PTR
) &fhdr
;
2298 if (! _bfd_compute_and_write_armap (abfd
, 0))
2302 /* Write out the archive file header. */
2304 /* We need spaces, not null bytes, in the header. */
2305 for (p
= (char *) &fhdr
; p
< (char *) &fhdr
+ SIZEOF_AR_FILE_HDR
; p
++)
2309 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
2310 || (bfd_bwrite ((PTR
) &fhdr
, (bfd_size_type
) SIZEOF_AR_FILE_HDR
, abfd
)
2311 != SIZEOF_AR_FILE_HDR
))
2318 xcoff_write_archive_contents_big (abfd
)
2321 struct xcoff_ar_file_hdr_big fhdr
;
2322 bfd_size_type count
;
2323 bfd_size_type total_namlen
;
2325 bfd_boolean makemap
;
2326 bfd_boolean hasobjects
;
2327 file_ptr prevoff
, nextoff
;
2330 struct xcoff_ar_hdr_big
*hdr
, ahdr
;
2332 char *member_table
, *mt
;
2333 bfd_vma member_table_size
;
2335 memset (&fhdr
, 0, SIZEOF_AR_FILE_HDR_BIG
);
2336 memcpy (fhdr
.magic
, XCOFFARMAGBIG
, SXCOFFARMAG
);
2338 if (bfd_seek (abfd
, (file_ptr
) SIZEOF_AR_FILE_HDR_BIG
, SEEK_SET
) != 0)
2341 /* Calculate count and total_namlen. */
2342 makemap
= bfd_has_map (abfd
);
2344 for (current_bfd
= abfd
->archive_head
, count
= 0, total_namlen
= 0;
2345 current_bfd
!= NULL
;
2346 current_bfd
= current_bfd
->archive_next
, count
++)
2348 total_namlen
+= strlen (normalize_filename (current_bfd
)) + 1;
2352 && bfd_check_format (current_bfd
, bfd_object
))
2359 offsets
= (file_ptr
*) bfd_malloc (count
* sizeof (file_ptr
));
2360 if (offsets
== NULL
)
2365 nextoff
= SIZEOF_AR_FILE_HDR_BIG
;
2366 for (current_bfd
= abfd
->archive_head
, i
= 0;
2367 current_bfd
!= NULL
;
2368 current_bfd
= current_bfd
->archive_next
, i
++)
2371 bfd_size_type namlen
;
2372 struct xcoff_ar_hdr_big
*ahdrp
;
2373 bfd_size_type remaining
;
2375 name
= normalize_filename (current_bfd
);
2376 namlen
= strlen (name
);
2378 if (current_bfd
->arelt_data
!= NULL
)
2379 ahdrp
= arch_xhdr_big (current_bfd
);
2388 /* XXX This should actually be a call to stat64 (at least on
2390 XXX This call will fail if the original object is not found. */
2391 if (stat (bfd_get_filename (current_bfd
), &s
) != 0)
2393 bfd_set_error (bfd_error_system_call
);
2397 PRINT20 (ahdrp
->size
, s
.st_size
);
2398 PRINT12 (ahdrp
->date
, s
.st_mtime
);
2399 PRINT12 (ahdrp
->uid
, s
.st_uid
);
2400 PRINT12 (ahdrp
->gid
, s
.st_gid
);
2401 PRINT12_OCTAL (ahdrp
->mode
, s
.st_mode
);
2403 if (current_bfd
->arelt_data
== NULL
)
2405 size
= sizeof (struct areltdata
);
2406 current_bfd
->arelt_data
= bfd_alloc (current_bfd
, size
);
2407 if (current_bfd
->arelt_data
== NULL
)
2411 arch_eltdata (current_bfd
)->parsed_size
= s
.st_size
;
2414 PRINT20 (ahdrp
->prevoff
, prevoff
);
2415 PRINT4 (ahdrp
->namlen
, namlen
);
2417 /* If the length of the name is odd, we write out the null byte
2418 after the name as well. */
2419 namlen
= (namlen
+ 1) &~ (bfd_size_type
) 1;
2421 remaining
= arelt_size (current_bfd
);
2422 size
= (SIZEOF_AR_HDR_BIG
2427 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2429 /* Check for xcoff shared objects.
2430 Their text section needs to be aligned wrt the archive file position.
2431 This requires extra padding before the archive header. */
2432 if (! do_shared_object_padding (abfd
, current_bfd
, & nextoff
,
2433 SIZEOF_AR_HDR_BIG
+ namlen
2437 offsets
[i
] = nextoff
;
2440 nextoff
+= size
+ (size
& 1);
2442 PRINT20 (ahdrp
->nextoff
, nextoff
);
2444 if ((bfd_bwrite ((PTR
) ahdrp
, (bfd_size_type
) SIZEOF_AR_HDR_BIG
, abfd
)
2445 != SIZEOF_AR_HDR_BIG
)
2446 || bfd_bwrite ((PTR
) name
, (bfd_size_type
) namlen
, abfd
) != namlen
2447 || (bfd_bwrite ((PTR
) XCOFFARFMAG
, (bfd_size_type
) SXCOFFARFMAG
,
2448 abfd
) != SXCOFFARFMAG
))
2451 if (bfd_seek (current_bfd
, (file_ptr
) 0, SEEK_SET
) != 0)
2454 if (! do_copy (abfd
, current_bfd
))
2457 if (! do_pad (abfd
, size
& 1))
2463 PRINT20 (fhdr
.firstmemoff
, offsets
[0]);
2464 PRINT20 (fhdr
.lastmemoff
, prevoff
);
2467 /* Write out the member table.
2470 standard big archive header
2471 0x0000 ar_size [0x14]
2472 0x0014 ar_nxtmem [0x14]
2473 0x0028 ar_prvmem [0x14]
2474 0x003C ar_date [0x0C]
2475 0x0048 ar_uid [0x0C]
2476 0x0054 ar_gid [0x0C]
2477 0x0060 ar_mod [0x0C]
2478 0x006C ar_namelen[0x04]
2479 0x0070 ar_fmag [0x02]
2483 0x0086 offsets [0x14 * counts]
2484 0x0086 + 0x14 * counts names [??]
2485 ?? pad to even bytes.
2488 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2490 member_table_size
= (SIZEOF_AR_HDR_BIG
2492 + XCOFFARMAGBIG_ELEMENT_SIZE
2493 + count
* XCOFFARMAGBIG_ELEMENT_SIZE
2496 member_table_size
+= member_table_size
& 1;
2497 member_table
= bfd_zmalloc (member_table_size
);
2498 if (member_table
== NULL
)
2501 hdr
= (struct xcoff_ar_hdr_big
*) member_table
;
2503 PRINT20 (hdr
->size
, (XCOFFARMAGBIG_ELEMENT_SIZE
2504 + count
* XCOFFARMAGBIG_ELEMENT_SIZE
2505 + total_namlen
+ (total_namlen
& 1)));
2506 if (makemap
&& hasobjects
)
2507 PRINT20 (hdr
->nextoff
, nextoff
+ member_table_size
);
2509 PRINT20 (hdr
->nextoff
, 0);
2510 PRINT20 (hdr
->prevoff
, prevoff
);
2511 PRINT12 (hdr
->date
, 0);
2512 PRINT12 (hdr
->uid
, 0);
2513 PRINT12 (hdr
->gid
, 0);
2514 PRINT12 (hdr
->mode
, 0);
2515 PRINT4 (hdr
->namlen
, 0);
2517 mt
= member_table
+ SIZEOF_AR_HDR_BIG
;
2518 memcpy (mt
, XCOFFARFMAG
, SXCOFFARFMAG
);
2521 PRINT20 (mt
, count
);
2522 mt
+= XCOFFARMAGBIG_ELEMENT_SIZE
;
2523 for (i
= 0; i
< (size_t) count
; i
++)
2525 PRINT20 (mt
, offsets
[i
]);
2526 mt
+= XCOFFARMAGBIG_ELEMENT_SIZE
;
2535 for (current_bfd
= abfd
->archive_head
;
2536 current_bfd
!= NULL
;
2537 current_bfd
= current_bfd
->archive_next
)
2542 name
= normalize_filename (current_bfd
);
2543 namlen
= sprintf (mt
, "%s", name
);
2547 if (bfd_bwrite (member_table
, member_table_size
, abfd
) != member_table_size
)
2550 free (member_table
);
2552 PRINT20 (fhdr
.memoff
, nextoff
);
2555 nextoff
+= member_table_size
;
2557 /* Write out the armap, if appropriate. */
2559 if (! makemap
|| ! hasobjects
)
2560 PRINT20 (fhdr
.symoff
, 0);
2563 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2565 /* Save nextoff in fhdr.symoff so the armap routine can use it. */
2566 PRINT20 (fhdr
.symoff
, nextoff
);
2568 bfd_ardata (abfd
)->tdata
= (PTR
) &fhdr
;
2569 if (! _bfd_compute_and_write_armap (abfd
, 0))
2573 /* Write out the archive file header. */
2575 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
2576 || (bfd_bwrite ((PTR
) &fhdr
, (bfd_size_type
) SIZEOF_AR_FILE_HDR_BIG
,
2577 abfd
) != SIZEOF_AR_FILE_HDR_BIG
))
2584 _bfd_xcoff_write_archive_contents (abfd
)
2587 if (! xcoff_big_format_p (abfd
))
2588 return xcoff_write_archive_contents_old (abfd
);
2590 return xcoff_write_archive_contents_big (abfd
);
2593 /* We can't use the usual coff_sizeof_headers routine, because AIX
2594 always uses an a.out header. */
2597 _bfd_xcoff_sizeof_headers (bfd
*abfd
,
2598 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
2603 if (xcoff_data (abfd
)->full_aouthdr
)
2606 size
+= SMALL_AOUTSZ
;
2607 size
+= abfd
->section_count
* SCNHSZ
;
2611 /* Routines to swap information in the XCOFF .loader section. If we
2612 ever need to write an XCOFF loader, this stuff will need to be
2613 moved to another file shared by the linker (which XCOFF calls the
2614 ``binder'') and the loader. */
2616 /* Swap in the ldhdr structure. */
2619 xcoff_swap_ldhdr_in (abfd
, s
, dst
)
2622 struct internal_ldhdr
*dst
;
2624 const struct external_ldhdr
*src
= (const struct external_ldhdr
*) s
;
2626 dst
->l_version
= bfd_get_32 (abfd
, src
->l_version
);
2627 dst
->l_nsyms
= bfd_get_32 (abfd
, src
->l_nsyms
);
2628 dst
->l_nreloc
= bfd_get_32 (abfd
, src
->l_nreloc
);
2629 dst
->l_istlen
= bfd_get_32 (abfd
, src
->l_istlen
);
2630 dst
->l_nimpid
= bfd_get_32 (abfd
, src
->l_nimpid
);
2631 dst
->l_impoff
= bfd_get_32 (abfd
, src
->l_impoff
);
2632 dst
->l_stlen
= bfd_get_32 (abfd
, src
->l_stlen
);
2633 dst
->l_stoff
= bfd_get_32 (abfd
, src
->l_stoff
);
2636 /* Swap out the ldhdr structure. */
2639 xcoff_swap_ldhdr_out (abfd
, src
, d
)
2641 const struct internal_ldhdr
*src
;
2644 struct external_ldhdr
*dst
= (struct external_ldhdr
*) d
;
2646 bfd_put_32 (abfd
, (bfd_vma
) src
->l_version
, dst
->l_version
);
2647 bfd_put_32 (abfd
, src
->l_nsyms
, dst
->l_nsyms
);
2648 bfd_put_32 (abfd
, src
->l_nreloc
, dst
->l_nreloc
);
2649 bfd_put_32 (abfd
, src
->l_istlen
, dst
->l_istlen
);
2650 bfd_put_32 (abfd
, src
->l_nimpid
, dst
->l_nimpid
);
2651 bfd_put_32 (abfd
, src
->l_impoff
, dst
->l_impoff
);
2652 bfd_put_32 (abfd
, src
->l_stlen
, dst
->l_stlen
);
2653 bfd_put_32 (abfd
, src
->l_stoff
, dst
->l_stoff
);
2656 /* Swap in the ldsym structure. */
2659 xcoff_swap_ldsym_in (abfd
, s
, dst
)
2662 struct internal_ldsym
*dst
;
2664 const struct external_ldsym
*src
= (const struct external_ldsym
*) s
;
2666 if (bfd_get_32 (abfd
, src
->_l
._l_l
._l_zeroes
) != 0) {
2667 memcpy (dst
->_l
._l_name
, src
->_l
._l_name
, SYMNMLEN
);
2669 dst
->_l
._l_l
._l_zeroes
= 0;
2670 dst
->_l
._l_l
._l_offset
= bfd_get_32 (abfd
, src
->_l
._l_l
._l_offset
);
2672 dst
->l_value
= bfd_get_32 (abfd
, src
->l_value
);
2673 dst
->l_scnum
= bfd_get_16 (abfd
, src
->l_scnum
);
2674 dst
->l_smtype
= bfd_get_8 (abfd
, src
->l_smtype
);
2675 dst
->l_smclas
= bfd_get_8 (abfd
, src
->l_smclas
);
2676 dst
->l_ifile
= bfd_get_32 (abfd
, src
->l_ifile
);
2677 dst
->l_parm
= bfd_get_32 (abfd
, src
->l_parm
);
2680 /* Swap out the ldsym structure. */
2683 xcoff_swap_ldsym_out (abfd
, src
, d
)
2685 const struct internal_ldsym
*src
;
2688 struct external_ldsym
*dst
= (struct external_ldsym
*) d
;
2690 if (src
->_l
._l_l
._l_zeroes
!= 0)
2691 memcpy (dst
->_l
._l_name
, src
->_l
._l_name
, SYMNMLEN
);
2694 bfd_put_32 (abfd
, (bfd_vma
) 0, dst
->_l
._l_l
._l_zeroes
);
2695 bfd_put_32 (abfd
, (bfd_vma
) src
->_l
._l_l
._l_offset
,
2696 dst
->_l
._l_l
._l_offset
);
2698 bfd_put_32 (abfd
, src
->l_value
, dst
->l_value
);
2699 bfd_put_16 (abfd
, (bfd_vma
) src
->l_scnum
, dst
->l_scnum
);
2700 bfd_put_8 (abfd
, src
->l_smtype
, dst
->l_smtype
);
2701 bfd_put_8 (abfd
, src
->l_smclas
, dst
->l_smclas
);
2702 bfd_put_32 (abfd
, src
->l_ifile
, dst
->l_ifile
);
2703 bfd_put_32 (abfd
, src
->l_parm
, dst
->l_parm
);
2707 xcoff_swap_reloc_in (abfd
, s
, d
)
2712 struct external_reloc
*src
= (struct external_reloc
*) s
;
2713 struct internal_reloc
*dst
= (struct internal_reloc
*) d
;
2715 memset (dst
, 0, sizeof (struct internal_reloc
));
2717 dst
->r_vaddr
= bfd_get_32 (abfd
, src
->r_vaddr
);
2718 dst
->r_symndx
= bfd_get_32 (abfd
, src
->r_symndx
);
2719 dst
->r_size
= bfd_get_8 (abfd
, src
->r_size
);
2720 dst
->r_type
= bfd_get_8 (abfd
, src
->r_type
);
2724 xcoff_swap_reloc_out (abfd
, s
, d
)
2729 struct internal_reloc
*src
= (struct internal_reloc
*) s
;
2730 struct external_reloc
*dst
= (struct external_reloc
*) d
;
2732 bfd_put_32 (abfd
, src
->r_vaddr
, dst
->r_vaddr
);
2733 bfd_put_32 (abfd
, src
->r_symndx
, dst
->r_symndx
);
2734 bfd_put_8 (abfd
, src
->r_type
, dst
->r_type
);
2735 bfd_put_8 (abfd
, src
->r_size
, dst
->r_size
);
2737 return bfd_coff_relsz (abfd
);
2740 /* Swap in the ldrel structure. */
2743 xcoff_swap_ldrel_in (abfd
, s
, dst
)
2746 struct internal_ldrel
*dst
;
2748 const struct external_ldrel
*src
= (const struct external_ldrel
*) s
;
2750 dst
->l_vaddr
= bfd_get_32 (abfd
, src
->l_vaddr
);
2751 dst
->l_symndx
= bfd_get_32 (abfd
, src
->l_symndx
);
2752 dst
->l_rtype
= bfd_get_16 (abfd
, src
->l_rtype
);
2753 dst
->l_rsecnm
= bfd_get_16 (abfd
, src
->l_rsecnm
);
2756 /* Swap out the ldrel structure. */
2759 xcoff_swap_ldrel_out (abfd
, src
, d
)
2761 const struct internal_ldrel
*src
;
2764 struct external_ldrel
*dst
= (struct external_ldrel
*) d
;
2766 bfd_put_32 (abfd
, src
->l_vaddr
, dst
->l_vaddr
);
2767 bfd_put_32 (abfd
, src
->l_symndx
, dst
->l_symndx
);
2768 bfd_put_16 (abfd
, (bfd_vma
) src
->l_rtype
, dst
->l_rtype
);
2769 bfd_put_16 (abfd
, (bfd_vma
) src
->l_rsecnm
, dst
->l_rsecnm
);
2774 xcoff_reloc_type_noop (input_bfd
, input_section
, output_bfd
, rel
, sym
, howto
,
2775 val
, addend
, relocation
, contents
)
2776 bfd
*input_bfd ATTRIBUTE_UNUSED
;
2777 asection
*input_section ATTRIBUTE_UNUSED
;
2778 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2779 struct internal_reloc
*rel ATTRIBUTE_UNUSED
;
2780 struct internal_syment
*sym ATTRIBUTE_UNUSED
;
2781 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
;
2782 bfd_vma val ATTRIBUTE_UNUSED
;
2783 bfd_vma addend ATTRIBUTE_UNUSED
;
2784 bfd_vma
*relocation ATTRIBUTE_UNUSED
;
2785 bfd_byte
*contents ATTRIBUTE_UNUSED
;
2791 xcoff_reloc_type_fail (input_bfd
, input_section
, output_bfd
, rel
, sym
, howto
,
2792 val
, addend
, relocation
, contents
)
2794 asection
*input_section ATTRIBUTE_UNUSED
;
2795 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2796 struct internal_reloc
*rel
;
2797 struct internal_syment
*sym ATTRIBUTE_UNUSED
;
2798 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
;
2799 bfd_vma val ATTRIBUTE_UNUSED
;
2800 bfd_vma addend ATTRIBUTE_UNUSED
;
2801 bfd_vma
*relocation ATTRIBUTE_UNUSED
;
2802 bfd_byte
*contents ATTRIBUTE_UNUSED
;
2804 (*_bfd_error_handler
)
2805 (_("%s: unsupported relocation type 0x%02x"),
2806 bfd_get_filename (input_bfd
), (unsigned int) rel
->r_type
);
2807 bfd_set_error (bfd_error_bad_value
);
2812 xcoff_reloc_type_pos (input_bfd
, input_section
, output_bfd
, rel
, sym
, howto
,
2813 val
, addend
, relocation
, contents
)
2814 bfd
*input_bfd ATTRIBUTE_UNUSED
;
2815 asection
*input_section ATTRIBUTE_UNUSED
;
2816 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2817 struct internal_reloc
*rel ATTRIBUTE_UNUSED
;
2818 struct internal_syment
*sym ATTRIBUTE_UNUSED
;
2819 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
;
2822 bfd_vma
*relocation
;
2823 bfd_byte
*contents ATTRIBUTE_UNUSED
;
2825 *relocation
= val
+ addend
;
2830 xcoff_reloc_type_neg (input_bfd
, input_section
, output_bfd
, rel
, sym
, howto
,
2831 val
, addend
, relocation
, contents
)
2832 bfd
*input_bfd ATTRIBUTE_UNUSED
;
2833 asection
*input_section ATTRIBUTE_UNUSED
;
2834 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2835 struct internal_reloc
*rel ATTRIBUTE_UNUSED
;
2836 struct internal_syment
*sym ATTRIBUTE_UNUSED
;
2837 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
;
2840 bfd_vma
*relocation
;
2841 bfd_byte
*contents ATTRIBUTE_UNUSED
;
2843 *relocation
= addend
- val
;
2848 xcoff_reloc_type_rel (input_bfd
, input_section
, output_bfd
, rel
, sym
, howto
,
2849 val
, addend
, relocation
, contents
)
2850 bfd
*input_bfd ATTRIBUTE_UNUSED
;
2851 asection
*input_section
;
2852 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2853 struct internal_reloc
*rel ATTRIBUTE_UNUSED
;
2854 struct internal_syment
*sym ATTRIBUTE_UNUSED
;
2855 struct reloc_howto_struct
*howto
;
2858 bfd_vma
*relocation
;
2859 bfd_byte
*contents ATTRIBUTE_UNUSED
;
2861 howto
->pc_relative
= TRUE
;
2863 /* A PC relative reloc includes the section address. */
2864 addend
+= input_section
->vma
;
2866 *relocation
= val
+ addend
;
2867 *relocation
-= (input_section
->output_section
->vma
2868 + input_section
->output_offset
);
2873 xcoff_reloc_type_toc (input_bfd
, input_section
, output_bfd
, rel
, sym
, howto
,
2874 val
, addend
, relocation
, contents
)
2876 asection
*input_section ATTRIBUTE_UNUSED
;
2878 struct internal_reloc
*rel
;
2879 struct internal_syment
*sym
;
2880 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
;
2882 bfd_vma addend ATTRIBUTE_UNUSED
;
2883 bfd_vma
*relocation
;
2884 bfd_byte
*contents ATTRIBUTE_UNUSED
;
2886 struct xcoff_link_hash_entry
*h
;
2888 if (0 > rel
->r_symndx
)
2891 h
= obj_xcoff_sym_hashes (input_bfd
)[rel
->r_symndx
];
2893 if (h
!= NULL
&& h
->smclas
!= XMC_TD
)
2895 if (h
->toc_section
== NULL
)
2897 (*_bfd_error_handler
)
2898 (_("%s: TOC reloc at 0x%x to symbol `%s' with no TOC entry"),
2899 bfd_get_filename (input_bfd
), rel
->r_vaddr
,
2900 h
->root
.root
.string
);
2901 bfd_set_error (bfd_error_bad_value
);
2905 BFD_ASSERT ((h
->flags
& XCOFF_SET_TOC
) == 0);
2906 val
= (h
->toc_section
->output_section
->vma
2907 + h
->toc_section
->output_offset
);
2910 *relocation
= ((val
- xcoff_data (output_bfd
)->toc
)
2911 - (sym
->n_value
- xcoff_data (input_bfd
)->toc
));
2916 xcoff_reloc_type_ba (input_bfd
, input_section
, output_bfd
, rel
, sym
, howto
,
2917 val
, addend
, relocation
, contents
)
2918 bfd
*input_bfd ATTRIBUTE_UNUSED
;
2919 asection
*input_section ATTRIBUTE_UNUSED
;
2920 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2921 struct internal_reloc
*rel ATTRIBUTE_UNUSED
;
2922 struct internal_syment
*sym ATTRIBUTE_UNUSED
;
2923 struct reloc_howto_struct
*howto
;
2926 bfd_vma
*relocation
;
2927 bfd_byte
*contents ATTRIBUTE_UNUSED
;
2929 howto
->src_mask
&= ~3;
2930 howto
->dst_mask
= howto
->src_mask
;
2932 *relocation
= val
+ addend
;
2938 xcoff_reloc_type_br (input_bfd
, input_section
, output_bfd
, rel
, sym
, howto
,
2939 val
, addend
, relocation
, contents
)
2941 asection
*input_section
;
2942 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2943 struct internal_reloc
*rel
;
2944 struct internal_syment
*sym ATTRIBUTE_UNUSED
;
2945 struct reloc_howto_struct
*howto
;
2948 bfd_vma
*relocation
;
2951 struct xcoff_link_hash_entry
*h
;
2952 bfd_vma section_offset
;
2954 if (0 > rel
->r_symndx
)
2957 h
= obj_xcoff_sym_hashes (input_bfd
)[rel
->r_symndx
];
2958 section_offset
= rel
->r_vaddr
- input_section
->vma
;
2960 /* If we see an R_BR or R_RBR reloc which is jumping to global
2961 linkage code, and it is followed by an appropriate cror nop
2962 instruction, we replace the cror with lwz r2,20(r1). This
2963 restores the TOC after the glink code. Contrariwise, if the
2964 call is followed by a lwz r2,20(r1), but the call is not
2965 going to global linkage code, we can replace the load with a
2968 && (bfd_link_hash_defined
== h
->root
.type
2969 || bfd_link_hash_defweak
== h
->root
.type
)
2970 && section_offset
+ 8 <= input_section
->size
)
2975 pnext
= contents
+ section_offset
+ 4;
2976 next
= bfd_get_32 (input_bfd
, pnext
);
2978 /* The _ptrgl function is magic. It is used by the AIX
2979 compiler to call a function through a pointer. */
2980 if (h
->smclas
== XMC_GL
|| strcmp (h
->root
.root
.string
, "._ptrgl") == 0)
2982 if (next
== 0x4def7b82 /* cror 15,15,15 */
2983 || next
== 0x4ffffb82 /* cror 31,31,31 */
2984 || next
== 0x60000000) /* ori r0,r0,0 */
2985 bfd_put_32 (input_bfd
, 0x80410014, pnext
); /* lwz r2,20(r1) */
2990 if (next
== 0x80410014) /* lwz r2,20(r1) */
2991 bfd_put_32 (input_bfd
, 0x60000000, pnext
); /* ori r0,r0,0 */
2994 else if (NULL
!= h
&& bfd_link_hash_undefined
== h
->root
.type
)
2996 /* Normally, this relocation is against a defined symbol. In the
2997 case where this is a partial link and the output section offset
2998 is greater than 2^25, the linker will return an invalid error
2999 message that the relocation has been truncated. Yes it has been
3000 truncated but no it not important. For this case, disable the
3001 overflow checking. */
3003 howto
->complain_on_overflow
= complain_overflow_dont
;
3006 /* The original PC-relative relocation is biased by -r_vaddr, so adding
3007 the value below will give the absolute target address. */
3008 *relocation
= val
+ addend
+ rel
->r_vaddr
;
3010 howto
->src_mask
&= ~3;
3011 howto
->dst_mask
= howto
->src_mask
;
3014 && (h
->root
.type
== bfd_link_hash_defined
3015 || h
->root
.type
== bfd_link_hash_defweak
)
3016 && bfd_is_abs_section (h
->root
.u
.def
.section
)
3017 && section_offset
+ 4 <= input_section
->size
)
3022 /* Turn the relative branch into an absolute one by setting the
3024 ptr
= contents
+ section_offset
;
3025 insn
= bfd_get_32 (input_bfd
, ptr
);
3027 bfd_put_32 (input_bfd
, insn
, ptr
);
3029 /* Make the howto absolute too. */
3030 howto
->pc_relative
= FALSE
;
3031 howto
->complain_on_overflow
= complain_overflow_bitfield
;
3035 /* Use a PC-relative howto and subtract the instruction's address
3036 from the target address we calculated above. */
3037 howto
->pc_relative
= TRUE
;
3038 *relocation
-= (input_section
->output_section
->vma
3039 + input_section
->output_offset
3046 xcoff_reloc_type_crel (input_bfd
, input_section
, output_bfd
, rel
, sym
, howto
,
3047 val
, addend
, relocation
, contents
)
3048 bfd
*input_bfd ATTRIBUTE_UNUSED
;
3049 asection
*input_section
;
3050 bfd
*output_bfd ATTRIBUTE_UNUSED
;
3051 struct internal_reloc
*rel ATTRIBUTE_UNUSED
;
3052 struct internal_syment
*sym ATTRIBUTE_UNUSED
;
3053 struct reloc_howto_struct
*howto
;
3054 bfd_vma val ATTRIBUTE_UNUSED
;
3056 bfd_vma
*relocation
;
3057 bfd_byte
*contents ATTRIBUTE_UNUSED
;
3059 howto
->pc_relative
= TRUE
;
3060 howto
->src_mask
&= ~3;
3061 howto
->dst_mask
= howto
->src_mask
;
3063 /* A PC relative reloc includes the section address. */
3064 addend
+= input_section
->vma
;
3066 *relocation
= val
+ addend
;
3067 *relocation
-= (input_section
->output_section
->vma
3068 + input_section
->output_offset
);
3073 xcoff_complain_overflow_dont_func (input_bfd
, val
, relocation
, howto
)
3074 bfd
*input_bfd ATTRIBUTE_UNUSED
;
3075 bfd_vma val ATTRIBUTE_UNUSED
;
3076 bfd_vma relocation ATTRIBUTE_UNUSED
;
3077 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
;
3083 xcoff_complain_overflow_bitfield_func (input_bfd
, val
, relocation
, howto
)
3087 struct reloc_howto_struct
*howto
;
3089 bfd_vma addrmask
, fieldmask
, signmask
, ss
;
3092 /* Get the values to be added together. For signed and unsigned
3093 relocations, we assume that all values should be truncated to
3094 the size of an address. For bitfields, all the bits matter.
3095 See also bfd_check_overflow. */
3096 fieldmask
= N_ONES (howto
->bitsize
);
3097 addrmask
= N_ONES (bfd_arch_bits_per_address (input_bfd
)) | fieldmask
;
3099 b
= val
& howto
->src_mask
;
3101 /* Much like unsigned, except no trimming with addrmask. In
3102 addition, the sum overflows if there is a carry out of
3103 the bfd_vma, i.e., the sum is less than either input
3105 a
>>= howto
->rightshift
;
3106 b
>>= howto
->bitpos
;
3108 /* Bitfields are sometimes used for signed numbers; for
3109 example, a 13-bit field sometimes represents values in
3110 0..8191 and sometimes represents values in -4096..4095.
3111 If the field is signed and a is -4095 (0x1001) and b is
3112 -1 (0x1fff), the sum is -4096 (0x1000), but (0x1001 +
3113 0x1fff is 0x3000). It's not clear how to handle this
3114 everywhere, since there is not way to know how many bits
3115 are significant in the relocation, but the original code
3116 assumed that it was fully sign extended, and we will keep
3118 signmask
= (fieldmask
>> 1) + 1;
3120 if ((a
& ~ fieldmask
) != 0)
3122 /* Some bits out of the field are set. This might not
3123 be a problem: if this is a signed bitfield, it is OK
3124 iff all the high bits are set, including the sign
3125 bit. We'll try setting all but the most significant
3126 bit in the original relocation value: if this is all
3127 ones, we are OK, assuming a signed bitfield. */
3128 ss
= (signmask
<< howto
->rightshift
) - 1;
3129 if ((ss
| relocation
) != ~ (bfd_vma
) 0)
3134 /* We just assume (b & ~ fieldmask) == 0. */
3136 /* We explicitly permit wrap around if this relocation
3137 covers the high bit of an address. The Linux kernel
3138 relies on it, and it is the only way to write assembler
3139 code which can run when loaded at a location 0x80000000
3140 away from the location at which it is linked. */
3141 if (howto
->bitsize
+ howto
->rightshift
3142 == bfd_arch_bits_per_address (input_bfd
))
3146 if (sum
< a
|| (sum
& ~ fieldmask
) != 0)
3148 /* There was a carry out, or the field overflow. Test
3149 for signed operands again. Here is the overflow test
3150 is as for complain_overflow_signed. */
3151 if (((~ (a
^ b
)) & (a
^ sum
)) & signmask
)
3159 xcoff_complain_overflow_signed_func (input_bfd
, val
, relocation
, howto
)
3163 struct reloc_howto_struct
*howto
;
3165 bfd_vma addrmask
, fieldmask
, signmask
, ss
;
3168 /* Get the values to be added together. For signed and unsigned
3169 relocations, we assume that all values should be truncated to
3170 the size of an address. For bitfields, all the bits matter.
3171 See also bfd_check_overflow. */
3172 fieldmask
= N_ONES (howto
->bitsize
);
3173 addrmask
= N_ONES (bfd_arch_bits_per_address (input_bfd
)) | fieldmask
;
3175 b
= val
& howto
->src_mask
;
3177 a
= (a
& addrmask
) >> howto
->rightshift
;
3179 /* If any sign bits are set, all sign bits must be set.
3180 That is, A must be a valid negative address after
3182 signmask
= ~ (fieldmask
>> 1);
3184 if (ss
!= 0 && ss
!= ((addrmask
>> howto
->rightshift
) & signmask
))
3187 /* We only need this next bit of code if the sign bit of B
3188 is below the sign bit of A. This would only happen if
3189 SRC_MASK had fewer bits than BITSIZE. Note that if
3190 SRC_MASK has more bits than BITSIZE, we can get into
3191 trouble; we would need to verify that B is in range, as
3192 we do for A above. */
3193 signmask
= ((~ howto
->src_mask
) >> 1) & howto
->src_mask
;
3194 if ((b
& signmask
) != 0)
3196 /* Set all the bits above the sign bit. */
3197 b
-= signmask
<<= 1;
3200 b
= (b
& addrmask
) >> howto
->bitpos
;
3202 /* Now we can do the addition. */
3205 /* See if the result has the correct sign. Bits above the
3206 sign bit are junk now; ignore them. If the sum is
3207 positive, make sure we did not have all negative inputs;
3208 if the sum is negative, make sure we did not have all
3209 positive inputs. The test below looks only at the sign
3210 bits, and it really just
3211 SIGN (A) == SIGN (B) && SIGN (A) != SIGN (SUM)
3213 signmask
= (fieldmask
>> 1) + 1;
3214 if (((~ (a
^ b
)) & (a
^ sum
)) & signmask
)
3221 xcoff_complain_overflow_unsigned_func (input_bfd
, val
, relocation
, howto
)
3225 struct reloc_howto_struct
*howto
;
3227 bfd_vma addrmask
, fieldmask
;
3230 /* Get the values to be added together. For signed and unsigned
3231 relocations, we assume that all values should be truncated to
3232 the size of an address. For bitfields, all the bits matter.
3233 See also bfd_check_overflow. */
3234 fieldmask
= N_ONES (howto
->bitsize
);
3235 addrmask
= N_ONES (bfd_arch_bits_per_address (input_bfd
)) | fieldmask
;
3237 b
= val
& howto
->src_mask
;
3239 /* Checking for an unsigned overflow is relatively easy:
3240 trim the addresses and add, and trim the result as well.
3241 Overflow is normally indicated when the result does not
3242 fit in the field. However, we also need to consider the
3243 case when, e.g., fieldmask is 0x7fffffff or smaller, an
3244 input is 0x80000000, and bfd_vma is only 32 bits; then we
3245 will get sum == 0, but there is an overflow, since the
3246 inputs did not fit in the field. Instead of doing a
3247 separate test, we can check for this by or-ing in the
3248 operands when testing for the sum overflowing its final
3250 a
= (a
& addrmask
) >> howto
->rightshift
;
3251 b
= (b
& addrmask
) >> howto
->bitpos
;
3252 sum
= (a
+ b
) & addrmask
;
3253 if ((a
| b
| sum
) & ~ fieldmask
)
3259 /* This is the relocation function for the RS/6000/POWER/PowerPC.
3260 This is currently the only processor which uses XCOFF; I hope that
3263 I took the relocation type definitions from two documents:
3264 the PowerPC AIX Version 4 Application Binary Interface, First
3265 Edition (April 1992), and the PowerOpen ABI, Big-Endian
3266 32-Bit Hardware Implementation (June 30, 1994). Differences
3267 between the documents are noted below.
3269 Unsupported r_type's
3275 These relocs are defined by the PowerPC ABI to be
3276 relative branches which use half of the difference
3277 between the symbol and the program counter. I can't
3278 quite figure out when this is useful. These relocs are
3279 not defined by the PowerOpen ABI.
3284 Simple positive relocation.
3287 Simple negative relocation.
3290 Simple PC relative relocation.
3293 TOC relative relocation. The value in the instruction in
3294 the input file is the offset from the input file TOC to
3295 the desired location. We want the offset from the final
3296 TOC to the desired location. We have:
3301 so we must change insn by on - in.
3304 GL linkage relocation. The value of this relocation
3305 is the address of the entry in the TOC section.
3308 Local object TOC address. I can't figure out the
3309 difference between this and case R_GL.
3312 TOC relative relocation. A TOC relative load instruction
3313 which may be changed to a load address instruction.
3314 FIXME: We don't currently implement this optimization.
3317 TOC relative relocation. This is a TOC relative load
3318 address instruction which may be changed to a load
3319 instruction. FIXME: I don't know if this is the correct
3323 Absolute branch. We don't want to mess with the lower
3324 two bits of the instruction.
3327 The PowerPC ABI defines this as an absolute call which
3328 may be modified to become a relative call. The PowerOpen
3329 ABI does not define this relocation type.
3332 Absolute branch which may be modified to become a
3336 The PowerPC ABI defines this as an absolute branch to a
3337 fixed address which may be modified to an absolute branch
3338 to a symbol. The PowerOpen ABI does not define this
3342 The PowerPC ABI defines this as an absolute branch to a
3343 fixed address which may be modified to a relative branch.
3344 The PowerOpen ABI does not define this relocation type.
3347 Relative branch. We don't want to mess with the lower
3348 two bits of the instruction.
3351 The PowerPC ABI defines this as a relative call which may
3352 be modified to become an absolute call. The PowerOpen
3353 ABI does not define this relocation type.
3356 A relative branch which may be modified to become an
3360 The PowerPC AIX ABI describes this as a load which may be
3361 changed to a load address. The PowerOpen ABI says this
3362 is the same as case R_POS.
3365 The PowerPC AIX ABI describes this as a load address
3366 which may be changed to a load. The PowerOpen ABI says
3367 this is the same as R_POS.
3371 xcoff_ppc_relocate_section (output_bfd
, info
, input_bfd
,
3372 input_section
, contents
, relocs
, syms
,
3375 struct bfd_link_info
*info
;
3377 asection
*input_section
;
3379 struct internal_reloc
*relocs
;
3380 struct internal_syment
*syms
;
3381 asection
**sections
;
3383 struct internal_reloc
*rel
;
3384 struct internal_reloc
*relend
;
3387 relend
= rel
+ input_section
->reloc_count
;
3388 for (; rel
< relend
; rel
++)
3391 struct xcoff_link_hash_entry
*h
;
3392 struct internal_syment
*sym
;
3395 struct reloc_howto_struct howto
;
3397 bfd_vma value_to_relocate
;
3401 /* Relocation type R_REF is a special relocation type which is
3402 merely used to prevent garbage collection from occurring for
3403 the csect including the symbol which it references. */
3404 if (rel
->r_type
== R_REF
)
3408 howto
.type
= rel
->r_type
;
3409 howto
.rightshift
= 0;
3410 howto
.bitsize
= (rel
->r_size
& 0x1f) + 1;
3411 howto
.size
= howto
.bitsize
> 16 ? 2 : 1;
3412 howto
.pc_relative
= FALSE
;
3414 howto
.complain_on_overflow
= (rel
->r_size
& 0x80
3415 ? complain_overflow_signed
3416 : complain_overflow_bitfield
);
3417 howto
.special_function
= NULL
;
3418 howto
.name
= "internal";
3419 howto
.partial_inplace
= TRUE
;
3420 howto
.src_mask
= howto
.dst_mask
= N_ONES (howto
.bitsize
);
3421 howto
.pcrel_offset
= FALSE
;
3428 symndx
= rel
->r_symndx
;
3434 h
= obj_xcoff_sym_hashes (input_bfd
)[symndx
];
3435 sym
= syms
+ symndx
;
3436 addend
= - sym
->n_value
;
3440 sec
= sections
[symndx
];
3441 /* Hack to make sure we use the right TOC anchor value
3442 if this reloc is against the TOC anchor. */
3443 if (sec
->name
[3] == '0'
3444 && strcmp (sec
->name
, ".tc0") == 0)
3445 val
= xcoff_data (output_bfd
)->toc
;
3447 val
= (sec
->output_section
->vma
3448 + sec
->output_offset
3454 if (info
->unresolved_syms_in_objects
!= RM_IGNORE
3455 && (h
->flags
& XCOFF_WAS_UNDEFINED
) != 0)
3457 if (! ((*info
->callbacks
->undefined_symbol
)
3458 (info
, h
->root
.root
.string
,
3459 input_bfd
, input_section
,
3460 rel
->r_vaddr
- input_section
->vma
,
3461 (info
->unresolved_syms_in_objects
3462 == RM_GENERATE_ERROR
))))
3465 if (h
->root
.type
== bfd_link_hash_defined
3466 || h
->root
.type
== bfd_link_hash_defweak
)
3468 sec
= h
->root
.u
.def
.section
;
3469 val
= (h
->root
.u
.def
.value
3470 + sec
->output_section
->vma
3471 + sec
->output_offset
);
3473 else if (h
->root
.type
== bfd_link_hash_common
)
3475 sec
= h
->root
.u
.c
.p
->section
;
3476 val
= (sec
->output_section
->vma
3477 + sec
->output_offset
);
3482 BFD_ASSERT (info
->relocatable
3483 || (h
->flags
& XCOFF_DEF_DYNAMIC
) != 0
3484 || (h
->flags
& XCOFF_IMPORT
) != 0);
3489 if (rel
->r_type
>= XCOFF_MAX_CALCULATE_RELOCATION
3490 || !((*xcoff_calculate_relocation
[rel
->r_type
])
3491 (input_bfd
, input_section
, output_bfd
, rel
, sym
, &howto
, val
,
3492 addend
, &relocation
, contents
)))
3496 address
= rel
->r_vaddr
- input_section
->vma
;
3497 location
= contents
+ address
;
3499 if (address
> input_section
->size
)
3502 /* Get the value we are going to relocate. */
3503 if (1 == howto
.size
)
3504 value_to_relocate
= bfd_get_16 (input_bfd
, location
);
3506 value_to_relocate
= bfd_get_32 (input_bfd
, location
);
3510 FIXME: We may drop bits during the addition
3511 which we don't check for. We must either check at every single
3512 operation, which would be tedious, or we must do the computations
3513 in a type larger than bfd_vma, which would be inefficient. */
3515 if ((unsigned int) howto
.complain_on_overflow
3516 >= XCOFF_MAX_COMPLAIN_OVERFLOW
)
3519 if (((*xcoff_complain_overflow
[howto
.complain_on_overflow
])
3520 (input_bfd
, value_to_relocate
, relocation
, &howto
)))
3523 char buf
[SYMNMLEN
+ 1];
3524 char reloc_type_name
[10];
3536 name
= _bfd_coff_internal_syment_name (input_bfd
, sym
, buf
);
3540 sprintf (reloc_type_name
, "0x%02x", rel
->r_type
);
3542 if (! ((*info
->callbacks
->reloc_overflow
)
3543 (info
, (h
? &h
->root
: NULL
), name
, reloc_type_name
,
3544 (bfd_vma
) 0, input_bfd
, input_section
,
3545 rel
->r_vaddr
- input_section
->vma
)))
3549 /* Add RELOCATION to the right bits of VALUE_TO_RELOCATE. */
3550 value_to_relocate
= ((value_to_relocate
& ~howto
.dst_mask
)
3551 | (((value_to_relocate
& howto
.src_mask
)
3552 + relocation
) & howto
.dst_mask
));
3554 /* Put the value back in the object file. */
3555 if (1 == howto
.size
)
3556 bfd_put_16 (input_bfd
, value_to_relocate
, location
);
3558 bfd_put_32 (input_bfd
, value_to_relocate
, location
);
3565 _bfd_xcoff_put_ldsymbol_name (abfd
, ldinfo
, ldsym
, name
)
3566 bfd
*abfd ATTRIBUTE_UNUSED
;
3567 struct xcoff_loader_info
*ldinfo
;
3568 struct internal_ldsym
*ldsym
;
3572 len
= strlen (name
);
3574 if (len
<= SYMNMLEN
)
3575 strncpy (ldsym
->_l
._l_name
, name
, SYMNMLEN
);
3578 if (ldinfo
->string_size
+ len
+ 3 > ldinfo
->string_alc
)
3580 bfd_size_type newalc
;
3583 newalc
= ldinfo
->string_alc
* 2;
3586 while (ldinfo
->string_size
+ len
+ 3 > newalc
)
3589 newstrings
= bfd_realloc (ldinfo
->strings
, newalc
);
3590 if (newstrings
== NULL
)
3592 ldinfo
->failed
= TRUE
;
3595 ldinfo
->string_alc
= newalc
;
3596 ldinfo
->strings
= newstrings
;
3599 bfd_put_16 (ldinfo
->output_bfd
, (bfd_vma
) (len
+ 1),
3600 ldinfo
->strings
+ ldinfo
->string_size
);
3601 strcpy (ldinfo
->strings
+ ldinfo
->string_size
+ 2, name
);
3602 ldsym
->_l
._l_l
._l_zeroes
= 0;
3603 ldsym
->_l
._l_l
._l_offset
= ldinfo
->string_size
+ 2;
3604 ldinfo
->string_size
+= len
+ 3;
3611 _bfd_xcoff_put_symbol_name (bfd
*abfd
, struct bfd_strtab_hash
*strtab
,
3612 struct internal_syment
*sym
,
3615 if (strlen (name
) <= SYMNMLEN
)
3617 strncpy (sym
->_n
._n_name
, name
, SYMNMLEN
);
3625 if ((abfd
->flags
& BFD_TRADITIONAL_FORMAT
) != 0)
3627 indx
= _bfd_stringtab_add (strtab
, name
, hash
, FALSE
);
3628 if (indx
== (bfd_size_type
) -1)
3630 sym
->_n
._n_n
._n_zeroes
= 0;
3631 sym
->_n
._n_n
._n_offset
= STRING_SIZE_SIZE
+ indx
;
3637 xcoff_create_csect_from_smclas (abfd
, aux
, symbol_name
)
3639 union internal_auxent
*aux
;
3640 const char *symbol_name
;
3642 asection
*return_value
= NULL
;
3644 /* .sv64 = x_smclas == 17
3645 This is an invalid csect for 32 bit apps. */
3646 static const char *names
[19] =
3648 ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo",
3649 ".sv", ".bs", ".ds", ".uc", ".ti", ".tb", NULL
, ".tc0",
3650 ".td", NULL
, ".sv3264"
3653 if ((19 >= aux
->x_csect
.x_smclas
)
3654 && (NULL
!= names
[aux
->x_csect
.x_smclas
]))
3656 return_value
= bfd_make_section_anyway
3657 (abfd
, names
[aux
->x_csect
.x_smclas
]);
3661 (*_bfd_error_handler
)
3662 (_("%B: symbol `%s' has unrecognized smclas %d"),
3663 abfd
, symbol_name
, aux
->x_csect
.x_smclas
);
3664 bfd_set_error (bfd_error_bad_value
);
3667 return return_value
;
3671 xcoff_is_lineno_count_overflow (abfd
, value
)
3672 bfd
*abfd ATTRIBUTE_UNUSED
;
3675 if (0xffff <= value
)
3682 xcoff_is_reloc_count_overflow (abfd
, value
)
3683 bfd
*abfd ATTRIBUTE_UNUSED
;
3686 if (0xffff <= value
)
3693 xcoff_loader_symbol_offset (abfd
, ldhdr
)
3695 struct internal_ldhdr
*ldhdr ATTRIBUTE_UNUSED
;
3697 return bfd_xcoff_ldhdrsz (abfd
);
3701 xcoff_loader_reloc_offset (abfd
, ldhdr
)
3703 struct internal_ldhdr
*ldhdr
;
3705 return bfd_xcoff_ldhdrsz (abfd
) + ldhdr
->l_nsyms
* bfd_xcoff_ldsymsz (abfd
);
3709 xcoff_generate_rtinit (abfd
, init
, fini
, rtld
)
3715 bfd_byte filehdr_ext
[FILHSZ
];
3716 bfd_byte scnhdr_ext
[SCNHSZ
];
3717 bfd_byte syment_ext
[SYMESZ
* 10];
3718 bfd_byte reloc_ext
[RELSZ
* 3];
3719 bfd_byte
*data_buffer
;
3720 bfd_size_type data_buffer_size
;
3721 bfd_byte
*string_table
= NULL
, *st_tmp
= NULL
;
3722 bfd_size_type string_table_size
;
3724 size_t initsz
, finisz
;
3725 struct internal_filehdr filehdr
;
3726 struct internal_scnhdr scnhdr
;
3727 struct internal_syment syment
;
3728 union internal_auxent auxent
;
3729 struct internal_reloc reloc
;
3731 char *data_name
= ".data";
3732 char *rtinit_name
= "__rtinit";
3733 char *rtld_name
= "__rtld";
3735 if (! bfd_xcoff_rtinit_size (abfd
))
3738 initsz
= (init
== NULL
? 0 : 1 + strlen (init
));
3739 finisz
= (fini
== NULL
? 0 : 1 + strlen (fini
));
3742 memset (filehdr_ext
, 0, FILHSZ
);
3743 memset (&filehdr
, 0, sizeof (struct internal_filehdr
));
3744 filehdr
.f_magic
= bfd_xcoff_magic_number (abfd
);
3745 filehdr
.f_nscns
= 1;
3746 filehdr
.f_timdat
= 0;
3747 filehdr
.f_nsyms
= 0; /* at least 6, no more than 10 */
3748 filehdr
.f_symptr
= 0; /* set below */
3749 filehdr
.f_opthdr
= 0;
3750 filehdr
.f_flags
= 0;
3752 /* section header */
3753 memset (scnhdr_ext
, 0, SCNHSZ
);
3754 memset (&scnhdr
, 0, sizeof (struct internal_scnhdr
));
3755 memcpy (scnhdr
.s_name
, data_name
, strlen (data_name
));
3758 scnhdr
.s_size
= 0; /* set below */
3759 scnhdr
.s_scnptr
= FILHSZ
+ SCNHSZ
;
3760 scnhdr
.s_relptr
= 0; /* set below */
3761 scnhdr
.s_lnnoptr
= 0;
3762 scnhdr
.s_nreloc
= 0; /* either 1 or 2 */
3764 scnhdr
.s_flags
= STYP_DATA
;
3767 0x0000 0x00000000 : rtl
3768 0x0004 0x00000010 : offset to init, or 0
3769 0x0008 0x00000028 : offset to fini, or 0
3770 0x000C 0x0000000C : size of descriptor
3771 0x0010 0x00000000 : init, needs a reloc
3772 0x0014 0x00000040 : offset to init name
3773 0x0018 0x00000000 : flags, padded to a word
3774 0x001C 0x00000000 : empty init
3777 0x0028 0x00000000 : fini, needs a reloc
3778 0x002C 0x00000??? : offset to fini name
3779 0x0030 0x00000000 : flags, padded to a word
3780 0x0034 0x00000000 : empty fini
3784 0x0040 + initsz fini name */
3786 data_buffer_size
= 0x0040 + initsz
+ finisz
;
3787 data_buffer_size
= (data_buffer_size
+ 7) &~ (bfd_size_type
) 7;
3789 data_buffer
= (bfd_byte
*) bfd_zmalloc (data_buffer_size
);
3790 if (data_buffer
== NULL
)
3796 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x04]);
3798 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x14]);
3799 memcpy (&data_buffer
[val
], init
, initsz
);
3805 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x08]);
3806 val
= 0x40 + initsz
;
3807 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x2C]);
3808 memcpy (&data_buffer
[val
], fini
, finisz
);
3812 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x0C]);
3814 scnhdr
.s_size
= data_buffer_size
;
3817 string_table_size
= 0;
3819 string_table_size
+= initsz
;
3821 string_table_size
+= finisz
;
3822 if (string_table_size
)
3824 string_table_size
+= 4;
3825 string_table
= (bfd_byte
*) bfd_zmalloc (string_table_size
);
3826 if (string_table
== NULL
)
3829 val
= string_table_size
;
3830 bfd_h_put_32 (abfd
, val
, &string_table
[0]);
3831 st_tmp
= string_table
+ 4;
3840 memset (syment_ext
, 0, 10 * SYMESZ
);
3841 memset (reloc_ext
, 0, 3 * RELSZ
);
3844 memset (&syment
, 0, sizeof (struct internal_syment
));
3845 memset (&auxent
, 0, sizeof (union internal_auxent
));
3846 memcpy (syment
._n
._n_name
, data_name
, strlen (data_name
));
3848 syment
.n_sclass
= C_HIDEXT
;
3849 syment
.n_numaux
= 1;
3850 auxent
.x_csect
.x_scnlen
.l
= data_buffer_size
;
3851 auxent
.x_csect
.x_smtyp
= 3 << 3 | XTY_SD
;
3852 auxent
.x_csect
.x_smclas
= XMC_RW
;
3853 bfd_coff_swap_sym_out (abfd
, &syment
,
3854 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3855 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3857 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3858 filehdr
.f_nsyms
+= 2;
3861 memset (&syment
, 0, sizeof (struct internal_syment
));
3862 memset (&auxent
, 0, sizeof (union internal_auxent
));
3863 memcpy (syment
._n
._n_name
, rtinit_name
, strlen (rtinit_name
));
3865 syment
.n_sclass
= C_EXT
;
3866 syment
.n_numaux
= 1;
3867 auxent
.x_csect
.x_smtyp
= XTY_LD
;
3868 auxent
.x_csect
.x_smclas
= XMC_RW
;
3869 bfd_coff_swap_sym_out (abfd
, &syment
,
3870 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3871 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3873 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3874 filehdr
.f_nsyms
+= 2;
3879 memset (&syment
, 0, sizeof (struct internal_syment
));
3880 memset (&auxent
, 0, sizeof (union internal_auxent
));
3884 syment
._n
._n_n
._n_offset
= st_tmp
- string_table
;
3885 memcpy (st_tmp
, init
, initsz
);
3889 memcpy (syment
._n
._n_name
, init
, initsz
- 1);
3891 syment
.n_sclass
= C_EXT
;
3892 syment
.n_numaux
= 1;
3893 bfd_coff_swap_sym_out (abfd
, &syment
,
3894 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3895 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3897 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3900 memset (&reloc
, 0, sizeof (struct internal_reloc
));
3901 reloc
.r_vaddr
= 0x0010;
3902 reloc
.r_symndx
= filehdr
.f_nsyms
;
3903 reloc
.r_type
= R_POS
;
3905 bfd_coff_swap_reloc_out (abfd
, &reloc
, &reloc_ext
[0]);
3907 filehdr
.f_nsyms
+= 2;
3908 scnhdr
.s_nreloc
+= 1;
3914 memset (&syment
, 0, sizeof (struct internal_syment
));
3915 memset (&auxent
, 0, sizeof (union internal_auxent
));
3919 syment
._n
._n_n
._n_offset
= st_tmp
- string_table
;
3920 memcpy (st_tmp
, fini
, finisz
);
3924 memcpy (syment
._n
._n_name
, fini
, finisz
- 1);
3926 syment
.n_sclass
= C_EXT
;
3927 syment
.n_numaux
= 1;
3928 bfd_coff_swap_sym_out (abfd
, &syment
,
3929 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3930 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3932 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3935 memset (&reloc
, 0, sizeof (struct internal_reloc
));
3936 reloc
.r_vaddr
= 0x0028;
3937 reloc
.r_symndx
= filehdr
.f_nsyms
;
3938 reloc
.r_type
= R_POS
;
3940 bfd_coff_swap_reloc_out (abfd
, &reloc
,
3941 &reloc_ext
[scnhdr
.s_nreloc
* RELSZ
]);
3943 filehdr
.f_nsyms
+= 2;
3944 scnhdr
.s_nreloc
+= 1;
3949 memset (&syment
, 0, sizeof (struct internal_syment
));
3950 memset (&auxent
, 0, sizeof (union internal_auxent
));
3951 memcpy (syment
._n
._n_name
, rtld_name
, strlen (rtld_name
));
3952 syment
.n_sclass
= C_EXT
;
3953 syment
.n_numaux
= 1;
3954 bfd_coff_swap_sym_out (abfd
, &syment
,
3955 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3956 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3958 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3961 memset (&reloc
, 0, sizeof (struct internal_reloc
));
3962 reloc
.r_vaddr
= 0x0000;
3963 reloc
.r_symndx
= filehdr
.f_nsyms
;
3964 reloc
.r_type
= R_POS
;
3966 bfd_coff_swap_reloc_out (abfd
, &reloc
,
3967 &reloc_ext
[scnhdr
.s_nreloc
* RELSZ
]);
3969 filehdr
.f_nsyms
+= 2;
3970 scnhdr
.s_nreloc
+= 1;
3973 scnhdr
.s_relptr
= scnhdr
.s_scnptr
+ data_buffer_size
;
3974 filehdr
.f_symptr
= scnhdr
.s_relptr
+ scnhdr
.s_nreloc
* RELSZ
;
3976 bfd_coff_swap_filehdr_out (abfd
, &filehdr
, filehdr_ext
);
3977 bfd_bwrite (filehdr_ext
, FILHSZ
, abfd
);
3978 bfd_coff_swap_scnhdr_out (abfd
, &scnhdr
, scnhdr_ext
);
3979 bfd_bwrite (scnhdr_ext
, SCNHSZ
, abfd
);
3980 bfd_bwrite (data_buffer
, data_buffer_size
, abfd
);
3981 bfd_bwrite (reloc_ext
, scnhdr
.s_nreloc
* RELSZ
, abfd
);
3982 bfd_bwrite (syment_ext
, filehdr
.f_nsyms
* SYMESZ
, abfd
);
3983 bfd_bwrite (string_table
, string_table_size
, abfd
);
3992 static reloc_howto_type xcoff_dynamic_reloc
=
3993 HOWTO (0, /* type */
3995 2, /* size (0 = byte, 1 = short, 2 = long) */
3997 FALSE
, /* pc_relative */
3999 complain_overflow_bitfield
, /* complain_on_overflow */
4000 0, /* special_function */
4002 TRUE
, /* partial_inplace */
4003 0xffffffff, /* src_mask */
4004 0xffffffff, /* dst_mask */
4005 FALSE
); /* pcrel_offset */
4009 The first word of global linkage code must be modified by filling in
4010 the correct TOC offset. */
4012 static unsigned long xcoff_glink_code
[9] =
4014 0x81820000, /* lwz r12,0(r2) */
4015 0x90410014, /* stw r2,20(r1) */
4016 0x800c0000, /* lwz r0,0(r12) */
4017 0x804c0004, /* lwz r2,4(r12) */
4018 0x7c0903a6, /* mtctr r0 */
4019 0x4e800420, /* bctr */
4020 0x00000000, /* start of traceback table */
4021 0x000c8000, /* traceback table */
4022 0x00000000, /* traceback table */
4026 static const struct xcoff_backend_data_rec bfd_xcoff_backend_data
=
4028 { /* COFF backend, defined in libcoff.h. */
4029 _bfd_xcoff_swap_aux_in
,
4030 _bfd_xcoff_swap_sym_in
,
4031 coff_swap_lineno_in
,
4032 _bfd_xcoff_swap_aux_out
,
4033 _bfd_xcoff_swap_sym_out
,
4034 coff_swap_lineno_out
,
4035 xcoff_swap_reloc_out
,
4036 coff_swap_filehdr_out
,
4037 coff_swap_aouthdr_out
,
4038 coff_swap_scnhdr_out
,
4047 TRUE
, /* _bfd_coff_long_filenames */
4048 XCOFF_NO_LONG_SECTION_NAMES
, /* _bfd_coff_long_section_names */
4049 3, /* _bfd_coff_default_section_alignment_power */
4050 FALSE
, /* _bfd_coff_force_symnames_in_strings */
4051 2, /* _bfd_coff_debug_string_prefix_length */
4052 coff_swap_filehdr_in
,
4053 coff_swap_aouthdr_in
,
4054 coff_swap_scnhdr_in
,
4055 xcoff_swap_reloc_in
,
4056 coff_bad_format_hook
,
4057 coff_set_arch_mach_hook
,
4060 coff_set_alignment_hook
,
4061 coff_slurp_symbol_table
,
4062 symname_in_debug_hook
,
4063 coff_pointerize_aux_hook
,
4065 dummy_reloc16_extra_cases
,
4066 dummy_reloc16_estimate
,
4067 NULL
, /* bfd_coff_sym_is_global */
4068 coff_compute_section_file_positions
,
4069 NULL
, /* _bfd_coff_start_final_link */
4070 xcoff_ppc_relocate_section
,
4071 coff_rtype_to_howto
,
4072 NULL
, /* _bfd_coff_adjust_symndx */
4073 _bfd_generic_link_add_one_symbol
,
4074 coff_link_output_has_begun
,
4075 coff_final_link_postscript
,
4076 NULL
/* print_pdata. */
4079 0x01DF, /* magic number */
4083 /* Function pointers to xcoff specific swap routines. */
4084 xcoff_swap_ldhdr_in
,
4085 xcoff_swap_ldhdr_out
,
4086 xcoff_swap_ldsym_in
,
4087 xcoff_swap_ldsym_out
,
4088 xcoff_swap_ldrel_in
,
4089 xcoff_swap_ldrel_out
,
4095 12, /* _xcoff_function_descriptor_size */
4099 1, /* _xcoff_ldhdr_version */
4101 _bfd_xcoff_put_symbol_name
,
4102 _bfd_xcoff_put_ldsymbol_name
,
4103 &xcoff_dynamic_reloc
,
4104 xcoff_create_csect_from_smclas
,
4106 /* Lineno and reloc count overflow. */
4107 xcoff_is_lineno_count_overflow
,
4108 xcoff_is_reloc_count_overflow
,
4110 xcoff_loader_symbol_offset
,
4111 xcoff_loader_reloc_offset
,
4114 &xcoff_glink_code
[0],
4115 36, /* _xcoff_glink_size */
4118 64, /* _xcoff_rtinit_size */
4119 xcoff_generate_rtinit
,
4122 /* The transfer vector that leads the outside world to all of the above. */
4123 const bfd_target rs6000coff_vec
=
4126 bfd_target_xcoff_flavour
,
4127 BFD_ENDIAN_BIG
, /* data byte order is big */
4128 BFD_ENDIAN_BIG
, /* header byte order is big */
4130 (HAS_RELOC
| EXEC_P
| HAS_LINENO
| HAS_DEBUG
| DYNAMIC
4131 | HAS_SYMS
| HAS_LOCALS
| WP_TEXT
),
4133 SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_CODE
| SEC_DATA
,
4134 0, /* leading char */
4135 '/', /* ar_pad_char */
4136 15, /* ar_max_namelen */
4160 { /* bfd_check_format */
4163 _bfd_xcoff_archive_p
,
4167 { /* bfd_set_format */
4170 _bfd_generic_mkarchive
,
4174 {/* bfd_write_contents */
4176 coff_write_object_contents
,
4177 _bfd_xcoff_write_archive_contents
,
4184 coff_new_section_hook
,
4185 _bfd_generic_get_section_contents
,
4186 _bfd_generic_get_section_contents_in_window
,
4189 _bfd_xcoff_copy_private_bfd_data
,
4190 ((bfd_boolean (*) (bfd
*, bfd
*)) bfd_true
),
4191 _bfd_generic_init_private_section_data
,
4192 ((bfd_boolean (*) (bfd
*, asection
*, bfd
*, asection
*)) bfd_true
),
4193 ((bfd_boolean (*) (bfd
*, asymbol
*, bfd
*, asymbol
*)) bfd_true
),
4194 ((bfd_boolean (*) (bfd
*, bfd
*)) bfd_true
),
4195 ((bfd_boolean (*) (bfd
*, flagword
)) bfd_true
),
4196 ((bfd_boolean (*) (bfd
*, void * )) bfd_true
),
4199 coff_core_file_failing_command
,
4200 coff_core_file_failing_signal
,
4201 coff_core_file_matches_executable_p
,
4204 _bfd_xcoff_slurp_armap
,
4206 ((bfd_boolean (*) (bfd
*, char **, bfd_size_type
*, const char **)) bfd_false
),
4207 bfd_dont_truncate_arname
,
4208 _bfd_xcoff_write_armap
,
4209 _bfd_xcoff_read_ar_hdr
,
4210 _bfd_xcoff_openr_next_archived_file
,
4211 _bfd_generic_get_elt_at_index
,
4212 _bfd_xcoff_stat_arch_elt
,
4216 coff_get_symtab_upper_bound
,
4217 coff_canonicalize_symtab
,
4218 coff_make_empty_symbol
,
4220 coff_get_symbol_info
,
4221 _bfd_xcoff_is_local_label_name
,
4222 coff_bfd_is_target_special_symbol
,
4224 coff_find_nearest_line
,
4225 _bfd_generic_find_line
,
4226 coff_find_inliner_info
,
4227 coff_bfd_make_debug_symbol
,
4228 _bfd_generic_read_minisymbols
,
4229 _bfd_generic_minisymbol_to_symbol
,
4232 coff_get_reloc_upper_bound
,
4233 coff_canonicalize_reloc
,
4234 _bfd_xcoff_reloc_type_lookup
,
4235 _bfd_xcoff_reloc_name_lookup
,
4239 coff_set_section_contents
,
4242 _bfd_xcoff_sizeof_headers
,
4243 bfd_generic_get_relocated_section_contents
,
4244 bfd_generic_relax_section
,
4245 _bfd_xcoff_bfd_link_hash_table_create
,
4246 _bfd_generic_link_hash_table_free
,
4247 _bfd_xcoff_bfd_link_add_symbols
,
4248 _bfd_generic_link_just_syms
,
4249 _bfd_xcoff_bfd_final_link
,
4250 _bfd_generic_link_split_section
,
4251 bfd_generic_gc_sections
,
4252 bfd_generic_merge_sections
,
4253 bfd_generic_is_group_section
,
4254 bfd_generic_discard_group
,
4255 _bfd_generic_section_already_linked
,
4258 _bfd_xcoff_get_dynamic_symtab_upper_bound
,
4259 _bfd_xcoff_canonicalize_dynamic_symtab
,
4260 _bfd_nodynamic_get_synthetic_symtab
,
4261 _bfd_xcoff_get_dynamic_reloc_upper_bound
,
4262 _bfd_xcoff_canonicalize_dynamic_reloc
,
4264 /* Opposite endian version, none exists */
4267 (void *) &bfd_xcoff_backend_data
,
4270 /* xcoff-powermac target
4272 Only difference between this target and the rs6000 target is the
4273 the default architecture and machine type used in coffcode.h
4275 PowerPC Macs use the same magic numbers as RS/6000
4276 (because that's how they were bootstrapped originally),
4277 but they are always PowerPC architecture. */
4278 static const struct xcoff_backend_data_rec bfd_pmac_xcoff_backend_data
=
4280 { /* COFF backend, defined in libcoff.h. */
4281 _bfd_xcoff_swap_aux_in
,
4282 _bfd_xcoff_swap_sym_in
,
4283 coff_swap_lineno_in
,
4284 _bfd_xcoff_swap_aux_out
,
4285 _bfd_xcoff_swap_sym_out
,
4286 coff_swap_lineno_out
,
4287 xcoff_swap_reloc_out
,
4288 coff_swap_filehdr_out
,
4289 coff_swap_aouthdr_out
,
4290 coff_swap_scnhdr_out
,
4299 TRUE
, /* _bfd_coff_long_filenames */
4300 XCOFF_NO_LONG_SECTION_NAMES
, /* _bfd_coff_long_section_names */
4301 3, /* _bfd_coff_default_section_alignment_power */
4302 FALSE
, /* _bfd_coff_force_symnames_in_strings */
4303 2, /* _bfd_coff_debug_string_prefix_length */
4304 coff_swap_filehdr_in
,
4305 coff_swap_aouthdr_in
,
4306 coff_swap_scnhdr_in
,
4307 xcoff_swap_reloc_in
,
4308 coff_bad_format_hook
,
4309 coff_set_arch_mach_hook
,
4312 coff_set_alignment_hook
,
4313 coff_slurp_symbol_table
,
4314 symname_in_debug_hook
,
4315 coff_pointerize_aux_hook
,
4317 dummy_reloc16_extra_cases
,
4318 dummy_reloc16_estimate
,
4319 NULL
, /* bfd_coff_sym_is_global */
4320 coff_compute_section_file_positions
,
4321 NULL
, /* _bfd_coff_start_final_link */
4322 xcoff_ppc_relocate_section
,
4323 coff_rtype_to_howto
,
4324 NULL
, /* _bfd_coff_adjust_symndx */
4325 _bfd_generic_link_add_one_symbol
,
4326 coff_link_output_has_begun
,
4327 coff_final_link_postscript
,
4328 NULL
/* print_pdata. */
4331 0x01DF, /* magic number */
4335 /* Function pointers to xcoff specific swap routines. */
4336 xcoff_swap_ldhdr_in
,
4337 xcoff_swap_ldhdr_out
,
4338 xcoff_swap_ldsym_in
,
4339 xcoff_swap_ldsym_out
,
4340 xcoff_swap_ldrel_in
,
4341 xcoff_swap_ldrel_out
,
4347 12, /* _xcoff_function_descriptor_size */
4351 1, /* _xcoff_ldhdr_version */
4353 _bfd_xcoff_put_symbol_name
,
4354 _bfd_xcoff_put_ldsymbol_name
,
4355 &xcoff_dynamic_reloc
,
4356 xcoff_create_csect_from_smclas
,
4358 /* Lineno and reloc count overflow. */
4359 xcoff_is_lineno_count_overflow
,
4360 xcoff_is_reloc_count_overflow
,
4362 xcoff_loader_symbol_offset
,
4363 xcoff_loader_reloc_offset
,
4366 &xcoff_glink_code
[0],
4367 36, /* _xcoff_glink_size */
4370 0, /* _xcoff_rtinit_size */
4371 xcoff_generate_rtinit
,
4374 /* The transfer vector that leads the outside world to all of the above. */
4375 const bfd_target pmac_xcoff_vec
=
4378 bfd_target_xcoff_flavour
,
4379 BFD_ENDIAN_BIG
, /* data byte order is big */
4380 BFD_ENDIAN_BIG
, /* header byte order is big */
4382 (HAS_RELOC
| EXEC_P
| HAS_LINENO
| HAS_DEBUG
| DYNAMIC
4383 | HAS_SYMS
| HAS_LOCALS
| WP_TEXT
),
4385 SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_CODE
| SEC_DATA
,
4386 0, /* leading char */
4387 '/', /* ar_pad_char */
4388 15, /* ar_max_namelen */
4412 { /* bfd_check_format */
4415 _bfd_xcoff_archive_p
,
4419 { /* bfd_set_format */
4422 _bfd_generic_mkarchive
,
4426 {/* bfd_write_contents */
4428 coff_write_object_contents
,
4429 _bfd_xcoff_write_archive_contents
,
4436 coff_new_section_hook
,
4437 _bfd_generic_get_section_contents
,
4438 _bfd_generic_get_section_contents_in_window
,
4441 _bfd_xcoff_copy_private_bfd_data
,
4442 ((bfd_boolean (*) (bfd
*, bfd
*)) bfd_true
),
4443 _bfd_generic_init_private_section_data
,
4444 ((bfd_boolean (*) (bfd
*, asection
*, bfd
*, asection
*)) bfd_true
),
4445 ((bfd_boolean (*) (bfd
*, asymbol
*, bfd
*, asymbol
*)) bfd_true
),
4446 ((bfd_boolean (*) (bfd
*, bfd
*)) bfd_true
),
4447 ((bfd_boolean (*) (bfd
*, flagword
)) bfd_true
),
4448 ((bfd_boolean (*) (bfd
*, void * )) bfd_true
),
4451 coff_core_file_failing_command
,
4452 coff_core_file_failing_signal
,
4453 coff_core_file_matches_executable_p
,
4456 _bfd_xcoff_slurp_armap
,
4458 ((bfd_boolean (*) (bfd
*, char **, bfd_size_type
*, const char **)) bfd_false
),
4459 bfd_dont_truncate_arname
,
4460 _bfd_xcoff_write_armap
,
4461 _bfd_xcoff_read_ar_hdr
,
4462 _bfd_xcoff_openr_next_archived_file
,
4463 _bfd_generic_get_elt_at_index
,
4464 _bfd_xcoff_stat_arch_elt
,
4468 coff_get_symtab_upper_bound
,
4469 coff_canonicalize_symtab
,
4470 coff_make_empty_symbol
,
4472 coff_get_symbol_info
,
4473 _bfd_xcoff_is_local_label_name
,
4474 coff_bfd_is_target_special_symbol
,
4476 coff_find_nearest_line
,
4477 _bfd_generic_find_line
,
4478 coff_find_inliner_info
,
4479 coff_bfd_make_debug_symbol
,
4480 _bfd_generic_read_minisymbols
,
4481 _bfd_generic_minisymbol_to_symbol
,
4484 coff_get_reloc_upper_bound
,
4485 coff_canonicalize_reloc
,
4486 _bfd_xcoff_reloc_type_lookup
,
4487 _bfd_xcoff_reloc_name_lookup
,
4491 coff_set_section_contents
,
4494 _bfd_xcoff_sizeof_headers
,
4495 bfd_generic_get_relocated_section_contents
,
4496 bfd_generic_relax_section
,
4497 _bfd_xcoff_bfd_link_hash_table_create
,
4498 _bfd_generic_link_hash_table_free
,
4499 _bfd_xcoff_bfd_link_add_symbols
,
4500 _bfd_generic_link_just_syms
,
4501 _bfd_xcoff_bfd_final_link
,
4502 _bfd_generic_link_split_section
,
4503 bfd_generic_gc_sections
,
4504 bfd_generic_merge_sections
,
4505 bfd_generic_is_group_section
,
4506 bfd_generic_discard_group
,
4507 _bfd_generic_section_already_linked
,
4510 _bfd_xcoff_get_dynamic_symtab_upper_bound
,
4511 _bfd_xcoff_canonicalize_dynamic_symtab
,
4512 _bfd_nodynamic_get_synthetic_symtab
,
4513 _bfd_xcoff_get_dynamic_reloc_upper_bound
,
4514 _bfd_xcoff_canonicalize_dynamic_reloc
,
4516 /* Opposite endian version, none exists */
4519 (void *) &bfd_pmac_xcoff_backend_data
,