1 /* BFD back-end for IBM RS/6000 "XCOFF" files.
2 Copyright (C) 1990-2023 Free Software Foundation, Inc.
3 Written by Metin G. Ozisik, Mimi Phuong-Thao Vo, and John Gilmore.
4 Archive support from Damon A. Permezel.
5 Contributed by IBM Corporation and Cygnus Support.
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 MA 02110-1301, USA. */
25 #include "libiberty.h"
29 #include "coff/internal.h"
30 #include "coff/xcoff.h"
31 #include "coff/rs6000.h"
35 extern bool _bfd_xcoff_mkobject (bfd
*);
36 extern bool _bfd_xcoff_copy_private_bfd_data (bfd
*, bfd
*);
37 extern bool _bfd_xcoff_is_local_label_name (bfd
*, const char *);
38 extern reloc_howto_type
*_bfd_xcoff_reloc_type_lookup
39 (bfd
*, bfd_reloc_code_real_type
);
40 extern bool _bfd_xcoff_slurp_armap (bfd
*);
41 extern bfd_cleanup
_bfd_xcoff_archive_p (bfd
*);
42 extern void * _bfd_xcoff_read_ar_hdr (bfd
*);
43 extern bfd
*_bfd_xcoff_openr_next_archived_file (bfd
*, bfd
*);
44 extern int _bfd_xcoff_stat_arch_elt (bfd
*, struct stat
*);
45 extern bool _bfd_xcoff_write_armap
46 (bfd
*, unsigned int, struct orl
*, unsigned int, int);
47 extern bool _bfd_xcoff_write_archive_contents (bfd
*);
48 extern int _bfd_xcoff_sizeof_headers (bfd
*, struct bfd_link_info
*);
49 extern void _bfd_xcoff_swap_sym_in (bfd
*, void *, void *);
50 extern unsigned int _bfd_xcoff_swap_sym_out (bfd
*, void *, void *);
51 extern void _bfd_xcoff_swap_aux_in (bfd
*, void *, int, int, int, int, void *);
52 extern unsigned int _bfd_xcoff_swap_aux_out
53 (bfd
*, void *, int, int, int, int, void *);
54 static void xcoff_swap_reloc_in (bfd
*, void *, void *);
55 static unsigned int xcoff_swap_reloc_out (bfd
*, void *, void *);
57 /* Forward declare xcoff_rtype2howto for coffcode.h macro. */
58 void xcoff_rtype2howto (arelent
*, struct internal_reloc
*);
60 /* coffcode.h needs these to be defined. */
61 #define RS6000COFF_C 1
63 #define SELECT_RELOC(internal, howto) \
65 internal.r_type = howto->type; \
67 ((howto->complain_on_overflow == complain_overflow_signed \
70 | (howto->bitsize - 1)); \
73 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
74 #define COFF_LONG_FILENAMES
75 #define NO_COFF_SYMBOLS
76 #define RTYPE2HOWTO(cache_ptr, dst) xcoff_rtype2howto (cache_ptr, dst)
77 #define coff_mkobject _bfd_xcoff_mkobject
78 #define coff_bfd_is_local_label_name _bfd_xcoff_is_local_label_name
80 extern bfd_cleanup
rs6000coff_core_p (bfd
*abfd
);
81 extern bool rs6000coff_core_file_matches_executable_p
82 (bfd
*cbfd
, bfd
*ebfd
);
83 extern char *rs6000coff_core_file_failing_command (bfd
*abfd
);
84 extern int rs6000coff_core_file_failing_signal (bfd
*abfd
);
85 #define CORE_FILE_P rs6000coff_core_p
86 #define coff_core_file_failing_command \
87 rs6000coff_core_file_failing_command
88 #define coff_core_file_failing_signal \
89 rs6000coff_core_file_failing_signal
90 #define coff_core_file_matches_executable_p \
91 rs6000coff_core_file_matches_executable_p
92 #define coff_core_file_pid \
93 _bfd_nocore_core_file_pid
95 #define CORE_FILE_P _bfd_dummy_target
96 #define coff_core_file_failing_command \
97 _bfd_nocore_core_file_failing_command
98 #define coff_core_file_failing_signal \
99 _bfd_nocore_core_file_failing_signal
100 #define coff_core_file_matches_executable_p \
101 _bfd_nocore_core_file_matches_executable_p
102 #define coff_core_file_pid \
103 _bfd_nocore_core_file_pid
105 #define coff_SWAP_sym_in _bfd_xcoff_swap_sym_in
106 #define coff_SWAP_sym_out _bfd_xcoff_swap_sym_out
107 #define coff_SWAP_aux_in _bfd_xcoff_swap_aux_in
108 #define coff_SWAP_aux_out _bfd_xcoff_swap_aux_out
109 #define coff_swap_reloc_in xcoff_swap_reloc_in
110 #define coff_swap_reloc_out xcoff_swap_reloc_out
111 #define NO_COFF_RELOCS
113 #ifndef bfd_pe_print_pdata
114 #define bfd_pe_print_pdata NULL
117 #include "coffcode.h"
119 /* The main body of code is in coffcode.h. */
121 static const char *normalize_filename (bfd
*);
122 static bool xcoff_write_armap_old
123 (bfd
*, unsigned int, struct orl
*, unsigned int, int);
124 static bool xcoff_write_armap_big
125 (bfd
*, unsigned int, struct orl
*, unsigned int, int);
126 static bool xcoff_write_archive_contents_old (bfd
*);
127 static bool xcoff_write_archive_contents_big (bfd
*);
128 static void xcoff_swap_ldhdr_in (bfd
*, const void *, struct internal_ldhdr
*);
129 static void xcoff_swap_ldhdr_out (bfd
*, const struct internal_ldhdr
*, void *);
130 static void xcoff_swap_ldsym_in (bfd
*, const void *, struct internal_ldsym
*);
131 static void xcoff_swap_ldsym_out (bfd
*, const struct internal_ldsym
*, void *);
132 static void xcoff_swap_ldrel_in (bfd
*, const void *, struct internal_ldrel
*);
133 static void xcoff_swap_ldrel_out (bfd
*, const struct internal_ldrel
*, void *);
134 static bool xcoff_ppc_relocate_section
135 (bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
136 struct internal_reloc
*, struct internal_syment
*, asection
**);
137 static bool _bfd_xcoff_put_ldsymbol_name
138 (bfd
*, struct xcoff_loader_info
*, struct internal_ldsym
*, const char *);
139 static asection
*xcoff_create_csect_from_smclas
140 (bfd
*, union internal_auxent
*, const char *);
141 static bool xcoff_is_lineno_count_overflow (bfd
*, bfd_vma
);
142 static bool xcoff_is_reloc_count_overflow (bfd
*, bfd_vma
);
143 static bfd_vma
xcoff_loader_symbol_offset (bfd
*, struct internal_ldhdr
*);
144 static bfd_vma
xcoff_loader_reloc_offset (bfd
*, struct internal_ldhdr
*);
145 static bool xcoff_generate_rtinit
146 (bfd
*, const char *, const char *, bool);
147 static bool do_pad (bfd
*, unsigned int);
148 static bool do_copy (bfd
*, bfd
*);
150 /* Relocation functions */
151 static xcoff_reloc_function xcoff_reloc_type_br
;
153 static xcoff_complain_function xcoff_complain_overflow_dont_func
;
154 static xcoff_complain_function xcoff_complain_overflow_bitfield_func
;
155 static xcoff_complain_function xcoff_complain_overflow_signed_func
;
156 static xcoff_complain_function xcoff_complain_overflow_unsigned_func
;
158 xcoff_reloc_function
*const
159 xcoff_calculate_relocation
[XCOFF_MAX_CALCULATE_RELOCATION
] =
161 xcoff_reloc_type_pos
, /* R_POS (0x00) */
162 xcoff_reloc_type_neg
, /* R_NEG (0x01) */
163 xcoff_reloc_type_rel
, /* R_REL (0x02) */
164 xcoff_reloc_type_toc
, /* R_TOC (0x03) */
165 xcoff_reloc_type_toc
, /* R_TRL (0x04) */
166 xcoff_reloc_type_toc
, /* R_GL (0x05) */
167 xcoff_reloc_type_toc
, /* R_TCL (0x06) */
168 xcoff_reloc_type_fail
, /* (0x07) */
169 xcoff_reloc_type_ba
, /* R_BA (0x08) */
170 xcoff_reloc_type_fail
, /* (0x09) */
171 xcoff_reloc_type_br
, /* R_BR (0x0a) */
172 xcoff_reloc_type_fail
, /* (0x0b) */
173 xcoff_reloc_type_pos
, /* R_RL (0x0c) */
174 xcoff_reloc_type_pos
, /* R_RLA (0x0d) */
175 xcoff_reloc_type_fail
, /* (0x0e) */
176 xcoff_reloc_type_noop
, /* R_REF (0x0f) */
177 xcoff_reloc_type_fail
, /* (0x10) */
178 xcoff_reloc_type_fail
, /* (0x11) */
179 xcoff_reloc_type_fail
, /* (0x12) */
180 xcoff_reloc_type_toc
, /* R_TRLA (0x13) */
181 xcoff_reloc_type_fail
, /* R_RRTBI (0x14) */
182 xcoff_reloc_type_fail
, /* R_RRTBA (0x15) */
183 xcoff_reloc_type_ba
, /* R_CAI (0x16) */
184 xcoff_reloc_type_crel
, /* R_CREL (0x17) */
185 xcoff_reloc_type_ba
, /* R_RBA (0x18) */
186 xcoff_reloc_type_ba
, /* R_RBAC (0x19) */
187 xcoff_reloc_type_br
, /* R_RBR (0x1a) */
188 xcoff_reloc_type_ba
, /* R_RBRC (0x1b) */
189 xcoff_reloc_type_fail
, /* (0x1c) */
190 xcoff_reloc_type_fail
, /* (0x1d) */
191 xcoff_reloc_type_fail
, /* (0x1e) */
192 xcoff_reloc_type_fail
, /* (0x1f) */
193 xcoff_reloc_type_tls
, /* R_TLS (0x20) */
194 xcoff_reloc_type_tls
, /* R_TLS_IE (0x21) */
195 xcoff_reloc_type_tls
, /* R_TLS_LD (0x22) */
196 xcoff_reloc_type_tls
, /* R_TLS_LE (0x23) */
197 xcoff_reloc_type_tls
, /* R_TLSM (0x24) */
198 xcoff_reloc_type_tls
, /* R_TLSML (0x25) */
199 xcoff_reloc_type_fail
, /* (0x26) */
200 xcoff_reloc_type_fail
, /* (0x27) */
201 xcoff_reloc_type_fail
, /* (0x28) */
202 xcoff_reloc_type_fail
, /* (0x29) */
203 xcoff_reloc_type_fail
, /* (0x2a) */
204 xcoff_reloc_type_fail
, /* (0x2b) */
205 xcoff_reloc_type_fail
, /* (0x2c) */
206 xcoff_reloc_type_fail
, /* (0x2d) */
207 xcoff_reloc_type_fail
, /* (0x2e) */
208 xcoff_reloc_type_fail
, /* (0x2f) */
209 xcoff_reloc_type_toc
, /* R_TOCU (0x30) */
210 xcoff_reloc_type_toc
, /* R_TOCL (0x31) */
213 xcoff_complain_function
*const
214 xcoff_complain_overflow
[XCOFF_MAX_COMPLAIN_OVERFLOW
] =
216 xcoff_complain_overflow_dont_func
,
217 xcoff_complain_overflow_bitfield_func
,
218 xcoff_complain_overflow_signed_func
,
219 xcoff_complain_overflow_unsigned_func
,
222 /* Information about one member of an archive. */
225 /* The archive member that this structure describes. */
228 /* The number of bytes of padding that must be inserted before the
229 start of the member in order to ensure that the section contents
230 are correctly aligned. */
231 unsigned int leading_padding
;
233 /* The offset of MEMBER from the start of the archive (i.e. the end
234 of the leading padding). */
237 /* The normalized name of MEMBER. */
240 /* The length of NAME, without padding. */
241 bfd_size_type namlen
;
243 /* The length of NAME, with padding. */
244 bfd_size_type padded_namlen
;
246 /* The size of MEMBER's header, including the name and magic sequence. */
247 bfd_size_type header_size
;
249 /* The size of the MEMBER's contents. */
250 bfd_size_type contents_size
;
252 /* The number of bytes of padding that must be inserted after MEMBER
253 in order to preserve even alignment. */
254 bfd_size_type trailing_padding
;
257 /* A structure used for iterating over the members of an archive. */
258 struct archive_iterator
260 /* The archive itself. */
263 /* Information about the current archive member. */
264 struct member_layout current
;
266 /* Information about the next archive member. MEMBER is null if there
267 are no more archive members, in which case OFFSET is the offset of
268 the first unused byte. */
269 struct member_layout next
;
272 /* Initialize INFO so that it describes member MEMBER of archive ARCHIVE.
273 OFFSET is the even-padded offset of MEMBER, not including any leading
274 padding needed for section alignment. */
277 member_layout_init (struct member_layout
*info
, bfd
*archive
,
278 bfd
*member
, file_ptr offset
)
280 info
->member
= member
;
281 info
->leading_padding
= 0;
284 info
->name
= normalize_filename (member
);
285 info
->namlen
= strlen (info
->name
);
286 info
->padded_namlen
= info
->namlen
+ (info
->namlen
& 1);
287 if (xcoff_big_format_p (archive
))
288 info
->header_size
= SIZEOF_AR_HDR_BIG
;
290 info
->header_size
= SIZEOF_AR_HDR
;
291 info
->header_size
+= info
->padded_namlen
+ SXCOFFARFMAG
;
292 info
->contents_size
= arelt_size (member
);
293 info
->trailing_padding
= info
->contents_size
& 1;
295 if (bfd_check_format (member
, bfd_object
)
296 && bfd_get_flavour (member
) == bfd_target_xcoff_flavour
297 && (member
->flags
& DYNAMIC
) != 0)
298 info
->leading_padding
299 = (-(offset
+ info
->header_size
)
300 & ((1 << bfd_xcoff_text_align_power (member
)) - 1));
302 info
->offset
= offset
+ info
->leading_padding
;
305 /* Set up ITERATOR to iterate through archive ARCHIVE. */
308 archive_iterator_begin (struct archive_iterator
*iterator
,
311 iterator
->archive
= archive
;
312 member_layout_init (&iterator
->next
, archive
, archive
->archive_head
,
313 xcoff_big_format_p (archive
)
314 ? SIZEOF_AR_FILE_HDR_BIG
315 : SIZEOF_AR_FILE_HDR
);
318 /* Make ITERATOR visit the first unvisited archive member. Return true
319 on success; return false if all members have been visited. */
322 archive_iterator_next (struct archive_iterator
*iterator
)
324 if (!iterator
->next
.member
)
327 iterator
->current
= iterator
->next
;
328 member_layout_init (&iterator
->next
, iterator
->archive
,
329 iterator
->current
.member
->archive_next
,
330 iterator
->current
.offset
331 + iterator
->current
.header_size
332 + iterator
->current
.contents_size
333 + iterator
->current
.trailing_padding
);
337 /* We use our own tdata type. Its first field is the COFF tdata type,
338 so the COFF routines are compatible. */
341 _bfd_xcoff_mkobject (bfd
*abfd
)
343 coff_data_type
*coff
;
344 size_t amt
= sizeof (struct xcoff_tdata
);
346 abfd
->tdata
.xcoff_obj_data
= (struct xcoff_tdata
*) bfd_zalloc (abfd
, amt
);
347 if (abfd
->tdata
.xcoff_obj_data
== NULL
)
349 coff
= coff_data (abfd
);
350 coff
->symbols
= (coff_symbol_type
*) NULL
;
351 coff
->conversion_table
= (unsigned int *) NULL
;
352 coff
->raw_syments
= (struct coff_ptr_struct
*) NULL
;
355 xcoff_data (abfd
)->modtype
= ('1' << 8) | 'L';
357 /* We set cputype to -1 to indicate that it has not been
359 xcoff_data (abfd
)->cputype
= -1;
361 xcoff_data (abfd
)->csects
= NULL
;
362 xcoff_data (abfd
)->debug_indices
= NULL
;
364 /* text section alignment is different than the default */
365 bfd_xcoff_text_align_power (abfd
) = 2;
370 /* Copy XCOFF data from one BFD to another. */
373 _bfd_xcoff_copy_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
375 struct xcoff_tdata
*ix
, *ox
;
378 if (ibfd
->xvec
!= obfd
->xvec
)
380 ix
= xcoff_data (ibfd
);
381 ox
= xcoff_data (obfd
);
382 ox
->full_aouthdr
= ix
->full_aouthdr
;
388 sec
= coff_section_from_bfd_index (ibfd
, ix
->sntoc
);
389 if (sec
== NULL
|| sec
->output_section
== NULL
)
392 ox
->sntoc
= sec
->output_section
->target_index
;
394 if (ix
->snentry
== 0)
398 sec
= coff_section_from_bfd_index (ibfd
, ix
->snentry
);
399 if (sec
== NULL
|| sec
->output_section
== NULL
)
402 ox
->snentry
= sec
->output_section
->target_index
;
404 bfd_xcoff_text_align_power (obfd
) = bfd_xcoff_text_align_power (ibfd
);
405 bfd_xcoff_data_align_power (obfd
) = bfd_xcoff_data_align_power (ibfd
);
406 ox
->modtype
= ix
->modtype
;
407 ox
->cputype
= ix
->cputype
;
408 ox
->maxdata
= ix
->maxdata
;
409 ox
->maxstack
= ix
->maxstack
;
413 /* I don't think XCOFF really has a notion of local labels based on
414 name. This will mean that ld -X doesn't actually strip anything.
415 The AIX native linker does not have a -X option, and it ignores the
419 _bfd_xcoff_is_local_label_name (bfd
*abfd ATTRIBUTE_UNUSED
,
420 const char *name ATTRIBUTE_UNUSED
)
426 _bfd_xcoff_swap_sym_in (bfd
*abfd
, void * ext1
, void * in1
)
428 SYMENT
*ext
= (SYMENT
*)ext1
;
429 struct internal_syment
* in
= (struct internal_syment
*)in1
;
431 if (ext
->e
.e_name
[0] != 0)
433 memcpy (in
->_n
._n_name
, ext
->e
.e_name
, SYMNMLEN
);
437 in
->_n
._n_n
._n_zeroes
= 0;
438 in
->_n
._n_n
._n_offset
= H_GET_32 (abfd
, ext
->e
.e
.e_offset
);
441 in
->n_value
= H_GET_32 (abfd
, ext
->e_value
);
442 in
->n_scnum
= (short) H_GET_16 (abfd
, ext
->e_scnum
);
443 in
->n_type
= H_GET_16 (abfd
, ext
->e_type
);
444 in
->n_sclass
= H_GET_8 (abfd
, ext
->e_sclass
);
445 in
->n_numaux
= H_GET_8 (abfd
, ext
->e_numaux
);
449 _bfd_xcoff_swap_sym_out (bfd
*abfd
, void * inp
, void * extp
)
451 struct internal_syment
*in
= (struct internal_syment
*)inp
;
452 SYMENT
*ext
=(SYMENT
*)extp
;
454 if (in
->_n
._n_name
[0] != 0)
456 memcpy (ext
->e
.e_name
, in
->_n
._n_name
, SYMNMLEN
);
460 H_PUT_32 (abfd
, 0, ext
->e
.e
.e_zeroes
);
461 H_PUT_32 (abfd
, in
->_n
._n_n
._n_offset
, ext
->e
.e
.e_offset
);
464 H_PUT_32 (abfd
, in
->n_value
, ext
->e_value
);
465 H_PUT_16 (abfd
, in
->n_scnum
, ext
->e_scnum
);
466 H_PUT_16 (abfd
, in
->n_type
, ext
->e_type
);
467 H_PUT_8 (abfd
, in
->n_sclass
, ext
->e_sclass
);
468 H_PUT_8 (abfd
, in
->n_numaux
, ext
->e_numaux
);
469 return bfd_coff_symesz (abfd
);
473 _bfd_xcoff_swap_aux_in (bfd
*abfd
, void * ext1
, int type ATTRIBUTE_UNUSED
,
474 int in_class
, int indx
, int numaux
, void * in1
)
476 AUXENT
* ext
= (AUXENT
*)ext1
;
477 union internal_auxent
*in
= (union internal_auxent
*)in1
;
483 /* xgettext: c-format */
484 (_("%pB: unsupported swap_aux_in for storage class %#x"),
485 abfd
, (unsigned int) in_class
);
486 bfd_set_error (bfd_error_bad_value
);
490 if (ext
->x_file
.x_n
.x_fname
[0] == 0)
492 in
->x_file
.x_n
.x_n
.x_zeroes
= 0;
493 in
->x_file
.x_n
.x_n
.x_offset
=
494 H_GET_32 (abfd
, ext
->x_file
.x_n
.x_n
.x_offset
);
497 memcpy (in
->x_file
.x_n
.x_fname
, ext
->x_file
.x_n
.x_fname
, FILNMLEN
);
498 in
->x_file
.x_ftype
= H_GET_8 (abfd
, ext
->x_file
.x_ftype
);
501 /* RS/6000 "csect" auxents.
502 There is always a CSECT auxiliary entry. But functions can
503 have FCN ones too. In this case, CSECT is always the last
508 if (indx
+ 1 == numaux
)
510 in
->x_csect
.x_scnlen
.u64
= H_GET_32 (abfd
, ext
->x_csect
.x_scnlen
);
511 in
->x_csect
.x_parmhash
= H_GET_32 (abfd
, ext
->x_csect
.x_parmhash
);
512 in
->x_csect
.x_snhash
= H_GET_16 (abfd
, ext
->x_csect
.x_snhash
);
513 /* We don't have to hack bitfields in x_smtyp because it's
514 defined by shifts-and-ands, which are equivalent on all
516 in
->x_csect
.x_smtyp
= H_GET_8 (abfd
, ext
->x_csect
.x_smtyp
);
517 in
->x_csect
.x_smclas
= H_GET_8 (abfd
, ext
->x_csect
.x_smclas
);
518 in
->x_csect
.x_stab
= H_GET_32 (abfd
, ext
->x_csect
.x_stab
);
519 in
->x_csect
.x_snstab
= H_GET_16 (abfd
, ext
->x_csect
.x_snstab
);
523 /* x_exptr isn't supported. */
524 in
->x_sym
.x_misc
.x_fsize
525 = H_GET_32 (abfd
, ext
->x_fcn
.x_fsize
);
526 in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
527 = H_GET_32 (abfd
, ext
->x_fcn
.x_lnnoptr
);
528 in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.u32
529 = H_GET_32 (abfd
, ext
->x_fcn
.x_endndx
);
534 in
->x_scn
.x_scnlen
= H_GET_32 (abfd
, ext
->x_scn
.x_scnlen
);
535 in
->x_scn
.x_nreloc
= H_GET_16 (abfd
, ext
->x_scn
.x_nreloc
);
536 in
->x_scn
.x_nlinno
= H_GET_16 (abfd
, ext
->x_scn
.x_nlinno
);
537 /* PE defines some extra fields; we zero them out for
539 in
->x_scn
.x_checksum
= 0;
540 in
->x_scn
.x_associated
= 0;
541 in
->x_scn
.x_comdat
= 0;
546 in
->x_sym
.x_misc
.x_lnsz
.x_lnno
547 = H_GET_32 (abfd
, ext
->x_sym
.x_lnno
);
551 in
->x_sect
.x_scnlen
= H_GET_32 (abfd
, ext
->x_sect
.x_scnlen
);
552 in
->x_sect
.x_nreloc
= H_GET_32 (abfd
, ext
->x_sect
.x_nreloc
);
559 _bfd_xcoff_swap_aux_out (bfd
*abfd
, void * inp
, int type ATTRIBUTE_UNUSED
,
560 int in_class
, int indx
, int numaux
, void * extp
)
562 union internal_auxent
*in
= (union internal_auxent
*)inp
;
563 AUXENT
*ext
= (AUXENT
*)extp
;
565 memset (ext
, 0, bfd_coff_auxesz (abfd
));
570 /* xgettext: c-format */
571 (_("%pB: unsupported swap_aux_out for storage class %#x"),
572 abfd
, (unsigned int) in_class
);
573 bfd_set_error (bfd_error_bad_value
);
577 if (in
->x_file
.x_n
.x_fname
[0] == 0)
579 H_PUT_32 (abfd
, 0, ext
->x_file
.x_n
.x_n
.x_zeroes
);
580 H_PUT_32 (abfd
, in
->x_file
.x_n
.x_n
.x_offset
,
581 ext
->x_file
.x_n
.x_n
.x_offset
);
584 memcpy (ext
->x_file
.x_n
.x_fname
, in
->x_file
.x_n
.x_fname
, FILNMLEN
);
585 H_PUT_8 (abfd
, in
->x_file
.x_ftype
, ext
->x_file
.x_ftype
);
588 /* RS/6000 "csect" auxents */
592 if (indx
+ 1 == numaux
)
594 H_PUT_32 (abfd
, in
->x_csect
.x_scnlen
.u64
, ext
->x_csect
.x_scnlen
);
595 H_PUT_32 (abfd
, in
->x_csect
.x_parmhash
, ext
->x_csect
.x_parmhash
);
596 H_PUT_16 (abfd
, in
->x_csect
.x_snhash
, ext
->x_csect
.x_snhash
);
597 /* We don't have to hack bitfields in x_smtyp because it's
598 defined by shifts-and-ands, which are equivalent on all
600 H_PUT_8 (abfd
, in
->x_csect
.x_smtyp
, ext
->x_csect
.x_smtyp
);
601 H_PUT_8 (abfd
, in
->x_csect
.x_smclas
, ext
->x_csect
.x_smclas
);
602 H_PUT_32 (abfd
, in
->x_csect
.x_stab
, ext
->x_csect
.x_stab
);
603 H_PUT_16 (abfd
, in
->x_csect
.x_snstab
, ext
->x_csect
.x_snstab
);
607 H_PUT_32 (abfd
, in
->x_sym
.x_misc
.x_fsize
, ext
->x_fcn
.x_fsize
);
608 H_PUT_32 (abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
,
609 ext
->x_fcn
.x_lnnoptr
);
610 H_PUT_32 (abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.u32
,
611 ext
->x_fcn
.x_endndx
);
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
);
623 H_PUT_32 (abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_lnno
, ext
->x_sym
.x_lnno
);
627 H_PUT_32 (abfd
, in
->x_sect
.x_scnlen
, ext
->x_sect
.x_scnlen
);
628 H_PUT_32 (abfd
, in
->x_sect
.x_nreloc
, ext
->x_sect
.x_nreloc
);
632 return bfd_coff_auxesz (abfd
);
635 /* The XCOFF reloc table.
636 XCOFF relocations aren't defined only by the type field r_type.
637 The bitsize and whether they are signed or not, are defined by
638 r_size field. Thus, it's complicated to create a constant
639 table reference every possible relocation.
640 This table contains the "default" relocation and few modified
641 relocations what were already there. It's enough when
642 xcoff_rtype2howto is called.
643 For relocations from an input bfd to an output bfd, the default
644 relocation is retrieved and when manually adapted.
646 For now, it seems to be enought. */
648 reloc_howto_type xcoff_howto_table
[] =
650 /* 0x00: Standard 32 bit relocation. */
651 HOWTO (R_POS
, /* type */
655 false, /* pc_relative */
657 complain_overflow_bitfield
, /* complain_on_overflow */
658 0, /* special_function */
660 true, /* partial_inplace */
661 0xffffffff, /* src_mask */
662 0xffffffff, /* dst_mask */
663 false), /* pcrel_offset */
665 /* 0x01: 32 bit relocation, but store negative value. */
666 HOWTO (R_NEG
, /* type */
670 false, /* pc_relative */
672 complain_overflow_bitfield
, /* complain_on_overflow */
673 0, /* special_function */
675 true, /* partial_inplace */
676 0xffffffff, /* src_mask */
677 0xffffffff, /* dst_mask */
678 false), /* pcrel_offset */
680 /* 0x02: 32 bit PC relative relocation. */
681 HOWTO (R_REL
, /* type */
685 true, /* pc_relative */
687 complain_overflow_signed
, /* complain_on_overflow */
688 0, /* special_function */
690 true, /* partial_inplace */
691 0xffffffff, /* src_mask */
692 0xffffffff, /* dst_mask */
693 false), /* pcrel_offset */
695 /* 0x03: 16 bit TOC relative relocation. */
696 HOWTO (R_TOC
, /* type */
700 false, /* pc_relative */
702 complain_overflow_bitfield
, /* complain_on_overflow */
703 0, /* special_function */
705 true, /* partial_inplace */
707 0xffff, /* dst_mask */
708 false), /* pcrel_offset */
710 /* 0x04: Same as R_TOC */
711 HOWTO (R_TRL
, /* type */
715 false, /* pc_relative */
717 complain_overflow_bitfield
, /* complain_on_overflow */
718 0, /* special_function */
720 true, /* partial_inplace */
722 0xffff, /* dst_mask */
723 false), /* pcrel_offset */
725 /* 0x05: External TOC relative symbol. */
726 HOWTO (R_GL
, /* type */
730 false, /* pc_relative */
732 complain_overflow_bitfield
, /* complain_on_overflow */
733 0, /* special_function */
735 true, /* partial_inplace */
737 0xffff, /* dst_mask */
738 false), /* pcrel_offset */
740 /* 0x06: Local TOC relative symbol. */
741 HOWTO (R_TCL
, /* type */
745 false, /* pc_relative */
747 complain_overflow_bitfield
, /* complain_on_overflow */
748 0, /* special_function */
750 true, /* partial_inplace */
752 0xffff, /* dst_mask */
753 false), /* pcrel_offset */
757 /* 0x08: Same as R_RBA. */
758 HOWTO (R_BA
, /* type */
762 false, /* pc_relative */
764 complain_overflow_bitfield
, /* complain_on_overflow */
765 0, /* special_function */
766 "R_BA_26", /* name */
767 true, /* partial_inplace */
768 0x03fffffc, /* src_mask */
769 0x03fffffc, /* dst_mask */
770 false), /* pcrel_offset */
774 /* 0x0a: Same as R_RBR. */
775 HOWTO (R_BR
, /* type */
779 true, /* pc_relative */
781 complain_overflow_signed
, /* complain_on_overflow */
782 0, /* special_function */
784 true, /* partial_inplace */
785 0x03fffffc, /* src_mask */
786 0x03fffffc, /* dst_mask */
787 false), /* pcrel_offset */
791 /* 0x0c: Same as R_POS. */
792 HOWTO (R_RL
, /* type */
796 false, /* pc_relative */
798 complain_overflow_bitfield
, /* complain_on_overflow */
799 0, /* special_function */
801 true, /* partial_inplace */
802 0xffffffff, /* src_mask */
803 0xffffffff, /* dst_mask */
804 false), /* pcrel_offset */
806 /* 0x0d: Same as R_POS. */
807 HOWTO (R_RLA
, /* type */
811 false, /* pc_relative */
813 complain_overflow_bitfield
, /* complain_on_overflow */
814 0, /* special_function */
816 true, /* partial_inplace */
817 0xffffffff, /* src_mask */
818 0xffffffff, /* dst_mask */
819 false), /* pcrel_offset */
823 /* 0x0f: Non-relocating reference. Bitsize is 1 so that r_rsize is 0. */
824 HOWTO (R_REF
, /* type */
828 false, /* pc_relative */
830 complain_overflow_dont
, /* complain_on_overflow */
831 0, /* special_function */
833 false, /* partial_inplace */
836 false), /* pcrel_offset */
842 /* 0x13: Same as R_TOC. */
843 HOWTO (R_TRLA
, /* type */
847 false, /* pc_relative */
849 complain_overflow_bitfield
, /* complain_on_overflow */
850 0, /* special_function */
852 true, /* partial_inplace */
854 0xffff, /* dst_mask */
855 false), /* pcrel_offset */
857 /* 0x14: Modifiable relative branch. */
858 HOWTO (R_RRTBI
, /* type */
862 false, /* pc_relative */
864 complain_overflow_bitfield
, /* complain_on_overflow */
865 0, /* special_function */
866 "R_RRTBI", /* name */
867 true, /* partial_inplace */
868 0xffffffff, /* src_mask */
869 0xffffffff, /* dst_mask */
870 false), /* pcrel_offset */
872 /* 0x15: Modifiable absolute branch. */
873 HOWTO (R_RRTBA
, /* type */
877 false, /* pc_relative */
879 complain_overflow_bitfield
, /* complain_on_overflow */
880 0, /* special_function */
881 "R_RRTBA", /* name */
882 true, /* partial_inplace */
883 0xffffffff, /* src_mask */
884 0xffffffff, /* dst_mask */
885 false), /* pcrel_offset */
887 /* 0x16: Modifiable call absolute indirect. */
888 HOWTO (R_CAI
, /* type */
892 false, /* pc_relative */
894 complain_overflow_bitfield
, /* complain_on_overflow */
895 0, /* special_function */
897 true, /* partial_inplace */
898 0xffff, /* src_mask */
899 0xffff, /* dst_mask */
900 false), /* pcrel_offset */
902 /* 0x17: Modifiable call relative. */
903 HOWTO (R_CREL
, /* type */
907 false, /* pc_relative */
909 complain_overflow_bitfield
, /* complain_on_overflow */
910 0, /* special_function */
912 true, /* partial_inplace */
913 0xffff, /* src_mask */
914 0xffff, /* dst_mask */
915 false), /* pcrel_offset */
917 /* 0x18: Modifiable branch absolute. */
918 HOWTO (R_RBA
, /* type */
922 false, /* pc_relative */
924 complain_overflow_bitfield
, /* complain_on_overflow */
925 0, /* special_function */
927 true, /* partial_inplace */
928 0x03fffffc, /* src_mask */
929 0x03fffffc, /* dst_mask */
930 false), /* pcrel_offset */
932 /* 0x19: Modifiable branch absolute. */
933 HOWTO (R_RBAC
, /* type */
937 false, /* pc_relative */
939 complain_overflow_bitfield
, /* complain_on_overflow */
940 0, /* special_function */
942 true, /* partial_inplace */
943 0xffffffff, /* src_mask */
944 0xffffffff, /* dst_mask */
945 false), /* pcrel_offset */
947 /* 0x1a: Modifiable branch relative. */
948 HOWTO (R_RBR
, /* type */
952 false, /* pc_relative */
954 complain_overflow_signed
, /* complain_on_overflow */
955 0, /* special_function */
956 "R_RBR_26", /* name */
957 true, /* partial_inplace */
958 0x03fffffc, /* src_mask */
959 0x03fffffc, /* dst_mask */
960 false), /* pcrel_offset */
962 /* 0x1b: Modifiable branch absolute. */
963 HOWTO (R_RBRC
, /* type */
967 false, /* pc_relative */
969 complain_overflow_bitfield
, /* complain_on_overflow */
970 0, /* special_function */
972 true, /* partial_inplace */
973 0xffff, /* src_mask */
974 0xffff, /* dst_mask */
975 false), /* pcrel_offset */
977 /* 0x1c: 16 bit Non modifiable absolute branch. */
978 HOWTO (R_BA
, /* type */
982 false, /* pc_relative */
984 complain_overflow_bitfield
, /* complain_on_overflow */
985 0, /* special_function */
986 "R_BA_16", /* name */
987 true, /* partial_inplace */
988 0xfffc, /* src_mask */
989 0xfffc, /* dst_mask */
990 false), /* pcrel_offset */
992 /* 0x1d: Modifiable branch relative. */
993 HOWTO (R_RBR
, /* type */
997 true, /* pc_relative */
999 complain_overflow_signed
, /* complain_on_overflow */
1000 0, /* special_function */
1001 "R_RBR_16", /* name */
1002 true, /* partial_inplace */
1003 0xfffc, /* src_mask */
1004 0xfffc, /* dst_mask */
1005 false), /* pcrel_offset */
1007 /* 0x1e: Modifiable branch relative. */
1008 HOWTO (R_RBA
, /* type */
1012 false, /* pc_relative */
1014 complain_overflow_signed
, /* complain_on_overflow */
1015 0, /* special_function */
1016 "R_RBA_16", /* name */
1017 true, /* partial_inplace */
1018 0xffff, /* src_mask */
1019 0xffff, /* dst_mask */
1020 false), /* pcrel_offset */
1024 /* 0x20: General-dynamic TLS relocation. */
1025 HOWTO (R_TLS
, /* type */
1029 false, /* pc_relative */
1031 complain_overflow_bitfield
, /* complain_on_overflow */
1032 0, /* special_function */
1034 true, /* partial_inplace */
1035 0xffffffff, /* src_mask */
1036 0xffffffff, /* dst_mask */
1037 false), /* pcrel_offset */
1039 /* 0x21: Initial-exec TLS relocation. */
1040 HOWTO (R_TLS_IE
, /* type */
1044 false, /* pc_relative */
1046 complain_overflow_bitfield
, /* complain_on_overflow */
1047 0, /* special_function */
1048 "R_TLS_IE", /* name */
1049 true, /* partial_inplace */
1050 0xffffffff, /* src_mask */
1051 0xffffffff, /* dst_mask */
1052 false), /* pcrel_offset */
1054 /* 0x22: Local-dynamic TLS relocation. */
1055 HOWTO (R_TLS_LD
, /* type */
1059 false, /* pc_relative */
1061 complain_overflow_bitfield
, /* complain_on_overflow */
1062 0, /* special_function */
1063 "R_TLS_LD", /* name */
1064 true, /* partial_inplace */
1065 0xffffffff, /* src_mask */
1066 0xffffffff, /* dst_mask */
1067 false), /* pcrel_offset */
1069 /* 0x23: Local-exec TLS relocation. */
1070 HOWTO (R_TLS_LE
, /* type */
1074 false, /* pc_relative */
1076 complain_overflow_bitfield
, /* complain_on_overflow */
1077 0, /* special_function */
1078 "R_TLS_LE", /* name */
1079 true, /* partial_inplace */
1080 0xffffffff, /* src_mask */
1081 0xffffffff, /* dst_mask */
1082 false), /* pcrel_offset */
1084 /* 0x24: TLS relocation. */
1085 HOWTO (R_TLSM
, /* type */
1089 false, /* pc_relative */
1091 complain_overflow_bitfield
, /* complain_on_overflow */
1092 0, /* special_function */
1093 "R_TLSM", /* name */
1094 true, /* partial_inplace */
1095 0xffffffff, /* src_mask */
1096 0xffffffff, /* dst_mask */
1097 false), /* pcrel_offset */
1100 /* 0x25: TLS module relocation. */
1101 HOWTO (R_TLSML
, /* type */
1105 false, /* pc_relative */
1107 complain_overflow_bitfield
, /* complain_on_overflow */
1108 0, /* special_function */
1109 "R_TLSML", /* name */
1110 true, /* partial_inplace */
1111 0xffffffff, /* src_mask */
1112 0xffffffff, /* dst_mask */
1113 false), /* pcrel_offset */
1126 /* 0x30: High-order 16 bit TOC relative relocation. */
1127 HOWTO (R_TOCU
, /* type */
1128 16, /* rightshift */
1131 false, /* pc_relative */
1133 complain_overflow_bitfield
, /* complain_on_overflow */
1134 0, /* special_function */
1135 "R_TOCU", /* name */
1136 true, /* partial_inplace */
1138 0xffff, /* dst_mask */
1139 false), /* pcrel_offset */
1141 /* 0x31: Low-order 16 bit TOC relative relocation. */
1142 HOWTO (R_TOCL
, /* type */
1146 false, /* pc_relative */
1148 complain_overflow_dont
, /* complain_on_overflow */
1149 0, /* special_function */
1150 "R_TOCL", /* name */
1151 true, /* partial_inplace */
1153 0xffff, /* dst_mask */
1154 false), /* pcrel_offset */
1159 xcoff_rtype2howto (arelent
*relent
, struct internal_reloc
*internal
)
1161 if (internal
->r_type
> R_TOCL
)
1164 /* Default howto layout works most of the time */
1165 relent
->howto
= &xcoff_howto_table
[internal
->r_type
];
1167 /* Special case some 16 bit reloc */
1168 if (15 == (internal
->r_size
& 0x1f))
1170 if (R_BA
== internal
->r_type
)
1171 relent
->howto
= &xcoff_howto_table
[0x1c];
1172 else if (R_RBR
== internal
->r_type
)
1173 relent
->howto
= &xcoff_howto_table
[0x1d];
1174 else if (R_RBA
== internal
->r_type
)
1175 relent
->howto
= &xcoff_howto_table
[0x1e];
1178 /* The r_size field of an XCOFF reloc encodes the bitsize of the
1179 relocation, as well as indicating whether it is signed or not.
1180 Doublecheck that the relocation information gathered from the
1181 type matches this information. The bitsize is not significant
1182 for R_REF relocs. */
1183 if (relent
->howto
->dst_mask
!= 0
1184 && (relent
->howto
->bitsize
1185 != ((unsigned int) internal
->r_size
& 0x1f) + 1))
1190 _bfd_xcoff_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1191 bfd_reloc_code_real_type code
)
1195 case BFD_RELOC_PPC_B26
:
1196 return &xcoff_howto_table
[0xa];
1197 case BFD_RELOC_PPC_BA16
:
1198 return &xcoff_howto_table
[0x1c];
1199 case BFD_RELOC_PPC_BA26
:
1200 return &xcoff_howto_table
[8];
1201 case BFD_RELOC_PPC_TOC16
:
1202 return &xcoff_howto_table
[3];
1203 case BFD_RELOC_PPC_TOC16_HI
:
1204 return &xcoff_howto_table
[0x30];
1205 case BFD_RELOC_PPC_TOC16_LO
:
1206 return &xcoff_howto_table
[0x31];
1207 case BFD_RELOC_PPC_B16
:
1208 return &xcoff_howto_table
[0x1d];
1210 case BFD_RELOC_CTOR
:
1211 return &xcoff_howto_table
[0];
1212 case BFD_RELOC_NONE
:
1213 return &xcoff_howto_table
[0xf];
1214 case BFD_RELOC_PPC_NEG
:
1215 return &xcoff_howto_table
[0x1];
1216 case BFD_RELOC_PPC_TLSGD
:
1217 return &xcoff_howto_table
[0x20];
1218 case BFD_RELOC_PPC_TLSIE
:
1219 return &xcoff_howto_table
[0x21];
1220 case BFD_RELOC_PPC_TLSLD
:
1221 return &xcoff_howto_table
[0x22];
1222 case BFD_RELOC_PPC_TLSLE
:
1223 return &xcoff_howto_table
[0x23];
1224 case BFD_RELOC_PPC_TLSM
:
1225 return &xcoff_howto_table
[0x24];
1226 case BFD_RELOC_PPC_TLSML
:
1227 return &xcoff_howto_table
[0x25];
1233 static reloc_howto_type
*
1234 _bfd_xcoff_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1240 i
< sizeof (xcoff_howto_table
) / sizeof (xcoff_howto_table
[0]);
1242 if (xcoff_howto_table
[i
].name
!= NULL
1243 && strcasecmp (xcoff_howto_table
[i
].name
, r_name
) == 0)
1244 return &xcoff_howto_table
[i
];
1249 /* XCOFF archive support. The original version of this code was by
1250 Damon A. Permezel. It was enhanced to permit cross support, and
1251 writing archive files, by Ian Lance Taylor, Cygnus Support.
1253 XCOFF uses its own archive format. Everything is hooked together
1254 with file offset links, so it is possible to rapidly update an
1255 archive in place. Of course, we don't do that. An XCOFF archive
1256 has a real file header, not just an ARMAG string. The structure of
1257 the file header and of each archive header appear below.
1259 An XCOFF archive also has a member table, which is a list of
1260 elements in the archive (you can get that by looking through the
1261 linked list, but you have to read a lot more of the file). The
1262 member table has a normal archive header with an empty name. It is
1263 normally (and perhaps must be) the second to last entry in the
1264 archive. The member table data is almost printable ASCII. It
1265 starts with a 12 character decimal string which is the number of
1266 entries in the table. For each entry it has a 12 character decimal
1267 string which is the offset in the archive of that member. These
1268 entries are followed by a series of null terminated strings which
1269 are the member names for each entry.
1271 Finally, an XCOFF archive has a global symbol table, which is what
1272 we call the armap. The global symbol table has a normal archive
1273 header with an empty name. It is normally (and perhaps must be)
1274 the last entry in the archive. The contents start with a four byte
1275 binary number which is the number of entries. This is followed by
1276 a that many four byte binary numbers; each is the file offset of an
1277 entry in the archive. These numbers are followed by a series of
1278 null terminated strings, which are symbol names.
1280 AIX 4.3 introduced a new archive format which can handle larger
1281 files and also 32- and 64-bit objects in the same archive. The
1282 things said above remain true except that there is now more than
1283 one global symbol table. The one is used to index 32-bit objects,
1284 the other for 64-bit objects.
1286 The new archives (recognizable by the new ARMAG string) has larger
1287 field lengths so that we cannot really share any code. Also we have
1288 to take care that we are not generating the new form of archives
1289 on AIX 4.2 or earlier systems. */
1291 /* PR 21786: The PE/COFF standard does not require NUL termination for any of
1292 the ASCII fields in the archive headers. So in order to be able to extract
1293 numerical values we provide our own versions of strtol and strtoll which
1294 take a maximum length as an additional parameter. Also - just to save space,
1295 we omit the endptr return parameter, since we know that it is never used. */
1298 _bfd_strntol (const char * nptr
, int base
, unsigned int maxlen
)
1300 char buf
[24]; /* Should be enough. */
1302 BFD_ASSERT (maxlen
< (sizeof (buf
) - 1));
1304 memcpy (buf
, nptr
, maxlen
);
1306 return strtol (buf
, NULL
, base
);
1310 _bfd_strntoll (const char * nptr
, int base
, unsigned int maxlen
)
1312 char buf
[32]; /* Should be enough. */
1314 BFD_ASSERT (maxlen
< (sizeof (buf
) - 1));
1316 memcpy (buf
, nptr
, maxlen
);
1318 return strtoll (buf
, NULL
, base
);
1321 /* Macro to read an ASCII value stored in an archive header field. */
1322 #define GET_VALUE_IN_FIELD(VAR, FIELD, BASE) \
1325 (VAR) = (sizeof (VAR) > sizeof (long) \
1326 ? _bfd_strntoll (FIELD, BASE, sizeof FIELD) \
1327 : _bfd_strntol (FIELD, BASE, sizeof FIELD)); \
1331 #define EQ_VALUE_IN_FIELD(VAR, FIELD, BASE) \
1332 (sizeof (VAR) > sizeof (long) \
1333 ? (VAR) == _bfd_strntoll (FIELD, BASE, sizeof FIELD) \
1334 : (VAR) == _bfd_strntol (FIELD, BASE, sizeof FIELD))
1336 /* Read in the armap of an XCOFF archive. */
1339 _bfd_xcoff_slurp_armap (bfd
*abfd
)
1344 bfd_byte
*contents
, *cend
;
1349 if (xcoff_ardata (abfd
) == NULL
)
1351 abfd
->has_armap
= false;
1355 if (! xcoff_big_format_p (abfd
))
1357 /* This is for the old format. */
1358 struct xcoff_ar_hdr hdr
;
1360 GET_VALUE_IN_FIELD (off
, xcoff_ardata (abfd
)->symoff
, 10);
1363 abfd
->has_armap
= false;
1367 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0)
1370 /* The symbol table starts with a normal archive header. */
1371 if (bfd_bread (&hdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1375 /* Skip the name (normally empty). */
1376 GET_VALUE_IN_FIELD (namlen
, hdr
.namlen
, 10);
1377 off
= ((namlen
+ 1) & ~ (size_t) 1) + SXCOFFARFMAG
;
1378 if (bfd_seek (abfd
, off
, SEEK_CUR
) != 0)
1381 GET_VALUE_IN_FIELD (sz
, hdr
.size
, 10);
1384 bfd_set_error (bfd_error_bad_value
);
1388 /* Read in the entire symbol table. */
1389 contents
= (bfd_byte
*) _bfd_alloc_and_read (abfd
, sz
+ 1, sz
);
1390 if (contents
== NULL
)
1393 /* Ensure strings are NULL terminated so we don't wander off the
1394 end of the buffer. */
1397 /* The symbol table starts with a four byte count. */
1398 c
= H_GET_32 (abfd
, contents
);
1402 bfd_set_error (bfd_error_bad_value
);
1406 bfd_ardata (abfd
)->symdefs
=
1407 ((carsym
*) bfd_alloc (abfd
, c
* sizeof (carsym
)));
1408 if (bfd_ardata (abfd
)->symdefs
== NULL
)
1411 /* After the count comes a list of four byte file offsets. */
1412 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
, p
= contents
+ 4;
1414 ++i
, ++arsym
, p
+= 4)
1415 arsym
->file_offset
= H_GET_32 (abfd
, p
);
1419 /* This is for the new format. */
1420 struct xcoff_ar_hdr_big hdr
;
1422 GET_VALUE_IN_FIELD (off
, xcoff_ardata_big (abfd
)->symoff
, 10);
1425 abfd
->has_armap
= false;
1429 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0)
1432 /* The symbol table starts with a normal archive header. */
1433 if (bfd_bread (&hdr
, (bfd_size_type
) SIZEOF_AR_HDR_BIG
, abfd
)
1434 != SIZEOF_AR_HDR_BIG
)
1437 /* Skip the name (normally empty). */
1438 GET_VALUE_IN_FIELD (namlen
, hdr
.namlen
, 10);
1439 off
= ((namlen
+ 1) & ~ (size_t) 1) + SXCOFFARFMAG
;
1440 if (bfd_seek (abfd
, off
, SEEK_CUR
) != 0)
1443 GET_VALUE_IN_FIELD (sz
, hdr
.size
, 10);
1446 bfd_set_error (bfd_error_bad_value
);
1450 /* Read in the entire symbol table. */
1451 contents
= (bfd_byte
*) _bfd_alloc_and_read (abfd
, sz
+ 1, sz
);
1452 if (contents
== NULL
)
1455 /* Ensure strings are NULL terminated so we don't wander off the
1456 end of the buffer. */
1459 /* The symbol table starts with an eight byte count. */
1460 c
= H_GET_64 (abfd
, contents
);
1464 bfd_set_error (bfd_error_bad_value
);
1468 bfd_ardata (abfd
)->symdefs
=
1469 ((carsym
*) bfd_alloc (abfd
, c
* sizeof (carsym
)));
1470 if (bfd_ardata (abfd
)->symdefs
== NULL
)
1473 /* After the count comes a list of eight byte file offsets. */
1474 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
, p
= contents
+ 8;
1476 ++i
, ++arsym
, p
+= 8)
1477 arsym
->file_offset
= H_GET_64 (abfd
, p
);
1480 /* After the file offsets come null terminated symbol names. */
1481 cend
= contents
+ sz
;
1482 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
;
1484 ++i
, ++arsym
, p
+= strlen ((char *) p
) + 1)
1488 bfd_set_error (bfd_error_bad_value
);
1491 arsym
->name
= (char *) p
;
1494 bfd_ardata (abfd
)->symdef_count
= c
;
1495 abfd
->has_armap
= true;
1500 /* See if this is an XCOFF archive. */
1503 _bfd_xcoff_archive_p (bfd
*abfd
)
1505 struct artdata
*tdata_hold
;
1506 char magic
[SXCOFFARMAG
];
1507 size_t amt
= SXCOFFARMAG
;
1509 if (bfd_bread (magic
, amt
, abfd
) != amt
)
1511 if (bfd_get_error () != bfd_error_system_call
)
1512 bfd_set_error (bfd_error_wrong_format
);
1516 if (strncmp (magic
, XCOFFARMAG
, SXCOFFARMAG
) != 0
1517 && strncmp (magic
, XCOFFARMAGBIG
, SXCOFFARMAG
) != 0)
1519 bfd_set_error (bfd_error_wrong_format
);
1523 tdata_hold
= bfd_ardata (abfd
);
1525 amt
= sizeof (struct artdata
);
1526 bfd_ardata (abfd
) = (struct artdata
*) bfd_zalloc (abfd
, amt
);
1527 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
1528 goto error_ret_restore
;
1530 /* Now handle the two formats. */
1531 if (magic
[1] != 'b')
1533 /* This is the old format. */
1534 struct xcoff_ar_file_hdr hdr
;
1536 /* Copy over the magic string. */
1537 memcpy (hdr
.magic
, magic
, SXCOFFARMAG
);
1539 /* Now read the rest of the file header. */
1540 amt
= SIZEOF_AR_FILE_HDR
- SXCOFFARMAG
;
1541 if (bfd_bread (&hdr
.memoff
, amt
, abfd
) != amt
)
1543 if (bfd_get_error () != bfd_error_system_call
)
1544 bfd_set_error (bfd_error_wrong_format
);
1548 GET_VALUE_IN_FIELD (bfd_ardata (abfd
)->first_file_filepos
,
1549 hdr
.firstmemoff
, 10);
1551 amt
= SIZEOF_AR_FILE_HDR
;
1552 bfd_ardata (abfd
)->tdata
= bfd_zalloc (abfd
, amt
);
1553 if (bfd_ardata (abfd
)->tdata
== NULL
)
1556 memcpy (bfd_ardata (abfd
)->tdata
, &hdr
, SIZEOF_AR_FILE_HDR
);
1560 /* This is the new format. */
1561 struct xcoff_ar_file_hdr_big hdr
;
1563 /* Copy over the magic string. */
1564 memcpy (hdr
.magic
, magic
, SXCOFFARMAG
);
1566 /* Now read the rest of the file header. */
1567 amt
= SIZEOF_AR_FILE_HDR_BIG
- SXCOFFARMAG
;
1568 if (bfd_bread (&hdr
.memoff
, amt
, abfd
) != amt
)
1570 if (bfd_get_error () != bfd_error_system_call
)
1571 bfd_set_error (bfd_error_wrong_format
);
1575 bfd_ardata (abfd
)->first_file_filepos
= bfd_scan_vma (hdr
.firstmemoff
,
1579 amt
= SIZEOF_AR_FILE_HDR_BIG
;
1580 bfd_ardata (abfd
)->tdata
= bfd_zalloc (abfd
, amt
);
1581 if (bfd_ardata (abfd
)->tdata
== NULL
)
1584 memcpy (bfd_ardata (abfd
)->tdata
, &hdr
, SIZEOF_AR_FILE_HDR_BIG
);
1587 if (! _bfd_xcoff_slurp_armap (abfd
))
1590 bfd_release (abfd
, bfd_ardata (abfd
));
1592 bfd_ardata (abfd
) = tdata_hold
;
1596 return _bfd_no_cleanup
;
1599 /* Read the archive header in an XCOFF archive. */
1602 _bfd_xcoff_read_ar_hdr (bfd
*abfd
)
1604 bfd_size_type namlen
;
1605 struct areltdata
*ret
;
1608 if (! xcoff_big_format_p (abfd
))
1610 struct xcoff_ar_hdr hdr
;
1611 struct xcoff_ar_hdr
*hdrp
;
1613 if (bfd_bread (&hdr
, SIZEOF_AR_HDR
, abfd
) != SIZEOF_AR_HDR
)
1616 GET_VALUE_IN_FIELD (namlen
, hdr
.namlen
, 10);
1617 if (namlen
> bfd_get_file_size (abfd
))
1619 amt
= sizeof (struct areltdata
) + SIZEOF_AR_HDR
+ namlen
+ 1;
1620 ret
= (struct areltdata
*) bfd_malloc (amt
);
1624 hdrp
= (struct xcoff_ar_hdr
*) (ret
+ 1);
1625 memcpy (hdrp
, &hdr
, SIZEOF_AR_HDR
);
1626 if (bfd_bread ((char *) hdrp
+ SIZEOF_AR_HDR
, namlen
, abfd
) != namlen
)
1631 ((char *) hdrp
)[SIZEOF_AR_HDR
+ namlen
] = '\0';
1633 ret
->arch_header
= (char *) hdrp
;
1634 GET_VALUE_IN_FIELD (ret
->parsed_size
, hdr
.size
, 10);
1635 ret
->filename
= (char *) hdrp
+ SIZEOF_AR_HDR
;
1639 struct xcoff_ar_hdr_big hdr
;
1640 struct xcoff_ar_hdr_big
*hdrp
;
1642 if (bfd_bread (&hdr
, SIZEOF_AR_HDR_BIG
, abfd
) != SIZEOF_AR_HDR_BIG
)
1645 GET_VALUE_IN_FIELD (namlen
, hdr
.namlen
, 10);
1646 if (namlen
> bfd_get_file_size (abfd
))
1648 amt
= sizeof (struct areltdata
) + SIZEOF_AR_HDR_BIG
+ namlen
+ 1;
1649 ret
= (struct areltdata
*) bfd_malloc (amt
);
1653 hdrp
= (struct xcoff_ar_hdr_big
*) (ret
+ 1);
1654 memcpy (hdrp
, &hdr
, SIZEOF_AR_HDR_BIG
);
1655 if (bfd_bread ((char *) hdrp
+ SIZEOF_AR_HDR_BIG
, namlen
, abfd
) != namlen
)
1660 ((char *) hdrp
)[SIZEOF_AR_HDR_BIG
+ namlen
] = '\0';
1662 ret
->arch_header
= (char *) hdrp
;
1663 GET_VALUE_IN_FIELD (ret
->parsed_size
, hdr
.size
, 10);
1664 ret
->filename
= (char *) hdrp
+ SIZEOF_AR_HDR_BIG
;
1667 /* Size occupied by the header above that covered in the fixed
1668 SIZEOF_AR_HDR or SIZEOF_AR_HDR_BIG. */
1669 ret
->extra_size
= namlen
+ (namlen
& 1) + SXCOFFARFMAG
;
1671 /* Skip over the XCOFFARFMAG at the end of the file name. */
1672 if (bfd_seek (abfd
, (file_ptr
) ((namlen
& 1) + SXCOFFARFMAG
), SEEK_CUR
) != 0)
1678 /* Open the next element in an XCOFF archive. */
1681 _bfd_xcoff_openr_next_archived_file (bfd
*archive
, bfd
*last_file
)
1684 file_ptr laststart
, lastend
;
1686 if (xcoff_ardata (archive
) == NULL
)
1688 bfd_set_error (bfd_error_invalid_operation
);
1692 if (! xcoff_big_format_p (archive
))
1694 if (last_file
== NULL
)
1696 filestart
= bfd_ardata (archive
)->first_file_filepos
;
1698 lastend
= SIZEOF_AR_FILE_HDR
;
1702 struct areltdata
*arel
= arch_eltdata (last_file
);
1704 GET_VALUE_IN_FIELD (filestart
, arch_xhdr (last_file
)->nextoff
, 10);
1705 laststart
= last_file
->proxy_origin
;
1706 lastend
= laststart
+ arel
->parsed_size
;
1707 laststart
-= SIZEOF_AR_HDR
+ arel
->extra_size
;
1710 /* Sanity check that we aren't pointing into the previous element,
1711 or into the header. */
1713 && (filestart
< SIZEOF_AR_FILE_HDR
1714 || (filestart
>= laststart
&& filestart
< lastend
)))
1716 bfd_set_error (bfd_error_malformed_archive
);
1721 || EQ_VALUE_IN_FIELD (filestart
, xcoff_ardata (archive
)->memoff
, 10)
1722 || EQ_VALUE_IN_FIELD (filestart
, xcoff_ardata (archive
)->symoff
, 10))
1724 bfd_set_error (bfd_error_no_more_archived_files
);
1730 if (last_file
== NULL
)
1732 filestart
= bfd_ardata (archive
)->first_file_filepos
;
1734 lastend
= SIZEOF_AR_FILE_HDR_BIG
;
1738 struct areltdata
*arel
= arch_eltdata (last_file
);
1740 GET_VALUE_IN_FIELD (filestart
, arch_xhdr_big (last_file
)->nextoff
, 10);
1741 laststart
= last_file
->proxy_origin
;
1742 lastend
= laststart
+ arel
->parsed_size
;
1743 laststart
-= SIZEOF_AR_HDR_BIG
+ arel
->extra_size
;
1746 /* Sanity check that we aren't pointing into the previous element
1747 or into the header. */
1749 && (filestart
< SIZEOF_AR_FILE_HDR_BIG
1750 || (filestart
>= laststart
&& filestart
< lastend
)))
1752 bfd_set_error (bfd_error_malformed_archive
);
1757 || EQ_VALUE_IN_FIELD (filestart
, xcoff_ardata_big (archive
)->memoff
, 10)
1758 || EQ_VALUE_IN_FIELD (filestart
, xcoff_ardata_big (archive
)->symoff
, 10))
1760 bfd_set_error (bfd_error_no_more_archived_files
);
1765 return _bfd_get_elt_at_filepos (archive
, filestart
, NULL
);
1768 /* Stat an element in an XCOFF archive. */
1771 _bfd_xcoff_stat_arch_elt (bfd
*abfd
, struct stat
*s
)
1773 if (abfd
->arelt_data
== NULL
)
1775 bfd_set_error (bfd_error_invalid_operation
);
1779 if (! xcoff_big_format_p (abfd
->my_archive
))
1781 struct xcoff_ar_hdr
*hdrp
= arch_xhdr (abfd
);
1783 GET_VALUE_IN_FIELD (s
->st_mtime
, hdrp
->date
, 10);
1784 GET_VALUE_IN_FIELD (s
->st_uid
, hdrp
->uid
, 10);
1785 GET_VALUE_IN_FIELD (s
->st_gid
, hdrp
->gid
, 10);
1786 GET_VALUE_IN_FIELD (s
->st_mode
, hdrp
->mode
, 8);
1787 s
->st_size
= arch_eltdata (abfd
)->parsed_size
;
1791 struct xcoff_ar_hdr_big
*hdrp
= arch_xhdr_big (abfd
);
1793 GET_VALUE_IN_FIELD (s
->st_mtime
, hdrp
->date
, 10);
1794 GET_VALUE_IN_FIELD (s
->st_uid
, hdrp
->uid
, 10);
1795 GET_VALUE_IN_FIELD (s
->st_gid
, hdrp
->gid
, 10);
1796 GET_VALUE_IN_FIELD (s
->st_mode
, hdrp
->mode
, 8);
1797 s
->st_size
= arch_eltdata (abfd
)->parsed_size
;
1803 /* Normalize a file name for inclusion in an archive. */
1806 normalize_filename (bfd
*abfd
)
1809 const char *filename
;
1811 file
= bfd_get_filename (abfd
);
1812 filename
= strrchr (file
, '/');
1813 if (filename
!= NULL
)
1820 /* Write out an XCOFF armap. */
1823 xcoff_write_armap_old (bfd
*abfd
, unsigned int elength ATTRIBUTE_UNUSED
,
1824 struct orl
*map
, unsigned int orl_count
, int stridx
)
1826 struct archive_iterator iterator
;
1827 struct xcoff_ar_hdr hdr
;
1829 unsigned char buf
[4];
1832 memset (&hdr
, 0, sizeof hdr
);
1833 sprintf (hdr
.size
, "%ld", (long) (4 + orl_count
* 4 + stridx
));
1834 sprintf (hdr
.nextoff
, "%d", 0);
1835 memcpy (hdr
.prevoff
, xcoff_ardata (abfd
)->memoff
, XCOFFARMAG_ELEMENT_SIZE
);
1836 sprintf (hdr
.date
, "%d", 0);
1837 sprintf (hdr
.uid
, "%d", 0);
1838 sprintf (hdr
.gid
, "%d", 0);
1839 sprintf (hdr
.mode
, "%d", 0);
1840 sprintf (hdr
.namlen
, "%d", 0);
1842 /* We need spaces, not null bytes, in the header. */
1843 for (p
= (char *) &hdr
; p
< (char *) &hdr
+ SIZEOF_AR_HDR
; p
++)
1847 if (bfd_bwrite (&hdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1849 || (bfd_bwrite (XCOFFARFMAG
, (bfd_size_type
) SXCOFFARFMAG
, abfd
)
1853 H_PUT_32 (abfd
, orl_count
, buf
);
1854 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
1858 archive_iterator_begin (&iterator
, abfd
);
1859 while (i
< orl_count
&& archive_iterator_next (&iterator
))
1860 while (map
[i
].u
.abfd
== iterator
.current
.member
)
1862 H_PUT_32 (abfd
, iterator
.current
.offset
, buf
);
1863 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
1868 for (i
= 0; i
< orl_count
; i
++)
1873 name
= *map
[i
].name
;
1874 namlen
= strlen (name
);
1875 if (bfd_bwrite (name
, (bfd_size_type
) (namlen
+ 1), abfd
) != namlen
+ 1)
1879 if ((stridx
& 1) != 0)
1884 if (bfd_bwrite (&b
, (bfd_size_type
) 1, abfd
) != 1)
1891 static char buff20
[XCOFFARMAGBIG_ELEMENT_SIZE
+ 1];
1892 #define FMT20 "%-20" PRId64
1893 #define FMT12 "%-12d"
1894 #define FMT12_OCTAL "%-12o"
1896 #define PRINT20(d, v) \
1897 sprintf (buff20, FMT20, (uint64_t) (v)), \
1898 memcpy ((void *) (d), buff20, 20)
1900 #define PRINT12(d, v) \
1901 sprintf (buff20, FMT12, (int)(v)), \
1902 memcpy ((void *) (d), buff20, 12)
1904 #define PRINT12_OCTAL(d, v) \
1905 sprintf (buff20, FMT12_OCTAL, (unsigned int)(v)), \
1906 memcpy ((void *) (d), buff20, 12)
1908 #define PRINT4(d, v) \
1909 sprintf (buff20, FMT4, (int)(v)), \
1910 memcpy ((void *) (d), buff20, 4)
1912 #define READ20(d, v) \
1914 memcpy (buff20, (d), 20), \
1915 (v) = bfd_scan_vma (buff20, (const char **) NULL, 10)
1918 do_pad (bfd
*abfd
, unsigned int number
)
1922 /* Limit pad to <= 4096. */
1927 if (bfd_bwrite (&b
, (bfd_size_type
) 1, abfd
) != 1)
1934 do_copy (bfd
*out_bfd
, bfd
*in_bfd
)
1936 bfd_size_type remaining
;
1937 bfd_byte buffer
[DEFAULT_BUFFERSIZE
];
1939 if (bfd_seek (in_bfd
, (file_ptr
) 0, SEEK_SET
) != 0)
1942 remaining
= arelt_size (in_bfd
);
1944 while (remaining
>= DEFAULT_BUFFERSIZE
)
1946 if (bfd_bread (buffer
, DEFAULT_BUFFERSIZE
, in_bfd
) != DEFAULT_BUFFERSIZE
1947 || bfd_bwrite (buffer
, DEFAULT_BUFFERSIZE
, out_bfd
) != DEFAULT_BUFFERSIZE
)
1950 remaining
-= DEFAULT_BUFFERSIZE
;
1955 if (bfd_bread (buffer
, remaining
, in_bfd
) != remaining
1956 || bfd_bwrite (buffer
, remaining
, out_bfd
) != remaining
)
1964 xcoff_write_armap_big (bfd
*abfd
, unsigned int elength ATTRIBUTE_UNUSED
,
1965 struct orl
*map
, unsigned int orl_count
, int stridx
)
1967 struct archive_iterator iterator
;
1968 struct xcoff_ar_file_hdr_big
*fhdr
;
1969 bfd_vma i
, sym_32
, sym_64
, str_32
, str_64
;
1970 const bfd_arch_info_type
*arch_info
;
1972 size_t string_length
;
1973 file_ptr nextoff
, prevoff
;
1975 /* First, we look through the symbols and work out which are
1976 from 32-bit objects and which from 64-bit ones. */
1977 sym_32
= sym_64
= str_32
= str_64
= 0;
1980 for (current_bfd
= abfd
->archive_head
;
1981 current_bfd
!= NULL
&& i
< orl_count
;
1982 current_bfd
= current_bfd
->archive_next
)
1984 arch_info
= bfd_get_arch_info (current_bfd
);
1985 while (map
[i
].u
.abfd
== current_bfd
)
1987 string_length
= strlen (*map
[i
].name
) + 1;
1988 if (arch_info
->bits_per_address
== 64)
1991 str_64
+= string_length
;
1996 str_32
+= string_length
;
2002 /* A quick sanity check... */
2003 BFD_ASSERT (sym_64
+ sym_32
== orl_count
);
2004 /* Explicit cast to int for compiler. */
2005 BFD_ASSERT ((int)(str_64
+ str_32
) == stridx
);
2007 fhdr
= xcoff_ardata_big (abfd
);
2009 /* xcoff_write_archive_contents_big passes nextoff in symoff. */
2010 READ20 (fhdr
->memoff
, prevoff
);
2011 READ20 (fhdr
->symoff
, nextoff
);
2013 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2015 /* Write out the symbol table.
2018 standard big archive header
2019 0x0000 ar_size [0x14]
2020 0x0014 ar_nxtmem [0x14]
2021 0x0028 ar_prvmem [0x14]
2022 0x003C ar_date [0x0C]
2023 0x0048 ar_uid [0x0C]
2024 0x0054 ar_gid [0x0C]
2025 0x0060 ar_mod [0x0C]
2026 0x006C ar_namelen[0x04]
2027 0x0070 ar_fmag [SXCOFFARFMAG]
2030 0x0072 num_syms [0x08], binary
2031 0x0078 offsets [0x08 * num_syms], binary
2032 0x0086 + 0x08 * num_syms names [??]
2033 ?? pad to even bytes.
2038 struct xcoff_ar_hdr_big
*hdr
;
2042 bfd_vma symbol_table_size
=
2047 + str_32
+ (str_32
& 1);
2049 symbol_table
= bfd_zmalloc (symbol_table_size
);
2050 if (symbol_table
== NULL
)
2053 hdr
= (struct xcoff_ar_hdr_big
*) symbol_table
;
2055 PRINT20 (hdr
->size
, 8 + 8 * sym_32
+ str_32
+ (str_32
& 1));
2058 PRINT20 (hdr
->nextoff
, nextoff
+ symbol_table_size
);
2060 PRINT20 (hdr
->nextoff
, 0);
2062 PRINT20 (hdr
->prevoff
, prevoff
);
2063 PRINT12 (hdr
->date
, 0);
2064 PRINT12 (hdr
->uid
, 0);
2065 PRINT12 (hdr
->gid
, 0);
2066 PRINT12 (hdr
->mode
, 0);
2067 PRINT4 (hdr
->namlen
, 0) ;
2069 st
= symbol_table
+ SIZEOF_AR_HDR_BIG
;
2070 memcpy (st
, XCOFFARFMAG
, SXCOFFARFMAG
);
2073 bfd_h_put_64 (abfd
, sym_32
, st
);
2076 /* loop over the 32 bit offsets */
2078 archive_iterator_begin (&iterator
, abfd
);
2079 while (i
< orl_count
&& archive_iterator_next (&iterator
))
2081 arch_info
= bfd_get_arch_info (iterator
.current
.member
);
2082 while (map
[i
].u
.abfd
== iterator
.current
.member
)
2084 if (arch_info
->bits_per_address
== 32)
2086 bfd_h_put_64 (abfd
, iterator
.current
.offset
, st
);
2093 /* loop over the 32 bit symbol names */
2095 for (current_bfd
= abfd
->archive_head
;
2096 current_bfd
!= NULL
&& i
< orl_count
;
2097 current_bfd
= current_bfd
->archive_next
)
2099 arch_info
= bfd_get_arch_info (current_bfd
);
2100 while (map
[i
].u
.abfd
== current_bfd
)
2102 if (arch_info
->bits_per_address
== 32)
2104 string_length
= sprintf (st
, "%s", *map
[i
].name
);
2105 st
+= string_length
+ 1;
2111 bfd_bwrite (symbol_table
, symbol_table_size
, abfd
);
2113 free (symbol_table
);
2116 nextoff
= nextoff
+ symbol_table_size
;
2119 PRINT20 (fhdr
->symoff
, 0);
2123 struct xcoff_ar_hdr_big
*hdr
;
2127 bfd_vma symbol_table_size
=
2132 + str_64
+ (str_64
& 1);
2134 symbol_table
= bfd_zmalloc (symbol_table_size
);
2135 if (symbol_table
== NULL
)
2138 hdr
= (struct xcoff_ar_hdr_big
*) symbol_table
;
2140 PRINT20 (hdr
->size
, 8 + 8 * sym_64
+ str_64
+ (str_64
& 1));
2141 PRINT20 (hdr
->nextoff
, 0);
2142 PRINT20 (hdr
->prevoff
, prevoff
);
2143 PRINT12 (hdr
->date
, 0);
2144 PRINT12 (hdr
->uid
, 0);
2145 PRINT12 (hdr
->gid
, 0);
2146 PRINT12 (hdr
->mode
, 0);
2147 PRINT4 (hdr
->namlen
, 0);
2149 st
= symbol_table
+ SIZEOF_AR_HDR_BIG
;
2150 memcpy (st
, XCOFFARFMAG
, SXCOFFARFMAG
);
2153 bfd_h_put_64 (abfd
, sym_64
, st
);
2156 /* loop over the 64 bit offsets */
2158 archive_iterator_begin (&iterator
, abfd
);
2159 while (i
< orl_count
&& archive_iterator_next (&iterator
))
2161 arch_info
= bfd_get_arch_info (iterator
.current
.member
);
2162 while (map
[i
].u
.abfd
== iterator
.current
.member
)
2164 if (arch_info
->bits_per_address
== 64)
2166 bfd_h_put_64 (abfd
, iterator
.current
.offset
, st
);
2173 /* loop over the 64 bit symbol names */
2175 for (current_bfd
= abfd
->archive_head
;
2176 current_bfd
!= NULL
&& i
< orl_count
;
2177 current_bfd
= current_bfd
->archive_next
)
2179 arch_info
= bfd_get_arch_info (current_bfd
);
2180 while (map
[i
].u
.abfd
== current_bfd
)
2182 if (arch_info
->bits_per_address
== 64)
2184 string_length
= sprintf (st
, "%s", *map
[i
].name
);
2185 st
+= string_length
+ 1;
2191 bfd_bwrite (symbol_table
, symbol_table_size
, abfd
);
2193 free (symbol_table
);
2195 PRINT20 (fhdr
->symoff64
, nextoff
);
2198 PRINT20 (fhdr
->symoff64
, 0);
2204 _bfd_xcoff_write_armap (bfd
*abfd
, unsigned int elength ATTRIBUTE_UNUSED
,
2205 struct orl
*map
, unsigned int orl_count
, int stridx
)
2207 if (! xcoff_big_format_p (abfd
))
2208 return xcoff_write_armap_old (abfd
, elength
, map
, orl_count
, stridx
);
2210 return xcoff_write_armap_big (abfd
, elength
, map
, orl_count
, stridx
);
2213 /* Write out an XCOFF archive. We always write an entire archive,
2214 rather than fussing with the freelist and so forth. */
2217 xcoff_write_archive_contents_old (bfd
*abfd
)
2219 struct archive_iterator iterator
;
2220 struct xcoff_ar_file_hdr fhdr
;
2221 bfd_size_type count
;
2222 bfd_size_type total_namlen
;
2226 file_ptr prevoff
, nextoff
;
2229 struct xcoff_ar_hdr ahdr
;
2232 char decbuf
[XCOFFARMAG_ELEMENT_SIZE
+ 1];
2234 memset (&fhdr
, 0, sizeof fhdr
);
2235 (void) memcpy (fhdr
.magic
, XCOFFARMAG
, SXCOFFARMAG
);
2236 sprintf (fhdr
.firstmemoff
, "%d", SIZEOF_AR_FILE_HDR
);
2237 sprintf (fhdr
.freeoff
, "%d", 0);
2241 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->archive_next
)
2244 total_namlen
+= strlen (normalize_filename (sub
)) + 1;
2245 if (sub
->arelt_data
== NULL
)
2247 sub
->arelt_data
= bfd_zmalloc (sizeof (struct areltdata
));
2248 if (sub
->arelt_data
== NULL
)
2251 if (arch_xhdr (sub
) == NULL
)
2253 struct xcoff_ar_hdr
*ahdrp
;
2256 if ((sub
->flags
& BFD_IN_MEMORY
) != 0)
2258 /* Assume we just "made" the member, and fake it. */
2259 struct bfd_in_memory
*bim
2260 = (struct bfd_in_memory
*) sub
->iostream
;
2262 s
.st_uid
= getuid ();
2263 s
.st_gid
= getgid ();
2265 s
.st_size
= bim
->size
;
2267 else if (stat (bfd_get_filename (sub
), &s
) != 0)
2269 bfd_set_input_error (sub
, bfd_error_system_call
);
2273 if ((abfd
->flags
& BFD_DETERMINISTIC_OUTPUT
) != 0)
2281 ahdrp
= bfd_zalloc (sub
, sizeof (*ahdrp
));
2285 sprintf (ahdrp
->size
, "%ld", (long) s
.st_size
);
2286 sprintf (ahdrp
->date
, "%ld", (long) s
.st_mtime
);
2287 sprintf (ahdrp
->uid
, "%ld", (long) s
.st_uid
);
2288 sprintf (ahdrp
->gid
, "%ld", (long) s
.st_gid
);
2289 sprintf (ahdrp
->mode
, "%o", (unsigned int) s
.st_mode
);
2291 arch_eltdata (sub
)->arch_header
= (char *) ahdrp
;
2292 arch_eltdata (sub
)->parsed_size
= s
.st_size
;
2295 offsets
= (file_ptr
*) bfd_alloc (abfd
, count
* sizeof (file_ptr
));
2296 if (offsets
== NULL
)
2299 if (bfd_seek (abfd
, (file_ptr
) SIZEOF_AR_FILE_HDR
, SEEK_SET
) != 0)
2302 makemap
= bfd_has_map (abfd
);
2305 for (archive_iterator_begin (&iterator
, abfd
), i
= 0;
2306 archive_iterator_next (&iterator
);
2309 bfd_size_type namlen
;
2310 struct xcoff_ar_hdr
*ahdrp
;
2312 if (makemap
&& ! hasobjects
)
2314 if (bfd_check_format (iterator
.current
.member
, bfd_object
))
2318 ahdrp
= arch_xhdr (iterator
.current
.member
);
2319 sprintf (ahdrp
->prevoff
, "%ld", (long) prevoff
);
2320 sprintf (ahdrp
->namlen
, "%ld", (long) iterator
.current
.namlen
);
2321 sprintf (ahdrp
->nextoff
, "%ld", (long) iterator
.next
.offset
);
2323 /* We need spaces, not null bytes, in the header. */
2324 for (p
= (char *) ahdrp
; p
< (char *) ahdrp
+ SIZEOF_AR_HDR
; p
++)
2328 if (!do_pad (abfd
, iterator
.current
.leading_padding
))
2331 BFD_ASSERT (iterator
.current
.offset
== bfd_tell (abfd
));
2332 namlen
= iterator
.current
.padded_namlen
;
2333 if (bfd_bwrite (ahdrp
, SIZEOF_AR_HDR
, abfd
) != SIZEOF_AR_HDR
2334 || bfd_bwrite (iterator
.current
.name
, namlen
, abfd
) != namlen
2335 || bfd_bwrite (XCOFFARFMAG
, SXCOFFARFMAG
, abfd
) != SXCOFFARFMAG
2336 || bfd_seek (iterator
.current
.member
, 0, SEEK_SET
) != 0
2337 || !do_copy (abfd
, iterator
.current
.member
)
2338 || !do_pad (abfd
, iterator
.current
.trailing_padding
))
2341 offsets
[i
] = iterator
.current
.offset
;
2342 prevoff
= iterator
.current
.offset
;
2345 sprintf (fhdr
.lastmemoff
, "%ld", (long) prevoff
);
2347 /* Write out the member table. */
2349 nextoff
= iterator
.next
.offset
;
2350 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2351 sprintf (fhdr
.memoff
, "%ld", (long) nextoff
);
2353 memset (&ahdr
, 0, sizeof ahdr
);
2354 sprintf (ahdr
.size
, "%ld", (long) (XCOFFARMAG_ELEMENT_SIZE
2355 + count
* XCOFFARMAG_ELEMENT_SIZE
2357 sprintf (ahdr
.prevoff
, "%ld", (long) prevoff
);
2358 sprintf (ahdr
.date
, "%d", 0);
2359 sprintf (ahdr
.uid
, "%d", 0);
2360 sprintf (ahdr
.gid
, "%d", 0);
2361 sprintf (ahdr
.mode
, "%d", 0);
2362 sprintf (ahdr
.namlen
, "%d", 0);
2364 size
= (SIZEOF_AR_HDR
2365 + XCOFFARMAG_ELEMENT_SIZE
2366 + count
* XCOFFARMAG_ELEMENT_SIZE
2371 nextoff
+= size
+ (size
& 1);
2373 if (makemap
&& hasobjects
)
2374 sprintf (ahdr
.nextoff
, "%ld", (long) nextoff
);
2376 sprintf (ahdr
.nextoff
, "%d", 0);
2378 /* We need spaces, not null bytes, in the header. */
2379 for (p
= (char *) &ahdr
; p
< (char *) &ahdr
+ SIZEOF_AR_HDR
; p
++)
2383 if ((bfd_bwrite (&ahdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
2385 || (bfd_bwrite (XCOFFARFMAG
, (bfd_size_type
) SXCOFFARFMAG
, abfd
)
2389 sprintf (decbuf
, "%-12ld", (long) count
);
2390 if (bfd_bwrite (decbuf
, (bfd_size_type
) XCOFFARMAG_ELEMENT_SIZE
, abfd
)
2391 != XCOFFARMAG_ELEMENT_SIZE
)
2393 for (i
= 0; i
< (size_t) count
; i
++)
2395 sprintf (decbuf
, "%-12ld", (long) offsets
[i
]);
2396 if (bfd_bwrite (decbuf
, (bfd_size_type
) XCOFFARMAG_ELEMENT_SIZE
,
2397 abfd
) != XCOFFARMAG_ELEMENT_SIZE
)
2400 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->archive_next
)
2403 bfd_size_type namlen
;
2405 name
= normalize_filename (sub
);
2406 namlen
= strlen (name
);
2407 if (bfd_bwrite (name
, namlen
+ 1, abfd
) != namlen
+ 1)
2411 if (! do_pad (abfd
, size
& 1))
2414 /* Write out the armap, if appropriate. */
2415 if (! makemap
|| ! hasobjects
)
2416 sprintf (fhdr
.symoff
, "%d", 0);
2419 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2420 sprintf (fhdr
.symoff
, "%ld", (long) nextoff
);
2421 bfd_ardata (abfd
)->tdata
= &fhdr
;
2422 if (! _bfd_compute_and_write_armap (abfd
, 0))
2426 /* Write out the archive file header. */
2428 /* We need spaces, not null bytes, in the header. */
2429 for (p
= (char *) &fhdr
; p
< (char *) &fhdr
+ SIZEOF_AR_FILE_HDR
; p
++)
2433 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
2434 || (bfd_bwrite (&fhdr
, (bfd_size_type
) SIZEOF_AR_FILE_HDR
, abfd
)
2435 != SIZEOF_AR_FILE_HDR
))
2442 xcoff_write_archive_contents_big (bfd
*abfd
)
2444 struct xcoff_ar_file_hdr_big fhdr
;
2445 bfd_size_type count
;
2446 bfd_size_type total_namlen
;
2450 file_ptr prevoff
, nextoff
;
2453 struct xcoff_ar_hdr_big
*hdr
;
2455 char *member_table
, *mt
;
2456 bfd_vma member_table_size
;
2457 struct archive_iterator iterator
;
2459 memset (&fhdr
, 0, SIZEOF_AR_FILE_HDR_BIG
);
2460 memcpy (fhdr
.magic
, XCOFFARMAGBIG
, SXCOFFARMAG
);
2462 if (bfd_seek (abfd
, (file_ptr
) SIZEOF_AR_FILE_HDR_BIG
, SEEK_SET
) != 0)
2465 /* Calculate count and total_namlen. */
2466 makemap
= bfd_has_map (abfd
);
2468 for (current_bfd
= abfd
->archive_head
, count
= 0, total_namlen
= 0;
2469 current_bfd
!= NULL
;
2470 current_bfd
= current_bfd
->archive_next
, count
++)
2472 total_namlen
+= strlen (normalize_filename (current_bfd
)) + 1;
2476 && bfd_check_format (current_bfd
, bfd_object
))
2479 if (current_bfd
->arelt_data
== NULL
)
2481 size
= sizeof (struct areltdata
);
2482 current_bfd
->arelt_data
= bfd_zmalloc (size
);
2483 if (current_bfd
->arelt_data
== NULL
)
2487 if (arch_xhdr_big (current_bfd
) == NULL
)
2489 struct xcoff_ar_hdr_big
*ahdrp
;
2492 if ((current_bfd
->flags
& BFD_IN_MEMORY
) != 0)
2494 /* Assume we just "made" the member, and fake it. */
2495 struct bfd_in_memory
*bim
2496 = (struct bfd_in_memory
*) current_bfd
->iostream
;
2498 s
.st_uid
= getuid ();
2499 s
.st_gid
= getgid ();
2501 s
.st_size
= bim
->size
;
2503 else if (stat (bfd_get_filename (current_bfd
), &s
) != 0)
2505 bfd_set_input_error (current_bfd
, bfd_error_system_call
);
2509 if ((abfd
->flags
& BFD_DETERMINISTIC_OUTPUT
) != 0)
2517 ahdrp
= bfd_zalloc (current_bfd
, sizeof (*ahdrp
));
2521 PRINT20 (ahdrp
->size
, s
.st_size
);
2522 PRINT12 (ahdrp
->date
, s
.st_mtime
);
2523 PRINT12 (ahdrp
->uid
, s
.st_uid
);
2524 PRINT12 (ahdrp
->gid
, s
.st_gid
);
2525 PRINT12_OCTAL (ahdrp
->mode
, s
.st_mode
);
2527 arch_eltdata (current_bfd
)->arch_header
= (char *) ahdrp
;
2528 arch_eltdata (current_bfd
)->parsed_size
= s
.st_size
;
2535 offsets
= (file_ptr
*) bfd_malloc (count
* sizeof (file_ptr
));
2536 if (offsets
== NULL
)
2541 for (archive_iterator_begin (&iterator
, abfd
), i
= 0;
2542 archive_iterator_next (&iterator
);
2545 bfd_size_type namlen
;
2546 struct xcoff_ar_hdr_big
*ahdrp
;
2548 ahdrp
= arch_xhdr_big (iterator
.current
.member
);
2549 PRINT20 (ahdrp
->prevoff
, prevoff
);
2550 PRINT4 (ahdrp
->namlen
, iterator
.current
.namlen
);
2551 PRINT20 (ahdrp
->nextoff
, iterator
.next
.offset
);
2553 if (!do_pad (abfd
, iterator
.current
.leading_padding
))
2559 BFD_ASSERT (iterator
.current
.offset
== bfd_tell (abfd
));
2560 namlen
= iterator
.current
.padded_namlen
;
2561 if (bfd_bwrite (ahdrp
, SIZEOF_AR_HDR_BIG
, abfd
) != SIZEOF_AR_HDR_BIG
2562 || bfd_bwrite (iterator
.current
.name
, namlen
, abfd
) != namlen
2563 || bfd_bwrite (XCOFFARFMAG
, SXCOFFARFMAG
, abfd
) != SXCOFFARFMAG
2564 || bfd_seek (iterator
.current
.member
, 0, SEEK_SET
) != 0
2565 || !do_copy (abfd
, iterator
.current
.member
)
2566 || !do_pad (abfd
, iterator
.current
.trailing_padding
))
2572 offsets
[i
] = iterator
.current
.offset
;
2573 prevoff
= iterator
.current
.offset
;
2578 PRINT20 (fhdr
.firstmemoff
, offsets
[0]);
2579 PRINT20 (fhdr
.lastmemoff
, prevoff
);
2582 /* Write out the member table.
2585 standard big archive header
2586 0x0000 ar_size [0x14]
2587 0x0014 ar_nxtmem [0x14]
2588 0x0028 ar_prvmem [0x14]
2589 0x003C ar_date [0x0C]
2590 0x0048 ar_uid [0x0C]
2591 0x0054 ar_gid [0x0C]
2592 0x0060 ar_mod [0x0C]
2593 0x006C ar_namelen[0x04]
2594 0x0070 ar_fmag [0x02]
2598 0x0086 offsets [0x14 * counts]
2599 0x0086 + 0x14 * counts names [??]
2600 ?? pad to even bytes.
2603 nextoff
= iterator
.next
.offset
;
2604 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2606 member_table_size
= (SIZEOF_AR_HDR_BIG
2608 + XCOFFARMAGBIG_ELEMENT_SIZE
2609 + count
* XCOFFARMAGBIG_ELEMENT_SIZE
2612 member_table_size
+= member_table_size
& 1;
2613 member_table
= bfd_zmalloc (member_table_size
);
2614 if (member_table
== NULL
)
2620 hdr
= (struct xcoff_ar_hdr_big
*) member_table
;
2622 PRINT20 (hdr
->size
, (XCOFFARMAGBIG_ELEMENT_SIZE
2623 + count
* XCOFFARMAGBIG_ELEMENT_SIZE
2624 + total_namlen
+ (total_namlen
& 1)));
2625 if (makemap
&& hasobjects
)
2626 PRINT20 (hdr
->nextoff
, nextoff
+ member_table_size
);
2628 PRINT20 (hdr
->nextoff
, 0);
2629 PRINT20 (hdr
->prevoff
, prevoff
);
2630 PRINT12 (hdr
->date
, 0);
2631 PRINT12 (hdr
->uid
, 0);
2632 PRINT12 (hdr
->gid
, 0);
2633 PRINT12 (hdr
->mode
, 0);
2634 PRINT4 (hdr
->namlen
, 0);
2636 mt
= member_table
+ SIZEOF_AR_HDR_BIG
;
2637 memcpy (mt
, XCOFFARFMAG
, SXCOFFARFMAG
);
2640 PRINT20 (mt
, count
);
2641 mt
+= XCOFFARMAGBIG_ELEMENT_SIZE
;
2642 for (i
= 0; i
< (size_t) count
; i
++)
2644 PRINT20 (mt
, offsets
[i
]);
2645 mt
+= XCOFFARMAGBIG_ELEMENT_SIZE
;
2654 for (current_bfd
= abfd
->archive_head
;
2655 current_bfd
!= NULL
;
2656 current_bfd
= current_bfd
->archive_next
)
2661 name
= normalize_filename (current_bfd
);
2662 namlen
= sprintf (mt
, "%s", name
);
2666 if (bfd_bwrite (member_table
, member_table_size
, abfd
) != member_table_size
)
2669 free (member_table
);
2671 PRINT20 (fhdr
.memoff
, nextoff
);
2674 nextoff
+= member_table_size
;
2676 /* Write out the armap, if appropriate. */
2678 if (! makemap
|| ! hasobjects
)
2679 PRINT20 (fhdr
.symoff
, 0);
2682 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2684 /* Save nextoff in fhdr.symoff so the armap routine can use it. */
2685 PRINT20 (fhdr
.symoff
, nextoff
);
2687 bfd_ardata (abfd
)->tdata
= &fhdr
;
2688 if (! _bfd_compute_and_write_armap (abfd
, 0))
2692 /* Write out the archive file header. */
2694 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
2695 || (bfd_bwrite (&fhdr
, (bfd_size_type
) SIZEOF_AR_FILE_HDR_BIG
,
2696 abfd
) != SIZEOF_AR_FILE_HDR_BIG
))
2703 _bfd_xcoff_write_archive_contents (bfd
*abfd
)
2705 if (! xcoff_big_format_p (abfd
))
2706 return xcoff_write_archive_contents_old (abfd
);
2708 return xcoff_write_archive_contents_big (abfd
);
2711 /* We can't use the usual coff_sizeof_headers routine, because AIX
2712 always uses an a.out header. */
2715 _bfd_xcoff_sizeof_headers (bfd
*abfd
,
2716 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
2721 if (xcoff_data (abfd
)->full_aouthdr
)
2724 size
+= SMALL_AOUTSZ
;
2725 size
+= abfd
->section_count
* SCNHSZ
;
2727 if (info
->strip
!= strip_all
)
2729 /* There can be additional sections just for dealing with overflow in
2730 reloc and lineno counts. But the numbers of relocs and lineno aren't
2731 known when bfd_sizeof_headers is called, so we compute them by
2732 summing the numbers from input sections. */
2733 struct nbr_reloc_lineno
2735 unsigned int reloc_count
;
2736 unsigned int lineno_count
;
2738 struct nbr_reloc_lineno
*n_rl
;
2740 unsigned int max_index
;
2743 /* Although the number of sections is known, the maximum value of
2744 section->index isn't (because some sections may have been removed).
2745 Don't try to renumber sections, just compute the upper bound. */
2747 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2748 if (s
->index
> max_index
)
2749 max_index
= s
->index
;
2751 /* Allocate the per section counters. It could be possible to use a
2752 preallocated array as the number of sections is limited on XCOFF,
2753 but this creates a maintainance issue. */
2754 n_rl
= bfd_zmalloc ((max_index
+ 1) * sizeof (*n_rl
));
2759 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link
.next
)
2760 for (s
= sub
->sections
; s
!= NULL
; s
= s
->next
)
2761 if (s
->output_section
->owner
== abfd
2762 && !bfd_section_removed_from_list (abfd
, s
->output_section
))
2764 struct nbr_reloc_lineno
*e
= &n_rl
[s
->output_section
->index
];
2765 e
->reloc_count
+= s
->reloc_count
;
2766 e
->lineno_count
+= s
->lineno_count
;
2769 /* Add the size of a section for each section with an overflow. */
2770 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2772 struct nbr_reloc_lineno
*e
= &n_rl
[s
->index
];
2774 if (e
->reloc_count
>= 0xffff
2775 || (e
->lineno_count
>= 0xffff && info
->strip
!= strip_debugger
))
2785 /* Routines to swap information in the XCOFF .loader section. If we
2786 ever need to write an XCOFF loader, this stuff will need to be
2787 moved to another file shared by the linker (which XCOFF calls the
2788 ``binder'') and the loader. */
2790 /* Swap in the ldhdr structure. */
2793 xcoff_swap_ldhdr_in (bfd
*abfd
, const void * s
, struct internal_ldhdr
*dst
)
2795 const struct external_ldhdr
*src
= (const struct external_ldhdr
*) s
;
2797 dst
->l_version
= bfd_get_32 (abfd
, src
->l_version
);
2798 dst
->l_nsyms
= bfd_get_32 (abfd
, src
->l_nsyms
);
2799 dst
->l_nreloc
= bfd_get_32 (abfd
, src
->l_nreloc
);
2800 dst
->l_istlen
= bfd_get_32 (abfd
, src
->l_istlen
);
2801 dst
->l_nimpid
= bfd_get_32 (abfd
, src
->l_nimpid
);
2802 dst
->l_impoff
= bfd_get_32 (abfd
, src
->l_impoff
);
2803 dst
->l_stlen
= bfd_get_32 (abfd
, src
->l_stlen
);
2804 dst
->l_stoff
= bfd_get_32 (abfd
, src
->l_stoff
);
2807 /* Swap out the ldhdr structure. */
2810 xcoff_swap_ldhdr_out (bfd
*abfd
, const struct internal_ldhdr
*src
, void * d
)
2812 struct external_ldhdr
*dst
= (struct external_ldhdr
*) d
;
2814 bfd_put_32 (abfd
, (bfd_vma
) src
->l_version
, dst
->l_version
);
2815 bfd_put_32 (abfd
, src
->l_nsyms
, dst
->l_nsyms
);
2816 bfd_put_32 (abfd
, src
->l_nreloc
, dst
->l_nreloc
);
2817 bfd_put_32 (abfd
, src
->l_istlen
, dst
->l_istlen
);
2818 bfd_put_32 (abfd
, src
->l_nimpid
, dst
->l_nimpid
);
2819 bfd_put_32 (abfd
, src
->l_impoff
, dst
->l_impoff
);
2820 bfd_put_32 (abfd
, src
->l_stlen
, dst
->l_stlen
);
2821 bfd_put_32 (abfd
, src
->l_stoff
, dst
->l_stoff
);
2824 /* Swap in the ldsym structure. */
2827 xcoff_swap_ldsym_in (bfd
*abfd
, const void * s
, struct internal_ldsym
*dst
)
2829 const struct external_ldsym
*src
= (const struct external_ldsym
*) s
;
2831 if (bfd_get_32 (abfd
, src
->_l
._l_l
._l_zeroes
) != 0) {
2832 memcpy (dst
->_l
._l_name
, src
->_l
._l_name
, SYMNMLEN
);
2834 dst
->_l
._l_l
._l_zeroes
= 0;
2835 dst
->_l
._l_l
._l_offset
= bfd_get_32 (abfd
, src
->_l
._l_l
._l_offset
);
2837 dst
->l_value
= bfd_get_32 (abfd
, src
->l_value
);
2838 dst
->l_scnum
= bfd_get_16 (abfd
, src
->l_scnum
);
2839 dst
->l_smtype
= bfd_get_8 (abfd
, src
->l_smtype
);
2840 dst
->l_smclas
= bfd_get_8 (abfd
, src
->l_smclas
);
2841 dst
->l_ifile
= bfd_get_32 (abfd
, src
->l_ifile
);
2842 dst
->l_parm
= bfd_get_32 (abfd
, src
->l_parm
);
2845 /* Swap out the ldsym structure. */
2848 xcoff_swap_ldsym_out (bfd
*abfd
, const struct internal_ldsym
*src
, void * d
)
2850 struct external_ldsym
*dst
= (struct external_ldsym
*) d
;
2852 if (src
->_l
._l_l
._l_zeroes
!= 0)
2853 memcpy (dst
->_l
._l_name
, src
->_l
._l_name
, SYMNMLEN
);
2856 bfd_put_32 (abfd
, (bfd_vma
) 0, dst
->_l
._l_l
._l_zeroes
);
2857 bfd_put_32 (abfd
, (bfd_vma
) src
->_l
._l_l
._l_offset
,
2858 dst
->_l
._l_l
._l_offset
);
2860 bfd_put_32 (abfd
, src
->l_value
, dst
->l_value
);
2861 bfd_put_16 (abfd
, (bfd_vma
) src
->l_scnum
, dst
->l_scnum
);
2862 bfd_put_8 (abfd
, src
->l_smtype
, dst
->l_smtype
);
2863 bfd_put_8 (abfd
, src
->l_smclas
, dst
->l_smclas
);
2864 bfd_put_32 (abfd
, src
->l_ifile
, dst
->l_ifile
);
2865 bfd_put_32 (abfd
, src
->l_parm
, dst
->l_parm
);
2869 xcoff_swap_reloc_in (bfd
*abfd
, void * s
, void * d
)
2871 struct external_reloc
*src
= (struct external_reloc
*) s
;
2872 struct internal_reloc
*dst
= (struct internal_reloc
*) d
;
2874 memset (dst
, 0, sizeof (struct internal_reloc
));
2876 dst
->r_vaddr
= bfd_get_32 (abfd
, src
->r_vaddr
);
2877 dst
->r_symndx
= bfd_get_32 (abfd
, src
->r_symndx
);
2878 dst
->r_size
= bfd_get_8 (abfd
, src
->r_size
);
2879 dst
->r_type
= bfd_get_8 (abfd
, src
->r_type
);
2883 xcoff_swap_reloc_out (bfd
*abfd
, void * s
, void * d
)
2885 struct internal_reloc
*src
= (struct internal_reloc
*) s
;
2886 struct external_reloc
*dst
= (struct external_reloc
*) d
;
2888 bfd_put_32 (abfd
, src
->r_vaddr
, dst
->r_vaddr
);
2889 bfd_put_32 (abfd
, src
->r_symndx
, dst
->r_symndx
);
2890 bfd_put_8 (abfd
, src
->r_type
, dst
->r_type
);
2891 bfd_put_8 (abfd
, src
->r_size
, dst
->r_size
);
2893 return bfd_coff_relsz (abfd
);
2896 /* Swap in the ldrel structure. */
2899 xcoff_swap_ldrel_in (bfd
*abfd
, const void * s
, struct internal_ldrel
*dst
)
2901 const struct external_ldrel
*src
= (const struct external_ldrel
*) s
;
2903 dst
->l_vaddr
= bfd_get_32 (abfd
, src
->l_vaddr
);
2904 dst
->l_symndx
= bfd_get_32 (abfd
, src
->l_symndx
);
2905 dst
->l_rtype
= bfd_get_16 (abfd
, src
->l_rtype
);
2906 dst
->l_rsecnm
= bfd_get_16 (abfd
, src
->l_rsecnm
);
2909 /* Swap out the ldrel structure. */
2912 xcoff_swap_ldrel_out (bfd
*abfd
, const struct internal_ldrel
*src
, void * d
)
2914 struct external_ldrel
*dst
= (struct external_ldrel
*) d
;
2916 bfd_put_32 (abfd
, src
->l_vaddr
, dst
->l_vaddr
);
2917 bfd_put_32 (abfd
, src
->l_symndx
, dst
->l_symndx
);
2918 bfd_put_16 (abfd
, (bfd_vma
) src
->l_rtype
, dst
->l_rtype
);
2919 bfd_put_16 (abfd
, (bfd_vma
) src
->l_rsecnm
, dst
->l_rsecnm
);
2924 xcoff_reloc_type_noop (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2925 asection
*input_section ATTRIBUTE_UNUSED
,
2926 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2927 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
2928 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2929 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
,
2930 bfd_vma val ATTRIBUTE_UNUSED
,
2931 bfd_vma addend ATTRIBUTE_UNUSED
,
2932 bfd_vma
*relocation ATTRIBUTE_UNUSED
,
2933 bfd_byte
*contents ATTRIBUTE_UNUSED
,
2934 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
2940 xcoff_reloc_type_fail (bfd
*input_bfd
,
2941 asection
*input_section ATTRIBUTE_UNUSED
,
2942 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2943 struct internal_reloc
*rel
,
2944 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2945 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
,
2946 bfd_vma val ATTRIBUTE_UNUSED
,
2947 bfd_vma addend ATTRIBUTE_UNUSED
,
2948 bfd_vma
*relocation ATTRIBUTE_UNUSED
,
2949 bfd_byte
*contents ATTRIBUTE_UNUSED
,
2950 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
2953 /* xgettext: c-format */
2954 (_("%pB: unsupported relocation type %#x"),
2955 input_bfd
, (unsigned int) rel
->r_type
);
2956 bfd_set_error (bfd_error_bad_value
);
2961 xcoff_reloc_type_pos (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2962 asection
*input_section ATTRIBUTE_UNUSED
,
2963 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2964 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
2965 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2966 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
,
2969 bfd_vma
*relocation
,
2970 bfd_byte
*contents ATTRIBUTE_UNUSED
,
2971 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
2973 *relocation
= val
+ addend
;
2978 xcoff_reloc_type_neg (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2979 asection
*input_section ATTRIBUTE_UNUSED
,
2980 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2981 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
2982 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2983 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
,
2986 bfd_vma
*relocation
,
2987 bfd_byte
*contents ATTRIBUTE_UNUSED
,
2988 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
2990 *relocation
= - val
- addend
;
2995 xcoff_reloc_type_rel (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2996 asection
*input_section
,
2997 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2998 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
2999 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
3000 struct reloc_howto_struct
*howto
,
3003 bfd_vma
*relocation
,
3004 bfd_byte
*contents ATTRIBUTE_UNUSED
,
3005 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
3007 howto
->pc_relative
= true;
3009 /* A PC relative reloc includes the section address. */
3010 addend
+= input_section
->vma
;
3012 *relocation
= val
+ addend
;
3013 *relocation
-= (input_section
->output_section
->vma
3014 + input_section
->output_offset
);
3019 xcoff_reloc_type_toc (bfd
*input_bfd
,
3020 asection
*input_section ATTRIBUTE_UNUSED
,
3022 struct internal_reloc
*rel
,
3023 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
3024 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
,
3026 bfd_vma addend ATTRIBUTE_UNUSED
,
3027 bfd_vma
*relocation
,
3028 bfd_byte
*contents ATTRIBUTE_UNUSED
,
3029 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
3031 struct xcoff_link_hash_entry
*h
;
3033 if (0 > rel
->r_symndx
)
3036 h
= obj_xcoff_sym_hashes (input_bfd
)[rel
->r_symndx
];
3038 if (h
!= NULL
&& h
->smclas
!= XMC_TD
)
3040 if (h
->toc_section
== NULL
)
3043 /* xgettext: c-format */
3044 (_("%pB: TOC reloc at %#" PRIx64
" to symbol `%s' with no TOC entry"),
3045 input_bfd
, (uint64_t) rel
->r_vaddr
, h
->root
.root
.string
);
3046 bfd_set_error (bfd_error_bad_value
);
3050 BFD_ASSERT ((h
->flags
& XCOFF_SET_TOC
) == 0);
3051 val
= (h
->toc_section
->output_section
->vma
3052 + h
->toc_section
->output_offset
);
3055 /* We can't use the preexisting value written down by the
3056 assembly, as R_TOCU needs to be adjusted when the final
3057 R_TOCL value is signed. */
3058 *relocation
= val
- xcoff_data (output_bfd
)->toc
;
3060 if (rel
->r_type
== R_TOCU
)
3061 *relocation
= ((*relocation
+ 0x8000) >> 16) & 0xffff;
3062 if (rel
->r_type
== R_TOCL
)
3063 *relocation
= *relocation
& 0x0000ffff;
3069 xcoff_reloc_type_ba (bfd
*input_bfd ATTRIBUTE_UNUSED
,
3070 asection
*input_section ATTRIBUTE_UNUSED
,
3071 bfd
*output_bfd ATTRIBUTE_UNUSED
,
3072 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
3073 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
3074 struct reloc_howto_struct
*howto
,
3077 bfd_vma
*relocation
,
3078 bfd_byte
*contents ATTRIBUTE_UNUSED
,
3079 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
3081 howto
->src_mask
&= ~3;
3082 howto
->dst_mask
= howto
->src_mask
;
3084 *relocation
= val
+ addend
;
3090 xcoff_reloc_type_br (bfd
*input_bfd
,
3091 asection
*input_section
,
3092 bfd
*output_bfd ATTRIBUTE_UNUSED
,
3093 struct internal_reloc
*rel
,
3094 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
3095 struct reloc_howto_struct
*howto
,
3098 bfd_vma
*relocation
,
3100 struct bfd_link_info
*info
)
3102 struct xcoff_link_hash_entry
*h
;
3103 bfd_vma section_offset
;
3104 struct xcoff_stub_hash_entry
*stub_entry
= NULL
;
3105 enum xcoff_stub_type stub_type
;
3107 if (0 > rel
->r_symndx
)
3110 h
= obj_xcoff_sym_hashes (input_bfd
)[rel
->r_symndx
];
3111 section_offset
= rel
->r_vaddr
- input_section
->vma
;
3113 /* If we see an R_BR or R_RBR reloc which is jumping to global
3114 linkage code, and it is followed by an appropriate cror nop
3115 instruction, we replace the cror with lwz r2,20(r1). This
3116 restores the TOC after the glink code. Contrariwise, if the
3117 call is followed by a lwz r2,20(r1), but the call is not
3118 going to global linkage code, we can replace the load with a
3121 && (bfd_link_hash_defined
== h
->root
.type
3122 || bfd_link_hash_defweak
== h
->root
.type
)
3123 && section_offset
+ 8 <= input_section
->size
)
3128 pnext
= contents
+ section_offset
+ 4;
3129 next
= bfd_get_32 (input_bfd
, pnext
);
3131 /* The _ptrgl function is magic. It is used by the AIX
3132 compiler to call a function through a pointer. */
3133 if (h
->smclas
== XMC_GL
|| strcmp (h
->root
.root
.string
, "._ptrgl") == 0)
3135 if (next
== 0x4def7b82 /* cror 15,15,15 */
3136 || next
== 0x4ffffb82 /* cror 31,31,31 */
3137 || next
== 0x60000000) /* ori r0,r0,0 */
3138 bfd_put_32 (input_bfd
, 0x80410014, pnext
); /* lwz r2,20(r1) */
3143 if (next
== 0x80410014) /* lwz r2,20(r1) */
3144 bfd_put_32 (input_bfd
, 0x60000000, pnext
); /* ori r0,r0,0 */
3147 else if (NULL
!= h
&& bfd_link_hash_undefined
== h
->root
.type
)
3149 /* Normally, this relocation is against a defined symbol. In the
3150 case where this is a partial link and the output section offset
3151 is greater than 2^25, the linker will return an invalid error
3152 message that the relocation has been truncated. Yes it has been
3153 truncated but no it not important. For this case, disable the
3154 overflow checking. */
3156 howto
->complain_on_overflow
= complain_overflow_dont
;
3159 /* Check if a stub is needed. */
3160 stub_type
= bfd_xcoff_type_of_stub (input_section
, rel
, val
, h
);
3161 if (stub_type
!= xcoff_stub_none
)
3163 asection
*stub_csect
;
3165 stub_entry
= bfd_xcoff_get_stub_entry (input_section
, h
, info
);
3166 if (stub_entry
== NULL
)
3168 _bfd_error_handler (_("Unable to find the stub entry targeting %s"),
3169 h
->root
.root
.string
);
3170 bfd_set_error (bfd_error_bad_value
);
3174 stub_csect
= stub_entry
->hcsect
->root
.u
.def
.section
;
3175 val
= (stub_entry
->stub_offset
3176 + stub_csect
->output_section
->vma
3177 + stub_csect
->output_offset
);
3180 /* The original PC-relative relocation is biased by -r_vaddr, so adding
3181 the value below will give the absolute target address. */
3182 *relocation
= val
+ addend
+ rel
->r_vaddr
;
3184 howto
->src_mask
&= ~3;
3185 howto
->dst_mask
= howto
->src_mask
;
3188 && (h
->root
.type
== bfd_link_hash_defined
3189 || h
->root
.type
== bfd_link_hash_defweak
)
3190 && bfd_is_abs_section (h
->root
.u
.def
.section
)
3191 && section_offset
+ 4 <= input_section
->size
)
3196 /* Turn the relative branch into an absolute one by setting the
3198 ptr
= contents
+ section_offset
;
3199 insn
= bfd_get_32 (input_bfd
, ptr
);
3201 bfd_put_32 (input_bfd
, insn
, ptr
);
3203 /* Make the howto absolute too. */
3204 howto
->pc_relative
= false;
3205 howto
->complain_on_overflow
= complain_overflow_bitfield
;
3209 /* Use a PC-relative howto and subtract the instruction's address
3210 from the target address we calculated above. */
3211 howto
->pc_relative
= true;
3212 *relocation
-= (input_section
->output_section
->vma
3213 + input_section
->output_offset
3220 xcoff_reloc_type_crel (bfd
*input_bfd ATTRIBUTE_UNUSED
,
3221 asection
*input_section
,
3222 bfd
*output_bfd ATTRIBUTE_UNUSED
,
3223 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
3224 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
3225 struct reloc_howto_struct
*howto
,
3226 bfd_vma val ATTRIBUTE_UNUSED
,
3228 bfd_vma
*relocation
,
3229 bfd_byte
*contents ATTRIBUTE_UNUSED
,
3230 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
3232 howto
->pc_relative
= true;
3233 howto
->src_mask
&= ~3;
3234 howto
->dst_mask
= howto
->src_mask
;
3236 /* A PC relative reloc includes the section address. */
3237 addend
+= input_section
->vma
;
3239 *relocation
= val
+ addend
;
3240 *relocation
-= (input_section
->output_section
->vma
3241 + input_section
->output_offset
);
3246 xcoff_reloc_type_tls (bfd
*input_bfd ATTRIBUTE_UNUSED
,
3247 asection
*input_section ATTRIBUTE_UNUSED
,
3248 bfd
*output_bfd ATTRIBUTE_UNUSED
,
3249 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
3250 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
3251 struct reloc_howto_struct
*howto
,
3254 bfd_vma
*relocation
,
3255 bfd_byte
*contents ATTRIBUTE_UNUSED
,
3256 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
3258 struct xcoff_link_hash_entry
*h
;
3260 if (0 > rel
->r_symndx
)
3263 h
= obj_xcoff_sym_hashes (input_bfd
)[rel
->r_symndx
];
3265 /* R_TLSML is handled by the loader but must be from a
3266 TOC entry targeting itslef. This is already verified in
3267 xcoff_link_add_symbols.
3268 The value must be 0. */
3269 if (howto
->type
== R_TLSML
)
3275 /* The target symbol should always be available even if it's not
3277 BFD_ASSERT (h
!= NULL
);
3279 /* TLS relocations must target a TLS symbol. */
3280 if (h
->smclas
!= XMC_TL
&& h
->smclas
!= XMC_UL
)
3283 (_("%pB: TLS relocation at 0x%" PRIx64
" over non-TLS symbol %s (0x%x)\n"),
3284 input_bfd
, (uint64_t) rel
->r_vaddr
, h
->root
.root
.string
, h
->smclas
);
3288 /* Local TLS relocations must target a local symbol, ie
3290 if ((rel
->r_type
== R_TLS_LD
|| rel
->r_type
== R_TLS_LE
)
3291 && (((h
->flags
& XCOFF_DEF_REGULAR
) == 0
3292 && (h
->flags
& XCOFF_DEF_DYNAMIC
) != 0)
3293 || (h
->flags
& XCOFF_IMPORT
) != 0))
3296 (_("%pB: TLS local relocation at 0x%" PRIx64
" over imported symbol %s\n"),
3297 input_bfd
, (uint64_t) rel
->r_vaddr
, h
->root
.root
.string
);
3301 /* R_TLSM are relocations used by the loader.
3302 The value must be 0. */
3303 if (howto
->type
== R_TLSM
)
3309 /* Other TLS relocations aims to put offsets from TLS pointers
3310 starting at -0x7c00 (or -0x7800 in XCOFF64). It becomes a
3311 simple R_POS relocation as long as .tdata and .tbss addresses
3312 start at the same value. This is done in aix ld scripts.
3313 TODO: implement optimization when tls size is < 62K. */
3314 *relocation
= val
+ addend
;
3320 xcoff_complain_overflow_dont_func (bfd
*input_bfd ATTRIBUTE_UNUSED
,
3321 bfd_vma val ATTRIBUTE_UNUSED
,
3322 bfd_vma relocation ATTRIBUTE_UNUSED
,
3323 struct reloc_howto_struct
*
3324 howto ATTRIBUTE_UNUSED
)
3330 xcoff_complain_overflow_bitfield_func (bfd
*input_bfd
,
3333 struct reloc_howto_struct
*howto
)
3335 bfd_vma fieldmask
, signmask
, ss
;
3338 /* Get the values to be added together. For signed and unsigned
3339 relocations, we assume that all values should be truncated to
3340 the size of an address. For bitfields, all the bits matter.
3341 See also bfd_check_overflow. */
3342 fieldmask
= N_ONES (howto
->bitsize
);
3344 b
= val
& howto
->src_mask
;
3346 /* Much like unsigned, except no trimming with addrmask. In
3347 addition, the sum overflows if there is a carry out of
3348 the bfd_vma, i.e., the sum is less than either input
3350 a
>>= howto
->rightshift
;
3351 b
>>= howto
->bitpos
;
3353 /* Bitfields are sometimes used for signed numbers; for
3354 example, a 13-bit field sometimes represents values in
3355 0..8191 and sometimes represents values in -4096..4095.
3356 If the field is signed and a is -4095 (0x1001) and b is
3357 -1 (0x1fff), the sum is -4096 (0x1000), but (0x1001 +
3358 0x1fff is 0x3000). It's not clear how to handle this
3359 everywhere, since there is not way to know how many bits
3360 are significant in the relocation, but the original code
3361 assumed that it was fully sign extended, and we will keep
3363 signmask
= (fieldmask
>> 1) + 1;
3365 if ((a
& ~ fieldmask
) != 0)
3367 /* Some bits out of the field are set. This might not
3368 be a problem: if this is a signed bitfield, it is OK
3369 iff all the high bits are set, including the sign
3370 bit. We'll try setting all but the most significant
3371 bit in the original relocation value: if this is all
3372 ones, we are OK, assuming a signed bitfield. */
3373 ss
= (signmask
<< howto
->rightshift
) - 1;
3374 if ((ss
| relocation
) != ~ (bfd_vma
) 0)
3379 /* We just assume (b & ~ fieldmask) == 0. */
3381 /* We explicitly permit wrap around if this relocation
3382 covers the high bit of an address. The Linux kernel
3383 relies on it, and it is the only way to write assembler
3384 code which can run when loaded at a location 0x80000000
3385 away from the location at which it is linked. */
3386 if ((unsigned) howto
->bitsize
+ howto
->rightshift
3387 == bfd_arch_bits_per_address (input_bfd
))
3391 if (sum
< a
|| (sum
& ~ fieldmask
) != 0)
3393 /* There was a carry out, or the field overflow. Test
3394 for signed operands again. Here is the overflow test
3395 is as for complain_overflow_signed. */
3396 if (((~ (a
^ b
)) & (a
^ sum
)) & signmask
)
3404 xcoff_complain_overflow_signed_func (bfd
*input_bfd
,
3407 struct reloc_howto_struct
*howto
)
3409 bfd_vma addrmask
, fieldmask
, signmask
, ss
;
3412 /* Get the values to be added together. For signed and unsigned
3413 relocations, we assume that all values should be truncated to
3414 the size of an address. For bitfields, all the bits matter.
3415 See also bfd_check_overflow. */
3416 fieldmask
= N_ONES (howto
->bitsize
);
3417 addrmask
= N_ONES (bfd_arch_bits_per_address (input_bfd
)) | fieldmask
;
3419 b
= val
& howto
->src_mask
;
3421 a
= (a
& addrmask
) >> howto
->rightshift
;
3423 /* If any sign bits are set, all sign bits must be set.
3424 That is, A must be a valid negative address after
3426 signmask
= ~ (fieldmask
>> 1);
3428 if (ss
!= 0 && ss
!= ((addrmask
>> howto
->rightshift
) & signmask
))
3431 /* We only need this next bit of code if the sign bit of B
3432 is below the sign bit of A. This would only happen if
3433 SRC_MASK had fewer bits than BITSIZE. Note that if
3434 SRC_MASK has more bits than BITSIZE, we can get into
3435 trouble; we would need to verify that B is in range, as
3436 we do for A above. */
3437 signmask
= ((~ howto
->src_mask
) >> 1) & howto
->src_mask
;
3438 if ((b
& signmask
) != 0)
3440 /* Set all the bits above the sign bit. */
3441 b
-= signmask
<<= 1;
3444 b
= (b
& addrmask
) >> howto
->bitpos
;
3446 /* Now we can do the addition. */
3449 /* See if the result has the correct sign. Bits above the
3450 sign bit are junk now; ignore them. If the sum is
3451 positive, make sure we did not have all negative inputs;
3452 if the sum is negative, make sure we did not have all
3453 positive inputs. The test below looks only at the sign
3454 bits, and it really just
3455 SIGN (A) == SIGN (B) && SIGN (A) != SIGN (SUM)
3457 signmask
= (fieldmask
>> 1) + 1;
3458 if (((~ (a
^ b
)) & (a
^ sum
)) & signmask
)
3465 xcoff_complain_overflow_unsigned_func (bfd
*input_bfd
,
3468 struct reloc_howto_struct
*howto
)
3470 bfd_vma addrmask
, fieldmask
;
3473 /* Get the values to be added together. For signed and unsigned
3474 relocations, we assume that all values should be truncated to
3475 the size of an address. For bitfields, all the bits matter.
3476 See also bfd_check_overflow. */
3477 fieldmask
= N_ONES (howto
->bitsize
);
3478 addrmask
= N_ONES (bfd_arch_bits_per_address (input_bfd
)) | fieldmask
;
3480 b
= val
& howto
->src_mask
;
3482 /* Checking for an unsigned overflow is relatively easy:
3483 trim the addresses and add, and trim the result as well.
3484 Overflow is normally indicated when the result does not
3485 fit in the field. However, we also need to consider the
3486 case when, e.g., fieldmask is 0x7fffffff or smaller, an
3487 input is 0x80000000, and bfd_vma is only 32 bits; then we
3488 will get sum == 0, but there is an overflow, since the
3489 inputs did not fit in the field. Instead of doing a
3490 separate test, we can check for this by or-ing in the
3491 operands when testing for the sum overflowing its final
3493 a
= (a
& addrmask
) >> howto
->rightshift
;
3494 b
= (b
& addrmask
) >> howto
->bitpos
;
3495 sum
= (a
+ b
) & addrmask
;
3496 if ((a
| b
| sum
) & ~ fieldmask
)
3502 /* This is the relocation function for the RS/6000/POWER/PowerPC.
3503 This is currently the only processor which uses XCOFF; I hope that
3506 The original version was based on two documents:
3507 the PowerPC AIX Version 4 Application Binary Interface, First
3508 Edition (April 1992), and the PowerOpen ABI, Big-Endian
3509 32-Bit Hardware Implementation (June 30, 1994). Differences
3510 between the documents are noted below.
3511 Now, IBM has released an official documentation about XCOFF
3513 https://www.ibm.com/support/knowledgecenter/ssw_aix_72/filesreference/XCOFF.html
3515 Unsupported r_type's
3521 These relocs are defined by the PowerPC ABI to be
3522 relative branches which use half of the difference
3523 between the symbol and the program counter. I can't
3524 quite figure out when this is useful. These relocs are
3525 not defined by the PowerOpen ABI.
3530 Simple positive relocation.
3533 Simple negative relocation.
3536 Simple PC relative relocation.
3539 TOC relative relocation. The value in the instruction in
3540 the input file is the offset from the input file TOC to
3541 the desired location. We want the offset from the final
3542 TOC to the desired location. We have:
3547 so we must change insn by on - in.
3548 This relocation allows the linker to perform optimizations
3549 by transforming a load instruction into a add-immediate
3550 when possible. The relocation is, then, changed to R_TRLA
3552 TODO: Currently, the optimisation isn't implemented.
3555 TOC relative relocation. Same as R_TOC, except that
3556 the optimization isn't allowed
3559 TOC relative relocation. This is a TOC relative load
3560 address instruction which have been changed to an add-
3561 immediate instruction.
3564 GL linkage relocation. The value of this relocation
3565 is the address of the external symbol in the TOC
3569 Local object TOC address. I can't figure out the
3570 difference between this and case R_GL.
3573 The PowerPC AIX ABI describes this as a load which may be
3574 changed to a load address. The PowerOpen ABI says this
3575 is the same as case R_POS.
3578 The PowerPC AIX ABI describes this as a load address
3579 which may be changed to a load. The PowerOpen ABI says
3580 this is the same as R_POS.
3583 Not a relocation but a way to prevent the garbage
3584 collector of AIX linker to remove symbols.
3585 This is not needed in our case.
3588 The PowerOpen ABI says this is the same as R_RBA.
3591 Absolute branch which may be modified to become a
3595 The PowerOpen ABI says this is the same as R_RBR.
3598 A relative branch which may be modified to become an
3602 The PowerPC ABI defines this as an absolute call which
3603 may be modified to become a relative call. The PowerOpen
3604 ABI does not define this relocation type.
3607 The PowerPC ABI defines this as a relative call which may
3608 be modified to become an absolute call. The PowerOpen
3609 ABI does not define this relocation type.
3612 The PowerPC ABI defines this as an absolute branch to a
3613 fixed address which may be modified to an absolute branch
3614 to a symbol. The PowerOpen ABI does not define this
3618 The PowerPC ABI defines this as an absolute branch to a
3619 fixed address which may be modified to a relative branch.
3620 The PowerOpen ABI does not define this relocation type.
3623 Thread-local storage relocation using general-dynamic
3627 Thread-local storage relocation using initial-exec model.
3630 Thread-local storage relocation using local-dynamic model.
3633 Thread-local storage relocation using local-exec model.
3636 Tread-local storage relocation used by the loader.
3639 Tread-local storage relocation used by the loader.
3642 Upper TOC relative relocation. The value is the
3643 high-order 16 bit of a TOC relative relocation.
3646 Lower TOC relative relocation. The value is the
3647 low-order 16 bit of a TOC relative relocation.
3651 xcoff_ppc_relocate_section (bfd
*output_bfd
,
3652 struct bfd_link_info
*info
,
3654 asection
*input_section
,
3656 struct internal_reloc
*relocs
,
3657 struct internal_syment
*syms
,
3658 asection
**sections
)
3660 struct internal_reloc
*rel
;
3661 struct internal_reloc
*relend
;
3664 relend
= rel
+ input_section
->reloc_count
;
3665 for (; rel
< relend
; rel
++)
3668 struct xcoff_link_hash_entry
*h
;
3669 struct internal_syment
*sym
;
3672 struct reloc_howto_struct howto
;
3674 bfd_vma value_to_relocate
;
3678 /* Relocation type R_REF is a special relocation type which is
3679 merely used to prevent garbage collection from occurring for
3680 the csect including the symbol which it references. */
3681 if (rel
->r_type
== R_REF
)
3684 /* Retrieve default value in HOWTO table and fix up according
3685 to r_size field, if it can be different.
3686 This should be made during relocation reading but the algorithms
3687 are expecting constant howtos. */
3688 memcpy (&howto
, &xcoff_howto_table
[rel
->r_type
], sizeof (howto
));
3689 if (howto
.bitsize
!= (rel
->r_size
& 0x1f) + 1)
3691 switch (rel
->r_type
)
3695 howto
.bitsize
= (rel
->r_size
& 0x1f) + 1;
3696 howto
.size
= HOWTO_RSIZE (howto
.bitsize
> 16 ? 4 : 2);
3697 howto
.src_mask
= howto
.dst_mask
= N_ONES (howto
.bitsize
);
3702 (_("%pB: relocation (%d) at 0x%" PRIx64
" has wrong r_rsize (0x%x)\n"),
3703 input_bfd
, rel
->r_type
, (uint64_t) rel
->r_vaddr
, rel
->r_size
);
3708 howto
.complain_on_overflow
= (rel
->r_size
& 0x80
3709 ? complain_overflow_signed
3710 : complain_overflow_bitfield
);
3717 symndx
= rel
->r_symndx
;
3723 h
= obj_xcoff_sym_hashes (input_bfd
)[symndx
];
3724 sym
= syms
+ symndx
;
3725 addend
= - sym
->n_value
;
3729 sec
= sections
[symndx
];
3730 /* Hack to make sure we use the right TOC anchor value
3731 if this reloc is against the TOC anchor. */
3732 if (sec
->name
[3] == '0'
3733 && strcmp (sec
->name
, ".tc0") == 0)
3734 val
= xcoff_data (output_bfd
)->toc
;
3736 val
= (sec
->output_section
->vma
3737 + sec
->output_offset
3743 if (info
->unresolved_syms_in_objects
!= RM_IGNORE
3744 && (h
->flags
& XCOFF_WAS_UNDEFINED
) != 0)
3745 (*info
->callbacks
->undefined_symbol
)
3746 (info
, h
->root
.root
.string
,
3747 input_bfd
, input_section
,
3748 rel
->r_vaddr
- input_section
->vma
,
3749 info
->unresolved_syms_in_objects
== RM_DIAGNOSE
&&
3750 !info
->warn_unresolved_syms
);
3752 if (h
->root
.type
== bfd_link_hash_defined
3753 || h
->root
.type
== bfd_link_hash_defweak
)
3755 sec
= h
->root
.u
.def
.section
;
3756 val
= (h
->root
.u
.def
.value
3757 + sec
->output_section
->vma
3758 + sec
->output_offset
);
3760 else if (h
->root
.type
== bfd_link_hash_common
)
3762 sec
= h
->root
.u
.c
.p
->section
;
3763 val
= (sec
->output_section
->vma
3764 + sec
->output_offset
);
3769 BFD_ASSERT (bfd_link_relocatable (info
)
3770 || (info
->static_link
3771 && (h
->flags
& XCOFF_WAS_UNDEFINED
) != 0)
3772 || (h
->flags
& XCOFF_DEF_DYNAMIC
) != 0
3773 || (h
->flags
& XCOFF_IMPORT
) != 0);
3778 if (rel
->r_type
>= XCOFF_MAX_CALCULATE_RELOCATION
3779 || !((*xcoff_calculate_relocation
[rel
->r_type
])
3780 (input_bfd
, input_section
, output_bfd
, rel
, sym
, &howto
, val
,
3781 addend
, &relocation
, contents
, info
)))
3785 address
= rel
->r_vaddr
- input_section
->vma
;
3786 location
= contents
+ address
;
3788 if (address
> input_section
->size
)
3791 /* Get the value we are going to relocate. */
3792 if (2 == bfd_get_reloc_size (&howto
))
3793 value_to_relocate
= bfd_get_16 (input_bfd
, location
);
3795 value_to_relocate
= bfd_get_32 (input_bfd
, location
);
3799 FIXME: We may drop bits during the addition
3800 which we don't check for. We must either check at every single
3801 operation, which would be tedious, or we must do the computations
3802 in a type larger than bfd_vma, which would be inefficient. */
3804 if (((*xcoff_complain_overflow
[howto
.complain_on_overflow
])
3805 (input_bfd
, value_to_relocate
, relocation
, &howto
)))
3808 char buf
[SYMNMLEN
+ 1];
3809 char reloc_type_name
[10];
3821 name
= _bfd_coff_internal_syment_name (input_bfd
, sym
, buf
);
3825 sprintf (reloc_type_name
, "0x%02x", rel
->r_type
);
3827 (*info
->callbacks
->reloc_overflow
)
3828 (info
, (h
? &h
->root
: NULL
), name
, reloc_type_name
,
3829 (bfd_vma
) 0, input_bfd
, input_section
,
3830 rel
->r_vaddr
- input_section
->vma
);
3833 /* Add RELOCATION to the right bits of VALUE_TO_RELOCATE. */
3834 value_to_relocate
= ((value_to_relocate
& ~howto
.dst_mask
)
3835 | (((value_to_relocate
& howto
.src_mask
)
3836 + relocation
) & howto
.dst_mask
));
3838 /* Put the value back in the object file. */
3839 if (2 == bfd_get_reloc_size (&howto
))
3840 bfd_put_16 (input_bfd
, value_to_relocate
, location
);
3842 bfd_put_32 (input_bfd
, value_to_relocate
, location
);
3848 /* gcc-8 warns (*) on all the strncpy calls in this function about
3849 possible string truncation. The "truncation" is not a bug. We
3850 have an external representation of structs with fields that are not
3851 necessarily NULL terminated and corresponding internal
3852 representation fields that are one larger so that they can always
3854 gcc versions between 4.2 and 4.6 do not allow pragma control of
3855 diagnostics inside functions, giving a hard error if you try to use
3856 the finer control available with later versions.
3857 gcc prior to 4.2 warns about diagnostic push and pop.
3858 gcc-5, gcc-6 and gcc-7 warn that -Wstringop-truncation is unknown,
3859 unless you also add #pragma GCC diagnostic ignored "-Wpragma".
3860 (*) Depending on your system header files! */
3861 #if GCC_VERSION >= 8000
3862 # pragma GCC diagnostic push
3863 # pragma GCC diagnostic ignored "-Wstringop-truncation"
3866 _bfd_xcoff_put_ldsymbol_name (bfd
*abfd ATTRIBUTE_UNUSED
,
3867 struct xcoff_loader_info
*ldinfo
,
3868 struct internal_ldsym
*ldsym
,
3872 len
= strlen (name
);
3874 if (len
<= SYMNMLEN
)
3875 strncpy (ldsym
->_l
._l_name
, name
, SYMNMLEN
);
3878 if (ldinfo
->string_size
+ len
+ 3 > ldinfo
->string_alc
)
3880 bfd_size_type newalc
;
3883 newalc
= ldinfo
->string_alc
* 2;
3886 while (ldinfo
->string_size
+ len
+ 3 > newalc
)
3889 newstrings
= bfd_realloc (ldinfo
->strings
, newalc
);
3890 if (newstrings
== NULL
)
3892 ldinfo
->failed
= true;
3895 ldinfo
->string_alc
= newalc
;
3896 ldinfo
->strings
= newstrings
;
3899 ldinfo
->strings
[ldinfo
->string_size
] = ((len
+ 1) >> 8) & 0xff;
3900 ldinfo
->strings
[ldinfo
->string_size
+ 1] = ((len
+ 1)) & 0xff;
3901 strcpy (ldinfo
->strings
+ ldinfo
->string_size
+ 2, name
);
3902 ldsym
->_l
._l_l
._l_zeroes
= 0;
3903 ldsym
->_l
._l_l
._l_offset
= ldinfo
->string_size
+ 2;
3904 ldinfo
->string_size
+= len
+ 3;
3911 _bfd_xcoff_put_symbol_name (struct bfd_link_info
*info
,
3912 struct bfd_strtab_hash
*strtab
,
3913 struct internal_syment
*sym
,
3916 if (strlen (name
) <= SYMNMLEN
)
3918 strncpy (sym
->_n
._n_name
, name
, SYMNMLEN
);
3925 hash
= !info
->traditional_format
;
3926 indx
= _bfd_stringtab_add (strtab
, name
, hash
, false);
3927 if (indx
== (bfd_size_type
) -1)
3929 sym
->_n
._n_n
._n_zeroes
= 0;
3930 sym
->_n
._n_n
._n_offset
= STRING_SIZE_SIZE
+ indx
;
3934 #if GCC_VERSION >= 8000
3935 # pragma GCC diagnostic pop
3939 xcoff_create_csect_from_smclas (bfd
*abfd
,
3940 union internal_auxent
*aux
,
3941 const char *symbol_name
)
3943 asection
*return_value
= NULL
;
3945 /* .sv64 = x_smclas == 17
3946 This is an invalid csect for 32 bit apps. */
3947 static const char * const names
[] =
3949 ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo", /* 0 - 7 */
3950 ".sv", ".bs", ".ds", ".uc", ".ti", ".tb", NULL
, ".tc0", /* 8 - 15 */
3951 ".td", NULL
, ".sv3264", NULL
, ".tl", ".ul", ".te"
3954 if ((aux
->x_csect
.x_smclas
< ARRAY_SIZE (names
))
3955 && (NULL
!= names
[aux
->x_csect
.x_smclas
]))
3957 return_value
= bfd_make_section_anyway
3958 (abfd
, names
[aux
->x_csect
.x_smclas
]);
3963 /* xgettext: c-format */
3964 (_("%pB: symbol `%s' has unrecognized smclas %d"),
3965 abfd
, symbol_name
, aux
->x_csect
.x_smclas
);
3966 bfd_set_error (bfd_error_bad_value
);
3969 return return_value
;
3973 xcoff_is_lineno_count_overflow (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_vma value
)
3975 if (0xffff <= value
)
3982 xcoff_is_reloc_count_overflow (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_vma value
)
3984 if (0xffff <= value
)
3991 xcoff_loader_symbol_offset (bfd
*abfd
,
3992 struct internal_ldhdr
*ldhdr ATTRIBUTE_UNUSED
)
3994 return bfd_xcoff_ldhdrsz (abfd
);
3998 xcoff_loader_reloc_offset (bfd
*abfd
, struct internal_ldhdr
*ldhdr
)
4000 return bfd_xcoff_ldhdrsz (abfd
) + ldhdr
->l_nsyms
* bfd_xcoff_ldsymsz (abfd
);
4004 xcoff_generate_rtinit (bfd
*abfd
, const char *init
, const char *fini
,
4007 bfd_byte filehdr_ext
[FILHSZ
];
4008 bfd_byte scnhdr_ext
[SCNHSZ
];
4009 bfd_byte syment_ext
[SYMESZ
* 10];
4010 bfd_byte reloc_ext
[RELSZ
* 3];
4011 bfd_byte
*data_buffer
;
4012 bfd_size_type data_buffer_size
;
4013 bfd_byte
*string_table
= NULL
, *st_tmp
= NULL
;
4014 bfd_size_type string_table_size
;
4016 size_t initsz
, finisz
;
4017 struct internal_filehdr filehdr
;
4018 struct internal_scnhdr scnhdr
;
4019 struct internal_syment syment
;
4020 union internal_auxent auxent
;
4021 struct internal_reloc reloc
;
4023 char *data_name
= ".data";
4024 char *rtinit_name
= "__rtinit";
4025 char *rtld_name
= "__rtld";
4027 if (! bfd_xcoff_rtinit_size (abfd
))
4030 initsz
= (init
== NULL
? 0 : 1 + strlen (init
));
4031 finisz
= (fini
== NULL
? 0 : 1 + strlen (fini
));
4034 memset (filehdr_ext
, 0, FILHSZ
);
4035 memset (&filehdr
, 0, sizeof (struct internal_filehdr
));
4036 filehdr
.f_magic
= bfd_xcoff_magic_number (abfd
);
4037 filehdr
.f_nscns
= 1;
4038 filehdr
.f_timdat
= 0;
4039 filehdr
.f_nsyms
= 0; /* at least 6, no more than 10 */
4040 filehdr
.f_symptr
= 0; /* set below */
4041 filehdr
.f_opthdr
= 0;
4042 filehdr
.f_flags
= 0;
4044 /* section header */
4045 memset (scnhdr_ext
, 0, SCNHSZ
);
4046 memset (&scnhdr
, 0, sizeof (struct internal_scnhdr
));
4047 memcpy (scnhdr
.s_name
, data_name
, strlen (data_name
));
4050 scnhdr
.s_size
= 0; /* set below */
4051 scnhdr
.s_scnptr
= FILHSZ
+ SCNHSZ
;
4052 scnhdr
.s_relptr
= 0; /* set below */
4053 scnhdr
.s_lnnoptr
= 0;
4054 scnhdr
.s_nreloc
= 0; /* either 1 or 2 */
4056 scnhdr
.s_flags
= STYP_DATA
;
4059 0x0000 0x00000000 : rtl
4060 0x0004 0x00000010 : offset to init, or 0
4061 0x0008 0x00000028 : offset to fini, or 0
4062 0x000C 0x0000000C : size of descriptor
4063 0x0010 0x00000000 : init, needs a reloc
4064 0x0014 0x00000040 : offset to init name
4065 0x0018 0x00000000 : flags, padded to a word
4066 0x001C 0x00000000 : empty init
4069 0x0028 0x00000000 : fini, needs a reloc
4070 0x002C 0x00000??? : offset to fini name
4071 0x0030 0x00000000 : flags, padded to a word
4072 0x0034 0x00000000 : empty fini
4076 0x0040 + initsz fini name */
4078 data_buffer_size
= 0x0040 + initsz
+ finisz
;
4079 data_buffer_size
= (data_buffer_size
+ 7) &~ (bfd_size_type
) 7;
4081 data_buffer
= (bfd_byte
*) bfd_zmalloc (data_buffer_size
);
4082 if (data_buffer
== NULL
)
4088 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x04]);
4090 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x14]);
4091 memcpy (&data_buffer
[val
], init
, initsz
);
4097 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x08]);
4098 val
= 0x40 + initsz
;
4099 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x2C]);
4100 memcpy (&data_buffer
[val
], fini
, finisz
);
4104 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x0C]);
4106 scnhdr
.s_size
= data_buffer_size
;
4109 string_table_size
= 0;
4111 string_table_size
+= initsz
;
4113 string_table_size
+= finisz
;
4114 if (string_table_size
)
4116 string_table_size
+= 4;
4117 string_table
= (bfd_byte
*) bfd_zmalloc (string_table_size
);
4118 if (string_table
== NULL
)
4121 val
= string_table_size
;
4122 bfd_h_put_32 (abfd
, val
, &string_table
[0]);
4123 st_tmp
= string_table
+ 4;
4132 memset (syment_ext
, 0, 10 * SYMESZ
);
4133 memset (reloc_ext
, 0, 3 * RELSZ
);
4136 memset (&syment
, 0, sizeof (struct internal_syment
));
4137 memset (&auxent
, 0, sizeof (union internal_auxent
));
4138 memcpy (syment
._n
._n_name
, data_name
, strlen (data_name
));
4140 syment
.n_sclass
= C_HIDEXT
;
4141 syment
.n_numaux
= 1;
4142 auxent
.x_csect
.x_scnlen
.u64
= data_buffer_size
;
4143 auxent
.x_csect
.x_smtyp
= 3 << 3 | XTY_SD
;
4144 auxent
.x_csect
.x_smclas
= XMC_RW
;
4145 bfd_coff_swap_sym_out (abfd
, &syment
,
4146 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
4147 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
4149 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
4150 filehdr
.f_nsyms
+= 2;
4153 memset (&syment
, 0, sizeof (struct internal_syment
));
4154 memset (&auxent
, 0, sizeof (union internal_auxent
));
4155 memcpy (syment
._n
._n_name
, rtinit_name
, strlen (rtinit_name
));
4157 syment
.n_sclass
= C_EXT
;
4158 syment
.n_numaux
= 1;
4159 auxent
.x_csect
.x_smtyp
= XTY_LD
;
4160 auxent
.x_csect
.x_smclas
= XMC_RW
;
4161 bfd_coff_swap_sym_out (abfd
, &syment
,
4162 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
4163 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
4165 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
4166 filehdr
.f_nsyms
+= 2;
4171 memset (&syment
, 0, sizeof (struct internal_syment
));
4172 memset (&auxent
, 0, sizeof (union internal_auxent
));
4176 syment
._n
._n_n
._n_offset
= st_tmp
- string_table
;
4177 memcpy (st_tmp
, init
, initsz
);
4181 memcpy (syment
._n
._n_name
, init
, initsz
- 1);
4183 syment
.n_sclass
= C_EXT
;
4184 syment
.n_numaux
= 1;
4185 bfd_coff_swap_sym_out (abfd
, &syment
,
4186 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
4187 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
4189 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
4192 memset (&reloc
, 0, sizeof (struct internal_reloc
));
4193 reloc
.r_vaddr
= 0x0010;
4194 reloc
.r_symndx
= filehdr
.f_nsyms
;
4195 reloc
.r_type
= R_POS
;
4197 bfd_coff_swap_reloc_out (abfd
, &reloc
, &reloc_ext
[0]);
4199 filehdr
.f_nsyms
+= 2;
4200 scnhdr
.s_nreloc
+= 1;
4206 memset (&syment
, 0, sizeof (struct internal_syment
));
4207 memset (&auxent
, 0, sizeof (union internal_auxent
));
4211 syment
._n
._n_n
._n_offset
= st_tmp
- string_table
;
4212 memcpy (st_tmp
, fini
, finisz
);
4216 memcpy (syment
._n
._n_name
, fini
, finisz
- 1);
4218 syment
.n_sclass
= C_EXT
;
4219 syment
.n_numaux
= 1;
4220 bfd_coff_swap_sym_out (abfd
, &syment
,
4221 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
4222 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
4224 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
4227 memset (&reloc
, 0, sizeof (struct internal_reloc
));
4228 reloc
.r_vaddr
= 0x0028;
4229 reloc
.r_symndx
= filehdr
.f_nsyms
;
4230 reloc
.r_type
= R_POS
;
4232 bfd_coff_swap_reloc_out (abfd
, &reloc
,
4233 &reloc_ext
[scnhdr
.s_nreloc
* RELSZ
]);
4235 filehdr
.f_nsyms
+= 2;
4236 scnhdr
.s_nreloc
+= 1;
4241 memset (&syment
, 0, sizeof (struct internal_syment
));
4242 memset (&auxent
, 0, sizeof (union internal_auxent
));
4243 memcpy (syment
._n
._n_name
, rtld_name
, strlen (rtld_name
));
4244 syment
.n_sclass
= C_EXT
;
4245 syment
.n_numaux
= 1;
4246 bfd_coff_swap_sym_out (abfd
, &syment
,
4247 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
4248 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
4250 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
4253 memset (&reloc
, 0, sizeof (struct internal_reloc
));
4254 reloc
.r_vaddr
= 0x0000;
4255 reloc
.r_symndx
= filehdr
.f_nsyms
;
4256 reloc
.r_type
= R_POS
;
4258 bfd_coff_swap_reloc_out (abfd
, &reloc
,
4259 &reloc_ext
[scnhdr
.s_nreloc
* RELSZ
]);
4261 filehdr
.f_nsyms
+= 2;
4262 scnhdr
.s_nreloc
+= 1;
4265 scnhdr
.s_relptr
= scnhdr
.s_scnptr
+ data_buffer_size
;
4266 filehdr
.f_symptr
= scnhdr
.s_relptr
+ scnhdr
.s_nreloc
* RELSZ
;
4268 bfd_coff_swap_filehdr_out (abfd
, &filehdr
, filehdr_ext
);
4269 bfd_bwrite (filehdr_ext
, FILHSZ
, abfd
);
4270 bfd_coff_swap_scnhdr_out (abfd
, &scnhdr
, scnhdr_ext
);
4271 bfd_bwrite (scnhdr_ext
, SCNHSZ
, abfd
);
4272 bfd_bwrite (data_buffer
, data_buffer_size
, abfd
);
4273 bfd_bwrite (reloc_ext
, scnhdr
.s_nreloc
* RELSZ
, abfd
);
4274 bfd_bwrite (syment_ext
, filehdr
.f_nsyms
* SYMESZ
, abfd
);
4275 bfd_bwrite (string_table
, string_table_size
, abfd
);
4284 static reloc_howto_type xcoff_dynamic_reloc
=
4285 HOWTO (0, /* type */
4289 false, /* pc_relative */
4291 complain_overflow_bitfield
, /* complain_on_overflow */
4292 0, /* special_function */
4294 true, /* partial_inplace */
4295 0xffffffff, /* src_mask */
4296 0xffffffff, /* dst_mask */
4297 false); /* pcrel_offset */
4299 /* Indirect call stub
4300 The first word of the code must be modified by filling in
4301 the correct TOC offset. */
4303 static const unsigned long xcoff_stub_indirect_call_code
[4] =
4305 0x81820000, /* lwz r12,0(r2) */
4306 0x800c0000, /* lwz r0,0(r12) */
4307 0x7c0903a6, /* mtctr r0 */
4308 0x4e800420, /* bctr */
4312 The first word of the code must be modified by filling in
4313 the correct TOC offset.
4314 This is exactly as the glink code but without the traceback,
4315 as it won't be an independent function. */
4317 static const unsigned long xcoff_stub_shared_call_code
[6] =
4319 0x81820000, /* lwz r12,0(r2) */
4320 0x90410014, /* stw r2,20(r1) */
4321 0x800c0000, /* lwz r0,0(r12) */
4322 0x804c0004, /* lwz r2,4(r12) */
4323 0x7c0903a6, /* mtctr r0 */
4324 0x4e800420, /* bctr */
4329 The first word of global linkage code must be modified by filling in
4330 the correct TOC offset. */
4332 static const unsigned long xcoff_glink_code
[9] =
4334 0x81820000, /* lwz r12,0(r2) */
4335 0x90410014, /* stw r2,20(r1) */
4336 0x800c0000, /* lwz r0,0(r12) */
4337 0x804c0004, /* lwz r2,4(r12) */
4338 0x7c0903a6, /* mtctr r0 */
4339 0x4e800420, /* bctr */
4340 0x00000000, /* start of traceback table */
4341 0x000c8000, /* traceback table */
4342 0x00000000, /* traceback table */
4345 /* Table to convert DWARF flags to section names.
4346 Remember to update binutils/dwarf.c:debug_displays
4347 if new DWARF sections are supported by XCOFF. */
4349 const struct xcoff_dwsect_name xcoff_dwsect_names
[] = {
4350 { SSUBTYP_DWINFO
, ".dwinfo", ".debug_info", true },
4351 { SSUBTYP_DWLINE
, ".dwline", ".debug_line", true },
4352 { SSUBTYP_DWPBNMS
, ".dwpbnms", ".debug_pubnames", true },
4353 { SSUBTYP_DWPBTYP
, ".dwpbtyp", ".debug_pubtypes", true },
4354 { SSUBTYP_DWARNGE
, ".dwarnge", ".debug_aranges", true },
4355 { SSUBTYP_DWABREV
, ".dwabrev", ".debug_abbrev", false },
4356 { SSUBTYP_DWSTR
, ".dwstr", ".debug_str", true },
4357 { SSUBTYP_DWRNGES
, ".dwrnges", ".debug_ranges", true },
4358 { SSUBTYP_DWLOC
, ".dwloc", ".debug_loc", true },
4359 { SSUBTYP_DWFRAME
, ".dwframe", ".debug_frame", true },
4360 { SSUBTYP_DWMAC
, ".dwmac", ".debug_macro", true }
4363 /* For generic entry points. */
4364 #define _bfd_xcoff_close_and_cleanup _bfd_coff_close_and_cleanup
4365 #define _bfd_xcoff_bfd_free_cached_info _bfd_bool_bfd_true
4366 #define _bfd_xcoff_new_section_hook coff_new_section_hook
4367 #define _bfd_xcoff_get_section_contents _bfd_generic_get_section_contents
4368 #define _bfd_xcoff_get_section_contents_in_window \
4369 _bfd_generic_get_section_contents_in_window
4371 /* For copy private data entry points. */
4372 #define _bfd_xcoff_bfd_copy_private_bfd_data \
4373 _bfd_xcoff_copy_private_bfd_data
4374 #define _bfd_xcoff_bfd_merge_private_bfd_data \
4375 _bfd_generic_bfd_merge_private_bfd_data
4376 #define _bfd_xcoff_bfd_copy_private_section_data \
4377 _bfd_generic_bfd_copy_private_section_data
4378 #define _bfd_xcoff_bfd_copy_private_symbol_data \
4379 _bfd_generic_bfd_copy_private_symbol_data
4380 #define _bfd_xcoff_bfd_copy_private_header_data \
4381 _bfd_generic_bfd_copy_private_header_data
4382 #define _bfd_xcoff_bfd_set_private_flags \
4383 _bfd_generic_bfd_set_private_flags
4384 #define _bfd_xcoff_bfd_print_private_bfd_data \
4385 _bfd_generic_bfd_print_private_bfd_data
4387 /* For archive entry points. */
4388 #define _bfd_xcoff_slurp_extended_name_table \
4389 _bfd_noarchive_slurp_extended_name_table
4390 #define _bfd_xcoff_construct_extended_name_table \
4391 _bfd_noarchive_construct_extended_name_table
4392 #define _bfd_xcoff_truncate_arname bfd_dont_truncate_arname
4393 #define _bfd_xcoff_write_ar_hdr _bfd_generic_write_ar_hdr
4394 #define _bfd_xcoff_get_elt_at_index _bfd_generic_get_elt_at_index
4395 #define _bfd_xcoff_generic_stat_arch_elt _bfd_xcoff_stat_arch_elt
4396 #define _bfd_xcoff_update_armap_timestamp _bfd_bool_bfd_true
4398 /* For symbols entry points. */
4399 #define _bfd_xcoff_get_symtab_upper_bound coff_get_symtab_upper_bound
4400 #define _bfd_xcoff_canonicalize_symtab coff_canonicalize_symtab
4401 #define _bfd_xcoff_make_empty_symbol coff_make_empty_symbol
4402 #define _bfd_xcoff_print_symbol coff_print_symbol
4403 #define _bfd_xcoff_get_symbol_info coff_get_symbol_info
4404 #define _bfd_xcoff_get_symbol_version_string \
4405 _bfd_nosymbols_get_symbol_version_string
4406 #define _bfd_xcoff_bfd_is_local_label_name _bfd_xcoff_is_local_label_name
4407 #define _bfd_xcoff_bfd_is_target_special_symbol \
4408 coff_bfd_is_target_special_symbol
4409 #define _bfd_xcoff_get_lineno coff_get_lineno
4410 #define _bfd_xcoff_find_nearest_line coff_find_nearest_line
4411 #define _bfd_xcoff_find_nearest_line_with_alt \
4412 coff_find_nearest_line_with_alt
4413 #define _bfd_xcoff_find_line coff_find_line
4414 #define _bfd_xcoff_find_inliner_info coff_find_inliner_info
4415 #define _bfd_xcoff_bfd_make_debug_symbol coff_bfd_make_debug_symbol
4416 #define _bfd_xcoff_read_minisymbols _bfd_generic_read_minisymbols
4417 #define _bfd_xcoff_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
4419 /* For reloc entry points. */
4420 #define _bfd_xcoff_get_reloc_upper_bound coff_get_reloc_upper_bound
4421 #define _bfd_xcoff_canonicalize_reloc coff_canonicalize_reloc
4422 #define _bfd_xcoff_set_reloc _bfd_generic_set_reloc
4423 #define _bfd_xcoff_bfd_reloc_type_lookup _bfd_xcoff_reloc_type_lookup
4424 #define _bfd_xcoff_bfd_reloc_name_lookup _bfd_xcoff_reloc_name_lookup
4426 /* For link entry points. */
4427 #define _bfd_xcoff_bfd_get_relocated_section_contents \
4428 bfd_generic_get_relocated_section_contents
4429 #define _bfd_xcoff_bfd_relax_section bfd_generic_relax_section
4430 #define _bfd_xcoff_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
4431 #define _bfd_xcoff_bfd_link_just_syms _bfd_generic_link_just_syms
4432 #define _bfd_xcoff_bfd_copy_link_hash_symbol_type \
4433 _bfd_generic_copy_link_hash_symbol_type
4434 #define _bfd_xcoff_bfd_link_split_section _bfd_generic_link_split_section
4435 #define _bfd_xcoff_bfd_gc_sections bfd_generic_gc_sections
4436 #define _bfd_xcoff_bfd_lookup_section_flags bfd_generic_lookup_section_flags
4437 #define _bfd_xcoff_bfd_merge_sections bfd_generic_merge_sections
4438 #define _bfd_xcoff_bfd_is_group_section bfd_generic_is_group_section
4439 #define _bfd_xcoff_bfd_group_name bfd_generic_group_name
4440 #define _bfd_xcoff_bfd_discard_group bfd_generic_discard_group
4441 #define _bfd_xcoff_section_already_linked _bfd_generic_section_already_linked
4442 #define _bfd_xcoff_bfd_define_common_symbol _bfd_xcoff_define_common_symbol
4443 #define _bfd_xcoff_bfd_link_hide_symbol _bfd_generic_link_hide_symbol
4444 #define _bfd_xcoff_bfd_define_start_stop bfd_generic_define_start_stop
4445 #define _bfd_xcoff_bfd_link_check_relocs _bfd_generic_link_check_relocs
4447 /* For dynamic symbols and relocs entry points. */
4448 #define _bfd_xcoff_get_synthetic_symtab _bfd_nodynamic_get_synthetic_symtab
4450 static const struct xcoff_backend_data_rec bfd_xcoff_backend_data
=
4452 { /* COFF backend, defined in libcoff.h. */
4453 _bfd_xcoff_swap_aux_in
,
4454 _bfd_xcoff_swap_sym_in
,
4455 coff_swap_lineno_in
,
4456 _bfd_xcoff_swap_aux_out
,
4457 _bfd_xcoff_swap_sym_out
,
4458 coff_swap_lineno_out
,
4459 xcoff_swap_reloc_out
,
4460 coff_swap_filehdr_out
,
4461 coff_swap_aouthdr_out
,
4462 coff_swap_scnhdr_out
,
4471 true, /* _bfd_coff_long_filenames */
4472 XCOFF_NO_LONG_SECTION_NAMES
, /* _bfd_coff_long_section_names */
4473 3, /* _bfd_coff_default_section_alignment_power */
4474 false, /* _bfd_coff_force_symnames_in_strings */
4475 2, /* _bfd_coff_debug_string_prefix_length */
4476 32768, /* _bfd_coff_max_nscns */
4477 coff_swap_filehdr_in
,
4478 coff_swap_aouthdr_in
,
4479 coff_swap_scnhdr_in
,
4480 xcoff_swap_reloc_in
,
4481 coff_bad_format_hook
,
4482 coff_set_arch_mach_hook
,
4485 coff_set_alignment_hook
,
4486 coff_slurp_symbol_table
,
4487 symname_in_debug_hook
,
4488 coff_pointerize_aux_hook
,
4490 dummy_reloc16_extra_cases
,
4491 dummy_reloc16_estimate
,
4492 NULL
, /* bfd_coff_sym_is_global */
4493 coff_compute_section_file_positions
,
4494 NULL
, /* _bfd_coff_start_final_link */
4495 xcoff_ppc_relocate_section
,
4496 coff_rtype_to_howto
,
4497 NULL
, /* _bfd_coff_adjust_symndx */
4498 _bfd_generic_link_add_one_symbol
,
4499 coff_link_output_has_begun
,
4500 coff_final_link_postscript
,
4501 NULL
/* print_pdata. */
4504 0x01DF, /* magic number */
4508 /* Function pointers to xcoff specific swap routines. */
4509 xcoff_swap_ldhdr_in
,
4510 xcoff_swap_ldhdr_out
,
4511 xcoff_swap_ldsym_in
,
4512 xcoff_swap_ldsym_out
,
4513 xcoff_swap_ldrel_in
,
4514 xcoff_swap_ldrel_out
,
4520 12, /* _xcoff_function_descriptor_size */
4524 1, /* _xcoff_ldhdr_version */
4526 _bfd_xcoff_put_symbol_name
,
4527 _bfd_xcoff_put_ldsymbol_name
,
4528 &xcoff_dynamic_reloc
,
4529 xcoff_create_csect_from_smclas
,
4531 /* Lineno and reloc count overflow. */
4532 xcoff_is_lineno_count_overflow
,
4533 xcoff_is_reloc_count_overflow
,
4535 xcoff_loader_symbol_offset
,
4536 xcoff_loader_reloc_offset
,
4539 &xcoff_glink_code
[0],
4540 36, /* _xcoff_glink_size */
4543 64, /* _xcoff_rtinit_size */
4544 xcoff_generate_rtinit
,
4546 /* Stub indirect call. */
4547 &xcoff_stub_indirect_call_code
[0],
4548 16, /* _xcoff_stub_indirect_call_size */
4550 /* Stub shared call. */
4551 &xcoff_stub_shared_call_code
[0],
4552 24, /* _xcoff_stub_shared_call_size */
4555 /* The transfer vector that leads the outside world to all of the above. */
4556 const bfd_target rs6000_xcoff_vec
=
4559 bfd_target_xcoff_flavour
,
4560 BFD_ENDIAN_BIG
, /* data byte order is big */
4561 BFD_ENDIAN_BIG
, /* header byte order is big */
4563 (HAS_RELOC
| EXEC_P
| HAS_LINENO
| HAS_DEBUG
| DYNAMIC
4564 | HAS_SYMS
| HAS_LOCALS
| WP_TEXT
),
4566 SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_CODE
| SEC_DATA
,
4567 0, /* leading char */
4568 '/', /* ar_pad_char */
4569 15, /* ar_max_namelen */
4570 0, /* match priority. */
4571 TARGET_KEEP_UNUSED_SECTION_SYMBOLS
, /* keep unused section symbols. */
4595 { /* bfd_check_format */
4598 _bfd_xcoff_archive_p
,
4602 { /* bfd_set_format */
4603 _bfd_bool_bfd_false_error
,
4605 _bfd_generic_mkarchive
,
4606 _bfd_bool_bfd_false_error
4609 {/* bfd_write_contents */
4610 _bfd_bool_bfd_false_error
,
4611 coff_write_object_contents
,
4612 _bfd_xcoff_write_archive_contents
,
4613 _bfd_bool_bfd_false_error
4616 BFD_JUMP_TABLE_GENERIC (_bfd_xcoff
),
4617 BFD_JUMP_TABLE_COPY (_bfd_xcoff
),
4618 BFD_JUMP_TABLE_CORE (coff
),
4619 BFD_JUMP_TABLE_ARCHIVE (_bfd_xcoff
),
4620 BFD_JUMP_TABLE_SYMBOLS (_bfd_xcoff
),
4621 BFD_JUMP_TABLE_RELOCS (_bfd_xcoff
),
4622 BFD_JUMP_TABLE_WRITE (coff
),
4623 BFD_JUMP_TABLE_LINK (_bfd_xcoff
),
4624 BFD_JUMP_TABLE_DYNAMIC (_bfd_xcoff
),
4626 /* Opposite endian version, none exists */
4629 & bfd_xcoff_backend_data
,
4632 /* xcoff-powermac target
4634 Only difference between this target and the rs6000 target is the
4635 the default architecture and machine type used in coffcode.h
4637 PowerPC Macs use the same magic numbers as RS/6000
4638 (because that's how they were bootstrapped originally),
4639 but they are always PowerPC architecture. */
4640 static const struct xcoff_backend_data_rec bfd_pmac_xcoff_backend_data
=
4642 { /* COFF backend, defined in libcoff.h. */
4643 _bfd_xcoff_swap_aux_in
,
4644 _bfd_xcoff_swap_sym_in
,
4645 coff_swap_lineno_in
,
4646 _bfd_xcoff_swap_aux_out
,
4647 _bfd_xcoff_swap_sym_out
,
4648 coff_swap_lineno_out
,
4649 xcoff_swap_reloc_out
,
4650 coff_swap_filehdr_out
,
4651 coff_swap_aouthdr_out
,
4652 coff_swap_scnhdr_out
,
4661 true, /* _bfd_coff_long_filenames */
4662 XCOFF_NO_LONG_SECTION_NAMES
, /* _bfd_coff_long_section_names */
4663 3, /* _bfd_coff_default_section_alignment_power */
4664 false, /* _bfd_coff_force_symnames_in_strings */
4665 2, /* _bfd_coff_debug_string_prefix_length */
4666 32768, /* _bfd_coff_max_nscns */
4667 coff_swap_filehdr_in
,
4668 coff_swap_aouthdr_in
,
4669 coff_swap_scnhdr_in
,
4670 xcoff_swap_reloc_in
,
4671 coff_bad_format_hook
,
4672 coff_set_arch_mach_hook
,
4675 coff_set_alignment_hook
,
4676 coff_slurp_symbol_table
,
4677 symname_in_debug_hook
,
4678 coff_pointerize_aux_hook
,
4680 dummy_reloc16_extra_cases
,
4681 dummy_reloc16_estimate
,
4682 NULL
, /* bfd_coff_sym_is_global */
4683 coff_compute_section_file_positions
,
4684 NULL
, /* _bfd_coff_start_final_link */
4685 xcoff_ppc_relocate_section
,
4686 coff_rtype_to_howto
,
4687 NULL
, /* _bfd_coff_adjust_symndx */
4688 _bfd_generic_link_add_one_symbol
,
4689 coff_link_output_has_begun
,
4690 coff_final_link_postscript
,
4691 NULL
/* print_pdata. */
4694 0x01DF, /* magic number */
4698 /* Function pointers to xcoff specific swap routines. */
4699 xcoff_swap_ldhdr_in
,
4700 xcoff_swap_ldhdr_out
,
4701 xcoff_swap_ldsym_in
,
4702 xcoff_swap_ldsym_out
,
4703 xcoff_swap_ldrel_in
,
4704 xcoff_swap_ldrel_out
,
4710 12, /* _xcoff_function_descriptor_size */
4714 1, /* _xcoff_ldhdr_version */
4716 _bfd_xcoff_put_symbol_name
,
4717 _bfd_xcoff_put_ldsymbol_name
,
4718 &xcoff_dynamic_reloc
,
4719 xcoff_create_csect_from_smclas
,
4721 /* Lineno and reloc count overflow. */
4722 xcoff_is_lineno_count_overflow
,
4723 xcoff_is_reloc_count_overflow
,
4725 xcoff_loader_symbol_offset
,
4726 xcoff_loader_reloc_offset
,
4729 &xcoff_glink_code
[0],
4730 36, /* _xcoff_glink_size */
4733 0, /* _xcoff_rtinit_size */
4734 xcoff_generate_rtinit
,
4736 /* Stub indirect call. */
4737 &xcoff_stub_indirect_call_code
[0],
4738 16, /* _xcoff_stub_indirect_call_size */
4740 /* Stub shared call. */
4741 &xcoff_stub_shared_call_code
[0],
4742 24, /* _xcoff_stub_shared_call_size */
4745 /* The transfer vector that leads the outside world to all of the above. */
4746 const bfd_target powerpc_xcoff_vec
=
4749 bfd_target_xcoff_flavour
,
4750 BFD_ENDIAN_BIG
, /* data byte order is big */
4751 BFD_ENDIAN_BIG
, /* header byte order is big */
4753 (HAS_RELOC
| EXEC_P
| HAS_LINENO
| HAS_DEBUG
| DYNAMIC
4754 | HAS_SYMS
| HAS_LOCALS
| WP_TEXT
),
4756 SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_CODE
| SEC_DATA
,
4757 0, /* leading char */
4758 '/', /* ar_pad_char */
4759 15, /* ar_max_namelen */
4760 0, /* match priority. */
4761 TARGET_KEEP_UNUSED_SECTION_SYMBOLS
, /* keep unused section symbols. */
4785 { /* bfd_check_format */
4788 _bfd_xcoff_archive_p
,
4792 { /* bfd_set_format */
4793 _bfd_bool_bfd_false_error
,
4795 _bfd_generic_mkarchive
,
4796 _bfd_bool_bfd_false_error
4799 {/* bfd_write_contents */
4800 _bfd_bool_bfd_false_error
,
4801 coff_write_object_contents
,
4802 _bfd_xcoff_write_archive_contents
,
4803 _bfd_bool_bfd_false_error
4806 BFD_JUMP_TABLE_GENERIC (_bfd_xcoff
),
4807 BFD_JUMP_TABLE_COPY (_bfd_xcoff
),
4808 BFD_JUMP_TABLE_CORE (coff
),
4809 BFD_JUMP_TABLE_ARCHIVE (_bfd_xcoff
),
4810 BFD_JUMP_TABLE_SYMBOLS (_bfd_xcoff
),
4811 BFD_JUMP_TABLE_RELOCS (_bfd_xcoff
),
4812 BFD_JUMP_TABLE_WRITE (coff
),
4813 BFD_JUMP_TABLE_LINK (_bfd_xcoff
),
4814 BFD_JUMP_TABLE_DYNAMIC (_bfd_xcoff
),
4816 /* Opposite endian version, none exists */
4819 & bfd_pmac_xcoff_backend_data
,