1 /* BFD back-end for IBM RS/6000 "XCOFF" files.
2 Copyright (C) 1990-2019 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 bfd_boolean
_bfd_xcoff_mkobject (bfd
*);
36 extern bfd_boolean
_bfd_xcoff_copy_private_bfd_data (bfd
*, bfd
*);
37 extern bfd_boolean
_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 bfd_boolean
_bfd_xcoff_slurp_armap (bfd
*);
41 extern const bfd_target
*_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 bfd_boolean _bfd_xcoff_write_armap
46 (bfd
*, unsigned int, struct orl
*, unsigned int, int);
47 extern bfd_boolean
_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 const bfd_target
* rs6000coff_core_p (bfd
*abfd
);
81 extern bfd_boolean 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 bfd_boolean xcoff_write_armap_old
123 (bfd
*, unsigned int, struct orl
*, unsigned int, int);
124 static bfd_boolean xcoff_write_armap_big
125 (bfd
*, unsigned int, struct orl
*, unsigned int, int);
126 static bfd_boolean
xcoff_write_archive_contents_old (bfd
*);
127 static bfd_boolean
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 bfd_boolean xcoff_ppc_relocate_section
135 (bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
136 struct internal_reloc
*, struct internal_syment
*, asection
**);
137 static bfd_boolean _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 bfd_boolean
xcoff_is_lineno_count_overflow (bfd
*, bfd_vma
);
142 static bfd_boolean
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 bfd_boolean xcoff_generate_rtinit
146 (bfd
*, const char *, const char *, bfd_boolean
);
147 static bfd_boolean
do_pad (bfd
*, unsigned int);
148 static bfd_boolean
do_copy (bfd
*, bfd
*);
150 /* Relocation functions */
151 static bfd_boolean
xcoff_reloc_type_br (XCOFF_RELOC_FUNCTION_ARGS
);
153 static bfd_boolean xcoff_complain_overflow_dont_func
154 (XCOFF_COMPLAIN_FUNCTION_ARGS
);
155 static bfd_boolean xcoff_complain_overflow_bitfield_func
156 (XCOFF_COMPLAIN_FUNCTION_ARGS
);
157 static bfd_boolean xcoff_complain_overflow_signed_func
158 (XCOFF_COMPLAIN_FUNCTION_ARGS
);
159 static bfd_boolean xcoff_complain_overflow_unsigned_func
160 (XCOFF_COMPLAIN_FUNCTION_ARGS
);
162 bfd_boolean (*xcoff_calculate_relocation
[XCOFF_MAX_CALCULATE_RELOCATION
])
163 (XCOFF_RELOC_FUNCTION_ARGS
) =
165 xcoff_reloc_type_pos
, /* R_POS (0x00) */
166 xcoff_reloc_type_neg
, /* R_NEG (0x01) */
167 xcoff_reloc_type_rel
, /* R_REL (0x02) */
168 xcoff_reloc_type_toc
, /* R_TOC (0x03) */
169 xcoff_reloc_type_fail
, /* R_RTB (0x04) */
170 xcoff_reloc_type_toc
, /* R_GL (0x05) */
171 xcoff_reloc_type_toc
, /* R_TCL (0x06) */
172 xcoff_reloc_type_fail
, /* (0x07) */
173 xcoff_reloc_type_ba
, /* R_BA (0x08) */
174 xcoff_reloc_type_fail
, /* (0x09) */
175 xcoff_reloc_type_br
, /* R_BR (0x0a) */
176 xcoff_reloc_type_fail
, /* (0x0b) */
177 xcoff_reloc_type_pos
, /* R_RL (0x0c) */
178 xcoff_reloc_type_pos
, /* R_RLA (0x0d) */
179 xcoff_reloc_type_fail
, /* (0x0e) */
180 xcoff_reloc_type_noop
, /* R_REF (0x0f) */
181 xcoff_reloc_type_fail
, /* (0x10) */
182 xcoff_reloc_type_fail
, /* (0x11) */
183 xcoff_reloc_type_toc
, /* R_TRL (0x12) */
184 xcoff_reloc_type_toc
, /* R_TRLA (0x13) */
185 xcoff_reloc_type_fail
, /* R_RRTBI (0x14) */
186 xcoff_reloc_type_fail
, /* R_RRTBA (0x15) */
187 xcoff_reloc_type_ba
, /* R_CAI (0x16) */
188 xcoff_reloc_type_crel
, /* R_CREL (0x17) */
189 xcoff_reloc_type_ba
, /* R_RBA (0x18) */
190 xcoff_reloc_type_ba
, /* R_RBAC (0x19) */
191 xcoff_reloc_type_br
, /* R_RBR (0x1a) */
192 xcoff_reloc_type_ba
, /* R_RBRC (0x1b) */
195 bfd_boolean (*xcoff_complain_overflow
[XCOFF_MAX_COMPLAIN_OVERFLOW
])
196 (XCOFF_COMPLAIN_FUNCTION_ARGS
) =
198 xcoff_complain_overflow_dont_func
,
199 xcoff_complain_overflow_bitfield_func
,
200 xcoff_complain_overflow_signed_func
,
201 xcoff_complain_overflow_unsigned_func
,
204 /* Information about one member of an archive. */
207 /* The archive member that this structure describes. */
210 /* The number of bytes of padding that must be inserted before the
211 start of the member in order to ensure that the section contents
212 are correctly aligned. */
213 unsigned int leading_padding
;
215 /* The offset of MEMBER from the start of the archive (i.e. the end
216 of the leading padding). */
219 /* The normalized name of MEMBER. */
222 /* The length of NAME, without padding. */
223 bfd_size_type namlen
;
225 /* The length of NAME, with padding. */
226 bfd_size_type padded_namlen
;
228 /* The size of MEMBER's header, including the name and magic sequence. */
229 bfd_size_type header_size
;
231 /* The size of the MEMBER's contents. */
232 bfd_size_type contents_size
;
234 /* The number of bytes of padding that must be inserted after MEMBER
235 in order to preserve even alignment. */
236 bfd_size_type trailing_padding
;
239 /* A structure used for iterating over the members of an archive. */
240 struct archive_iterator
242 /* The archive itself. */
245 /* Information about the current archive member. */
246 struct member_layout current
;
248 /* Information about the next archive member. MEMBER is null if there
249 are no more archive members, in which case OFFSET is the offset of
250 the first unused byte. */
251 struct member_layout next
;
254 /* Initialize INFO so that it describes member MEMBER of archive ARCHIVE.
255 OFFSET is the even-padded offset of MEMBER, not including any leading
256 padding needed for section alignment. */
259 member_layout_init (struct member_layout
*info
, bfd
*archive
,
260 bfd
*member
, file_ptr offset
)
262 info
->member
= member
;
263 info
->leading_padding
= 0;
266 info
->name
= normalize_filename (member
);
267 info
->namlen
= strlen (info
->name
);
268 info
->padded_namlen
= info
->namlen
+ (info
->namlen
& 1);
269 if (xcoff_big_format_p (archive
))
270 info
->header_size
= SIZEOF_AR_HDR_BIG
;
272 info
->header_size
= SIZEOF_AR_HDR
;
273 info
->header_size
+= info
->padded_namlen
+ SXCOFFARFMAG
;
274 info
->contents_size
= arelt_size (member
);
275 info
->trailing_padding
= info
->contents_size
& 1;
277 if (bfd_check_format (member
, bfd_object
)
278 && bfd_get_flavour (member
) == bfd_target_xcoff_flavour
279 && (member
->flags
& DYNAMIC
) != 0)
280 info
->leading_padding
281 = (-(offset
+ info
->header_size
)
282 & ((1 << bfd_xcoff_text_align_power (member
)) - 1));
284 info
->offset
= offset
+ info
->leading_padding
;
287 /* Set up ITERATOR to iterate through archive ARCHIVE. */
290 archive_iterator_begin (struct archive_iterator
*iterator
,
293 iterator
->archive
= archive
;
294 member_layout_init (&iterator
->next
, archive
, archive
->archive_head
,
295 xcoff_big_format_p (archive
)
296 ? SIZEOF_AR_FILE_HDR_BIG
297 : SIZEOF_AR_FILE_HDR
);
300 /* Make ITERATOR visit the first unvisited archive member. Return true
301 on success; return false if all members have been visited. */
304 archive_iterator_next (struct archive_iterator
*iterator
)
306 if (!iterator
->next
.member
)
309 iterator
->current
= iterator
->next
;
310 member_layout_init (&iterator
->next
, iterator
->archive
,
311 iterator
->current
.member
->archive_next
,
312 iterator
->current
.offset
313 + iterator
->current
.header_size
314 + iterator
->current
.contents_size
315 + iterator
->current
.trailing_padding
);
319 /* We use our own tdata type. Its first field is the COFF tdata type,
320 so the COFF routines are compatible. */
323 _bfd_xcoff_mkobject (bfd
*abfd
)
325 coff_data_type
*coff
;
326 bfd_size_type amt
= sizeof (struct xcoff_tdata
);
328 abfd
->tdata
.xcoff_obj_data
= (struct xcoff_tdata
*) bfd_zalloc (abfd
, amt
);
329 if (abfd
->tdata
.xcoff_obj_data
== NULL
)
331 coff
= coff_data (abfd
);
332 coff
->symbols
= (coff_symbol_type
*) NULL
;
333 coff
->conversion_table
= (unsigned int *) NULL
;
334 coff
->raw_syments
= (struct coff_ptr_struct
*) NULL
;
337 xcoff_data (abfd
)->modtype
= ('1' << 8) | 'L';
339 /* We set cputype to -1 to indicate that it has not been
341 xcoff_data (abfd
)->cputype
= -1;
343 xcoff_data (abfd
)->csects
= NULL
;
344 xcoff_data (abfd
)->debug_indices
= NULL
;
346 /* text section alignment is different than the default */
347 bfd_xcoff_text_align_power (abfd
) = 2;
352 /* Copy XCOFF data from one BFD to another. */
355 _bfd_xcoff_copy_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
357 struct xcoff_tdata
*ix
, *ox
;
360 if (ibfd
->xvec
!= obfd
->xvec
)
362 ix
= xcoff_data (ibfd
);
363 ox
= xcoff_data (obfd
);
364 ox
->full_aouthdr
= ix
->full_aouthdr
;
370 sec
= coff_section_from_bfd_index (ibfd
, ix
->sntoc
);
374 ox
->sntoc
= sec
->output_section
->target_index
;
376 if (ix
->snentry
== 0)
380 sec
= coff_section_from_bfd_index (ibfd
, ix
->snentry
);
384 ox
->snentry
= sec
->output_section
->target_index
;
386 bfd_xcoff_text_align_power (obfd
) = bfd_xcoff_text_align_power (ibfd
);
387 bfd_xcoff_data_align_power (obfd
) = bfd_xcoff_data_align_power (ibfd
);
388 ox
->modtype
= ix
->modtype
;
389 ox
->cputype
= ix
->cputype
;
390 ox
->maxdata
= ix
->maxdata
;
391 ox
->maxstack
= ix
->maxstack
;
395 /* I don't think XCOFF really has a notion of local labels based on
396 name. This will mean that ld -X doesn't actually strip anything.
397 The AIX native linker does not have a -X option, and it ignores the
401 _bfd_xcoff_is_local_label_name (bfd
*abfd ATTRIBUTE_UNUSED
,
402 const char *name ATTRIBUTE_UNUSED
)
408 _bfd_xcoff_swap_sym_in (bfd
*abfd
, void * ext1
, void * in1
)
410 SYMENT
*ext
= (SYMENT
*)ext1
;
411 struct internal_syment
* in
= (struct internal_syment
*)in1
;
413 if (ext
->e
.e_name
[0] != 0)
415 memcpy (in
->_n
._n_name
, ext
->e
.e_name
, SYMNMLEN
);
419 in
->_n
._n_n
._n_zeroes
= 0;
420 in
->_n
._n_n
._n_offset
= H_GET_32 (abfd
, ext
->e
.e
.e_offset
);
423 in
->n_value
= H_GET_32 (abfd
, ext
->e_value
);
424 in
->n_scnum
= (short) H_GET_16 (abfd
, ext
->e_scnum
);
425 in
->n_type
= H_GET_16 (abfd
, ext
->e_type
);
426 in
->n_sclass
= H_GET_8 (abfd
, ext
->e_sclass
);
427 in
->n_numaux
= H_GET_8 (abfd
, ext
->e_numaux
);
431 _bfd_xcoff_swap_sym_out (bfd
*abfd
, void * inp
, void * extp
)
433 struct internal_syment
*in
= (struct internal_syment
*)inp
;
434 SYMENT
*ext
=(SYMENT
*)extp
;
436 if (in
->_n
._n_name
[0] != 0)
438 memcpy (ext
->e
.e_name
, in
->_n
._n_name
, SYMNMLEN
);
442 H_PUT_32 (abfd
, 0, ext
->e
.e
.e_zeroes
);
443 H_PUT_32 (abfd
, in
->_n
._n_n
._n_offset
, ext
->e
.e
.e_offset
);
446 H_PUT_32 (abfd
, in
->n_value
, ext
->e_value
);
447 H_PUT_16 (abfd
, in
->n_scnum
, ext
->e_scnum
);
448 H_PUT_16 (abfd
, in
->n_type
, ext
->e_type
);
449 H_PUT_8 (abfd
, in
->n_sclass
, ext
->e_sclass
);
450 H_PUT_8 (abfd
, in
->n_numaux
, ext
->e_numaux
);
451 return bfd_coff_symesz (abfd
);
455 _bfd_xcoff_swap_aux_in (bfd
*abfd
, void * ext1
, int type
, int in_class
,
456 int indx
, int numaux
, void * in1
)
458 AUXENT
* ext
= (AUXENT
*)ext1
;
459 union internal_auxent
*in
= (union internal_auxent
*)in1
;
464 if (ext
->x_file
.x_n
.x_fname
[0] == 0)
466 in
->x_file
.x_n
.x_zeroes
= 0;
467 in
->x_file
.x_n
.x_offset
=
468 H_GET_32 (abfd
, ext
->x_file
.x_n
.x_n
.x_offset
);
475 memcpy (in
->x_file
.x_fname
, ext
->x_file
.x_n
.x_fname
,
476 numaux
* sizeof (AUXENT
));
480 memcpy (in
->x_file
.x_fname
, ext
->x_file
.x_n
.x_fname
, FILNMLEN
);
485 /* RS/6000 "csect" auxents */
489 if (indx
+ 1 == numaux
)
491 in
->x_csect
.x_scnlen
.l
= H_GET_32 (abfd
, ext
->x_csect
.x_scnlen
);
492 in
->x_csect
.x_parmhash
= H_GET_32 (abfd
, ext
->x_csect
.x_parmhash
);
493 in
->x_csect
.x_snhash
= H_GET_16 (abfd
, ext
->x_csect
.x_snhash
);
494 /* We don't have to hack bitfields in x_smtyp because it's
495 defined by shifts-and-ands, which are equivalent on all
497 in
->x_csect
.x_smtyp
= H_GET_8 (abfd
, ext
->x_csect
.x_smtyp
);
498 in
->x_csect
.x_smclas
= H_GET_8 (abfd
, ext
->x_csect
.x_smclas
);
499 in
->x_csect
.x_stab
= H_GET_32 (abfd
, ext
->x_csect
.x_stab
);
500 in
->x_csect
.x_snstab
= H_GET_16 (abfd
, ext
->x_csect
.x_snstab
);
510 in
->x_scn
.x_scnlen
= H_GET_32 (abfd
, ext
->x_scn
.x_scnlen
);
511 in
->x_scn
.x_nreloc
= H_GET_16 (abfd
, ext
->x_scn
.x_nreloc
);
512 in
->x_scn
.x_nlinno
= H_GET_16 (abfd
, ext
->x_scn
.x_nlinno
);
513 /* PE defines some extra fields; we zero them out for
515 in
->x_scn
.x_checksum
= 0;
516 in
->x_scn
.x_associated
= 0;
517 in
->x_scn
.x_comdat
= 0;
524 in
->x_sym
.x_tagndx
.l
= H_GET_32 (abfd
, ext
->x_sym
.x_tagndx
);
525 in
->x_sym
.x_tvndx
= H_GET_16 (abfd
, ext
->x_sym
.x_tvndx
);
527 if (in_class
== C_BLOCK
|| in_class
== C_FCN
|| ISFCN (type
)
530 in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
=
531 H_GET_32 (abfd
, ext
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
532 in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
=
533 H_GET_32 (abfd
, ext
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
537 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0] =
538 H_GET_16 (abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
539 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1] =
540 H_GET_16 (abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
541 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2] =
542 H_GET_16 (abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
543 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3] =
544 H_GET_16 (abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
549 in
->x_sym
.x_misc
.x_fsize
= H_GET_32 (abfd
, ext
->x_sym
.x_misc
.x_fsize
);
553 in
->x_sym
.x_misc
.x_lnsz
.x_lnno
=
554 H_GET_16 (abfd
, ext
->x_sym
.x_misc
.x_lnsz
.x_lnno
);
555 in
->x_sym
.x_misc
.x_lnsz
.x_size
=
556 H_GET_16 (abfd
, ext
->x_sym
.x_misc
.x_lnsz
.x_size
);
560 /* The semicolon is because MSVC doesn't like labels at
565 _bfd_xcoff_swap_aux_out (bfd
*abfd
, void * inp
, int type
, int in_class
,
566 int indx ATTRIBUTE_UNUSED
,
567 int numaux ATTRIBUTE_UNUSED
,
570 union internal_auxent
*in
= (union internal_auxent
*)inp
;
571 AUXENT
*ext
= (AUXENT
*)extp
;
573 memset (ext
, 0, bfd_coff_auxesz (abfd
));
577 if (in
->x_file
.x_fname
[0] == 0)
579 H_PUT_32 (abfd
, 0, ext
->x_file
.x_n
.x_n
.x_zeroes
);
580 H_PUT_32 (abfd
, in
->x_file
.x_n
.x_offset
,
581 ext
->x_file
.x_n
.x_n
.x_offset
);
585 memcpy (ext
->x_file
.x_n
.x_fname
, in
->x_file
.x_fname
, FILNMLEN
);
589 /* RS/6000 "csect" auxents */
593 if (indx
+ 1 == numaux
)
595 H_PUT_32 (abfd
, in
->x_csect
.x_scnlen
.l
, ext
->x_csect
.x_scnlen
);
596 H_PUT_32 (abfd
, in
->x_csect
.x_parmhash
, ext
->x_csect
.x_parmhash
);
597 H_PUT_16 (abfd
, in
->x_csect
.x_snhash
, ext
->x_csect
.x_snhash
);
598 /* We don't have to hack bitfields in x_smtyp because it's
599 defined by shifts-and-ands, which are equivalent on all
601 H_PUT_8 (abfd
, in
->x_csect
.x_smtyp
, ext
->x_csect
.x_smtyp
);
602 H_PUT_8 (abfd
, in
->x_csect
.x_smclas
, ext
->x_csect
.x_smclas
);
603 H_PUT_32 (abfd
, in
->x_csect
.x_stab
, ext
->x_csect
.x_stab
);
604 H_PUT_16 (abfd
, in
->x_csect
.x_snstab
, ext
->x_csect
.x_snstab
);
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
);
622 H_PUT_32 (abfd
, in
->x_sym
.x_tagndx
.l
, ext
->x_sym
.x_tagndx
);
623 H_PUT_16 (abfd
, in
->x_sym
.x_tvndx
, ext
->x_sym
.x_tvndx
);
625 if (in_class
== C_BLOCK
|| in_class
== C_FCN
|| ISFCN (type
)
628 H_PUT_32 (abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
,
629 ext
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
630 H_PUT_32 (abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
,
631 ext
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
635 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0],
636 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
637 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1],
638 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
639 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2],
640 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
641 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3],
642 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
646 H_PUT_32 (abfd
, in
->x_sym
.x_misc
.x_fsize
, ext
->x_sym
.x_misc
.x_fsize
);
649 H_PUT_16 (abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_lnno
,
650 ext
->x_sym
.x_misc
.x_lnsz
.x_lnno
);
651 H_PUT_16 (abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_size
,
652 ext
->x_sym
.x_misc
.x_lnsz
.x_size
);
656 return bfd_coff_auxesz (abfd
);
659 /* The XCOFF reloc table. Actually, XCOFF relocations specify the
660 bitsize and whether they are signed or not, along with a
661 conventional type. This table is for the types, which are used for
662 different algorithms for putting in the reloc. Many of these
663 relocs need special_function entries, which I have not written. */
665 reloc_howto_type xcoff_howto_table
[] =
667 /* 0x00: Standard 32 bit relocation. */
668 HOWTO (R_POS
, /* type */
670 2, /* size (0 = byte, 1 = short, 2 = long) */
672 FALSE
, /* pc_relative */
674 complain_overflow_bitfield
, /* complain_on_overflow */
675 0, /* special_function */
677 TRUE
, /* partial_inplace */
678 0xffffffff, /* src_mask */
679 0xffffffff, /* dst_mask */
680 FALSE
), /* pcrel_offset */
682 /* 0x01: 32 bit relocation, but store negative value. */
683 HOWTO (R_NEG
, /* type */
685 -2, /* size (0 = byte, 1 = short, 2 = long) */
687 FALSE
, /* pc_relative */
689 complain_overflow_bitfield
, /* complain_on_overflow */
690 0, /* special_function */
692 TRUE
, /* partial_inplace */
693 0xffffffff, /* src_mask */
694 0xffffffff, /* dst_mask */
695 FALSE
), /* pcrel_offset */
697 /* 0x02: 32 bit PC relative relocation. */
698 HOWTO (R_REL
, /* type */
700 2, /* size (0 = byte, 1 = short, 2 = long) */
702 TRUE
, /* pc_relative */
704 complain_overflow_signed
, /* complain_on_overflow */
705 0, /* special_function */
707 TRUE
, /* partial_inplace */
708 0xffffffff, /* src_mask */
709 0xffffffff, /* dst_mask */
710 FALSE
), /* pcrel_offset */
712 /* 0x03: 16 bit TOC relative relocation. */
713 HOWTO (R_TOC
, /* type */
715 1, /* size (0 = byte, 1 = short, 2 = long) */
717 FALSE
, /* pc_relative */
719 complain_overflow_bitfield
, /* complain_on_overflow */
720 0, /* special_function */
722 TRUE
, /* partial_inplace */
723 0xffff, /* src_mask */
724 0xffff, /* dst_mask */
725 FALSE
), /* pcrel_offset */
727 /* 0x04: I don't really know what this is. */
728 HOWTO (R_RTB
, /* type */
730 2, /* size (0 = byte, 1 = short, 2 = long) */
732 FALSE
, /* pc_relative */
734 complain_overflow_bitfield
, /* complain_on_overflow */
735 0, /* special_function */
737 TRUE
, /* partial_inplace */
738 0xffffffff, /* src_mask */
739 0xffffffff, /* dst_mask */
740 FALSE
), /* pcrel_offset */
742 /* 0x05: External TOC relative symbol. */
743 HOWTO (R_GL
, /* type */
745 1, /* size (0 = byte, 1 = short, 2 = long) */
747 FALSE
, /* pc_relative */
749 complain_overflow_bitfield
, /* complain_on_overflow */
750 0, /* special_function */
752 TRUE
, /* partial_inplace */
753 0xffff, /* src_mask */
754 0xffff, /* dst_mask */
755 FALSE
), /* pcrel_offset */
757 /* 0x06: Local TOC relative symbol. */
758 HOWTO (R_TCL
, /* type */
760 1, /* size (0 = byte, 1 = short, 2 = long) */
762 FALSE
, /* pc_relative */
764 complain_overflow_bitfield
, /* complain_on_overflow */
765 0, /* special_function */
767 TRUE
, /* partial_inplace */
768 0xffff, /* src_mask */
769 0xffff, /* dst_mask */
770 FALSE
), /* pcrel_offset */
774 /* 0x08: Non modifiable absolute branch. */
775 HOWTO (R_BA
, /* type */
777 2, /* size (0 = byte, 1 = short, 2 = long) */
779 FALSE
, /* pc_relative */
781 complain_overflow_bitfield
, /* complain_on_overflow */
782 0, /* special_function */
783 "R_BA_26", /* name */
784 TRUE
, /* partial_inplace */
785 0x03fffffc, /* src_mask */
786 0x03fffffc, /* dst_mask */
787 FALSE
), /* pcrel_offset */
791 /* 0x0a: Non modifiable relative branch. */
792 HOWTO (R_BR
, /* type */
794 2, /* size (0 = byte, 1 = short, 2 = long) */
796 TRUE
, /* pc_relative */
798 complain_overflow_signed
, /* complain_on_overflow */
799 0, /* special_function */
801 TRUE
, /* partial_inplace */
802 0x03fffffc, /* src_mask */
803 0x03fffffc, /* dst_mask */
804 FALSE
), /* pcrel_offset */
808 /* 0x0c: Indirect load. */
809 HOWTO (R_RL
, /* type */
811 1, /* size (0 = byte, 1 = short, 2 = long) */
813 FALSE
, /* pc_relative */
815 complain_overflow_bitfield
, /* complain_on_overflow */
816 0, /* special_function */
818 TRUE
, /* partial_inplace */
819 0xffff, /* src_mask */
820 0xffff, /* dst_mask */
821 FALSE
), /* pcrel_offset */
823 /* 0x0d: Load address. */
824 HOWTO (R_RLA
, /* type */
826 1, /* size (0 = byte, 1 = short, 2 = long) */
828 FALSE
, /* pc_relative */
830 complain_overflow_bitfield
, /* complain_on_overflow */
831 0, /* special_function */
833 TRUE
, /* partial_inplace */
834 0xffff, /* src_mask */
835 0xffff, /* dst_mask */
836 FALSE
), /* pcrel_offset */
840 /* 0x0f: Non-relocating reference. Bitsize is 1 so that r_rsize is 0. */
841 HOWTO (R_REF
, /* type */
843 0, /* size (0 = byte, 1 = short, 2 = long) */
845 FALSE
, /* pc_relative */
847 complain_overflow_dont
, /* complain_on_overflow */
848 0, /* special_function */
850 FALSE
, /* partial_inplace */
853 FALSE
), /* pcrel_offset */
858 /* 0x12: TOC relative indirect load. */
859 HOWTO (R_TRL
, /* type */
861 1, /* size (0 = byte, 1 = short, 2 = long) */
863 FALSE
, /* pc_relative */
865 complain_overflow_bitfield
, /* complain_on_overflow */
866 0, /* special_function */
868 TRUE
, /* partial_inplace */
869 0xffff, /* src_mask */
870 0xffff, /* dst_mask */
871 FALSE
), /* pcrel_offset */
873 /* 0x13: TOC relative load address. */
874 HOWTO (R_TRLA
, /* type */
876 1, /* size (0 = byte, 1 = short, 2 = long) */
878 FALSE
, /* pc_relative */
880 complain_overflow_bitfield
, /* complain_on_overflow */
881 0, /* special_function */
883 TRUE
, /* partial_inplace */
884 0xffff, /* src_mask */
885 0xffff, /* dst_mask */
886 FALSE
), /* pcrel_offset */
888 /* 0x14: Modifiable relative branch. */
889 HOWTO (R_RRTBI
, /* type */
891 2, /* size (0 = byte, 1 = short, 2 = long) */
893 FALSE
, /* pc_relative */
895 complain_overflow_bitfield
, /* complain_on_overflow */
896 0, /* special_function */
897 "R_RRTBI", /* name */
898 TRUE
, /* partial_inplace */
899 0xffffffff, /* src_mask */
900 0xffffffff, /* dst_mask */
901 FALSE
), /* pcrel_offset */
903 /* 0x15: Modifiable absolute branch. */
904 HOWTO (R_RRTBA
, /* type */
906 2, /* size (0 = byte, 1 = short, 2 = long) */
908 FALSE
, /* pc_relative */
910 complain_overflow_bitfield
, /* complain_on_overflow */
911 0, /* special_function */
912 "R_RRTBA", /* name */
913 TRUE
, /* partial_inplace */
914 0xffffffff, /* src_mask */
915 0xffffffff, /* dst_mask */
916 FALSE
), /* pcrel_offset */
918 /* 0x16: Modifiable call absolute indirect. */
919 HOWTO (R_CAI
, /* type */
921 1, /* size (0 = byte, 1 = short, 2 = long) */
923 FALSE
, /* pc_relative */
925 complain_overflow_bitfield
, /* complain_on_overflow */
926 0, /* special_function */
928 TRUE
, /* partial_inplace */
929 0xffff, /* src_mask */
930 0xffff, /* dst_mask */
931 FALSE
), /* pcrel_offset */
933 /* 0x17: Modifiable call relative. */
934 HOWTO (R_CREL
, /* type */
936 1, /* size (0 = byte, 1 = short, 2 = long) */
938 FALSE
, /* pc_relative */
940 complain_overflow_bitfield
, /* complain_on_overflow */
941 0, /* special_function */
943 TRUE
, /* partial_inplace */
944 0xffff, /* src_mask */
945 0xffff, /* dst_mask */
946 FALSE
), /* pcrel_offset */
948 /* 0x18: Modifiable branch absolute. */
949 HOWTO (R_RBA
, /* type */
951 2, /* size (0 = byte, 1 = short, 2 = long) */
953 FALSE
, /* pc_relative */
955 complain_overflow_bitfield
, /* complain_on_overflow */
956 0, /* special_function */
958 TRUE
, /* partial_inplace */
959 0x03fffffc, /* src_mask */
960 0x03fffffc, /* dst_mask */
961 FALSE
), /* pcrel_offset */
963 /* 0x19: Modifiable branch absolute. */
964 HOWTO (R_RBAC
, /* type */
966 2, /* size (0 = byte, 1 = short, 2 = long) */
968 FALSE
, /* pc_relative */
970 complain_overflow_bitfield
, /* complain_on_overflow */
971 0, /* special_function */
973 TRUE
, /* partial_inplace */
974 0xffffffff, /* src_mask */
975 0xffffffff, /* dst_mask */
976 FALSE
), /* pcrel_offset */
978 /* 0x1a: Modifiable branch relative. */
979 HOWTO (R_RBR
, /* type */
981 2, /* size (0 = byte, 1 = short, 2 = long) */
983 FALSE
, /* pc_relative */
985 complain_overflow_signed
, /* complain_on_overflow */
986 0, /* special_function */
987 "R_RBR_26", /* name */
988 TRUE
, /* partial_inplace */
989 0x03fffffc, /* src_mask */
990 0x03fffffc, /* dst_mask */
991 FALSE
), /* pcrel_offset */
993 /* 0x1b: Modifiable branch absolute. */
994 HOWTO (R_RBRC
, /* type */
996 1, /* size (0 = byte, 1 = short, 2 = long) */
998 FALSE
, /* pc_relative */
1000 complain_overflow_bitfield
, /* complain_on_overflow */
1001 0, /* special_function */
1002 "R_RBRC", /* name */
1003 TRUE
, /* partial_inplace */
1004 0xffff, /* src_mask */
1005 0xffff, /* dst_mask */
1006 FALSE
), /* pcrel_offset */
1008 /* 0x1c: 16 bit Non modifiable absolute branch. */
1009 HOWTO (R_BA
, /* type */
1011 1, /* size (0 = byte, 1 = short, 2 = long) */
1013 FALSE
, /* pc_relative */
1015 complain_overflow_bitfield
, /* complain_on_overflow */
1016 0, /* special_function */
1017 "R_BA_16", /* name */
1018 TRUE
, /* partial_inplace */
1019 0xfffc, /* src_mask */
1020 0xfffc, /* dst_mask */
1021 FALSE
), /* pcrel_offset */
1023 /* 0x1d: Modifiable branch relative. */
1024 HOWTO (R_RBR
, /* type */
1026 1, /* size (0 = byte, 1 = short, 2 = long) */
1028 TRUE
, /* pc_relative */
1030 complain_overflow_signed
, /* complain_on_overflow */
1031 0, /* special_function */
1032 "R_RBR_16", /* name */
1033 TRUE
, /* partial_inplace */
1034 0xfffc, /* src_mask */
1035 0xfffc, /* dst_mask */
1036 FALSE
), /* pcrel_offset */
1038 /* 0x1e: Modifiable branch relative. */
1039 HOWTO (R_RBA
, /* type */
1041 1, /* size (0 = byte, 1 = short, 2 = long) */
1043 FALSE
, /* pc_relative */
1045 complain_overflow_signed
, /* complain_on_overflow */
1046 0, /* special_function */
1047 "R_RBA_16", /* name */
1048 TRUE
, /* partial_inplace */
1049 0xffff, /* src_mask */
1050 0xffff, /* dst_mask */
1051 FALSE
), /* pcrel_offset */
1055 xcoff_rtype2howto (arelent
*relent
, struct internal_reloc
*internal
)
1057 if (internal
->r_type
> R_RBRC
)
1060 /* Default howto layout works most of the time */
1061 relent
->howto
= &xcoff_howto_table
[internal
->r_type
];
1063 /* Special case some 16 bit reloc */
1064 if (15 == (internal
->r_size
& 0x1f))
1066 if (R_BA
== internal
->r_type
)
1067 relent
->howto
= &xcoff_howto_table
[0x1c];
1068 else if (R_RBR
== internal
->r_type
)
1069 relent
->howto
= &xcoff_howto_table
[0x1d];
1070 else if (R_RBA
== internal
->r_type
)
1071 relent
->howto
= &xcoff_howto_table
[0x1e];
1074 /* The r_size field of an XCOFF reloc encodes the bitsize of the
1075 relocation, as well as indicating whether it is signed or not.
1076 Doublecheck that the relocation information gathered from the
1077 type matches this information. The bitsize is not significant
1078 for R_REF relocs. */
1079 if (relent
->howto
->dst_mask
!= 0
1080 && (relent
->howto
->bitsize
1081 != ((unsigned int) internal
->r_size
& 0x1f) + 1))
1086 _bfd_xcoff_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1087 bfd_reloc_code_real_type code
)
1091 case BFD_RELOC_PPC_B26
:
1092 return &xcoff_howto_table
[0xa];
1093 case BFD_RELOC_PPC_BA16
:
1094 return &xcoff_howto_table
[0x1c];
1095 case BFD_RELOC_PPC_BA26
:
1096 return &xcoff_howto_table
[8];
1097 case BFD_RELOC_PPC_TOC16
:
1098 return &xcoff_howto_table
[3];
1100 /* Note that this relocation is only internally used by gas. */
1101 return &xcoff_howto_table
[0xc];
1102 case BFD_RELOC_PPC_B16
:
1103 return &xcoff_howto_table
[0x1d];
1105 case BFD_RELOC_CTOR
:
1106 return &xcoff_howto_table
[0];
1107 case BFD_RELOC_NONE
:
1108 return &xcoff_howto_table
[0xf];
1114 static reloc_howto_type
*
1115 _bfd_xcoff_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1121 i
< sizeof (xcoff_howto_table
) / sizeof (xcoff_howto_table
[0]);
1123 if (xcoff_howto_table
[i
].name
!= NULL
1124 && strcasecmp (xcoff_howto_table
[i
].name
, r_name
) == 0)
1125 return &xcoff_howto_table
[i
];
1130 /* XCOFF archive support. The original version of this code was by
1131 Damon A. Permezel. It was enhanced to permit cross support, and
1132 writing archive files, by Ian Lance Taylor, Cygnus Support.
1134 XCOFF uses its own archive format. Everything is hooked together
1135 with file offset links, so it is possible to rapidly update an
1136 archive in place. Of course, we don't do that. An XCOFF archive
1137 has a real file header, not just an ARMAG string. The structure of
1138 the file header and of each archive header appear below.
1140 An XCOFF archive also has a member table, which is a list of
1141 elements in the archive (you can get that by looking through the
1142 linked list, but you have to read a lot more of the file). The
1143 member table has a normal archive header with an empty name. It is
1144 normally (and perhaps must be) the second to last entry in the
1145 archive. The member table data is almost printable ASCII. It
1146 starts with a 12 character decimal string which is the number of
1147 entries in the table. For each entry it has a 12 character decimal
1148 string which is the offset in the archive of that member. These
1149 entries are followed by a series of null terminated strings which
1150 are the member names for each entry.
1152 Finally, an XCOFF archive has a global symbol table, which is what
1153 we call the armap. The global symbol table has a normal archive
1154 header with an empty name. It is normally (and perhaps must be)
1155 the last entry in the archive. The contents start with a four byte
1156 binary number which is the number of entries. This is followed by
1157 a that many four byte binary numbers; each is the file offset of an
1158 entry in the archive. These numbers are followed by a series of
1159 null terminated strings, which are symbol names.
1161 AIX 4.3 introduced a new archive format which can handle larger
1162 files and also 32- and 64-bit objects in the same archive. The
1163 things said above remain true except that there is now more than
1164 one global symbol table. The one is used to index 32-bit objects,
1165 the other for 64-bit objects.
1167 The new archives (recognizable by the new ARMAG string) has larger
1168 field lengths so that we cannot really share any code. Also we have
1169 to take care that we are not generating the new form of archives
1170 on AIX 4.2 or earlier systems. */
1172 /* XCOFF archives use this as a magic string. Note that both strings
1173 have the same length. */
1175 /* Set the magic for archive. */
1178 bfd_xcoff_ar_archive_set_magic (bfd
*abfd ATTRIBUTE_UNUSED
,
1179 char *magic ATTRIBUTE_UNUSED
)
1181 /* Not supported yet. */
1183 /* bfd_xcoff_archive_set_magic (abfd, magic); */
1186 /* PR 21786: The PE/COFF standard does not require NUL termination for any of
1187 the ASCII fields in the archive headers. So in order to be able to extract
1188 numerical values we provide our own versions of strtol and strtoll which
1189 take a maximum length as an additional parameter. Also - just to save space,
1190 we omit the endptr return parameter, since we know that it is never used. */
1193 _bfd_strntol (const char * nptr
, int base
, unsigned int maxlen
)
1195 char buf
[24]; /* Should be enough. */
1197 BFD_ASSERT (maxlen
< (sizeof (buf
) - 1));
1199 memcpy (buf
, nptr
, maxlen
);
1201 return strtol (buf
, NULL
, base
);
1205 _bfd_strntoll (const char * nptr
, int base
, unsigned int maxlen
)
1207 char buf
[32]; /* Should be enough. */
1209 BFD_ASSERT (maxlen
< (sizeof (buf
) - 1));
1211 memcpy (buf
, nptr
, maxlen
);
1213 return strtoll (buf
, NULL
, base
);
1216 /* Macro to read an ASCII value stored in an archive header field. */
1217 #define GET_VALUE_IN_FIELD(VAR, FIELD, BASE) \
1220 (VAR) = (sizeof (VAR) > sizeof (long) \
1221 ? _bfd_strntoll (FIELD, BASE, sizeof FIELD) \
1222 : _bfd_strntol (FIELD, BASE, sizeof FIELD)); \
1226 #define EQ_VALUE_IN_FIELD(VAR, FIELD, BASE) \
1227 (sizeof (VAR) > sizeof (long) \
1228 ? (VAR) == _bfd_strntoll (FIELD, BASE, sizeof FIELD) \
1229 : (VAR) == _bfd_strntol (FIELD, BASE, sizeof FIELD))
1231 /* Read in the armap of an XCOFF archive. */
1234 _bfd_xcoff_slurp_armap (bfd
*abfd
)
1239 bfd_byte
*contents
, *cend
;
1244 if (xcoff_ardata (abfd
) == NULL
)
1246 bfd_has_map (abfd
) = FALSE
;
1250 if (! xcoff_big_format_p (abfd
))
1252 /* This is for the old format. */
1253 struct xcoff_ar_hdr hdr
;
1255 GET_VALUE_IN_FIELD (off
, xcoff_ardata (abfd
)->symoff
, 10);
1258 bfd_has_map (abfd
) = FALSE
;
1262 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0)
1265 /* The symbol table starts with a normal archive header. */
1266 if (bfd_bread (&hdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1270 /* Skip the name (normally empty). */
1271 GET_VALUE_IN_FIELD (namlen
, hdr
.namlen
, 10);
1272 off
= ((namlen
+ 1) & ~ (size_t) 1) + SXCOFFARFMAG
;
1273 if (bfd_seek (abfd
, off
, SEEK_CUR
) != 0)
1276 GET_VALUE_IN_FIELD (sz
, hdr
.size
, 10);
1278 /* Read in the entire symbol table. */
1279 contents
= (bfd_byte
*) bfd_alloc (abfd
, sz
);
1280 if (contents
== NULL
)
1282 if (bfd_bread (contents
, sz
, abfd
) != sz
)
1285 /* The symbol table starts with a four byte count. */
1286 c
= H_GET_32 (abfd
, contents
);
1290 bfd_set_error (bfd_error_bad_value
);
1294 bfd_ardata (abfd
)->symdefs
=
1295 ((carsym
*) bfd_alloc (abfd
, c
* sizeof (carsym
)));
1296 if (bfd_ardata (abfd
)->symdefs
== NULL
)
1299 /* After the count comes a list of four byte file offsets. */
1300 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
, p
= contents
+ 4;
1302 ++i
, ++arsym
, p
+= 4)
1303 arsym
->file_offset
= H_GET_32 (abfd
, p
);
1307 /* This is for the new format. */
1308 struct xcoff_ar_hdr_big hdr
;
1310 GET_VALUE_IN_FIELD (off
, xcoff_ardata_big (abfd
)->symoff
, 10);
1313 bfd_has_map (abfd
) = FALSE
;
1317 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0)
1320 /* The symbol table starts with a normal archive header. */
1321 if (bfd_bread (&hdr
, (bfd_size_type
) SIZEOF_AR_HDR_BIG
, abfd
)
1322 != SIZEOF_AR_HDR_BIG
)
1325 /* Skip the name (normally empty). */
1326 GET_VALUE_IN_FIELD (namlen
, hdr
.namlen
, 10);
1327 off
= ((namlen
+ 1) & ~ (size_t) 1) + SXCOFFARFMAG
;
1328 if (bfd_seek (abfd
, off
, SEEK_CUR
) != 0)
1331 GET_VALUE_IN_FIELD (sz
, hdr
.size
, 10);
1333 /* Read in the entire symbol table. */
1334 contents
= (bfd_byte
*) bfd_alloc (abfd
, sz
);
1335 if (contents
== NULL
)
1337 if (bfd_bread (contents
, sz
, abfd
) != sz
)
1340 /* The symbol table starts with an eight byte count. */
1341 c
= H_GET_64 (abfd
, contents
);
1345 bfd_set_error (bfd_error_bad_value
);
1349 bfd_ardata (abfd
)->symdefs
=
1350 ((carsym
*) bfd_alloc (abfd
, c
* sizeof (carsym
)));
1351 if (bfd_ardata (abfd
)->symdefs
== NULL
)
1354 /* After the count comes a list of eight byte file offsets. */
1355 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
, p
= contents
+ 8;
1357 ++i
, ++arsym
, p
+= 8)
1358 arsym
->file_offset
= H_GET_64 (abfd
, p
);
1361 /* After the file offsets come null terminated symbol names. */
1362 cend
= contents
+ sz
;
1363 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
;
1365 ++i
, ++arsym
, p
+= strlen ((char *) p
) + 1)
1369 bfd_set_error (bfd_error_bad_value
);
1372 arsym
->name
= (char *) p
;
1375 bfd_ardata (abfd
)->symdef_count
= c
;
1376 bfd_has_map (abfd
) = TRUE
;
1381 /* See if this is an XCOFF archive. */
1384 _bfd_xcoff_archive_p (bfd
*abfd
)
1386 struct artdata
*tdata_hold
;
1387 char magic
[SXCOFFARMAG
];
1388 bfd_size_type amt
= SXCOFFARMAG
;
1390 if (bfd_bread (magic
, amt
, abfd
) != amt
)
1392 if (bfd_get_error () != bfd_error_system_call
)
1393 bfd_set_error (bfd_error_wrong_format
);
1397 if (strncmp (magic
, XCOFFARMAG
, SXCOFFARMAG
) != 0
1398 && strncmp (magic
, XCOFFARMAGBIG
, SXCOFFARMAG
) != 0)
1400 bfd_set_error (bfd_error_wrong_format
);
1404 tdata_hold
= bfd_ardata (abfd
);
1406 amt
= sizeof (struct artdata
);
1407 bfd_ardata (abfd
) = (struct artdata
*) bfd_zalloc (abfd
, amt
);
1408 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
1409 goto error_ret_restore
;
1411 /* Cleared by bfd_zalloc above.
1412 bfd_ardata (abfd)->cache = NULL;
1413 bfd_ardata (abfd)->archive_head = NULL;
1414 bfd_ardata (abfd)->symdefs = NULL;
1415 bfd_ardata (abfd)->extended_names = NULL;
1416 bfd_ardata (abfd)->extended_names_size = 0; */
1418 /* Now handle the two formats. */
1419 if (magic
[1] != 'b')
1421 /* This is the old format. */
1422 struct xcoff_ar_file_hdr hdr
;
1424 /* Copy over the magic string. */
1425 memcpy (hdr
.magic
, magic
, SXCOFFARMAG
);
1427 /* Now read the rest of the file header. */
1428 amt
= SIZEOF_AR_FILE_HDR
- SXCOFFARMAG
;
1429 if (bfd_bread (&hdr
.memoff
, amt
, abfd
) != amt
)
1431 if (bfd_get_error () != bfd_error_system_call
)
1432 bfd_set_error (bfd_error_wrong_format
);
1436 GET_VALUE_IN_FIELD (bfd_ardata (abfd
)->first_file_filepos
,
1437 hdr
.firstmemoff
, 10);
1439 amt
= SIZEOF_AR_FILE_HDR
;
1440 bfd_ardata (abfd
)->tdata
= bfd_zalloc (abfd
, amt
);
1441 if (bfd_ardata (abfd
)->tdata
== NULL
)
1444 memcpy (bfd_ardata (abfd
)->tdata
, &hdr
, SIZEOF_AR_FILE_HDR
);
1448 /* This is the new format. */
1449 struct xcoff_ar_file_hdr_big hdr
;
1451 /* Copy over the magic string. */
1452 memcpy (hdr
.magic
, magic
, SXCOFFARMAG
);
1454 /* Now read the rest of the file header. */
1455 amt
= SIZEOF_AR_FILE_HDR_BIG
- SXCOFFARMAG
;
1456 if (bfd_bread (&hdr
.memoff
, amt
, abfd
) != amt
)
1458 if (bfd_get_error () != bfd_error_system_call
)
1459 bfd_set_error (bfd_error_wrong_format
);
1463 bfd_ardata (abfd
)->first_file_filepos
= bfd_scan_vma (hdr
.firstmemoff
,
1467 amt
= SIZEOF_AR_FILE_HDR_BIG
;
1468 bfd_ardata (abfd
)->tdata
= bfd_zalloc (abfd
, amt
);
1469 if (bfd_ardata (abfd
)->tdata
== NULL
)
1472 memcpy (bfd_ardata (abfd
)->tdata
, &hdr
, SIZEOF_AR_FILE_HDR_BIG
);
1475 if (! _bfd_xcoff_slurp_armap (abfd
))
1478 bfd_release (abfd
, bfd_ardata (abfd
));
1480 bfd_ardata (abfd
) = tdata_hold
;
1487 /* Read the archive header in an XCOFF archive. */
1490 _bfd_xcoff_read_ar_hdr (bfd
*abfd
)
1492 bfd_size_type namlen
;
1493 struct areltdata
*ret
;
1494 bfd_size_type amt
= sizeof (struct areltdata
);
1496 ret
= (struct areltdata
*) bfd_zmalloc (amt
);
1500 if (! xcoff_big_format_p (abfd
))
1502 struct xcoff_ar_hdr hdr
;
1503 struct xcoff_ar_hdr
*hdrp
;
1505 if (bfd_bread (&hdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1512 GET_VALUE_IN_FIELD (namlen
, hdr
.namlen
, 10);
1513 amt
= SIZEOF_AR_HDR
+ namlen
+ 1;
1514 hdrp
= (struct xcoff_ar_hdr
*) bfd_alloc (abfd
, amt
);
1520 memcpy (hdrp
, &hdr
, SIZEOF_AR_HDR
);
1521 if (bfd_bread ((char *) hdrp
+ SIZEOF_AR_HDR
, namlen
, abfd
) != namlen
)
1526 ((char *) hdrp
)[SIZEOF_AR_HDR
+ namlen
] = '\0';
1528 ret
->arch_header
= (char *) hdrp
;
1529 GET_VALUE_IN_FIELD (ret
->parsed_size
, hdr
.size
, 10);
1530 ret
->filename
= (char *) hdrp
+ SIZEOF_AR_HDR
;
1534 struct xcoff_ar_hdr_big hdr
;
1535 struct xcoff_ar_hdr_big
*hdrp
;
1537 if (bfd_bread (&hdr
, (bfd_size_type
) SIZEOF_AR_HDR_BIG
, abfd
)
1538 != SIZEOF_AR_HDR_BIG
)
1544 GET_VALUE_IN_FIELD (namlen
, hdr
.namlen
, 10);
1545 amt
= SIZEOF_AR_HDR_BIG
+ namlen
+ 1;
1546 hdrp
= (struct xcoff_ar_hdr_big
*) bfd_alloc (abfd
, amt
);
1552 memcpy (hdrp
, &hdr
, SIZEOF_AR_HDR_BIG
);
1553 if (bfd_bread ((char *) hdrp
+ SIZEOF_AR_HDR_BIG
, namlen
, abfd
) != namlen
)
1558 ((char *) hdrp
)[SIZEOF_AR_HDR_BIG
+ namlen
] = '\0';
1560 ret
->arch_header
= (char *) hdrp
;
1561 GET_VALUE_IN_FIELD (ret
->parsed_size
, hdr
.size
, 10);
1562 ret
->filename
= (char *) hdrp
+ SIZEOF_AR_HDR_BIG
;
1565 /* Skip over the XCOFFARFMAG at the end of the file name. */
1566 if (bfd_seek (abfd
, (file_ptr
) ((namlen
& 1) + SXCOFFARFMAG
), SEEK_CUR
) != 0)
1572 /* Open the next element in an XCOFF archive. */
1575 _bfd_xcoff_openr_next_archived_file (bfd
*archive
, bfd
*last_file
)
1579 if (xcoff_ardata (archive
) == NULL
)
1581 bfd_set_error (bfd_error_invalid_operation
);
1585 if (! xcoff_big_format_p (archive
))
1587 if (last_file
== NULL
)
1588 filestart
= bfd_ardata (archive
)->first_file_filepos
;
1590 GET_VALUE_IN_FIELD (filestart
, arch_xhdr (last_file
)->nextoff
, 10);
1593 || EQ_VALUE_IN_FIELD (filestart
, xcoff_ardata (archive
)->memoff
, 10)
1594 || EQ_VALUE_IN_FIELD (filestart
, xcoff_ardata (archive
)->symoff
, 10))
1596 bfd_set_error (bfd_error_no_more_archived_files
);
1602 if (last_file
== NULL
)
1603 filestart
= bfd_ardata (archive
)->first_file_filepos
;
1605 GET_VALUE_IN_FIELD (filestart
, arch_xhdr_big (last_file
)->nextoff
, 10);
1608 || EQ_VALUE_IN_FIELD (filestart
, xcoff_ardata_big (archive
)->memoff
, 10)
1609 || EQ_VALUE_IN_FIELD (filestart
, xcoff_ardata_big (archive
)->symoff
, 10))
1611 bfd_set_error (bfd_error_no_more_archived_files
);
1616 return _bfd_get_elt_at_filepos (archive
, filestart
);
1619 /* Stat an element in an XCOFF archive. */
1622 _bfd_xcoff_stat_arch_elt (bfd
*abfd
, struct stat
*s
)
1624 if (abfd
->arelt_data
== NULL
)
1626 bfd_set_error (bfd_error_invalid_operation
);
1630 if (! xcoff_big_format_p (abfd
->my_archive
))
1632 struct xcoff_ar_hdr
*hdrp
= arch_xhdr (abfd
);
1634 GET_VALUE_IN_FIELD (s
->st_mtime
, hdrp
->date
, 10);
1635 GET_VALUE_IN_FIELD (s
->st_uid
, hdrp
->uid
, 10);
1636 GET_VALUE_IN_FIELD (s
->st_gid
, hdrp
->gid
, 10);
1637 GET_VALUE_IN_FIELD (s
->st_mode
, hdrp
->mode
, 8);
1638 s
->st_size
= arch_eltdata (abfd
)->parsed_size
;
1642 struct xcoff_ar_hdr_big
*hdrp
= arch_xhdr_big (abfd
);
1644 GET_VALUE_IN_FIELD (s
->st_mtime
, hdrp
->date
, 10);
1645 GET_VALUE_IN_FIELD (s
->st_uid
, hdrp
->uid
, 10);
1646 GET_VALUE_IN_FIELD (s
->st_gid
, hdrp
->gid
, 10);
1647 GET_VALUE_IN_FIELD (s
->st_mode
, hdrp
->mode
, 8);
1648 s
->st_size
= arch_eltdata (abfd
)->parsed_size
;
1654 /* Normalize a file name for inclusion in an archive. */
1657 normalize_filename (bfd
*abfd
)
1660 const char *filename
;
1662 file
= bfd_get_filename (abfd
);
1663 filename
= strrchr (file
, '/');
1664 if (filename
!= NULL
)
1671 /* Write out an XCOFF armap. */
1674 xcoff_write_armap_old (bfd
*abfd
, unsigned int elength ATTRIBUTE_UNUSED
,
1675 struct orl
*map
, unsigned int orl_count
, int stridx
)
1677 struct archive_iterator iterator
;
1678 struct xcoff_ar_hdr hdr
;
1680 unsigned char buf
[4];
1683 memset (&hdr
, 0, sizeof hdr
);
1684 sprintf (hdr
.size
, "%ld", (long) (4 + orl_count
* 4 + stridx
));
1685 sprintf (hdr
.nextoff
, "%d", 0);
1686 memcpy (hdr
.prevoff
, xcoff_ardata (abfd
)->memoff
, XCOFFARMAG_ELEMENT_SIZE
);
1687 sprintf (hdr
.date
, "%d", 0);
1688 sprintf (hdr
.uid
, "%d", 0);
1689 sprintf (hdr
.gid
, "%d", 0);
1690 sprintf (hdr
.mode
, "%d", 0);
1691 sprintf (hdr
.namlen
, "%d", 0);
1693 /* We need spaces, not null bytes, in the header. */
1694 for (p
= (char *) &hdr
; p
< (char *) &hdr
+ SIZEOF_AR_HDR
; p
++)
1698 if (bfd_bwrite (&hdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1700 || (bfd_bwrite (XCOFFARFMAG
, (bfd_size_type
) SXCOFFARFMAG
, abfd
)
1704 H_PUT_32 (abfd
, orl_count
, buf
);
1705 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
1709 archive_iterator_begin (&iterator
, abfd
);
1710 while (i
< orl_count
&& archive_iterator_next (&iterator
))
1711 while (map
[i
].u
.abfd
== iterator
.current
.member
)
1713 H_PUT_32 (abfd
, iterator
.current
.offset
, buf
);
1714 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
1719 for (i
= 0; i
< orl_count
; i
++)
1724 name
= *map
[i
].name
;
1725 namlen
= strlen (name
);
1726 if (bfd_bwrite (name
, (bfd_size_type
) (namlen
+ 1), abfd
) != namlen
+ 1)
1730 if ((stridx
& 1) != 0)
1735 if (bfd_bwrite (&b
, (bfd_size_type
) 1, abfd
) != 1)
1742 static char buff20
[XCOFFARMAGBIG_ELEMENT_SIZE
+ 1];
1743 #if BFD_HOST_64BIT_LONG
1744 #define FMT20 "%-20ld"
1745 #elif defined (__MSVCRT__)
1746 #define FMT20 "%-20I64d"
1748 #define FMT20 "%-20lld"
1750 #define FMT12 "%-12d"
1751 #define FMT12_OCTAL "%-12o"
1753 #define PRINT20(d, v) \
1754 sprintf (buff20, FMT20, (bfd_uint64_t)(v)), \
1755 memcpy ((void *) (d), buff20, 20)
1757 #define PRINT12(d, v) \
1758 sprintf (buff20, FMT12, (int)(v)), \
1759 memcpy ((void *) (d), buff20, 12)
1761 #define PRINT12_OCTAL(d, v) \
1762 sprintf (buff20, FMT12_OCTAL, (unsigned int)(v)), \
1763 memcpy ((void *) (d), buff20, 12)
1765 #define PRINT4(d, v) \
1766 sprintf (buff20, FMT4, (int)(v)), \
1767 memcpy ((void *) (d), buff20, 4)
1769 #define READ20(d, v) \
1771 memcpy (buff20, (d), 20), \
1772 (v) = bfd_scan_vma (buff20, (const char **) NULL, 10)
1775 do_pad (bfd
*abfd
, unsigned int number
)
1779 /* Limit pad to <= 4096. */
1784 if (bfd_bwrite (&b
, (bfd_size_type
) 1, abfd
) != 1)
1791 do_copy (bfd
*out_bfd
, bfd
*in_bfd
)
1793 bfd_size_type remaining
;
1794 bfd_byte buffer
[DEFAULT_BUFFERSIZE
];
1796 if (bfd_seek (in_bfd
, (file_ptr
) 0, SEEK_SET
) != 0)
1799 remaining
= arelt_size (in_bfd
);
1801 while (remaining
>= DEFAULT_BUFFERSIZE
)
1803 if (bfd_bread (buffer
, DEFAULT_BUFFERSIZE
, in_bfd
) != DEFAULT_BUFFERSIZE
1804 || bfd_bwrite (buffer
, DEFAULT_BUFFERSIZE
, out_bfd
) != DEFAULT_BUFFERSIZE
)
1807 remaining
-= DEFAULT_BUFFERSIZE
;
1812 if (bfd_bread (buffer
, remaining
, in_bfd
) != remaining
1813 || bfd_bwrite (buffer
, remaining
, out_bfd
) != remaining
)
1821 xcoff_write_armap_big (bfd
*abfd
, unsigned int elength ATTRIBUTE_UNUSED
,
1822 struct orl
*map
, unsigned int orl_count
, int stridx
)
1824 struct archive_iterator iterator
;
1825 struct xcoff_ar_file_hdr_big
*fhdr
;
1826 bfd_vma i
, sym_32
, sym_64
, str_32
, str_64
;
1827 const bfd_arch_info_type
*arch_info
;
1829 size_t string_length
;
1830 file_ptr nextoff
, prevoff
;
1832 /* First, we look through the symbols and work out which are
1833 from 32-bit objects and which from 64-bit ones. */
1834 sym_32
= sym_64
= str_32
= str_64
= 0;
1837 for (current_bfd
= abfd
->archive_head
;
1838 current_bfd
!= NULL
&& i
< orl_count
;
1839 current_bfd
= current_bfd
->archive_next
)
1841 arch_info
= bfd_get_arch_info (current_bfd
);
1842 while (map
[i
].u
.abfd
== current_bfd
)
1844 string_length
= strlen (*map
[i
].name
) + 1;
1845 if (arch_info
->bits_per_address
== 64)
1848 str_64
+= string_length
;
1853 str_32
+= string_length
;
1859 /* A quick sanity check... */
1860 BFD_ASSERT (sym_64
+ sym_32
== orl_count
);
1861 /* Explicit cast to int for compiler. */
1862 BFD_ASSERT ((int)(str_64
+ str_32
) == stridx
);
1864 fhdr
= xcoff_ardata_big (abfd
);
1866 /* xcoff_write_archive_contents_big passes nextoff in symoff. */
1867 READ20 (fhdr
->memoff
, prevoff
);
1868 READ20 (fhdr
->symoff
, nextoff
);
1870 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
1872 /* Write out the symbol table.
1875 standard big archive header
1876 0x0000 ar_size [0x14]
1877 0x0014 ar_nxtmem [0x14]
1878 0x0028 ar_prvmem [0x14]
1879 0x003C ar_date [0x0C]
1880 0x0048 ar_uid [0x0C]
1881 0x0054 ar_gid [0x0C]
1882 0x0060 ar_mod [0x0C]
1883 0x006C ar_namelen[0x04]
1884 0x0070 ar_fmag [SXCOFFARFMAG]
1887 0x0072 num_syms [0x08], binary
1888 0x0078 offsets [0x08 * num_syms], binary
1889 0x0086 + 0x08 * num_syms names [??]
1890 ?? pad to even bytes.
1895 struct xcoff_ar_hdr_big
*hdr
;
1899 bfd_vma symbol_table_size
=
1904 + str_32
+ (str_32
& 1);
1906 symbol_table
= bfd_zmalloc (symbol_table_size
);
1907 if (symbol_table
== NULL
)
1910 hdr
= (struct xcoff_ar_hdr_big
*) symbol_table
;
1912 PRINT20 (hdr
->size
, 8 + 8 * sym_32
+ str_32
+ (str_32
& 1));
1915 PRINT20 (hdr
->nextoff
, nextoff
+ symbol_table_size
);
1917 PRINT20 (hdr
->nextoff
, 0);
1919 PRINT20 (hdr
->prevoff
, prevoff
);
1920 PRINT12 (hdr
->date
, 0);
1921 PRINT12 (hdr
->uid
, 0);
1922 PRINT12 (hdr
->gid
, 0);
1923 PRINT12 (hdr
->mode
, 0);
1924 PRINT4 (hdr
->namlen
, 0) ;
1926 st
= symbol_table
+ SIZEOF_AR_HDR_BIG
;
1927 memcpy (st
, XCOFFARFMAG
, SXCOFFARFMAG
);
1930 bfd_h_put_64 (abfd
, sym_32
, st
);
1933 /* loop over the 32 bit offsets */
1935 archive_iterator_begin (&iterator
, abfd
);
1936 while (i
< orl_count
&& archive_iterator_next (&iterator
))
1938 arch_info
= bfd_get_arch_info (iterator
.current
.member
);
1939 while (map
[i
].u
.abfd
== iterator
.current
.member
)
1941 if (arch_info
->bits_per_address
== 32)
1943 bfd_h_put_64 (abfd
, iterator
.current
.offset
, st
);
1950 /* loop over the 32 bit symbol names */
1952 for (current_bfd
= abfd
->archive_head
;
1953 current_bfd
!= NULL
&& i
< orl_count
;
1954 current_bfd
= current_bfd
->archive_next
)
1956 arch_info
= bfd_get_arch_info (current_bfd
);
1957 while (map
[i
].u
.abfd
== current_bfd
)
1959 if (arch_info
->bits_per_address
== 32)
1961 string_length
= sprintf (st
, "%s", *map
[i
].name
);
1962 st
+= string_length
+ 1;
1968 bfd_bwrite (symbol_table
, symbol_table_size
, abfd
);
1970 free (symbol_table
);
1973 nextoff
= nextoff
+ symbol_table_size
;
1976 PRINT20 (fhdr
->symoff
, 0);
1980 struct xcoff_ar_hdr_big
*hdr
;
1984 bfd_vma symbol_table_size
=
1989 + str_64
+ (str_64
& 1);
1991 symbol_table
= bfd_zmalloc (symbol_table_size
);
1992 if (symbol_table
== NULL
)
1995 hdr
= (struct xcoff_ar_hdr_big
*) symbol_table
;
1997 PRINT20 (hdr
->size
, 8 + 8 * sym_64
+ str_64
+ (str_64
& 1));
1998 PRINT20 (hdr
->nextoff
, 0);
1999 PRINT20 (hdr
->prevoff
, prevoff
);
2000 PRINT12 (hdr
->date
, 0);
2001 PRINT12 (hdr
->uid
, 0);
2002 PRINT12 (hdr
->gid
, 0);
2003 PRINT12 (hdr
->mode
, 0);
2004 PRINT4 (hdr
->namlen
, 0);
2006 st
= symbol_table
+ SIZEOF_AR_HDR_BIG
;
2007 memcpy (st
, XCOFFARFMAG
, SXCOFFARFMAG
);
2010 bfd_h_put_64 (abfd
, sym_64
, st
);
2013 /* loop over the 64 bit offsets */
2015 archive_iterator_begin (&iterator
, abfd
);
2016 while (i
< orl_count
&& archive_iterator_next (&iterator
))
2018 arch_info
= bfd_get_arch_info (iterator
.current
.member
);
2019 while (map
[i
].u
.abfd
== iterator
.current
.member
)
2021 if (arch_info
->bits_per_address
== 64)
2023 bfd_h_put_64 (abfd
, iterator
.current
.offset
, st
);
2030 /* loop over the 64 bit symbol names */
2032 for (current_bfd
= abfd
->archive_head
;
2033 current_bfd
!= NULL
&& i
< orl_count
;
2034 current_bfd
= current_bfd
->archive_next
)
2036 arch_info
= bfd_get_arch_info (current_bfd
);
2037 while (map
[i
].u
.abfd
== current_bfd
)
2039 if (arch_info
->bits_per_address
== 64)
2041 string_length
= sprintf (st
, "%s", *map
[i
].name
);
2042 st
+= string_length
+ 1;
2048 bfd_bwrite (symbol_table
, symbol_table_size
, abfd
);
2050 free (symbol_table
);
2052 PRINT20 (fhdr
->symoff64
, nextoff
);
2055 PRINT20 (fhdr
->symoff64
, 0);
2061 _bfd_xcoff_write_armap (bfd
*abfd
, unsigned int elength ATTRIBUTE_UNUSED
,
2062 struct orl
*map
, unsigned int orl_count
, int stridx
)
2064 if (! xcoff_big_format_p (abfd
))
2065 return xcoff_write_armap_old (abfd
, elength
, map
, orl_count
, stridx
);
2067 return xcoff_write_armap_big (abfd
, elength
, map
, orl_count
, stridx
);
2070 /* Write out an XCOFF archive. We always write an entire archive,
2071 rather than fussing with the freelist and so forth. */
2074 xcoff_write_archive_contents_old (bfd
*abfd
)
2076 struct archive_iterator iterator
;
2077 struct xcoff_ar_file_hdr fhdr
;
2078 bfd_size_type count
;
2079 bfd_size_type total_namlen
;
2081 bfd_boolean makemap
;
2082 bfd_boolean hasobjects
;
2083 file_ptr prevoff
, nextoff
;
2086 struct xcoff_ar_hdr ahdr
;
2089 char decbuf
[XCOFFARMAG_ELEMENT_SIZE
+ 1];
2091 memset (&fhdr
, 0, sizeof fhdr
);
2092 (void) memcpy (fhdr
.magic
, XCOFFARMAG
, SXCOFFARMAG
);
2093 sprintf (fhdr
.firstmemoff
, "%d", SIZEOF_AR_FILE_HDR
);
2094 sprintf (fhdr
.freeoff
, "%d", 0);
2098 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->archive_next
)
2101 total_namlen
+= strlen (normalize_filename (sub
)) + 1;
2102 if (sub
->arelt_data
== NULL
)
2104 sub
->arelt_data
= bfd_zmalloc (sizeof (struct areltdata
));
2105 if (sub
->arelt_data
== NULL
)
2108 if (arch_xhdr (sub
) == NULL
)
2110 struct xcoff_ar_hdr
*ahdrp
;
2113 if (stat (bfd_get_filename (sub
), &s
) != 0)
2115 bfd_set_error (bfd_error_system_call
);
2119 ahdrp
= bfd_zalloc (sub
, sizeof (*ahdrp
));
2123 sprintf (ahdrp
->size
, "%ld", (long) s
.st_size
);
2124 sprintf (ahdrp
->date
, "%ld", (long) s
.st_mtime
);
2125 sprintf (ahdrp
->uid
, "%ld", (long) s
.st_uid
);
2126 sprintf (ahdrp
->gid
, "%ld", (long) s
.st_gid
);
2127 sprintf (ahdrp
->mode
, "%o", (unsigned int) s
.st_mode
);
2129 arch_eltdata (sub
)->arch_header
= (char *) ahdrp
;
2130 arch_eltdata (sub
)->parsed_size
= s
.st_size
;
2133 offsets
= (file_ptr
*) bfd_alloc (abfd
, count
* sizeof (file_ptr
));
2134 if (offsets
== NULL
)
2137 if (bfd_seek (abfd
, (file_ptr
) SIZEOF_AR_FILE_HDR
, SEEK_SET
) != 0)
2140 makemap
= bfd_has_map (abfd
);
2143 for (archive_iterator_begin (&iterator
, abfd
), i
= 0;
2144 archive_iterator_next (&iterator
);
2147 bfd_size_type namlen
;
2148 struct xcoff_ar_hdr
*ahdrp
;
2150 if (makemap
&& ! hasobjects
)
2152 if (bfd_check_format (iterator
.current
.member
, bfd_object
))
2156 ahdrp
= arch_xhdr (iterator
.current
.member
);
2157 sprintf (ahdrp
->prevoff
, "%ld", (long) prevoff
);
2158 sprintf (ahdrp
->namlen
, "%ld", (long) iterator
.current
.namlen
);
2159 sprintf (ahdrp
->nextoff
, "%ld", (long) iterator
.next
.offset
);
2161 /* We need spaces, not null bytes, in the header. */
2162 for (p
= (char *) ahdrp
; p
< (char *) ahdrp
+ SIZEOF_AR_HDR
; p
++)
2166 if (!do_pad (abfd
, iterator
.current
.leading_padding
))
2169 BFD_ASSERT (iterator
.current
.offset
== bfd_tell (abfd
));
2170 namlen
= iterator
.current
.padded_namlen
;
2171 if (bfd_bwrite (ahdrp
, SIZEOF_AR_HDR
, abfd
) != SIZEOF_AR_HDR
2172 || bfd_bwrite (iterator
.current
.name
, namlen
, abfd
) != namlen
2173 || bfd_bwrite (XCOFFARFMAG
, SXCOFFARFMAG
, abfd
) != SXCOFFARFMAG
2174 || bfd_seek (iterator
.current
.member
, 0, SEEK_SET
) != 0
2175 || !do_copy (abfd
, iterator
.current
.member
)
2176 || !do_pad (abfd
, iterator
.current
.trailing_padding
))
2179 offsets
[i
] = iterator
.current
.offset
;
2180 prevoff
= iterator
.current
.offset
;
2183 sprintf (fhdr
.lastmemoff
, "%ld", (long) prevoff
);
2185 /* Write out the member table. */
2187 nextoff
= iterator
.next
.offset
;
2188 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2189 sprintf (fhdr
.memoff
, "%ld", (long) nextoff
);
2191 memset (&ahdr
, 0, sizeof ahdr
);
2192 sprintf (ahdr
.size
, "%ld", (long) (XCOFFARMAG_ELEMENT_SIZE
2193 + count
* XCOFFARMAG_ELEMENT_SIZE
2195 sprintf (ahdr
.prevoff
, "%ld", (long) prevoff
);
2196 sprintf (ahdr
.date
, "%d", 0);
2197 sprintf (ahdr
.uid
, "%d", 0);
2198 sprintf (ahdr
.gid
, "%d", 0);
2199 sprintf (ahdr
.mode
, "%d", 0);
2200 sprintf (ahdr
.namlen
, "%d", 0);
2202 size
= (SIZEOF_AR_HDR
2203 + XCOFFARMAG_ELEMENT_SIZE
2204 + count
* XCOFFARMAG_ELEMENT_SIZE
2209 nextoff
+= size
+ (size
& 1);
2211 if (makemap
&& hasobjects
)
2212 sprintf (ahdr
.nextoff
, "%ld", (long) nextoff
);
2214 sprintf (ahdr
.nextoff
, "%d", 0);
2216 /* We need spaces, not null bytes, in the header. */
2217 for (p
= (char *) &ahdr
; p
< (char *) &ahdr
+ SIZEOF_AR_HDR
; p
++)
2221 if ((bfd_bwrite (&ahdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
2223 || (bfd_bwrite (XCOFFARFMAG
, (bfd_size_type
) SXCOFFARFMAG
, abfd
)
2227 sprintf (decbuf
, "%-12ld", (long) count
);
2228 if (bfd_bwrite (decbuf
, (bfd_size_type
) XCOFFARMAG_ELEMENT_SIZE
, abfd
)
2229 != XCOFFARMAG_ELEMENT_SIZE
)
2231 for (i
= 0; i
< (size_t) count
; i
++)
2233 sprintf (decbuf
, "%-12ld", (long) offsets
[i
]);
2234 if (bfd_bwrite (decbuf
, (bfd_size_type
) XCOFFARMAG_ELEMENT_SIZE
,
2235 abfd
) != XCOFFARMAG_ELEMENT_SIZE
)
2238 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->archive_next
)
2241 bfd_size_type namlen
;
2243 name
= normalize_filename (sub
);
2244 namlen
= strlen (name
);
2245 if (bfd_bwrite (name
, namlen
+ 1, abfd
) != namlen
+ 1)
2249 if (! do_pad (abfd
, size
& 1))
2252 /* Write out the armap, if appropriate. */
2253 if (! makemap
|| ! hasobjects
)
2254 sprintf (fhdr
.symoff
, "%d", 0);
2257 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2258 sprintf (fhdr
.symoff
, "%ld", (long) nextoff
);
2259 bfd_ardata (abfd
)->tdata
= &fhdr
;
2260 if (! _bfd_compute_and_write_armap (abfd
, 0))
2264 /* Write out the archive file header. */
2266 /* We need spaces, not null bytes, in the header. */
2267 for (p
= (char *) &fhdr
; p
< (char *) &fhdr
+ SIZEOF_AR_FILE_HDR
; p
++)
2271 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
2272 || (bfd_bwrite (&fhdr
, (bfd_size_type
) SIZEOF_AR_FILE_HDR
, abfd
)
2273 != SIZEOF_AR_FILE_HDR
))
2280 xcoff_write_archive_contents_big (bfd
*abfd
)
2282 struct xcoff_ar_file_hdr_big fhdr
;
2283 bfd_size_type count
;
2284 bfd_size_type total_namlen
;
2286 bfd_boolean makemap
;
2287 bfd_boolean hasobjects
;
2288 file_ptr prevoff
, nextoff
;
2291 struct xcoff_ar_hdr_big
*hdr
;
2293 char *member_table
, *mt
;
2294 bfd_vma member_table_size
;
2295 struct archive_iterator iterator
;
2297 memset (&fhdr
, 0, SIZEOF_AR_FILE_HDR_BIG
);
2298 memcpy (fhdr
.magic
, XCOFFARMAGBIG
, SXCOFFARMAG
);
2300 if (bfd_seek (abfd
, (file_ptr
) SIZEOF_AR_FILE_HDR_BIG
, SEEK_SET
) != 0)
2303 /* Calculate count and total_namlen. */
2304 makemap
= bfd_has_map (abfd
);
2306 for (current_bfd
= abfd
->archive_head
, count
= 0, total_namlen
= 0;
2307 current_bfd
!= NULL
;
2308 current_bfd
= current_bfd
->archive_next
, count
++)
2310 total_namlen
+= strlen (normalize_filename (current_bfd
)) + 1;
2314 && bfd_check_format (current_bfd
, bfd_object
))
2317 if (current_bfd
->arelt_data
== NULL
)
2319 size
= sizeof (struct areltdata
);
2320 current_bfd
->arelt_data
= bfd_zmalloc (size
);
2321 if (current_bfd
->arelt_data
== NULL
)
2325 if (arch_xhdr_big (current_bfd
) == NULL
)
2327 struct xcoff_ar_hdr_big
*ahdrp
;
2330 /* XXX This should actually be a call to stat64 (at least on
2332 XXX This call will fail if the original object is not found. */
2333 if (stat (bfd_get_filename (current_bfd
), &s
) != 0)
2335 bfd_set_error (bfd_error_system_call
);
2339 ahdrp
= bfd_zalloc (current_bfd
, sizeof (*ahdrp
));
2343 PRINT20 (ahdrp
->size
, s
.st_size
);
2344 PRINT12 (ahdrp
->date
, s
.st_mtime
);
2345 PRINT12 (ahdrp
->uid
, s
.st_uid
);
2346 PRINT12 (ahdrp
->gid
, s
.st_gid
);
2347 PRINT12_OCTAL (ahdrp
->mode
, s
.st_mode
);
2349 arch_eltdata (current_bfd
)->arch_header
= (char *) ahdrp
;
2350 arch_eltdata (current_bfd
)->parsed_size
= s
.st_size
;
2357 offsets
= (file_ptr
*) bfd_malloc (count
* sizeof (file_ptr
));
2358 if (offsets
== NULL
)
2363 for (archive_iterator_begin (&iterator
, abfd
), i
= 0;
2364 archive_iterator_next (&iterator
);
2367 bfd_size_type namlen
;
2368 struct xcoff_ar_hdr_big
*ahdrp
;
2370 ahdrp
= arch_xhdr_big (iterator
.current
.member
);
2371 PRINT20 (ahdrp
->prevoff
, prevoff
);
2372 PRINT4 (ahdrp
->namlen
, iterator
.current
.namlen
);
2373 PRINT20 (ahdrp
->nextoff
, iterator
.next
.offset
);
2375 if (!do_pad (abfd
, iterator
.current
.leading_padding
))
2381 BFD_ASSERT (iterator
.current
.offset
== bfd_tell (abfd
));
2382 namlen
= iterator
.current
.padded_namlen
;
2383 if (bfd_bwrite (ahdrp
, SIZEOF_AR_HDR_BIG
, abfd
) != SIZEOF_AR_HDR_BIG
2384 || bfd_bwrite (iterator
.current
.name
, namlen
, abfd
) != namlen
2385 || bfd_bwrite (XCOFFARFMAG
, SXCOFFARFMAG
, abfd
) != SXCOFFARFMAG
2386 || bfd_seek (iterator
.current
.member
, 0, SEEK_SET
) != 0
2387 || !do_copy (abfd
, iterator
.current
.member
)
2388 || !do_pad (abfd
, iterator
.current
.trailing_padding
))
2394 offsets
[i
] = iterator
.current
.offset
;
2395 prevoff
= iterator
.current
.offset
;
2400 PRINT20 (fhdr
.firstmemoff
, offsets
[0]);
2401 PRINT20 (fhdr
.lastmemoff
, prevoff
);
2404 /* Write out the member table.
2407 standard big archive header
2408 0x0000 ar_size [0x14]
2409 0x0014 ar_nxtmem [0x14]
2410 0x0028 ar_prvmem [0x14]
2411 0x003C ar_date [0x0C]
2412 0x0048 ar_uid [0x0C]
2413 0x0054 ar_gid [0x0C]
2414 0x0060 ar_mod [0x0C]
2415 0x006C ar_namelen[0x04]
2416 0x0070 ar_fmag [0x02]
2420 0x0086 offsets [0x14 * counts]
2421 0x0086 + 0x14 * counts names [??]
2422 ?? pad to even bytes.
2425 nextoff
= iterator
.next
.offset
;
2426 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2428 member_table_size
= (SIZEOF_AR_HDR_BIG
2430 + XCOFFARMAGBIG_ELEMENT_SIZE
2431 + count
* XCOFFARMAGBIG_ELEMENT_SIZE
2434 member_table_size
+= member_table_size
& 1;
2435 member_table
= bfd_zmalloc (member_table_size
);
2436 if (member_table
== NULL
)
2442 hdr
= (struct xcoff_ar_hdr_big
*) member_table
;
2444 PRINT20 (hdr
->size
, (XCOFFARMAGBIG_ELEMENT_SIZE
2445 + count
* XCOFFARMAGBIG_ELEMENT_SIZE
2446 + total_namlen
+ (total_namlen
& 1)));
2447 if (makemap
&& hasobjects
)
2448 PRINT20 (hdr
->nextoff
, nextoff
+ member_table_size
);
2450 PRINT20 (hdr
->nextoff
, 0);
2451 PRINT20 (hdr
->prevoff
, prevoff
);
2452 PRINT12 (hdr
->date
, 0);
2453 PRINT12 (hdr
->uid
, 0);
2454 PRINT12 (hdr
->gid
, 0);
2455 PRINT12 (hdr
->mode
, 0);
2456 PRINT4 (hdr
->namlen
, 0);
2458 mt
= member_table
+ SIZEOF_AR_HDR_BIG
;
2459 memcpy (mt
, XCOFFARFMAG
, SXCOFFARFMAG
);
2462 PRINT20 (mt
, count
);
2463 mt
+= XCOFFARMAGBIG_ELEMENT_SIZE
;
2464 for (i
= 0; i
< (size_t) count
; i
++)
2466 PRINT20 (mt
, offsets
[i
]);
2467 mt
+= XCOFFARMAGBIG_ELEMENT_SIZE
;
2476 for (current_bfd
= abfd
->archive_head
;
2477 current_bfd
!= NULL
;
2478 current_bfd
= current_bfd
->archive_next
)
2483 name
= normalize_filename (current_bfd
);
2484 namlen
= sprintf (mt
, "%s", name
);
2488 if (bfd_bwrite (member_table
, member_table_size
, abfd
) != member_table_size
)
2491 free (member_table
);
2493 PRINT20 (fhdr
.memoff
, nextoff
);
2496 nextoff
+= member_table_size
;
2498 /* Write out the armap, if appropriate. */
2500 if (! makemap
|| ! hasobjects
)
2501 PRINT20 (fhdr
.symoff
, 0);
2504 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2506 /* Save nextoff in fhdr.symoff so the armap routine can use it. */
2507 PRINT20 (fhdr
.symoff
, nextoff
);
2509 bfd_ardata (abfd
)->tdata
= &fhdr
;
2510 if (! _bfd_compute_and_write_armap (abfd
, 0))
2514 /* Write out the archive file header. */
2516 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
2517 || (bfd_bwrite (&fhdr
, (bfd_size_type
) SIZEOF_AR_FILE_HDR_BIG
,
2518 abfd
) != SIZEOF_AR_FILE_HDR_BIG
))
2525 _bfd_xcoff_write_archive_contents (bfd
*abfd
)
2527 if (! xcoff_big_format_p (abfd
))
2528 return xcoff_write_archive_contents_old (abfd
);
2530 return xcoff_write_archive_contents_big (abfd
);
2533 /* We can't use the usual coff_sizeof_headers routine, because AIX
2534 always uses an a.out header. */
2537 _bfd_xcoff_sizeof_headers (bfd
*abfd
,
2538 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
2543 if (xcoff_data (abfd
)->full_aouthdr
)
2546 size
+= SMALL_AOUTSZ
;
2547 size
+= abfd
->section_count
* SCNHSZ
;
2549 if (info
->strip
!= strip_all
)
2551 /* There can be additional sections just for dealing with overflow in
2552 reloc and lineno counts. But the numbers of relocs and lineno aren't
2553 known when bfd_sizeof_headers is called, so we compute them by
2554 summing the numbers from input sections. */
2555 struct nbr_reloc_lineno
2557 unsigned int reloc_count
;
2558 unsigned int lineno_count
;
2560 struct nbr_reloc_lineno
*n_rl
;
2562 unsigned int max_index
;
2565 /* Although the number of sections is known, the maximum value of
2566 section->index isn't (because some sections may have been removed).
2567 Don't try to renumber sections, just compute the upper bound. */
2569 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2570 if (s
->index
> max_index
)
2571 max_index
= s
->index
;
2573 /* Allocate the per section counters. It could be possible to use a
2574 preallocated array as the number of sections is limited on XCOFF,
2575 but this creates a maintainance issue. */
2576 n_rl
= bfd_zmalloc ((max_index
+ 1) * sizeof (*n_rl
));
2581 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link
.next
)
2582 for (s
= sub
->sections
; s
!= NULL
; s
= s
->next
)
2584 struct nbr_reloc_lineno
*e
= &n_rl
[s
->output_section
->index
];
2585 e
->reloc_count
+= s
->reloc_count
;
2586 e
->lineno_count
+= s
->lineno_count
;
2589 /* Add the size of a section for each section with an overflow. */
2590 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2592 struct nbr_reloc_lineno
*e
= &n_rl
[s
->index
];
2594 if (e
->reloc_count
>= 0xffff
2595 || (e
->lineno_count
>= 0xffff && info
->strip
!= strip_debugger
))
2605 /* Routines to swap information in the XCOFF .loader section. If we
2606 ever need to write an XCOFF loader, this stuff will need to be
2607 moved to another file shared by the linker (which XCOFF calls the
2608 ``binder'') and the loader. */
2610 /* Swap in the ldhdr structure. */
2613 xcoff_swap_ldhdr_in (bfd
*abfd
, const void * s
, struct internal_ldhdr
*dst
)
2615 const struct external_ldhdr
*src
= (const struct external_ldhdr
*) s
;
2617 dst
->l_version
= bfd_get_32 (abfd
, src
->l_version
);
2618 dst
->l_nsyms
= bfd_get_32 (abfd
, src
->l_nsyms
);
2619 dst
->l_nreloc
= bfd_get_32 (abfd
, src
->l_nreloc
);
2620 dst
->l_istlen
= bfd_get_32 (abfd
, src
->l_istlen
);
2621 dst
->l_nimpid
= bfd_get_32 (abfd
, src
->l_nimpid
);
2622 dst
->l_impoff
= bfd_get_32 (abfd
, src
->l_impoff
);
2623 dst
->l_stlen
= bfd_get_32 (abfd
, src
->l_stlen
);
2624 dst
->l_stoff
= bfd_get_32 (abfd
, src
->l_stoff
);
2627 /* Swap out the ldhdr structure. */
2630 xcoff_swap_ldhdr_out (bfd
*abfd
, const struct internal_ldhdr
*src
, void * d
)
2632 struct external_ldhdr
*dst
= (struct external_ldhdr
*) d
;
2634 bfd_put_32 (abfd
, (bfd_vma
) src
->l_version
, dst
->l_version
);
2635 bfd_put_32 (abfd
, src
->l_nsyms
, dst
->l_nsyms
);
2636 bfd_put_32 (abfd
, src
->l_nreloc
, dst
->l_nreloc
);
2637 bfd_put_32 (abfd
, src
->l_istlen
, dst
->l_istlen
);
2638 bfd_put_32 (abfd
, src
->l_nimpid
, dst
->l_nimpid
);
2639 bfd_put_32 (abfd
, src
->l_impoff
, dst
->l_impoff
);
2640 bfd_put_32 (abfd
, src
->l_stlen
, dst
->l_stlen
);
2641 bfd_put_32 (abfd
, src
->l_stoff
, dst
->l_stoff
);
2644 /* Swap in the ldsym structure. */
2647 xcoff_swap_ldsym_in (bfd
*abfd
, const void * s
, struct internal_ldsym
*dst
)
2649 const struct external_ldsym
*src
= (const struct external_ldsym
*) s
;
2651 if (bfd_get_32 (abfd
, src
->_l
._l_l
._l_zeroes
) != 0) {
2652 memcpy (dst
->_l
._l_name
, src
->_l
._l_name
, SYMNMLEN
);
2654 dst
->_l
._l_l
._l_zeroes
= 0;
2655 dst
->_l
._l_l
._l_offset
= bfd_get_32 (abfd
, src
->_l
._l_l
._l_offset
);
2657 dst
->l_value
= bfd_get_32 (abfd
, src
->l_value
);
2658 dst
->l_scnum
= bfd_get_16 (abfd
, src
->l_scnum
);
2659 dst
->l_smtype
= bfd_get_8 (abfd
, src
->l_smtype
);
2660 dst
->l_smclas
= bfd_get_8 (abfd
, src
->l_smclas
);
2661 dst
->l_ifile
= bfd_get_32 (abfd
, src
->l_ifile
);
2662 dst
->l_parm
= bfd_get_32 (abfd
, src
->l_parm
);
2665 /* Swap out the ldsym structure. */
2668 xcoff_swap_ldsym_out (bfd
*abfd
, const struct internal_ldsym
*src
, void * d
)
2670 struct external_ldsym
*dst
= (struct external_ldsym
*) d
;
2672 if (src
->_l
._l_l
._l_zeroes
!= 0)
2673 memcpy (dst
->_l
._l_name
, src
->_l
._l_name
, SYMNMLEN
);
2676 bfd_put_32 (abfd
, (bfd_vma
) 0, dst
->_l
._l_l
._l_zeroes
);
2677 bfd_put_32 (abfd
, (bfd_vma
) src
->_l
._l_l
._l_offset
,
2678 dst
->_l
._l_l
._l_offset
);
2680 bfd_put_32 (abfd
, src
->l_value
, dst
->l_value
);
2681 bfd_put_16 (abfd
, (bfd_vma
) src
->l_scnum
, dst
->l_scnum
);
2682 bfd_put_8 (abfd
, src
->l_smtype
, dst
->l_smtype
);
2683 bfd_put_8 (abfd
, src
->l_smclas
, dst
->l_smclas
);
2684 bfd_put_32 (abfd
, src
->l_ifile
, dst
->l_ifile
);
2685 bfd_put_32 (abfd
, src
->l_parm
, dst
->l_parm
);
2689 xcoff_swap_reloc_in (bfd
*abfd
, void * s
, void * d
)
2691 struct external_reloc
*src
= (struct external_reloc
*) s
;
2692 struct internal_reloc
*dst
= (struct internal_reloc
*) d
;
2694 memset (dst
, 0, sizeof (struct internal_reloc
));
2696 dst
->r_vaddr
= bfd_get_32 (abfd
, src
->r_vaddr
);
2697 dst
->r_symndx
= bfd_get_32 (abfd
, src
->r_symndx
);
2698 dst
->r_size
= bfd_get_8 (abfd
, src
->r_size
);
2699 dst
->r_type
= bfd_get_8 (abfd
, src
->r_type
);
2703 xcoff_swap_reloc_out (bfd
*abfd
, void * s
, void * d
)
2705 struct internal_reloc
*src
= (struct internal_reloc
*) s
;
2706 struct external_reloc
*dst
= (struct external_reloc
*) d
;
2708 bfd_put_32 (abfd
, src
->r_vaddr
, dst
->r_vaddr
);
2709 bfd_put_32 (abfd
, src
->r_symndx
, dst
->r_symndx
);
2710 bfd_put_8 (abfd
, src
->r_type
, dst
->r_type
);
2711 bfd_put_8 (abfd
, src
->r_size
, dst
->r_size
);
2713 return bfd_coff_relsz (abfd
);
2716 /* Swap in the ldrel structure. */
2719 xcoff_swap_ldrel_in (bfd
*abfd
, const void * s
, struct internal_ldrel
*dst
)
2721 const struct external_ldrel
*src
= (const struct external_ldrel
*) s
;
2723 dst
->l_vaddr
= bfd_get_32 (abfd
, src
->l_vaddr
);
2724 dst
->l_symndx
= bfd_get_32 (abfd
, src
->l_symndx
);
2725 dst
->l_rtype
= bfd_get_16 (abfd
, src
->l_rtype
);
2726 dst
->l_rsecnm
= bfd_get_16 (abfd
, src
->l_rsecnm
);
2729 /* Swap out the ldrel structure. */
2732 xcoff_swap_ldrel_out (bfd
*abfd
, const struct internal_ldrel
*src
, void * d
)
2734 struct external_ldrel
*dst
= (struct external_ldrel
*) d
;
2736 bfd_put_32 (abfd
, src
->l_vaddr
, dst
->l_vaddr
);
2737 bfd_put_32 (abfd
, src
->l_symndx
, dst
->l_symndx
);
2738 bfd_put_16 (abfd
, (bfd_vma
) src
->l_rtype
, dst
->l_rtype
);
2739 bfd_put_16 (abfd
, (bfd_vma
) src
->l_rsecnm
, dst
->l_rsecnm
);
2744 xcoff_reloc_type_noop (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2745 asection
*input_section ATTRIBUTE_UNUSED
,
2746 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2747 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
2748 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2749 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
,
2750 bfd_vma val ATTRIBUTE_UNUSED
,
2751 bfd_vma addend ATTRIBUTE_UNUSED
,
2752 bfd_vma
*relocation ATTRIBUTE_UNUSED
,
2753 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2759 xcoff_reloc_type_fail (bfd
*input_bfd
,
2760 asection
*input_section ATTRIBUTE_UNUSED
,
2761 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2762 struct internal_reloc
*rel
,
2763 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2764 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
,
2765 bfd_vma val ATTRIBUTE_UNUSED
,
2766 bfd_vma addend ATTRIBUTE_UNUSED
,
2767 bfd_vma
*relocation ATTRIBUTE_UNUSED
,
2768 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2771 /* xgettext: c-format */
2772 (_("%pB: unsupported relocation type %#x"),
2773 input_bfd
, (unsigned int) rel
->r_type
);
2774 bfd_set_error (bfd_error_bad_value
);
2779 xcoff_reloc_type_pos (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2780 asection
*input_section ATTRIBUTE_UNUSED
,
2781 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2782 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
2783 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2784 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
,
2787 bfd_vma
*relocation
,
2788 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2790 *relocation
= val
+ addend
;
2795 xcoff_reloc_type_neg (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2796 asection
*input_section ATTRIBUTE_UNUSED
,
2797 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2798 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
2799 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2800 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
,
2803 bfd_vma
*relocation
,
2804 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2806 *relocation
= addend
- val
;
2811 xcoff_reloc_type_rel (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2812 asection
*input_section
,
2813 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2814 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
2815 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2816 struct reloc_howto_struct
*howto
,
2819 bfd_vma
*relocation
,
2820 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2822 howto
->pc_relative
= TRUE
;
2824 /* A PC relative reloc includes the section address. */
2825 addend
+= input_section
->vma
;
2827 *relocation
= val
+ addend
;
2828 *relocation
-= (input_section
->output_section
->vma
2829 + input_section
->output_offset
);
2834 xcoff_reloc_type_toc (bfd
*input_bfd
,
2835 asection
*input_section ATTRIBUTE_UNUSED
,
2837 struct internal_reloc
*rel
,
2838 struct internal_syment
*sym
,
2839 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
,
2841 bfd_vma addend ATTRIBUTE_UNUSED
,
2842 bfd_vma
*relocation
,
2843 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2845 struct xcoff_link_hash_entry
*h
;
2847 if (0 > rel
->r_symndx
)
2850 h
= obj_xcoff_sym_hashes (input_bfd
)[rel
->r_symndx
];
2852 if (h
!= NULL
&& h
->smclas
!= XMC_TD
)
2854 if (h
->toc_section
== NULL
)
2857 /* xgettext: c-format */
2858 (_("%pB: TOC reloc at %#" PRIx64
" to symbol `%s' with no TOC entry"),
2859 input_bfd
, (uint64_t) rel
->r_vaddr
, h
->root
.root
.string
);
2860 bfd_set_error (bfd_error_bad_value
);
2864 BFD_ASSERT ((h
->flags
& XCOFF_SET_TOC
) == 0);
2865 val
= (h
->toc_section
->output_section
->vma
2866 + h
->toc_section
->output_offset
);
2869 *relocation
= ((val
- xcoff_data (output_bfd
)->toc
)
2870 - (sym
->n_value
- xcoff_data (input_bfd
)->toc
));
2875 xcoff_reloc_type_ba (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2876 asection
*input_section ATTRIBUTE_UNUSED
,
2877 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2878 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
2879 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2880 struct reloc_howto_struct
*howto
,
2883 bfd_vma
*relocation
,
2884 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2886 howto
->src_mask
&= ~3;
2887 howto
->dst_mask
= howto
->src_mask
;
2889 *relocation
= val
+ addend
;
2895 xcoff_reloc_type_br (bfd
*input_bfd
,
2896 asection
*input_section
,
2897 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2898 struct internal_reloc
*rel
,
2899 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2900 struct reloc_howto_struct
*howto
,
2903 bfd_vma
*relocation
,
2906 struct xcoff_link_hash_entry
*h
;
2907 bfd_vma section_offset
;
2909 if (0 > rel
->r_symndx
)
2912 h
= obj_xcoff_sym_hashes (input_bfd
)[rel
->r_symndx
];
2913 section_offset
= rel
->r_vaddr
- input_section
->vma
;
2915 /* If we see an R_BR or R_RBR reloc which is jumping to global
2916 linkage code, and it is followed by an appropriate cror nop
2917 instruction, we replace the cror with lwz r2,20(r1). This
2918 restores the TOC after the glink code. Contrariwise, if the
2919 call is followed by a lwz r2,20(r1), but the call is not
2920 going to global linkage code, we can replace the load with a
2923 && (bfd_link_hash_defined
== h
->root
.type
2924 || bfd_link_hash_defweak
== h
->root
.type
)
2925 && section_offset
+ 8 <= input_section
->size
)
2930 pnext
= contents
+ section_offset
+ 4;
2931 next
= bfd_get_32 (input_bfd
, pnext
);
2933 /* The _ptrgl function is magic. It is used by the AIX
2934 compiler to call a function through a pointer. */
2935 if (h
->smclas
== XMC_GL
|| strcmp (h
->root
.root
.string
, "._ptrgl") == 0)
2937 if (next
== 0x4def7b82 /* cror 15,15,15 */
2938 || next
== 0x4ffffb82 /* cror 31,31,31 */
2939 || next
== 0x60000000) /* ori r0,r0,0 */
2940 bfd_put_32 (input_bfd
, 0x80410014, pnext
); /* lwz r2,20(r1) */
2945 if (next
== 0x80410014) /* lwz r2,20(r1) */
2946 bfd_put_32 (input_bfd
, 0x60000000, pnext
); /* ori r0,r0,0 */
2949 else if (NULL
!= h
&& bfd_link_hash_undefined
== h
->root
.type
)
2951 /* Normally, this relocation is against a defined symbol. In the
2952 case where this is a partial link and the output section offset
2953 is greater than 2^25, the linker will return an invalid error
2954 message that the relocation has been truncated. Yes it has been
2955 truncated but no it not important. For this case, disable the
2956 overflow checking. */
2958 howto
->complain_on_overflow
= complain_overflow_dont
;
2961 /* The original PC-relative relocation is biased by -r_vaddr, so adding
2962 the value below will give the absolute target address. */
2963 *relocation
= val
+ addend
+ rel
->r_vaddr
;
2965 howto
->src_mask
&= ~3;
2966 howto
->dst_mask
= howto
->src_mask
;
2969 && (h
->root
.type
== bfd_link_hash_defined
2970 || h
->root
.type
== bfd_link_hash_defweak
)
2971 && bfd_is_abs_section (h
->root
.u
.def
.section
)
2972 && section_offset
+ 4 <= input_section
->size
)
2977 /* Turn the relative branch into an absolute one by setting the
2979 ptr
= contents
+ section_offset
;
2980 insn
= bfd_get_32 (input_bfd
, ptr
);
2982 bfd_put_32 (input_bfd
, insn
, ptr
);
2984 /* Make the howto absolute too. */
2985 howto
->pc_relative
= FALSE
;
2986 howto
->complain_on_overflow
= complain_overflow_bitfield
;
2990 /* Use a PC-relative howto and subtract the instruction's address
2991 from the target address we calculated above. */
2992 howto
->pc_relative
= TRUE
;
2993 *relocation
-= (input_section
->output_section
->vma
2994 + input_section
->output_offset
3001 xcoff_reloc_type_crel (bfd
*input_bfd ATTRIBUTE_UNUSED
,
3002 asection
*input_section
,
3003 bfd
*output_bfd ATTRIBUTE_UNUSED
,
3004 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
3005 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
3006 struct reloc_howto_struct
*howto
,
3007 bfd_vma val ATTRIBUTE_UNUSED
,
3009 bfd_vma
*relocation
,
3010 bfd_byte
*contents ATTRIBUTE_UNUSED
)
3012 howto
->pc_relative
= TRUE
;
3013 howto
->src_mask
&= ~3;
3014 howto
->dst_mask
= howto
->src_mask
;
3016 /* A PC relative reloc includes the section address. */
3017 addend
+= input_section
->vma
;
3019 *relocation
= val
+ addend
;
3020 *relocation
-= (input_section
->output_section
->vma
3021 + input_section
->output_offset
);
3026 xcoff_complain_overflow_dont_func (bfd
*input_bfd ATTRIBUTE_UNUSED
,
3027 bfd_vma val ATTRIBUTE_UNUSED
,
3028 bfd_vma relocation ATTRIBUTE_UNUSED
,
3029 struct reloc_howto_struct
*
3030 howto ATTRIBUTE_UNUSED
)
3036 xcoff_complain_overflow_bitfield_func (bfd
*input_bfd
,
3039 struct reloc_howto_struct
*howto
)
3041 bfd_vma fieldmask
, signmask
, ss
;
3044 /* Get the values to be added together. For signed and unsigned
3045 relocations, we assume that all values should be truncated to
3046 the size of an address. For bitfields, all the bits matter.
3047 See also bfd_check_overflow. */
3048 fieldmask
= N_ONES (howto
->bitsize
);
3050 b
= val
& howto
->src_mask
;
3052 /* Much like unsigned, except no trimming with addrmask. In
3053 addition, the sum overflows if there is a carry out of
3054 the bfd_vma, i.e., the sum is less than either input
3056 a
>>= howto
->rightshift
;
3057 b
>>= howto
->bitpos
;
3059 /* Bitfields are sometimes used for signed numbers; for
3060 example, a 13-bit field sometimes represents values in
3061 0..8191 and sometimes represents values in -4096..4095.
3062 If the field is signed and a is -4095 (0x1001) and b is
3063 -1 (0x1fff), the sum is -4096 (0x1000), but (0x1001 +
3064 0x1fff is 0x3000). It's not clear how to handle this
3065 everywhere, since there is not way to know how many bits
3066 are significant in the relocation, but the original code
3067 assumed that it was fully sign extended, and we will keep
3069 signmask
= (fieldmask
>> 1) + 1;
3071 if ((a
& ~ fieldmask
) != 0)
3073 /* Some bits out of the field are set. This might not
3074 be a problem: if this is a signed bitfield, it is OK
3075 iff all the high bits are set, including the sign
3076 bit. We'll try setting all but the most significant
3077 bit in the original relocation value: if this is all
3078 ones, we are OK, assuming a signed bitfield. */
3079 ss
= (signmask
<< howto
->rightshift
) - 1;
3080 if ((ss
| relocation
) != ~ (bfd_vma
) 0)
3085 /* We just assume (b & ~ fieldmask) == 0. */
3087 /* We explicitly permit wrap around if this relocation
3088 covers the high bit of an address. The Linux kernel
3089 relies on it, and it is the only way to write assembler
3090 code which can run when loaded at a location 0x80000000
3091 away from the location at which it is linked. */
3092 if ((unsigned) howto
->bitsize
+ howto
->rightshift
3093 == bfd_arch_bits_per_address (input_bfd
))
3097 if (sum
< a
|| (sum
& ~ fieldmask
) != 0)
3099 /* There was a carry out, or the field overflow. Test
3100 for signed operands again. Here is the overflow test
3101 is as for complain_overflow_signed. */
3102 if (((~ (a
^ b
)) & (a
^ sum
)) & signmask
)
3110 xcoff_complain_overflow_signed_func (bfd
*input_bfd
,
3113 struct reloc_howto_struct
*howto
)
3115 bfd_vma addrmask
, fieldmask
, signmask
, ss
;
3118 /* Get the values to be added together. For signed and unsigned
3119 relocations, we assume that all values should be truncated to
3120 the size of an address. For bitfields, all the bits matter.
3121 See also bfd_check_overflow. */
3122 fieldmask
= N_ONES (howto
->bitsize
);
3123 addrmask
= N_ONES (bfd_arch_bits_per_address (input_bfd
)) | fieldmask
;
3125 b
= val
& howto
->src_mask
;
3127 a
= (a
& addrmask
) >> howto
->rightshift
;
3129 /* If any sign bits are set, all sign bits must be set.
3130 That is, A must be a valid negative address after
3132 signmask
= ~ (fieldmask
>> 1);
3134 if (ss
!= 0 && ss
!= ((addrmask
>> howto
->rightshift
) & signmask
))
3137 /* We only need this next bit of code if the sign bit of B
3138 is below the sign bit of A. This would only happen if
3139 SRC_MASK had fewer bits than BITSIZE. Note that if
3140 SRC_MASK has more bits than BITSIZE, we can get into
3141 trouble; we would need to verify that B is in range, as
3142 we do for A above. */
3143 signmask
= ((~ howto
->src_mask
) >> 1) & howto
->src_mask
;
3144 if ((b
& signmask
) != 0)
3146 /* Set all the bits above the sign bit. */
3147 b
-= signmask
<<= 1;
3150 b
= (b
& addrmask
) >> howto
->bitpos
;
3152 /* Now we can do the addition. */
3155 /* See if the result has the correct sign. Bits above the
3156 sign bit are junk now; ignore them. If the sum is
3157 positive, make sure we did not have all negative inputs;
3158 if the sum is negative, make sure we did not have all
3159 positive inputs. The test below looks only at the sign
3160 bits, and it really just
3161 SIGN (A) == SIGN (B) && SIGN (A) != SIGN (SUM)
3163 signmask
= (fieldmask
>> 1) + 1;
3164 if (((~ (a
^ b
)) & (a
^ sum
)) & signmask
)
3171 xcoff_complain_overflow_unsigned_func (bfd
*input_bfd
,
3174 struct reloc_howto_struct
*howto
)
3176 bfd_vma addrmask
, fieldmask
;
3179 /* Get the values to be added together. For signed and unsigned
3180 relocations, we assume that all values should be truncated to
3181 the size of an address. For bitfields, all the bits matter.
3182 See also bfd_check_overflow. */
3183 fieldmask
= N_ONES (howto
->bitsize
);
3184 addrmask
= N_ONES (bfd_arch_bits_per_address (input_bfd
)) | fieldmask
;
3186 b
= val
& howto
->src_mask
;
3188 /* Checking for an unsigned overflow is relatively easy:
3189 trim the addresses and add, and trim the result as well.
3190 Overflow is normally indicated when the result does not
3191 fit in the field. However, we also need to consider the
3192 case when, e.g., fieldmask is 0x7fffffff or smaller, an
3193 input is 0x80000000, and bfd_vma is only 32 bits; then we
3194 will get sum == 0, but there is an overflow, since the
3195 inputs did not fit in the field. Instead of doing a
3196 separate test, we can check for this by or-ing in the
3197 operands when testing for the sum overflowing its final
3199 a
= (a
& addrmask
) >> howto
->rightshift
;
3200 b
= (b
& addrmask
) >> howto
->bitpos
;
3201 sum
= (a
+ b
) & addrmask
;
3202 if ((a
| b
| sum
) & ~ fieldmask
)
3208 /* This is the relocation function for the RS/6000/POWER/PowerPC.
3209 This is currently the only processor which uses XCOFF; I hope that
3212 I took the relocation type definitions from two documents:
3213 the PowerPC AIX Version 4 Application Binary Interface, First
3214 Edition (April 1992), and the PowerOpen ABI, Big-Endian
3215 32-Bit Hardware Implementation (June 30, 1994). Differences
3216 between the documents are noted below.
3218 Unsupported r_type's
3224 These relocs are defined by the PowerPC ABI to be
3225 relative branches which use half of the difference
3226 between the symbol and the program counter. I can't
3227 quite figure out when this is useful. These relocs are
3228 not defined by the PowerOpen ABI.
3233 Simple positive relocation.
3236 Simple negative relocation.
3239 Simple PC relative relocation.
3242 TOC relative relocation. The value in the instruction in
3243 the input file is the offset from the input file TOC to
3244 the desired location. We want the offset from the final
3245 TOC to the desired location. We have:
3250 so we must change insn by on - in.
3253 GL linkage relocation. The value of this relocation
3254 is the address of the entry in the TOC section.
3257 Local object TOC address. I can't figure out the
3258 difference between this and case R_GL.
3261 TOC relative relocation. A TOC relative load instruction
3262 which may be changed to a load address instruction.
3263 FIXME: We don't currently implement this optimization.
3266 TOC relative relocation. This is a TOC relative load
3267 address instruction which may be changed to a load
3268 instruction. FIXME: I don't know if this is the correct
3272 Absolute branch. We don't want to mess with the lower
3273 two bits of the instruction.
3276 The PowerPC ABI defines this as an absolute call which
3277 may be modified to become a relative call. The PowerOpen
3278 ABI does not define this relocation type.
3281 Absolute branch which may be modified to become a
3285 The PowerPC ABI defines this as an absolute branch to a
3286 fixed address which may be modified to an absolute branch
3287 to a symbol. The PowerOpen ABI does not define this
3291 The PowerPC ABI defines this as an absolute branch to a
3292 fixed address which may be modified to a relative branch.
3293 The PowerOpen ABI does not define this relocation type.
3296 Relative branch. We don't want to mess with the lower
3297 two bits of the instruction.
3300 The PowerPC ABI defines this as a relative call which may
3301 be modified to become an absolute call. The PowerOpen
3302 ABI does not define this relocation type.
3305 A relative branch which may be modified to become an
3309 The PowerPC AIX ABI describes this as a load which may be
3310 changed to a load address. The PowerOpen ABI says this
3311 is the same as case R_POS.
3314 The PowerPC AIX ABI describes this as a load address
3315 which may be changed to a load. The PowerOpen ABI says
3316 this is the same as R_POS.
3320 xcoff_ppc_relocate_section (bfd
*output_bfd
,
3321 struct bfd_link_info
*info
,
3323 asection
*input_section
,
3325 struct internal_reloc
*relocs
,
3326 struct internal_syment
*syms
,
3327 asection
**sections
)
3329 struct internal_reloc
*rel
;
3330 struct internal_reloc
*relend
;
3333 relend
= rel
+ input_section
->reloc_count
;
3334 for (; rel
< relend
; rel
++)
3337 struct xcoff_link_hash_entry
*h
;
3338 struct internal_syment
*sym
;
3341 struct reloc_howto_struct howto
;
3343 bfd_vma value_to_relocate
;
3347 /* Relocation type R_REF is a special relocation type which is
3348 merely used to prevent garbage collection from occurring for
3349 the csect including the symbol which it references. */
3350 if (rel
->r_type
== R_REF
)
3354 howto
.type
= rel
->r_type
;
3355 howto
.rightshift
= 0;
3356 howto
.bitsize
= (rel
->r_size
& 0x1f) + 1;
3357 howto
.size
= howto
.bitsize
> 16 ? 2 : 1;
3358 howto
.pc_relative
= FALSE
;
3360 howto
.complain_on_overflow
= (rel
->r_size
& 0x80
3361 ? complain_overflow_signed
3362 : complain_overflow_bitfield
);
3363 howto
.special_function
= NULL
;
3364 howto
.name
= "internal";
3365 howto
.partial_inplace
= TRUE
;
3366 howto
.src_mask
= howto
.dst_mask
= N_ONES (howto
.bitsize
);
3367 howto
.pcrel_offset
= FALSE
;
3374 symndx
= rel
->r_symndx
;
3380 h
= obj_xcoff_sym_hashes (input_bfd
)[symndx
];
3381 sym
= syms
+ symndx
;
3382 addend
= - sym
->n_value
;
3386 sec
= sections
[symndx
];
3387 /* Hack to make sure we use the right TOC anchor value
3388 if this reloc is against the TOC anchor. */
3389 if (sec
->name
[3] == '0'
3390 && strcmp (sec
->name
, ".tc0") == 0)
3391 val
= xcoff_data (output_bfd
)->toc
;
3393 val
= (sec
->output_section
->vma
3394 + sec
->output_offset
3400 if (info
->unresolved_syms_in_objects
!= RM_IGNORE
3401 && (h
->flags
& XCOFF_WAS_UNDEFINED
) != 0)
3402 (*info
->callbacks
->undefined_symbol
)
3403 (info
, h
->root
.root
.string
,
3404 input_bfd
, input_section
,
3405 rel
->r_vaddr
- input_section
->vma
,
3406 info
->unresolved_syms_in_objects
== RM_GENERATE_ERROR
);
3408 if (h
->root
.type
== bfd_link_hash_defined
3409 || h
->root
.type
== bfd_link_hash_defweak
)
3411 sec
= h
->root
.u
.def
.section
;
3412 val
= (h
->root
.u
.def
.value
3413 + sec
->output_section
->vma
3414 + sec
->output_offset
);
3416 else if (h
->root
.type
== bfd_link_hash_common
)
3418 sec
= h
->root
.u
.c
.p
->section
;
3419 val
= (sec
->output_section
->vma
3420 + sec
->output_offset
);
3425 BFD_ASSERT (bfd_link_relocatable (info
)
3426 || (info
->static_link
3427 && (h
->flags
& XCOFF_WAS_UNDEFINED
) != 0)
3428 || (h
->flags
& XCOFF_DEF_DYNAMIC
) != 0
3429 || (h
->flags
& XCOFF_IMPORT
) != 0);
3434 if (rel
->r_type
>= XCOFF_MAX_CALCULATE_RELOCATION
3435 || !((*xcoff_calculate_relocation
[rel
->r_type
])
3436 (input_bfd
, input_section
, output_bfd
, rel
, sym
, &howto
, val
,
3437 addend
, &relocation
, contents
)))
3441 address
= rel
->r_vaddr
- input_section
->vma
;
3442 location
= contents
+ address
;
3444 if (address
> input_section
->size
)
3447 /* Get the value we are going to relocate. */
3448 if (1 == howto
.size
)
3449 value_to_relocate
= bfd_get_16 (input_bfd
, location
);
3451 value_to_relocate
= bfd_get_32 (input_bfd
, location
);
3455 FIXME: We may drop bits during the addition
3456 which we don't check for. We must either check at every single
3457 operation, which would be tedious, or we must do the computations
3458 in a type larger than bfd_vma, which would be inefficient. */
3460 if (((*xcoff_complain_overflow
[howto
.complain_on_overflow
])
3461 (input_bfd
, value_to_relocate
, relocation
, &howto
)))
3464 char buf
[SYMNMLEN
+ 1];
3465 char reloc_type_name
[10];
3477 name
= _bfd_coff_internal_syment_name (input_bfd
, sym
, buf
);
3481 sprintf (reloc_type_name
, "0x%02x", rel
->r_type
);
3483 (*info
->callbacks
->reloc_overflow
)
3484 (info
, (h
? &h
->root
: NULL
), name
, reloc_type_name
,
3485 (bfd_vma
) 0, input_bfd
, input_section
,
3486 rel
->r_vaddr
- input_section
->vma
);
3489 /* Add RELOCATION to the right bits of VALUE_TO_RELOCATE. */
3490 value_to_relocate
= ((value_to_relocate
& ~howto
.dst_mask
)
3491 | (((value_to_relocate
& howto
.src_mask
)
3492 + relocation
) & howto
.dst_mask
));
3494 /* Put the value back in the object file. */
3495 if (1 == howto
.size
)
3496 bfd_put_16 (input_bfd
, value_to_relocate
, location
);
3498 bfd_put_32 (input_bfd
, value_to_relocate
, location
);
3504 /* gcc-8 warns (*) on all the strncpy calls in this function about
3505 possible string truncation. The "truncation" is not a bug. We
3506 have an external representation of structs with fields that are not
3507 necessarily NULL terminated and corresponding internal
3508 representation fields that are one larger so that they can always
3510 gcc versions between 4.2 and 4.6 do not allow pragma control of
3511 diagnostics inside functions, giving a hard error if you try to use
3512 the finer control available with later versions.
3513 gcc prior to 4.2 warns about diagnostic push and pop.
3514 gcc-5, gcc-6 and gcc-7 warn that -Wstringop-truncation is unknown,
3515 unless you also add #pragma GCC diagnostic ignored "-Wpragma".
3516 (*) Depending on your system header files! */
3517 #if GCC_VERSION >= 8000
3518 # pragma GCC diagnostic push
3519 # pragma GCC diagnostic ignored "-Wstringop-truncation"
3522 _bfd_xcoff_put_ldsymbol_name (bfd
*abfd ATTRIBUTE_UNUSED
,
3523 struct xcoff_loader_info
*ldinfo
,
3524 struct internal_ldsym
*ldsym
,
3528 len
= strlen (name
);
3530 if (len
<= SYMNMLEN
)
3531 strncpy (ldsym
->_l
._l_name
, name
, SYMNMLEN
);
3534 if (ldinfo
->string_size
+ len
+ 3 > ldinfo
->string_alc
)
3536 bfd_size_type newalc
;
3539 newalc
= ldinfo
->string_alc
* 2;
3542 while (ldinfo
->string_size
+ len
+ 3 > newalc
)
3545 newstrings
= bfd_realloc (ldinfo
->strings
, newalc
);
3546 if (newstrings
== NULL
)
3548 ldinfo
->failed
= TRUE
;
3551 ldinfo
->string_alc
= newalc
;
3552 ldinfo
->strings
= newstrings
;
3555 bfd_put_16 (ldinfo
->output_bfd
, (bfd_vma
) (len
+ 1),
3556 ldinfo
->strings
+ ldinfo
->string_size
);
3557 strcpy (ldinfo
->strings
+ ldinfo
->string_size
+ 2, name
);
3558 ldsym
->_l
._l_l
._l_zeroes
= 0;
3559 ldsym
->_l
._l_l
._l_offset
= ldinfo
->string_size
+ 2;
3560 ldinfo
->string_size
+= len
+ 3;
3567 _bfd_xcoff_put_symbol_name (struct bfd_link_info
*info
,
3568 struct bfd_strtab_hash
*strtab
,
3569 struct internal_syment
*sym
,
3572 if (strlen (name
) <= SYMNMLEN
)
3574 strncpy (sym
->_n
._n_name
, name
, SYMNMLEN
);
3581 hash
= !info
->traditional_format
;
3582 indx
= _bfd_stringtab_add (strtab
, name
, hash
, FALSE
);
3583 if (indx
== (bfd_size_type
) -1)
3585 sym
->_n
._n_n
._n_zeroes
= 0;
3586 sym
->_n
._n_n
._n_offset
= STRING_SIZE_SIZE
+ indx
;
3590 #if GCC_VERSION >= 8000
3591 # pragma GCC diagnostic pop
3595 xcoff_create_csect_from_smclas (bfd
*abfd
,
3596 union internal_auxent
*aux
,
3597 const char *symbol_name
)
3599 asection
*return_value
= NULL
;
3601 /* .sv64 = x_smclas == 17
3602 This is an invalid csect for 32 bit apps. */
3603 static const char * const names
[] =
3605 ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo", /* 0 - 7 */
3606 ".sv", ".bs", ".ds", ".uc", ".ti", ".tb", NULL
, ".tc0", /* 8 - 15 */
3607 ".td", NULL
, ".sv3264", NULL
, ".tl", ".ul", ".te"
3610 if ((aux
->x_csect
.x_smclas
< ARRAY_SIZE (names
))
3611 && (NULL
!= names
[aux
->x_csect
.x_smclas
]))
3613 return_value
= bfd_make_section_anyway
3614 (abfd
, names
[aux
->x_csect
.x_smclas
]);
3619 /* xgettext: c-format */
3620 (_("%pB: symbol `%s' has unrecognized smclas %d"),
3621 abfd
, symbol_name
, aux
->x_csect
.x_smclas
);
3622 bfd_set_error (bfd_error_bad_value
);
3625 return return_value
;
3629 xcoff_is_lineno_count_overflow (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_vma value
)
3631 if (0xffff <= value
)
3638 xcoff_is_reloc_count_overflow (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_vma value
)
3640 if (0xffff <= value
)
3647 xcoff_loader_symbol_offset (bfd
*abfd
,
3648 struct internal_ldhdr
*ldhdr ATTRIBUTE_UNUSED
)
3650 return bfd_xcoff_ldhdrsz (abfd
);
3654 xcoff_loader_reloc_offset (bfd
*abfd
, struct internal_ldhdr
*ldhdr
)
3656 return bfd_xcoff_ldhdrsz (abfd
) + ldhdr
->l_nsyms
* bfd_xcoff_ldsymsz (abfd
);
3660 xcoff_generate_rtinit (bfd
*abfd
, const char *init
, const char *fini
,
3663 bfd_byte filehdr_ext
[FILHSZ
];
3664 bfd_byte scnhdr_ext
[SCNHSZ
];
3665 bfd_byte syment_ext
[SYMESZ
* 10];
3666 bfd_byte reloc_ext
[RELSZ
* 3];
3667 bfd_byte
*data_buffer
;
3668 bfd_size_type data_buffer_size
;
3669 bfd_byte
*string_table
= NULL
, *st_tmp
= NULL
;
3670 bfd_size_type string_table_size
;
3672 size_t initsz
, finisz
;
3673 struct internal_filehdr filehdr
;
3674 struct internal_scnhdr scnhdr
;
3675 struct internal_syment syment
;
3676 union internal_auxent auxent
;
3677 struct internal_reloc reloc
;
3679 char *data_name
= ".data";
3680 char *rtinit_name
= "__rtinit";
3681 char *rtld_name
= "__rtld";
3683 if (! bfd_xcoff_rtinit_size (abfd
))
3686 initsz
= (init
== NULL
? 0 : 1 + strlen (init
));
3687 finisz
= (fini
== NULL
? 0 : 1 + strlen (fini
));
3690 memset (filehdr_ext
, 0, FILHSZ
);
3691 memset (&filehdr
, 0, sizeof (struct internal_filehdr
));
3692 filehdr
.f_magic
= bfd_xcoff_magic_number (abfd
);
3693 filehdr
.f_nscns
= 1;
3694 filehdr
.f_timdat
= 0;
3695 filehdr
.f_nsyms
= 0; /* at least 6, no more than 10 */
3696 filehdr
.f_symptr
= 0; /* set below */
3697 filehdr
.f_opthdr
= 0;
3698 filehdr
.f_flags
= 0;
3700 /* section header */
3701 memset (scnhdr_ext
, 0, SCNHSZ
);
3702 memset (&scnhdr
, 0, sizeof (struct internal_scnhdr
));
3703 memcpy (scnhdr
.s_name
, data_name
, strlen (data_name
));
3706 scnhdr
.s_size
= 0; /* set below */
3707 scnhdr
.s_scnptr
= FILHSZ
+ SCNHSZ
;
3708 scnhdr
.s_relptr
= 0; /* set below */
3709 scnhdr
.s_lnnoptr
= 0;
3710 scnhdr
.s_nreloc
= 0; /* either 1 or 2 */
3712 scnhdr
.s_flags
= STYP_DATA
;
3715 0x0000 0x00000000 : rtl
3716 0x0004 0x00000010 : offset to init, or 0
3717 0x0008 0x00000028 : offset to fini, or 0
3718 0x000C 0x0000000C : size of descriptor
3719 0x0010 0x00000000 : init, needs a reloc
3720 0x0014 0x00000040 : offset to init name
3721 0x0018 0x00000000 : flags, padded to a word
3722 0x001C 0x00000000 : empty init
3725 0x0028 0x00000000 : fini, needs a reloc
3726 0x002C 0x00000??? : offset to fini name
3727 0x0030 0x00000000 : flags, padded to a word
3728 0x0034 0x00000000 : empty fini
3732 0x0040 + initsz fini name */
3734 data_buffer_size
= 0x0040 + initsz
+ finisz
;
3735 data_buffer_size
= (data_buffer_size
+ 7) &~ (bfd_size_type
) 7;
3737 data_buffer
= (bfd_byte
*) bfd_zmalloc (data_buffer_size
);
3738 if (data_buffer
== NULL
)
3744 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x04]);
3746 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x14]);
3747 memcpy (&data_buffer
[val
], init
, initsz
);
3753 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x08]);
3754 val
= 0x40 + initsz
;
3755 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x2C]);
3756 memcpy (&data_buffer
[val
], fini
, finisz
);
3760 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x0C]);
3762 scnhdr
.s_size
= data_buffer_size
;
3765 string_table_size
= 0;
3767 string_table_size
+= initsz
;
3769 string_table_size
+= finisz
;
3770 if (string_table_size
)
3772 string_table_size
+= 4;
3773 string_table
= (bfd_byte
*) bfd_zmalloc (string_table_size
);
3774 if (string_table
== NULL
)
3777 val
= string_table_size
;
3778 bfd_h_put_32 (abfd
, val
, &string_table
[0]);
3779 st_tmp
= string_table
+ 4;
3788 memset (syment_ext
, 0, 10 * SYMESZ
);
3789 memset (reloc_ext
, 0, 3 * RELSZ
);
3792 memset (&syment
, 0, sizeof (struct internal_syment
));
3793 memset (&auxent
, 0, sizeof (union internal_auxent
));
3794 memcpy (syment
._n
._n_name
, data_name
, strlen (data_name
));
3796 syment
.n_sclass
= C_HIDEXT
;
3797 syment
.n_numaux
= 1;
3798 auxent
.x_csect
.x_scnlen
.l
= data_buffer_size
;
3799 auxent
.x_csect
.x_smtyp
= 3 << 3 | XTY_SD
;
3800 auxent
.x_csect
.x_smclas
= XMC_RW
;
3801 bfd_coff_swap_sym_out (abfd
, &syment
,
3802 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3803 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3805 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3806 filehdr
.f_nsyms
+= 2;
3809 memset (&syment
, 0, sizeof (struct internal_syment
));
3810 memset (&auxent
, 0, sizeof (union internal_auxent
));
3811 memcpy (syment
._n
._n_name
, rtinit_name
, strlen (rtinit_name
));
3813 syment
.n_sclass
= C_EXT
;
3814 syment
.n_numaux
= 1;
3815 auxent
.x_csect
.x_smtyp
= XTY_LD
;
3816 auxent
.x_csect
.x_smclas
= XMC_RW
;
3817 bfd_coff_swap_sym_out (abfd
, &syment
,
3818 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3819 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3821 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3822 filehdr
.f_nsyms
+= 2;
3827 memset (&syment
, 0, sizeof (struct internal_syment
));
3828 memset (&auxent
, 0, sizeof (union internal_auxent
));
3832 syment
._n
._n_n
._n_offset
= st_tmp
- string_table
;
3833 memcpy (st_tmp
, init
, initsz
);
3837 memcpy (syment
._n
._n_name
, init
, initsz
- 1);
3839 syment
.n_sclass
= C_EXT
;
3840 syment
.n_numaux
= 1;
3841 bfd_coff_swap_sym_out (abfd
, &syment
,
3842 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3843 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3845 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3848 memset (&reloc
, 0, sizeof (struct internal_reloc
));
3849 reloc
.r_vaddr
= 0x0010;
3850 reloc
.r_symndx
= filehdr
.f_nsyms
;
3851 reloc
.r_type
= R_POS
;
3853 bfd_coff_swap_reloc_out (abfd
, &reloc
, &reloc_ext
[0]);
3855 filehdr
.f_nsyms
+= 2;
3856 scnhdr
.s_nreloc
+= 1;
3862 memset (&syment
, 0, sizeof (struct internal_syment
));
3863 memset (&auxent
, 0, sizeof (union internal_auxent
));
3867 syment
._n
._n_n
._n_offset
= st_tmp
- string_table
;
3868 memcpy (st_tmp
, fini
, finisz
);
3872 memcpy (syment
._n
._n_name
, fini
, finisz
- 1);
3874 syment
.n_sclass
= C_EXT
;
3875 syment
.n_numaux
= 1;
3876 bfd_coff_swap_sym_out (abfd
, &syment
,
3877 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3878 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3880 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3883 memset (&reloc
, 0, sizeof (struct internal_reloc
));
3884 reloc
.r_vaddr
= 0x0028;
3885 reloc
.r_symndx
= filehdr
.f_nsyms
;
3886 reloc
.r_type
= R_POS
;
3888 bfd_coff_swap_reloc_out (abfd
, &reloc
,
3889 &reloc_ext
[scnhdr
.s_nreloc
* RELSZ
]);
3891 filehdr
.f_nsyms
+= 2;
3892 scnhdr
.s_nreloc
+= 1;
3897 memset (&syment
, 0, sizeof (struct internal_syment
));
3898 memset (&auxent
, 0, sizeof (union internal_auxent
));
3899 memcpy (syment
._n
._n_name
, rtld_name
, strlen (rtld_name
));
3900 syment
.n_sclass
= C_EXT
;
3901 syment
.n_numaux
= 1;
3902 bfd_coff_swap_sym_out (abfd
, &syment
,
3903 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3904 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3906 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3909 memset (&reloc
, 0, sizeof (struct internal_reloc
));
3910 reloc
.r_vaddr
= 0x0000;
3911 reloc
.r_symndx
= filehdr
.f_nsyms
;
3912 reloc
.r_type
= R_POS
;
3914 bfd_coff_swap_reloc_out (abfd
, &reloc
,
3915 &reloc_ext
[scnhdr
.s_nreloc
* RELSZ
]);
3917 filehdr
.f_nsyms
+= 2;
3918 scnhdr
.s_nreloc
+= 1;
3921 scnhdr
.s_relptr
= scnhdr
.s_scnptr
+ data_buffer_size
;
3922 filehdr
.f_symptr
= scnhdr
.s_relptr
+ scnhdr
.s_nreloc
* RELSZ
;
3924 bfd_coff_swap_filehdr_out (abfd
, &filehdr
, filehdr_ext
);
3925 bfd_bwrite (filehdr_ext
, FILHSZ
, abfd
);
3926 bfd_coff_swap_scnhdr_out (abfd
, &scnhdr
, scnhdr_ext
);
3927 bfd_bwrite (scnhdr_ext
, SCNHSZ
, abfd
);
3928 bfd_bwrite (data_buffer
, data_buffer_size
, abfd
);
3929 bfd_bwrite (reloc_ext
, scnhdr
.s_nreloc
* RELSZ
, abfd
);
3930 bfd_bwrite (syment_ext
, filehdr
.f_nsyms
* SYMESZ
, abfd
);
3931 bfd_bwrite (string_table
, string_table_size
, abfd
);
3940 static reloc_howto_type xcoff_dynamic_reloc
=
3941 HOWTO (0, /* type */
3943 2, /* size (0 = byte, 1 = short, 2 = long) */
3945 FALSE
, /* pc_relative */
3947 complain_overflow_bitfield
, /* complain_on_overflow */
3948 0, /* special_function */
3950 TRUE
, /* partial_inplace */
3951 0xffffffff, /* src_mask */
3952 0xffffffff, /* dst_mask */
3953 FALSE
); /* pcrel_offset */
3957 The first word of global linkage code must be modified by filling in
3958 the correct TOC offset. */
3960 static unsigned long xcoff_glink_code
[9] =
3962 0x81820000, /* lwz r12,0(r2) */
3963 0x90410014, /* stw r2,20(r1) */
3964 0x800c0000, /* lwz r0,0(r12) */
3965 0x804c0004, /* lwz r2,4(r12) */
3966 0x7c0903a6, /* mtctr r0 */
3967 0x4e800420, /* bctr */
3968 0x00000000, /* start of traceback table */
3969 0x000c8000, /* traceback table */
3970 0x00000000, /* traceback table */
3973 /* Table to convert DWARF flags to section names. */
3975 const struct xcoff_dwsect_name xcoff_dwsect_names
[] = {
3976 { SSUBTYP_DWINFO
, ".dwinfo", TRUE
},
3977 { SSUBTYP_DWLINE
, ".dwline", TRUE
},
3978 { SSUBTYP_DWPBNMS
, ".dwpbnms", TRUE
},
3979 { SSUBTYP_DWPBTYP
, ".dwpbtyp", TRUE
},
3980 { SSUBTYP_DWARNGE
, ".dwarnge", TRUE
},
3981 { SSUBTYP_DWABREV
, ".dwabrev", FALSE
},
3982 { SSUBTYP_DWSTR
, ".dwstr", TRUE
},
3983 { SSUBTYP_DWRNGES
, ".dwrnges", TRUE
}
3986 /* For generic entry points. */
3987 #define _bfd_xcoff_close_and_cleanup _bfd_archive_close_and_cleanup
3988 #define _bfd_xcoff_bfd_free_cached_info _bfd_bool_bfd_true
3989 #define _bfd_xcoff_new_section_hook coff_new_section_hook
3990 #define _bfd_xcoff_get_section_contents _bfd_generic_get_section_contents
3991 #define _bfd_xcoff_get_section_contents_in_window \
3992 _bfd_generic_get_section_contents_in_window
3994 /* For copy private data entry points. */
3995 #define _bfd_xcoff_bfd_copy_private_bfd_data \
3996 _bfd_xcoff_copy_private_bfd_data
3997 #define _bfd_xcoff_bfd_merge_private_bfd_data \
3998 _bfd_generic_bfd_merge_private_bfd_data
3999 #define _bfd_xcoff_bfd_copy_private_section_data \
4000 _bfd_generic_bfd_copy_private_section_data
4001 #define _bfd_xcoff_bfd_copy_private_symbol_data \
4002 _bfd_generic_bfd_copy_private_symbol_data
4003 #define _bfd_xcoff_bfd_copy_private_header_data \
4004 _bfd_generic_bfd_copy_private_header_data
4005 #define _bfd_xcoff_bfd_set_private_flags \
4006 _bfd_generic_bfd_set_private_flags
4007 #define _bfd_xcoff_bfd_print_private_bfd_data \
4008 _bfd_generic_bfd_print_private_bfd_data
4010 /* For archive entry points. */
4011 #define _bfd_xcoff_slurp_extended_name_table \
4012 _bfd_noarchive_slurp_extended_name_table
4013 #define _bfd_xcoff_construct_extended_name_table \
4014 _bfd_noarchive_construct_extended_name_table
4015 #define _bfd_xcoff_truncate_arname bfd_dont_truncate_arname
4016 #define _bfd_xcoff_write_ar_hdr _bfd_generic_write_ar_hdr
4017 #define _bfd_xcoff_get_elt_at_index _bfd_generic_get_elt_at_index
4018 #define _bfd_xcoff_generic_stat_arch_elt _bfd_xcoff_stat_arch_elt
4019 #define _bfd_xcoff_update_armap_timestamp _bfd_bool_bfd_true
4021 /* For symbols entry points. */
4022 #define _bfd_xcoff_get_symtab_upper_bound coff_get_symtab_upper_bound
4023 #define _bfd_xcoff_canonicalize_symtab coff_canonicalize_symtab
4024 #define _bfd_xcoff_make_empty_symbol coff_make_empty_symbol
4025 #define _bfd_xcoff_print_symbol coff_print_symbol
4026 #define _bfd_xcoff_get_symbol_info coff_get_symbol_info
4027 #define _bfd_xcoff_get_symbol_version_string \
4028 _bfd_nosymbols_get_symbol_version_string
4029 #define _bfd_xcoff_bfd_is_local_label_name _bfd_xcoff_is_local_label_name
4030 #define _bfd_xcoff_bfd_is_target_special_symbol \
4031 coff_bfd_is_target_special_symbol
4032 #define _bfd_xcoff_get_lineno coff_get_lineno
4033 #define _bfd_xcoff_find_nearest_line coff_find_nearest_line
4034 #define _bfd_xcoff_find_line coff_find_line
4035 #define _bfd_xcoff_find_inliner_info coff_find_inliner_info
4036 #define _bfd_xcoff_bfd_make_debug_symbol coff_bfd_make_debug_symbol
4037 #define _bfd_xcoff_read_minisymbols _bfd_generic_read_minisymbols
4038 #define _bfd_xcoff_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
4040 /* For reloc entry points. */
4041 #define _bfd_xcoff_get_reloc_upper_bound coff_get_reloc_upper_bound
4042 #define _bfd_xcoff_canonicalize_reloc coff_canonicalize_reloc
4043 #define _bfd_xcoff_set_reloc _bfd_generic_set_reloc
4044 #define _bfd_xcoff_bfd_reloc_type_lookup _bfd_xcoff_reloc_type_lookup
4045 #define _bfd_xcoff_bfd_reloc_name_lookup _bfd_xcoff_reloc_name_lookup
4047 /* For link entry points. */
4048 #define _bfd_xcoff_bfd_get_relocated_section_contents \
4049 bfd_generic_get_relocated_section_contents
4050 #define _bfd_xcoff_bfd_relax_section bfd_generic_relax_section
4051 #define _bfd_xcoff_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
4052 #define _bfd_xcoff_bfd_link_just_syms _bfd_generic_link_just_syms
4053 #define _bfd_xcoff_bfd_copy_link_hash_symbol_type \
4054 _bfd_generic_copy_link_hash_symbol_type
4055 #define _bfd_xcoff_bfd_link_split_section _bfd_generic_link_split_section
4056 #define _bfd_xcoff_bfd_gc_sections bfd_generic_gc_sections
4057 #define _bfd_xcoff_bfd_lookup_section_flags bfd_generic_lookup_section_flags
4058 #define _bfd_xcoff_bfd_merge_sections bfd_generic_merge_sections
4059 #define _bfd_xcoff_bfd_is_group_section bfd_generic_is_group_section
4060 #define _bfd_xcoff_bfd_discard_group bfd_generic_discard_group
4061 #define _bfd_xcoff_section_already_linked _bfd_generic_section_already_linked
4062 #define _bfd_xcoff_bfd_define_common_symbol _bfd_xcoff_define_common_symbol
4063 #define _bfd_xcoff_bfd_link_hide_symbol _bfd_generic_link_hide_symbol
4064 #define _bfd_xcoff_bfd_define_start_stop bfd_generic_define_start_stop
4065 #define _bfd_xcoff_bfd_link_check_relocs _bfd_generic_link_check_relocs
4067 /* For dynamic symbols and relocs entry points. */
4068 #define _bfd_xcoff_get_synthetic_symtab _bfd_nodynamic_get_synthetic_symtab
4070 static const struct xcoff_backend_data_rec bfd_xcoff_backend_data
=
4072 { /* COFF backend, defined in libcoff.h. */
4073 _bfd_xcoff_swap_aux_in
,
4074 _bfd_xcoff_swap_sym_in
,
4075 coff_swap_lineno_in
,
4076 _bfd_xcoff_swap_aux_out
,
4077 _bfd_xcoff_swap_sym_out
,
4078 coff_swap_lineno_out
,
4079 xcoff_swap_reloc_out
,
4080 coff_swap_filehdr_out
,
4081 coff_swap_aouthdr_out
,
4082 coff_swap_scnhdr_out
,
4091 TRUE
, /* _bfd_coff_long_filenames */
4092 XCOFF_NO_LONG_SECTION_NAMES
, /* _bfd_coff_long_section_names */
4093 3, /* _bfd_coff_default_section_alignment_power */
4094 FALSE
, /* _bfd_coff_force_symnames_in_strings */
4095 2, /* _bfd_coff_debug_string_prefix_length */
4096 32768, /* _bfd_coff_max_nscns */
4097 coff_swap_filehdr_in
,
4098 coff_swap_aouthdr_in
,
4099 coff_swap_scnhdr_in
,
4100 xcoff_swap_reloc_in
,
4101 coff_bad_format_hook
,
4102 coff_set_arch_mach_hook
,
4105 coff_set_alignment_hook
,
4106 coff_slurp_symbol_table
,
4107 symname_in_debug_hook
,
4108 coff_pointerize_aux_hook
,
4110 dummy_reloc16_extra_cases
,
4111 dummy_reloc16_estimate
,
4112 NULL
, /* bfd_coff_sym_is_global */
4113 coff_compute_section_file_positions
,
4114 NULL
, /* _bfd_coff_start_final_link */
4115 xcoff_ppc_relocate_section
,
4116 coff_rtype_to_howto
,
4117 NULL
, /* _bfd_coff_adjust_symndx */
4118 _bfd_generic_link_add_one_symbol
,
4119 coff_link_output_has_begun
,
4120 coff_final_link_postscript
,
4121 NULL
/* print_pdata. */
4124 0x01DF, /* magic number */
4128 /* Function pointers to xcoff specific swap routines. */
4129 xcoff_swap_ldhdr_in
,
4130 xcoff_swap_ldhdr_out
,
4131 xcoff_swap_ldsym_in
,
4132 xcoff_swap_ldsym_out
,
4133 xcoff_swap_ldrel_in
,
4134 xcoff_swap_ldrel_out
,
4140 12, /* _xcoff_function_descriptor_size */
4144 1, /* _xcoff_ldhdr_version */
4146 _bfd_xcoff_put_symbol_name
,
4147 _bfd_xcoff_put_ldsymbol_name
,
4148 &xcoff_dynamic_reloc
,
4149 xcoff_create_csect_from_smclas
,
4151 /* Lineno and reloc count overflow. */
4152 xcoff_is_lineno_count_overflow
,
4153 xcoff_is_reloc_count_overflow
,
4155 xcoff_loader_symbol_offset
,
4156 xcoff_loader_reloc_offset
,
4159 &xcoff_glink_code
[0],
4160 36, /* _xcoff_glink_size */
4163 64, /* _xcoff_rtinit_size */
4164 xcoff_generate_rtinit
,
4167 /* The transfer vector that leads the outside world to all of the above. */
4168 const bfd_target rs6000_xcoff_vec
=
4171 bfd_target_xcoff_flavour
,
4172 BFD_ENDIAN_BIG
, /* data byte order is big */
4173 BFD_ENDIAN_BIG
, /* header byte order is big */
4175 (HAS_RELOC
| EXEC_P
| HAS_LINENO
| HAS_DEBUG
| DYNAMIC
4176 | HAS_SYMS
| HAS_LOCALS
| WP_TEXT
),
4178 SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_CODE
| SEC_DATA
,
4179 0, /* leading char */
4180 '/', /* ar_pad_char */
4181 15, /* ar_max_namelen */
4182 0, /* match priority. */
4206 { /* bfd_check_format */
4209 _bfd_xcoff_archive_p
,
4213 { /* bfd_set_format */
4214 _bfd_bool_bfd_false_error
,
4216 _bfd_generic_mkarchive
,
4217 _bfd_bool_bfd_false_error
4220 {/* bfd_write_contents */
4221 _bfd_bool_bfd_false_error
,
4222 coff_write_object_contents
,
4223 _bfd_xcoff_write_archive_contents
,
4224 _bfd_bool_bfd_false_error
4227 BFD_JUMP_TABLE_GENERIC (_bfd_xcoff
),
4228 BFD_JUMP_TABLE_COPY (_bfd_xcoff
),
4229 BFD_JUMP_TABLE_CORE (coff
),
4230 BFD_JUMP_TABLE_ARCHIVE (_bfd_xcoff
),
4231 BFD_JUMP_TABLE_SYMBOLS (_bfd_xcoff
),
4232 BFD_JUMP_TABLE_RELOCS (_bfd_xcoff
),
4233 BFD_JUMP_TABLE_WRITE (coff
),
4234 BFD_JUMP_TABLE_LINK (_bfd_xcoff
),
4235 BFD_JUMP_TABLE_DYNAMIC (_bfd_xcoff
),
4237 /* Opposite endian version, none exists */
4240 & bfd_xcoff_backend_data
,
4243 /* xcoff-powermac target
4245 Only difference between this target and the rs6000 target is the
4246 the default architecture and machine type used in coffcode.h
4248 PowerPC Macs use the same magic numbers as RS/6000
4249 (because that's how they were bootstrapped originally),
4250 but they are always PowerPC architecture. */
4251 static const struct xcoff_backend_data_rec bfd_pmac_xcoff_backend_data
=
4253 { /* COFF backend, defined in libcoff.h. */
4254 _bfd_xcoff_swap_aux_in
,
4255 _bfd_xcoff_swap_sym_in
,
4256 coff_swap_lineno_in
,
4257 _bfd_xcoff_swap_aux_out
,
4258 _bfd_xcoff_swap_sym_out
,
4259 coff_swap_lineno_out
,
4260 xcoff_swap_reloc_out
,
4261 coff_swap_filehdr_out
,
4262 coff_swap_aouthdr_out
,
4263 coff_swap_scnhdr_out
,
4272 TRUE
, /* _bfd_coff_long_filenames */
4273 XCOFF_NO_LONG_SECTION_NAMES
, /* _bfd_coff_long_section_names */
4274 3, /* _bfd_coff_default_section_alignment_power */
4275 FALSE
, /* _bfd_coff_force_symnames_in_strings */
4276 2, /* _bfd_coff_debug_string_prefix_length */
4277 32768, /* _bfd_coff_max_nscns */
4278 coff_swap_filehdr_in
,
4279 coff_swap_aouthdr_in
,
4280 coff_swap_scnhdr_in
,
4281 xcoff_swap_reloc_in
,
4282 coff_bad_format_hook
,
4283 coff_set_arch_mach_hook
,
4286 coff_set_alignment_hook
,
4287 coff_slurp_symbol_table
,
4288 symname_in_debug_hook
,
4289 coff_pointerize_aux_hook
,
4291 dummy_reloc16_extra_cases
,
4292 dummy_reloc16_estimate
,
4293 NULL
, /* bfd_coff_sym_is_global */
4294 coff_compute_section_file_positions
,
4295 NULL
, /* _bfd_coff_start_final_link */
4296 xcoff_ppc_relocate_section
,
4297 coff_rtype_to_howto
,
4298 NULL
, /* _bfd_coff_adjust_symndx */
4299 _bfd_generic_link_add_one_symbol
,
4300 coff_link_output_has_begun
,
4301 coff_final_link_postscript
,
4302 NULL
/* print_pdata. */
4305 0x01DF, /* magic number */
4309 /* Function pointers to xcoff specific swap routines. */
4310 xcoff_swap_ldhdr_in
,
4311 xcoff_swap_ldhdr_out
,
4312 xcoff_swap_ldsym_in
,
4313 xcoff_swap_ldsym_out
,
4314 xcoff_swap_ldrel_in
,
4315 xcoff_swap_ldrel_out
,
4321 12, /* _xcoff_function_descriptor_size */
4325 1, /* _xcoff_ldhdr_version */
4327 _bfd_xcoff_put_symbol_name
,
4328 _bfd_xcoff_put_ldsymbol_name
,
4329 &xcoff_dynamic_reloc
,
4330 xcoff_create_csect_from_smclas
,
4332 /* Lineno and reloc count overflow. */
4333 xcoff_is_lineno_count_overflow
,
4334 xcoff_is_reloc_count_overflow
,
4336 xcoff_loader_symbol_offset
,
4337 xcoff_loader_reloc_offset
,
4340 &xcoff_glink_code
[0],
4341 36, /* _xcoff_glink_size */
4344 0, /* _xcoff_rtinit_size */
4345 xcoff_generate_rtinit
,
4348 /* The transfer vector that leads the outside world to all of the above. */
4349 const bfd_target powerpc_xcoff_vec
=
4352 bfd_target_xcoff_flavour
,
4353 BFD_ENDIAN_BIG
, /* data byte order is big */
4354 BFD_ENDIAN_BIG
, /* header byte order is big */
4356 (HAS_RELOC
| EXEC_P
| HAS_LINENO
| HAS_DEBUG
| DYNAMIC
4357 | HAS_SYMS
| HAS_LOCALS
| WP_TEXT
),
4359 SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_CODE
| SEC_DATA
,
4360 0, /* leading char */
4361 '/', /* ar_pad_char */
4362 15, /* ar_max_namelen */
4363 0, /* match priority. */
4387 { /* bfd_check_format */
4390 _bfd_xcoff_archive_p
,
4394 { /* bfd_set_format */
4395 _bfd_bool_bfd_false_error
,
4397 _bfd_generic_mkarchive
,
4398 _bfd_bool_bfd_false_error
4401 {/* bfd_write_contents */
4402 _bfd_bool_bfd_false_error
,
4403 coff_write_object_contents
,
4404 _bfd_xcoff_write_archive_contents
,
4405 _bfd_bool_bfd_false_error
4408 BFD_JUMP_TABLE_GENERIC (_bfd_xcoff
),
4409 BFD_JUMP_TABLE_COPY (_bfd_xcoff
),
4410 BFD_JUMP_TABLE_CORE (coff
),
4411 BFD_JUMP_TABLE_ARCHIVE (_bfd_xcoff
),
4412 BFD_JUMP_TABLE_SYMBOLS (_bfd_xcoff
),
4413 BFD_JUMP_TABLE_RELOCS (_bfd_xcoff
),
4414 BFD_JUMP_TABLE_WRITE (coff
),
4415 BFD_JUMP_TABLE_LINK (_bfd_xcoff
),
4416 BFD_JUMP_TABLE_DYNAMIC (_bfd_xcoff
),
4418 /* Opposite endian version, none exists */
4421 & bfd_pmac_xcoff_backend_data
,