1 /* BFD back-end for IBM RS/6000 "XCOFF" files.
2 Copyright 1990-1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
4 Free Software Foundation, Inc.
5 Written by Metin G. Ozisik, Mimi Phuong-Thao Vo, and John Gilmore.
6 Archive support from Damon A. Permezel.
7 Contributed by IBM Corporation and Cygnus Support.
9 This file is part of BFD, the Binary File Descriptor library.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
24 MA 02110-1301, USA. */
30 #include "coff/internal.h"
31 #include "coff/xcoff.h"
32 #include "coff/rs6000.h"
36 extern bfd_boolean _bfd_xcoff_mkobject
38 extern bfd_boolean _bfd_xcoff_copy_private_bfd_data
39 PARAMS ((bfd
*, bfd
*));
40 extern bfd_boolean _bfd_xcoff_is_local_label_name
41 PARAMS ((bfd
*, const char *));
42 extern reloc_howto_type
*_bfd_xcoff_reloc_type_lookup
43 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
44 extern bfd_boolean _bfd_xcoff_slurp_armap
46 extern const bfd_target
*_bfd_xcoff_archive_p
48 extern PTR _bfd_xcoff_read_ar_hdr
50 extern bfd
*_bfd_xcoff_openr_next_archived_file
51 PARAMS ((bfd
*, bfd
*));
52 extern int _bfd_xcoff_stat_arch_elt
53 PARAMS ((bfd
*, struct stat
*));
54 extern bfd_boolean _bfd_xcoff_write_armap
55 PARAMS ((bfd
*, unsigned int, struct orl
*, unsigned int, int));
56 extern bfd_boolean _bfd_xcoff_write_archive_contents
58 extern int _bfd_xcoff_sizeof_headers
59 PARAMS ((bfd
*, struct bfd_link_info
*));
60 extern void _bfd_xcoff_swap_sym_in
61 PARAMS ((bfd
*, PTR
, PTR
));
62 extern unsigned int _bfd_xcoff_swap_sym_out
63 PARAMS ((bfd
*, PTR
, PTR
));
64 extern void _bfd_xcoff_swap_aux_in
65 PARAMS ((bfd
*, PTR
, int, int, int, int, PTR
));
66 extern unsigned int _bfd_xcoff_swap_aux_out
67 PARAMS ((bfd
*, PTR
, int, int, int, int, PTR
));
68 static void xcoff_swap_reloc_in
69 PARAMS ((bfd
*, PTR
, PTR
));
70 static unsigned int xcoff_swap_reloc_out
71 PARAMS ((bfd
*, PTR
, PTR
));
73 /* Forward declare xcoff_rtype2howto for coffcode.h macro. */
74 void xcoff_rtype2howto
75 PARAMS ((arelent
*, struct internal_reloc
*));
77 /* coffcode.h needs these to be defined. */
78 #define RS6000COFF_C 1
80 #define SELECT_RELOC(internal, howto) \
82 internal.r_type = howto->type; \
84 ((howto->complain_on_overflow == complain_overflow_signed \
87 | (howto->bitsize - 1)); \
90 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
91 #define COFF_LONG_FILENAMES
92 #define NO_COFF_SYMBOLS
93 #define RTYPE2HOWTO(cache_ptr, dst) xcoff_rtype2howto (cache_ptr, dst)
94 #define coff_mkobject _bfd_xcoff_mkobject
95 #define coff_bfd_copy_private_bfd_data _bfd_xcoff_copy_private_bfd_data
96 #define coff_bfd_is_local_label_name _bfd_xcoff_is_local_label_name
97 #define coff_bfd_reloc_type_lookup _bfd_xcoff_reloc_type_lookup
98 #define coff_bfd_reloc_name_lookup _bfd_xcoff_reloc_name_lookup
100 extern const bfd_target
* rs6000coff_core_p
101 PARAMS ((bfd
*abfd
));
102 extern bfd_boolean rs6000coff_core_file_matches_executable_p
103 PARAMS ((bfd
*cbfd
, bfd
*ebfd
));
104 extern char *rs6000coff_core_file_failing_command
105 PARAMS ((bfd
*abfd
));
106 extern int rs6000coff_core_file_failing_signal
107 PARAMS ((bfd
*abfd
));
108 #define CORE_FILE_P rs6000coff_core_p
109 #define coff_core_file_failing_command \
110 rs6000coff_core_file_failing_command
111 #define coff_core_file_failing_signal \
112 rs6000coff_core_file_failing_signal
113 #define coff_core_file_matches_executable_p \
114 rs6000coff_core_file_matches_executable_p
115 #define coff_core_file_pid \
116 _bfd_nocore_core_file_pid
118 #define CORE_FILE_P _bfd_dummy_target
119 #define coff_core_file_failing_command \
120 _bfd_nocore_core_file_failing_command
121 #define coff_core_file_failing_signal \
122 _bfd_nocore_core_file_failing_signal
123 #define coff_core_file_matches_executable_p \
124 _bfd_nocore_core_file_matches_executable_p
125 #define coff_core_file_pid \
126 _bfd_nocore_core_file_pid
128 #define coff_SWAP_sym_in _bfd_xcoff_swap_sym_in
129 #define coff_SWAP_sym_out _bfd_xcoff_swap_sym_out
130 #define coff_SWAP_aux_in _bfd_xcoff_swap_aux_in
131 #define coff_SWAP_aux_out _bfd_xcoff_swap_aux_out
132 #define coff_swap_reloc_in xcoff_swap_reloc_in
133 #define coff_swap_reloc_out xcoff_swap_reloc_out
134 #define NO_COFF_RELOCS
136 #ifndef bfd_pe_print_pdata
137 #define bfd_pe_print_pdata NULL
140 #include "coffcode.h"
142 /* The main body of code is in coffcode.h. */
144 static const char *normalize_filename
146 static bfd_boolean xcoff_write_armap_old
147 PARAMS ((bfd
*, unsigned int, struct orl
*, unsigned int, int));
148 static bfd_boolean xcoff_write_armap_big
149 PARAMS ((bfd
*, unsigned int, struct orl
*, unsigned int, int));
150 static bfd_boolean xcoff_write_archive_contents_old
152 static bfd_boolean xcoff_write_archive_contents_big
154 static void xcoff_swap_ldhdr_in
155 PARAMS ((bfd
*, const PTR
, struct internal_ldhdr
*));
156 static void xcoff_swap_ldhdr_out
157 PARAMS ((bfd
*, const struct internal_ldhdr
*, PTR
));
158 static void xcoff_swap_ldsym_in
159 PARAMS ((bfd
*, const PTR
, struct internal_ldsym
*));
160 static void xcoff_swap_ldsym_out
161 PARAMS ((bfd
*, const struct internal_ldsym
*, PTR
));
162 static void xcoff_swap_ldrel_in
163 PARAMS ((bfd
*, const PTR
, struct internal_ldrel
*));
164 static void xcoff_swap_ldrel_out
165 PARAMS ((bfd
*, const struct internal_ldrel
*, PTR
));
166 static bfd_boolean xcoff_ppc_relocate_section
167 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
168 struct internal_reloc
*, struct internal_syment
*, asection
**));
169 static bfd_boolean _bfd_xcoff_put_ldsymbol_name
170 PARAMS ((bfd
*, struct xcoff_loader_info
*, struct internal_ldsym
*,
172 static asection
*xcoff_create_csect_from_smclas
173 PARAMS ((bfd
*, union internal_auxent
*, const char *));
174 static bfd_boolean xcoff_is_lineno_count_overflow
175 PARAMS ((bfd
*, bfd_vma
));
176 static bfd_boolean xcoff_is_reloc_count_overflow
177 PARAMS ((bfd
*, bfd_vma
));
178 static bfd_vma xcoff_loader_symbol_offset
179 PARAMS ((bfd
*, struct internal_ldhdr
*));
180 static bfd_vma xcoff_loader_reloc_offset
181 PARAMS ((bfd
*, struct internal_ldhdr
*));
182 static bfd_boolean xcoff_generate_rtinit
183 PARAMS ((bfd
*, const char *, const char *, bfd_boolean
));
184 static bfd_boolean do_pad
185 PARAMS ((bfd
*, unsigned int));
186 static bfd_boolean do_copy
187 PARAMS ((bfd
*, bfd
*));
189 /* Relocation functions */
190 static bfd_boolean xcoff_reloc_type_br
191 PARAMS ((XCOFF_RELOC_FUNCTION_ARGS
));
193 static bfd_boolean xcoff_complain_overflow_dont_func
194 PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS
));
195 static bfd_boolean xcoff_complain_overflow_bitfield_func
196 PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS
));
197 static bfd_boolean xcoff_complain_overflow_signed_func
198 PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS
));
199 static bfd_boolean xcoff_complain_overflow_unsigned_func
200 PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS
));
202 bfd_boolean (*xcoff_calculate_relocation
[XCOFF_MAX_CALCULATE_RELOCATION
])
203 PARAMS ((XCOFF_RELOC_FUNCTION_ARGS
)) =
205 xcoff_reloc_type_pos
, /* R_POS (0x00) */
206 xcoff_reloc_type_neg
, /* R_NEG (0x01) */
207 xcoff_reloc_type_rel
, /* R_REL (0x02) */
208 xcoff_reloc_type_toc
, /* R_TOC (0x03) */
209 xcoff_reloc_type_fail
, /* R_RTB (0x04) */
210 xcoff_reloc_type_toc
, /* R_GL (0x05) */
211 xcoff_reloc_type_toc
, /* R_TCL (0x06) */
212 xcoff_reloc_type_fail
, /* (0x07) */
213 xcoff_reloc_type_ba
, /* R_BA (0x08) */
214 xcoff_reloc_type_fail
, /* (0x09) */
215 xcoff_reloc_type_br
, /* R_BR (0x0a) */
216 xcoff_reloc_type_fail
, /* (0x0b) */
217 xcoff_reloc_type_pos
, /* R_RL (0x0c) */
218 xcoff_reloc_type_pos
, /* R_RLA (0x0d) */
219 xcoff_reloc_type_fail
, /* (0x0e) */
220 xcoff_reloc_type_noop
, /* R_REF (0x0f) */
221 xcoff_reloc_type_fail
, /* (0x10) */
222 xcoff_reloc_type_fail
, /* (0x11) */
223 xcoff_reloc_type_toc
, /* R_TRL (0x12) */
224 xcoff_reloc_type_toc
, /* R_TRLA (0x13) */
225 xcoff_reloc_type_fail
, /* R_RRTBI (0x14) */
226 xcoff_reloc_type_fail
, /* R_RRTBA (0x15) */
227 xcoff_reloc_type_ba
, /* R_CAI (0x16) */
228 xcoff_reloc_type_crel
, /* R_CREL (0x17) */
229 xcoff_reloc_type_ba
, /* R_RBA (0x18) */
230 xcoff_reloc_type_ba
, /* R_RBAC (0x19) */
231 xcoff_reloc_type_br
, /* R_RBR (0x1a) */
232 xcoff_reloc_type_ba
, /* R_RBRC (0x1b) */
235 bfd_boolean (*xcoff_complain_overflow
[XCOFF_MAX_COMPLAIN_OVERFLOW
])
236 PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS
)) =
238 xcoff_complain_overflow_dont_func
,
239 xcoff_complain_overflow_bitfield_func
,
240 xcoff_complain_overflow_signed_func
,
241 xcoff_complain_overflow_unsigned_func
,
244 /* Information about one member of an archive. */
245 struct member_layout
{
246 /* The archive member that this structure describes. */
249 /* The number of bytes of padding that must be inserted before the
250 start of the member in order to ensure that the section contents
251 are correctly aligned. */
252 unsigned int leading_padding
;
254 /* The offset of MEMBER from the start of the archive (i.e. the end
255 of the leading padding). */
258 /* The normalized name of MEMBER. */
261 /* The length of NAME, without padding. */
262 bfd_size_type namlen
;
264 /* The length of NAME, with padding. */
265 bfd_size_type padded_namlen
;
267 /* The size of MEMBER's header, including the name and magic sequence. */
268 bfd_size_type header_size
;
270 /* The size of the MEMBER's contents. */
271 bfd_size_type contents_size
;
273 /* The number of bytes of padding that must be inserted after MEMBER
274 in order to preserve even alignment. */
275 bfd_size_type trailing_padding
;
278 /* A structure used for iterating over the members of an archive. */
279 struct archive_iterator
{
280 /* The archive itself. */
283 /* Information about the current archive member. */
284 struct member_layout current
;
286 /* Information about the next archive member. MEMBER is null if there
287 are no more archive members, in which case OFFSET is the offset of
288 the first unused byte. */
289 struct member_layout next
;
292 /* Initialize INFO so that it describes member MEMBER of archive ARCHIVE.
293 OFFSET is the even-padded offset of MEMBER, not including any leading
294 padding needed for section alignment. */
297 member_layout_init (struct member_layout
*info
, bfd
*archive
,
298 bfd
*member
, file_ptr offset
)
300 info
->member
= member
;
301 info
->leading_padding
= 0;
304 info
->name
= normalize_filename (member
);
305 info
->namlen
= strlen (info
->name
);
306 info
->padded_namlen
= info
->namlen
+ (info
->namlen
& 1);
307 if (xcoff_big_format_p (archive
))
308 info
->header_size
= SIZEOF_AR_HDR_BIG
;
310 info
->header_size
= SIZEOF_AR_HDR
;
311 info
->header_size
+= info
->padded_namlen
+ SXCOFFARFMAG
;
312 info
->contents_size
= arelt_size (member
);
313 info
->trailing_padding
= info
->contents_size
& 1;
315 if (bfd_check_format (member
, bfd_object
)
316 && bfd_get_flavour (member
) == bfd_target_xcoff_flavour
317 && (member
->flags
& DYNAMIC
) != 0)
318 info
->leading_padding
319 = (-(offset
+ info
->header_size
)
320 & ((1 << bfd_xcoff_text_align_power (member
)) - 1));
322 info
->offset
= offset
+ info
->leading_padding
;
325 /* Set up ITERATOR to iterate through archive ARCHIVE. */
328 archive_iterator_begin (struct archive_iterator
*iterator
,
331 iterator
->archive
= archive
;
332 member_layout_init (&iterator
->next
, archive
, archive
->archive_head
,
333 xcoff_big_format_p (archive
)
334 ? SIZEOF_AR_FILE_HDR_BIG
335 : SIZEOF_AR_FILE_HDR
);
338 /* Make ITERATOR visit the first unvisited archive member. Return true
339 on success; return false if all members have been visited. */
342 archive_iterator_next (struct archive_iterator
*iterator
)
344 if (!iterator
->next
.member
)
347 iterator
->current
= iterator
->next
;
348 member_layout_init (&iterator
->next
, iterator
->archive
,
349 iterator
->current
.member
->archive_next
,
350 iterator
->current
.offset
351 + iterator
->current
.header_size
352 + iterator
->current
.contents_size
353 + iterator
->current
.trailing_padding
);
357 /* We use our own tdata type. Its first field is the COFF tdata type,
358 so the COFF routines are compatible. */
361 _bfd_xcoff_mkobject (abfd
)
364 coff_data_type
*coff
;
365 bfd_size_type amt
= sizeof (struct xcoff_tdata
);
367 abfd
->tdata
.xcoff_obj_data
= (struct xcoff_tdata
*) bfd_zalloc (abfd
, amt
);
368 if (abfd
->tdata
.xcoff_obj_data
== NULL
)
370 coff
= coff_data (abfd
);
371 coff
->symbols
= (coff_symbol_type
*) NULL
;
372 coff
->conversion_table
= (unsigned int *) NULL
;
373 coff
->raw_syments
= (struct coff_ptr_struct
*) NULL
;
376 xcoff_data (abfd
)->modtype
= ('1' << 8) | 'L';
378 /* We set cputype to -1 to indicate that it has not been
380 xcoff_data (abfd
)->cputype
= -1;
382 xcoff_data (abfd
)->csects
= NULL
;
383 xcoff_data (abfd
)->debug_indices
= NULL
;
385 /* text section alignment is different than the default */
386 bfd_xcoff_text_align_power (abfd
) = 2;
391 /* Copy XCOFF data from one BFD to another. */
394 _bfd_xcoff_copy_private_bfd_data (ibfd
, obfd
)
398 struct xcoff_tdata
*ix
, *ox
;
401 if (ibfd
->xvec
!= obfd
->xvec
)
403 ix
= xcoff_data (ibfd
);
404 ox
= xcoff_data (obfd
);
405 ox
->full_aouthdr
= ix
->full_aouthdr
;
411 sec
= coff_section_from_bfd_index (ibfd
, ix
->sntoc
);
415 ox
->sntoc
= sec
->output_section
->target_index
;
417 if (ix
->snentry
== 0)
421 sec
= coff_section_from_bfd_index (ibfd
, ix
->snentry
);
425 ox
->snentry
= sec
->output_section
->target_index
;
427 bfd_xcoff_text_align_power (obfd
) = bfd_xcoff_text_align_power (ibfd
);
428 bfd_xcoff_data_align_power (obfd
) = bfd_xcoff_data_align_power (ibfd
);
429 ox
->modtype
= ix
->modtype
;
430 ox
->cputype
= ix
->cputype
;
431 ox
->maxdata
= ix
->maxdata
;
432 ox
->maxstack
= ix
->maxstack
;
436 /* I don't think XCOFF really has a notion of local labels based on
437 name. This will mean that ld -X doesn't actually strip anything.
438 The AIX native linker does not have a -X option, and it ignores the
442 _bfd_xcoff_is_local_label_name (abfd
, name
)
443 bfd
*abfd ATTRIBUTE_UNUSED
;
444 const char *name ATTRIBUTE_UNUSED
;
450 _bfd_xcoff_swap_sym_in (abfd
, ext1
, in1
)
455 SYMENT
*ext
= (SYMENT
*)ext1
;
456 struct internal_syment
* in
= (struct internal_syment
*)in1
;
458 if (ext
->e
.e_name
[0] != 0)
460 memcpy (in
->_n
._n_name
, ext
->e
.e_name
, SYMNMLEN
);
464 in
->_n
._n_n
._n_zeroes
= 0;
465 in
->_n
._n_n
._n_offset
= H_GET_32 (abfd
, ext
->e
.e
.e_offset
);
468 in
->n_value
= H_GET_32 (abfd
, ext
->e_value
);
469 in
->n_scnum
= H_GET_16 (abfd
, ext
->e_scnum
);
470 in
->n_type
= H_GET_16 (abfd
, ext
->e_type
);
471 in
->n_sclass
= H_GET_8 (abfd
, ext
->e_sclass
);
472 in
->n_numaux
= H_GET_8 (abfd
, ext
->e_numaux
);
476 _bfd_xcoff_swap_sym_out (abfd
, inp
, extp
)
481 struct internal_syment
*in
= (struct internal_syment
*)inp
;
482 SYMENT
*ext
=(SYMENT
*)extp
;
484 if (in
->_n
._n_name
[0] != 0)
486 memcpy (ext
->e
.e_name
, in
->_n
._n_name
, SYMNMLEN
);
490 H_PUT_32 (abfd
, 0, ext
->e
.e
.e_zeroes
);
491 H_PUT_32 (abfd
, in
->_n
._n_n
._n_offset
, ext
->e
.e
.e_offset
);
494 H_PUT_32 (abfd
, in
->n_value
, ext
->e_value
);
495 H_PUT_16 (abfd
, in
->n_scnum
, ext
->e_scnum
);
496 H_PUT_16 (abfd
, in
->n_type
, ext
->e_type
);
497 H_PUT_8 (abfd
, in
->n_sclass
, ext
->e_sclass
);
498 H_PUT_8 (abfd
, in
->n_numaux
, ext
->e_numaux
);
499 return bfd_coff_symesz (abfd
);
503 _bfd_xcoff_swap_aux_in (abfd
, ext1
, type
, in_class
, indx
, numaux
, in1
)
512 AUXENT
* ext
= (AUXENT
*)ext1
;
513 union internal_auxent
*in
= (union internal_auxent
*)in1
;
518 if (ext
->x_file
.x_fname
[0] == 0)
520 in
->x_file
.x_n
.x_zeroes
= 0;
521 in
->x_file
.x_n
.x_offset
=
522 H_GET_32 (abfd
, ext
->x_file
.x_n
.x_offset
);
529 memcpy (in
->x_file
.x_fname
, ext
->x_file
.x_fname
,
530 numaux
* sizeof (AUXENT
));
534 memcpy (in
->x_file
.x_fname
, ext
->x_file
.x_fname
, FILNMLEN
);
539 /* RS/6000 "csect" auxents */
543 if (indx
+ 1 == numaux
)
545 in
->x_csect
.x_scnlen
.l
= H_GET_32 (abfd
, ext
->x_csect
.x_scnlen
);
546 in
->x_csect
.x_parmhash
= H_GET_32 (abfd
, ext
->x_csect
.x_parmhash
);
547 in
->x_csect
.x_snhash
= H_GET_16 (abfd
, ext
->x_csect
.x_snhash
);
548 /* We don't have to hack bitfields in x_smtyp because it's
549 defined by shifts-and-ands, which are equivalent on all
551 in
->x_csect
.x_smtyp
= H_GET_8 (abfd
, ext
->x_csect
.x_smtyp
);
552 in
->x_csect
.x_smclas
= H_GET_8 (abfd
, ext
->x_csect
.x_smclas
);
553 in
->x_csect
.x_stab
= H_GET_32 (abfd
, ext
->x_csect
.x_stab
);
554 in
->x_csect
.x_snstab
= H_GET_16 (abfd
, ext
->x_csect
.x_snstab
);
564 in
->x_scn
.x_scnlen
= H_GET_32 (abfd
, ext
->x_scn
.x_scnlen
);
565 in
->x_scn
.x_nreloc
= H_GET_16 (abfd
, ext
->x_scn
.x_nreloc
);
566 in
->x_scn
.x_nlinno
= H_GET_16 (abfd
, ext
->x_scn
.x_nlinno
);
567 /* PE defines some extra fields; we zero them out for
569 in
->x_scn
.x_checksum
= 0;
570 in
->x_scn
.x_associated
= 0;
571 in
->x_scn
.x_comdat
= 0;
578 in
->x_sym
.x_tagndx
.l
= H_GET_32 (abfd
, ext
->x_sym
.x_tagndx
);
579 in
->x_sym
.x_tvndx
= H_GET_16 (abfd
, ext
->x_sym
.x_tvndx
);
581 if (in_class
== C_BLOCK
|| in_class
== C_FCN
|| ISFCN (type
)
584 in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
=
585 H_GET_32 (abfd
, ext
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
586 in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
=
587 H_GET_32 (abfd
, ext
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
591 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0] =
592 H_GET_16 (abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
593 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1] =
594 H_GET_16 (abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
595 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2] =
596 H_GET_16 (abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
597 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3] =
598 H_GET_16 (abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
603 in
->x_sym
.x_misc
.x_fsize
= H_GET_32 (abfd
, ext
->x_sym
.x_misc
.x_fsize
);
607 in
->x_sym
.x_misc
.x_lnsz
.x_lnno
=
608 H_GET_16 (abfd
, ext
->x_sym
.x_misc
.x_lnsz
.x_lnno
);
609 in
->x_sym
.x_misc
.x_lnsz
.x_size
=
610 H_GET_16 (abfd
, ext
->x_sym
.x_misc
.x_lnsz
.x_size
);
614 /* The semicolon is because MSVC doesn't like labels at
619 unsigned int _bfd_xcoff_swap_aux_out
620 PARAMS ((bfd
*, PTR
, int, int, int, int, PTR
));
623 _bfd_xcoff_swap_aux_out (abfd
, inp
, type
, in_class
, indx
, numaux
, extp
)
628 int indx ATTRIBUTE_UNUSED
;
629 int numaux ATTRIBUTE_UNUSED
;
632 union internal_auxent
*in
= (union internal_auxent
*)inp
;
633 AUXENT
*ext
= (AUXENT
*)extp
;
635 memset ((PTR
)ext
, 0, bfd_coff_auxesz (abfd
));
639 if (in
->x_file
.x_fname
[0] == 0)
641 H_PUT_32 (abfd
, 0, ext
->x_file
.x_n
.x_zeroes
);
642 H_PUT_32 (abfd
, in
->x_file
.x_n
.x_offset
, ext
->x_file
.x_n
.x_offset
);
646 memcpy (ext
->x_file
.x_fname
, in
->x_file
.x_fname
, FILNMLEN
);
650 /* RS/6000 "csect" auxents */
654 if (indx
+ 1 == numaux
)
656 H_PUT_32 (abfd
, in
->x_csect
.x_scnlen
.l
, ext
->x_csect
.x_scnlen
);
657 H_PUT_32 (abfd
, in
->x_csect
.x_parmhash
, ext
->x_csect
.x_parmhash
);
658 H_PUT_16 (abfd
, in
->x_csect
.x_snhash
, ext
->x_csect
.x_snhash
);
659 /* We don't have to hack bitfields in x_smtyp because it's
660 defined by shifts-and-ands, which are equivalent on all
662 H_PUT_8 (abfd
, in
->x_csect
.x_smtyp
, ext
->x_csect
.x_smtyp
);
663 H_PUT_8 (abfd
, in
->x_csect
.x_smclas
, ext
->x_csect
.x_smclas
);
664 H_PUT_32 (abfd
, in
->x_csect
.x_stab
, ext
->x_csect
.x_stab
);
665 H_PUT_16 (abfd
, in
->x_csect
.x_snstab
, ext
->x_csect
.x_snstab
);
675 H_PUT_32 (abfd
, in
->x_scn
.x_scnlen
, ext
->x_scn
.x_scnlen
);
676 H_PUT_16 (abfd
, in
->x_scn
.x_nreloc
, ext
->x_scn
.x_nreloc
);
677 H_PUT_16 (abfd
, in
->x_scn
.x_nlinno
, ext
->x_scn
.x_nlinno
);
683 H_PUT_32 (abfd
, in
->x_sym
.x_tagndx
.l
, ext
->x_sym
.x_tagndx
);
684 H_PUT_16 (abfd
, in
->x_sym
.x_tvndx
, ext
->x_sym
.x_tvndx
);
686 if (in_class
== C_BLOCK
|| in_class
== C_FCN
|| ISFCN (type
)
689 H_PUT_32 (abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
,
690 ext
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
691 H_PUT_32 (abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
,
692 ext
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
696 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0],
697 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
698 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1],
699 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
700 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2],
701 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
702 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3],
703 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
707 H_PUT_32 (abfd
, in
->x_sym
.x_misc
.x_fsize
, ext
->x_sym
.x_misc
.x_fsize
);
710 H_PUT_16 (abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_lnno
,
711 ext
->x_sym
.x_misc
.x_lnsz
.x_lnno
);
712 H_PUT_16 (abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_size
,
713 ext
->x_sym
.x_misc
.x_lnsz
.x_size
);
717 return bfd_coff_auxesz (abfd
);
722 /* The XCOFF reloc table. Actually, XCOFF relocations specify the
723 bitsize and whether they are signed or not, along with a
724 conventional type. This table is for the types, which are used for
725 different algorithms for putting in the reloc. Many of these
726 relocs need special_function entries, which I have not written. */
729 reloc_howto_type xcoff_howto_table
[] =
731 /* Standard 32 bit relocation. */
732 HOWTO (R_POS
, /* type */
734 2, /* size (0 = byte, 1 = short, 2 = long) */
736 FALSE
, /* pc_relative */
738 complain_overflow_bitfield
, /* complain_on_overflow */
739 0, /* special_function */
741 TRUE
, /* partial_inplace */
742 0xffffffff, /* src_mask */
743 0xffffffff, /* dst_mask */
744 FALSE
), /* pcrel_offset */
746 /* 32 bit relocation, but store negative value. */
747 HOWTO (R_NEG
, /* type */
749 -2, /* size (0 = byte, 1 = short, 2 = long) */
751 FALSE
, /* pc_relative */
753 complain_overflow_bitfield
, /* complain_on_overflow */
754 0, /* special_function */
756 TRUE
, /* partial_inplace */
757 0xffffffff, /* src_mask */
758 0xffffffff, /* dst_mask */
759 FALSE
), /* pcrel_offset */
761 /* 32 bit PC relative relocation. */
762 HOWTO (R_REL
, /* type */
764 2, /* size (0 = byte, 1 = short, 2 = long) */
766 TRUE
, /* pc_relative */
768 complain_overflow_signed
, /* complain_on_overflow */
769 0, /* special_function */
771 TRUE
, /* partial_inplace */
772 0xffffffff, /* src_mask */
773 0xffffffff, /* dst_mask */
774 FALSE
), /* pcrel_offset */
776 /* 16 bit TOC relative relocation. */
777 HOWTO (R_TOC
, /* type */
779 1, /* size (0 = byte, 1 = short, 2 = long) */
781 FALSE
, /* pc_relative */
783 complain_overflow_bitfield
, /* complain_on_overflow */
784 0, /* special_function */
786 TRUE
, /* partial_inplace */
787 0xffff, /* src_mask */
788 0xffff, /* dst_mask */
789 FALSE
), /* pcrel_offset */
791 /* I don't really know what this is. */
792 HOWTO (R_RTB
, /* type */
794 2, /* size (0 = byte, 1 = short, 2 = long) */
796 FALSE
, /* pc_relative */
798 complain_overflow_bitfield
, /* complain_on_overflow */
799 0, /* special_function */
801 TRUE
, /* partial_inplace */
802 0xffffffff, /* src_mask */
803 0xffffffff, /* dst_mask */
804 FALSE
), /* pcrel_offset */
806 /* External TOC relative symbol. */
807 HOWTO (R_GL
, /* type */
809 1, /* size (0 = byte, 1 = short, 2 = long) */
811 FALSE
, /* pc_relative */
813 complain_overflow_bitfield
, /* complain_on_overflow */
814 0, /* special_function */
816 TRUE
, /* partial_inplace */
817 0xffff, /* src_mask */
818 0xffff, /* dst_mask */
819 FALSE
), /* pcrel_offset */
821 /* Local TOC relative symbol. */
822 HOWTO (R_TCL
, /* type */
824 1, /* size (0 = byte, 1 = short, 2 = long) */
826 FALSE
, /* pc_relative */
828 complain_overflow_bitfield
, /* complain_on_overflow */
829 0, /* special_function */
831 TRUE
, /* partial_inplace */
832 0xffff, /* src_mask */
833 0xffff, /* dst_mask */
834 FALSE
), /* pcrel_offset */
838 /* Non modifiable absolute branch. */
839 HOWTO (R_BA
, /* type */
841 2, /* size (0 = byte, 1 = short, 2 = long) */
843 FALSE
, /* pc_relative */
845 complain_overflow_bitfield
, /* complain_on_overflow */
846 0, /* special_function */
847 "R_BA_26", /* name */
848 TRUE
, /* partial_inplace */
849 0x03fffffc, /* src_mask */
850 0x03fffffc, /* dst_mask */
851 FALSE
), /* pcrel_offset */
855 /* Non modifiable relative branch. */
856 HOWTO (R_BR
, /* type */
858 2, /* size (0 = byte, 1 = short, 2 = long) */
860 TRUE
, /* pc_relative */
862 complain_overflow_signed
, /* complain_on_overflow */
863 0, /* special_function */
865 TRUE
, /* partial_inplace */
866 0x03fffffc, /* src_mask */
867 0x03fffffc, /* dst_mask */
868 FALSE
), /* pcrel_offset */
873 HOWTO (R_RL
, /* type */
875 1, /* size (0 = byte, 1 = short, 2 = long) */
877 FALSE
, /* pc_relative */
879 complain_overflow_bitfield
, /* complain_on_overflow */
880 0, /* special_function */
882 TRUE
, /* partial_inplace */
883 0xffff, /* src_mask */
884 0xffff, /* dst_mask */
885 FALSE
), /* pcrel_offset */
888 HOWTO (R_RLA
, /* type */
890 1, /* size (0 = byte, 1 = short, 2 = long) */
892 FALSE
, /* pc_relative */
894 complain_overflow_bitfield
, /* complain_on_overflow */
895 0, /* special_function */
897 TRUE
, /* partial_inplace */
898 0xffff, /* src_mask */
899 0xffff, /* dst_mask */
900 FALSE
), /* pcrel_offset */
904 /* Non-relocating reference. Bitsize is 1 so that r_rsize is 0. */
905 HOWTO (R_REF
, /* type */
907 0, /* size (0 = byte, 1 = short, 2 = long) */
909 FALSE
, /* pc_relative */
911 complain_overflow_dont
, /* complain_on_overflow */
912 0, /* special_function */
914 FALSE
, /* partial_inplace */
917 FALSE
), /* pcrel_offset */
922 /* TOC relative indirect load. */
923 HOWTO (R_TRL
, /* type */
925 1, /* size (0 = byte, 1 = short, 2 = long) */
927 FALSE
, /* pc_relative */
929 complain_overflow_bitfield
, /* complain_on_overflow */
930 0, /* special_function */
932 TRUE
, /* partial_inplace */
933 0xffff, /* src_mask */
934 0xffff, /* dst_mask */
935 FALSE
), /* pcrel_offset */
937 /* TOC relative load address. */
938 HOWTO (R_TRLA
, /* type */
940 1, /* size (0 = byte, 1 = short, 2 = long) */
942 FALSE
, /* pc_relative */
944 complain_overflow_bitfield
, /* complain_on_overflow */
945 0, /* special_function */
947 TRUE
, /* partial_inplace */
948 0xffff, /* src_mask */
949 0xffff, /* dst_mask */
950 FALSE
), /* pcrel_offset */
952 /* Modifiable relative branch. */
953 HOWTO (R_RRTBI
, /* type */
955 2, /* size (0 = byte, 1 = short, 2 = long) */
957 FALSE
, /* pc_relative */
959 complain_overflow_bitfield
, /* complain_on_overflow */
960 0, /* special_function */
961 "R_RRTBI", /* name */
962 TRUE
, /* partial_inplace */
963 0xffffffff, /* src_mask */
964 0xffffffff, /* dst_mask */
965 FALSE
), /* pcrel_offset */
967 /* Modifiable absolute branch. */
968 HOWTO (R_RRTBA
, /* type */
970 2, /* size (0 = byte, 1 = short, 2 = long) */
972 FALSE
, /* pc_relative */
974 complain_overflow_bitfield
, /* complain_on_overflow */
975 0, /* special_function */
976 "R_RRTBA", /* name */
977 TRUE
, /* partial_inplace */
978 0xffffffff, /* src_mask */
979 0xffffffff, /* dst_mask */
980 FALSE
), /* pcrel_offset */
982 /* Modifiable call absolute indirect. */
983 HOWTO (R_CAI
, /* type */
985 1, /* size (0 = byte, 1 = short, 2 = long) */
987 FALSE
, /* pc_relative */
989 complain_overflow_bitfield
, /* complain_on_overflow */
990 0, /* special_function */
992 TRUE
, /* partial_inplace */
993 0xffff, /* src_mask */
994 0xffff, /* dst_mask */
995 FALSE
), /* pcrel_offset */
997 /* Modifiable call relative. */
998 HOWTO (R_CREL
, /* type */
1000 1, /* size (0 = byte, 1 = short, 2 = long) */
1002 FALSE
, /* pc_relative */
1004 complain_overflow_bitfield
, /* complain_on_overflow */
1005 0, /* special_function */
1006 "R_CREL", /* name */
1007 TRUE
, /* partial_inplace */
1008 0xffff, /* src_mask */
1009 0xffff, /* dst_mask */
1010 FALSE
), /* pcrel_offset */
1012 /* Modifiable branch absolute. */
1013 HOWTO (R_RBA
, /* type */
1015 2, /* size (0 = byte, 1 = short, 2 = long) */
1017 FALSE
, /* pc_relative */
1019 complain_overflow_bitfield
, /* complain_on_overflow */
1020 0, /* special_function */
1022 TRUE
, /* partial_inplace */
1023 0x03fffffc, /* src_mask */
1024 0x03fffffc, /* dst_mask */
1025 FALSE
), /* pcrel_offset */
1027 /* Modifiable branch absolute. */
1028 HOWTO (R_RBAC
, /* type */
1030 2, /* size (0 = byte, 1 = short, 2 = long) */
1032 FALSE
, /* pc_relative */
1034 complain_overflow_bitfield
, /* complain_on_overflow */
1035 0, /* special_function */
1036 "R_RBAC", /* name */
1037 TRUE
, /* partial_inplace */
1038 0xffffffff, /* src_mask */
1039 0xffffffff, /* dst_mask */
1040 FALSE
), /* pcrel_offset */
1042 /* Modifiable branch relative. */
1043 HOWTO (R_RBR
, /* type */
1045 2, /* size (0 = byte, 1 = short, 2 = long) */
1047 FALSE
, /* pc_relative */
1049 complain_overflow_signed
, /* complain_on_overflow */
1050 0, /* special_function */
1051 "R_RBR_26", /* name */
1052 TRUE
, /* partial_inplace */
1053 0x03fffffc, /* src_mask */
1054 0x03fffffc, /* dst_mask */
1055 FALSE
), /* pcrel_offset */
1057 /* Modifiable branch absolute. */
1058 HOWTO (R_RBRC
, /* type */
1060 1, /* size (0 = byte, 1 = short, 2 = long) */
1062 FALSE
, /* pc_relative */
1064 complain_overflow_bitfield
, /* complain_on_overflow */
1065 0, /* special_function */
1066 "R_RBRC", /* name */
1067 TRUE
, /* partial_inplace */
1068 0xffff, /* src_mask */
1069 0xffff, /* dst_mask */
1070 FALSE
), /* pcrel_offset */
1072 /* 16 bit Non modifiable absolute branch. */
1073 HOWTO (R_BA
, /* type */
1075 1, /* size (0 = byte, 1 = short, 2 = long) */
1077 FALSE
, /* pc_relative */
1079 complain_overflow_bitfield
, /* complain_on_overflow */
1080 0, /* special_function */
1081 "R_BA_16", /* name */
1082 TRUE
, /* partial_inplace */
1083 0xfffc, /* src_mask */
1084 0xfffc, /* dst_mask */
1085 FALSE
), /* pcrel_offset */
1087 /* Modifiable branch relative. */
1088 HOWTO (R_RBR
, /* type */
1090 1, /* size (0 = byte, 1 = short, 2 = long) */
1092 FALSE
, /* pc_relative */
1094 complain_overflow_signed
, /* complain_on_overflow */
1095 0, /* special_function */
1096 "R_RBR_16", /* name */
1097 TRUE
, /* partial_inplace */
1098 0xffff, /* src_mask */
1099 0xffff, /* dst_mask */
1100 FALSE
), /* pcrel_offset */
1102 /* Modifiable branch relative. */
1103 HOWTO (R_RBA
, /* type */
1105 1, /* size (0 = byte, 1 = short, 2 = long) */
1107 FALSE
, /* pc_relative */
1109 complain_overflow_signed
, /* complain_on_overflow */
1110 0, /* special_function */
1111 "R_RBA_16", /* name */
1112 TRUE
, /* partial_inplace */
1113 0xffff, /* src_mask */
1114 0xffff, /* dst_mask */
1115 FALSE
), /* pcrel_offset */
1120 xcoff_rtype2howto (relent
, internal
)
1122 struct internal_reloc
*internal
;
1124 if (internal
->r_type
> R_RBRC
)
1127 /* Default howto layout works most of the time */
1128 relent
->howto
= &xcoff_howto_table
[internal
->r_type
];
1130 /* Special case some 16 bit reloc */
1131 if (15 == (internal
->r_size
& 0x1f))
1133 if (R_BA
== internal
->r_type
)
1134 relent
->howto
= &xcoff_howto_table
[0x1c];
1135 else if (R_RBR
== internal
->r_type
)
1136 relent
->howto
= &xcoff_howto_table
[0x1d];
1137 else if (R_RBA
== internal
->r_type
)
1138 relent
->howto
= &xcoff_howto_table
[0x1e];
1141 /* The r_size field of an XCOFF reloc encodes the bitsize of the
1142 relocation, as well as indicating whether it is signed or not.
1143 Doublecheck that the relocation information gathered from the
1144 type matches this information. The bitsize is not significant
1145 for R_REF relocs. */
1146 if (relent
->howto
->dst_mask
!= 0
1147 && (relent
->howto
->bitsize
1148 != ((unsigned int) internal
->r_size
& 0x1f) + 1))
1153 _bfd_xcoff_reloc_type_lookup (abfd
, code
)
1154 bfd
*abfd ATTRIBUTE_UNUSED
;
1155 bfd_reloc_code_real_type code
;
1159 case BFD_RELOC_PPC_B26
:
1160 return &xcoff_howto_table
[0xa];
1161 case BFD_RELOC_PPC_BA16
:
1162 return &xcoff_howto_table
[0x1c];
1163 case BFD_RELOC_PPC_BA26
:
1164 return &xcoff_howto_table
[8];
1165 case BFD_RELOC_PPC_TOC16
:
1166 return &xcoff_howto_table
[3];
1168 case BFD_RELOC_CTOR
:
1169 return &xcoff_howto_table
[0];
1170 case BFD_RELOC_NONE
:
1171 return &xcoff_howto_table
[0xf];
1177 static reloc_howto_type
*
1178 _bfd_xcoff_reloc_name_lookup (bfd
*abfd ATTRIBUTE_UNUSED
,
1184 i
< sizeof (xcoff_howto_table
) / sizeof (xcoff_howto_table
[0]);
1186 if (xcoff_howto_table
[i
].name
!= NULL
1187 && strcasecmp (xcoff_howto_table
[i
].name
, r_name
) == 0)
1188 return &xcoff_howto_table
[i
];
1193 /* XCOFF archive support. The original version of this code was by
1194 Damon A. Permezel. It was enhanced to permit cross support, and
1195 writing archive files, by Ian Lance Taylor, Cygnus Support.
1197 XCOFF uses its own archive format. Everything is hooked together
1198 with file offset links, so it is possible to rapidly update an
1199 archive in place. Of course, we don't do that. An XCOFF archive
1200 has a real file header, not just an ARMAG string. The structure of
1201 the file header and of each archive header appear below.
1203 An XCOFF archive also has a member table, which is a list of
1204 elements in the archive (you can get that by looking through the
1205 linked list, but you have to read a lot more of the file). The
1206 member table has a normal archive header with an empty name. It is
1207 normally (and perhaps must be) the second to last entry in the
1208 archive. The member table data is almost printable ASCII. It
1209 starts with a 12 character decimal string which is the number of
1210 entries in the table. For each entry it has a 12 character decimal
1211 string which is the offset in the archive of that member. These
1212 entries are followed by a series of null terminated strings which
1213 are the member names for each entry.
1215 Finally, an XCOFF archive has a global symbol table, which is what
1216 we call the armap. The global symbol table has a normal archive
1217 header with an empty name. It is normally (and perhaps must be)
1218 the last entry in the archive. The contents start with a four byte
1219 binary number which is the number of entries. This is followed by
1220 a that many four byte binary numbers; each is the file offset of an
1221 entry in the archive. These numbers are followed by a series of
1222 null terminated strings, which are symbol names.
1224 AIX 4.3 introduced a new archive format which can handle larger
1225 files and also 32- and 64-bit objects in the same archive. The
1226 things said above remain true except that there is now more than
1227 one global symbol table. The one is used to index 32-bit objects,
1228 the other for 64-bit objects.
1230 The new archives (recognizable by the new ARMAG string) has larger
1231 field lengths so that we cannot really share any code. Also we have
1232 to take care that we are not generating the new form of archives
1233 on AIX 4.2 or earlier systems. */
1235 /* XCOFF archives use this as a magic string. Note that both strings
1236 have the same length. */
1238 /* Set the magic for archive. */
1241 bfd_xcoff_ar_archive_set_magic (abfd
, magic
)
1242 bfd
*abfd ATTRIBUTE_UNUSED
;
1243 char *magic ATTRIBUTE_UNUSED
;
1245 /* Not supported yet. */
1247 /* bfd_xcoff_archive_set_magic (abfd, magic); */
1250 /* Read in the armap of an XCOFF archive. */
1253 _bfd_xcoff_slurp_armap (abfd
)
1259 bfd_byte
*contents
, *cend
;
1264 if (xcoff_ardata (abfd
) == NULL
)
1266 bfd_has_map (abfd
) = FALSE
;
1270 if (! xcoff_big_format_p (abfd
))
1272 /* This is for the old format. */
1273 struct xcoff_ar_hdr hdr
;
1275 off
= strtol (xcoff_ardata (abfd
)->symoff
, (char **) NULL
, 10);
1278 bfd_has_map (abfd
) = FALSE
;
1282 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0)
1285 /* The symbol table starts with a normal archive header. */
1286 if (bfd_bread ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1290 /* Skip the name (normally empty). */
1291 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1292 off
= ((namlen
+ 1) & ~ (size_t) 1) + SXCOFFARFMAG
;
1293 if (bfd_seek (abfd
, off
, SEEK_CUR
) != 0)
1296 sz
= strtol (hdr
.size
, (char **) NULL
, 10);
1298 /* Read in the entire symbol table. */
1299 contents
= (bfd_byte
*) bfd_alloc (abfd
, sz
);
1300 if (contents
== NULL
)
1302 if (bfd_bread ((PTR
) contents
, sz
, abfd
) != sz
)
1305 /* The symbol table starts with a four byte count. */
1306 c
= H_GET_32 (abfd
, contents
);
1310 bfd_set_error (bfd_error_bad_value
);
1314 bfd_ardata (abfd
)->symdefs
=
1315 ((carsym
*) bfd_alloc (abfd
, c
* sizeof (carsym
)));
1316 if (bfd_ardata (abfd
)->symdefs
== NULL
)
1319 /* After the count comes a list of four byte file offsets. */
1320 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
, p
= contents
+ 4;
1322 ++i
, ++arsym
, p
+= 4)
1323 arsym
->file_offset
= H_GET_32 (abfd
, p
);
1327 /* This is for the new format. */
1328 struct xcoff_ar_hdr_big hdr
;
1330 off
= strtol (xcoff_ardata_big (abfd
)->symoff
, (char **) NULL
, 10);
1333 bfd_has_map (abfd
) = FALSE
;
1337 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0)
1340 /* The symbol table starts with a normal archive header. */
1341 if (bfd_bread ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR_BIG
, abfd
)
1342 != SIZEOF_AR_HDR_BIG
)
1345 /* Skip the name (normally empty). */
1346 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1347 off
= ((namlen
+ 1) & ~ (size_t) 1) + SXCOFFARFMAG
;
1348 if (bfd_seek (abfd
, off
, SEEK_CUR
) != 0)
1351 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1352 machines) since the field width is 20 and there numbers with more
1353 than 32 bits can be represented. */
1354 sz
= strtol (hdr
.size
, (char **) NULL
, 10);
1356 /* Read in the entire symbol table. */
1357 contents
= (bfd_byte
*) bfd_alloc (abfd
, sz
);
1358 if (contents
== NULL
)
1360 if (bfd_bread ((PTR
) contents
, sz
, abfd
) != sz
)
1363 /* The symbol table starts with an eight byte count. */
1364 c
= H_GET_64 (abfd
, contents
);
1368 bfd_set_error (bfd_error_bad_value
);
1372 bfd_ardata (abfd
)->symdefs
=
1373 ((carsym
*) bfd_alloc (abfd
, c
* sizeof (carsym
)));
1374 if (bfd_ardata (abfd
)->symdefs
== NULL
)
1377 /* After the count comes a list of eight byte file offsets. */
1378 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
, p
= contents
+ 8;
1380 ++i
, ++arsym
, p
+= 8)
1381 arsym
->file_offset
= H_GET_64 (abfd
, p
);
1384 /* After the file offsets come null terminated symbol names. */
1385 cend
= contents
+ sz
;
1386 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
;
1388 ++i
, ++arsym
, p
+= strlen ((char *) p
) + 1)
1392 bfd_set_error (bfd_error_bad_value
);
1395 arsym
->name
= (char *) p
;
1398 bfd_ardata (abfd
)->symdef_count
= c
;
1399 bfd_has_map (abfd
) = TRUE
;
1404 /* See if this is an XCOFF archive. */
1407 _bfd_xcoff_archive_p (abfd
)
1410 struct artdata
*tdata_hold
;
1411 char magic
[SXCOFFARMAG
];
1412 bfd_size_type amt
= SXCOFFARMAG
;
1414 if (bfd_bread ((PTR
) magic
, amt
, abfd
) != amt
)
1416 if (bfd_get_error () != bfd_error_system_call
)
1417 bfd_set_error (bfd_error_wrong_format
);
1421 if (strncmp (magic
, XCOFFARMAG
, SXCOFFARMAG
) != 0
1422 && strncmp (magic
, XCOFFARMAGBIG
, SXCOFFARMAG
) != 0)
1424 bfd_set_error (bfd_error_wrong_format
);
1428 tdata_hold
= bfd_ardata (abfd
);
1430 amt
= sizeof (struct artdata
);
1431 bfd_ardata (abfd
) = (struct artdata
*) bfd_zalloc (abfd
, amt
);
1432 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
1433 goto error_ret_restore
;
1435 /* Cleared by bfd_zalloc above.
1436 bfd_ardata (abfd)->cache = NULL;
1437 bfd_ardata (abfd)->archive_head = NULL;
1438 bfd_ardata (abfd)->symdefs = NULL;
1439 bfd_ardata (abfd)->extended_names = NULL;
1440 bfd_ardata (abfd)->extended_names_size = 0; */
1442 /* Now handle the two formats. */
1443 if (magic
[1] != 'b')
1445 /* This is the old format. */
1446 struct xcoff_ar_file_hdr hdr
;
1448 /* Copy over the magic string. */
1449 memcpy (hdr
.magic
, magic
, SXCOFFARMAG
);
1451 /* Now read the rest of the file header. */
1452 amt
= SIZEOF_AR_FILE_HDR
- SXCOFFARMAG
;
1453 if (bfd_bread ((PTR
) &hdr
.memoff
, amt
, abfd
) != amt
)
1455 if (bfd_get_error () != bfd_error_system_call
)
1456 bfd_set_error (bfd_error_wrong_format
);
1460 bfd_ardata (abfd
)->first_file_filepos
= strtol (hdr
.firstmemoff
,
1461 (char **) NULL
, 10);
1463 amt
= SIZEOF_AR_FILE_HDR
;
1464 bfd_ardata (abfd
)->tdata
= bfd_zalloc (abfd
, amt
);
1465 if (bfd_ardata (abfd
)->tdata
== NULL
)
1468 memcpy (bfd_ardata (abfd
)->tdata
, &hdr
, SIZEOF_AR_FILE_HDR
);
1472 /* This is the new format. */
1473 struct xcoff_ar_file_hdr_big hdr
;
1475 /* Copy over the magic string. */
1476 memcpy (hdr
.magic
, magic
, SXCOFFARMAG
);
1478 /* Now read the rest of the file header. */
1479 amt
= SIZEOF_AR_FILE_HDR_BIG
- SXCOFFARMAG
;
1480 if (bfd_bread ((PTR
) &hdr
.memoff
, amt
, abfd
) != amt
)
1482 if (bfd_get_error () != bfd_error_system_call
)
1483 bfd_set_error (bfd_error_wrong_format
);
1487 bfd_ardata (abfd
)->first_file_filepos
= bfd_scan_vma (hdr
.firstmemoff
,
1491 amt
= SIZEOF_AR_FILE_HDR_BIG
;
1492 bfd_ardata (abfd
)->tdata
= bfd_zalloc (abfd
, amt
);
1493 if (bfd_ardata (abfd
)->tdata
== NULL
)
1496 memcpy (bfd_ardata (abfd
)->tdata
, &hdr
, SIZEOF_AR_FILE_HDR_BIG
);
1499 if (! _bfd_xcoff_slurp_armap (abfd
))
1502 bfd_release (abfd
, bfd_ardata (abfd
));
1504 bfd_ardata (abfd
) = tdata_hold
;
1511 /* Read the archive header in an XCOFF archive. */
1514 _bfd_xcoff_read_ar_hdr (abfd
)
1517 bfd_size_type namlen
;
1518 struct areltdata
*ret
;
1519 bfd_size_type amt
= sizeof (struct areltdata
);
1521 ret
= (struct areltdata
*) bfd_alloc (abfd
, amt
);
1525 if (! xcoff_big_format_p (abfd
))
1527 struct xcoff_ar_hdr hdr
;
1528 struct xcoff_ar_hdr
*hdrp
;
1530 if (bfd_bread ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1537 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1538 amt
= SIZEOF_AR_HDR
+ namlen
+ 1;
1539 hdrp
= (struct xcoff_ar_hdr
*) bfd_alloc (abfd
, amt
);
1545 memcpy (hdrp
, &hdr
, SIZEOF_AR_HDR
);
1546 if (bfd_bread ((char *) hdrp
+ SIZEOF_AR_HDR
, namlen
, abfd
) != namlen
)
1551 ((char *) hdrp
)[SIZEOF_AR_HDR
+ namlen
] = '\0';
1553 ret
->arch_header
= (char *) hdrp
;
1554 ret
->parsed_size
= strtol (hdr
.size
, (char **) NULL
, 10);
1555 ret
->filename
= (char *) hdrp
+ SIZEOF_AR_HDR
;
1559 struct xcoff_ar_hdr_big hdr
;
1560 struct xcoff_ar_hdr_big
*hdrp
;
1562 if (bfd_bread ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR_BIG
, abfd
)
1563 != SIZEOF_AR_HDR_BIG
)
1569 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1570 amt
= SIZEOF_AR_HDR_BIG
+ namlen
+ 1;
1571 hdrp
= (struct xcoff_ar_hdr_big
*) bfd_alloc (abfd
, amt
);
1577 memcpy (hdrp
, &hdr
, SIZEOF_AR_HDR_BIG
);
1578 if (bfd_bread ((char *) hdrp
+ SIZEOF_AR_HDR_BIG
, namlen
, abfd
) != namlen
)
1583 ((char *) hdrp
)[SIZEOF_AR_HDR_BIG
+ namlen
] = '\0';
1585 ret
->arch_header
= (char *) hdrp
;
1586 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1587 machines) since the field width is 20 and there numbers with more
1588 than 32 bits can be represented. */
1589 ret
->parsed_size
= strtol (hdr
.size
, (char **) NULL
, 10);
1590 ret
->filename
= (char *) hdrp
+ SIZEOF_AR_HDR_BIG
;
1593 /* Skip over the XCOFFARFMAG at the end of the file name. */
1594 if (bfd_seek (abfd
, (file_ptr
) ((namlen
& 1) + SXCOFFARFMAG
), SEEK_CUR
) != 0)
1600 /* Open the next element in an XCOFF archive. */
1603 _bfd_xcoff_openr_next_archived_file (archive
, last_file
)
1609 if (xcoff_ardata (archive
) == NULL
)
1611 bfd_set_error (bfd_error_invalid_operation
);
1615 if (! xcoff_big_format_p (archive
))
1617 if (last_file
== NULL
)
1618 filestart
= bfd_ardata (archive
)->first_file_filepos
;
1620 filestart
= strtol (arch_xhdr (last_file
)->nextoff
, (char **) NULL
,
1624 || filestart
== strtol (xcoff_ardata (archive
)->memoff
,
1626 || filestart
== strtol (xcoff_ardata (archive
)->symoff
,
1627 (char **) NULL
, 10))
1629 bfd_set_error (bfd_error_no_more_archived_files
);
1635 if (last_file
== NULL
)
1636 filestart
= bfd_ardata (archive
)->first_file_filepos
;
1638 /* XXX These actually have to be a calls to strtoll (at least
1639 on 32-bit machines) since the fields's width is 20 and
1640 there numbers with more than 32 bits can be represented. */
1641 filestart
= strtol (arch_xhdr_big (last_file
)->nextoff
, (char **) NULL
,
1644 /* XXX These actually have to be calls to strtoll (at least on 32-bit
1645 machines) since the fields's width is 20 and there numbers with more
1646 than 32 bits can be represented. */
1648 || filestart
== strtol (xcoff_ardata_big (archive
)->memoff
,
1650 || filestart
== strtol (xcoff_ardata_big (archive
)->symoff
,
1651 (char **) NULL
, 10))
1653 bfd_set_error (bfd_error_no_more_archived_files
);
1658 return _bfd_get_elt_at_filepos (archive
, filestart
);
1661 /* Stat an element in an XCOFF archive. */
1664 _bfd_xcoff_stat_arch_elt (abfd
, s
)
1668 if (abfd
->arelt_data
== NULL
)
1670 bfd_set_error (bfd_error_invalid_operation
);
1674 if (! xcoff_big_format_p (abfd
->my_archive
))
1676 struct xcoff_ar_hdr
*hdrp
= arch_xhdr (abfd
);
1678 s
->st_mtime
= strtol (hdrp
->date
, (char **) NULL
, 10);
1679 s
->st_uid
= strtol (hdrp
->uid
, (char **) NULL
, 10);
1680 s
->st_gid
= strtol (hdrp
->gid
, (char **) NULL
, 10);
1681 s
->st_mode
= strtol (hdrp
->mode
, (char **) NULL
, 8);
1682 s
->st_size
= arch_eltdata (abfd
)->parsed_size
;
1686 struct xcoff_ar_hdr_big
*hdrp
= arch_xhdr_big (abfd
);
1688 s
->st_mtime
= strtol (hdrp
->date
, (char **) NULL
, 10);
1689 s
->st_uid
= strtol (hdrp
->uid
, (char **) NULL
, 10);
1690 s
->st_gid
= strtol (hdrp
->gid
, (char **) NULL
, 10);
1691 s
->st_mode
= strtol (hdrp
->mode
, (char **) NULL
, 8);
1692 s
->st_size
= arch_eltdata (abfd
)->parsed_size
;
1698 /* Normalize a file name for inclusion in an archive. */
1701 normalize_filename (abfd
)
1705 const char *filename
;
1707 file
= bfd_get_filename (abfd
);
1708 filename
= strrchr (file
, '/');
1709 if (filename
!= NULL
)
1716 /* Write out an XCOFF armap. */
1719 xcoff_write_armap_old (abfd
, elength
, map
, orl_count
, stridx
)
1721 unsigned int elength ATTRIBUTE_UNUSED
;
1723 unsigned int orl_count
;
1726 struct archive_iterator iterator
;
1727 struct xcoff_ar_hdr hdr
;
1729 unsigned char buf
[4];
1732 memset (&hdr
, 0, sizeof hdr
);
1733 sprintf (hdr
.size
, "%ld", (long) (4 + orl_count
* 4 + stridx
));
1734 sprintf (hdr
.nextoff
, "%d", 0);
1735 memcpy (hdr
.prevoff
, xcoff_ardata (abfd
)->memoff
, XCOFFARMAG_ELEMENT_SIZE
);
1736 sprintf (hdr
.date
, "%d", 0);
1737 sprintf (hdr
.uid
, "%d", 0);
1738 sprintf (hdr
.gid
, "%d", 0);
1739 sprintf (hdr
.mode
, "%d", 0);
1740 sprintf (hdr
.namlen
, "%d", 0);
1742 /* We need spaces, not null bytes, in the header. */
1743 for (p
= (char *) &hdr
; p
< (char *) &hdr
+ SIZEOF_AR_HDR
; p
++)
1747 if (bfd_bwrite ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1749 || (bfd_bwrite (XCOFFARFMAG
, (bfd_size_type
) SXCOFFARFMAG
, abfd
)
1753 H_PUT_32 (abfd
, orl_count
, buf
);
1754 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
1758 archive_iterator_begin (&iterator
, abfd
);
1759 while (i
< orl_count
&& archive_iterator_next (&iterator
))
1760 while (map
[i
].u
.abfd
== iterator
.current
.member
)
1762 H_PUT_32 (abfd
, iterator
.current
.offset
, buf
);
1763 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
1768 for (i
= 0; i
< orl_count
; i
++)
1773 name
= *map
[i
].name
;
1774 namlen
= strlen (name
);
1775 if (bfd_bwrite (name
, (bfd_size_type
) (namlen
+ 1), abfd
) != namlen
+ 1)
1779 if ((stridx
& 1) != 0)
1784 if (bfd_bwrite (&b
, (bfd_size_type
) 1, abfd
) != 1)
1791 static char buff20
[XCOFFARMAGBIG_ELEMENT_SIZE
+ 1];
1792 #define FMT20 "%-20lld"
1793 #define FMT12 "%-12d"
1794 #define FMT12_OCTAL "%-12o"
1796 #define PRINT20(d, v) \
1797 sprintf (buff20, FMT20, (long long)(v)), \
1798 memcpy ((void *) (d), buff20, 20)
1800 #define PRINT12(d, v) \
1801 sprintf (buff20, FMT12, (int)(v)), \
1802 memcpy ((void *) (d), buff20, 12)
1804 #define PRINT12_OCTAL(d, v) \
1805 sprintf (buff20, FMT12_OCTAL, (unsigned int)(v)), \
1806 memcpy ((void *) (d), buff20, 12)
1808 #define PRINT4(d, v) \
1809 sprintf (buff20, FMT4, (int)(v)), \
1810 memcpy ((void *) (d), buff20, 4)
1812 #define READ20(d, v) \
1814 memcpy (buff20, (d), 20), \
1815 (v) = bfd_scan_vma (buff20, (const char **) NULL, 10)
1818 do_pad (abfd
, number
)
1820 unsigned int number
;
1824 /* Limit pad to <= 4096. */
1829 if (bfd_bwrite (&b
, (bfd_size_type
) 1, abfd
) != 1)
1836 do_copy (out_bfd
, in_bfd
)
1840 bfd_size_type remaining
;
1841 bfd_byte buffer
[DEFAULT_BUFFERSIZE
];
1843 if (bfd_seek (in_bfd
, (file_ptr
) 0, SEEK_SET
) != 0)
1846 remaining
= arelt_size (in_bfd
);
1848 while (remaining
>= DEFAULT_BUFFERSIZE
)
1850 if (bfd_bread (buffer
, DEFAULT_BUFFERSIZE
, in_bfd
) != DEFAULT_BUFFERSIZE
1851 || bfd_bwrite (buffer
, DEFAULT_BUFFERSIZE
, out_bfd
) != DEFAULT_BUFFERSIZE
)
1854 remaining
-= DEFAULT_BUFFERSIZE
;
1859 if (bfd_bread (buffer
, remaining
, in_bfd
) != remaining
1860 || bfd_bwrite (buffer
, remaining
, out_bfd
) != remaining
)
1868 xcoff_write_armap_big (abfd
, elength
, map
, orl_count
, stridx
)
1870 unsigned int elength ATTRIBUTE_UNUSED
;
1872 unsigned int orl_count
;
1875 struct archive_iterator iterator
;
1876 struct xcoff_ar_file_hdr_big
*fhdr
;
1877 bfd_vma i
, sym_32
, sym_64
, str_32
, str_64
;
1878 const bfd_arch_info_type
*arch_info
;
1880 size_t string_length
;
1881 file_ptr nextoff
, prevoff
;
1883 /* First, we look through the symbols and work out which are
1884 from 32-bit objects and which from 64-bit ones. */
1885 sym_32
= sym_64
= str_32
= str_64
= 0;
1888 for (current_bfd
= abfd
->archive_head
;
1889 current_bfd
!= NULL
&& i
< orl_count
;
1890 current_bfd
= current_bfd
->archive_next
)
1892 arch_info
= bfd_get_arch_info (current_bfd
);
1893 while (map
[i
].u
.abfd
== current_bfd
)
1895 string_length
= strlen (*map
[i
].name
) + 1;
1896 if (arch_info
->bits_per_address
== 64)
1899 str_64
+= string_length
;
1904 str_32
+= string_length
;
1910 /* A quick sanity check... */
1911 BFD_ASSERT (sym_64
+ sym_32
== orl_count
);
1912 /* Explicit cast to int for compiler. */
1913 BFD_ASSERT ((int)(str_64
+ str_32
) == stridx
);
1915 fhdr
= xcoff_ardata_big (abfd
);
1917 /* xcoff_write_archive_contents_big passes nextoff in symoff. */
1918 READ20 (fhdr
->memoff
, prevoff
);
1919 READ20 (fhdr
->symoff
, nextoff
);
1921 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
1923 /* Write out the symbol table.
1926 standard big archive header
1927 0x0000 ar_size [0x14]
1928 0x0014 ar_nxtmem [0x14]
1929 0x0028 ar_prvmem [0x14]
1930 0x003C ar_date [0x0C]
1931 0x0048 ar_uid [0x0C]
1932 0x0054 ar_gid [0x0C]
1933 0x0060 ar_mod [0x0C]
1934 0x006C ar_namelen[0x04]
1935 0x0070 ar_fmag [SXCOFFARFMAG]
1938 0x0072 num_syms [0x08], binary
1939 0x0078 offsets [0x08 * num_syms], binary
1940 0x0086 + 0x08 * num_syms names [??]
1941 ?? pad to even bytes.
1946 struct xcoff_ar_hdr_big
*hdr
;
1950 bfd_vma symbol_table_size
=
1955 + str_32
+ (str_32
& 1);
1957 symbol_table
= bfd_zmalloc (symbol_table_size
);
1958 if (symbol_table
== NULL
)
1961 hdr
= (struct xcoff_ar_hdr_big
*) symbol_table
;
1963 PRINT20 (hdr
->size
, 8 + 8 * sym_32
+ str_32
+ (str_32
& 1));
1966 PRINT20 (hdr
->nextoff
, nextoff
+ symbol_table_size
);
1968 PRINT20 (hdr
->nextoff
, 0);
1970 PRINT20 (hdr
->prevoff
, prevoff
);
1971 PRINT12 (hdr
->date
, 0);
1972 PRINT12 (hdr
->uid
, 0);
1973 PRINT12 (hdr
->gid
, 0);
1974 PRINT12 (hdr
->mode
, 0);
1975 PRINT4 (hdr
->namlen
, 0) ;
1977 st
= symbol_table
+ SIZEOF_AR_HDR_BIG
;
1978 memcpy (st
, XCOFFARFMAG
, SXCOFFARFMAG
);
1981 bfd_h_put_64 (abfd
, sym_32
, st
);
1984 /* loop over the 32 bit offsets */
1986 archive_iterator_begin (&iterator
, abfd
);
1987 while (i
< orl_count
&& archive_iterator_next (&iterator
))
1989 arch_info
= bfd_get_arch_info (iterator
.current
.member
);
1990 while (map
[i
].u
.abfd
== iterator
.current
.member
)
1992 if (arch_info
->bits_per_address
== 32)
1994 bfd_h_put_64 (abfd
, iterator
.current
.offset
, st
);
2001 /* loop over the 32 bit symbol names */
2003 for (current_bfd
= abfd
->archive_head
;
2004 current_bfd
!= NULL
&& i
< orl_count
;
2005 current_bfd
= current_bfd
->archive_next
)
2007 arch_info
= bfd_get_arch_info (current_bfd
);
2008 while (map
[i
].u
.abfd
== current_bfd
)
2010 if (arch_info
->bits_per_address
== 32)
2012 string_length
= sprintf (st
, "%s", *map
[i
].name
);
2013 st
+= string_length
+ 1;
2019 bfd_bwrite (symbol_table
, symbol_table_size
, abfd
);
2021 free (symbol_table
);
2024 nextoff
= nextoff
+ symbol_table_size
;
2027 PRINT20 (fhdr
->symoff
, 0);
2031 struct xcoff_ar_hdr_big
*hdr
;
2035 bfd_vma symbol_table_size
=
2040 + str_64
+ (str_64
& 1);
2042 symbol_table
= bfd_zmalloc (symbol_table_size
);
2043 if (symbol_table
== NULL
)
2046 hdr
= (struct xcoff_ar_hdr_big
*) symbol_table
;
2048 PRINT20 (hdr
->size
, 8 + 8 * sym_64
+ str_64
+ (str_64
& 1));
2049 PRINT20 (hdr
->nextoff
, 0);
2050 PRINT20 (hdr
->prevoff
, prevoff
);
2051 PRINT12 (hdr
->date
, 0);
2052 PRINT12 (hdr
->uid
, 0);
2053 PRINT12 (hdr
->gid
, 0);
2054 PRINT12 (hdr
->mode
, 0);
2055 PRINT4 (hdr
->namlen
, 0);
2057 st
= symbol_table
+ SIZEOF_AR_HDR_BIG
;
2058 memcpy (st
, XCOFFARFMAG
, SXCOFFARFMAG
);
2061 bfd_h_put_64 (abfd
, sym_64
, st
);
2064 /* loop over the 64 bit offsets */
2066 archive_iterator_begin (&iterator
, abfd
);
2067 while (i
< orl_count
&& archive_iterator_next (&iterator
))
2069 arch_info
= bfd_get_arch_info (iterator
.current
.member
);
2070 while (map
[i
].u
.abfd
== iterator
.current
.member
)
2072 if (arch_info
->bits_per_address
== 64)
2074 bfd_h_put_64 (abfd
, iterator
.current
.offset
, st
);
2081 /* loop over the 64 bit symbol names */
2083 for (current_bfd
= abfd
->archive_head
;
2084 current_bfd
!= NULL
&& i
< orl_count
;
2085 current_bfd
= current_bfd
->archive_next
)
2087 arch_info
= bfd_get_arch_info (current_bfd
);
2088 while (map
[i
].u
.abfd
== current_bfd
)
2090 if (arch_info
->bits_per_address
== 64)
2092 string_length
= sprintf (st
, "%s", *map
[i
].name
);
2093 st
+= string_length
+ 1;
2099 bfd_bwrite (symbol_table
, symbol_table_size
, abfd
);
2101 free (symbol_table
);
2103 PRINT20 (fhdr
->symoff64
, nextoff
);
2106 PRINT20 (fhdr
->symoff64
, 0);
2112 _bfd_xcoff_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
2114 unsigned int elength ATTRIBUTE_UNUSED
;
2116 unsigned int orl_count
;
2119 if (! xcoff_big_format_p (abfd
))
2120 return xcoff_write_armap_old (abfd
, elength
, map
, orl_count
, stridx
);
2122 return xcoff_write_armap_big (abfd
, elength
, map
, orl_count
, stridx
);
2125 /* Write out an XCOFF archive. We always write an entire archive,
2126 rather than fussing with the freelist and so forth. */
2129 xcoff_write_archive_contents_old (abfd
)
2132 struct archive_iterator iterator
;
2133 struct xcoff_ar_file_hdr fhdr
;
2134 bfd_size_type count
;
2135 bfd_size_type total_namlen
;
2137 bfd_boolean makemap
;
2138 bfd_boolean hasobjects
;
2139 file_ptr prevoff
, nextoff
;
2142 struct xcoff_ar_hdr ahdr
;
2145 char decbuf
[XCOFFARMAG_ELEMENT_SIZE
+ 1];
2147 memset (&fhdr
, 0, sizeof fhdr
);
2148 (void) strncpy (fhdr
.magic
, XCOFFARMAG
, SXCOFFARMAG
);
2149 sprintf (fhdr
.firstmemoff
, "%d", SIZEOF_AR_FILE_HDR
);
2150 sprintf (fhdr
.freeoff
, "%d", 0);
2154 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->archive_next
)
2157 total_namlen
+= strlen (normalize_filename (sub
)) + 1;
2158 if (sub
->arelt_data
== NULL
)
2160 sub
->arelt_data
= bfd_zalloc (sub
, sizeof (struct areltdata
));
2161 if (sub
->arelt_data
== NULL
)
2164 if (arch_xhdr (sub
) == NULL
)
2166 struct xcoff_ar_hdr
*ahdrp
;
2169 if (stat (bfd_get_filename (sub
), &s
) != 0)
2171 bfd_set_error (bfd_error_system_call
);
2175 ahdrp
= bfd_zalloc (sub
, sizeof (*ahdrp
));
2179 sprintf (ahdrp
->size
, "%ld", (long) s
.st_size
);
2180 sprintf (ahdrp
->date
, "%ld", (long) s
.st_mtime
);
2181 sprintf (ahdrp
->uid
, "%ld", (long) s
.st_uid
);
2182 sprintf (ahdrp
->gid
, "%ld", (long) s
.st_gid
);
2183 sprintf (ahdrp
->mode
, "%o", (unsigned int) s
.st_mode
);
2185 arch_eltdata (sub
)->arch_header
= (char *) ahdrp
;
2186 arch_eltdata (sub
)->parsed_size
= s
.st_size
;
2189 offsets
= (file_ptr
*) bfd_alloc (abfd
, count
* sizeof (file_ptr
));
2190 if (offsets
== NULL
)
2193 if (bfd_seek (abfd
, (file_ptr
) SIZEOF_AR_FILE_HDR
, SEEK_SET
) != 0)
2196 makemap
= bfd_has_map (abfd
);
2199 for (archive_iterator_begin (&iterator
, abfd
), i
= 0;
2200 archive_iterator_next (&iterator
);
2203 bfd_size_type namlen
;
2204 struct xcoff_ar_hdr
*ahdrp
;
2206 if (makemap
&& ! hasobjects
)
2208 if (bfd_check_format (iterator
.current
.member
, bfd_object
))
2212 ahdrp
= arch_xhdr (iterator
.current
.member
);
2213 sprintf (ahdrp
->prevoff
, "%ld", (long) prevoff
);
2214 sprintf (ahdrp
->namlen
, "%ld", (long) iterator
.current
.namlen
);
2215 sprintf (ahdrp
->nextoff
, "%ld", (long) iterator
.next
.offset
);
2217 /* We need spaces, not null bytes, in the header. */
2218 for (p
= (char *) ahdrp
; p
< (char *) ahdrp
+ SIZEOF_AR_HDR
; p
++)
2222 if (!do_pad (abfd
, iterator
.current
.leading_padding
))
2225 BFD_ASSERT (iterator
.current
.offset
== bfd_tell (abfd
));
2226 namlen
= iterator
.current
.padded_namlen
;
2227 if (bfd_bwrite (ahdrp
, SIZEOF_AR_HDR
, abfd
) != SIZEOF_AR_HDR
2228 || bfd_bwrite (iterator
.current
.name
, namlen
, abfd
) != namlen
2229 || bfd_bwrite (XCOFFARFMAG
, SXCOFFARFMAG
, abfd
) != SXCOFFARFMAG
2230 || bfd_seek (iterator
.current
.member
, 0, SEEK_SET
) != 0
2231 || !do_copy (abfd
, iterator
.current
.member
)
2232 || !do_pad (abfd
, iterator
.current
.trailing_padding
))
2235 offsets
[i
] = iterator
.current
.offset
;
2236 prevoff
= iterator
.current
.offset
;
2239 sprintf (fhdr
.lastmemoff
, "%ld", (long) prevoff
);
2241 /* Write out the member table. */
2243 nextoff
= iterator
.next
.offset
;
2244 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2245 sprintf (fhdr
.memoff
, "%ld", (long) nextoff
);
2247 memset (&ahdr
, 0, sizeof ahdr
);
2248 sprintf (ahdr
.size
, "%ld", (long) (XCOFFARMAG_ELEMENT_SIZE
2249 + count
* XCOFFARMAG_ELEMENT_SIZE
2251 sprintf (ahdr
.prevoff
, "%ld", (long) prevoff
);
2252 sprintf (ahdr
.date
, "%d", 0);
2253 sprintf (ahdr
.uid
, "%d", 0);
2254 sprintf (ahdr
.gid
, "%d", 0);
2255 sprintf (ahdr
.mode
, "%d", 0);
2256 sprintf (ahdr
.namlen
, "%d", 0);
2258 size
= (SIZEOF_AR_HDR
2259 + XCOFFARMAG_ELEMENT_SIZE
2260 + count
* XCOFFARMAG_ELEMENT_SIZE
2265 nextoff
+= size
+ (size
& 1);
2267 if (makemap
&& hasobjects
)
2268 sprintf (ahdr
.nextoff
, "%ld", (long) nextoff
);
2270 sprintf (ahdr
.nextoff
, "%d", 0);
2272 /* We need spaces, not null bytes, in the header. */
2273 for (p
= (char *) &ahdr
; p
< (char *) &ahdr
+ SIZEOF_AR_HDR
; p
++)
2277 if ((bfd_bwrite ((PTR
) &ahdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
2279 || (bfd_bwrite ((PTR
) XCOFFARFMAG
, (bfd_size_type
) SXCOFFARFMAG
, abfd
)
2283 sprintf (decbuf
, "%-12ld", (long) count
);
2284 if (bfd_bwrite ((PTR
) decbuf
, (bfd_size_type
) XCOFFARMAG_ELEMENT_SIZE
, abfd
)
2285 != XCOFFARMAG_ELEMENT_SIZE
)
2287 for (i
= 0; i
< (size_t) count
; i
++)
2289 sprintf (decbuf
, "%-12ld", (long) offsets
[i
]);
2290 if (bfd_bwrite ((PTR
) decbuf
, (bfd_size_type
) XCOFFARMAG_ELEMENT_SIZE
,
2291 abfd
) != XCOFFARMAG_ELEMENT_SIZE
)
2294 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->archive_next
)
2297 bfd_size_type namlen
;
2299 name
= normalize_filename (sub
);
2300 namlen
= strlen (name
);
2301 if (bfd_bwrite ((PTR
) name
, namlen
+ 1, abfd
) != namlen
+ 1)
2305 if (! do_pad (abfd
, size
& 1))
2308 /* Write out the armap, if appropriate. */
2309 if (! makemap
|| ! hasobjects
)
2310 sprintf (fhdr
.symoff
, "%d", 0);
2313 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2314 sprintf (fhdr
.symoff
, "%ld", (long) nextoff
);
2315 bfd_ardata (abfd
)->tdata
= (PTR
) &fhdr
;
2316 if (! _bfd_compute_and_write_armap (abfd
, 0))
2320 /* Write out the archive file header. */
2322 /* We need spaces, not null bytes, in the header. */
2323 for (p
= (char *) &fhdr
; p
< (char *) &fhdr
+ SIZEOF_AR_FILE_HDR
; p
++)
2327 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
2328 || (bfd_bwrite ((PTR
) &fhdr
, (bfd_size_type
) SIZEOF_AR_FILE_HDR
, abfd
)
2329 != SIZEOF_AR_FILE_HDR
))
2336 xcoff_write_archive_contents_big (abfd
)
2339 struct xcoff_ar_file_hdr_big fhdr
;
2340 bfd_size_type count
;
2341 bfd_size_type total_namlen
;
2343 bfd_boolean makemap
;
2344 bfd_boolean hasobjects
;
2345 file_ptr prevoff
, nextoff
;
2348 struct xcoff_ar_hdr_big
*hdr
;
2350 char *member_table
, *mt
;
2351 bfd_vma member_table_size
;
2352 struct archive_iterator iterator
;
2354 memset (&fhdr
, 0, SIZEOF_AR_FILE_HDR_BIG
);
2355 memcpy (fhdr
.magic
, XCOFFARMAGBIG
, SXCOFFARMAG
);
2357 if (bfd_seek (abfd
, (file_ptr
) SIZEOF_AR_FILE_HDR_BIG
, SEEK_SET
) != 0)
2360 /* Calculate count and total_namlen. */
2361 makemap
= bfd_has_map (abfd
);
2363 for (current_bfd
= abfd
->archive_head
, count
= 0, total_namlen
= 0;
2364 current_bfd
!= NULL
;
2365 current_bfd
= current_bfd
->archive_next
, count
++)
2367 total_namlen
+= strlen (normalize_filename (current_bfd
)) + 1;
2371 && bfd_check_format (current_bfd
, bfd_object
))
2374 if (current_bfd
->arelt_data
== NULL
)
2376 size
= sizeof (struct areltdata
);
2377 current_bfd
->arelt_data
= bfd_zalloc (current_bfd
, size
);
2378 if (current_bfd
->arelt_data
== NULL
)
2382 if (arch_xhdr_big (current_bfd
) == NULL
)
2384 struct xcoff_ar_hdr_big
*ahdrp
;
2387 /* XXX This should actually be a call to stat64 (at least on
2389 XXX This call will fail if the original object is not found. */
2390 if (stat (bfd_get_filename (current_bfd
), &s
) != 0)
2392 bfd_set_error (bfd_error_system_call
);
2396 ahdrp
= bfd_zalloc (current_bfd
, sizeof (*ahdrp
));
2400 PRINT20 (ahdrp
->size
, s
.st_size
);
2401 PRINT12 (ahdrp
->date
, s
.st_mtime
);
2402 PRINT12 (ahdrp
->uid
, s
.st_uid
);
2403 PRINT12 (ahdrp
->gid
, s
.st_gid
);
2404 PRINT12_OCTAL (ahdrp
->mode
, s
.st_mode
);
2406 arch_eltdata (current_bfd
)->arch_header
= (char *) ahdrp
;
2407 arch_eltdata (current_bfd
)->parsed_size
= s
.st_size
;
2414 offsets
= (file_ptr
*) bfd_malloc (count
* sizeof (file_ptr
));
2415 if (offsets
== NULL
)
2420 for (archive_iterator_begin (&iterator
, abfd
), i
= 0;
2421 archive_iterator_next (&iterator
);
2424 bfd_size_type namlen
;
2425 struct xcoff_ar_hdr_big
*ahdrp
;
2427 ahdrp
= arch_xhdr_big (iterator
.current
.member
);
2428 PRINT20 (ahdrp
->prevoff
, prevoff
);
2429 PRINT4 (ahdrp
->namlen
, iterator
.current
.namlen
);
2430 PRINT20 (ahdrp
->nextoff
, iterator
.next
.offset
);
2432 if (!do_pad (abfd
, iterator
.current
.leading_padding
))
2435 BFD_ASSERT (iterator
.current
.offset
== bfd_tell (abfd
));
2436 namlen
= iterator
.current
.padded_namlen
;
2437 if (bfd_bwrite (ahdrp
, SIZEOF_AR_HDR_BIG
, abfd
) != SIZEOF_AR_HDR_BIG
2438 || bfd_bwrite (iterator
.current
.name
, namlen
, abfd
) != namlen
2439 || bfd_bwrite (XCOFFARFMAG
, SXCOFFARFMAG
, abfd
) != SXCOFFARFMAG
2440 || bfd_seek (iterator
.current
.member
, 0, SEEK_SET
) != 0
2441 || !do_copy (abfd
, iterator
.current
.member
)
2442 || !do_pad (abfd
, iterator
.current
.trailing_padding
))
2445 offsets
[i
] = iterator
.current
.offset
;
2446 prevoff
= iterator
.current
.offset
;
2451 PRINT20 (fhdr
.firstmemoff
, offsets
[0]);
2452 PRINT20 (fhdr
.lastmemoff
, prevoff
);
2455 /* Write out the member table.
2458 standard big archive header
2459 0x0000 ar_size [0x14]
2460 0x0014 ar_nxtmem [0x14]
2461 0x0028 ar_prvmem [0x14]
2462 0x003C ar_date [0x0C]
2463 0x0048 ar_uid [0x0C]
2464 0x0054 ar_gid [0x0C]
2465 0x0060 ar_mod [0x0C]
2466 0x006C ar_namelen[0x04]
2467 0x0070 ar_fmag [0x02]
2471 0x0086 offsets [0x14 * counts]
2472 0x0086 + 0x14 * counts names [??]
2473 ?? pad to even bytes.
2476 nextoff
= iterator
.next
.offset
;
2477 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2479 member_table_size
= (SIZEOF_AR_HDR_BIG
2481 + XCOFFARMAGBIG_ELEMENT_SIZE
2482 + count
* XCOFFARMAGBIG_ELEMENT_SIZE
2485 member_table_size
+= member_table_size
& 1;
2486 member_table
= bfd_zmalloc (member_table_size
);
2487 if (member_table
== NULL
)
2490 hdr
= (struct xcoff_ar_hdr_big
*) member_table
;
2492 PRINT20 (hdr
->size
, (XCOFFARMAGBIG_ELEMENT_SIZE
2493 + count
* XCOFFARMAGBIG_ELEMENT_SIZE
2494 + total_namlen
+ (total_namlen
& 1)));
2495 if (makemap
&& hasobjects
)
2496 PRINT20 (hdr
->nextoff
, nextoff
+ member_table_size
);
2498 PRINT20 (hdr
->nextoff
, 0);
2499 PRINT20 (hdr
->prevoff
, prevoff
);
2500 PRINT12 (hdr
->date
, 0);
2501 PRINT12 (hdr
->uid
, 0);
2502 PRINT12 (hdr
->gid
, 0);
2503 PRINT12 (hdr
->mode
, 0);
2504 PRINT4 (hdr
->namlen
, 0);
2506 mt
= member_table
+ SIZEOF_AR_HDR_BIG
;
2507 memcpy (mt
, XCOFFARFMAG
, SXCOFFARFMAG
);
2510 PRINT20 (mt
, count
);
2511 mt
+= XCOFFARMAGBIG_ELEMENT_SIZE
;
2512 for (i
= 0; i
< (size_t) count
; i
++)
2514 PRINT20 (mt
, offsets
[i
]);
2515 mt
+= XCOFFARMAGBIG_ELEMENT_SIZE
;
2524 for (current_bfd
= abfd
->archive_head
;
2525 current_bfd
!= NULL
;
2526 current_bfd
= current_bfd
->archive_next
)
2531 name
= normalize_filename (current_bfd
);
2532 namlen
= sprintf (mt
, "%s", name
);
2536 if (bfd_bwrite (member_table
, member_table_size
, abfd
) != member_table_size
)
2539 free (member_table
);
2541 PRINT20 (fhdr
.memoff
, nextoff
);
2544 nextoff
+= member_table_size
;
2546 /* Write out the armap, if appropriate. */
2548 if (! makemap
|| ! hasobjects
)
2549 PRINT20 (fhdr
.symoff
, 0);
2552 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2554 /* Save nextoff in fhdr.symoff so the armap routine can use it. */
2555 PRINT20 (fhdr
.symoff
, nextoff
);
2557 bfd_ardata (abfd
)->tdata
= (PTR
) &fhdr
;
2558 if (! _bfd_compute_and_write_armap (abfd
, 0))
2562 /* Write out the archive file header. */
2564 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
2565 || (bfd_bwrite ((PTR
) &fhdr
, (bfd_size_type
) SIZEOF_AR_FILE_HDR_BIG
,
2566 abfd
) != SIZEOF_AR_FILE_HDR_BIG
))
2573 _bfd_xcoff_write_archive_contents (abfd
)
2576 if (! xcoff_big_format_p (abfd
))
2577 return xcoff_write_archive_contents_old (abfd
);
2579 return xcoff_write_archive_contents_big (abfd
);
2582 /* We can't use the usual coff_sizeof_headers routine, because AIX
2583 always uses an a.out header. */
2586 _bfd_xcoff_sizeof_headers (bfd
*abfd
,
2587 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
2592 if (xcoff_data (abfd
)->full_aouthdr
)
2595 size
+= SMALL_AOUTSZ
;
2596 size
+= abfd
->section_count
* SCNHSZ
;
2600 /* Routines to swap information in the XCOFF .loader section. If we
2601 ever need to write an XCOFF loader, this stuff will need to be
2602 moved to another file shared by the linker (which XCOFF calls the
2603 ``binder'') and the loader. */
2605 /* Swap in the ldhdr structure. */
2608 xcoff_swap_ldhdr_in (abfd
, s
, dst
)
2611 struct internal_ldhdr
*dst
;
2613 const struct external_ldhdr
*src
= (const struct external_ldhdr
*) s
;
2615 dst
->l_version
= bfd_get_32 (abfd
, src
->l_version
);
2616 dst
->l_nsyms
= bfd_get_32 (abfd
, src
->l_nsyms
);
2617 dst
->l_nreloc
= bfd_get_32 (abfd
, src
->l_nreloc
);
2618 dst
->l_istlen
= bfd_get_32 (abfd
, src
->l_istlen
);
2619 dst
->l_nimpid
= bfd_get_32 (abfd
, src
->l_nimpid
);
2620 dst
->l_impoff
= bfd_get_32 (abfd
, src
->l_impoff
);
2621 dst
->l_stlen
= bfd_get_32 (abfd
, src
->l_stlen
);
2622 dst
->l_stoff
= bfd_get_32 (abfd
, src
->l_stoff
);
2625 /* Swap out the ldhdr structure. */
2628 xcoff_swap_ldhdr_out (abfd
, src
, d
)
2630 const struct internal_ldhdr
*src
;
2633 struct external_ldhdr
*dst
= (struct external_ldhdr
*) d
;
2635 bfd_put_32 (abfd
, (bfd_vma
) src
->l_version
, dst
->l_version
);
2636 bfd_put_32 (abfd
, src
->l_nsyms
, dst
->l_nsyms
);
2637 bfd_put_32 (abfd
, src
->l_nreloc
, dst
->l_nreloc
);
2638 bfd_put_32 (abfd
, src
->l_istlen
, dst
->l_istlen
);
2639 bfd_put_32 (abfd
, src
->l_nimpid
, dst
->l_nimpid
);
2640 bfd_put_32 (abfd
, src
->l_impoff
, dst
->l_impoff
);
2641 bfd_put_32 (abfd
, src
->l_stlen
, dst
->l_stlen
);
2642 bfd_put_32 (abfd
, src
->l_stoff
, dst
->l_stoff
);
2645 /* Swap in the ldsym structure. */
2648 xcoff_swap_ldsym_in (abfd
, s
, dst
)
2651 struct internal_ldsym
*dst
;
2653 const struct external_ldsym
*src
= (const struct external_ldsym
*) s
;
2655 if (bfd_get_32 (abfd
, src
->_l
._l_l
._l_zeroes
) != 0) {
2656 memcpy (dst
->_l
._l_name
, src
->_l
._l_name
, SYMNMLEN
);
2658 dst
->_l
._l_l
._l_zeroes
= 0;
2659 dst
->_l
._l_l
._l_offset
= bfd_get_32 (abfd
, src
->_l
._l_l
._l_offset
);
2661 dst
->l_value
= bfd_get_32 (abfd
, src
->l_value
);
2662 dst
->l_scnum
= bfd_get_16 (abfd
, src
->l_scnum
);
2663 dst
->l_smtype
= bfd_get_8 (abfd
, src
->l_smtype
);
2664 dst
->l_smclas
= bfd_get_8 (abfd
, src
->l_smclas
);
2665 dst
->l_ifile
= bfd_get_32 (abfd
, src
->l_ifile
);
2666 dst
->l_parm
= bfd_get_32 (abfd
, src
->l_parm
);
2669 /* Swap out the ldsym structure. */
2672 xcoff_swap_ldsym_out (abfd
, src
, d
)
2674 const struct internal_ldsym
*src
;
2677 struct external_ldsym
*dst
= (struct external_ldsym
*) d
;
2679 if (src
->_l
._l_l
._l_zeroes
!= 0)
2680 memcpy (dst
->_l
._l_name
, src
->_l
._l_name
, SYMNMLEN
);
2683 bfd_put_32 (abfd
, (bfd_vma
) 0, dst
->_l
._l_l
._l_zeroes
);
2684 bfd_put_32 (abfd
, (bfd_vma
) src
->_l
._l_l
._l_offset
,
2685 dst
->_l
._l_l
._l_offset
);
2687 bfd_put_32 (abfd
, src
->l_value
, dst
->l_value
);
2688 bfd_put_16 (abfd
, (bfd_vma
) src
->l_scnum
, dst
->l_scnum
);
2689 bfd_put_8 (abfd
, src
->l_smtype
, dst
->l_smtype
);
2690 bfd_put_8 (abfd
, src
->l_smclas
, dst
->l_smclas
);
2691 bfd_put_32 (abfd
, src
->l_ifile
, dst
->l_ifile
);
2692 bfd_put_32 (abfd
, src
->l_parm
, dst
->l_parm
);
2696 xcoff_swap_reloc_in (abfd
, s
, d
)
2701 struct external_reloc
*src
= (struct external_reloc
*) s
;
2702 struct internal_reloc
*dst
= (struct internal_reloc
*) d
;
2704 memset (dst
, 0, sizeof (struct internal_reloc
));
2706 dst
->r_vaddr
= bfd_get_32 (abfd
, src
->r_vaddr
);
2707 dst
->r_symndx
= bfd_get_32 (abfd
, src
->r_symndx
);
2708 dst
->r_size
= bfd_get_8 (abfd
, src
->r_size
);
2709 dst
->r_type
= bfd_get_8 (abfd
, src
->r_type
);
2713 xcoff_swap_reloc_out (abfd
, s
, d
)
2718 struct internal_reloc
*src
= (struct internal_reloc
*) s
;
2719 struct external_reloc
*dst
= (struct external_reloc
*) d
;
2721 bfd_put_32 (abfd
, src
->r_vaddr
, dst
->r_vaddr
);
2722 bfd_put_32 (abfd
, src
->r_symndx
, dst
->r_symndx
);
2723 bfd_put_8 (abfd
, src
->r_type
, dst
->r_type
);
2724 bfd_put_8 (abfd
, src
->r_size
, dst
->r_size
);
2726 return bfd_coff_relsz (abfd
);
2729 /* Swap in the ldrel structure. */
2732 xcoff_swap_ldrel_in (abfd
, s
, dst
)
2735 struct internal_ldrel
*dst
;
2737 const struct external_ldrel
*src
= (const struct external_ldrel
*) s
;
2739 dst
->l_vaddr
= bfd_get_32 (abfd
, src
->l_vaddr
);
2740 dst
->l_symndx
= bfd_get_32 (abfd
, src
->l_symndx
);
2741 dst
->l_rtype
= bfd_get_16 (abfd
, src
->l_rtype
);
2742 dst
->l_rsecnm
= bfd_get_16 (abfd
, src
->l_rsecnm
);
2745 /* Swap out the ldrel structure. */
2748 xcoff_swap_ldrel_out (abfd
, src
, d
)
2750 const struct internal_ldrel
*src
;
2753 struct external_ldrel
*dst
= (struct external_ldrel
*) d
;
2755 bfd_put_32 (abfd
, src
->l_vaddr
, dst
->l_vaddr
);
2756 bfd_put_32 (abfd
, src
->l_symndx
, dst
->l_symndx
);
2757 bfd_put_16 (abfd
, (bfd_vma
) src
->l_rtype
, dst
->l_rtype
);
2758 bfd_put_16 (abfd
, (bfd_vma
) src
->l_rsecnm
, dst
->l_rsecnm
);
2763 xcoff_reloc_type_noop (input_bfd
, input_section
, output_bfd
, rel
, sym
, howto
,
2764 val
, addend
, relocation
, contents
)
2765 bfd
*input_bfd ATTRIBUTE_UNUSED
;
2766 asection
*input_section ATTRIBUTE_UNUSED
;
2767 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2768 struct internal_reloc
*rel ATTRIBUTE_UNUSED
;
2769 struct internal_syment
*sym ATTRIBUTE_UNUSED
;
2770 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
;
2771 bfd_vma val ATTRIBUTE_UNUSED
;
2772 bfd_vma addend ATTRIBUTE_UNUSED
;
2773 bfd_vma
*relocation ATTRIBUTE_UNUSED
;
2774 bfd_byte
*contents ATTRIBUTE_UNUSED
;
2780 xcoff_reloc_type_fail (input_bfd
, input_section
, output_bfd
, rel
, sym
, howto
,
2781 val
, addend
, relocation
, contents
)
2783 asection
*input_section ATTRIBUTE_UNUSED
;
2784 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2785 struct internal_reloc
*rel
;
2786 struct internal_syment
*sym ATTRIBUTE_UNUSED
;
2787 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
;
2788 bfd_vma val ATTRIBUTE_UNUSED
;
2789 bfd_vma addend ATTRIBUTE_UNUSED
;
2790 bfd_vma
*relocation ATTRIBUTE_UNUSED
;
2791 bfd_byte
*contents ATTRIBUTE_UNUSED
;
2793 (*_bfd_error_handler
)
2794 (_("%s: unsupported relocation type 0x%02x"),
2795 bfd_get_filename (input_bfd
), (unsigned int) rel
->r_type
);
2796 bfd_set_error (bfd_error_bad_value
);
2801 xcoff_reloc_type_pos (input_bfd
, input_section
, output_bfd
, rel
, sym
, howto
,
2802 val
, addend
, relocation
, contents
)
2803 bfd
*input_bfd ATTRIBUTE_UNUSED
;
2804 asection
*input_section ATTRIBUTE_UNUSED
;
2805 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2806 struct internal_reloc
*rel ATTRIBUTE_UNUSED
;
2807 struct internal_syment
*sym ATTRIBUTE_UNUSED
;
2808 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
;
2811 bfd_vma
*relocation
;
2812 bfd_byte
*contents ATTRIBUTE_UNUSED
;
2814 *relocation
= val
+ addend
;
2819 xcoff_reloc_type_neg (input_bfd
, input_section
, output_bfd
, rel
, sym
, howto
,
2820 val
, addend
, relocation
, contents
)
2821 bfd
*input_bfd ATTRIBUTE_UNUSED
;
2822 asection
*input_section ATTRIBUTE_UNUSED
;
2823 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2824 struct internal_reloc
*rel ATTRIBUTE_UNUSED
;
2825 struct internal_syment
*sym ATTRIBUTE_UNUSED
;
2826 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
;
2829 bfd_vma
*relocation
;
2830 bfd_byte
*contents ATTRIBUTE_UNUSED
;
2832 *relocation
= addend
- val
;
2837 xcoff_reloc_type_rel (input_bfd
, input_section
, output_bfd
, rel
, sym
, howto
,
2838 val
, addend
, relocation
, contents
)
2839 bfd
*input_bfd ATTRIBUTE_UNUSED
;
2840 asection
*input_section
;
2841 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2842 struct internal_reloc
*rel ATTRIBUTE_UNUSED
;
2843 struct internal_syment
*sym ATTRIBUTE_UNUSED
;
2844 struct reloc_howto_struct
*howto
;
2847 bfd_vma
*relocation
;
2848 bfd_byte
*contents ATTRIBUTE_UNUSED
;
2850 howto
->pc_relative
= TRUE
;
2852 /* A PC relative reloc includes the section address. */
2853 addend
+= input_section
->vma
;
2855 *relocation
= val
+ addend
;
2856 *relocation
-= (input_section
->output_section
->vma
2857 + input_section
->output_offset
);
2862 xcoff_reloc_type_toc (input_bfd
, input_section
, output_bfd
, rel
, sym
, howto
,
2863 val
, addend
, relocation
, contents
)
2865 asection
*input_section ATTRIBUTE_UNUSED
;
2867 struct internal_reloc
*rel
;
2868 struct internal_syment
*sym
;
2869 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
;
2871 bfd_vma addend ATTRIBUTE_UNUSED
;
2872 bfd_vma
*relocation
;
2873 bfd_byte
*contents ATTRIBUTE_UNUSED
;
2875 struct xcoff_link_hash_entry
*h
;
2877 if (0 > rel
->r_symndx
)
2880 h
= obj_xcoff_sym_hashes (input_bfd
)[rel
->r_symndx
];
2882 if (h
!= NULL
&& h
->smclas
!= XMC_TD
)
2884 if (h
->toc_section
== NULL
)
2886 (*_bfd_error_handler
)
2887 (_("%s: TOC reloc at 0x%x to symbol `%s' with no TOC entry"),
2888 bfd_get_filename (input_bfd
), rel
->r_vaddr
,
2889 h
->root
.root
.string
);
2890 bfd_set_error (bfd_error_bad_value
);
2894 BFD_ASSERT ((h
->flags
& XCOFF_SET_TOC
) == 0);
2895 val
= (h
->toc_section
->output_section
->vma
2896 + h
->toc_section
->output_offset
);
2899 *relocation
= ((val
- xcoff_data (output_bfd
)->toc
)
2900 - (sym
->n_value
- xcoff_data (input_bfd
)->toc
));
2905 xcoff_reloc_type_ba (input_bfd
, input_section
, output_bfd
, rel
, sym
, howto
,
2906 val
, addend
, relocation
, contents
)
2907 bfd
*input_bfd ATTRIBUTE_UNUSED
;
2908 asection
*input_section ATTRIBUTE_UNUSED
;
2909 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2910 struct internal_reloc
*rel ATTRIBUTE_UNUSED
;
2911 struct internal_syment
*sym ATTRIBUTE_UNUSED
;
2912 struct reloc_howto_struct
*howto
;
2915 bfd_vma
*relocation
;
2916 bfd_byte
*contents ATTRIBUTE_UNUSED
;
2918 howto
->src_mask
&= ~3;
2919 howto
->dst_mask
= howto
->src_mask
;
2921 *relocation
= val
+ addend
;
2927 xcoff_reloc_type_br (input_bfd
, input_section
, output_bfd
, rel
, sym
, howto
,
2928 val
, addend
, relocation
, contents
)
2930 asection
*input_section
;
2931 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2932 struct internal_reloc
*rel
;
2933 struct internal_syment
*sym ATTRIBUTE_UNUSED
;
2934 struct reloc_howto_struct
*howto
;
2937 bfd_vma
*relocation
;
2940 struct xcoff_link_hash_entry
*h
;
2941 bfd_vma section_offset
;
2943 if (0 > rel
->r_symndx
)
2946 h
= obj_xcoff_sym_hashes (input_bfd
)[rel
->r_symndx
];
2947 section_offset
= rel
->r_vaddr
- input_section
->vma
;
2949 /* If we see an R_BR or R_RBR reloc which is jumping to global
2950 linkage code, and it is followed by an appropriate cror nop
2951 instruction, we replace the cror with lwz r2,20(r1). This
2952 restores the TOC after the glink code. Contrariwise, if the
2953 call is followed by a lwz r2,20(r1), but the call is not
2954 going to global linkage code, we can replace the load with a
2957 && (bfd_link_hash_defined
== h
->root
.type
2958 || bfd_link_hash_defweak
== h
->root
.type
)
2959 && section_offset
+ 8 <= input_section
->size
)
2964 pnext
= contents
+ section_offset
+ 4;
2965 next
= bfd_get_32 (input_bfd
, pnext
);
2967 /* The _ptrgl function is magic. It is used by the AIX
2968 compiler to call a function through a pointer. */
2969 if (h
->smclas
== XMC_GL
|| strcmp (h
->root
.root
.string
, "._ptrgl") == 0)
2971 if (next
== 0x4def7b82 /* cror 15,15,15 */
2972 || next
== 0x4ffffb82 /* cror 31,31,31 */
2973 || next
== 0x60000000) /* ori r0,r0,0 */
2974 bfd_put_32 (input_bfd
, 0x80410014, pnext
); /* lwz r2,20(r1) */
2979 if (next
== 0x80410014) /* lwz r2,20(r1) */
2980 bfd_put_32 (input_bfd
, 0x60000000, pnext
); /* ori r0,r0,0 */
2983 else if (NULL
!= h
&& bfd_link_hash_undefined
== h
->root
.type
)
2985 /* Normally, this relocation is against a defined symbol. In the
2986 case where this is a partial link and the output section offset
2987 is greater than 2^25, the linker will return an invalid error
2988 message that the relocation has been truncated. Yes it has been
2989 truncated but no it not important. For this case, disable the
2990 overflow checking. */
2992 howto
->complain_on_overflow
= complain_overflow_dont
;
2995 /* The original PC-relative relocation is biased by -r_vaddr, so adding
2996 the value below will give the absolute target address. */
2997 *relocation
= val
+ addend
+ rel
->r_vaddr
;
2999 howto
->src_mask
&= ~3;
3000 howto
->dst_mask
= howto
->src_mask
;
3003 && (h
->root
.type
== bfd_link_hash_defined
3004 || h
->root
.type
== bfd_link_hash_defweak
)
3005 && bfd_is_abs_section (h
->root
.u
.def
.section
)
3006 && section_offset
+ 4 <= input_section
->size
)
3011 /* Turn the relative branch into an absolute one by setting the
3013 ptr
= contents
+ section_offset
;
3014 insn
= bfd_get_32 (input_bfd
, ptr
);
3016 bfd_put_32 (input_bfd
, insn
, ptr
);
3018 /* Make the howto absolute too. */
3019 howto
->pc_relative
= FALSE
;
3020 howto
->complain_on_overflow
= complain_overflow_bitfield
;
3024 /* Use a PC-relative howto and subtract the instruction's address
3025 from the target address we calculated above. */
3026 howto
->pc_relative
= TRUE
;
3027 *relocation
-= (input_section
->output_section
->vma
3028 + input_section
->output_offset
3035 xcoff_reloc_type_crel (input_bfd
, input_section
, output_bfd
, rel
, sym
, howto
,
3036 val
, addend
, relocation
, contents
)
3037 bfd
*input_bfd ATTRIBUTE_UNUSED
;
3038 asection
*input_section
;
3039 bfd
*output_bfd ATTRIBUTE_UNUSED
;
3040 struct internal_reloc
*rel ATTRIBUTE_UNUSED
;
3041 struct internal_syment
*sym ATTRIBUTE_UNUSED
;
3042 struct reloc_howto_struct
*howto
;
3043 bfd_vma val ATTRIBUTE_UNUSED
;
3045 bfd_vma
*relocation
;
3046 bfd_byte
*contents ATTRIBUTE_UNUSED
;
3048 howto
->pc_relative
= TRUE
;
3049 howto
->src_mask
&= ~3;
3050 howto
->dst_mask
= howto
->src_mask
;
3052 /* A PC relative reloc includes the section address. */
3053 addend
+= input_section
->vma
;
3055 *relocation
= val
+ addend
;
3056 *relocation
-= (input_section
->output_section
->vma
3057 + input_section
->output_offset
);
3062 xcoff_complain_overflow_dont_func (input_bfd
, val
, relocation
, howto
)
3063 bfd
*input_bfd ATTRIBUTE_UNUSED
;
3064 bfd_vma val ATTRIBUTE_UNUSED
;
3065 bfd_vma relocation ATTRIBUTE_UNUSED
;
3066 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
;
3072 xcoff_complain_overflow_bitfield_func (input_bfd
, val
, relocation
, howto
)
3076 struct reloc_howto_struct
*howto
;
3078 bfd_vma fieldmask
, signmask
, ss
;
3081 /* Get the values to be added together. For signed and unsigned
3082 relocations, we assume that all values should be truncated to
3083 the size of an address. For bitfields, all the bits matter.
3084 See also bfd_check_overflow. */
3085 fieldmask
= N_ONES (howto
->bitsize
);
3087 b
= val
& howto
->src_mask
;
3089 /* Much like unsigned, except no trimming with addrmask. In
3090 addition, the sum overflows if there is a carry out of
3091 the bfd_vma, i.e., the sum is less than either input
3093 a
>>= howto
->rightshift
;
3094 b
>>= howto
->bitpos
;
3096 /* Bitfields are sometimes used for signed numbers; for
3097 example, a 13-bit field sometimes represents values in
3098 0..8191 and sometimes represents values in -4096..4095.
3099 If the field is signed and a is -4095 (0x1001) and b is
3100 -1 (0x1fff), the sum is -4096 (0x1000), but (0x1001 +
3101 0x1fff is 0x3000). It's not clear how to handle this
3102 everywhere, since there is not way to know how many bits
3103 are significant in the relocation, but the original code
3104 assumed that it was fully sign extended, and we will keep
3106 signmask
= (fieldmask
>> 1) + 1;
3108 if ((a
& ~ fieldmask
) != 0)
3110 /* Some bits out of the field are set. This might not
3111 be a problem: if this is a signed bitfield, it is OK
3112 iff all the high bits are set, including the sign
3113 bit. We'll try setting all but the most significant
3114 bit in the original relocation value: if this is all
3115 ones, we are OK, assuming a signed bitfield. */
3116 ss
= (signmask
<< howto
->rightshift
) - 1;
3117 if ((ss
| relocation
) != ~ (bfd_vma
) 0)
3122 /* We just assume (b & ~ fieldmask) == 0. */
3124 /* We explicitly permit wrap around if this relocation
3125 covers the high bit of an address. The Linux kernel
3126 relies on it, and it is the only way to write assembler
3127 code which can run when loaded at a location 0x80000000
3128 away from the location at which it is linked. */
3129 if (howto
->bitsize
+ howto
->rightshift
3130 == bfd_arch_bits_per_address (input_bfd
))
3134 if (sum
< a
|| (sum
& ~ fieldmask
) != 0)
3136 /* There was a carry out, or the field overflow. Test
3137 for signed operands again. Here is the overflow test
3138 is as for complain_overflow_signed. */
3139 if (((~ (a
^ b
)) & (a
^ sum
)) & signmask
)
3147 xcoff_complain_overflow_signed_func (input_bfd
, val
, relocation
, howto
)
3151 struct reloc_howto_struct
*howto
;
3153 bfd_vma addrmask
, fieldmask
, signmask
, ss
;
3156 /* Get the values to be added together. For signed and unsigned
3157 relocations, we assume that all values should be truncated to
3158 the size of an address. For bitfields, all the bits matter.
3159 See also bfd_check_overflow. */
3160 fieldmask
= N_ONES (howto
->bitsize
);
3161 addrmask
= N_ONES (bfd_arch_bits_per_address (input_bfd
)) | fieldmask
;
3163 b
= val
& howto
->src_mask
;
3165 a
= (a
& addrmask
) >> howto
->rightshift
;
3167 /* If any sign bits are set, all sign bits must be set.
3168 That is, A must be a valid negative address after
3170 signmask
= ~ (fieldmask
>> 1);
3172 if (ss
!= 0 && ss
!= ((addrmask
>> howto
->rightshift
) & signmask
))
3175 /* We only need this next bit of code if the sign bit of B
3176 is below the sign bit of A. This would only happen if
3177 SRC_MASK had fewer bits than BITSIZE. Note that if
3178 SRC_MASK has more bits than BITSIZE, we can get into
3179 trouble; we would need to verify that B is in range, as
3180 we do for A above. */
3181 signmask
= ((~ howto
->src_mask
) >> 1) & howto
->src_mask
;
3182 if ((b
& signmask
) != 0)
3184 /* Set all the bits above the sign bit. */
3185 b
-= signmask
<<= 1;
3188 b
= (b
& addrmask
) >> howto
->bitpos
;
3190 /* Now we can do the addition. */
3193 /* See if the result has the correct sign. Bits above the
3194 sign bit are junk now; ignore them. If the sum is
3195 positive, make sure we did not have all negative inputs;
3196 if the sum is negative, make sure we did not have all
3197 positive inputs. The test below looks only at the sign
3198 bits, and it really just
3199 SIGN (A) == SIGN (B) && SIGN (A) != SIGN (SUM)
3201 signmask
= (fieldmask
>> 1) + 1;
3202 if (((~ (a
^ b
)) & (a
^ sum
)) & signmask
)
3209 xcoff_complain_overflow_unsigned_func (input_bfd
, val
, relocation
, howto
)
3213 struct reloc_howto_struct
*howto
;
3215 bfd_vma addrmask
, fieldmask
;
3218 /* Get the values to be added together. For signed and unsigned
3219 relocations, we assume that all values should be truncated to
3220 the size of an address. For bitfields, all the bits matter.
3221 See also bfd_check_overflow. */
3222 fieldmask
= N_ONES (howto
->bitsize
);
3223 addrmask
= N_ONES (bfd_arch_bits_per_address (input_bfd
)) | fieldmask
;
3225 b
= val
& howto
->src_mask
;
3227 /* Checking for an unsigned overflow is relatively easy:
3228 trim the addresses and add, and trim the result as well.
3229 Overflow is normally indicated when the result does not
3230 fit in the field. However, we also need to consider the
3231 case when, e.g., fieldmask is 0x7fffffff or smaller, an
3232 input is 0x80000000, and bfd_vma is only 32 bits; then we
3233 will get sum == 0, but there is an overflow, since the
3234 inputs did not fit in the field. Instead of doing a
3235 separate test, we can check for this by or-ing in the
3236 operands when testing for the sum overflowing its final
3238 a
= (a
& addrmask
) >> howto
->rightshift
;
3239 b
= (b
& addrmask
) >> howto
->bitpos
;
3240 sum
= (a
+ b
) & addrmask
;
3241 if ((a
| b
| sum
) & ~ fieldmask
)
3247 /* This is the relocation function for the RS/6000/POWER/PowerPC.
3248 This is currently the only processor which uses XCOFF; I hope that
3251 I took the relocation type definitions from two documents:
3252 the PowerPC AIX Version 4 Application Binary Interface, First
3253 Edition (April 1992), and the PowerOpen ABI, Big-Endian
3254 32-Bit Hardware Implementation (June 30, 1994). Differences
3255 between the documents are noted below.
3257 Unsupported r_type's
3263 These relocs are defined by the PowerPC ABI to be
3264 relative branches which use half of the difference
3265 between the symbol and the program counter. I can't
3266 quite figure out when this is useful. These relocs are
3267 not defined by the PowerOpen ABI.
3272 Simple positive relocation.
3275 Simple negative relocation.
3278 Simple PC relative relocation.
3281 TOC relative relocation. The value in the instruction in
3282 the input file is the offset from the input file TOC to
3283 the desired location. We want the offset from the final
3284 TOC to the desired location. We have:
3289 so we must change insn by on - in.
3292 GL linkage relocation. The value of this relocation
3293 is the address of the entry in the TOC section.
3296 Local object TOC address. I can't figure out the
3297 difference between this and case R_GL.
3300 TOC relative relocation. A TOC relative load instruction
3301 which may be changed to a load address instruction.
3302 FIXME: We don't currently implement this optimization.
3305 TOC relative relocation. This is a TOC relative load
3306 address instruction which may be changed to a load
3307 instruction. FIXME: I don't know if this is the correct
3311 Absolute branch. We don't want to mess with the lower
3312 two bits of the instruction.
3315 The PowerPC ABI defines this as an absolute call which
3316 may be modified to become a relative call. The PowerOpen
3317 ABI does not define this relocation type.
3320 Absolute branch which may be modified to become a
3324 The PowerPC ABI defines this as an absolute branch to a
3325 fixed address which may be modified to an absolute branch
3326 to a symbol. The PowerOpen ABI does not define this
3330 The PowerPC ABI defines this as an absolute branch to a
3331 fixed address which may be modified to a relative branch.
3332 The PowerOpen ABI does not define this relocation type.
3335 Relative branch. We don't want to mess with the lower
3336 two bits of the instruction.
3339 The PowerPC ABI defines this as a relative call which may
3340 be modified to become an absolute call. The PowerOpen
3341 ABI does not define this relocation type.
3344 A relative branch which may be modified to become an
3348 The PowerPC AIX ABI describes this as a load which may be
3349 changed to a load address. The PowerOpen ABI says this
3350 is the same as case R_POS.
3353 The PowerPC AIX ABI describes this as a load address
3354 which may be changed to a load. The PowerOpen ABI says
3355 this is the same as R_POS.
3359 xcoff_ppc_relocate_section (output_bfd
, info
, input_bfd
,
3360 input_section
, contents
, relocs
, syms
,
3363 struct bfd_link_info
*info
;
3365 asection
*input_section
;
3367 struct internal_reloc
*relocs
;
3368 struct internal_syment
*syms
;
3369 asection
**sections
;
3371 struct internal_reloc
*rel
;
3372 struct internal_reloc
*relend
;
3375 relend
= rel
+ input_section
->reloc_count
;
3376 for (; rel
< relend
; rel
++)
3379 struct xcoff_link_hash_entry
*h
;
3380 struct internal_syment
*sym
;
3383 struct reloc_howto_struct howto
;
3385 bfd_vma value_to_relocate
;
3389 /* Relocation type R_REF is a special relocation type which is
3390 merely used to prevent garbage collection from occurring for
3391 the csect including the symbol which it references. */
3392 if (rel
->r_type
== R_REF
)
3396 howto
.type
= rel
->r_type
;
3397 howto
.rightshift
= 0;
3398 howto
.bitsize
= (rel
->r_size
& 0x1f) + 1;
3399 howto
.size
= howto
.bitsize
> 16 ? 2 : 1;
3400 howto
.pc_relative
= FALSE
;
3402 howto
.complain_on_overflow
= (rel
->r_size
& 0x80
3403 ? complain_overflow_signed
3404 : complain_overflow_bitfield
);
3405 howto
.special_function
= NULL
;
3406 howto
.name
= "internal";
3407 howto
.partial_inplace
= TRUE
;
3408 howto
.src_mask
= howto
.dst_mask
= N_ONES (howto
.bitsize
);
3409 howto
.pcrel_offset
= FALSE
;
3416 symndx
= rel
->r_symndx
;
3422 h
= obj_xcoff_sym_hashes (input_bfd
)[symndx
];
3423 sym
= syms
+ symndx
;
3424 addend
= - sym
->n_value
;
3428 sec
= sections
[symndx
];
3429 /* Hack to make sure we use the right TOC anchor value
3430 if this reloc is against the TOC anchor. */
3431 if (sec
->name
[3] == '0'
3432 && strcmp (sec
->name
, ".tc0") == 0)
3433 val
= xcoff_data (output_bfd
)->toc
;
3435 val
= (sec
->output_section
->vma
3436 + sec
->output_offset
3442 if (info
->unresolved_syms_in_objects
!= RM_IGNORE
3443 && (h
->flags
& XCOFF_WAS_UNDEFINED
) != 0)
3445 if (! ((*info
->callbacks
->undefined_symbol
)
3446 (info
, h
->root
.root
.string
,
3447 input_bfd
, input_section
,
3448 rel
->r_vaddr
- input_section
->vma
,
3449 (info
->unresolved_syms_in_objects
3450 == RM_GENERATE_ERROR
))))
3453 if (h
->root
.type
== bfd_link_hash_defined
3454 || h
->root
.type
== bfd_link_hash_defweak
)
3456 sec
= h
->root
.u
.def
.section
;
3457 val
= (h
->root
.u
.def
.value
3458 + sec
->output_section
->vma
3459 + sec
->output_offset
);
3461 else if (h
->root
.type
== bfd_link_hash_common
)
3463 sec
= h
->root
.u
.c
.p
->section
;
3464 val
= (sec
->output_section
->vma
3465 + sec
->output_offset
);
3470 BFD_ASSERT (info
->relocatable
3471 || (info
->static_link
3472 && (h
->flags
& XCOFF_WAS_UNDEFINED
) != 0)
3473 || (h
->flags
& XCOFF_DEF_DYNAMIC
) != 0
3474 || (h
->flags
& XCOFF_IMPORT
) != 0);
3479 if (rel
->r_type
>= XCOFF_MAX_CALCULATE_RELOCATION
3480 || !((*xcoff_calculate_relocation
[rel
->r_type
])
3481 (input_bfd
, input_section
, output_bfd
, rel
, sym
, &howto
, val
,
3482 addend
, &relocation
, contents
)))
3486 address
= rel
->r_vaddr
- input_section
->vma
;
3487 location
= contents
+ address
;
3489 if (address
> input_section
->size
)
3492 /* Get the value we are going to relocate. */
3493 if (1 == howto
.size
)
3494 value_to_relocate
= bfd_get_16 (input_bfd
, location
);
3496 value_to_relocate
= bfd_get_32 (input_bfd
, location
);
3500 FIXME: We may drop bits during the addition
3501 which we don't check for. We must either check at every single
3502 operation, which would be tedious, or we must do the computations
3503 in a type larger than bfd_vma, which would be inefficient. */
3505 if ((unsigned int) howto
.complain_on_overflow
3506 >= XCOFF_MAX_COMPLAIN_OVERFLOW
)
3509 if (((*xcoff_complain_overflow
[howto
.complain_on_overflow
])
3510 (input_bfd
, value_to_relocate
, relocation
, &howto
)))
3513 char buf
[SYMNMLEN
+ 1];
3514 char reloc_type_name
[10];
3526 name
= _bfd_coff_internal_syment_name (input_bfd
, sym
, buf
);
3530 sprintf (reloc_type_name
, "0x%02x", rel
->r_type
);
3532 if (! ((*info
->callbacks
->reloc_overflow
)
3533 (info
, (h
? &h
->root
: NULL
), name
, reloc_type_name
,
3534 (bfd_vma
) 0, input_bfd
, input_section
,
3535 rel
->r_vaddr
- input_section
->vma
)))
3539 /* Add RELOCATION to the right bits of VALUE_TO_RELOCATE. */
3540 value_to_relocate
= ((value_to_relocate
& ~howto
.dst_mask
)
3541 | (((value_to_relocate
& howto
.src_mask
)
3542 + relocation
) & howto
.dst_mask
));
3544 /* Put the value back in the object file. */
3545 if (1 == howto
.size
)
3546 bfd_put_16 (input_bfd
, value_to_relocate
, location
);
3548 bfd_put_32 (input_bfd
, value_to_relocate
, location
);
3555 _bfd_xcoff_put_ldsymbol_name (abfd
, ldinfo
, ldsym
, name
)
3556 bfd
*abfd ATTRIBUTE_UNUSED
;
3557 struct xcoff_loader_info
*ldinfo
;
3558 struct internal_ldsym
*ldsym
;
3562 len
= strlen (name
);
3564 if (len
<= SYMNMLEN
)
3565 strncpy (ldsym
->_l
._l_name
, name
, SYMNMLEN
);
3568 if (ldinfo
->string_size
+ len
+ 3 > ldinfo
->string_alc
)
3570 bfd_size_type newalc
;
3573 newalc
= ldinfo
->string_alc
* 2;
3576 while (ldinfo
->string_size
+ len
+ 3 > newalc
)
3579 newstrings
= bfd_realloc (ldinfo
->strings
, newalc
);
3580 if (newstrings
== NULL
)
3582 ldinfo
->failed
= TRUE
;
3585 ldinfo
->string_alc
= newalc
;
3586 ldinfo
->strings
= newstrings
;
3589 bfd_put_16 (ldinfo
->output_bfd
, (bfd_vma
) (len
+ 1),
3590 ldinfo
->strings
+ ldinfo
->string_size
);
3591 strcpy (ldinfo
->strings
+ ldinfo
->string_size
+ 2, name
);
3592 ldsym
->_l
._l_l
._l_zeroes
= 0;
3593 ldsym
->_l
._l_l
._l_offset
= ldinfo
->string_size
+ 2;
3594 ldinfo
->string_size
+= len
+ 3;
3601 _bfd_xcoff_put_symbol_name (bfd
*abfd
, struct bfd_strtab_hash
*strtab
,
3602 struct internal_syment
*sym
,
3605 if (strlen (name
) <= SYMNMLEN
)
3607 strncpy (sym
->_n
._n_name
, name
, SYMNMLEN
);
3615 if ((abfd
->flags
& BFD_TRADITIONAL_FORMAT
) != 0)
3617 indx
= _bfd_stringtab_add (strtab
, name
, hash
, FALSE
);
3618 if (indx
== (bfd_size_type
) -1)
3620 sym
->_n
._n_n
._n_zeroes
= 0;
3621 sym
->_n
._n_n
._n_offset
= STRING_SIZE_SIZE
+ indx
;
3627 xcoff_create_csect_from_smclas (abfd
, aux
, symbol_name
)
3629 union internal_auxent
*aux
;
3630 const char *symbol_name
;
3632 asection
*return_value
= NULL
;
3634 /* .sv64 = x_smclas == 17
3635 This is an invalid csect for 32 bit apps. */
3636 static const char *names
[19] =
3638 ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo",
3639 ".sv", ".bs", ".ds", ".uc", ".ti", ".tb", NULL
, ".tc0",
3640 ".td", NULL
, ".sv3264"
3643 if ((19 >= aux
->x_csect
.x_smclas
)
3644 && (NULL
!= names
[aux
->x_csect
.x_smclas
]))
3646 return_value
= bfd_make_section_anyway
3647 (abfd
, names
[aux
->x_csect
.x_smclas
]);
3651 (*_bfd_error_handler
)
3652 (_("%B: symbol `%s' has unrecognized smclas %d"),
3653 abfd
, symbol_name
, aux
->x_csect
.x_smclas
);
3654 bfd_set_error (bfd_error_bad_value
);
3657 return return_value
;
3661 xcoff_is_lineno_count_overflow (abfd
, value
)
3662 bfd
*abfd ATTRIBUTE_UNUSED
;
3665 if (0xffff <= value
)
3672 xcoff_is_reloc_count_overflow (abfd
, value
)
3673 bfd
*abfd ATTRIBUTE_UNUSED
;
3676 if (0xffff <= value
)
3683 xcoff_loader_symbol_offset (abfd
, ldhdr
)
3685 struct internal_ldhdr
*ldhdr ATTRIBUTE_UNUSED
;
3687 return bfd_xcoff_ldhdrsz (abfd
);
3691 xcoff_loader_reloc_offset (abfd
, ldhdr
)
3693 struct internal_ldhdr
*ldhdr
;
3695 return bfd_xcoff_ldhdrsz (abfd
) + ldhdr
->l_nsyms
* bfd_xcoff_ldsymsz (abfd
);
3699 xcoff_generate_rtinit (abfd
, init
, fini
, rtld
)
3705 bfd_byte filehdr_ext
[FILHSZ
];
3706 bfd_byte scnhdr_ext
[SCNHSZ
];
3707 bfd_byte syment_ext
[SYMESZ
* 10];
3708 bfd_byte reloc_ext
[RELSZ
* 3];
3709 bfd_byte
*data_buffer
;
3710 bfd_size_type data_buffer_size
;
3711 bfd_byte
*string_table
= NULL
, *st_tmp
= NULL
;
3712 bfd_size_type string_table_size
;
3714 size_t initsz
, finisz
;
3715 struct internal_filehdr filehdr
;
3716 struct internal_scnhdr scnhdr
;
3717 struct internal_syment syment
;
3718 union internal_auxent auxent
;
3719 struct internal_reloc reloc
;
3721 char *data_name
= ".data";
3722 char *rtinit_name
= "__rtinit";
3723 char *rtld_name
= "__rtld";
3725 if (! bfd_xcoff_rtinit_size (abfd
))
3728 initsz
= (init
== NULL
? 0 : 1 + strlen (init
));
3729 finisz
= (fini
== NULL
? 0 : 1 + strlen (fini
));
3732 memset (filehdr_ext
, 0, FILHSZ
);
3733 memset (&filehdr
, 0, sizeof (struct internal_filehdr
));
3734 filehdr
.f_magic
= bfd_xcoff_magic_number (abfd
);
3735 filehdr
.f_nscns
= 1;
3736 filehdr
.f_timdat
= 0;
3737 filehdr
.f_nsyms
= 0; /* at least 6, no more than 10 */
3738 filehdr
.f_symptr
= 0; /* set below */
3739 filehdr
.f_opthdr
= 0;
3740 filehdr
.f_flags
= 0;
3742 /* section header */
3743 memset (scnhdr_ext
, 0, SCNHSZ
);
3744 memset (&scnhdr
, 0, sizeof (struct internal_scnhdr
));
3745 memcpy (scnhdr
.s_name
, data_name
, strlen (data_name
));
3748 scnhdr
.s_size
= 0; /* set below */
3749 scnhdr
.s_scnptr
= FILHSZ
+ SCNHSZ
;
3750 scnhdr
.s_relptr
= 0; /* set below */
3751 scnhdr
.s_lnnoptr
= 0;
3752 scnhdr
.s_nreloc
= 0; /* either 1 or 2 */
3754 scnhdr
.s_flags
= STYP_DATA
;
3757 0x0000 0x00000000 : rtl
3758 0x0004 0x00000010 : offset to init, or 0
3759 0x0008 0x00000028 : offset to fini, or 0
3760 0x000C 0x0000000C : size of descriptor
3761 0x0010 0x00000000 : init, needs a reloc
3762 0x0014 0x00000040 : offset to init name
3763 0x0018 0x00000000 : flags, padded to a word
3764 0x001C 0x00000000 : empty init
3767 0x0028 0x00000000 : fini, needs a reloc
3768 0x002C 0x00000??? : offset to fini name
3769 0x0030 0x00000000 : flags, padded to a word
3770 0x0034 0x00000000 : empty fini
3774 0x0040 + initsz fini name */
3776 data_buffer_size
= 0x0040 + initsz
+ finisz
;
3777 data_buffer_size
= (data_buffer_size
+ 7) &~ (bfd_size_type
) 7;
3779 data_buffer
= (bfd_byte
*) bfd_zmalloc (data_buffer_size
);
3780 if (data_buffer
== NULL
)
3786 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x04]);
3788 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x14]);
3789 memcpy (&data_buffer
[val
], init
, initsz
);
3795 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x08]);
3796 val
= 0x40 + initsz
;
3797 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x2C]);
3798 memcpy (&data_buffer
[val
], fini
, finisz
);
3802 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x0C]);
3804 scnhdr
.s_size
= data_buffer_size
;
3807 string_table_size
= 0;
3809 string_table_size
+= initsz
;
3811 string_table_size
+= finisz
;
3812 if (string_table_size
)
3814 string_table_size
+= 4;
3815 string_table
= (bfd_byte
*) bfd_zmalloc (string_table_size
);
3816 if (string_table
== NULL
)
3819 val
= string_table_size
;
3820 bfd_h_put_32 (abfd
, val
, &string_table
[0]);
3821 st_tmp
= string_table
+ 4;
3830 memset (syment_ext
, 0, 10 * SYMESZ
);
3831 memset (reloc_ext
, 0, 3 * RELSZ
);
3834 memset (&syment
, 0, sizeof (struct internal_syment
));
3835 memset (&auxent
, 0, sizeof (union internal_auxent
));
3836 memcpy (syment
._n
._n_name
, data_name
, strlen (data_name
));
3838 syment
.n_sclass
= C_HIDEXT
;
3839 syment
.n_numaux
= 1;
3840 auxent
.x_csect
.x_scnlen
.l
= data_buffer_size
;
3841 auxent
.x_csect
.x_smtyp
= 3 << 3 | XTY_SD
;
3842 auxent
.x_csect
.x_smclas
= XMC_RW
;
3843 bfd_coff_swap_sym_out (abfd
, &syment
,
3844 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3845 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3847 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3848 filehdr
.f_nsyms
+= 2;
3851 memset (&syment
, 0, sizeof (struct internal_syment
));
3852 memset (&auxent
, 0, sizeof (union internal_auxent
));
3853 memcpy (syment
._n
._n_name
, rtinit_name
, strlen (rtinit_name
));
3855 syment
.n_sclass
= C_EXT
;
3856 syment
.n_numaux
= 1;
3857 auxent
.x_csect
.x_smtyp
= XTY_LD
;
3858 auxent
.x_csect
.x_smclas
= XMC_RW
;
3859 bfd_coff_swap_sym_out (abfd
, &syment
,
3860 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3861 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3863 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3864 filehdr
.f_nsyms
+= 2;
3869 memset (&syment
, 0, sizeof (struct internal_syment
));
3870 memset (&auxent
, 0, sizeof (union internal_auxent
));
3874 syment
._n
._n_n
._n_offset
= st_tmp
- string_table
;
3875 memcpy (st_tmp
, init
, initsz
);
3879 memcpy (syment
._n
._n_name
, init
, initsz
- 1);
3881 syment
.n_sclass
= C_EXT
;
3882 syment
.n_numaux
= 1;
3883 bfd_coff_swap_sym_out (abfd
, &syment
,
3884 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3885 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3887 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3890 memset (&reloc
, 0, sizeof (struct internal_reloc
));
3891 reloc
.r_vaddr
= 0x0010;
3892 reloc
.r_symndx
= filehdr
.f_nsyms
;
3893 reloc
.r_type
= R_POS
;
3895 bfd_coff_swap_reloc_out (abfd
, &reloc
, &reloc_ext
[0]);
3897 filehdr
.f_nsyms
+= 2;
3898 scnhdr
.s_nreloc
+= 1;
3904 memset (&syment
, 0, sizeof (struct internal_syment
));
3905 memset (&auxent
, 0, sizeof (union internal_auxent
));
3909 syment
._n
._n_n
._n_offset
= st_tmp
- string_table
;
3910 memcpy (st_tmp
, fini
, finisz
);
3914 memcpy (syment
._n
._n_name
, fini
, finisz
- 1);
3916 syment
.n_sclass
= C_EXT
;
3917 syment
.n_numaux
= 1;
3918 bfd_coff_swap_sym_out (abfd
, &syment
,
3919 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3920 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3922 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3925 memset (&reloc
, 0, sizeof (struct internal_reloc
));
3926 reloc
.r_vaddr
= 0x0028;
3927 reloc
.r_symndx
= filehdr
.f_nsyms
;
3928 reloc
.r_type
= R_POS
;
3930 bfd_coff_swap_reloc_out (abfd
, &reloc
,
3931 &reloc_ext
[scnhdr
.s_nreloc
* RELSZ
]);
3933 filehdr
.f_nsyms
+= 2;
3934 scnhdr
.s_nreloc
+= 1;
3939 memset (&syment
, 0, sizeof (struct internal_syment
));
3940 memset (&auxent
, 0, sizeof (union internal_auxent
));
3941 memcpy (syment
._n
._n_name
, rtld_name
, strlen (rtld_name
));
3942 syment
.n_sclass
= C_EXT
;
3943 syment
.n_numaux
= 1;
3944 bfd_coff_swap_sym_out (abfd
, &syment
,
3945 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3946 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3948 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3951 memset (&reloc
, 0, sizeof (struct internal_reloc
));
3952 reloc
.r_vaddr
= 0x0000;
3953 reloc
.r_symndx
= filehdr
.f_nsyms
;
3954 reloc
.r_type
= R_POS
;
3956 bfd_coff_swap_reloc_out (abfd
, &reloc
,
3957 &reloc_ext
[scnhdr
.s_nreloc
* RELSZ
]);
3959 filehdr
.f_nsyms
+= 2;
3960 scnhdr
.s_nreloc
+= 1;
3963 scnhdr
.s_relptr
= scnhdr
.s_scnptr
+ data_buffer_size
;
3964 filehdr
.f_symptr
= scnhdr
.s_relptr
+ scnhdr
.s_nreloc
* RELSZ
;
3966 bfd_coff_swap_filehdr_out (abfd
, &filehdr
, filehdr_ext
);
3967 bfd_bwrite (filehdr_ext
, FILHSZ
, abfd
);
3968 bfd_coff_swap_scnhdr_out (abfd
, &scnhdr
, scnhdr_ext
);
3969 bfd_bwrite (scnhdr_ext
, SCNHSZ
, abfd
);
3970 bfd_bwrite (data_buffer
, data_buffer_size
, abfd
);
3971 bfd_bwrite (reloc_ext
, scnhdr
.s_nreloc
* RELSZ
, abfd
);
3972 bfd_bwrite (syment_ext
, filehdr
.f_nsyms
* SYMESZ
, abfd
);
3973 bfd_bwrite (string_table
, string_table_size
, abfd
);
3982 static reloc_howto_type xcoff_dynamic_reloc
=
3983 HOWTO (0, /* type */
3985 2, /* size (0 = byte, 1 = short, 2 = long) */
3987 FALSE
, /* pc_relative */
3989 complain_overflow_bitfield
, /* complain_on_overflow */
3990 0, /* special_function */
3992 TRUE
, /* partial_inplace */
3993 0xffffffff, /* src_mask */
3994 0xffffffff, /* dst_mask */
3995 FALSE
); /* pcrel_offset */
3999 The first word of global linkage code must be modified by filling in
4000 the correct TOC offset. */
4002 static unsigned long xcoff_glink_code
[9] =
4004 0x81820000, /* lwz r12,0(r2) */
4005 0x90410014, /* stw r2,20(r1) */
4006 0x800c0000, /* lwz r0,0(r12) */
4007 0x804c0004, /* lwz r2,4(r12) */
4008 0x7c0903a6, /* mtctr r0 */
4009 0x4e800420, /* bctr */
4010 0x00000000, /* start of traceback table */
4011 0x000c8000, /* traceback table */
4012 0x00000000, /* traceback table */
4016 static const struct xcoff_backend_data_rec bfd_xcoff_backend_data
=
4018 { /* COFF backend, defined in libcoff.h. */
4019 _bfd_xcoff_swap_aux_in
,
4020 _bfd_xcoff_swap_sym_in
,
4021 coff_swap_lineno_in
,
4022 _bfd_xcoff_swap_aux_out
,
4023 _bfd_xcoff_swap_sym_out
,
4024 coff_swap_lineno_out
,
4025 xcoff_swap_reloc_out
,
4026 coff_swap_filehdr_out
,
4027 coff_swap_aouthdr_out
,
4028 coff_swap_scnhdr_out
,
4037 TRUE
, /* _bfd_coff_long_filenames */
4038 XCOFF_NO_LONG_SECTION_NAMES
, /* _bfd_coff_long_section_names */
4039 3, /* _bfd_coff_default_section_alignment_power */
4040 FALSE
, /* _bfd_coff_force_symnames_in_strings */
4041 2, /* _bfd_coff_debug_string_prefix_length */
4042 coff_swap_filehdr_in
,
4043 coff_swap_aouthdr_in
,
4044 coff_swap_scnhdr_in
,
4045 xcoff_swap_reloc_in
,
4046 coff_bad_format_hook
,
4047 coff_set_arch_mach_hook
,
4050 coff_set_alignment_hook
,
4051 coff_slurp_symbol_table
,
4052 symname_in_debug_hook
,
4053 coff_pointerize_aux_hook
,
4055 dummy_reloc16_extra_cases
,
4056 dummy_reloc16_estimate
,
4057 NULL
, /* bfd_coff_sym_is_global */
4058 coff_compute_section_file_positions
,
4059 NULL
, /* _bfd_coff_start_final_link */
4060 xcoff_ppc_relocate_section
,
4061 coff_rtype_to_howto
,
4062 NULL
, /* _bfd_coff_adjust_symndx */
4063 _bfd_generic_link_add_one_symbol
,
4064 coff_link_output_has_begun
,
4065 coff_final_link_postscript
,
4066 NULL
/* print_pdata. */
4069 0x01DF, /* magic number */
4073 /* Function pointers to xcoff specific swap routines. */
4074 xcoff_swap_ldhdr_in
,
4075 xcoff_swap_ldhdr_out
,
4076 xcoff_swap_ldsym_in
,
4077 xcoff_swap_ldsym_out
,
4078 xcoff_swap_ldrel_in
,
4079 xcoff_swap_ldrel_out
,
4085 12, /* _xcoff_function_descriptor_size */
4089 1, /* _xcoff_ldhdr_version */
4091 _bfd_xcoff_put_symbol_name
,
4092 _bfd_xcoff_put_ldsymbol_name
,
4093 &xcoff_dynamic_reloc
,
4094 xcoff_create_csect_from_smclas
,
4096 /* Lineno and reloc count overflow. */
4097 xcoff_is_lineno_count_overflow
,
4098 xcoff_is_reloc_count_overflow
,
4100 xcoff_loader_symbol_offset
,
4101 xcoff_loader_reloc_offset
,
4104 &xcoff_glink_code
[0],
4105 36, /* _xcoff_glink_size */
4108 64, /* _xcoff_rtinit_size */
4109 xcoff_generate_rtinit
,
4112 /* The transfer vector that leads the outside world to all of the above. */
4113 const bfd_target rs6000coff_vec
=
4116 bfd_target_xcoff_flavour
,
4117 BFD_ENDIAN_BIG
, /* data byte order is big */
4118 BFD_ENDIAN_BIG
, /* header byte order is big */
4120 (HAS_RELOC
| EXEC_P
| HAS_LINENO
| HAS_DEBUG
| DYNAMIC
4121 | HAS_SYMS
| HAS_LOCALS
| WP_TEXT
),
4123 SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_CODE
| SEC_DATA
,
4124 0, /* leading char */
4125 '/', /* ar_pad_char */
4126 15, /* ar_max_namelen */
4150 { /* bfd_check_format */
4153 _bfd_xcoff_archive_p
,
4157 { /* bfd_set_format */
4160 _bfd_generic_mkarchive
,
4164 {/* bfd_write_contents */
4166 coff_write_object_contents
,
4167 _bfd_xcoff_write_archive_contents
,
4174 coff_new_section_hook
,
4175 _bfd_generic_get_section_contents
,
4176 _bfd_generic_get_section_contents_in_window
,
4179 _bfd_xcoff_copy_private_bfd_data
,
4180 _bfd_generic_bfd_merge_private_bfd_data
,
4181 _bfd_generic_init_private_section_data
,
4182 _bfd_generic_bfd_copy_private_section_data
,
4183 _bfd_generic_bfd_copy_private_symbol_data
,
4184 _bfd_generic_bfd_copy_private_header_data
,
4185 _bfd_generic_bfd_set_private_flags
,
4186 _bfd_generic_bfd_print_private_bfd_data
,
4189 BFD_JUMP_TABLE_CORE (coff
),
4192 _bfd_xcoff_slurp_armap
,
4193 _bfd_noarchive_slurp_extended_name_table
,
4194 _bfd_noarchive_construct_extended_name_table
,
4195 bfd_dont_truncate_arname
,
4196 _bfd_xcoff_write_armap
,
4197 _bfd_xcoff_read_ar_hdr
,
4198 _bfd_generic_write_ar_hdr
,
4199 _bfd_xcoff_openr_next_archived_file
,
4200 _bfd_generic_get_elt_at_index
,
4201 _bfd_xcoff_stat_arch_elt
,
4205 coff_get_symtab_upper_bound
,
4206 coff_canonicalize_symtab
,
4207 coff_make_empty_symbol
,
4209 coff_get_symbol_info
,
4210 _bfd_xcoff_is_local_label_name
,
4211 coff_bfd_is_target_special_symbol
,
4213 coff_find_nearest_line
,
4214 _bfd_generic_find_line
,
4215 coff_find_inliner_info
,
4216 coff_bfd_make_debug_symbol
,
4217 _bfd_generic_read_minisymbols
,
4218 _bfd_generic_minisymbol_to_symbol
,
4221 coff_get_reloc_upper_bound
,
4222 coff_canonicalize_reloc
,
4223 _bfd_xcoff_reloc_type_lookup
,
4224 _bfd_xcoff_reloc_name_lookup
,
4228 coff_set_section_contents
,
4231 _bfd_xcoff_sizeof_headers
,
4232 bfd_generic_get_relocated_section_contents
,
4233 bfd_generic_relax_section
,
4234 _bfd_xcoff_bfd_link_hash_table_create
,
4235 _bfd_generic_link_hash_table_free
,
4236 _bfd_xcoff_bfd_link_add_symbols
,
4237 _bfd_generic_link_just_syms
,
4238 _bfd_generic_copy_link_hash_symbol_type
,
4239 _bfd_xcoff_bfd_final_link
,
4240 _bfd_generic_link_split_section
,
4241 bfd_generic_gc_sections
,
4242 bfd_generic_merge_sections
,
4243 bfd_generic_is_group_section
,
4244 bfd_generic_discard_group
,
4245 _bfd_generic_section_already_linked
,
4246 _bfd_xcoff_define_common_symbol
,
4249 _bfd_xcoff_get_dynamic_symtab_upper_bound
,
4250 _bfd_xcoff_canonicalize_dynamic_symtab
,
4251 _bfd_nodynamic_get_synthetic_symtab
,
4252 _bfd_xcoff_get_dynamic_reloc_upper_bound
,
4253 _bfd_xcoff_canonicalize_dynamic_reloc
,
4255 /* Opposite endian version, none exists */
4258 (void *) &bfd_xcoff_backend_data
,
4261 /* xcoff-powermac target
4263 Only difference between this target and the rs6000 target is the
4264 the default architecture and machine type used in coffcode.h
4266 PowerPC Macs use the same magic numbers as RS/6000
4267 (because that's how they were bootstrapped originally),
4268 but they are always PowerPC architecture. */
4269 static const struct xcoff_backend_data_rec bfd_pmac_xcoff_backend_data
=
4271 { /* COFF backend, defined in libcoff.h. */
4272 _bfd_xcoff_swap_aux_in
,
4273 _bfd_xcoff_swap_sym_in
,
4274 coff_swap_lineno_in
,
4275 _bfd_xcoff_swap_aux_out
,
4276 _bfd_xcoff_swap_sym_out
,
4277 coff_swap_lineno_out
,
4278 xcoff_swap_reloc_out
,
4279 coff_swap_filehdr_out
,
4280 coff_swap_aouthdr_out
,
4281 coff_swap_scnhdr_out
,
4290 TRUE
, /* _bfd_coff_long_filenames */
4291 XCOFF_NO_LONG_SECTION_NAMES
, /* _bfd_coff_long_section_names */
4292 3, /* _bfd_coff_default_section_alignment_power */
4293 FALSE
, /* _bfd_coff_force_symnames_in_strings */
4294 2, /* _bfd_coff_debug_string_prefix_length */
4295 coff_swap_filehdr_in
,
4296 coff_swap_aouthdr_in
,
4297 coff_swap_scnhdr_in
,
4298 xcoff_swap_reloc_in
,
4299 coff_bad_format_hook
,
4300 coff_set_arch_mach_hook
,
4303 coff_set_alignment_hook
,
4304 coff_slurp_symbol_table
,
4305 symname_in_debug_hook
,
4306 coff_pointerize_aux_hook
,
4308 dummy_reloc16_extra_cases
,
4309 dummy_reloc16_estimate
,
4310 NULL
, /* bfd_coff_sym_is_global */
4311 coff_compute_section_file_positions
,
4312 NULL
, /* _bfd_coff_start_final_link */
4313 xcoff_ppc_relocate_section
,
4314 coff_rtype_to_howto
,
4315 NULL
, /* _bfd_coff_adjust_symndx */
4316 _bfd_generic_link_add_one_symbol
,
4317 coff_link_output_has_begun
,
4318 coff_final_link_postscript
,
4319 NULL
/* print_pdata. */
4322 0x01DF, /* magic number */
4326 /* Function pointers to xcoff specific swap routines. */
4327 xcoff_swap_ldhdr_in
,
4328 xcoff_swap_ldhdr_out
,
4329 xcoff_swap_ldsym_in
,
4330 xcoff_swap_ldsym_out
,
4331 xcoff_swap_ldrel_in
,
4332 xcoff_swap_ldrel_out
,
4338 12, /* _xcoff_function_descriptor_size */
4342 1, /* _xcoff_ldhdr_version */
4344 _bfd_xcoff_put_symbol_name
,
4345 _bfd_xcoff_put_ldsymbol_name
,
4346 &xcoff_dynamic_reloc
,
4347 xcoff_create_csect_from_smclas
,
4349 /* Lineno and reloc count overflow. */
4350 xcoff_is_lineno_count_overflow
,
4351 xcoff_is_reloc_count_overflow
,
4353 xcoff_loader_symbol_offset
,
4354 xcoff_loader_reloc_offset
,
4357 &xcoff_glink_code
[0],
4358 36, /* _xcoff_glink_size */
4361 0, /* _xcoff_rtinit_size */
4362 xcoff_generate_rtinit
,
4365 /* The transfer vector that leads the outside world to all of the above. */
4366 const bfd_target pmac_xcoff_vec
=
4369 bfd_target_xcoff_flavour
,
4370 BFD_ENDIAN_BIG
, /* data byte order is big */
4371 BFD_ENDIAN_BIG
, /* header byte order is big */
4373 (HAS_RELOC
| EXEC_P
| HAS_LINENO
| HAS_DEBUG
| DYNAMIC
4374 | HAS_SYMS
| HAS_LOCALS
| WP_TEXT
),
4376 SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
| SEC_CODE
| SEC_DATA
,
4377 0, /* leading char */
4378 '/', /* ar_pad_char */
4379 15, /* ar_max_namelen */
4403 { /* bfd_check_format */
4406 _bfd_xcoff_archive_p
,
4410 { /* bfd_set_format */
4413 _bfd_generic_mkarchive
,
4417 {/* bfd_write_contents */
4419 coff_write_object_contents
,
4420 _bfd_xcoff_write_archive_contents
,
4427 coff_new_section_hook
,
4428 _bfd_generic_get_section_contents
,
4429 _bfd_generic_get_section_contents_in_window
,
4432 _bfd_xcoff_copy_private_bfd_data
,
4433 _bfd_generic_bfd_merge_private_bfd_data
,
4434 _bfd_generic_init_private_section_data
,
4435 _bfd_generic_bfd_copy_private_section_data
,
4436 _bfd_generic_bfd_copy_private_symbol_data
,
4437 _bfd_generic_bfd_copy_private_header_data
,
4438 _bfd_generic_bfd_set_private_flags
,
4439 _bfd_generic_bfd_print_private_bfd_data
,
4442 BFD_JUMP_TABLE_CORE (coff
),
4445 _bfd_xcoff_slurp_armap
,
4446 _bfd_noarchive_slurp_extended_name_table
,
4447 _bfd_noarchive_construct_extended_name_table
,
4448 bfd_dont_truncate_arname
,
4449 _bfd_xcoff_write_armap
,
4450 _bfd_xcoff_read_ar_hdr
,
4451 _bfd_generic_write_ar_hdr
,
4452 _bfd_xcoff_openr_next_archived_file
,
4453 _bfd_generic_get_elt_at_index
,
4454 _bfd_xcoff_stat_arch_elt
,
4458 coff_get_symtab_upper_bound
,
4459 coff_canonicalize_symtab
,
4460 coff_make_empty_symbol
,
4462 coff_get_symbol_info
,
4463 _bfd_xcoff_is_local_label_name
,
4464 coff_bfd_is_target_special_symbol
,
4466 coff_find_nearest_line
,
4467 _bfd_generic_find_line
,
4468 coff_find_inliner_info
,
4469 coff_bfd_make_debug_symbol
,
4470 _bfd_generic_read_minisymbols
,
4471 _bfd_generic_minisymbol_to_symbol
,
4474 coff_get_reloc_upper_bound
,
4475 coff_canonicalize_reloc
,
4476 _bfd_xcoff_reloc_type_lookup
,
4477 _bfd_xcoff_reloc_name_lookup
,
4481 coff_set_section_contents
,
4484 _bfd_xcoff_sizeof_headers
,
4485 bfd_generic_get_relocated_section_contents
,
4486 bfd_generic_relax_section
,
4487 _bfd_xcoff_bfd_link_hash_table_create
,
4488 _bfd_generic_link_hash_table_free
,
4489 _bfd_xcoff_bfd_link_add_symbols
,
4490 _bfd_generic_link_just_syms
,
4491 _bfd_generic_copy_link_hash_symbol_type
,
4492 _bfd_xcoff_bfd_final_link
,
4493 _bfd_generic_link_split_section
,
4494 bfd_generic_gc_sections
,
4495 bfd_generic_merge_sections
,
4496 bfd_generic_is_group_section
,
4497 bfd_generic_discard_group
,
4498 _bfd_generic_section_already_linked
,
4499 _bfd_xcoff_define_common_symbol
,
4502 _bfd_xcoff_get_dynamic_symtab_upper_bound
,
4503 _bfd_xcoff_canonicalize_dynamic_symtab
,
4504 _bfd_nodynamic_get_synthetic_symtab
,
4505 _bfd_xcoff_get_dynamic_reloc_upper_bound
,
4506 _bfd_xcoff_canonicalize_dynamic_reloc
,
4508 /* Opposite endian version, none exists */
4511 (void *) &bfd_pmac_xcoff_backend_data
,