1 /* BFD back-end for IBM RS/6000 "XCOFF" files.
2 Copyright (C) 1990-2017 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
118 #include "coffcode.h"
120 /* The main body of code is in coffcode.h. */
122 static const char *normalize_filename (bfd
*);
123 static bfd_boolean xcoff_write_armap_old
124 (bfd
*, unsigned int, struct orl
*, unsigned int, int);
125 static bfd_boolean xcoff_write_armap_big
126 (bfd
*, unsigned int, struct orl
*, unsigned int, int);
127 static bfd_boolean
xcoff_write_archive_contents_old (bfd
*);
128 static bfd_boolean
xcoff_write_archive_contents_big (bfd
*);
129 static void xcoff_swap_ldhdr_in (bfd
*, const void *, struct internal_ldhdr
*);
130 static void xcoff_swap_ldhdr_out (bfd
*, const struct internal_ldhdr
*, void *);
131 static void xcoff_swap_ldsym_in (bfd
*, const void *, struct internal_ldsym
*);
132 static void xcoff_swap_ldsym_out (bfd
*, const struct internal_ldsym
*, void *);
133 static void xcoff_swap_ldrel_in (bfd
*, const void *, struct internal_ldrel
*);
134 static void xcoff_swap_ldrel_out (bfd
*, const struct internal_ldrel
*, void *);
135 static bfd_boolean xcoff_ppc_relocate_section
136 (bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
137 struct internal_reloc
*, struct internal_syment
*, asection
**);
138 static bfd_boolean _bfd_xcoff_put_ldsymbol_name
139 (bfd
*, struct xcoff_loader_info
*, struct internal_ldsym
*, const char *);
140 static asection
*xcoff_create_csect_from_smclas
141 (bfd
*, union internal_auxent
*, const char *);
142 static bfd_boolean
xcoff_is_lineno_count_overflow (bfd
*, bfd_vma
);
143 static bfd_boolean
xcoff_is_reloc_count_overflow (bfd
*, bfd_vma
);
144 static bfd_vma
xcoff_loader_symbol_offset (bfd
*, struct internal_ldhdr
*);
145 static bfd_vma
xcoff_loader_reloc_offset (bfd
*, struct internal_ldhdr
*);
146 static bfd_boolean xcoff_generate_rtinit
147 (bfd
*, const char *, const char *, bfd_boolean
);
148 static bfd_boolean
do_pad (bfd
*, unsigned int);
149 static bfd_boolean
do_copy (bfd
*, bfd
*);
151 /* Relocation functions */
152 static bfd_boolean
xcoff_reloc_type_br (XCOFF_RELOC_FUNCTION_ARGS
);
154 static bfd_boolean xcoff_complain_overflow_dont_func
155 (XCOFF_COMPLAIN_FUNCTION_ARGS
);
156 static bfd_boolean xcoff_complain_overflow_bitfield_func
157 (XCOFF_COMPLAIN_FUNCTION_ARGS
);
158 static bfd_boolean xcoff_complain_overflow_signed_func
159 (XCOFF_COMPLAIN_FUNCTION_ARGS
);
160 static bfd_boolean xcoff_complain_overflow_unsigned_func
161 (XCOFF_COMPLAIN_FUNCTION_ARGS
);
163 bfd_boolean (*xcoff_calculate_relocation
[XCOFF_MAX_CALCULATE_RELOCATION
])
164 (XCOFF_RELOC_FUNCTION_ARGS
) =
166 xcoff_reloc_type_pos
, /* R_POS (0x00) */
167 xcoff_reloc_type_neg
, /* R_NEG (0x01) */
168 xcoff_reloc_type_rel
, /* R_REL (0x02) */
169 xcoff_reloc_type_toc
, /* R_TOC (0x03) */
170 xcoff_reloc_type_fail
, /* R_RTB (0x04) */
171 xcoff_reloc_type_toc
, /* R_GL (0x05) */
172 xcoff_reloc_type_toc
, /* R_TCL (0x06) */
173 xcoff_reloc_type_fail
, /* (0x07) */
174 xcoff_reloc_type_ba
, /* R_BA (0x08) */
175 xcoff_reloc_type_fail
, /* (0x09) */
176 xcoff_reloc_type_br
, /* R_BR (0x0a) */
177 xcoff_reloc_type_fail
, /* (0x0b) */
178 xcoff_reloc_type_pos
, /* R_RL (0x0c) */
179 xcoff_reloc_type_pos
, /* R_RLA (0x0d) */
180 xcoff_reloc_type_fail
, /* (0x0e) */
181 xcoff_reloc_type_noop
, /* R_REF (0x0f) */
182 xcoff_reloc_type_fail
, /* (0x10) */
183 xcoff_reloc_type_fail
, /* (0x11) */
184 xcoff_reloc_type_toc
, /* R_TRL (0x12) */
185 xcoff_reloc_type_toc
, /* R_TRLA (0x13) */
186 xcoff_reloc_type_fail
, /* R_RRTBI (0x14) */
187 xcoff_reloc_type_fail
, /* R_RRTBA (0x15) */
188 xcoff_reloc_type_ba
, /* R_CAI (0x16) */
189 xcoff_reloc_type_crel
, /* R_CREL (0x17) */
190 xcoff_reloc_type_ba
, /* R_RBA (0x18) */
191 xcoff_reloc_type_ba
, /* R_RBAC (0x19) */
192 xcoff_reloc_type_br
, /* R_RBR (0x1a) */
193 xcoff_reloc_type_ba
, /* R_RBRC (0x1b) */
196 bfd_boolean (*xcoff_complain_overflow
[XCOFF_MAX_COMPLAIN_OVERFLOW
])
197 (XCOFF_COMPLAIN_FUNCTION_ARGS
) =
199 xcoff_complain_overflow_dont_func
,
200 xcoff_complain_overflow_bitfield_func
,
201 xcoff_complain_overflow_signed_func
,
202 xcoff_complain_overflow_unsigned_func
,
205 /* Information about one member of an archive. */
208 /* The archive member that this structure describes. */
211 /* The number of bytes of padding that must be inserted before the
212 start of the member in order to ensure that the section contents
213 are correctly aligned. */
214 unsigned int leading_padding
;
216 /* The offset of MEMBER from the start of the archive (i.e. the end
217 of the leading padding). */
220 /* The normalized name of MEMBER. */
223 /* The length of NAME, without padding. */
224 bfd_size_type namlen
;
226 /* The length of NAME, with padding. */
227 bfd_size_type padded_namlen
;
229 /* The size of MEMBER's header, including the name and magic sequence. */
230 bfd_size_type header_size
;
232 /* The size of the MEMBER's contents. */
233 bfd_size_type contents_size
;
235 /* The number of bytes of padding that must be inserted after MEMBER
236 in order to preserve even alignment. */
237 bfd_size_type trailing_padding
;
240 /* A structure used for iterating over the members of an archive. */
241 struct archive_iterator
243 /* The archive itself. */
246 /* Information about the current archive member. */
247 struct member_layout current
;
249 /* Information about the next archive member. MEMBER is null if there
250 are no more archive members, in which case OFFSET is the offset of
251 the first unused byte. */
252 struct member_layout next
;
255 /* Initialize INFO so that it describes member MEMBER of archive ARCHIVE.
256 OFFSET is the even-padded offset of MEMBER, not including any leading
257 padding needed for section alignment. */
260 member_layout_init (struct member_layout
*info
, bfd
*archive
,
261 bfd
*member
, file_ptr offset
)
263 info
->member
= member
;
264 info
->leading_padding
= 0;
267 info
->name
= normalize_filename (member
);
268 info
->namlen
= strlen (info
->name
);
269 info
->padded_namlen
= info
->namlen
+ (info
->namlen
& 1);
270 if (xcoff_big_format_p (archive
))
271 info
->header_size
= SIZEOF_AR_HDR_BIG
;
273 info
->header_size
= SIZEOF_AR_HDR
;
274 info
->header_size
+= info
->padded_namlen
+ SXCOFFARFMAG
;
275 info
->contents_size
= arelt_size (member
);
276 info
->trailing_padding
= info
->contents_size
& 1;
278 if (bfd_check_format (member
, bfd_object
)
279 && bfd_get_flavour (member
) == bfd_target_xcoff_flavour
280 && (member
->flags
& DYNAMIC
) != 0)
281 info
->leading_padding
282 = (-(offset
+ info
->header_size
)
283 & ((1 << bfd_xcoff_text_align_power (member
)) - 1));
285 info
->offset
= offset
+ info
->leading_padding
;
288 /* Set up ITERATOR to iterate through archive ARCHIVE. */
291 archive_iterator_begin (struct archive_iterator
*iterator
,
294 iterator
->archive
= archive
;
295 member_layout_init (&iterator
->next
, archive
, archive
->archive_head
,
296 xcoff_big_format_p (archive
)
297 ? SIZEOF_AR_FILE_HDR_BIG
298 : SIZEOF_AR_FILE_HDR
);
301 /* Make ITERATOR visit the first unvisited archive member. Return true
302 on success; return false if all members have been visited. */
305 archive_iterator_next (struct archive_iterator
*iterator
)
307 if (!iterator
->next
.member
)
310 iterator
->current
= iterator
->next
;
311 member_layout_init (&iterator
->next
, iterator
->archive
,
312 iterator
->current
.member
->archive_next
,
313 iterator
->current
.offset
314 + iterator
->current
.header_size
315 + iterator
->current
.contents_size
316 + iterator
->current
.trailing_padding
);
320 /* We use our own tdata type. Its first field is the COFF tdata type,
321 so the COFF routines are compatible. */
324 _bfd_xcoff_mkobject (bfd
*abfd
)
326 coff_data_type
*coff
;
327 bfd_size_type amt
= sizeof (struct xcoff_tdata
);
329 abfd
->tdata
.xcoff_obj_data
= (struct xcoff_tdata
*) bfd_zalloc (abfd
, amt
);
330 if (abfd
->tdata
.xcoff_obj_data
== NULL
)
332 coff
= coff_data (abfd
);
333 coff
->symbols
= (coff_symbol_type
*) NULL
;
334 coff
->conversion_table
= (unsigned int *) NULL
;
335 coff
->raw_syments
= (struct coff_ptr_struct
*) NULL
;
338 xcoff_data (abfd
)->modtype
= ('1' << 8) | 'L';
340 /* We set cputype to -1 to indicate that it has not been
342 xcoff_data (abfd
)->cputype
= -1;
344 xcoff_data (abfd
)->csects
= NULL
;
345 xcoff_data (abfd
)->debug_indices
= NULL
;
347 /* text section alignment is different than the default */
348 bfd_xcoff_text_align_power (abfd
) = 2;
353 /* Copy XCOFF data from one BFD to another. */
356 _bfd_xcoff_copy_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
358 struct xcoff_tdata
*ix
, *ox
;
361 if (ibfd
->xvec
!= obfd
->xvec
)
363 ix
= xcoff_data (ibfd
);
364 ox
= xcoff_data (obfd
);
365 ox
->full_aouthdr
= ix
->full_aouthdr
;
371 sec
= coff_section_from_bfd_index (ibfd
, ix
->sntoc
);
375 ox
->sntoc
= sec
->output_section
->target_index
;
377 if (ix
->snentry
== 0)
381 sec
= coff_section_from_bfd_index (ibfd
, ix
->snentry
);
385 ox
->snentry
= sec
->output_section
->target_index
;
387 bfd_xcoff_text_align_power (obfd
) = bfd_xcoff_text_align_power (ibfd
);
388 bfd_xcoff_data_align_power (obfd
) = bfd_xcoff_data_align_power (ibfd
);
389 ox
->modtype
= ix
->modtype
;
390 ox
->cputype
= ix
->cputype
;
391 ox
->maxdata
= ix
->maxdata
;
392 ox
->maxstack
= ix
->maxstack
;
396 /* I don't think XCOFF really has a notion of local labels based on
397 name. This will mean that ld -X doesn't actually strip anything.
398 The AIX native linker does not have a -X option, and it ignores the
402 _bfd_xcoff_is_local_label_name (bfd
*abfd ATTRIBUTE_UNUSED
,
403 const char *name ATTRIBUTE_UNUSED
)
409 _bfd_xcoff_swap_sym_in (bfd
*abfd
, void * ext1
, void * in1
)
411 SYMENT
*ext
= (SYMENT
*)ext1
;
412 struct internal_syment
* in
= (struct internal_syment
*)in1
;
414 if (ext
->e
.e_name
[0] != 0)
416 memcpy (in
->_n
._n_name
, ext
->e
.e_name
, SYMNMLEN
);
420 in
->_n
._n_n
._n_zeroes
= 0;
421 in
->_n
._n_n
._n_offset
= H_GET_32 (abfd
, ext
->e
.e
.e_offset
);
424 in
->n_value
= H_GET_32 (abfd
, ext
->e_value
);
425 in
->n_scnum
= (short) H_GET_16 (abfd
, ext
->e_scnum
);
426 in
->n_type
= H_GET_16 (abfd
, ext
->e_type
);
427 in
->n_sclass
= H_GET_8 (abfd
, ext
->e_sclass
);
428 in
->n_numaux
= H_GET_8 (abfd
, ext
->e_numaux
);
432 _bfd_xcoff_swap_sym_out (bfd
*abfd
, void * inp
, void * extp
)
434 struct internal_syment
*in
= (struct internal_syment
*)inp
;
435 SYMENT
*ext
=(SYMENT
*)extp
;
437 if (in
->_n
._n_name
[0] != 0)
439 memcpy (ext
->e
.e_name
, in
->_n
._n_name
, SYMNMLEN
);
443 H_PUT_32 (abfd
, 0, ext
->e
.e
.e_zeroes
);
444 H_PUT_32 (abfd
, in
->_n
._n_n
._n_offset
, ext
->e
.e
.e_offset
);
447 H_PUT_32 (abfd
, in
->n_value
, ext
->e_value
);
448 H_PUT_16 (abfd
, in
->n_scnum
, ext
->e_scnum
);
449 H_PUT_16 (abfd
, in
->n_type
, ext
->e_type
);
450 H_PUT_8 (abfd
, in
->n_sclass
, ext
->e_sclass
);
451 H_PUT_8 (abfd
, in
->n_numaux
, ext
->e_numaux
);
452 return bfd_coff_symesz (abfd
);
456 _bfd_xcoff_swap_aux_in (bfd
*abfd
, void * ext1
, int type
, int in_class
,
457 int indx
, int numaux
, void * in1
)
459 AUXENT
* ext
= (AUXENT
*)ext1
;
460 union internal_auxent
*in
= (union internal_auxent
*)in1
;
465 if (ext
->x_file
.x_n
.x_fname
[0] == 0)
467 in
->x_file
.x_n
.x_zeroes
= 0;
468 in
->x_file
.x_n
.x_offset
=
469 H_GET_32 (abfd
, ext
->x_file
.x_n
.x_n
.x_offset
);
476 memcpy (in
->x_file
.x_fname
, ext
->x_file
.x_n
.x_fname
,
477 numaux
* sizeof (AUXENT
));
481 memcpy (in
->x_file
.x_fname
, ext
->x_file
.x_n
.x_fname
, FILNMLEN
);
486 /* RS/6000 "csect" auxents */
490 if (indx
+ 1 == numaux
)
492 in
->x_csect
.x_scnlen
.l
= H_GET_32 (abfd
, ext
->x_csect
.x_scnlen
);
493 in
->x_csect
.x_parmhash
= H_GET_32 (abfd
, ext
->x_csect
.x_parmhash
);
494 in
->x_csect
.x_snhash
= H_GET_16 (abfd
, ext
->x_csect
.x_snhash
);
495 /* We don't have to hack bitfields in x_smtyp because it's
496 defined by shifts-and-ands, which are equivalent on all
498 in
->x_csect
.x_smtyp
= H_GET_8 (abfd
, ext
->x_csect
.x_smtyp
);
499 in
->x_csect
.x_smclas
= H_GET_8 (abfd
, ext
->x_csect
.x_smclas
);
500 in
->x_csect
.x_stab
= H_GET_32 (abfd
, ext
->x_csect
.x_stab
);
501 in
->x_csect
.x_snstab
= H_GET_16 (abfd
, ext
->x_csect
.x_snstab
);
511 in
->x_scn
.x_scnlen
= H_GET_32 (abfd
, ext
->x_scn
.x_scnlen
);
512 in
->x_scn
.x_nreloc
= H_GET_16 (abfd
, ext
->x_scn
.x_nreloc
);
513 in
->x_scn
.x_nlinno
= H_GET_16 (abfd
, ext
->x_scn
.x_nlinno
);
514 /* PE defines some extra fields; we zero them out for
516 in
->x_scn
.x_checksum
= 0;
517 in
->x_scn
.x_associated
= 0;
518 in
->x_scn
.x_comdat
= 0;
525 in
->x_sym
.x_tagndx
.l
= H_GET_32 (abfd
, ext
->x_sym
.x_tagndx
);
526 in
->x_sym
.x_tvndx
= H_GET_16 (abfd
, ext
->x_sym
.x_tvndx
);
528 if (in_class
== C_BLOCK
|| in_class
== C_FCN
|| ISFCN (type
)
531 in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
=
532 H_GET_32 (abfd
, ext
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
533 in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
=
534 H_GET_32 (abfd
, ext
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
538 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0] =
539 H_GET_16 (abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
540 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1] =
541 H_GET_16 (abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
542 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2] =
543 H_GET_16 (abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
544 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3] =
545 H_GET_16 (abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
550 in
->x_sym
.x_misc
.x_fsize
= H_GET_32 (abfd
, ext
->x_sym
.x_misc
.x_fsize
);
554 in
->x_sym
.x_misc
.x_lnsz
.x_lnno
=
555 H_GET_16 (abfd
, ext
->x_sym
.x_misc
.x_lnsz
.x_lnno
);
556 in
->x_sym
.x_misc
.x_lnsz
.x_size
=
557 H_GET_16 (abfd
, ext
->x_sym
.x_misc
.x_lnsz
.x_size
);
561 /* The semicolon is because MSVC doesn't like labels at
566 _bfd_xcoff_swap_aux_out (bfd
*abfd
, void * inp
, int type
, int in_class
,
567 int indx ATTRIBUTE_UNUSED
,
568 int numaux ATTRIBUTE_UNUSED
,
571 union internal_auxent
*in
= (union internal_auxent
*)inp
;
572 AUXENT
*ext
= (AUXENT
*)extp
;
574 memset (ext
, 0, bfd_coff_auxesz (abfd
));
578 if (in
->x_file
.x_fname
[0] == 0)
580 H_PUT_32 (abfd
, 0, ext
->x_file
.x_n
.x_n
.x_zeroes
);
581 H_PUT_32 (abfd
, in
->x_file
.x_n
.x_offset
,
582 ext
->x_file
.x_n
.x_n
.x_offset
);
586 memcpy (ext
->x_file
.x_n
.x_fname
, in
->x_file
.x_fname
, FILNMLEN
);
590 /* RS/6000 "csect" auxents */
594 if (indx
+ 1 == numaux
)
596 H_PUT_32 (abfd
, in
->x_csect
.x_scnlen
.l
, ext
->x_csect
.x_scnlen
);
597 H_PUT_32 (abfd
, in
->x_csect
.x_parmhash
, ext
->x_csect
.x_parmhash
);
598 H_PUT_16 (abfd
, in
->x_csect
.x_snhash
, ext
->x_csect
.x_snhash
);
599 /* We don't have to hack bitfields in x_smtyp because it's
600 defined by shifts-and-ands, which are equivalent on all
602 H_PUT_8 (abfd
, in
->x_csect
.x_smtyp
, ext
->x_csect
.x_smtyp
);
603 H_PUT_8 (abfd
, in
->x_csect
.x_smclas
, ext
->x_csect
.x_smclas
);
604 H_PUT_32 (abfd
, in
->x_csect
.x_stab
, ext
->x_csect
.x_stab
);
605 H_PUT_16 (abfd
, in
->x_csect
.x_snstab
, ext
->x_csect
.x_snstab
);
615 H_PUT_32 (abfd
, in
->x_scn
.x_scnlen
, ext
->x_scn
.x_scnlen
);
616 H_PUT_16 (abfd
, in
->x_scn
.x_nreloc
, ext
->x_scn
.x_nreloc
);
617 H_PUT_16 (abfd
, in
->x_scn
.x_nlinno
, ext
->x_scn
.x_nlinno
);
623 H_PUT_32 (abfd
, in
->x_sym
.x_tagndx
.l
, ext
->x_sym
.x_tagndx
);
624 H_PUT_16 (abfd
, in
->x_sym
.x_tvndx
, ext
->x_sym
.x_tvndx
);
626 if (in_class
== C_BLOCK
|| in_class
== C_FCN
|| ISFCN (type
)
629 H_PUT_32 (abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
,
630 ext
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
631 H_PUT_32 (abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
,
632 ext
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
636 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0],
637 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
638 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1],
639 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
640 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2],
641 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
642 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3],
643 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
647 H_PUT_32 (abfd
, in
->x_sym
.x_misc
.x_fsize
, ext
->x_sym
.x_misc
.x_fsize
);
650 H_PUT_16 (abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_lnno
,
651 ext
->x_sym
.x_misc
.x_lnsz
.x_lnno
);
652 H_PUT_16 (abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_size
,
653 ext
->x_sym
.x_misc
.x_lnsz
.x_size
);
657 return bfd_coff_auxesz (abfd
);
660 /* The XCOFF reloc table. Actually, XCOFF relocations specify the
661 bitsize and whether they are signed or not, along with a
662 conventional type. This table is for the types, which are used for
663 different algorithms for putting in the reloc. Many of these
664 relocs need special_function entries, which I have not written. */
666 reloc_howto_type xcoff_howto_table
[] =
668 /* 0x00: Standard 32 bit relocation. */
669 HOWTO (R_POS
, /* type */
671 2, /* size (0 = byte, 1 = short, 2 = long) */
673 FALSE
, /* pc_relative */
675 complain_overflow_bitfield
, /* complain_on_overflow */
676 0, /* special_function */
678 TRUE
, /* partial_inplace */
679 0xffffffff, /* src_mask */
680 0xffffffff, /* dst_mask */
681 FALSE
), /* pcrel_offset */
683 /* 0x01: 32 bit relocation, but store negative value. */
684 HOWTO (R_NEG
, /* type */
686 -2, /* size (0 = byte, 1 = short, 2 = long) */
688 FALSE
, /* pc_relative */
690 complain_overflow_bitfield
, /* complain_on_overflow */
691 0, /* special_function */
693 TRUE
, /* partial_inplace */
694 0xffffffff, /* src_mask */
695 0xffffffff, /* dst_mask */
696 FALSE
), /* pcrel_offset */
698 /* 0x02: 32 bit PC relative relocation. */
699 HOWTO (R_REL
, /* type */
701 2, /* size (0 = byte, 1 = short, 2 = long) */
703 TRUE
, /* pc_relative */
705 complain_overflow_signed
, /* complain_on_overflow */
706 0, /* special_function */
708 TRUE
, /* partial_inplace */
709 0xffffffff, /* src_mask */
710 0xffffffff, /* dst_mask */
711 FALSE
), /* pcrel_offset */
713 /* 0x03: 16 bit TOC relative relocation. */
714 HOWTO (R_TOC
, /* type */
716 1, /* size (0 = byte, 1 = short, 2 = long) */
718 FALSE
, /* pc_relative */
720 complain_overflow_bitfield
, /* complain_on_overflow */
721 0, /* special_function */
723 TRUE
, /* partial_inplace */
724 0xffff, /* src_mask */
725 0xffff, /* dst_mask */
726 FALSE
), /* pcrel_offset */
728 /* 0x04: I don't really know what this is. */
729 HOWTO (R_RTB
, /* type */
731 2, /* size (0 = byte, 1 = short, 2 = long) */
733 FALSE
, /* pc_relative */
735 complain_overflow_bitfield
, /* complain_on_overflow */
736 0, /* special_function */
738 TRUE
, /* partial_inplace */
739 0xffffffff, /* src_mask */
740 0xffffffff, /* dst_mask */
741 FALSE
), /* pcrel_offset */
743 /* 0x05: External TOC relative symbol. */
744 HOWTO (R_GL
, /* type */
746 1, /* size (0 = byte, 1 = short, 2 = long) */
748 FALSE
, /* pc_relative */
750 complain_overflow_bitfield
, /* complain_on_overflow */
751 0, /* special_function */
753 TRUE
, /* partial_inplace */
754 0xffff, /* src_mask */
755 0xffff, /* dst_mask */
756 FALSE
), /* pcrel_offset */
758 /* 0x06: Local TOC relative symbol. */
759 HOWTO (R_TCL
, /* type */
761 1, /* size (0 = byte, 1 = short, 2 = long) */
763 FALSE
, /* pc_relative */
765 complain_overflow_bitfield
, /* complain_on_overflow */
766 0, /* special_function */
768 TRUE
, /* partial_inplace */
769 0xffff, /* src_mask */
770 0xffff, /* dst_mask */
771 FALSE
), /* pcrel_offset */
775 /* 0x08: Non modifiable absolute branch. */
776 HOWTO (R_BA
, /* type */
778 2, /* size (0 = byte, 1 = short, 2 = long) */
780 FALSE
, /* pc_relative */
782 complain_overflow_bitfield
, /* complain_on_overflow */
783 0, /* special_function */
784 "R_BA_26", /* name */
785 TRUE
, /* partial_inplace */
786 0x03fffffc, /* src_mask */
787 0x03fffffc, /* dst_mask */
788 FALSE
), /* pcrel_offset */
792 /* 0x0a: Non modifiable relative branch. */
793 HOWTO (R_BR
, /* type */
795 2, /* size (0 = byte, 1 = short, 2 = long) */
797 TRUE
, /* pc_relative */
799 complain_overflow_signed
, /* complain_on_overflow */
800 0, /* special_function */
802 TRUE
, /* partial_inplace */
803 0x03fffffc, /* src_mask */
804 0x03fffffc, /* dst_mask */
805 FALSE
), /* pcrel_offset */
809 /* 0x0c: Indirect load. */
810 HOWTO (R_RL
, /* type */
812 1, /* size (0 = byte, 1 = short, 2 = long) */
814 FALSE
, /* pc_relative */
816 complain_overflow_bitfield
, /* complain_on_overflow */
817 0, /* special_function */
819 TRUE
, /* partial_inplace */
820 0xffff, /* src_mask */
821 0xffff, /* dst_mask */
822 FALSE
), /* pcrel_offset */
824 /* 0x0d: Load address. */
825 HOWTO (R_RLA
, /* type */
827 1, /* size (0 = byte, 1 = short, 2 = long) */
829 FALSE
, /* pc_relative */
831 complain_overflow_bitfield
, /* complain_on_overflow */
832 0, /* special_function */
834 TRUE
, /* partial_inplace */
835 0xffff, /* src_mask */
836 0xffff, /* dst_mask */
837 FALSE
), /* pcrel_offset */
841 /* 0x0f: Non-relocating reference. Bitsize is 1 so that r_rsize is 0. */
842 HOWTO (R_REF
, /* type */
844 0, /* size (0 = byte, 1 = short, 2 = long) */
846 FALSE
, /* pc_relative */
848 complain_overflow_dont
, /* complain_on_overflow */
849 0, /* special_function */
851 FALSE
, /* partial_inplace */
854 FALSE
), /* pcrel_offset */
859 /* 0x12: TOC relative indirect load. */
860 HOWTO (R_TRL
, /* type */
862 1, /* size (0 = byte, 1 = short, 2 = long) */
864 FALSE
, /* pc_relative */
866 complain_overflow_bitfield
, /* complain_on_overflow */
867 0, /* special_function */
869 TRUE
, /* partial_inplace */
870 0xffff, /* src_mask */
871 0xffff, /* dst_mask */
872 FALSE
), /* pcrel_offset */
874 /* 0x13: TOC relative load address. */
875 HOWTO (R_TRLA
, /* type */
877 1, /* size (0 = byte, 1 = short, 2 = long) */
879 FALSE
, /* pc_relative */
881 complain_overflow_bitfield
, /* complain_on_overflow */
882 0, /* special_function */
884 TRUE
, /* partial_inplace */
885 0xffff, /* src_mask */
886 0xffff, /* dst_mask */
887 FALSE
), /* pcrel_offset */
889 /* 0x14: Modifiable relative branch. */
890 HOWTO (R_RRTBI
, /* type */
892 2, /* size (0 = byte, 1 = short, 2 = long) */
894 FALSE
, /* pc_relative */
896 complain_overflow_bitfield
, /* complain_on_overflow */
897 0, /* special_function */
898 "R_RRTBI", /* name */
899 TRUE
, /* partial_inplace */
900 0xffffffff, /* src_mask */
901 0xffffffff, /* dst_mask */
902 FALSE
), /* pcrel_offset */
904 /* 0x15: Modifiable absolute branch. */
905 HOWTO (R_RRTBA
, /* type */
907 2, /* size (0 = byte, 1 = short, 2 = long) */
909 FALSE
, /* pc_relative */
911 complain_overflow_bitfield
, /* complain_on_overflow */
912 0, /* special_function */
913 "R_RRTBA", /* name */
914 TRUE
, /* partial_inplace */
915 0xffffffff, /* src_mask */
916 0xffffffff, /* dst_mask */
917 FALSE
), /* pcrel_offset */
919 /* 0x16: Modifiable call absolute indirect. */
920 HOWTO (R_CAI
, /* type */
922 1, /* size (0 = byte, 1 = short, 2 = long) */
924 FALSE
, /* pc_relative */
926 complain_overflow_bitfield
, /* complain_on_overflow */
927 0, /* special_function */
929 TRUE
, /* partial_inplace */
930 0xffff, /* src_mask */
931 0xffff, /* dst_mask */
932 FALSE
), /* pcrel_offset */
934 /* 0x17: Modifiable call relative. */
935 HOWTO (R_CREL
, /* type */
937 1, /* size (0 = byte, 1 = short, 2 = long) */
939 FALSE
, /* pc_relative */
941 complain_overflow_bitfield
, /* complain_on_overflow */
942 0, /* special_function */
944 TRUE
, /* partial_inplace */
945 0xffff, /* src_mask */
946 0xffff, /* dst_mask */
947 FALSE
), /* pcrel_offset */
949 /* 0x18: Modifiable branch absolute. */
950 HOWTO (R_RBA
, /* type */
952 2, /* size (0 = byte, 1 = short, 2 = long) */
954 FALSE
, /* pc_relative */
956 complain_overflow_bitfield
, /* complain_on_overflow */
957 0, /* special_function */
959 TRUE
, /* partial_inplace */
960 0x03fffffc, /* src_mask */
961 0x03fffffc, /* dst_mask */
962 FALSE
), /* pcrel_offset */
964 /* 0x19: Modifiable branch absolute. */
965 HOWTO (R_RBAC
, /* type */
967 2, /* size (0 = byte, 1 = short, 2 = long) */
969 FALSE
, /* pc_relative */
971 complain_overflow_bitfield
, /* complain_on_overflow */
972 0, /* special_function */
974 TRUE
, /* partial_inplace */
975 0xffffffff, /* src_mask */
976 0xffffffff, /* dst_mask */
977 FALSE
), /* pcrel_offset */
979 /* 0x1a: Modifiable branch relative. */
980 HOWTO (R_RBR
, /* type */
982 2, /* size (0 = byte, 1 = short, 2 = long) */
984 FALSE
, /* pc_relative */
986 complain_overflow_signed
, /* complain_on_overflow */
987 0, /* special_function */
988 "R_RBR_26", /* name */
989 TRUE
, /* partial_inplace */
990 0x03fffffc, /* src_mask */
991 0x03fffffc, /* dst_mask */
992 FALSE
), /* pcrel_offset */
994 /* 0x1b: Modifiable branch absolute. */
995 HOWTO (R_RBRC
, /* type */
997 1, /* size (0 = byte, 1 = short, 2 = long) */
999 FALSE
, /* pc_relative */
1001 complain_overflow_bitfield
, /* complain_on_overflow */
1002 0, /* special_function */
1003 "R_RBRC", /* name */
1004 TRUE
, /* partial_inplace */
1005 0xffff, /* src_mask */
1006 0xffff, /* dst_mask */
1007 FALSE
), /* pcrel_offset */
1009 /* 0x1c: 16 bit Non modifiable absolute branch. */
1010 HOWTO (R_BA
, /* type */
1012 1, /* size (0 = byte, 1 = short, 2 = long) */
1014 FALSE
, /* pc_relative */
1016 complain_overflow_bitfield
, /* complain_on_overflow */
1017 0, /* special_function */
1018 "R_BA_16", /* name */
1019 TRUE
, /* partial_inplace */
1020 0xfffc, /* src_mask */
1021 0xfffc, /* dst_mask */
1022 FALSE
), /* pcrel_offset */
1024 /* 0x1d: Modifiable branch relative. */
1025 HOWTO (R_RBR
, /* type */
1027 1, /* size (0 = byte, 1 = short, 2 = long) */
1029 TRUE
, /* pc_relative */
1031 complain_overflow_signed
, /* complain_on_overflow */
1032 0, /* special_function */
1033 "R_RBR_16", /* name */
1034 TRUE
, /* partial_inplace */
1035 0xfffc, /* src_mask */
1036 0xfffc, /* dst_mask */
1037 FALSE
), /* pcrel_offset */
1039 /* 0x1e: Modifiable branch relative. */
1040 HOWTO (R_RBA
, /* type */
1042 1, /* size (0 = byte, 1 = short, 2 = long) */
1044 FALSE
, /* pc_relative */
1046 complain_overflow_signed
, /* complain_on_overflow */
1047 0, /* special_function */
1048 "R_RBA_16", /* name */
1049 TRUE
, /* partial_inplace */
1050 0xffff, /* src_mask */
1051 0xffff, /* dst_mask */
1052 FALSE
), /* pcrel_offset */
1056 xcoff_rtype2howto (arelent
*relent
, struct internal_reloc
*internal
)
1058 if (internal
->r_type
> R_RBRC
)
1061 /* Default howto layout works most of the time */
1062 relent
->howto
= &xcoff_howto_table
[internal
->r_type
];
1064 /* Special case some 16 bit reloc */
1065 if (15 == (internal
->r_size
& 0x1f))
1067 if (R_BA
== internal
->r_type
)
1068 relent
->howto
= &xcoff_howto_table
[0x1c];
1069 else if (R_RBR
== internal
->r_type
)
1070 relent
->howto
= &xcoff_howto_table
[0x1d];
1071 else if (R_RBA
== internal
->r_type
)
1072 relent
->howto
= &xcoff_howto_table
[0x1e];
1075 /* The r_size field of an XCOFF reloc encodes the bitsize of the
1076 relocation, as well as indicating whether it is signed or not.
1077 Doublecheck that the relocation information gathered from the
1078 type matches this information. The bitsize is not significant
1079 for R_REF relocs. */
1080 if (relent
->howto
->dst_mask
!= 0
1081 && (relent
->howto
->bitsize
1082 != ((unsigned int) internal
->r_size
& 0x1f) + 1))
1087 _bfd_xcoff_reloc_type_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1088 bfd_reloc_code_real_type code
)
1092 case BFD_RELOC_PPC_B26
:
1093 return &xcoff_howto_table
[0xa];
1094 case BFD_RELOC_PPC_BA16
:
1095 return &xcoff_howto_table
[0x1c];
1096 case BFD_RELOC_PPC_BA26
:
1097 return &xcoff_howto_table
[8];
1098 case BFD_RELOC_PPC_TOC16
:
1099 return &xcoff_howto_table
[3];
1101 /* Note that this relocation is only internally used by gas. */
1102 return &xcoff_howto_table
[0xc];
1103 case BFD_RELOC_PPC_B16
:
1104 return &xcoff_howto_table
[0x1d];
1106 case BFD_RELOC_CTOR
:
1107 return &xcoff_howto_table
[0];
1108 case BFD_RELOC_NONE
:
1109 return &xcoff_howto_table
[0xf];
1115 static reloc_howto_type
*
1116 _bfd_xcoff_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1122 i
< sizeof (xcoff_howto_table
) / sizeof (xcoff_howto_table
[0]);
1124 if (xcoff_howto_table
[i
].name
!= NULL
1125 && strcasecmp (xcoff_howto_table
[i
].name
, r_name
) == 0)
1126 return &xcoff_howto_table
[i
];
1131 /* XCOFF archive support. The original version of this code was by
1132 Damon A. Permezel. It was enhanced to permit cross support, and
1133 writing archive files, by Ian Lance Taylor, Cygnus Support.
1135 XCOFF uses its own archive format. Everything is hooked together
1136 with file offset links, so it is possible to rapidly update an
1137 archive in place. Of course, we don't do that. An XCOFF archive
1138 has a real file header, not just an ARMAG string. The structure of
1139 the file header and of each archive header appear below.
1141 An XCOFF archive also has a member table, which is a list of
1142 elements in the archive (you can get that by looking through the
1143 linked list, but you have to read a lot more of the file). The
1144 member table has a normal archive header with an empty name. It is
1145 normally (and perhaps must be) the second to last entry in the
1146 archive. The member table data is almost printable ASCII. It
1147 starts with a 12 character decimal string which is the number of
1148 entries in the table. For each entry it has a 12 character decimal
1149 string which is the offset in the archive of that member. These
1150 entries are followed by a series of null terminated strings which
1151 are the member names for each entry.
1153 Finally, an XCOFF archive has a global symbol table, which is what
1154 we call the armap. The global symbol table has a normal archive
1155 header with an empty name. It is normally (and perhaps must be)
1156 the last entry in the archive. The contents start with a four byte
1157 binary number which is the number of entries. This is followed by
1158 a that many four byte binary numbers; each is the file offset of an
1159 entry in the archive. These numbers are followed by a series of
1160 null terminated strings, which are symbol names.
1162 AIX 4.3 introduced a new archive format which can handle larger
1163 files and also 32- and 64-bit objects in the same archive. The
1164 things said above remain true except that there is now more than
1165 one global symbol table. The one is used to index 32-bit objects,
1166 the other for 64-bit objects.
1168 The new archives (recognizable by the new ARMAG string) has larger
1169 field lengths so that we cannot really share any code. Also we have
1170 to take care that we are not generating the new form of archives
1171 on AIX 4.2 or earlier systems. */
1173 /* XCOFF archives use this as a magic string. Note that both strings
1174 have the same length. */
1176 /* Set the magic for archive. */
1179 bfd_xcoff_ar_archive_set_magic (bfd
*abfd ATTRIBUTE_UNUSED
,
1180 char *magic ATTRIBUTE_UNUSED
)
1182 /* Not supported yet. */
1184 /* bfd_xcoff_archive_set_magic (abfd, magic); */
1187 /* PR 21786: The PE/COFF standard does not require NUL termination for any of
1188 the ASCII fields in the archive headers. So in order to be able to extract
1189 numerical values we provide our own versions of strtol and strtoll which
1190 take a maximum length as an additional parameter. Also - just to save space,
1191 we omit the endptr return parameter, since we know that it is never used. */
1194 _bfd_strntol (const char * nptr
, int base
, unsigned int maxlen
)
1196 char buf
[24]; /* Should be enough. */
1198 BFD_ASSERT (maxlen
< (sizeof (buf
) - 1));
1200 memcpy (buf
, nptr
, maxlen
);
1202 return strtol (buf
, NULL
, base
);
1206 _bfd_strntoll (const char * nptr
, int base
, unsigned int maxlen
)
1208 char buf
[32]; /* Should be enough. */
1210 BFD_ASSERT (maxlen
< (sizeof (buf
) - 1));
1212 memcpy (buf
, nptr
, maxlen
);
1214 return strtoll (buf
, NULL
, base
);
1217 /* Macro to read an ASCII value stored in an archive header field. */
1218 #define GET_VALUE_IN_FIELD(VAR, FIELD) \
1221 (VAR) = sizeof (VAR) > sizeof (long) \
1222 ? _bfd_strntoll (FIELD, 10, sizeof FIELD) \
1223 : _bfd_strntol (FIELD, 10, sizeof FIELD); \
1227 #define EQ_VALUE_IN_FIELD(VAR, FIELD) \
1228 (sizeof (VAR) > sizeof (long) \
1229 ? (VAR) ==_bfd_strntoll (FIELD, 10, sizeof FIELD) \
1230 : (VAR) == _bfd_strntol (FIELD, 10, sizeof FIELD))
1232 /* Read in the armap of an XCOFF archive. */
1235 _bfd_xcoff_slurp_armap (bfd
*abfd
)
1240 bfd_byte
*contents
, *cend
;
1245 if (xcoff_ardata (abfd
) == NULL
)
1247 bfd_has_map (abfd
) = FALSE
;
1251 if (! xcoff_big_format_p (abfd
))
1253 /* This is for the old format. */
1254 struct xcoff_ar_hdr hdr
;
1256 GET_VALUE_IN_FIELD (off
, xcoff_ardata (abfd
)->symoff
);
1259 bfd_has_map (abfd
) = FALSE
;
1263 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0)
1266 /* The symbol table starts with a normal archive header. */
1267 if (bfd_bread (&hdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1271 /* Skip the name (normally empty). */
1272 GET_VALUE_IN_FIELD (namlen
, hdr
.namlen
);
1273 off
= ((namlen
+ 1) & ~ (size_t) 1) + SXCOFFARFMAG
;
1274 if (bfd_seek (abfd
, off
, SEEK_CUR
) != 0)
1277 GET_VALUE_IN_FIELD (sz
, hdr
.size
);
1279 /* Read in the entire symbol table. */
1280 contents
= (bfd_byte
*) bfd_alloc (abfd
, sz
);
1281 if (contents
== NULL
)
1283 if (bfd_bread (contents
, sz
, abfd
) != sz
)
1286 /* The symbol table starts with a four byte count. */
1287 c
= H_GET_32 (abfd
, contents
);
1291 bfd_set_error (bfd_error_bad_value
);
1295 bfd_ardata (abfd
)->symdefs
=
1296 ((carsym
*) bfd_alloc (abfd
, c
* sizeof (carsym
)));
1297 if (bfd_ardata (abfd
)->symdefs
== NULL
)
1300 /* After the count comes a list of four byte file offsets. */
1301 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
, p
= contents
+ 4;
1303 ++i
, ++arsym
, p
+= 4)
1304 arsym
->file_offset
= H_GET_32 (abfd
, p
);
1308 /* This is for the new format. */
1309 struct xcoff_ar_hdr_big hdr
;
1311 GET_VALUE_IN_FIELD (off
, xcoff_ardata_big (abfd
)->symoff
);
1314 bfd_has_map (abfd
) = FALSE
;
1318 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0)
1321 /* The symbol table starts with a normal archive header. */
1322 if (bfd_bread (&hdr
, (bfd_size_type
) SIZEOF_AR_HDR_BIG
, abfd
)
1323 != SIZEOF_AR_HDR_BIG
)
1326 /* Skip the name (normally empty). */
1327 GET_VALUE_IN_FIELD (namlen
, hdr
.namlen
);
1328 off
= ((namlen
+ 1) & ~ (size_t) 1) + SXCOFFARFMAG
;
1329 if (bfd_seek (abfd
, off
, SEEK_CUR
) != 0)
1332 GET_VALUE_IN_FIELD (sz
, hdr
.size
);
1334 /* Read in the entire symbol table. */
1335 contents
= (bfd_byte
*) bfd_alloc (abfd
, sz
);
1336 if (contents
== NULL
)
1338 if (bfd_bread (contents
, sz
, abfd
) != sz
)
1341 /* The symbol table starts with an eight byte count. */
1342 c
= H_GET_64 (abfd
, contents
);
1346 bfd_set_error (bfd_error_bad_value
);
1350 bfd_ardata (abfd
)->symdefs
=
1351 ((carsym
*) bfd_alloc (abfd
, c
* sizeof (carsym
)));
1352 if (bfd_ardata (abfd
)->symdefs
== NULL
)
1355 /* After the count comes a list of eight byte file offsets. */
1356 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
, p
= contents
+ 8;
1358 ++i
, ++arsym
, p
+= 8)
1359 arsym
->file_offset
= H_GET_64 (abfd
, p
);
1362 /* After the file offsets come null terminated symbol names. */
1363 cend
= contents
+ sz
;
1364 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
;
1366 ++i
, ++arsym
, p
+= strlen ((char *) p
) + 1)
1370 bfd_set_error (bfd_error_bad_value
);
1373 arsym
->name
= (char *) p
;
1376 bfd_ardata (abfd
)->symdef_count
= c
;
1377 bfd_has_map (abfd
) = TRUE
;
1382 /* See if this is an XCOFF archive. */
1385 _bfd_xcoff_archive_p (bfd
*abfd
)
1387 struct artdata
*tdata_hold
;
1388 char magic
[SXCOFFARMAG
];
1389 bfd_size_type amt
= SXCOFFARMAG
;
1391 if (bfd_bread (magic
, amt
, abfd
) != amt
)
1393 if (bfd_get_error () != bfd_error_system_call
)
1394 bfd_set_error (bfd_error_wrong_format
);
1398 if (strncmp (magic
, XCOFFARMAG
, SXCOFFARMAG
) != 0
1399 && strncmp (magic
, XCOFFARMAGBIG
, SXCOFFARMAG
) != 0)
1401 bfd_set_error (bfd_error_wrong_format
);
1405 tdata_hold
= bfd_ardata (abfd
);
1407 amt
= sizeof (struct artdata
);
1408 bfd_ardata (abfd
) = (struct artdata
*) bfd_zalloc (abfd
, amt
);
1409 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
1410 goto error_ret_restore
;
1412 /* Cleared by bfd_zalloc above.
1413 bfd_ardata (abfd)->cache = NULL;
1414 bfd_ardata (abfd)->archive_head = NULL;
1415 bfd_ardata (abfd)->symdefs = NULL;
1416 bfd_ardata (abfd)->extended_names = NULL;
1417 bfd_ardata (abfd)->extended_names_size = 0; */
1419 /* Now handle the two formats. */
1420 if (magic
[1] != 'b')
1422 /* This is the old format. */
1423 struct xcoff_ar_file_hdr hdr
;
1425 /* Copy over the magic string. */
1426 memcpy (hdr
.magic
, magic
, SXCOFFARMAG
);
1428 /* Now read the rest of the file header. */
1429 amt
= SIZEOF_AR_FILE_HDR
- SXCOFFARMAG
;
1430 if (bfd_bread (&hdr
.memoff
, amt
, abfd
) != amt
)
1432 if (bfd_get_error () != bfd_error_system_call
)
1433 bfd_set_error (bfd_error_wrong_format
);
1437 GET_VALUE_IN_FIELD (bfd_ardata (abfd
)->first_file_filepos
,
1440 amt
= SIZEOF_AR_FILE_HDR
;
1441 bfd_ardata (abfd
)->tdata
= bfd_zalloc (abfd
, amt
);
1442 if (bfd_ardata (abfd
)->tdata
== NULL
)
1445 memcpy (bfd_ardata (abfd
)->tdata
, &hdr
, SIZEOF_AR_FILE_HDR
);
1449 /* This is the new format. */
1450 struct xcoff_ar_file_hdr_big hdr
;
1452 /* Copy over the magic string. */
1453 memcpy (hdr
.magic
, magic
, SXCOFFARMAG
);
1455 /* Now read the rest of the file header. */
1456 amt
= SIZEOF_AR_FILE_HDR_BIG
- SXCOFFARMAG
;
1457 if (bfd_bread (&hdr
.memoff
, amt
, abfd
) != amt
)
1459 if (bfd_get_error () != bfd_error_system_call
)
1460 bfd_set_error (bfd_error_wrong_format
);
1464 bfd_ardata (abfd
)->first_file_filepos
= bfd_scan_vma (hdr
.firstmemoff
,
1468 amt
= SIZEOF_AR_FILE_HDR_BIG
;
1469 bfd_ardata (abfd
)->tdata
= bfd_zalloc (abfd
, amt
);
1470 if (bfd_ardata (abfd
)->tdata
== NULL
)
1473 memcpy (bfd_ardata (abfd
)->tdata
, &hdr
, SIZEOF_AR_FILE_HDR_BIG
);
1476 if (! _bfd_xcoff_slurp_armap (abfd
))
1479 bfd_release (abfd
, bfd_ardata (abfd
));
1481 bfd_ardata (abfd
) = tdata_hold
;
1488 /* Read the archive header in an XCOFF archive. */
1491 _bfd_xcoff_read_ar_hdr (bfd
*abfd
)
1493 bfd_size_type namlen
;
1494 struct areltdata
*ret
;
1495 bfd_size_type amt
= sizeof (struct areltdata
);
1497 ret
= (struct areltdata
*) bfd_zmalloc (amt
);
1501 if (! xcoff_big_format_p (abfd
))
1503 struct xcoff_ar_hdr hdr
;
1504 struct xcoff_ar_hdr
*hdrp
;
1506 if (bfd_bread (&hdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1513 GET_VALUE_IN_FIELD (namlen
, hdr
.namlen
);
1514 amt
= SIZEOF_AR_HDR
+ namlen
+ 1;
1515 hdrp
= (struct xcoff_ar_hdr
*) bfd_alloc (abfd
, amt
);
1521 memcpy (hdrp
, &hdr
, SIZEOF_AR_HDR
);
1522 if (bfd_bread ((char *) hdrp
+ SIZEOF_AR_HDR
, namlen
, abfd
) != namlen
)
1527 ((char *) hdrp
)[SIZEOF_AR_HDR
+ namlen
] = '\0';
1529 ret
->arch_header
= (char *) hdrp
;
1530 GET_VALUE_IN_FIELD (ret
->parsed_size
, hdr
.size
);
1531 ret
->filename
= (char *) hdrp
+ SIZEOF_AR_HDR
;
1535 struct xcoff_ar_hdr_big hdr
;
1536 struct xcoff_ar_hdr_big
*hdrp
;
1538 if (bfd_bread (&hdr
, (bfd_size_type
) SIZEOF_AR_HDR_BIG
, abfd
)
1539 != SIZEOF_AR_HDR_BIG
)
1545 GET_VALUE_IN_FIELD (namlen
, hdr
.namlen
);
1546 amt
= SIZEOF_AR_HDR_BIG
+ namlen
+ 1;
1547 hdrp
= (struct xcoff_ar_hdr_big
*) bfd_alloc (abfd
, amt
);
1553 memcpy (hdrp
, &hdr
, SIZEOF_AR_HDR_BIG
);
1554 if (bfd_bread ((char *) hdrp
+ SIZEOF_AR_HDR_BIG
, namlen
, abfd
) != namlen
)
1559 ((char *) hdrp
)[SIZEOF_AR_HDR_BIG
+ namlen
] = '\0';
1561 ret
->arch_header
= (char *) hdrp
;
1562 GET_VALUE_IN_FIELD (ret
->parsed_size
, hdr
.size
);
1563 ret
->filename
= (char *) hdrp
+ SIZEOF_AR_HDR_BIG
;
1566 /* Skip over the XCOFFARFMAG at the end of the file name. */
1567 if (bfd_seek (abfd
, (file_ptr
) ((namlen
& 1) + SXCOFFARFMAG
), SEEK_CUR
) != 0)
1573 /* Open the next element in an XCOFF archive. */
1576 _bfd_xcoff_openr_next_archived_file (bfd
*archive
, bfd
*last_file
)
1580 if (xcoff_ardata (archive
) == NULL
)
1582 bfd_set_error (bfd_error_invalid_operation
);
1586 if (! xcoff_big_format_p (archive
))
1588 if (last_file
== NULL
)
1589 filestart
= bfd_ardata (archive
)->first_file_filepos
;
1591 GET_VALUE_IN_FIELD (filestart
, arch_xhdr (last_file
)->nextoff
);
1594 || EQ_VALUE_IN_FIELD (filestart
, xcoff_ardata (archive
)->memoff
)
1595 || EQ_VALUE_IN_FIELD (filestart
, xcoff_ardata (archive
)->symoff
))
1597 bfd_set_error (bfd_error_no_more_archived_files
);
1603 if (last_file
== NULL
)
1604 filestart
= bfd_ardata (archive
)->first_file_filepos
;
1606 GET_VALUE_IN_FIELD (filestart
, arch_xhdr_big (last_file
)->nextoff
);
1609 || EQ_VALUE_IN_FIELD (filestart
, xcoff_ardata_big (archive
)->memoff
)
1610 || EQ_VALUE_IN_FIELD (filestart
, xcoff_ardata_big (archive
)->symoff
))
1612 bfd_set_error (bfd_error_no_more_archived_files
);
1617 return _bfd_get_elt_at_filepos (archive
, filestart
);
1620 /* Stat an element in an XCOFF archive. */
1623 _bfd_xcoff_stat_arch_elt (bfd
*abfd
, struct stat
*s
)
1625 if (abfd
->arelt_data
== NULL
)
1627 bfd_set_error (bfd_error_invalid_operation
);
1631 if (! xcoff_big_format_p (abfd
->my_archive
))
1633 struct xcoff_ar_hdr
*hdrp
= arch_xhdr (abfd
);
1635 GET_VALUE_IN_FIELD (s
->st_mtime
, hdrp
->date
);
1636 GET_VALUE_IN_FIELD (s
->st_uid
, hdrp
->uid
);
1637 GET_VALUE_IN_FIELD (s
->st_gid
, hdrp
->gid
);
1638 GET_VALUE_IN_FIELD (s
->st_mode
, hdrp
->mode
);
1639 s
->st_size
= arch_eltdata (abfd
)->parsed_size
;
1643 struct xcoff_ar_hdr_big
*hdrp
= arch_xhdr_big (abfd
);
1645 GET_VALUE_IN_FIELD (s
->st_mtime
, hdrp
->date
);
1646 GET_VALUE_IN_FIELD (s
->st_uid
, hdrp
->uid
);
1647 GET_VALUE_IN_FIELD (s
->st_gid
, hdrp
->gid
);
1648 GET_VALUE_IN_FIELD (s
->st_mode
, hdrp
->mode
);
1649 s
->st_size
= arch_eltdata (abfd
)->parsed_size
;
1655 /* Normalize a file name for inclusion in an archive. */
1658 normalize_filename (bfd
*abfd
)
1661 const char *filename
;
1663 file
= bfd_get_filename (abfd
);
1664 filename
= strrchr (file
, '/');
1665 if (filename
!= NULL
)
1672 /* Write out an XCOFF armap. */
1675 xcoff_write_armap_old (bfd
*abfd
, unsigned int elength ATTRIBUTE_UNUSED
,
1676 struct orl
*map
, unsigned int orl_count
, int stridx
)
1678 struct archive_iterator iterator
;
1679 struct xcoff_ar_hdr hdr
;
1681 unsigned char buf
[4];
1684 memset (&hdr
, 0, sizeof hdr
);
1685 sprintf (hdr
.size
, "%ld", (long) (4 + orl_count
* 4 + stridx
));
1686 sprintf (hdr
.nextoff
, "%d", 0);
1687 memcpy (hdr
.prevoff
, xcoff_ardata (abfd
)->memoff
, XCOFFARMAG_ELEMENT_SIZE
);
1688 sprintf (hdr
.date
, "%d", 0);
1689 sprintf (hdr
.uid
, "%d", 0);
1690 sprintf (hdr
.gid
, "%d", 0);
1691 sprintf (hdr
.mode
, "%d", 0);
1692 sprintf (hdr
.namlen
, "%d", 0);
1694 /* We need spaces, not null bytes, in the header. */
1695 for (p
= (char *) &hdr
; p
< (char *) &hdr
+ SIZEOF_AR_HDR
; p
++)
1699 if (bfd_bwrite (&hdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1701 || (bfd_bwrite (XCOFFARFMAG
, (bfd_size_type
) SXCOFFARFMAG
, abfd
)
1705 H_PUT_32 (abfd
, orl_count
, buf
);
1706 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
1710 archive_iterator_begin (&iterator
, abfd
);
1711 while (i
< orl_count
&& archive_iterator_next (&iterator
))
1712 while (map
[i
].u
.abfd
== iterator
.current
.member
)
1714 H_PUT_32 (abfd
, iterator
.current
.offset
, buf
);
1715 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
1720 for (i
= 0; i
< orl_count
; i
++)
1725 name
= *map
[i
].name
;
1726 namlen
= strlen (name
);
1727 if (bfd_bwrite (name
, (bfd_size_type
) (namlen
+ 1), abfd
) != namlen
+ 1)
1731 if ((stridx
& 1) != 0)
1736 if (bfd_bwrite (&b
, (bfd_size_type
) 1, abfd
) != 1)
1743 static char buff20
[XCOFFARMAGBIG_ELEMENT_SIZE
+ 1];
1744 #if BFD_HOST_64BIT_LONG
1745 #define FMT20 "%-20ld"
1746 #elif defined (__MSVCRT__)
1747 #define FMT20 "%-20I64d"
1749 #define FMT20 "%-20lld"
1751 #define FMT12 "%-12d"
1752 #define FMT12_OCTAL "%-12o"
1754 #define PRINT20(d, v) \
1755 sprintf (buff20, FMT20, (bfd_uint64_t)(v)), \
1756 memcpy ((void *) (d), buff20, 20)
1758 #define PRINT12(d, v) \
1759 sprintf (buff20, FMT12, (int)(v)), \
1760 memcpy ((void *) (d), buff20, 12)
1762 #define PRINT12_OCTAL(d, v) \
1763 sprintf (buff20, FMT12_OCTAL, (unsigned int)(v)), \
1764 memcpy ((void *) (d), buff20, 12)
1766 #define PRINT4(d, v) \
1767 sprintf (buff20, FMT4, (int)(v)), \
1768 memcpy ((void *) (d), buff20, 4)
1770 #define READ20(d, v) \
1772 memcpy (buff20, (d), 20), \
1773 (v) = bfd_scan_vma (buff20, (const char **) NULL, 10)
1776 do_pad (bfd
*abfd
, unsigned int number
)
1780 /* Limit pad to <= 4096. */
1785 if (bfd_bwrite (&b
, (bfd_size_type
) 1, abfd
) != 1)
1792 do_copy (bfd
*out_bfd
, bfd
*in_bfd
)
1794 bfd_size_type remaining
;
1795 bfd_byte buffer
[DEFAULT_BUFFERSIZE
];
1797 if (bfd_seek (in_bfd
, (file_ptr
) 0, SEEK_SET
) != 0)
1800 remaining
= arelt_size (in_bfd
);
1802 while (remaining
>= DEFAULT_BUFFERSIZE
)
1804 if (bfd_bread (buffer
, DEFAULT_BUFFERSIZE
, in_bfd
) != DEFAULT_BUFFERSIZE
1805 || bfd_bwrite (buffer
, DEFAULT_BUFFERSIZE
, out_bfd
) != DEFAULT_BUFFERSIZE
)
1808 remaining
-= DEFAULT_BUFFERSIZE
;
1813 if (bfd_bread (buffer
, remaining
, in_bfd
) != remaining
1814 || bfd_bwrite (buffer
, remaining
, out_bfd
) != remaining
)
1822 xcoff_write_armap_big (bfd
*abfd
, unsigned int elength ATTRIBUTE_UNUSED
,
1823 struct orl
*map
, unsigned int orl_count
, int stridx
)
1825 struct archive_iterator iterator
;
1826 struct xcoff_ar_file_hdr_big
*fhdr
;
1827 bfd_vma i
, sym_32
, sym_64
, str_32
, str_64
;
1828 const bfd_arch_info_type
*arch_info
;
1830 size_t string_length
;
1831 file_ptr nextoff
, prevoff
;
1833 /* First, we look through the symbols and work out which are
1834 from 32-bit objects and which from 64-bit ones. */
1835 sym_32
= sym_64
= str_32
= str_64
= 0;
1838 for (current_bfd
= abfd
->archive_head
;
1839 current_bfd
!= NULL
&& i
< orl_count
;
1840 current_bfd
= current_bfd
->archive_next
)
1842 arch_info
= bfd_get_arch_info (current_bfd
);
1843 while (map
[i
].u
.abfd
== current_bfd
)
1845 string_length
= strlen (*map
[i
].name
) + 1;
1846 if (arch_info
->bits_per_address
== 64)
1849 str_64
+= string_length
;
1854 str_32
+= string_length
;
1860 /* A quick sanity check... */
1861 BFD_ASSERT (sym_64
+ sym_32
== orl_count
);
1862 /* Explicit cast to int for compiler. */
1863 BFD_ASSERT ((int)(str_64
+ str_32
) == stridx
);
1865 fhdr
= xcoff_ardata_big (abfd
);
1867 /* xcoff_write_archive_contents_big passes nextoff in symoff. */
1868 READ20 (fhdr
->memoff
, prevoff
);
1869 READ20 (fhdr
->symoff
, nextoff
);
1871 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
1873 /* Write out the symbol table.
1876 standard big archive header
1877 0x0000 ar_size [0x14]
1878 0x0014 ar_nxtmem [0x14]
1879 0x0028 ar_prvmem [0x14]
1880 0x003C ar_date [0x0C]
1881 0x0048 ar_uid [0x0C]
1882 0x0054 ar_gid [0x0C]
1883 0x0060 ar_mod [0x0C]
1884 0x006C ar_namelen[0x04]
1885 0x0070 ar_fmag [SXCOFFARFMAG]
1888 0x0072 num_syms [0x08], binary
1889 0x0078 offsets [0x08 * num_syms], binary
1890 0x0086 + 0x08 * num_syms names [??]
1891 ?? pad to even bytes.
1896 struct xcoff_ar_hdr_big
*hdr
;
1900 bfd_vma symbol_table_size
=
1905 + str_32
+ (str_32
& 1);
1907 symbol_table
= bfd_zmalloc (symbol_table_size
);
1908 if (symbol_table
== NULL
)
1911 hdr
= (struct xcoff_ar_hdr_big
*) symbol_table
;
1913 PRINT20 (hdr
->size
, 8 + 8 * sym_32
+ str_32
+ (str_32
& 1));
1916 PRINT20 (hdr
->nextoff
, nextoff
+ symbol_table_size
);
1918 PRINT20 (hdr
->nextoff
, 0);
1920 PRINT20 (hdr
->prevoff
, prevoff
);
1921 PRINT12 (hdr
->date
, 0);
1922 PRINT12 (hdr
->uid
, 0);
1923 PRINT12 (hdr
->gid
, 0);
1924 PRINT12 (hdr
->mode
, 0);
1925 PRINT4 (hdr
->namlen
, 0) ;
1927 st
= symbol_table
+ SIZEOF_AR_HDR_BIG
;
1928 memcpy (st
, XCOFFARFMAG
, SXCOFFARFMAG
);
1931 bfd_h_put_64 (abfd
, sym_32
, st
);
1934 /* loop over the 32 bit offsets */
1936 archive_iterator_begin (&iterator
, abfd
);
1937 while (i
< orl_count
&& archive_iterator_next (&iterator
))
1939 arch_info
= bfd_get_arch_info (iterator
.current
.member
);
1940 while (map
[i
].u
.abfd
== iterator
.current
.member
)
1942 if (arch_info
->bits_per_address
== 32)
1944 bfd_h_put_64 (abfd
, iterator
.current
.offset
, st
);
1951 /* loop over the 32 bit symbol names */
1953 for (current_bfd
= abfd
->archive_head
;
1954 current_bfd
!= NULL
&& i
< orl_count
;
1955 current_bfd
= current_bfd
->archive_next
)
1957 arch_info
= bfd_get_arch_info (current_bfd
);
1958 while (map
[i
].u
.abfd
== current_bfd
)
1960 if (arch_info
->bits_per_address
== 32)
1962 string_length
= sprintf (st
, "%s", *map
[i
].name
);
1963 st
+= string_length
+ 1;
1969 bfd_bwrite (symbol_table
, symbol_table_size
, abfd
);
1971 free (symbol_table
);
1974 nextoff
= nextoff
+ symbol_table_size
;
1977 PRINT20 (fhdr
->symoff
, 0);
1981 struct xcoff_ar_hdr_big
*hdr
;
1985 bfd_vma symbol_table_size
=
1990 + str_64
+ (str_64
& 1);
1992 symbol_table
= bfd_zmalloc (symbol_table_size
);
1993 if (symbol_table
== NULL
)
1996 hdr
= (struct xcoff_ar_hdr_big
*) symbol_table
;
1998 PRINT20 (hdr
->size
, 8 + 8 * sym_64
+ str_64
+ (str_64
& 1));
1999 PRINT20 (hdr
->nextoff
, 0);
2000 PRINT20 (hdr
->prevoff
, prevoff
);
2001 PRINT12 (hdr
->date
, 0);
2002 PRINT12 (hdr
->uid
, 0);
2003 PRINT12 (hdr
->gid
, 0);
2004 PRINT12 (hdr
->mode
, 0);
2005 PRINT4 (hdr
->namlen
, 0);
2007 st
= symbol_table
+ SIZEOF_AR_HDR_BIG
;
2008 memcpy (st
, XCOFFARFMAG
, SXCOFFARFMAG
);
2011 bfd_h_put_64 (abfd
, sym_64
, st
);
2014 /* loop over the 64 bit offsets */
2016 archive_iterator_begin (&iterator
, abfd
);
2017 while (i
< orl_count
&& archive_iterator_next (&iterator
))
2019 arch_info
= bfd_get_arch_info (iterator
.current
.member
);
2020 while (map
[i
].u
.abfd
== iterator
.current
.member
)
2022 if (arch_info
->bits_per_address
== 64)
2024 bfd_h_put_64 (abfd
, iterator
.current
.offset
, st
);
2031 /* loop over the 64 bit symbol names */
2033 for (current_bfd
= abfd
->archive_head
;
2034 current_bfd
!= NULL
&& i
< orl_count
;
2035 current_bfd
= current_bfd
->archive_next
)
2037 arch_info
= bfd_get_arch_info (current_bfd
);
2038 while (map
[i
].u
.abfd
== current_bfd
)
2040 if (arch_info
->bits_per_address
== 64)
2042 string_length
= sprintf (st
, "%s", *map
[i
].name
);
2043 st
+= string_length
+ 1;
2049 bfd_bwrite (symbol_table
, symbol_table_size
, abfd
);
2051 free (symbol_table
);
2053 PRINT20 (fhdr
->symoff64
, nextoff
);
2056 PRINT20 (fhdr
->symoff64
, 0);
2062 _bfd_xcoff_write_armap (bfd
*abfd
, unsigned int elength ATTRIBUTE_UNUSED
,
2063 struct orl
*map
, unsigned int orl_count
, int stridx
)
2065 if (! xcoff_big_format_p (abfd
))
2066 return xcoff_write_armap_old (abfd
, elength
, map
, orl_count
, stridx
);
2068 return xcoff_write_armap_big (abfd
, elength
, map
, orl_count
, stridx
);
2071 /* Write out an XCOFF archive. We always write an entire archive,
2072 rather than fussing with the freelist and so forth. */
2075 xcoff_write_archive_contents_old (bfd
*abfd
)
2077 struct archive_iterator iterator
;
2078 struct xcoff_ar_file_hdr fhdr
;
2079 bfd_size_type count
;
2080 bfd_size_type total_namlen
;
2082 bfd_boolean makemap
;
2083 bfd_boolean hasobjects
;
2084 file_ptr prevoff
, nextoff
;
2087 struct xcoff_ar_hdr ahdr
;
2090 char decbuf
[XCOFFARMAG_ELEMENT_SIZE
+ 1];
2092 memset (&fhdr
, 0, sizeof fhdr
);
2093 (void) strncpy (fhdr
.magic
, XCOFFARMAG
, SXCOFFARMAG
);
2094 sprintf (fhdr
.firstmemoff
, "%d", SIZEOF_AR_FILE_HDR
);
2095 sprintf (fhdr
.freeoff
, "%d", 0);
2099 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->archive_next
)
2102 total_namlen
+= strlen (normalize_filename (sub
)) + 1;
2103 if (sub
->arelt_data
== NULL
)
2105 sub
->arelt_data
= bfd_zmalloc (sizeof (struct areltdata
));
2106 if (sub
->arelt_data
== NULL
)
2109 if (arch_xhdr (sub
) == NULL
)
2111 struct xcoff_ar_hdr
*ahdrp
;
2114 if (stat (bfd_get_filename (sub
), &s
) != 0)
2116 bfd_set_error (bfd_error_system_call
);
2120 ahdrp
= bfd_zalloc (sub
, sizeof (*ahdrp
));
2124 sprintf (ahdrp
->size
, "%ld", (long) s
.st_size
);
2125 sprintf (ahdrp
->date
, "%ld", (long) s
.st_mtime
);
2126 sprintf (ahdrp
->uid
, "%ld", (long) s
.st_uid
);
2127 sprintf (ahdrp
->gid
, "%ld", (long) s
.st_gid
);
2128 sprintf (ahdrp
->mode
, "%o", (unsigned int) s
.st_mode
);
2130 arch_eltdata (sub
)->arch_header
= (char *) ahdrp
;
2131 arch_eltdata (sub
)->parsed_size
= s
.st_size
;
2134 offsets
= (file_ptr
*) bfd_alloc (abfd
, count
* sizeof (file_ptr
));
2135 if (offsets
== NULL
)
2138 if (bfd_seek (abfd
, (file_ptr
) SIZEOF_AR_FILE_HDR
, SEEK_SET
) != 0)
2141 makemap
= bfd_has_map (abfd
);
2144 for (archive_iterator_begin (&iterator
, abfd
), i
= 0;
2145 archive_iterator_next (&iterator
);
2148 bfd_size_type namlen
;
2149 struct xcoff_ar_hdr
*ahdrp
;
2151 if (makemap
&& ! hasobjects
)
2153 if (bfd_check_format (iterator
.current
.member
, bfd_object
))
2157 ahdrp
= arch_xhdr (iterator
.current
.member
);
2158 sprintf (ahdrp
->prevoff
, "%ld", (long) prevoff
);
2159 sprintf (ahdrp
->namlen
, "%ld", (long) iterator
.current
.namlen
);
2160 sprintf (ahdrp
->nextoff
, "%ld", (long) iterator
.next
.offset
);
2162 /* We need spaces, not null bytes, in the header. */
2163 for (p
= (char *) ahdrp
; p
< (char *) ahdrp
+ SIZEOF_AR_HDR
; p
++)
2167 if (!do_pad (abfd
, iterator
.current
.leading_padding
))
2170 BFD_ASSERT (iterator
.current
.offset
== bfd_tell (abfd
));
2171 namlen
= iterator
.current
.padded_namlen
;
2172 if (bfd_bwrite (ahdrp
, SIZEOF_AR_HDR
, abfd
) != SIZEOF_AR_HDR
2173 || bfd_bwrite (iterator
.current
.name
, namlen
, abfd
) != namlen
2174 || bfd_bwrite (XCOFFARFMAG
, SXCOFFARFMAG
, abfd
) != SXCOFFARFMAG
2175 || bfd_seek (iterator
.current
.member
, 0, SEEK_SET
) != 0
2176 || !do_copy (abfd
, iterator
.current
.member
)
2177 || !do_pad (abfd
, iterator
.current
.trailing_padding
))
2180 offsets
[i
] = iterator
.current
.offset
;
2181 prevoff
= iterator
.current
.offset
;
2184 sprintf (fhdr
.lastmemoff
, "%ld", (long) prevoff
);
2186 /* Write out the member table. */
2188 nextoff
= iterator
.next
.offset
;
2189 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2190 sprintf (fhdr
.memoff
, "%ld", (long) nextoff
);
2192 memset (&ahdr
, 0, sizeof ahdr
);
2193 sprintf (ahdr
.size
, "%ld", (long) (XCOFFARMAG_ELEMENT_SIZE
2194 + count
* XCOFFARMAG_ELEMENT_SIZE
2196 sprintf (ahdr
.prevoff
, "%ld", (long) prevoff
);
2197 sprintf (ahdr
.date
, "%d", 0);
2198 sprintf (ahdr
.uid
, "%d", 0);
2199 sprintf (ahdr
.gid
, "%d", 0);
2200 sprintf (ahdr
.mode
, "%d", 0);
2201 sprintf (ahdr
.namlen
, "%d", 0);
2203 size
= (SIZEOF_AR_HDR
2204 + XCOFFARMAG_ELEMENT_SIZE
2205 + count
* XCOFFARMAG_ELEMENT_SIZE
2210 nextoff
+= size
+ (size
& 1);
2212 if (makemap
&& hasobjects
)
2213 sprintf (ahdr
.nextoff
, "%ld", (long) nextoff
);
2215 sprintf (ahdr
.nextoff
, "%d", 0);
2217 /* We need spaces, not null bytes, in the header. */
2218 for (p
= (char *) &ahdr
; p
< (char *) &ahdr
+ SIZEOF_AR_HDR
; p
++)
2222 if ((bfd_bwrite (&ahdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
2224 || (bfd_bwrite (XCOFFARFMAG
, (bfd_size_type
) SXCOFFARFMAG
, abfd
)
2228 sprintf (decbuf
, "%-12ld", (long) count
);
2229 if (bfd_bwrite (decbuf
, (bfd_size_type
) XCOFFARMAG_ELEMENT_SIZE
, abfd
)
2230 != XCOFFARMAG_ELEMENT_SIZE
)
2232 for (i
= 0; i
< (size_t) count
; i
++)
2234 sprintf (decbuf
, "%-12ld", (long) offsets
[i
]);
2235 if (bfd_bwrite (decbuf
, (bfd_size_type
) XCOFFARMAG_ELEMENT_SIZE
,
2236 abfd
) != XCOFFARMAG_ELEMENT_SIZE
)
2239 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->archive_next
)
2242 bfd_size_type namlen
;
2244 name
= normalize_filename (sub
);
2245 namlen
= strlen (name
);
2246 if (bfd_bwrite (name
, namlen
+ 1, abfd
) != namlen
+ 1)
2250 if (! do_pad (abfd
, size
& 1))
2253 /* Write out the armap, if appropriate. */
2254 if (! makemap
|| ! hasobjects
)
2255 sprintf (fhdr
.symoff
, "%d", 0);
2258 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2259 sprintf (fhdr
.symoff
, "%ld", (long) nextoff
);
2260 bfd_ardata (abfd
)->tdata
= &fhdr
;
2261 if (! _bfd_compute_and_write_armap (abfd
, 0))
2265 /* Write out the archive file header. */
2267 /* We need spaces, not null bytes, in the header. */
2268 for (p
= (char *) &fhdr
; p
< (char *) &fhdr
+ SIZEOF_AR_FILE_HDR
; p
++)
2272 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
2273 || (bfd_bwrite (&fhdr
, (bfd_size_type
) SIZEOF_AR_FILE_HDR
, abfd
)
2274 != SIZEOF_AR_FILE_HDR
))
2281 xcoff_write_archive_contents_big (bfd
*abfd
)
2283 struct xcoff_ar_file_hdr_big fhdr
;
2284 bfd_size_type count
;
2285 bfd_size_type total_namlen
;
2287 bfd_boolean makemap
;
2288 bfd_boolean hasobjects
;
2289 file_ptr prevoff
, nextoff
;
2292 struct xcoff_ar_hdr_big
*hdr
;
2294 char *member_table
, *mt
;
2295 bfd_vma member_table_size
;
2296 struct archive_iterator iterator
;
2298 memset (&fhdr
, 0, SIZEOF_AR_FILE_HDR_BIG
);
2299 memcpy (fhdr
.magic
, XCOFFARMAGBIG
, SXCOFFARMAG
);
2301 if (bfd_seek (abfd
, (file_ptr
) SIZEOF_AR_FILE_HDR_BIG
, SEEK_SET
) != 0)
2304 /* Calculate count and total_namlen. */
2305 makemap
= bfd_has_map (abfd
);
2307 for (current_bfd
= abfd
->archive_head
, count
= 0, total_namlen
= 0;
2308 current_bfd
!= NULL
;
2309 current_bfd
= current_bfd
->archive_next
, count
++)
2311 total_namlen
+= strlen (normalize_filename (current_bfd
)) + 1;
2315 && bfd_check_format (current_bfd
, bfd_object
))
2318 if (current_bfd
->arelt_data
== NULL
)
2320 size
= sizeof (struct areltdata
);
2321 current_bfd
->arelt_data
= bfd_zmalloc (size
);
2322 if (current_bfd
->arelt_data
== NULL
)
2326 if (arch_xhdr_big (current_bfd
) == NULL
)
2328 struct xcoff_ar_hdr_big
*ahdrp
;
2331 /* XXX This should actually be a call to stat64 (at least on
2333 XXX This call will fail if the original object is not found. */
2334 if (stat (bfd_get_filename (current_bfd
), &s
) != 0)
2336 bfd_set_error (bfd_error_system_call
);
2340 ahdrp
= bfd_zalloc (current_bfd
, sizeof (*ahdrp
));
2344 PRINT20 (ahdrp
->size
, s
.st_size
);
2345 PRINT12 (ahdrp
->date
, s
.st_mtime
);
2346 PRINT12 (ahdrp
->uid
, s
.st_uid
);
2347 PRINT12 (ahdrp
->gid
, s
.st_gid
);
2348 PRINT12_OCTAL (ahdrp
->mode
, s
.st_mode
);
2350 arch_eltdata (current_bfd
)->arch_header
= (char *) ahdrp
;
2351 arch_eltdata (current_bfd
)->parsed_size
= s
.st_size
;
2358 offsets
= (file_ptr
*) bfd_malloc (count
* sizeof (file_ptr
));
2359 if (offsets
== NULL
)
2364 for (archive_iterator_begin (&iterator
, abfd
), i
= 0;
2365 archive_iterator_next (&iterator
);
2368 bfd_size_type namlen
;
2369 struct xcoff_ar_hdr_big
*ahdrp
;
2371 ahdrp
= arch_xhdr_big (iterator
.current
.member
);
2372 PRINT20 (ahdrp
->prevoff
, prevoff
);
2373 PRINT4 (ahdrp
->namlen
, iterator
.current
.namlen
);
2374 PRINT20 (ahdrp
->nextoff
, iterator
.next
.offset
);
2376 if (!do_pad (abfd
, iterator
.current
.leading_padding
))
2382 BFD_ASSERT (iterator
.current
.offset
== bfd_tell (abfd
));
2383 namlen
= iterator
.current
.padded_namlen
;
2384 if (bfd_bwrite (ahdrp
, SIZEOF_AR_HDR_BIG
, abfd
) != SIZEOF_AR_HDR_BIG
2385 || bfd_bwrite (iterator
.current
.name
, namlen
, abfd
) != namlen
2386 || bfd_bwrite (XCOFFARFMAG
, SXCOFFARFMAG
, abfd
) != SXCOFFARFMAG
2387 || bfd_seek (iterator
.current
.member
, 0, SEEK_SET
) != 0
2388 || !do_copy (abfd
, iterator
.current
.member
)
2389 || !do_pad (abfd
, iterator
.current
.trailing_padding
))
2395 offsets
[i
] = iterator
.current
.offset
;
2396 prevoff
= iterator
.current
.offset
;
2401 PRINT20 (fhdr
.firstmemoff
, offsets
[0]);
2402 PRINT20 (fhdr
.lastmemoff
, prevoff
);
2405 /* Write out the member table.
2408 standard big archive header
2409 0x0000 ar_size [0x14]
2410 0x0014 ar_nxtmem [0x14]
2411 0x0028 ar_prvmem [0x14]
2412 0x003C ar_date [0x0C]
2413 0x0048 ar_uid [0x0C]
2414 0x0054 ar_gid [0x0C]
2415 0x0060 ar_mod [0x0C]
2416 0x006C ar_namelen[0x04]
2417 0x0070 ar_fmag [0x02]
2421 0x0086 offsets [0x14 * counts]
2422 0x0086 + 0x14 * counts names [??]
2423 ?? pad to even bytes.
2426 nextoff
= iterator
.next
.offset
;
2427 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2429 member_table_size
= (SIZEOF_AR_HDR_BIG
2431 + XCOFFARMAGBIG_ELEMENT_SIZE
2432 + count
* XCOFFARMAGBIG_ELEMENT_SIZE
2435 member_table_size
+= member_table_size
& 1;
2436 member_table
= bfd_zmalloc (member_table_size
);
2437 if (member_table
== NULL
)
2443 hdr
= (struct xcoff_ar_hdr_big
*) member_table
;
2445 PRINT20 (hdr
->size
, (XCOFFARMAGBIG_ELEMENT_SIZE
2446 + count
* XCOFFARMAGBIG_ELEMENT_SIZE
2447 + total_namlen
+ (total_namlen
& 1)));
2448 if (makemap
&& hasobjects
)
2449 PRINT20 (hdr
->nextoff
, nextoff
+ member_table_size
);
2451 PRINT20 (hdr
->nextoff
, 0);
2452 PRINT20 (hdr
->prevoff
, prevoff
);
2453 PRINT12 (hdr
->date
, 0);
2454 PRINT12 (hdr
->uid
, 0);
2455 PRINT12 (hdr
->gid
, 0);
2456 PRINT12 (hdr
->mode
, 0);
2457 PRINT4 (hdr
->namlen
, 0);
2459 mt
= member_table
+ SIZEOF_AR_HDR_BIG
;
2460 memcpy (mt
, XCOFFARFMAG
, SXCOFFARFMAG
);
2463 PRINT20 (mt
, count
);
2464 mt
+= XCOFFARMAGBIG_ELEMENT_SIZE
;
2465 for (i
= 0; i
< (size_t) count
; i
++)
2467 PRINT20 (mt
, offsets
[i
]);
2468 mt
+= XCOFFARMAGBIG_ELEMENT_SIZE
;
2477 for (current_bfd
= abfd
->archive_head
;
2478 current_bfd
!= NULL
;
2479 current_bfd
= current_bfd
->archive_next
)
2484 name
= normalize_filename (current_bfd
);
2485 namlen
= sprintf (mt
, "%s", name
);
2489 if (bfd_bwrite (member_table
, member_table_size
, abfd
) != member_table_size
)
2492 free (member_table
);
2494 PRINT20 (fhdr
.memoff
, nextoff
);
2497 nextoff
+= member_table_size
;
2499 /* Write out the armap, if appropriate. */
2501 if (! makemap
|| ! hasobjects
)
2502 PRINT20 (fhdr
.symoff
, 0);
2505 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2507 /* Save nextoff in fhdr.symoff so the armap routine can use it. */
2508 PRINT20 (fhdr
.symoff
, nextoff
);
2510 bfd_ardata (abfd
)->tdata
= &fhdr
;
2511 if (! _bfd_compute_and_write_armap (abfd
, 0))
2515 /* Write out the archive file header. */
2517 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
2518 || (bfd_bwrite (&fhdr
, (bfd_size_type
) SIZEOF_AR_FILE_HDR_BIG
,
2519 abfd
) != SIZEOF_AR_FILE_HDR_BIG
))
2526 _bfd_xcoff_write_archive_contents (bfd
*abfd
)
2528 if (! xcoff_big_format_p (abfd
))
2529 return xcoff_write_archive_contents_old (abfd
);
2531 return xcoff_write_archive_contents_big (abfd
);
2534 /* We can't use the usual coff_sizeof_headers routine, because AIX
2535 always uses an a.out header. */
2538 _bfd_xcoff_sizeof_headers (bfd
*abfd
,
2539 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
2544 if (xcoff_data (abfd
)->full_aouthdr
)
2547 size
+= SMALL_AOUTSZ
;
2548 size
+= abfd
->section_count
* SCNHSZ
;
2550 if (info
->strip
!= strip_all
)
2552 /* There can be additional sections just for dealing with overflow in
2553 reloc and lineno counts. But the numbers of relocs and lineno aren't
2554 known when bfd_sizeof_headers is called, so we compute them by
2555 summing the numbers from input sections. */
2556 struct nbr_reloc_lineno
2558 unsigned int reloc_count
;
2559 unsigned int lineno_count
;
2561 struct nbr_reloc_lineno
*n_rl
;
2563 unsigned int max_index
;
2566 /* Although the number of sections is known, the maximum value of
2567 section->index isn't (because some sections may have been removed).
2568 Don't try to renumber sections, just compute the upper bound. */
2570 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2571 if (s
->index
> max_index
)
2572 max_index
= s
->index
;
2574 /* Allocate the per section counters. It could be possible to use a
2575 preallocated array as the number of sections is limited on XCOFF,
2576 but this creates a maintainance issue. */
2577 n_rl
= bfd_zmalloc ((max_index
+ 1) * sizeof (*n_rl
));
2582 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link
.next
)
2583 for (s
= sub
->sections
; s
!= NULL
; s
= s
->next
)
2585 struct nbr_reloc_lineno
*e
= &n_rl
[s
->output_section
->index
];
2586 e
->reloc_count
+= s
->reloc_count
;
2587 e
->lineno_count
+= s
->lineno_count
;
2590 /* Add the size of a section for each section with an overflow. */
2591 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2593 struct nbr_reloc_lineno
*e
= &n_rl
[s
->index
];
2595 if (e
->reloc_count
>= 0xffff
2596 || (e
->lineno_count
>= 0xffff && info
->strip
!= strip_debugger
))
2606 /* Routines to swap information in the XCOFF .loader section. If we
2607 ever need to write an XCOFF loader, this stuff will need to be
2608 moved to another file shared by the linker (which XCOFF calls the
2609 ``binder'') and the loader. */
2611 /* Swap in the ldhdr structure. */
2614 xcoff_swap_ldhdr_in (bfd
*abfd
, const void * s
, struct internal_ldhdr
*dst
)
2616 const struct external_ldhdr
*src
= (const struct external_ldhdr
*) s
;
2618 dst
->l_version
= bfd_get_32 (abfd
, src
->l_version
);
2619 dst
->l_nsyms
= bfd_get_32 (abfd
, src
->l_nsyms
);
2620 dst
->l_nreloc
= bfd_get_32 (abfd
, src
->l_nreloc
);
2621 dst
->l_istlen
= bfd_get_32 (abfd
, src
->l_istlen
);
2622 dst
->l_nimpid
= bfd_get_32 (abfd
, src
->l_nimpid
);
2623 dst
->l_impoff
= bfd_get_32 (abfd
, src
->l_impoff
);
2624 dst
->l_stlen
= bfd_get_32 (abfd
, src
->l_stlen
);
2625 dst
->l_stoff
= bfd_get_32 (abfd
, src
->l_stoff
);
2628 /* Swap out the ldhdr structure. */
2631 xcoff_swap_ldhdr_out (bfd
*abfd
, const struct internal_ldhdr
*src
, void * d
)
2633 struct external_ldhdr
*dst
= (struct external_ldhdr
*) d
;
2635 bfd_put_32 (abfd
, (bfd_vma
) src
->l_version
, dst
->l_version
);
2636 bfd_put_32 (abfd
, src
->l_nsyms
, dst
->l_nsyms
);
2637 bfd_put_32 (abfd
, src
->l_nreloc
, dst
->l_nreloc
);
2638 bfd_put_32 (abfd
, src
->l_istlen
, dst
->l_istlen
);
2639 bfd_put_32 (abfd
, src
->l_nimpid
, dst
->l_nimpid
);
2640 bfd_put_32 (abfd
, src
->l_impoff
, dst
->l_impoff
);
2641 bfd_put_32 (abfd
, src
->l_stlen
, dst
->l_stlen
);
2642 bfd_put_32 (abfd
, src
->l_stoff
, dst
->l_stoff
);
2645 /* Swap in the ldsym structure. */
2648 xcoff_swap_ldsym_in (bfd
*abfd
, const void * s
, struct internal_ldsym
*dst
)
2650 const struct external_ldsym
*src
= (const struct external_ldsym
*) s
;
2652 if (bfd_get_32 (abfd
, src
->_l
._l_l
._l_zeroes
) != 0) {
2653 memcpy (dst
->_l
._l_name
, src
->_l
._l_name
, SYMNMLEN
);
2655 dst
->_l
._l_l
._l_zeroes
= 0;
2656 dst
->_l
._l_l
._l_offset
= bfd_get_32 (abfd
, src
->_l
._l_l
._l_offset
);
2658 dst
->l_value
= bfd_get_32 (abfd
, src
->l_value
);
2659 dst
->l_scnum
= bfd_get_16 (abfd
, src
->l_scnum
);
2660 dst
->l_smtype
= bfd_get_8 (abfd
, src
->l_smtype
);
2661 dst
->l_smclas
= bfd_get_8 (abfd
, src
->l_smclas
);
2662 dst
->l_ifile
= bfd_get_32 (abfd
, src
->l_ifile
);
2663 dst
->l_parm
= bfd_get_32 (abfd
, src
->l_parm
);
2666 /* Swap out the ldsym structure. */
2669 xcoff_swap_ldsym_out (bfd
*abfd
, const struct internal_ldsym
*src
, void * d
)
2671 struct external_ldsym
*dst
= (struct external_ldsym
*) d
;
2673 if (src
->_l
._l_l
._l_zeroes
!= 0)
2674 memcpy (dst
->_l
._l_name
, src
->_l
._l_name
, SYMNMLEN
);
2677 bfd_put_32 (abfd
, (bfd_vma
) 0, dst
->_l
._l_l
._l_zeroes
);
2678 bfd_put_32 (abfd
, (bfd_vma
) src
->_l
._l_l
._l_offset
,
2679 dst
->_l
._l_l
._l_offset
);
2681 bfd_put_32 (abfd
, src
->l_value
, dst
->l_value
);
2682 bfd_put_16 (abfd
, (bfd_vma
) src
->l_scnum
, dst
->l_scnum
);
2683 bfd_put_8 (abfd
, src
->l_smtype
, dst
->l_smtype
);
2684 bfd_put_8 (abfd
, src
->l_smclas
, dst
->l_smclas
);
2685 bfd_put_32 (abfd
, src
->l_ifile
, dst
->l_ifile
);
2686 bfd_put_32 (abfd
, src
->l_parm
, dst
->l_parm
);
2690 xcoff_swap_reloc_in (bfd
*abfd
, void * s
, void * d
)
2692 struct external_reloc
*src
= (struct external_reloc
*) s
;
2693 struct internal_reloc
*dst
= (struct internal_reloc
*) d
;
2695 memset (dst
, 0, sizeof (struct internal_reloc
));
2697 dst
->r_vaddr
= bfd_get_32 (abfd
, src
->r_vaddr
);
2698 dst
->r_symndx
= bfd_get_32 (abfd
, src
->r_symndx
);
2699 dst
->r_size
= bfd_get_8 (abfd
, src
->r_size
);
2700 dst
->r_type
= bfd_get_8 (abfd
, src
->r_type
);
2704 xcoff_swap_reloc_out (bfd
*abfd
, void * s
, void * d
)
2706 struct internal_reloc
*src
= (struct internal_reloc
*) s
;
2707 struct external_reloc
*dst
= (struct external_reloc
*) d
;
2709 bfd_put_32 (abfd
, src
->r_vaddr
, dst
->r_vaddr
);
2710 bfd_put_32 (abfd
, src
->r_symndx
, dst
->r_symndx
);
2711 bfd_put_8 (abfd
, src
->r_type
, dst
->r_type
);
2712 bfd_put_8 (abfd
, src
->r_size
, dst
->r_size
);
2714 return bfd_coff_relsz (abfd
);
2717 /* Swap in the ldrel structure. */
2720 xcoff_swap_ldrel_in (bfd
*abfd
, const void * s
, struct internal_ldrel
*dst
)
2722 const struct external_ldrel
*src
= (const struct external_ldrel
*) s
;
2724 dst
->l_vaddr
= bfd_get_32 (abfd
, src
->l_vaddr
);
2725 dst
->l_symndx
= bfd_get_32 (abfd
, src
->l_symndx
);
2726 dst
->l_rtype
= bfd_get_16 (abfd
, src
->l_rtype
);
2727 dst
->l_rsecnm
= bfd_get_16 (abfd
, src
->l_rsecnm
);
2730 /* Swap out the ldrel structure. */
2733 xcoff_swap_ldrel_out (bfd
*abfd
, const struct internal_ldrel
*src
, void * d
)
2735 struct external_ldrel
*dst
= (struct external_ldrel
*) d
;
2737 bfd_put_32 (abfd
, src
->l_vaddr
, dst
->l_vaddr
);
2738 bfd_put_32 (abfd
, src
->l_symndx
, dst
->l_symndx
);
2739 bfd_put_16 (abfd
, (bfd_vma
) src
->l_rtype
, dst
->l_rtype
);
2740 bfd_put_16 (abfd
, (bfd_vma
) src
->l_rsecnm
, dst
->l_rsecnm
);
2745 xcoff_reloc_type_noop (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2746 asection
*input_section ATTRIBUTE_UNUSED
,
2747 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2748 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
2749 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2750 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
,
2751 bfd_vma val ATTRIBUTE_UNUSED
,
2752 bfd_vma addend ATTRIBUTE_UNUSED
,
2753 bfd_vma
*relocation ATTRIBUTE_UNUSED
,
2754 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2760 xcoff_reloc_type_fail (bfd
*input_bfd
,
2761 asection
*input_section ATTRIBUTE_UNUSED
,
2762 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2763 struct internal_reloc
*rel
,
2764 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2765 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
,
2766 bfd_vma val ATTRIBUTE_UNUSED
,
2767 bfd_vma addend ATTRIBUTE_UNUSED
,
2768 bfd_vma
*relocation ATTRIBUTE_UNUSED
,
2769 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2772 /* xgettext: c-format */
2773 (_("%B: unsupported relocation type 0x%02x"),
2774 input_bfd
, (unsigned int) rel
->r_type
);
2775 bfd_set_error (bfd_error_bad_value
);
2780 xcoff_reloc_type_pos (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2781 asection
*input_section ATTRIBUTE_UNUSED
,
2782 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2783 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
2784 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2785 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
,
2788 bfd_vma
*relocation
,
2789 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2791 *relocation
= val
+ addend
;
2796 xcoff_reloc_type_neg (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2797 asection
*input_section ATTRIBUTE_UNUSED
,
2798 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2799 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
2800 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2801 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
,
2804 bfd_vma
*relocation
,
2805 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2807 *relocation
= addend
- val
;
2812 xcoff_reloc_type_rel (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2813 asection
*input_section
,
2814 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2815 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
2816 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2817 struct reloc_howto_struct
*howto
,
2820 bfd_vma
*relocation
,
2821 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2823 howto
->pc_relative
= TRUE
;
2825 /* A PC relative reloc includes the section address. */
2826 addend
+= input_section
->vma
;
2828 *relocation
= val
+ addend
;
2829 *relocation
-= (input_section
->output_section
->vma
2830 + input_section
->output_offset
);
2835 xcoff_reloc_type_toc (bfd
*input_bfd
,
2836 asection
*input_section ATTRIBUTE_UNUSED
,
2838 struct internal_reloc
*rel
,
2839 struct internal_syment
*sym
,
2840 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
,
2842 bfd_vma addend ATTRIBUTE_UNUSED
,
2843 bfd_vma
*relocation
,
2844 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2846 struct xcoff_link_hash_entry
*h
;
2848 if (0 > rel
->r_symndx
)
2851 h
= obj_xcoff_sym_hashes (input_bfd
)[rel
->r_symndx
];
2853 if (h
!= NULL
&& h
->smclas
!= XMC_TD
)
2855 if (h
->toc_section
== NULL
)
2858 /* xgettext: c-format */
2859 (_("%B: TOC reloc at %#Lx to symbol `%s' with no TOC entry"),
2860 input_bfd
, rel
->r_vaddr
, h
->root
.root
.string
);
2861 bfd_set_error (bfd_error_bad_value
);
2865 BFD_ASSERT ((h
->flags
& XCOFF_SET_TOC
) == 0);
2866 val
= (h
->toc_section
->output_section
->vma
2867 + h
->toc_section
->output_offset
);
2870 *relocation
= ((val
- xcoff_data (output_bfd
)->toc
)
2871 - (sym
->n_value
- xcoff_data (input_bfd
)->toc
));
2876 xcoff_reloc_type_ba (bfd
*input_bfd ATTRIBUTE_UNUSED
,
2877 asection
*input_section ATTRIBUTE_UNUSED
,
2878 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2879 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
2880 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2881 struct reloc_howto_struct
*howto
,
2884 bfd_vma
*relocation
,
2885 bfd_byte
*contents ATTRIBUTE_UNUSED
)
2887 howto
->src_mask
&= ~3;
2888 howto
->dst_mask
= howto
->src_mask
;
2890 *relocation
= val
+ addend
;
2896 xcoff_reloc_type_br (bfd
*input_bfd
,
2897 asection
*input_section
,
2898 bfd
*output_bfd ATTRIBUTE_UNUSED
,
2899 struct internal_reloc
*rel
,
2900 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
2901 struct reloc_howto_struct
*howto
,
2904 bfd_vma
*relocation
,
2907 struct xcoff_link_hash_entry
*h
;
2908 bfd_vma section_offset
;
2910 if (0 > rel
->r_symndx
)
2913 h
= obj_xcoff_sym_hashes (input_bfd
)[rel
->r_symndx
];
2914 section_offset
= rel
->r_vaddr
- input_section
->vma
;
2916 /* If we see an R_BR or R_RBR reloc which is jumping to global
2917 linkage code, and it is followed by an appropriate cror nop
2918 instruction, we replace the cror with lwz r2,20(r1). This
2919 restores the TOC after the glink code. Contrariwise, if the
2920 call is followed by a lwz r2,20(r1), but the call is not
2921 going to global linkage code, we can replace the load with a
2924 && (bfd_link_hash_defined
== h
->root
.type
2925 || bfd_link_hash_defweak
== h
->root
.type
)
2926 && section_offset
+ 8 <= input_section
->size
)
2931 pnext
= contents
+ section_offset
+ 4;
2932 next
= bfd_get_32 (input_bfd
, pnext
);
2934 /* The _ptrgl function is magic. It is used by the AIX
2935 compiler to call a function through a pointer. */
2936 if (h
->smclas
== XMC_GL
|| strcmp (h
->root
.root
.string
, "._ptrgl") == 0)
2938 if (next
== 0x4def7b82 /* cror 15,15,15 */
2939 || next
== 0x4ffffb82 /* cror 31,31,31 */
2940 || next
== 0x60000000) /* ori r0,r0,0 */
2941 bfd_put_32 (input_bfd
, 0x80410014, pnext
); /* lwz r2,20(r1) */
2946 if (next
== 0x80410014) /* lwz r2,20(r1) */
2947 bfd_put_32 (input_bfd
, 0x60000000, pnext
); /* ori r0,r0,0 */
2950 else if (NULL
!= h
&& bfd_link_hash_undefined
== h
->root
.type
)
2952 /* Normally, this relocation is against a defined symbol. In the
2953 case where this is a partial link and the output section offset
2954 is greater than 2^25, the linker will return an invalid error
2955 message that the relocation has been truncated. Yes it has been
2956 truncated but no it not important. For this case, disable the
2957 overflow checking. */
2959 howto
->complain_on_overflow
= complain_overflow_dont
;
2962 /* The original PC-relative relocation is biased by -r_vaddr, so adding
2963 the value below will give the absolute target address. */
2964 *relocation
= val
+ addend
+ rel
->r_vaddr
;
2966 howto
->src_mask
&= ~3;
2967 howto
->dst_mask
= howto
->src_mask
;
2970 && (h
->root
.type
== bfd_link_hash_defined
2971 || h
->root
.type
== bfd_link_hash_defweak
)
2972 && bfd_is_abs_section (h
->root
.u
.def
.section
)
2973 && section_offset
+ 4 <= input_section
->size
)
2978 /* Turn the relative branch into an absolute one by setting the
2980 ptr
= contents
+ section_offset
;
2981 insn
= bfd_get_32 (input_bfd
, ptr
);
2983 bfd_put_32 (input_bfd
, insn
, ptr
);
2985 /* Make the howto absolute too. */
2986 howto
->pc_relative
= FALSE
;
2987 howto
->complain_on_overflow
= complain_overflow_bitfield
;
2991 /* Use a PC-relative howto and subtract the instruction's address
2992 from the target address we calculated above. */
2993 howto
->pc_relative
= TRUE
;
2994 *relocation
-= (input_section
->output_section
->vma
2995 + input_section
->output_offset
3002 xcoff_reloc_type_crel (bfd
*input_bfd ATTRIBUTE_UNUSED
,
3003 asection
*input_section
,
3004 bfd
*output_bfd ATTRIBUTE_UNUSED
,
3005 struct internal_reloc
*rel ATTRIBUTE_UNUSED
,
3006 struct internal_syment
*sym ATTRIBUTE_UNUSED
,
3007 struct reloc_howto_struct
*howto
,
3008 bfd_vma val ATTRIBUTE_UNUSED
,
3010 bfd_vma
*relocation
,
3011 bfd_byte
*contents ATTRIBUTE_UNUSED
)
3013 howto
->pc_relative
= TRUE
;
3014 howto
->src_mask
&= ~3;
3015 howto
->dst_mask
= howto
->src_mask
;
3017 /* A PC relative reloc includes the section address. */
3018 addend
+= input_section
->vma
;
3020 *relocation
= val
+ addend
;
3021 *relocation
-= (input_section
->output_section
->vma
3022 + input_section
->output_offset
);
3027 xcoff_complain_overflow_dont_func (bfd
*input_bfd ATTRIBUTE_UNUSED
,
3028 bfd_vma val ATTRIBUTE_UNUSED
,
3029 bfd_vma relocation ATTRIBUTE_UNUSED
,
3030 struct reloc_howto_struct
*
3031 howto ATTRIBUTE_UNUSED
)
3037 xcoff_complain_overflow_bitfield_func (bfd
*input_bfd
,
3040 struct reloc_howto_struct
*howto
)
3042 bfd_vma fieldmask
, signmask
, ss
;
3045 /* Get the values to be added together. For signed and unsigned
3046 relocations, we assume that all values should be truncated to
3047 the size of an address. For bitfields, all the bits matter.
3048 See also bfd_check_overflow. */
3049 fieldmask
= N_ONES (howto
->bitsize
);
3051 b
= val
& howto
->src_mask
;
3053 /* Much like unsigned, except no trimming with addrmask. In
3054 addition, the sum overflows if there is a carry out of
3055 the bfd_vma, i.e., the sum is less than either input
3057 a
>>= howto
->rightshift
;
3058 b
>>= howto
->bitpos
;
3060 /* Bitfields are sometimes used for signed numbers; for
3061 example, a 13-bit field sometimes represents values in
3062 0..8191 and sometimes represents values in -4096..4095.
3063 If the field is signed and a is -4095 (0x1001) and b is
3064 -1 (0x1fff), the sum is -4096 (0x1000), but (0x1001 +
3065 0x1fff is 0x3000). It's not clear how to handle this
3066 everywhere, since there is not way to know how many bits
3067 are significant in the relocation, but the original code
3068 assumed that it was fully sign extended, and we will keep
3070 signmask
= (fieldmask
>> 1) + 1;
3072 if ((a
& ~ fieldmask
) != 0)
3074 /* Some bits out of the field are set. This might not
3075 be a problem: if this is a signed bitfield, it is OK
3076 iff all the high bits are set, including the sign
3077 bit. We'll try setting all but the most significant
3078 bit in the original relocation value: if this is all
3079 ones, we are OK, assuming a signed bitfield. */
3080 ss
= (signmask
<< howto
->rightshift
) - 1;
3081 if ((ss
| relocation
) != ~ (bfd_vma
) 0)
3086 /* We just assume (b & ~ fieldmask) == 0. */
3088 /* We explicitly permit wrap around if this relocation
3089 covers the high bit of an address. The Linux kernel
3090 relies on it, and it is the only way to write assembler
3091 code which can run when loaded at a location 0x80000000
3092 away from the location at which it is linked. */
3093 if (howto
->bitsize
+ howto
->rightshift
3094 == bfd_arch_bits_per_address (input_bfd
))
3098 if (sum
< a
|| (sum
& ~ fieldmask
) != 0)
3100 /* There was a carry out, or the field overflow. Test
3101 for signed operands again. Here is the overflow test
3102 is as for complain_overflow_signed. */
3103 if (((~ (a
^ b
)) & (a
^ sum
)) & signmask
)
3111 xcoff_complain_overflow_signed_func (bfd
*input_bfd
,
3114 struct reloc_howto_struct
*howto
)
3116 bfd_vma addrmask
, fieldmask
, signmask
, ss
;
3119 /* Get the values to be added together. For signed and unsigned
3120 relocations, we assume that all values should be truncated to
3121 the size of an address. For bitfields, all the bits matter.
3122 See also bfd_check_overflow. */
3123 fieldmask
= N_ONES (howto
->bitsize
);
3124 addrmask
= N_ONES (bfd_arch_bits_per_address (input_bfd
)) | fieldmask
;
3126 b
= val
& howto
->src_mask
;
3128 a
= (a
& addrmask
) >> howto
->rightshift
;
3130 /* If any sign bits are set, all sign bits must be set.
3131 That is, A must be a valid negative address after
3133 signmask
= ~ (fieldmask
>> 1);
3135 if (ss
!= 0 && ss
!= ((addrmask
>> howto
->rightshift
) & signmask
))
3138 /* We only need this next bit of code if the sign bit of B
3139 is below the sign bit of A. This would only happen if
3140 SRC_MASK had fewer bits than BITSIZE. Note that if
3141 SRC_MASK has more bits than BITSIZE, we can get into
3142 trouble; we would need to verify that B is in range, as
3143 we do for A above. */
3144 signmask
= ((~ howto
->src_mask
) >> 1) & howto
->src_mask
;
3145 if ((b
& signmask
) != 0)
3147 /* Set all the bits above the sign bit. */
3148 b
-= signmask
<<= 1;
3151 b
= (b
& addrmask
) >> howto
->bitpos
;
3153 /* Now we can do the addition. */
3156 /* See if the result has the correct sign. Bits above the
3157 sign bit are junk now; ignore them. If the sum is
3158 positive, make sure we did not have all negative inputs;
3159 if the sum is negative, make sure we did not have all
3160 positive inputs. The test below looks only at the sign
3161 bits, and it really just
3162 SIGN (A) == SIGN (B) && SIGN (A) != SIGN (SUM)
3164 signmask
= (fieldmask
>> 1) + 1;
3165 if (((~ (a
^ b
)) & (a
^ sum
)) & signmask
)
3172 xcoff_complain_overflow_unsigned_func (bfd
*input_bfd
,
3175 struct reloc_howto_struct
*howto
)
3177 bfd_vma addrmask
, fieldmask
;
3180 /* Get the values to be added together. For signed and unsigned
3181 relocations, we assume that all values should be truncated to
3182 the size of an address. For bitfields, all the bits matter.
3183 See also bfd_check_overflow. */
3184 fieldmask
= N_ONES (howto
->bitsize
);
3185 addrmask
= N_ONES (bfd_arch_bits_per_address (input_bfd
)) | fieldmask
;
3187 b
= val
& howto
->src_mask
;
3189 /* Checking for an unsigned overflow is relatively easy:
3190 trim the addresses and add, and trim the result as well.
3191 Overflow is normally indicated when the result does not
3192 fit in the field. However, we also need to consider the
3193 case when, e.g., fieldmask is 0x7fffffff or smaller, an
3194 input is 0x80000000, and bfd_vma is only 32 bits; then we
3195 will get sum == 0, but there is an overflow, since the
3196 inputs did not fit in the field. Instead of doing a
3197 separate test, we can check for this by or-ing in the
3198 operands when testing for the sum overflowing its final
3200 a
= (a
& addrmask
) >> howto
->rightshift
;
3201 b
= (b
& addrmask
) >> howto
->bitpos
;
3202 sum
= (a
+ b
) & addrmask
;
3203 if ((a
| b
| sum
) & ~ fieldmask
)
3209 /* This is the relocation function for the RS/6000/POWER/PowerPC.
3210 This is currently the only processor which uses XCOFF; I hope that
3213 I took the relocation type definitions from two documents:
3214 the PowerPC AIX Version 4 Application Binary Interface, First
3215 Edition (April 1992), and the PowerOpen ABI, Big-Endian
3216 32-Bit Hardware Implementation (June 30, 1994). Differences
3217 between the documents are noted below.
3219 Unsupported r_type's
3225 These relocs are defined by the PowerPC ABI to be
3226 relative branches which use half of the difference
3227 between the symbol and the program counter. I can't
3228 quite figure out when this is useful. These relocs are
3229 not defined by the PowerOpen ABI.
3234 Simple positive relocation.
3237 Simple negative relocation.
3240 Simple PC relative relocation.
3243 TOC relative relocation. The value in the instruction in
3244 the input file is the offset from the input file TOC to
3245 the desired location. We want the offset from the final
3246 TOC to the desired location. We have:
3251 so we must change insn by on - in.
3254 GL linkage relocation. The value of this relocation
3255 is the address of the entry in the TOC section.
3258 Local object TOC address. I can't figure out the
3259 difference between this and case R_GL.
3262 TOC relative relocation. A TOC relative load instruction
3263 which may be changed to a load address instruction.
3264 FIXME: We don't currently implement this optimization.
3267 TOC relative relocation. This is a TOC relative load
3268 address instruction which may be changed to a load
3269 instruction. FIXME: I don't know if this is the correct
3273 Absolute branch. We don't want to mess with the lower
3274 two bits of the instruction.
3277 The PowerPC ABI defines this as an absolute call which
3278 may be modified to become a relative call. The PowerOpen
3279 ABI does not define this relocation type.
3282 Absolute branch which may be modified to become a
3286 The PowerPC ABI defines this as an absolute branch to a
3287 fixed address which may be modified to an absolute branch
3288 to a symbol. The PowerOpen ABI does not define this
3292 The PowerPC ABI defines this as an absolute branch to a
3293 fixed address which may be modified to a relative branch.
3294 The PowerOpen ABI does not define this relocation type.
3297 Relative branch. We don't want to mess with the lower
3298 two bits of the instruction.
3301 The PowerPC ABI defines this as a relative call which may
3302 be modified to become an absolute call. The PowerOpen
3303 ABI does not define this relocation type.
3306 A relative branch which may be modified to become an
3310 The PowerPC AIX ABI describes this as a load which may be
3311 changed to a load address. The PowerOpen ABI says this
3312 is the same as case R_POS.
3315 The PowerPC AIX ABI describes this as a load address
3316 which may be changed to a load. The PowerOpen ABI says
3317 this is the same as R_POS.
3321 xcoff_ppc_relocate_section (bfd
*output_bfd
,
3322 struct bfd_link_info
*info
,
3324 asection
*input_section
,
3326 struct internal_reloc
*relocs
,
3327 struct internal_syment
*syms
,
3328 asection
**sections
)
3330 struct internal_reloc
*rel
;
3331 struct internal_reloc
*relend
;
3334 relend
= rel
+ input_section
->reloc_count
;
3335 for (; rel
< relend
; rel
++)
3338 struct xcoff_link_hash_entry
*h
;
3339 struct internal_syment
*sym
;
3342 struct reloc_howto_struct howto
;
3344 bfd_vma value_to_relocate
;
3348 /* Relocation type R_REF is a special relocation type which is
3349 merely used to prevent garbage collection from occurring for
3350 the csect including the symbol which it references. */
3351 if (rel
->r_type
== R_REF
)
3355 howto
.type
= rel
->r_type
;
3356 howto
.rightshift
= 0;
3357 howto
.bitsize
= (rel
->r_size
& 0x1f) + 1;
3358 howto
.size
= howto
.bitsize
> 16 ? 2 : 1;
3359 howto
.pc_relative
= FALSE
;
3361 howto
.complain_on_overflow
= (rel
->r_size
& 0x80
3362 ? complain_overflow_signed
3363 : complain_overflow_bitfield
);
3364 howto
.special_function
= NULL
;
3365 howto
.name
= "internal";
3366 howto
.partial_inplace
= TRUE
;
3367 howto
.src_mask
= howto
.dst_mask
= N_ONES (howto
.bitsize
);
3368 howto
.pcrel_offset
= FALSE
;
3375 symndx
= rel
->r_symndx
;
3381 h
= obj_xcoff_sym_hashes (input_bfd
)[symndx
];
3382 sym
= syms
+ symndx
;
3383 addend
= - sym
->n_value
;
3387 sec
= sections
[symndx
];
3388 /* Hack to make sure we use the right TOC anchor value
3389 if this reloc is against the TOC anchor. */
3390 if (sec
->name
[3] == '0'
3391 && strcmp (sec
->name
, ".tc0") == 0)
3392 val
= xcoff_data (output_bfd
)->toc
;
3394 val
= (sec
->output_section
->vma
3395 + sec
->output_offset
3401 if (info
->unresolved_syms_in_objects
!= RM_IGNORE
3402 && (h
->flags
& XCOFF_WAS_UNDEFINED
) != 0)
3403 (*info
->callbacks
->undefined_symbol
)
3404 (info
, h
->root
.root
.string
,
3405 input_bfd
, input_section
,
3406 rel
->r_vaddr
- input_section
->vma
,
3407 info
->unresolved_syms_in_objects
== RM_GENERATE_ERROR
);
3409 if (h
->root
.type
== bfd_link_hash_defined
3410 || h
->root
.type
== bfd_link_hash_defweak
)
3412 sec
= h
->root
.u
.def
.section
;
3413 val
= (h
->root
.u
.def
.value
3414 + sec
->output_section
->vma
3415 + sec
->output_offset
);
3417 else if (h
->root
.type
== bfd_link_hash_common
)
3419 sec
= h
->root
.u
.c
.p
->section
;
3420 val
= (sec
->output_section
->vma
3421 + sec
->output_offset
);
3426 BFD_ASSERT (bfd_link_relocatable (info
)
3427 || (info
->static_link
3428 && (h
->flags
& XCOFF_WAS_UNDEFINED
) != 0)
3429 || (h
->flags
& XCOFF_DEF_DYNAMIC
) != 0
3430 || (h
->flags
& XCOFF_IMPORT
) != 0);
3435 if (rel
->r_type
>= XCOFF_MAX_CALCULATE_RELOCATION
3436 || !((*xcoff_calculate_relocation
[rel
->r_type
])
3437 (input_bfd
, input_section
, output_bfd
, rel
, sym
, &howto
, val
,
3438 addend
, &relocation
, contents
)))
3442 address
= rel
->r_vaddr
- input_section
->vma
;
3443 location
= contents
+ address
;
3445 if (address
> input_section
->size
)
3448 /* Get the value we are going to relocate. */
3449 if (1 == howto
.size
)
3450 value_to_relocate
= bfd_get_16 (input_bfd
, location
);
3452 value_to_relocate
= bfd_get_32 (input_bfd
, location
);
3456 FIXME: We may drop bits during the addition
3457 which we don't check for. We must either check at every single
3458 operation, which would be tedious, or we must do the computations
3459 in a type larger than bfd_vma, which would be inefficient. */
3461 if ((unsigned int) howto
.complain_on_overflow
3462 >= XCOFF_MAX_COMPLAIN_OVERFLOW
)
3465 if (((*xcoff_complain_overflow
[howto
.complain_on_overflow
])
3466 (input_bfd
, value_to_relocate
, relocation
, &howto
)))
3469 char buf
[SYMNMLEN
+ 1];
3470 char reloc_type_name
[10];
3482 name
= _bfd_coff_internal_syment_name (input_bfd
, sym
, buf
);
3486 sprintf (reloc_type_name
, "0x%02x", rel
->r_type
);
3488 (*info
->callbacks
->reloc_overflow
)
3489 (info
, (h
? &h
->root
: NULL
), name
, reloc_type_name
,
3490 (bfd_vma
) 0, input_bfd
, input_section
,
3491 rel
->r_vaddr
- input_section
->vma
);
3494 /* Add RELOCATION to the right bits of VALUE_TO_RELOCATE. */
3495 value_to_relocate
= ((value_to_relocate
& ~howto
.dst_mask
)
3496 | (((value_to_relocate
& howto
.src_mask
)
3497 + relocation
) & howto
.dst_mask
));
3499 /* Put the value back in the object file. */
3500 if (1 == howto
.size
)
3501 bfd_put_16 (input_bfd
, value_to_relocate
, location
);
3503 bfd_put_32 (input_bfd
, value_to_relocate
, location
);
3510 _bfd_xcoff_put_ldsymbol_name (bfd
*abfd ATTRIBUTE_UNUSED
,
3511 struct xcoff_loader_info
*ldinfo
,
3512 struct internal_ldsym
*ldsym
,
3516 len
= strlen (name
);
3518 if (len
<= SYMNMLEN
)
3519 strncpy (ldsym
->_l
._l_name
, name
, SYMNMLEN
);
3522 if (ldinfo
->string_size
+ len
+ 3 > ldinfo
->string_alc
)
3524 bfd_size_type newalc
;
3527 newalc
= ldinfo
->string_alc
* 2;
3530 while (ldinfo
->string_size
+ len
+ 3 > newalc
)
3533 newstrings
= bfd_realloc (ldinfo
->strings
, newalc
);
3534 if (newstrings
== NULL
)
3536 ldinfo
->failed
= TRUE
;
3539 ldinfo
->string_alc
= newalc
;
3540 ldinfo
->strings
= newstrings
;
3543 bfd_put_16 (ldinfo
->output_bfd
, (bfd_vma
) (len
+ 1),
3544 ldinfo
->strings
+ ldinfo
->string_size
);
3545 strcpy (ldinfo
->strings
+ ldinfo
->string_size
+ 2, name
);
3546 ldsym
->_l
._l_l
._l_zeroes
= 0;
3547 ldsym
->_l
._l_l
._l_offset
= ldinfo
->string_size
+ 2;
3548 ldinfo
->string_size
+= len
+ 3;
3555 _bfd_xcoff_put_symbol_name (struct bfd_link_info
*info
,
3556 struct bfd_strtab_hash
*strtab
,
3557 struct internal_syment
*sym
,
3560 if (strlen (name
) <= SYMNMLEN
)
3562 strncpy (sym
->_n
._n_name
, name
, SYMNMLEN
);
3569 hash
= !info
->traditional_format
;
3570 indx
= _bfd_stringtab_add (strtab
, name
, hash
, FALSE
);
3571 if (indx
== (bfd_size_type
) -1)
3573 sym
->_n
._n_n
._n_zeroes
= 0;
3574 sym
->_n
._n_n
._n_offset
= STRING_SIZE_SIZE
+ indx
;
3580 xcoff_create_csect_from_smclas (bfd
*abfd
,
3581 union internal_auxent
*aux
,
3582 const char *symbol_name
)
3584 asection
*return_value
= NULL
;
3586 /* .sv64 = x_smclas == 17
3587 This is an invalid csect for 32 bit apps. */
3588 static const char * const names
[] =
3590 ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo", /* 0 - 7 */
3591 ".sv", ".bs", ".ds", ".uc", ".ti", ".tb", NULL
, ".tc0", /* 8 - 15 */
3592 ".td", NULL
, ".sv3264", NULL
, ".tl", ".ul", ".te"
3595 if ((aux
->x_csect
.x_smclas
< ARRAY_SIZE (names
))
3596 && (NULL
!= names
[aux
->x_csect
.x_smclas
]))
3598 return_value
= bfd_make_section_anyway
3599 (abfd
, names
[aux
->x_csect
.x_smclas
]);
3604 /* xgettext: c-format */
3605 (_("%B: symbol `%s' has unrecognized smclas %d"),
3606 abfd
, symbol_name
, aux
->x_csect
.x_smclas
);
3607 bfd_set_error (bfd_error_bad_value
);
3610 return return_value
;
3614 xcoff_is_lineno_count_overflow (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_vma value
)
3616 if (0xffff <= value
)
3623 xcoff_is_reloc_count_overflow (bfd
*abfd ATTRIBUTE_UNUSED
, bfd_vma value
)
3625 if (0xffff <= value
)
3632 xcoff_loader_symbol_offset (bfd
*abfd
,
3633 struct internal_ldhdr
*ldhdr ATTRIBUTE_UNUSED
)
3635 return bfd_xcoff_ldhdrsz (abfd
);
3639 xcoff_loader_reloc_offset (bfd
*abfd
, struct internal_ldhdr
*ldhdr
)
3641 return bfd_xcoff_ldhdrsz (abfd
) + ldhdr
->l_nsyms
* bfd_xcoff_ldsymsz (abfd
);
3645 xcoff_generate_rtinit (bfd
*abfd
, const char *init
, const char *fini
,
3648 bfd_byte filehdr_ext
[FILHSZ
];
3649 bfd_byte scnhdr_ext
[SCNHSZ
];
3650 bfd_byte syment_ext
[SYMESZ
* 10];
3651 bfd_byte reloc_ext
[RELSZ
* 3];
3652 bfd_byte
*data_buffer
;
3653 bfd_size_type data_buffer_size
;
3654 bfd_byte
*string_table
= NULL
, *st_tmp
= NULL
;
3655 bfd_size_type string_table_size
;
3657 size_t initsz
, finisz
;
3658 struct internal_filehdr filehdr
;
3659 struct internal_scnhdr scnhdr
;
3660 struct internal_syment syment
;
3661 union internal_auxent auxent
;
3662 struct internal_reloc reloc
;
3664 char *data_name
= ".data";
3665 char *rtinit_name
= "__rtinit";
3666 char *rtld_name
= "__rtld";
3668 if (! bfd_xcoff_rtinit_size (abfd
))
3671 initsz
= (init
== NULL
? 0 : 1 + strlen (init
));
3672 finisz
= (fini
== NULL
? 0 : 1 + strlen (fini
));
3675 memset (filehdr_ext
, 0, FILHSZ
);
3676 memset (&filehdr
, 0, sizeof (struct internal_filehdr
));
3677 filehdr
.f_magic
= bfd_xcoff_magic_number (abfd
);
3678 filehdr
.f_nscns
= 1;
3679 filehdr
.f_timdat
= 0;
3680 filehdr
.f_nsyms
= 0; /* at least 6, no more than 10 */
3681 filehdr
.f_symptr
= 0; /* set below */
3682 filehdr
.f_opthdr
= 0;
3683 filehdr
.f_flags
= 0;
3685 /* section header */
3686 memset (scnhdr_ext
, 0, SCNHSZ
);
3687 memset (&scnhdr
, 0, sizeof (struct internal_scnhdr
));
3688 memcpy (scnhdr
.s_name
, data_name
, strlen (data_name
));
3691 scnhdr
.s_size
= 0; /* set below */
3692 scnhdr
.s_scnptr
= FILHSZ
+ SCNHSZ
;
3693 scnhdr
.s_relptr
= 0; /* set below */
3694 scnhdr
.s_lnnoptr
= 0;
3695 scnhdr
.s_nreloc
= 0; /* either 1 or 2 */
3697 scnhdr
.s_flags
= STYP_DATA
;
3700 0x0000 0x00000000 : rtl
3701 0x0004 0x00000010 : offset to init, or 0
3702 0x0008 0x00000028 : offset to fini, or 0
3703 0x000C 0x0000000C : size of descriptor
3704 0x0010 0x00000000 : init, needs a reloc
3705 0x0014 0x00000040 : offset to init name
3706 0x0018 0x00000000 : flags, padded to a word
3707 0x001C 0x00000000 : empty init
3710 0x0028 0x00000000 : fini, needs a reloc
3711 0x002C 0x00000??? : offset to fini name
3712 0x0030 0x00000000 : flags, padded to a word
3713 0x0034 0x00000000 : empty fini
3717 0x0040 + initsz fini name */
3719 data_buffer_size
= 0x0040 + initsz
+ finisz
;
3720 data_buffer_size
= (data_buffer_size
+ 7) &~ (bfd_size_type
) 7;
3722 data_buffer
= (bfd_byte
*) bfd_zmalloc (data_buffer_size
);
3723 if (data_buffer
== NULL
)
3729 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x04]);
3731 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x14]);
3732 memcpy (&data_buffer
[val
], init
, initsz
);
3738 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x08]);
3739 val
= 0x40 + initsz
;
3740 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x2C]);
3741 memcpy (&data_buffer
[val
], fini
, finisz
);
3745 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x0C]);
3747 scnhdr
.s_size
= data_buffer_size
;
3750 string_table_size
= 0;
3752 string_table_size
+= initsz
;
3754 string_table_size
+= finisz
;
3755 if (string_table_size
)
3757 string_table_size
+= 4;
3758 string_table
= (bfd_byte
*) bfd_zmalloc (string_table_size
);
3759 if (string_table
== NULL
)
3762 val
= string_table_size
;
3763 bfd_h_put_32 (abfd
, val
, &string_table
[0]);
3764 st_tmp
= string_table
+ 4;
3773 memset (syment_ext
, 0, 10 * SYMESZ
);
3774 memset (reloc_ext
, 0, 3 * RELSZ
);
3777 memset (&syment
, 0, sizeof (struct internal_syment
));
3778 memset (&auxent
, 0, sizeof (union internal_auxent
));
3779 memcpy (syment
._n
._n_name
, data_name
, strlen (data_name
));
3781 syment
.n_sclass
= C_HIDEXT
;
3782 syment
.n_numaux
= 1;
3783 auxent
.x_csect
.x_scnlen
.l
= data_buffer_size
;
3784 auxent
.x_csect
.x_smtyp
= 3 << 3 | XTY_SD
;
3785 auxent
.x_csect
.x_smclas
= XMC_RW
;
3786 bfd_coff_swap_sym_out (abfd
, &syment
,
3787 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3788 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3790 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3791 filehdr
.f_nsyms
+= 2;
3794 memset (&syment
, 0, sizeof (struct internal_syment
));
3795 memset (&auxent
, 0, sizeof (union internal_auxent
));
3796 memcpy (syment
._n
._n_name
, rtinit_name
, strlen (rtinit_name
));
3798 syment
.n_sclass
= C_EXT
;
3799 syment
.n_numaux
= 1;
3800 auxent
.x_csect
.x_smtyp
= XTY_LD
;
3801 auxent
.x_csect
.x_smclas
= XMC_RW
;
3802 bfd_coff_swap_sym_out (abfd
, &syment
,
3803 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3804 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3806 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3807 filehdr
.f_nsyms
+= 2;
3812 memset (&syment
, 0, sizeof (struct internal_syment
));
3813 memset (&auxent
, 0, sizeof (union internal_auxent
));
3817 syment
._n
._n_n
._n_offset
= st_tmp
- string_table
;
3818 memcpy (st_tmp
, init
, initsz
);
3822 memcpy (syment
._n
._n_name
, init
, initsz
- 1);
3824 syment
.n_sclass
= C_EXT
;
3825 syment
.n_numaux
= 1;
3826 bfd_coff_swap_sym_out (abfd
, &syment
,
3827 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3828 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3830 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3833 memset (&reloc
, 0, sizeof (struct internal_reloc
));
3834 reloc
.r_vaddr
= 0x0010;
3835 reloc
.r_symndx
= filehdr
.f_nsyms
;
3836 reloc
.r_type
= R_POS
;
3838 bfd_coff_swap_reloc_out (abfd
, &reloc
, &reloc_ext
[0]);
3840 filehdr
.f_nsyms
+= 2;
3841 scnhdr
.s_nreloc
+= 1;
3847 memset (&syment
, 0, sizeof (struct internal_syment
));
3848 memset (&auxent
, 0, sizeof (union internal_auxent
));
3852 syment
._n
._n_n
._n_offset
= st_tmp
- string_table
;
3853 memcpy (st_tmp
, fini
, finisz
);
3857 memcpy (syment
._n
._n_name
, fini
, finisz
- 1);
3859 syment
.n_sclass
= C_EXT
;
3860 syment
.n_numaux
= 1;
3861 bfd_coff_swap_sym_out (abfd
, &syment
,
3862 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3863 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3865 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3868 memset (&reloc
, 0, sizeof (struct internal_reloc
));
3869 reloc
.r_vaddr
= 0x0028;
3870 reloc
.r_symndx
= filehdr
.f_nsyms
;
3871 reloc
.r_type
= R_POS
;
3873 bfd_coff_swap_reloc_out (abfd
, &reloc
,
3874 &reloc_ext
[scnhdr
.s_nreloc
* RELSZ
]);
3876 filehdr
.f_nsyms
+= 2;
3877 scnhdr
.s_nreloc
+= 1;
3882 memset (&syment
, 0, sizeof (struct internal_syment
));
3883 memset (&auxent
, 0, sizeof (union internal_auxent
));
3884 memcpy (syment
._n
._n_name
, rtld_name
, strlen (rtld_name
));
3885 syment
.n_sclass
= C_EXT
;
3886 syment
.n_numaux
= 1;
3887 bfd_coff_swap_sym_out (abfd
, &syment
,
3888 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3889 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3891 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3894 memset (&reloc
, 0, sizeof (struct internal_reloc
));
3895 reloc
.r_vaddr
= 0x0000;
3896 reloc
.r_symndx
= filehdr
.f_nsyms
;
3897 reloc
.r_type
= R_POS
;
3899 bfd_coff_swap_reloc_out (abfd
, &reloc
,
3900 &reloc_ext
[scnhdr
.s_nreloc
* RELSZ
]);
3902 filehdr
.f_nsyms
+= 2;
3903 scnhdr
.s_nreloc
+= 1;
3906 scnhdr
.s_relptr
= scnhdr
.s_scnptr
+ data_buffer_size
;
3907 filehdr
.f_symptr
= scnhdr
.s_relptr
+ scnhdr
.s_nreloc
* RELSZ
;
3909 bfd_coff_swap_filehdr_out (abfd
, &filehdr
, filehdr_ext
);
3910 bfd_bwrite (filehdr_ext
, FILHSZ
, abfd
);
3911 bfd_coff_swap_scnhdr_out (abfd
, &scnhdr
, scnhdr_ext
);
3912 bfd_bwrite (scnhdr_ext
, SCNHSZ
, abfd
);
3913 bfd_bwrite (data_buffer
, data_buffer_size
, abfd
);
3914 bfd_bwrite (reloc_ext
, scnhdr
.s_nreloc
* RELSZ
, abfd
);
3915 bfd_bwrite (syment_ext
, filehdr
.f_nsyms
* SYMESZ
, abfd
);
3916 bfd_bwrite (string_table
, string_table_size
, abfd
);
3925 static reloc_howto_type xcoff_dynamic_reloc
=
3926 HOWTO (0, /* type */
3928 2, /* size (0 = byte, 1 = short, 2 = long) */
3930 FALSE
, /* pc_relative */
3932 complain_overflow_bitfield
, /* complain_on_overflow */
3933 0, /* special_function */
3935 TRUE
, /* partial_inplace */
3936 0xffffffff, /* src_mask */
3937 0xffffffff, /* dst_mask */
3938 FALSE
); /* pcrel_offset */
3942 The first word of global linkage code must be modified by filling in
3943 the correct TOC offset. */
3945 static unsigned long xcoff_glink_code
[9] =
3947 0x81820000, /* lwz r12,0(r2) */
3948 0x90410014, /* stw r2,20(r1) */
3949 0x800c0000, /* lwz r0,0(r12) */
3950 0x804c0004, /* lwz r2,4(r12) */
3951 0x7c0903a6, /* mtctr r0 */
3952 0x4e800420, /* bctr */
3953 0x00000000, /* start of traceback table */
3954 0x000c8000, /* traceback table */
3955 0x00000000, /* traceback table */
3958 /* Table to convert DWARF flags to section names. */
3960 const struct xcoff_dwsect_name xcoff_dwsect_names
[] = {
3961 { SSUBTYP_DWINFO
, ".dwinfo", TRUE
},
3962 { SSUBTYP_DWLINE
, ".dwline", TRUE
},
3963 { SSUBTYP_DWPBNMS
, ".dwpbnms", TRUE
},
3964 { SSUBTYP_DWPBTYP
, ".dwpbtyp", TRUE
},
3965 { SSUBTYP_DWARNGE
, ".dwarnge", TRUE
},
3966 { SSUBTYP_DWABREV
, ".dwabrev", FALSE
},
3967 { SSUBTYP_DWSTR
, ".dwstr", TRUE
},
3968 { SSUBTYP_DWRNGES
, ".dwrnges", TRUE
}
3971 /* For generic entry points. */
3972 #define _bfd_xcoff_close_and_cleanup _bfd_archive_close_and_cleanup
3973 #define _bfd_xcoff_bfd_free_cached_info bfd_true
3974 #define _bfd_xcoff_new_section_hook coff_new_section_hook
3975 #define _bfd_xcoff_get_section_contents _bfd_generic_get_section_contents
3976 #define _bfd_xcoff_get_section_contents_in_window \
3977 _bfd_generic_get_section_contents_in_window
3979 /* For copy private data entry points. */
3980 #define _bfd_xcoff_bfd_copy_private_bfd_data \
3981 _bfd_xcoff_copy_private_bfd_data
3982 #define _bfd_xcoff_bfd_merge_private_bfd_data \
3983 _bfd_generic_bfd_merge_private_bfd_data
3984 #define _bfd_xcoff_bfd_copy_private_section_data \
3985 _bfd_generic_bfd_copy_private_section_data
3986 #define _bfd_xcoff_bfd_copy_private_symbol_data \
3987 _bfd_generic_bfd_copy_private_symbol_data
3988 #define _bfd_xcoff_bfd_copy_private_header_data \
3989 _bfd_generic_bfd_copy_private_header_data
3990 #define _bfd_xcoff_bfd_set_private_flags \
3991 _bfd_generic_bfd_set_private_flags
3992 #define _bfd_xcoff_bfd_print_private_bfd_data \
3993 _bfd_generic_bfd_print_private_bfd_data
3995 /* For archive entry points. */
3996 #define _bfd_xcoff_slurp_extended_name_table \
3997 _bfd_noarchive_slurp_extended_name_table
3998 #define _bfd_xcoff_construct_extended_name_table \
3999 _bfd_noarchive_construct_extended_name_table
4000 #define _bfd_xcoff_truncate_arname bfd_dont_truncate_arname
4001 #define _bfd_xcoff_write_ar_hdr _bfd_generic_write_ar_hdr
4002 #define _bfd_xcoff_get_elt_at_index _bfd_generic_get_elt_at_index
4003 #define _bfd_xcoff_generic_stat_arch_elt _bfd_xcoff_stat_arch_elt
4004 #define _bfd_xcoff_update_armap_timestamp bfd_true
4006 /* For symbols entry points. */
4007 #define _bfd_xcoff_get_symtab_upper_bound coff_get_symtab_upper_bound
4008 #define _bfd_xcoff_canonicalize_symtab coff_canonicalize_symtab
4009 #define _bfd_xcoff_make_empty_symbol coff_make_empty_symbol
4010 #define _bfd_xcoff_print_symbol coff_print_symbol
4011 #define _bfd_xcoff_get_symbol_info coff_get_symbol_info
4012 #define _bfd_xcoff_get_symbol_version_string \
4013 _bfd_nosymbols_get_symbol_version_string
4014 #define _bfd_xcoff_bfd_is_local_label_name _bfd_xcoff_is_local_label_name
4015 #define _bfd_xcoff_bfd_is_target_special_symbol \
4016 coff_bfd_is_target_special_symbol
4017 #define _bfd_xcoff_get_lineno coff_get_lineno
4018 #define _bfd_xcoff_find_nearest_line coff_find_nearest_line
4019 #define _bfd_xcoff_find_line coff_find_line
4020 #define _bfd_xcoff_find_inliner_info coff_find_inliner_info
4021 #define _bfd_xcoff_bfd_make_debug_symbol coff_bfd_make_debug_symbol
4022 #define _bfd_xcoff_read_minisymbols _bfd_generic_read_minisymbols
4023 #define _bfd_xcoff_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
4025 /* For reloc entry points. */
4026 #define _bfd_xcoff_get_reloc_upper_bound coff_get_reloc_upper_bound
4027 #define _bfd_xcoff_canonicalize_reloc coff_canonicalize_reloc
4028 #define _bfd_xcoff_set_reloc _bfd_generic_set_reloc
4029 #define _bfd_xcoff_bfd_reloc_type_lookup _bfd_xcoff_reloc_type_lookup
4030 #define _bfd_xcoff_bfd_reloc_name_lookup _bfd_xcoff_reloc_name_lookup
4032 /* For link entry points. */
4033 #define _bfd_xcoff_bfd_get_relocated_section_contents \
4034 bfd_generic_get_relocated_section_contents
4035 #define _bfd_xcoff_bfd_relax_section bfd_generic_relax_section
4036 #define _bfd_xcoff_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
4037 #define _bfd_xcoff_bfd_link_just_syms _bfd_generic_link_just_syms
4038 #define _bfd_xcoff_bfd_copy_link_hash_symbol_type \
4039 _bfd_generic_copy_link_hash_symbol_type
4040 #define _bfd_xcoff_bfd_link_split_section _bfd_generic_link_split_section
4041 #define _bfd_xcoff_bfd_gc_sections bfd_generic_gc_sections
4042 #define _bfd_xcoff_bfd_lookup_section_flags bfd_generic_lookup_section_flags
4043 #define _bfd_xcoff_bfd_merge_sections bfd_generic_merge_sections
4044 #define _bfd_xcoff_bfd_is_group_section bfd_generic_is_group_section
4045 #define _bfd_xcoff_bfd_discard_group bfd_generic_discard_group
4046 #define _bfd_xcoff_section_already_linked _bfd_generic_section_already_linked
4047 #define _bfd_xcoff_bfd_define_common_symbol _bfd_xcoff_define_common_symbol
4048 #define _bfd_xcoff_bfd_define_start_stop bfd_generic_define_start_stop
4049 #define _bfd_xcoff_bfd_link_check_relocs _bfd_generic_link_check_relocs
4051 /* For dynamic symbols and relocs entry points. */
4052 #define _bfd_xcoff_get_synthetic_symtab _bfd_nodynamic_get_synthetic_symtab
4054 static const struct xcoff_backend_data_rec bfd_xcoff_backend_data
=
4056 { /* COFF backend, defined in libcoff.h. */
4057 _bfd_xcoff_swap_aux_in
,
4058 _bfd_xcoff_swap_sym_in
,
4059 coff_swap_lineno_in
,
4060 _bfd_xcoff_swap_aux_out
,
4061 _bfd_xcoff_swap_sym_out
,
4062 coff_swap_lineno_out
,
4063 xcoff_swap_reloc_out
,
4064 coff_swap_filehdr_out
,
4065 coff_swap_aouthdr_out
,
4066 coff_swap_scnhdr_out
,
4075 TRUE
, /* _bfd_coff_long_filenames */
4076 XCOFF_NO_LONG_SECTION_NAMES
, /* _bfd_coff_long_section_names */
4077 3, /* _bfd_coff_default_section_alignment_power */
4078 FALSE
, /* _bfd_coff_force_symnames_in_strings */
4079 2, /* _bfd_coff_debug_string_prefix_length */
4080 32768, /* _bfd_coff_max_nscns */
4081 coff_swap_filehdr_in
,
4082 coff_swap_aouthdr_in
,
4083 coff_swap_scnhdr_in
,
4084 xcoff_swap_reloc_in
,
4085 coff_bad_format_hook
,
4086 coff_set_arch_mach_hook
,
4089 coff_set_alignment_hook
,
4090 coff_slurp_symbol_table
,
4091 symname_in_debug_hook
,
4092 coff_pointerize_aux_hook
,
4094 dummy_reloc16_extra_cases
,
4095 dummy_reloc16_estimate
,
4096 NULL
, /* bfd_coff_sym_is_global */
4097 coff_compute_section_file_positions
,
4098 NULL
, /* _bfd_coff_start_final_link */
4099 xcoff_ppc_relocate_section
,
4100 coff_rtype_to_howto
,
4101 NULL
, /* _bfd_coff_adjust_symndx */
4102 _bfd_generic_link_add_one_symbol
,
4103 coff_link_output_has_begun
,
4104 coff_final_link_postscript
,
4105 NULL
/* print_pdata. */
4108 0x01DF, /* magic number */
4112 /* Function pointers to xcoff specific swap routines. */
4113 xcoff_swap_ldhdr_in
,
4114 xcoff_swap_ldhdr_out
,
4115 xcoff_swap_ldsym_in
,
4116 xcoff_swap_ldsym_out
,
4117 xcoff_swap_ldrel_in
,
4118 xcoff_swap_ldrel_out
,
4124 12, /* _xcoff_function_descriptor_size */
4128 1, /* _xcoff_ldhdr_version */
4130 _bfd_xcoff_put_symbol_name
,
4131 _bfd_xcoff_put_ldsymbol_name
,
4132 &xcoff_dynamic_reloc
,
4133 xcoff_create_csect_from_smclas
,
4135 /* Lineno and reloc count overflow. */
4136 xcoff_is_lineno_count_overflow
,
4137 xcoff_is_reloc_count_overflow
,
4139 xcoff_loader_symbol_offset
,
4140 xcoff_loader_reloc_offset
,
4143 &xcoff_glink_code
[0],
4144 36, /* _xcoff_glink_size */
4147 64, /* _xcoff_rtinit_size */
4148 xcoff_generate_rtinit
,
4151 /* The transfer vector that leads the outside world to all of the above. */
4152 const bfd_target rs6000_xcoff_vec
=
4155 bfd_target_xcoff_flavour
,
4156 BFD_ENDIAN_BIG
, /* data byte order is big */
4157 BFD_ENDIAN_BIG
, /* header byte order is big */
4159 (HAS_RELOC
| EXEC_P
| HAS_LINENO
| HAS_DEBUG
| DYNAMIC
4160 | HAS_SYMS
| HAS_LOCALS
| WP_TEXT
),
4162 SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_CODE
| SEC_DATA
,
4163 0, /* leading char */
4164 '/', /* ar_pad_char */
4165 15, /* ar_max_namelen */
4166 0, /* match priority. */
4190 { /* bfd_check_format */
4193 _bfd_xcoff_archive_p
,
4197 { /* bfd_set_format */
4200 _bfd_generic_mkarchive
,
4204 {/* bfd_write_contents */
4206 coff_write_object_contents
,
4207 _bfd_xcoff_write_archive_contents
,
4211 BFD_JUMP_TABLE_GENERIC (_bfd_xcoff
),
4212 BFD_JUMP_TABLE_COPY (_bfd_xcoff
),
4213 BFD_JUMP_TABLE_CORE (coff
),
4214 BFD_JUMP_TABLE_ARCHIVE (_bfd_xcoff
),
4215 BFD_JUMP_TABLE_SYMBOLS (_bfd_xcoff
),
4216 BFD_JUMP_TABLE_RELOCS (_bfd_xcoff
),
4217 BFD_JUMP_TABLE_WRITE (coff
),
4218 BFD_JUMP_TABLE_LINK (_bfd_xcoff
),
4219 BFD_JUMP_TABLE_DYNAMIC (_bfd_xcoff
),
4221 /* Opposite endian version, none exists */
4224 & bfd_xcoff_backend_data
,
4227 /* xcoff-powermac target
4229 Only difference between this target and the rs6000 target is the
4230 the default architecture and machine type used in coffcode.h
4232 PowerPC Macs use the same magic numbers as RS/6000
4233 (because that's how they were bootstrapped originally),
4234 but they are always PowerPC architecture. */
4235 static const struct xcoff_backend_data_rec bfd_pmac_xcoff_backend_data
=
4237 { /* COFF backend, defined in libcoff.h. */
4238 _bfd_xcoff_swap_aux_in
,
4239 _bfd_xcoff_swap_sym_in
,
4240 coff_swap_lineno_in
,
4241 _bfd_xcoff_swap_aux_out
,
4242 _bfd_xcoff_swap_sym_out
,
4243 coff_swap_lineno_out
,
4244 xcoff_swap_reloc_out
,
4245 coff_swap_filehdr_out
,
4246 coff_swap_aouthdr_out
,
4247 coff_swap_scnhdr_out
,
4256 TRUE
, /* _bfd_coff_long_filenames */
4257 XCOFF_NO_LONG_SECTION_NAMES
, /* _bfd_coff_long_section_names */
4258 3, /* _bfd_coff_default_section_alignment_power */
4259 FALSE
, /* _bfd_coff_force_symnames_in_strings */
4260 2, /* _bfd_coff_debug_string_prefix_length */
4261 32768, /* _bfd_coff_max_nscns */
4262 coff_swap_filehdr_in
,
4263 coff_swap_aouthdr_in
,
4264 coff_swap_scnhdr_in
,
4265 xcoff_swap_reloc_in
,
4266 coff_bad_format_hook
,
4267 coff_set_arch_mach_hook
,
4270 coff_set_alignment_hook
,
4271 coff_slurp_symbol_table
,
4272 symname_in_debug_hook
,
4273 coff_pointerize_aux_hook
,
4275 dummy_reloc16_extra_cases
,
4276 dummy_reloc16_estimate
,
4277 NULL
, /* bfd_coff_sym_is_global */
4278 coff_compute_section_file_positions
,
4279 NULL
, /* _bfd_coff_start_final_link */
4280 xcoff_ppc_relocate_section
,
4281 coff_rtype_to_howto
,
4282 NULL
, /* _bfd_coff_adjust_symndx */
4283 _bfd_generic_link_add_one_symbol
,
4284 coff_link_output_has_begun
,
4285 coff_final_link_postscript
,
4286 NULL
/* print_pdata. */
4289 0x01DF, /* magic number */
4293 /* Function pointers to xcoff specific swap routines. */
4294 xcoff_swap_ldhdr_in
,
4295 xcoff_swap_ldhdr_out
,
4296 xcoff_swap_ldsym_in
,
4297 xcoff_swap_ldsym_out
,
4298 xcoff_swap_ldrel_in
,
4299 xcoff_swap_ldrel_out
,
4305 12, /* _xcoff_function_descriptor_size */
4309 1, /* _xcoff_ldhdr_version */
4311 _bfd_xcoff_put_symbol_name
,
4312 _bfd_xcoff_put_ldsymbol_name
,
4313 &xcoff_dynamic_reloc
,
4314 xcoff_create_csect_from_smclas
,
4316 /* Lineno and reloc count overflow. */
4317 xcoff_is_lineno_count_overflow
,
4318 xcoff_is_reloc_count_overflow
,
4320 xcoff_loader_symbol_offset
,
4321 xcoff_loader_reloc_offset
,
4324 &xcoff_glink_code
[0],
4325 36, /* _xcoff_glink_size */
4328 0, /* _xcoff_rtinit_size */
4329 xcoff_generate_rtinit
,
4332 /* The transfer vector that leads the outside world to all of the above. */
4333 const bfd_target powerpc_xcoff_vec
=
4336 bfd_target_xcoff_flavour
,
4337 BFD_ENDIAN_BIG
, /* data byte order is big */
4338 BFD_ENDIAN_BIG
, /* header byte order is big */
4340 (HAS_RELOC
| EXEC_P
| HAS_LINENO
| HAS_DEBUG
| DYNAMIC
4341 | HAS_SYMS
| HAS_LOCALS
| WP_TEXT
),
4343 SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_CODE
| SEC_DATA
,
4344 0, /* leading char */
4345 '/', /* ar_pad_char */
4346 15, /* ar_max_namelen */
4347 0, /* match priority. */
4371 { /* bfd_check_format */
4374 _bfd_xcoff_archive_p
,
4378 { /* bfd_set_format */
4381 _bfd_generic_mkarchive
,
4385 {/* bfd_write_contents */
4387 coff_write_object_contents
,
4388 _bfd_xcoff_write_archive_contents
,
4392 BFD_JUMP_TABLE_GENERIC (_bfd_xcoff
),
4393 BFD_JUMP_TABLE_COPY (_bfd_xcoff
),
4394 BFD_JUMP_TABLE_CORE (coff
),
4395 BFD_JUMP_TABLE_ARCHIVE (_bfd_xcoff
),
4396 BFD_JUMP_TABLE_SYMBOLS (_bfd_xcoff
),
4397 BFD_JUMP_TABLE_RELOCS (_bfd_xcoff
),
4398 BFD_JUMP_TABLE_WRITE (coff
),
4399 BFD_JUMP_TABLE_LINK (_bfd_xcoff
),
4400 BFD_JUMP_TABLE_DYNAMIC (_bfd_xcoff
),
4402 /* Opposite endian version, none exists */
4405 & bfd_pmac_xcoff_backend_data
,