1 /* BFD back-end for IBM RS/6000 "XCOFF" files.
2 Copyright 1990-1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
4 Free Software Foundation, Inc.
5 Written by Metin G. Ozisik, Mimi Phuong-Thao Vo, and John Gilmore.
6 Archive support from Damon A. Permezel.
7 Contributed by IBM Corporation and Cygnus Support.
9 This file is part of BFD, the Binary File Descriptor library.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
24 MA 02110-1301, USA. */
30 #include "coff/internal.h"
31 #include "coff/xcoff.h"
32 #include "coff/rs6000.h"
36 extern bfd_boolean
_bfd_xcoff_mkobject (bfd
*);
37 extern bfd_boolean
_bfd_xcoff_copy_private_bfd_data (bfd
*, bfd
*);
38 extern bfd_boolean
_bfd_xcoff_is_local_label_name (bfd
*, const char *);
39 extern reloc_howto_type
*_bfd_xcoff_reloc_type_lookup
40 (bfd
*, bfd_reloc_code_real_type
);
41 extern bfd_boolean
_bfd_xcoff_slurp_armap (bfd
*);
42 extern const bfd_target
*_bfd_xcoff_archive_p (bfd
*);
43 extern PTR
_bfd_xcoff_read_ar_hdr (bfd
*);
44 extern bfd
*_bfd_xcoff_openr_next_archived_file (bfd
*, bfd
*);
45 extern int _bfd_xcoff_stat_arch_elt (bfd
*, struct stat
*);
46 extern bfd_boolean _bfd_xcoff_write_armap
47 (bfd
*, unsigned int, struct orl
*, unsigned int, int);
48 extern bfd_boolean
_bfd_xcoff_write_archive_contents (bfd
*);
49 extern int _bfd_xcoff_sizeof_headers (bfd
*, struct bfd_link_info
*);
50 extern void _bfd_xcoff_swap_sym_in (bfd
*, PTR
, PTR
);
51 extern unsigned int _bfd_xcoff_swap_sym_out (bfd
*, PTR
, PTR
);
52 extern void _bfd_xcoff_swap_aux_in (bfd
*, PTR
, int, int, int, int, PTR
);
53 extern unsigned int _bfd_xcoff_swap_aux_out
54 (bfd
*, PTR
, int, int, int, int, PTR
);
55 static void xcoff_swap_reloc_in (bfd
*, PTR
, PTR
);
56 static unsigned int xcoff_swap_reloc_out (bfd
*, PTR
, PTR
);
58 /* Forward declare xcoff_rtype2howto for coffcode.h macro. */
59 void xcoff_rtype2howto (arelent
*, struct internal_reloc
*);
61 /* coffcode.h needs these to be defined. */
62 #define RS6000COFF_C 1
64 #define SELECT_RELOC(internal, howto) \
66 internal.r_type = howto->type; \
68 ((howto->complain_on_overflow == complain_overflow_signed \
71 | (howto->bitsize - 1)); \
74 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
75 #define COFF_LONG_FILENAMES
76 #define NO_COFF_SYMBOLS
77 #define RTYPE2HOWTO(cache_ptr, dst) xcoff_rtype2howto (cache_ptr, dst)
78 #define coff_mkobject _bfd_xcoff_mkobject
79 #define coff_bfd_copy_private_bfd_data _bfd_xcoff_copy_private_bfd_data
80 #define coff_bfd_is_local_label_name _bfd_xcoff_is_local_label_name
81 #define coff_bfd_reloc_type_lookup _bfd_xcoff_reloc_type_lookup
82 #define coff_bfd_reloc_name_lookup _bfd_xcoff_reloc_name_lookup
84 extern const bfd_target
* rs6000coff_core_p (bfd
*abfd
);
85 extern bfd_boolean rs6000coff_core_file_matches_executable_p
86 (bfd
*cbfd
, bfd
*ebfd
);
87 extern char *rs6000coff_core_file_failing_command (bfd
*abfd
);
88 extern int rs6000coff_core_file_failing_signal (bfd
*abfd
);
89 #define CORE_FILE_P rs6000coff_core_p
90 #define coff_core_file_failing_command \
91 rs6000coff_core_file_failing_command
92 #define coff_core_file_failing_signal \
93 rs6000coff_core_file_failing_signal
94 #define coff_core_file_matches_executable_p \
95 rs6000coff_core_file_matches_executable_p
96 #define coff_core_file_pid \
97 _bfd_nocore_core_file_pid
99 #define CORE_FILE_P _bfd_dummy_target
100 #define coff_core_file_failing_command \
101 _bfd_nocore_core_file_failing_command
102 #define coff_core_file_failing_signal \
103 _bfd_nocore_core_file_failing_signal
104 #define coff_core_file_matches_executable_p \
105 _bfd_nocore_core_file_matches_executable_p
106 #define coff_core_file_pid \
107 _bfd_nocore_core_file_pid
109 #define coff_SWAP_sym_in _bfd_xcoff_swap_sym_in
110 #define coff_SWAP_sym_out _bfd_xcoff_swap_sym_out
111 #define coff_SWAP_aux_in _bfd_xcoff_swap_aux_in
112 #define coff_SWAP_aux_out _bfd_xcoff_swap_aux_out
113 #define coff_swap_reloc_in xcoff_swap_reloc_in
114 #define coff_swap_reloc_out xcoff_swap_reloc_out
115 #define NO_COFF_RELOCS
117 #ifndef bfd_pe_print_pdata
118 #define bfd_pe_print_pdata NULL
121 #include "coffcode.h"
123 /* The main body of code is in coffcode.h. */
125 static const char *normalize_filename (bfd
*);
126 static bfd_boolean xcoff_write_armap_old
127 (bfd
*, unsigned int, struct orl
*, unsigned int, int);
128 static bfd_boolean xcoff_write_armap_big
129 (bfd
*, unsigned int, struct orl
*, unsigned int, int);
130 static bfd_boolean
xcoff_write_archive_contents_old (bfd
*);
131 static bfd_boolean
xcoff_write_archive_contents_big (bfd
*);
132 static void xcoff_swap_ldhdr_in (bfd
*, const PTR
, struct internal_ldhdr
*);
133 static void xcoff_swap_ldhdr_out (bfd
*, const struct internal_ldhdr
*, PTR
);
134 static void xcoff_swap_ldsym_in (bfd
*, const PTR
, struct internal_ldsym
*);
135 static void xcoff_swap_ldsym_out (bfd
*, const struct internal_ldsym
*, PTR
);
136 static void xcoff_swap_ldrel_in (bfd
*, const PTR
, struct internal_ldrel
*);
137 static void xcoff_swap_ldrel_out (bfd
*, const struct internal_ldrel
*, PTR
);
138 static bfd_boolean xcoff_ppc_relocate_section
139 (bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
140 struct internal_reloc
*, struct internal_syment
*, asection
**);
141 static bfd_boolean _bfd_xcoff_put_ldsymbol_name
142 (bfd
*, struct xcoff_loader_info
*, struct internal_ldsym
*, const char *);
143 static asection
*xcoff_create_csect_from_smclas
144 (bfd
*, union internal_auxent
*, const char *);
145 static bfd_boolean
xcoff_is_lineno_count_overflow (bfd
*, bfd_vma
);
146 static bfd_boolean
xcoff_is_reloc_count_overflow (bfd
*, bfd_vma
);
147 static bfd_vma
xcoff_loader_symbol_offset (bfd
*, struct internal_ldhdr
*);
148 static bfd_vma
xcoff_loader_reloc_offset (bfd
*, struct internal_ldhdr
*);
149 static bfd_boolean xcoff_generate_rtinit
150 (bfd
*, const char *, const char *, bfd_boolean
);
151 static bfd_boolean
do_pad (bfd
*, unsigned int);
152 static bfd_boolean
do_copy (bfd
*, bfd
*);
154 /* Relocation functions */
155 static bfd_boolean
xcoff_reloc_type_br (XCOFF_RELOC_FUNCTION_ARGS
);
157 static bfd_boolean xcoff_complain_overflow_dont_func
158 (XCOFF_COMPLAIN_FUNCTION_ARGS
);
159 static bfd_boolean xcoff_complain_overflow_bitfield_func
160 (XCOFF_COMPLAIN_FUNCTION_ARGS
);
161 static bfd_boolean xcoff_complain_overflow_signed_func
162 (XCOFF_COMPLAIN_FUNCTION_ARGS
);
163 static bfd_boolean xcoff_complain_overflow_unsigned_func
164 (XCOFF_COMPLAIN_FUNCTION_ARGS
);
166 bfd_boolean (*xcoff_calculate_relocation
[XCOFF_MAX_CALCULATE_RELOCATION
])
167 (XCOFF_RELOC_FUNCTION_ARGS
) =
169 xcoff_reloc_type_pos
, /* R_POS (0x00) */
170 xcoff_reloc_type_neg
, /* R_NEG (0x01) */
171 xcoff_reloc_type_rel
, /* R_REL (0x02) */
172 xcoff_reloc_type_toc
, /* R_TOC (0x03) */
173 xcoff_reloc_type_fail
, /* R_RTB (0x04) */
174 xcoff_reloc_type_toc
, /* R_GL (0x05) */
175 xcoff_reloc_type_toc
, /* R_TCL (0x06) */
176 xcoff_reloc_type_fail
, /* (0x07) */
177 xcoff_reloc_type_ba
, /* R_BA (0x08) */
178 xcoff_reloc_type_fail
, /* (0x09) */
179 xcoff_reloc_type_br
, /* R_BR (0x0a) */
180 xcoff_reloc_type_fail
, /* (0x0b) */
181 xcoff_reloc_type_pos
, /* R_RL (0x0c) */
182 xcoff_reloc_type_pos
, /* R_RLA (0x0d) */
183 xcoff_reloc_type_fail
, /* (0x0e) */
184 xcoff_reloc_type_noop
, /* R_REF (0x0f) */
185 xcoff_reloc_type_fail
, /* (0x10) */
186 xcoff_reloc_type_fail
, /* (0x11) */
187 xcoff_reloc_type_toc
, /* R_TRL (0x12) */
188 xcoff_reloc_type_toc
, /* R_TRLA (0x13) */
189 xcoff_reloc_type_fail
, /* R_RRTBI (0x14) */
190 xcoff_reloc_type_fail
, /* R_RRTBA (0x15) */
191 xcoff_reloc_type_ba
, /* R_CAI (0x16) */
192 xcoff_reloc_type_crel
, /* R_CREL (0x17) */
193 xcoff_reloc_type_ba
, /* R_RBA (0x18) */
194 xcoff_reloc_type_ba
, /* R_RBAC (0x19) */
195 xcoff_reloc_type_br
, /* R_RBR (0x1a) */
196 xcoff_reloc_type_ba
, /* R_RBRC (0x1b) */
199 bfd_boolean (*xcoff_complain_overflow
[XCOFF_MAX_COMPLAIN_OVERFLOW
])
200 (XCOFF_COMPLAIN_FUNCTION_ARGS
) =
202 xcoff_complain_overflow_dont_func
,
203 xcoff_complain_overflow_bitfield_func
,
204 xcoff_complain_overflow_signed_func
,
205 xcoff_complain_overflow_unsigned_func
,
208 /* Information about one member of an archive. */
209 struct member_layout
{
210 /* The archive member that this structure describes. */
213 /* The number of bytes of padding that must be inserted before the
214 start of the member in order to ensure that the section contents
215 are correctly aligned. */
216 unsigned int leading_padding
;
218 /* The offset of MEMBER from the start of the archive (i.e. the end
219 of the leading padding). */
222 /* The normalized name of MEMBER. */
225 /* The length of NAME, without padding. */
226 bfd_size_type namlen
;
228 /* The length of NAME, with padding. */
229 bfd_size_type padded_namlen
;
231 /* The size of MEMBER's header, including the name and magic sequence. */
232 bfd_size_type header_size
;
234 /* The size of the MEMBER's contents. */
235 bfd_size_type contents_size
;
237 /* The number of bytes of padding that must be inserted after MEMBER
238 in order to preserve even alignment. */
239 bfd_size_type trailing_padding
;
242 /* A structure used for iterating over the members of an archive. */
243 struct archive_iterator
{
244 /* The archive itself. */
247 /* Information about the current archive member. */
248 struct member_layout current
;
250 /* Information about the next archive member. MEMBER is null if there
251 are no more archive members, in which case OFFSET is the offset of
252 the first unused byte. */
253 struct member_layout next
;
256 /* Initialize INFO so that it describes member MEMBER of archive ARCHIVE.
257 OFFSET is the even-padded offset of MEMBER, not including any leading
258 padding needed for section alignment. */
261 member_layout_init (struct member_layout
*info
, bfd
*archive
,
262 bfd
*member
, file_ptr offset
)
264 info
->member
= member
;
265 info
->leading_padding
= 0;
268 info
->name
= normalize_filename (member
);
269 info
->namlen
= strlen (info
->name
);
270 info
->padded_namlen
= info
->namlen
+ (info
->namlen
& 1);
271 if (xcoff_big_format_p (archive
))
272 info
->header_size
= SIZEOF_AR_HDR_BIG
;
274 info
->header_size
= SIZEOF_AR_HDR
;
275 info
->header_size
+= info
->padded_namlen
+ SXCOFFARFMAG
;
276 info
->contents_size
= arelt_size (member
);
277 info
->trailing_padding
= info
->contents_size
& 1;
279 if (bfd_check_format (member
, bfd_object
)
280 && bfd_get_flavour (member
) == bfd_target_xcoff_flavour
281 && (member
->flags
& DYNAMIC
) != 0)
282 info
->leading_padding
283 = (-(offset
+ info
->header_size
)
284 & ((1 << bfd_xcoff_text_align_power (member
)) - 1));
286 info
->offset
= offset
+ info
->leading_padding
;
289 /* Set up ITERATOR to iterate through archive ARCHIVE. */
292 archive_iterator_begin (struct archive_iterator
*iterator
,
295 iterator
->archive
= archive
;
296 member_layout_init (&iterator
->next
, archive
, archive
->archive_head
,
297 xcoff_big_format_p (archive
)
298 ? SIZEOF_AR_FILE_HDR_BIG
299 : SIZEOF_AR_FILE_HDR
);
302 /* Make ITERATOR visit the first unvisited archive member. Return true
303 on success; return false if all members have been visited. */
306 archive_iterator_next (struct archive_iterator
*iterator
)
308 if (!iterator
->next
.member
)
311 iterator
->current
= iterator
->next
;
312 member_layout_init (&iterator
->next
, iterator
->archive
,
313 iterator
->current
.member
->archive_next
,
314 iterator
->current
.offset
315 + iterator
->current
.header_size
316 + iterator
->current
.contents_size
317 + iterator
->current
.trailing_padding
);
321 /* We use our own tdata type. Its first field is the COFF tdata type,
322 so the COFF routines are compatible. */
325 _bfd_xcoff_mkobject (bfd
*abfd
)
327 coff_data_type
*coff
;
328 bfd_size_type amt
= sizeof (struct xcoff_tdata
);
330 abfd
->tdata
.xcoff_obj_data
= (struct xcoff_tdata
*) bfd_zalloc (abfd
, amt
);
331 if (abfd
->tdata
.xcoff_obj_data
== NULL
)
333 coff
= coff_data (abfd
);
334 coff
->symbols
= (coff_symbol_type
*) NULL
;
335 coff
->conversion_table
= (unsigned int *) NULL
;
336 coff
->raw_syments
= (struct coff_ptr_struct
*) NULL
;
339 xcoff_data (abfd
)->modtype
= ('1' << 8) | 'L';
341 /* We set cputype to -1 to indicate that it has not been
343 xcoff_data (abfd
)->cputype
= -1;
345 xcoff_data (abfd
)->csects
= NULL
;
346 xcoff_data (abfd
)->debug_indices
= NULL
;
348 /* text section alignment is different than the default */
349 bfd_xcoff_text_align_power (abfd
) = 2;
354 /* Copy XCOFF data from one BFD to another. */
357 _bfd_xcoff_copy_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
359 struct xcoff_tdata
*ix
, *ox
;
362 if (ibfd
->xvec
!= obfd
->xvec
)
364 ix
= xcoff_data (ibfd
);
365 ox
= xcoff_data (obfd
);
366 ox
->full_aouthdr
= ix
->full_aouthdr
;
372 sec
= coff_section_from_bfd_index (ibfd
, ix
->sntoc
);
376 ox
->sntoc
= sec
->output_section
->target_index
;
378 if (ix
->snentry
== 0)
382 sec
= coff_section_from_bfd_index (ibfd
, ix
->snentry
);
386 ox
->snentry
= sec
->output_section
->target_index
;
388 bfd_xcoff_text_align_power (obfd
) = bfd_xcoff_text_align_power (ibfd
);
389 bfd_xcoff_data_align_power (obfd
) = bfd_xcoff_data_align_power (ibfd
);
390 ox
->modtype
= ix
->modtype
;
391 ox
->cputype
= ix
->cputype
;
392 ox
->maxdata
= ix
->maxdata
;
393 ox
->maxstack
= ix
->maxstack
;
397 /* I don't think XCOFF really has a notion of local labels based on
398 name. This will mean that ld -X doesn't actually strip anything.
399 The AIX native linker does not have a -X option, and it ignores the
403 _bfd_xcoff_is_local_label_name (bfd
*abfd ATTRIBUTE_UNUSED
,
404 const char *name ATTRIBUTE_UNUSED
)
410 _bfd_xcoff_swap_sym_in (bfd
*abfd
, PTR ext1
, PTR in1
)
412 SYMENT
*ext
= (SYMENT
*)ext1
;
413 struct internal_syment
* in
= (struct internal_syment
*)in1
;
415 if (ext
->e
.e_name
[0] != 0)
417 memcpy (in
->_n
._n_name
, ext
->e
.e_name
, SYMNMLEN
);
421 in
->_n
._n_n
._n_zeroes
= 0;
422 in
->_n
._n_n
._n_offset
= H_GET_32 (abfd
, ext
->e
.e
.e_offset
);
425 in
->n_value
= H_GET_32 (abfd
, ext
->e_value
);
426 in
->n_scnum
= H_GET_16 (abfd
, ext
->e_scnum
);
427 in
->n_type
= H_GET_16 (abfd
, ext
->e_type
);
428 in
->n_sclass
= H_GET_8 (abfd
, ext
->e_sclass
);
429 in
->n_numaux
= H_GET_8 (abfd
, ext
->e_numaux
);
433 _bfd_xcoff_swap_sym_out (bfd
*abfd
, PTR inp
, PTR extp
)
435 struct internal_syment
*in
= (struct internal_syment
*)inp
;
436 SYMENT
*ext
=(SYMENT
*)extp
;
438 if (in
->_n
._n_name
[0] != 0)
440 memcpy (ext
->e
.e_name
, in
->_n
._n_name
, SYMNMLEN
);
444 H_PUT_32 (abfd
, 0, ext
->e
.e
.e_zeroes
);
445 H_PUT_32 (abfd
, in
->_n
._n_n
._n_offset
, ext
->e
.e
.e_offset
);
448 H_PUT_32 (abfd
, in
->n_value
, ext
->e_value
);
449 H_PUT_16 (abfd
, in
->n_scnum
, ext
->e_scnum
);
450 H_PUT_16 (abfd
, in
->n_type
, ext
->e_type
);
451 H_PUT_8 (abfd
, in
->n_sclass
, ext
->e_sclass
);
452 H_PUT_8 (abfd
, in
->n_numaux
, ext
->e_numaux
);
453 return bfd_coff_symesz (abfd
);
457 _bfd_xcoff_swap_aux_in (bfd
*abfd
, PTR ext1
, int type
, int in_class
,
458 int indx
, int numaux
, PTR in1
)
460 AUXENT
* ext
= (AUXENT
*)ext1
;
461 union internal_auxent
*in
= (union internal_auxent
*)in1
;
466 if (ext
->x_file
.x_fname
[0] == 0)
468 in
->x_file
.x_n
.x_zeroes
= 0;
469 in
->x_file
.x_n
.x_offset
=
470 H_GET_32 (abfd
, ext
->x_file
.x_n
.x_offset
);
477 memcpy (in
->x_file
.x_fname
, ext
->x_file
.x_fname
,
478 numaux
* sizeof (AUXENT
));
482 memcpy (in
->x_file
.x_fname
, ext
->x_file
.x_fname
, FILNMLEN
);
487 /* RS/6000 "csect" auxents */
491 if (indx
+ 1 == numaux
)
493 in
->x_csect
.x_scnlen
.l
= H_GET_32 (abfd
, ext
->x_csect
.x_scnlen
);
494 in
->x_csect
.x_parmhash
= H_GET_32 (abfd
, ext
->x_csect
.x_parmhash
);
495 in
->x_csect
.x_snhash
= H_GET_16 (abfd
, ext
->x_csect
.x_snhash
);
496 /* We don't have to hack bitfields in x_smtyp because it's
497 defined by shifts-and-ands, which are equivalent on all
499 in
->x_csect
.x_smtyp
= H_GET_8 (abfd
, ext
->x_csect
.x_smtyp
);
500 in
->x_csect
.x_smclas
= H_GET_8 (abfd
, ext
->x_csect
.x_smclas
);
501 in
->x_csect
.x_stab
= H_GET_32 (abfd
, ext
->x_csect
.x_stab
);
502 in
->x_csect
.x_snstab
= H_GET_16 (abfd
, ext
->x_csect
.x_snstab
);
512 in
->x_scn
.x_scnlen
= H_GET_32 (abfd
, ext
->x_scn
.x_scnlen
);
513 in
->x_scn
.x_nreloc
= H_GET_16 (abfd
, ext
->x_scn
.x_nreloc
);
514 in
->x_scn
.x_nlinno
= H_GET_16 (abfd
, ext
->x_scn
.x_nlinno
);
515 /* PE defines some extra fields; we zero them out for
517 in
->x_scn
.x_checksum
= 0;
518 in
->x_scn
.x_associated
= 0;
519 in
->x_scn
.x_comdat
= 0;
526 in
->x_sym
.x_tagndx
.l
= H_GET_32 (abfd
, ext
->x_sym
.x_tagndx
);
527 in
->x_sym
.x_tvndx
= H_GET_16 (abfd
, ext
->x_sym
.x_tvndx
);
529 if (in_class
== C_BLOCK
|| in_class
== C_FCN
|| ISFCN (type
)
532 in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
=
533 H_GET_32 (abfd
, ext
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
534 in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
=
535 H_GET_32 (abfd
, ext
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
539 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0] =
540 H_GET_16 (abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
541 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1] =
542 H_GET_16 (abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
543 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2] =
544 H_GET_16 (abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
545 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3] =
546 H_GET_16 (abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
551 in
->x_sym
.x_misc
.x_fsize
= H_GET_32 (abfd
, ext
->x_sym
.x_misc
.x_fsize
);
555 in
->x_sym
.x_misc
.x_lnsz
.x_lnno
=
556 H_GET_16 (abfd
, ext
->x_sym
.x_misc
.x_lnsz
.x_lnno
);
557 in
->x_sym
.x_misc
.x_lnsz
.x_size
=
558 H_GET_16 (abfd
, ext
->x_sym
.x_misc
.x_lnsz
.x_size
);
562 /* The semicolon is because MSVC doesn't like labels at
567 _bfd_xcoff_swap_aux_out (bfd
*abfd
, PTR inp
, int type
, int in_class
,
568 int indx ATTRIBUTE_UNUSED
,
569 int numaux ATTRIBUTE_UNUSED
,
572 union internal_auxent
*in
= (union internal_auxent
*)inp
;
573 AUXENT
*ext
= (AUXENT
*)extp
;
575 memset ((PTR
)ext
, 0, bfd_coff_auxesz (abfd
));
579 if (in
->x_file
.x_fname
[0] == 0)
581 H_PUT_32 (abfd
, 0, ext
->x_file
.x_n
.x_zeroes
);
582 H_PUT_32 (abfd
, in
->x_file
.x_n
.x_offset
, ext
->x_file
.x_n
.x_offset
);
586 memcpy (ext
->x_file
.x_fname
, in
->x_file
.x_fname
, FILNMLEN
);
590 /* RS/6000 "csect" auxents */
594 if (indx
+ 1 == numaux
)
596 H_PUT_32 (abfd
, in
->x_csect
.x_scnlen
.l
, ext
->x_csect
.x_scnlen
);
597 H_PUT_32 (abfd
, in
->x_csect
.x_parmhash
, ext
->x_csect
.x_parmhash
);
598 H_PUT_16 (abfd
, in
->x_csect
.x_snhash
, ext
->x_csect
.x_snhash
);
599 /* We don't have to hack bitfields in x_smtyp because it's
600 defined by shifts-and-ands, which are equivalent on all
602 H_PUT_8 (abfd
, in
->x_csect
.x_smtyp
, ext
->x_csect
.x_smtyp
);
603 H_PUT_8 (abfd
, in
->x_csect
.x_smclas
, ext
->x_csect
.x_smclas
);
604 H_PUT_32 (abfd
, in
->x_csect
.x_stab
, ext
->x_csect
.x_stab
);
605 H_PUT_16 (abfd
, in
->x_csect
.x_snstab
, ext
->x_csect
.x_snstab
);
615 H_PUT_32 (abfd
, in
->x_scn
.x_scnlen
, ext
->x_scn
.x_scnlen
);
616 H_PUT_16 (abfd
, in
->x_scn
.x_nreloc
, ext
->x_scn
.x_nreloc
);
617 H_PUT_16 (abfd
, in
->x_scn
.x_nlinno
, ext
->x_scn
.x_nlinno
);
623 H_PUT_32 (abfd
, in
->x_sym
.x_tagndx
.l
, ext
->x_sym
.x_tagndx
);
624 H_PUT_16 (abfd
, in
->x_sym
.x_tvndx
, ext
->x_sym
.x_tvndx
);
626 if (in_class
== C_BLOCK
|| in_class
== C_FCN
|| ISFCN (type
)
629 H_PUT_32 (abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
,
630 ext
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
631 H_PUT_32 (abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
,
632 ext
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
636 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0],
637 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
638 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1],
639 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
640 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2],
641 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
642 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3],
643 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
647 H_PUT_32 (abfd
, in
->x_sym
.x_misc
.x_fsize
, ext
->x_sym
.x_misc
.x_fsize
);
650 H_PUT_16 (abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_lnno
,
651 ext
->x_sym
.x_misc
.x_lnsz
.x_lnno
);
652 H_PUT_16 (abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_size
,
653 ext
->x_sym
.x_misc
.x_lnsz
.x_size
);
657 return bfd_coff_auxesz (abfd
);
662 /* The XCOFF reloc table. Actually, XCOFF relocations specify the
663 bitsize and whether they are signed or not, along with a
664 conventional type. This table is for the types, which are used for
665 different algorithms for putting in the reloc. Many of these
666 relocs need special_function entries, which I have not written. */
669 reloc_howto_type xcoff_howto_table
[] =
671 /* Standard 32 bit relocation. */
672 HOWTO (R_POS
, /* type */
674 2, /* size (0 = byte, 1 = short, 2 = long) */
676 FALSE
, /* pc_relative */
678 complain_overflow_bitfield
, /* complain_on_overflow */
679 0, /* special_function */
681 TRUE
, /* partial_inplace */
682 0xffffffff, /* src_mask */
683 0xffffffff, /* dst_mask */
684 FALSE
), /* pcrel_offset */
686 /* 32 bit relocation, but store negative value. */
687 HOWTO (R_NEG
, /* type */
689 -2, /* size (0 = byte, 1 = short, 2 = long) */
691 FALSE
, /* pc_relative */
693 complain_overflow_bitfield
, /* complain_on_overflow */
694 0, /* special_function */
696 TRUE
, /* partial_inplace */
697 0xffffffff, /* src_mask */
698 0xffffffff, /* dst_mask */
699 FALSE
), /* pcrel_offset */
701 /* 32 bit PC relative relocation. */
702 HOWTO (R_REL
, /* type */
704 2, /* size (0 = byte, 1 = short, 2 = long) */
706 TRUE
, /* pc_relative */
708 complain_overflow_signed
, /* complain_on_overflow */
709 0, /* special_function */
711 TRUE
, /* partial_inplace */
712 0xffffffff, /* src_mask */
713 0xffffffff, /* dst_mask */
714 FALSE
), /* pcrel_offset */
716 /* 16 bit TOC relative relocation. */
717 HOWTO (R_TOC
, /* type */
719 1, /* size (0 = byte, 1 = short, 2 = long) */
721 FALSE
, /* pc_relative */
723 complain_overflow_bitfield
, /* complain_on_overflow */
724 0, /* special_function */
726 TRUE
, /* partial_inplace */
727 0xffff, /* src_mask */
728 0xffff, /* dst_mask */
729 FALSE
), /* pcrel_offset */
731 /* I don't really know what this is. */
732 HOWTO (R_RTB
, /* type */
734 2, /* size (0 = byte, 1 = short, 2 = long) */
736 FALSE
, /* pc_relative */
738 complain_overflow_bitfield
, /* complain_on_overflow */
739 0, /* special_function */
741 TRUE
, /* partial_inplace */
742 0xffffffff, /* src_mask */
743 0xffffffff, /* dst_mask */
744 FALSE
), /* pcrel_offset */
746 /* External TOC relative symbol. */
747 HOWTO (R_GL
, /* type */
749 1, /* size (0 = byte, 1 = short, 2 = long) */
751 FALSE
, /* pc_relative */
753 complain_overflow_bitfield
, /* complain_on_overflow */
754 0, /* special_function */
756 TRUE
, /* partial_inplace */
757 0xffff, /* src_mask */
758 0xffff, /* dst_mask */
759 FALSE
), /* pcrel_offset */
761 /* Local TOC relative symbol. */
762 HOWTO (R_TCL
, /* type */
764 1, /* size (0 = byte, 1 = short, 2 = long) */
766 FALSE
, /* pc_relative */
768 complain_overflow_bitfield
, /* complain_on_overflow */
769 0, /* special_function */
771 TRUE
, /* partial_inplace */
772 0xffff, /* src_mask */
773 0xffff, /* dst_mask */
774 FALSE
), /* pcrel_offset */
778 /* Non modifiable absolute branch. */
779 HOWTO (R_BA
, /* type */
781 2, /* size (0 = byte, 1 = short, 2 = long) */
783 FALSE
, /* pc_relative */
785 complain_overflow_bitfield
, /* complain_on_overflow */
786 0, /* special_function */
787 "R_BA_26", /* name */
788 TRUE
, /* partial_inplace */
789 0x03fffffc, /* src_mask */
790 0x03fffffc, /* dst_mask */
791 FALSE
), /* pcrel_offset */
795 /* Non modifiable relative branch. */
796 HOWTO (R_BR
, /* type */
798 2, /* size (0 = byte, 1 = short, 2 = long) */
800 TRUE
, /* pc_relative */
802 complain_overflow_signed
, /* complain_on_overflow */
803 0, /* special_function */
805 TRUE
, /* partial_inplace */
806 0x03fffffc, /* src_mask */
807 0x03fffffc, /* dst_mask */
808 FALSE
), /* pcrel_offset */
813 HOWTO (R_RL
, /* type */
815 1, /* size (0 = byte, 1 = short, 2 = long) */
817 FALSE
, /* pc_relative */
819 complain_overflow_bitfield
, /* complain_on_overflow */
820 0, /* special_function */
822 TRUE
, /* partial_inplace */
823 0xffff, /* src_mask */
824 0xffff, /* dst_mask */
825 FALSE
), /* pcrel_offset */
828 HOWTO (R_RLA
, /* type */
830 1, /* size (0 = byte, 1 = short, 2 = long) */
832 FALSE
, /* pc_relative */
834 complain_overflow_bitfield
, /* complain_on_overflow */
835 0, /* special_function */
837 TRUE
, /* partial_inplace */
838 0xffff, /* src_mask */
839 0xffff, /* dst_mask */
840 FALSE
), /* pcrel_offset */
844 /* Non-relocating reference. Bitsize is 1 so that r_rsize is 0. */
845 HOWTO (R_REF
, /* type */
847 0, /* size (0 = byte, 1 = short, 2 = long) */
849 FALSE
, /* pc_relative */
851 complain_overflow_dont
, /* complain_on_overflow */
852 0, /* special_function */
854 FALSE
, /* partial_inplace */
857 FALSE
), /* pcrel_offset */
862 /* TOC relative indirect load. */
863 HOWTO (R_TRL
, /* type */
865 1, /* size (0 = byte, 1 = short, 2 = long) */
867 FALSE
, /* pc_relative */
869 complain_overflow_bitfield
, /* complain_on_overflow */
870 0, /* special_function */
872 TRUE
, /* partial_inplace */
873 0xffff, /* src_mask */
874 0xffff, /* dst_mask */
875 FALSE
), /* pcrel_offset */
877 /* TOC relative load address. */
878 HOWTO (R_TRLA
, /* type */
880 1, /* size (0 = byte, 1 = short, 2 = long) */
882 FALSE
, /* pc_relative */
884 complain_overflow_bitfield
, /* complain_on_overflow */
885 0, /* special_function */
887 TRUE
, /* partial_inplace */
888 0xffff, /* src_mask */
889 0xffff, /* dst_mask */
890 FALSE
), /* pcrel_offset */
892 /* Modifiable relative branch. */
893 HOWTO (R_RRTBI
, /* type */
895 2, /* size (0 = byte, 1 = short, 2 = long) */
897 FALSE
, /* pc_relative */
899 complain_overflow_bitfield
, /* complain_on_overflow */
900 0, /* special_function */
901 "R_RRTBI", /* name */
902 TRUE
, /* partial_inplace */
903 0xffffffff, /* src_mask */
904 0xffffffff, /* dst_mask */
905 FALSE
), /* pcrel_offset */
907 /* Modifiable absolute branch. */
908 HOWTO (R_RRTBA
, /* type */
910 2, /* size (0 = byte, 1 = short, 2 = long) */
912 FALSE
, /* pc_relative */
914 complain_overflow_bitfield
, /* complain_on_overflow */
915 0, /* special_function */
916 "R_RRTBA", /* name */
917 TRUE
, /* partial_inplace */
918 0xffffffff, /* src_mask */
919 0xffffffff, /* dst_mask */
920 FALSE
), /* pcrel_offset */
922 /* Modifiable call absolute indirect. */
923 HOWTO (R_CAI
, /* type */
925 1, /* size (0 = byte, 1 = short, 2 = long) */
927 FALSE
, /* pc_relative */
929 complain_overflow_bitfield
, /* complain_on_overflow */
930 0, /* special_function */
932 TRUE
, /* partial_inplace */
933 0xffff, /* src_mask */
934 0xffff, /* dst_mask */
935 FALSE
), /* pcrel_offset */
937 /* Modifiable call relative. */
938 HOWTO (R_CREL
, /* type */
940 1, /* size (0 = byte, 1 = short, 2 = long) */
942 FALSE
, /* pc_relative */
944 complain_overflow_bitfield
, /* complain_on_overflow */
945 0, /* special_function */
947 TRUE
, /* partial_inplace */
948 0xffff, /* src_mask */
949 0xffff, /* dst_mask */
950 FALSE
), /* pcrel_offset */
952 /* Modifiable branch absolute. */
953 HOWTO (R_RBA
, /* type */
955 2, /* size (0 = byte, 1 = short, 2 = long) */
957 FALSE
, /* pc_relative */
959 complain_overflow_bitfield
, /* complain_on_overflow */
960 0, /* special_function */
962 TRUE
, /* partial_inplace */
963 0x03fffffc, /* src_mask */
964 0x03fffffc, /* dst_mask */
965 FALSE
), /* pcrel_offset */
967 /* Modifiable branch absolute. */
968 HOWTO (R_RBAC
, /* type */
970 2, /* size (0 = byte, 1 = short, 2 = long) */
972 FALSE
, /* pc_relative */
974 complain_overflow_bitfield
, /* complain_on_overflow */
975 0, /* special_function */
977 TRUE
, /* partial_inplace */
978 0xffffffff, /* src_mask */
979 0xffffffff, /* dst_mask */
980 FALSE
), /* pcrel_offset */
982 /* Modifiable branch relative. */
983 HOWTO (R_RBR
, /* type */
985 2, /* size (0 = byte, 1 = short, 2 = long) */
987 FALSE
, /* pc_relative */
989 complain_overflow_signed
, /* complain_on_overflow */
990 0, /* special_function */
991 "R_RBR_26", /* name */
992 TRUE
, /* partial_inplace */
993 0x03fffffc, /* src_mask */
994 0x03fffffc, /* dst_mask */
995 FALSE
), /* pcrel_offset */
997 /* Modifiable branch absolute. */
998 HOWTO (R_RBRC
, /* type */
1000 1, /* size (0 = byte, 1 = short, 2 = long) */
1002 FALSE
, /* pc_relative */
1004 complain_overflow_bitfield
, /* complain_on_overflow */
1005 0, /* special_function */
1006 "R_RBRC", /* name */
1007 TRUE
, /* partial_inplace */
1008 0xffff, /* src_mask */
1009 0xffff, /* dst_mask */
1010 FALSE
), /* pcrel_offset */
1012 /* 16 bit Non modifiable absolute branch. */
1013 HOWTO (R_BA
, /* type */
1015 1, /* size (0 = byte, 1 = short, 2 = long) */
1017 FALSE
, /* pc_relative */
1019 complain_overflow_bitfield
, /* complain_on_overflow */
1020 0, /* special_function */
1021 "R_BA_16", /* name */
1022 TRUE
, /* partial_inplace */
1023 0xfffc, /* src_mask */
1024 0xfffc, /* dst_mask */
1025 FALSE
), /* pcrel_offset */
1027 /* Modifiable branch relative. */
1028 HOWTO (R_RBR
, /* type */
1030 1, /* size (0 = byte, 1 = short, 2 = long) */
1032 FALSE
, /* pc_relative */
1034 complain_overflow_signed
, /* complain_on_overflow */
1035 0, /* special_function */
1036 "R_RBR_16", /* name */
1037 TRUE
, /* partial_inplace */
1038 0xffff, /* src_mask */
1039 0xffff, /* dst_mask */
1040 FALSE
), /* pcrel_offset */
1042 /* Modifiable branch relative. */
1043 HOWTO (R_RBA
, /* type */
1045 1, /* size (0 = byte, 1 = short, 2 = long) */
1047 FALSE
, /* pc_relative */
1049 complain_overflow_signed
, /* complain_on_overflow */
1050 0, /* special_function */
1051 "R_RBA_16", /* name */
1052 TRUE
, /* partial_inplace */
1053 0xffff, /* src_mask */
1054 0xffff, /* dst_mask */
1055 FALSE
), /* pcrel_offset */
1060 xcoff_rtype2howto (arelent
*relent
, struct internal_reloc
*internal
)
1062 if (internal
->r_type
> R_RBRC
)
1065 /* Default howto layout works most of the time */
1066 relent
->howto
= &xcoff_howto_table
[internal
->r_type
];
1068 /* Special case some 16 bit reloc */
1069 if (15 == (internal
->r_size
& 0x1f))
1071 if (R_BA
== internal
->r_type
)
1072 relent
->howto
= &xcoff_howto_table
[0x1c];
1073 else if (R_RBR
== internal
->r_type
)
1074 relent
->howto
= &xcoff_howto_table
[0x1d];
1075 else if (R_RBA
== internal
->r_type
)
1076 relent
->howto
= &xcoff_howto_table
[0x1e];
1079 /* The r_size field of an XCOFF reloc encodes the bitsize of the
1080 relocation, as well as indicating whether it is signed or not.
1081 Doublecheck that the relocation information gathered from the
1082 type matches this information. The bitsize is not significant
1083 for R_REF relocs. */
1084 if (relent
->howto
->dst_mask
!= 0
1085 && (relent
->howto
->bitsize
1086 != ((unsigned int) internal
->r_size
& 0x1f) + 1))
1091 _bfd_xcoff_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1092 bfd_reloc_code_real_type code
)
1096 case BFD_RELOC_PPC_B26
:
1097 return &xcoff_howto_table
[0xa];
1098 case BFD_RELOC_PPC_BA16
:
1099 return &xcoff_howto_table
[0x1c];
1100 case BFD_RELOC_PPC_BA26
:
1101 return &xcoff_howto_table
[8];
1102 case BFD_RELOC_PPC_TOC16
:
1103 return &xcoff_howto_table
[3];
1105 case BFD_RELOC_CTOR
:
1106 return &xcoff_howto_table
[0];
1107 case BFD_RELOC_NONE
:
1108 return &xcoff_howto_table
[0xf];
1114 static reloc_howto_type
*
1115 _bfd_xcoff_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1121 i
< sizeof (xcoff_howto_table
) / sizeof (xcoff_howto_table
[0]);
1123 if (xcoff_howto_table
[i
].name
!= NULL
1124 && strcasecmp (xcoff_howto_table
[i
].name
, r_name
) == 0)
1125 return &xcoff_howto_table
[i
];
1130 /* XCOFF archive support. The original version of this code was by
1131 Damon A. Permezel. It was enhanced to permit cross support, and
1132 writing archive files, by Ian Lance Taylor, Cygnus Support.
1134 XCOFF uses its own archive format. Everything is hooked together
1135 with file offset links, so it is possible to rapidly update an
1136 archive in place. Of course, we don't do that. An XCOFF archive
1137 has a real file header, not just an ARMAG string. The structure of
1138 the file header and of each archive header appear below.
1140 An XCOFF archive also has a member table, which is a list of
1141 elements in the archive (you can get that by looking through the
1142 linked list, but you have to read a lot more of the file). The
1143 member table has a normal archive header with an empty name. It is
1144 normally (and perhaps must be) the second to last entry in the
1145 archive. The member table data is almost printable ASCII. It
1146 starts with a 12 character decimal string which is the number of
1147 entries in the table. For each entry it has a 12 character decimal
1148 string which is the offset in the archive of that member. These
1149 entries are followed by a series of null terminated strings which
1150 are the member names for each entry.
1152 Finally, an XCOFF archive has a global symbol table, which is what
1153 we call the armap. The global symbol table has a normal archive
1154 header with an empty name. It is normally (and perhaps must be)
1155 the last entry in the archive. The contents start with a four byte
1156 binary number which is the number of entries. This is followed by
1157 a that many four byte binary numbers; each is the file offset of an
1158 entry in the archive. These numbers are followed by a series of
1159 null terminated strings, which are symbol names.
1161 AIX 4.3 introduced a new archive format which can handle larger
1162 files and also 32- and 64-bit objects in the same archive. The
1163 things said above remain true except that there is now more than
1164 one global symbol table. The one is used to index 32-bit objects,
1165 the other for 64-bit objects.
1167 The new archives (recognizable by the new ARMAG string) has larger
1168 field lengths so that we cannot really share any code. Also we have
1169 to take care that we are not generating the new form of archives
1170 on AIX 4.2 or earlier systems. */
1172 /* XCOFF archives use this as a magic string. Note that both strings
1173 have the same length. */
1175 /* Set the magic for archive. */
1178 bfd_xcoff_ar_archive_set_magic (bfd
*abfd ATTRIBUTE_UNUSED
,
1179 char *magic ATTRIBUTE_UNUSED
)
1181 /* Not supported yet. */
1183 /* bfd_xcoff_archive_set_magic (abfd, magic); */
1186 /* Read in the armap of an XCOFF archive. */
1189 _bfd_xcoff_slurp_armap (bfd
*abfd
)
1194 bfd_byte
*contents
, *cend
;
1199 if (xcoff_ardata (abfd
) == NULL
)
1201 bfd_has_map (abfd
) = FALSE
;
1205 if (! xcoff_big_format_p (abfd
))
1207 /* This is for the old format. */
1208 struct xcoff_ar_hdr hdr
;
1210 off
= strtol (xcoff_ardata (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
, abfd
)
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 sz
= strtol (hdr
.size
, (char **) NULL
, 10);
1233 /* Read in the entire symbol table. */
1234 contents
= (bfd_byte
*) bfd_alloc (abfd
, sz
);
1235 if (contents
== NULL
)
1237 if (bfd_bread ((PTR
) contents
, sz
, abfd
) != sz
)
1240 /* The symbol table starts with a four byte count. */
1241 c
= H_GET_32 (abfd
, contents
);
1245 bfd_set_error (bfd_error_bad_value
);
1249 bfd_ardata (abfd
)->symdefs
=
1250 ((carsym
*) bfd_alloc (abfd
, c
* sizeof (carsym
)));
1251 if (bfd_ardata (abfd
)->symdefs
== NULL
)
1254 /* After the count comes a list of four byte file offsets. */
1255 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
, p
= contents
+ 4;
1257 ++i
, ++arsym
, p
+= 4)
1258 arsym
->file_offset
= H_GET_32 (abfd
, p
);
1262 /* This is for the new format. */
1263 struct xcoff_ar_hdr_big hdr
;
1265 off
= strtol (xcoff_ardata_big (abfd
)->symoff
, (char **) NULL
, 10);
1268 bfd_has_map (abfd
) = FALSE
;
1272 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0)
1275 /* The symbol table starts with a normal archive header. */
1276 if (bfd_bread ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR_BIG
, abfd
)
1277 != SIZEOF_AR_HDR_BIG
)
1280 /* Skip the name (normally empty). */
1281 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1282 off
= ((namlen
+ 1) & ~ (size_t) 1) + SXCOFFARFMAG
;
1283 if (bfd_seek (abfd
, off
, SEEK_CUR
) != 0)
1286 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1287 machines) since the field width is 20 and there numbers with more
1288 than 32 bits can be represented. */
1289 sz
= strtol (hdr
.size
, (char **) NULL
, 10);
1291 /* Read in the entire symbol table. */
1292 contents
= (bfd_byte
*) bfd_alloc (abfd
, sz
);
1293 if (contents
== NULL
)
1295 if (bfd_bread ((PTR
) contents
, sz
, abfd
) != sz
)
1298 /* The symbol table starts with an eight byte count. */
1299 c
= H_GET_64 (abfd
, contents
);
1303 bfd_set_error (bfd_error_bad_value
);
1307 bfd_ardata (abfd
)->symdefs
=
1308 ((carsym
*) bfd_alloc (abfd
, c
* sizeof (carsym
)));
1309 if (bfd_ardata (abfd
)->symdefs
== NULL
)
1312 /* After the count comes a list of eight byte file offsets. */
1313 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
, p
= contents
+ 8;
1315 ++i
, ++arsym
, p
+= 8)
1316 arsym
->file_offset
= H_GET_64 (abfd
, p
);
1319 /* After the file offsets come null terminated symbol names. */
1320 cend
= contents
+ sz
;
1321 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
;
1323 ++i
, ++arsym
, p
+= strlen ((char *) p
) + 1)
1327 bfd_set_error (bfd_error_bad_value
);
1330 arsym
->name
= (char *) p
;
1333 bfd_ardata (abfd
)->symdef_count
= c
;
1334 bfd_has_map (abfd
) = TRUE
;
1339 /* See if this is an XCOFF archive. */
1342 _bfd_xcoff_archive_p (bfd
*abfd
)
1344 struct artdata
*tdata_hold
;
1345 char magic
[SXCOFFARMAG
];
1346 bfd_size_type amt
= SXCOFFARMAG
;
1348 if (bfd_bread ((PTR
) magic
, amt
, abfd
) != amt
)
1350 if (bfd_get_error () != bfd_error_system_call
)
1351 bfd_set_error (bfd_error_wrong_format
);
1355 if (strncmp (magic
, XCOFFARMAG
, SXCOFFARMAG
) != 0
1356 && strncmp (magic
, XCOFFARMAGBIG
, SXCOFFARMAG
) != 0)
1358 bfd_set_error (bfd_error_wrong_format
);
1362 tdata_hold
= bfd_ardata (abfd
);
1364 amt
= sizeof (struct artdata
);
1365 bfd_ardata (abfd
) = (struct artdata
*) bfd_zalloc (abfd
, amt
);
1366 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
1367 goto error_ret_restore
;
1369 /* Cleared by bfd_zalloc above.
1370 bfd_ardata (abfd)->cache = NULL;
1371 bfd_ardata (abfd)->archive_head = NULL;
1372 bfd_ardata (abfd)->symdefs = NULL;
1373 bfd_ardata (abfd)->extended_names = NULL;
1374 bfd_ardata (abfd)->extended_names_size = 0; */
1376 /* Now handle the two formats. */
1377 if (magic
[1] != 'b')
1379 /* This is the old format. */
1380 struct xcoff_ar_file_hdr hdr
;
1382 /* Copy over the magic string. */
1383 memcpy (hdr
.magic
, magic
, SXCOFFARMAG
);
1385 /* Now read the rest of the file header. */
1386 amt
= SIZEOF_AR_FILE_HDR
- SXCOFFARMAG
;
1387 if (bfd_bread ((PTR
) &hdr
.memoff
, amt
, abfd
) != amt
)
1389 if (bfd_get_error () != bfd_error_system_call
)
1390 bfd_set_error (bfd_error_wrong_format
);
1394 bfd_ardata (abfd
)->first_file_filepos
= strtol (hdr
.firstmemoff
,
1395 (char **) NULL
, 10);
1397 amt
= SIZEOF_AR_FILE_HDR
;
1398 bfd_ardata (abfd
)->tdata
= bfd_zalloc (abfd
, amt
);
1399 if (bfd_ardata (abfd
)->tdata
== NULL
)
1402 memcpy (bfd_ardata (abfd
)->tdata
, &hdr
, SIZEOF_AR_FILE_HDR
);
1406 /* This is the new format. */
1407 struct xcoff_ar_file_hdr_big hdr
;
1409 /* Copy over the magic string. */
1410 memcpy (hdr
.magic
, magic
, SXCOFFARMAG
);
1412 /* Now read the rest of the file header. */
1413 amt
= SIZEOF_AR_FILE_HDR_BIG
- SXCOFFARMAG
;
1414 if (bfd_bread ((PTR
) &hdr
.memoff
, amt
, abfd
) != amt
)
1416 if (bfd_get_error () != bfd_error_system_call
)
1417 bfd_set_error (bfd_error_wrong_format
);
1421 bfd_ardata (abfd
)->first_file_filepos
= bfd_scan_vma (hdr
.firstmemoff
,
1425 amt
= SIZEOF_AR_FILE_HDR_BIG
;
1426 bfd_ardata (abfd
)->tdata
= bfd_zalloc (abfd
, amt
);
1427 if (bfd_ardata (abfd
)->tdata
== NULL
)
1430 memcpy (bfd_ardata (abfd
)->tdata
, &hdr
, SIZEOF_AR_FILE_HDR_BIG
);
1433 if (! _bfd_xcoff_slurp_armap (abfd
))
1436 bfd_release (abfd
, bfd_ardata (abfd
));
1438 bfd_ardata (abfd
) = tdata_hold
;
1445 /* Read the archive header in an XCOFF archive. */
1448 _bfd_xcoff_read_ar_hdr (bfd
*abfd
)
1450 bfd_size_type namlen
;
1451 struct areltdata
*ret
;
1452 bfd_size_type amt
= sizeof (struct areltdata
);
1454 ret
= (struct areltdata
*) bfd_alloc (abfd
, amt
);
1458 if (! xcoff_big_format_p (abfd
))
1460 struct xcoff_ar_hdr hdr
;
1461 struct xcoff_ar_hdr
*hdrp
;
1463 if (bfd_bread ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1470 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1471 amt
= SIZEOF_AR_HDR
+ namlen
+ 1;
1472 hdrp
= (struct xcoff_ar_hdr
*) bfd_alloc (abfd
, amt
);
1478 memcpy (hdrp
, &hdr
, SIZEOF_AR_HDR
);
1479 if (bfd_bread ((char *) hdrp
+ SIZEOF_AR_HDR
, namlen
, abfd
) != namlen
)
1484 ((char *) hdrp
)[SIZEOF_AR_HDR
+ namlen
] = '\0';
1486 ret
->arch_header
= (char *) hdrp
;
1487 ret
->parsed_size
= strtol (hdr
.size
, (char **) NULL
, 10);
1488 ret
->filename
= (char *) hdrp
+ SIZEOF_AR_HDR
;
1492 struct xcoff_ar_hdr_big hdr
;
1493 struct xcoff_ar_hdr_big
*hdrp
;
1495 if (bfd_bread ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR_BIG
, abfd
)
1496 != SIZEOF_AR_HDR_BIG
)
1502 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1503 amt
= SIZEOF_AR_HDR_BIG
+ namlen
+ 1;
1504 hdrp
= (struct xcoff_ar_hdr_big
*) bfd_alloc (abfd
, amt
);
1510 memcpy (hdrp
, &hdr
, SIZEOF_AR_HDR_BIG
);
1511 if (bfd_bread ((char *) hdrp
+ SIZEOF_AR_HDR_BIG
, namlen
, abfd
) != namlen
)
1516 ((char *) hdrp
)[SIZEOF_AR_HDR_BIG
+ namlen
] = '\0';
1518 ret
->arch_header
= (char *) hdrp
;
1519 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1520 machines) since the field width is 20 and there numbers with more
1521 than 32 bits can be represented. */
1522 ret
->parsed_size
= strtol (hdr
.size
, (char **) NULL
, 10);
1523 ret
->filename
= (char *) hdrp
+ SIZEOF_AR_HDR_BIG
;
1526 /* Skip over the XCOFFARFMAG at the end of the file name. */
1527 if (bfd_seek (abfd
, (file_ptr
) ((namlen
& 1) + SXCOFFARFMAG
), SEEK_CUR
) != 0)
1533 /* Open the next element in an XCOFF archive. */
1536 _bfd_xcoff_openr_next_archived_file (bfd
*archive
, bfd
*last_file
)
1540 if (xcoff_ardata (archive
) == NULL
)
1542 bfd_set_error (bfd_error_invalid_operation
);
1546 if (! xcoff_big_format_p (archive
))
1548 if (last_file
== NULL
)
1549 filestart
= bfd_ardata (archive
)->first_file_filepos
;
1551 filestart
= strtol (arch_xhdr (last_file
)->nextoff
, (char **) NULL
,
1555 || filestart
== strtol (xcoff_ardata (archive
)->memoff
,
1557 || filestart
== strtol (xcoff_ardata (archive
)->symoff
,
1558 (char **) NULL
, 10))
1560 bfd_set_error (bfd_error_no_more_archived_files
);
1566 if (last_file
== NULL
)
1567 filestart
= bfd_ardata (archive
)->first_file_filepos
;
1569 /* XXX These actually have to be a calls to strtoll (at least
1570 on 32-bit machines) since the fields's width is 20 and
1571 there numbers with more than 32 bits can be represented. */
1572 filestart
= strtol (arch_xhdr_big (last_file
)->nextoff
, (char **) NULL
,
1575 /* XXX These actually have to be calls to strtoll (at least on 32-bit
1576 machines) since the fields's width is 20 and there numbers with more
1577 than 32 bits can be represented. */
1579 || filestart
== strtol (xcoff_ardata_big (archive
)->memoff
,
1581 || filestart
== strtol (xcoff_ardata_big (archive
)->symoff
,
1582 (char **) NULL
, 10))
1584 bfd_set_error (bfd_error_no_more_archived_files
);
1589 return _bfd_get_elt_at_filepos (archive
, filestart
);
1592 /* Stat an element in an XCOFF archive. */
1595 _bfd_xcoff_stat_arch_elt (bfd
*abfd
, struct stat
*s
)
1597 if (abfd
->arelt_data
== NULL
)
1599 bfd_set_error (bfd_error_invalid_operation
);
1603 if (! xcoff_big_format_p (abfd
->my_archive
))
1605 struct xcoff_ar_hdr
*hdrp
= arch_xhdr (abfd
);
1607 s
->st_mtime
= strtol (hdrp
->date
, (char **) NULL
, 10);
1608 s
->st_uid
= strtol (hdrp
->uid
, (char **) NULL
, 10);
1609 s
->st_gid
= strtol (hdrp
->gid
, (char **) NULL
, 10);
1610 s
->st_mode
= strtol (hdrp
->mode
, (char **) NULL
, 8);
1611 s
->st_size
= arch_eltdata (abfd
)->parsed_size
;
1615 struct xcoff_ar_hdr_big
*hdrp
= arch_xhdr_big (abfd
);
1617 s
->st_mtime
= strtol (hdrp
->date
, (char **) NULL
, 10);
1618 s
->st_uid
= strtol (hdrp
->uid
, (char **) NULL
, 10);
1619 s
->st_gid
= strtol (hdrp
->gid
, (char **) NULL
, 10);
1620 s
->st_mode
= strtol (hdrp
->mode
, (char **) NULL
, 8);
1621 s
->st_size
= arch_eltdata (abfd
)->parsed_size
;
1627 /* Normalize a file name for inclusion in an archive. */
1630 normalize_filename (bfd
*abfd
)
1633 const char *filename
;
1635 file
= bfd_get_filename (abfd
);
1636 filename
= strrchr (file
, '/');
1637 if (filename
!= NULL
)
1644 /* Write out an XCOFF armap. */
1647 xcoff_write_armap_old (bfd
*abfd
, unsigned int elength ATTRIBUTE_UNUSED
,
1648 struct orl
*map
, unsigned int orl_count
, int stridx
)
1650 struct archive_iterator iterator
;
1651 struct xcoff_ar_hdr hdr
;
1653 unsigned char buf
[4];
1656 memset (&hdr
, 0, sizeof hdr
);
1657 sprintf (hdr
.size
, "%ld", (long) (4 + orl_count
* 4 + stridx
));
1658 sprintf (hdr
.nextoff
, "%d", 0);
1659 memcpy (hdr
.prevoff
, xcoff_ardata (abfd
)->memoff
, XCOFFARMAG_ELEMENT_SIZE
);
1660 sprintf (hdr
.date
, "%d", 0);
1661 sprintf (hdr
.uid
, "%d", 0);
1662 sprintf (hdr
.gid
, "%d", 0);
1663 sprintf (hdr
.mode
, "%d", 0);
1664 sprintf (hdr
.namlen
, "%d", 0);
1666 /* We need spaces, not null bytes, in the header. */
1667 for (p
= (char *) &hdr
; p
< (char *) &hdr
+ SIZEOF_AR_HDR
; p
++)
1671 if (bfd_bwrite ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1673 || (bfd_bwrite (XCOFFARFMAG
, (bfd_size_type
) SXCOFFARFMAG
, abfd
)
1677 H_PUT_32 (abfd
, orl_count
, buf
);
1678 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
1682 archive_iterator_begin (&iterator
, abfd
);
1683 while (i
< orl_count
&& archive_iterator_next (&iterator
))
1684 while (map
[i
].u
.abfd
== iterator
.current
.member
)
1686 H_PUT_32 (abfd
, iterator
.current
.offset
, buf
);
1687 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
1692 for (i
= 0; i
< orl_count
; i
++)
1697 name
= *map
[i
].name
;
1698 namlen
= strlen (name
);
1699 if (bfd_bwrite (name
, (bfd_size_type
) (namlen
+ 1), abfd
) != namlen
+ 1)
1703 if ((stridx
& 1) != 0)
1708 if (bfd_bwrite (&b
, (bfd_size_type
) 1, abfd
) != 1)
1715 static char buff20
[XCOFFARMAGBIG_ELEMENT_SIZE
+ 1];
1716 #define FMT20 "%-20lld"
1717 #define FMT12 "%-12d"
1718 #define FMT12_OCTAL "%-12o"
1720 #define PRINT20(d, v) \
1721 sprintf (buff20, FMT20, (long long)(v)), \
1722 memcpy ((void *) (d), buff20, 20)
1724 #define PRINT12(d, v) \
1725 sprintf (buff20, FMT12, (int)(v)), \
1726 memcpy ((void *) (d), buff20, 12)
1728 #define PRINT12_OCTAL(d, v) \
1729 sprintf (buff20, FMT12_OCTAL, (unsigned int)(v)), \
1730 memcpy ((void *) (d), buff20, 12)
1732 #define PRINT4(d, v) \
1733 sprintf (buff20, FMT4, (int)(v)), \
1734 memcpy ((void *) (d), buff20, 4)
1736 #define READ20(d, v) \
1738 memcpy (buff20, (d), 20), \
1739 (v) = bfd_scan_vma (buff20, (const char **) NULL, 10)
1742 do_pad (bfd
*abfd
, unsigned int number
)
1746 /* Limit pad to <= 4096. */
1751 if (bfd_bwrite (&b
, (bfd_size_type
) 1, abfd
) != 1)
1758 do_copy (bfd
*out_bfd
, bfd
*in_bfd
)
1760 bfd_size_type remaining
;
1761 bfd_byte buffer
[DEFAULT_BUFFERSIZE
];
1763 if (bfd_seek (in_bfd
, (file_ptr
) 0, SEEK_SET
) != 0)
1766 remaining
= arelt_size (in_bfd
);
1768 while (remaining
>= DEFAULT_BUFFERSIZE
)
1770 if (bfd_bread (buffer
, DEFAULT_BUFFERSIZE
, in_bfd
) != DEFAULT_BUFFERSIZE
1771 || bfd_bwrite (buffer
, DEFAULT_BUFFERSIZE
, out_bfd
) != DEFAULT_BUFFERSIZE
)
1774 remaining
-= DEFAULT_BUFFERSIZE
;
1779 if (bfd_bread (buffer
, remaining
, in_bfd
) != remaining
1780 || bfd_bwrite (buffer
, remaining
, out_bfd
) != remaining
)
1788 xcoff_write_armap_big (bfd
*abfd
, unsigned int elength ATTRIBUTE_UNUSED
,
1789 struct orl
*map
, unsigned int orl_count
, int stridx
)
1791 struct archive_iterator iterator
;
1792 struct xcoff_ar_file_hdr_big
*fhdr
;
1793 bfd_vma i
, sym_32
, sym_64
, str_32
, str_64
;
1794 const bfd_arch_info_type
*arch_info
;
1796 size_t string_length
;
1797 file_ptr nextoff
, prevoff
;
1799 /* First, we look through the symbols and work out which are
1800 from 32-bit objects and which from 64-bit ones. */
1801 sym_32
= sym_64
= str_32
= str_64
= 0;
1804 for (current_bfd
= abfd
->archive_head
;
1805 current_bfd
!= NULL
&& i
< orl_count
;
1806 current_bfd
= current_bfd
->archive_next
)
1808 arch_info
= bfd_get_arch_info (current_bfd
);
1809 while (map
[i
].u
.abfd
== current_bfd
)
1811 string_length
= strlen (*map
[i
].name
) + 1;
1812 if (arch_info
->bits_per_address
== 64)
1815 str_64
+= string_length
;
1820 str_32
+= string_length
;
1826 /* A quick sanity check... */
1827 BFD_ASSERT (sym_64
+ sym_32
== orl_count
);
1828 /* Explicit cast to int for compiler. */
1829 BFD_ASSERT ((int)(str_64
+ str_32
) == stridx
);
1831 fhdr
= xcoff_ardata_big (abfd
);
1833 /* xcoff_write_archive_contents_big passes nextoff in symoff. */
1834 READ20 (fhdr
->memoff
, prevoff
);
1835 READ20 (fhdr
->symoff
, nextoff
);
1837 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
1839 /* Write out the symbol table.
1842 standard big archive header
1843 0x0000 ar_size [0x14]
1844 0x0014 ar_nxtmem [0x14]
1845 0x0028 ar_prvmem [0x14]
1846 0x003C ar_date [0x0C]
1847 0x0048 ar_uid [0x0C]
1848 0x0054 ar_gid [0x0C]
1849 0x0060 ar_mod [0x0C]
1850 0x006C ar_namelen[0x04]
1851 0x0070 ar_fmag [SXCOFFARFMAG]
1854 0x0072 num_syms [0x08], binary
1855 0x0078 offsets [0x08 * num_syms], binary
1856 0x0086 + 0x08 * num_syms names [??]
1857 ?? pad to even bytes.
1862 struct xcoff_ar_hdr_big
*hdr
;
1866 bfd_vma symbol_table_size
=
1871 + str_32
+ (str_32
& 1);
1873 symbol_table
= bfd_zmalloc (symbol_table_size
);
1874 if (symbol_table
== NULL
)
1877 hdr
= (struct xcoff_ar_hdr_big
*) symbol_table
;
1879 PRINT20 (hdr
->size
, 8 + 8 * sym_32
+ str_32
+ (str_32
& 1));
1882 PRINT20 (hdr
->nextoff
, nextoff
+ symbol_table_size
);
1884 PRINT20 (hdr
->nextoff
, 0);
1886 PRINT20 (hdr
->prevoff
, prevoff
);
1887 PRINT12 (hdr
->date
, 0);
1888 PRINT12 (hdr
->uid
, 0);
1889 PRINT12 (hdr
->gid
, 0);
1890 PRINT12 (hdr
->mode
, 0);
1891 PRINT4 (hdr
->namlen
, 0) ;
1893 st
= symbol_table
+ SIZEOF_AR_HDR_BIG
;
1894 memcpy (st
, XCOFFARFMAG
, SXCOFFARFMAG
);
1897 bfd_h_put_64 (abfd
, sym_32
, st
);
1900 /* loop over the 32 bit offsets */
1902 archive_iterator_begin (&iterator
, abfd
);
1903 while (i
< orl_count
&& archive_iterator_next (&iterator
))
1905 arch_info
= bfd_get_arch_info (iterator
.current
.member
);
1906 while (map
[i
].u
.abfd
== iterator
.current
.member
)
1908 if (arch_info
->bits_per_address
== 32)
1910 bfd_h_put_64 (abfd
, iterator
.current
.offset
, st
);
1917 /* loop over the 32 bit symbol names */
1919 for (current_bfd
= abfd
->archive_head
;
1920 current_bfd
!= NULL
&& i
< orl_count
;
1921 current_bfd
= current_bfd
->archive_next
)
1923 arch_info
= bfd_get_arch_info (current_bfd
);
1924 while (map
[i
].u
.abfd
== current_bfd
)
1926 if (arch_info
->bits_per_address
== 32)
1928 string_length
= sprintf (st
, "%s", *map
[i
].name
);
1929 st
+= string_length
+ 1;
1935 bfd_bwrite (symbol_table
, symbol_table_size
, abfd
);
1937 free (symbol_table
);
1940 nextoff
= nextoff
+ symbol_table_size
;
1943 PRINT20 (fhdr
->symoff
, 0);
1947 struct xcoff_ar_hdr_big
*hdr
;
1951 bfd_vma symbol_table_size
=
1956 + str_64
+ (str_64
& 1);
1958 symbol_table
= bfd_zmalloc (symbol_table_size
);
1959 if (symbol_table
== NULL
)
1962 hdr
= (struct xcoff_ar_hdr_big
*) symbol_table
;
1964 PRINT20 (hdr
->size
, 8 + 8 * sym_64
+ str_64
+ (str_64
& 1));
1965 PRINT20 (hdr
->nextoff
, 0);
1966 PRINT20 (hdr
->prevoff
, prevoff
);
1967 PRINT12 (hdr
->date
, 0);
1968 PRINT12 (hdr
->uid
, 0);
1969 PRINT12 (hdr
->gid
, 0);
1970 PRINT12 (hdr
->mode
, 0);
1971 PRINT4 (hdr
->namlen
, 0);
1973 st
= symbol_table
+ SIZEOF_AR_HDR_BIG
;
1974 memcpy (st
, XCOFFARFMAG
, SXCOFFARFMAG
);
1977 bfd_h_put_64 (abfd
, sym_64
, st
);
1980 /* loop over the 64 bit offsets */
1982 archive_iterator_begin (&iterator
, abfd
);
1983 while (i
< orl_count
&& archive_iterator_next (&iterator
))
1985 arch_info
= bfd_get_arch_info (iterator
.current
.member
);
1986 while (map
[i
].u
.abfd
== iterator
.current
.member
)
1988 if (arch_info
->bits_per_address
== 64)
1990 bfd_h_put_64 (abfd
, iterator
.current
.offset
, st
);
1997 /* loop over the 64 bit symbol names */
1999 for (current_bfd
= abfd
->archive_head
;
2000 current_bfd
!= NULL
&& i
< orl_count
;
2001 current_bfd
= current_bfd
->archive_next
)
2003 arch_info
= bfd_get_arch_info (current_bfd
);
2004 while (map
[i
].u
.abfd
== current_bfd
)
2006 if (arch_info
->bits_per_address
== 64)
2008 string_length
= sprintf (st
, "%s", *map
[i
].name
);
2009 st
+= string_length
+ 1;
2015 bfd_bwrite (symbol_table
, symbol_table_size
, abfd
);
2017 free (symbol_table
);
2019 PRINT20 (fhdr
->symoff64
, nextoff
);
2022 PRINT20 (fhdr
->symoff64
, 0);
2028 _bfd_xcoff_write_armap (bfd
*abfd
, unsigned int elength ATTRIBUTE_UNUSED
,
2029 struct orl
*map
, unsigned int orl_count
, int stridx
)
2031 if (! xcoff_big_format_p (abfd
))
2032 return xcoff_write_armap_old (abfd
, elength
, map
, orl_count
, stridx
);
2034 return xcoff_write_armap_big (abfd
, elength
, map
, orl_count
, stridx
);
2037 /* Write out an XCOFF archive. We always write an entire archive,
2038 rather than fussing with the freelist and so forth. */
2041 xcoff_write_archive_contents_old (bfd
*abfd
)
2043 struct archive_iterator iterator
;
2044 struct xcoff_ar_file_hdr fhdr
;
2045 bfd_size_type count
;
2046 bfd_size_type total_namlen
;
2048 bfd_boolean makemap
;
2049 bfd_boolean hasobjects
;
2050 file_ptr prevoff
, nextoff
;
2053 struct xcoff_ar_hdr ahdr
;
2056 char decbuf
[XCOFFARMAG_ELEMENT_SIZE
+ 1];
2058 memset (&fhdr
, 0, sizeof fhdr
);
2059 (void) strncpy (fhdr
.magic
, XCOFFARMAG
, SXCOFFARMAG
);
2060 sprintf (fhdr
.firstmemoff
, "%d", SIZEOF_AR_FILE_HDR
);
2061 sprintf (fhdr
.freeoff
, "%d", 0);
2065 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->archive_next
)
2068 total_namlen
+= strlen (normalize_filename (sub
)) + 1;
2069 if (sub
->arelt_data
== NULL
)
2071 sub
->arelt_data
= bfd_zalloc (sub
, sizeof (struct areltdata
));
2072 if (sub
->arelt_data
== NULL
)
2075 if (arch_xhdr (sub
) == NULL
)
2077 struct xcoff_ar_hdr
*ahdrp
;
2080 if (stat (bfd_get_filename (sub
), &s
) != 0)
2082 bfd_set_error (bfd_error_system_call
);
2086 ahdrp
= bfd_zalloc (sub
, sizeof (*ahdrp
));
2090 sprintf (ahdrp
->size
, "%ld", (long) s
.st_size
);
2091 sprintf (ahdrp
->date
, "%ld", (long) s
.st_mtime
);
2092 sprintf (ahdrp
->uid
, "%ld", (long) s
.st_uid
);
2093 sprintf (ahdrp
->gid
, "%ld", (long) s
.st_gid
);
2094 sprintf (ahdrp
->mode
, "%o", (unsigned int) s
.st_mode
);
2096 arch_eltdata (sub
)->arch_header
= (char *) ahdrp
;
2097 arch_eltdata (sub
)->parsed_size
= s
.st_size
;
2100 offsets
= (file_ptr
*) bfd_alloc (abfd
, count
* sizeof (file_ptr
));
2101 if (offsets
== NULL
)
2104 if (bfd_seek (abfd
, (file_ptr
) SIZEOF_AR_FILE_HDR
, SEEK_SET
) != 0)
2107 makemap
= bfd_has_map (abfd
);
2110 for (archive_iterator_begin (&iterator
, abfd
), i
= 0;
2111 archive_iterator_next (&iterator
);
2114 bfd_size_type namlen
;
2115 struct xcoff_ar_hdr
*ahdrp
;
2117 if (makemap
&& ! hasobjects
)
2119 if (bfd_check_format (iterator
.current
.member
, bfd_object
))
2123 ahdrp
= arch_xhdr (iterator
.current
.member
);
2124 sprintf (ahdrp
->prevoff
, "%ld", (long) prevoff
);
2125 sprintf (ahdrp
->namlen
, "%ld", (long) iterator
.current
.namlen
);
2126 sprintf (ahdrp
->nextoff
, "%ld", (long) iterator
.next
.offset
);
2128 /* We need spaces, not null bytes, in the header. */
2129 for (p
= (char *) ahdrp
; p
< (char *) ahdrp
+ SIZEOF_AR_HDR
; p
++)
2133 if (!do_pad (abfd
, iterator
.current
.leading_padding
))
2136 BFD_ASSERT (iterator
.current
.offset
== bfd_tell (abfd
));
2137 namlen
= iterator
.current
.padded_namlen
;
2138 if (bfd_bwrite (ahdrp
, SIZEOF_AR_HDR
, abfd
) != SIZEOF_AR_HDR
2139 || bfd_bwrite (iterator
.current
.name
, namlen
, abfd
) != namlen
2140 || bfd_bwrite (XCOFFARFMAG
, SXCOFFARFMAG
, abfd
) != SXCOFFARFMAG
2141 || bfd_seek (iterator
.current
.member
, 0, SEEK_SET
) != 0
2142 || !do_copy (abfd
, iterator
.current
.member
)
2143 || !do_pad (abfd
, iterator
.current
.trailing_padding
))
2146 offsets
[i
] = iterator
.current
.offset
;
2147 prevoff
= iterator
.current
.offset
;
2150 sprintf (fhdr
.lastmemoff
, "%ld", (long) prevoff
);
2152 /* Write out the member table. */
2154 nextoff
= iterator
.next
.offset
;
2155 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2156 sprintf (fhdr
.memoff
, "%ld", (long) nextoff
);
2158 memset (&ahdr
, 0, sizeof ahdr
);
2159 sprintf (ahdr
.size
, "%ld", (long) (XCOFFARMAG_ELEMENT_SIZE
2160 + count
* XCOFFARMAG_ELEMENT_SIZE
2162 sprintf (ahdr
.prevoff
, "%ld", (long) prevoff
);
2163 sprintf (ahdr
.date
, "%d", 0);
2164 sprintf (ahdr
.uid
, "%d", 0);
2165 sprintf (ahdr
.gid
, "%d", 0);
2166 sprintf (ahdr
.mode
, "%d", 0);
2167 sprintf (ahdr
.namlen
, "%d", 0);
2169 size
= (SIZEOF_AR_HDR
2170 + XCOFFARMAG_ELEMENT_SIZE
2171 + count
* XCOFFARMAG_ELEMENT_SIZE
2176 nextoff
+= size
+ (size
& 1);
2178 if (makemap
&& hasobjects
)
2179 sprintf (ahdr
.nextoff
, "%ld", (long) nextoff
);
2181 sprintf (ahdr
.nextoff
, "%d", 0);
2183 /* We need spaces, not null bytes, in the header. */
2184 for (p
= (char *) &ahdr
; p
< (char *) &ahdr
+ SIZEOF_AR_HDR
; p
++)
2188 if ((bfd_bwrite ((PTR
) &ahdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
2190 || (bfd_bwrite ((PTR
) XCOFFARFMAG
, (bfd_size_type
) SXCOFFARFMAG
, abfd
)
2194 sprintf (decbuf
, "%-12ld", (long) count
);
2195 if (bfd_bwrite ((PTR
) decbuf
, (bfd_size_type
) XCOFFARMAG_ELEMENT_SIZE
, abfd
)
2196 != XCOFFARMAG_ELEMENT_SIZE
)
2198 for (i
= 0; i
< (size_t) count
; i
++)
2200 sprintf (decbuf
, "%-12ld", (long) offsets
[i
]);
2201 if (bfd_bwrite ((PTR
) decbuf
, (bfd_size_type
) XCOFFARMAG_ELEMENT_SIZE
,
2202 abfd
) != XCOFFARMAG_ELEMENT_SIZE
)
2205 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->archive_next
)
2208 bfd_size_type namlen
;
2210 name
= normalize_filename (sub
);
2211 namlen
= strlen (name
);
2212 if (bfd_bwrite ((PTR
) name
, namlen
+ 1, abfd
) != namlen
+ 1)
2216 if (! do_pad (abfd
, size
& 1))
2219 /* Write out the armap, if appropriate. */
2220 if (! makemap
|| ! hasobjects
)
2221 sprintf (fhdr
.symoff
, "%d", 0);
2224 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2225 sprintf (fhdr
.symoff
, "%ld", (long) nextoff
);
2226 bfd_ardata (abfd
)->tdata
= (PTR
) &fhdr
;
2227 if (! _bfd_compute_and_write_armap (abfd
, 0))
2231 /* Write out the archive file header. */
2233 /* We need spaces, not null bytes, in the header. */
2234 for (p
= (char *) &fhdr
; p
< (char *) &fhdr
+ SIZEOF_AR_FILE_HDR
; p
++)
2238 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
2239 || (bfd_bwrite ((PTR
) &fhdr
, (bfd_size_type
) SIZEOF_AR_FILE_HDR
, abfd
)
2240 != SIZEOF_AR_FILE_HDR
))
2247 xcoff_write_archive_contents_big (bfd
*abfd
)
2249 struct xcoff_ar_file_hdr_big fhdr
;
2250 bfd_size_type count
;
2251 bfd_size_type total_namlen
;
2253 bfd_boolean makemap
;
2254 bfd_boolean hasobjects
;
2255 file_ptr prevoff
, nextoff
;
2258 struct xcoff_ar_hdr_big
*hdr
;
2260 char *member_table
, *mt
;
2261 bfd_vma member_table_size
;
2262 struct archive_iterator iterator
;
2264 memset (&fhdr
, 0, SIZEOF_AR_FILE_HDR_BIG
);
2265 memcpy (fhdr
.magic
, XCOFFARMAGBIG
, SXCOFFARMAG
);
2267 if (bfd_seek (abfd
, (file_ptr
) SIZEOF_AR_FILE_HDR_BIG
, SEEK_SET
) != 0)
2270 /* Calculate count and total_namlen. */
2271 makemap
= bfd_has_map (abfd
);
2273 for (current_bfd
= abfd
->archive_head
, count
= 0, total_namlen
= 0;
2274 current_bfd
!= NULL
;
2275 current_bfd
= current_bfd
->archive_next
, count
++)
2277 total_namlen
+= strlen (normalize_filename (current_bfd
)) + 1;
2281 && bfd_check_format (current_bfd
, bfd_object
))
2284 if (current_bfd
->arelt_data
== NULL
)
2286 size
= sizeof (struct areltdata
);
2287 current_bfd
->arelt_data
= bfd_zalloc (current_bfd
, size
);
2288 if (current_bfd
->arelt_data
== NULL
)
2292 if (arch_xhdr_big (current_bfd
) == NULL
)
2294 struct xcoff_ar_hdr_big
*ahdrp
;
2297 /* XXX This should actually be a call to stat64 (at least on
2299 XXX This call will fail if the original object is not found. */
2300 if (stat (bfd_get_filename (current_bfd
), &s
) != 0)
2302 bfd_set_error (bfd_error_system_call
);
2306 ahdrp
= bfd_zalloc (current_bfd
, sizeof (*ahdrp
));
2310 PRINT20 (ahdrp
->size
, s
.st_size
);
2311 PRINT12 (ahdrp
->date
, s
.st_mtime
);
2312 PRINT12 (ahdrp
->uid
, s
.st_uid
);
2313 PRINT12 (ahdrp
->gid
, s
.st_gid
);
2314 PRINT12_OCTAL (ahdrp
->mode
, s
.st_mode
);
2316 arch_eltdata (current_bfd
)->arch_header
= (char *) ahdrp
;
2317 arch_eltdata (current_bfd
)->parsed_size
= s
.st_size
;
2324 offsets
= (file_ptr
*) bfd_malloc (count
* sizeof (file_ptr
));
2325 if (offsets
== NULL
)
2330 for (archive_iterator_begin (&iterator
, abfd
), i
= 0;
2331 archive_iterator_next (&iterator
);
2334 bfd_size_type namlen
;
2335 struct xcoff_ar_hdr_big
*ahdrp
;
2337 ahdrp
= arch_xhdr_big (iterator
.current
.member
);
2338 PRINT20 (ahdrp
->prevoff
, prevoff
);
2339 PRINT4 (ahdrp
->namlen
, iterator
.current
.namlen
);
2340 PRINT20 (ahdrp
->nextoff
, iterator
.next
.offset
);
2342 if (!do_pad (abfd
, iterator
.current
.leading_padding
))
2345 BFD_ASSERT (iterator
.current
.offset
== bfd_tell (abfd
));
2346 namlen
= iterator
.current
.padded_namlen
;
2347 if (bfd_bwrite (ahdrp
, SIZEOF_AR_HDR_BIG
, abfd
) != SIZEOF_AR_HDR_BIG
2348 || bfd_bwrite (iterator
.current
.name
, namlen
, abfd
) != namlen
2349 || bfd_bwrite (XCOFFARFMAG
, SXCOFFARFMAG
, abfd
) != SXCOFFARFMAG
2350 || bfd_seek (iterator
.current
.member
, 0, SEEK_SET
) != 0
2351 || !do_copy (abfd
, iterator
.current
.member
)
2352 || !do_pad (abfd
, iterator
.current
.trailing_padding
))
2355 offsets
[i
] = iterator
.current
.offset
;
2356 prevoff
= iterator
.current
.offset
;
2361 PRINT20 (fhdr
.firstmemoff
, offsets
[0]);
2362 PRINT20 (fhdr
.lastmemoff
, prevoff
);
2365 /* Write out the member table.
2368 standard big archive header
2369 0x0000 ar_size [0x14]
2370 0x0014 ar_nxtmem [0x14]
2371 0x0028 ar_prvmem [0x14]
2372 0x003C ar_date [0x0C]
2373 0x0048 ar_uid [0x0C]
2374 0x0054 ar_gid [0x0C]
2375 0x0060 ar_mod [0x0C]
2376 0x006C ar_namelen[0x04]
2377 0x0070 ar_fmag [0x02]
2381 0x0086 offsets [0x14 * counts]
2382 0x0086 + 0x14 * counts names [??]
2383 ?? pad to even bytes.
2386 nextoff
= iterator
.next
.offset
;
2387 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2389 member_table_size
= (SIZEOF_AR_HDR_BIG
2391 + XCOFFARMAGBIG_ELEMENT_SIZE
2392 + count
* XCOFFARMAGBIG_ELEMENT_SIZE
2395 member_table_size
+= member_table_size
& 1;
2396 member_table
= bfd_zmalloc (member_table_size
);
2397 if (member_table
== NULL
)
2400 hdr
= (struct xcoff_ar_hdr_big
*) member_table
;
2402 PRINT20 (hdr
->size
, (XCOFFARMAGBIG_ELEMENT_SIZE
2403 + count
* XCOFFARMAGBIG_ELEMENT_SIZE
2404 + total_namlen
+ (total_namlen
& 1)));
2405 if (makemap
&& hasobjects
)
2406 PRINT20 (hdr
->nextoff
, nextoff
+ member_table_size
);
2408 PRINT20 (hdr
->nextoff
, 0);
2409 PRINT20 (hdr
->prevoff
, prevoff
);
2410 PRINT12 (hdr
->date
, 0);
2411 PRINT12 (hdr
->uid
, 0);
2412 PRINT12 (hdr
->gid
, 0);
2413 PRINT12 (hdr
->mode
, 0);
2414 PRINT4 (hdr
->namlen
, 0);
2416 mt
= member_table
+ SIZEOF_AR_HDR_BIG
;
2417 memcpy (mt
, XCOFFARFMAG
, SXCOFFARFMAG
);
2420 PRINT20 (mt
, count
);
2421 mt
+= XCOFFARMAGBIG_ELEMENT_SIZE
;
2422 for (i
= 0; i
< (size_t) count
; i
++)
2424 PRINT20 (mt
, offsets
[i
]);
2425 mt
+= XCOFFARMAGBIG_ELEMENT_SIZE
;
2434 for (current_bfd
= abfd
->archive_head
;
2435 current_bfd
!= NULL
;
2436 current_bfd
= current_bfd
->archive_next
)
2441 name
= normalize_filename (current_bfd
);
2442 namlen
= sprintf (mt
, "%s", name
);
2446 if (bfd_bwrite (member_table
, member_table_size
, abfd
) != member_table_size
)
2449 free (member_table
);
2451 PRINT20 (fhdr
.memoff
, nextoff
);
2454 nextoff
+= member_table_size
;
2456 /* Write out the armap, if appropriate. */
2458 if (! makemap
|| ! hasobjects
)
2459 PRINT20 (fhdr
.symoff
, 0);
2462 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2464 /* Save nextoff in fhdr.symoff so the armap routine can use it. */
2465 PRINT20 (fhdr
.symoff
, nextoff
);
2467 bfd_ardata (abfd
)->tdata
= (PTR
) &fhdr
;
2468 if (! _bfd_compute_and_write_armap (abfd
, 0))
2472 /* Write out the archive file header. */
2474 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
2475 || (bfd_bwrite ((PTR
) &fhdr
, (bfd_size_type
) SIZEOF_AR_FILE_HDR_BIG
,
2476 abfd
) != SIZEOF_AR_FILE_HDR_BIG
))
2483 _bfd_xcoff_write_archive_contents (bfd
*abfd
)
2485 if (! xcoff_big_format_p (abfd
))
2486 return xcoff_write_archive_contents_old (abfd
);
2488 return xcoff_write_archive_contents_big (abfd
);
2491 /* We can't use the usual coff_sizeof_headers routine, because AIX
2492 always uses an a.out header. */
2495 _bfd_xcoff_sizeof_headers (bfd
*abfd
,
2496 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
2501 if (xcoff_data (abfd
)->full_aouthdr
)
2504 size
+= SMALL_AOUTSZ
;
2505 size
+= abfd
->section_count
* SCNHSZ
;
2509 /* Routines to swap information in the XCOFF .loader section. If we
2510 ever need to write an XCOFF loader, this stuff will need to be
2511 moved to another file shared by the linker (which XCOFF calls the
2512 ``binder'') and the loader. */
2514 /* Swap in the ldhdr structure. */
2517 xcoff_swap_ldhdr_in (bfd
*abfd
, const PTR s
, struct internal_ldhdr
*dst
)
2519 const struct external_ldhdr
*src
= (const struct external_ldhdr
*) s
;
2521 dst
->l_version
= bfd_get_32 (abfd
, src
->l_version
);
2522 dst
->l_nsyms
= bfd_get_32 (abfd
, src
->l_nsyms
);
2523 dst
->l_nreloc
= bfd_get_32 (abfd
, src
->l_nreloc
);
2524 dst
->l_istlen
= bfd_get_32 (abfd
, src
->l_istlen
);
2525 dst
->l_nimpid
= bfd_get_32 (abfd
, src
->l_nimpid
);
2526 dst
->l_impoff
= bfd_get_32 (abfd
, src
->l_impoff
);
2527 dst
->l_stlen
= bfd_get_32 (abfd
, src
->l_stlen
);
2528 dst
->l_stoff
= bfd_get_32 (abfd
, src
->l_stoff
);
2531 /* Swap out the ldhdr structure. */
2534 xcoff_swap_ldhdr_out (bfd
*abfd
, const struct internal_ldhdr
*src
, PTR d
)
2536 struct external_ldhdr
*dst
= (struct external_ldhdr
*) d
;
2538 bfd_put_32 (abfd
, (bfd_vma
) src
->l_version
, dst
->l_version
);
2539 bfd_put_32 (abfd
, src
->l_nsyms
, dst
->l_nsyms
);
2540 bfd_put_32 (abfd
, src
->l_nreloc
, dst
->l_nreloc
);
2541 bfd_put_32 (abfd
, src
->l_istlen
, dst
->l_istlen
);
2542 bfd_put_32 (abfd
, src
->l_nimpid
, dst
->l_nimpid
);
2543 bfd_put_32 (abfd
, src
->l_impoff
, dst
->l_impoff
);
2544 bfd_put_32 (abfd
, src
->l_stlen
, dst
->l_stlen
);
2545 bfd_put_32 (abfd
, src
->l_stoff
, dst
->l_stoff
);
2548 /* Swap in the ldsym structure. */
2551 xcoff_swap_ldsym_in (bfd
*abfd
, const PTR s
, struct internal_ldsym
*dst
)
2553 const struct external_ldsym
*src
= (const struct external_ldsym
*) s
;
2555 if (bfd_get_32 (abfd
, src
->_l
._l_l
._l_zeroes
) != 0) {
2556 memcpy (dst
->_l
._l_name
, src
->_l
._l_name
, SYMNMLEN
);
2558 dst
->_l
._l_l
._l_zeroes
= 0;
2559 dst
->_l
._l_l
._l_offset
= bfd_get_32 (abfd
, src
->_l
._l_l
._l_offset
);
2561 dst
->l_value
= bfd_get_32 (abfd
, src
->l_value
);
2562 dst
->l_scnum
= bfd_get_16 (abfd
, src
->l_scnum
);
2563 dst
->l_smtype
= bfd_get_8 (abfd
, src
->l_smtype
);
2564 dst
->l_smclas
= bfd_get_8 (abfd
, src
->l_smclas
);
2565 dst
->l_ifile
= bfd_get_32 (abfd
, src
->l_ifile
);
2566 dst
->l_parm
= bfd_get_32 (abfd
, src
->l_parm
);
2569 /* Swap out the ldsym structure. */
2572 xcoff_swap_ldsym_out (bfd
*abfd
, const struct internal_ldsym
*src
, PTR d
)
2574 struct external_ldsym
*dst
= (struct external_ldsym
*) d
;
2576 if (src
->_l
._l_l
._l_zeroes
!= 0)
2577 memcpy (dst
->_l
._l_name
, src
->_l
._l_name
, SYMNMLEN
);
2580 bfd_put_32 (abfd
, (bfd_vma
) 0, dst
->_l
._l_l
._l_zeroes
);
2581 bfd_put_32 (abfd
, (bfd_vma
) src
->_l
._l_l
._l_offset
,
2582 dst
->_l
._l_l
._l_offset
);
2584 bfd_put_32 (abfd
, src
->l_value
, dst
->l_value
);
2585 bfd_put_16 (abfd
, (bfd_vma
) src
->l_scnum
, dst
->l_scnum
);
2586 bfd_put_8 (abfd
, src
->l_smtype
, dst
->l_smtype
);
2587 bfd_put_8 (abfd
, src
->l_smclas
, dst
->l_smclas
);
2588 bfd_put_32 (abfd
, src
->l_ifile
, dst
->l_ifile
);
2589 bfd_put_32 (abfd
, src
->l_parm
, dst
->l_parm
);
2593 xcoff_swap_reloc_in (bfd
*abfd
, PTR s
, PTR d
)
2595 struct external_reloc
*src
= (struct external_reloc
*) s
;
2596 struct internal_reloc
*dst
= (struct internal_reloc
*) d
;
2598 memset (dst
, 0, sizeof (struct internal_reloc
));
2600 dst
->r_vaddr
= bfd_get_32 (abfd
, src
->r_vaddr
);
2601 dst
->r_symndx
= bfd_get_32 (abfd
, src
->r_symndx
);
2602 dst
->r_size
= bfd_get_8 (abfd
, src
->r_size
);
2603 dst
->r_type
= bfd_get_8 (abfd
, src
->r_type
);
2607 xcoff_swap_reloc_out (bfd
*abfd
, PTR s
, PTR d
)
2609 struct internal_reloc
*src
= (struct internal_reloc
*) s
;
2610 struct external_reloc
*dst
= (struct external_reloc
*) d
;
2612 bfd_put_32 (abfd
, src
->r_vaddr
, dst
->r_vaddr
);
2613 bfd_put_32 (abfd
, src
->r_symndx
, dst
->r_symndx
);
2614 bfd_put_8 (abfd
, src
->r_type
, dst
->r_type
);
2615 bfd_put_8 (abfd
, src
->r_size
, dst
->r_size
);
2617 return bfd_coff_relsz (abfd
);
2620 /* Swap in the ldrel structure. */
2623 xcoff_swap_ldrel_in (bfd
*abfd
, const PTR s
, struct internal_ldrel
*dst
)
2625 const struct external_ldrel
*src
= (const struct external_ldrel
*) s
;
2627 dst
->l_vaddr
= bfd_get_32 (abfd
, src
->l_vaddr
);
2628 dst
->l_symndx
= bfd_get_32 (abfd
, src
->l_symndx
);
2629 dst
->l_rtype
= bfd_get_16 (abfd
, src
->l_rtype
);
2630 dst
->l_rsecnm
= bfd_get_16 (abfd
, src
->l_rsecnm
);
2633 /* Swap out the ldrel structure. */
2636 xcoff_swap_ldrel_out (bfd
*abfd
, const struct internal_ldrel
*src
, PTR d
)
2638 struct external_ldrel
*dst
= (struct external_ldrel
*) d
;
2640 bfd_put_32 (abfd
, src
->l_vaddr
, dst
->l_vaddr
);
2641 bfd_put_32 (abfd
, src
->l_symndx
, dst
->l_symndx
);
2642 bfd_put_16 (abfd
, (bfd_vma
) src
->l_rtype
, dst
->l_rtype
);
2643 bfd_put_16 (abfd
, (bfd_vma
) src
->l_rsecnm
, dst
->l_rsecnm
);
2648 xcoff_reloc_type_noop (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2649 asection
*input_section ATTRIBUTE_UNUSED
,
2650 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2651 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
2652 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2653 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
,
2654 bfd_vma val ATTRIBUTE_UNUSED
,
2655 bfd_vma addend ATTRIBUTE_UNUSED
,
2656 bfd_vma
*relocation ATTRIBUTE_UNUSED
,
2657 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2663 xcoff_reloc_type_fail (bfd
*input_bfd
,
2664 asection
*input_section ATTRIBUTE_UNUSED
,
2665 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2666 struct internal_reloc
*rel
,
2667 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2668 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
,
2669 bfd_vma val ATTRIBUTE_UNUSED
,
2670 bfd_vma addend ATTRIBUTE_UNUSED
,
2671 bfd_vma
*relocation ATTRIBUTE_UNUSED
,
2672 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2674 (*_bfd_error_handler
)
2675 (_("%s: unsupported relocation type 0x%02x"),
2676 bfd_get_filename (input_bfd
), (unsigned int) rel
->r_type
);
2677 bfd_set_error (bfd_error_bad_value
);
2682 xcoff_reloc_type_pos (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2683 asection
*input_section ATTRIBUTE_UNUSED
,
2684 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2685 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
2686 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2687 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
,
2690 bfd_vma
*relocation
,
2691 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2693 *relocation
= val
+ addend
;
2698 xcoff_reloc_type_neg (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2699 asection
*input_section ATTRIBUTE_UNUSED
,
2700 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2701 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
2702 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2703 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
,
2706 bfd_vma
*relocation
,
2707 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2709 *relocation
= addend
- val
;
2714 xcoff_reloc_type_rel (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2715 asection
*input_section
,
2716 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2717 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
2718 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2719 struct reloc_howto_struct
*howto
,
2722 bfd_vma
*relocation
,
2723 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2725 howto
->pc_relative
= TRUE
;
2727 /* A PC relative reloc includes the section address. */
2728 addend
+= input_section
->vma
;
2730 *relocation
= val
+ addend
;
2731 *relocation
-= (input_section
->output_section
->vma
2732 + input_section
->output_offset
);
2737 xcoff_reloc_type_toc (bfd
*input_bfd
,
2738 asection
*input_section ATTRIBUTE_UNUSED
,
2740 struct internal_reloc
*rel
,
2741 struct internal_syment
*sym
,
2742 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
,
2744 bfd_vma addend ATTRIBUTE_UNUSED
,
2745 bfd_vma
*relocation
,
2746 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2748 struct xcoff_link_hash_entry
*h
;
2750 if (0 > rel
->r_symndx
)
2753 h
= obj_xcoff_sym_hashes (input_bfd
)[rel
->r_symndx
];
2755 if (h
!= NULL
&& h
->smclas
!= XMC_TD
)
2757 if (h
->toc_section
== NULL
)
2759 (*_bfd_error_handler
)
2760 (_("%s: TOC reloc at 0x%x to symbol `%s' with no TOC entry"),
2761 bfd_get_filename (input_bfd
), rel
->r_vaddr
,
2762 h
->root
.root
.string
);
2763 bfd_set_error (bfd_error_bad_value
);
2767 BFD_ASSERT ((h
->flags
& XCOFF_SET_TOC
) == 0);
2768 val
= (h
->toc_section
->output_section
->vma
2769 + h
->toc_section
->output_offset
);
2772 *relocation
= ((val
- xcoff_data (output_bfd
)->toc
)
2773 - (sym
->n_value
- xcoff_data (input_bfd
)->toc
));
2778 xcoff_reloc_type_ba (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2779 asection
*input_section ATTRIBUTE_UNUSED
,
2780 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2781 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
2782 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2783 struct reloc_howto_struct
*howto
,
2786 bfd_vma
*relocation
,
2787 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2789 howto
->src_mask
&= ~3;
2790 howto
->dst_mask
= howto
->src_mask
;
2792 *relocation
= val
+ addend
;
2798 xcoff_reloc_type_br (bfd
*input_bfd
,
2799 asection
*input_section
,
2800 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2801 struct internal_reloc
*rel
,
2802 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2803 struct reloc_howto_struct
*howto
,
2806 bfd_vma
*relocation
,
2809 struct xcoff_link_hash_entry
*h
;
2810 bfd_vma section_offset
;
2812 if (0 > rel
->r_symndx
)
2815 h
= obj_xcoff_sym_hashes (input_bfd
)[rel
->r_symndx
];
2816 section_offset
= rel
->r_vaddr
- input_section
->vma
;
2818 /* If we see an R_BR or R_RBR reloc which is jumping to global
2819 linkage code, and it is followed by an appropriate cror nop
2820 instruction, we replace the cror with lwz r2,20(r1). This
2821 restores the TOC after the glink code. Contrariwise, if the
2822 call is followed by a lwz r2,20(r1), but the call is not
2823 going to global linkage code, we can replace the load with a
2826 && (bfd_link_hash_defined
== h
->root
.type
2827 || bfd_link_hash_defweak
== h
->root
.type
)
2828 && section_offset
+ 8 <= input_section
->size
)
2833 pnext
= contents
+ section_offset
+ 4;
2834 next
= bfd_get_32 (input_bfd
, pnext
);
2836 /* The _ptrgl function is magic. It is used by the AIX
2837 compiler to call a function through a pointer. */
2838 if (h
->smclas
== XMC_GL
|| strcmp (h
->root
.root
.string
, "._ptrgl") == 0)
2840 if (next
== 0x4def7b82 /* cror 15,15,15 */
2841 || next
== 0x4ffffb82 /* cror 31,31,31 */
2842 || next
== 0x60000000) /* ori r0,r0,0 */
2843 bfd_put_32 (input_bfd
, 0x80410014, pnext
); /* lwz r2,20(r1) */
2848 if (next
== 0x80410014) /* lwz r2,20(r1) */
2849 bfd_put_32 (input_bfd
, 0x60000000, pnext
); /* ori r0,r0,0 */
2852 else if (NULL
!= h
&& bfd_link_hash_undefined
== h
->root
.type
)
2854 /* Normally, this relocation is against a defined symbol. In the
2855 case where this is a partial link and the output section offset
2856 is greater than 2^25, the linker will return an invalid error
2857 message that the relocation has been truncated. Yes it has been
2858 truncated but no it not important. For this case, disable the
2859 overflow checking. */
2861 howto
->complain_on_overflow
= complain_overflow_dont
;
2864 /* The original PC-relative relocation is biased by -r_vaddr, so adding
2865 the value below will give the absolute target address. */
2866 *relocation
= val
+ addend
+ rel
->r_vaddr
;
2868 howto
->src_mask
&= ~3;
2869 howto
->dst_mask
= howto
->src_mask
;
2872 && (h
->root
.type
== bfd_link_hash_defined
2873 || h
->root
.type
== bfd_link_hash_defweak
)
2874 && bfd_is_abs_section (h
->root
.u
.def
.section
)
2875 && section_offset
+ 4 <= input_section
->size
)
2880 /* Turn the relative branch into an absolute one by setting the
2882 ptr
= contents
+ section_offset
;
2883 insn
= bfd_get_32 (input_bfd
, ptr
);
2885 bfd_put_32 (input_bfd
, insn
, ptr
);
2887 /* Make the howto absolute too. */
2888 howto
->pc_relative
= FALSE
;
2889 howto
->complain_on_overflow
= complain_overflow_bitfield
;
2893 /* Use a PC-relative howto and subtract the instruction's address
2894 from the target address we calculated above. */
2895 howto
->pc_relative
= TRUE
;
2896 *relocation
-= (input_section
->output_section
->vma
2897 + input_section
->output_offset
2904 xcoff_reloc_type_crel (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2905 asection
*input_section
,
2906 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2907 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
2908 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2909 struct reloc_howto_struct
*howto
,
2910 bfd_vma val ATTRIBUTE_UNUSED
,
2912 bfd_vma
*relocation
,
2913 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2915 howto
->pc_relative
= TRUE
;
2916 howto
->src_mask
&= ~3;
2917 howto
->dst_mask
= howto
->src_mask
;
2919 /* A PC relative reloc includes the section address. */
2920 addend
+= input_section
->vma
;
2922 *relocation
= val
+ addend
;
2923 *relocation
-= (input_section
->output_section
->vma
2924 + input_section
->output_offset
);
2929 xcoff_complain_overflow_dont_func (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2930 bfd_vma val ATTRIBUTE_UNUSED
,
2931 bfd_vma relocation ATTRIBUTE_UNUSED
,
2932 struct reloc_howto_struct
*
2933 howto ATTRIBUTE_UNUSED
)
2939 xcoff_complain_overflow_bitfield_func (bfd
*input_bfd
,
2942 struct reloc_howto_struct
*howto
)
2944 bfd_vma fieldmask
, signmask
, ss
;
2947 /* Get the values to be added together. For signed and unsigned
2948 relocations, we assume that all values should be truncated to
2949 the size of an address. For bitfields, all the bits matter.
2950 See also bfd_check_overflow. */
2951 fieldmask
= N_ONES (howto
->bitsize
);
2953 b
= val
& howto
->src_mask
;
2955 /* Much like unsigned, except no trimming with addrmask. In
2956 addition, the sum overflows if there is a carry out of
2957 the bfd_vma, i.e., the sum is less than either input
2959 a
>>= howto
->rightshift
;
2960 b
>>= howto
->bitpos
;
2962 /* Bitfields are sometimes used for signed numbers; for
2963 example, a 13-bit field sometimes represents values in
2964 0..8191 and sometimes represents values in -4096..4095.
2965 If the field is signed and a is -4095 (0x1001) and b is
2966 -1 (0x1fff), the sum is -4096 (0x1000), but (0x1001 +
2967 0x1fff is 0x3000). It's not clear how to handle this
2968 everywhere, since there is not way to know how many bits
2969 are significant in the relocation, but the original code
2970 assumed that it was fully sign extended, and we will keep
2972 signmask
= (fieldmask
>> 1) + 1;
2974 if ((a
& ~ fieldmask
) != 0)
2976 /* Some bits out of the field are set. This might not
2977 be a problem: if this is a signed bitfield, it is OK
2978 iff all the high bits are set, including the sign
2979 bit. We'll try setting all but the most significant
2980 bit in the original relocation value: if this is all
2981 ones, we are OK, assuming a signed bitfield. */
2982 ss
= (signmask
<< howto
->rightshift
) - 1;
2983 if ((ss
| relocation
) != ~ (bfd_vma
) 0)
2988 /* We just assume (b & ~ fieldmask) == 0. */
2990 /* We explicitly permit wrap around if this relocation
2991 covers the high bit of an address. The Linux kernel
2992 relies on it, and it is the only way to write assembler
2993 code which can run when loaded at a location 0x80000000
2994 away from the location at which it is linked. */
2995 if (howto
->bitsize
+ howto
->rightshift
2996 == bfd_arch_bits_per_address (input_bfd
))
3000 if (sum
< a
|| (sum
& ~ fieldmask
) != 0)
3002 /* There was a carry out, or the field overflow. Test
3003 for signed operands again. Here is the overflow test
3004 is as for complain_overflow_signed. */
3005 if (((~ (a
^ b
)) & (a
^ sum
)) & signmask
)
3013 xcoff_complain_overflow_signed_func (bfd
*input_bfd
,
3016 struct reloc_howto_struct
*howto
)
3018 bfd_vma addrmask
, fieldmask
, signmask
, ss
;
3021 /* Get the values to be added together. For signed and unsigned
3022 relocations, we assume that all values should be truncated to
3023 the size of an address. For bitfields, all the bits matter.
3024 See also bfd_check_overflow. */
3025 fieldmask
= N_ONES (howto
->bitsize
);
3026 addrmask
= N_ONES (bfd_arch_bits_per_address (input_bfd
)) | fieldmask
;
3028 b
= val
& howto
->src_mask
;
3030 a
= (a
& addrmask
) >> howto
->rightshift
;
3032 /* If any sign bits are set, all sign bits must be set.
3033 That is, A must be a valid negative address after
3035 signmask
= ~ (fieldmask
>> 1);
3037 if (ss
!= 0 && ss
!= ((addrmask
>> howto
->rightshift
) & signmask
))
3040 /* We only need this next bit of code if the sign bit of B
3041 is below the sign bit of A. This would only happen if
3042 SRC_MASK had fewer bits than BITSIZE. Note that if
3043 SRC_MASK has more bits than BITSIZE, we can get into
3044 trouble; we would need to verify that B is in range, as
3045 we do for A above. */
3046 signmask
= ((~ howto
->src_mask
) >> 1) & howto
->src_mask
;
3047 if ((b
& signmask
) != 0)
3049 /* Set all the bits above the sign bit. */
3050 b
-= signmask
<<= 1;
3053 b
= (b
& addrmask
) >> howto
->bitpos
;
3055 /* Now we can do the addition. */
3058 /* See if the result has the correct sign. Bits above the
3059 sign bit are junk now; ignore them. If the sum is
3060 positive, make sure we did not have all negative inputs;
3061 if the sum is negative, make sure we did not have all
3062 positive inputs. The test below looks only at the sign
3063 bits, and it really just
3064 SIGN (A) == SIGN (B) && SIGN (A) != SIGN (SUM)
3066 signmask
= (fieldmask
>> 1) + 1;
3067 if (((~ (a
^ b
)) & (a
^ sum
)) & signmask
)
3074 xcoff_complain_overflow_unsigned_func (bfd
*input_bfd
,
3077 struct reloc_howto_struct
*howto
)
3079 bfd_vma addrmask
, fieldmask
;
3082 /* Get the values to be added together. For signed and unsigned
3083 relocations, we assume that all values should be truncated to
3084 the size of an address. For bitfields, all the bits matter.
3085 See also bfd_check_overflow. */
3086 fieldmask
= N_ONES (howto
->bitsize
);
3087 addrmask
= N_ONES (bfd_arch_bits_per_address (input_bfd
)) | fieldmask
;
3089 b
= val
& howto
->src_mask
;
3091 /* Checking for an unsigned overflow is relatively easy:
3092 trim the addresses and add, and trim the result as well.
3093 Overflow is normally indicated when the result does not
3094 fit in the field. However, we also need to consider the
3095 case when, e.g., fieldmask is 0x7fffffff or smaller, an
3096 input is 0x80000000, and bfd_vma is only 32 bits; then we
3097 will get sum == 0, but there is an overflow, since the
3098 inputs did not fit in the field. Instead of doing a
3099 separate test, we can check for this by or-ing in the
3100 operands when testing for the sum overflowing its final
3102 a
= (a
& addrmask
) >> howto
->rightshift
;
3103 b
= (b
& addrmask
) >> howto
->bitpos
;
3104 sum
= (a
+ b
) & addrmask
;
3105 if ((a
| b
| sum
) & ~ fieldmask
)
3111 /* This is the relocation function for the RS/6000/POWER/PowerPC.
3112 This is currently the only processor which uses XCOFF; I hope that
3115 I took the relocation type definitions from two documents:
3116 the PowerPC AIX Version 4 Application Binary Interface, First
3117 Edition (April 1992), and the PowerOpen ABI, Big-Endian
3118 32-Bit Hardware Implementation (June 30, 1994). Differences
3119 between the documents are noted below.
3121 Unsupported r_type's
3127 These relocs are defined by the PowerPC ABI to be
3128 relative branches which use half of the difference
3129 between the symbol and the program counter. I can't
3130 quite figure out when this is useful. These relocs are
3131 not defined by the PowerOpen ABI.
3136 Simple positive relocation.
3139 Simple negative relocation.
3142 Simple PC relative relocation.
3145 TOC relative relocation. The value in the instruction in
3146 the input file is the offset from the input file TOC to
3147 the desired location. We want the offset from the final
3148 TOC to the desired location. We have:
3153 so we must change insn by on - in.
3156 GL linkage relocation. The value of this relocation
3157 is the address of the entry in the TOC section.
3160 Local object TOC address. I can't figure out the
3161 difference between this and case R_GL.
3164 TOC relative relocation. A TOC relative load instruction
3165 which may be changed to a load address instruction.
3166 FIXME: We don't currently implement this optimization.
3169 TOC relative relocation. This is a TOC relative load
3170 address instruction which may be changed to a load
3171 instruction. FIXME: I don't know if this is the correct
3175 Absolute branch. We don't want to mess with the lower
3176 two bits of the instruction.
3179 The PowerPC ABI defines this as an absolute call which
3180 may be modified to become a relative call. The PowerOpen
3181 ABI does not define this relocation type.
3184 Absolute branch which may be modified to become a
3188 The PowerPC ABI defines this as an absolute branch to a
3189 fixed address which may be modified to an absolute branch
3190 to a symbol. The PowerOpen ABI does not define this
3194 The PowerPC ABI defines this as an absolute branch to a
3195 fixed address which may be modified to a relative branch.
3196 The PowerOpen ABI does not define this relocation type.
3199 Relative branch. We don't want to mess with the lower
3200 two bits of the instruction.
3203 The PowerPC ABI defines this as a relative call which may
3204 be modified to become an absolute call. The PowerOpen
3205 ABI does not define this relocation type.
3208 A relative branch which may be modified to become an
3212 The PowerPC AIX ABI describes this as a load which may be
3213 changed to a load address. The PowerOpen ABI says this
3214 is the same as case R_POS.
3217 The PowerPC AIX ABI describes this as a load address
3218 which may be changed to a load. The PowerOpen ABI says
3219 this is the same as R_POS.
3223 xcoff_ppc_relocate_section (bfd
*output_bfd
,
3224 struct bfd_link_info
*info
,
3226 asection
*input_section
,
3228 struct internal_reloc
*relocs
,
3229 struct internal_syment
*syms
,
3230 asection
**sections
)
3232 struct internal_reloc
*rel
;
3233 struct internal_reloc
*relend
;
3236 relend
= rel
+ input_section
->reloc_count
;
3237 for (; rel
< relend
; rel
++)
3240 struct xcoff_link_hash_entry
*h
;
3241 struct internal_syment
*sym
;
3244 struct reloc_howto_struct howto
;
3246 bfd_vma value_to_relocate
;
3250 /* Relocation type R_REF is a special relocation type which is
3251 merely used to prevent garbage collection from occurring for
3252 the csect including the symbol which it references. */
3253 if (rel
->r_type
== R_REF
)
3257 howto
.type
= rel
->r_type
;
3258 howto
.rightshift
= 0;
3259 howto
.bitsize
= (rel
->r_size
& 0x1f) + 1;
3260 howto
.size
= howto
.bitsize
> 16 ? 2 : 1;
3261 howto
.pc_relative
= FALSE
;
3263 howto
.complain_on_overflow
= (rel
->r_size
& 0x80
3264 ? complain_overflow_signed
3265 : complain_overflow_bitfield
);
3266 howto
.special_function
= NULL
;
3267 howto
.name
= "internal";
3268 howto
.partial_inplace
= TRUE
;
3269 howto
.src_mask
= howto
.dst_mask
= N_ONES (howto
.bitsize
);
3270 howto
.pcrel_offset
= FALSE
;
3277 symndx
= rel
->r_symndx
;
3283 h
= obj_xcoff_sym_hashes (input_bfd
)[symndx
];
3284 sym
= syms
+ symndx
;
3285 addend
= - sym
->n_value
;
3289 sec
= sections
[symndx
];
3290 /* Hack to make sure we use the right TOC anchor value
3291 if this reloc is against the TOC anchor. */
3292 if (sec
->name
[3] == '0'
3293 && strcmp (sec
->name
, ".tc0") == 0)
3294 val
= xcoff_data (output_bfd
)->toc
;
3296 val
= (sec
->output_section
->vma
3297 + sec
->output_offset
3303 if (info
->unresolved_syms_in_objects
!= RM_IGNORE
3304 && (h
->flags
& XCOFF_WAS_UNDEFINED
) != 0)
3306 if (! ((*info
->callbacks
->undefined_symbol
)
3307 (info
, h
->root
.root
.string
,
3308 input_bfd
, input_section
,
3309 rel
->r_vaddr
- input_section
->vma
,
3310 (info
->unresolved_syms_in_objects
3311 == RM_GENERATE_ERROR
))))
3314 if (h
->root
.type
== bfd_link_hash_defined
3315 || h
->root
.type
== bfd_link_hash_defweak
)
3317 sec
= h
->root
.u
.def
.section
;
3318 val
= (h
->root
.u
.def
.value
3319 + sec
->output_section
->vma
3320 + sec
->output_offset
);
3322 else if (h
->root
.type
== bfd_link_hash_common
)
3324 sec
= h
->root
.u
.c
.p
->section
;
3325 val
= (sec
->output_section
->vma
3326 + sec
->output_offset
);
3331 BFD_ASSERT (info
->relocatable
3332 || (info
->static_link
3333 && (h
->flags
& XCOFF_WAS_UNDEFINED
) != 0)
3334 || (h
->flags
& XCOFF_DEF_DYNAMIC
) != 0
3335 || (h
->flags
& XCOFF_IMPORT
) != 0);
3340 if (rel
->r_type
>= XCOFF_MAX_CALCULATE_RELOCATION
3341 || !((*xcoff_calculate_relocation
[rel
->r_type
])
3342 (input_bfd
, input_section
, output_bfd
, rel
, sym
, &howto
, val
,
3343 addend
, &relocation
, contents
)))
3347 address
= rel
->r_vaddr
- input_section
->vma
;
3348 location
= contents
+ address
;
3350 if (address
> input_section
->size
)
3353 /* Get the value we are going to relocate. */
3354 if (1 == howto
.size
)
3355 value_to_relocate
= bfd_get_16 (input_bfd
, location
);
3357 value_to_relocate
= bfd_get_32 (input_bfd
, location
);
3361 FIXME: We may drop bits during the addition
3362 which we don't check for. We must either check at every single
3363 operation, which would be tedious, or we must do the computations
3364 in a type larger than bfd_vma, which would be inefficient. */
3366 if ((unsigned int) howto
.complain_on_overflow
3367 >= XCOFF_MAX_COMPLAIN_OVERFLOW
)
3370 if (((*xcoff_complain_overflow
[howto
.complain_on_overflow
])
3371 (input_bfd
, value_to_relocate
, relocation
, &howto
)))
3374 char buf
[SYMNMLEN
+ 1];
3375 char reloc_type_name
[10];
3387 name
= _bfd_coff_internal_syment_name (input_bfd
, sym
, buf
);
3391 sprintf (reloc_type_name
, "0x%02x", rel
->r_type
);
3393 if (! ((*info
->callbacks
->reloc_overflow
)
3394 (info
, (h
? &h
->root
: NULL
), name
, reloc_type_name
,
3395 (bfd_vma
) 0, input_bfd
, input_section
,
3396 rel
->r_vaddr
- input_section
->vma
)))
3400 /* Add RELOCATION to the right bits of VALUE_TO_RELOCATE. */
3401 value_to_relocate
= ((value_to_relocate
& ~howto
.dst_mask
)
3402 | (((value_to_relocate
& howto
.src_mask
)
3403 + relocation
) & howto
.dst_mask
));
3405 /* Put the value back in the object file. */
3406 if (1 == howto
.size
)
3407 bfd_put_16 (input_bfd
, value_to_relocate
, location
);
3409 bfd_put_32 (input_bfd
, value_to_relocate
, location
);
3416 _bfd_xcoff_put_ldsymbol_name (bfd
*abfd ATTRIBUTE_UNUSED
,
3417 struct xcoff_loader_info
*ldinfo
,
3418 struct internal_ldsym
*ldsym
,
3422 len
= strlen (name
);
3424 if (len
<= SYMNMLEN
)
3425 strncpy (ldsym
->_l
._l_name
, name
, SYMNMLEN
);
3428 if (ldinfo
->string_size
+ len
+ 3 > ldinfo
->string_alc
)
3430 bfd_size_type newalc
;
3433 newalc
= ldinfo
->string_alc
* 2;
3436 while (ldinfo
->string_size
+ len
+ 3 > newalc
)
3439 newstrings
= bfd_realloc (ldinfo
->strings
, newalc
);
3440 if (newstrings
== NULL
)
3442 ldinfo
->failed
= TRUE
;
3445 ldinfo
->string_alc
= newalc
;
3446 ldinfo
->strings
= newstrings
;
3449 bfd_put_16 (ldinfo
->output_bfd
, (bfd_vma
) (len
+ 1),
3450 ldinfo
->strings
+ ldinfo
->string_size
);
3451 strcpy (ldinfo
->strings
+ ldinfo
->string_size
+ 2, name
);
3452 ldsym
->_l
._l_l
._l_zeroes
= 0;
3453 ldsym
->_l
._l_l
._l_offset
= ldinfo
->string_size
+ 2;
3454 ldinfo
->string_size
+= len
+ 3;
3461 _bfd_xcoff_put_symbol_name (bfd
*abfd
, struct bfd_strtab_hash
*strtab
,
3462 struct internal_syment
*sym
,
3465 if (strlen (name
) <= SYMNMLEN
)
3467 strncpy (sym
->_n
._n_name
, name
, SYMNMLEN
);
3475 if ((abfd
->flags
& BFD_TRADITIONAL_FORMAT
) != 0)
3477 indx
= _bfd_stringtab_add (strtab
, name
, hash
, FALSE
);
3478 if (indx
== (bfd_size_type
) -1)
3480 sym
->_n
._n_n
._n_zeroes
= 0;
3481 sym
->_n
._n_n
._n_offset
= STRING_SIZE_SIZE
+ indx
;
3487 xcoff_create_csect_from_smclas (bfd
*abfd
,
3488 union internal_auxent
*aux
,
3489 const char *symbol_name
)
3491 asection
*return_value
= NULL
;
3493 /* .sv64 = x_smclas == 17
3494 This is an invalid csect for 32 bit apps. */
3495 static const char *names
[19] =
3497 ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo",
3498 ".sv", ".bs", ".ds", ".uc", ".ti", ".tb", NULL
, ".tc0",
3499 ".td", NULL
, ".sv3264"
3502 if ((19 >= aux
->x_csect
.x_smclas
)
3503 && (NULL
!= names
[aux
->x_csect
.x_smclas
]))
3505 return_value
= bfd_make_section_anyway
3506 (abfd
, names
[aux
->x_csect
.x_smclas
]);
3510 (*_bfd_error_handler
)
3511 (_("%B: symbol `%s' has unrecognized smclas %d"),
3512 abfd
, symbol_name
, aux
->x_csect
.x_smclas
);
3513 bfd_set_error (bfd_error_bad_value
);
3516 return return_value
;
3520 xcoff_is_lineno_count_overflow (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_vma value
)
3522 if (0xffff <= value
)
3529 xcoff_is_reloc_count_overflow (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_vma value
)
3531 if (0xffff <= value
)
3538 xcoff_loader_symbol_offset (bfd
*abfd
,
3539 struct internal_ldhdr
*ldhdr ATTRIBUTE_UNUSED
)
3541 return bfd_xcoff_ldhdrsz (abfd
);
3545 xcoff_loader_reloc_offset (bfd
*abfd
, struct internal_ldhdr
*ldhdr
)
3547 return bfd_xcoff_ldhdrsz (abfd
) + ldhdr
->l_nsyms
* bfd_xcoff_ldsymsz (abfd
);
3551 xcoff_generate_rtinit (bfd
*abfd
, const char *init
, const char *fini
,
3554 bfd_byte filehdr_ext
[FILHSZ
];
3555 bfd_byte scnhdr_ext
[SCNHSZ
];
3556 bfd_byte syment_ext
[SYMESZ
* 10];
3557 bfd_byte reloc_ext
[RELSZ
* 3];
3558 bfd_byte
*data_buffer
;
3559 bfd_size_type data_buffer_size
;
3560 bfd_byte
*string_table
= NULL
, *st_tmp
= NULL
;
3561 bfd_size_type string_table_size
;
3563 size_t initsz
, finisz
;
3564 struct internal_filehdr filehdr
;
3565 struct internal_scnhdr scnhdr
;
3566 struct internal_syment syment
;
3567 union internal_auxent auxent
;
3568 struct internal_reloc reloc
;
3570 char *data_name
= ".data";
3571 char *rtinit_name
= "__rtinit";
3572 char *rtld_name
= "__rtld";
3574 if (! bfd_xcoff_rtinit_size (abfd
))
3577 initsz
= (init
== NULL
? 0 : 1 + strlen (init
));
3578 finisz
= (fini
== NULL
? 0 : 1 + strlen (fini
));
3581 memset (filehdr_ext
, 0, FILHSZ
);
3582 memset (&filehdr
, 0, sizeof (struct internal_filehdr
));
3583 filehdr
.f_magic
= bfd_xcoff_magic_number (abfd
);
3584 filehdr
.f_nscns
= 1;
3585 filehdr
.f_timdat
= 0;
3586 filehdr
.f_nsyms
= 0; /* at least 6, no more than 10 */
3587 filehdr
.f_symptr
= 0; /* set below */
3588 filehdr
.f_opthdr
= 0;
3589 filehdr
.f_flags
= 0;
3591 /* section header */
3592 memset (scnhdr_ext
, 0, SCNHSZ
);
3593 memset (&scnhdr
, 0, sizeof (struct internal_scnhdr
));
3594 memcpy (scnhdr
.s_name
, data_name
, strlen (data_name
));
3597 scnhdr
.s_size
= 0; /* set below */
3598 scnhdr
.s_scnptr
= FILHSZ
+ SCNHSZ
;
3599 scnhdr
.s_relptr
= 0; /* set below */
3600 scnhdr
.s_lnnoptr
= 0;
3601 scnhdr
.s_nreloc
= 0; /* either 1 or 2 */
3603 scnhdr
.s_flags
= STYP_DATA
;
3606 0x0000 0x00000000 : rtl
3607 0x0004 0x00000010 : offset to init, or 0
3608 0x0008 0x00000028 : offset to fini, or 0
3609 0x000C 0x0000000C : size of descriptor
3610 0x0010 0x00000000 : init, needs a reloc
3611 0x0014 0x00000040 : offset to init name
3612 0x0018 0x00000000 : flags, padded to a word
3613 0x001C 0x00000000 : empty init
3616 0x0028 0x00000000 : fini, needs a reloc
3617 0x002C 0x00000??? : offset to fini name
3618 0x0030 0x00000000 : flags, padded to a word
3619 0x0034 0x00000000 : empty fini
3623 0x0040 + initsz fini name */
3625 data_buffer_size
= 0x0040 + initsz
+ finisz
;
3626 data_buffer_size
= (data_buffer_size
+ 7) &~ (bfd_size_type
) 7;
3628 data_buffer
= (bfd_byte
*) bfd_zmalloc (data_buffer_size
);
3629 if (data_buffer
== NULL
)
3635 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x04]);
3637 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x14]);
3638 memcpy (&data_buffer
[val
], init
, initsz
);
3644 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x08]);
3645 val
= 0x40 + initsz
;
3646 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x2C]);
3647 memcpy (&data_buffer
[val
], fini
, finisz
);
3651 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x0C]);
3653 scnhdr
.s_size
= data_buffer_size
;
3656 string_table_size
= 0;
3658 string_table_size
+= initsz
;
3660 string_table_size
+= finisz
;
3661 if (string_table_size
)
3663 string_table_size
+= 4;
3664 string_table
= (bfd_byte
*) bfd_zmalloc (string_table_size
);
3665 if (string_table
== NULL
)
3668 val
= string_table_size
;
3669 bfd_h_put_32 (abfd
, val
, &string_table
[0]);
3670 st_tmp
= string_table
+ 4;
3679 memset (syment_ext
, 0, 10 * SYMESZ
);
3680 memset (reloc_ext
, 0, 3 * RELSZ
);
3683 memset (&syment
, 0, sizeof (struct internal_syment
));
3684 memset (&auxent
, 0, sizeof (union internal_auxent
));
3685 memcpy (syment
._n
._n_name
, data_name
, strlen (data_name
));
3687 syment
.n_sclass
= C_HIDEXT
;
3688 syment
.n_numaux
= 1;
3689 auxent
.x_csect
.x_scnlen
.l
= data_buffer_size
;
3690 auxent
.x_csect
.x_smtyp
= 3 << 3 | XTY_SD
;
3691 auxent
.x_csect
.x_smclas
= XMC_RW
;
3692 bfd_coff_swap_sym_out (abfd
, &syment
,
3693 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3694 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3696 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3697 filehdr
.f_nsyms
+= 2;
3700 memset (&syment
, 0, sizeof (struct internal_syment
));
3701 memset (&auxent
, 0, sizeof (union internal_auxent
));
3702 memcpy (syment
._n
._n_name
, rtinit_name
, strlen (rtinit_name
));
3704 syment
.n_sclass
= C_EXT
;
3705 syment
.n_numaux
= 1;
3706 auxent
.x_csect
.x_smtyp
= XTY_LD
;
3707 auxent
.x_csect
.x_smclas
= XMC_RW
;
3708 bfd_coff_swap_sym_out (abfd
, &syment
,
3709 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3710 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3712 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3713 filehdr
.f_nsyms
+= 2;
3718 memset (&syment
, 0, sizeof (struct internal_syment
));
3719 memset (&auxent
, 0, sizeof (union internal_auxent
));
3723 syment
._n
._n_n
._n_offset
= st_tmp
- string_table
;
3724 memcpy (st_tmp
, init
, initsz
);
3728 memcpy (syment
._n
._n_name
, init
, initsz
- 1);
3730 syment
.n_sclass
= C_EXT
;
3731 syment
.n_numaux
= 1;
3732 bfd_coff_swap_sym_out (abfd
, &syment
,
3733 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3734 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3736 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3739 memset (&reloc
, 0, sizeof (struct internal_reloc
));
3740 reloc
.r_vaddr
= 0x0010;
3741 reloc
.r_symndx
= filehdr
.f_nsyms
;
3742 reloc
.r_type
= R_POS
;
3744 bfd_coff_swap_reloc_out (abfd
, &reloc
, &reloc_ext
[0]);
3746 filehdr
.f_nsyms
+= 2;
3747 scnhdr
.s_nreloc
+= 1;
3753 memset (&syment
, 0, sizeof (struct internal_syment
));
3754 memset (&auxent
, 0, sizeof (union internal_auxent
));
3758 syment
._n
._n_n
._n_offset
= st_tmp
- string_table
;
3759 memcpy (st_tmp
, fini
, finisz
);
3763 memcpy (syment
._n
._n_name
, fini
, finisz
- 1);
3765 syment
.n_sclass
= C_EXT
;
3766 syment
.n_numaux
= 1;
3767 bfd_coff_swap_sym_out (abfd
, &syment
,
3768 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3769 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3771 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3774 memset (&reloc
, 0, sizeof (struct internal_reloc
));
3775 reloc
.r_vaddr
= 0x0028;
3776 reloc
.r_symndx
= filehdr
.f_nsyms
;
3777 reloc
.r_type
= R_POS
;
3779 bfd_coff_swap_reloc_out (abfd
, &reloc
,
3780 &reloc_ext
[scnhdr
.s_nreloc
* RELSZ
]);
3782 filehdr
.f_nsyms
+= 2;
3783 scnhdr
.s_nreloc
+= 1;
3788 memset (&syment
, 0, sizeof (struct internal_syment
));
3789 memset (&auxent
, 0, sizeof (union internal_auxent
));
3790 memcpy (syment
._n
._n_name
, rtld_name
, strlen (rtld_name
));
3791 syment
.n_sclass
= C_EXT
;
3792 syment
.n_numaux
= 1;
3793 bfd_coff_swap_sym_out (abfd
, &syment
,
3794 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3795 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3797 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3800 memset (&reloc
, 0, sizeof (struct internal_reloc
));
3801 reloc
.r_vaddr
= 0x0000;
3802 reloc
.r_symndx
= filehdr
.f_nsyms
;
3803 reloc
.r_type
= R_POS
;
3805 bfd_coff_swap_reloc_out (abfd
, &reloc
,
3806 &reloc_ext
[scnhdr
.s_nreloc
* RELSZ
]);
3808 filehdr
.f_nsyms
+= 2;
3809 scnhdr
.s_nreloc
+= 1;
3812 scnhdr
.s_relptr
= scnhdr
.s_scnptr
+ data_buffer_size
;
3813 filehdr
.f_symptr
= scnhdr
.s_relptr
+ scnhdr
.s_nreloc
* RELSZ
;
3815 bfd_coff_swap_filehdr_out (abfd
, &filehdr
, filehdr_ext
);
3816 bfd_bwrite (filehdr_ext
, FILHSZ
, abfd
);
3817 bfd_coff_swap_scnhdr_out (abfd
, &scnhdr
, scnhdr_ext
);
3818 bfd_bwrite (scnhdr_ext
, SCNHSZ
, abfd
);
3819 bfd_bwrite (data_buffer
, data_buffer_size
, abfd
);
3820 bfd_bwrite (reloc_ext
, scnhdr
.s_nreloc
* RELSZ
, abfd
);
3821 bfd_bwrite (syment_ext
, filehdr
.f_nsyms
* SYMESZ
, abfd
);
3822 bfd_bwrite (string_table
, string_table_size
, abfd
);
3831 static reloc_howto_type xcoff_dynamic_reloc
=
3832 HOWTO (0, /* type */
3834 2, /* size (0 = byte, 1 = short, 2 = long) */
3836 FALSE
, /* pc_relative */
3838 complain_overflow_bitfield
, /* complain_on_overflow */
3839 0, /* special_function */
3841 TRUE
, /* partial_inplace */
3842 0xffffffff, /* src_mask */
3843 0xffffffff, /* dst_mask */
3844 FALSE
); /* pcrel_offset */
3848 The first word of global linkage code must be modified by filling in
3849 the correct TOC offset. */
3851 static unsigned long xcoff_glink_code
[9] =
3853 0x81820000, /* lwz r12,0(r2) */
3854 0x90410014, /* stw r2,20(r1) */
3855 0x800c0000, /* lwz r0,0(r12) */
3856 0x804c0004, /* lwz r2,4(r12) */
3857 0x7c0903a6, /* mtctr r0 */
3858 0x4e800420, /* bctr */
3859 0x00000000, /* start of traceback table */
3860 0x000c8000, /* traceback table */
3861 0x00000000, /* traceback table */
3865 static const struct xcoff_backend_data_rec bfd_xcoff_backend_data
=
3867 { /* COFF backend, defined in libcoff.h. */
3868 _bfd_xcoff_swap_aux_in
,
3869 _bfd_xcoff_swap_sym_in
,
3870 coff_swap_lineno_in
,
3871 _bfd_xcoff_swap_aux_out
,
3872 _bfd_xcoff_swap_sym_out
,
3873 coff_swap_lineno_out
,
3874 xcoff_swap_reloc_out
,
3875 coff_swap_filehdr_out
,
3876 coff_swap_aouthdr_out
,
3877 coff_swap_scnhdr_out
,
3886 TRUE
, /* _bfd_coff_long_filenames */
3887 XCOFF_NO_LONG_SECTION_NAMES
, /* _bfd_coff_long_section_names */
3888 3, /* _bfd_coff_default_section_alignment_power */
3889 FALSE
, /* _bfd_coff_force_symnames_in_strings */
3890 2, /* _bfd_coff_debug_string_prefix_length */
3891 coff_swap_filehdr_in
,
3892 coff_swap_aouthdr_in
,
3893 coff_swap_scnhdr_in
,
3894 xcoff_swap_reloc_in
,
3895 coff_bad_format_hook
,
3896 coff_set_arch_mach_hook
,
3899 coff_set_alignment_hook
,
3900 coff_slurp_symbol_table
,
3901 symname_in_debug_hook
,
3902 coff_pointerize_aux_hook
,
3904 dummy_reloc16_extra_cases
,
3905 dummy_reloc16_estimate
,
3906 NULL
, /* bfd_coff_sym_is_global */
3907 coff_compute_section_file_positions
,
3908 NULL
, /* _bfd_coff_start_final_link */
3909 xcoff_ppc_relocate_section
,
3910 coff_rtype_to_howto
,
3911 NULL
, /* _bfd_coff_adjust_symndx */
3912 _bfd_generic_link_add_one_symbol
,
3913 coff_link_output_has_begun
,
3914 coff_final_link_postscript
,
3915 NULL
/* print_pdata. */
3918 0x01DF, /* magic number */
3922 /* Function pointers to xcoff specific swap routines. */
3923 xcoff_swap_ldhdr_in
,
3924 xcoff_swap_ldhdr_out
,
3925 xcoff_swap_ldsym_in
,
3926 xcoff_swap_ldsym_out
,
3927 xcoff_swap_ldrel_in
,
3928 xcoff_swap_ldrel_out
,
3934 12, /* _xcoff_function_descriptor_size */
3938 1, /* _xcoff_ldhdr_version */
3940 _bfd_xcoff_put_symbol_name
,
3941 _bfd_xcoff_put_ldsymbol_name
,
3942 &xcoff_dynamic_reloc
,
3943 xcoff_create_csect_from_smclas
,
3945 /* Lineno and reloc count overflow. */
3946 xcoff_is_lineno_count_overflow
,
3947 xcoff_is_reloc_count_overflow
,
3949 xcoff_loader_symbol_offset
,
3950 xcoff_loader_reloc_offset
,
3953 &xcoff_glink_code
[0],
3954 36, /* _xcoff_glink_size */
3957 64, /* _xcoff_rtinit_size */
3958 xcoff_generate_rtinit
,
3961 /* The transfer vector that leads the outside world to all of the above. */
3962 const bfd_target rs6000coff_vec
=
3965 bfd_target_xcoff_flavour
,
3966 BFD_ENDIAN_BIG
, /* data byte order is big */
3967 BFD_ENDIAN_BIG
, /* header byte order is big */
3969 (HAS_RELOC
| EXEC_P
| HAS_LINENO
| HAS_DEBUG
| DYNAMIC
3970 | HAS_SYMS
| HAS_LOCALS
| WP_TEXT
),
3972 SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_CODE
| SEC_DATA
,
3973 0, /* leading char */
3974 '/', /* ar_pad_char */
3975 15, /* ar_max_namelen */
3999 { /* bfd_check_format */
4002 _bfd_xcoff_archive_p
,
4006 { /* bfd_set_format */
4009 _bfd_generic_mkarchive
,
4013 {/* bfd_write_contents */
4015 coff_write_object_contents
,
4016 _bfd_xcoff_write_archive_contents
,
4023 coff_new_section_hook
,
4024 _bfd_generic_get_section_contents
,
4025 _bfd_generic_get_section_contents_in_window
,
4028 _bfd_xcoff_copy_private_bfd_data
,
4029 _bfd_generic_bfd_merge_private_bfd_data
,
4030 _bfd_generic_init_private_section_data
,
4031 _bfd_generic_bfd_copy_private_section_data
,
4032 _bfd_generic_bfd_copy_private_symbol_data
,
4033 _bfd_generic_bfd_copy_private_header_data
,
4034 _bfd_generic_bfd_set_private_flags
,
4035 _bfd_generic_bfd_print_private_bfd_data
,
4038 BFD_JUMP_TABLE_CORE (coff
),
4041 _bfd_xcoff_slurp_armap
,
4042 _bfd_noarchive_slurp_extended_name_table
,
4043 _bfd_noarchive_construct_extended_name_table
,
4044 bfd_dont_truncate_arname
,
4045 _bfd_xcoff_write_armap
,
4046 _bfd_xcoff_read_ar_hdr
,
4047 _bfd_generic_write_ar_hdr
,
4048 _bfd_xcoff_openr_next_archived_file
,
4049 _bfd_generic_get_elt_at_index
,
4050 _bfd_xcoff_stat_arch_elt
,
4054 coff_get_symtab_upper_bound
,
4055 coff_canonicalize_symtab
,
4056 coff_make_empty_symbol
,
4058 coff_get_symbol_info
,
4059 _bfd_xcoff_is_local_label_name
,
4060 coff_bfd_is_target_special_symbol
,
4062 coff_find_nearest_line
,
4063 _bfd_generic_find_line
,
4064 coff_find_inliner_info
,
4065 coff_bfd_make_debug_symbol
,
4066 _bfd_generic_read_minisymbols
,
4067 _bfd_generic_minisymbol_to_symbol
,
4070 coff_get_reloc_upper_bound
,
4071 coff_canonicalize_reloc
,
4072 _bfd_xcoff_reloc_type_lookup
,
4073 _bfd_xcoff_reloc_name_lookup
,
4077 coff_set_section_contents
,
4080 _bfd_xcoff_sizeof_headers
,
4081 bfd_generic_get_relocated_section_contents
,
4082 bfd_generic_relax_section
,
4083 _bfd_xcoff_bfd_link_hash_table_create
,
4084 _bfd_generic_link_hash_table_free
,
4085 _bfd_xcoff_bfd_link_add_symbols
,
4086 _bfd_generic_link_just_syms
,
4087 _bfd_generic_copy_link_hash_symbol_type
,
4088 _bfd_xcoff_bfd_final_link
,
4089 _bfd_generic_link_split_section
,
4090 bfd_generic_gc_sections
,
4091 bfd_generic_merge_sections
,
4092 bfd_generic_is_group_section
,
4093 bfd_generic_discard_group
,
4094 _bfd_generic_section_already_linked
,
4095 _bfd_xcoff_define_common_symbol
,
4098 _bfd_xcoff_get_dynamic_symtab_upper_bound
,
4099 _bfd_xcoff_canonicalize_dynamic_symtab
,
4100 _bfd_nodynamic_get_synthetic_symtab
,
4101 _bfd_xcoff_get_dynamic_reloc_upper_bound
,
4102 _bfd_xcoff_canonicalize_dynamic_reloc
,
4104 /* Opposite endian version, none exists */
4107 (void *) &bfd_xcoff_backend_data
,
4110 /* xcoff-powermac target
4112 Only difference between this target and the rs6000 target is the
4113 the default architecture and machine type used in coffcode.h
4115 PowerPC Macs use the same magic numbers as RS/6000
4116 (because that's how they were bootstrapped originally),
4117 but they are always PowerPC architecture. */
4118 static const struct xcoff_backend_data_rec bfd_pmac_xcoff_backend_data
=
4120 { /* COFF backend, defined in libcoff.h. */
4121 _bfd_xcoff_swap_aux_in
,
4122 _bfd_xcoff_swap_sym_in
,
4123 coff_swap_lineno_in
,
4124 _bfd_xcoff_swap_aux_out
,
4125 _bfd_xcoff_swap_sym_out
,
4126 coff_swap_lineno_out
,
4127 xcoff_swap_reloc_out
,
4128 coff_swap_filehdr_out
,
4129 coff_swap_aouthdr_out
,
4130 coff_swap_scnhdr_out
,
4139 TRUE
, /* _bfd_coff_long_filenames */
4140 XCOFF_NO_LONG_SECTION_NAMES
, /* _bfd_coff_long_section_names */
4141 3, /* _bfd_coff_default_section_alignment_power */
4142 FALSE
, /* _bfd_coff_force_symnames_in_strings */
4143 2, /* _bfd_coff_debug_string_prefix_length */
4144 coff_swap_filehdr_in
,
4145 coff_swap_aouthdr_in
,
4146 coff_swap_scnhdr_in
,
4147 xcoff_swap_reloc_in
,
4148 coff_bad_format_hook
,
4149 coff_set_arch_mach_hook
,
4152 coff_set_alignment_hook
,
4153 coff_slurp_symbol_table
,
4154 symname_in_debug_hook
,
4155 coff_pointerize_aux_hook
,
4157 dummy_reloc16_extra_cases
,
4158 dummy_reloc16_estimate
,
4159 NULL
, /* bfd_coff_sym_is_global */
4160 coff_compute_section_file_positions
,
4161 NULL
, /* _bfd_coff_start_final_link */
4162 xcoff_ppc_relocate_section
,
4163 coff_rtype_to_howto
,
4164 NULL
, /* _bfd_coff_adjust_symndx */
4165 _bfd_generic_link_add_one_symbol
,
4166 coff_link_output_has_begun
,
4167 coff_final_link_postscript
,
4168 NULL
/* print_pdata. */
4171 0x01DF, /* magic number */
4175 /* Function pointers to xcoff specific swap routines. */
4176 xcoff_swap_ldhdr_in
,
4177 xcoff_swap_ldhdr_out
,
4178 xcoff_swap_ldsym_in
,
4179 xcoff_swap_ldsym_out
,
4180 xcoff_swap_ldrel_in
,
4181 xcoff_swap_ldrel_out
,
4187 12, /* _xcoff_function_descriptor_size */
4191 1, /* _xcoff_ldhdr_version */
4193 _bfd_xcoff_put_symbol_name
,
4194 _bfd_xcoff_put_ldsymbol_name
,
4195 &xcoff_dynamic_reloc
,
4196 xcoff_create_csect_from_smclas
,
4198 /* Lineno and reloc count overflow. */
4199 xcoff_is_lineno_count_overflow
,
4200 xcoff_is_reloc_count_overflow
,
4202 xcoff_loader_symbol_offset
,
4203 xcoff_loader_reloc_offset
,
4206 &xcoff_glink_code
[0],
4207 36, /* _xcoff_glink_size */
4210 0, /* _xcoff_rtinit_size */
4211 xcoff_generate_rtinit
,
4214 /* The transfer vector that leads the outside world to all of the above. */
4215 const bfd_target pmac_xcoff_vec
=
4218 bfd_target_xcoff_flavour
,
4219 BFD_ENDIAN_BIG
, /* data byte order is big */
4220 BFD_ENDIAN_BIG
, /* header byte order is big */
4222 (HAS_RELOC
| EXEC_P
| HAS_LINENO
| HAS_DEBUG
| DYNAMIC
4223 | HAS_SYMS
| HAS_LOCALS
| WP_TEXT
),
4225 SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_CODE
| SEC_DATA
,
4226 0, /* leading char */
4227 '/', /* ar_pad_char */
4228 15, /* ar_max_namelen */
4252 { /* bfd_check_format */
4255 _bfd_xcoff_archive_p
,
4259 { /* bfd_set_format */
4262 _bfd_generic_mkarchive
,
4266 {/* bfd_write_contents */
4268 coff_write_object_contents
,
4269 _bfd_xcoff_write_archive_contents
,
4276 coff_new_section_hook
,
4277 _bfd_generic_get_section_contents
,
4278 _bfd_generic_get_section_contents_in_window
,
4281 _bfd_xcoff_copy_private_bfd_data
,
4282 _bfd_generic_bfd_merge_private_bfd_data
,
4283 _bfd_generic_init_private_section_data
,
4284 _bfd_generic_bfd_copy_private_section_data
,
4285 _bfd_generic_bfd_copy_private_symbol_data
,
4286 _bfd_generic_bfd_copy_private_header_data
,
4287 _bfd_generic_bfd_set_private_flags
,
4288 _bfd_generic_bfd_print_private_bfd_data
,
4291 BFD_JUMP_TABLE_CORE (coff
),
4294 _bfd_xcoff_slurp_armap
,
4295 _bfd_noarchive_slurp_extended_name_table
,
4296 _bfd_noarchive_construct_extended_name_table
,
4297 bfd_dont_truncate_arname
,
4298 _bfd_xcoff_write_armap
,
4299 _bfd_xcoff_read_ar_hdr
,
4300 _bfd_generic_write_ar_hdr
,
4301 _bfd_xcoff_openr_next_archived_file
,
4302 _bfd_generic_get_elt_at_index
,
4303 _bfd_xcoff_stat_arch_elt
,
4307 coff_get_symtab_upper_bound
,
4308 coff_canonicalize_symtab
,
4309 coff_make_empty_symbol
,
4311 coff_get_symbol_info
,
4312 _bfd_xcoff_is_local_label_name
,
4313 coff_bfd_is_target_special_symbol
,
4315 coff_find_nearest_line
,
4316 _bfd_generic_find_line
,
4317 coff_find_inliner_info
,
4318 coff_bfd_make_debug_symbol
,
4319 _bfd_generic_read_minisymbols
,
4320 _bfd_generic_minisymbol_to_symbol
,
4323 coff_get_reloc_upper_bound
,
4324 coff_canonicalize_reloc
,
4325 _bfd_xcoff_reloc_type_lookup
,
4326 _bfd_xcoff_reloc_name_lookup
,
4330 coff_set_section_contents
,
4333 _bfd_xcoff_sizeof_headers
,
4334 bfd_generic_get_relocated_section_contents
,
4335 bfd_generic_relax_section
,
4336 _bfd_xcoff_bfd_link_hash_table_create
,
4337 _bfd_generic_link_hash_table_free
,
4338 _bfd_xcoff_bfd_link_add_symbols
,
4339 _bfd_generic_link_just_syms
,
4340 _bfd_generic_copy_link_hash_symbol_type
,
4341 _bfd_xcoff_bfd_final_link
,
4342 _bfd_generic_link_split_section
,
4343 bfd_generic_gc_sections
,
4344 bfd_generic_merge_sections
,
4345 bfd_generic_is_group_section
,
4346 bfd_generic_discard_group
,
4347 _bfd_generic_section_already_linked
,
4348 _bfd_xcoff_define_common_symbol
,
4351 _bfd_xcoff_get_dynamic_symtab_upper_bound
,
4352 _bfd_xcoff_canonicalize_dynamic_symtab
,
4353 _bfd_nodynamic_get_synthetic_symtab
,
4354 _bfd_xcoff_get_dynamic_reloc_upper_bound
,
4355 _bfd_xcoff_canonicalize_dynamic_reloc
,
4357 /* Opposite endian version, none exists */
4360 (void *) &bfd_pmac_xcoff_backend_data
,