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_n
.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_n
.x_offset
);
477 memcpy (in
->x_file
.x_fname
, ext
->x_file
.x_n
.x_fname
,
478 numaux
* sizeof (AUXENT
));
482 memcpy (in
->x_file
.x_fname
, ext
->x_file
.x_n
.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_n
.x_zeroes
);
582 H_PUT_32 (abfd
, in
->x_file
.x_n
.x_offset
,
583 ext
->x_file
.x_n
.x_n
.x_offset
);
587 memcpy (ext
->x_file
.x_n
.x_fname
, in
->x_file
.x_fname
, FILNMLEN
);
591 /* RS/6000 "csect" auxents */
595 if (indx
+ 1 == numaux
)
597 H_PUT_32 (abfd
, in
->x_csect
.x_scnlen
.l
, ext
->x_csect
.x_scnlen
);
598 H_PUT_32 (abfd
, in
->x_csect
.x_parmhash
, ext
->x_csect
.x_parmhash
);
599 H_PUT_16 (abfd
, in
->x_csect
.x_snhash
, ext
->x_csect
.x_snhash
);
600 /* We don't have to hack bitfields in x_smtyp because it's
601 defined by shifts-and-ands, which are equivalent on all
603 H_PUT_8 (abfd
, in
->x_csect
.x_smtyp
, ext
->x_csect
.x_smtyp
);
604 H_PUT_8 (abfd
, in
->x_csect
.x_smclas
, ext
->x_csect
.x_smclas
);
605 H_PUT_32 (abfd
, in
->x_csect
.x_stab
, ext
->x_csect
.x_stab
);
606 H_PUT_16 (abfd
, in
->x_csect
.x_snstab
, ext
->x_csect
.x_snstab
);
616 H_PUT_32 (abfd
, in
->x_scn
.x_scnlen
, ext
->x_scn
.x_scnlen
);
617 H_PUT_16 (abfd
, in
->x_scn
.x_nreloc
, ext
->x_scn
.x_nreloc
);
618 H_PUT_16 (abfd
, in
->x_scn
.x_nlinno
, ext
->x_scn
.x_nlinno
);
624 H_PUT_32 (abfd
, in
->x_sym
.x_tagndx
.l
, ext
->x_sym
.x_tagndx
);
625 H_PUT_16 (abfd
, in
->x_sym
.x_tvndx
, ext
->x_sym
.x_tvndx
);
627 if (in_class
== C_BLOCK
|| in_class
== C_FCN
|| ISFCN (type
)
630 H_PUT_32 (abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
,
631 ext
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
632 H_PUT_32 (abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
,
633 ext
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
637 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0],
638 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
639 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1],
640 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
641 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2],
642 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
643 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3],
644 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
648 H_PUT_32 (abfd
, in
->x_sym
.x_misc
.x_fsize
, ext
->x_sym
.x_misc
.x_fsize
);
651 H_PUT_16 (abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_lnno
,
652 ext
->x_sym
.x_misc
.x_lnsz
.x_lnno
);
653 H_PUT_16 (abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_size
,
654 ext
->x_sym
.x_misc
.x_lnsz
.x_size
);
658 return bfd_coff_auxesz (abfd
);
663 /* The XCOFF reloc table. Actually, XCOFF relocations specify the
664 bitsize and whether they are signed or not, along with a
665 conventional type. This table is for the types, which are used for
666 different algorithms for putting in the reloc. Many of these
667 relocs need special_function entries, which I have not written. */
670 reloc_howto_type xcoff_howto_table
[] =
672 /* Standard 32 bit relocation. */
673 HOWTO (R_POS
, /* type */
675 2, /* size (0 = byte, 1 = short, 2 = long) */
677 FALSE
, /* pc_relative */
679 complain_overflow_bitfield
, /* complain_on_overflow */
680 0, /* special_function */
682 TRUE
, /* partial_inplace */
683 0xffffffff, /* src_mask */
684 0xffffffff, /* dst_mask */
685 FALSE
), /* pcrel_offset */
687 /* 32 bit relocation, but store negative value. */
688 HOWTO (R_NEG
, /* type */
690 -2, /* size (0 = byte, 1 = short, 2 = long) */
692 FALSE
, /* pc_relative */
694 complain_overflow_bitfield
, /* complain_on_overflow */
695 0, /* special_function */
697 TRUE
, /* partial_inplace */
698 0xffffffff, /* src_mask */
699 0xffffffff, /* dst_mask */
700 FALSE
), /* pcrel_offset */
702 /* 32 bit PC relative relocation. */
703 HOWTO (R_REL
, /* type */
705 2, /* size (0 = byte, 1 = short, 2 = long) */
707 TRUE
, /* pc_relative */
709 complain_overflow_signed
, /* complain_on_overflow */
710 0, /* special_function */
712 TRUE
, /* partial_inplace */
713 0xffffffff, /* src_mask */
714 0xffffffff, /* dst_mask */
715 FALSE
), /* pcrel_offset */
717 /* 16 bit TOC relative relocation. */
718 HOWTO (R_TOC
, /* type */
720 1, /* size (0 = byte, 1 = short, 2 = long) */
722 FALSE
, /* pc_relative */
724 complain_overflow_bitfield
, /* complain_on_overflow */
725 0, /* special_function */
727 TRUE
, /* partial_inplace */
728 0xffff, /* src_mask */
729 0xffff, /* dst_mask */
730 FALSE
), /* pcrel_offset */
732 /* I don't really know what this is. */
733 HOWTO (R_RTB
, /* type */
735 2, /* size (0 = byte, 1 = short, 2 = long) */
737 FALSE
, /* pc_relative */
739 complain_overflow_bitfield
, /* complain_on_overflow */
740 0, /* special_function */
742 TRUE
, /* partial_inplace */
743 0xffffffff, /* src_mask */
744 0xffffffff, /* dst_mask */
745 FALSE
), /* pcrel_offset */
747 /* External TOC relative symbol. */
748 HOWTO (R_GL
, /* type */
750 1, /* size (0 = byte, 1 = short, 2 = long) */
752 FALSE
, /* pc_relative */
754 complain_overflow_bitfield
, /* complain_on_overflow */
755 0, /* special_function */
757 TRUE
, /* partial_inplace */
758 0xffff, /* src_mask */
759 0xffff, /* dst_mask */
760 FALSE
), /* pcrel_offset */
762 /* Local TOC relative symbol. */
763 HOWTO (R_TCL
, /* type */
765 1, /* size (0 = byte, 1 = short, 2 = long) */
767 FALSE
, /* pc_relative */
769 complain_overflow_bitfield
, /* complain_on_overflow */
770 0, /* special_function */
772 TRUE
, /* partial_inplace */
773 0xffff, /* src_mask */
774 0xffff, /* dst_mask */
775 FALSE
), /* pcrel_offset */
779 /* Non modifiable absolute branch. */
780 HOWTO (R_BA
, /* type */
782 2, /* size (0 = byte, 1 = short, 2 = long) */
784 FALSE
, /* pc_relative */
786 complain_overflow_bitfield
, /* complain_on_overflow */
787 0, /* special_function */
788 "R_BA_26", /* name */
789 TRUE
, /* partial_inplace */
790 0x03fffffc, /* src_mask */
791 0x03fffffc, /* dst_mask */
792 FALSE
), /* pcrel_offset */
796 /* Non modifiable relative branch. */
797 HOWTO (R_BR
, /* type */
799 2, /* size (0 = byte, 1 = short, 2 = long) */
801 TRUE
, /* pc_relative */
803 complain_overflow_signed
, /* complain_on_overflow */
804 0, /* special_function */
806 TRUE
, /* partial_inplace */
807 0x03fffffc, /* src_mask */
808 0x03fffffc, /* dst_mask */
809 FALSE
), /* pcrel_offset */
814 HOWTO (R_RL
, /* type */
816 1, /* size (0 = byte, 1 = short, 2 = long) */
818 FALSE
, /* pc_relative */
820 complain_overflow_bitfield
, /* complain_on_overflow */
821 0, /* special_function */
823 TRUE
, /* partial_inplace */
824 0xffff, /* src_mask */
825 0xffff, /* dst_mask */
826 FALSE
), /* pcrel_offset */
829 HOWTO (R_RLA
, /* type */
831 1, /* size (0 = byte, 1 = short, 2 = long) */
833 FALSE
, /* pc_relative */
835 complain_overflow_bitfield
, /* complain_on_overflow */
836 0, /* special_function */
838 TRUE
, /* partial_inplace */
839 0xffff, /* src_mask */
840 0xffff, /* dst_mask */
841 FALSE
), /* pcrel_offset */
845 /* Non-relocating reference. Bitsize is 1 so that r_rsize is 0. */
846 HOWTO (R_REF
, /* type */
848 0, /* size (0 = byte, 1 = short, 2 = long) */
850 FALSE
, /* pc_relative */
852 complain_overflow_dont
, /* complain_on_overflow */
853 0, /* special_function */
855 FALSE
, /* partial_inplace */
858 FALSE
), /* pcrel_offset */
863 /* TOC relative indirect load. */
864 HOWTO (R_TRL
, /* type */
866 1, /* size (0 = byte, 1 = short, 2 = long) */
868 FALSE
, /* pc_relative */
870 complain_overflow_bitfield
, /* complain_on_overflow */
871 0, /* special_function */
873 TRUE
, /* partial_inplace */
874 0xffff, /* src_mask */
875 0xffff, /* dst_mask */
876 FALSE
), /* pcrel_offset */
878 /* TOC relative load address. */
879 HOWTO (R_TRLA
, /* type */
881 1, /* size (0 = byte, 1 = short, 2 = long) */
883 FALSE
, /* pc_relative */
885 complain_overflow_bitfield
, /* complain_on_overflow */
886 0, /* special_function */
888 TRUE
, /* partial_inplace */
889 0xffff, /* src_mask */
890 0xffff, /* dst_mask */
891 FALSE
), /* pcrel_offset */
893 /* Modifiable relative branch. */
894 HOWTO (R_RRTBI
, /* type */
896 2, /* size (0 = byte, 1 = short, 2 = long) */
898 FALSE
, /* pc_relative */
900 complain_overflow_bitfield
, /* complain_on_overflow */
901 0, /* special_function */
902 "R_RRTBI", /* name */
903 TRUE
, /* partial_inplace */
904 0xffffffff, /* src_mask */
905 0xffffffff, /* dst_mask */
906 FALSE
), /* pcrel_offset */
908 /* Modifiable absolute branch. */
909 HOWTO (R_RRTBA
, /* type */
911 2, /* size (0 = byte, 1 = short, 2 = long) */
913 FALSE
, /* pc_relative */
915 complain_overflow_bitfield
, /* complain_on_overflow */
916 0, /* special_function */
917 "R_RRTBA", /* name */
918 TRUE
, /* partial_inplace */
919 0xffffffff, /* src_mask */
920 0xffffffff, /* dst_mask */
921 FALSE
), /* pcrel_offset */
923 /* Modifiable call absolute indirect. */
924 HOWTO (R_CAI
, /* type */
926 1, /* size (0 = byte, 1 = short, 2 = long) */
928 FALSE
, /* pc_relative */
930 complain_overflow_bitfield
, /* complain_on_overflow */
931 0, /* special_function */
933 TRUE
, /* partial_inplace */
934 0xffff, /* src_mask */
935 0xffff, /* dst_mask */
936 FALSE
), /* pcrel_offset */
938 /* Modifiable call relative. */
939 HOWTO (R_CREL
, /* type */
941 1, /* size (0 = byte, 1 = short, 2 = long) */
943 FALSE
, /* pc_relative */
945 complain_overflow_bitfield
, /* complain_on_overflow */
946 0, /* special_function */
948 TRUE
, /* partial_inplace */
949 0xffff, /* src_mask */
950 0xffff, /* dst_mask */
951 FALSE
), /* pcrel_offset */
953 /* Modifiable branch absolute. */
954 HOWTO (R_RBA
, /* type */
956 2, /* size (0 = byte, 1 = short, 2 = long) */
958 FALSE
, /* pc_relative */
960 complain_overflow_bitfield
, /* complain_on_overflow */
961 0, /* special_function */
963 TRUE
, /* partial_inplace */
964 0x03fffffc, /* src_mask */
965 0x03fffffc, /* dst_mask */
966 FALSE
), /* pcrel_offset */
968 /* Modifiable branch absolute. */
969 HOWTO (R_RBAC
, /* type */
971 2, /* size (0 = byte, 1 = short, 2 = long) */
973 FALSE
, /* pc_relative */
975 complain_overflow_bitfield
, /* complain_on_overflow */
976 0, /* special_function */
978 TRUE
, /* partial_inplace */
979 0xffffffff, /* src_mask */
980 0xffffffff, /* dst_mask */
981 FALSE
), /* pcrel_offset */
983 /* Modifiable branch relative. */
984 HOWTO (R_RBR
, /* type */
986 2, /* size (0 = byte, 1 = short, 2 = long) */
988 FALSE
, /* pc_relative */
990 complain_overflow_signed
, /* complain_on_overflow */
991 0, /* special_function */
992 "R_RBR_26", /* name */
993 TRUE
, /* partial_inplace */
994 0x03fffffc, /* src_mask */
995 0x03fffffc, /* dst_mask */
996 FALSE
), /* pcrel_offset */
998 /* Modifiable branch absolute. */
999 HOWTO (R_RBRC
, /* type */
1001 1, /* size (0 = byte, 1 = short, 2 = long) */
1003 FALSE
, /* pc_relative */
1005 complain_overflow_bitfield
, /* complain_on_overflow */
1006 0, /* special_function */
1007 "R_RBRC", /* name */
1008 TRUE
, /* partial_inplace */
1009 0xffff, /* src_mask */
1010 0xffff, /* dst_mask */
1011 FALSE
), /* pcrel_offset */
1013 /* 16 bit Non modifiable absolute branch. */
1014 HOWTO (R_BA
, /* type */
1016 1, /* size (0 = byte, 1 = short, 2 = long) */
1018 FALSE
, /* pc_relative */
1020 complain_overflow_bitfield
, /* complain_on_overflow */
1021 0, /* special_function */
1022 "R_BA_16", /* name */
1023 TRUE
, /* partial_inplace */
1024 0xfffc, /* src_mask */
1025 0xfffc, /* dst_mask */
1026 FALSE
), /* pcrel_offset */
1028 /* Modifiable branch relative. */
1029 HOWTO (R_RBR
, /* type */
1031 1, /* size (0 = byte, 1 = short, 2 = long) */
1033 FALSE
, /* pc_relative */
1035 complain_overflow_signed
, /* complain_on_overflow */
1036 0, /* special_function */
1037 "R_RBR_16", /* name */
1038 TRUE
, /* partial_inplace */
1039 0xffff, /* src_mask */
1040 0xffff, /* dst_mask */
1041 FALSE
), /* pcrel_offset */
1043 /* Modifiable branch relative. */
1044 HOWTO (R_RBA
, /* type */
1046 1, /* size (0 = byte, 1 = short, 2 = long) */
1048 FALSE
, /* pc_relative */
1050 complain_overflow_signed
, /* complain_on_overflow */
1051 0, /* special_function */
1052 "R_RBA_16", /* name */
1053 TRUE
, /* partial_inplace */
1054 0xffff, /* src_mask */
1055 0xffff, /* dst_mask */
1056 FALSE
), /* pcrel_offset */
1061 xcoff_rtype2howto (arelent
*relent
, struct internal_reloc
*internal
)
1063 if (internal
->r_type
> R_RBRC
)
1066 /* Default howto layout works most of the time */
1067 relent
->howto
= &xcoff_howto_table
[internal
->r_type
];
1069 /* Special case some 16 bit reloc */
1070 if (15 == (internal
->r_size
& 0x1f))
1072 if (R_BA
== internal
->r_type
)
1073 relent
->howto
= &xcoff_howto_table
[0x1c];
1074 else if (R_RBR
== internal
->r_type
)
1075 relent
->howto
= &xcoff_howto_table
[0x1d];
1076 else if (R_RBA
== internal
->r_type
)
1077 relent
->howto
= &xcoff_howto_table
[0x1e];
1080 /* The r_size field of an XCOFF reloc encodes the bitsize of the
1081 relocation, as well as indicating whether it is signed or not.
1082 Doublecheck that the relocation information gathered from the
1083 type matches this information. The bitsize is not significant
1084 for R_REF relocs. */
1085 if (relent
->howto
->dst_mask
!= 0
1086 && (relent
->howto
->bitsize
1087 != ((unsigned int) internal
->r_size
& 0x1f) + 1))
1092 _bfd_xcoff_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1093 bfd_reloc_code_real_type code
)
1097 case BFD_RELOC_PPC_B26
:
1098 return &xcoff_howto_table
[0xa];
1099 case BFD_RELOC_PPC_BA16
:
1100 return &xcoff_howto_table
[0x1c];
1101 case BFD_RELOC_PPC_BA26
:
1102 return &xcoff_howto_table
[8];
1103 case BFD_RELOC_PPC_TOC16
:
1104 return &xcoff_howto_table
[3];
1106 case BFD_RELOC_CTOR
:
1107 return &xcoff_howto_table
[0];
1108 case BFD_RELOC_NONE
:
1109 return &xcoff_howto_table
[0xf];
1115 static reloc_howto_type
*
1116 _bfd_xcoff_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1122 i
< sizeof (xcoff_howto_table
) / sizeof (xcoff_howto_table
[0]);
1124 if (xcoff_howto_table
[i
].name
!= NULL
1125 && strcasecmp (xcoff_howto_table
[i
].name
, r_name
) == 0)
1126 return &xcoff_howto_table
[i
];
1131 /* XCOFF archive support. The original version of this code was by
1132 Damon A. Permezel. It was enhanced to permit cross support, and
1133 writing archive files, by Ian Lance Taylor, Cygnus Support.
1135 XCOFF uses its own archive format. Everything is hooked together
1136 with file offset links, so it is possible to rapidly update an
1137 archive in place. Of course, we don't do that. An XCOFF archive
1138 has a real file header, not just an ARMAG string. The structure of
1139 the file header and of each archive header appear below.
1141 An XCOFF archive also has a member table, which is a list of
1142 elements in the archive (you can get that by looking through the
1143 linked list, but you have to read a lot more of the file). The
1144 member table has a normal archive header with an empty name. It is
1145 normally (and perhaps must be) the second to last entry in the
1146 archive. The member table data is almost printable ASCII. It
1147 starts with a 12 character decimal string which is the number of
1148 entries in the table. For each entry it has a 12 character decimal
1149 string which is the offset in the archive of that member. These
1150 entries are followed by a series of null terminated strings which
1151 are the member names for each entry.
1153 Finally, an XCOFF archive has a global symbol table, which is what
1154 we call the armap. The global symbol table has a normal archive
1155 header with an empty name. It is normally (and perhaps must be)
1156 the last entry in the archive. The contents start with a four byte
1157 binary number which is the number of entries. This is followed by
1158 a that many four byte binary numbers; each is the file offset of an
1159 entry in the archive. These numbers are followed by a series of
1160 null terminated strings, which are symbol names.
1162 AIX 4.3 introduced a new archive format which can handle larger
1163 files and also 32- and 64-bit objects in the same archive. The
1164 things said above remain true except that there is now more than
1165 one global symbol table. The one is used to index 32-bit objects,
1166 the other for 64-bit objects.
1168 The new archives (recognizable by the new ARMAG string) has larger
1169 field lengths so that we cannot really share any code. Also we have
1170 to take care that we are not generating the new form of archives
1171 on AIX 4.2 or earlier systems. */
1173 /* XCOFF archives use this as a magic string. Note that both strings
1174 have the same length. */
1176 /* Set the magic for archive. */
1179 bfd_xcoff_ar_archive_set_magic (bfd
*abfd ATTRIBUTE_UNUSED
,
1180 char *magic ATTRIBUTE_UNUSED
)
1182 /* Not supported yet. */
1184 /* bfd_xcoff_archive_set_magic (abfd, magic); */
1187 /* Read in the armap of an XCOFF archive. */
1190 _bfd_xcoff_slurp_armap (bfd
*abfd
)
1195 bfd_byte
*contents
, *cend
;
1200 if (xcoff_ardata (abfd
) == NULL
)
1202 bfd_has_map (abfd
) = FALSE
;
1206 if (! xcoff_big_format_p (abfd
))
1208 /* This is for the old format. */
1209 struct xcoff_ar_hdr hdr
;
1211 off
= strtol (xcoff_ardata (abfd
)->symoff
, (char **) NULL
, 10);
1214 bfd_has_map (abfd
) = FALSE
;
1218 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0)
1221 /* The symbol table starts with a normal archive header. */
1222 if (bfd_bread ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1226 /* Skip the name (normally empty). */
1227 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1228 off
= ((namlen
+ 1) & ~ (size_t) 1) + SXCOFFARFMAG
;
1229 if (bfd_seek (abfd
, off
, SEEK_CUR
) != 0)
1232 sz
= strtol (hdr
.size
, (char **) NULL
, 10);
1234 /* Read in the entire symbol table. */
1235 contents
= (bfd_byte
*) bfd_alloc (abfd
, sz
);
1236 if (contents
== NULL
)
1238 if (bfd_bread ((PTR
) contents
, sz
, abfd
) != sz
)
1241 /* The symbol table starts with a four byte count. */
1242 c
= H_GET_32 (abfd
, contents
);
1246 bfd_set_error (bfd_error_bad_value
);
1250 bfd_ardata (abfd
)->symdefs
=
1251 ((carsym
*) bfd_alloc (abfd
, c
* sizeof (carsym
)));
1252 if (bfd_ardata (abfd
)->symdefs
== NULL
)
1255 /* After the count comes a list of four byte file offsets. */
1256 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
, p
= contents
+ 4;
1258 ++i
, ++arsym
, p
+= 4)
1259 arsym
->file_offset
= H_GET_32 (abfd
, p
);
1263 /* This is for the new format. */
1264 struct xcoff_ar_hdr_big hdr
;
1266 off
= strtol (xcoff_ardata_big (abfd
)->symoff
, (char **) NULL
, 10);
1269 bfd_has_map (abfd
) = FALSE
;
1273 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0)
1276 /* The symbol table starts with a normal archive header. */
1277 if (bfd_bread ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR_BIG
, abfd
)
1278 != SIZEOF_AR_HDR_BIG
)
1281 /* Skip the name (normally empty). */
1282 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1283 off
= ((namlen
+ 1) & ~ (size_t) 1) + SXCOFFARFMAG
;
1284 if (bfd_seek (abfd
, off
, SEEK_CUR
) != 0)
1287 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1288 machines) since the field width is 20 and there numbers with more
1289 than 32 bits can be represented. */
1290 sz
= strtol (hdr
.size
, (char **) NULL
, 10);
1292 /* Read in the entire symbol table. */
1293 contents
= (bfd_byte
*) bfd_alloc (abfd
, sz
);
1294 if (contents
== NULL
)
1296 if (bfd_bread ((PTR
) contents
, sz
, abfd
) != sz
)
1299 /* The symbol table starts with an eight byte count. */
1300 c
= H_GET_64 (abfd
, contents
);
1304 bfd_set_error (bfd_error_bad_value
);
1308 bfd_ardata (abfd
)->symdefs
=
1309 ((carsym
*) bfd_alloc (abfd
, c
* sizeof (carsym
)));
1310 if (bfd_ardata (abfd
)->symdefs
== NULL
)
1313 /* After the count comes a list of eight byte file offsets. */
1314 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
, p
= contents
+ 8;
1316 ++i
, ++arsym
, p
+= 8)
1317 arsym
->file_offset
= H_GET_64 (abfd
, p
);
1320 /* After the file offsets come null terminated symbol names. */
1321 cend
= contents
+ sz
;
1322 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
;
1324 ++i
, ++arsym
, p
+= strlen ((char *) p
) + 1)
1328 bfd_set_error (bfd_error_bad_value
);
1331 arsym
->name
= (char *) p
;
1334 bfd_ardata (abfd
)->symdef_count
= c
;
1335 bfd_has_map (abfd
) = TRUE
;
1340 /* See if this is an XCOFF archive. */
1343 _bfd_xcoff_archive_p (bfd
*abfd
)
1345 struct artdata
*tdata_hold
;
1346 char magic
[SXCOFFARMAG
];
1347 bfd_size_type amt
= SXCOFFARMAG
;
1349 if (bfd_bread ((PTR
) magic
, amt
, abfd
) != amt
)
1351 if (bfd_get_error () != bfd_error_system_call
)
1352 bfd_set_error (bfd_error_wrong_format
);
1356 if (strncmp (magic
, XCOFFARMAG
, SXCOFFARMAG
) != 0
1357 && strncmp (magic
, XCOFFARMAGBIG
, SXCOFFARMAG
) != 0)
1359 bfd_set_error (bfd_error_wrong_format
);
1363 tdata_hold
= bfd_ardata (abfd
);
1365 amt
= sizeof (struct artdata
);
1366 bfd_ardata (abfd
) = (struct artdata
*) bfd_zalloc (abfd
, amt
);
1367 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
1368 goto error_ret_restore
;
1370 /* Cleared by bfd_zalloc above.
1371 bfd_ardata (abfd)->cache = NULL;
1372 bfd_ardata (abfd)->archive_head = NULL;
1373 bfd_ardata (abfd)->symdefs = NULL;
1374 bfd_ardata (abfd)->extended_names = NULL;
1375 bfd_ardata (abfd)->extended_names_size = 0; */
1377 /* Now handle the two formats. */
1378 if (magic
[1] != 'b')
1380 /* This is the old format. */
1381 struct xcoff_ar_file_hdr hdr
;
1383 /* Copy over the magic string. */
1384 memcpy (hdr
.magic
, magic
, SXCOFFARMAG
);
1386 /* Now read the rest of the file header. */
1387 amt
= SIZEOF_AR_FILE_HDR
- SXCOFFARMAG
;
1388 if (bfd_bread ((PTR
) &hdr
.memoff
, amt
, abfd
) != amt
)
1390 if (bfd_get_error () != bfd_error_system_call
)
1391 bfd_set_error (bfd_error_wrong_format
);
1395 bfd_ardata (abfd
)->first_file_filepos
= strtol (hdr
.firstmemoff
,
1396 (char **) NULL
, 10);
1398 amt
= SIZEOF_AR_FILE_HDR
;
1399 bfd_ardata (abfd
)->tdata
= bfd_zalloc (abfd
, amt
);
1400 if (bfd_ardata (abfd
)->tdata
== NULL
)
1403 memcpy (bfd_ardata (abfd
)->tdata
, &hdr
, SIZEOF_AR_FILE_HDR
);
1407 /* This is the new format. */
1408 struct xcoff_ar_file_hdr_big hdr
;
1410 /* Copy over the magic string. */
1411 memcpy (hdr
.magic
, magic
, SXCOFFARMAG
);
1413 /* Now read the rest of the file header. */
1414 amt
= SIZEOF_AR_FILE_HDR_BIG
- SXCOFFARMAG
;
1415 if (bfd_bread ((PTR
) &hdr
.memoff
, amt
, abfd
) != amt
)
1417 if (bfd_get_error () != bfd_error_system_call
)
1418 bfd_set_error (bfd_error_wrong_format
);
1422 bfd_ardata (abfd
)->first_file_filepos
= bfd_scan_vma (hdr
.firstmemoff
,
1426 amt
= SIZEOF_AR_FILE_HDR_BIG
;
1427 bfd_ardata (abfd
)->tdata
= bfd_zalloc (abfd
, amt
);
1428 if (bfd_ardata (abfd
)->tdata
== NULL
)
1431 memcpy (bfd_ardata (abfd
)->tdata
, &hdr
, SIZEOF_AR_FILE_HDR_BIG
);
1434 if (! _bfd_xcoff_slurp_armap (abfd
))
1437 bfd_release (abfd
, bfd_ardata (abfd
));
1439 bfd_ardata (abfd
) = tdata_hold
;
1446 /* Read the archive header in an XCOFF archive. */
1449 _bfd_xcoff_read_ar_hdr (bfd
*abfd
)
1451 bfd_size_type namlen
;
1452 struct areltdata
*ret
;
1453 bfd_size_type amt
= sizeof (struct areltdata
);
1455 ret
= (struct areltdata
*) bfd_alloc (abfd
, amt
);
1459 if (! xcoff_big_format_p (abfd
))
1461 struct xcoff_ar_hdr hdr
;
1462 struct xcoff_ar_hdr
*hdrp
;
1464 if (bfd_bread ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1471 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1472 amt
= SIZEOF_AR_HDR
+ namlen
+ 1;
1473 hdrp
= (struct xcoff_ar_hdr
*) bfd_alloc (abfd
, amt
);
1479 memcpy (hdrp
, &hdr
, SIZEOF_AR_HDR
);
1480 if (bfd_bread ((char *) hdrp
+ SIZEOF_AR_HDR
, namlen
, abfd
) != namlen
)
1485 ((char *) hdrp
)[SIZEOF_AR_HDR
+ namlen
] = '\0';
1487 ret
->arch_header
= (char *) hdrp
;
1488 ret
->parsed_size
= strtol (hdr
.size
, (char **) NULL
, 10);
1489 ret
->filename
= (char *) hdrp
+ SIZEOF_AR_HDR
;
1493 struct xcoff_ar_hdr_big hdr
;
1494 struct xcoff_ar_hdr_big
*hdrp
;
1496 if (bfd_bread ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR_BIG
, abfd
)
1497 != SIZEOF_AR_HDR_BIG
)
1503 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1504 amt
= SIZEOF_AR_HDR_BIG
+ namlen
+ 1;
1505 hdrp
= (struct xcoff_ar_hdr_big
*) bfd_alloc (abfd
, amt
);
1511 memcpy (hdrp
, &hdr
, SIZEOF_AR_HDR_BIG
);
1512 if (bfd_bread ((char *) hdrp
+ SIZEOF_AR_HDR_BIG
, namlen
, abfd
) != namlen
)
1517 ((char *) hdrp
)[SIZEOF_AR_HDR_BIG
+ namlen
] = '\0';
1519 ret
->arch_header
= (char *) hdrp
;
1520 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1521 machines) since the field width is 20 and there numbers with more
1522 than 32 bits can be represented. */
1523 ret
->parsed_size
= strtol (hdr
.size
, (char **) NULL
, 10);
1524 ret
->filename
= (char *) hdrp
+ SIZEOF_AR_HDR_BIG
;
1527 /* Skip over the XCOFFARFMAG at the end of the file name. */
1528 if (bfd_seek (abfd
, (file_ptr
) ((namlen
& 1) + SXCOFFARFMAG
), SEEK_CUR
) != 0)
1534 /* Open the next element in an XCOFF archive. */
1537 _bfd_xcoff_openr_next_archived_file (bfd
*archive
, bfd
*last_file
)
1541 if (xcoff_ardata (archive
) == NULL
)
1543 bfd_set_error (bfd_error_invalid_operation
);
1547 if (! xcoff_big_format_p (archive
))
1549 if (last_file
== NULL
)
1550 filestart
= bfd_ardata (archive
)->first_file_filepos
;
1552 filestart
= strtol (arch_xhdr (last_file
)->nextoff
, (char **) NULL
,
1556 || filestart
== strtol (xcoff_ardata (archive
)->memoff
,
1558 || filestart
== strtol (xcoff_ardata (archive
)->symoff
,
1559 (char **) NULL
, 10))
1561 bfd_set_error (bfd_error_no_more_archived_files
);
1567 if (last_file
== NULL
)
1568 filestart
= bfd_ardata (archive
)->first_file_filepos
;
1570 /* XXX These actually have to be a calls to strtoll (at least
1571 on 32-bit machines) since the fields's width is 20 and
1572 there numbers with more than 32 bits can be represented. */
1573 filestart
= strtol (arch_xhdr_big (last_file
)->nextoff
, (char **) NULL
,
1576 /* XXX These actually have to be calls to strtoll (at least on 32-bit
1577 machines) since the fields's width is 20 and there numbers with more
1578 than 32 bits can be represented. */
1580 || filestart
== strtol (xcoff_ardata_big (archive
)->memoff
,
1582 || filestart
== strtol (xcoff_ardata_big (archive
)->symoff
,
1583 (char **) NULL
, 10))
1585 bfd_set_error (bfd_error_no_more_archived_files
);
1590 return _bfd_get_elt_at_filepos (archive
, filestart
);
1593 /* Stat an element in an XCOFF archive. */
1596 _bfd_xcoff_stat_arch_elt (bfd
*abfd
, struct stat
*s
)
1598 if (abfd
->arelt_data
== NULL
)
1600 bfd_set_error (bfd_error_invalid_operation
);
1604 if (! xcoff_big_format_p (abfd
->my_archive
))
1606 struct xcoff_ar_hdr
*hdrp
= arch_xhdr (abfd
);
1608 s
->st_mtime
= strtol (hdrp
->date
, (char **) NULL
, 10);
1609 s
->st_uid
= strtol (hdrp
->uid
, (char **) NULL
, 10);
1610 s
->st_gid
= strtol (hdrp
->gid
, (char **) NULL
, 10);
1611 s
->st_mode
= strtol (hdrp
->mode
, (char **) NULL
, 8);
1612 s
->st_size
= arch_eltdata (abfd
)->parsed_size
;
1616 struct xcoff_ar_hdr_big
*hdrp
= arch_xhdr_big (abfd
);
1618 s
->st_mtime
= strtol (hdrp
->date
, (char **) NULL
, 10);
1619 s
->st_uid
= strtol (hdrp
->uid
, (char **) NULL
, 10);
1620 s
->st_gid
= strtol (hdrp
->gid
, (char **) NULL
, 10);
1621 s
->st_mode
= strtol (hdrp
->mode
, (char **) NULL
, 8);
1622 s
->st_size
= arch_eltdata (abfd
)->parsed_size
;
1628 /* Normalize a file name for inclusion in an archive. */
1631 normalize_filename (bfd
*abfd
)
1634 const char *filename
;
1636 file
= bfd_get_filename (abfd
);
1637 filename
= strrchr (file
, '/');
1638 if (filename
!= NULL
)
1645 /* Write out an XCOFF armap. */
1648 xcoff_write_armap_old (bfd
*abfd
, unsigned int elength ATTRIBUTE_UNUSED
,
1649 struct orl
*map
, unsigned int orl_count
, int stridx
)
1651 struct archive_iterator iterator
;
1652 struct xcoff_ar_hdr hdr
;
1654 unsigned char buf
[4];
1657 memset (&hdr
, 0, sizeof hdr
);
1658 sprintf (hdr
.size
, "%ld", (long) (4 + orl_count
* 4 + stridx
));
1659 sprintf (hdr
.nextoff
, "%d", 0);
1660 memcpy (hdr
.prevoff
, xcoff_ardata (abfd
)->memoff
, XCOFFARMAG_ELEMENT_SIZE
);
1661 sprintf (hdr
.date
, "%d", 0);
1662 sprintf (hdr
.uid
, "%d", 0);
1663 sprintf (hdr
.gid
, "%d", 0);
1664 sprintf (hdr
.mode
, "%d", 0);
1665 sprintf (hdr
.namlen
, "%d", 0);
1667 /* We need spaces, not null bytes, in the header. */
1668 for (p
= (char *) &hdr
; p
< (char *) &hdr
+ SIZEOF_AR_HDR
; p
++)
1672 if (bfd_bwrite ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1674 || (bfd_bwrite (XCOFFARFMAG
, (bfd_size_type
) SXCOFFARFMAG
, abfd
)
1678 H_PUT_32 (abfd
, orl_count
, buf
);
1679 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
1683 archive_iterator_begin (&iterator
, abfd
);
1684 while (i
< orl_count
&& archive_iterator_next (&iterator
))
1685 while (map
[i
].u
.abfd
== iterator
.current
.member
)
1687 H_PUT_32 (abfd
, iterator
.current
.offset
, buf
);
1688 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
1693 for (i
= 0; i
< orl_count
; i
++)
1698 name
= *map
[i
].name
;
1699 namlen
= strlen (name
);
1700 if (bfd_bwrite (name
, (bfd_size_type
) (namlen
+ 1), abfd
) != namlen
+ 1)
1704 if ((stridx
& 1) != 0)
1709 if (bfd_bwrite (&b
, (bfd_size_type
) 1, abfd
) != 1)
1716 static char buff20
[XCOFFARMAGBIG_ELEMENT_SIZE
+ 1];
1717 #define FMT20 "%-20lld"
1718 #define FMT12 "%-12d"
1719 #define FMT12_OCTAL "%-12o"
1721 #define PRINT20(d, v) \
1722 sprintf (buff20, FMT20, (long long)(v)), \
1723 memcpy ((void *) (d), buff20, 20)
1725 #define PRINT12(d, v) \
1726 sprintf (buff20, FMT12, (int)(v)), \
1727 memcpy ((void *) (d), buff20, 12)
1729 #define PRINT12_OCTAL(d, v) \
1730 sprintf (buff20, FMT12_OCTAL, (unsigned int)(v)), \
1731 memcpy ((void *) (d), buff20, 12)
1733 #define PRINT4(d, v) \
1734 sprintf (buff20, FMT4, (int)(v)), \
1735 memcpy ((void *) (d), buff20, 4)
1737 #define READ20(d, v) \
1739 memcpy (buff20, (d), 20), \
1740 (v) = bfd_scan_vma (buff20, (const char **) NULL, 10)
1743 do_pad (bfd
*abfd
, unsigned int number
)
1747 /* Limit pad to <= 4096. */
1752 if (bfd_bwrite (&b
, (bfd_size_type
) 1, abfd
) != 1)
1759 do_copy (bfd
*out_bfd
, bfd
*in_bfd
)
1761 bfd_size_type remaining
;
1762 bfd_byte buffer
[DEFAULT_BUFFERSIZE
];
1764 if (bfd_seek (in_bfd
, (file_ptr
) 0, SEEK_SET
) != 0)
1767 remaining
= arelt_size (in_bfd
);
1769 while (remaining
>= DEFAULT_BUFFERSIZE
)
1771 if (bfd_bread (buffer
, DEFAULT_BUFFERSIZE
, in_bfd
) != DEFAULT_BUFFERSIZE
1772 || bfd_bwrite (buffer
, DEFAULT_BUFFERSIZE
, out_bfd
) != DEFAULT_BUFFERSIZE
)
1775 remaining
-= DEFAULT_BUFFERSIZE
;
1780 if (bfd_bread (buffer
, remaining
, in_bfd
) != remaining
1781 || bfd_bwrite (buffer
, remaining
, out_bfd
) != remaining
)
1789 xcoff_write_armap_big (bfd
*abfd
, unsigned int elength ATTRIBUTE_UNUSED
,
1790 struct orl
*map
, unsigned int orl_count
, int stridx
)
1792 struct archive_iterator iterator
;
1793 struct xcoff_ar_file_hdr_big
*fhdr
;
1794 bfd_vma i
, sym_32
, sym_64
, str_32
, str_64
;
1795 const bfd_arch_info_type
*arch_info
;
1797 size_t string_length
;
1798 file_ptr nextoff
, prevoff
;
1800 /* First, we look through the symbols and work out which are
1801 from 32-bit objects and which from 64-bit ones. */
1802 sym_32
= sym_64
= str_32
= str_64
= 0;
1805 for (current_bfd
= abfd
->archive_head
;
1806 current_bfd
!= NULL
&& i
< orl_count
;
1807 current_bfd
= current_bfd
->archive_next
)
1809 arch_info
= bfd_get_arch_info (current_bfd
);
1810 while (map
[i
].u
.abfd
== current_bfd
)
1812 string_length
= strlen (*map
[i
].name
) + 1;
1813 if (arch_info
->bits_per_address
== 64)
1816 str_64
+= string_length
;
1821 str_32
+= string_length
;
1827 /* A quick sanity check... */
1828 BFD_ASSERT (sym_64
+ sym_32
== orl_count
);
1829 /* Explicit cast to int for compiler. */
1830 BFD_ASSERT ((int)(str_64
+ str_32
) == stridx
);
1832 fhdr
= xcoff_ardata_big (abfd
);
1834 /* xcoff_write_archive_contents_big passes nextoff in symoff. */
1835 READ20 (fhdr
->memoff
, prevoff
);
1836 READ20 (fhdr
->symoff
, nextoff
);
1838 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
1840 /* Write out the symbol table.
1843 standard big archive header
1844 0x0000 ar_size [0x14]
1845 0x0014 ar_nxtmem [0x14]
1846 0x0028 ar_prvmem [0x14]
1847 0x003C ar_date [0x0C]
1848 0x0048 ar_uid [0x0C]
1849 0x0054 ar_gid [0x0C]
1850 0x0060 ar_mod [0x0C]
1851 0x006C ar_namelen[0x04]
1852 0x0070 ar_fmag [SXCOFFARFMAG]
1855 0x0072 num_syms [0x08], binary
1856 0x0078 offsets [0x08 * num_syms], binary
1857 0x0086 + 0x08 * num_syms names [??]
1858 ?? pad to even bytes.
1863 struct xcoff_ar_hdr_big
*hdr
;
1867 bfd_vma symbol_table_size
=
1872 + str_32
+ (str_32
& 1);
1874 symbol_table
= bfd_zmalloc (symbol_table_size
);
1875 if (symbol_table
== NULL
)
1878 hdr
= (struct xcoff_ar_hdr_big
*) symbol_table
;
1880 PRINT20 (hdr
->size
, 8 + 8 * sym_32
+ str_32
+ (str_32
& 1));
1883 PRINT20 (hdr
->nextoff
, nextoff
+ symbol_table_size
);
1885 PRINT20 (hdr
->nextoff
, 0);
1887 PRINT20 (hdr
->prevoff
, prevoff
);
1888 PRINT12 (hdr
->date
, 0);
1889 PRINT12 (hdr
->uid
, 0);
1890 PRINT12 (hdr
->gid
, 0);
1891 PRINT12 (hdr
->mode
, 0);
1892 PRINT4 (hdr
->namlen
, 0) ;
1894 st
= symbol_table
+ SIZEOF_AR_HDR_BIG
;
1895 memcpy (st
, XCOFFARFMAG
, SXCOFFARFMAG
);
1898 bfd_h_put_64 (abfd
, sym_32
, st
);
1901 /* loop over the 32 bit offsets */
1903 archive_iterator_begin (&iterator
, abfd
);
1904 while (i
< orl_count
&& archive_iterator_next (&iterator
))
1906 arch_info
= bfd_get_arch_info (iterator
.current
.member
);
1907 while (map
[i
].u
.abfd
== iterator
.current
.member
)
1909 if (arch_info
->bits_per_address
== 32)
1911 bfd_h_put_64 (abfd
, iterator
.current
.offset
, st
);
1918 /* loop over the 32 bit symbol names */
1920 for (current_bfd
= abfd
->archive_head
;
1921 current_bfd
!= NULL
&& i
< orl_count
;
1922 current_bfd
= current_bfd
->archive_next
)
1924 arch_info
= bfd_get_arch_info (current_bfd
);
1925 while (map
[i
].u
.abfd
== current_bfd
)
1927 if (arch_info
->bits_per_address
== 32)
1929 string_length
= sprintf (st
, "%s", *map
[i
].name
);
1930 st
+= string_length
+ 1;
1936 bfd_bwrite (symbol_table
, symbol_table_size
, abfd
);
1938 free (symbol_table
);
1941 nextoff
= nextoff
+ symbol_table_size
;
1944 PRINT20 (fhdr
->symoff
, 0);
1948 struct xcoff_ar_hdr_big
*hdr
;
1952 bfd_vma symbol_table_size
=
1957 + str_64
+ (str_64
& 1);
1959 symbol_table
= bfd_zmalloc (symbol_table_size
);
1960 if (symbol_table
== NULL
)
1963 hdr
= (struct xcoff_ar_hdr_big
*) symbol_table
;
1965 PRINT20 (hdr
->size
, 8 + 8 * sym_64
+ str_64
+ (str_64
& 1));
1966 PRINT20 (hdr
->nextoff
, 0);
1967 PRINT20 (hdr
->prevoff
, prevoff
);
1968 PRINT12 (hdr
->date
, 0);
1969 PRINT12 (hdr
->uid
, 0);
1970 PRINT12 (hdr
->gid
, 0);
1971 PRINT12 (hdr
->mode
, 0);
1972 PRINT4 (hdr
->namlen
, 0);
1974 st
= symbol_table
+ SIZEOF_AR_HDR_BIG
;
1975 memcpy (st
, XCOFFARFMAG
, SXCOFFARFMAG
);
1978 bfd_h_put_64 (abfd
, sym_64
, st
);
1981 /* loop over the 64 bit offsets */
1983 archive_iterator_begin (&iterator
, abfd
);
1984 while (i
< orl_count
&& archive_iterator_next (&iterator
))
1986 arch_info
= bfd_get_arch_info (iterator
.current
.member
);
1987 while (map
[i
].u
.abfd
== iterator
.current
.member
)
1989 if (arch_info
->bits_per_address
== 64)
1991 bfd_h_put_64 (abfd
, iterator
.current
.offset
, st
);
1998 /* loop over the 64 bit symbol names */
2000 for (current_bfd
= abfd
->archive_head
;
2001 current_bfd
!= NULL
&& i
< orl_count
;
2002 current_bfd
= current_bfd
->archive_next
)
2004 arch_info
= bfd_get_arch_info (current_bfd
);
2005 while (map
[i
].u
.abfd
== current_bfd
)
2007 if (arch_info
->bits_per_address
== 64)
2009 string_length
= sprintf (st
, "%s", *map
[i
].name
);
2010 st
+= string_length
+ 1;
2016 bfd_bwrite (symbol_table
, symbol_table_size
, abfd
);
2018 free (symbol_table
);
2020 PRINT20 (fhdr
->symoff64
, nextoff
);
2023 PRINT20 (fhdr
->symoff64
, 0);
2029 _bfd_xcoff_write_armap (bfd
*abfd
, unsigned int elength ATTRIBUTE_UNUSED
,
2030 struct orl
*map
, unsigned int orl_count
, int stridx
)
2032 if (! xcoff_big_format_p (abfd
))
2033 return xcoff_write_armap_old (abfd
, elength
, map
, orl_count
, stridx
);
2035 return xcoff_write_armap_big (abfd
, elength
, map
, orl_count
, stridx
);
2038 /* Write out an XCOFF archive. We always write an entire archive,
2039 rather than fussing with the freelist and so forth. */
2042 xcoff_write_archive_contents_old (bfd
*abfd
)
2044 struct archive_iterator iterator
;
2045 struct xcoff_ar_file_hdr fhdr
;
2046 bfd_size_type count
;
2047 bfd_size_type total_namlen
;
2049 bfd_boolean makemap
;
2050 bfd_boolean hasobjects
;
2051 file_ptr prevoff
, nextoff
;
2054 struct xcoff_ar_hdr ahdr
;
2057 char decbuf
[XCOFFARMAG_ELEMENT_SIZE
+ 1];
2059 memset (&fhdr
, 0, sizeof fhdr
);
2060 (void) strncpy (fhdr
.magic
, XCOFFARMAG
, SXCOFFARMAG
);
2061 sprintf (fhdr
.firstmemoff
, "%d", SIZEOF_AR_FILE_HDR
);
2062 sprintf (fhdr
.freeoff
, "%d", 0);
2066 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->archive_next
)
2069 total_namlen
+= strlen (normalize_filename (sub
)) + 1;
2070 if (sub
->arelt_data
== NULL
)
2072 sub
->arelt_data
= bfd_zalloc (sub
, sizeof (struct areltdata
));
2073 if (sub
->arelt_data
== NULL
)
2076 if (arch_xhdr (sub
) == NULL
)
2078 struct xcoff_ar_hdr
*ahdrp
;
2081 if (stat (bfd_get_filename (sub
), &s
) != 0)
2083 bfd_set_error (bfd_error_system_call
);
2087 ahdrp
= bfd_zalloc (sub
, sizeof (*ahdrp
));
2091 sprintf (ahdrp
->size
, "%ld", (long) s
.st_size
);
2092 sprintf (ahdrp
->date
, "%ld", (long) s
.st_mtime
);
2093 sprintf (ahdrp
->uid
, "%ld", (long) s
.st_uid
);
2094 sprintf (ahdrp
->gid
, "%ld", (long) s
.st_gid
);
2095 sprintf (ahdrp
->mode
, "%o", (unsigned int) s
.st_mode
);
2097 arch_eltdata (sub
)->arch_header
= (char *) ahdrp
;
2098 arch_eltdata (sub
)->parsed_size
= s
.st_size
;
2101 offsets
= (file_ptr
*) bfd_alloc (abfd
, count
* sizeof (file_ptr
));
2102 if (offsets
== NULL
)
2105 if (bfd_seek (abfd
, (file_ptr
) SIZEOF_AR_FILE_HDR
, SEEK_SET
) != 0)
2108 makemap
= bfd_has_map (abfd
);
2111 for (archive_iterator_begin (&iterator
, abfd
), i
= 0;
2112 archive_iterator_next (&iterator
);
2115 bfd_size_type namlen
;
2116 struct xcoff_ar_hdr
*ahdrp
;
2118 if (makemap
&& ! hasobjects
)
2120 if (bfd_check_format (iterator
.current
.member
, bfd_object
))
2124 ahdrp
= arch_xhdr (iterator
.current
.member
);
2125 sprintf (ahdrp
->prevoff
, "%ld", (long) prevoff
);
2126 sprintf (ahdrp
->namlen
, "%ld", (long) iterator
.current
.namlen
);
2127 sprintf (ahdrp
->nextoff
, "%ld", (long) iterator
.next
.offset
);
2129 /* We need spaces, not null bytes, in the header. */
2130 for (p
= (char *) ahdrp
; p
< (char *) ahdrp
+ SIZEOF_AR_HDR
; p
++)
2134 if (!do_pad (abfd
, iterator
.current
.leading_padding
))
2137 BFD_ASSERT (iterator
.current
.offset
== bfd_tell (abfd
));
2138 namlen
= iterator
.current
.padded_namlen
;
2139 if (bfd_bwrite (ahdrp
, SIZEOF_AR_HDR
, abfd
) != SIZEOF_AR_HDR
2140 || bfd_bwrite (iterator
.current
.name
, namlen
, abfd
) != namlen
2141 || bfd_bwrite (XCOFFARFMAG
, SXCOFFARFMAG
, abfd
) != SXCOFFARFMAG
2142 || bfd_seek (iterator
.current
.member
, 0, SEEK_SET
) != 0
2143 || !do_copy (abfd
, iterator
.current
.member
)
2144 || !do_pad (abfd
, iterator
.current
.trailing_padding
))
2147 offsets
[i
] = iterator
.current
.offset
;
2148 prevoff
= iterator
.current
.offset
;
2151 sprintf (fhdr
.lastmemoff
, "%ld", (long) prevoff
);
2153 /* Write out the member table. */
2155 nextoff
= iterator
.next
.offset
;
2156 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2157 sprintf (fhdr
.memoff
, "%ld", (long) nextoff
);
2159 memset (&ahdr
, 0, sizeof ahdr
);
2160 sprintf (ahdr
.size
, "%ld", (long) (XCOFFARMAG_ELEMENT_SIZE
2161 + count
* XCOFFARMAG_ELEMENT_SIZE
2163 sprintf (ahdr
.prevoff
, "%ld", (long) prevoff
);
2164 sprintf (ahdr
.date
, "%d", 0);
2165 sprintf (ahdr
.uid
, "%d", 0);
2166 sprintf (ahdr
.gid
, "%d", 0);
2167 sprintf (ahdr
.mode
, "%d", 0);
2168 sprintf (ahdr
.namlen
, "%d", 0);
2170 size
= (SIZEOF_AR_HDR
2171 + XCOFFARMAG_ELEMENT_SIZE
2172 + count
* XCOFFARMAG_ELEMENT_SIZE
2177 nextoff
+= size
+ (size
& 1);
2179 if (makemap
&& hasobjects
)
2180 sprintf (ahdr
.nextoff
, "%ld", (long) nextoff
);
2182 sprintf (ahdr
.nextoff
, "%d", 0);
2184 /* We need spaces, not null bytes, in the header. */
2185 for (p
= (char *) &ahdr
; p
< (char *) &ahdr
+ SIZEOF_AR_HDR
; p
++)
2189 if ((bfd_bwrite ((PTR
) &ahdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
2191 || (bfd_bwrite ((PTR
) XCOFFARFMAG
, (bfd_size_type
) SXCOFFARFMAG
, abfd
)
2195 sprintf (decbuf
, "%-12ld", (long) count
);
2196 if (bfd_bwrite ((PTR
) decbuf
, (bfd_size_type
) XCOFFARMAG_ELEMENT_SIZE
, abfd
)
2197 != XCOFFARMAG_ELEMENT_SIZE
)
2199 for (i
= 0; i
< (size_t) count
; i
++)
2201 sprintf (decbuf
, "%-12ld", (long) offsets
[i
]);
2202 if (bfd_bwrite ((PTR
) decbuf
, (bfd_size_type
) XCOFFARMAG_ELEMENT_SIZE
,
2203 abfd
) != XCOFFARMAG_ELEMENT_SIZE
)
2206 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->archive_next
)
2209 bfd_size_type namlen
;
2211 name
= normalize_filename (sub
);
2212 namlen
= strlen (name
);
2213 if (bfd_bwrite ((PTR
) name
, namlen
+ 1, abfd
) != namlen
+ 1)
2217 if (! do_pad (abfd
, size
& 1))
2220 /* Write out the armap, if appropriate. */
2221 if (! makemap
|| ! hasobjects
)
2222 sprintf (fhdr
.symoff
, "%d", 0);
2225 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2226 sprintf (fhdr
.symoff
, "%ld", (long) nextoff
);
2227 bfd_ardata (abfd
)->tdata
= (PTR
) &fhdr
;
2228 if (! _bfd_compute_and_write_armap (abfd
, 0))
2232 /* Write out the archive file header. */
2234 /* We need spaces, not null bytes, in the header. */
2235 for (p
= (char *) &fhdr
; p
< (char *) &fhdr
+ SIZEOF_AR_FILE_HDR
; p
++)
2239 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
2240 || (bfd_bwrite ((PTR
) &fhdr
, (bfd_size_type
) SIZEOF_AR_FILE_HDR
, abfd
)
2241 != SIZEOF_AR_FILE_HDR
))
2248 xcoff_write_archive_contents_big (bfd
*abfd
)
2250 struct xcoff_ar_file_hdr_big fhdr
;
2251 bfd_size_type count
;
2252 bfd_size_type total_namlen
;
2254 bfd_boolean makemap
;
2255 bfd_boolean hasobjects
;
2256 file_ptr prevoff
, nextoff
;
2259 struct xcoff_ar_hdr_big
*hdr
;
2261 char *member_table
, *mt
;
2262 bfd_vma member_table_size
;
2263 struct archive_iterator iterator
;
2265 memset (&fhdr
, 0, SIZEOF_AR_FILE_HDR_BIG
);
2266 memcpy (fhdr
.magic
, XCOFFARMAGBIG
, SXCOFFARMAG
);
2268 if (bfd_seek (abfd
, (file_ptr
) SIZEOF_AR_FILE_HDR_BIG
, SEEK_SET
) != 0)
2271 /* Calculate count and total_namlen. */
2272 makemap
= bfd_has_map (abfd
);
2274 for (current_bfd
= abfd
->archive_head
, count
= 0, total_namlen
= 0;
2275 current_bfd
!= NULL
;
2276 current_bfd
= current_bfd
->archive_next
, count
++)
2278 total_namlen
+= strlen (normalize_filename (current_bfd
)) + 1;
2282 && bfd_check_format (current_bfd
, bfd_object
))
2285 if (current_bfd
->arelt_data
== NULL
)
2287 size
= sizeof (struct areltdata
);
2288 current_bfd
->arelt_data
= bfd_zalloc (current_bfd
, size
);
2289 if (current_bfd
->arelt_data
== NULL
)
2293 if (arch_xhdr_big (current_bfd
) == NULL
)
2295 struct xcoff_ar_hdr_big
*ahdrp
;
2298 /* XXX This should actually be a call to stat64 (at least on
2300 XXX This call will fail if the original object is not found. */
2301 if (stat (bfd_get_filename (current_bfd
), &s
) != 0)
2303 bfd_set_error (bfd_error_system_call
);
2307 ahdrp
= bfd_zalloc (current_bfd
, sizeof (*ahdrp
));
2311 PRINT20 (ahdrp
->size
, s
.st_size
);
2312 PRINT12 (ahdrp
->date
, s
.st_mtime
);
2313 PRINT12 (ahdrp
->uid
, s
.st_uid
);
2314 PRINT12 (ahdrp
->gid
, s
.st_gid
);
2315 PRINT12_OCTAL (ahdrp
->mode
, s
.st_mode
);
2317 arch_eltdata (current_bfd
)->arch_header
= (char *) ahdrp
;
2318 arch_eltdata (current_bfd
)->parsed_size
= s
.st_size
;
2325 offsets
= (file_ptr
*) bfd_malloc (count
* sizeof (file_ptr
));
2326 if (offsets
== NULL
)
2331 for (archive_iterator_begin (&iterator
, abfd
), i
= 0;
2332 archive_iterator_next (&iterator
);
2335 bfd_size_type namlen
;
2336 struct xcoff_ar_hdr_big
*ahdrp
;
2338 ahdrp
= arch_xhdr_big (iterator
.current
.member
);
2339 PRINT20 (ahdrp
->prevoff
, prevoff
);
2340 PRINT4 (ahdrp
->namlen
, iterator
.current
.namlen
);
2341 PRINT20 (ahdrp
->nextoff
, iterator
.next
.offset
);
2343 if (!do_pad (abfd
, iterator
.current
.leading_padding
))
2346 BFD_ASSERT (iterator
.current
.offset
== bfd_tell (abfd
));
2347 namlen
= iterator
.current
.padded_namlen
;
2348 if (bfd_bwrite (ahdrp
, SIZEOF_AR_HDR_BIG
, abfd
) != SIZEOF_AR_HDR_BIG
2349 || bfd_bwrite (iterator
.current
.name
, namlen
, abfd
) != namlen
2350 || bfd_bwrite (XCOFFARFMAG
, SXCOFFARFMAG
, abfd
) != SXCOFFARFMAG
2351 || bfd_seek (iterator
.current
.member
, 0, SEEK_SET
) != 0
2352 || !do_copy (abfd
, iterator
.current
.member
)
2353 || !do_pad (abfd
, iterator
.current
.trailing_padding
))
2356 offsets
[i
] = iterator
.current
.offset
;
2357 prevoff
= iterator
.current
.offset
;
2362 PRINT20 (fhdr
.firstmemoff
, offsets
[0]);
2363 PRINT20 (fhdr
.lastmemoff
, prevoff
);
2366 /* Write out the member table.
2369 standard big archive header
2370 0x0000 ar_size [0x14]
2371 0x0014 ar_nxtmem [0x14]
2372 0x0028 ar_prvmem [0x14]
2373 0x003C ar_date [0x0C]
2374 0x0048 ar_uid [0x0C]
2375 0x0054 ar_gid [0x0C]
2376 0x0060 ar_mod [0x0C]
2377 0x006C ar_namelen[0x04]
2378 0x0070 ar_fmag [0x02]
2382 0x0086 offsets [0x14 * counts]
2383 0x0086 + 0x14 * counts names [??]
2384 ?? pad to even bytes.
2387 nextoff
= iterator
.next
.offset
;
2388 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2390 member_table_size
= (SIZEOF_AR_HDR_BIG
2392 + XCOFFARMAGBIG_ELEMENT_SIZE
2393 + count
* XCOFFARMAGBIG_ELEMENT_SIZE
2396 member_table_size
+= member_table_size
& 1;
2397 member_table
= bfd_zmalloc (member_table_size
);
2398 if (member_table
== NULL
)
2401 hdr
= (struct xcoff_ar_hdr_big
*) member_table
;
2403 PRINT20 (hdr
->size
, (XCOFFARMAGBIG_ELEMENT_SIZE
2404 + count
* XCOFFARMAGBIG_ELEMENT_SIZE
2405 + total_namlen
+ (total_namlen
& 1)));
2406 if (makemap
&& hasobjects
)
2407 PRINT20 (hdr
->nextoff
, nextoff
+ member_table_size
);
2409 PRINT20 (hdr
->nextoff
, 0);
2410 PRINT20 (hdr
->prevoff
, prevoff
);
2411 PRINT12 (hdr
->date
, 0);
2412 PRINT12 (hdr
->uid
, 0);
2413 PRINT12 (hdr
->gid
, 0);
2414 PRINT12 (hdr
->mode
, 0);
2415 PRINT4 (hdr
->namlen
, 0);
2417 mt
= member_table
+ SIZEOF_AR_HDR_BIG
;
2418 memcpy (mt
, XCOFFARFMAG
, SXCOFFARFMAG
);
2421 PRINT20 (mt
, count
);
2422 mt
+= XCOFFARMAGBIG_ELEMENT_SIZE
;
2423 for (i
= 0; i
< (size_t) count
; i
++)
2425 PRINT20 (mt
, offsets
[i
]);
2426 mt
+= XCOFFARMAGBIG_ELEMENT_SIZE
;
2435 for (current_bfd
= abfd
->archive_head
;
2436 current_bfd
!= NULL
;
2437 current_bfd
= current_bfd
->archive_next
)
2442 name
= normalize_filename (current_bfd
);
2443 namlen
= sprintf (mt
, "%s", name
);
2447 if (bfd_bwrite (member_table
, member_table_size
, abfd
) != member_table_size
)
2450 free (member_table
);
2452 PRINT20 (fhdr
.memoff
, nextoff
);
2455 nextoff
+= member_table_size
;
2457 /* Write out the armap, if appropriate. */
2459 if (! makemap
|| ! hasobjects
)
2460 PRINT20 (fhdr
.symoff
, 0);
2463 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2465 /* Save nextoff in fhdr.symoff so the armap routine can use it. */
2466 PRINT20 (fhdr
.symoff
, nextoff
);
2468 bfd_ardata (abfd
)->tdata
= (PTR
) &fhdr
;
2469 if (! _bfd_compute_and_write_armap (abfd
, 0))
2473 /* Write out the archive file header. */
2475 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
2476 || (bfd_bwrite ((PTR
) &fhdr
, (bfd_size_type
) SIZEOF_AR_FILE_HDR_BIG
,
2477 abfd
) != SIZEOF_AR_FILE_HDR_BIG
))
2484 _bfd_xcoff_write_archive_contents (bfd
*abfd
)
2486 if (! xcoff_big_format_p (abfd
))
2487 return xcoff_write_archive_contents_old (abfd
);
2489 return xcoff_write_archive_contents_big (abfd
);
2492 /* We can't use the usual coff_sizeof_headers routine, because AIX
2493 always uses an a.out header. */
2496 _bfd_xcoff_sizeof_headers (bfd
*abfd
,
2497 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
2502 if (xcoff_data (abfd
)->full_aouthdr
)
2505 size
+= SMALL_AOUTSZ
;
2506 size
+= abfd
->section_count
* SCNHSZ
;
2510 /* Routines to swap information in the XCOFF .loader section. If we
2511 ever need to write an XCOFF loader, this stuff will need to be
2512 moved to another file shared by the linker (which XCOFF calls the
2513 ``binder'') and the loader. */
2515 /* Swap in the ldhdr structure. */
2518 xcoff_swap_ldhdr_in (bfd
*abfd
, const PTR s
, struct internal_ldhdr
*dst
)
2520 const struct external_ldhdr
*src
= (const struct external_ldhdr
*) s
;
2522 dst
->l_version
= bfd_get_32 (abfd
, src
->l_version
);
2523 dst
->l_nsyms
= bfd_get_32 (abfd
, src
->l_nsyms
);
2524 dst
->l_nreloc
= bfd_get_32 (abfd
, src
->l_nreloc
);
2525 dst
->l_istlen
= bfd_get_32 (abfd
, src
->l_istlen
);
2526 dst
->l_nimpid
= bfd_get_32 (abfd
, src
->l_nimpid
);
2527 dst
->l_impoff
= bfd_get_32 (abfd
, src
->l_impoff
);
2528 dst
->l_stlen
= bfd_get_32 (abfd
, src
->l_stlen
);
2529 dst
->l_stoff
= bfd_get_32 (abfd
, src
->l_stoff
);
2532 /* Swap out the ldhdr structure. */
2535 xcoff_swap_ldhdr_out (bfd
*abfd
, const struct internal_ldhdr
*src
, PTR d
)
2537 struct external_ldhdr
*dst
= (struct external_ldhdr
*) d
;
2539 bfd_put_32 (abfd
, (bfd_vma
) src
->l_version
, dst
->l_version
);
2540 bfd_put_32 (abfd
, src
->l_nsyms
, dst
->l_nsyms
);
2541 bfd_put_32 (abfd
, src
->l_nreloc
, dst
->l_nreloc
);
2542 bfd_put_32 (abfd
, src
->l_istlen
, dst
->l_istlen
);
2543 bfd_put_32 (abfd
, src
->l_nimpid
, dst
->l_nimpid
);
2544 bfd_put_32 (abfd
, src
->l_impoff
, dst
->l_impoff
);
2545 bfd_put_32 (abfd
, src
->l_stlen
, dst
->l_stlen
);
2546 bfd_put_32 (abfd
, src
->l_stoff
, dst
->l_stoff
);
2549 /* Swap in the ldsym structure. */
2552 xcoff_swap_ldsym_in (bfd
*abfd
, const PTR s
, struct internal_ldsym
*dst
)
2554 const struct external_ldsym
*src
= (const struct external_ldsym
*) s
;
2556 if (bfd_get_32 (abfd
, src
->_l
._l_l
._l_zeroes
) != 0) {
2557 memcpy (dst
->_l
._l_name
, src
->_l
._l_name
, SYMNMLEN
);
2559 dst
->_l
._l_l
._l_zeroes
= 0;
2560 dst
->_l
._l_l
._l_offset
= bfd_get_32 (abfd
, src
->_l
._l_l
._l_offset
);
2562 dst
->l_value
= bfd_get_32 (abfd
, src
->l_value
);
2563 dst
->l_scnum
= bfd_get_16 (abfd
, src
->l_scnum
);
2564 dst
->l_smtype
= bfd_get_8 (abfd
, src
->l_smtype
);
2565 dst
->l_smclas
= bfd_get_8 (abfd
, src
->l_smclas
);
2566 dst
->l_ifile
= bfd_get_32 (abfd
, src
->l_ifile
);
2567 dst
->l_parm
= bfd_get_32 (abfd
, src
->l_parm
);
2570 /* Swap out the ldsym structure. */
2573 xcoff_swap_ldsym_out (bfd
*abfd
, const struct internal_ldsym
*src
, PTR d
)
2575 struct external_ldsym
*dst
= (struct external_ldsym
*) d
;
2577 if (src
->_l
._l_l
._l_zeroes
!= 0)
2578 memcpy (dst
->_l
._l_name
, src
->_l
._l_name
, SYMNMLEN
);
2581 bfd_put_32 (abfd
, (bfd_vma
) 0, dst
->_l
._l_l
._l_zeroes
);
2582 bfd_put_32 (abfd
, (bfd_vma
) src
->_l
._l_l
._l_offset
,
2583 dst
->_l
._l_l
._l_offset
);
2585 bfd_put_32 (abfd
, src
->l_value
, dst
->l_value
);
2586 bfd_put_16 (abfd
, (bfd_vma
) src
->l_scnum
, dst
->l_scnum
);
2587 bfd_put_8 (abfd
, src
->l_smtype
, dst
->l_smtype
);
2588 bfd_put_8 (abfd
, src
->l_smclas
, dst
->l_smclas
);
2589 bfd_put_32 (abfd
, src
->l_ifile
, dst
->l_ifile
);
2590 bfd_put_32 (abfd
, src
->l_parm
, dst
->l_parm
);
2594 xcoff_swap_reloc_in (bfd
*abfd
, PTR s
, PTR d
)
2596 struct external_reloc
*src
= (struct external_reloc
*) s
;
2597 struct internal_reloc
*dst
= (struct internal_reloc
*) d
;
2599 memset (dst
, 0, sizeof (struct internal_reloc
));
2601 dst
->r_vaddr
= bfd_get_32 (abfd
, src
->r_vaddr
);
2602 dst
->r_symndx
= bfd_get_32 (abfd
, src
->r_symndx
);
2603 dst
->r_size
= bfd_get_8 (abfd
, src
->r_size
);
2604 dst
->r_type
= bfd_get_8 (abfd
, src
->r_type
);
2608 xcoff_swap_reloc_out (bfd
*abfd
, PTR s
, PTR d
)
2610 struct internal_reloc
*src
= (struct internal_reloc
*) s
;
2611 struct external_reloc
*dst
= (struct external_reloc
*) d
;
2613 bfd_put_32 (abfd
, src
->r_vaddr
, dst
->r_vaddr
);
2614 bfd_put_32 (abfd
, src
->r_symndx
, dst
->r_symndx
);
2615 bfd_put_8 (abfd
, src
->r_type
, dst
->r_type
);
2616 bfd_put_8 (abfd
, src
->r_size
, dst
->r_size
);
2618 return bfd_coff_relsz (abfd
);
2621 /* Swap in the ldrel structure. */
2624 xcoff_swap_ldrel_in (bfd
*abfd
, const PTR s
, struct internal_ldrel
*dst
)
2626 const struct external_ldrel
*src
= (const struct external_ldrel
*) s
;
2628 dst
->l_vaddr
= bfd_get_32 (abfd
, src
->l_vaddr
);
2629 dst
->l_symndx
= bfd_get_32 (abfd
, src
->l_symndx
);
2630 dst
->l_rtype
= bfd_get_16 (abfd
, src
->l_rtype
);
2631 dst
->l_rsecnm
= bfd_get_16 (abfd
, src
->l_rsecnm
);
2634 /* Swap out the ldrel structure. */
2637 xcoff_swap_ldrel_out (bfd
*abfd
, const struct internal_ldrel
*src
, PTR d
)
2639 struct external_ldrel
*dst
= (struct external_ldrel
*) d
;
2641 bfd_put_32 (abfd
, src
->l_vaddr
, dst
->l_vaddr
);
2642 bfd_put_32 (abfd
, src
->l_symndx
, dst
->l_symndx
);
2643 bfd_put_16 (abfd
, (bfd_vma
) src
->l_rtype
, dst
->l_rtype
);
2644 bfd_put_16 (abfd
, (bfd_vma
) src
->l_rsecnm
, dst
->l_rsecnm
);
2649 xcoff_reloc_type_noop (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2650 asection
*input_section ATTRIBUTE_UNUSED
,
2651 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2652 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
2653 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2654 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
,
2655 bfd_vma val ATTRIBUTE_UNUSED
,
2656 bfd_vma addend ATTRIBUTE_UNUSED
,
2657 bfd_vma
*relocation ATTRIBUTE_UNUSED
,
2658 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2664 xcoff_reloc_type_fail (bfd
*input_bfd
,
2665 asection
*input_section ATTRIBUTE_UNUSED
,
2666 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2667 struct internal_reloc
*rel
,
2668 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2669 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
,
2670 bfd_vma val ATTRIBUTE_UNUSED
,
2671 bfd_vma addend ATTRIBUTE_UNUSED
,
2672 bfd_vma
*relocation ATTRIBUTE_UNUSED
,
2673 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2675 (*_bfd_error_handler
)
2676 (_("%s: unsupported relocation type 0x%02x"),
2677 bfd_get_filename (input_bfd
), (unsigned int) rel
->r_type
);
2678 bfd_set_error (bfd_error_bad_value
);
2683 xcoff_reloc_type_pos (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2684 asection
*input_section ATTRIBUTE_UNUSED
,
2685 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2686 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
2687 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2688 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
,
2691 bfd_vma
*relocation
,
2692 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2694 *relocation
= val
+ addend
;
2699 xcoff_reloc_type_neg (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2700 asection
*input_section ATTRIBUTE_UNUSED
,
2701 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2702 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
2703 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2704 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
,
2707 bfd_vma
*relocation
,
2708 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2710 *relocation
= addend
- val
;
2715 xcoff_reloc_type_rel (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2716 asection
*input_section
,
2717 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2718 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
2719 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2720 struct reloc_howto_struct
*howto
,
2723 bfd_vma
*relocation
,
2724 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2726 howto
->pc_relative
= TRUE
;
2728 /* A PC relative reloc includes the section address. */
2729 addend
+= input_section
->vma
;
2731 *relocation
= val
+ addend
;
2732 *relocation
-= (input_section
->output_section
->vma
2733 + input_section
->output_offset
);
2738 xcoff_reloc_type_toc (bfd
*input_bfd
,
2739 asection
*input_section ATTRIBUTE_UNUSED
,
2741 struct internal_reloc
*rel
,
2742 struct internal_syment
*sym
,
2743 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
,
2745 bfd_vma addend ATTRIBUTE_UNUSED
,
2746 bfd_vma
*relocation
,
2747 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2749 struct xcoff_link_hash_entry
*h
;
2751 if (0 > rel
->r_symndx
)
2754 h
= obj_xcoff_sym_hashes (input_bfd
)[rel
->r_symndx
];
2756 if (h
!= NULL
&& h
->smclas
!= XMC_TD
)
2758 if (h
->toc_section
== NULL
)
2760 (*_bfd_error_handler
)
2761 (_("%s: TOC reloc at 0x%x to symbol `%s' with no TOC entry"),
2762 bfd_get_filename (input_bfd
), rel
->r_vaddr
,
2763 h
->root
.root
.string
);
2764 bfd_set_error (bfd_error_bad_value
);
2768 BFD_ASSERT ((h
->flags
& XCOFF_SET_TOC
) == 0);
2769 val
= (h
->toc_section
->output_section
->vma
2770 + h
->toc_section
->output_offset
);
2773 *relocation
= ((val
- xcoff_data (output_bfd
)->toc
)
2774 - (sym
->n_value
- xcoff_data (input_bfd
)->toc
));
2779 xcoff_reloc_type_ba (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2780 asection
*input_section ATTRIBUTE_UNUSED
,
2781 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2782 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
2783 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2784 struct reloc_howto_struct
*howto
,
2787 bfd_vma
*relocation
,
2788 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2790 howto
->src_mask
&= ~3;
2791 howto
->dst_mask
= howto
->src_mask
;
2793 *relocation
= val
+ addend
;
2799 xcoff_reloc_type_br (bfd
*input_bfd
,
2800 asection
*input_section
,
2801 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2802 struct internal_reloc
*rel
,
2803 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2804 struct reloc_howto_struct
*howto
,
2807 bfd_vma
*relocation
,
2810 struct xcoff_link_hash_entry
*h
;
2811 bfd_vma section_offset
;
2813 if (0 > rel
->r_symndx
)
2816 h
= obj_xcoff_sym_hashes (input_bfd
)[rel
->r_symndx
];
2817 section_offset
= rel
->r_vaddr
- input_section
->vma
;
2819 /* If we see an R_BR or R_RBR reloc which is jumping to global
2820 linkage code, and it is followed by an appropriate cror nop
2821 instruction, we replace the cror with lwz r2,20(r1). This
2822 restores the TOC after the glink code. Contrariwise, if the
2823 call is followed by a lwz r2,20(r1), but the call is not
2824 going to global linkage code, we can replace the load with a
2827 && (bfd_link_hash_defined
== h
->root
.type
2828 || bfd_link_hash_defweak
== h
->root
.type
)
2829 && section_offset
+ 8 <= input_section
->size
)
2834 pnext
= contents
+ section_offset
+ 4;
2835 next
= bfd_get_32 (input_bfd
, pnext
);
2837 /* The _ptrgl function is magic. It is used by the AIX
2838 compiler to call a function through a pointer. */
2839 if (h
->smclas
== XMC_GL
|| strcmp (h
->root
.root
.string
, "._ptrgl") == 0)
2841 if (next
== 0x4def7b82 /* cror 15,15,15 */
2842 || next
== 0x4ffffb82 /* cror 31,31,31 */
2843 || next
== 0x60000000) /* ori r0,r0,0 */
2844 bfd_put_32 (input_bfd
, 0x80410014, pnext
); /* lwz r2,20(r1) */
2849 if (next
== 0x80410014) /* lwz r2,20(r1) */
2850 bfd_put_32 (input_bfd
, 0x60000000, pnext
); /* ori r0,r0,0 */
2853 else if (NULL
!= h
&& bfd_link_hash_undefined
== h
->root
.type
)
2855 /* Normally, this relocation is against a defined symbol. In the
2856 case where this is a partial link and the output section offset
2857 is greater than 2^25, the linker will return an invalid error
2858 message that the relocation has been truncated. Yes it has been
2859 truncated but no it not important. For this case, disable the
2860 overflow checking. */
2862 howto
->complain_on_overflow
= complain_overflow_dont
;
2865 /* The original PC-relative relocation is biased by -r_vaddr, so adding
2866 the value below will give the absolute target address. */
2867 *relocation
= val
+ addend
+ rel
->r_vaddr
;
2869 howto
->src_mask
&= ~3;
2870 howto
->dst_mask
= howto
->src_mask
;
2873 && (h
->root
.type
== bfd_link_hash_defined
2874 || h
->root
.type
== bfd_link_hash_defweak
)
2875 && bfd_is_abs_section (h
->root
.u
.def
.section
)
2876 && section_offset
+ 4 <= input_section
->size
)
2881 /* Turn the relative branch into an absolute one by setting the
2883 ptr
= contents
+ section_offset
;
2884 insn
= bfd_get_32 (input_bfd
, ptr
);
2886 bfd_put_32 (input_bfd
, insn
, ptr
);
2888 /* Make the howto absolute too. */
2889 howto
->pc_relative
= FALSE
;
2890 howto
->complain_on_overflow
= complain_overflow_bitfield
;
2894 /* Use a PC-relative howto and subtract the instruction's address
2895 from the target address we calculated above. */
2896 howto
->pc_relative
= TRUE
;
2897 *relocation
-= (input_section
->output_section
->vma
2898 + input_section
->output_offset
2905 xcoff_reloc_type_crel (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2906 asection
*input_section
,
2907 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2908 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
2909 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2910 struct reloc_howto_struct
*howto
,
2911 bfd_vma val ATTRIBUTE_UNUSED
,
2913 bfd_vma
*relocation
,
2914 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2916 howto
->pc_relative
= TRUE
;
2917 howto
->src_mask
&= ~3;
2918 howto
->dst_mask
= howto
->src_mask
;
2920 /* A PC relative reloc includes the section address. */
2921 addend
+= input_section
->vma
;
2923 *relocation
= val
+ addend
;
2924 *relocation
-= (input_section
->output_section
->vma
2925 + input_section
->output_offset
);
2930 xcoff_complain_overflow_dont_func (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2931 bfd_vma val ATTRIBUTE_UNUSED
,
2932 bfd_vma relocation ATTRIBUTE_UNUSED
,
2933 struct reloc_howto_struct
*
2934 howto ATTRIBUTE_UNUSED
)
2940 xcoff_complain_overflow_bitfield_func (bfd
*input_bfd
,
2943 struct reloc_howto_struct
*howto
)
2945 bfd_vma fieldmask
, signmask
, ss
;
2948 /* Get the values to be added together. For signed and unsigned
2949 relocations, we assume that all values should be truncated to
2950 the size of an address. For bitfields, all the bits matter.
2951 See also bfd_check_overflow. */
2952 fieldmask
= N_ONES (howto
->bitsize
);
2954 b
= val
& howto
->src_mask
;
2956 /* Much like unsigned, except no trimming with addrmask. In
2957 addition, the sum overflows if there is a carry out of
2958 the bfd_vma, i.e., the sum is less than either input
2960 a
>>= howto
->rightshift
;
2961 b
>>= howto
->bitpos
;
2963 /* Bitfields are sometimes used for signed numbers; for
2964 example, a 13-bit field sometimes represents values in
2965 0..8191 and sometimes represents values in -4096..4095.
2966 If the field is signed and a is -4095 (0x1001) and b is
2967 -1 (0x1fff), the sum is -4096 (0x1000), but (0x1001 +
2968 0x1fff is 0x3000). It's not clear how to handle this
2969 everywhere, since there is not way to know how many bits
2970 are significant in the relocation, but the original code
2971 assumed that it was fully sign extended, and we will keep
2973 signmask
= (fieldmask
>> 1) + 1;
2975 if ((a
& ~ fieldmask
) != 0)
2977 /* Some bits out of the field are set. This might not
2978 be a problem: if this is a signed bitfield, it is OK
2979 iff all the high bits are set, including the sign
2980 bit. We'll try setting all but the most significant
2981 bit in the original relocation value: if this is all
2982 ones, we are OK, assuming a signed bitfield. */
2983 ss
= (signmask
<< howto
->rightshift
) - 1;
2984 if ((ss
| relocation
) != ~ (bfd_vma
) 0)
2989 /* We just assume (b & ~ fieldmask) == 0. */
2991 /* We explicitly permit wrap around if this relocation
2992 covers the high bit of an address. The Linux kernel
2993 relies on it, and it is the only way to write assembler
2994 code which can run when loaded at a location 0x80000000
2995 away from the location at which it is linked. */
2996 if (howto
->bitsize
+ howto
->rightshift
2997 == bfd_arch_bits_per_address (input_bfd
))
3001 if (sum
< a
|| (sum
& ~ fieldmask
) != 0)
3003 /* There was a carry out, or the field overflow. Test
3004 for signed operands again. Here is the overflow test
3005 is as for complain_overflow_signed. */
3006 if (((~ (a
^ b
)) & (a
^ sum
)) & signmask
)
3014 xcoff_complain_overflow_signed_func (bfd
*input_bfd
,
3017 struct reloc_howto_struct
*howto
)
3019 bfd_vma addrmask
, fieldmask
, signmask
, ss
;
3022 /* Get the values to be added together. For signed and unsigned
3023 relocations, we assume that all values should be truncated to
3024 the size of an address. For bitfields, all the bits matter.
3025 See also bfd_check_overflow. */
3026 fieldmask
= N_ONES (howto
->bitsize
);
3027 addrmask
= N_ONES (bfd_arch_bits_per_address (input_bfd
)) | fieldmask
;
3029 b
= val
& howto
->src_mask
;
3031 a
= (a
& addrmask
) >> howto
->rightshift
;
3033 /* If any sign bits are set, all sign bits must be set.
3034 That is, A must be a valid negative address after
3036 signmask
= ~ (fieldmask
>> 1);
3038 if (ss
!= 0 && ss
!= ((addrmask
>> howto
->rightshift
) & signmask
))
3041 /* We only need this next bit of code if the sign bit of B
3042 is below the sign bit of A. This would only happen if
3043 SRC_MASK had fewer bits than BITSIZE. Note that if
3044 SRC_MASK has more bits than BITSIZE, we can get into
3045 trouble; we would need to verify that B is in range, as
3046 we do for A above. */
3047 signmask
= ((~ howto
->src_mask
) >> 1) & howto
->src_mask
;
3048 if ((b
& signmask
) != 0)
3050 /* Set all the bits above the sign bit. */
3051 b
-= signmask
<<= 1;
3054 b
= (b
& addrmask
) >> howto
->bitpos
;
3056 /* Now we can do the addition. */
3059 /* See if the result has the correct sign. Bits above the
3060 sign bit are junk now; ignore them. If the sum is
3061 positive, make sure we did not have all negative inputs;
3062 if the sum is negative, make sure we did not have all
3063 positive inputs. The test below looks only at the sign
3064 bits, and it really just
3065 SIGN (A) == SIGN (B) && SIGN (A) != SIGN (SUM)
3067 signmask
= (fieldmask
>> 1) + 1;
3068 if (((~ (a
^ b
)) & (a
^ sum
)) & signmask
)
3075 xcoff_complain_overflow_unsigned_func (bfd
*input_bfd
,
3078 struct reloc_howto_struct
*howto
)
3080 bfd_vma addrmask
, fieldmask
;
3083 /* Get the values to be added together. For signed and unsigned
3084 relocations, we assume that all values should be truncated to
3085 the size of an address. For bitfields, all the bits matter.
3086 See also bfd_check_overflow. */
3087 fieldmask
= N_ONES (howto
->bitsize
);
3088 addrmask
= N_ONES (bfd_arch_bits_per_address (input_bfd
)) | fieldmask
;
3090 b
= val
& howto
->src_mask
;
3092 /* Checking for an unsigned overflow is relatively easy:
3093 trim the addresses and add, and trim the result as well.
3094 Overflow is normally indicated when the result does not
3095 fit in the field. However, we also need to consider the
3096 case when, e.g., fieldmask is 0x7fffffff or smaller, an
3097 input is 0x80000000, and bfd_vma is only 32 bits; then we
3098 will get sum == 0, but there is an overflow, since the
3099 inputs did not fit in the field. Instead of doing a
3100 separate test, we can check for this by or-ing in the
3101 operands when testing for the sum overflowing its final
3103 a
= (a
& addrmask
) >> howto
->rightshift
;
3104 b
= (b
& addrmask
) >> howto
->bitpos
;
3105 sum
= (a
+ b
) & addrmask
;
3106 if ((a
| b
| sum
) & ~ fieldmask
)
3112 /* This is the relocation function for the RS/6000/POWER/PowerPC.
3113 This is currently the only processor which uses XCOFF; I hope that
3116 I took the relocation type definitions from two documents:
3117 the PowerPC AIX Version 4 Application Binary Interface, First
3118 Edition (April 1992), and the PowerOpen ABI, Big-Endian
3119 32-Bit Hardware Implementation (June 30, 1994). Differences
3120 between the documents are noted below.
3122 Unsupported r_type's
3128 These relocs are defined by the PowerPC ABI to be
3129 relative branches which use half of the difference
3130 between the symbol and the program counter. I can't
3131 quite figure out when this is useful. These relocs are
3132 not defined by the PowerOpen ABI.
3137 Simple positive relocation.
3140 Simple negative relocation.
3143 Simple PC relative relocation.
3146 TOC relative relocation. The value in the instruction in
3147 the input file is the offset from the input file TOC to
3148 the desired location. We want the offset from the final
3149 TOC to the desired location. We have:
3154 so we must change insn by on - in.
3157 GL linkage relocation. The value of this relocation
3158 is the address of the entry in the TOC section.
3161 Local object TOC address. I can't figure out the
3162 difference between this and case R_GL.
3165 TOC relative relocation. A TOC relative load instruction
3166 which may be changed to a load address instruction.
3167 FIXME: We don't currently implement this optimization.
3170 TOC relative relocation. This is a TOC relative load
3171 address instruction which may be changed to a load
3172 instruction. FIXME: I don't know if this is the correct
3176 Absolute branch. We don't want to mess with the lower
3177 two bits of the instruction.
3180 The PowerPC ABI defines this as an absolute call which
3181 may be modified to become a relative call. The PowerOpen
3182 ABI does not define this relocation type.
3185 Absolute branch which may be modified to become a
3189 The PowerPC ABI defines this as an absolute branch to a
3190 fixed address which may be modified to an absolute branch
3191 to a symbol. The PowerOpen ABI does not define this
3195 The PowerPC ABI defines this as an absolute branch to a
3196 fixed address which may be modified to a relative branch.
3197 The PowerOpen ABI does not define this relocation type.
3200 Relative branch. We don't want to mess with the lower
3201 two bits of the instruction.
3204 The PowerPC ABI defines this as a relative call which may
3205 be modified to become an absolute call. The PowerOpen
3206 ABI does not define this relocation type.
3209 A relative branch which may be modified to become an
3213 The PowerPC AIX ABI describes this as a load which may be
3214 changed to a load address. The PowerOpen ABI says this
3215 is the same as case R_POS.
3218 The PowerPC AIX ABI describes this as a load address
3219 which may be changed to a load. The PowerOpen ABI says
3220 this is the same as R_POS.
3224 xcoff_ppc_relocate_section (bfd
*output_bfd
,
3225 struct bfd_link_info
*info
,
3227 asection
*input_section
,
3229 struct internal_reloc
*relocs
,
3230 struct internal_syment
*syms
,
3231 asection
**sections
)
3233 struct internal_reloc
*rel
;
3234 struct internal_reloc
*relend
;
3237 relend
= rel
+ input_section
->reloc_count
;
3238 for (; rel
< relend
; rel
++)
3241 struct xcoff_link_hash_entry
*h
;
3242 struct internal_syment
*sym
;
3245 struct reloc_howto_struct howto
;
3247 bfd_vma value_to_relocate
;
3251 /* Relocation type R_REF is a special relocation type which is
3252 merely used to prevent garbage collection from occurring for
3253 the csect including the symbol which it references. */
3254 if (rel
->r_type
== R_REF
)
3258 howto
.type
= rel
->r_type
;
3259 howto
.rightshift
= 0;
3260 howto
.bitsize
= (rel
->r_size
& 0x1f) + 1;
3261 howto
.size
= howto
.bitsize
> 16 ? 2 : 1;
3262 howto
.pc_relative
= FALSE
;
3264 howto
.complain_on_overflow
= (rel
->r_size
& 0x80
3265 ? complain_overflow_signed
3266 : complain_overflow_bitfield
);
3267 howto
.special_function
= NULL
;
3268 howto
.name
= "internal";
3269 howto
.partial_inplace
= TRUE
;
3270 howto
.src_mask
= howto
.dst_mask
= N_ONES (howto
.bitsize
);
3271 howto
.pcrel_offset
= FALSE
;
3278 symndx
= rel
->r_symndx
;
3284 h
= obj_xcoff_sym_hashes (input_bfd
)[symndx
];
3285 sym
= syms
+ symndx
;
3286 addend
= - sym
->n_value
;
3290 sec
= sections
[symndx
];
3291 /* Hack to make sure we use the right TOC anchor value
3292 if this reloc is against the TOC anchor. */
3293 if (sec
->name
[3] == '0'
3294 && strcmp (sec
->name
, ".tc0") == 0)
3295 val
= xcoff_data (output_bfd
)->toc
;
3297 val
= (sec
->output_section
->vma
3298 + sec
->output_offset
3304 if (info
->unresolved_syms_in_objects
!= RM_IGNORE
3305 && (h
->flags
& XCOFF_WAS_UNDEFINED
) != 0)
3307 if (! ((*info
->callbacks
->undefined_symbol
)
3308 (info
, h
->root
.root
.string
,
3309 input_bfd
, input_section
,
3310 rel
->r_vaddr
- input_section
->vma
,
3311 (info
->unresolved_syms_in_objects
3312 == RM_GENERATE_ERROR
))))
3315 if (h
->root
.type
== bfd_link_hash_defined
3316 || h
->root
.type
== bfd_link_hash_defweak
)
3318 sec
= h
->root
.u
.def
.section
;
3319 val
= (h
->root
.u
.def
.value
3320 + sec
->output_section
->vma
3321 + sec
->output_offset
);
3323 else if (h
->root
.type
== bfd_link_hash_common
)
3325 sec
= h
->root
.u
.c
.p
->section
;
3326 val
= (sec
->output_section
->vma
3327 + sec
->output_offset
);
3332 BFD_ASSERT (info
->relocatable
3333 || (info
->static_link
3334 && (h
->flags
& XCOFF_WAS_UNDEFINED
) != 0)
3335 || (h
->flags
& XCOFF_DEF_DYNAMIC
) != 0
3336 || (h
->flags
& XCOFF_IMPORT
) != 0);
3341 if (rel
->r_type
>= XCOFF_MAX_CALCULATE_RELOCATION
3342 || !((*xcoff_calculate_relocation
[rel
->r_type
])
3343 (input_bfd
, input_section
, output_bfd
, rel
, sym
, &howto
, val
,
3344 addend
, &relocation
, contents
)))
3348 address
= rel
->r_vaddr
- input_section
->vma
;
3349 location
= contents
+ address
;
3351 if (address
> input_section
->size
)
3354 /* Get the value we are going to relocate. */
3355 if (1 == howto
.size
)
3356 value_to_relocate
= bfd_get_16 (input_bfd
, location
);
3358 value_to_relocate
= bfd_get_32 (input_bfd
, location
);
3362 FIXME: We may drop bits during the addition
3363 which we don't check for. We must either check at every single
3364 operation, which would be tedious, or we must do the computations
3365 in a type larger than bfd_vma, which would be inefficient. */
3367 if ((unsigned int) howto
.complain_on_overflow
3368 >= XCOFF_MAX_COMPLAIN_OVERFLOW
)
3371 if (((*xcoff_complain_overflow
[howto
.complain_on_overflow
])
3372 (input_bfd
, value_to_relocate
, relocation
, &howto
)))
3375 char buf
[SYMNMLEN
+ 1];
3376 char reloc_type_name
[10];
3388 name
= _bfd_coff_internal_syment_name (input_bfd
, sym
, buf
);
3392 sprintf (reloc_type_name
, "0x%02x", rel
->r_type
);
3394 if (! ((*info
->callbacks
->reloc_overflow
)
3395 (info
, (h
? &h
->root
: NULL
), name
, reloc_type_name
,
3396 (bfd_vma
) 0, input_bfd
, input_section
,
3397 rel
->r_vaddr
- input_section
->vma
)))
3401 /* Add RELOCATION to the right bits of VALUE_TO_RELOCATE. */
3402 value_to_relocate
= ((value_to_relocate
& ~howto
.dst_mask
)
3403 | (((value_to_relocate
& howto
.src_mask
)
3404 + relocation
) & howto
.dst_mask
));
3406 /* Put the value back in the object file. */
3407 if (1 == howto
.size
)
3408 bfd_put_16 (input_bfd
, value_to_relocate
, location
);
3410 bfd_put_32 (input_bfd
, value_to_relocate
, location
);
3417 _bfd_xcoff_put_ldsymbol_name (bfd
*abfd ATTRIBUTE_UNUSED
,
3418 struct xcoff_loader_info
*ldinfo
,
3419 struct internal_ldsym
*ldsym
,
3423 len
= strlen (name
);
3425 if (len
<= SYMNMLEN
)
3426 strncpy (ldsym
->_l
._l_name
, name
, SYMNMLEN
);
3429 if (ldinfo
->string_size
+ len
+ 3 > ldinfo
->string_alc
)
3431 bfd_size_type newalc
;
3434 newalc
= ldinfo
->string_alc
* 2;
3437 while (ldinfo
->string_size
+ len
+ 3 > newalc
)
3440 newstrings
= bfd_realloc (ldinfo
->strings
, newalc
);
3441 if (newstrings
== NULL
)
3443 ldinfo
->failed
= TRUE
;
3446 ldinfo
->string_alc
= newalc
;
3447 ldinfo
->strings
= newstrings
;
3450 bfd_put_16 (ldinfo
->output_bfd
, (bfd_vma
) (len
+ 1),
3451 ldinfo
->strings
+ ldinfo
->string_size
);
3452 strcpy (ldinfo
->strings
+ ldinfo
->string_size
+ 2, name
);
3453 ldsym
->_l
._l_l
._l_zeroes
= 0;
3454 ldsym
->_l
._l_l
._l_offset
= ldinfo
->string_size
+ 2;
3455 ldinfo
->string_size
+= len
+ 3;
3462 _bfd_xcoff_put_symbol_name (bfd
*abfd
, struct bfd_strtab_hash
*strtab
,
3463 struct internal_syment
*sym
,
3466 if (strlen (name
) <= SYMNMLEN
)
3468 strncpy (sym
->_n
._n_name
, name
, SYMNMLEN
);
3476 if ((abfd
->flags
& BFD_TRADITIONAL_FORMAT
) != 0)
3478 indx
= _bfd_stringtab_add (strtab
, name
, hash
, FALSE
);
3479 if (indx
== (bfd_size_type
) -1)
3481 sym
->_n
._n_n
._n_zeroes
= 0;
3482 sym
->_n
._n_n
._n_offset
= STRING_SIZE_SIZE
+ indx
;
3488 xcoff_create_csect_from_smclas (bfd
*abfd
,
3489 union internal_auxent
*aux
,
3490 const char *symbol_name
)
3492 asection
*return_value
= NULL
;
3494 /* .sv64 = x_smclas == 17
3495 This is an invalid csect for 32 bit apps. */
3496 static const char *names
[19] =
3498 ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo",
3499 ".sv", ".bs", ".ds", ".uc", ".ti", ".tb", NULL
, ".tc0",
3500 ".td", NULL
, ".sv3264"
3503 if ((19 >= aux
->x_csect
.x_smclas
)
3504 && (NULL
!= names
[aux
->x_csect
.x_smclas
]))
3506 return_value
= bfd_make_section_anyway
3507 (abfd
, names
[aux
->x_csect
.x_smclas
]);
3511 (*_bfd_error_handler
)
3512 (_("%B: symbol `%s' has unrecognized smclas %d"),
3513 abfd
, symbol_name
, aux
->x_csect
.x_smclas
);
3514 bfd_set_error (bfd_error_bad_value
);
3517 return return_value
;
3521 xcoff_is_lineno_count_overflow (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_vma value
)
3523 if (0xffff <= value
)
3530 xcoff_is_reloc_count_overflow (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_vma value
)
3532 if (0xffff <= value
)
3539 xcoff_loader_symbol_offset (bfd
*abfd
,
3540 struct internal_ldhdr
*ldhdr ATTRIBUTE_UNUSED
)
3542 return bfd_xcoff_ldhdrsz (abfd
);
3546 xcoff_loader_reloc_offset (bfd
*abfd
, struct internal_ldhdr
*ldhdr
)
3548 return bfd_xcoff_ldhdrsz (abfd
) + ldhdr
->l_nsyms
* bfd_xcoff_ldsymsz (abfd
);
3552 xcoff_generate_rtinit (bfd
*abfd
, const char *init
, const char *fini
,
3555 bfd_byte filehdr_ext
[FILHSZ
];
3556 bfd_byte scnhdr_ext
[SCNHSZ
];
3557 bfd_byte syment_ext
[SYMESZ
* 10];
3558 bfd_byte reloc_ext
[RELSZ
* 3];
3559 bfd_byte
*data_buffer
;
3560 bfd_size_type data_buffer_size
;
3561 bfd_byte
*string_table
= NULL
, *st_tmp
= NULL
;
3562 bfd_size_type string_table_size
;
3564 size_t initsz
, finisz
;
3565 struct internal_filehdr filehdr
;
3566 struct internal_scnhdr scnhdr
;
3567 struct internal_syment syment
;
3568 union internal_auxent auxent
;
3569 struct internal_reloc reloc
;
3571 char *data_name
= ".data";
3572 char *rtinit_name
= "__rtinit";
3573 char *rtld_name
= "__rtld";
3575 if (! bfd_xcoff_rtinit_size (abfd
))
3578 initsz
= (init
== NULL
? 0 : 1 + strlen (init
));
3579 finisz
= (fini
== NULL
? 0 : 1 + strlen (fini
));
3582 memset (filehdr_ext
, 0, FILHSZ
);
3583 memset (&filehdr
, 0, sizeof (struct internal_filehdr
));
3584 filehdr
.f_magic
= bfd_xcoff_magic_number (abfd
);
3585 filehdr
.f_nscns
= 1;
3586 filehdr
.f_timdat
= 0;
3587 filehdr
.f_nsyms
= 0; /* at least 6, no more than 10 */
3588 filehdr
.f_symptr
= 0; /* set below */
3589 filehdr
.f_opthdr
= 0;
3590 filehdr
.f_flags
= 0;
3592 /* section header */
3593 memset (scnhdr_ext
, 0, SCNHSZ
);
3594 memset (&scnhdr
, 0, sizeof (struct internal_scnhdr
));
3595 memcpy (scnhdr
.s_name
, data_name
, strlen (data_name
));
3598 scnhdr
.s_size
= 0; /* set below */
3599 scnhdr
.s_scnptr
= FILHSZ
+ SCNHSZ
;
3600 scnhdr
.s_relptr
= 0; /* set below */
3601 scnhdr
.s_lnnoptr
= 0;
3602 scnhdr
.s_nreloc
= 0; /* either 1 or 2 */
3604 scnhdr
.s_flags
= STYP_DATA
;
3607 0x0000 0x00000000 : rtl
3608 0x0004 0x00000010 : offset to init, or 0
3609 0x0008 0x00000028 : offset to fini, or 0
3610 0x000C 0x0000000C : size of descriptor
3611 0x0010 0x00000000 : init, needs a reloc
3612 0x0014 0x00000040 : offset to init name
3613 0x0018 0x00000000 : flags, padded to a word
3614 0x001C 0x00000000 : empty init
3617 0x0028 0x00000000 : fini, needs a reloc
3618 0x002C 0x00000??? : offset to fini name
3619 0x0030 0x00000000 : flags, padded to a word
3620 0x0034 0x00000000 : empty fini
3624 0x0040 + initsz fini name */
3626 data_buffer_size
= 0x0040 + initsz
+ finisz
;
3627 data_buffer_size
= (data_buffer_size
+ 7) &~ (bfd_size_type
) 7;
3629 data_buffer
= (bfd_byte
*) bfd_zmalloc (data_buffer_size
);
3630 if (data_buffer
== NULL
)
3636 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x04]);
3638 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x14]);
3639 memcpy (&data_buffer
[val
], init
, initsz
);
3645 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x08]);
3646 val
= 0x40 + initsz
;
3647 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x2C]);
3648 memcpy (&data_buffer
[val
], fini
, finisz
);
3652 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x0C]);
3654 scnhdr
.s_size
= data_buffer_size
;
3657 string_table_size
= 0;
3659 string_table_size
+= initsz
;
3661 string_table_size
+= finisz
;
3662 if (string_table_size
)
3664 string_table_size
+= 4;
3665 string_table
= (bfd_byte
*) bfd_zmalloc (string_table_size
);
3666 if (string_table
== NULL
)
3669 val
= string_table_size
;
3670 bfd_h_put_32 (abfd
, val
, &string_table
[0]);
3671 st_tmp
= string_table
+ 4;
3680 memset (syment_ext
, 0, 10 * SYMESZ
);
3681 memset (reloc_ext
, 0, 3 * RELSZ
);
3684 memset (&syment
, 0, sizeof (struct internal_syment
));
3685 memset (&auxent
, 0, sizeof (union internal_auxent
));
3686 memcpy (syment
._n
._n_name
, data_name
, strlen (data_name
));
3688 syment
.n_sclass
= C_HIDEXT
;
3689 syment
.n_numaux
= 1;
3690 auxent
.x_csect
.x_scnlen
.l
= data_buffer_size
;
3691 auxent
.x_csect
.x_smtyp
= 3 << 3 | XTY_SD
;
3692 auxent
.x_csect
.x_smclas
= XMC_RW
;
3693 bfd_coff_swap_sym_out (abfd
, &syment
,
3694 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3695 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3697 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3698 filehdr
.f_nsyms
+= 2;
3701 memset (&syment
, 0, sizeof (struct internal_syment
));
3702 memset (&auxent
, 0, sizeof (union internal_auxent
));
3703 memcpy (syment
._n
._n_name
, rtinit_name
, strlen (rtinit_name
));
3705 syment
.n_sclass
= C_EXT
;
3706 syment
.n_numaux
= 1;
3707 auxent
.x_csect
.x_smtyp
= XTY_LD
;
3708 auxent
.x_csect
.x_smclas
= XMC_RW
;
3709 bfd_coff_swap_sym_out (abfd
, &syment
,
3710 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3711 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3713 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3714 filehdr
.f_nsyms
+= 2;
3719 memset (&syment
, 0, sizeof (struct internal_syment
));
3720 memset (&auxent
, 0, sizeof (union internal_auxent
));
3724 syment
._n
._n_n
._n_offset
= st_tmp
- string_table
;
3725 memcpy (st_tmp
, init
, initsz
);
3729 memcpy (syment
._n
._n_name
, init
, initsz
- 1);
3731 syment
.n_sclass
= C_EXT
;
3732 syment
.n_numaux
= 1;
3733 bfd_coff_swap_sym_out (abfd
, &syment
,
3734 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3735 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3737 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3740 memset (&reloc
, 0, sizeof (struct internal_reloc
));
3741 reloc
.r_vaddr
= 0x0010;
3742 reloc
.r_symndx
= filehdr
.f_nsyms
;
3743 reloc
.r_type
= R_POS
;
3745 bfd_coff_swap_reloc_out (abfd
, &reloc
, &reloc_ext
[0]);
3747 filehdr
.f_nsyms
+= 2;
3748 scnhdr
.s_nreloc
+= 1;
3754 memset (&syment
, 0, sizeof (struct internal_syment
));
3755 memset (&auxent
, 0, sizeof (union internal_auxent
));
3759 syment
._n
._n_n
._n_offset
= st_tmp
- string_table
;
3760 memcpy (st_tmp
, fini
, finisz
);
3764 memcpy (syment
._n
._n_name
, fini
, finisz
- 1);
3766 syment
.n_sclass
= C_EXT
;
3767 syment
.n_numaux
= 1;
3768 bfd_coff_swap_sym_out (abfd
, &syment
,
3769 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3770 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3772 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3775 memset (&reloc
, 0, sizeof (struct internal_reloc
));
3776 reloc
.r_vaddr
= 0x0028;
3777 reloc
.r_symndx
= filehdr
.f_nsyms
;
3778 reloc
.r_type
= R_POS
;
3780 bfd_coff_swap_reloc_out (abfd
, &reloc
,
3781 &reloc_ext
[scnhdr
.s_nreloc
* RELSZ
]);
3783 filehdr
.f_nsyms
+= 2;
3784 scnhdr
.s_nreloc
+= 1;
3789 memset (&syment
, 0, sizeof (struct internal_syment
));
3790 memset (&auxent
, 0, sizeof (union internal_auxent
));
3791 memcpy (syment
._n
._n_name
, rtld_name
, strlen (rtld_name
));
3792 syment
.n_sclass
= C_EXT
;
3793 syment
.n_numaux
= 1;
3794 bfd_coff_swap_sym_out (abfd
, &syment
,
3795 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3796 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3798 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3801 memset (&reloc
, 0, sizeof (struct internal_reloc
));
3802 reloc
.r_vaddr
= 0x0000;
3803 reloc
.r_symndx
= filehdr
.f_nsyms
;
3804 reloc
.r_type
= R_POS
;
3806 bfd_coff_swap_reloc_out (abfd
, &reloc
,
3807 &reloc_ext
[scnhdr
.s_nreloc
* RELSZ
]);
3809 filehdr
.f_nsyms
+= 2;
3810 scnhdr
.s_nreloc
+= 1;
3813 scnhdr
.s_relptr
= scnhdr
.s_scnptr
+ data_buffer_size
;
3814 filehdr
.f_symptr
= scnhdr
.s_relptr
+ scnhdr
.s_nreloc
* RELSZ
;
3816 bfd_coff_swap_filehdr_out (abfd
, &filehdr
, filehdr_ext
);
3817 bfd_bwrite (filehdr_ext
, FILHSZ
, abfd
);
3818 bfd_coff_swap_scnhdr_out (abfd
, &scnhdr
, scnhdr_ext
);
3819 bfd_bwrite (scnhdr_ext
, SCNHSZ
, abfd
);
3820 bfd_bwrite (data_buffer
, data_buffer_size
, abfd
);
3821 bfd_bwrite (reloc_ext
, scnhdr
.s_nreloc
* RELSZ
, abfd
);
3822 bfd_bwrite (syment_ext
, filehdr
.f_nsyms
* SYMESZ
, abfd
);
3823 bfd_bwrite (string_table
, string_table_size
, abfd
);
3832 static reloc_howto_type xcoff_dynamic_reloc
=
3833 HOWTO (0, /* type */
3835 2, /* size (0 = byte, 1 = short, 2 = long) */
3837 FALSE
, /* pc_relative */
3839 complain_overflow_bitfield
, /* complain_on_overflow */
3840 0, /* special_function */
3842 TRUE
, /* partial_inplace */
3843 0xffffffff, /* src_mask */
3844 0xffffffff, /* dst_mask */
3845 FALSE
); /* pcrel_offset */
3849 The first word of global linkage code must be modified by filling in
3850 the correct TOC offset. */
3852 static unsigned long xcoff_glink_code
[9] =
3854 0x81820000, /* lwz r12,0(r2) */
3855 0x90410014, /* stw r2,20(r1) */
3856 0x800c0000, /* lwz r0,0(r12) */
3857 0x804c0004, /* lwz r2,4(r12) */
3858 0x7c0903a6, /* mtctr r0 */
3859 0x4e800420, /* bctr */
3860 0x00000000, /* start of traceback table */
3861 0x000c8000, /* traceback table */
3862 0x00000000, /* traceback table */
3865 /* Table to convert DWARF flags to section names. */
3867 const struct xcoff_dwsect_name xcoff_dwsect_names
[] = {
3868 { SSUBTYP_DWINFO
, ".dwinfo", TRUE
},
3869 { SSUBTYP_DWLINE
, ".dwline", TRUE
},
3870 { SSUBTYP_DWPBNMS
, ".dwpbnms", TRUE
},
3871 { SSUBTYP_DWPBTYP
, ".dwpbtyp", TRUE
},
3872 { SSUBTYP_DWARNGE
, ".dwarnge", TRUE
},
3873 { SSUBTYP_DWABREV
, ".dwabrev", FALSE
},
3874 { SSUBTYP_DWSTR
, ".dwstr", TRUE
},
3875 { SSUBTYP_DWRNGES
, ".dwrnges", TRUE
}
3878 static const struct xcoff_backend_data_rec bfd_xcoff_backend_data
=
3880 { /* COFF backend, defined in libcoff.h. */
3881 _bfd_xcoff_swap_aux_in
,
3882 _bfd_xcoff_swap_sym_in
,
3883 coff_swap_lineno_in
,
3884 _bfd_xcoff_swap_aux_out
,
3885 _bfd_xcoff_swap_sym_out
,
3886 coff_swap_lineno_out
,
3887 xcoff_swap_reloc_out
,
3888 coff_swap_filehdr_out
,
3889 coff_swap_aouthdr_out
,
3890 coff_swap_scnhdr_out
,
3899 TRUE
, /* _bfd_coff_long_filenames */
3900 XCOFF_NO_LONG_SECTION_NAMES
, /* _bfd_coff_long_section_names */
3901 3, /* _bfd_coff_default_section_alignment_power */
3902 FALSE
, /* _bfd_coff_force_symnames_in_strings */
3903 2, /* _bfd_coff_debug_string_prefix_length */
3904 coff_swap_filehdr_in
,
3905 coff_swap_aouthdr_in
,
3906 coff_swap_scnhdr_in
,
3907 xcoff_swap_reloc_in
,
3908 coff_bad_format_hook
,
3909 coff_set_arch_mach_hook
,
3912 coff_set_alignment_hook
,
3913 coff_slurp_symbol_table
,
3914 symname_in_debug_hook
,
3915 coff_pointerize_aux_hook
,
3917 dummy_reloc16_extra_cases
,
3918 dummy_reloc16_estimate
,
3919 NULL
, /* bfd_coff_sym_is_global */
3920 coff_compute_section_file_positions
,
3921 NULL
, /* _bfd_coff_start_final_link */
3922 xcoff_ppc_relocate_section
,
3923 coff_rtype_to_howto
,
3924 NULL
, /* _bfd_coff_adjust_symndx */
3925 _bfd_generic_link_add_one_symbol
,
3926 coff_link_output_has_begun
,
3927 coff_final_link_postscript
,
3928 NULL
/* print_pdata. */
3931 0x01DF, /* magic number */
3935 /* Function pointers to xcoff specific swap routines. */
3936 xcoff_swap_ldhdr_in
,
3937 xcoff_swap_ldhdr_out
,
3938 xcoff_swap_ldsym_in
,
3939 xcoff_swap_ldsym_out
,
3940 xcoff_swap_ldrel_in
,
3941 xcoff_swap_ldrel_out
,
3947 12, /* _xcoff_function_descriptor_size */
3951 1, /* _xcoff_ldhdr_version */
3953 _bfd_xcoff_put_symbol_name
,
3954 _bfd_xcoff_put_ldsymbol_name
,
3955 &xcoff_dynamic_reloc
,
3956 xcoff_create_csect_from_smclas
,
3958 /* Lineno and reloc count overflow. */
3959 xcoff_is_lineno_count_overflow
,
3960 xcoff_is_reloc_count_overflow
,
3962 xcoff_loader_symbol_offset
,
3963 xcoff_loader_reloc_offset
,
3966 &xcoff_glink_code
[0],
3967 36, /* _xcoff_glink_size */
3970 64, /* _xcoff_rtinit_size */
3971 xcoff_generate_rtinit
,
3974 /* The transfer vector that leads the outside world to all of the above. */
3975 const bfd_target rs6000coff_vec
=
3978 bfd_target_xcoff_flavour
,
3979 BFD_ENDIAN_BIG
, /* data byte order is big */
3980 BFD_ENDIAN_BIG
, /* header byte order is big */
3982 (HAS_RELOC
| EXEC_P
| HAS_LINENO
| HAS_DEBUG
| DYNAMIC
3983 | HAS_SYMS
| HAS_LOCALS
| WP_TEXT
),
3985 SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_CODE
| SEC_DATA
,
3986 0, /* leading char */
3987 '/', /* ar_pad_char */
3988 15, /* ar_max_namelen */
3989 0, /* match priority. */
4013 { /* bfd_check_format */
4016 _bfd_xcoff_archive_p
,
4020 { /* bfd_set_format */
4023 _bfd_generic_mkarchive
,
4027 {/* bfd_write_contents */
4029 coff_write_object_contents
,
4030 _bfd_xcoff_write_archive_contents
,
4037 coff_new_section_hook
,
4038 _bfd_generic_get_section_contents
,
4039 _bfd_generic_get_section_contents_in_window
,
4042 _bfd_xcoff_copy_private_bfd_data
,
4043 _bfd_generic_bfd_merge_private_bfd_data
,
4044 _bfd_generic_init_private_section_data
,
4045 _bfd_generic_bfd_copy_private_section_data
,
4046 _bfd_generic_bfd_copy_private_symbol_data
,
4047 _bfd_generic_bfd_copy_private_header_data
,
4048 _bfd_generic_bfd_set_private_flags
,
4049 _bfd_generic_bfd_print_private_bfd_data
,
4052 BFD_JUMP_TABLE_CORE (coff
),
4055 _bfd_xcoff_slurp_armap
,
4056 _bfd_noarchive_slurp_extended_name_table
,
4057 _bfd_noarchive_construct_extended_name_table
,
4058 bfd_dont_truncate_arname
,
4059 _bfd_xcoff_write_armap
,
4060 _bfd_xcoff_read_ar_hdr
,
4061 _bfd_generic_write_ar_hdr
,
4062 _bfd_xcoff_openr_next_archived_file
,
4063 _bfd_generic_get_elt_at_index
,
4064 _bfd_xcoff_stat_arch_elt
,
4068 coff_get_symtab_upper_bound
,
4069 coff_canonicalize_symtab
,
4070 coff_make_empty_symbol
,
4072 coff_get_symbol_info
,
4073 _bfd_xcoff_is_local_label_name
,
4074 coff_bfd_is_target_special_symbol
,
4076 coff_find_nearest_line
,
4077 _bfd_generic_find_line
,
4078 coff_find_inliner_info
,
4079 coff_bfd_make_debug_symbol
,
4080 _bfd_generic_read_minisymbols
,
4081 _bfd_generic_minisymbol_to_symbol
,
4084 coff_get_reloc_upper_bound
,
4085 coff_canonicalize_reloc
,
4086 _bfd_xcoff_reloc_type_lookup
,
4087 _bfd_xcoff_reloc_name_lookup
,
4091 coff_set_section_contents
,
4094 _bfd_xcoff_sizeof_headers
,
4095 bfd_generic_get_relocated_section_contents
,
4096 bfd_generic_relax_section
,
4097 _bfd_xcoff_bfd_link_hash_table_create
,
4098 _bfd_generic_link_hash_table_free
,
4099 _bfd_xcoff_bfd_link_add_symbols
,
4100 _bfd_generic_link_just_syms
,
4101 _bfd_generic_copy_link_hash_symbol_type
,
4102 _bfd_xcoff_bfd_final_link
,
4103 _bfd_generic_link_split_section
,
4104 bfd_generic_gc_sections
,
4105 bfd_generic_lookup_section_flags
,
4106 bfd_generic_merge_sections
,
4107 bfd_generic_is_group_section
,
4108 bfd_generic_discard_group
,
4109 _bfd_generic_section_already_linked
,
4110 _bfd_xcoff_define_common_symbol
,
4113 _bfd_xcoff_get_dynamic_symtab_upper_bound
,
4114 _bfd_xcoff_canonicalize_dynamic_symtab
,
4115 _bfd_nodynamic_get_synthetic_symtab
,
4116 _bfd_xcoff_get_dynamic_reloc_upper_bound
,
4117 _bfd_xcoff_canonicalize_dynamic_reloc
,
4119 /* Opposite endian version, none exists */
4122 (void *) &bfd_xcoff_backend_data
,
4125 /* xcoff-powermac target
4127 Only difference between this target and the rs6000 target is the
4128 the default architecture and machine type used in coffcode.h
4130 PowerPC Macs use the same magic numbers as RS/6000
4131 (because that's how they were bootstrapped originally),
4132 but they are always PowerPC architecture. */
4133 static const struct xcoff_backend_data_rec bfd_pmac_xcoff_backend_data
=
4135 { /* COFF backend, defined in libcoff.h. */
4136 _bfd_xcoff_swap_aux_in
,
4137 _bfd_xcoff_swap_sym_in
,
4138 coff_swap_lineno_in
,
4139 _bfd_xcoff_swap_aux_out
,
4140 _bfd_xcoff_swap_sym_out
,
4141 coff_swap_lineno_out
,
4142 xcoff_swap_reloc_out
,
4143 coff_swap_filehdr_out
,
4144 coff_swap_aouthdr_out
,
4145 coff_swap_scnhdr_out
,
4154 TRUE
, /* _bfd_coff_long_filenames */
4155 XCOFF_NO_LONG_SECTION_NAMES
, /* _bfd_coff_long_section_names */
4156 3, /* _bfd_coff_default_section_alignment_power */
4157 FALSE
, /* _bfd_coff_force_symnames_in_strings */
4158 2, /* _bfd_coff_debug_string_prefix_length */
4159 coff_swap_filehdr_in
,
4160 coff_swap_aouthdr_in
,
4161 coff_swap_scnhdr_in
,
4162 xcoff_swap_reloc_in
,
4163 coff_bad_format_hook
,
4164 coff_set_arch_mach_hook
,
4167 coff_set_alignment_hook
,
4168 coff_slurp_symbol_table
,
4169 symname_in_debug_hook
,
4170 coff_pointerize_aux_hook
,
4172 dummy_reloc16_extra_cases
,
4173 dummy_reloc16_estimate
,
4174 NULL
, /* bfd_coff_sym_is_global */
4175 coff_compute_section_file_positions
,
4176 NULL
, /* _bfd_coff_start_final_link */
4177 xcoff_ppc_relocate_section
,
4178 coff_rtype_to_howto
,
4179 NULL
, /* _bfd_coff_adjust_symndx */
4180 _bfd_generic_link_add_one_symbol
,
4181 coff_link_output_has_begun
,
4182 coff_final_link_postscript
,
4183 NULL
/* print_pdata. */
4186 0x01DF, /* magic number */
4190 /* Function pointers to xcoff specific swap routines. */
4191 xcoff_swap_ldhdr_in
,
4192 xcoff_swap_ldhdr_out
,
4193 xcoff_swap_ldsym_in
,
4194 xcoff_swap_ldsym_out
,
4195 xcoff_swap_ldrel_in
,
4196 xcoff_swap_ldrel_out
,
4202 12, /* _xcoff_function_descriptor_size */
4206 1, /* _xcoff_ldhdr_version */
4208 _bfd_xcoff_put_symbol_name
,
4209 _bfd_xcoff_put_ldsymbol_name
,
4210 &xcoff_dynamic_reloc
,
4211 xcoff_create_csect_from_smclas
,
4213 /* Lineno and reloc count overflow. */
4214 xcoff_is_lineno_count_overflow
,
4215 xcoff_is_reloc_count_overflow
,
4217 xcoff_loader_symbol_offset
,
4218 xcoff_loader_reloc_offset
,
4221 &xcoff_glink_code
[0],
4222 36, /* _xcoff_glink_size */
4225 0, /* _xcoff_rtinit_size */
4226 xcoff_generate_rtinit
,
4229 /* The transfer vector that leads the outside world to all of the above. */
4230 const bfd_target pmac_xcoff_vec
=
4233 bfd_target_xcoff_flavour
,
4234 BFD_ENDIAN_BIG
, /* data byte order is big */
4235 BFD_ENDIAN_BIG
, /* header byte order is big */
4237 (HAS_RELOC
| EXEC_P
| HAS_LINENO
| HAS_DEBUG
| DYNAMIC
4238 | HAS_SYMS
| HAS_LOCALS
| WP_TEXT
),
4240 SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_CODE
| SEC_DATA
,
4241 0, /* leading char */
4242 '/', /* ar_pad_char */
4243 15, /* ar_max_namelen */
4244 0, /* match priority. */
4268 { /* bfd_check_format */
4271 _bfd_xcoff_archive_p
,
4275 { /* bfd_set_format */
4278 _bfd_generic_mkarchive
,
4282 {/* bfd_write_contents */
4284 coff_write_object_contents
,
4285 _bfd_xcoff_write_archive_contents
,
4292 coff_new_section_hook
,
4293 _bfd_generic_get_section_contents
,
4294 _bfd_generic_get_section_contents_in_window
,
4297 _bfd_xcoff_copy_private_bfd_data
,
4298 _bfd_generic_bfd_merge_private_bfd_data
,
4299 _bfd_generic_init_private_section_data
,
4300 _bfd_generic_bfd_copy_private_section_data
,
4301 _bfd_generic_bfd_copy_private_symbol_data
,
4302 _bfd_generic_bfd_copy_private_header_data
,
4303 _bfd_generic_bfd_set_private_flags
,
4304 _bfd_generic_bfd_print_private_bfd_data
,
4307 BFD_JUMP_TABLE_CORE (coff
),
4310 _bfd_xcoff_slurp_armap
,
4311 _bfd_noarchive_slurp_extended_name_table
,
4312 _bfd_noarchive_construct_extended_name_table
,
4313 bfd_dont_truncate_arname
,
4314 _bfd_xcoff_write_armap
,
4315 _bfd_xcoff_read_ar_hdr
,
4316 _bfd_generic_write_ar_hdr
,
4317 _bfd_xcoff_openr_next_archived_file
,
4318 _bfd_generic_get_elt_at_index
,
4319 _bfd_xcoff_stat_arch_elt
,
4323 coff_get_symtab_upper_bound
,
4324 coff_canonicalize_symtab
,
4325 coff_make_empty_symbol
,
4327 coff_get_symbol_info
,
4328 _bfd_xcoff_is_local_label_name
,
4329 coff_bfd_is_target_special_symbol
,
4331 coff_find_nearest_line
,
4332 _bfd_generic_find_line
,
4333 coff_find_inliner_info
,
4334 coff_bfd_make_debug_symbol
,
4335 _bfd_generic_read_minisymbols
,
4336 _bfd_generic_minisymbol_to_symbol
,
4339 coff_get_reloc_upper_bound
,
4340 coff_canonicalize_reloc
,
4341 _bfd_xcoff_reloc_type_lookup
,
4342 _bfd_xcoff_reloc_name_lookup
,
4346 coff_set_section_contents
,
4349 _bfd_xcoff_sizeof_headers
,
4350 bfd_generic_get_relocated_section_contents
,
4351 bfd_generic_relax_section
,
4352 _bfd_xcoff_bfd_link_hash_table_create
,
4353 _bfd_generic_link_hash_table_free
,
4354 _bfd_xcoff_bfd_link_add_symbols
,
4355 _bfd_generic_link_just_syms
,
4356 _bfd_generic_copy_link_hash_symbol_type
,
4357 _bfd_xcoff_bfd_final_link
,
4358 _bfd_generic_link_split_section
,
4359 bfd_generic_gc_sections
,
4360 bfd_generic_lookup_section_flags
,
4361 bfd_generic_merge_sections
,
4362 bfd_generic_is_group_section
,
4363 bfd_generic_discard_group
,
4364 _bfd_generic_section_already_linked
,
4365 _bfd_xcoff_define_common_symbol
,
4368 _bfd_xcoff_get_dynamic_symtab_upper_bound
,
4369 _bfd_xcoff_canonicalize_dynamic_symtab
,
4370 _bfd_nodynamic_get_synthetic_symtab
,
4371 _bfd_xcoff_get_dynamic_reloc_upper_bound
,
4372 _bfd_xcoff_canonicalize_dynamic_reloc
,
4374 /* Opposite endian version, none exists */
4377 (void *) &bfd_pmac_xcoff_backend_data
,