1 /* BFD back-end for IBM RS/6000 "XCOFF" files.
2 Copyright 1990-1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 2008, 2009 Free Software Foundation, Inc.
4 Written by Metin G. Ozisik, Mimi Phuong-Thao Vo, and John Gilmore.
5 Archive support from Damon A. Permezel.
6 Contributed by IBM Corporation and Cygnus Support.
8 This file is part of BFD, the Binary File Descriptor library.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
23 MA 02110-1301, USA. */
29 #include "coff/internal.h"
30 #include "coff/xcoff.h"
31 #include "coff/rs6000.h"
35 extern bfd_boolean _bfd_xcoff_mkobject
37 extern bfd_boolean _bfd_xcoff_copy_private_bfd_data
38 PARAMS ((bfd
*, bfd
*));
39 extern bfd_boolean _bfd_xcoff_is_local_label_name
40 PARAMS ((bfd
*, const char *));
41 extern reloc_howto_type
*_bfd_xcoff_reloc_type_lookup
42 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
43 extern bfd_boolean _bfd_xcoff_slurp_armap
45 extern const bfd_target
*_bfd_xcoff_archive_p
47 extern PTR _bfd_xcoff_read_ar_hdr
49 extern bfd
*_bfd_xcoff_openr_next_archived_file
50 PARAMS ((bfd
*, bfd
*));
51 extern int _bfd_xcoff_stat_arch_elt
52 PARAMS ((bfd
*, struct stat
*));
53 extern bfd_boolean _bfd_xcoff_write_armap
54 PARAMS ((bfd
*, unsigned int, struct orl
*, unsigned int, int));
55 extern bfd_boolean _bfd_xcoff_write_archive_contents
57 extern int _bfd_xcoff_sizeof_headers
58 PARAMS ((bfd
*, struct bfd_link_info
*));
59 extern void _bfd_xcoff_swap_sym_in
60 PARAMS ((bfd
*, PTR
, PTR
));
61 extern unsigned int _bfd_xcoff_swap_sym_out
62 PARAMS ((bfd
*, PTR
, PTR
));
63 extern void _bfd_xcoff_swap_aux_in
64 PARAMS ((bfd
*, PTR
, int, int, int, int, PTR
));
65 extern unsigned int _bfd_xcoff_swap_aux_out
66 PARAMS ((bfd
*, PTR
, int, int, int, int, PTR
));
67 static void xcoff_swap_reloc_in
68 PARAMS ((bfd
*, PTR
, PTR
));
69 static unsigned int xcoff_swap_reloc_out
70 PARAMS ((bfd
*, PTR
, PTR
));
72 /* Forward declare xcoff_rtype2howto for coffcode.h macro. */
73 void xcoff_rtype2howto
74 PARAMS ((arelent
*, struct internal_reloc
*));
76 /* coffcode.h needs these to be defined. */
77 #define RS6000COFF_C 1
79 #define SELECT_RELOC(internal, howto) \
81 internal.r_type = howto->type; \
83 ((howto->complain_on_overflow == complain_overflow_signed \
86 | (howto->bitsize - 1)); \
89 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
90 #define COFF_LONG_FILENAMES
91 #define NO_COFF_SYMBOLS
92 #define RTYPE2HOWTO(cache_ptr, dst) xcoff_rtype2howto (cache_ptr, dst)
93 #define coff_mkobject _bfd_xcoff_mkobject
94 #define coff_bfd_copy_private_bfd_data _bfd_xcoff_copy_private_bfd_data
95 #define coff_bfd_is_local_label_name _bfd_xcoff_is_local_label_name
96 #define coff_bfd_reloc_type_lookup _bfd_xcoff_reloc_type_lookup
97 #define coff_bfd_reloc_name_lookup _bfd_xcoff_reloc_name_lookup
99 extern const bfd_target
* rs6000coff_core_p
100 PARAMS ((bfd
*abfd
));
101 extern bfd_boolean rs6000coff_core_file_matches_executable_p
102 PARAMS ((bfd
*cbfd
, bfd
*ebfd
));
103 extern char *rs6000coff_core_file_failing_command
104 PARAMS ((bfd
*abfd
));
105 extern int rs6000coff_core_file_failing_signal
106 PARAMS ((bfd
*abfd
));
107 #define CORE_FILE_P rs6000coff_core_p
108 #define coff_core_file_failing_command \
109 rs6000coff_core_file_failing_command
110 #define coff_core_file_failing_signal \
111 rs6000coff_core_file_failing_signal
112 #define coff_core_file_matches_executable_p \
113 rs6000coff_core_file_matches_executable_p
115 #define CORE_FILE_P _bfd_dummy_target
116 #define coff_core_file_failing_command \
117 _bfd_nocore_core_file_failing_command
118 #define coff_core_file_failing_signal \
119 _bfd_nocore_core_file_failing_signal
120 #define coff_core_file_matches_executable_p \
121 _bfd_nocore_core_file_matches_executable_p
123 #define coff_SWAP_sym_in _bfd_xcoff_swap_sym_in
124 #define coff_SWAP_sym_out _bfd_xcoff_swap_sym_out
125 #define coff_SWAP_aux_in _bfd_xcoff_swap_aux_in
126 #define coff_SWAP_aux_out _bfd_xcoff_swap_aux_out
127 #define coff_swap_reloc_in xcoff_swap_reloc_in
128 #define coff_swap_reloc_out xcoff_swap_reloc_out
129 #define NO_COFF_RELOCS
131 #ifndef bfd_pe_print_pdata
132 #define bfd_pe_print_pdata NULL
135 #include "coffcode.h"
137 /* The main body of code is in coffcode.h. */
139 static const char *normalize_filename
141 static bfd_boolean xcoff_write_armap_old
142 PARAMS ((bfd
*, unsigned int, struct orl
*, unsigned int, int));
143 static bfd_boolean xcoff_write_armap_big
144 PARAMS ((bfd
*, unsigned int, struct orl
*, unsigned int, int));
145 static bfd_boolean xcoff_write_archive_contents_old
147 static bfd_boolean xcoff_write_archive_contents_big
149 static void xcoff_swap_ldhdr_in
150 PARAMS ((bfd
*, const PTR
, struct internal_ldhdr
*));
151 static void xcoff_swap_ldhdr_out
152 PARAMS ((bfd
*, const struct internal_ldhdr
*, PTR
));
153 static void xcoff_swap_ldsym_in
154 PARAMS ((bfd
*, const PTR
, struct internal_ldsym
*));
155 static void xcoff_swap_ldsym_out
156 PARAMS ((bfd
*, const struct internal_ldsym
*, PTR
));
157 static void xcoff_swap_ldrel_in
158 PARAMS ((bfd
*, const PTR
, struct internal_ldrel
*));
159 static void xcoff_swap_ldrel_out
160 PARAMS ((bfd
*, const struct internal_ldrel
*, PTR
));
161 static bfd_boolean xcoff_ppc_relocate_section
162 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
163 struct internal_reloc
*, struct internal_syment
*, asection
**));
164 static bfd_boolean _bfd_xcoff_put_ldsymbol_name
165 PARAMS ((bfd
*, struct xcoff_loader_info
*, struct internal_ldsym
*,
167 static asection
*xcoff_create_csect_from_smclas
168 PARAMS ((bfd
*, union internal_auxent
*, const char *));
169 static bfd_boolean xcoff_is_lineno_count_overflow
170 PARAMS ((bfd
*, bfd_vma
));
171 static bfd_boolean xcoff_is_reloc_count_overflow
172 PARAMS ((bfd
*, bfd_vma
));
173 static bfd_vma xcoff_loader_symbol_offset
174 PARAMS ((bfd
*, struct internal_ldhdr
*));
175 static bfd_vma xcoff_loader_reloc_offset
176 PARAMS ((bfd
*, struct internal_ldhdr
*));
177 static bfd_boolean xcoff_generate_rtinit
178 PARAMS ((bfd
*, const char *, const char *, bfd_boolean
));
179 static bfd_boolean do_pad
180 PARAMS ((bfd
*, unsigned int));
181 static bfd_boolean do_copy
182 PARAMS ((bfd
*, bfd
*));
184 /* Relocation functions */
185 static bfd_boolean xcoff_reloc_type_br
186 PARAMS ((XCOFF_RELOC_FUNCTION_ARGS
));
188 static bfd_boolean xcoff_complain_overflow_dont_func
189 PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS
));
190 static bfd_boolean xcoff_complain_overflow_bitfield_func
191 PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS
));
192 static bfd_boolean xcoff_complain_overflow_signed_func
193 PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS
));
194 static bfd_boolean xcoff_complain_overflow_unsigned_func
195 PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS
));
197 bfd_boolean (*xcoff_calculate_relocation
[XCOFF_MAX_CALCULATE_RELOCATION
])
198 PARAMS ((XCOFF_RELOC_FUNCTION_ARGS
)) =
200 xcoff_reloc_type_pos
, /* R_POS (0x00) */
201 xcoff_reloc_type_neg
, /* R_NEG (0x01) */
202 xcoff_reloc_type_rel
, /* R_REL (0x02) */
203 xcoff_reloc_type_toc
, /* R_TOC (0x03) */
204 xcoff_reloc_type_fail
, /* R_RTB (0x04) */
205 xcoff_reloc_type_toc
, /* R_GL (0x05) */
206 xcoff_reloc_type_toc
, /* R_TCL (0x06) */
207 xcoff_reloc_type_fail
, /* (0x07) */
208 xcoff_reloc_type_ba
, /* R_BA (0x08) */
209 xcoff_reloc_type_fail
, /* (0x09) */
210 xcoff_reloc_type_br
, /* R_BR (0x0a) */
211 xcoff_reloc_type_fail
, /* (0x0b) */
212 xcoff_reloc_type_pos
, /* R_RL (0x0c) */
213 xcoff_reloc_type_pos
, /* R_RLA (0x0d) */
214 xcoff_reloc_type_fail
, /* (0x0e) */
215 xcoff_reloc_type_noop
, /* R_REF (0x0f) */
216 xcoff_reloc_type_fail
, /* (0x10) */
217 xcoff_reloc_type_fail
, /* (0x11) */
218 xcoff_reloc_type_toc
, /* R_TRL (0x12) */
219 xcoff_reloc_type_toc
, /* R_TRLA (0x13) */
220 xcoff_reloc_type_fail
, /* R_RRTBI (0x14) */
221 xcoff_reloc_type_fail
, /* R_RRTBA (0x15) */
222 xcoff_reloc_type_ba
, /* R_CAI (0x16) */
223 xcoff_reloc_type_crel
, /* R_CREL (0x17) */
224 xcoff_reloc_type_ba
, /* R_RBA (0x18) */
225 xcoff_reloc_type_ba
, /* R_RBAC (0x19) */
226 xcoff_reloc_type_br
, /* R_RBR (0x1a) */
227 xcoff_reloc_type_ba
, /* R_RBRC (0x1b) */
230 bfd_boolean (*xcoff_complain_overflow
[XCOFF_MAX_COMPLAIN_OVERFLOW
])
231 PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS
)) =
233 xcoff_complain_overflow_dont_func
,
234 xcoff_complain_overflow_bitfield_func
,
235 xcoff_complain_overflow_signed_func
,
236 xcoff_complain_overflow_unsigned_func
,
239 /* Information about one member of an archive. */
240 struct member_layout
{
241 /* The archive member that this structure describes. */
244 /* The number of bytes of padding that must be inserted before the
245 start of the member in order to ensure that the section contents
246 are correctly aligned. */
247 unsigned int leading_padding
;
249 /* The offset of MEMBER from the start of the archive (i.e. the end
250 of the leading padding). */
253 /* The normalized name of MEMBER. */
256 /* The length of NAME, without padding. */
257 bfd_size_type namlen
;
259 /* The length of NAME, with padding. */
260 bfd_size_type padded_namlen
;
262 /* The size of MEMBER's header, including the name and magic sequence. */
263 bfd_size_type header_size
;
265 /* The size of the MEMBER's contents. */
266 bfd_size_type contents_size
;
268 /* The number of bytes of padding that must be inserted after MEMBER
269 in order to preserve even alignment. */
270 bfd_size_type trailing_padding
;
273 /* A structure used for iterating over the members of an archive. */
274 struct archive_iterator
{
275 /* The archive itself. */
278 /* Information about the current archive member. */
279 struct member_layout current
;
281 /* Information about the next archive member. MEMBER is null if there
282 are no more archive members, in which case OFFSET is the offset of
283 the first unused byte. */
284 struct member_layout next
;
287 /* Initialize INFO so that it describes member MEMBER of archive ARCHIVE.
288 OFFSET is the even-padded offset of MEMBER, not including any leading
289 padding needed for section alignment. */
292 member_layout_init (struct member_layout
*info
, bfd
*archive
,
293 bfd
*member
, file_ptr offset
)
295 info
->member
= member
;
296 info
->leading_padding
= 0;
299 info
->name
= normalize_filename (member
);
300 info
->namlen
= strlen (info
->name
);
301 info
->padded_namlen
= info
->namlen
+ (info
->namlen
& 1);
302 if (xcoff_big_format_p (archive
))
303 info
->header_size
= SIZEOF_AR_HDR_BIG
;
305 info
->header_size
= SIZEOF_AR_HDR
;
306 info
->header_size
+= info
->padded_namlen
+ SXCOFFARFMAG
;
307 info
->contents_size
= arelt_size (member
);
308 info
->trailing_padding
= info
->contents_size
& 1;
310 if (bfd_check_format (member
, bfd_object
)
311 && bfd_get_flavour (member
) == bfd_target_xcoff_flavour
312 && (member
->flags
& DYNAMIC
) != 0)
313 info
->leading_padding
314 = (-(offset
+ info
->header_size
)
315 & ((1 << bfd_xcoff_text_align_power (member
)) - 1));
317 info
->offset
= offset
+ info
->leading_padding
;
320 /* Set up ITERATOR to iterate through archive ARCHIVE. */
323 archive_iterator_begin (struct archive_iterator
*iterator
,
326 iterator
->archive
= archive
;
327 member_layout_init (&iterator
->next
, archive
, archive
->archive_head
,
328 xcoff_big_format_p (archive
)
329 ? SIZEOF_AR_FILE_HDR_BIG
330 : SIZEOF_AR_FILE_HDR
);
333 /* Make ITERATOR visit the first unvisited archive member. Return true
334 on success; return false if all members have been visited. */
337 archive_iterator_next (struct archive_iterator
*iterator
)
339 if (!iterator
->next
.member
)
342 iterator
->current
= iterator
->next
;
343 member_layout_init (&iterator
->next
, iterator
->archive
,
344 iterator
->current
.member
->archive_next
,
345 iterator
->current
.offset
346 + iterator
->current
.header_size
347 + iterator
->current
.contents_size
348 + iterator
->current
.trailing_padding
);
352 /* We use our own tdata type. Its first field is the COFF tdata type,
353 so the COFF routines are compatible. */
356 _bfd_xcoff_mkobject (abfd
)
359 coff_data_type
*coff
;
360 bfd_size_type amt
= sizeof (struct xcoff_tdata
);
362 abfd
->tdata
.xcoff_obj_data
= (struct xcoff_tdata
*) bfd_zalloc (abfd
, amt
);
363 if (abfd
->tdata
.xcoff_obj_data
== NULL
)
365 coff
= coff_data (abfd
);
366 coff
->symbols
= (coff_symbol_type
*) NULL
;
367 coff
->conversion_table
= (unsigned int *) NULL
;
368 coff
->raw_syments
= (struct coff_ptr_struct
*) NULL
;
371 xcoff_data (abfd
)->modtype
= ('1' << 8) | 'L';
373 /* We set cputype to -1 to indicate that it has not been
375 xcoff_data (abfd
)->cputype
= -1;
377 xcoff_data (abfd
)->csects
= NULL
;
378 xcoff_data (abfd
)->debug_indices
= NULL
;
380 /* text section alignment is different than the default */
381 bfd_xcoff_text_align_power (abfd
) = 2;
386 /* Copy XCOFF data from one BFD to another. */
389 _bfd_xcoff_copy_private_bfd_data (ibfd
, obfd
)
393 struct xcoff_tdata
*ix
, *ox
;
396 if (ibfd
->xvec
!= obfd
->xvec
)
398 ix
= xcoff_data (ibfd
);
399 ox
= xcoff_data (obfd
);
400 ox
->full_aouthdr
= ix
->full_aouthdr
;
406 sec
= coff_section_from_bfd_index (ibfd
, ix
->sntoc
);
410 ox
->sntoc
= sec
->output_section
->target_index
;
412 if (ix
->snentry
== 0)
416 sec
= coff_section_from_bfd_index (ibfd
, ix
->snentry
);
420 ox
->snentry
= sec
->output_section
->target_index
;
422 bfd_xcoff_text_align_power (obfd
) = bfd_xcoff_text_align_power (ibfd
);
423 bfd_xcoff_data_align_power (obfd
) = bfd_xcoff_data_align_power (ibfd
);
424 ox
->modtype
= ix
->modtype
;
425 ox
->cputype
= ix
->cputype
;
426 ox
->maxdata
= ix
->maxdata
;
427 ox
->maxstack
= ix
->maxstack
;
431 /* I don't think XCOFF really has a notion of local labels based on
432 name. This will mean that ld -X doesn't actually strip anything.
433 The AIX native linker does not have a -X option, and it ignores the
437 _bfd_xcoff_is_local_label_name (abfd
, name
)
438 bfd
*abfd ATTRIBUTE_UNUSED
;
439 const char *name ATTRIBUTE_UNUSED
;
445 _bfd_xcoff_swap_sym_in (abfd
, ext1
, in1
)
450 SYMENT
*ext
= (SYMENT
*)ext1
;
451 struct internal_syment
* in
= (struct internal_syment
*)in1
;
453 if (ext
->e
.e_name
[0] != 0)
455 memcpy (in
->_n
._n_name
, ext
->e
.e_name
, SYMNMLEN
);
459 in
->_n
._n_n
._n_zeroes
= 0;
460 in
->_n
._n_n
._n_offset
= H_GET_32 (abfd
, ext
->e
.e
.e_offset
);
463 in
->n_value
= H_GET_32 (abfd
, ext
->e_value
);
464 in
->n_scnum
= H_GET_16 (abfd
, ext
->e_scnum
);
465 in
->n_type
= H_GET_16 (abfd
, ext
->e_type
);
466 in
->n_sclass
= H_GET_8 (abfd
, ext
->e_sclass
);
467 in
->n_numaux
= H_GET_8 (abfd
, ext
->e_numaux
);
471 _bfd_xcoff_swap_sym_out (abfd
, inp
, extp
)
476 struct internal_syment
*in
= (struct internal_syment
*)inp
;
477 SYMENT
*ext
=(SYMENT
*)extp
;
479 if (in
->_n
._n_name
[0] != 0)
481 memcpy (ext
->e
.e_name
, in
->_n
._n_name
, SYMNMLEN
);
485 H_PUT_32 (abfd
, 0, ext
->e
.e
.e_zeroes
);
486 H_PUT_32 (abfd
, in
->_n
._n_n
._n_offset
, ext
->e
.e
.e_offset
);
489 H_PUT_32 (abfd
, in
->n_value
, ext
->e_value
);
490 H_PUT_16 (abfd
, in
->n_scnum
, ext
->e_scnum
);
491 H_PUT_16 (abfd
, in
->n_type
, ext
->e_type
);
492 H_PUT_8 (abfd
, in
->n_sclass
, ext
->e_sclass
);
493 H_PUT_8 (abfd
, in
->n_numaux
, ext
->e_numaux
);
494 return bfd_coff_symesz (abfd
);
498 _bfd_xcoff_swap_aux_in (abfd
, ext1
, type
, class, indx
, numaux
, in1
)
507 AUXENT
* ext
= (AUXENT
*)ext1
;
508 union internal_auxent
*in
= (union internal_auxent
*)in1
;
513 if (ext
->x_file
.x_fname
[0] == 0)
515 in
->x_file
.x_n
.x_zeroes
= 0;
516 in
->x_file
.x_n
.x_offset
=
517 H_GET_32 (abfd
, ext
->x_file
.x_n
.x_offset
);
524 memcpy (in
->x_file
.x_fname
, ext
->x_file
.x_fname
,
525 numaux
* sizeof (AUXENT
));
529 memcpy (in
->x_file
.x_fname
, ext
->x_file
.x_fname
, FILNMLEN
);
534 /* RS/6000 "csect" auxents */
538 if (indx
+ 1 == numaux
)
540 in
->x_csect
.x_scnlen
.l
= H_GET_32 (abfd
, ext
->x_csect
.x_scnlen
);
541 in
->x_csect
.x_parmhash
= H_GET_32 (abfd
, ext
->x_csect
.x_parmhash
);
542 in
->x_csect
.x_snhash
= H_GET_16 (abfd
, ext
->x_csect
.x_snhash
);
543 /* We don't have to hack bitfields in x_smtyp because it's
544 defined by shifts-and-ands, which are equivalent on all
546 in
->x_csect
.x_smtyp
= H_GET_8 (abfd
, ext
->x_csect
.x_smtyp
);
547 in
->x_csect
.x_smclas
= H_GET_8 (abfd
, ext
->x_csect
.x_smclas
);
548 in
->x_csect
.x_stab
= H_GET_32 (abfd
, ext
->x_csect
.x_stab
);
549 in
->x_csect
.x_snstab
= H_GET_16 (abfd
, ext
->x_csect
.x_snstab
);
559 in
->x_scn
.x_scnlen
= H_GET_32 (abfd
, ext
->x_scn
.x_scnlen
);
560 in
->x_scn
.x_nreloc
= H_GET_16 (abfd
, ext
->x_scn
.x_nreloc
);
561 in
->x_scn
.x_nlinno
= H_GET_16 (abfd
, ext
->x_scn
.x_nlinno
);
562 /* PE defines some extra fields; we zero them out for
564 in
->x_scn
.x_checksum
= 0;
565 in
->x_scn
.x_associated
= 0;
566 in
->x_scn
.x_comdat
= 0;
573 in
->x_sym
.x_tagndx
.l
= H_GET_32 (abfd
, ext
->x_sym
.x_tagndx
);
574 in
->x_sym
.x_tvndx
= H_GET_16 (abfd
, ext
->x_sym
.x_tvndx
);
576 if (class == C_BLOCK
|| class == C_FCN
|| ISFCN (type
) || ISTAG (class))
578 in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
=
579 H_GET_32 (abfd
, ext
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
580 in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
=
581 H_GET_32 (abfd
, ext
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
585 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0] =
586 H_GET_16 (abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
587 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1] =
588 H_GET_16 (abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
589 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2] =
590 H_GET_16 (abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
591 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3] =
592 H_GET_16 (abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
597 in
->x_sym
.x_misc
.x_fsize
= H_GET_32 (abfd
, ext
->x_sym
.x_misc
.x_fsize
);
601 in
->x_sym
.x_misc
.x_lnsz
.x_lnno
=
602 H_GET_16 (abfd
, ext
->x_sym
.x_misc
.x_lnsz
.x_lnno
);
603 in
->x_sym
.x_misc
.x_lnsz
.x_size
=
604 H_GET_16 (abfd
, ext
->x_sym
.x_misc
.x_lnsz
.x_size
);
608 /* The semicolon is because MSVC doesn't like labels at
613 unsigned int _bfd_xcoff_swap_aux_out
614 PARAMS ((bfd
*, PTR
, int, int, int, int, PTR
));
617 _bfd_xcoff_swap_aux_out (abfd
, inp
, type
, class, indx
, numaux
, extp
)
622 int indx ATTRIBUTE_UNUSED
;
623 int numaux ATTRIBUTE_UNUSED
;
626 union internal_auxent
*in
= (union internal_auxent
*)inp
;
627 AUXENT
*ext
= (AUXENT
*)extp
;
629 memset ((PTR
)ext
, 0, bfd_coff_auxesz (abfd
));
633 if (in
->x_file
.x_fname
[0] == 0)
635 H_PUT_32 (abfd
, 0, ext
->x_file
.x_n
.x_zeroes
);
636 H_PUT_32 (abfd
, in
->x_file
.x_n
.x_offset
, ext
->x_file
.x_n
.x_offset
);
640 memcpy (ext
->x_file
.x_fname
, in
->x_file
.x_fname
, FILNMLEN
);
644 /* RS/6000 "csect" auxents */
648 if (indx
+ 1 == numaux
)
650 H_PUT_32 (abfd
, in
->x_csect
.x_scnlen
.l
, ext
->x_csect
.x_scnlen
);
651 H_PUT_32 (abfd
, in
->x_csect
.x_parmhash
, ext
->x_csect
.x_parmhash
);
652 H_PUT_16 (abfd
, in
->x_csect
.x_snhash
, ext
->x_csect
.x_snhash
);
653 /* We don't have to hack bitfields in x_smtyp because it's
654 defined by shifts-and-ands, which are equivalent on all
656 H_PUT_8 (abfd
, in
->x_csect
.x_smtyp
, ext
->x_csect
.x_smtyp
);
657 H_PUT_8 (abfd
, in
->x_csect
.x_smclas
, ext
->x_csect
.x_smclas
);
658 H_PUT_32 (abfd
, in
->x_csect
.x_stab
, ext
->x_csect
.x_stab
);
659 H_PUT_16 (abfd
, in
->x_csect
.x_snstab
, ext
->x_csect
.x_snstab
);
669 H_PUT_32 (abfd
, in
->x_scn
.x_scnlen
, ext
->x_scn
.x_scnlen
);
670 H_PUT_16 (abfd
, in
->x_scn
.x_nreloc
, ext
->x_scn
.x_nreloc
);
671 H_PUT_16 (abfd
, in
->x_scn
.x_nlinno
, ext
->x_scn
.x_nlinno
);
677 H_PUT_32 (abfd
, in
->x_sym
.x_tagndx
.l
, ext
->x_sym
.x_tagndx
);
678 H_PUT_16 (abfd
, in
->x_sym
.x_tvndx
, ext
->x_sym
.x_tvndx
);
680 if (class == C_BLOCK
|| class == C_FCN
|| ISFCN (type
) || ISTAG (class))
682 H_PUT_32 (abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
,
683 ext
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
684 H_PUT_32 (abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
,
685 ext
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
689 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0],
690 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
691 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1],
692 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
693 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2],
694 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
695 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3],
696 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
700 H_PUT_32 (abfd
, in
->x_sym
.x_misc
.x_fsize
, ext
->x_sym
.x_misc
.x_fsize
);
703 H_PUT_16 (abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_lnno
,
704 ext
->x_sym
.x_misc
.x_lnsz
.x_lnno
);
705 H_PUT_16 (abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_size
,
706 ext
->x_sym
.x_misc
.x_lnsz
.x_size
);
710 return bfd_coff_auxesz (abfd
);
715 /* The XCOFF reloc table. Actually, XCOFF relocations specify the
716 bitsize and whether they are signed or not, along with a
717 conventional type. This table is for the types, which are used for
718 different algorithms for putting in the reloc. Many of these
719 relocs need special_function entries, which I have not written. */
722 reloc_howto_type xcoff_howto_table
[] =
724 /* Standard 32 bit relocation. */
725 HOWTO (R_POS
, /* type */
727 2, /* size (0 = byte, 1 = short, 2 = long) */
729 FALSE
, /* pc_relative */
731 complain_overflow_bitfield
, /* complain_on_overflow */
732 0, /* special_function */
734 TRUE
, /* partial_inplace */
735 0xffffffff, /* src_mask */
736 0xffffffff, /* dst_mask */
737 FALSE
), /* pcrel_offset */
739 /* 32 bit relocation, but store negative value. */
740 HOWTO (R_NEG
, /* type */
742 -2, /* size (0 = byte, 1 = short, 2 = long) */
744 FALSE
, /* pc_relative */
746 complain_overflow_bitfield
, /* complain_on_overflow */
747 0, /* special_function */
749 TRUE
, /* partial_inplace */
750 0xffffffff, /* src_mask */
751 0xffffffff, /* dst_mask */
752 FALSE
), /* pcrel_offset */
754 /* 32 bit PC relative relocation. */
755 HOWTO (R_REL
, /* type */
757 2, /* size (0 = byte, 1 = short, 2 = long) */
759 TRUE
, /* pc_relative */
761 complain_overflow_signed
, /* complain_on_overflow */
762 0, /* special_function */
764 TRUE
, /* partial_inplace */
765 0xffffffff, /* src_mask */
766 0xffffffff, /* dst_mask */
767 FALSE
), /* pcrel_offset */
769 /* 16 bit TOC relative relocation. */
770 HOWTO (R_TOC
, /* type */
772 1, /* size (0 = byte, 1 = short, 2 = long) */
774 FALSE
, /* pc_relative */
776 complain_overflow_bitfield
, /* complain_on_overflow */
777 0, /* special_function */
779 TRUE
, /* partial_inplace */
780 0xffff, /* src_mask */
781 0xffff, /* dst_mask */
782 FALSE
), /* pcrel_offset */
784 /* I don't really know what this is. */
785 HOWTO (R_RTB
, /* type */
787 2, /* size (0 = byte, 1 = short, 2 = long) */
789 FALSE
, /* pc_relative */
791 complain_overflow_bitfield
, /* complain_on_overflow */
792 0, /* special_function */
794 TRUE
, /* partial_inplace */
795 0xffffffff, /* src_mask */
796 0xffffffff, /* dst_mask */
797 FALSE
), /* pcrel_offset */
799 /* External TOC relative symbol. */
800 HOWTO (R_GL
, /* type */
802 1, /* size (0 = byte, 1 = short, 2 = long) */
804 FALSE
, /* pc_relative */
806 complain_overflow_bitfield
, /* complain_on_overflow */
807 0, /* special_function */
809 TRUE
, /* partial_inplace */
810 0xffff, /* src_mask */
811 0xffff, /* dst_mask */
812 FALSE
), /* pcrel_offset */
814 /* Local TOC relative symbol. */
815 HOWTO (R_TCL
, /* type */
817 1, /* size (0 = byte, 1 = short, 2 = long) */
819 FALSE
, /* pc_relative */
821 complain_overflow_bitfield
, /* complain_on_overflow */
822 0, /* special_function */
824 TRUE
, /* partial_inplace */
825 0xffff, /* src_mask */
826 0xffff, /* dst_mask */
827 FALSE
), /* pcrel_offset */
831 /* Non modifiable absolute branch. */
832 HOWTO (R_BA
, /* type */
834 2, /* size (0 = byte, 1 = short, 2 = long) */
836 FALSE
, /* pc_relative */
838 complain_overflow_bitfield
, /* complain_on_overflow */
839 0, /* special_function */
840 "R_BA_26", /* name */
841 TRUE
, /* partial_inplace */
842 0x03fffffc, /* src_mask */
843 0x03fffffc, /* dst_mask */
844 FALSE
), /* pcrel_offset */
848 /* Non modifiable relative branch. */
849 HOWTO (R_BR
, /* type */
851 2, /* size (0 = byte, 1 = short, 2 = long) */
853 TRUE
, /* pc_relative */
855 complain_overflow_signed
, /* complain_on_overflow */
856 0, /* special_function */
858 TRUE
, /* partial_inplace */
859 0x03fffffc, /* src_mask */
860 0x03fffffc, /* dst_mask */
861 FALSE
), /* pcrel_offset */
866 HOWTO (R_RL
, /* type */
868 1, /* size (0 = byte, 1 = short, 2 = long) */
870 FALSE
, /* pc_relative */
872 complain_overflow_bitfield
, /* complain_on_overflow */
873 0, /* special_function */
875 TRUE
, /* partial_inplace */
876 0xffff, /* src_mask */
877 0xffff, /* dst_mask */
878 FALSE
), /* pcrel_offset */
881 HOWTO (R_RLA
, /* type */
883 1, /* size (0 = byte, 1 = short, 2 = long) */
885 FALSE
, /* pc_relative */
887 complain_overflow_bitfield
, /* complain_on_overflow */
888 0, /* special_function */
890 TRUE
, /* partial_inplace */
891 0xffff, /* src_mask */
892 0xffff, /* dst_mask */
893 FALSE
), /* pcrel_offset */
897 /* Non-relocating reference. */
898 HOWTO (R_REF
, /* type */
900 2, /* size (0 = byte, 1 = short, 2 = long) */
902 FALSE
, /* pc_relative */
904 complain_overflow_dont
, /* complain_on_overflow */
905 0, /* special_function */
907 FALSE
, /* partial_inplace */
910 FALSE
), /* pcrel_offset */
915 /* TOC relative indirect load. */
916 HOWTO (R_TRL
, /* type */
918 1, /* size (0 = byte, 1 = short, 2 = long) */
920 FALSE
, /* pc_relative */
922 complain_overflow_bitfield
, /* complain_on_overflow */
923 0, /* special_function */
925 TRUE
, /* partial_inplace */
926 0xffff, /* src_mask */
927 0xffff, /* dst_mask */
928 FALSE
), /* pcrel_offset */
930 /* TOC relative load address. */
931 HOWTO (R_TRLA
, /* type */
933 1, /* size (0 = byte, 1 = short, 2 = long) */
935 FALSE
, /* pc_relative */
937 complain_overflow_bitfield
, /* complain_on_overflow */
938 0, /* special_function */
940 TRUE
, /* partial_inplace */
941 0xffff, /* src_mask */
942 0xffff, /* dst_mask */
943 FALSE
), /* pcrel_offset */
945 /* Modifiable relative branch. */
946 HOWTO (R_RRTBI
, /* type */
948 2, /* size (0 = byte, 1 = short, 2 = long) */
950 FALSE
, /* pc_relative */
952 complain_overflow_bitfield
, /* complain_on_overflow */
953 0, /* special_function */
954 "R_RRTBI", /* name */
955 TRUE
, /* partial_inplace */
956 0xffffffff, /* src_mask */
957 0xffffffff, /* dst_mask */
958 FALSE
), /* pcrel_offset */
960 /* Modifiable absolute branch. */
961 HOWTO (R_RRTBA
, /* type */
963 2, /* size (0 = byte, 1 = short, 2 = long) */
965 FALSE
, /* pc_relative */
967 complain_overflow_bitfield
, /* complain_on_overflow */
968 0, /* special_function */
969 "R_RRTBA", /* name */
970 TRUE
, /* partial_inplace */
971 0xffffffff, /* src_mask */
972 0xffffffff, /* dst_mask */
973 FALSE
), /* pcrel_offset */
975 /* Modifiable call absolute indirect. */
976 HOWTO (R_CAI
, /* type */
978 1, /* size (0 = byte, 1 = short, 2 = long) */
980 FALSE
, /* pc_relative */
982 complain_overflow_bitfield
, /* complain_on_overflow */
983 0, /* special_function */
985 TRUE
, /* partial_inplace */
986 0xffff, /* src_mask */
987 0xffff, /* dst_mask */
988 FALSE
), /* pcrel_offset */
990 /* Modifiable call relative. */
991 HOWTO (R_CREL
, /* type */
993 1, /* size (0 = byte, 1 = short, 2 = long) */
995 FALSE
, /* pc_relative */
997 complain_overflow_bitfield
, /* complain_on_overflow */
998 0, /* special_function */
1000 TRUE
, /* partial_inplace */
1001 0xffff, /* src_mask */
1002 0xffff, /* dst_mask */
1003 FALSE
), /* pcrel_offset */
1005 /* Modifiable branch absolute. */
1006 HOWTO (R_RBA
, /* type */
1008 2, /* size (0 = byte, 1 = short, 2 = long) */
1010 FALSE
, /* pc_relative */
1012 complain_overflow_bitfield
, /* complain_on_overflow */
1013 0, /* special_function */
1015 TRUE
, /* partial_inplace */
1016 0x03fffffc, /* src_mask */
1017 0x03fffffc, /* dst_mask */
1018 FALSE
), /* pcrel_offset */
1020 /* Modifiable branch absolute. */
1021 HOWTO (R_RBAC
, /* type */
1023 2, /* size (0 = byte, 1 = short, 2 = long) */
1025 FALSE
, /* pc_relative */
1027 complain_overflow_bitfield
, /* complain_on_overflow */
1028 0, /* special_function */
1029 "R_RBAC", /* name */
1030 TRUE
, /* partial_inplace */
1031 0xffffffff, /* src_mask */
1032 0xffffffff, /* dst_mask */
1033 FALSE
), /* pcrel_offset */
1035 /* Modifiable branch relative. */
1036 HOWTO (R_RBR
, /* type */
1038 2, /* size (0 = byte, 1 = short, 2 = long) */
1040 FALSE
, /* pc_relative */
1042 complain_overflow_signed
, /* complain_on_overflow */
1043 0, /* special_function */
1044 "R_RBR_26", /* name */
1045 TRUE
, /* partial_inplace */
1046 0x03fffffc, /* src_mask */
1047 0x03fffffc, /* dst_mask */
1048 FALSE
), /* pcrel_offset */
1050 /* Modifiable branch absolute. */
1051 HOWTO (R_RBRC
, /* type */
1053 1, /* size (0 = byte, 1 = short, 2 = long) */
1055 FALSE
, /* pc_relative */
1057 complain_overflow_bitfield
, /* complain_on_overflow */
1058 0, /* special_function */
1059 "R_RBRC", /* name */
1060 TRUE
, /* partial_inplace */
1061 0xffff, /* src_mask */
1062 0xffff, /* dst_mask */
1063 FALSE
), /* pcrel_offset */
1065 /* 16 bit Non modifiable absolute branch. */
1066 HOWTO (R_BA
, /* type */
1068 1, /* size (0 = byte, 1 = short, 2 = long) */
1070 FALSE
, /* pc_relative */
1072 complain_overflow_bitfield
, /* complain_on_overflow */
1073 0, /* special_function */
1074 "R_BA_16", /* name */
1075 TRUE
, /* partial_inplace */
1076 0xfffc, /* src_mask */
1077 0xfffc, /* dst_mask */
1078 FALSE
), /* pcrel_offset */
1080 /* Modifiable branch relative. */
1081 HOWTO (R_RBR
, /* type */
1083 1, /* size (0 = byte, 1 = short, 2 = long) */
1085 FALSE
, /* pc_relative */
1087 complain_overflow_signed
, /* complain_on_overflow */
1088 0, /* special_function */
1089 "R_RBR_16", /* name */
1090 TRUE
, /* partial_inplace */
1091 0xffff, /* src_mask */
1092 0xffff, /* dst_mask */
1093 FALSE
), /* pcrel_offset */
1095 /* Modifiable branch relative. */
1096 HOWTO (R_RBA
, /* type */
1098 1, /* size (0 = byte, 1 = short, 2 = long) */
1100 FALSE
, /* pc_relative */
1102 complain_overflow_signed
, /* complain_on_overflow */
1103 0, /* special_function */
1104 "R_RBA_16", /* name */
1105 TRUE
, /* partial_inplace */
1106 0xffff, /* src_mask */
1107 0xffff, /* dst_mask */
1108 FALSE
), /* pcrel_offset */
1113 xcoff_rtype2howto (relent
, internal
)
1115 struct internal_reloc
*internal
;
1117 if (internal
->r_type
> R_RBRC
)
1120 /* Default howto layout works most of the time */
1121 relent
->howto
= &xcoff_howto_table
[internal
->r_type
];
1123 /* Special case some 16 bit reloc */
1124 if (15 == (internal
->r_size
& 0x1f))
1126 if (R_BA
== internal
->r_type
)
1127 relent
->howto
= &xcoff_howto_table
[0x1c];
1128 else if (R_RBR
== internal
->r_type
)
1129 relent
->howto
= &xcoff_howto_table
[0x1d];
1130 else if (R_RBA
== internal
->r_type
)
1131 relent
->howto
= &xcoff_howto_table
[0x1e];
1134 /* The r_size field of an XCOFF reloc encodes the bitsize of the
1135 relocation, as well as indicating whether it is signed or not.
1136 Doublecheck that the relocation information gathered from the
1137 type matches this information. The bitsize is not significant
1138 for R_REF relocs. */
1139 if (relent
->howto
->dst_mask
!= 0
1140 && (relent
->howto
->bitsize
1141 != ((unsigned int) internal
->r_size
& 0x1f) + 1))
1146 _bfd_xcoff_reloc_type_lookup (abfd
, code
)
1147 bfd
*abfd ATTRIBUTE_UNUSED
;
1148 bfd_reloc_code_real_type code
;
1152 case BFD_RELOC_PPC_B26
:
1153 return &xcoff_howto_table
[0xa];
1154 case BFD_RELOC_PPC_BA16
:
1155 return &xcoff_howto_table
[0x1c];
1156 case BFD_RELOC_PPC_BA26
:
1157 return &xcoff_howto_table
[8];
1158 case BFD_RELOC_PPC_TOC16
:
1159 return &xcoff_howto_table
[3];
1161 case BFD_RELOC_CTOR
:
1162 return &xcoff_howto_table
[0];
1168 static reloc_howto_type
*
1169 _bfd_xcoff_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1175 i
< sizeof (xcoff_howto_table
) / sizeof (xcoff_howto_table
[0]);
1177 if (xcoff_howto_table
[i
].name
!= NULL
1178 && strcasecmp (xcoff_howto_table
[i
].name
, r_name
) == 0)
1179 return &xcoff_howto_table
[i
];
1184 /* XCOFF archive support. The original version of this code was by
1185 Damon A. Permezel. It was enhanced to permit cross support, and
1186 writing archive files, by Ian Lance Taylor, Cygnus Support.
1188 XCOFF uses its own archive format. Everything is hooked together
1189 with file offset links, so it is possible to rapidly update an
1190 archive in place. Of course, we don't do that. An XCOFF archive
1191 has a real file header, not just an ARMAG string. The structure of
1192 the file header and of each archive header appear below.
1194 An XCOFF archive also has a member table, which is a list of
1195 elements in the archive (you can get that by looking through the
1196 linked list, but you have to read a lot more of the file). The
1197 member table has a normal archive header with an empty name. It is
1198 normally (and perhaps must be) the second to last entry in the
1199 archive. The member table data is almost printable ASCII. It
1200 starts with a 12 character decimal string which is the number of
1201 entries in the table. For each entry it has a 12 character decimal
1202 string which is the offset in the archive of that member. These
1203 entries are followed by a series of null terminated strings which
1204 are the member names for each entry.
1206 Finally, an XCOFF archive has a global symbol table, which is what
1207 we call the armap. The global symbol table has a normal archive
1208 header with an empty name. It is normally (and perhaps must be)
1209 the last entry in the archive. The contents start with a four byte
1210 binary number which is the number of entries. This is followed by
1211 a that many four byte binary numbers; each is the file offset of an
1212 entry in the archive. These numbers are followed by a series of
1213 null terminated strings, which are symbol names.
1215 AIX 4.3 introduced a new archive format which can handle larger
1216 files and also 32- and 64-bit objects in the same archive. The
1217 things said above remain true except that there is now more than
1218 one global symbol table. The one is used to index 32-bit objects,
1219 the other for 64-bit objects.
1221 The new archives (recognizable by the new ARMAG string) has larger
1222 field lengths so that we cannot really share any code. Also we have
1223 to take care that we are not generating the new form of archives
1224 on AIX 4.2 or earlier systems. */
1226 /* XCOFF archives use this as a magic string. Note that both strings
1227 have the same length. */
1229 /* Set the magic for archive. */
1232 bfd_xcoff_ar_archive_set_magic (abfd
, magic
)
1233 bfd
*abfd ATTRIBUTE_UNUSED
;
1234 char *magic ATTRIBUTE_UNUSED
;
1236 /* Not supported yet. */
1238 /* bfd_xcoff_archive_set_magic (abfd, magic); */
1241 /* Read in the armap of an XCOFF archive. */
1244 _bfd_xcoff_slurp_armap (abfd
)
1250 bfd_byte
*contents
, *cend
;
1255 if (xcoff_ardata (abfd
) == NULL
)
1257 bfd_has_map (abfd
) = FALSE
;
1261 if (! xcoff_big_format_p (abfd
))
1263 /* This is for the old format. */
1264 struct xcoff_ar_hdr hdr
;
1266 off
= strtol (xcoff_ardata (abfd
)->symoff
, (char **) NULL
, 10);
1269 bfd_has_map (abfd
) = FALSE
;
1273 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0)
1276 /* The symbol table starts with a normal archive header. */
1277 if (bfd_bread ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1281 /* Skip the name (normally empty). */
1282 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1283 off
= ((namlen
+ 1) & ~ (size_t) 1) + SXCOFFARFMAG
;
1284 if (bfd_seek (abfd
, off
, SEEK_CUR
) != 0)
1287 sz
= strtol (hdr
.size
, (char **) NULL
, 10);
1289 /* Read in the entire symbol table. */
1290 contents
= (bfd_byte
*) bfd_alloc (abfd
, sz
);
1291 if (contents
== NULL
)
1293 if (bfd_bread ((PTR
) contents
, sz
, abfd
) != sz
)
1296 /* The symbol table starts with a four byte count. */
1297 c
= H_GET_32 (abfd
, contents
);
1301 bfd_set_error (bfd_error_bad_value
);
1305 bfd_ardata (abfd
)->symdefs
=
1306 ((carsym
*) bfd_alloc (abfd
, c
* sizeof (carsym
)));
1307 if (bfd_ardata (abfd
)->symdefs
== NULL
)
1310 /* After the count comes a list of four byte file offsets. */
1311 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
, p
= contents
+ 4;
1313 ++i
, ++arsym
, p
+= 4)
1314 arsym
->file_offset
= H_GET_32 (abfd
, p
);
1318 /* This is for the new format. */
1319 struct xcoff_ar_hdr_big hdr
;
1321 off
= strtol (xcoff_ardata_big (abfd
)->symoff
, (char **) NULL
, 10);
1324 bfd_has_map (abfd
) = FALSE
;
1328 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0)
1331 /* The symbol table starts with a normal archive header. */
1332 if (bfd_bread ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR_BIG
, abfd
)
1333 != SIZEOF_AR_HDR_BIG
)
1336 /* Skip the name (normally empty). */
1337 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1338 off
= ((namlen
+ 1) & ~ (size_t) 1) + SXCOFFARFMAG
;
1339 if (bfd_seek (abfd
, off
, SEEK_CUR
) != 0)
1342 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1343 machines) since the field width is 20 and there numbers with more
1344 than 32 bits can be represented. */
1345 sz
= strtol (hdr
.size
, (char **) NULL
, 10);
1347 /* Read in the entire symbol table. */
1348 contents
= (bfd_byte
*) bfd_alloc (abfd
, sz
);
1349 if (contents
== NULL
)
1351 if (bfd_bread ((PTR
) contents
, sz
, abfd
) != sz
)
1354 /* The symbol table starts with an eight byte count. */
1355 c
= H_GET_64 (abfd
, contents
);
1359 bfd_set_error (bfd_error_bad_value
);
1363 bfd_ardata (abfd
)->symdefs
=
1364 ((carsym
*) bfd_alloc (abfd
, c
* sizeof (carsym
)));
1365 if (bfd_ardata (abfd
)->symdefs
== NULL
)
1368 /* After the count comes a list of eight byte file offsets. */
1369 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
, p
= contents
+ 8;
1371 ++i
, ++arsym
, p
+= 8)
1372 arsym
->file_offset
= H_GET_64 (abfd
, p
);
1375 /* After the file offsets come null terminated symbol names. */
1376 cend
= contents
+ sz
;
1377 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
;
1379 ++i
, ++arsym
, p
+= strlen ((char *) p
) + 1)
1383 bfd_set_error (bfd_error_bad_value
);
1386 arsym
->name
= (char *) p
;
1389 bfd_ardata (abfd
)->symdef_count
= c
;
1390 bfd_has_map (abfd
) = TRUE
;
1395 /* See if this is an XCOFF archive. */
1398 _bfd_xcoff_archive_p (abfd
)
1401 struct artdata
*tdata_hold
;
1402 char magic
[SXCOFFARMAG
];
1403 bfd_size_type amt
= SXCOFFARMAG
;
1405 if (bfd_bread ((PTR
) magic
, amt
, abfd
) != amt
)
1407 if (bfd_get_error () != bfd_error_system_call
)
1408 bfd_set_error (bfd_error_wrong_format
);
1412 if (strncmp (magic
, XCOFFARMAG
, SXCOFFARMAG
) != 0
1413 && strncmp (magic
, XCOFFARMAGBIG
, SXCOFFARMAG
) != 0)
1415 bfd_set_error (bfd_error_wrong_format
);
1419 tdata_hold
= bfd_ardata (abfd
);
1421 amt
= sizeof (struct artdata
);
1422 bfd_ardata (abfd
) = (struct artdata
*) bfd_zalloc (abfd
, amt
);
1423 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
1424 goto error_ret_restore
;
1426 /* Cleared by bfd_zalloc above.
1427 bfd_ardata (abfd)->cache = NULL;
1428 bfd_ardata (abfd)->archive_head = NULL;
1429 bfd_ardata (abfd)->symdefs = NULL;
1430 bfd_ardata (abfd)->extended_names = NULL;
1431 bfd_ardata (abfd)->extended_names_size = 0; */
1433 /* Now handle the two formats. */
1434 if (magic
[1] != 'b')
1436 /* This is the old format. */
1437 struct xcoff_ar_file_hdr hdr
;
1439 /* Copy over the magic string. */
1440 memcpy (hdr
.magic
, magic
, SXCOFFARMAG
);
1442 /* Now read the rest of the file header. */
1443 amt
= SIZEOF_AR_FILE_HDR
- SXCOFFARMAG
;
1444 if (bfd_bread ((PTR
) &hdr
.memoff
, amt
, abfd
) != amt
)
1446 if (bfd_get_error () != bfd_error_system_call
)
1447 bfd_set_error (bfd_error_wrong_format
);
1451 bfd_ardata (abfd
)->first_file_filepos
= strtol (hdr
.firstmemoff
,
1452 (char **) NULL
, 10);
1454 amt
= SIZEOF_AR_FILE_HDR
;
1455 bfd_ardata (abfd
)->tdata
= bfd_zalloc (abfd
, amt
);
1456 if (bfd_ardata (abfd
)->tdata
== NULL
)
1459 memcpy (bfd_ardata (abfd
)->tdata
, &hdr
, SIZEOF_AR_FILE_HDR
);
1463 /* This is the new format. */
1464 struct xcoff_ar_file_hdr_big hdr
;
1466 /* Copy over the magic string. */
1467 memcpy (hdr
.magic
, magic
, SXCOFFARMAG
);
1469 /* Now read the rest of the file header. */
1470 amt
= SIZEOF_AR_FILE_HDR_BIG
- SXCOFFARMAG
;
1471 if (bfd_bread ((PTR
) &hdr
.memoff
, amt
, abfd
) != amt
)
1473 if (bfd_get_error () != bfd_error_system_call
)
1474 bfd_set_error (bfd_error_wrong_format
);
1478 bfd_ardata (abfd
)->first_file_filepos
= bfd_scan_vma (hdr
.firstmemoff
,
1482 amt
= SIZEOF_AR_FILE_HDR_BIG
;
1483 bfd_ardata (abfd
)->tdata
= bfd_zalloc (abfd
, amt
);
1484 if (bfd_ardata (abfd
)->tdata
== NULL
)
1487 memcpy (bfd_ardata (abfd
)->tdata
, &hdr
, SIZEOF_AR_FILE_HDR_BIG
);
1490 if (! _bfd_xcoff_slurp_armap (abfd
))
1493 bfd_release (abfd
, bfd_ardata (abfd
));
1495 bfd_ardata (abfd
) = tdata_hold
;
1502 /* Read the archive header in an XCOFF archive. */
1505 _bfd_xcoff_read_ar_hdr (abfd
)
1508 bfd_size_type namlen
;
1509 struct areltdata
*ret
;
1510 bfd_size_type amt
= sizeof (struct areltdata
);
1512 ret
= (struct areltdata
*) bfd_alloc (abfd
, amt
);
1516 if (! xcoff_big_format_p (abfd
))
1518 struct xcoff_ar_hdr hdr
;
1519 struct xcoff_ar_hdr
*hdrp
;
1521 if (bfd_bread ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1528 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1529 amt
= SIZEOF_AR_HDR
+ namlen
+ 1;
1530 hdrp
= (struct xcoff_ar_hdr
*) bfd_alloc (abfd
, amt
);
1536 memcpy (hdrp
, &hdr
, SIZEOF_AR_HDR
);
1537 if (bfd_bread ((char *) hdrp
+ SIZEOF_AR_HDR
, namlen
, abfd
) != namlen
)
1542 ((char *) hdrp
)[SIZEOF_AR_HDR
+ namlen
] = '\0';
1544 ret
->arch_header
= (char *) hdrp
;
1545 ret
->parsed_size
= strtol (hdr
.size
, (char **) NULL
, 10);
1546 ret
->filename
= (char *) hdrp
+ SIZEOF_AR_HDR
;
1550 struct xcoff_ar_hdr_big hdr
;
1551 struct xcoff_ar_hdr_big
*hdrp
;
1553 if (bfd_bread ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR_BIG
, abfd
)
1554 != SIZEOF_AR_HDR_BIG
)
1560 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1561 amt
= SIZEOF_AR_HDR_BIG
+ namlen
+ 1;
1562 hdrp
= (struct xcoff_ar_hdr_big
*) bfd_alloc (abfd
, amt
);
1568 memcpy (hdrp
, &hdr
, SIZEOF_AR_HDR_BIG
);
1569 if (bfd_bread ((char *) hdrp
+ SIZEOF_AR_HDR_BIG
, namlen
, abfd
) != namlen
)
1574 ((char *) hdrp
)[SIZEOF_AR_HDR_BIG
+ namlen
] = '\0';
1576 ret
->arch_header
= (char *) hdrp
;
1577 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1578 machines) since the field width is 20 and there numbers with more
1579 than 32 bits can be represented. */
1580 ret
->parsed_size
= strtol (hdr
.size
, (char **) NULL
, 10);
1581 ret
->filename
= (char *) hdrp
+ SIZEOF_AR_HDR_BIG
;
1584 /* Skip over the XCOFFARFMAG at the end of the file name. */
1585 if (bfd_seek (abfd
, (file_ptr
) ((namlen
& 1) + SXCOFFARFMAG
), SEEK_CUR
) != 0)
1591 /* Open the next element in an XCOFF archive. */
1594 _bfd_xcoff_openr_next_archived_file (archive
, last_file
)
1600 if (xcoff_ardata (archive
) == NULL
)
1602 bfd_set_error (bfd_error_invalid_operation
);
1606 if (! xcoff_big_format_p (archive
))
1608 if (last_file
== NULL
)
1609 filestart
= bfd_ardata (archive
)->first_file_filepos
;
1611 filestart
= strtol (arch_xhdr (last_file
)->nextoff
, (char **) NULL
,
1615 || filestart
== strtol (xcoff_ardata (archive
)->memoff
,
1617 || filestart
== strtol (xcoff_ardata (archive
)->symoff
,
1618 (char **) NULL
, 10))
1620 bfd_set_error (bfd_error_no_more_archived_files
);
1626 if (last_file
== NULL
)
1627 filestart
= bfd_ardata (archive
)->first_file_filepos
;
1629 /* XXX These actually have to be a calls to strtoll (at least
1630 on 32-bit machines) since the fields's width is 20 and
1631 there numbers with more than 32 bits can be represented. */
1632 filestart
= strtol (arch_xhdr_big (last_file
)->nextoff
, (char **) NULL
,
1635 /* XXX These actually have to be calls to strtoll (at least on 32-bit
1636 machines) since the fields's width is 20 and there numbers with more
1637 than 32 bits can be represented. */
1639 || filestart
== strtol (xcoff_ardata_big (archive
)->memoff
,
1641 || filestart
== strtol (xcoff_ardata_big (archive
)->symoff
,
1642 (char **) NULL
, 10))
1644 bfd_set_error (bfd_error_no_more_archived_files
);
1649 return _bfd_get_elt_at_filepos (archive
, filestart
);
1652 /* Stat an element in an XCOFF archive. */
1655 _bfd_xcoff_stat_arch_elt (abfd
, s
)
1659 if (abfd
->arelt_data
== NULL
)
1661 bfd_set_error (bfd_error_invalid_operation
);
1665 if (! xcoff_big_format_p (abfd
->my_archive
))
1667 struct xcoff_ar_hdr
*hdrp
= arch_xhdr (abfd
);
1669 s
->st_mtime
= strtol (hdrp
->date
, (char **) NULL
, 10);
1670 s
->st_uid
= strtol (hdrp
->uid
, (char **) NULL
, 10);
1671 s
->st_gid
= strtol (hdrp
->gid
, (char **) NULL
, 10);
1672 s
->st_mode
= strtol (hdrp
->mode
, (char **) NULL
, 8);
1673 s
->st_size
= arch_eltdata (abfd
)->parsed_size
;
1677 struct xcoff_ar_hdr_big
*hdrp
= arch_xhdr_big (abfd
);
1679 s
->st_mtime
= strtol (hdrp
->date
, (char **) NULL
, 10);
1680 s
->st_uid
= strtol (hdrp
->uid
, (char **) NULL
, 10);
1681 s
->st_gid
= strtol (hdrp
->gid
, (char **) NULL
, 10);
1682 s
->st_mode
= strtol (hdrp
->mode
, (char **) NULL
, 8);
1683 s
->st_size
= arch_eltdata (abfd
)->parsed_size
;
1689 /* Normalize a file name for inclusion in an archive. */
1692 normalize_filename (abfd
)
1696 const char *filename
;
1698 file
= bfd_get_filename (abfd
);
1699 filename
= strrchr (file
, '/');
1700 if (filename
!= NULL
)
1707 /* Write out an XCOFF armap. */
1710 xcoff_write_armap_old (abfd
, elength
, map
, orl_count
, stridx
)
1712 unsigned int elength ATTRIBUTE_UNUSED
;
1714 unsigned int orl_count
;
1717 struct archive_iterator iterator
;
1718 struct xcoff_ar_hdr hdr
;
1720 unsigned char buf
[4];
1723 memset (&hdr
, 0, sizeof hdr
);
1724 sprintf (hdr
.size
, "%ld", (long) (4 + orl_count
* 4 + stridx
));
1725 sprintf (hdr
.nextoff
, "%d", 0);
1726 memcpy (hdr
.prevoff
, xcoff_ardata (abfd
)->memoff
, XCOFFARMAG_ELEMENT_SIZE
);
1727 sprintf (hdr
.date
, "%d", 0);
1728 sprintf (hdr
.uid
, "%d", 0);
1729 sprintf (hdr
.gid
, "%d", 0);
1730 sprintf (hdr
.mode
, "%d", 0);
1731 sprintf (hdr
.namlen
, "%d", 0);
1733 /* We need spaces, not null bytes, in the header. */
1734 for (p
= (char *) &hdr
; p
< (char *) &hdr
+ SIZEOF_AR_HDR
; p
++)
1738 if (bfd_bwrite ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1740 || (bfd_bwrite (XCOFFARFMAG
, (bfd_size_type
) SXCOFFARFMAG
, abfd
)
1744 H_PUT_32 (abfd
, orl_count
, buf
);
1745 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
1749 archive_iterator_begin (&iterator
, abfd
);
1750 while (i
< orl_count
&& archive_iterator_next (&iterator
))
1751 while (map
[i
].u
.abfd
== iterator
.current
.member
)
1753 H_PUT_32 (abfd
, iterator
.current
.offset
, buf
);
1754 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
1759 for (i
= 0; i
< orl_count
; i
++)
1764 name
= *map
[i
].name
;
1765 namlen
= strlen (name
);
1766 if (bfd_bwrite (name
, (bfd_size_type
) (namlen
+ 1), abfd
) != namlen
+ 1)
1770 if ((stridx
& 1) != 0)
1775 if (bfd_bwrite (&b
, (bfd_size_type
) 1, abfd
) != 1)
1782 static char buff20
[XCOFFARMAGBIG_ELEMENT_SIZE
+ 1];
1783 #define FMT20 "%-20lld"
1784 #define FMT12 "%-12d"
1785 #define FMT12_OCTAL "%-12o"
1787 #define PRINT20(d, v) \
1788 sprintf (buff20, FMT20, (long long)(v)), \
1789 memcpy ((void *) (d), buff20, 20)
1791 #define PRINT12(d, v) \
1792 sprintf (buff20, FMT12, (int)(v)), \
1793 memcpy ((void *) (d), buff20, 12)
1795 #define PRINT12_OCTAL(d, v) \
1796 sprintf (buff20, FMT12_OCTAL, (unsigned int)(v)), \
1797 memcpy ((void *) (d), buff20, 12)
1799 #define PRINT4(d, v) \
1800 sprintf (buff20, FMT4, (int)(v)), \
1801 memcpy ((void *) (d), buff20, 4)
1803 #define READ20(d, v) \
1805 memcpy (buff20, (d), 20), \
1806 (v) = bfd_scan_vma (buff20, (const char **) NULL, 10)
1809 do_pad (abfd
, number
)
1811 unsigned int number
;
1815 /* Limit pad to <= 4096. */
1820 if (bfd_bwrite (&b
, (bfd_size_type
) 1, abfd
) != 1)
1827 do_copy (out_bfd
, in_bfd
)
1831 bfd_size_type remaining
;
1832 bfd_byte buffer
[DEFAULT_BUFFERSIZE
];
1834 if (bfd_seek (in_bfd
, (file_ptr
) 0, SEEK_SET
) != 0)
1837 remaining
= arelt_size (in_bfd
);
1839 while (remaining
>= DEFAULT_BUFFERSIZE
)
1841 if (bfd_bread (buffer
, DEFAULT_BUFFERSIZE
, in_bfd
) != DEFAULT_BUFFERSIZE
1842 || bfd_bwrite (buffer
, DEFAULT_BUFFERSIZE
, out_bfd
) != DEFAULT_BUFFERSIZE
)
1845 remaining
-= DEFAULT_BUFFERSIZE
;
1850 if (bfd_bread (buffer
, remaining
, in_bfd
) != remaining
1851 || bfd_bwrite (buffer
, remaining
, out_bfd
) != remaining
)
1859 xcoff_write_armap_big (abfd
, elength
, map
, orl_count
, stridx
)
1861 unsigned int elength ATTRIBUTE_UNUSED
;
1863 unsigned int orl_count
;
1866 struct archive_iterator iterator
;
1867 struct xcoff_ar_file_hdr_big
*fhdr
;
1868 bfd_vma i
, sym_32
, sym_64
, str_32
, str_64
;
1869 const bfd_arch_info_type
*arch_info
;
1871 size_t string_length
;
1872 file_ptr nextoff
, prevoff
;
1874 /* First, we look through the symbols and work out which are
1875 from 32-bit objects and which from 64-bit ones. */
1876 sym_32
= sym_64
= str_32
= str_64
= 0;
1879 for (current_bfd
= abfd
->archive_head
;
1880 current_bfd
!= NULL
&& i
< orl_count
;
1881 current_bfd
= current_bfd
->archive_next
)
1883 arch_info
= bfd_get_arch_info (current_bfd
);
1884 while (map
[i
].u
.abfd
== current_bfd
)
1886 string_length
= strlen (*map
[i
].name
) + 1;
1887 if (arch_info
->bits_per_address
== 64)
1890 str_64
+= string_length
;
1895 str_32
+= string_length
;
1901 /* A quick sanity check... */
1902 BFD_ASSERT (sym_64
+ sym_32
== orl_count
);
1903 /* Explicit cast to int for compiler. */
1904 BFD_ASSERT ((int)(str_64
+ str_32
) == stridx
);
1906 fhdr
= xcoff_ardata_big (abfd
);
1908 /* xcoff_write_archive_contents_big passes nextoff in symoff. */
1909 READ20 (fhdr
->memoff
, prevoff
);
1910 READ20 (fhdr
->symoff
, nextoff
);
1912 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
1914 /* Write out the symbol table.
1917 standard big archive header
1918 0x0000 ar_size [0x14]
1919 0x0014 ar_nxtmem [0x14]
1920 0x0028 ar_prvmem [0x14]
1921 0x003C ar_date [0x0C]
1922 0x0048 ar_uid [0x0C]
1923 0x0054 ar_gid [0x0C]
1924 0x0060 ar_mod [0x0C]
1925 0x006C ar_namelen[0x04]
1926 0x0070 ar_fmag [SXCOFFARFMAG]
1929 0x0072 num_syms [0x08], binary
1930 0x0078 offsets [0x08 * num_syms], binary
1931 0x0086 + 0x08 * num_syms names [??]
1932 ?? pad to even bytes.
1937 struct xcoff_ar_hdr_big
*hdr
;
1941 bfd_vma symbol_table_size
=
1946 + str_32
+ (str_32
& 1);
1948 symbol_table
= bfd_zmalloc (symbol_table_size
);
1949 if (symbol_table
== NULL
)
1952 hdr
= (struct xcoff_ar_hdr_big
*) symbol_table
;
1954 PRINT20 (hdr
->size
, 8 + 8 * sym_32
+ str_32
+ (str_32
& 1));
1957 PRINT20 (hdr
->nextoff
, nextoff
+ symbol_table_size
);
1959 PRINT20 (hdr
->nextoff
, 0);
1961 PRINT20 (hdr
->prevoff
, prevoff
);
1962 PRINT12 (hdr
->date
, 0);
1963 PRINT12 (hdr
->uid
, 0);
1964 PRINT12 (hdr
->gid
, 0);
1965 PRINT12 (hdr
->mode
, 0);
1966 PRINT4 (hdr
->namlen
, 0) ;
1968 st
= symbol_table
+ SIZEOF_AR_HDR_BIG
;
1969 memcpy (st
, XCOFFARFMAG
, SXCOFFARFMAG
);
1972 bfd_h_put_64 (abfd
, sym_32
, st
);
1975 /* loop over the 32 bit offsets */
1977 archive_iterator_begin (&iterator
, abfd
);
1978 while (i
< orl_count
&& archive_iterator_next (&iterator
))
1980 arch_info
= bfd_get_arch_info (iterator
.current
.member
);
1981 while (map
[i
].u
.abfd
== iterator
.current
.member
)
1983 if (arch_info
->bits_per_address
== 32)
1985 bfd_h_put_64 (abfd
, iterator
.current
.offset
, st
);
1992 /* loop over the 32 bit symbol names */
1994 for (current_bfd
= abfd
->archive_head
;
1995 current_bfd
!= NULL
&& i
< orl_count
;
1996 current_bfd
= current_bfd
->archive_next
)
1998 arch_info
= bfd_get_arch_info (current_bfd
);
1999 while (map
[i
].u
.abfd
== current_bfd
)
2001 if (arch_info
->bits_per_address
== 32)
2003 string_length
= sprintf (st
, "%s", *map
[i
].name
);
2004 st
+= string_length
+ 1;
2010 bfd_bwrite (symbol_table
, symbol_table_size
, abfd
);
2012 free (symbol_table
);
2015 nextoff
= nextoff
+ symbol_table_size
;
2018 PRINT20 (fhdr
->symoff
, 0);
2022 struct xcoff_ar_hdr_big
*hdr
;
2026 bfd_vma symbol_table_size
=
2031 + str_64
+ (str_64
& 1);
2033 symbol_table
= bfd_zmalloc (symbol_table_size
);
2034 if (symbol_table
== NULL
)
2037 hdr
= (struct xcoff_ar_hdr_big
*) symbol_table
;
2039 PRINT20 (hdr
->size
, 8 + 8 * sym_64
+ str_64
+ (str_64
& 1));
2040 PRINT20 (hdr
->nextoff
, 0);
2041 PRINT20 (hdr
->prevoff
, prevoff
);
2042 PRINT12 (hdr
->date
, 0);
2043 PRINT12 (hdr
->uid
, 0);
2044 PRINT12 (hdr
->gid
, 0);
2045 PRINT12 (hdr
->mode
, 0);
2046 PRINT4 (hdr
->namlen
, 0);
2048 st
= symbol_table
+ SIZEOF_AR_HDR_BIG
;
2049 memcpy (st
, XCOFFARFMAG
, SXCOFFARFMAG
);
2052 bfd_h_put_64 (abfd
, sym_64
, st
);
2055 /* loop over the 64 bit offsets */
2057 archive_iterator_begin (&iterator
, abfd
);
2058 while (i
< orl_count
&& archive_iterator_next (&iterator
))
2060 arch_info
= bfd_get_arch_info (iterator
.current
.member
);
2061 while (map
[i
].u
.abfd
== iterator
.current
.member
)
2063 if (arch_info
->bits_per_address
== 64)
2065 bfd_h_put_64 (abfd
, iterator
.current
.offset
, st
);
2072 /* loop over the 64 bit symbol names */
2074 for (current_bfd
= abfd
->archive_head
;
2075 current_bfd
!= NULL
&& i
< orl_count
;
2076 current_bfd
= current_bfd
->archive_next
)
2078 arch_info
= bfd_get_arch_info (current_bfd
);
2079 while (map
[i
].u
.abfd
== current_bfd
)
2081 if (arch_info
->bits_per_address
== 64)
2083 string_length
= sprintf (st
, "%s", *map
[i
].name
);
2084 st
+= string_length
+ 1;
2090 bfd_bwrite (symbol_table
, symbol_table_size
, abfd
);
2092 free (symbol_table
);
2094 PRINT20 (fhdr
->symoff64
, nextoff
);
2097 PRINT20 (fhdr
->symoff64
, 0);
2103 _bfd_xcoff_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
2105 unsigned int elength ATTRIBUTE_UNUSED
;
2107 unsigned int orl_count
;
2110 if (! xcoff_big_format_p (abfd
))
2111 return xcoff_write_armap_old (abfd
, elength
, map
, orl_count
, stridx
);
2113 return xcoff_write_armap_big (abfd
, elength
, map
, orl_count
, stridx
);
2116 /* Write out an XCOFF archive. We always write an entire archive,
2117 rather than fussing with the freelist and so forth. */
2120 xcoff_write_archive_contents_old (abfd
)
2123 struct archive_iterator iterator
;
2124 struct xcoff_ar_file_hdr fhdr
;
2125 bfd_size_type count
;
2126 bfd_size_type total_namlen
;
2128 bfd_boolean makemap
;
2129 bfd_boolean hasobjects
;
2130 file_ptr prevoff
, nextoff
;
2133 struct xcoff_ar_hdr ahdr
;
2136 char decbuf
[XCOFFARMAG_ELEMENT_SIZE
+ 1];
2138 memset (&fhdr
, 0, sizeof fhdr
);
2139 (void) strncpy (fhdr
.magic
, XCOFFARMAG
, SXCOFFARMAG
);
2140 sprintf (fhdr
.firstmemoff
, "%d", SIZEOF_AR_FILE_HDR
);
2141 sprintf (fhdr
.freeoff
, "%d", 0);
2145 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->archive_next
)
2148 total_namlen
+= strlen (normalize_filename (sub
)) + 1;
2149 if (sub
->arelt_data
== NULL
)
2151 sub
->arelt_data
= bfd_zalloc (sub
, sizeof (struct areltdata
));
2152 if (sub
->arelt_data
== NULL
)
2155 if (arch_xhdr (sub
) == NULL
)
2157 struct xcoff_ar_hdr
*ahdrp
;
2160 if (stat (bfd_get_filename (sub
), &s
) != 0)
2162 bfd_set_error (bfd_error_system_call
);
2166 ahdrp
= bfd_zalloc (sub
, sizeof (*ahdrp
));
2170 sprintf (ahdrp
->size
, "%ld", (long) s
.st_size
);
2171 sprintf (ahdrp
->date
, "%ld", (long) s
.st_mtime
);
2172 sprintf (ahdrp
->uid
, "%ld", (long) s
.st_uid
);
2173 sprintf (ahdrp
->gid
, "%ld", (long) s
.st_gid
);
2174 sprintf (ahdrp
->mode
, "%o", (unsigned int) s
.st_mode
);
2176 arch_eltdata (sub
)->arch_header
= (char *) ahdrp
;
2177 arch_eltdata (sub
)->parsed_size
= s
.st_size
;
2180 offsets
= (file_ptr
*) bfd_alloc (abfd
, count
* sizeof (file_ptr
));
2181 if (offsets
== NULL
)
2184 if (bfd_seek (abfd
, (file_ptr
) SIZEOF_AR_FILE_HDR
, SEEK_SET
) != 0)
2187 makemap
= bfd_has_map (abfd
);
2190 for (archive_iterator_begin (&iterator
, abfd
), i
= 0;
2191 archive_iterator_next (&iterator
);
2194 bfd_size_type namlen
;
2195 struct xcoff_ar_hdr
*ahdrp
;
2197 if (makemap
&& ! hasobjects
)
2199 if (bfd_check_format (iterator
.current
.member
, bfd_object
))
2203 ahdrp
= arch_xhdr (iterator
.current
.member
);
2204 sprintf (ahdrp
->prevoff
, "%ld", (long) prevoff
);
2205 sprintf (ahdrp
->namlen
, "%ld", (long) iterator
.current
.namlen
);
2206 sprintf (ahdrp
->nextoff
, "%ld", (long) iterator
.next
.offset
);
2208 /* We need spaces, not null bytes, in the header. */
2209 for (p
= (char *) ahdrp
; p
< (char *) ahdrp
+ SIZEOF_AR_HDR
; p
++)
2213 if (!do_pad (abfd
, iterator
.current
.leading_padding
))
2216 BFD_ASSERT (iterator
.current
.offset
== bfd_tell (abfd
));
2217 namlen
= iterator
.current
.padded_namlen
;
2218 if (bfd_bwrite (ahdrp
, SIZEOF_AR_HDR
, abfd
) != SIZEOF_AR_HDR
2219 || bfd_bwrite (iterator
.current
.name
, namlen
, abfd
) != namlen
2220 || bfd_bwrite (XCOFFARFMAG
, SXCOFFARFMAG
, abfd
) != SXCOFFARFMAG
2221 || bfd_seek (iterator
.current
.member
, 0, SEEK_SET
) != 0
2222 || !do_copy (abfd
, iterator
.current
.member
)
2223 || !do_pad (abfd
, iterator
.current
.trailing_padding
))
2226 offsets
[i
] = iterator
.current
.offset
;
2227 prevoff
= iterator
.current
.offset
;
2230 sprintf (fhdr
.lastmemoff
, "%ld", (long) prevoff
);
2232 /* Write out the member table. */
2234 nextoff
= iterator
.next
.offset
;
2235 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2236 sprintf (fhdr
.memoff
, "%ld", (long) nextoff
);
2238 memset (&ahdr
, 0, sizeof ahdr
);
2239 sprintf (ahdr
.size
, "%ld", (long) (XCOFFARMAG_ELEMENT_SIZE
2240 + count
* XCOFFARMAG_ELEMENT_SIZE
2242 sprintf (ahdr
.prevoff
, "%ld", (long) prevoff
);
2243 sprintf (ahdr
.date
, "%d", 0);
2244 sprintf (ahdr
.uid
, "%d", 0);
2245 sprintf (ahdr
.gid
, "%d", 0);
2246 sprintf (ahdr
.mode
, "%d", 0);
2247 sprintf (ahdr
.namlen
, "%d", 0);
2249 size
= (SIZEOF_AR_HDR
2250 + XCOFFARMAG_ELEMENT_SIZE
2251 + count
* XCOFFARMAG_ELEMENT_SIZE
2256 nextoff
+= size
+ (size
& 1);
2258 if (makemap
&& hasobjects
)
2259 sprintf (ahdr
.nextoff
, "%ld", (long) nextoff
);
2261 sprintf (ahdr
.nextoff
, "%d", 0);
2263 /* We need spaces, not null bytes, in the header. */
2264 for (p
= (char *) &ahdr
; p
< (char *) &ahdr
+ SIZEOF_AR_HDR
; p
++)
2268 if ((bfd_bwrite ((PTR
) &ahdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
2270 || (bfd_bwrite ((PTR
) XCOFFARFMAG
, (bfd_size_type
) SXCOFFARFMAG
, abfd
)
2274 sprintf (decbuf
, "%-12ld", (long) count
);
2275 if (bfd_bwrite ((PTR
) decbuf
, (bfd_size_type
) XCOFFARMAG_ELEMENT_SIZE
, abfd
)
2276 != XCOFFARMAG_ELEMENT_SIZE
)
2278 for (i
= 0; i
< (size_t) count
; i
++)
2280 sprintf (decbuf
, "%-12ld", (long) offsets
[i
]);
2281 if (bfd_bwrite ((PTR
) decbuf
, (bfd_size_type
) XCOFFARMAG_ELEMENT_SIZE
,
2282 abfd
) != XCOFFARMAG_ELEMENT_SIZE
)
2285 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->archive_next
)
2288 bfd_size_type namlen
;
2290 name
= normalize_filename (sub
);
2291 namlen
= strlen (name
);
2292 if (bfd_bwrite ((PTR
) name
, namlen
+ 1, abfd
) != namlen
+ 1)
2296 if (! do_pad (abfd
, size
& 1))
2299 /* Write out the armap, if appropriate. */
2300 if (! makemap
|| ! hasobjects
)
2301 sprintf (fhdr
.symoff
, "%d", 0);
2304 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2305 sprintf (fhdr
.symoff
, "%ld", (long) nextoff
);
2306 bfd_ardata (abfd
)->tdata
= (PTR
) &fhdr
;
2307 if (! _bfd_compute_and_write_armap (abfd
, 0))
2311 /* Write out the archive file header. */
2313 /* We need spaces, not null bytes, in the header. */
2314 for (p
= (char *) &fhdr
; p
< (char *) &fhdr
+ SIZEOF_AR_FILE_HDR
; p
++)
2318 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
2319 || (bfd_bwrite ((PTR
) &fhdr
, (bfd_size_type
) SIZEOF_AR_FILE_HDR
, abfd
)
2320 != SIZEOF_AR_FILE_HDR
))
2327 xcoff_write_archive_contents_big (abfd
)
2330 struct xcoff_ar_file_hdr_big fhdr
;
2331 bfd_size_type count
;
2332 bfd_size_type total_namlen
;
2334 bfd_boolean makemap
;
2335 bfd_boolean hasobjects
;
2336 file_ptr prevoff
, nextoff
;
2339 struct xcoff_ar_hdr_big
*hdr
;
2341 char *member_table
, *mt
;
2342 bfd_vma member_table_size
;
2343 struct archive_iterator iterator
;
2345 memset (&fhdr
, 0, SIZEOF_AR_FILE_HDR_BIG
);
2346 memcpy (fhdr
.magic
, XCOFFARMAGBIG
, SXCOFFARMAG
);
2348 if (bfd_seek (abfd
, (file_ptr
) SIZEOF_AR_FILE_HDR_BIG
, SEEK_SET
) != 0)
2351 /* Calculate count and total_namlen. */
2352 makemap
= bfd_has_map (abfd
);
2354 for (current_bfd
= abfd
->archive_head
, count
= 0, total_namlen
= 0;
2355 current_bfd
!= NULL
;
2356 current_bfd
= current_bfd
->archive_next
, count
++)
2358 total_namlen
+= strlen (normalize_filename (current_bfd
)) + 1;
2362 && bfd_check_format (current_bfd
, bfd_object
))
2365 if (current_bfd
->arelt_data
== NULL
)
2367 size
= sizeof (struct areltdata
);
2368 current_bfd
->arelt_data
= bfd_zalloc (current_bfd
, size
);
2369 if (current_bfd
->arelt_data
== NULL
)
2373 if (arch_xhdr_big (current_bfd
) == NULL
)
2375 struct xcoff_ar_hdr_big
*ahdrp
;
2378 /* XXX This should actually be a call to stat64 (at least on
2380 XXX This call will fail if the original object is not found. */
2381 if (stat (bfd_get_filename (current_bfd
), &s
) != 0)
2383 bfd_set_error (bfd_error_system_call
);
2387 ahdrp
= bfd_zalloc (current_bfd
, sizeof (*ahdrp
));
2391 PRINT20 (ahdrp
->size
, s
.st_size
);
2392 PRINT12 (ahdrp
->date
, s
.st_mtime
);
2393 PRINT12 (ahdrp
->uid
, s
.st_uid
);
2394 PRINT12 (ahdrp
->gid
, s
.st_gid
);
2395 PRINT12_OCTAL (ahdrp
->mode
, s
.st_mode
);
2397 arch_eltdata (current_bfd
)->arch_header
= (char *) ahdrp
;
2398 arch_eltdata (current_bfd
)->parsed_size
= s
.st_size
;
2405 offsets
= (file_ptr
*) bfd_malloc (count
* sizeof (file_ptr
));
2406 if (offsets
== NULL
)
2411 for (archive_iterator_begin (&iterator
, abfd
), i
= 0;
2412 archive_iterator_next (&iterator
);
2415 bfd_size_type namlen
;
2416 struct xcoff_ar_hdr_big
*ahdrp
;
2418 ahdrp
= arch_xhdr_big (iterator
.current
.member
);
2419 PRINT20 (ahdrp
->prevoff
, prevoff
);
2420 PRINT4 (ahdrp
->namlen
, iterator
.current
.namlen
);
2421 PRINT20 (ahdrp
->nextoff
, iterator
.next
.offset
);
2423 if (!do_pad (abfd
, iterator
.current
.leading_padding
))
2426 BFD_ASSERT (iterator
.current
.offset
== bfd_tell (abfd
));
2427 namlen
= iterator
.current
.padded_namlen
;
2428 if (bfd_bwrite (ahdrp
, SIZEOF_AR_HDR_BIG
, abfd
) != SIZEOF_AR_HDR_BIG
2429 || bfd_bwrite (iterator
.current
.name
, namlen
, abfd
) != namlen
2430 || bfd_bwrite (XCOFFARFMAG
, SXCOFFARFMAG
, abfd
) != SXCOFFARFMAG
2431 || bfd_seek (iterator
.current
.member
, 0, SEEK_SET
) != 0
2432 || !do_copy (abfd
, iterator
.current
.member
)
2433 || !do_pad (abfd
, iterator
.current
.trailing_padding
))
2436 offsets
[i
] = iterator
.current
.offset
;
2437 prevoff
= iterator
.current
.offset
;
2442 PRINT20 (fhdr
.firstmemoff
, offsets
[0]);
2443 PRINT20 (fhdr
.lastmemoff
, prevoff
);
2446 /* Write out the member table.
2449 standard big archive header
2450 0x0000 ar_size [0x14]
2451 0x0014 ar_nxtmem [0x14]
2452 0x0028 ar_prvmem [0x14]
2453 0x003C ar_date [0x0C]
2454 0x0048 ar_uid [0x0C]
2455 0x0054 ar_gid [0x0C]
2456 0x0060 ar_mod [0x0C]
2457 0x006C ar_namelen[0x04]
2458 0x0070 ar_fmag [0x02]
2462 0x0086 offsets [0x14 * counts]
2463 0x0086 + 0x14 * counts names [??]
2464 ?? pad to even bytes.
2467 nextoff
= iterator
.next
.offset
;
2468 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2470 member_table_size
= (SIZEOF_AR_HDR_BIG
2472 + XCOFFARMAGBIG_ELEMENT_SIZE
2473 + count
* XCOFFARMAGBIG_ELEMENT_SIZE
2476 member_table_size
+= member_table_size
& 1;
2477 member_table
= bfd_zmalloc (member_table_size
);
2478 if (member_table
== NULL
)
2481 hdr
= (struct xcoff_ar_hdr_big
*) member_table
;
2483 PRINT20 (hdr
->size
, (XCOFFARMAGBIG_ELEMENT_SIZE
2484 + count
* XCOFFARMAGBIG_ELEMENT_SIZE
2485 + total_namlen
+ (total_namlen
& 1)));
2486 if (makemap
&& hasobjects
)
2487 PRINT20 (hdr
->nextoff
, nextoff
+ member_table_size
);
2489 PRINT20 (hdr
->nextoff
, 0);
2490 PRINT20 (hdr
->prevoff
, prevoff
);
2491 PRINT12 (hdr
->date
, 0);
2492 PRINT12 (hdr
->uid
, 0);
2493 PRINT12 (hdr
->gid
, 0);
2494 PRINT12 (hdr
->mode
, 0);
2495 PRINT4 (hdr
->namlen
, 0);
2497 mt
= member_table
+ SIZEOF_AR_HDR_BIG
;
2498 memcpy (mt
, XCOFFARFMAG
, SXCOFFARFMAG
);
2501 PRINT20 (mt
, count
);
2502 mt
+= XCOFFARMAGBIG_ELEMENT_SIZE
;
2503 for (i
= 0; i
< (size_t) count
; i
++)
2505 PRINT20 (mt
, offsets
[i
]);
2506 mt
+= XCOFFARMAGBIG_ELEMENT_SIZE
;
2515 for (current_bfd
= abfd
->archive_head
;
2516 current_bfd
!= NULL
;
2517 current_bfd
= current_bfd
->archive_next
)
2522 name
= normalize_filename (current_bfd
);
2523 namlen
= sprintf (mt
, "%s", name
);
2527 if (bfd_bwrite (member_table
, member_table_size
, abfd
) != member_table_size
)
2530 free (member_table
);
2532 PRINT20 (fhdr
.memoff
, nextoff
);
2535 nextoff
+= member_table_size
;
2537 /* Write out the armap, if appropriate. */
2539 if (! makemap
|| ! hasobjects
)
2540 PRINT20 (fhdr
.symoff
, 0);
2543 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2545 /* Save nextoff in fhdr.symoff so the armap routine can use it. */
2546 PRINT20 (fhdr
.symoff
, nextoff
);
2548 bfd_ardata (abfd
)->tdata
= (PTR
) &fhdr
;
2549 if (! _bfd_compute_and_write_armap (abfd
, 0))
2553 /* Write out the archive file header. */
2555 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
2556 || (bfd_bwrite ((PTR
) &fhdr
, (bfd_size_type
) SIZEOF_AR_FILE_HDR_BIG
,
2557 abfd
) != SIZEOF_AR_FILE_HDR_BIG
))
2564 _bfd_xcoff_write_archive_contents (abfd
)
2567 if (! xcoff_big_format_p (abfd
))
2568 return xcoff_write_archive_contents_old (abfd
);
2570 return xcoff_write_archive_contents_big (abfd
);
2573 /* We can't use the usual coff_sizeof_headers routine, because AIX
2574 always uses an a.out header. */
2577 _bfd_xcoff_sizeof_headers (bfd
*abfd
,
2578 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
2583 if (xcoff_data (abfd
)->full_aouthdr
)
2586 size
+= SMALL_AOUTSZ
;
2587 size
+= abfd
->section_count
* SCNHSZ
;
2591 /* Routines to swap information in the XCOFF .loader section. If we
2592 ever need to write an XCOFF loader, this stuff will need to be
2593 moved to another file shared by the linker (which XCOFF calls the
2594 ``binder'') and the loader. */
2596 /* Swap in the ldhdr structure. */
2599 xcoff_swap_ldhdr_in (abfd
, s
, dst
)
2602 struct internal_ldhdr
*dst
;
2604 const struct external_ldhdr
*src
= (const struct external_ldhdr
*) s
;
2606 dst
->l_version
= bfd_get_32 (abfd
, src
->l_version
);
2607 dst
->l_nsyms
= bfd_get_32 (abfd
, src
->l_nsyms
);
2608 dst
->l_nreloc
= bfd_get_32 (abfd
, src
->l_nreloc
);
2609 dst
->l_istlen
= bfd_get_32 (abfd
, src
->l_istlen
);
2610 dst
->l_nimpid
= bfd_get_32 (abfd
, src
->l_nimpid
);
2611 dst
->l_impoff
= bfd_get_32 (abfd
, src
->l_impoff
);
2612 dst
->l_stlen
= bfd_get_32 (abfd
, src
->l_stlen
);
2613 dst
->l_stoff
= bfd_get_32 (abfd
, src
->l_stoff
);
2616 /* Swap out the ldhdr structure. */
2619 xcoff_swap_ldhdr_out (abfd
, src
, d
)
2621 const struct internal_ldhdr
*src
;
2624 struct external_ldhdr
*dst
= (struct external_ldhdr
*) d
;
2626 bfd_put_32 (abfd
, (bfd_vma
) src
->l_version
, dst
->l_version
);
2627 bfd_put_32 (abfd
, src
->l_nsyms
, dst
->l_nsyms
);
2628 bfd_put_32 (abfd
, src
->l_nreloc
, dst
->l_nreloc
);
2629 bfd_put_32 (abfd
, src
->l_istlen
, dst
->l_istlen
);
2630 bfd_put_32 (abfd
, src
->l_nimpid
, dst
->l_nimpid
);
2631 bfd_put_32 (abfd
, src
->l_impoff
, dst
->l_impoff
);
2632 bfd_put_32 (abfd
, src
->l_stlen
, dst
->l_stlen
);
2633 bfd_put_32 (abfd
, src
->l_stoff
, dst
->l_stoff
);
2636 /* Swap in the ldsym structure. */
2639 xcoff_swap_ldsym_in (abfd
, s
, dst
)
2642 struct internal_ldsym
*dst
;
2644 const struct external_ldsym
*src
= (const struct external_ldsym
*) s
;
2646 if (bfd_get_32 (abfd
, src
->_l
._l_l
._l_zeroes
) != 0) {
2647 memcpy (dst
->_l
._l_name
, src
->_l
._l_name
, SYMNMLEN
);
2649 dst
->_l
._l_l
._l_zeroes
= 0;
2650 dst
->_l
._l_l
._l_offset
= bfd_get_32 (abfd
, src
->_l
._l_l
._l_offset
);
2652 dst
->l_value
= bfd_get_32 (abfd
, src
->l_value
);
2653 dst
->l_scnum
= bfd_get_16 (abfd
, src
->l_scnum
);
2654 dst
->l_smtype
= bfd_get_8 (abfd
, src
->l_smtype
);
2655 dst
->l_smclas
= bfd_get_8 (abfd
, src
->l_smclas
);
2656 dst
->l_ifile
= bfd_get_32 (abfd
, src
->l_ifile
);
2657 dst
->l_parm
= bfd_get_32 (abfd
, src
->l_parm
);
2660 /* Swap out the ldsym structure. */
2663 xcoff_swap_ldsym_out (abfd
, src
, d
)
2665 const struct internal_ldsym
*src
;
2668 struct external_ldsym
*dst
= (struct external_ldsym
*) d
;
2670 if (src
->_l
._l_l
._l_zeroes
!= 0)
2671 memcpy (dst
->_l
._l_name
, src
->_l
._l_name
, SYMNMLEN
);
2674 bfd_put_32 (abfd
, (bfd_vma
) 0, dst
->_l
._l_l
._l_zeroes
);
2675 bfd_put_32 (abfd
, (bfd_vma
) src
->_l
._l_l
._l_offset
,
2676 dst
->_l
._l_l
._l_offset
);
2678 bfd_put_32 (abfd
, src
->l_value
, dst
->l_value
);
2679 bfd_put_16 (abfd
, (bfd_vma
) src
->l_scnum
, dst
->l_scnum
);
2680 bfd_put_8 (abfd
, src
->l_smtype
, dst
->l_smtype
);
2681 bfd_put_8 (abfd
, src
->l_smclas
, dst
->l_smclas
);
2682 bfd_put_32 (abfd
, src
->l_ifile
, dst
->l_ifile
);
2683 bfd_put_32 (abfd
, src
->l_parm
, dst
->l_parm
);
2687 xcoff_swap_reloc_in (abfd
, s
, 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 (abfd
, s
, d
)
2709 struct internal_reloc
*src
= (struct internal_reloc
*) s
;
2710 struct external_reloc
*dst
= (struct external_reloc
*) d
;
2712 bfd_put_32 (abfd
, src
->r_vaddr
, dst
->r_vaddr
);
2713 bfd_put_32 (abfd
, src
->r_symndx
, dst
->r_symndx
);
2714 bfd_put_8 (abfd
, src
->r_type
, dst
->r_type
);
2715 bfd_put_8 (abfd
, src
->r_size
, dst
->r_size
);
2717 return bfd_coff_relsz (abfd
);
2720 /* Swap in the ldrel structure. */
2723 xcoff_swap_ldrel_in (abfd
, s
, dst
)
2726 struct internal_ldrel
*dst
;
2728 const struct external_ldrel
*src
= (const struct external_ldrel
*) s
;
2730 dst
->l_vaddr
= bfd_get_32 (abfd
, src
->l_vaddr
);
2731 dst
->l_symndx
= bfd_get_32 (abfd
, src
->l_symndx
);
2732 dst
->l_rtype
= bfd_get_16 (abfd
, src
->l_rtype
);
2733 dst
->l_rsecnm
= bfd_get_16 (abfd
, src
->l_rsecnm
);
2736 /* Swap out the ldrel structure. */
2739 xcoff_swap_ldrel_out (abfd
, src
, d
)
2741 const struct internal_ldrel
*src
;
2744 struct external_ldrel
*dst
= (struct external_ldrel
*) d
;
2746 bfd_put_32 (abfd
, src
->l_vaddr
, dst
->l_vaddr
);
2747 bfd_put_32 (abfd
, src
->l_symndx
, dst
->l_symndx
);
2748 bfd_put_16 (abfd
, (bfd_vma
) src
->l_rtype
, dst
->l_rtype
);
2749 bfd_put_16 (abfd
, (bfd_vma
) src
->l_rsecnm
, dst
->l_rsecnm
);
2754 xcoff_reloc_type_noop (input_bfd
, input_section
, output_bfd
, rel
, sym
, howto
,
2755 val
, addend
, relocation
, contents
)
2756 bfd
*input_bfd ATTRIBUTE_UNUSED
;
2757 asection
*input_section ATTRIBUTE_UNUSED
;
2758 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2759 struct internal_reloc
*rel ATTRIBUTE_UNUSED
;
2760 struct internal_syment
*sym ATTRIBUTE_UNUSED
;
2761 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
;
2762 bfd_vma val ATTRIBUTE_UNUSED
;
2763 bfd_vma addend ATTRIBUTE_UNUSED
;
2764 bfd_vma
*relocation ATTRIBUTE_UNUSED
;
2765 bfd_byte
*contents ATTRIBUTE_UNUSED
;
2771 xcoff_reloc_type_fail (input_bfd
, input_section
, output_bfd
, rel
, sym
, howto
,
2772 val
, addend
, relocation
, contents
)
2774 asection
*input_section ATTRIBUTE_UNUSED
;
2775 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2776 struct internal_reloc
*rel
;
2777 struct internal_syment
*sym ATTRIBUTE_UNUSED
;
2778 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
;
2779 bfd_vma val ATTRIBUTE_UNUSED
;
2780 bfd_vma addend ATTRIBUTE_UNUSED
;
2781 bfd_vma
*relocation ATTRIBUTE_UNUSED
;
2782 bfd_byte
*contents ATTRIBUTE_UNUSED
;
2784 (*_bfd_error_handler
)
2785 (_("%s: unsupported relocation type 0x%02x"),
2786 bfd_get_filename (input_bfd
), (unsigned int) rel
->r_type
);
2787 bfd_set_error (bfd_error_bad_value
);
2792 xcoff_reloc_type_pos (input_bfd
, input_section
, output_bfd
, rel
, sym
, howto
,
2793 val
, addend
, relocation
, contents
)
2794 bfd
*input_bfd ATTRIBUTE_UNUSED
;
2795 asection
*input_section ATTRIBUTE_UNUSED
;
2796 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2797 struct internal_reloc
*rel ATTRIBUTE_UNUSED
;
2798 struct internal_syment
*sym ATTRIBUTE_UNUSED
;
2799 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
;
2802 bfd_vma
*relocation
;
2803 bfd_byte
*contents ATTRIBUTE_UNUSED
;
2805 *relocation
= val
+ addend
;
2810 xcoff_reloc_type_neg (input_bfd
, input_section
, output_bfd
, rel
, sym
, howto
,
2811 val
, addend
, relocation
, contents
)
2812 bfd
*input_bfd ATTRIBUTE_UNUSED
;
2813 asection
*input_section ATTRIBUTE_UNUSED
;
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 ATTRIBUTE_UNUSED
;
2820 bfd_vma
*relocation
;
2821 bfd_byte
*contents ATTRIBUTE_UNUSED
;
2823 *relocation
= addend
- val
;
2828 xcoff_reloc_type_rel (input_bfd
, input_section
, output_bfd
, rel
, sym
, howto
,
2829 val
, addend
, relocation
, contents
)
2830 bfd
*input_bfd ATTRIBUTE_UNUSED
;
2831 asection
*input_section
;
2832 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2833 struct internal_reloc
*rel ATTRIBUTE_UNUSED
;
2834 struct internal_syment
*sym ATTRIBUTE_UNUSED
;
2835 struct reloc_howto_struct
*howto
;
2838 bfd_vma
*relocation
;
2839 bfd_byte
*contents ATTRIBUTE_UNUSED
;
2841 howto
->pc_relative
= TRUE
;
2843 /* A PC relative reloc includes the section address. */
2844 addend
+= input_section
->vma
;
2846 *relocation
= val
+ addend
;
2847 *relocation
-= (input_section
->output_section
->vma
2848 + input_section
->output_offset
);
2853 xcoff_reloc_type_toc (input_bfd
, input_section
, output_bfd
, rel
, sym
, howto
,
2854 val
, addend
, relocation
, contents
)
2856 asection
*input_section ATTRIBUTE_UNUSED
;
2858 struct internal_reloc
*rel
;
2859 struct internal_syment
*sym
;
2860 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
;
2862 bfd_vma addend ATTRIBUTE_UNUSED
;
2863 bfd_vma
*relocation
;
2864 bfd_byte
*contents ATTRIBUTE_UNUSED
;
2866 struct xcoff_link_hash_entry
*h
;
2868 if (0 > rel
->r_symndx
)
2871 h
= obj_xcoff_sym_hashes (input_bfd
)[rel
->r_symndx
];
2873 if (h
!= NULL
&& h
->smclas
!= XMC_TD
)
2875 if (h
->toc_section
== NULL
)
2877 (*_bfd_error_handler
)
2878 (_("%s: TOC reloc at 0x%x to symbol `%s' with no TOC entry"),
2879 bfd_get_filename (input_bfd
), rel
->r_vaddr
,
2880 h
->root
.root
.string
);
2881 bfd_set_error (bfd_error_bad_value
);
2885 BFD_ASSERT ((h
->flags
& XCOFF_SET_TOC
) == 0);
2886 val
= (h
->toc_section
->output_section
->vma
2887 + h
->toc_section
->output_offset
);
2890 *relocation
= ((val
- xcoff_data (output_bfd
)->toc
)
2891 - (sym
->n_value
- xcoff_data (input_bfd
)->toc
));
2896 xcoff_reloc_type_ba (input_bfd
, input_section
, output_bfd
, rel
, sym
, howto
,
2897 val
, addend
, relocation
, contents
)
2898 bfd
*input_bfd ATTRIBUTE_UNUSED
;
2899 asection
*input_section ATTRIBUTE_UNUSED
;
2900 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2901 struct internal_reloc
*rel ATTRIBUTE_UNUSED
;
2902 struct internal_syment
*sym ATTRIBUTE_UNUSED
;
2903 struct reloc_howto_struct
*howto
;
2906 bfd_vma
*relocation
;
2907 bfd_byte
*contents ATTRIBUTE_UNUSED
;
2909 howto
->src_mask
&= ~3;
2910 howto
->dst_mask
= howto
->src_mask
;
2912 *relocation
= val
+ addend
;
2918 xcoff_reloc_type_br (input_bfd
, input_section
, output_bfd
, rel
, sym
, howto
,
2919 val
, addend
, relocation
, contents
)
2921 asection
*input_section
;
2922 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2923 struct internal_reloc
*rel
;
2924 struct internal_syment
*sym ATTRIBUTE_UNUSED
;
2925 struct reloc_howto_struct
*howto
;
2928 bfd_vma
*relocation
;
2931 struct xcoff_link_hash_entry
*h
;
2932 bfd_vma section_offset
;
2934 if (0 > rel
->r_symndx
)
2937 h
= obj_xcoff_sym_hashes (input_bfd
)[rel
->r_symndx
];
2938 section_offset
= rel
->r_vaddr
- input_section
->vma
;
2940 /* If we see an R_BR or R_RBR reloc which is jumping to global
2941 linkage code, and it is followed by an appropriate cror nop
2942 instruction, we replace the cror with lwz r2,20(r1). This
2943 restores the TOC after the glink code. Contrariwise, if the
2944 call is followed by a lwz r2,20(r1), but the call is not
2945 going to global linkage code, we can replace the load with a
2948 && (bfd_link_hash_defined
== h
->root
.type
2949 || bfd_link_hash_defweak
== h
->root
.type
)
2950 && section_offset
+ 8 <= input_section
->size
)
2955 pnext
= contents
+ section_offset
+ 4;
2956 next
= bfd_get_32 (input_bfd
, pnext
);
2958 /* The _ptrgl function is magic. It is used by the AIX
2959 compiler to call a function through a pointer. */
2960 if (h
->smclas
== XMC_GL
|| strcmp (h
->root
.root
.string
, "._ptrgl") == 0)
2962 if (next
== 0x4def7b82 /* cror 15,15,15 */
2963 || next
== 0x4ffffb82 /* cror 31,31,31 */
2964 || next
== 0x60000000) /* ori r0,r0,0 */
2965 bfd_put_32 (input_bfd
, 0x80410014, pnext
); /* lwz r2,20(r1) */
2970 if (next
== 0x80410014) /* lwz r2,20(r1) */
2971 bfd_put_32 (input_bfd
, 0x60000000, pnext
); /* ori r0,r0,0 */
2974 else if (NULL
!= h
&& bfd_link_hash_undefined
== h
->root
.type
)
2976 /* Normally, this relocation is against a defined symbol. In the
2977 case where this is a partial link and the output section offset
2978 is greater than 2^25, the linker will return an invalid error
2979 message that the relocation has been truncated. Yes it has been
2980 truncated but no it not important. For this case, disable the
2981 overflow checking. */
2983 howto
->complain_on_overflow
= complain_overflow_dont
;
2986 /* The original PC-relative relocation is biased by -r_vaddr, so adding
2987 the value below will give the absolute target address. */
2988 *relocation
= val
+ addend
+ rel
->r_vaddr
;
2990 howto
->src_mask
&= ~3;
2991 howto
->dst_mask
= howto
->src_mask
;
2994 && (h
->root
.type
== bfd_link_hash_defined
2995 || h
->root
.type
== bfd_link_hash_defweak
)
2996 && bfd_is_abs_section (h
->root
.u
.def
.section
)
2997 && section_offset
+ 4 <= input_section
->size
)
3002 /* Turn the relative branch into an absolute one by setting the
3004 ptr
= contents
+ section_offset
;
3005 insn
= bfd_get_32 (input_bfd
, ptr
);
3007 bfd_put_32 (input_bfd
, insn
, ptr
);
3009 /* Make the howto absolute too. */
3010 howto
->pc_relative
= FALSE
;
3011 howto
->complain_on_overflow
= complain_overflow_bitfield
;
3015 /* Use a PC-relative howto and subtract the instruction's address
3016 from the target address we calculated above. */
3017 howto
->pc_relative
= TRUE
;
3018 *relocation
-= (input_section
->output_section
->vma
3019 + input_section
->output_offset
3026 xcoff_reloc_type_crel (input_bfd
, input_section
, output_bfd
, rel
, sym
, howto
,
3027 val
, addend
, relocation
, contents
)
3028 bfd
*input_bfd ATTRIBUTE_UNUSED
;
3029 asection
*input_section
;
3030 bfd
*output_bfd ATTRIBUTE_UNUSED
;
3031 struct internal_reloc
*rel ATTRIBUTE_UNUSED
;
3032 struct internal_syment
*sym ATTRIBUTE_UNUSED
;
3033 struct reloc_howto_struct
*howto
;
3034 bfd_vma val ATTRIBUTE_UNUSED
;
3036 bfd_vma
*relocation
;
3037 bfd_byte
*contents ATTRIBUTE_UNUSED
;
3039 howto
->pc_relative
= TRUE
;
3040 howto
->src_mask
&= ~3;
3041 howto
->dst_mask
= howto
->src_mask
;
3043 /* A PC relative reloc includes the section address. */
3044 addend
+= input_section
->vma
;
3046 *relocation
= val
+ addend
;
3047 *relocation
-= (input_section
->output_section
->vma
3048 + input_section
->output_offset
);
3053 xcoff_complain_overflow_dont_func (input_bfd
, val
, relocation
, howto
)
3054 bfd
*input_bfd ATTRIBUTE_UNUSED
;
3055 bfd_vma val ATTRIBUTE_UNUSED
;
3056 bfd_vma relocation ATTRIBUTE_UNUSED
;
3057 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
;
3063 xcoff_complain_overflow_bitfield_func (input_bfd
, val
, relocation
, howto
)
3067 struct reloc_howto_struct
*howto
;
3069 bfd_vma addrmask
, fieldmask
, signmask
, ss
;
3072 /* Get the values to be added together. For signed and unsigned
3073 relocations, we assume that all values should be truncated to
3074 the size of an address. For bitfields, all the bits matter.
3075 See also bfd_check_overflow. */
3076 fieldmask
= N_ONES (howto
->bitsize
);
3077 addrmask
= N_ONES (bfd_arch_bits_per_address (input_bfd
)) | fieldmask
;
3079 b
= val
& howto
->src_mask
;
3081 /* Much like unsigned, except no trimming with addrmask. In
3082 addition, the sum overflows if there is a carry out of
3083 the bfd_vma, i.e., the sum is less than either input
3085 a
>>= howto
->rightshift
;
3086 b
>>= howto
->bitpos
;
3088 /* Bitfields are sometimes used for signed numbers; for
3089 example, a 13-bit field sometimes represents values in
3090 0..8191 and sometimes represents values in -4096..4095.
3091 If the field is signed and a is -4095 (0x1001) and b is
3092 -1 (0x1fff), the sum is -4096 (0x1000), but (0x1001 +
3093 0x1fff is 0x3000). It's not clear how to handle this
3094 everywhere, since there is not way to know how many bits
3095 are significant in the relocation, but the original code
3096 assumed that it was fully sign extended, and we will keep
3098 signmask
= (fieldmask
>> 1) + 1;
3100 if ((a
& ~ fieldmask
) != 0)
3102 /* Some bits out of the field are set. This might not
3103 be a problem: if this is a signed bitfield, it is OK
3104 iff all the high bits are set, including the sign
3105 bit. We'll try setting all but the most significant
3106 bit in the original relocation value: if this is all
3107 ones, we are OK, assuming a signed bitfield. */
3108 ss
= (signmask
<< howto
->rightshift
) - 1;
3109 if ((ss
| relocation
) != ~ (bfd_vma
) 0)
3114 /* We just assume (b & ~ fieldmask) == 0. */
3116 /* We explicitly permit wrap around if this relocation
3117 covers the high bit of an address. The Linux kernel
3118 relies on it, and it is the only way to write assembler
3119 code which can run when loaded at a location 0x80000000
3120 away from the location at which it is linked. */
3121 if (howto
->bitsize
+ howto
->rightshift
3122 == bfd_arch_bits_per_address (input_bfd
))
3126 if (sum
< a
|| (sum
& ~ fieldmask
) != 0)
3128 /* There was a carry out, or the field overflow. Test
3129 for signed operands again. Here is the overflow test
3130 is as for complain_overflow_signed. */
3131 if (((~ (a
^ b
)) & (a
^ sum
)) & signmask
)
3139 xcoff_complain_overflow_signed_func (input_bfd
, val
, relocation
, howto
)
3143 struct reloc_howto_struct
*howto
;
3145 bfd_vma addrmask
, fieldmask
, signmask
, ss
;
3148 /* Get the values to be added together. For signed and unsigned
3149 relocations, we assume that all values should be truncated to
3150 the size of an address. For bitfields, all the bits matter.
3151 See also bfd_check_overflow. */
3152 fieldmask
= N_ONES (howto
->bitsize
);
3153 addrmask
= N_ONES (bfd_arch_bits_per_address (input_bfd
)) | fieldmask
;
3155 b
= val
& howto
->src_mask
;
3157 a
= (a
& addrmask
) >> howto
->rightshift
;
3159 /* If any sign bits are set, all sign bits must be set.
3160 That is, A must be a valid negative address after
3162 signmask
= ~ (fieldmask
>> 1);
3164 if (ss
!= 0 && ss
!= ((addrmask
>> howto
->rightshift
) & signmask
))
3167 /* We only need this next bit of code if the sign bit of B
3168 is below the sign bit of A. This would only happen if
3169 SRC_MASK had fewer bits than BITSIZE. Note that if
3170 SRC_MASK has more bits than BITSIZE, we can get into
3171 trouble; we would need to verify that B is in range, as
3172 we do for A above. */
3173 signmask
= ((~ howto
->src_mask
) >> 1) & howto
->src_mask
;
3174 if ((b
& signmask
) != 0)
3176 /* Set all the bits above the sign bit. */
3177 b
-= signmask
<<= 1;
3180 b
= (b
& addrmask
) >> howto
->bitpos
;
3182 /* Now we can do the addition. */
3185 /* See if the result has the correct sign. Bits above the
3186 sign bit are junk now; ignore them. If the sum is
3187 positive, make sure we did not have all negative inputs;
3188 if the sum is negative, make sure we did not have all
3189 positive inputs. The test below looks only at the sign
3190 bits, and it really just
3191 SIGN (A) == SIGN (B) && SIGN (A) != SIGN (SUM)
3193 signmask
= (fieldmask
>> 1) + 1;
3194 if (((~ (a
^ b
)) & (a
^ sum
)) & signmask
)
3201 xcoff_complain_overflow_unsigned_func (input_bfd
, val
, relocation
, howto
)
3205 struct reloc_howto_struct
*howto
;
3207 bfd_vma addrmask
, fieldmask
;
3210 /* Get the values to be added together. For signed and unsigned
3211 relocations, we assume that all values should be truncated to
3212 the size of an address. For bitfields, all the bits matter.
3213 See also bfd_check_overflow. */
3214 fieldmask
= N_ONES (howto
->bitsize
);
3215 addrmask
= N_ONES (bfd_arch_bits_per_address (input_bfd
)) | fieldmask
;
3217 b
= val
& howto
->src_mask
;
3219 /* Checking for an unsigned overflow is relatively easy:
3220 trim the addresses and add, and trim the result as well.
3221 Overflow is normally indicated when the result does not
3222 fit in the field. However, we also need to consider the
3223 case when, e.g., fieldmask is 0x7fffffff or smaller, an
3224 input is 0x80000000, and bfd_vma is only 32 bits; then we
3225 will get sum == 0, but there is an overflow, since the
3226 inputs did not fit in the field. Instead of doing a
3227 separate test, we can check for this by or-ing in the
3228 operands when testing for the sum overflowing its final
3230 a
= (a
& addrmask
) >> howto
->rightshift
;
3231 b
= (b
& addrmask
) >> howto
->bitpos
;
3232 sum
= (a
+ b
) & addrmask
;
3233 if ((a
| b
| sum
) & ~ fieldmask
)
3239 /* This is the relocation function for the RS/6000/POWER/PowerPC.
3240 This is currently the only processor which uses XCOFF; I hope that
3243 I took the relocation type definitions from two documents:
3244 the PowerPC AIX Version 4 Application Binary Interface, First
3245 Edition (April 1992), and the PowerOpen ABI, Big-Endian
3246 32-Bit Hardware Implementation (June 30, 1994). Differences
3247 between the documents are noted below.
3249 Unsupported r_type's
3255 These relocs are defined by the PowerPC ABI to be
3256 relative branches which use half of the difference
3257 between the symbol and the program counter. I can't
3258 quite figure out when this is useful. These relocs are
3259 not defined by the PowerOpen ABI.
3264 Simple positive relocation.
3267 Simple negative relocation.
3270 Simple PC relative relocation.
3273 TOC relative relocation. The value in the instruction in
3274 the input file is the offset from the input file TOC to
3275 the desired location. We want the offset from the final
3276 TOC to the desired location. We have:
3281 so we must change insn by on - in.
3284 GL linkage relocation. The value of this relocation
3285 is the address of the entry in the TOC section.
3288 Local object TOC address. I can't figure out the
3289 difference between this and case R_GL.
3292 TOC relative relocation. A TOC relative load instruction
3293 which may be changed to a load address instruction.
3294 FIXME: We don't currently implement this optimization.
3297 TOC relative relocation. This is a TOC relative load
3298 address instruction which may be changed to a load
3299 instruction. FIXME: I don't know if this is the correct
3303 Absolute branch. We don't want to mess with the lower
3304 two bits of the instruction.
3307 The PowerPC ABI defines this as an absolute call which
3308 may be modified to become a relative call. The PowerOpen
3309 ABI does not define this relocation type.
3312 Absolute branch which may be modified to become a
3316 The PowerPC ABI defines this as an absolute branch to a
3317 fixed address which may be modified to an absolute branch
3318 to a symbol. The PowerOpen ABI does not define this
3322 The PowerPC ABI defines this as an absolute branch to a
3323 fixed address which may be modified to a relative branch.
3324 The PowerOpen ABI does not define this relocation type.
3327 Relative branch. We don't want to mess with the lower
3328 two bits of the instruction.
3331 The PowerPC ABI defines this as a relative call which may
3332 be modified to become an absolute call. The PowerOpen
3333 ABI does not define this relocation type.
3336 A relative branch which may be modified to become an
3340 The PowerPC AIX ABI describes this as a load which may be
3341 changed to a load address. The PowerOpen ABI says this
3342 is the same as case R_POS.
3345 The PowerPC AIX ABI describes this as a load address
3346 which may be changed to a load. The PowerOpen ABI says
3347 this is the same as R_POS.
3351 xcoff_ppc_relocate_section (output_bfd
, info
, input_bfd
,
3352 input_section
, contents
, relocs
, syms
,
3355 struct bfd_link_info
*info
;
3357 asection
*input_section
;
3359 struct internal_reloc
*relocs
;
3360 struct internal_syment
*syms
;
3361 asection
**sections
;
3363 struct internal_reloc
*rel
;
3364 struct internal_reloc
*relend
;
3367 relend
= rel
+ input_section
->reloc_count
;
3368 for (; rel
< relend
; rel
++)
3371 struct xcoff_link_hash_entry
*h
;
3372 struct internal_syment
*sym
;
3375 struct reloc_howto_struct howto
;
3377 bfd_vma value_to_relocate
;
3381 /* Relocation type R_REF is a special relocation type which is
3382 merely used to prevent garbage collection from occurring for
3383 the csect including the symbol which it references. */
3384 if (rel
->r_type
== R_REF
)
3388 howto
.type
= rel
->r_type
;
3389 howto
.rightshift
= 0;
3390 howto
.bitsize
= (rel
->r_size
& 0x1f) + 1;
3391 howto
.size
= howto
.bitsize
> 16 ? 2 : 1;
3392 howto
.pc_relative
= FALSE
;
3394 howto
.complain_on_overflow
= (rel
->r_size
& 0x80
3395 ? complain_overflow_signed
3396 : complain_overflow_bitfield
);
3397 howto
.special_function
= NULL
;
3398 howto
.name
= "internal";
3399 howto
.partial_inplace
= TRUE
;
3400 howto
.src_mask
= howto
.dst_mask
= N_ONES (howto
.bitsize
);
3401 howto
.pcrel_offset
= FALSE
;
3408 symndx
= rel
->r_symndx
;
3414 h
= obj_xcoff_sym_hashes (input_bfd
)[symndx
];
3415 sym
= syms
+ symndx
;
3416 addend
= - sym
->n_value
;
3420 sec
= sections
[symndx
];
3421 /* Hack to make sure we use the right TOC anchor value
3422 if this reloc is against the TOC anchor. */
3423 if (sec
->name
[3] == '0'
3424 && strcmp (sec
->name
, ".tc0") == 0)
3425 val
= xcoff_data (output_bfd
)->toc
;
3427 val
= (sec
->output_section
->vma
3428 + sec
->output_offset
3434 if (info
->unresolved_syms_in_objects
!= RM_IGNORE
3435 && (h
->flags
& XCOFF_WAS_UNDEFINED
) != 0)
3437 if (! ((*info
->callbacks
->undefined_symbol
)
3438 (info
, h
->root
.root
.string
,
3439 input_bfd
, input_section
,
3440 rel
->r_vaddr
- input_section
->vma
,
3441 (info
->unresolved_syms_in_objects
3442 == RM_GENERATE_ERROR
))))
3445 if (h
->root
.type
== bfd_link_hash_defined
3446 || h
->root
.type
== bfd_link_hash_defweak
)
3448 sec
= h
->root
.u
.def
.section
;
3449 val
= (h
->root
.u
.def
.value
3450 + sec
->output_section
->vma
3451 + sec
->output_offset
);
3453 else if (h
->root
.type
== bfd_link_hash_common
)
3455 sec
= h
->root
.u
.c
.p
->section
;
3456 val
= (sec
->output_section
->vma
3457 + sec
->output_offset
);
3462 BFD_ASSERT (info
->relocatable
3463 || (info
->static_link
3464 && (h
->flags
& XCOFF_WAS_UNDEFINED
) != 0)
3465 || (h
->flags
& XCOFF_DEF_DYNAMIC
) != 0
3466 || (h
->flags
& XCOFF_IMPORT
) != 0);
3471 if (rel
->r_type
>= XCOFF_MAX_CALCULATE_RELOCATION
3472 || !((*xcoff_calculate_relocation
[rel
->r_type
])
3473 (input_bfd
, input_section
, output_bfd
, rel
, sym
, &howto
, val
,
3474 addend
, &relocation
, contents
)))
3478 address
= rel
->r_vaddr
- input_section
->vma
;
3479 location
= contents
+ address
;
3481 if (address
> input_section
->size
)
3484 /* Get the value we are going to relocate. */
3485 if (1 == howto
.size
)
3486 value_to_relocate
= bfd_get_16 (input_bfd
, location
);
3488 value_to_relocate
= bfd_get_32 (input_bfd
, location
);
3492 FIXME: We may drop bits during the addition
3493 which we don't check for. We must either check at every single
3494 operation, which would be tedious, or we must do the computations
3495 in a type larger than bfd_vma, which would be inefficient. */
3497 if ((unsigned int) howto
.complain_on_overflow
3498 >= XCOFF_MAX_COMPLAIN_OVERFLOW
)
3501 if (((*xcoff_complain_overflow
[howto
.complain_on_overflow
])
3502 (input_bfd
, value_to_relocate
, relocation
, &howto
)))
3505 char buf
[SYMNMLEN
+ 1];
3506 char reloc_type_name
[10];
3518 name
= _bfd_coff_internal_syment_name (input_bfd
, sym
, buf
);
3522 sprintf (reloc_type_name
, "0x%02x", rel
->r_type
);
3524 if (! ((*info
->callbacks
->reloc_overflow
)
3525 (info
, (h
? &h
->root
: NULL
), name
, reloc_type_name
,
3526 (bfd_vma
) 0, input_bfd
, input_section
,
3527 rel
->r_vaddr
- input_section
->vma
)))
3531 /* Add RELOCATION to the right bits of VALUE_TO_RELOCATE. */
3532 value_to_relocate
= ((value_to_relocate
& ~howto
.dst_mask
)
3533 | (((value_to_relocate
& howto
.src_mask
)
3534 + relocation
) & howto
.dst_mask
));
3536 /* Put the value back in the object file. */
3537 if (1 == howto
.size
)
3538 bfd_put_16 (input_bfd
, value_to_relocate
, location
);
3540 bfd_put_32 (input_bfd
, value_to_relocate
, location
);
3547 _bfd_xcoff_put_ldsymbol_name (abfd
, ldinfo
, ldsym
, name
)
3548 bfd
*abfd ATTRIBUTE_UNUSED
;
3549 struct xcoff_loader_info
*ldinfo
;
3550 struct internal_ldsym
*ldsym
;
3554 len
= strlen (name
);
3556 if (len
<= SYMNMLEN
)
3557 strncpy (ldsym
->_l
._l_name
, name
, SYMNMLEN
);
3560 if (ldinfo
->string_size
+ len
+ 3 > ldinfo
->string_alc
)
3562 bfd_size_type newalc
;
3565 newalc
= ldinfo
->string_alc
* 2;
3568 while (ldinfo
->string_size
+ len
+ 3 > newalc
)
3571 newstrings
= bfd_realloc (ldinfo
->strings
, newalc
);
3572 if (newstrings
== NULL
)
3574 ldinfo
->failed
= TRUE
;
3577 ldinfo
->string_alc
= newalc
;
3578 ldinfo
->strings
= newstrings
;
3581 bfd_put_16 (ldinfo
->output_bfd
, (bfd_vma
) (len
+ 1),
3582 ldinfo
->strings
+ ldinfo
->string_size
);
3583 strcpy (ldinfo
->strings
+ ldinfo
->string_size
+ 2, name
);
3584 ldsym
->_l
._l_l
._l_zeroes
= 0;
3585 ldsym
->_l
._l_l
._l_offset
= ldinfo
->string_size
+ 2;
3586 ldinfo
->string_size
+= len
+ 3;
3593 _bfd_xcoff_put_symbol_name (bfd
*abfd
, struct bfd_strtab_hash
*strtab
,
3594 struct internal_syment
*sym
,
3597 if (strlen (name
) <= SYMNMLEN
)
3599 strncpy (sym
->_n
._n_name
, name
, SYMNMLEN
);
3607 if ((abfd
->flags
& BFD_TRADITIONAL_FORMAT
) != 0)
3609 indx
= _bfd_stringtab_add (strtab
, name
, hash
, FALSE
);
3610 if (indx
== (bfd_size_type
) -1)
3612 sym
->_n
._n_n
._n_zeroes
= 0;
3613 sym
->_n
._n_n
._n_offset
= STRING_SIZE_SIZE
+ indx
;
3619 xcoff_create_csect_from_smclas (abfd
, aux
, symbol_name
)
3621 union internal_auxent
*aux
;
3622 const char *symbol_name
;
3624 asection
*return_value
= NULL
;
3626 /* .sv64 = x_smclas == 17
3627 This is an invalid csect for 32 bit apps. */
3628 static const char *names
[19] =
3630 ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo",
3631 ".sv", ".bs", ".ds", ".uc", ".ti", ".tb", NULL
, ".tc0",
3632 ".td", NULL
, ".sv3264"
3635 if ((19 >= aux
->x_csect
.x_smclas
)
3636 && (NULL
!= names
[aux
->x_csect
.x_smclas
]))
3638 return_value
= bfd_make_section_anyway
3639 (abfd
, names
[aux
->x_csect
.x_smclas
]);
3643 (*_bfd_error_handler
)
3644 (_("%B: symbol `%s' has unrecognized smclas %d"),
3645 abfd
, symbol_name
, aux
->x_csect
.x_smclas
);
3646 bfd_set_error (bfd_error_bad_value
);
3649 return return_value
;
3653 xcoff_is_lineno_count_overflow (abfd
, value
)
3654 bfd
*abfd ATTRIBUTE_UNUSED
;
3657 if (0xffff <= value
)
3664 xcoff_is_reloc_count_overflow (abfd
, value
)
3665 bfd
*abfd ATTRIBUTE_UNUSED
;
3668 if (0xffff <= value
)
3675 xcoff_loader_symbol_offset (abfd
, ldhdr
)
3677 struct internal_ldhdr
*ldhdr ATTRIBUTE_UNUSED
;
3679 return bfd_xcoff_ldhdrsz (abfd
);
3683 xcoff_loader_reloc_offset (abfd
, ldhdr
)
3685 struct internal_ldhdr
*ldhdr
;
3687 return bfd_xcoff_ldhdrsz (abfd
) + ldhdr
->l_nsyms
* bfd_xcoff_ldsymsz (abfd
);
3691 xcoff_generate_rtinit (abfd
, init
, fini
, rtld
)
3697 bfd_byte filehdr_ext
[FILHSZ
];
3698 bfd_byte scnhdr_ext
[SCNHSZ
];
3699 bfd_byte syment_ext
[SYMESZ
* 10];
3700 bfd_byte reloc_ext
[RELSZ
* 3];
3701 bfd_byte
*data_buffer
;
3702 bfd_size_type data_buffer_size
;
3703 bfd_byte
*string_table
= NULL
, *st_tmp
= NULL
;
3704 bfd_size_type string_table_size
;
3706 size_t initsz
, finisz
;
3707 struct internal_filehdr filehdr
;
3708 struct internal_scnhdr scnhdr
;
3709 struct internal_syment syment
;
3710 union internal_auxent auxent
;
3711 struct internal_reloc reloc
;
3713 char *data_name
= ".data";
3714 char *rtinit_name
= "__rtinit";
3715 char *rtld_name
= "__rtld";
3717 if (! bfd_xcoff_rtinit_size (abfd
))
3720 initsz
= (init
== NULL
? 0 : 1 + strlen (init
));
3721 finisz
= (fini
== NULL
? 0 : 1 + strlen (fini
));
3724 memset (filehdr_ext
, 0, FILHSZ
);
3725 memset (&filehdr
, 0, sizeof (struct internal_filehdr
));
3726 filehdr
.f_magic
= bfd_xcoff_magic_number (abfd
);
3727 filehdr
.f_nscns
= 1;
3728 filehdr
.f_timdat
= 0;
3729 filehdr
.f_nsyms
= 0; /* at least 6, no more than 10 */
3730 filehdr
.f_symptr
= 0; /* set below */
3731 filehdr
.f_opthdr
= 0;
3732 filehdr
.f_flags
= 0;
3734 /* section header */
3735 memset (scnhdr_ext
, 0, SCNHSZ
);
3736 memset (&scnhdr
, 0, sizeof (struct internal_scnhdr
));
3737 memcpy (scnhdr
.s_name
, data_name
, strlen (data_name
));
3740 scnhdr
.s_size
= 0; /* set below */
3741 scnhdr
.s_scnptr
= FILHSZ
+ SCNHSZ
;
3742 scnhdr
.s_relptr
= 0; /* set below */
3743 scnhdr
.s_lnnoptr
= 0;
3744 scnhdr
.s_nreloc
= 0; /* either 1 or 2 */
3746 scnhdr
.s_flags
= STYP_DATA
;
3749 0x0000 0x00000000 : rtl
3750 0x0004 0x00000010 : offset to init, or 0
3751 0x0008 0x00000028 : offset to fini, or 0
3752 0x000C 0x0000000C : size of descriptor
3753 0x0010 0x00000000 : init, needs a reloc
3754 0x0014 0x00000040 : offset to init name
3755 0x0018 0x00000000 : flags, padded to a word
3756 0x001C 0x00000000 : empty init
3759 0x0028 0x00000000 : fini, needs a reloc
3760 0x002C 0x00000??? : offset to fini name
3761 0x0030 0x00000000 : flags, padded to a word
3762 0x0034 0x00000000 : empty fini
3766 0x0040 + initsz fini name */
3768 data_buffer_size
= 0x0040 + initsz
+ finisz
;
3769 data_buffer_size
= (data_buffer_size
+ 7) &~ (bfd_size_type
) 7;
3771 data_buffer
= (bfd_byte
*) bfd_zmalloc (data_buffer_size
);
3772 if (data_buffer
== NULL
)
3778 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x04]);
3780 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x14]);
3781 memcpy (&data_buffer
[val
], init
, initsz
);
3787 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x08]);
3788 val
= 0x40 + initsz
;
3789 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x2C]);
3790 memcpy (&data_buffer
[val
], fini
, finisz
);
3794 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x0C]);
3796 scnhdr
.s_size
= data_buffer_size
;
3799 string_table_size
= 0;
3801 string_table_size
+= initsz
;
3803 string_table_size
+= finisz
;
3804 if (string_table_size
)
3806 string_table_size
+= 4;
3807 string_table
= (bfd_byte
*) bfd_zmalloc (string_table_size
);
3808 if (string_table
== NULL
)
3811 val
= string_table_size
;
3812 bfd_h_put_32 (abfd
, val
, &string_table
[0]);
3813 st_tmp
= string_table
+ 4;
3822 memset (syment_ext
, 0, 10 * SYMESZ
);
3823 memset (reloc_ext
, 0, 3 * RELSZ
);
3826 memset (&syment
, 0, sizeof (struct internal_syment
));
3827 memset (&auxent
, 0, sizeof (union internal_auxent
));
3828 memcpy (syment
._n
._n_name
, data_name
, strlen (data_name
));
3830 syment
.n_sclass
= C_HIDEXT
;
3831 syment
.n_numaux
= 1;
3832 auxent
.x_csect
.x_scnlen
.l
= data_buffer_size
;
3833 auxent
.x_csect
.x_smtyp
= 3 << 3 | XTY_SD
;
3834 auxent
.x_csect
.x_smclas
= XMC_RW
;
3835 bfd_coff_swap_sym_out (abfd
, &syment
,
3836 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3837 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3839 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3840 filehdr
.f_nsyms
+= 2;
3843 memset (&syment
, 0, sizeof (struct internal_syment
));
3844 memset (&auxent
, 0, sizeof (union internal_auxent
));
3845 memcpy (syment
._n
._n_name
, rtinit_name
, strlen (rtinit_name
));
3847 syment
.n_sclass
= C_EXT
;
3848 syment
.n_numaux
= 1;
3849 auxent
.x_csect
.x_smtyp
= XTY_LD
;
3850 auxent
.x_csect
.x_smclas
= XMC_RW
;
3851 bfd_coff_swap_sym_out (abfd
, &syment
,
3852 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3853 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3855 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3856 filehdr
.f_nsyms
+= 2;
3861 memset (&syment
, 0, sizeof (struct internal_syment
));
3862 memset (&auxent
, 0, sizeof (union internal_auxent
));
3866 syment
._n
._n_n
._n_offset
= st_tmp
- string_table
;
3867 memcpy (st_tmp
, init
, initsz
);
3871 memcpy (syment
._n
._n_name
, init
, initsz
- 1);
3873 syment
.n_sclass
= C_EXT
;
3874 syment
.n_numaux
= 1;
3875 bfd_coff_swap_sym_out (abfd
, &syment
,
3876 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3877 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3879 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3882 memset (&reloc
, 0, sizeof (struct internal_reloc
));
3883 reloc
.r_vaddr
= 0x0010;
3884 reloc
.r_symndx
= filehdr
.f_nsyms
;
3885 reloc
.r_type
= R_POS
;
3887 bfd_coff_swap_reloc_out (abfd
, &reloc
, &reloc_ext
[0]);
3889 filehdr
.f_nsyms
+= 2;
3890 scnhdr
.s_nreloc
+= 1;
3896 memset (&syment
, 0, sizeof (struct internal_syment
));
3897 memset (&auxent
, 0, sizeof (union internal_auxent
));
3901 syment
._n
._n_n
._n_offset
= st_tmp
- string_table
;
3902 memcpy (st_tmp
, fini
, finisz
);
3906 memcpy (syment
._n
._n_name
, fini
, finisz
- 1);
3908 syment
.n_sclass
= C_EXT
;
3909 syment
.n_numaux
= 1;
3910 bfd_coff_swap_sym_out (abfd
, &syment
,
3911 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3912 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3914 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3917 memset (&reloc
, 0, sizeof (struct internal_reloc
));
3918 reloc
.r_vaddr
= 0x0028;
3919 reloc
.r_symndx
= filehdr
.f_nsyms
;
3920 reloc
.r_type
= R_POS
;
3922 bfd_coff_swap_reloc_out (abfd
, &reloc
,
3923 &reloc_ext
[scnhdr
.s_nreloc
* RELSZ
]);
3925 filehdr
.f_nsyms
+= 2;
3926 scnhdr
.s_nreloc
+= 1;
3931 memset (&syment
, 0, sizeof (struct internal_syment
));
3932 memset (&auxent
, 0, sizeof (union internal_auxent
));
3933 memcpy (syment
._n
._n_name
, rtld_name
, strlen (rtld_name
));
3934 syment
.n_sclass
= C_EXT
;
3935 syment
.n_numaux
= 1;
3936 bfd_coff_swap_sym_out (abfd
, &syment
,
3937 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3938 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3940 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3943 memset (&reloc
, 0, sizeof (struct internal_reloc
));
3944 reloc
.r_vaddr
= 0x0000;
3945 reloc
.r_symndx
= filehdr
.f_nsyms
;
3946 reloc
.r_type
= R_POS
;
3948 bfd_coff_swap_reloc_out (abfd
, &reloc
,
3949 &reloc_ext
[scnhdr
.s_nreloc
* RELSZ
]);
3951 filehdr
.f_nsyms
+= 2;
3952 scnhdr
.s_nreloc
+= 1;
3955 scnhdr
.s_relptr
= scnhdr
.s_scnptr
+ data_buffer_size
;
3956 filehdr
.f_symptr
= scnhdr
.s_relptr
+ scnhdr
.s_nreloc
* RELSZ
;
3958 bfd_coff_swap_filehdr_out (abfd
, &filehdr
, filehdr_ext
);
3959 bfd_bwrite (filehdr_ext
, FILHSZ
, abfd
);
3960 bfd_coff_swap_scnhdr_out (abfd
, &scnhdr
, scnhdr_ext
);
3961 bfd_bwrite (scnhdr_ext
, SCNHSZ
, abfd
);
3962 bfd_bwrite (data_buffer
, data_buffer_size
, abfd
);
3963 bfd_bwrite (reloc_ext
, scnhdr
.s_nreloc
* RELSZ
, abfd
);
3964 bfd_bwrite (syment_ext
, filehdr
.f_nsyms
* SYMESZ
, abfd
);
3965 bfd_bwrite (string_table
, string_table_size
, abfd
);
3974 static reloc_howto_type xcoff_dynamic_reloc
=
3975 HOWTO (0, /* type */
3977 2, /* size (0 = byte, 1 = short, 2 = long) */
3979 FALSE
, /* pc_relative */
3981 complain_overflow_bitfield
, /* complain_on_overflow */
3982 0, /* special_function */
3984 TRUE
, /* partial_inplace */
3985 0xffffffff, /* src_mask */
3986 0xffffffff, /* dst_mask */
3987 FALSE
); /* pcrel_offset */
3991 The first word of global linkage code must be modified by filling in
3992 the correct TOC offset. */
3994 static unsigned long xcoff_glink_code
[9] =
3996 0x81820000, /* lwz r12,0(r2) */
3997 0x90410014, /* stw r2,20(r1) */
3998 0x800c0000, /* lwz r0,0(r12) */
3999 0x804c0004, /* lwz r2,4(r12) */
4000 0x7c0903a6, /* mtctr r0 */
4001 0x4e800420, /* bctr */
4002 0x00000000, /* start of traceback table */
4003 0x000c8000, /* traceback table */
4004 0x00000000, /* traceback table */
4008 static const struct xcoff_backend_data_rec bfd_xcoff_backend_data
=
4010 { /* COFF backend, defined in libcoff.h. */
4011 _bfd_xcoff_swap_aux_in
,
4012 _bfd_xcoff_swap_sym_in
,
4013 coff_swap_lineno_in
,
4014 _bfd_xcoff_swap_aux_out
,
4015 _bfd_xcoff_swap_sym_out
,
4016 coff_swap_lineno_out
,
4017 xcoff_swap_reloc_out
,
4018 coff_swap_filehdr_out
,
4019 coff_swap_aouthdr_out
,
4020 coff_swap_scnhdr_out
,
4029 TRUE
, /* _bfd_coff_long_filenames */
4030 XCOFF_NO_LONG_SECTION_NAMES
, /* _bfd_coff_long_section_names */
4031 3, /* _bfd_coff_default_section_alignment_power */
4032 FALSE
, /* _bfd_coff_force_symnames_in_strings */
4033 2, /* _bfd_coff_debug_string_prefix_length */
4034 coff_swap_filehdr_in
,
4035 coff_swap_aouthdr_in
,
4036 coff_swap_scnhdr_in
,
4037 xcoff_swap_reloc_in
,
4038 coff_bad_format_hook
,
4039 coff_set_arch_mach_hook
,
4042 coff_set_alignment_hook
,
4043 coff_slurp_symbol_table
,
4044 symname_in_debug_hook
,
4045 coff_pointerize_aux_hook
,
4047 dummy_reloc16_extra_cases
,
4048 dummy_reloc16_estimate
,
4049 NULL
, /* bfd_coff_sym_is_global */
4050 coff_compute_section_file_positions
,
4051 NULL
, /* _bfd_coff_start_final_link */
4052 xcoff_ppc_relocate_section
,
4053 coff_rtype_to_howto
,
4054 NULL
, /* _bfd_coff_adjust_symndx */
4055 _bfd_generic_link_add_one_symbol
,
4056 coff_link_output_has_begun
,
4057 coff_final_link_postscript
,
4058 NULL
/* print_pdata. */
4061 0x01DF, /* magic number */
4065 /* Function pointers to xcoff specific swap routines. */
4066 xcoff_swap_ldhdr_in
,
4067 xcoff_swap_ldhdr_out
,
4068 xcoff_swap_ldsym_in
,
4069 xcoff_swap_ldsym_out
,
4070 xcoff_swap_ldrel_in
,
4071 xcoff_swap_ldrel_out
,
4077 12, /* _xcoff_function_descriptor_size */
4081 1, /* _xcoff_ldhdr_version */
4083 _bfd_xcoff_put_symbol_name
,
4084 _bfd_xcoff_put_ldsymbol_name
,
4085 &xcoff_dynamic_reloc
,
4086 xcoff_create_csect_from_smclas
,
4088 /* Lineno and reloc count overflow. */
4089 xcoff_is_lineno_count_overflow
,
4090 xcoff_is_reloc_count_overflow
,
4092 xcoff_loader_symbol_offset
,
4093 xcoff_loader_reloc_offset
,
4096 &xcoff_glink_code
[0],
4097 36, /* _xcoff_glink_size */
4100 64, /* _xcoff_rtinit_size */
4101 xcoff_generate_rtinit
,
4104 /* The transfer vector that leads the outside world to all of the above. */
4105 const bfd_target rs6000coff_vec
=
4108 bfd_target_xcoff_flavour
,
4109 BFD_ENDIAN_BIG
, /* data byte order is big */
4110 BFD_ENDIAN_BIG
, /* header byte order is big */
4112 (HAS_RELOC
| EXEC_P
| HAS_LINENO
| HAS_DEBUG
| DYNAMIC
4113 | HAS_SYMS
| HAS_LOCALS
| WP_TEXT
),
4115 SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_CODE
| SEC_DATA
,
4116 0, /* leading char */
4117 '/', /* ar_pad_char */
4118 15, /* ar_max_namelen */
4142 { /* bfd_check_format */
4145 _bfd_xcoff_archive_p
,
4149 { /* bfd_set_format */
4152 _bfd_generic_mkarchive
,
4156 {/* bfd_write_contents */
4158 coff_write_object_contents
,
4159 _bfd_xcoff_write_archive_contents
,
4166 coff_new_section_hook
,
4167 _bfd_generic_get_section_contents
,
4168 _bfd_generic_get_section_contents_in_window
,
4171 _bfd_xcoff_copy_private_bfd_data
,
4172 ((bfd_boolean (*) (bfd
*, bfd
*)) bfd_true
),
4173 _bfd_generic_init_private_section_data
,
4174 ((bfd_boolean (*) (bfd
*, asection
*, bfd
*, asection
*)) bfd_true
),
4175 ((bfd_boolean (*) (bfd
*, asymbol
*, bfd
*, asymbol
*)) bfd_true
),
4176 ((bfd_boolean (*) (bfd
*, bfd
*)) bfd_true
),
4177 ((bfd_boolean (*) (bfd
*, flagword
)) bfd_true
),
4178 ((bfd_boolean (*) (bfd
*, void * )) bfd_true
),
4181 coff_core_file_failing_command
,
4182 coff_core_file_failing_signal
,
4183 coff_core_file_matches_executable_p
,
4186 _bfd_xcoff_slurp_armap
,
4188 ((bfd_boolean (*) (bfd
*, char **, bfd_size_type
*, const char **)) bfd_false
),
4189 bfd_dont_truncate_arname
,
4190 _bfd_xcoff_write_armap
,
4191 _bfd_xcoff_read_ar_hdr
,
4192 _bfd_xcoff_openr_next_archived_file
,
4193 _bfd_generic_get_elt_at_index
,
4194 _bfd_xcoff_stat_arch_elt
,
4198 coff_get_symtab_upper_bound
,
4199 coff_canonicalize_symtab
,
4200 coff_make_empty_symbol
,
4202 coff_get_symbol_info
,
4203 _bfd_xcoff_is_local_label_name
,
4204 coff_bfd_is_target_special_symbol
,
4206 coff_find_nearest_line
,
4207 _bfd_generic_find_line
,
4208 coff_find_inliner_info
,
4209 coff_bfd_make_debug_symbol
,
4210 _bfd_generic_read_minisymbols
,
4211 _bfd_generic_minisymbol_to_symbol
,
4214 coff_get_reloc_upper_bound
,
4215 coff_canonicalize_reloc
,
4216 _bfd_xcoff_reloc_type_lookup
,
4217 _bfd_xcoff_reloc_name_lookup
,
4221 coff_set_section_contents
,
4224 _bfd_xcoff_sizeof_headers
,
4225 bfd_generic_get_relocated_section_contents
,
4226 bfd_generic_relax_section
,
4227 _bfd_xcoff_bfd_link_hash_table_create
,
4228 _bfd_generic_link_hash_table_free
,
4229 _bfd_xcoff_bfd_link_add_symbols
,
4230 _bfd_generic_link_just_syms
,
4231 _bfd_xcoff_bfd_final_link
,
4232 _bfd_generic_link_split_section
,
4233 bfd_generic_gc_sections
,
4234 bfd_generic_merge_sections
,
4235 bfd_generic_is_group_section
,
4236 bfd_generic_discard_group
,
4237 _bfd_generic_section_already_linked
,
4238 _bfd_xcoff_define_common_symbol
,
4241 _bfd_xcoff_get_dynamic_symtab_upper_bound
,
4242 _bfd_xcoff_canonicalize_dynamic_symtab
,
4243 _bfd_nodynamic_get_synthetic_symtab
,
4244 _bfd_xcoff_get_dynamic_reloc_upper_bound
,
4245 _bfd_xcoff_canonicalize_dynamic_reloc
,
4247 /* Opposite endian version, none exists */
4250 (void *) &bfd_xcoff_backend_data
,
4253 /* xcoff-powermac target
4255 Only difference between this target and the rs6000 target is the
4256 the default architecture and machine type used in coffcode.h
4258 PowerPC Macs use the same magic numbers as RS/6000
4259 (because that's how they were bootstrapped originally),
4260 but they are always PowerPC architecture. */
4261 static const struct xcoff_backend_data_rec bfd_pmac_xcoff_backend_data
=
4263 { /* COFF backend, defined in libcoff.h. */
4264 _bfd_xcoff_swap_aux_in
,
4265 _bfd_xcoff_swap_sym_in
,
4266 coff_swap_lineno_in
,
4267 _bfd_xcoff_swap_aux_out
,
4268 _bfd_xcoff_swap_sym_out
,
4269 coff_swap_lineno_out
,
4270 xcoff_swap_reloc_out
,
4271 coff_swap_filehdr_out
,
4272 coff_swap_aouthdr_out
,
4273 coff_swap_scnhdr_out
,
4282 TRUE
, /* _bfd_coff_long_filenames */
4283 XCOFF_NO_LONG_SECTION_NAMES
, /* _bfd_coff_long_section_names */
4284 3, /* _bfd_coff_default_section_alignment_power */
4285 FALSE
, /* _bfd_coff_force_symnames_in_strings */
4286 2, /* _bfd_coff_debug_string_prefix_length */
4287 coff_swap_filehdr_in
,
4288 coff_swap_aouthdr_in
,
4289 coff_swap_scnhdr_in
,
4290 xcoff_swap_reloc_in
,
4291 coff_bad_format_hook
,
4292 coff_set_arch_mach_hook
,
4295 coff_set_alignment_hook
,
4296 coff_slurp_symbol_table
,
4297 symname_in_debug_hook
,
4298 coff_pointerize_aux_hook
,
4300 dummy_reloc16_extra_cases
,
4301 dummy_reloc16_estimate
,
4302 NULL
, /* bfd_coff_sym_is_global */
4303 coff_compute_section_file_positions
,
4304 NULL
, /* _bfd_coff_start_final_link */
4305 xcoff_ppc_relocate_section
,
4306 coff_rtype_to_howto
,
4307 NULL
, /* _bfd_coff_adjust_symndx */
4308 _bfd_generic_link_add_one_symbol
,
4309 coff_link_output_has_begun
,
4310 coff_final_link_postscript
,
4311 NULL
/* print_pdata. */
4314 0x01DF, /* magic number */
4318 /* Function pointers to xcoff specific swap routines. */
4319 xcoff_swap_ldhdr_in
,
4320 xcoff_swap_ldhdr_out
,
4321 xcoff_swap_ldsym_in
,
4322 xcoff_swap_ldsym_out
,
4323 xcoff_swap_ldrel_in
,
4324 xcoff_swap_ldrel_out
,
4330 12, /* _xcoff_function_descriptor_size */
4334 1, /* _xcoff_ldhdr_version */
4336 _bfd_xcoff_put_symbol_name
,
4337 _bfd_xcoff_put_ldsymbol_name
,
4338 &xcoff_dynamic_reloc
,
4339 xcoff_create_csect_from_smclas
,
4341 /* Lineno and reloc count overflow. */
4342 xcoff_is_lineno_count_overflow
,
4343 xcoff_is_reloc_count_overflow
,
4345 xcoff_loader_symbol_offset
,
4346 xcoff_loader_reloc_offset
,
4349 &xcoff_glink_code
[0],
4350 36, /* _xcoff_glink_size */
4353 0, /* _xcoff_rtinit_size */
4354 xcoff_generate_rtinit
,
4357 /* The transfer vector that leads the outside world to all of the above. */
4358 const bfd_target pmac_xcoff_vec
=
4361 bfd_target_xcoff_flavour
,
4362 BFD_ENDIAN_BIG
, /* data byte order is big */
4363 BFD_ENDIAN_BIG
, /* header byte order is big */
4365 (HAS_RELOC
| EXEC_P
| HAS_LINENO
| HAS_DEBUG
| DYNAMIC
4366 | HAS_SYMS
| HAS_LOCALS
| WP_TEXT
),
4368 SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_CODE
| SEC_DATA
,
4369 0, /* leading char */
4370 '/', /* ar_pad_char */
4371 15, /* ar_max_namelen */
4395 { /* bfd_check_format */
4398 _bfd_xcoff_archive_p
,
4402 { /* bfd_set_format */
4405 _bfd_generic_mkarchive
,
4409 {/* bfd_write_contents */
4411 coff_write_object_contents
,
4412 _bfd_xcoff_write_archive_contents
,
4419 coff_new_section_hook
,
4420 _bfd_generic_get_section_contents
,
4421 _bfd_generic_get_section_contents_in_window
,
4424 _bfd_xcoff_copy_private_bfd_data
,
4425 ((bfd_boolean (*) (bfd
*, bfd
*)) bfd_true
),
4426 _bfd_generic_init_private_section_data
,
4427 ((bfd_boolean (*) (bfd
*, asection
*, bfd
*, asection
*)) bfd_true
),
4428 ((bfd_boolean (*) (bfd
*, asymbol
*, bfd
*, asymbol
*)) bfd_true
),
4429 ((bfd_boolean (*) (bfd
*, bfd
*)) bfd_true
),
4430 ((bfd_boolean (*) (bfd
*, flagword
)) bfd_true
),
4431 ((bfd_boolean (*) (bfd
*, void * )) bfd_true
),
4434 coff_core_file_failing_command
,
4435 coff_core_file_failing_signal
,
4436 coff_core_file_matches_executable_p
,
4439 _bfd_xcoff_slurp_armap
,
4441 ((bfd_boolean (*) (bfd
*, char **, bfd_size_type
*, const char **)) bfd_false
),
4442 bfd_dont_truncate_arname
,
4443 _bfd_xcoff_write_armap
,
4444 _bfd_xcoff_read_ar_hdr
,
4445 _bfd_xcoff_openr_next_archived_file
,
4446 _bfd_generic_get_elt_at_index
,
4447 _bfd_xcoff_stat_arch_elt
,
4451 coff_get_symtab_upper_bound
,
4452 coff_canonicalize_symtab
,
4453 coff_make_empty_symbol
,
4455 coff_get_symbol_info
,
4456 _bfd_xcoff_is_local_label_name
,
4457 coff_bfd_is_target_special_symbol
,
4459 coff_find_nearest_line
,
4460 _bfd_generic_find_line
,
4461 coff_find_inliner_info
,
4462 coff_bfd_make_debug_symbol
,
4463 _bfd_generic_read_minisymbols
,
4464 _bfd_generic_minisymbol_to_symbol
,
4467 coff_get_reloc_upper_bound
,
4468 coff_canonicalize_reloc
,
4469 _bfd_xcoff_reloc_type_lookup
,
4470 _bfd_xcoff_reloc_name_lookup
,
4474 coff_set_section_contents
,
4477 _bfd_xcoff_sizeof_headers
,
4478 bfd_generic_get_relocated_section_contents
,
4479 bfd_generic_relax_section
,
4480 _bfd_xcoff_bfd_link_hash_table_create
,
4481 _bfd_generic_link_hash_table_free
,
4482 _bfd_xcoff_bfd_link_add_symbols
,
4483 _bfd_generic_link_just_syms
,
4484 _bfd_xcoff_bfd_final_link
,
4485 _bfd_generic_link_split_section
,
4486 bfd_generic_gc_sections
,
4487 bfd_generic_merge_sections
,
4488 bfd_generic_is_group_section
,
4489 bfd_generic_discard_group
,
4490 _bfd_generic_section_already_linked
,
4491 _bfd_xcoff_define_common_symbol
,
4494 _bfd_xcoff_get_dynamic_symtab_upper_bound
,
4495 _bfd_xcoff_canonicalize_dynamic_symtab
,
4496 _bfd_nodynamic_get_synthetic_symtab
,
4497 _bfd_xcoff_get_dynamic_reloc_upper_bound
,
4498 _bfd_xcoff_canonicalize_dynamic_reloc
,
4500 /* Opposite endian version, none exists */
4503 (void *) &bfd_pmac_xcoff_backend_data
,