1 /* BFD back-end for IBM RS/6000 "XCOFF" files.
2 Copyright (C) 1990-2021 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
);
392 ox
->sntoc
= sec
->output_section
->target_index
;
394 if (ix
->snentry
== 0)
398 sec
= coff_section_from_bfd_index (ibfd
, ix
->snentry
);
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_zeroes
= 0;
493 in
->x_file
.x_n
.x_offset
=
494 H_GET_32 (abfd
, ext
->x_file
.x_n
.x_n
.x_offset
);
497 memcpy (in
->x_file
.x_fname
, ext
->x_file
.x_n
.x_fname
, FILNMLEN
);
500 /* RS/6000 "csect" auxents.
501 There is always a CSECT auxiliary entry. But functions can
502 have FCN ones too. In this case, CSECT is always the last
507 if (indx
+ 1 == numaux
)
509 in
->x_csect
.x_scnlen
.l
= H_GET_32 (abfd
, ext
->x_csect
.x_scnlen
);
510 in
->x_csect
.x_parmhash
= H_GET_32 (abfd
, ext
->x_csect
.x_parmhash
);
511 in
->x_csect
.x_snhash
= H_GET_16 (abfd
, ext
->x_csect
.x_snhash
);
512 /* We don't have to hack bitfields in x_smtyp because it's
513 defined by shifts-and-ands, which are equivalent on all
515 in
->x_csect
.x_smtyp
= H_GET_8 (abfd
, ext
->x_csect
.x_smtyp
);
516 in
->x_csect
.x_smclas
= H_GET_8 (abfd
, ext
->x_csect
.x_smclas
);
517 in
->x_csect
.x_stab
= H_GET_32 (abfd
, ext
->x_csect
.x_stab
);
518 in
->x_csect
.x_snstab
= H_GET_16 (abfd
, ext
->x_csect
.x_snstab
);
522 /* x_exptr isn't supported. */
523 in
->x_sym
.x_misc
.x_fsize
524 = H_GET_32 (abfd
, ext
->x_fcn
.x_fsize
);
525 in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
526 = H_GET_32 (abfd
, ext
->x_fcn
.x_lnnoptr
);
527 in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
528 = H_GET_32 (abfd
, ext
->x_fcn
.x_endndx
);
533 in
->x_scn
.x_scnlen
= H_GET_32 (abfd
, ext
->x_scn
.x_scnlen
);
534 in
->x_scn
.x_nreloc
= H_GET_16 (abfd
, ext
->x_scn
.x_nreloc
);
535 in
->x_scn
.x_nlinno
= H_GET_16 (abfd
, ext
->x_scn
.x_nlinno
);
536 /* PE defines some extra fields; we zero them out for
538 in
->x_scn
.x_checksum
= 0;
539 in
->x_scn
.x_associated
= 0;
540 in
->x_scn
.x_comdat
= 0;
545 in
->x_sym
.x_misc
.x_lnsz
.x_lnno
546 = H_GET_32 (abfd
, ext
->x_sym
.x_lnno
);
550 in
->x_sect
.x_scnlen
= H_GET_32 (abfd
, ext
->x_sect
.x_scnlen
);
551 in
->x_sect
.x_nreloc
= H_GET_32 (abfd
, ext
->x_sect
.x_nreloc
);
558 _bfd_xcoff_swap_aux_out (bfd
*abfd
, void * inp
, int type ATTRIBUTE_UNUSED
,
559 int in_class
, int indx
, int numaux
, void * extp
)
561 union internal_auxent
*in
= (union internal_auxent
*)inp
;
562 AUXENT
*ext
= (AUXENT
*)extp
;
564 memset (ext
, 0, bfd_coff_auxesz (abfd
));
569 /* xgettext: c-format */
570 (_("%pB: unsupported swap_aux_out for storage class %#x"),
571 abfd
, (unsigned int) in_class
);
572 bfd_set_error (bfd_error_bad_value
);
576 if (in
->x_file
.x_fname
[0] == 0)
578 H_PUT_32 (abfd
, 0, ext
->x_file
.x_n
.x_n
.x_zeroes
);
579 H_PUT_32 (abfd
, in
->x_file
.x_n
.x_offset
,
580 ext
->x_file
.x_n
.x_n
.x_offset
);
583 memcpy (ext
->x_file
.x_n
.x_fname
, in
->x_file
.x_fname
, FILNMLEN
);
586 /* RS/6000 "csect" auxents */
590 if (indx
+ 1 == numaux
)
592 H_PUT_32 (abfd
, in
->x_csect
.x_scnlen
.l
, ext
->x_csect
.x_scnlen
);
593 H_PUT_32 (abfd
, in
->x_csect
.x_parmhash
, ext
->x_csect
.x_parmhash
);
594 H_PUT_16 (abfd
, in
->x_csect
.x_snhash
, ext
->x_csect
.x_snhash
);
595 /* We don't have to hack bitfields in x_smtyp because it's
596 defined by shifts-and-ands, which are equivalent on all
598 H_PUT_8 (abfd
, in
->x_csect
.x_smtyp
, ext
->x_csect
.x_smtyp
);
599 H_PUT_8 (abfd
, in
->x_csect
.x_smclas
, ext
->x_csect
.x_smclas
);
600 H_PUT_32 (abfd
, in
->x_csect
.x_stab
, ext
->x_csect
.x_stab
);
601 H_PUT_16 (abfd
, in
->x_csect
.x_snstab
, ext
->x_csect
.x_snstab
);
605 H_PUT_32 (abfd
, in
->x_sym
.x_misc
.x_fsize
, ext
->x_fcn
.x_fsize
);
606 H_PUT_32 (abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
,
607 ext
->x_fcn
.x_lnnoptr
);
608 H_PUT_32 (abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
,
609 ext
->x_fcn
.x_endndx
);
614 H_PUT_32 (abfd
, in
->x_scn
.x_scnlen
, ext
->x_scn
.x_scnlen
);
615 H_PUT_16 (abfd
, in
->x_scn
.x_nreloc
, ext
->x_scn
.x_nreloc
);
616 H_PUT_16 (abfd
, in
->x_scn
.x_nlinno
, ext
->x_scn
.x_nlinno
);
621 H_PUT_32 (abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_lnno
, ext
->x_sym
.x_lnno
);
625 H_PUT_32 (abfd
, in
->x_sect
.x_scnlen
, ext
->x_sect
.x_scnlen
);
626 H_PUT_32 (abfd
, in
->x_sect
.x_nreloc
, ext
->x_sect
.x_nreloc
);
630 return bfd_coff_auxesz (abfd
);
633 /* The XCOFF reloc table.
634 XCOFF relocations aren't defined only by the type field r_type.
635 The bitsize and whether they are signed or not, are defined by
636 r_size field. Thus, it's complicated to create a constant
637 table reference every possible relocation.
638 This table contains the "default" relocation and few modified
639 relocations what were already there. It's enough when
640 xcoff_rtype2howto is called.
641 For relocations from an input bfd to an output bfd, the default
642 relocation is retrieved and when manually adapted.
644 For now, it seems to be enought. */
646 reloc_howto_type xcoff_howto_table
[] =
648 /* 0x00: Standard 32 bit relocation. */
649 HOWTO (R_POS
, /* type */
651 2, /* size (0 = byte, 1 = short, 2 = long) */
653 false, /* pc_relative */
655 complain_overflow_bitfield
, /* complain_on_overflow */
656 0, /* special_function */
658 true, /* partial_inplace */
659 0xffffffff, /* src_mask */
660 0xffffffff, /* dst_mask */
661 false), /* pcrel_offset */
663 /* 0x01: 32 bit relocation, but store negative value. */
664 HOWTO (R_NEG
, /* type */
666 -2, /* size (0 = byte, 1 = short, 2 = long) */
668 false, /* pc_relative */
670 complain_overflow_bitfield
, /* complain_on_overflow */
671 0, /* special_function */
673 true, /* partial_inplace */
674 0xffffffff, /* src_mask */
675 0xffffffff, /* dst_mask */
676 false), /* pcrel_offset */
678 /* 0x02: 32 bit PC relative relocation. */
679 HOWTO (R_REL
, /* type */
681 2, /* size (0 = byte, 1 = short, 2 = long) */
683 true, /* pc_relative */
685 complain_overflow_signed
, /* complain_on_overflow */
686 0, /* special_function */
688 true, /* partial_inplace */
689 0xffffffff, /* src_mask */
690 0xffffffff, /* dst_mask */
691 false), /* pcrel_offset */
693 /* 0x03: 16 bit TOC relative relocation. */
694 HOWTO (R_TOC
, /* type */
696 1, /* size (0 = byte, 1 = short, 2 = long) */
698 false, /* pc_relative */
700 complain_overflow_bitfield
, /* complain_on_overflow */
701 0, /* special_function */
703 true, /* partial_inplace */
705 0xffff, /* dst_mask */
706 false), /* pcrel_offset */
708 /* 0x04: Same as R_TOC */
709 HOWTO (R_TRL
, /* type */
711 1, /* size (0 = byte, 1 = short, 2 = long) */
713 false, /* pc_relative */
715 complain_overflow_bitfield
, /* complain_on_overflow */
716 0, /* special_function */
718 true, /* partial_inplace */
720 0xffff, /* dst_mask */
721 false), /* pcrel_offset */
723 /* 0x05: External TOC relative symbol. */
724 HOWTO (R_GL
, /* type */
726 1, /* size (0 = byte, 1 = short, 2 = long) */
728 false, /* pc_relative */
730 complain_overflow_bitfield
, /* complain_on_overflow */
731 0, /* special_function */
733 true, /* partial_inplace */
735 0xffff, /* dst_mask */
736 false), /* pcrel_offset */
738 /* 0x06: Local TOC relative symbol. */
739 HOWTO (R_TCL
, /* type */
741 1, /* size (0 = byte, 1 = short, 2 = long) */
743 false, /* pc_relative */
745 complain_overflow_bitfield
, /* complain_on_overflow */
746 0, /* special_function */
748 true, /* partial_inplace */
750 0xffff, /* dst_mask */
751 false), /* pcrel_offset */
755 /* 0x08: Same as R_RBA. */
756 HOWTO (R_BA
, /* type */
758 2, /* size (0 = byte, 1 = short, 2 = long) */
760 false, /* pc_relative */
762 complain_overflow_bitfield
, /* complain_on_overflow */
763 0, /* special_function */
764 "R_BA_26", /* name */
765 true, /* partial_inplace */
766 0x03fffffc, /* src_mask */
767 0x03fffffc, /* dst_mask */
768 false), /* pcrel_offset */
772 /* 0x0a: Same as R_RBR. */
773 HOWTO (R_BR
, /* type */
775 2, /* size (0 = byte, 1 = short, 2 = long) */
777 true, /* pc_relative */
779 complain_overflow_signed
, /* complain_on_overflow */
780 0, /* special_function */
782 true, /* partial_inplace */
783 0x03fffffc, /* src_mask */
784 0x03fffffc, /* dst_mask */
785 false), /* pcrel_offset */
789 /* 0x0c: Same as R_POS. */
790 HOWTO (R_RL
, /* type */
792 2, /* size (0 = byte, 1 = short, 2 = long) */
794 false, /* pc_relative */
796 complain_overflow_bitfield
, /* complain_on_overflow */
797 0, /* special_function */
799 true, /* partial_inplace */
800 0xffffffff, /* src_mask */
801 0xffffffff, /* dst_mask */
802 false), /* pcrel_offset */
804 /* 0x0d: Same as R_POS. */
805 HOWTO (R_RLA
, /* type */
807 2, /* size (0 = byte, 1 = short, 2 = long) */
809 false, /* pc_relative */
811 complain_overflow_bitfield
, /* complain_on_overflow */
812 0, /* special_function */
814 true, /* partial_inplace */
815 0xffffffff, /* src_mask */
816 0xffffffff, /* dst_mask */
817 false), /* pcrel_offset */
821 /* 0x0f: Non-relocating reference. Bitsize is 1 so that r_rsize is 0. */
822 HOWTO (R_REF
, /* type */
824 0, /* size (0 = byte, 1 = short, 2 = long) */
826 false, /* pc_relative */
828 complain_overflow_dont
, /* complain_on_overflow */
829 0, /* special_function */
831 false, /* partial_inplace */
834 false), /* pcrel_offset */
840 /* 0x13: Same as R_TOC. */
841 HOWTO (R_TRLA
, /* type */
843 1, /* size (0 = byte, 1 = short, 2 = long) */
845 false, /* pc_relative */
847 complain_overflow_bitfield
, /* complain_on_overflow */
848 0, /* special_function */
850 true, /* partial_inplace */
852 0xffff, /* dst_mask */
853 false), /* pcrel_offset */
855 /* 0x14: Modifiable relative branch. */
856 HOWTO (R_RRTBI
, /* type */
858 2, /* size (0 = byte, 1 = short, 2 = long) */
860 false, /* pc_relative */
862 complain_overflow_bitfield
, /* complain_on_overflow */
863 0, /* special_function */
864 "R_RRTBI", /* name */
865 true, /* partial_inplace */
866 0xffffffff, /* src_mask */
867 0xffffffff, /* dst_mask */
868 false), /* pcrel_offset */
870 /* 0x15: Modifiable absolute branch. */
871 HOWTO (R_RRTBA
, /* type */
873 2, /* size (0 = byte, 1 = short, 2 = long) */
875 false, /* pc_relative */
877 complain_overflow_bitfield
, /* complain_on_overflow */
878 0, /* special_function */
879 "R_RRTBA", /* name */
880 true, /* partial_inplace */
881 0xffffffff, /* src_mask */
882 0xffffffff, /* dst_mask */
883 false), /* pcrel_offset */
885 /* 0x16: Modifiable call absolute indirect. */
886 HOWTO (R_CAI
, /* type */
888 1, /* size (0 = byte, 1 = short, 2 = long) */
890 false, /* pc_relative */
892 complain_overflow_bitfield
, /* complain_on_overflow */
893 0, /* special_function */
895 true, /* partial_inplace */
896 0xffff, /* src_mask */
897 0xffff, /* dst_mask */
898 false), /* pcrel_offset */
900 /* 0x17: Modifiable call relative. */
901 HOWTO (R_CREL
, /* type */
903 1, /* size (0 = byte, 1 = short, 2 = long) */
905 false, /* pc_relative */
907 complain_overflow_bitfield
, /* complain_on_overflow */
908 0, /* special_function */
910 true, /* partial_inplace */
911 0xffff, /* src_mask */
912 0xffff, /* dst_mask */
913 false), /* pcrel_offset */
915 /* 0x18: Modifiable branch absolute. */
916 HOWTO (R_RBA
, /* type */
918 2, /* size (0 = byte, 1 = short, 2 = long) */
920 false, /* pc_relative */
922 complain_overflow_bitfield
, /* complain_on_overflow */
923 0, /* special_function */
925 true, /* partial_inplace */
926 0x03fffffc, /* src_mask */
927 0x03fffffc, /* dst_mask */
928 false), /* pcrel_offset */
930 /* 0x19: Modifiable branch absolute. */
931 HOWTO (R_RBAC
, /* type */
933 2, /* size (0 = byte, 1 = short, 2 = long) */
935 false, /* pc_relative */
937 complain_overflow_bitfield
, /* complain_on_overflow */
938 0, /* special_function */
940 true, /* partial_inplace */
941 0xffffffff, /* src_mask */
942 0xffffffff, /* dst_mask */
943 false), /* pcrel_offset */
945 /* 0x1a: Modifiable branch relative. */
946 HOWTO (R_RBR
, /* type */
948 2, /* size (0 = byte, 1 = short, 2 = long) */
950 false, /* pc_relative */
952 complain_overflow_signed
, /* complain_on_overflow */
953 0, /* special_function */
954 "R_RBR_26", /* name */
955 true, /* partial_inplace */
956 0x03fffffc, /* src_mask */
957 0x03fffffc, /* dst_mask */
958 false), /* pcrel_offset */
960 /* 0x1b: Modifiable branch absolute. */
961 HOWTO (R_RBRC
, /* type */
963 1, /* size (0 = byte, 1 = short, 2 = long) */
965 false, /* pc_relative */
967 complain_overflow_bitfield
, /* complain_on_overflow */
968 0, /* special_function */
970 true, /* partial_inplace */
971 0xffff, /* src_mask */
972 0xffff, /* dst_mask */
973 false), /* pcrel_offset */
975 /* 0x1c: 16 bit Non modifiable absolute branch. */
976 HOWTO (R_BA
, /* type */
978 1, /* size (0 = byte, 1 = short, 2 = long) */
980 false, /* pc_relative */
982 complain_overflow_bitfield
, /* complain_on_overflow */
983 0, /* special_function */
984 "R_BA_16", /* name */
985 true, /* partial_inplace */
986 0xfffc, /* src_mask */
987 0xfffc, /* dst_mask */
988 false), /* pcrel_offset */
990 /* 0x1d: Modifiable branch relative. */
991 HOWTO (R_RBR
, /* type */
993 1, /* size (0 = byte, 1 = short, 2 = long) */
995 true, /* pc_relative */
997 complain_overflow_signed
, /* complain_on_overflow */
998 0, /* special_function */
999 "R_RBR_16", /* name */
1000 true, /* partial_inplace */
1001 0xfffc, /* src_mask */
1002 0xfffc, /* dst_mask */
1003 false), /* pcrel_offset */
1005 /* 0x1e: Modifiable branch relative. */
1006 HOWTO (R_RBA
, /* type */
1008 1, /* size (0 = byte, 1 = short, 2 = long) */
1010 false, /* pc_relative */
1012 complain_overflow_signed
, /* complain_on_overflow */
1013 0, /* special_function */
1014 "R_RBA_16", /* name */
1015 true, /* partial_inplace */
1016 0xffff, /* src_mask */
1017 0xffff, /* dst_mask */
1018 false), /* pcrel_offset */
1022 /* 0x20: General-dynamic TLS relocation. */
1023 HOWTO (R_TLS
, /* type */
1025 2, /* size (0 = byte, 1 = short, 2 = long) */
1027 false, /* pc_relative */
1029 complain_overflow_bitfield
, /* complain_on_overflow */
1030 0, /* special_function */
1032 true, /* partial_inplace */
1033 0xffffffff, /* src_mask */
1034 0xffffffff, /* dst_mask */
1035 false), /* pcrel_offset */
1037 /* 0x21: Initial-exec TLS relocation. */
1038 HOWTO (R_TLS_IE
, /* type */
1040 2, /* size (0 = byte, 1 = short, 2 = long) */
1042 false, /* pc_relative */
1044 complain_overflow_bitfield
, /* complain_on_overflow */
1045 0, /* special_function */
1046 "R_TLS_IE", /* name */
1047 true, /* partial_inplace */
1048 0xffffffff, /* src_mask */
1049 0xffffffff, /* dst_mask */
1050 false), /* pcrel_offset */
1052 /* 0x22: Local-dynamic TLS relocation. */
1053 HOWTO (R_TLS_LD
, /* type */
1055 2, /* size (0 = byte, 1 = short, 2 = long) */
1057 false, /* pc_relative */
1059 complain_overflow_bitfield
, /* complain_on_overflow */
1060 0, /* special_function */
1061 "R_TLS_LD", /* name */
1062 true, /* partial_inplace */
1063 0xffffffff, /* src_mask */
1064 0xffffffff, /* dst_mask */
1065 false), /* pcrel_offset */
1067 /* 0x23: Local-exec TLS relocation. */
1068 HOWTO (R_TLS_LE
, /* type */
1070 2, /* size (0 = byte, 1 = short, 2 = long) */
1072 false, /* pc_relative */
1074 complain_overflow_bitfield
, /* complain_on_overflow */
1075 0, /* special_function */
1076 "R_TLS_LE", /* name */
1077 true, /* partial_inplace */
1078 0xffffffff, /* src_mask */
1079 0xffffffff, /* dst_mask */
1080 false), /* pcrel_offset */
1082 /* 0x24: TLS relocation. */
1083 HOWTO (R_TLSM
, /* type */
1085 2, /* size (0 = byte, 1 = short, 2 = long) */
1087 false, /* pc_relative */
1089 complain_overflow_bitfield
, /* complain_on_overflow */
1090 0, /* special_function */
1091 "R_TLSM", /* name */
1092 true, /* partial_inplace */
1093 0xffffffff, /* src_mask */
1094 0xffffffff, /* dst_mask */
1095 false), /* pcrel_offset */
1098 /* 0x25: TLS module relocation. */
1099 HOWTO (R_TLSML
, /* type */
1101 2, /* size (0 = byte, 1 = short, 2 = long) */
1103 false, /* pc_relative */
1105 complain_overflow_bitfield
, /* complain_on_overflow */
1106 0, /* special_function */
1107 "R_TLSM", /* name */
1108 true, /* partial_inplace */
1109 0xffffffff, /* src_mask */
1110 0xffffffff, /* dst_mask */
1111 false), /* pcrel_offset */
1124 /* 0x30: High-order 16 bit TOC relative relocation. */
1125 HOWTO (R_TOCU
, /* type */
1126 16, /* rightshift */
1127 1, /* size (0 = byte, 1 = short, 2 = long) */
1129 false, /* pc_relative */
1131 complain_overflow_bitfield
, /* complain_on_overflow */
1132 0, /* special_function */
1133 "R_TOCU", /* name */
1134 true, /* partial_inplace */
1136 0xffff, /* dst_mask */
1137 false), /* pcrel_offset */
1139 /* 0x31: Low-order 16 bit TOC relative relocation. */
1140 HOWTO (R_TOCL
, /* type */
1142 1, /* size (0 = byte, 1 = short, 2 = long) */
1144 false, /* pc_relative */
1146 complain_overflow_dont
, /* complain_on_overflow */
1147 0, /* special_function */
1148 "R_TOCL", /* name */
1149 true, /* partial_inplace */
1151 0xffff, /* dst_mask */
1152 false), /* pcrel_offset */
1157 xcoff_rtype2howto (arelent
*relent
, struct internal_reloc
*internal
)
1159 if (internal
->r_type
> R_TOCL
)
1162 /* Default howto layout works most of the time */
1163 relent
->howto
= &xcoff_howto_table
[internal
->r_type
];
1165 /* Special case some 16 bit reloc */
1166 if (15 == (internal
->r_size
& 0x1f))
1168 if (R_BA
== internal
->r_type
)
1169 relent
->howto
= &xcoff_howto_table
[0x1c];
1170 else if (R_RBR
== internal
->r_type
)
1171 relent
->howto
= &xcoff_howto_table
[0x1d];
1172 else if (R_RBA
== internal
->r_type
)
1173 relent
->howto
= &xcoff_howto_table
[0x1e];
1176 /* The r_size field of an XCOFF reloc encodes the bitsize of the
1177 relocation, as well as indicating whether it is signed or not.
1178 Doublecheck that the relocation information gathered from the
1179 type matches this information. The bitsize is not significant
1180 for R_REF relocs. */
1181 if (relent
->howto
->dst_mask
!= 0
1182 && (relent
->howto
->bitsize
1183 != ((unsigned int) internal
->r_size
& 0x1f) + 1))
1188 _bfd_xcoff_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1189 bfd_reloc_code_real_type code
)
1193 case BFD_RELOC_PPC_B26
:
1194 return &xcoff_howto_table
[0xa];
1195 case BFD_RELOC_PPC_BA16
:
1196 return &xcoff_howto_table
[0x1c];
1197 case BFD_RELOC_PPC_BA26
:
1198 return &xcoff_howto_table
[8];
1199 case BFD_RELOC_PPC_TOC16
:
1200 return &xcoff_howto_table
[3];
1201 case BFD_RELOC_PPC_TOC16_HI
:
1202 return &xcoff_howto_table
[0x30];
1203 case BFD_RELOC_PPC_TOC16_LO
:
1204 return &xcoff_howto_table
[0x31];
1205 case BFD_RELOC_PPC_B16
:
1206 return &xcoff_howto_table
[0x1d];
1208 case BFD_RELOC_CTOR
:
1209 return &xcoff_howto_table
[0];
1210 case BFD_RELOC_NONE
:
1211 return &xcoff_howto_table
[0xf];
1212 case BFD_RELOC_PPC_NEG
:
1213 return &xcoff_howto_table
[0x1];
1214 case BFD_RELOC_PPC_TLSGD
:
1215 return &xcoff_howto_table
[0x20];
1216 case BFD_RELOC_PPC_TLSIE
:
1217 return &xcoff_howto_table
[0x21];
1218 case BFD_RELOC_PPC_TLSLD
:
1219 return &xcoff_howto_table
[0x22];
1220 case BFD_RELOC_PPC_TLSLE
:
1221 return &xcoff_howto_table
[0x23];
1222 case BFD_RELOC_PPC_TLSM
:
1223 return &xcoff_howto_table
[0x24];
1224 case BFD_RELOC_PPC_TLSML
:
1225 return &xcoff_howto_table
[0x25];
1231 static reloc_howto_type
*
1232 _bfd_xcoff_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1238 i
< sizeof (xcoff_howto_table
) / sizeof (xcoff_howto_table
[0]);
1240 if (xcoff_howto_table
[i
].name
!= NULL
1241 && strcasecmp (xcoff_howto_table
[i
].name
, r_name
) == 0)
1242 return &xcoff_howto_table
[i
];
1247 /* XCOFF archive support. The original version of this code was by
1248 Damon A. Permezel. It was enhanced to permit cross support, and
1249 writing archive files, by Ian Lance Taylor, Cygnus Support.
1251 XCOFF uses its own archive format. Everything is hooked together
1252 with file offset links, so it is possible to rapidly update an
1253 archive in place. Of course, we don't do that. An XCOFF archive
1254 has a real file header, not just an ARMAG string. The structure of
1255 the file header and of each archive header appear below.
1257 An XCOFF archive also has a member table, which is a list of
1258 elements in the archive (you can get that by looking through the
1259 linked list, but you have to read a lot more of the file). The
1260 member table has a normal archive header with an empty name. It is
1261 normally (and perhaps must be) the second to last entry in the
1262 archive. The member table data is almost printable ASCII. It
1263 starts with a 12 character decimal string which is the number of
1264 entries in the table. For each entry it has a 12 character decimal
1265 string which is the offset in the archive of that member. These
1266 entries are followed by a series of null terminated strings which
1267 are the member names for each entry.
1269 Finally, an XCOFF archive has a global symbol table, which is what
1270 we call the armap. The global symbol table has a normal archive
1271 header with an empty name. It is normally (and perhaps must be)
1272 the last entry in the archive. The contents start with a four byte
1273 binary number which is the number of entries. This is followed by
1274 a that many four byte binary numbers; each is the file offset of an
1275 entry in the archive. These numbers are followed by a series of
1276 null terminated strings, which are symbol names.
1278 AIX 4.3 introduced a new archive format which can handle larger
1279 files and also 32- and 64-bit objects in the same archive. The
1280 things said above remain true except that there is now more than
1281 one global symbol table. The one is used to index 32-bit objects,
1282 the other for 64-bit objects.
1284 The new archives (recognizable by the new ARMAG string) has larger
1285 field lengths so that we cannot really share any code. Also we have
1286 to take care that we are not generating the new form of archives
1287 on AIX 4.2 or earlier systems. */
1289 /* PR 21786: The PE/COFF standard does not require NUL termination for any of
1290 the ASCII fields in the archive headers. So in order to be able to extract
1291 numerical values we provide our own versions of strtol and strtoll which
1292 take a maximum length as an additional parameter. Also - just to save space,
1293 we omit the endptr return parameter, since we know that it is never used. */
1296 _bfd_strntol (const char * nptr
, int base
, unsigned int maxlen
)
1298 char buf
[24]; /* Should be enough. */
1300 BFD_ASSERT (maxlen
< (sizeof (buf
) - 1));
1302 memcpy (buf
, nptr
, maxlen
);
1304 return strtol (buf
, NULL
, base
);
1308 _bfd_strntoll (const char * nptr
, int base
, unsigned int maxlen
)
1310 char buf
[32]; /* Should be enough. */
1312 BFD_ASSERT (maxlen
< (sizeof (buf
) - 1));
1314 memcpy (buf
, nptr
, maxlen
);
1316 return strtoll (buf
, NULL
, base
);
1319 /* Macro to read an ASCII value stored in an archive header field. */
1320 #define GET_VALUE_IN_FIELD(VAR, FIELD, BASE) \
1323 (VAR) = (sizeof (VAR) > sizeof (long) \
1324 ? _bfd_strntoll (FIELD, BASE, sizeof FIELD) \
1325 : _bfd_strntol (FIELD, BASE, sizeof FIELD)); \
1329 #define EQ_VALUE_IN_FIELD(VAR, FIELD, BASE) \
1330 (sizeof (VAR) > sizeof (long) \
1331 ? (VAR) == _bfd_strntoll (FIELD, BASE, sizeof FIELD) \
1332 : (VAR) == _bfd_strntol (FIELD, BASE, sizeof FIELD))
1334 /* Read in the armap of an XCOFF archive. */
1337 _bfd_xcoff_slurp_armap (bfd
*abfd
)
1342 bfd_byte
*contents
, *cend
;
1347 if (xcoff_ardata (abfd
) == NULL
)
1349 abfd
->has_armap
= false;
1353 if (! xcoff_big_format_p (abfd
))
1355 /* This is for the old format. */
1356 struct xcoff_ar_hdr hdr
;
1358 GET_VALUE_IN_FIELD (off
, xcoff_ardata (abfd
)->symoff
, 10);
1361 abfd
->has_armap
= false;
1365 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0)
1368 /* The symbol table starts with a normal archive header. */
1369 if (bfd_bread (&hdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1373 /* Skip the name (normally empty). */
1374 GET_VALUE_IN_FIELD (namlen
, hdr
.namlen
, 10);
1375 off
= ((namlen
+ 1) & ~ (size_t) 1) + SXCOFFARFMAG
;
1376 if (bfd_seek (abfd
, off
, SEEK_CUR
) != 0)
1379 GET_VALUE_IN_FIELD (sz
, hdr
.size
, 10);
1382 bfd_set_error (bfd_error_bad_value
);
1386 /* Read in the entire symbol table. */
1387 contents
= (bfd_byte
*) _bfd_alloc_and_read (abfd
, sz
+ 1, sz
);
1388 if (contents
== NULL
)
1391 /* Ensure strings are NULL terminated so we don't wander off the
1392 end of the buffer. */
1395 /* The symbol table starts with a four byte count. */
1396 c
= H_GET_32 (abfd
, contents
);
1400 bfd_set_error (bfd_error_bad_value
);
1404 bfd_ardata (abfd
)->symdefs
=
1405 ((carsym
*) bfd_alloc (abfd
, c
* sizeof (carsym
)));
1406 if (bfd_ardata (abfd
)->symdefs
== NULL
)
1409 /* After the count comes a list of four byte file offsets. */
1410 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
, p
= contents
+ 4;
1412 ++i
, ++arsym
, p
+= 4)
1413 arsym
->file_offset
= H_GET_32 (abfd
, p
);
1417 /* This is for the new format. */
1418 struct xcoff_ar_hdr_big hdr
;
1420 GET_VALUE_IN_FIELD (off
, xcoff_ardata_big (abfd
)->symoff
, 10);
1423 abfd
->has_armap
= false;
1427 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0)
1430 /* The symbol table starts with a normal archive header. */
1431 if (bfd_bread (&hdr
, (bfd_size_type
) SIZEOF_AR_HDR_BIG
, abfd
)
1432 != SIZEOF_AR_HDR_BIG
)
1435 /* Skip the name (normally empty). */
1436 GET_VALUE_IN_FIELD (namlen
, hdr
.namlen
, 10);
1437 off
= ((namlen
+ 1) & ~ (size_t) 1) + SXCOFFARFMAG
;
1438 if (bfd_seek (abfd
, off
, SEEK_CUR
) != 0)
1441 GET_VALUE_IN_FIELD (sz
, hdr
.size
, 10);
1444 bfd_set_error (bfd_error_bad_value
);
1448 /* Read in the entire symbol table. */
1449 contents
= (bfd_byte
*) _bfd_alloc_and_read (abfd
, sz
+ 1, sz
);
1450 if (contents
== NULL
)
1453 /* Ensure strings are NULL terminated so we don't wander off the
1454 end of the buffer. */
1457 /* The symbol table starts with an eight byte count. */
1458 c
= H_GET_64 (abfd
, contents
);
1462 bfd_set_error (bfd_error_bad_value
);
1466 bfd_ardata (abfd
)->symdefs
=
1467 ((carsym
*) bfd_alloc (abfd
, c
* sizeof (carsym
)));
1468 if (bfd_ardata (abfd
)->symdefs
== NULL
)
1471 /* After the count comes a list of eight byte file offsets. */
1472 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
, p
= contents
+ 8;
1474 ++i
, ++arsym
, p
+= 8)
1475 arsym
->file_offset
= H_GET_64 (abfd
, p
);
1478 /* After the file offsets come null terminated symbol names. */
1479 cend
= contents
+ sz
;
1480 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
;
1482 ++i
, ++arsym
, p
+= strlen ((char *) p
) + 1)
1486 bfd_set_error (bfd_error_bad_value
);
1489 arsym
->name
= (char *) p
;
1492 bfd_ardata (abfd
)->symdef_count
= c
;
1493 abfd
->has_armap
= true;
1498 /* See if this is an XCOFF archive. */
1501 _bfd_xcoff_archive_p (bfd
*abfd
)
1503 struct artdata
*tdata_hold
;
1504 char magic
[SXCOFFARMAG
];
1505 size_t amt
= SXCOFFARMAG
;
1507 if (bfd_bread (magic
, amt
, abfd
) != amt
)
1509 if (bfd_get_error () != bfd_error_system_call
)
1510 bfd_set_error (bfd_error_wrong_format
);
1514 if (strncmp (magic
, XCOFFARMAG
, SXCOFFARMAG
) != 0
1515 && strncmp (magic
, XCOFFARMAGBIG
, SXCOFFARMAG
) != 0)
1517 bfd_set_error (bfd_error_wrong_format
);
1521 tdata_hold
= bfd_ardata (abfd
);
1523 amt
= sizeof (struct artdata
);
1524 bfd_ardata (abfd
) = (struct artdata
*) bfd_zalloc (abfd
, amt
);
1525 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
1526 goto error_ret_restore
;
1528 /* Cleared by bfd_zalloc above.
1529 bfd_ardata (abfd)->cache = NULL;
1530 bfd_ardata (abfd)->archive_head = NULL;
1531 bfd_ardata (abfd)->symdefs = NULL;
1532 bfd_ardata (abfd)->extended_names = NULL;
1533 bfd_ardata (abfd)->extended_names_size = 0; */
1535 /* Now handle the two formats. */
1536 if (magic
[1] != 'b')
1538 /* This is the old format. */
1539 struct xcoff_ar_file_hdr hdr
;
1541 /* Copy over the magic string. */
1542 memcpy (hdr
.magic
, magic
, SXCOFFARMAG
);
1544 /* Now read the rest of the file header. */
1545 amt
= SIZEOF_AR_FILE_HDR
- SXCOFFARMAG
;
1546 if (bfd_bread (&hdr
.memoff
, amt
, abfd
) != amt
)
1548 if (bfd_get_error () != bfd_error_system_call
)
1549 bfd_set_error (bfd_error_wrong_format
);
1553 GET_VALUE_IN_FIELD (bfd_ardata (abfd
)->first_file_filepos
,
1554 hdr
.firstmemoff
, 10);
1556 amt
= SIZEOF_AR_FILE_HDR
;
1557 bfd_ardata (abfd
)->tdata
= bfd_zalloc (abfd
, amt
);
1558 if (bfd_ardata (abfd
)->tdata
== NULL
)
1561 memcpy (bfd_ardata (abfd
)->tdata
, &hdr
, SIZEOF_AR_FILE_HDR
);
1565 /* This is the new format. */
1566 struct xcoff_ar_file_hdr_big hdr
;
1568 /* Copy over the magic string. */
1569 memcpy (hdr
.magic
, magic
, SXCOFFARMAG
);
1571 /* Now read the rest of the file header. */
1572 amt
= SIZEOF_AR_FILE_HDR_BIG
- SXCOFFARMAG
;
1573 if (bfd_bread (&hdr
.memoff
, amt
, abfd
) != amt
)
1575 if (bfd_get_error () != bfd_error_system_call
)
1576 bfd_set_error (bfd_error_wrong_format
);
1580 bfd_ardata (abfd
)->first_file_filepos
= bfd_scan_vma (hdr
.firstmemoff
,
1584 amt
= SIZEOF_AR_FILE_HDR_BIG
;
1585 bfd_ardata (abfd
)->tdata
= bfd_zalloc (abfd
, amt
);
1586 if (bfd_ardata (abfd
)->tdata
== NULL
)
1589 memcpy (bfd_ardata (abfd
)->tdata
, &hdr
, SIZEOF_AR_FILE_HDR_BIG
);
1592 if (! _bfd_xcoff_slurp_armap (abfd
))
1595 bfd_release (abfd
, bfd_ardata (abfd
));
1597 bfd_ardata (abfd
) = tdata_hold
;
1601 return _bfd_no_cleanup
;
1604 /* Read the archive header in an XCOFF archive. */
1607 _bfd_xcoff_read_ar_hdr (bfd
*abfd
)
1609 bfd_size_type namlen
;
1610 struct areltdata
*ret
;
1613 if (! xcoff_big_format_p (abfd
))
1615 struct xcoff_ar_hdr hdr
;
1616 struct xcoff_ar_hdr
*hdrp
;
1618 if (bfd_bread (&hdr
, SIZEOF_AR_HDR
, abfd
) != SIZEOF_AR_HDR
)
1621 GET_VALUE_IN_FIELD (namlen
, hdr
.namlen
, 10);
1622 amt
= sizeof (struct areltdata
) + SIZEOF_AR_HDR
+ namlen
+ 1;
1623 ret
= (struct areltdata
*) bfd_malloc (amt
);
1627 hdrp
= (struct xcoff_ar_hdr
*) (ret
+ 1);
1628 memcpy (hdrp
, &hdr
, SIZEOF_AR_HDR
);
1629 if (bfd_bread ((char *) hdrp
+ SIZEOF_AR_HDR
, namlen
, abfd
) != namlen
)
1634 ((char *) hdrp
)[SIZEOF_AR_HDR
+ namlen
] = '\0';
1636 ret
->arch_header
= (char *) hdrp
;
1637 GET_VALUE_IN_FIELD (ret
->parsed_size
, hdr
.size
, 10);
1638 ret
->filename
= (char *) hdrp
+ SIZEOF_AR_HDR
;
1642 struct xcoff_ar_hdr_big hdr
;
1643 struct xcoff_ar_hdr_big
*hdrp
;
1645 if (bfd_bread (&hdr
, SIZEOF_AR_HDR_BIG
, abfd
) != SIZEOF_AR_HDR_BIG
)
1648 GET_VALUE_IN_FIELD (namlen
, hdr
.namlen
, 10);
1649 amt
= sizeof (struct areltdata
) + SIZEOF_AR_HDR_BIG
+ namlen
+ 1;
1650 ret
= (struct areltdata
*) bfd_malloc (amt
);
1654 hdrp
= (struct xcoff_ar_hdr_big
*) (ret
+ 1);
1655 memcpy (hdrp
, &hdr
, SIZEOF_AR_HDR_BIG
);
1656 if (bfd_bread ((char *) hdrp
+ SIZEOF_AR_HDR_BIG
, namlen
, abfd
) != namlen
)
1661 ((char *) hdrp
)[SIZEOF_AR_HDR_BIG
+ namlen
] = '\0';
1663 ret
->arch_header
= (char *) hdrp
;
1664 GET_VALUE_IN_FIELD (ret
->parsed_size
, hdr
.size
, 10);
1665 ret
->filename
= (char *) hdrp
+ SIZEOF_AR_HDR_BIG
;
1668 /* Skip over the XCOFFARFMAG at the end of the file name. */
1669 if (bfd_seek (abfd
, (file_ptr
) ((namlen
& 1) + SXCOFFARFMAG
), SEEK_CUR
) != 0)
1675 /* Open the next element in an XCOFF archive. */
1678 _bfd_xcoff_openr_next_archived_file (bfd
*archive
, bfd
*last_file
)
1682 if (xcoff_ardata (archive
) == NULL
)
1684 bfd_set_error (bfd_error_invalid_operation
);
1688 if (! xcoff_big_format_p (archive
))
1690 if (last_file
== NULL
)
1691 filestart
= bfd_ardata (archive
)->first_file_filepos
;
1693 GET_VALUE_IN_FIELD (filestart
, arch_xhdr (last_file
)->nextoff
, 10);
1696 || EQ_VALUE_IN_FIELD (filestart
, xcoff_ardata (archive
)->memoff
, 10)
1697 || EQ_VALUE_IN_FIELD (filestart
, xcoff_ardata (archive
)->symoff
, 10))
1699 bfd_set_error (bfd_error_no_more_archived_files
);
1705 if (last_file
== NULL
)
1706 filestart
= bfd_ardata (archive
)->first_file_filepos
;
1708 GET_VALUE_IN_FIELD (filestart
, arch_xhdr_big (last_file
)->nextoff
, 10);
1711 || EQ_VALUE_IN_FIELD (filestart
, xcoff_ardata_big (archive
)->memoff
, 10)
1712 || EQ_VALUE_IN_FIELD (filestart
, xcoff_ardata_big (archive
)->symoff
, 10))
1714 bfd_set_error (bfd_error_no_more_archived_files
);
1719 return _bfd_get_elt_at_filepos (archive
, filestart
);
1722 /* Stat an element in an XCOFF archive. */
1725 _bfd_xcoff_stat_arch_elt (bfd
*abfd
, struct stat
*s
)
1727 if (abfd
->arelt_data
== NULL
)
1729 bfd_set_error (bfd_error_invalid_operation
);
1733 if (! xcoff_big_format_p (abfd
->my_archive
))
1735 struct xcoff_ar_hdr
*hdrp
= arch_xhdr (abfd
);
1737 GET_VALUE_IN_FIELD (s
->st_mtime
, hdrp
->date
, 10);
1738 GET_VALUE_IN_FIELD (s
->st_uid
, hdrp
->uid
, 10);
1739 GET_VALUE_IN_FIELD (s
->st_gid
, hdrp
->gid
, 10);
1740 GET_VALUE_IN_FIELD (s
->st_mode
, hdrp
->mode
, 8);
1741 s
->st_size
= arch_eltdata (abfd
)->parsed_size
;
1745 struct xcoff_ar_hdr_big
*hdrp
= arch_xhdr_big (abfd
);
1747 GET_VALUE_IN_FIELD (s
->st_mtime
, hdrp
->date
, 10);
1748 GET_VALUE_IN_FIELD (s
->st_uid
, hdrp
->uid
, 10);
1749 GET_VALUE_IN_FIELD (s
->st_gid
, hdrp
->gid
, 10);
1750 GET_VALUE_IN_FIELD (s
->st_mode
, hdrp
->mode
, 8);
1751 s
->st_size
= arch_eltdata (abfd
)->parsed_size
;
1757 /* Normalize a file name for inclusion in an archive. */
1760 normalize_filename (bfd
*abfd
)
1763 const char *filename
;
1765 file
= bfd_get_filename (abfd
);
1766 filename
= strrchr (file
, '/');
1767 if (filename
!= NULL
)
1774 /* Write out an XCOFF armap. */
1777 xcoff_write_armap_old (bfd
*abfd
, unsigned int elength ATTRIBUTE_UNUSED
,
1778 struct orl
*map
, unsigned int orl_count
, int stridx
)
1780 struct archive_iterator iterator
;
1781 struct xcoff_ar_hdr hdr
;
1783 unsigned char buf
[4];
1786 memset (&hdr
, 0, sizeof hdr
);
1787 sprintf (hdr
.size
, "%ld", (long) (4 + orl_count
* 4 + stridx
));
1788 sprintf (hdr
.nextoff
, "%d", 0);
1789 memcpy (hdr
.prevoff
, xcoff_ardata (abfd
)->memoff
, XCOFFARMAG_ELEMENT_SIZE
);
1790 sprintf (hdr
.date
, "%d", 0);
1791 sprintf (hdr
.uid
, "%d", 0);
1792 sprintf (hdr
.gid
, "%d", 0);
1793 sprintf (hdr
.mode
, "%d", 0);
1794 sprintf (hdr
.namlen
, "%d", 0);
1796 /* We need spaces, not null bytes, in the header. */
1797 for (p
= (char *) &hdr
; p
< (char *) &hdr
+ SIZEOF_AR_HDR
; p
++)
1801 if (bfd_bwrite (&hdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1803 || (bfd_bwrite (XCOFFARFMAG
, (bfd_size_type
) SXCOFFARFMAG
, abfd
)
1807 H_PUT_32 (abfd
, orl_count
, buf
);
1808 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
1812 archive_iterator_begin (&iterator
, abfd
);
1813 while (i
< orl_count
&& archive_iterator_next (&iterator
))
1814 while (map
[i
].u
.abfd
== iterator
.current
.member
)
1816 H_PUT_32 (abfd
, iterator
.current
.offset
, buf
);
1817 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
1822 for (i
= 0; i
< orl_count
; i
++)
1827 name
= *map
[i
].name
;
1828 namlen
= strlen (name
);
1829 if (bfd_bwrite (name
, (bfd_size_type
) (namlen
+ 1), abfd
) != namlen
+ 1)
1833 if ((stridx
& 1) != 0)
1838 if (bfd_bwrite (&b
, (bfd_size_type
) 1, abfd
) != 1)
1845 static char buff20
[XCOFFARMAGBIG_ELEMENT_SIZE
+ 1];
1846 #if BFD_HOST_64BIT_LONG
1847 #define FMT20 "%-20ld"
1848 #elif defined (__MSVCRT__)
1849 #define FMT20 "%-20I64d"
1851 #define FMT20 "%-20lld"
1853 #define FMT12 "%-12d"
1854 #define FMT12_OCTAL "%-12o"
1856 #define PRINT20(d, v) \
1857 sprintf (buff20, FMT20, (bfd_uint64_t)(v)), \
1858 memcpy ((void *) (d), buff20, 20)
1860 #define PRINT12(d, v) \
1861 sprintf (buff20, FMT12, (int)(v)), \
1862 memcpy ((void *) (d), buff20, 12)
1864 #define PRINT12_OCTAL(d, v) \
1865 sprintf (buff20, FMT12_OCTAL, (unsigned int)(v)), \
1866 memcpy ((void *) (d), buff20, 12)
1868 #define PRINT4(d, v) \
1869 sprintf (buff20, FMT4, (int)(v)), \
1870 memcpy ((void *) (d), buff20, 4)
1872 #define READ20(d, v) \
1874 memcpy (buff20, (d), 20), \
1875 (v) = bfd_scan_vma (buff20, (const char **) NULL, 10)
1878 do_pad (bfd
*abfd
, unsigned int number
)
1882 /* Limit pad to <= 4096. */
1887 if (bfd_bwrite (&b
, (bfd_size_type
) 1, abfd
) != 1)
1894 do_copy (bfd
*out_bfd
, bfd
*in_bfd
)
1896 bfd_size_type remaining
;
1897 bfd_byte buffer
[DEFAULT_BUFFERSIZE
];
1899 if (bfd_seek (in_bfd
, (file_ptr
) 0, SEEK_SET
) != 0)
1902 remaining
= arelt_size (in_bfd
);
1904 while (remaining
>= DEFAULT_BUFFERSIZE
)
1906 if (bfd_bread (buffer
, DEFAULT_BUFFERSIZE
, in_bfd
) != DEFAULT_BUFFERSIZE
1907 || bfd_bwrite (buffer
, DEFAULT_BUFFERSIZE
, out_bfd
) != DEFAULT_BUFFERSIZE
)
1910 remaining
-= DEFAULT_BUFFERSIZE
;
1915 if (bfd_bread (buffer
, remaining
, in_bfd
) != remaining
1916 || bfd_bwrite (buffer
, remaining
, out_bfd
) != remaining
)
1924 xcoff_write_armap_big (bfd
*abfd
, unsigned int elength ATTRIBUTE_UNUSED
,
1925 struct orl
*map
, unsigned int orl_count
, int stridx
)
1927 struct archive_iterator iterator
;
1928 struct xcoff_ar_file_hdr_big
*fhdr
;
1929 bfd_vma i
, sym_32
, sym_64
, str_32
, str_64
;
1930 const bfd_arch_info_type
*arch_info
;
1932 size_t string_length
;
1933 file_ptr nextoff
, prevoff
;
1935 /* First, we look through the symbols and work out which are
1936 from 32-bit objects and which from 64-bit ones. */
1937 sym_32
= sym_64
= str_32
= str_64
= 0;
1940 for (current_bfd
= abfd
->archive_head
;
1941 current_bfd
!= NULL
&& i
< orl_count
;
1942 current_bfd
= current_bfd
->archive_next
)
1944 arch_info
= bfd_get_arch_info (current_bfd
);
1945 while (map
[i
].u
.abfd
== current_bfd
)
1947 string_length
= strlen (*map
[i
].name
) + 1;
1948 if (arch_info
->bits_per_address
== 64)
1951 str_64
+= string_length
;
1956 str_32
+= string_length
;
1962 /* A quick sanity check... */
1963 BFD_ASSERT (sym_64
+ sym_32
== orl_count
);
1964 /* Explicit cast to int for compiler. */
1965 BFD_ASSERT ((int)(str_64
+ str_32
) == stridx
);
1967 fhdr
= xcoff_ardata_big (abfd
);
1969 /* xcoff_write_archive_contents_big passes nextoff in symoff. */
1970 READ20 (fhdr
->memoff
, prevoff
);
1971 READ20 (fhdr
->symoff
, nextoff
);
1973 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
1975 /* Write out the symbol table.
1978 standard big archive header
1979 0x0000 ar_size [0x14]
1980 0x0014 ar_nxtmem [0x14]
1981 0x0028 ar_prvmem [0x14]
1982 0x003C ar_date [0x0C]
1983 0x0048 ar_uid [0x0C]
1984 0x0054 ar_gid [0x0C]
1985 0x0060 ar_mod [0x0C]
1986 0x006C ar_namelen[0x04]
1987 0x0070 ar_fmag [SXCOFFARFMAG]
1990 0x0072 num_syms [0x08], binary
1991 0x0078 offsets [0x08 * num_syms], binary
1992 0x0086 + 0x08 * num_syms names [??]
1993 ?? pad to even bytes.
1998 struct xcoff_ar_hdr_big
*hdr
;
2002 bfd_vma symbol_table_size
=
2007 + str_32
+ (str_32
& 1);
2009 symbol_table
= bfd_zmalloc (symbol_table_size
);
2010 if (symbol_table
== NULL
)
2013 hdr
= (struct xcoff_ar_hdr_big
*) symbol_table
;
2015 PRINT20 (hdr
->size
, 8 + 8 * sym_32
+ str_32
+ (str_32
& 1));
2018 PRINT20 (hdr
->nextoff
, nextoff
+ symbol_table_size
);
2020 PRINT20 (hdr
->nextoff
, 0);
2022 PRINT20 (hdr
->prevoff
, prevoff
);
2023 PRINT12 (hdr
->date
, 0);
2024 PRINT12 (hdr
->uid
, 0);
2025 PRINT12 (hdr
->gid
, 0);
2026 PRINT12 (hdr
->mode
, 0);
2027 PRINT4 (hdr
->namlen
, 0) ;
2029 st
= symbol_table
+ SIZEOF_AR_HDR_BIG
;
2030 memcpy (st
, XCOFFARFMAG
, SXCOFFARFMAG
);
2033 bfd_h_put_64 (abfd
, sym_32
, st
);
2036 /* loop over the 32 bit offsets */
2038 archive_iterator_begin (&iterator
, abfd
);
2039 while (i
< orl_count
&& archive_iterator_next (&iterator
))
2041 arch_info
= bfd_get_arch_info (iterator
.current
.member
);
2042 while (map
[i
].u
.abfd
== iterator
.current
.member
)
2044 if (arch_info
->bits_per_address
== 32)
2046 bfd_h_put_64 (abfd
, iterator
.current
.offset
, st
);
2053 /* loop over the 32 bit symbol names */
2055 for (current_bfd
= abfd
->archive_head
;
2056 current_bfd
!= NULL
&& i
< orl_count
;
2057 current_bfd
= current_bfd
->archive_next
)
2059 arch_info
= bfd_get_arch_info (current_bfd
);
2060 while (map
[i
].u
.abfd
== current_bfd
)
2062 if (arch_info
->bits_per_address
== 32)
2064 string_length
= sprintf (st
, "%s", *map
[i
].name
);
2065 st
+= string_length
+ 1;
2071 bfd_bwrite (symbol_table
, symbol_table_size
, abfd
);
2073 free (symbol_table
);
2076 nextoff
= nextoff
+ symbol_table_size
;
2079 PRINT20 (fhdr
->symoff
, 0);
2083 struct xcoff_ar_hdr_big
*hdr
;
2087 bfd_vma symbol_table_size
=
2092 + str_64
+ (str_64
& 1);
2094 symbol_table
= bfd_zmalloc (symbol_table_size
);
2095 if (symbol_table
== NULL
)
2098 hdr
= (struct xcoff_ar_hdr_big
*) symbol_table
;
2100 PRINT20 (hdr
->size
, 8 + 8 * sym_64
+ str_64
+ (str_64
& 1));
2101 PRINT20 (hdr
->nextoff
, 0);
2102 PRINT20 (hdr
->prevoff
, prevoff
);
2103 PRINT12 (hdr
->date
, 0);
2104 PRINT12 (hdr
->uid
, 0);
2105 PRINT12 (hdr
->gid
, 0);
2106 PRINT12 (hdr
->mode
, 0);
2107 PRINT4 (hdr
->namlen
, 0);
2109 st
= symbol_table
+ SIZEOF_AR_HDR_BIG
;
2110 memcpy (st
, XCOFFARFMAG
, SXCOFFARFMAG
);
2113 bfd_h_put_64 (abfd
, sym_64
, st
);
2116 /* loop over the 64 bit offsets */
2118 archive_iterator_begin (&iterator
, abfd
);
2119 while (i
< orl_count
&& archive_iterator_next (&iterator
))
2121 arch_info
= bfd_get_arch_info (iterator
.current
.member
);
2122 while (map
[i
].u
.abfd
== iterator
.current
.member
)
2124 if (arch_info
->bits_per_address
== 64)
2126 bfd_h_put_64 (abfd
, iterator
.current
.offset
, st
);
2133 /* loop over the 64 bit symbol names */
2135 for (current_bfd
= abfd
->archive_head
;
2136 current_bfd
!= NULL
&& i
< orl_count
;
2137 current_bfd
= current_bfd
->archive_next
)
2139 arch_info
= bfd_get_arch_info (current_bfd
);
2140 while (map
[i
].u
.abfd
== current_bfd
)
2142 if (arch_info
->bits_per_address
== 64)
2144 string_length
= sprintf (st
, "%s", *map
[i
].name
);
2145 st
+= string_length
+ 1;
2151 bfd_bwrite (symbol_table
, symbol_table_size
, abfd
);
2153 free (symbol_table
);
2155 PRINT20 (fhdr
->symoff64
, nextoff
);
2158 PRINT20 (fhdr
->symoff64
, 0);
2164 _bfd_xcoff_write_armap (bfd
*abfd
, unsigned int elength ATTRIBUTE_UNUSED
,
2165 struct orl
*map
, unsigned int orl_count
, int stridx
)
2167 if (! xcoff_big_format_p (abfd
))
2168 return xcoff_write_armap_old (abfd
, elength
, map
, orl_count
, stridx
);
2170 return xcoff_write_armap_big (abfd
, elength
, map
, orl_count
, stridx
);
2173 /* Write out an XCOFF archive. We always write an entire archive,
2174 rather than fussing with the freelist and so forth. */
2177 xcoff_write_archive_contents_old (bfd
*abfd
)
2179 struct archive_iterator iterator
;
2180 struct xcoff_ar_file_hdr fhdr
;
2181 bfd_size_type count
;
2182 bfd_size_type total_namlen
;
2186 file_ptr prevoff
, nextoff
;
2189 struct xcoff_ar_hdr ahdr
;
2192 char decbuf
[XCOFFARMAG_ELEMENT_SIZE
+ 1];
2194 memset (&fhdr
, 0, sizeof fhdr
);
2195 (void) memcpy (fhdr
.magic
, XCOFFARMAG
, SXCOFFARMAG
);
2196 sprintf (fhdr
.firstmemoff
, "%d", SIZEOF_AR_FILE_HDR
);
2197 sprintf (fhdr
.freeoff
, "%d", 0);
2201 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->archive_next
)
2204 total_namlen
+= strlen (normalize_filename (sub
)) + 1;
2205 if (sub
->arelt_data
== NULL
)
2207 sub
->arelt_data
= bfd_zmalloc (sizeof (struct areltdata
));
2208 if (sub
->arelt_data
== NULL
)
2211 if (arch_xhdr (sub
) == NULL
)
2213 struct xcoff_ar_hdr
*ahdrp
;
2216 if ((sub
->flags
& BFD_IN_MEMORY
) != 0)
2218 /* Assume we just "made" the member, and fake it. */
2219 struct bfd_in_memory
*bim
2220 = (struct bfd_in_memory
*) sub
->iostream
;
2222 s
.st_uid
= getuid ();
2223 s
.st_gid
= getgid ();
2225 s
.st_size
= bim
->size
;
2227 else if (stat (bfd_get_filename (sub
), &s
) != 0)
2229 bfd_set_input_error (sub
, bfd_error_system_call
);
2233 if ((abfd
->flags
& BFD_DETERMINISTIC_OUTPUT
) != 0)
2241 ahdrp
= bfd_zalloc (sub
, sizeof (*ahdrp
));
2245 sprintf (ahdrp
->size
, "%ld", (long) s
.st_size
);
2246 sprintf (ahdrp
->date
, "%ld", (long) s
.st_mtime
);
2247 sprintf (ahdrp
->uid
, "%ld", (long) s
.st_uid
);
2248 sprintf (ahdrp
->gid
, "%ld", (long) s
.st_gid
);
2249 sprintf (ahdrp
->mode
, "%o", (unsigned int) s
.st_mode
);
2251 arch_eltdata (sub
)->arch_header
= (char *) ahdrp
;
2252 arch_eltdata (sub
)->parsed_size
= s
.st_size
;
2255 offsets
= (file_ptr
*) bfd_alloc (abfd
, count
* sizeof (file_ptr
));
2256 if (offsets
== NULL
)
2259 if (bfd_seek (abfd
, (file_ptr
) SIZEOF_AR_FILE_HDR
, SEEK_SET
) != 0)
2262 makemap
= bfd_has_map (abfd
);
2265 for (archive_iterator_begin (&iterator
, abfd
), i
= 0;
2266 archive_iterator_next (&iterator
);
2269 bfd_size_type namlen
;
2270 struct xcoff_ar_hdr
*ahdrp
;
2272 if (makemap
&& ! hasobjects
)
2274 if (bfd_check_format (iterator
.current
.member
, bfd_object
))
2278 ahdrp
= arch_xhdr (iterator
.current
.member
);
2279 sprintf (ahdrp
->prevoff
, "%ld", (long) prevoff
);
2280 sprintf (ahdrp
->namlen
, "%ld", (long) iterator
.current
.namlen
);
2281 sprintf (ahdrp
->nextoff
, "%ld", (long) iterator
.next
.offset
);
2283 /* We need spaces, not null bytes, in the header. */
2284 for (p
= (char *) ahdrp
; p
< (char *) ahdrp
+ SIZEOF_AR_HDR
; p
++)
2288 if (!do_pad (abfd
, iterator
.current
.leading_padding
))
2291 BFD_ASSERT (iterator
.current
.offset
== bfd_tell (abfd
));
2292 namlen
= iterator
.current
.padded_namlen
;
2293 if (bfd_bwrite (ahdrp
, SIZEOF_AR_HDR
, abfd
) != SIZEOF_AR_HDR
2294 || bfd_bwrite (iterator
.current
.name
, namlen
, abfd
) != namlen
2295 || bfd_bwrite (XCOFFARFMAG
, SXCOFFARFMAG
, abfd
) != SXCOFFARFMAG
2296 || bfd_seek (iterator
.current
.member
, 0, SEEK_SET
) != 0
2297 || !do_copy (abfd
, iterator
.current
.member
)
2298 || !do_pad (abfd
, iterator
.current
.trailing_padding
))
2301 offsets
[i
] = iterator
.current
.offset
;
2302 prevoff
= iterator
.current
.offset
;
2305 sprintf (fhdr
.lastmemoff
, "%ld", (long) prevoff
);
2307 /* Write out the member table. */
2309 nextoff
= iterator
.next
.offset
;
2310 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2311 sprintf (fhdr
.memoff
, "%ld", (long) nextoff
);
2313 memset (&ahdr
, 0, sizeof ahdr
);
2314 sprintf (ahdr
.size
, "%ld", (long) (XCOFFARMAG_ELEMENT_SIZE
2315 + count
* XCOFFARMAG_ELEMENT_SIZE
2317 sprintf (ahdr
.prevoff
, "%ld", (long) prevoff
);
2318 sprintf (ahdr
.date
, "%d", 0);
2319 sprintf (ahdr
.uid
, "%d", 0);
2320 sprintf (ahdr
.gid
, "%d", 0);
2321 sprintf (ahdr
.mode
, "%d", 0);
2322 sprintf (ahdr
.namlen
, "%d", 0);
2324 size
= (SIZEOF_AR_HDR
2325 + XCOFFARMAG_ELEMENT_SIZE
2326 + count
* XCOFFARMAG_ELEMENT_SIZE
2331 nextoff
+= size
+ (size
& 1);
2333 if (makemap
&& hasobjects
)
2334 sprintf (ahdr
.nextoff
, "%ld", (long) nextoff
);
2336 sprintf (ahdr
.nextoff
, "%d", 0);
2338 /* We need spaces, not null bytes, in the header. */
2339 for (p
= (char *) &ahdr
; p
< (char *) &ahdr
+ SIZEOF_AR_HDR
; p
++)
2343 if ((bfd_bwrite (&ahdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
2345 || (bfd_bwrite (XCOFFARFMAG
, (bfd_size_type
) SXCOFFARFMAG
, abfd
)
2349 sprintf (decbuf
, "%-12ld", (long) count
);
2350 if (bfd_bwrite (decbuf
, (bfd_size_type
) XCOFFARMAG_ELEMENT_SIZE
, abfd
)
2351 != XCOFFARMAG_ELEMENT_SIZE
)
2353 for (i
= 0; i
< (size_t) count
; i
++)
2355 sprintf (decbuf
, "%-12ld", (long) offsets
[i
]);
2356 if (bfd_bwrite (decbuf
, (bfd_size_type
) XCOFFARMAG_ELEMENT_SIZE
,
2357 abfd
) != XCOFFARMAG_ELEMENT_SIZE
)
2360 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->archive_next
)
2363 bfd_size_type namlen
;
2365 name
= normalize_filename (sub
);
2366 namlen
= strlen (name
);
2367 if (bfd_bwrite (name
, namlen
+ 1, abfd
) != namlen
+ 1)
2371 if (! do_pad (abfd
, size
& 1))
2374 /* Write out the armap, if appropriate. */
2375 if (! makemap
|| ! hasobjects
)
2376 sprintf (fhdr
.symoff
, "%d", 0);
2379 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2380 sprintf (fhdr
.symoff
, "%ld", (long) nextoff
);
2381 bfd_ardata (abfd
)->tdata
= &fhdr
;
2382 if (! _bfd_compute_and_write_armap (abfd
, 0))
2386 /* Write out the archive file header. */
2388 /* We need spaces, not null bytes, in the header. */
2389 for (p
= (char *) &fhdr
; p
< (char *) &fhdr
+ SIZEOF_AR_FILE_HDR
; p
++)
2393 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
2394 || (bfd_bwrite (&fhdr
, (bfd_size_type
) SIZEOF_AR_FILE_HDR
, abfd
)
2395 != SIZEOF_AR_FILE_HDR
))
2402 xcoff_write_archive_contents_big (bfd
*abfd
)
2404 struct xcoff_ar_file_hdr_big fhdr
;
2405 bfd_size_type count
;
2406 bfd_size_type total_namlen
;
2410 file_ptr prevoff
, nextoff
;
2413 struct xcoff_ar_hdr_big
*hdr
;
2415 char *member_table
, *mt
;
2416 bfd_vma member_table_size
;
2417 struct archive_iterator iterator
;
2419 memset (&fhdr
, 0, SIZEOF_AR_FILE_HDR_BIG
);
2420 memcpy (fhdr
.magic
, XCOFFARMAGBIG
, SXCOFFARMAG
);
2422 if (bfd_seek (abfd
, (file_ptr
) SIZEOF_AR_FILE_HDR_BIG
, SEEK_SET
) != 0)
2425 /* Calculate count and total_namlen. */
2426 makemap
= bfd_has_map (abfd
);
2428 for (current_bfd
= abfd
->archive_head
, count
= 0, total_namlen
= 0;
2429 current_bfd
!= NULL
;
2430 current_bfd
= current_bfd
->archive_next
, count
++)
2432 total_namlen
+= strlen (normalize_filename (current_bfd
)) + 1;
2436 && bfd_check_format (current_bfd
, bfd_object
))
2439 if (current_bfd
->arelt_data
== NULL
)
2441 size
= sizeof (struct areltdata
);
2442 current_bfd
->arelt_data
= bfd_zmalloc (size
);
2443 if (current_bfd
->arelt_data
== NULL
)
2447 if (arch_xhdr_big (current_bfd
) == NULL
)
2449 struct xcoff_ar_hdr_big
*ahdrp
;
2452 if ((current_bfd
->flags
& BFD_IN_MEMORY
) != 0)
2454 /* Assume we just "made" the member, and fake it. */
2455 struct bfd_in_memory
*bim
2456 = (struct bfd_in_memory
*) current_bfd
->iostream
;
2458 s
.st_uid
= getuid ();
2459 s
.st_gid
= getgid ();
2461 s
.st_size
= bim
->size
;
2463 else if (stat (bfd_get_filename (current_bfd
), &s
) != 0)
2465 bfd_set_input_error (current_bfd
, bfd_error_system_call
);
2469 if ((abfd
->flags
& BFD_DETERMINISTIC_OUTPUT
) != 0)
2477 ahdrp
= bfd_zalloc (current_bfd
, sizeof (*ahdrp
));
2481 PRINT20 (ahdrp
->size
, s
.st_size
);
2482 PRINT12 (ahdrp
->date
, s
.st_mtime
);
2483 PRINT12 (ahdrp
->uid
, s
.st_uid
);
2484 PRINT12 (ahdrp
->gid
, s
.st_gid
);
2485 PRINT12_OCTAL (ahdrp
->mode
, s
.st_mode
);
2487 arch_eltdata (current_bfd
)->arch_header
= (char *) ahdrp
;
2488 arch_eltdata (current_bfd
)->parsed_size
= s
.st_size
;
2495 offsets
= (file_ptr
*) bfd_malloc (count
* sizeof (file_ptr
));
2496 if (offsets
== NULL
)
2501 for (archive_iterator_begin (&iterator
, abfd
), i
= 0;
2502 archive_iterator_next (&iterator
);
2505 bfd_size_type namlen
;
2506 struct xcoff_ar_hdr_big
*ahdrp
;
2508 ahdrp
= arch_xhdr_big (iterator
.current
.member
);
2509 PRINT20 (ahdrp
->prevoff
, prevoff
);
2510 PRINT4 (ahdrp
->namlen
, iterator
.current
.namlen
);
2511 PRINT20 (ahdrp
->nextoff
, iterator
.next
.offset
);
2513 if (!do_pad (abfd
, iterator
.current
.leading_padding
))
2519 BFD_ASSERT (iterator
.current
.offset
== bfd_tell (abfd
));
2520 namlen
= iterator
.current
.padded_namlen
;
2521 if (bfd_bwrite (ahdrp
, SIZEOF_AR_HDR_BIG
, abfd
) != SIZEOF_AR_HDR_BIG
2522 || bfd_bwrite (iterator
.current
.name
, namlen
, abfd
) != namlen
2523 || bfd_bwrite (XCOFFARFMAG
, SXCOFFARFMAG
, abfd
) != SXCOFFARFMAG
2524 || bfd_seek (iterator
.current
.member
, 0, SEEK_SET
) != 0
2525 || !do_copy (abfd
, iterator
.current
.member
)
2526 || !do_pad (abfd
, iterator
.current
.trailing_padding
))
2532 offsets
[i
] = iterator
.current
.offset
;
2533 prevoff
= iterator
.current
.offset
;
2538 PRINT20 (fhdr
.firstmemoff
, offsets
[0]);
2539 PRINT20 (fhdr
.lastmemoff
, prevoff
);
2542 /* Write out the member table.
2545 standard big archive header
2546 0x0000 ar_size [0x14]
2547 0x0014 ar_nxtmem [0x14]
2548 0x0028 ar_prvmem [0x14]
2549 0x003C ar_date [0x0C]
2550 0x0048 ar_uid [0x0C]
2551 0x0054 ar_gid [0x0C]
2552 0x0060 ar_mod [0x0C]
2553 0x006C ar_namelen[0x04]
2554 0x0070 ar_fmag [0x02]
2558 0x0086 offsets [0x14 * counts]
2559 0x0086 + 0x14 * counts names [??]
2560 ?? pad to even bytes.
2563 nextoff
= iterator
.next
.offset
;
2564 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2566 member_table_size
= (SIZEOF_AR_HDR_BIG
2568 + XCOFFARMAGBIG_ELEMENT_SIZE
2569 + count
* XCOFFARMAGBIG_ELEMENT_SIZE
2572 member_table_size
+= member_table_size
& 1;
2573 member_table
= bfd_zmalloc (member_table_size
);
2574 if (member_table
== NULL
)
2580 hdr
= (struct xcoff_ar_hdr_big
*) member_table
;
2582 PRINT20 (hdr
->size
, (XCOFFARMAGBIG_ELEMENT_SIZE
2583 + count
* XCOFFARMAGBIG_ELEMENT_SIZE
2584 + total_namlen
+ (total_namlen
& 1)));
2585 if (makemap
&& hasobjects
)
2586 PRINT20 (hdr
->nextoff
, nextoff
+ member_table_size
);
2588 PRINT20 (hdr
->nextoff
, 0);
2589 PRINT20 (hdr
->prevoff
, prevoff
);
2590 PRINT12 (hdr
->date
, 0);
2591 PRINT12 (hdr
->uid
, 0);
2592 PRINT12 (hdr
->gid
, 0);
2593 PRINT12 (hdr
->mode
, 0);
2594 PRINT4 (hdr
->namlen
, 0);
2596 mt
= member_table
+ SIZEOF_AR_HDR_BIG
;
2597 memcpy (mt
, XCOFFARFMAG
, SXCOFFARFMAG
);
2600 PRINT20 (mt
, count
);
2601 mt
+= XCOFFARMAGBIG_ELEMENT_SIZE
;
2602 for (i
= 0; i
< (size_t) count
; i
++)
2604 PRINT20 (mt
, offsets
[i
]);
2605 mt
+= XCOFFARMAGBIG_ELEMENT_SIZE
;
2614 for (current_bfd
= abfd
->archive_head
;
2615 current_bfd
!= NULL
;
2616 current_bfd
= current_bfd
->archive_next
)
2621 name
= normalize_filename (current_bfd
);
2622 namlen
= sprintf (mt
, "%s", name
);
2626 if (bfd_bwrite (member_table
, member_table_size
, abfd
) != member_table_size
)
2629 free (member_table
);
2631 PRINT20 (fhdr
.memoff
, nextoff
);
2634 nextoff
+= member_table_size
;
2636 /* Write out the armap, if appropriate. */
2638 if (! makemap
|| ! hasobjects
)
2639 PRINT20 (fhdr
.symoff
, 0);
2642 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2644 /* Save nextoff in fhdr.symoff so the armap routine can use it. */
2645 PRINT20 (fhdr
.symoff
, nextoff
);
2647 bfd_ardata (abfd
)->tdata
= &fhdr
;
2648 if (! _bfd_compute_and_write_armap (abfd
, 0))
2652 /* Write out the archive file header. */
2654 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
2655 || (bfd_bwrite (&fhdr
, (bfd_size_type
) SIZEOF_AR_FILE_HDR_BIG
,
2656 abfd
) != SIZEOF_AR_FILE_HDR_BIG
))
2663 _bfd_xcoff_write_archive_contents (bfd
*abfd
)
2665 if (! xcoff_big_format_p (abfd
))
2666 return xcoff_write_archive_contents_old (abfd
);
2668 return xcoff_write_archive_contents_big (abfd
);
2671 /* We can't use the usual coff_sizeof_headers routine, because AIX
2672 always uses an a.out header. */
2675 _bfd_xcoff_sizeof_headers (bfd
*abfd
,
2676 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
2681 if (xcoff_data (abfd
)->full_aouthdr
)
2684 size
+= SMALL_AOUTSZ
;
2685 size
+= abfd
->section_count
* SCNHSZ
;
2687 if (info
->strip
!= strip_all
)
2689 /* There can be additional sections just for dealing with overflow in
2690 reloc and lineno counts. But the numbers of relocs and lineno aren't
2691 known when bfd_sizeof_headers is called, so we compute them by
2692 summing the numbers from input sections. */
2693 struct nbr_reloc_lineno
2695 unsigned int reloc_count
;
2696 unsigned int lineno_count
;
2698 struct nbr_reloc_lineno
*n_rl
;
2700 unsigned int max_index
;
2703 /* Although the number of sections is known, the maximum value of
2704 section->index isn't (because some sections may have been removed).
2705 Don't try to renumber sections, just compute the upper bound. */
2707 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2708 if (s
->index
> max_index
)
2709 max_index
= s
->index
;
2711 /* Allocate the per section counters. It could be possible to use a
2712 preallocated array as the number of sections is limited on XCOFF,
2713 but this creates a maintainance issue. */
2714 n_rl
= bfd_zmalloc ((max_index
+ 1) * sizeof (*n_rl
));
2719 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link
.next
)
2720 for (s
= sub
->sections
; s
!= NULL
; s
= s
->next
)
2721 if (s
->output_section
->owner
== abfd
2722 && !bfd_section_removed_from_list (abfd
, s
->output_section
))
2724 struct nbr_reloc_lineno
*e
= &n_rl
[s
->output_section
->index
];
2725 e
->reloc_count
+= s
->reloc_count
;
2726 e
->lineno_count
+= s
->lineno_count
;
2729 /* Add the size of a section for each section with an overflow. */
2730 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2732 struct nbr_reloc_lineno
*e
= &n_rl
[s
->index
];
2734 if (e
->reloc_count
>= 0xffff
2735 || (e
->lineno_count
>= 0xffff && info
->strip
!= strip_debugger
))
2745 /* Routines to swap information in the XCOFF .loader section. If we
2746 ever need to write an XCOFF loader, this stuff will need to be
2747 moved to another file shared by the linker (which XCOFF calls the
2748 ``binder'') and the loader. */
2750 /* Swap in the ldhdr structure. */
2753 xcoff_swap_ldhdr_in (bfd
*abfd
, const void * s
, struct internal_ldhdr
*dst
)
2755 const struct external_ldhdr
*src
= (const struct external_ldhdr
*) s
;
2757 dst
->l_version
= bfd_get_32 (abfd
, src
->l_version
);
2758 dst
->l_nsyms
= bfd_get_32 (abfd
, src
->l_nsyms
);
2759 dst
->l_nreloc
= bfd_get_32 (abfd
, src
->l_nreloc
);
2760 dst
->l_istlen
= bfd_get_32 (abfd
, src
->l_istlen
);
2761 dst
->l_nimpid
= bfd_get_32 (abfd
, src
->l_nimpid
);
2762 dst
->l_impoff
= bfd_get_32 (abfd
, src
->l_impoff
);
2763 dst
->l_stlen
= bfd_get_32 (abfd
, src
->l_stlen
);
2764 dst
->l_stoff
= bfd_get_32 (abfd
, src
->l_stoff
);
2767 /* Swap out the ldhdr structure. */
2770 xcoff_swap_ldhdr_out (bfd
*abfd
, const struct internal_ldhdr
*src
, void * d
)
2772 struct external_ldhdr
*dst
= (struct external_ldhdr
*) d
;
2774 bfd_put_32 (abfd
, (bfd_vma
) src
->l_version
, dst
->l_version
);
2775 bfd_put_32 (abfd
, src
->l_nsyms
, dst
->l_nsyms
);
2776 bfd_put_32 (abfd
, src
->l_nreloc
, dst
->l_nreloc
);
2777 bfd_put_32 (abfd
, src
->l_istlen
, dst
->l_istlen
);
2778 bfd_put_32 (abfd
, src
->l_nimpid
, dst
->l_nimpid
);
2779 bfd_put_32 (abfd
, src
->l_impoff
, dst
->l_impoff
);
2780 bfd_put_32 (abfd
, src
->l_stlen
, dst
->l_stlen
);
2781 bfd_put_32 (abfd
, src
->l_stoff
, dst
->l_stoff
);
2784 /* Swap in the ldsym structure. */
2787 xcoff_swap_ldsym_in (bfd
*abfd
, const void * s
, struct internal_ldsym
*dst
)
2789 const struct external_ldsym
*src
= (const struct external_ldsym
*) s
;
2791 if (bfd_get_32 (abfd
, src
->_l
._l_l
._l_zeroes
) != 0) {
2792 memcpy (dst
->_l
._l_name
, src
->_l
._l_name
, SYMNMLEN
);
2794 dst
->_l
._l_l
._l_zeroes
= 0;
2795 dst
->_l
._l_l
._l_offset
= bfd_get_32 (abfd
, src
->_l
._l_l
._l_offset
);
2797 dst
->l_value
= bfd_get_32 (abfd
, src
->l_value
);
2798 dst
->l_scnum
= bfd_get_16 (abfd
, src
->l_scnum
);
2799 dst
->l_smtype
= bfd_get_8 (abfd
, src
->l_smtype
);
2800 dst
->l_smclas
= bfd_get_8 (abfd
, src
->l_smclas
);
2801 dst
->l_ifile
= bfd_get_32 (abfd
, src
->l_ifile
);
2802 dst
->l_parm
= bfd_get_32 (abfd
, src
->l_parm
);
2805 /* Swap out the ldsym structure. */
2808 xcoff_swap_ldsym_out (bfd
*abfd
, const struct internal_ldsym
*src
, void * d
)
2810 struct external_ldsym
*dst
= (struct external_ldsym
*) d
;
2812 if (src
->_l
._l_l
._l_zeroes
!= 0)
2813 memcpy (dst
->_l
._l_name
, src
->_l
._l_name
, SYMNMLEN
);
2816 bfd_put_32 (abfd
, (bfd_vma
) 0, dst
->_l
._l_l
._l_zeroes
);
2817 bfd_put_32 (abfd
, (bfd_vma
) src
->_l
._l_l
._l_offset
,
2818 dst
->_l
._l_l
._l_offset
);
2820 bfd_put_32 (abfd
, src
->l_value
, dst
->l_value
);
2821 bfd_put_16 (abfd
, (bfd_vma
) src
->l_scnum
, dst
->l_scnum
);
2822 bfd_put_8 (abfd
, src
->l_smtype
, dst
->l_smtype
);
2823 bfd_put_8 (abfd
, src
->l_smclas
, dst
->l_smclas
);
2824 bfd_put_32 (abfd
, src
->l_ifile
, dst
->l_ifile
);
2825 bfd_put_32 (abfd
, src
->l_parm
, dst
->l_parm
);
2829 xcoff_swap_reloc_in (bfd
*abfd
, void * s
, void * d
)
2831 struct external_reloc
*src
= (struct external_reloc
*) s
;
2832 struct internal_reloc
*dst
= (struct internal_reloc
*) d
;
2834 memset (dst
, 0, sizeof (struct internal_reloc
));
2836 dst
->r_vaddr
= bfd_get_32 (abfd
, src
->r_vaddr
);
2837 dst
->r_symndx
= bfd_get_32 (abfd
, src
->r_symndx
);
2838 dst
->r_size
= bfd_get_8 (abfd
, src
->r_size
);
2839 dst
->r_type
= bfd_get_8 (abfd
, src
->r_type
);
2843 xcoff_swap_reloc_out (bfd
*abfd
, void * s
, void * d
)
2845 struct internal_reloc
*src
= (struct internal_reloc
*) s
;
2846 struct external_reloc
*dst
= (struct external_reloc
*) d
;
2848 bfd_put_32 (abfd
, src
->r_vaddr
, dst
->r_vaddr
);
2849 bfd_put_32 (abfd
, src
->r_symndx
, dst
->r_symndx
);
2850 bfd_put_8 (abfd
, src
->r_type
, dst
->r_type
);
2851 bfd_put_8 (abfd
, src
->r_size
, dst
->r_size
);
2853 return bfd_coff_relsz (abfd
);
2856 /* Swap in the ldrel structure. */
2859 xcoff_swap_ldrel_in (bfd
*abfd
, const void * s
, struct internal_ldrel
*dst
)
2861 const struct external_ldrel
*src
= (const struct external_ldrel
*) s
;
2863 dst
->l_vaddr
= bfd_get_32 (abfd
, src
->l_vaddr
);
2864 dst
->l_symndx
= bfd_get_32 (abfd
, src
->l_symndx
);
2865 dst
->l_rtype
= bfd_get_16 (abfd
, src
->l_rtype
);
2866 dst
->l_rsecnm
= bfd_get_16 (abfd
, src
->l_rsecnm
);
2869 /* Swap out the ldrel structure. */
2872 xcoff_swap_ldrel_out (bfd
*abfd
, const struct internal_ldrel
*src
, void * d
)
2874 struct external_ldrel
*dst
= (struct external_ldrel
*) d
;
2876 bfd_put_32 (abfd
, src
->l_vaddr
, dst
->l_vaddr
);
2877 bfd_put_32 (abfd
, src
->l_symndx
, dst
->l_symndx
);
2878 bfd_put_16 (abfd
, (bfd_vma
) src
->l_rtype
, dst
->l_rtype
);
2879 bfd_put_16 (abfd
, (bfd_vma
) src
->l_rsecnm
, dst
->l_rsecnm
);
2884 xcoff_reloc_type_noop (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2885 asection
*input_section ATTRIBUTE_UNUSED
,
2886 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2887 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
2888 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2889 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
,
2890 bfd_vma val ATTRIBUTE_UNUSED
,
2891 bfd_vma addend ATTRIBUTE_UNUSED
,
2892 bfd_vma
*relocation ATTRIBUTE_UNUSED
,
2893 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2899 xcoff_reloc_type_fail (bfd
*input_bfd
,
2900 asection
*input_section ATTRIBUTE_UNUSED
,
2901 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2902 struct internal_reloc
*rel
,
2903 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2904 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
,
2905 bfd_vma val ATTRIBUTE_UNUSED
,
2906 bfd_vma addend ATTRIBUTE_UNUSED
,
2907 bfd_vma
*relocation ATTRIBUTE_UNUSED
,
2908 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2911 /* xgettext: c-format */
2912 (_("%pB: unsupported relocation type %#x"),
2913 input_bfd
, (unsigned int) rel
->r_type
);
2914 bfd_set_error (bfd_error_bad_value
);
2919 xcoff_reloc_type_pos (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2920 asection
*input_section ATTRIBUTE_UNUSED
,
2921 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2922 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
2923 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2924 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
,
2927 bfd_vma
*relocation
,
2928 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2930 *relocation
= val
+ addend
;
2935 xcoff_reloc_type_neg (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2936 asection
*input_section ATTRIBUTE_UNUSED
,
2937 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2938 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
2939 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2940 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
,
2943 bfd_vma
*relocation
,
2944 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2946 *relocation
= - val
- addend
;
2951 xcoff_reloc_type_rel (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2952 asection
*input_section
,
2953 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2954 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
2955 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2956 struct reloc_howto_struct
*howto
,
2959 bfd_vma
*relocation
,
2960 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2962 howto
->pc_relative
= true;
2964 /* A PC relative reloc includes the section address. */
2965 addend
+= input_section
->vma
;
2967 *relocation
= val
+ addend
;
2968 *relocation
-= (input_section
->output_section
->vma
2969 + input_section
->output_offset
);
2974 xcoff_reloc_type_toc (bfd
*input_bfd
,
2975 asection
*input_section ATTRIBUTE_UNUSED
,
2977 struct internal_reloc
*rel
,
2978 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2979 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
,
2981 bfd_vma addend ATTRIBUTE_UNUSED
,
2982 bfd_vma
*relocation
,
2983 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2985 struct xcoff_link_hash_entry
*h
;
2987 if (0 > rel
->r_symndx
)
2990 h
= obj_xcoff_sym_hashes (input_bfd
)[rel
->r_symndx
];
2992 if (h
!= NULL
&& h
->smclas
!= XMC_TD
)
2994 if (h
->toc_section
== NULL
)
2997 /* xgettext: c-format */
2998 (_("%pB: TOC reloc at %#" PRIx64
" to symbol `%s' with no TOC entry"),
2999 input_bfd
, (uint64_t) rel
->r_vaddr
, h
->root
.root
.string
);
3000 bfd_set_error (bfd_error_bad_value
);
3004 BFD_ASSERT ((h
->flags
& XCOFF_SET_TOC
) == 0);
3005 val
= (h
->toc_section
->output_section
->vma
3006 + h
->toc_section
->output_offset
);
3009 /* We can't use the preexisting value written down by the
3010 assembly, as R_TOCU needs to be adjusted when the final
3011 R_TOCL value is signed. */
3012 *relocation
= val
- xcoff_data (output_bfd
)->toc
;
3014 if (rel
->r_type
== R_TOCU
)
3015 *relocation
= ((*relocation
+ 0x8000) >> 16) & 0xffff;
3016 if (rel
->r_type
== R_TOCL
)
3017 *relocation
= *relocation
& 0x0000ffff;
3023 xcoff_reloc_type_ba (bfd
*input_bfd ATTRIBUTE_UNUSED
,
3024 asection
*input_section ATTRIBUTE_UNUSED
,
3025 bfd
*output_bfd ATTRIBUTE_UNUSED
,
3026 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
3027 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
3028 struct reloc_howto_struct
*howto
,
3031 bfd_vma
*relocation
,
3032 bfd_byte
*contents ATTRIBUTE_UNUSED
)
3034 howto
->src_mask
&= ~3;
3035 howto
->dst_mask
= howto
->src_mask
;
3037 *relocation
= val
+ addend
;
3043 xcoff_reloc_type_br (bfd
*input_bfd
,
3044 asection
*input_section
,
3045 bfd
*output_bfd ATTRIBUTE_UNUSED
,
3046 struct internal_reloc
*rel
,
3047 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
3048 struct reloc_howto_struct
*howto
,
3051 bfd_vma
*relocation
,
3054 struct xcoff_link_hash_entry
*h
;
3055 bfd_vma section_offset
;
3057 if (0 > rel
->r_symndx
)
3060 h
= obj_xcoff_sym_hashes (input_bfd
)[rel
->r_symndx
];
3061 section_offset
= rel
->r_vaddr
- input_section
->vma
;
3063 /* If we see an R_BR or R_RBR reloc which is jumping to global
3064 linkage code, and it is followed by an appropriate cror nop
3065 instruction, we replace the cror with lwz r2,20(r1). This
3066 restores the TOC after the glink code. Contrariwise, if the
3067 call is followed by a lwz r2,20(r1), but the call is not
3068 going to global linkage code, we can replace the load with a
3071 && (bfd_link_hash_defined
== h
->root
.type
3072 || bfd_link_hash_defweak
== h
->root
.type
)
3073 && section_offset
+ 8 <= input_section
->size
)
3078 pnext
= contents
+ section_offset
+ 4;
3079 next
= bfd_get_32 (input_bfd
, pnext
);
3081 /* The _ptrgl function is magic. It is used by the AIX
3082 compiler to call a function through a pointer. */
3083 if (h
->smclas
== XMC_GL
|| strcmp (h
->root
.root
.string
, "._ptrgl") == 0)
3085 if (next
== 0x4def7b82 /* cror 15,15,15 */
3086 || next
== 0x4ffffb82 /* cror 31,31,31 */
3087 || next
== 0x60000000) /* ori r0,r0,0 */
3088 bfd_put_32 (input_bfd
, 0x80410014, pnext
); /* lwz r2,20(r1) */
3093 if (next
== 0x80410014) /* lwz r2,20(r1) */
3094 bfd_put_32 (input_bfd
, 0x60000000, pnext
); /* ori r0,r0,0 */
3097 else if (NULL
!= h
&& bfd_link_hash_undefined
== h
->root
.type
)
3099 /* Normally, this relocation is against a defined symbol. In the
3100 case where this is a partial link and the output section offset
3101 is greater than 2^25, the linker will return an invalid error
3102 message that the relocation has been truncated. Yes it has been
3103 truncated but no it not important. For this case, disable the
3104 overflow checking. */
3106 howto
->complain_on_overflow
= complain_overflow_dont
;
3109 /* The original PC-relative relocation is biased by -r_vaddr, so adding
3110 the value below will give the absolute target address. */
3111 *relocation
= val
+ addend
+ rel
->r_vaddr
;
3113 howto
->src_mask
&= ~3;
3114 howto
->dst_mask
= howto
->src_mask
;
3117 && (h
->root
.type
== bfd_link_hash_defined
3118 || h
->root
.type
== bfd_link_hash_defweak
)
3119 && bfd_is_abs_section (h
->root
.u
.def
.section
)
3120 && section_offset
+ 4 <= input_section
->size
)
3125 /* Turn the relative branch into an absolute one by setting the
3127 ptr
= contents
+ section_offset
;
3128 insn
= bfd_get_32 (input_bfd
, ptr
);
3130 bfd_put_32 (input_bfd
, insn
, ptr
);
3132 /* Make the howto absolute too. */
3133 howto
->pc_relative
= false;
3134 howto
->complain_on_overflow
= complain_overflow_bitfield
;
3138 /* Use a PC-relative howto and subtract the instruction's address
3139 from the target address we calculated above. */
3140 howto
->pc_relative
= true;
3141 *relocation
-= (input_section
->output_section
->vma
3142 + input_section
->output_offset
3149 xcoff_reloc_type_crel (bfd
*input_bfd ATTRIBUTE_UNUSED
,
3150 asection
*input_section
,
3151 bfd
*output_bfd ATTRIBUTE_UNUSED
,
3152 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
3153 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
3154 struct reloc_howto_struct
*howto
,
3155 bfd_vma val ATTRIBUTE_UNUSED
,
3157 bfd_vma
*relocation
,
3158 bfd_byte
*contents ATTRIBUTE_UNUSED
)
3160 howto
->pc_relative
= true;
3161 howto
->src_mask
&= ~3;
3162 howto
->dst_mask
= howto
->src_mask
;
3164 /* A PC relative reloc includes the section address. */
3165 addend
+= input_section
->vma
;
3167 *relocation
= val
+ addend
;
3168 *relocation
-= (input_section
->output_section
->vma
3169 + input_section
->output_offset
);
3174 xcoff_reloc_type_tls (bfd
*input_bfd ATTRIBUTE_UNUSED
,
3175 asection
*input_section ATTRIBUTE_UNUSED
,
3176 bfd
*output_bfd ATTRIBUTE_UNUSED
,
3177 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
3178 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
3179 struct reloc_howto_struct
*howto
,
3182 bfd_vma
*relocation
,
3183 bfd_byte
*contents ATTRIBUTE_UNUSED
)
3185 struct xcoff_link_hash_entry
*h
;
3187 if (0 > rel
->r_symndx
)
3190 h
= obj_xcoff_sym_hashes (input_bfd
)[rel
->r_symndx
];
3192 /* FIXME: R_TLSML is targeting a internal TOC symbol, which will
3193 make the following checks failing. It should be moved with
3194 R_TLSM bellow once it works. */
3195 if (howto
->type
== R_TLSML
)
3201 /* FIXME: h is sometimes null, if the TLS symbol is not exported. */
3205 (_("%pB: TLS relocation at (0x%" BFD_VMA_FMT
"x) over "
3206 "internal symbols (C_HIDEXT) not yet possible\n"),
3207 input_bfd
, rel
->r_vaddr
);
3212 /* TLS relocations must target a TLS symbol. */
3213 if (h
->smclas
!= XMC_TL
&& h
->smclas
!= XMC_UL
)
3216 (_("%pB: TLS relocation at (0x%" BFD_VMA_FMT
"x) over "
3217 "non-TLS symbol %s (0x%x)\n"),
3218 input_bfd
, rel
->r_vaddr
, h
->root
.root
.string
, h
->smclas
);
3222 /* Local TLS relocations must target a local symbol, ie
3224 if ((rel
->r_type
== R_TLS_LD
|| rel
->r_type
== R_TLS_LE
)
3225 && (((h
->flags
& XCOFF_DEF_REGULAR
) == 0
3226 && (h
->flags
& XCOFF_DEF_DYNAMIC
) != 0)
3227 || (h
->flags
& XCOFF_IMPORT
) != 0))
3230 (_("%pB: TLS local relocation at (0x%" BFD_VMA_FMT
"x) over "
3231 "imported symbol %s\n"),
3232 input_bfd
, rel
->r_vaddr
, h
->root
.root
.string
);
3236 /* R_TLSM and R_TLSML are relocations used by the loader.
3237 The value must be 0.
3238 FIXME: move R_TLSML here. */
3239 if (howto
->type
== R_TLSM
)
3245 /* Other TLS relocations aims to put offsets from TLS pointers
3246 starting at -0x7c00 (or -0x7800 in XCOFF64). It becomes a
3247 simple R_POS relocation as long as .tdata and .tbss addresses
3248 start at the same value. This is done in aix ld scripts.
3249 TODO: implement optimization when tls size is < 62K. */
3250 *relocation
= val
+ addend
;
3256 xcoff_complain_overflow_dont_func (bfd
*input_bfd ATTRIBUTE_UNUSED
,
3257 bfd_vma val ATTRIBUTE_UNUSED
,
3258 bfd_vma relocation ATTRIBUTE_UNUSED
,
3259 struct reloc_howto_struct
*
3260 howto ATTRIBUTE_UNUSED
)
3266 xcoff_complain_overflow_bitfield_func (bfd
*input_bfd
,
3269 struct reloc_howto_struct
*howto
)
3271 bfd_vma fieldmask
, signmask
, ss
;
3274 /* Get the values to be added together. For signed and unsigned
3275 relocations, we assume that all values should be truncated to
3276 the size of an address. For bitfields, all the bits matter.
3277 See also bfd_check_overflow. */
3278 fieldmask
= N_ONES (howto
->bitsize
);
3280 b
= val
& howto
->src_mask
;
3282 /* Much like unsigned, except no trimming with addrmask. In
3283 addition, the sum overflows if there is a carry out of
3284 the bfd_vma, i.e., the sum is less than either input
3286 a
>>= howto
->rightshift
;
3287 b
>>= howto
->bitpos
;
3289 /* Bitfields are sometimes used for signed numbers; for
3290 example, a 13-bit field sometimes represents values in
3291 0..8191 and sometimes represents values in -4096..4095.
3292 If the field is signed and a is -4095 (0x1001) and b is
3293 -1 (0x1fff), the sum is -4096 (0x1000), but (0x1001 +
3294 0x1fff is 0x3000). It's not clear how to handle this
3295 everywhere, since there is not way to know how many bits
3296 are significant in the relocation, but the original code
3297 assumed that it was fully sign extended, and we will keep
3299 signmask
= (fieldmask
>> 1) + 1;
3301 if ((a
& ~ fieldmask
) != 0)
3303 /* Some bits out of the field are set. This might not
3304 be a problem: if this is a signed bitfield, it is OK
3305 iff all the high bits are set, including the sign
3306 bit. We'll try setting all but the most significant
3307 bit in the original relocation value: if this is all
3308 ones, we are OK, assuming a signed bitfield. */
3309 ss
= (signmask
<< howto
->rightshift
) - 1;
3310 if ((ss
| relocation
) != ~ (bfd_vma
) 0)
3315 /* We just assume (b & ~ fieldmask) == 0. */
3317 /* We explicitly permit wrap around if this relocation
3318 covers the high bit of an address. The Linux kernel
3319 relies on it, and it is the only way to write assembler
3320 code which can run when loaded at a location 0x80000000
3321 away from the location at which it is linked. */
3322 if ((unsigned) howto
->bitsize
+ howto
->rightshift
3323 == bfd_arch_bits_per_address (input_bfd
))
3327 if (sum
< a
|| (sum
& ~ fieldmask
) != 0)
3329 /* There was a carry out, or the field overflow. Test
3330 for signed operands again. Here is the overflow test
3331 is as for complain_overflow_signed. */
3332 if (((~ (a
^ b
)) & (a
^ sum
)) & signmask
)
3340 xcoff_complain_overflow_signed_func (bfd
*input_bfd
,
3343 struct reloc_howto_struct
*howto
)
3345 bfd_vma addrmask
, fieldmask
, signmask
, ss
;
3348 /* Get the values to be added together. For signed and unsigned
3349 relocations, we assume that all values should be truncated to
3350 the size of an address. For bitfields, all the bits matter.
3351 See also bfd_check_overflow. */
3352 fieldmask
= N_ONES (howto
->bitsize
);
3353 addrmask
= N_ONES (bfd_arch_bits_per_address (input_bfd
)) | fieldmask
;
3355 b
= val
& howto
->src_mask
;
3357 a
= (a
& addrmask
) >> howto
->rightshift
;
3359 /* If any sign bits are set, all sign bits must be set.
3360 That is, A must be a valid negative address after
3362 signmask
= ~ (fieldmask
>> 1);
3364 if (ss
!= 0 && ss
!= ((addrmask
>> howto
->rightshift
) & signmask
))
3367 /* We only need this next bit of code if the sign bit of B
3368 is below the sign bit of A. This would only happen if
3369 SRC_MASK had fewer bits than BITSIZE. Note that if
3370 SRC_MASK has more bits than BITSIZE, we can get into
3371 trouble; we would need to verify that B is in range, as
3372 we do for A above. */
3373 signmask
= ((~ howto
->src_mask
) >> 1) & howto
->src_mask
;
3374 if ((b
& signmask
) != 0)
3376 /* Set all the bits above the sign bit. */
3377 b
-= signmask
<<= 1;
3380 b
= (b
& addrmask
) >> howto
->bitpos
;
3382 /* Now we can do the addition. */
3385 /* See if the result has the correct sign. Bits above the
3386 sign bit are junk now; ignore them. If the sum is
3387 positive, make sure we did not have all negative inputs;
3388 if the sum is negative, make sure we did not have all
3389 positive inputs. The test below looks only at the sign
3390 bits, and it really just
3391 SIGN (A) == SIGN (B) && SIGN (A) != SIGN (SUM)
3393 signmask
= (fieldmask
>> 1) + 1;
3394 if (((~ (a
^ b
)) & (a
^ sum
)) & signmask
)
3401 xcoff_complain_overflow_unsigned_func (bfd
*input_bfd
,
3404 struct reloc_howto_struct
*howto
)
3406 bfd_vma addrmask
, fieldmask
;
3409 /* Get the values to be added together. For signed and unsigned
3410 relocations, we assume that all values should be truncated to
3411 the size of an address. For bitfields, all the bits matter.
3412 See also bfd_check_overflow. */
3413 fieldmask
= N_ONES (howto
->bitsize
);
3414 addrmask
= N_ONES (bfd_arch_bits_per_address (input_bfd
)) | fieldmask
;
3416 b
= val
& howto
->src_mask
;
3418 /* Checking for an unsigned overflow is relatively easy:
3419 trim the addresses and add, and trim the result as well.
3420 Overflow is normally indicated when the result does not
3421 fit in the field. However, we also need to consider the
3422 case when, e.g., fieldmask is 0x7fffffff or smaller, an
3423 input is 0x80000000, and bfd_vma is only 32 bits; then we
3424 will get sum == 0, but there is an overflow, since the
3425 inputs did not fit in the field. Instead of doing a
3426 separate test, we can check for this by or-ing in the
3427 operands when testing for the sum overflowing its final
3429 a
= (a
& addrmask
) >> howto
->rightshift
;
3430 b
= (b
& addrmask
) >> howto
->bitpos
;
3431 sum
= (a
+ b
) & addrmask
;
3432 if ((a
| b
| sum
) & ~ fieldmask
)
3438 /* This is the relocation function for the RS/6000/POWER/PowerPC.
3439 This is currently the only processor which uses XCOFF; I hope that
3442 The original version was based on two documents:
3443 the PowerPC AIX Version 4 Application Binary Interface, First
3444 Edition (April 1992), and the PowerOpen ABI, Big-Endian
3445 32-Bit Hardware Implementation (June 30, 1994). Differences
3446 between the documents are noted below.
3447 Now, IBM has released an official documentation about XCOFF
3449 https://www.ibm.com/support/knowledgecenter/ssw_aix_72/filesreference/XCOFF.html
3451 Unsupported r_type's
3457 These relocs are defined by the PowerPC ABI to be
3458 relative branches which use half of the difference
3459 between the symbol and the program counter. I can't
3460 quite figure out when this is useful. These relocs are
3461 not defined by the PowerOpen ABI.
3466 Simple positive relocation.
3469 Simple negative relocation.
3472 Simple PC relative relocation.
3475 TOC relative relocation. The value in the instruction in
3476 the input file is the offset from the input file TOC to
3477 the desired location. We want the offset from the final
3478 TOC to the desired location. We have:
3483 so we must change insn by on - in.
3484 This relocation allows the linker to perform optimizations
3485 by transforming a load instruction into a add-immediate
3486 when possible. The relocation is, then, changed to R_TRLA
3488 TODO: Currently, the optimisation isn't implemented.
3491 TOC relative relocation. Same as R_TOC, except that
3492 the optimization isn't allowed
3495 TOC relative relocation. This is a TOC relative load
3496 address instruction which have been changed to an add-
3497 immediate instruction.
3500 GL linkage relocation. The value of this relocation
3501 is the address of the external symbol in the TOC
3505 Local object TOC address. I can't figure out the
3506 difference between this and case R_GL.
3509 The PowerPC AIX ABI describes this as a load which may be
3510 changed to a load address. The PowerOpen ABI says this
3511 is the same as case R_POS.
3514 The PowerPC AIX ABI describes this as a load address
3515 which may be changed to a load. The PowerOpen ABI says
3516 this is the same as R_POS.
3519 Not a relocation but a way to prevent the garbage
3520 collector of AIX linker to remove symbols.
3521 This is not needed in our case.
3524 The PowerOpen ABI says this is the same as R_RBA.
3527 Absolute branch which may be modified to become a
3531 The PowerOpen ABI says this is the same as R_RBR.
3534 A relative branch which may be modified to become an
3538 The PowerPC ABI defines this as an absolute call which
3539 may be modified to become a relative call. The PowerOpen
3540 ABI does not define this relocation type.
3543 The PowerPC ABI defines this as a relative call which may
3544 be modified to become an absolute call. The PowerOpen
3545 ABI does not define this relocation type.
3548 The PowerPC ABI defines this as an absolute branch to a
3549 fixed address which may be modified to an absolute branch
3550 to a symbol. The PowerOpen ABI does not define this
3554 The PowerPC ABI defines this as an absolute branch to a
3555 fixed address which may be modified to a relative branch.
3556 The PowerOpen ABI does not define this relocation type.
3559 Thread-local storage relocation using general-dynamic
3563 Thread-local storage relocation using initial-exec model.
3566 Thread-local storage relocation using local-dynamic model.
3569 Thread-local storage relocation using local-exec model.
3572 Tread-local storage relocation used by the loader.
3575 Tread-local storage relocation used by the loader.
3578 Upper TOC relative relocation. The value is the
3579 high-order 16 bit of a TOC relative relocation.
3582 Lower TOC relative relocation. The value is the
3583 low-order 16 bit of a TOC relative relocation.
3587 xcoff_ppc_relocate_section (bfd
*output_bfd
,
3588 struct bfd_link_info
*info
,
3590 asection
*input_section
,
3592 struct internal_reloc
*relocs
,
3593 struct internal_syment
*syms
,
3594 asection
**sections
)
3596 struct internal_reloc
*rel
;
3597 struct internal_reloc
*relend
;
3600 relend
= rel
+ input_section
->reloc_count
;
3601 for (; rel
< relend
; rel
++)
3604 struct xcoff_link_hash_entry
*h
;
3605 struct internal_syment
*sym
;
3608 struct reloc_howto_struct howto
;
3610 bfd_vma value_to_relocate
;
3614 /* Relocation type R_REF is a special relocation type which is
3615 merely used to prevent garbage collection from occurring for
3616 the csect including the symbol which it references. */
3617 if (rel
->r_type
== R_REF
)
3620 /* Retrieve default value in HOWTO table and fix up according
3621 to r_size field, if it can be different.
3622 This should be made during relocation reading but the algorithms
3623 are expecting constant howtos. */
3624 memcpy (&howto
, &xcoff_howto_table
[rel
->r_type
], sizeof (howto
));
3625 if (howto
.bitsize
!= (rel
->r_size
& 0x1f) + 1)
3627 switch (rel
->r_type
)
3631 howto
.bitsize
= (rel
->r_size
& 0x1f) + 1;
3632 howto
.size
= howto
.bitsize
> 16 ? 2 : 1;
3633 howto
.src_mask
= howto
.dst_mask
= N_ONES (howto
.bitsize
);
3638 (_("%pB: relocatation (%d) at (0x%" BFD_VMA_FMT
"x) has wrong"
3639 " r_rsize (0x%x)\n"),
3640 input_bfd
, rel
->r_type
, rel
->r_vaddr
, rel
->r_size
);
3645 howto
.complain_on_overflow
= (rel
->r_size
& 0x80
3646 ? complain_overflow_signed
3647 : complain_overflow_bitfield
);
3654 symndx
= rel
->r_symndx
;
3660 h
= obj_xcoff_sym_hashes (input_bfd
)[symndx
];
3661 sym
= syms
+ symndx
;
3662 addend
= - sym
->n_value
;
3666 sec
= sections
[symndx
];
3667 /* Hack to make sure we use the right TOC anchor value
3668 if this reloc is against the TOC anchor. */
3669 if (sec
->name
[3] == '0'
3670 && strcmp (sec
->name
, ".tc0") == 0)
3671 val
= xcoff_data (output_bfd
)->toc
;
3673 val
= (sec
->output_section
->vma
3674 + sec
->output_offset
3680 if (info
->unresolved_syms_in_objects
!= RM_IGNORE
3681 && (h
->flags
& XCOFF_WAS_UNDEFINED
) != 0)
3682 (*info
->callbacks
->undefined_symbol
)
3683 (info
, h
->root
.root
.string
,
3684 input_bfd
, input_section
,
3685 rel
->r_vaddr
- input_section
->vma
,
3686 info
->unresolved_syms_in_objects
== RM_DIAGNOSE
&&
3687 !info
->warn_unresolved_syms
);
3689 if (h
->root
.type
== bfd_link_hash_defined
3690 || h
->root
.type
== bfd_link_hash_defweak
)
3692 sec
= h
->root
.u
.def
.section
;
3693 val
= (h
->root
.u
.def
.value
3694 + sec
->output_section
->vma
3695 + sec
->output_offset
);
3697 else if (h
->root
.type
== bfd_link_hash_common
)
3699 sec
= h
->root
.u
.c
.p
->section
;
3700 val
= (sec
->output_section
->vma
3701 + sec
->output_offset
);
3706 BFD_ASSERT (bfd_link_relocatable (info
)
3707 || (info
->static_link
3708 && (h
->flags
& XCOFF_WAS_UNDEFINED
) != 0)
3709 || (h
->flags
& XCOFF_DEF_DYNAMIC
) != 0
3710 || (h
->flags
& XCOFF_IMPORT
) != 0);
3715 if (rel
->r_type
>= XCOFF_MAX_CALCULATE_RELOCATION
3716 || !((*xcoff_calculate_relocation
[rel
->r_type
])
3717 (input_bfd
, input_section
, output_bfd
, rel
, sym
, &howto
, val
,
3718 addend
, &relocation
, contents
)))
3722 address
= rel
->r_vaddr
- input_section
->vma
;
3723 location
= contents
+ address
;
3725 if (address
> input_section
->size
)
3728 /* Get the value we are going to relocate. */
3729 if (1 == howto
.size
)
3730 value_to_relocate
= bfd_get_16 (input_bfd
, location
);
3732 value_to_relocate
= bfd_get_32 (input_bfd
, location
);
3736 FIXME: We may drop bits during the addition
3737 which we don't check for. We must either check at every single
3738 operation, which would be tedious, or we must do the computations
3739 in a type larger than bfd_vma, which would be inefficient. */
3741 if (((*xcoff_complain_overflow
[howto
.complain_on_overflow
])
3742 (input_bfd
, value_to_relocate
, relocation
, &howto
)))
3745 char buf
[SYMNMLEN
+ 1];
3746 char reloc_type_name
[10];
3758 name
= _bfd_coff_internal_syment_name (input_bfd
, sym
, buf
);
3762 sprintf (reloc_type_name
, "0x%02x", rel
->r_type
);
3764 (*info
->callbacks
->reloc_overflow
)
3765 (info
, (h
? &h
->root
: NULL
), name
, reloc_type_name
,
3766 (bfd_vma
) 0, input_bfd
, input_section
,
3767 rel
->r_vaddr
- input_section
->vma
);
3770 /* Add RELOCATION to the right bits of VALUE_TO_RELOCATE. */
3771 value_to_relocate
= ((value_to_relocate
& ~howto
.dst_mask
)
3772 | (((value_to_relocate
& howto
.src_mask
)
3773 + relocation
) & howto
.dst_mask
));
3775 /* Put the value back in the object file. */
3776 if (1 == howto
.size
)
3777 bfd_put_16 (input_bfd
, value_to_relocate
, location
);
3779 bfd_put_32 (input_bfd
, value_to_relocate
, location
);
3785 /* gcc-8 warns (*) on all the strncpy calls in this function about
3786 possible string truncation. The "truncation" is not a bug. We
3787 have an external representation of structs with fields that are not
3788 necessarily NULL terminated and corresponding internal
3789 representation fields that are one larger so that they can always
3791 gcc versions between 4.2 and 4.6 do not allow pragma control of
3792 diagnostics inside functions, giving a hard error if you try to use
3793 the finer control available with later versions.
3794 gcc prior to 4.2 warns about diagnostic push and pop.
3795 gcc-5, gcc-6 and gcc-7 warn that -Wstringop-truncation is unknown,
3796 unless you also add #pragma GCC diagnostic ignored "-Wpragma".
3797 (*) Depending on your system header files! */
3798 #if GCC_VERSION >= 8000
3799 # pragma GCC diagnostic push
3800 # pragma GCC diagnostic ignored "-Wstringop-truncation"
3803 _bfd_xcoff_put_ldsymbol_name (bfd
*abfd ATTRIBUTE_UNUSED
,
3804 struct xcoff_loader_info
*ldinfo
,
3805 struct internal_ldsym
*ldsym
,
3809 len
= strlen (name
);
3811 if (len
<= SYMNMLEN
)
3812 strncpy (ldsym
->_l
._l_name
, name
, SYMNMLEN
);
3815 if (ldinfo
->string_size
+ len
+ 3 > ldinfo
->string_alc
)
3817 bfd_size_type newalc
;
3820 newalc
= ldinfo
->string_alc
* 2;
3823 while (ldinfo
->string_size
+ len
+ 3 > newalc
)
3826 newstrings
= bfd_realloc (ldinfo
->strings
, newalc
);
3827 if (newstrings
== NULL
)
3829 ldinfo
->failed
= true;
3832 ldinfo
->string_alc
= newalc
;
3833 ldinfo
->strings
= newstrings
;
3836 bfd_put_16 (ldinfo
->output_bfd
, (bfd_vma
) (len
+ 1),
3837 ldinfo
->strings
+ ldinfo
->string_size
);
3838 strcpy (ldinfo
->strings
+ ldinfo
->string_size
+ 2, name
);
3839 ldsym
->_l
._l_l
._l_zeroes
= 0;
3840 ldsym
->_l
._l_l
._l_offset
= ldinfo
->string_size
+ 2;
3841 ldinfo
->string_size
+= len
+ 3;
3848 _bfd_xcoff_put_symbol_name (struct bfd_link_info
*info
,
3849 struct bfd_strtab_hash
*strtab
,
3850 struct internal_syment
*sym
,
3853 if (strlen (name
) <= SYMNMLEN
)
3855 strncpy (sym
->_n
._n_name
, name
, SYMNMLEN
);
3862 hash
= !info
->traditional_format
;
3863 indx
= _bfd_stringtab_add (strtab
, name
, hash
, false);
3864 if (indx
== (bfd_size_type
) -1)
3866 sym
->_n
._n_n
._n_zeroes
= 0;
3867 sym
->_n
._n_n
._n_offset
= STRING_SIZE_SIZE
+ indx
;
3871 #if GCC_VERSION >= 8000
3872 # pragma GCC diagnostic pop
3876 xcoff_create_csect_from_smclas (bfd
*abfd
,
3877 union internal_auxent
*aux
,
3878 const char *symbol_name
)
3880 asection
*return_value
= NULL
;
3882 /* .sv64 = x_smclas == 17
3883 This is an invalid csect for 32 bit apps. */
3884 static const char * const names
[] =
3886 ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo", /* 0 - 7 */
3887 ".sv", ".bs", ".ds", ".uc", ".ti", ".tb", NULL
, ".tc0", /* 8 - 15 */
3888 ".td", NULL
, ".sv3264", NULL
, ".tl", ".ul", ".te"
3891 if ((aux
->x_csect
.x_smclas
< ARRAY_SIZE (names
))
3892 && (NULL
!= names
[aux
->x_csect
.x_smclas
]))
3894 return_value
= bfd_make_section_anyway
3895 (abfd
, names
[aux
->x_csect
.x_smclas
]);
3900 /* xgettext: c-format */
3901 (_("%pB: symbol `%s' has unrecognized smclas %d"),
3902 abfd
, symbol_name
, aux
->x_csect
.x_smclas
);
3903 bfd_set_error (bfd_error_bad_value
);
3906 return return_value
;
3910 xcoff_is_lineno_count_overflow (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_vma value
)
3912 if (0xffff <= value
)
3919 xcoff_is_reloc_count_overflow (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_vma value
)
3921 if (0xffff <= value
)
3928 xcoff_loader_symbol_offset (bfd
*abfd
,
3929 struct internal_ldhdr
*ldhdr ATTRIBUTE_UNUSED
)
3931 return bfd_xcoff_ldhdrsz (abfd
);
3935 xcoff_loader_reloc_offset (bfd
*abfd
, struct internal_ldhdr
*ldhdr
)
3937 return bfd_xcoff_ldhdrsz (abfd
) + ldhdr
->l_nsyms
* bfd_xcoff_ldsymsz (abfd
);
3941 xcoff_generate_rtinit (bfd
*abfd
, const char *init
, const char *fini
,
3944 bfd_byte filehdr_ext
[FILHSZ
];
3945 bfd_byte scnhdr_ext
[SCNHSZ
];
3946 bfd_byte syment_ext
[SYMESZ
* 10];
3947 bfd_byte reloc_ext
[RELSZ
* 3];
3948 bfd_byte
*data_buffer
;
3949 bfd_size_type data_buffer_size
;
3950 bfd_byte
*string_table
= NULL
, *st_tmp
= NULL
;
3951 bfd_size_type string_table_size
;
3953 size_t initsz
, finisz
;
3954 struct internal_filehdr filehdr
;
3955 struct internal_scnhdr scnhdr
;
3956 struct internal_syment syment
;
3957 union internal_auxent auxent
;
3958 struct internal_reloc reloc
;
3960 char *data_name
= ".data";
3961 char *rtinit_name
= "__rtinit";
3962 char *rtld_name
= "__rtld";
3964 if (! bfd_xcoff_rtinit_size (abfd
))
3967 initsz
= (init
== NULL
? 0 : 1 + strlen (init
));
3968 finisz
= (fini
== NULL
? 0 : 1 + strlen (fini
));
3971 memset (filehdr_ext
, 0, FILHSZ
);
3972 memset (&filehdr
, 0, sizeof (struct internal_filehdr
));
3973 filehdr
.f_magic
= bfd_xcoff_magic_number (abfd
);
3974 filehdr
.f_nscns
= 1;
3975 filehdr
.f_timdat
= 0;
3976 filehdr
.f_nsyms
= 0; /* at least 6, no more than 10 */
3977 filehdr
.f_symptr
= 0; /* set below */
3978 filehdr
.f_opthdr
= 0;
3979 filehdr
.f_flags
= 0;
3981 /* section header */
3982 memset (scnhdr_ext
, 0, SCNHSZ
);
3983 memset (&scnhdr
, 0, sizeof (struct internal_scnhdr
));
3984 memcpy (scnhdr
.s_name
, data_name
, strlen (data_name
));
3987 scnhdr
.s_size
= 0; /* set below */
3988 scnhdr
.s_scnptr
= FILHSZ
+ SCNHSZ
;
3989 scnhdr
.s_relptr
= 0; /* set below */
3990 scnhdr
.s_lnnoptr
= 0;
3991 scnhdr
.s_nreloc
= 0; /* either 1 or 2 */
3993 scnhdr
.s_flags
= STYP_DATA
;
3996 0x0000 0x00000000 : rtl
3997 0x0004 0x00000010 : offset to init, or 0
3998 0x0008 0x00000028 : offset to fini, or 0
3999 0x000C 0x0000000C : size of descriptor
4000 0x0010 0x00000000 : init, needs a reloc
4001 0x0014 0x00000040 : offset to init name
4002 0x0018 0x00000000 : flags, padded to a word
4003 0x001C 0x00000000 : empty init
4006 0x0028 0x00000000 : fini, needs a reloc
4007 0x002C 0x00000??? : offset to fini name
4008 0x0030 0x00000000 : flags, padded to a word
4009 0x0034 0x00000000 : empty fini
4013 0x0040 + initsz fini name */
4015 data_buffer_size
= 0x0040 + initsz
+ finisz
;
4016 data_buffer_size
= (data_buffer_size
+ 7) &~ (bfd_size_type
) 7;
4018 data_buffer
= (bfd_byte
*) bfd_zmalloc (data_buffer_size
);
4019 if (data_buffer
== NULL
)
4025 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x04]);
4027 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x14]);
4028 memcpy (&data_buffer
[val
], init
, initsz
);
4034 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x08]);
4035 val
= 0x40 + initsz
;
4036 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x2C]);
4037 memcpy (&data_buffer
[val
], fini
, finisz
);
4041 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x0C]);
4043 scnhdr
.s_size
= data_buffer_size
;
4046 string_table_size
= 0;
4048 string_table_size
+= initsz
;
4050 string_table_size
+= finisz
;
4051 if (string_table_size
)
4053 string_table_size
+= 4;
4054 string_table
= (bfd_byte
*) bfd_zmalloc (string_table_size
);
4055 if (string_table
== NULL
)
4058 val
= string_table_size
;
4059 bfd_h_put_32 (abfd
, val
, &string_table
[0]);
4060 st_tmp
= string_table
+ 4;
4069 memset (syment_ext
, 0, 10 * SYMESZ
);
4070 memset (reloc_ext
, 0, 3 * RELSZ
);
4073 memset (&syment
, 0, sizeof (struct internal_syment
));
4074 memset (&auxent
, 0, sizeof (union internal_auxent
));
4075 memcpy (syment
._n
._n_name
, data_name
, strlen (data_name
));
4077 syment
.n_sclass
= C_HIDEXT
;
4078 syment
.n_numaux
= 1;
4079 auxent
.x_csect
.x_scnlen
.l
= data_buffer_size
;
4080 auxent
.x_csect
.x_smtyp
= 3 << 3 | XTY_SD
;
4081 auxent
.x_csect
.x_smclas
= XMC_RW
;
4082 bfd_coff_swap_sym_out (abfd
, &syment
,
4083 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
4084 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
4086 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
4087 filehdr
.f_nsyms
+= 2;
4090 memset (&syment
, 0, sizeof (struct internal_syment
));
4091 memset (&auxent
, 0, sizeof (union internal_auxent
));
4092 memcpy (syment
._n
._n_name
, rtinit_name
, strlen (rtinit_name
));
4094 syment
.n_sclass
= C_EXT
;
4095 syment
.n_numaux
= 1;
4096 auxent
.x_csect
.x_smtyp
= XTY_LD
;
4097 auxent
.x_csect
.x_smclas
= XMC_RW
;
4098 bfd_coff_swap_sym_out (abfd
, &syment
,
4099 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
4100 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
4102 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
4103 filehdr
.f_nsyms
+= 2;
4108 memset (&syment
, 0, sizeof (struct internal_syment
));
4109 memset (&auxent
, 0, sizeof (union internal_auxent
));
4113 syment
._n
._n_n
._n_offset
= st_tmp
- string_table
;
4114 memcpy (st_tmp
, init
, initsz
);
4118 memcpy (syment
._n
._n_name
, init
, initsz
- 1);
4120 syment
.n_sclass
= C_EXT
;
4121 syment
.n_numaux
= 1;
4122 bfd_coff_swap_sym_out (abfd
, &syment
,
4123 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
4124 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
4126 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
4129 memset (&reloc
, 0, sizeof (struct internal_reloc
));
4130 reloc
.r_vaddr
= 0x0010;
4131 reloc
.r_symndx
= filehdr
.f_nsyms
;
4132 reloc
.r_type
= R_POS
;
4134 bfd_coff_swap_reloc_out (abfd
, &reloc
, &reloc_ext
[0]);
4136 filehdr
.f_nsyms
+= 2;
4137 scnhdr
.s_nreloc
+= 1;
4143 memset (&syment
, 0, sizeof (struct internal_syment
));
4144 memset (&auxent
, 0, sizeof (union internal_auxent
));
4148 syment
._n
._n_n
._n_offset
= st_tmp
- string_table
;
4149 memcpy (st_tmp
, fini
, finisz
);
4153 memcpy (syment
._n
._n_name
, fini
, finisz
- 1);
4155 syment
.n_sclass
= C_EXT
;
4156 syment
.n_numaux
= 1;
4157 bfd_coff_swap_sym_out (abfd
, &syment
,
4158 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
4159 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
4161 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
4164 memset (&reloc
, 0, sizeof (struct internal_reloc
));
4165 reloc
.r_vaddr
= 0x0028;
4166 reloc
.r_symndx
= filehdr
.f_nsyms
;
4167 reloc
.r_type
= R_POS
;
4169 bfd_coff_swap_reloc_out (abfd
, &reloc
,
4170 &reloc_ext
[scnhdr
.s_nreloc
* RELSZ
]);
4172 filehdr
.f_nsyms
+= 2;
4173 scnhdr
.s_nreloc
+= 1;
4178 memset (&syment
, 0, sizeof (struct internal_syment
));
4179 memset (&auxent
, 0, sizeof (union internal_auxent
));
4180 memcpy (syment
._n
._n_name
, rtld_name
, strlen (rtld_name
));
4181 syment
.n_sclass
= C_EXT
;
4182 syment
.n_numaux
= 1;
4183 bfd_coff_swap_sym_out (abfd
, &syment
,
4184 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
4185 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
4187 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
4190 memset (&reloc
, 0, sizeof (struct internal_reloc
));
4191 reloc
.r_vaddr
= 0x0000;
4192 reloc
.r_symndx
= filehdr
.f_nsyms
;
4193 reloc
.r_type
= R_POS
;
4195 bfd_coff_swap_reloc_out (abfd
, &reloc
,
4196 &reloc_ext
[scnhdr
.s_nreloc
* RELSZ
]);
4198 filehdr
.f_nsyms
+= 2;
4199 scnhdr
.s_nreloc
+= 1;
4202 scnhdr
.s_relptr
= scnhdr
.s_scnptr
+ data_buffer_size
;
4203 filehdr
.f_symptr
= scnhdr
.s_relptr
+ scnhdr
.s_nreloc
* RELSZ
;
4205 bfd_coff_swap_filehdr_out (abfd
, &filehdr
, filehdr_ext
);
4206 bfd_bwrite (filehdr_ext
, FILHSZ
, abfd
);
4207 bfd_coff_swap_scnhdr_out (abfd
, &scnhdr
, scnhdr_ext
);
4208 bfd_bwrite (scnhdr_ext
, SCNHSZ
, abfd
);
4209 bfd_bwrite (data_buffer
, data_buffer_size
, abfd
);
4210 bfd_bwrite (reloc_ext
, scnhdr
.s_nreloc
* RELSZ
, abfd
);
4211 bfd_bwrite (syment_ext
, filehdr
.f_nsyms
* SYMESZ
, abfd
);
4212 bfd_bwrite (string_table
, string_table_size
, abfd
);
4221 static reloc_howto_type xcoff_dynamic_reloc
=
4222 HOWTO (0, /* type */
4224 2, /* size (0 = byte, 1 = short, 2 = long) */
4226 false, /* pc_relative */
4228 complain_overflow_bitfield
, /* complain_on_overflow */
4229 0, /* special_function */
4231 true, /* partial_inplace */
4232 0xffffffff, /* src_mask */
4233 0xffffffff, /* dst_mask */
4234 false); /* pcrel_offset */
4238 The first word of global linkage code must be modified by filling in
4239 the correct TOC offset. */
4241 static const unsigned long xcoff_glink_code
[9] =
4243 0x81820000, /* lwz r12,0(r2) */
4244 0x90410014, /* stw r2,20(r1) */
4245 0x800c0000, /* lwz r0,0(r12) */
4246 0x804c0004, /* lwz r2,4(r12) */
4247 0x7c0903a6, /* mtctr r0 */
4248 0x4e800420, /* bctr */
4249 0x00000000, /* start of traceback table */
4250 0x000c8000, /* traceback table */
4251 0x00000000, /* traceback table */
4254 /* Table to convert DWARF flags to section names. */
4256 const struct xcoff_dwsect_name xcoff_dwsect_names
[] = {
4257 { SSUBTYP_DWINFO
, ".dwinfo", true },
4258 { SSUBTYP_DWLINE
, ".dwline", true },
4259 { SSUBTYP_DWPBNMS
, ".dwpbnms", true },
4260 { SSUBTYP_DWPBTYP
, ".dwpbtyp", true },
4261 { SSUBTYP_DWARNGE
, ".dwarnge", true },
4262 { SSUBTYP_DWABREV
, ".dwabrev", false },
4263 { SSUBTYP_DWSTR
, ".dwstr", true },
4264 { SSUBTYP_DWRNGES
, ".dwrnges", true }
4267 /* For generic entry points. */
4268 #define _bfd_xcoff_close_and_cleanup _bfd_archive_close_and_cleanup
4269 #define _bfd_xcoff_bfd_free_cached_info _bfd_bool_bfd_true
4270 #define _bfd_xcoff_new_section_hook coff_new_section_hook
4271 #define _bfd_xcoff_get_section_contents _bfd_generic_get_section_contents
4272 #define _bfd_xcoff_get_section_contents_in_window \
4273 _bfd_generic_get_section_contents_in_window
4275 /* For copy private data entry points. */
4276 #define _bfd_xcoff_bfd_copy_private_bfd_data \
4277 _bfd_xcoff_copy_private_bfd_data
4278 #define _bfd_xcoff_bfd_merge_private_bfd_data \
4279 _bfd_generic_bfd_merge_private_bfd_data
4280 #define _bfd_xcoff_bfd_copy_private_section_data \
4281 _bfd_generic_bfd_copy_private_section_data
4282 #define _bfd_xcoff_bfd_copy_private_symbol_data \
4283 _bfd_generic_bfd_copy_private_symbol_data
4284 #define _bfd_xcoff_bfd_copy_private_header_data \
4285 _bfd_generic_bfd_copy_private_header_data
4286 #define _bfd_xcoff_bfd_set_private_flags \
4287 _bfd_generic_bfd_set_private_flags
4288 #define _bfd_xcoff_bfd_print_private_bfd_data \
4289 _bfd_generic_bfd_print_private_bfd_data
4291 /* For archive entry points. */
4292 #define _bfd_xcoff_slurp_extended_name_table \
4293 _bfd_noarchive_slurp_extended_name_table
4294 #define _bfd_xcoff_construct_extended_name_table \
4295 _bfd_noarchive_construct_extended_name_table
4296 #define _bfd_xcoff_truncate_arname bfd_dont_truncate_arname
4297 #define _bfd_xcoff_write_ar_hdr _bfd_generic_write_ar_hdr
4298 #define _bfd_xcoff_get_elt_at_index _bfd_generic_get_elt_at_index
4299 #define _bfd_xcoff_generic_stat_arch_elt _bfd_xcoff_stat_arch_elt
4300 #define _bfd_xcoff_update_armap_timestamp _bfd_bool_bfd_true
4302 /* For symbols entry points. */
4303 #define _bfd_xcoff_get_symtab_upper_bound coff_get_symtab_upper_bound
4304 #define _bfd_xcoff_canonicalize_symtab coff_canonicalize_symtab
4305 #define _bfd_xcoff_make_empty_symbol coff_make_empty_symbol
4306 #define _bfd_xcoff_print_symbol coff_print_symbol
4307 #define _bfd_xcoff_get_symbol_info coff_get_symbol_info
4308 #define _bfd_xcoff_get_symbol_version_string \
4309 _bfd_nosymbols_get_symbol_version_string
4310 #define _bfd_xcoff_bfd_is_local_label_name _bfd_xcoff_is_local_label_name
4311 #define _bfd_xcoff_bfd_is_target_special_symbol \
4312 coff_bfd_is_target_special_symbol
4313 #define _bfd_xcoff_get_lineno coff_get_lineno
4314 #define _bfd_xcoff_find_nearest_line coff_find_nearest_line
4315 #define _bfd_xcoff_find_line coff_find_line
4316 #define _bfd_xcoff_find_inliner_info coff_find_inliner_info
4317 #define _bfd_xcoff_bfd_make_debug_symbol coff_bfd_make_debug_symbol
4318 #define _bfd_xcoff_read_minisymbols _bfd_generic_read_minisymbols
4319 #define _bfd_xcoff_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
4321 /* For reloc entry points. */
4322 #define _bfd_xcoff_get_reloc_upper_bound coff_get_reloc_upper_bound
4323 #define _bfd_xcoff_canonicalize_reloc coff_canonicalize_reloc
4324 #define _bfd_xcoff_set_reloc _bfd_generic_set_reloc
4325 #define _bfd_xcoff_bfd_reloc_type_lookup _bfd_xcoff_reloc_type_lookup
4326 #define _bfd_xcoff_bfd_reloc_name_lookup _bfd_xcoff_reloc_name_lookup
4328 /* For link entry points. */
4329 #define _bfd_xcoff_bfd_get_relocated_section_contents \
4330 bfd_generic_get_relocated_section_contents
4331 #define _bfd_xcoff_bfd_relax_section bfd_generic_relax_section
4332 #define _bfd_xcoff_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
4333 #define _bfd_xcoff_bfd_link_just_syms _bfd_generic_link_just_syms
4334 #define _bfd_xcoff_bfd_copy_link_hash_symbol_type \
4335 _bfd_generic_copy_link_hash_symbol_type
4336 #define _bfd_xcoff_bfd_link_split_section _bfd_generic_link_split_section
4337 #define _bfd_xcoff_bfd_gc_sections bfd_generic_gc_sections
4338 #define _bfd_xcoff_bfd_lookup_section_flags bfd_generic_lookup_section_flags
4339 #define _bfd_xcoff_bfd_merge_sections bfd_generic_merge_sections
4340 #define _bfd_xcoff_bfd_is_group_section bfd_generic_is_group_section
4341 #define _bfd_xcoff_bfd_group_name bfd_generic_group_name
4342 #define _bfd_xcoff_bfd_discard_group bfd_generic_discard_group
4343 #define _bfd_xcoff_section_already_linked _bfd_generic_section_already_linked
4344 #define _bfd_xcoff_bfd_define_common_symbol _bfd_xcoff_define_common_symbol
4345 #define _bfd_xcoff_bfd_link_hide_symbol _bfd_generic_link_hide_symbol
4346 #define _bfd_xcoff_bfd_define_start_stop bfd_generic_define_start_stop
4347 #define _bfd_xcoff_bfd_link_check_relocs _bfd_generic_link_check_relocs
4349 /* For dynamic symbols and relocs entry points. */
4350 #define _bfd_xcoff_get_synthetic_symtab _bfd_nodynamic_get_synthetic_symtab
4352 static const struct xcoff_backend_data_rec bfd_xcoff_backend_data
=
4354 { /* COFF backend, defined in libcoff.h. */
4355 _bfd_xcoff_swap_aux_in
,
4356 _bfd_xcoff_swap_sym_in
,
4357 coff_swap_lineno_in
,
4358 _bfd_xcoff_swap_aux_out
,
4359 _bfd_xcoff_swap_sym_out
,
4360 coff_swap_lineno_out
,
4361 xcoff_swap_reloc_out
,
4362 coff_swap_filehdr_out
,
4363 coff_swap_aouthdr_out
,
4364 coff_swap_scnhdr_out
,
4373 true, /* _bfd_coff_long_filenames */
4374 XCOFF_NO_LONG_SECTION_NAMES
, /* _bfd_coff_long_section_names */
4375 3, /* _bfd_coff_default_section_alignment_power */
4376 false, /* _bfd_coff_force_symnames_in_strings */
4377 2, /* _bfd_coff_debug_string_prefix_length */
4378 32768, /* _bfd_coff_max_nscns */
4379 coff_swap_filehdr_in
,
4380 coff_swap_aouthdr_in
,
4381 coff_swap_scnhdr_in
,
4382 xcoff_swap_reloc_in
,
4383 coff_bad_format_hook
,
4384 coff_set_arch_mach_hook
,
4387 coff_set_alignment_hook
,
4388 coff_slurp_symbol_table
,
4389 symname_in_debug_hook
,
4390 coff_pointerize_aux_hook
,
4392 dummy_reloc16_extra_cases
,
4393 dummy_reloc16_estimate
,
4394 NULL
, /* bfd_coff_sym_is_global */
4395 coff_compute_section_file_positions
,
4396 NULL
, /* _bfd_coff_start_final_link */
4397 xcoff_ppc_relocate_section
,
4398 coff_rtype_to_howto
,
4399 NULL
, /* _bfd_coff_adjust_symndx */
4400 _bfd_generic_link_add_one_symbol
,
4401 coff_link_output_has_begun
,
4402 coff_final_link_postscript
,
4403 NULL
/* print_pdata. */
4406 0x01DF, /* magic number */
4410 /* Function pointers to xcoff specific swap routines. */
4411 xcoff_swap_ldhdr_in
,
4412 xcoff_swap_ldhdr_out
,
4413 xcoff_swap_ldsym_in
,
4414 xcoff_swap_ldsym_out
,
4415 xcoff_swap_ldrel_in
,
4416 xcoff_swap_ldrel_out
,
4422 12, /* _xcoff_function_descriptor_size */
4426 1, /* _xcoff_ldhdr_version */
4428 _bfd_xcoff_put_symbol_name
,
4429 _bfd_xcoff_put_ldsymbol_name
,
4430 &xcoff_dynamic_reloc
,
4431 xcoff_create_csect_from_smclas
,
4433 /* Lineno and reloc count overflow. */
4434 xcoff_is_lineno_count_overflow
,
4435 xcoff_is_reloc_count_overflow
,
4437 xcoff_loader_symbol_offset
,
4438 xcoff_loader_reloc_offset
,
4441 &xcoff_glink_code
[0],
4442 36, /* _xcoff_glink_size */
4445 64, /* _xcoff_rtinit_size */
4446 xcoff_generate_rtinit
,
4449 /* The transfer vector that leads the outside world to all of the above. */
4450 const bfd_target rs6000_xcoff_vec
=
4453 bfd_target_xcoff_flavour
,
4454 BFD_ENDIAN_BIG
, /* data byte order is big */
4455 BFD_ENDIAN_BIG
, /* header byte order is big */
4457 (HAS_RELOC
| EXEC_P
| HAS_LINENO
| HAS_DEBUG
| DYNAMIC
4458 | HAS_SYMS
| HAS_LOCALS
| WP_TEXT
),
4460 SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_CODE
| SEC_DATA
,
4461 0, /* leading char */
4462 '/', /* ar_pad_char */
4463 15, /* ar_max_namelen */
4464 0, /* match priority. */
4465 TARGET_KEEP_UNUSED_SECTION_SYMBOLS
, /* keep unused section symbols. */
4489 { /* bfd_check_format */
4492 _bfd_xcoff_archive_p
,
4496 { /* bfd_set_format */
4497 _bfd_bool_bfd_false_error
,
4499 _bfd_generic_mkarchive
,
4500 _bfd_bool_bfd_false_error
4503 {/* bfd_write_contents */
4504 _bfd_bool_bfd_false_error
,
4505 coff_write_object_contents
,
4506 _bfd_xcoff_write_archive_contents
,
4507 _bfd_bool_bfd_false_error
4510 BFD_JUMP_TABLE_GENERIC (_bfd_xcoff
),
4511 BFD_JUMP_TABLE_COPY (_bfd_xcoff
),
4512 BFD_JUMP_TABLE_CORE (coff
),
4513 BFD_JUMP_TABLE_ARCHIVE (_bfd_xcoff
),
4514 BFD_JUMP_TABLE_SYMBOLS (_bfd_xcoff
),
4515 BFD_JUMP_TABLE_RELOCS (_bfd_xcoff
),
4516 BFD_JUMP_TABLE_WRITE (coff
),
4517 BFD_JUMP_TABLE_LINK (_bfd_xcoff
),
4518 BFD_JUMP_TABLE_DYNAMIC (_bfd_xcoff
),
4520 /* Opposite endian version, none exists */
4523 & bfd_xcoff_backend_data
,
4526 /* xcoff-powermac target
4528 Only difference between this target and the rs6000 target is the
4529 the default architecture and machine type used in coffcode.h
4531 PowerPC Macs use the same magic numbers as RS/6000
4532 (because that's how they were bootstrapped originally),
4533 but they are always PowerPC architecture. */
4534 static const struct xcoff_backend_data_rec bfd_pmac_xcoff_backend_data
=
4536 { /* COFF backend, defined in libcoff.h. */
4537 _bfd_xcoff_swap_aux_in
,
4538 _bfd_xcoff_swap_sym_in
,
4539 coff_swap_lineno_in
,
4540 _bfd_xcoff_swap_aux_out
,
4541 _bfd_xcoff_swap_sym_out
,
4542 coff_swap_lineno_out
,
4543 xcoff_swap_reloc_out
,
4544 coff_swap_filehdr_out
,
4545 coff_swap_aouthdr_out
,
4546 coff_swap_scnhdr_out
,
4555 true, /* _bfd_coff_long_filenames */
4556 XCOFF_NO_LONG_SECTION_NAMES
, /* _bfd_coff_long_section_names */
4557 3, /* _bfd_coff_default_section_alignment_power */
4558 false, /* _bfd_coff_force_symnames_in_strings */
4559 2, /* _bfd_coff_debug_string_prefix_length */
4560 32768, /* _bfd_coff_max_nscns */
4561 coff_swap_filehdr_in
,
4562 coff_swap_aouthdr_in
,
4563 coff_swap_scnhdr_in
,
4564 xcoff_swap_reloc_in
,
4565 coff_bad_format_hook
,
4566 coff_set_arch_mach_hook
,
4569 coff_set_alignment_hook
,
4570 coff_slurp_symbol_table
,
4571 symname_in_debug_hook
,
4572 coff_pointerize_aux_hook
,
4574 dummy_reloc16_extra_cases
,
4575 dummy_reloc16_estimate
,
4576 NULL
, /* bfd_coff_sym_is_global */
4577 coff_compute_section_file_positions
,
4578 NULL
, /* _bfd_coff_start_final_link */
4579 xcoff_ppc_relocate_section
,
4580 coff_rtype_to_howto
,
4581 NULL
, /* _bfd_coff_adjust_symndx */
4582 _bfd_generic_link_add_one_symbol
,
4583 coff_link_output_has_begun
,
4584 coff_final_link_postscript
,
4585 NULL
/* print_pdata. */
4588 0x01DF, /* magic number */
4592 /* Function pointers to xcoff specific swap routines. */
4593 xcoff_swap_ldhdr_in
,
4594 xcoff_swap_ldhdr_out
,
4595 xcoff_swap_ldsym_in
,
4596 xcoff_swap_ldsym_out
,
4597 xcoff_swap_ldrel_in
,
4598 xcoff_swap_ldrel_out
,
4604 12, /* _xcoff_function_descriptor_size */
4608 1, /* _xcoff_ldhdr_version */
4610 _bfd_xcoff_put_symbol_name
,
4611 _bfd_xcoff_put_ldsymbol_name
,
4612 &xcoff_dynamic_reloc
,
4613 xcoff_create_csect_from_smclas
,
4615 /* Lineno and reloc count overflow. */
4616 xcoff_is_lineno_count_overflow
,
4617 xcoff_is_reloc_count_overflow
,
4619 xcoff_loader_symbol_offset
,
4620 xcoff_loader_reloc_offset
,
4623 &xcoff_glink_code
[0],
4624 36, /* _xcoff_glink_size */
4627 0, /* _xcoff_rtinit_size */
4628 xcoff_generate_rtinit
,
4631 /* The transfer vector that leads the outside world to all of the above. */
4632 const bfd_target powerpc_xcoff_vec
=
4635 bfd_target_xcoff_flavour
,
4636 BFD_ENDIAN_BIG
, /* data byte order is big */
4637 BFD_ENDIAN_BIG
, /* header byte order is big */
4639 (HAS_RELOC
| EXEC_P
| HAS_LINENO
| HAS_DEBUG
| DYNAMIC
4640 | HAS_SYMS
| HAS_LOCALS
| WP_TEXT
),
4642 SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_CODE
| SEC_DATA
,
4643 0, /* leading char */
4644 '/', /* ar_pad_char */
4645 15, /* ar_max_namelen */
4646 0, /* match priority. */
4647 TARGET_KEEP_UNUSED_SECTION_SYMBOLS
, /* keep unused section symbols. */
4671 { /* bfd_check_format */
4674 _bfd_xcoff_archive_p
,
4678 { /* bfd_set_format */
4679 _bfd_bool_bfd_false_error
,
4681 _bfd_generic_mkarchive
,
4682 _bfd_bool_bfd_false_error
4685 {/* bfd_write_contents */
4686 _bfd_bool_bfd_false_error
,
4687 coff_write_object_contents
,
4688 _bfd_xcoff_write_archive_contents
,
4689 _bfd_bool_bfd_false_error
4692 BFD_JUMP_TABLE_GENERIC (_bfd_xcoff
),
4693 BFD_JUMP_TABLE_COPY (_bfd_xcoff
),
4694 BFD_JUMP_TABLE_CORE (coff
),
4695 BFD_JUMP_TABLE_ARCHIVE (_bfd_xcoff
),
4696 BFD_JUMP_TABLE_SYMBOLS (_bfd_xcoff
),
4697 BFD_JUMP_TABLE_RELOCS (_bfd_xcoff
),
4698 BFD_JUMP_TABLE_WRITE (coff
),
4699 BFD_JUMP_TABLE_LINK (_bfd_xcoff
),
4700 BFD_JUMP_TABLE_DYNAMIC (_bfd_xcoff
),
4702 /* Opposite endian version, none exists */
4705 & bfd_pmac_xcoff_backend_data
,