1 /* BFD back-end for IBM RS/6000 "XCOFF" files.
2 Copyright 1990-1999, 2000, 2001, 2002
3 Free Software Foundation, Inc.
4 FIXME: Can someone provide a transliteration of this name into ASCII?
5 Using the following chars caused a compiler warning on HIUX (so I replaced
6 them with octal escapes), and isn't useful without an understanding of what
8 Written by Metin G. Ozisik, Mimi Ph\373\364ng-Th\345o V\365,
10 Archive support from Damon A. Permezel.
11 Contributed by IBM Corporation and Cygnus Support.
13 This file is part of BFD, the Binary File Descriptor library.
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or
18 (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
33 #include "coff/internal.h"
34 #include "coff/xcoff.h"
35 #include "coff/rs6000.h"
39 extern boolean _bfd_xcoff_mkobject
PARAMS ((bfd
*));
40 extern boolean _bfd_xcoff_copy_private_bfd_data
PARAMS ((bfd
*, bfd
*));
41 extern boolean _bfd_xcoff_is_local_label_name
PARAMS ((bfd
*, const char *));
42 extern reloc_howto_type
*_bfd_xcoff_reloc_type_lookup
43 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
44 extern boolean _bfd_xcoff_slurp_armap
PARAMS ((bfd
*));
45 extern const bfd_target
*_bfd_xcoff_archive_p
PARAMS ((bfd
*));
46 extern PTR _bfd_xcoff_read_ar_hdr
PARAMS ((bfd
*));
47 extern bfd
*_bfd_xcoff_openr_next_archived_file
PARAMS ((bfd
*, bfd
*));
48 extern int _bfd_xcoff_stat_arch_elt
PARAMS ((bfd
*, struct stat
*));
49 extern boolean _bfd_xcoff_write_armap
50 PARAMS ((bfd
*, unsigned int, struct orl
*, unsigned int, int));
51 extern boolean _bfd_xcoff_write_archive_contents
PARAMS ((bfd
*));
52 extern int _bfd_xcoff_sizeof_headers
PARAMS ((bfd
*, boolean
));
53 extern void _bfd_xcoff_swap_sym_in
PARAMS ((bfd
*, PTR
, PTR
));
54 extern unsigned int _bfd_xcoff_swap_sym_out
PARAMS ((bfd
*, PTR
, PTR
));
55 extern void _bfd_xcoff_swap_aux_in
PARAMS ((bfd
*, PTR
, int, int, int, int, PTR
));
56 extern unsigned int _bfd_xcoff_swap_aux_out
PARAMS ((bfd
*, PTR
, int, int, int, int, PTR
));
57 static void xcoff_swap_reloc_in
PARAMS ((bfd
*, PTR
, PTR
));
58 static unsigned int xcoff_swap_reloc_out
PARAMS ((bfd
*, PTR
, PTR
));
60 /* Forward declare xcoff_rtype2howto for coffcode.h macro. */
61 void xcoff_rtype2howto
PARAMS ((arelent
*, struct internal_reloc
*));
63 /* coffcode.h needs these to be defined. */
64 #define RS6000COFF_C 1
66 #define SELECT_RELOC(internal, howto) \
68 internal.r_type = howto->type; \
70 ((howto->complain_on_overflow == complain_overflow_signed \
73 | (howto->bitsize - 1)); \
76 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
77 #define COFF_LONG_FILENAMES
78 #define NO_COFF_SYMBOLS
79 #define RTYPE2HOWTO(cache_ptr, dst) xcoff_rtype2howto (cache_ptr, dst)
80 #define coff_mkobject _bfd_xcoff_mkobject
81 #define coff_bfd_copy_private_bfd_data _bfd_xcoff_copy_private_bfd_data
82 #define coff_bfd_is_local_label_name _bfd_xcoff_is_local_label_name
83 #define coff_bfd_reloc_type_lookup _bfd_xcoff_reloc_type_lookup
85 extern const bfd_target
* rs6000coff_core_p
PARAMS ((bfd
*abfd
));
86 extern boolean rs6000coff_core_file_matches_executable_p
87 PARAMS ((bfd
*cbfd
, bfd
*ebfd
));
88 extern char *rs6000coff_core_file_failing_command
PARAMS ((bfd
*abfd
));
89 extern int rs6000coff_core_file_failing_signal
PARAMS ((bfd
*abfd
));
90 #define CORE_FILE_P rs6000coff_core_p
91 #define coff_core_file_failing_command \
92 rs6000coff_core_file_failing_command
93 #define coff_core_file_failing_signal \
94 rs6000coff_core_file_failing_signal
95 #define coff_core_file_matches_executable_p \
96 rs6000coff_core_file_matches_executable_p
98 #define CORE_FILE_P _bfd_dummy_target
99 #define coff_core_file_failing_command \
100 _bfd_nocore_core_file_failing_command
101 #define coff_core_file_failing_signal \
102 _bfd_nocore_core_file_failing_signal
103 #define coff_core_file_matches_executable_p \
104 _bfd_nocore_core_file_matches_executable_p
106 #define coff_SWAP_sym_in _bfd_xcoff_swap_sym_in
107 #define coff_SWAP_sym_out _bfd_xcoff_swap_sym_out
108 #define coff_SWAP_aux_in _bfd_xcoff_swap_aux_in
109 #define coff_SWAP_aux_out _bfd_xcoff_swap_aux_out
110 #define coff_swap_reloc_in xcoff_swap_reloc_in
111 #define coff_swap_reloc_out xcoff_swap_reloc_out
112 #define NO_COFF_RELOCS
114 #include "coffcode.h"
116 /* The main body of code is in coffcode.h. */
118 static const char *normalize_filename
PARAMS ((bfd
*));
119 static boolean xcoff_write_armap_old
120 PARAMS ((bfd
*, unsigned int, struct orl
*, unsigned int, int));
121 static boolean xcoff_write_armap_big
122 PARAMS ((bfd
*, unsigned int, struct orl
*, unsigned int, int));
123 static boolean xcoff_write_archive_contents_old
PARAMS ((bfd
*));
124 static boolean xcoff_write_archive_contents_big
PARAMS ((bfd
*));
125 static void xcoff_swap_ldhdr_in
126 PARAMS ((bfd
*, const PTR
, struct internal_ldhdr
*));
127 static void xcoff_swap_ldhdr_out
128 PARAMS ((bfd
*, const struct internal_ldhdr
*, PTR
));
129 static void xcoff_swap_ldsym_in
130 PARAMS ((bfd
*, const PTR
, struct internal_ldsym
*));
131 static void xcoff_swap_ldsym_out
132 PARAMS ((bfd
*, const struct internal_ldsym
*, PTR
));
133 static void xcoff_swap_ldrel_in
134 PARAMS ((bfd
*, const PTR
, struct internal_ldrel
*));
135 static void xcoff_swap_ldrel_out
136 PARAMS ((bfd
*, const struct internal_ldrel
*, PTR
));
137 static boolean xcoff_ppc_relocate_section
138 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
139 struct internal_reloc
*, struct internal_syment
*, asection
**));
140 static boolean _bfd_xcoff_put_ldsymbol_name
141 PARAMS ((bfd
*, struct xcoff_loader_info
*, struct internal_ldsym
*,
143 static asection
*xcoff_create_csect_from_smclas
144 PARAMS ((bfd
*, union internal_auxent
*, const char *));
145 static boolean xcoff_is_lineno_count_overflow
PARAMS ((bfd
*, bfd_vma
));
146 static boolean xcoff_is_reloc_count_overflow
PARAMS ((bfd
*, bfd_vma
));
147 static bfd_vma xcoff_loader_symbol_offset
148 PARAMS ((bfd
*, struct internal_ldhdr
*));
149 static bfd_vma xcoff_loader_reloc_offset
150 PARAMS ((bfd
*, struct internal_ldhdr
*));
151 static boolean xcoff_generate_rtinit
152 PARAMS((bfd
*, const char *, const char *, boolean
));
153 static boolean do_pad
PARAMS((bfd
*, unsigned int));
154 static boolean do_copy
PARAMS((bfd
*, bfd
*));
155 static boolean do_shared_object_padding
PARAMS ((bfd
*, bfd
*, ufile_ptr
*, int));
157 /* Relocation functions */
158 static boolean xcoff_reloc_type_noop
PARAMS ((XCOFF_RELOC_FUNCTION_ARGS
));
159 static boolean xcoff_reloc_type_fail
PARAMS ((XCOFF_RELOC_FUNCTION_ARGS
));
160 static boolean xcoff_reloc_type_pos
PARAMS ((XCOFF_RELOC_FUNCTION_ARGS
));
161 static boolean xcoff_reloc_type_neg
PARAMS ((XCOFF_RELOC_FUNCTION_ARGS
));
162 static boolean xcoff_reloc_type_rel
PARAMS ((XCOFF_RELOC_FUNCTION_ARGS
));
163 static boolean xcoff_reloc_type_toc
PARAMS ((XCOFF_RELOC_FUNCTION_ARGS
));
164 static boolean xcoff_reloc_type_ba
PARAMS ((XCOFF_RELOC_FUNCTION_ARGS
));
165 static boolean xcoff_reloc_type_br
PARAMS ((XCOFF_RELOC_FUNCTION_ARGS
));
166 static boolean xcoff_reloc_type_crel
PARAMS ((XCOFF_RELOC_FUNCTION_ARGS
));
168 static boolean xcoff_complain_overflow_dont_func
169 PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS
));
170 static boolean xcoff_complain_overflow_bitfield_func
171 PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS
));
172 static boolean xcoff_complain_overflow_signed_func
173 PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS
));
174 static boolean xcoff_complain_overflow_unsigned_func
175 PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS
));
177 boolean (*xcoff_calculate_relocation
[XCOFF_MAX_CALCULATE_RELOCATION
])
178 (XCOFF_RELOC_FUNCTION_ARGS
) =
180 xcoff_reloc_type_pos
, /* R_POS (0x00) */
181 xcoff_reloc_type_neg
, /* R_NEG (0x01) */
182 xcoff_reloc_type_rel
, /* R_REL (0x02) */
183 xcoff_reloc_type_toc
, /* R_TOC (0x03) */
184 xcoff_reloc_type_fail
, /* R_RTB (0x04) */
185 xcoff_reloc_type_toc
, /* R_GL (0x05) */
186 xcoff_reloc_type_toc
, /* R_TCL (0x06) */
187 xcoff_reloc_type_fail
, /* (0x07) */
188 xcoff_reloc_type_ba
, /* R_BA (0x08) */
189 xcoff_reloc_type_fail
, /* (0x09) */
190 xcoff_reloc_type_br
, /* R_BR (0x0a) */
191 xcoff_reloc_type_fail
, /* (0x0b) */
192 xcoff_reloc_type_pos
, /* R_RL (0x0c) */
193 xcoff_reloc_type_pos
, /* R_RLA (0x0d) */
194 xcoff_reloc_type_fail
, /* (0x0e) */
195 xcoff_reloc_type_noop
, /* R_REF (0x0f) */
196 xcoff_reloc_type_fail
, /* (0x10) */
197 xcoff_reloc_type_fail
, /* (0x11) */
198 xcoff_reloc_type_toc
, /* R_TRL (0x12) */
199 xcoff_reloc_type_toc
, /* R_TRLA (0x13) */
200 xcoff_reloc_type_fail
, /* R_RRTBI (0x14) */
201 xcoff_reloc_type_fail
, /* R_RRTBA (0x15) */
202 xcoff_reloc_type_ba
, /* R_CAI (0x16) */
203 xcoff_reloc_type_crel
, /* R_CREL (0x17) */
204 xcoff_reloc_type_ba
, /* R_RBA (0x18) */
205 xcoff_reloc_type_ba
, /* R_RBAC (0x19) */
206 xcoff_reloc_type_br
, /* R_RBR (0x1a) */
207 xcoff_reloc_type_ba
, /* R_RBRC (0x1b) */
210 boolean (*xcoff_complain_overflow
[XCOFF_MAX_COMPLAIN_OVERFLOW
])
211 (XCOFF_COMPLAIN_FUNCTION_ARGS
) =
213 xcoff_complain_overflow_dont_func
,
214 xcoff_complain_overflow_bitfield_func
,
215 xcoff_complain_overflow_signed_func
,
216 xcoff_complain_overflow_unsigned_func
,
219 /* We use our own tdata type. Its first field is the COFF tdata type,
220 so the COFF routines are compatible. */
223 _bfd_xcoff_mkobject (abfd
)
226 coff_data_type
*coff
;
227 bfd_size_type amt
= sizeof (struct xcoff_tdata
);
229 abfd
->tdata
.xcoff_obj_data
= (struct xcoff_tdata
*) bfd_zalloc (abfd
, amt
);
230 if (abfd
->tdata
.xcoff_obj_data
== NULL
)
232 coff
= coff_data (abfd
);
233 coff
->symbols
= (coff_symbol_type
*) NULL
;
234 coff
->conversion_table
= (unsigned int *) NULL
;
235 coff
->raw_syments
= (struct coff_ptr_struct
*) NULL
;
238 xcoff_data (abfd
)->modtype
= ('1' << 8) | 'L';
240 /* We set cputype to -1 to indicate that it has not been
242 xcoff_data (abfd
)->cputype
= -1;
244 xcoff_data (abfd
)->csects
= NULL
;
245 xcoff_data (abfd
)->debug_indices
= NULL
;
247 /* text section alignment is different than the default */
248 /* xcoff_data (abfd)->text_align_power = 5; */
253 /* Copy XCOFF data from one BFD to another. */
256 _bfd_xcoff_copy_private_bfd_data (ibfd
, obfd
)
260 struct xcoff_tdata
*ix
, *ox
;
263 if (ibfd
->xvec
!= obfd
->xvec
)
265 ix
= xcoff_data (ibfd
);
266 ox
= xcoff_data (obfd
);
267 ox
->full_aouthdr
= ix
->full_aouthdr
;
273 sec
= coff_section_from_bfd_index (ibfd
, ix
->sntoc
);
277 ox
->sntoc
= sec
->output_section
->target_index
;
279 if (ix
->snentry
== 0)
283 sec
= coff_section_from_bfd_index (ibfd
, ix
->snentry
);
287 ox
->snentry
= sec
->output_section
->target_index
;
289 ox
->text_align_power
= ix
->text_align_power
;
290 ox
->data_align_power
= ix
->data_align_power
;
291 ox
->modtype
= ix
->modtype
;
292 ox
->cputype
= ix
->cputype
;
293 ox
->maxdata
= ix
->maxdata
;
294 ox
->maxstack
= ix
->maxstack
;
298 /* I don't think XCOFF really has a notion of local labels based on
299 name. This will mean that ld -X doesn't actually strip anything.
300 The AIX native linker does not have a -X option, and it ignores the
304 _bfd_xcoff_is_local_label_name (abfd
, name
)
305 bfd
*abfd ATTRIBUTE_UNUSED
;
306 const char *name ATTRIBUTE_UNUSED
;
312 _bfd_xcoff_swap_sym_in (abfd
, ext1
, in1
)
317 SYMENT
*ext
= (SYMENT
*)ext1
;
318 struct internal_syment
* in
= (struct internal_syment
*)in1
;
320 if (ext
->e
.e_name
[0] != 0)
322 memcpy(in
->_n
._n_name
, ext
->e
.e_name
, SYMNMLEN
);
326 in
->_n
._n_n
._n_zeroes
= 0;
327 in
->_n
._n_n
._n_offset
= H_GET_32 (abfd
, ext
->e
.e
.e_offset
);
330 in
->n_value
= H_GET_32 (abfd
, ext
->e_value
);
331 in
->n_scnum
= H_GET_16 (abfd
, ext
->e_scnum
);
332 in
->n_type
= H_GET_16 (abfd
, ext
->e_type
);
333 in
->n_sclass
= H_GET_8 (abfd
, ext
->e_sclass
);
334 in
->n_numaux
= H_GET_8 (abfd
, ext
->e_numaux
);
338 _bfd_xcoff_swap_sym_out (abfd
, inp
, extp
)
343 struct internal_syment
*in
= (struct internal_syment
*)inp
;
344 SYMENT
*ext
=(SYMENT
*)extp
;
346 if (in
->_n
._n_name
[0] != 0)
348 memcpy(ext
->e
.e_name
, in
->_n
._n_name
, SYMNMLEN
);
352 H_PUT_32 (abfd
, 0, ext
->e
.e
.e_zeroes
);
353 H_PUT_32 (abfd
, in
->_n
._n_n
._n_offset
, ext
->e
.e
.e_offset
);
356 H_PUT_32 (abfd
, in
->n_value
, ext
->e_value
);
357 H_PUT_16 (abfd
, in
->n_scnum
, ext
->e_scnum
);
358 H_PUT_16 (abfd
, in
->n_type
, ext
->e_type
);
359 H_PUT_8 (abfd
, in
->n_sclass
, ext
->e_sclass
);
360 H_PUT_8 (abfd
, in
->n_numaux
, ext
->e_numaux
);
361 return bfd_coff_symesz (abfd
);
365 _bfd_xcoff_swap_aux_in (abfd
, ext1
, type
, class, indx
, numaux
, in1
)
374 AUXENT
* ext
= (AUXENT
*)ext1
;
375 union internal_auxent
*in
= (union internal_auxent
*)in1
;
380 if (ext
->x_file
.x_fname
[0] == 0)
382 in
->x_file
.x_n
.x_zeroes
= 0;
383 in
->x_file
.x_n
.x_offset
=
384 H_GET_32 (abfd
, ext
->x_file
.x_n
.x_offset
);
391 memcpy (in
->x_file
.x_fname
, ext
->x_file
.x_fname
,
392 numaux
* sizeof (AUXENT
));
396 memcpy (in
->x_file
.x_fname
, ext
->x_file
.x_fname
, FILNMLEN
);
401 /* RS/6000 "csect" auxents */
404 if (indx
+ 1 == numaux
)
406 in
->x_csect
.x_scnlen
.l
= H_GET_32 (abfd
, ext
->x_csect
.x_scnlen
);
407 in
->x_csect
.x_parmhash
= H_GET_32 (abfd
, ext
->x_csect
.x_parmhash
);
408 in
->x_csect
.x_snhash
= H_GET_16 (abfd
, ext
->x_csect
.x_snhash
);
409 /* We don't have to hack bitfields in x_smtyp because it's
410 defined by shifts-and-ands, which are equivalent on all
412 in
->x_csect
.x_smtyp
= H_GET_8 (abfd
, ext
->x_csect
.x_smtyp
);
413 in
->x_csect
.x_smclas
= H_GET_8 (abfd
, ext
->x_csect
.x_smclas
);
414 in
->x_csect
.x_stab
= H_GET_32 (abfd
, ext
->x_csect
.x_stab
);
415 in
->x_csect
.x_snstab
= H_GET_16 (abfd
, ext
->x_csect
.x_snstab
);
425 in
->x_scn
.x_scnlen
= H_GET_32 (abfd
, ext
->x_scn
.x_scnlen
);
426 in
->x_scn
.x_nreloc
= H_GET_16 (abfd
, ext
->x_scn
.x_nreloc
);
427 in
->x_scn
.x_nlinno
= H_GET_16 (abfd
, ext
->x_scn
.x_nlinno
);
428 /* PE defines some extra fields; we zero them out for
430 in
->x_scn
.x_checksum
= 0;
431 in
->x_scn
.x_associated
= 0;
432 in
->x_scn
.x_comdat
= 0;
439 in
->x_sym
.x_tagndx
.l
= H_GET_32 (abfd
, ext
->x_sym
.x_tagndx
);
440 in
->x_sym
.x_tvndx
= H_GET_16 (abfd
, ext
->x_sym
.x_tvndx
);
442 if (class == C_BLOCK
|| class == C_FCN
|| ISFCN (type
) || ISTAG (class))
444 in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
=
445 H_GET_32 (abfd
, ext
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
446 in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
=
447 H_GET_32 (abfd
, ext
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
451 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0] =
452 H_GET_16 (abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
453 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1] =
454 H_GET_16 (abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
455 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2] =
456 H_GET_16 (abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
457 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3] =
458 H_GET_16 (abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
463 in
->x_sym
.x_misc
.x_fsize
= H_GET_32 (abfd
, ext
->x_sym
.x_misc
.x_fsize
);
467 in
->x_sym
.x_misc
.x_lnsz
.x_lnno
=
468 H_GET_16 (abfd
, ext
->x_sym
.x_misc
.x_lnsz
.x_lnno
);
469 in
->x_sym
.x_misc
.x_lnsz
.x_size
=
470 H_GET_16 (abfd
, ext
->x_sym
.x_misc
.x_lnsz
.x_size
);
474 /* The semicolon is because MSVC doesn't like labels at
479 unsigned int _bfd_xcoff_swap_aux_out
PARAMS ((bfd
*, PTR
, int, int, int, int, PTR
));
482 _bfd_xcoff_swap_aux_out (abfd
, inp
, type
, class, indx
, numaux
, extp
)
487 int indx ATTRIBUTE_UNUSED
;
488 int numaux ATTRIBUTE_UNUSED
;
491 union internal_auxent
*in
= (union internal_auxent
*)inp
;
492 AUXENT
*ext
= (AUXENT
*)extp
;
494 memset((PTR
)ext
, 0, bfd_coff_auxesz (abfd
));
498 if (in
->x_file
.x_fname
[0] == 0)
500 H_PUT_32 (abfd
, 0, ext
->x_file
.x_n
.x_zeroes
);
501 H_PUT_32 (abfd
, in
->x_file
.x_n
.x_offset
, ext
->x_file
.x_n
.x_offset
);
505 memcpy (ext
->x_file
.x_fname
, in
->x_file
.x_fname
, FILNMLEN
);
509 /* RS/6000 "csect" auxents */
512 if (indx
+ 1 == numaux
)
514 H_PUT_32 (abfd
, in
->x_csect
.x_scnlen
.l
, ext
->x_csect
.x_scnlen
);
515 H_PUT_32 (abfd
, in
->x_csect
.x_parmhash
, ext
->x_csect
.x_parmhash
);
516 H_PUT_16 (abfd
, in
->x_csect
.x_snhash
, ext
->x_csect
.x_snhash
);
517 /* We don't have to hack bitfields in x_smtyp because it's
518 defined by shifts-and-ands, which are equivalent on all
520 H_PUT_8 (abfd
, in
->x_csect
.x_smtyp
, ext
->x_csect
.x_smtyp
);
521 H_PUT_8 (abfd
, in
->x_csect
.x_smclas
, ext
->x_csect
.x_smclas
);
522 H_PUT_32 (abfd
, in
->x_csect
.x_stab
, ext
->x_csect
.x_stab
);
523 H_PUT_16 (abfd
, in
->x_csect
.x_snstab
, ext
->x_csect
.x_snstab
);
533 H_PUT_32 (abfd
, in
->x_scn
.x_scnlen
, ext
->x_scn
.x_scnlen
);
534 H_PUT_16 (abfd
, in
->x_scn
.x_nreloc
, ext
->x_scn
.x_nreloc
);
535 H_PUT_16 (abfd
, in
->x_scn
.x_nlinno
, ext
->x_scn
.x_nlinno
);
541 H_PUT_32 (abfd
, in
->x_sym
.x_tagndx
.l
, ext
->x_sym
.x_tagndx
);
542 H_PUT_16 (abfd
, in
->x_sym
.x_tvndx
, ext
->x_sym
.x_tvndx
);
544 if (class == C_BLOCK
|| class == C_FCN
|| ISFCN (type
) || ISTAG (class))
546 H_PUT_32 (abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
,
547 ext
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
548 H_PUT_32 (abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
,
549 ext
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
553 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0],
554 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
555 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1],
556 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
557 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2],
558 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
559 H_PUT_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3],
560 ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
564 H_PUT_32 (abfd
, in
->x_sym
.x_misc
.x_fsize
, ext
->x_sym
.x_misc
.x_fsize
);
567 H_PUT_16 (abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_lnno
,
568 ext
->x_sym
.x_misc
.x_lnsz
.x_lnno
);
569 H_PUT_16 (abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_size
,
570 ext
->x_sym
.x_misc
.x_lnsz
.x_size
);
574 return bfd_coff_auxesz (abfd
);
579 /* The XCOFF reloc table. Actually, XCOFF relocations specify the
580 bitsize and whether they are signed or not, along with a
581 conventional type. This table is for the types, which are used for
582 different algorithms for putting in the reloc. Many of these
583 relocs need special_function entries, which I have not written. */
586 reloc_howto_type xcoff_howto_table
[] =
588 /* Standard 32 bit relocation. */
589 HOWTO (R_POS
, /* type */
591 2, /* size (0 = byte, 1 = short, 2 = long) */
593 false, /* pc_relative */
595 complain_overflow_bitfield
, /* complain_on_overflow */
596 0, /* special_function */
598 true, /* partial_inplace */
599 0xffffffff, /* src_mask */
600 0xffffffff, /* dst_mask */
601 false), /* pcrel_offset */
603 /* 32 bit relocation, but store negative value. */
604 HOWTO (R_NEG
, /* type */
606 -2, /* size (0 = byte, 1 = short, 2 = long) */
608 false, /* pc_relative */
610 complain_overflow_bitfield
, /* complain_on_overflow */
611 0, /* special_function */
613 true, /* partial_inplace */
614 0xffffffff, /* src_mask */
615 0xffffffff, /* dst_mask */
616 false), /* pcrel_offset */
618 /* 32 bit PC relative relocation. */
619 HOWTO (R_REL
, /* type */
621 2, /* size (0 = byte, 1 = short, 2 = long) */
623 true, /* pc_relative */
625 complain_overflow_signed
, /* complain_on_overflow */
626 0, /* special_function */
628 true, /* partial_inplace */
629 0xffffffff, /* src_mask */
630 0xffffffff, /* dst_mask */
631 false), /* pcrel_offset */
633 /* 16 bit TOC relative relocation. */
634 HOWTO (R_TOC
, /* type */
636 1, /* size (0 = byte, 1 = short, 2 = long) */
638 false, /* pc_relative */
640 complain_overflow_bitfield
, /* complain_on_overflow */
641 0, /* special_function */
643 true, /* partial_inplace */
644 0xffff, /* src_mask */
645 0xffff, /* dst_mask */
646 false), /* pcrel_offset */
648 /* I don't really know what this is. */
649 HOWTO (R_RTB
, /* type */
651 2, /* size (0 = byte, 1 = short, 2 = long) */
653 false, /* pc_relative */
655 complain_overflow_bitfield
, /* complain_on_overflow */
656 0, /* special_function */
658 true, /* partial_inplace */
659 0xffffffff, /* src_mask */
660 0xffffffff, /* dst_mask */
661 false), /* pcrel_offset */
663 /* External TOC relative symbol. */
664 HOWTO (R_GL
, /* type */
666 2, /* size (0 = byte, 1 = short, 2 = long) */
668 false, /* pc_relative */
670 complain_overflow_bitfield
, /* complain_on_overflow */
671 0, /* special_function */
673 true, /* partial_inplace */
674 0xffff, /* src_mask */
675 0xffff, /* dst_mask */
676 false), /* pcrel_offset */
678 /* Local TOC relative symbol. */
679 HOWTO (R_TCL
, /* type */
681 2, /* size (0 = byte, 1 = short, 2 = long) */
683 false, /* pc_relative */
685 complain_overflow_bitfield
, /* complain_on_overflow */
686 0, /* special_function */
688 true, /* partial_inplace */
689 0xffff, /* src_mask */
690 0xffff, /* dst_mask */
691 false), /* pcrel_offset */
695 /* Non modifiable absolute branch. */
696 HOWTO (R_BA
, /* type */
698 2, /* size (0 = byte, 1 = short, 2 = long) */
700 false, /* pc_relative */
702 complain_overflow_bitfield
, /* complain_on_overflow */
703 0, /* special_function */
704 "R_BA_26", /* name */
705 true, /* partial_inplace */
706 0x3fffffc, /* src_mask */
707 0x3fffffc, /* dst_mask */
708 false), /* pcrel_offset */
712 /* Non modifiable relative branch. */
713 HOWTO (R_BR
, /* type */
715 2, /* size (0 = byte, 1 = short, 2 = long) */
717 true, /* pc_relative */
719 complain_overflow_signed
, /* complain_on_overflow */
720 0, /* special_function */
722 true, /* partial_inplace */
723 0x3fffffc, /* src_mask */
724 0x3fffffc, /* dst_mask */
725 false), /* pcrel_offset */
730 HOWTO (R_RL
, /* type */
732 2, /* size (0 = byte, 1 = short, 2 = long) */
734 false, /* pc_relative */
736 complain_overflow_bitfield
, /* complain_on_overflow */
737 0, /* special_function */
739 true, /* partial_inplace */
740 0xffff, /* src_mask */
741 0xffff, /* dst_mask */
742 false), /* pcrel_offset */
745 HOWTO (R_RLA
, /* type */
747 2, /* size (0 = byte, 1 = short, 2 = long) */
749 false, /* pc_relative */
751 complain_overflow_bitfield
, /* complain_on_overflow */
752 0, /* special_function */
754 true, /* partial_inplace */
755 0xffff, /* src_mask */
756 0xffff, /* dst_mask */
757 false), /* pcrel_offset */
761 /* Non-relocating reference. */
762 HOWTO (R_REF
, /* type */
764 2, /* size (0 = byte, 1 = short, 2 = long) */
766 false, /* pc_relative */
768 complain_overflow_bitfield
, /* complain_on_overflow */
769 0, /* special_function */
771 false, /* partial_inplace */
774 false), /* pcrel_offset */
779 /* TOC relative indirect load. */
780 HOWTO (R_TRL
, /* type */
782 2, /* size (0 = byte, 1 = short, 2 = long) */
784 false, /* pc_relative */
786 complain_overflow_bitfield
, /* complain_on_overflow */
787 0, /* special_function */
789 true, /* partial_inplace */
790 0xffff, /* src_mask */
791 0xffff, /* dst_mask */
792 false), /* pcrel_offset */
794 /* TOC relative load address. */
795 HOWTO (R_TRLA
, /* type */
797 2, /* size (0 = byte, 1 = short, 2 = long) */
799 false, /* pc_relative */
801 complain_overflow_bitfield
, /* complain_on_overflow */
802 0, /* special_function */
804 true, /* partial_inplace */
805 0xffff, /* src_mask */
806 0xffff, /* dst_mask */
807 false), /* pcrel_offset */
809 /* Modifiable relative branch. */
810 HOWTO (R_RRTBI
, /* type */
812 2, /* size (0 = byte, 1 = short, 2 = long) */
814 false, /* pc_relative */
816 complain_overflow_bitfield
, /* complain_on_overflow */
817 0, /* special_function */
818 "R_RRTBI", /* name */
819 true, /* partial_inplace */
820 0xffffffff, /* src_mask */
821 0xffffffff, /* dst_mask */
822 false), /* pcrel_offset */
824 /* Modifiable absolute branch. */
825 HOWTO (R_RRTBA
, /* type */
827 2, /* size (0 = byte, 1 = short, 2 = long) */
829 false, /* pc_relative */
831 complain_overflow_bitfield
, /* complain_on_overflow */
832 0, /* special_function */
833 "R_RRTBA", /* name */
834 true, /* partial_inplace */
835 0xffffffff, /* src_mask */
836 0xffffffff, /* dst_mask */
837 false), /* pcrel_offset */
839 /* Modifiable call absolute indirect. */
840 HOWTO (R_CAI
, /* type */
842 2, /* size (0 = byte, 1 = short, 2 = long) */
844 false, /* pc_relative */
846 complain_overflow_bitfield
, /* complain_on_overflow */
847 0, /* special_function */
849 true, /* partial_inplace */
850 0xffff, /* src_mask */
851 0xffff, /* dst_mask */
852 false), /* pcrel_offset */
854 /* Modifiable call relative. */
855 HOWTO (R_CREL
, /* type */
857 2, /* size (0 = byte, 1 = short, 2 = long) */
859 false, /* pc_relative */
861 complain_overflow_bitfield
, /* complain_on_overflow */
862 0, /* special_function */
864 true, /* partial_inplace */
865 0xffff, /* src_mask */
866 0xffff, /* dst_mask */
867 false), /* pcrel_offset */
869 /* Modifiable branch absolute. */
870 HOWTO (R_RBA
, /* type */
872 2, /* size (0 = byte, 1 = short, 2 = long) */
874 false, /* pc_relative */
876 complain_overflow_bitfield
, /* complain_on_overflow */
877 0, /* special_function */
879 true, /* partial_inplace */
880 0xffff, /* src_mask */
881 0xffff, /* dst_mask */
882 false), /* pcrel_offset */
884 /* Modifiable branch absolute. */
885 HOWTO (R_RBAC
, /* type */
887 2, /* size (0 = byte, 1 = short, 2 = long) */
889 false, /* pc_relative */
891 complain_overflow_bitfield
, /* complain_on_overflow */
892 0, /* special_function */
894 true, /* partial_inplace */
895 0xffff, /* src_mask */
896 0xffff, /* dst_mask */
897 false), /* pcrel_offset */
899 /* Modifiable branch relative. */
900 HOWTO (R_RBR
, /* type */
902 2, /* size (0 = byte, 1 = short, 2 = long) */
904 false, /* pc_relative */
906 complain_overflow_signed
, /* complain_on_overflow */
907 0, /* special_function */
908 "R_RBR_26", /* name */
909 true, /* partial_inplace */
910 0xffff, /* src_mask */
911 0xffff, /* dst_mask */
912 false), /* pcrel_offset */
914 /* Modifiable branch absolute. */
915 HOWTO (R_RBRC
, /* type */
917 2, /* size (0 = byte, 1 = short, 2 = long) */
919 false, /* pc_relative */
921 complain_overflow_bitfield
, /* complain_on_overflow */
922 0, /* special_function */
924 true, /* partial_inplace */
925 0xffff, /* src_mask */
926 0xffff, /* dst_mask */
927 false), /* pcrel_offset */
929 /* 16 bit Non modifiable absolute branch. */
930 HOWTO (R_BA
, /* type */
932 1, /* size (0 = byte, 1 = short, 2 = long) */
934 false, /* pc_relative */
936 complain_overflow_bitfield
, /* complain_on_overflow */
937 0, /* special_function */
938 "R_BA_16", /* name */
939 true, /* partial_inplace */
940 0xfffc, /* src_mask */
941 0xfffc, /* dst_mask */
942 false), /* pcrel_offset */
944 /* Modifiable branch relative. */
945 HOWTO (R_RBR
, /* type */
947 1, /* size (0 = byte, 1 = short, 2 = long) */
949 false, /* pc_relative */
951 complain_overflow_signed
, /* complain_on_overflow */
952 0, /* special_function */
953 "R_RBR_16", /* name */
954 true, /* partial_inplace */
955 0xffff, /* src_mask */
956 0xffff, /* dst_mask */
957 false), /* pcrel_offset */
962 xcoff_rtype2howto (relent
, internal
)
964 struct internal_reloc
*internal
;
966 if (internal
->r_type
> R_RBRC
)
969 /* Default howto layout works most of the time */
970 relent
->howto
= &xcoff_howto_table
[internal
->r_type
];
972 /* Special case some 16 bit reoloc */
973 if (15 == (internal
->r_size
& 0x1f))
975 if (R_BA
== internal
->r_type
)
976 relent
->howto
= &xcoff_howto_table
[0x1c];
977 else if (R_RBR
== internal
->r_type
)
978 relent
->howto
= &xcoff_howto_table
[0x1d];
981 /* The r_size field of an XCOFF reloc encodes the bitsize of the
982 relocation, as well as indicating whether it is signed or not.
983 Doublecheck that the relocation information gathered from the
984 type matches this information. The bitsize is not significant
986 if (relent
->howto
->dst_mask
!= 0
987 && (relent
->howto
->bitsize
988 != ((unsigned int) internal
->r_size
& 0x1f) + 1))
991 /* Put a meaningful value in addend */
992 relent
->addend
= (internal
->r_size
& 0x80) ? - internal
->r_vaddr
997 _bfd_xcoff_reloc_type_lookup (abfd
, code
)
998 bfd
*abfd ATTRIBUTE_UNUSED
;
999 bfd_reloc_code_real_type code
;
1003 case BFD_RELOC_PPC_B26
:
1004 return &xcoff_howto_table
[0xa];
1005 case BFD_RELOC_PPC_BA16
:
1006 return &xcoff_howto_table
[0x1c];
1007 case BFD_RELOC_PPC_BA26
:
1008 return &xcoff_howto_table
[8];
1009 case BFD_RELOC_PPC_TOC16
:
1010 return &xcoff_howto_table
[3];
1012 case BFD_RELOC_CTOR
:
1013 return &xcoff_howto_table
[0];
1020 /* XCOFF archive support. The original version of this code was by
1021 Damon A. Permezel. It was enhanced to permit cross support, and
1022 writing archive files, by Ian Lance Taylor, Cygnus Support.
1024 XCOFF uses its own archive format. Everything is hooked together
1025 with file offset links, so it is possible to rapidly update an
1026 archive in place. Of course, we don't do that. An XCOFF archive
1027 has a real file header, not just an ARMAG string. The structure of
1028 the file header and of each archive header appear below.
1030 An XCOFF archive also has a member table, which is a list of
1031 elements in the archive (you can get that by looking through the
1032 linked list, but you have to read a lot more of the file). The
1033 member table has a normal archive header with an empty name. It is
1034 normally (and perhaps must be) the second to last entry in the
1035 archive. The member table data is almost printable ASCII. It
1036 starts with a 12 character decimal string which is the number of
1037 entries in the table. For each entry it has a 12 character decimal
1038 string which is the offset in the archive of that member. These
1039 entries are followed by a series of null terminated strings which
1040 are the member names for each entry.
1042 Finally, an XCOFF archive has a global symbol table, which is what
1043 we call the armap. The global symbol table has a normal archive
1044 header with an empty name. It is normally (and perhaps must be)
1045 the last entry in the archive. The contents start with a four byte
1046 binary number which is the number of entries. This is followed by
1047 a that many four byte binary numbers; each is the file offset of an
1048 entry in the archive. These numbers are followed by a series of
1049 null terminated strings, which are symbol names.
1051 AIX 4.3 introduced a new archive format which can handle larger
1052 files and also 32- and 64-bit objects in the same archive. The
1053 things said above remain true except that there is now more than
1054 one global symbol table. The one is used to index 32-bit objects,
1055 the other for 64-bit objects.
1057 The new archives (recognizable by the new ARMAG string) has larger
1058 field lengths so that we cannot really share any code. Also we have
1059 to take care that we are not generating the new form of archives
1060 on AIX 4.2 or earlier systems. */
1062 /* XCOFF archives use this as a magic string. Note that both strings
1063 have the same length. */
1065 /* Set the magic for archive. */
1068 bfd_xcoff_ar_archive_set_magic (abfd
, magic
)
1069 bfd
*abfd ATTRIBUTE_UNUSED
;
1070 char *magic ATTRIBUTE_UNUSED
;
1072 /* Not supported yet. */
1074 /* bfd_xcoff_archive_set_magic (abfd, magic); */
1077 /* Read in the armap of an XCOFF archive. */
1080 _bfd_xcoff_slurp_armap (abfd
)
1086 bfd_byte
*contents
, *cend
;
1091 if (xcoff_ardata (abfd
) == NULL
)
1093 bfd_has_map (abfd
) = false;
1097 if (! xcoff_big_format_p (abfd
))
1099 /* This is for the old format. */
1100 struct xcoff_ar_hdr hdr
;
1102 off
= strtol (xcoff_ardata (abfd
)->symoff
, (char **) NULL
, 10);
1105 bfd_has_map (abfd
) = false;
1109 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0)
1112 /* The symbol table starts with a normal archive header. */
1113 if (bfd_bread ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1117 /* Skip the name (normally empty). */
1118 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1119 off
= ((namlen
+ 1) & ~ (size_t) 1) + SXCOFFARFMAG
;
1120 if (bfd_seek (abfd
, off
, SEEK_CUR
) != 0)
1123 sz
= strtol (hdr
.size
, (char **) NULL
, 10);
1125 /* Read in the entire symbol table. */
1126 contents
= (bfd_byte
*) bfd_alloc (abfd
, sz
);
1127 if (contents
== NULL
)
1129 if (bfd_bread ((PTR
) contents
, sz
, abfd
) != sz
)
1132 /* The symbol table starts with a four byte count. */
1133 c
= H_GET_32 (abfd
, contents
);
1137 bfd_set_error (bfd_error_bad_value
);
1141 bfd_ardata (abfd
)->symdefs
=
1142 ((carsym
*) bfd_alloc (abfd
, c
* sizeof (carsym
)));
1143 if (bfd_ardata (abfd
)->symdefs
== NULL
)
1146 /* After the count comes a list of four byte file offsets. */
1147 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
, p
= contents
+ 4;
1149 ++i
, ++arsym
, p
+= 4)
1150 arsym
->file_offset
= H_GET_32 (abfd
, p
);
1154 /* This is for the new format. */
1155 struct xcoff_ar_hdr_big hdr
;
1157 off
= strtol (xcoff_ardata_big (abfd
)->symoff
, (char **) NULL
, 10);
1160 bfd_has_map (abfd
) = false;
1164 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0)
1167 /* The symbol table starts with a normal archive header. */
1168 if (bfd_bread ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR_BIG
, abfd
)
1169 != SIZEOF_AR_HDR_BIG
)
1172 /* Skip the name (normally empty). */
1173 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1174 off
= ((namlen
+ 1) & ~ (size_t) 1) + SXCOFFARFMAG
;
1175 if (bfd_seek (abfd
, off
, SEEK_CUR
) != 0)
1178 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1179 machines) since the field width is 20 and there numbers with more
1180 than 32 bits can be represented. */
1181 sz
= strtol (hdr
.size
, (char **) NULL
, 10);
1183 /* Read in the entire symbol table. */
1184 contents
= (bfd_byte
*) bfd_alloc (abfd
, sz
);
1185 if (contents
== NULL
)
1187 if (bfd_bread ((PTR
) contents
, sz
, abfd
) != sz
)
1190 /* The symbol table starts with an eight byte count. */
1191 c
= H_GET_64 (abfd
, contents
);
1195 bfd_set_error (bfd_error_bad_value
);
1199 bfd_ardata (abfd
)->symdefs
=
1200 ((carsym
*) bfd_alloc (abfd
, c
* sizeof (carsym
)));
1201 if (bfd_ardata (abfd
)->symdefs
== NULL
)
1204 /* After the count comes a list of eight byte file offsets. */
1205 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
, p
= contents
+ 8;
1207 ++i
, ++arsym
, p
+= 8)
1208 arsym
->file_offset
= H_GET_64 (abfd
, p
);
1211 /* After the file offsets come null terminated symbol names. */
1212 cend
= contents
+ sz
;
1213 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
;
1215 ++i
, ++arsym
, p
+= strlen ((char *) p
) + 1)
1219 bfd_set_error (bfd_error_bad_value
);
1222 arsym
->name
= (char *) p
;
1225 bfd_ardata (abfd
)->symdef_count
= c
;
1226 bfd_has_map (abfd
) = true;
1231 /* See if this is an XCOFF archive. */
1234 _bfd_xcoff_archive_p (abfd
)
1237 char magic
[SXCOFFARMAG
];
1240 if (bfd_bread ((PTR
) magic
, (bfd_size_type
) SXCOFFARMAG
, abfd
) != SXCOFFARMAG
)
1242 if (bfd_get_error () != bfd_error_system_call
)
1243 bfd_set_error (bfd_error_wrong_format
);
1247 if (strncmp (magic
, XCOFFARMAG
, SXCOFFARMAG
) != 0
1248 && strncmp (magic
, XCOFFARMAGBIG
, SXCOFFARMAG
) != 0)
1250 bfd_set_error (bfd_error_wrong_format
);
1254 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
1255 involves a cast, we can't do it as the left operand of
1257 amt
= sizeof (struct artdata
);
1258 abfd
->tdata
.aout_ar_data
= (struct artdata
*) bfd_zalloc (abfd
, amt
);
1259 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
1262 bfd_ardata (abfd
)->cache
= NULL
;
1263 bfd_ardata (abfd
)->archive_head
= NULL
;
1264 bfd_ardata (abfd
)->symdefs
= NULL
;
1265 bfd_ardata (abfd
)->extended_names
= NULL
;
1267 /* Now handle the two formats. */
1268 if (magic
[1] != 'b')
1270 /* This is the old format. */
1271 struct xcoff_ar_file_hdr hdr
;
1273 /* Copy over the magic string. */
1274 memcpy (hdr
.magic
, magic
, SXCOFFARMAG
);
1276 /* Now read the rest of the file header. */
1277 if (bfd_bread ((PTR
) &hdr
.memoff
,
1278 (bfd_size_type
) SIZEOF_AR_FILE_HDR
- SXCOFFARMAG
, abfd
)
1279 != SIZEOF_AR_FILE_HDR
- SXCOFFARMAG
)
1281 if (bfd_get_error () != bfd_error_system_call
)
1282 bfd_set_error (bfd_error_wrong_format
);
1286 bfd_ardata (abfd
)->first_file_filepos
= strtol (hdr
.firstmemoff
,
1287 (char **) NULL
, 10);
1289 amt
= SIZEOF_AR_FILE_HDR
;
1290 bfd_ardata (abfd
)->tdata
= bfd_zalloc (abfd
, amt
);
1291 if (bfd_ardata (abfd
)->tdata
== NULL
)
1294 memcpy (bfd_ardata (abfd
)->tdata
, &hdr
, SIZEOF_AR_FILE_HDR
);
1298 /* This is the new format. */
1299 struct xcoff_ar_file_hdr_big hdr
;
1301 /* Copy over the magic string. */
1302 memcpy (hdr
.magic
, magic
, SXCOFFARMAG
);
1304 /* Now read the rest of the file header. */
1305 if (bfd_bread ((PTR
) &hdr
.memoff
,
1306 (bfd_size_type
) SIZEOF_AR_FILE_HDR_BIG
- SXCOFFARMAG
, abfd
)
1307 != SIZEOF_AR_FILE_HDR_BIG
- SXCOFFARMAG
)
1309 if (bfd_get_error () != bfd_error_system_call
)
1310 bfd_set_error (bfd_error_wrong_format
);
1314 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1315 machines) since the field width is 20 and there numbers with more
1316 than 32 bits can be represented. */
1317 bfd_ardata (abfd
)->first_file_filepos
= strtol (hdr
.firstmemoff
,
1318 (char **) NULL
, 10);
1320 amt
= SIZEOF_AR_FILE_HDR_BIG
;
1321 bfd_ardata (abfd
)->tdata
= bfd_zalloc (abfd
, amt
);
1322 if (bfd_ardata (abfd
)->tdata
== NULL
)
1325 memcpy (bfd_ardata (abfd
)->tdata
, &hdr
, SIZEOF_AR_FILE_HDR_BIG
);
1328 if (! _bfd_xcoff_slurp_armap (abfd
))
1330 bfd_release (abfd
, bfd_ardata (abfd
));
1331 abfd
->tdata
.aout_ar_data
= (struct artdata
*) NULL
;
1338 /* Read the archive header in an XCOFF archive. */
1341 _bfd_xcoff_read_ar_hdr (abfd
)
1344 bfd_size_type namlen
;
1345 struct areltdata
*ret
;
1346 bfd_size_type amt
= sizeof (struct areltdata
);
1348 ret
= (struct areltdata
*) bfd_alloc (abfd
, amt
);
1352 if (! xcoff_big_format_p (abfd
))
1354 struct xcoff_ar_hdr hdr
;
1355 struct xcoff_ar_hdr
*hdrp
;
1357 if (bfd_bread ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1364 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1365 amt
= SIZEOF_AR_HDR
+ namlen
+ 1;
1366 hdrp
= (struct xcoff_ar_hdr
*) bfd_alloc (abfd
, amt
);
1372 memcpy (hdrp
, &hdr
, SIZEOF_AR_HDR
);
1373 if (bfd_bread ((char *) hdrp
+ SIZEOF_AR_HDR
, namlen
, abfd
) != namlen
)
1378 ((char *) hdrp
)[SIZEOF_AR_HDR
+ namlen
] = '\0';
1380 ret
->arch_header
= (char *) hdrp
;
1381 ret
->parsed_size
= strtol (hdr
.size
, (char **) NULL
, 10);
1382 ret
->filename
= (char *) hdrp
+ SIZEOF_AR_HDR
;
1386 struct xcoff_ar_hdr_big hdr
;
1387 struct xcoff_ar_hdr_big
*hdrp
;
1389 if (bfd_bread ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR_BIG
, abfd
)
1390 != SIZEOF_AR_HDR_BIG
)
1396 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1397 amt
= SIZEOF_AR_HDR_BIG
+ namlen
+ 1;
1398 hdrp
= (struct xcoff_ar_hdr_big
*) bfd_alloc (abfd
, amt
);
1404 memcpy (hdrp
, &hdr
, SIZEOF_AR_HDR_BIG
);
1405 if (bfd_bread ((char *) hdrp
+ SIZEOF_AR_HDR_BIG
, namlen
, abfd
) != namlen
)
1410 ((char *) hdrp
)[SIZEOF_AR_HDR_BIG
+ namlen
] = '\0';
1412 ret
->arch_header
= (char *) hdrp
;
1413 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1414 machines) since the field width is 20 and there numbers with more
1415 than 32 bits can be represented. */
1416 ret
->parsed_size
= strtol (hdr
.size
, (char **) NULL
, 10);
1417 ret
->filename
= (char *) hdrp
+ SIZEOF_AR_HDR_BIG
;
1420 /* Skip over the XCOFFARFMAG at the end of the file name. */
1421 if (bfd_seek (abfd
, (file_ptr
) ((namlen
& 1) + SXCOFFARFMAG
), SEEK_CUR
) != 0)
1427 /* Open the next element in an XCOFF archive. */
1430 _bfd_xcoff_openr_next_archived_file (archive
, last_file
)
1436 if (xcoff_ardata (archive
) == NULL
)
1438 bfd_set_error (bfd_error_invalid_operation
);
1442 if (! xcoff_big_format_p (archive
))
1444 if (last_file
== NULL
)
1445 filestart
= bfd_ardata (archive
)->first_file_filepos
;
1447 filestart
= strtol (arch_xhdr (last_file
)->nextoff
, (char **) NULL
,
1451 || filestart
== strtol (xcoff_ardata (archive
)->memoff
,
1453 || filestart
== strtol (xcoff_ardata (archive
)->symoff
,
1454 (char **) NULL
, 10))
1456 bfd_set_error (bfd_error_no_more_archived_files
);
1462 if (last_file
== NULL
)
1463 filestart
= bfd_ardata (archive
)->first_file_filepos
;
1465 /* XXX These actually have to be a calls to strtoll (at least
1466 on 32-bit machines) since the fields's width is 20 and
1467 there numbers with more than 32 bits can be represented. */
1468 filestart
= strtol (arch_xhdr_big (last_file
)->nextoff
, (char **) NULL
,
1471 /* XXX These actually have to be calls to strtoll (at least on 32-bit
1472 machines) since the fields's width is 20 and there numbers with more
1473 than 32 bits can be represented. */
1475 || filestart
== strtol (xcoff_ardata_big (archive
)->memoff
,
1477 || filestart
== strtol (xcoff_ardata_big (archive
)->symoff
,
1478 (char **) NULL
, 10))
1480 bfd_set_error (bfd_error_no_more_archived_files
);
1485 return _bfd_get_elt_at_filepos (archive
, filestart
);
1488 /* Stat an element in an XCOFF archive. */
1491 _bfd_xcoff_stat_arch_elt (abfd
, s
)
1495 if (abfd
->arelt_data
== NULL
)
1497 bfd_set_error (bfd_error_invalid_operation
);
1501 if (! xcoff_big_format_p (abfd
->my_archive
))
1503 struct xcoff_ar_hdr
*hdrp
= arch_xhdr (abfd
);
1505 s
->st_mtime
= strtol (hdrp
->date
, (char **) NULL
, 10);
1506 s
->st_uid
= strtol (hdrp
->uid
, (char **) NULL
, 10);
1507 s
->st_gid
= strtol (hdrp
->gid
, (char **) NULL
, 10);
1508 s
->st_mode
= strtol (hdrp
->mode
, (char **) NULL
, 8);
1509 s
->st_size
= arch_eltdata (abfd
)->parsed_size
;
1513 struct xcoff_ar_hdr_big
*hdrp
= arch_xhdr_big (abfd
);
1515 s
->st_mtime
= strtol (hdrp
->date
, (char **) NULL
, 10);
1516 s
->st_uid
= strtol (hdrp
->uid
, (char **) NULL
, 10);
1517 s
->st_gid
= strtol (hdrp
->gid
, (char **) NULL
, 10);
1518 s
->st_mode
= strtol (hdrp
->mode
, (char **) NULL
, 8);
1519 s
->st_size
= arch_eltdata (abfd
)->parsed_size
;
1525 /* Normalize a file name for inclusion in an archive. */
1528 normalize_filename (abfd
)
1532 const char *filename
;
1534 file
= bfd_get_filename (abfd
);
1535 filename
= strrchr (file
, '/');
1536 if (filename
!= NULL
)
1543 /* Write out an XCOFF armap. */
1547 xcoff_write_armap_old (abfd
, elength
, map
, orl_count
, stridx
)
1549 unsigned int elength ATTRIBUTE_UNUSED
;
1551 unsigned int orl_count
;
1554 struct xcoff_ar_hdr hdr
;
1556 unsigned char buf
[4];
1561 memset (&hdr
, 0, sizeof hdr
);
1562 sprintf (hdr
.size
, "%ld", (long) (4 + orl_count
* 4 + stridx
));
1563 sprintf (hdr
.nextoff
, "%d", 0);
1564 memcpy (hdr
.prevoff
, xcoff_ardata (abfd
)->memoff
, XCOFFARMAG_ELEMENT_SIZE
);
1565 sprintf (hdr
.date
, "%d", 0);
1566 sprintf (hdr
.uid
, "%d", 0);
1567 sprintf (hdr
.gid
, "%d", 0);
1568 sprintf (hdr
.mode
, "%d", 0);
1569 sprintf (hdr
.namlen
, "%d", 0);
1571 /* We need spaces, not null bytes, in the header. */
1572 for (p
= (char *) &hdr
; p
< (char *) &hdr
+ SIZEOF_AR_HDR
; p
++)
1576 if (bfd_bwrite ((PTR
) &hdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
1578 || (bfd_bwrite (XCOFFARFMAG
, (bfd_size_type
) SXCOFFARFMAG
, abfd
)
1582 H_PUT_32 (abfd
, orl_count
, buf
);
1583 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
1586 sub
= abfd
->archive_head
;
1587 fileoff
= SIZEOF_AR_FILE_HDR
;
1589 while (sub
!= NULL
&& i
< orl_count
)
1593 while (map
[i
].u
.abfd
== sub
)
1595 H_PUT_32 (abfd
, fileoff
, buf
);
1596 if (bfd_bwrite (buf
, (bfd_size_type
) 4, abfd
) != 4)
1600 namlen
= strlen (normalize_filename (sub
));
1601 namlen
= (namlen
+ 1) &~ (size_t) 1;
1602 fileoff
+= (SIZEOF_AR_HDR
1605 + arelt_size (sub
));
1606 fileoff
= (fileoff
+ 1) &~ 1;
1610 for (i
= 0; i
< orl_count
; i
++)
1615 name
= *map
[i
].name
;
1616 namlen
= strlen (name
);
1617 if (bfd_bwrite (name
, (bfd_size_type
) (namlen
+ 1), abfd
) != namlen
+ 1)
1621 if ((stridx
& 1) != 0)
1626 if (bfd_bwrite (&b
, (bfd_size_type
) 1, abfd
) != 1)
1633 static char buff20
[XCOFFARMAGBIG_ELEMENT_SIZE
+ 1];
1634 #define FMT20 "%-20lld"
1635 #define FMT12 "%-12d"
1636 #define FMT12_OCTAL "%-12o"
1638 #define PRINT20(d, v) \
1639 sprintf (buff20, FMT20, (long long)(v)), \
1640 memcpy ((void *) (d), buff20, 20)
1642 #define PRINT12(d, v) \
1643 sprintf (buff20, FMT12, (int)(v)), \
1644 memcpy ((void *) (d), buff20, 12)
1646 #define PRINT12_OCTAL(d, v) \
1647 sprintf (buff20, FMT12_OCTAL, (unsigned int)(v)), \
1648 memcpy ((void *) (d), buff20, 12)
1650 #define PRINT4(d, v) \
1651 sprintf (buff20, FMT4, (int)(v)), \
1652 memcpy ((void *) (d), buff20, 4)
1654 #define READ20(d, v) \
1656 memcpy (buff20, (d), 20), \
1657 (v) = bfd_scan_vma (buff20, (const char **) NULL, 10)
1660 do_pad (abfd
, number
)
1662 unsigned int number
;
1666 /* Limit pad to <= 4096. */
1671 if (bfd_bwrite (&b
, (bfd_size_type
) 1, abfd
) != 1)
1678 do_copy (out_bfd
, in_bfd
)
1682 bfd_size_type remaining
;
1683 bfd_byte buffer
[DEFAULT_BUFFERSIZE
];
1685 if (bfd_seek (in_bfd
, (file_ptr
) 0, SEEK_SET
) != 0)
1688 remaining
= arelt_size (in_bfd
);
1690 while (remaining
>= DEFAULT_BUFFERSIZE
)
1692 if (bfd_bread (buffer
, DEFAULT_BUFFERSIZE
, in_bfd
) != DEFAULT_BUFFERSIZE
1693 || bfd_bwrite (buffer
, DEFAULT_BUFFERSIZE
, out_bfd
) != DEFAULT_BUFFERSIZE
)
1696 remaining
-= DEFAULT_BUFFERSIZE
;
1701 if (bfd_bread (buffer
, remaining
, in_bfd
) != remaining
1702 || bfd_bwrite (buffer
, remaining
, out_bfd
) != remaining
)
1710 do_shared_object_padding (out_bfd
, in_bfd
, offset
, ar_header_size
)
1716 if (bfd_check_format (in_bfd
, bfd_object
)
1717 && bfd_get_flavour (in_bfd
) == bfd_target_xcoff_flavour
1718 && (in_bfd
->flags
& DYNAMIC
) != 0)
1720 bfd_size_type pad
= 0;
1721 int text_align_power
;
1723 text_align_power
= bfd_xcoff_text_align_power (in_bfd
);
1724 BFD_ASSERT (2 < text_align_power
);
1726 pad
= 1 << text_align_power
;
1727 pad
-= (*offset
+ ar_header_size
) & (pad
- 1);
1729 if (! do_pad (out_bfd
, pad
))
1739 xcoff_write_armap_big (abfd
, elength
, map
, orl_count
, stridx
)
1741 unsigned int elength ATTRIBUTE_UNUSED
;
1743 unsigned int orl_count
;
1746 struct xcoff_ar_file_hdr_big
*fhdr
;
1747 bfd_vma i
, sym_32
, sym_64
, str_32
, str_64
;
1748 const bfd_arch_info_type
*arch_info
= NULL
;
1750 size_t string_length
;
1751 ufile_ptr nextoff
, prevoff
;
1753 /* First, we look through the symbols and work out which are
1754 from 32-bit objects and which from 64-bit ones. */
1755 sym_32
= sym_64
= str_32
= str_64
= 0;
1757 current_bfd
= abfd
->archive_head
;
1758 if (current_bfd
!= NULL
)
1759 arch_info
= bfd_get_arch_info (current_bfd
);
1761 while (current_bfd
!= NULL
&& i
< orl_count
)
1763 while (map
[i
].u
.abfd
== current_bfd
)
1765 string_length
= strlen (*map
[i
].name
) + 1;
1767 if (arch_info
->bits_per_address
== 64)
1770 str_64
+= string_length
;
1775 str_32
+= string_length
;
1779 current_bfd
= current_bfd
->next
;
1780 if (current_bfd
!= NULL
)
1781 arch_info
= bfd_get_arch_info (current_bfd
);
1784 /* A quick sanity check... */
1785 BFD_ASSERT (sym_64
+ sym_32
== orl_count
);
1786 /* Explicit cast to int for compiler. */
1787 BFD_ASSERT ((int)(str_64
+ str_32
) == stridx
);
1789 fhdr
= xcoff_ardata_big (abfd
);
1791 /* xcoff_write_archive_contents_big passes nextoff in symoff. */
1792 READ20 (fhdr
->memoff
, prevoff
);
1793 READ20 (fhdr
->symoff
, nextoff
);
1795 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
1797 /* Write out the symbol table.
1800 standard big archive header
1801 0x0000 ar_size [0x14]
1802 0x0014 ar_nxtmem [0x14]
1803 0x0028 ar_prvmem [0x14]
1804 0x003C ar_date [0x0C]
1805 0x0048 ar_uid [0x0C]
1806 0x0054 ar_gid [0x0C]
1807 0x0060 ar_mod [0x0C]
1808 0x006C ar_namelen[0x04]
1809 0x0070 ar_fmag [SXCOFFARFMAG]
1812 0x0072 num_syms [0x08], binary
1813 0x0078 offsets [0x08 * num_syms], binary
1814 0x0086 + 0x08 * num_syms names [??]
1815 ?? pad to even bytes.
1820 struct xcoff_ar_hdr_big
*hdr
;
1821 bfd_byte
*symbol_table
;
1825 bfd_vma symbol_table_size
=
1830 + str_32
+ (str_32
& 1);
1832 symbol_table
= NULL
;
1833 symbol_table
= (bfd_byte
*) bfd_malloc (symbol_table_size
);
1834 if (symbol_table
== NULL
)
1836 memset (symbol_table
, 0, symbol_table_size
);
1838 hdr
= (struct xcoff_ar_hdr_big
*) symbol_table
;
1840 PRINT20 (hdr
->size
, 8 + 8 * sym_32
+ str_32
+ (str_32
& 1));
1843 PRINT20 (hdr
->nextoff
, nextoff
+ symbol_table_size
);
1845 PRINT20 (hdr
->nextoff
, 0);
1847 PRINT20 (hdr
->prevoff
, prevoff
);
1848 PRINT12 (hdr
->date
, 0);
1849 PRINT12 (hdr
->uid
, 0);
1850 PRINT12 (hdr
->gid
, 0);
1851 PRINT12 (hdr
->mode
, 0);
1852 PRINT4 (hdr
->namlen
, 0) ;
1854 st
= symbol_table
+ SIZEOF_AR_HDR_BIG
;
1855 memcpy (st
, XCOFFARFMAG
, SXCOFFARFMAG
);
1858 bfd_h_put_64 (abfd
, sym_32
, st
);
1861 /* loop over the 32 bit offsets */
1862 current_bfd
= abfd
->archive_head
;
1863 if (current_bfd
!= NULL
)
1864 arch_info
= bfd_get_arch_info (current_bfd
);
1865 fileoff
= SIZEOF_AR_FILE_HDR_BIG
;
1867 while (current_bfd
!= NULL
&& i
< orl_count
)
1869 while (map
[i
].u
.abfd
== current_bfd
)
1871 if (arch_info
->bits_per_address
== 32)
1873 bfd_h_put_64 (abfd
, fileoff
, st
);
1878 string_length
= strlen (normalize_filename (current_bfd
));
1879 string_length
+= string_length
& 1;
1880 fileoff
+= (SIZEOF_AR_HDR_BIG
1883 + arelt_size (current_bfd
));
1884 fileoff
+= fileoff
& 1;
1885 current_bfd
= current_bfd
->next
;
1886 if (current_bfd
!= NULL
)
1887 arch_info
= bfd_get_arch_info (current_bfd
);
1890 /* loop over the 32 bit symbol names */
1891 current_bfd
= abfd
->archive_head
;
1892 if (current_bfd
!= NULL
)
1893 arch_info
= bfd_get_arch_info (current_bfd
);
1895 while (current_bfd
!= NULL
&& i
< orl_count
)
1897 while (map
[i
].u
.abfd
== current_bfd
)
1899 if (arch_info
->bits_per_address
== 32)
1901 string_length
= sprintf (st
, "%s", *map
[i
].name
);
1902 st
+= string_length
+ 1;
1906 current_bfd
= current_bfd
->next
;
1907 if (current_bfd
!= NULL
)
1908 arch_info
= bfd_get_arch_info (current_bfd
);
1911 bfd_bwrite (symbol_table
, symbol_table_size
, abfd
);
1913 free (symbol_table
);
1914 symbol_table
= NULL
;
1917 nextoff
= nextoff
+ symbol_table_size
;
1920 PRINT20 (fhdr
->symoff
, 0);
1924 struct xcoff_ar_hdr_big
*hdr
;
1925 bfd_byte
*symbol_table
;
1929 bfd_vma symbol_table_size
=
1934 + str_64
+ (str_64
& 1);
1936 symbol_table
= NULL
;
1937 symbol_table
= (bfd_byte
*) bfd_malloc (symbol_table_size
);
1938 if (symbol_table
== NULL
)
1940 memset (symbol_table
, 0, symbol_table_size
);
1942 hdr
= (struct xcoff_ar_hdr_big
*) symbol_table
;
1944 PRINT20 (hdr
->size
, 8 + 8 * sym_64
+ str_64
+ (str_64
& 1));
1945 PRINT20 (hdr
->nextoff
, 0);
1946 PRINT20 (hdr
->prevoff
, prevoff
);
1947 PRINT12 (hdr
->date
, 0);
1948 PRINT12 (hdr
->uid
, 0);
1949 PRINT12 (hdr
->gid
, 0);
1950 PRINT12 (hdr
->mode
, 0);
1951 PRINT4 (hdr
->namlen
, 0);
1953 st
= symbol_table
+ SIZEOF_AR_HDR_BIG
;
1954 memcpy (st
, XCOFFARFMAG
, SXCOFFARFMAG
);
1957 bfd_h_put_64 (abfd
, sym_64
, st
);
1960 /* loop over the 64 bit offsets */
1961 current_bfd
= abfd
->archive_head
;
1962 if (current_bfd
!= NULL
)
1963 arch_info
= bfd_get_arch_info (current_bfd
);
1964 fileoff
= SIZEOF_AR_FILE_HDR_BIG
;
1966 while (current_bfd
!= NULL
&& i
< orl_count
)
1968 while (map
[i
].u
.abfd
== current_bfd
)
1970 if (arch_info
->bits_per_address
== 64)
1972 bfd_h_put_64 (abfd
, fileoff
, st
);
1977 string_length
= strlen (normalize_filename (current_bfd
));
1978 string_length
+= string_length
& 1;
1979 fileoff
+= (SIZEOF_AR_HDR_BIG
1982 + arelt_size (current_bfd
));
1983 fileoff
+= fileoff
& 1;
1984 current_bfd
= current_bfd
->next
;
1985 if (current_bfd
!= NULL
)
1986 arch_info
= bfd_get_arch_info (current_bfd
);
1989 /* loop over the 64 bit symbol names */
1990 current_bfd
= abfd
->archive_head
;
1991 if (current_bfd
!= NULL
)
1992 arch_info
= bfd_get_arch_info (current_bfd
);
1994 while (current_bfd
!= NULL
&& i
< orl_count
)
1996 while (map
[i
].u
.abfd
== current_bfd
)
1998 if (arch_info
->bits_per_address
== 64)
2000 string_length
= sprintf (st
, "%s", *map
[i
].name
);
2001 st
+= string_length
+ 1;
2005 current_bfd
= current_bfd
->next
;
2006 if (current_bfd
!= NULL
)
2007 arch_info
= bfd_get_arch_info (current_bfd
);
2010 bfd_bwrite (symbol_table
, symbol_table_size
, abfd
);
2012 free (symbol_table
);
2013 symbol_table
= NULL
;
2015 PRINT20 (fhdr
->symoff64
, nextoff
);
2018 PRINT20 (fhdr
->symoff64
, 0);
2024 _bfd_xcoff_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
2026 unsigned int elength ATTRIBUTE_UNUSED
;
2028 unsigned int orl_count
;
2031 if (! xcoff_big_format_p (abfd
))
2032 return xcoff_write_armap_old (abfd
, elength
, map
, orl_count
, stridx
);
2034 return xcoff_write_armap_big (abfd
, elength
, map
, orl_count
, stridx
);
2037 /* Write out an XCOFF archive. We always write an entire archive,
2038 rather than fussing with the freelist and so forth. */
2041 xcoff_write_archive_contents_old (abfd
)
2044 struct xcoff_ar_file_hdr fhdr
;
2045 bfd_size_type count
;
2046 bfd_size_type total_namlen
;
2050 ufile_ptr prevoff
, nextoff
;
2053 struct xcoff_ar_hdr ahdr
;
2056 char decbuf
[XCOFFARMAG_ELEMENT_SIZE
+ 1];
2058 memset (&fhdr
, 0, sizeof fhdr
);
2059 strncpy (fhdr
.magic
, XCOFFARMAG
, SXCOFFARMAG
);
2060 sprintf (fhdr
.firstmemoff
, "%d", SIZEOF_AR_FILE_HDR
);
2061 sprintf (fhdr
.freeoff
, "%d", 0);
2065 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->next
)
2068 total_namlen
+= strlen (normalize_filename (sub
)) + 1;
2070 offsets
= (file_ptr
*) bfd_alloc (abfd
, count
* sizeof (file_ptr
));
2071 if (offsets
== NULL
)
2074 if (bfd_seek (abfd
, (file_ptr
) SIZEOF_AR_FILE_HDR
, SEEK_SET
) != 0)
2077 makemap
= bfd_has_map (abfd
);
2080 nextoff
= SIZEOF_AR_FILE_HDR
;
2081 for (sub
= abfd
->archive_head
, i
= 0; sub
!= NULL
; sub
= sub
->next
, i
++)
2084 bfd_size_type namlen
;
2085 struct xcoff_ar_hdr
*ahdrp
;
2086 bfd_size_type remaining
;
2088 if (makemap
&& ! hasobjects
)
2090 if (bfd_check_format (sub
, bfd_object
))
2094 name
= normalize_filename (sub
);
2095 namlen
= strlen (name
);
2097 if (sub
->arelt_data
!= NULL
)
2098 ahdrp
= arch_xhdr (sub
);
2106 memset (&ahdr
, 0, sizeof ahdr
);
2108 if (stat (bfd_get_filename (sub
), &s
) != 0)
2110 bfd_set_error (bfd_error_system_call
);
2114 sprintf (ahdrp
->size
, "%ld", (long) s
.st_size
);
2115 sprintf (ahdrp
->date
, "%ld", (long) s
.st_mtime
);
2116 sprintf (ahdrp
->uid
, "%ld", (long) s
.st_uid
);
2117 sprintf (ahdrp
->gid
, "%ld", (long) s
.st_gid
);
2118 sprintf (ahdrp
->mode
, "%o", (unsigned int) s
.st_mode
);
2120 if (sub
->arelt_data
== NULL
)
2122 size
= sizeof (struct areltdata
);
2123 sub
->arelt_data
= bfd_alloc (sub
, size
);
2124 if (sub
->arelt_data
== NULL
)
2128 arch_eltdata (sub
)->parsed_size
= s
.st_size
;
2131 sprintf (ahdrp
->prevoff
, "%ld", (long) prevoff
);
2132 sprintf (ahdrp
->namlen
, "%ld", (long) namlen
);
2134 /* If the length of the name is odd, we write out the null byte
2135 after the name as well. */
2136 namlen
= (namlen
+ 1) &~ (bfd_size_type
) 1;
2138 remaining
= arelt_size (sub
);
2139 size
= (SIZEOF_AR_HDR
2144 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2146 offsets
[i
] = nextoff
;
2149 nextoff
+= size
+ (size
& 1);
2151 sprintf (ahdrp
->nextoff
, "%ld", (long) nextoff
);
2153 /* We need spaces, not null bytes, in the header. */
2154 for (p
= (char *) ahdrp
; p
< (char *) ahdrp
+ SIZEOF_AR_HDR
; p
++)
2158 if ((bfd_bwrite ((PTR
) ahdrp
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
2160 || (bfd_bwrite ((PTR
) name
, namlen
, abfd
) != namlen
)
2161 || (bfd_bwrite ((PTR
) XCOFFARFMAG
, (bfd_size_type
) SXCOFFARFMAG
, abfd
)
2165 if (bfd_seek (sub
, (file_ptr
) 0, SEEK_SET
) != 0)
2168 if (! do_copy (abfd
, sub
))
2171 if (! do_pad (abfd
, size
& 1))
2175 sprintf (fhdr
.lastmemoff
, "%ld", (long) prevoff
);
2177 /* Write out the member table. */
2179 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2180 sprintf (fhdr
.memoff
, "%ld", (long) nextoff
);
2182 memset (&ahdr
, 0, sizeof ahdr
);
2183 sprintf (ahdr
.size
, "%ld", (long) (XCOFFARMAG_ELEMENT_SIZE
+
2184 count
* XCOFFARMAG_ELEMENT_SIZE
+
2186 sprintf (ahdr
.prevoff
, "%ld", (long) prevoff
);
2187 sprintf (ahdr
.date
, "%d", 0);
2188 sprintf (ahdr
.uid
, "%d", 0);
2189 sprintf (ahdr
.gid
, "%d", 0);
2190 sprintf (ahdr
.mode
, "%d", 0);
2191 sprintf (ahdr
.namlen
, "%d", 0);
2193 size
= (SIZEOF_AR_HDR
2194 + XCOFFARMAG_ELEMENT_SIZE
2195 + count
* XCOFFARMAG_ELEMENT_SIZE
2200 nextoff
+= size
+ (size
& 1);
2202 if (makemap
&& hasobjects
)
2203 sprintf (ahdr
.nextoff
, "%ld", (long) nextoff
);
2205 sprintf (ahdr
.nextoff
, "%d", 0);
2207 /* We need spaces, not null bytes, in the header. */
2208 for (p
= (char *) &ahdr
; p
< (char *) &ahdr
+ SIZEOF_AR_HDR
; p
++)
2212 if ((bfd_bwrite ((PTR
) &ahdr
, (bfd_size_type
) SIZEOF_AR_HDR
, abfd
)
2214 || (bfd_bwrite ((PTR
) XCOFFARFMAG
, (bfd_size_type
) SXCOFFARFMAG
, abfd
)
2218 sprintf (decbuf
, "%-12ld", (long) count
);
2219 if (bfd_bwrite ((PTR
) decbuf
, (bfd_size_type
) XCOFFARMAG_ELEMENT_SIZE
, abfd
)
2220 != XCOFFARMAG_ELEMENT_SIZE
)
2222 for (i
= 0; i
< (size_t) count
; i
++)
2224 sprintf (decbuf
, "%-12ld", (long) offsets
[i
]);
2225 if (bfd_bwrite ((PTR
) decbuf
, (bfd_size_type
) XCOFFARMAG_ELEMENT_SIZE
,
2226 abfd
) != XCOFFARMAG_ELEMENT_SIZE
)
2229 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->next
)
2232 bfd_size_type namlen
;
2234 name
= normalize_filename (sub
);
2235 namlen
= strlen (name
);
2236 if (bfd_bwrite ((PTR
) name
, namlen
+ 1, abfd
) != namlen
+ 1)
2240 if (! do_pad (abfd
, size
& 1))
2243 /* Write out the armap, if appropriate. */
2244 if (! makemap
|| ! hasobjects
)
2245 sprintf (fhdr
.symoff
, "%d", 0);
2248 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2249 sprintf (fhdr
.symoff
, "%ld", (long) nextoff
);
2250 bfd_ardata (abfd
)->tdata
= (PTR
) &fhdr
;
2251 if (! _bfd_compute_and_write_armap (abfd
, 0))
2255 /* Write out the archive file header. */
2257 /* We need spaces, not null bytes, in the header. */
2258 for (p
= (char *) &fhdr
; p
< (char *) &fhdr
+ SIZEOF_AR_FILE_HDR
; p
++)
2262 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
2263 || (bfd_bwrite ((PTR
) &fhdr
, (bfd_size_type
) SIZEOF_AR_FILE_HDR
, abfd
)
2264 != SIZEOF_AR_FILE_HDR
))
2271 xcoff_write_archive_contents_big (abfd
)
2274 struct xcoff_ar_file_hdr_big fhdr
;
2275 bfd_size_type count
;
2276 bfd_size_type total_namlen
;
2280 ufile_ptr prevoff
, nextoff
;
2283 struct xcoff_ar_hdr_big
*hdr
, ahdr
;
2285 bfd_byte
*member_table
, *mt
;
2286 bfd_vma member_table_size
;
2288 memset (&fhdr
, 0, SIZEOF_AR_FILE_HDR_BIG
);
2289 memcpy (fhdr
.magic
, XCOFFARMAGBIG
, SXCOFFARMAG
);
2291 if (bfd_seek (abfd
, (file_ptr
) SIZEOF_AR_FILE_HDR_BIG
, SEEK_SET
) != 0)
2294 /* Calculate count and total_namlen. */
2295 makemap
= bfd_has_map (abfd
);
2297 for (current_bfd
= abfd
->archive_head
, count
= 0, total_namlen
= 0;
2298 current_bfd
!= NULL
;
2299 current_bfd
= current_bfd
->next
, count
++)
2301 total_namlen
+= strlen (normalize_filename (current_bfd
)) + 1;
2305 && bfd_check_format (current_bfd
, bfd_object
))
2312 offsets
= (file_ptr
*) bfd_malloc (count
* sizeof (file_ptr
));
2313 if (offsets
== NULL
)
2318 nextoff
= SIZEOF_AR_FILE_HDR_BIG
;
2319 for (current_bfd
= abfd
->archive_head
, i
= 0;
2320 current_bfd
!= NULL
;
2321 current_bfd
= current_bfd
->next
, i
++)
2324 bfd_size_type namlen
;
2325 struct xcoff_ar_hdr_big
*ahdrp
;
2326 bfd_size_type remaining
;
2328 name
= normalize_filename (current_bfd
);
2329 namlen
= strlen (name
);
2331 if (current_bfd
->arelt_data
!= NULL
)
2332 ahdrp
= arch_xhdr_big (current_bfd
);
2341 /* XXX This should actually be a call to stat64 (at least on
2343 XXX This call will fail if the original object is not found. */
2344 if (stat (bfd_get_filename (current_bfd
), &s
) != 0)
2346 bfd_set_error (bfd_error_system_call
);
2350 PRINT20 (ahdrp
->size
, s
.st_size
);
2351 PRINT12 (ahdrp
->date
, s
.st_mtime
);
2352 PRINT12 (ahdrp
->uid
, s
.st_uid
);
2353 PRINT12 (ahdrp
->gid
, s
.st_gid
);
2354 PRINT12_OCTAL (ahdrp
->mode
, s
.st_mode
);
2356 if (current_bfd
->arelt_data
== NULL
)
2358 size
= sizeof (struct areltdata
);
2359 current_bfd
->arelt_data
= bfd_alloc (current_bfd
, size
);
2360 if (current_bfd
->arelt_data
== NULL
)
2364 arch_eltdata (current_bfd
)->parsed_size
= s
.st_size
;
2367 PRINT20 (ahdrp
->prevoff
, prevoff
);
2368 PRINT4 (ahdrp
->namlen
, namlen
);
2370 /* If the length of the name is odd, we write out the null byte
2371 after the name as well. */
2372 namlen
= (namlen
+ 1) &~ (bfd_size_type
) 1;
2374 remaining
= arelt_size (current_bfd
);
2375 size
= (SIZEOF_AR_HDR_BIG
2380 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2382 /* Check for xcoff shared objects.
2383 Their text section needs to be aligned wrt the archive file position.
2384 This requires extra padding before the archive header. */
2385 if (! do_shared_object_padding (abfd
, current_bfd
, & nextoff
,
2386 SIZEOF_AR_HDR_BIG
+ namlen
2390 offsets
[i
] = nextoff
;
2393 nextoff
+= size
+ (size
& 1);
2395 PRINT20 (ahdrp
->nextoff
, nextoff
);
2397 if ((bfd_bwrite ((PTR
) ahdrp
, (bfd_size_type
) SIZEOF_AR_HDR_BIG
, abfd
)
2398 != SIZEOF_AR_HDR_BIG
)
2399 || bfd_bwrite ((PTR
) name
, (bfd_size_type
) namlen
, abfd
) != namlen
2400 || (bfd_bwrite ((PTR
) XCOFFARFMAG
, (bfd_size_type
) SXCOFFARFMAG
,
2401 abfd
) != SXCOFFARFMAG
))
2404 if (bfd_seek (current_bfd
, (file_ptr
) 0, SEEK_SET
) != 0)
2407 if (! do_copy (abfd
, current_bfd
))
2410 if (! do_pad (abfd
, size
& 1))
2416 PRINT20 (fhdr
.firstmemoff
, offsets
[0]);
2417 PRINT20 (fhdr
.lastmemoff
, prevoff
);
2420 /* Write out the member table.
2423 standard big archive header
2424 0x0000 ar_size [0x14]
2425 0x0014 ar_nxtmem [0x14]
2426 0x0028 ar_prvmem [0x14]
2427 0x003C ar_date [0x0C]
2428 0x0048 ar_uid [0x0C]
2429 0x0054 ar_gid [0x0C]
2430 0x0060 ar_mod [0x0C]
2431 0x006C ar_namelen[0x04]
2432 0x0070 ar_fmag [0x02]
2436 0x0086 offsets [0x14 * counts]
2437 0x0086 + 0x14 * counts names [??]
2438 ?? pad to even bytes.
2441 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2443 member_table_size
= (SIZEOF_AR_HDR_BIG
2445 + XCOFFARMAGBIG_ELEMENT_SIZE
2446 + count
* XCOFFARMAGBIG_ELEMENT_SIZE
2449 member_table_size
+= member_table_size
& 1;
2450 member_table
= NULL
;
2451 member_table
= (bfd_byte
*) bfd_malloc (member_table_size
);
2452 if (member_table
== NULL
)
2454 memset (member_table
, 0, member_table_size
);
2456 hdr
= (struct xcoff_ar_hdr_big
*) member_table
;
2458 PRINT20 (hdr
->size
, (XCOFFARMAGBIG_ELEMENT_SIZE
+
2459 count
* XCOFFARMAGBIG_ELEMENT_SIZE
+
2460 total_namlen
+ (total_namlen
& 1)));
2461 if (makemap
&& hasobjects
)
2462 PRINT20 (hdr
->nextoff
, nextoff
+ member_table_size
);
2464 PRINT20 (hdr
->nextoff
, 0);
2465 PRINT20 (hdr
->prevoff
, prevoff
);
2466 PRINT12 (hdr
->date
, 0);
2467 PRINT12 (hdr
->uid
, 0);
2468 PRINT12 (hdr
->gid
, 0);
2469 PRINT12 (hdr
->mode
, 0);
2470 PRINT4 (hdr
->namlen
, 0);
2472 mt
= member_table
+ SIZEOF_AR_HDR_BIG
;
2473 memcpy (mt
, XCOFFARFMAG
, SXCOFFARFMAG
);
2476 PRINT20 (mt
, count
);
2477 mt
+= XCOFFARMAGBIG_ELEMENT_SIZE
;
2478 for (i
= 0; i
< (size_t) count
; i
++)
2480 PRINT20 (mt
, offsets
[i
]);
2481 mt
+= XCOFFARMAGBIG_ELEMENT_SIZE
;
2490 for (current_bfd
= abfd
->archive_head
; current_bfd
!= NULL
;
2491 current_bfd
= current_bfd
->next
)
2496 name
= normalize_filename (current_bfd
);
2497 namlen
= sprintf(mt
, "%s", name
);
2501 if (bfd_bwrite (member_table
, member_table_size
, abfd
) != member_table_size
)
2504 free (member_table
);
2505 member_table
= NULL
;
2507 PRINT20 (fhdr
.memoff
, nextoff
);
2510 nextoff
+= member_table_size
;
2512 /* Write out the armap, if appropriate. */
2514 if (! makemap
|| ! hasobjects
)
2515 PRINT20 (fhdr
.symoff
, 0);
2518 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2520 /* Save nextoff in fhdr.symoff so the armap routine can use it. */
2521 PRINT20 (fhdr
.symoff
, nextoff
);
2523 bfd_ardata (abfd
)->tdata
= (PTR
) &fhdr
;
2524 if (! _bfd_compute_and_write_armap (abfd
, 0))
2528 /* Write out the archive file header. */
2530 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
2531 || (bfd_bwrite ((PTR
) &fhdr
, (bfd_size_type
) SIZEOF_AR_FILE_HDR_BIG
,
2532 abfd
) != SIZEOF_AR_FILE_HDR_BIG
))
2539 _bfd_xcoff_write_archive_contents (abfd
)
2542 if (! xcoff_big_format_p (abfd
))
2543 return xcoff_write_archive_contents_old (abfd
);
2545 return xcoff_write_archive_contents_big (abfd
);
2548 /* We can't use the usual coff_sizeof_headers routine, because AIX
2549 always uses an a.out header. */
2552 _bfd_xcoff_sizeof_headers (abfd
, reloc
)
2554 boolean reloc ATTRIBUTE_UNUSED
;
2559 if (xcoff_data (abfd
)->full_aouthdr
)
2562 size
+= SMALL_AOUTSZ
;
2563 size
+= abfd
->section_count
* SCNHSZ
;
2567 /* Routines to swap information in the XCOFF .loader section. If we
2568 ever need to write an XCOFF loader, this stuff will need to be
2569 moved to another file shared by the linker (which XCOFF calls the
2570 ``binder'') and the loader. */
2572 /* Swap in the ldhdr structure. */
2575 xcoff_swap_ldhdr_in (abfd
, s
, dst
)
2578 struct internal_ldhdr
*dst
;
2580 const struct external_ldhdr
*src
= (const struct external_ldhdr
*) s
;
2582 dst
->l_version
= bfd_get_32 (abfd
, src
->l_version
);
2583 dst
->l_nsyms
= bfd_get_32 (abfd
, src
->l_nsyms
);
2584 dst
->l_nreloc
= bfd_get_32 (abfd
, src
->l_nreloc
);
2585 dst
->l_istlen
= bfd_get_32 (abfd
, src
->l_istlen
);
2586 dst
->l_nimpid
= bfd_get_32 (abfd
, src
->l_nimpid
);
2587 dst
->l_impoff
= bfd_get_32 (abfd
, src
->l_impoff
);
2588 dst
->l_stlen
= bfd_get_32 (abfd
, src
->l_stlen
);
2589 dst
->l_stoff
= bfd_get_32 (abfd
, src
->l_stoff
);
2592 /* Swap out the ldhdr structure. */
2595 xcoff_swap_ldhdr_out (abfd
, src
, d
)
2597 const struct internal_ldhdr
*src
;
2600 struct external_ldhdr
*dst
= (struct external_ldhdr
*) d
;
2602 bfd_put_32 (abfd
, (bfd_vma
) src
->l_version
, dst
->l_version
);
2603 bfd_put_32 (abfd
, src
->l_nsyms
, dst
->l_nsyms
);
2604 bfd_put_32 (abfd
, src
->l_nreloc
, dst
->l_nreloc
);
2605 bfd_put_32 (abfd
, src
->l_istlen
, dst
->l_istlen
);
2606 bfd_put_32 (abfd
, src
->l_nimpid
, dst
->l_nimpid
);
2607 bfd_put_32 (abfd
, src
->l_impoff
, dst
->l_impoff
);
2608 bfd_put_32 (abfd
, src
->l_stlen
, dst
->l_stlen
);
2609 bfd_put_32 (abfd
, src
->l_stoff
, dst
->l_stoff
);
2612 /* Swap in the ldsym structure. */
2615 xcoff_swap_ldsym_in (abfd
, s
, dst
)
2618 struct internal_ldsym
*dst
;
2620 const struct external_ldsym
*src
= (const struct external_ldsym
*) s
;
2622 if (bfd_get_32 (abfd
, src
->_l
._l_l
._l_zeroes
) != 0) {
2623 memcpy (dst
->_l
._l_name
, src
->_l
._l_name
, SYMNMLEN
);
2625 dst
->_l
._l_l
._l_zeroes
= 0;
2626 dst
->_l
._l_l
._l_offset
= bfd_get_32 (abfd
, src
->_l
._l_l
._l_offset
);
2628 dst
->l_value
= bfd_get_32 (abfd
, src
->l_value
);
2629 dst
->l_scnum
= bfd_get_16 (abfd
, src
->l_scnum
);
2630 dst
->l_smtype
= bfd_get_8 (abfd
, src
->l_smtype
);
2631 dst
->l_smclas
= bfd_get_8 (abfd
, src
->l_smclas
);
2632 dst
->l_ifile
= bfd_get_32 (abfd
, src
->l_ifile
);
2633 dst
->l_parm
= bfd_get_32 (abfd
, src
->l_parm
);
2636 /* Swap out the ldsym structure. */
2639 xcoff_swap_ldsym_out (abfd
, src
, d
)
2641 const struct internal_ldsym
*src
;
2644 struct external_ldsym
*dst
= (struct external_ldsym
*) d
;
2646 if (src
->_l
._l_l
._l_zeroes
!= 0)
2647 memcpy (dst
->_l
._l_name
, src
->_l
._l_name
, SYMNMLEN
);
2650 bfd_put_32 (abfd
, (bfd_vma
) 0, dst
->_l
._l_l
._l_zeroes
);
2651 bfd_put_32 (abfd
, (bfd_vma
) src
->_l
._l_l
._l_offset
,
2652 dst
->_l
._l_l
._l_offset
);
2654 bfd_put_32 (abfd
, src
->l_value
, dst
->l_value
);
2655 bfd_put_16 (abfd
, (bfd_vma
) src
->l_scnum
, dst
->l_scnum
);
2656 bfd_put_8 (abfd
, src
->l_smtype
, dst
->l_smtype
);
2657 bfd_put_8 (abfd
, src
->l_smclas
, dst
->l_smclas
);
2658 bfd_put_32 (abfd
, src
->l_ifile
, dst
->l_ifile
);
2659 bfd_put_32 (abfd
, src
->l_parm
, dst
->l_parm
);
2663 xcoff_swap_reloc_in (abfd
, s
, d
)
2668 struct external_reloc
*src
= (struct external_reloc
*) s
;
2669 struct internal_reloc
*dst
= (struct internal_reloc
*) d
;
2671 memset (dst
, 0, sizeof (struct internal_reloc
));
2673 dst
->r_vaddr
= bfd_get_32 (abfd
, src
->r_vaddr
);
2674 dst
->r_symndx
= bfd_get_32 (abfd
, src
->r_symndx
);
2675 dst
->r_size
= bfd_get_8 (abfd
, src
->r_size
);
2676 dst
->r_type
= bfd_get_8 (abfd
, src
->r_type
);
2680 xcoff_swap_reloc_out (abfd
, s
, d
)
2685 struct internal_reloc
*src
= (struct internal_reloc
*) s
;
2686 struct external_reloc
*dst
= (struct external_reloc
*) d
;
2688 bfd_put_32 (abfd
, src
->r_vaddr
, dst
->r_vaddr
);
2689 bfd_put_32 (abfd
, src
->r_symndx
, dst
->r_symndx
);
2690 bfd_put_8 (abfd
, src
->r_type
, dst
->r_type
);
2691 bfd_put_8 (abfd
, src
->r_size
, dst
->r_size
);
2693 return bfd_coff_relsz (abfd
);
2696 /* Swap in the ldrel structure. */
2699 xcoff_swap_ldrel_in (abfd
, s
, dst
)
2702 struct internal_ldrel
*dst
;
2704 const struct external_ldrel
*src
= (const struct external_ldrel
*) s
;
2706 dst
->l_vaddr
= bfd_get_32 (abfd
, src
->l_vaddr
);
2707 dst
->l_symndx
= bfd_get_32 (abfd
, src
->l_symndx
);
2708 dst
->l_rtype
= bfd_get_16 (abfd
, src
->l_rtype
);
2709 dst
->l_rsecnm
= bfd_get_16 (abfd
, src
->l_rsecnm
);
2712 /* Swap out the ldrel structure. */
2715 xcoff_swap_ldrel_out (abfd
, src
, d
)
2717 const struct internal_ldrel
*src
;
2720 struct external_ldrel
*dst
= (struct external_ldrel
*) d
;
2722 bfd_put_32 (abfd
, src
->l_vaddr
, dst
->l_vaddr
);
2723 bfd_put_32 (abfd
, src
->l_symndx
, dst
->l_symndx
);
2724 bfd_put_16 (abfd
, (bfd_vma
) src
->l_rtype
, dst
->l_rtype
);
2725 bfd_put_16 (abfd
, (bfd_vma
) src
->l_rsecnm
, dst
->l_rsecnm
);
2730 xcoff_reloc_type_noop (input_bfd
, input_section
, output_bfd
, rel
, sym
, howto
,
2731 val
, addend
, relocation
, contents
)
2732 bfd
*input_bfd ATTRIBUTE_UNUSED
;
2733 asection
*input_section ATTRIBUTE_UNUSED
;
2734 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2735 struct internal_reloc
*rel ATTRIBUTE_UNUSED
;
2736 struct internal_syment
*sym ATTRIBUTE_UNUSED
;
2737 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
;
2738 bfd_vma val ATTRIBUTE_UNUSED
;
2739 bfd_vma addend ATTRIBUTE_UNUSED
;
2740 bfd_vma
*relocation ATTRIBUTE_UNUSED
;
2741 bfd_byte
*contents ATTRIBUTE_UNUSED
;
2747 xcoff_reloc_type_fail (input_bfd
, input_section
, output_bfd
, rel
, sym
, howto
,
2748 val
, addend
, relocation
, contents
)
2750 asection
*input_section ATTRIBUTE_UNUSED
;
2751 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2752 struct internal_reloc
*rel
;
2753 struct internal_syment
*sym ATTRIBUTE_UNUSED
;
2754 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
;
2755 bfd_vma val ATTRIBUTE_UNUSED
;
2756 bfd_vma addend ATTRIBUTE_UNUSED
;
2757 bfd_vma
*relocation ATTRIBUTE_UNUSED
;
2758 bfd_byte
*contents ATTRIBUTE_UNUSED
;
2760 (*_bfd_error_handler
)
2761 (_("%s: unsupported relocation type 0x%02x"),
2762 bfd_get_filename (input_bfd
), (unsigned int) rel
->r_type
);
2763 bfd_set_error (bfd_error_bad_value
);
2768 xcoff_reloc_type_pos (input_bfd
, input_section
, output_bfd
, rel
, sym
, howto
,
2769 val
, addend
, relocation
, contents
)
2770 bfd
*input_bfd ATTRIBUTE_UNUSED
;
2771 asection
*input_section ATTRIBUTE_UNUSED
;
2772 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2773 struct internal_reloc
*rel ATTRIBUTE_UNUSED
;
2774 struct internal_syment
*sym ATTRIBUTE_UNUSED
;
2775 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
;
2778 bfd_vma
*relocation
;
2779 bfd_byte
*contents ATTRIBUTE_UNUSED
;
2781 *relocation
= val
+ addend
;
2786 xcoff_reloc_type_neg (input_bfd
, input_section
, output_bfd
, rel
, sym
, howto
,
2787 val
, addend
, relocation
, contents
)
2788 bfd
*input_bfd ATTRIBUTE_UNUSED
;
2789 asection
*input_section ATTRIBUTE_UNUSED
;
2790 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2791 struct internal_reloc
*rel ATTRIBUTE_UNUSED
;
2792 struct internal_syment
*sym ATTRIBUTE_UNUSED
;
2793 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
;
2796 bfd_vma
*relocation
;
2797 bfd_byte
*contents ATTRIBUTE_UNUSED
;
2799 *relocation
= addend
- val
;
2804 xcoff_reloc_type_rel (input_bfd
, input_section
, output_bfd
, rel
, sym
, howto
,
2805 val
, addend
, relocation
, contents
)
2806 bfd
*input_bfd ATTRIBUTE_UNUSED
;
2807 asection
*input_section
;
2808 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2809 struct internal_reloc
*rel ATTRIBUTE_UNUSED
;
2810 struct internal_syment
*sym ATTRIBUTE_UNUSED
;
2811 struct reloc_howto_struct
*howto
;
2814 bfd_vma
*relocation
;
2815 bfd_byte
*contents ATTRIBUTE_UNUSED
;
2817 howto
->pc_relative
= true;
2819 /* A PC relative reloc includes the section address. */
2820 addend
+= input_section
->vma
;
2822 *relocation
= val
+ addend
;
2823 *relocation
-= (input_section
->output_section
->vma
+
2824 input_section
->output_offset
);
2828 xcoff_reloc_type_toc (input_bfd
, input_section
, output_bfd
, rel
, sym
, howto
,
2829 val
, addend
, relocation
, contents
)
2831 asection
*input_section ATTRIBUTE_UNUSED
;
2833 struct internal_reloc
*rel
;
2834 struct internal_syment
*sym
;
2835 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
;
2837 bfd_vma addend ATTRIBUTE_UNUSED
;
2838 bfd_vma
*relocation
;
2839 bfd_byte
*contents ATTRIBUTE_UNUSED
;
2841 struct xcoff_link_hash_entry
*h
;
2843 if (0 > rel
->r_symndx
)
2846 h
= obj_xcoff_sym_hashes (input_bfd
)[rel
->r_symndx
];
2848 if (h
!= NULL
&& h
->smclas
!= XMC_TD
)
2850 if (h
->toc_section
== NULL
)
2852 (*_bfd_error_handler
)
2853 (_("%s: TOC reloc at 0x%x to symbol `%s' with no TOC entry"),
2854 bfd_get_filename (input_bfd
), rel
->r_vaddr
,
2855 h
->root
.root
.string
);
2856 bfd_set_error (bfd_error_bad_value
);
2860 BFD_ASSERT ((h
->flags
& XCOFF_SET_TOC
) == 0);
2861 val
= (h
->toc_section
->output_section
->vma
2862 + h
->toc_section
->output_offset
);
2865 *relocation
= ((val
- xcoff_data (output_bfd
)->toc
) -
2866 (sym
->n_value
- xcoff_data (input_bfd
)->toc
));
2870 xcoff_reloc_type_ba (input_bfd
, input_section
, output_bfd
, rel
, sym
, howto
,
2871 val
, addend
, relocation
, contents
)
2872 bfd
*input_bfd ATTRIBUTE_UNUSED
;
2873 asection
*input_section ATTRIBUTE_UNUSED
;
2874 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2875 struct internal_reloc
*rel ATTRIBUTE_UNUSED
;
2876 struct internal_syment
*sym ATTRIBUTE_UNUSED
;
2877 struct reloc_howto_struct
*howto
;
2880 bfd_vma
*relocation
;
2881 bfd_byte
*contents ATTRIBUTE_UNUSED
;
2883 howto
->src_mask
&= ~3;
2884 howto
->dst_mask
= howto
->src_mask
;
2886 *relocation
= val
+ addend
;
2892 xcoff_reloc_type_br (input_bfd
, input_section
, output_bfd
, rel
, sym
, howto
,
2893 val
, addend
, relocation
, contents
)
2895 asection
*input_section
;
2896 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2897 struct internal_reloc
*rel
;
2898 struct internal_syment
*sym ATTRIBUTE_UNUSED
;
2899 struct reloc_howto_struct
*howto
;
2902 bfd_vma
*relocation
;
2905 struct xcoff_link_hash_entry
*h
;
2907 if (0 > rel
->r_symndx
)
2910 h
= obj_xcoff_sym_hashes (input_bfd
)[rel
->r_symndx
];
2912 /* If we see an R_BR or R_RBR reloc which is jumping to global
2913 linkage code, and it is followed by an appropriate cror nop
2914 instruction, we replace the cror with lwz r2,20(r1). This
2915 restores the TOC after the glink code. Contrariwise, if the
2916 call is followed by a lwz r2,20(r1), but the call is not
2917 going to global linkage code, we can replace the load with a
2920 && bfd_link_hash_defined
== h
->root
.type
2921 && (rel
->r_vaddr
- input_section
->vma
+ 8 <=
2922 input_section
->_cooked_size
))
2927 pnext
= contents
+ (rel
->r_vaddr
- input_section
->vma
) + 4;
2928 next
= bfd_get_32 (input_bfd
, pnext
);
2930 /* The _ptrgl function is magic. It is used by the AIX
2931 compiler to call a function through a pointer. */
2932 if (h
->smclas
== XMC_GL
|| strcmp (h
->root
.root
.string
, "._ptrgl") == 0)
2934 if (next
== 0x4def7b82 /* cror 15,15,15 */
2935 || next
== 0x4ffffb82 /* cror 31,31,31 */
2936 || next
== 0x60000000) /* ori r0,r0,0 */
2937 bfd_put_32 (input_bfd
, 0x80410014, pnext
); /* lwz r1,20(r1) */
2941 if (next
== 0x80410014) /* lwz r1,20(r1) */
2942 bfd_put_32 (input_bfd
, 0x60000000, pnext
); /* ori r0,r0,0 */
2945 else if (NULL
!= h
&& bfd_link_hash_undefined
== h
->root
.type
)
2947 /* Normally, this relocation is against a defined symbol. In the
2948 case where this is a partial link and the output section offset
2949 is greater than 2^25, the linker will return an invalid error
2950 message that the relocation has been truncated. Yes it has been
2951 truncated but no it not important. For this case, disable the
2952 overflow checking. */
2954 howto
->complain_on_overflow
= complain_overflow_dont
;
2957 howto
->pc_relative
= true;
2958 howto
->src_mask
&= ~3;
2959 howto
->dst_mask
= howto
->src_mask
;
2961 /* A PC relative reloc includes the section address. */
2962 addend
+= input_section
->vma
;
2964 *relocation
= val
+ addend
;
2965 *relocation
-= (input_section
->output_section
->vma
+
2966 input_section
->output_offset
);
2971 xcoff_reloc_type_crel (input_bfd
, input_section
, output_bfd
, rel
, sym
, howto
,
2972 val
, addend
, relocation
, contents
)
2973 bfd
*input_bfd ATTRIBUTE_UNUSED
;
2974 asection
*input_section
;
2975 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2976 struct internal_reloc
*rel ATTRIBUTE_UNUSED
;
2977 struct internal_syment
*sym ATTRIBUTE_UNUSED
;
2978 struct reloc_howto_struct
*howto
;
2979 bfd_vma val ATTRIBUTE_UNUSED
;
2981 bfd_vma
*relocation
;
2982 bfd_byte
*contents ATTRIBUTE_UNUSED
;
2984 howto
->pc_relative
= true;
2985 howto
->src_mask
&= ~3;
2986 howto
->dst_mask
= howto
->src_mask
;
2988 /* A PC relative reloc includes the section address. */
2989 addend
+= input_section
->vma
;
2991 *relocation
= val
+ addend
;
2992 *relocation
-= (input_section
->output_section
->vma
+
2993 input_section
->output_offset
);
2998 xcoff_complain_overflow_dont_func (input_bfd
, val
, relocation
, howto
)
2999 bfd
*input_bfd ATTRIBUTE_UNUSED
;
3000 bfd_vma val ATTRIBUTE_UNUSED
;
3001 bfd_vma relocation ATTRIBUTE_UNUSED
;
3002 struct reloc_howto_struct
*howto ATTRIBUTE_UNUSED
;
3008 xcoff_complain_overflow_bitfield_func (input_bfd
, val
, relocation
, howto
)
3012 struct reloc_howto_struct
*howto
;
3014 bfd_vma addrmask
, fieldmask
, signmask
, ss
;
3017 /* Get the values to be added together. For signed and unsigned
3018 relocations, we assume that all values should be truncated to
3019 the size of an address. For bitfields, all the bits matter.
3020 See also bfd_check_overflow. */
3021 fieldmask
= N_ONES (howto
->bitsize
);
3022 addrmask
= N_ONES (bfd_arch_bits_per_address (input_bfd
)) | fieldmask
;
3024 b
= val
& howto
->src_mask
;
3026 /* Much like unsigned, except no trimming with addrmask. In
3027 addition, the sum overflows if there is a carry out of
3028 the bfd_vma, i.e., the sum is less than either input
3030 a
>>= howto
->rightshift
;
3031 b
>>= howto
->bitpos
;
3033 /* Bitfields are sometimes used for signed numbers; for
3034 example, a 13-bit field sometimes represents values in
3035 0..8191 and sometimes represents values in -4096..4095.
3036 If the field is signed and a is -4095 (0x1001) and b is
3037 -1 (0x1fff), the sum is -4096 (0x1000), but (0x1001 +
3038 0x1fff is 0x3000). It's not clear how to handle this
3039 everywhere, since there is not way to know how many bits
3040 are significant in the relocation, but the original code
3041 assumed that it was fully sign extended, and we will keep
3043 signmask
= (fieldmask
>> 1) + 1;
3045 if ((a
& ~ fieldmask
) != 0)
3047 /* Some bits out of the field are set. This might not
3048 be a problem: if this is a signed bitfield, it is OK
3049 iff all the high bits are set, including the sign
3050 bit. We'll try setting all but the most significant
3051 bit in the original relocation value: if this is all
3052 ones, we are OK, assuming a signed bitfield. */
3053 ss
= (signmask
<< howto
->rightshift
) - 1;
3054 if ((ss
| relocation
) != ~ (bfd_vma
) 0)
3059 /* We just assume (b & ~ fieldmask) == 0. */
3061 /* We explicitly permit wrap around if this relocation
3062 covers the high bit of an address. The Linux kernel
3063 relies on it, and it is the only way to write assembler
3064 code which can run when loaded at a location 0x80000000
3065 away from the location at which it is linked. */
3066 if (howto
->bitsize
+ howto
->rightshift
3067 == bfd_arch_bits_per_address (input_bfd
))
3071 if (sum
< a
|| (sum
& ~ fieldmask
) != 0)
3073 /* There was a carry out, or the field overflow. Test
3074 for signed operands again. Here is the overflow test
3075 is as for complain_overflow_signed. */
3076 if (((~ (a
^ b
)) & (a
^ sum
)) & signmask
)
3084 xcoff_complain_overflow_signed_func (input_bfd
, val
, relocation
, howto
)
3088 struct reloc_howto_struct
*howto
;
3090 bfd_vma addrmask
, fieldmask
, signmask
, ss
;
3093 /* Get the values to be added together. For signed and unsigned
3094 relocations, we assume that all values should be truncated to
3095 the size of an address. For bitfields, all the bits matter.
3096 See also bfd_check_overflow. */
3097 fieldmask
= N_ONES (howto
->bitsize
);
3098 addrmask
= N_ONES (bfd_arch_bits_per_address (input_bfd
)) | fieldmask
;
3100 b
= val
& howto
->src_mask
;
3102 a
= (a
& addrmask
) >> howto
->rightshift
;
3104 /* If any sign bits are set, all sign bits must be set.
3105 That is, A must be a valid negative address after
3107 signmask
= ~ (fieldmask
>> 1);
3109 if (ss
!= 0 && ss
!= ((addrmask
>> howto
->rightshift
) & signmask
))
3112 /* We only need this next bit of code if the sign bit of B
3113 is below the sign bit of A. This would only happen if
3114 SRC_MASK had fewer bits than BITSIZE. Note that if
3115 SRC_MASK has more bits than BITSIZE, we can get into
3116 trouble; we would need to verify that B is in range, as
3117 we do for A above. */
3118 signmask
= ((~ howto
->src_mask
) >> 1) & howto
->src_mask
;
3119 if ((b
& signmask
) != 0)
3121 /* Set all the bits above the sign bit. */
3122 b
-= signmask
<<= 1;
3125 b
= (b
& addrmask
) >> howto
->bitpos
;
3127 /* Now we can do the addition. */
3130 /* See if the result has the correct sign. Bits above the
3131 sign bit are junk now; ignore them. If the sum is
3132 positive, make sure we did not have all negative inputs;
3133 if the sum is negative, make sure we did not have all
3134 positive inputs. The test below looks only at the sign
3135 bits, and it really just
3136 SIGN (A) == SIGN (B) && SIGN (A) != SIGN (SUM)
3138 signmask
= (fieldmask
>> 1) + 1;
3139 if (((~ (a
^ b
)) & (a
^ sum
)) & signmask
)
3146 xcoff_complain_overflow_unsigned_func (input_bfd
, val
, relocation
, howto
)
3150 struct reloc_howto_struct
*howto
;
3152 bfd_vma addrmask
, fieldmask
;
3155 /* Get the values to be added together. For signed and unsigned
3156 relocations, we assume that all values should be truncated to
3157 the size of an address. For bitfields, all the bits matter.
3158 See also bfd_check_overflow. */
3159 fieldmask
= N_ONES (howto
->bitsize
);
3160 addrmask
= N_ONES (bfd_arch_bits_per_address (input_bfd
)) | fieldmask
;
3162 b
= val
& howto
->src_mask
;
3164 /* Checking for an unsigned overflow is relatively easy:
3165 trim the addresses and add, and trim the result as well.
3166 Overflow is normally indicated when the result does not
3167 fit in the field. However, we also need to consider the
3168 case when, e.g., fieldmask is 0x7fffffff or smaller, an
3169 input is 0x80000000, and bfd_vma is only 32 bits; then we
3170 will get sum == 0, but there is an overflow, since the
3171 inputs did not fit in the field. Instead of doing a
3172 separate test, we can check for this by or-ing in the
3173 operands when testing for the sum overflowing its final
3175 a
= (a
& addrmask
) >> howto
->rightshift
;
3176 b
= (b
& addrmask
) >> howto
->bitpos
;
3177 sum
= (a
+ b
) & addrmask
;
3178 if ((a
| b
| sum
) & ~ fieldmask
)
3184 /* This is the relocation function for the RS/6000/POWER/PowerPC.
3185 This is currently the only processor which uses XCOFF; I hope that
3188 I took the relocation type definitions from two documents:
3189 the PowerPC AIX Version 4 Application Binary Interface, First
3190 Edition (April 1992), and the PowerOpen ABI, Big-Endian
3191 32-Bit Hardware Implementation (June 30, 1994). Differences
3192 between the documents are noted below.
3194 Unsupported r_type's
3200 These relocs are defined by the PowerPC ABI to be
3201 relative branches which use half of the difference
3202 between the symbol and the program counter. I can't
3203 quite figure out when this is useful. These relocs are
3204 not defined by the PowerOpen ABI.
3209 Simple positive relocation.
3212 Simple negative relocation.
3215 Simple PC relative relocation.
3218 TOC relative relocation. The value in the instruction in
3219 the input file is the offset from the input file TOC to
3220 the desired location. We want the offset from the final
3221 TOC to the desired location. We have:
3226 so we must change insn by on - in.
3229 GL linkage relocation. The value of this relocation
3230 is the address of the entry in the TOC section.
3233 Local object TOC address. I can't figure out the
3234 difference between this and case R_GL.
3237 TOC relative relocation. A TOC relative load instruction
3238 which may be changed to a load address instruction.
3239 FIXME: We don't currently implement this optimization.
3242 TOC relative relocation. This is a TOC relative load
3243 address instruction which may be changed to a load
3244 instruction. FIXME: I don't know if this is the correct
3248 Absolute branch. We don't want to mess with the lower
3249 two bits of the instruction.
3252 The PowerPC ABI defines this as an absolute call which
3253 may be modified to become a relative call. The PowerOpen
3254 ABI does not define this relocation type.
3257 Absolute branch which may be modified to become a
3261 The PowerPC ABI defines this as an absolute branch to a
3262 fixed address which may be modified to an absolute branch
3263 to a symbol. The PowerOpen ABI does not define this
3267 The PowerPC ABI defines this as an absolute branch to a
3268 fixed address which may be modified to a relative branch.
3269 The PowerOpen ABI does not define this relocation type.
3272 Relative branch. We don't want to mess with the lower
3273 two bits of the instruction.
3276 The PowerPC ABI defines this as a relative call which may
3277 be modified to become an absolute call. The PowerOpen
3278 ABI does not define this relocation type.
3281 A relative branch which may be modified to become an
3282 absolute branch. FIXME: We don't implement this,
3283 although we should for symbols of storage mapping class
3287 The PowerPC AIX ABI describes this as a load which may be
3288 changed to a load address. The PowerOpen ABI says this
3289 is the same as case R_POS.
3292 The PowerPC AIX ABI describes this as a load address
3293 which may be changed to a load. The PowerOpen ABI says
3294 this is the same as R_POS.
3298 xcoff_ppc_relocate_section (output_bfd
, info
, input_bfd
,
3299 input_section
, contents
, relocs
, syms
,
3302 struct bfd_link_info
*info
;
3304 asection
*input_section
;
3306 struct internal_reloc
*relocs
;
3307 struct internal_syment
*syms
;
3308 asection
**sections
;
3310 struct internal_reloc
*rel
;
3311 struct internal_reloc
*relend
;
3314 relend
= rel
+ input_section
->reloc_count
;
3315 for (; rel
< relend
; rel
++)
3318 struct xcoff_link_hash_entry
*h
;
3319 struct internal_syment
*sym
;
3322 struct reloc_howto_struct howto
;
3324 bfd_vma value_to_relocate
;
3328 /* Relocation type R_REF is a special relocation type which is
3329 merely used to prevent garbage collection from occurring for
3330 the csect including the symbol which it references. */
3331 if (rel
->r_type
== R_REF
)
3335 howto
.type
= rel
->r_type
;
3336 howto
.rightshift
= 0;
3337 howto
.bitsize
= (rel
->r_size
& 0x1f) + 1;
3338 howto
.size
= howto
.bitsize
> 16 ? 2 : 1;
3339 howto
.pc_relative
= false;
3341 howto
.complain_on_overflow
= rel
->r_size
& 0x80 ?
3342 complain_overflow_signed
: complain_overflow_bitfield
;
3343 howto
.special_function
= NULL
;
3344 howto
.name
= "internal";
3345 howto
.partial_inplace
= true;
3346 howto
.src_mask
= howto
.dst_mask
= N_ONES(howto
.bitsize
);
3347 howto
.pcrel_offset
= false;
3354 symndx
= rel
->r_symndx
;
3360 h
= obj_xcoff_sym_hashes (input_bfd
)[symndx
];
3361 sym
= syms
+ symndx
;
3362 addend
= - sym
->n_value
;
3366 sec
= sections
[symndx
];
3367 /* Hack to make sure we use the right TOC anchor value
3368 if this reloc is against the TOC anchor. */
3369 if (sec
->name
[3] == '0'
3370 && strcmp (sec
->name
, ".tc0") == 0)
3371 val
= xcoff_data (output_bfd
)->toc
;
3373 val
= (sec
->output_section
->vma
3374 + sec
->output_offset
3380 if (h
->root
.type
== bfd_link_hash_defined
3381 || h
->root
.type
== bfd_link_hash_defweak
)
3383 sec
= h
->root
.u
.def
.section
;
3384 val
= (h
->root
.u
.def
.value
3385 + sec
->output_section
->vma
3386 + sec
->output_offset
);
3388 else if (h
->root
.type
== bfd_link_hash_common
)
3390 sec
= h
->root
.u
.c
.p
->section
;
3391 val
= (sec
->output_section
->vma
3392 + sec
->output_offset
);
3395 else if ((0 == (h
->flags
& (XCOFF_DEF_DYNAMIC
| XCOFF_IMPORT
)))
3396 && ! info
->relocateable
)
3398 if (! ((*info
->callbacks
->undefined_symbol
)
3399 (info
, h
->root
.root
.string
, input_bfd
, input_section
,
3400 rel
->r_vaddr
- input_section
->vma
, true)))
3403 /* Don't try to process the reloc. It can't help, and
3404 it may generate another error. */
3410 if (rel
->r_type
>= XCOFF_MAX_CALCULATE_RELOCATION
3411 || (false == xcoff_calculate_relocation
[rel
->r_type
]
3412 (input_bfd
, input_section
, output_bfd
, rel
, sym
, &howto
, val
,
3413 addend
, &relocation
, contents
)))
3417 address
= rel
->r_vaddr
- input_section
->vma
;
3418 location
= contents
+ address
;
3420 if (address
> input_section
->_raw_size
)
3423 /* Get the value we are going to relocate. */
3424 if (1 == howto
.size
)
3425 value_to_relocate
= bfd_get_16 (input_bfd
, location
);
3427 value_to_relocate
= bfd_get_32 (input_bfd
, location
);
3431 FIXME: We may drop bits during the addition
3432 which we don't check for. We must either check at every single
3433 operation, which would be tedious, or we must do the computations
3434 in a type larger than bfd_vma, which would be inefficient. */
3436 if ((unsigned int) howto
.complain_on_overflow
>=
3437 XCOFF_MAX_COMPLAIN_OVERFLOW
)
3440 if ((true == xcoff_complain_overflow
[howto
.complain_on_overflow
]
3441 (input_bfd
, value_to_relocate
, relocation
, &howto
)))
3444 char buf
[SYMNMLEN
+ 1];
3445 char reloc_type_name
[10];
3453 name
= h
->root
.root
.string
;
3457 name
= _bfd_coff_internal_syment_name (input_bfd
, sym
, buf
);
3461 sprintf (reloc_type_name
, "0x%02x", rel
->r_type
);
3463 if (! ((*info
->callbacks
->reloc_overflow
)
3464 (info
, name
, reloc_type_name
, (bfd_vma
) 0, input_bfd
,
3465 input_section
, rel
->r_vaddr
- input_section
->vma
)))
3469 /* Add RELOCATION to the right bits of VALUE_TO_RELOCATE. */
3470 value_to_relocate
= ((value_to_relocate
& ~howto
.dst_mask
) |
3471 (((value_to_relocate
& howto
.src_mask
) +
3472 relocation
) & howto
.dst_mask
));
3474 /* Put the value back in the object file. */
3475 if (1 == howto
.size
)
3476 bfd_put_16 (input_bfd
, value_to_relocate
, location
);
3478 bfd_put_32 (input_bfd
, value_to_relocate
, location
);
3485 _bfd_xcoff_put_ldsymbol_name (abfd
, ldinfo
, ldsym
, name
)
3486 bfd
*abfd ATTRIBUTE_UNUSED
;
3487 struct xcoff_loader_info
*ldinfo
;
3488 struct internal_ldsym
*ldsym
;
3492 len
= strlen (name
);
3494 if (len
<= SYMNMLEN
)
3495 strncpy (ldsym
->_l
._l_name
, name
, SYMNMLEN
);
3498 if (ldinfo
->string_size
+ len
+ 3 > ldinfo
->string_alc
)
3500 bfd_size_type newalc
;
3501 bfd_byte
*newstrings
;
3503 newalc
= ldinfo
->string_alc
* 2;
3506 while (ldinfo
->string_size
+ len
+ 3 > newalc
)
3509 newstrings
= ((bfd_byte
*)
3510 bfd_realloc ((PTR
) ldinfo
->strings
, newalc
));
3511 if (newstrings
== NULL
)
3513 ldinfo
->failed
= true;
3516 ldinfo
->string_alc
= newalc
;
3517 ldinfo
->strings
= newstrings
;
3520 bfd_put_16 (ldinfo
->output_bfd
, (bfd_vma
) (len
+ 1),
3521 ldinfo
->strings
+ ldinfo
->string_size
);
3522 strcpy (ldinfo
->strings
+ ldinfo
->string_size
+ 2, name
);
3523 ldsym
->_l
._l_l
._l_zeroes
= 0;
3524 ldsym
->_l
._l_l
._l_offset
= ldinfo
->string_size
+ 2;
3525 ldinfo
->string_size
+= len
+ 3;
3532 _bfd_xcoff_put_symbol_name (bfd
*abfd
, struct bfd_strtab_hash
*strtab
,
3533 struct internal_syment
*sym
,
3536 if (strlen (name
) <= SYMNMLEN
)
3538 strncpy (sym
->_n
._n_name
, name
, SYMNMLEN
);
3546 if ((abfd
->flags
& BFD_TRADITIONAL_FORMAT
) != 0)
3548 indx
= _bfd_stringtab_add (strtab
, name
, hash
, false);
3549 if (indx
== (bfd_size_type
) -1)
3551 sym
->_n
._n_n
._n_zeroes
= 0;
3552 sym
->_n
._n_n
._n_offset
= STRING_SIZE_SIZE
+ indx
;
3558 xcoff_create_csect_from_smclas (abfd
, aux
, symbol_name
)
3560 union internal_auxent
*aux
;
3561 const char *symbol_name
;
3563 asection
*return_value
= NULL
;
3565 /* .sv64 = x_smclas == 17
3566 This is an invalid csect for 32 bit apps. */
3567 static const char *names
[19] =
3569 ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo",
3570 ".sv", ".bs", ".ds", ".uc", ".ti", ".tb", NULL
, ".tc0",
3571 ".td", NULL
, ".sv3264"
3574 if ((19 >= aux
->x_csect
.x_smclas
) &&
3575 (NULL
!= names
[aux
->x_csect
.x_smclas
]))
3577 return_value
= bfd_make_section_anyway
3578 (abfd
, names
[aux
->x_csect
.x_smclas
]);
3582 (*_bfd_error_handler
)
3583 (_("%s: symbol `%s' has unrecognized smclas %d"),
3584 bfd_archive_filename (abfd
), symbol_name
, aux
->x_csect
.x_smclas
);
3585 bfd_set_error (bfd_error_bad_value
);
3588 return return_value
;
3592 xcoff_is_lineno_count_overflow (abfd
, value
)
3593 bfd
*abfd ATTRIBUTE_UNUSED
;
3596 if (0xffff <= value
)
3603 xcoff_is_reloc_count_overflow (abfd
, value
)
3604 bfd
*abfd ATTRIBUTE_UNUSED
;
3607 if (0xffff <= value
)
3614 xcoff_loader_symbol_offset (abfd
, ldhdr
)
3616 struct internal_ldhdr
*ldhdr ATTRIBUTE_UNUSED
;
3618 return bfd_xcoff_ldhdrsz(abfd
);
3622 xcoff_loader_reloc_offset (abfd
, ldhdr
)
3624 struct internal_ldhdr
*ldhdr
;
3626 return bfd_xcoff_ldhdrsz(abfd
) +
3627 (ldhdr
->l_nsyms
* bfd_xcoff_ldsymsz(abfd
));
3631 xcoff_generate_rtinit (abfd
, init
, fini
, rtld
)
3637 bfd_byte filehdr_ext
[FILHSZ
];
3638 bfd_byte scnhdr_ext
[SCNHSZ
];
3639 bfd_byte syment_ext
[SYMESZ
* 10];
3640 bfd_byte reloc_ext
[RELSZ
* 3];
3641 bfd_byte
*data_buffer
;
3642 bfd_size_type data_buffer_size
;
3643 bfd_byte
*string_table
= NULL
, *st_tmp
= NULL
;
3644 bfd_size_type string_table_size
;
3646 size_t initsz
, finisz
;
3647 struct internal_filehdr filehdr
;
3648 struct internal_scnhdr scnhdr
;
3649 struct internal_syment syment
;
3650 union internal_auxent auxent
;
3651 struct internal_reloc reloc
;
3653 char *data_name
= ".data";
3654 char *rtinit_name
= "__rtinit";
3655 char *rtld_name
= "__rtld";
3657 if (! bfd_xcoff_rtinit_size (abfd
))
3660 initsz
= (init
== NULL
? 0 : 1 + strlen (init
));
3661 finisz
= (fini
== NULL
? 0 : 1 + strlen (fini
));
3664 memset (filehdr_ext
, 0, FILHSZ
);
3665 memset (&filehdr
, 0, sizeof (struct internal_filehdr
));
3666 filehdr
.f_magic
= bfd_xcoff_magic_number (abfd
);
3667 filehdr
.f_nscns
= 1;
3668 filehdr
.f_timdat
= 0;
3669 filehdr
.f_nsyms
= 0; /* at least 6, no more than 10 */
3670 filehdr
.f_symptr
= 0; /* set below */
3671 filehdr
.f_opthdr
= 0;
3672 filehdr
.f_flags
= 0;
3674 /* section header */
3675 memset (scnhdr_ext
, 0, SCNHSZ
);
3676 memset (&scnhdr
, 0, sizeof (struct internal_scnhdr
));
3677 memcpy (scnhdr
.s_name
, data_name
, strlen (data_name
));
3680 scnhdr
.s_size
= 0; /* set below */
3681 scnhdr
.s_scnptr
= FILHSZ
+ SCNHSZ
;
3682 scnhdr
.s_relptr
= 0; /* set below */
3683 scnhdr
.s_lnnoptr
= 0;
3684 scnhdr
.s_nreloc
= 0; /* either 1 or 2 */
3686 scnhdr
.s_flags
= STYP_DATA
;
3689 0x0000 0x00000000 : rtl
3690 0x0004 0x00000010 : offset to init, or 0
3691 0x0008 0x00000028 : offset to fini, or 0
3692 0x000C 0x0000000C : size of descriptor
3693 0x0010 0x00000000 : init, needs a reloc
3694 0x0014 0x00000040 : offset to init name
3695 0x0018 0x00000000 : flags, padded to a word
3696 0x001C 0x00000000 : empty init
3699 0x0028 0x00000000 : fini, needs a reloc
3700 0x002C 0x00000??? : offset to fini name
3701 0x0030 0x00000000 : flags, padded to a word
3702 0x0034 0x00000000 : empty fini
3706 0x0040 + initsz fini name */
3708 data_buffer_size
= 0x0040 + initsz
+ finisz
;
3709 data_buffer_size
+= (data_buffer_size
& 7) ? 8 - (data_buffer_size
& 7) : 0;
3711 data_buffer
= (bfd_byte
*) bfd_malloc (data_buffer_size
);
3712 if (data_buffer
== NULL
)
3715 memset (data_buffer
, 0, data_buffer_size
);
3720 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x04]);
3722 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x14]);
3723 memcpy (&data_buffer
[val
], init
, initsz
);
3729 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x08]);
3730 val
= 0x40 + initsz
;
3731 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x2C]);
3732 memcpy (&data_buffer
[val
], fini
, finisz
);
3736 bfd_h_put_32 (abfd
, val
, &data_buffer
[0x0C]);
3738 scnhdr
.s_size
= data_buffer_size
;
3741 string_table_size
= 0;
3743 string_table_size
+= initsz
;
3745 string_table_size
+= finisz
;
3746 if (string_table_size
)
3748 string_table_size
+= 4;
3749 string_table
= (bfd_byte
*)bfd_malloc (string_table_size
);
3750 memset (string_table
, 0, string_table_size
);
3751 val
= string_table_size
;
3752 bfd_h_put_32 (abfd
, val
, &string_table
[0]);
3753 st_tmp
= string_table
+ 4;
3762 memset (syment_ext
, 0, 10 * SYMESZ
);
3763 memset (reloc_ext
, 0, 3 * RELSZ
);
3766 memset (&syment
, 0, sizeof (struct internal_syment
));
3767 memset (&auxent
, 0, sizeof (union internal_auxent
));
3768 memcpy (syment
._n
._n_name
, data_name
, strlen (data_name
));
3770 syment
.n_sclass
= C_HIDEXT
;
3771 syment
.n_numaux
= 1;
3772 auxent
.x_csect
.x_scnlen
.l
= data_buffer_size
;
3773 auxent
.x_csect
.x_smtyp
= 3 << 3 | XTY_SD
;
3774 auxent
.x_csect
.x_smclas
= XMC_RW
;
3775 bfd_coff_swap_sym_out (abfd
, &syment
,
3776 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3777 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3779 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3780 filehdr
.f_nsyms
+= 2;
3783 memset (&syment
, 0, sizeof (struct internal_syment
));
3784 memset (&auxent
, 0, sizeof (union internal_auxent
));
3785 memcpy (syment
._n
._n_name
, rtinit_name
, strlen (rtinit_name
));
3787 syment
.n_sclass
= C_EXT
;
3788 syment
.n_numaux
= 1;
3789 auxent
.x_csect
.x_smtyp
= XTY_LD
;
3790 auxent
.x_csect
.x_smclas
= XMC_RW
;
3791 bfd_coff_swap_sym_out (abfd
, &syment
,
3792 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3793 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3795 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3796 filehdr
.f_nsyms
+= 2;
3801 memset (&syment
, 0, sizeof (struct internal_syment
));
3802 memset (&auxent
, 0, sizeof (union internal_auxent
));
3806 syment
._n
._n_n
._n_offset
= st_tmp
- string_table
;
3807 memcpy (st_tmp
, init
, initsz
);
3811 memcpy (syment
._n
._n_name
, init
, initsz
- 1);
3813 syment
.n_sclass
= C_EXT
;
3814 syment
.n_numaux
= 1;
3815 bfd_coff_swap_sym_out (abfd
, &syment
,
3816 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3817 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3819 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3822 memset (&reloc
, 0, sizeof (struct internal_reloc
));
3823 reloc
.r_vaddr
= 0x0010;
3824 reloc
.r_symndx
= filehdr
.f_nsyms
;
3825 reloc
.r_type
= R_POS
;
3827 bfd_coff_swap_reloc_out (abfd
, &reloc
, &reloc_ext
[0]);
3829 filehdr
.f_nsyms
+= 2;
3830 scnhdr
.s_nreloc
+= 1;
3836 memset (&syment
, 0, sizeof (struct internal_syment
));
3837 memset (&auxent
, 0, sizeof (union internal_auxent
));
3841 syment
._n
._n_n
._n_offset
= st_tmp
- string_table
;
3842 memcpy (st_tmp
, fini
, finisz
);
3846 memcpy (syment
._n
._n_name
, fini
, finisz
- 1);
3848 syment
.n_sclass
= C_EXT
;
3849 syment
.n_numaux
= 1;
3850 bfd_coff_swap_sym_out (abfd
, &syment
,
3851 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3852 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3854 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3857 memset (&reloc
, 0, sizeof (struct internal_reloc
));
3858 reloc
.r_vaddr
= 0x0028;
3859 reloc
.r_symndx
= filehdr
.f_nsyms
;
3860 reloc
.r_type
= R_POS
;
3862 bfd_coff_swap_reloc_out (abfd
, &reloc
,
3863 &reloc_ext
[scnhdr
.s_nreloc
* RELSZ
]);
3865 filehdr
.f_nsyms
+= 2;
3866 scnhdr
.s_nreloc
+= 1;
3871 memset (&syment
, 0, sizeof (struct internal_syment
));
3872 memset (&auxent
, 0, sizeof (union internal_auxent
));
3873 memcpy (syment
._n
._n_name
, rtld_name
, strlen (rtld_name
));
3874 syment
.n_sclass
= C_EXT
;
3875 syment
.n_numaux
= 1;
3876 bfd_coff_swap_sym_out (abfd
, &syment
,
3877 &syment_ext
[filehdr
.f_nsyms
* SYMESZ
]);
3878 bfd_coff_swap_aux_out (abfd
, &auxent
, syment
.n_type
, syment
.n_sclass
, 0,
3880 &syment_ext
[(filehdr
.f_nsyms
+ 1) * SYMESZ
]);
3883 memset (&reloc
, 0, sizeof (struct internal_reloc
));
3884 reloc
.r_vaddr
= 0x0000;
3885 reloc
.r_symndx
= filehdr
.f_nsyms
;
3886 reloc
.r_type
= R_POS
;
3888 bfd_coff_swap_reloc_out (abfd
, &reloc
,
3889 &reloc_ext
[scnhdr
.s_nreloc
* RELSZ
]);
3891 filehdr
.f_nsyms
+= 2;
3892 scnhdr
.s_nreloc
+= 1;
3895 scnhdr
.s_relptr
= scnhdr
.s_scnptr
+ data_buffer_size
;
3896 filehdr
.f_symptr
= scnhdr
.s_relptr
+ scnhdr
.s_nreloc
* RELSZ
;
3898 bfd_coff_swap_filehdr_out (abfd
, &filehdr
, filehdr_ext
);
3899 bfd_bwrite (filehdr_ext
, FILHSZ
, abfd
);
3900 bfd_coff_swap_scnhdr_out (abfd
, &scnhdr
, scnhdr_ext
);
3901 bfd_bwrite (scnhdr_ext
, SCNHSZ
, abfd
);
3902 bfd_bwrite (data_buffer
, data_buffer_size
, abfd
);
3903 bfd_bwrite (reloc_ext
, scnhdr
.s_nreloc
* RELSZ
, abfd
);
3904 bfd_bwrite (syment_ext
, filehdr
.f_nsyms
* SYMESZ
, abfd
);
3905 bfd_bwrite (string_table
, string_table_size
, abfd
);
3914 static reloc_howto_type xcoff_dynamic_reloc
=
3915 HOWTO (0, /* type */
3917 2, /* size (0 = byte, 1 = short, 2 = long) */
3919 false, /* pc_relative */
3921 complain_overflow_bitfield
, /* complain_on_overflow */
3922 0, /* special_function */
3924 true, /* partial_inplace */
3925 0xffffffff, /* src_mask */
3926 0xffffffff, /* dst_mask */
3927 false); /* pcrel_offset */
3931 The first word of global linkage code must be modified by filling in
3932 the correct TOC offset. */
3934 static unsigned long xcoff_glink_code
[9] =
3936 0x81820000, /* lwz r12,0(r2) */
3937 0x90410014, /* stw r2,20(r1) */
3938 0x800c0000, /* lwz r0,0(r12) */
3939 0x804c0004, /* lwz r2,4(r12) */
3940 0x7c0903a6, /* mtctr r0 */
3941 0x4e800420, /* bctr */
3942 0x00000000, /* start of traceback table */
3943 0x000c8000, /* traceback table */
3944 0x00000000, /* traceback table */
3948 static const struct xcoff_backend_data_rec bfd_xcoff_backend_data
=
3950 { /* COFF backend, defined in libcoff.h. */
3951 _bfd_xcoff_swap_aux_in
, /* _bfd_coff_swap_aux_in */
3952 _bfd_xcoff_swap_sym_in
, /* _bfd_coff_swap_sym_in */
3953 coff_swap_lineno_in
, /* _bfd_coff_swap_lineno_in */
3954 _bfd_xcoff_swap_aux_out
, /* _bfd_swap_aux_out */
3955 _bfd_xcoff_swap_sym_out
, /* _bfd_swap_sym_out */
3956 coff_swap_lineno_out
, /* _bfd_swap_lineno_out */
3957 xcoff_swap_reloc_out
, /* _bfd_swap_reloc_out */
3958 coff_swap_filehdr_out
, /* _bfd_swap_filehdr_out */
3959 coff_swap_aouthdr_out
, /* _bfd_swap_aouthdr_out */
3960 coff_swap_scnhdr_out
, /* _bfd_swap_scnhdr_out */
3961 FILHSZ
, /* _bfd_filhsz */
3962 AOUTSZ
, /* _bfd_aoutsz */
3963 SCNHSZ
, /* _bfd_scnhsz */
3964 SYMESZ
, /* _bfd_symesz */
3965 AUXESZ
, /* _bfd_auxesz */
3966 RELSZ
, /* _bfd_relsz */
3967 LINESZ
, /* _bfd_linesz */
3968 FILNMLEN
, /* _bfd_filnmlen */
3969 true, /* _bfd_coff_long_filenames */
3970 false, /* _bfd_coff_long_section_names */
3971 (3), /* _bfd_coff_default_section_alignment_power */
3972 false, /* _bfd_coff_force_symnames_in_strings */
3973 2, /* _bfd_coff_debug_string_prefix_length */
3974 coff_swap_filehdr_in
, /* _bfd_coff_swap_filehdr_in */
3975 coff_swap_aouthdr_in
, /* _bfd_swap_aouthdr_in */
3976 coff_swap_scnhdr_in
, /* _bfd_swap_scnhdr_in */
3977 xcoff_swap_reloc_in
, /* _bfd_reloc_in */
3978 coff_bad_format_hook
, /* _bfd_bad_format_hook */
3979 coff_set_arch_mach_hook
, /* _bfd_set_arch_mach_hook */
3980 coff_mkobject_hook
, /* _bfd_mkobject_hook */
3981 styp_to_sec_flags
, /* _bfd_syp_to_sec_flags */
3982 coff_set_alignment_hook
, /* _bfd_set_alignment_hook */
3983 coff_slurp_symbol_table
, /* _bfd_coff_slurp_symbol_table */
3984 symname_in_debug_hook
, /* _coff_symname_in_debug_hook */
3985 coff_pointerize_aux_hook
, /* _bfd_coff_pointerize_aux_hook */
3986 coff_print_aux
, /* bfd_coff_print_aux */
3987 dummy_reloc16_extra_cases
, /* _bfd_coff_reloc16_extra_cases */
3988 dummy_reloc16_estimate
, /* _bfd_coff_reloc16_estimate */
3989 NULL
, /* bfd_coff_sym_is_global */
3990 coff_compute_section_file_positions
, /* _bfd_coff_compute_section_file_positions */
3991 NULL
, /* _bfd_coff_start_final_link */
3992 xcoff_ppc_relocate_section
, /* _bfd_coff_relocate_section */
3993 coff_rtype_to_howto
, /* _bfd_coff_rtype_to_howto */
3994 NULL
, /* _bfd_coff_addust_symndx */
3995 _bfd_generic_link_add_one_symbol
, /* _bfd_coff_add_one_symbol */
3996 coff_link_output_has_begun
, /* _bfd_coff_link_output_has_begun */
3997 coff_final_link_postscript
/* _bfd_coff_final_link_postscript */
4000 0x01DF, /* magic number */
4001 bfd_arch_rs6000
, /* architecture */
4002 bfd_mach_rs6k
, /* machine */
4004 /* Function pointers to xcoff specific swap routines. */
4005 xcoff_swap_ldhdr_in
, /* _xcoff_swap_ldhdr_in */
4006 xcoff_swap_ldhdr_out
, /* _xcoff_swap_ldhdr_out */
4007 xcoff_swap_ldsym_in
, /* _xcoff_swap_ldsym_in */
4008 xcoff_swap_ldsym_out
, /* _xcoff_swap_ldsym_out */
4009 xcoff_swap_ldrel_in
, /* _xcoff_swap_ldrel_in */
4010 xcoff_swap_ldrel_out
, /* _xcoff_swap_ldrel_out */
4013 LDHDRSZ
, /* _xcoff_ldhdrsz */
4014 LDSYMSZ
, /* _xcoff_ldsymsz */
4015 LDRELSZ
, /* _xcoff_ldrelsz */
4016 12, /* _xcoff_function_descriptor_size */
4017 SMALL_AOUTSZ
, /* _xcoff_small_aout_header_size */
4020 1, /* _xcoff_ldhdr_version */
4022 _bfd_xcoff_put_symbol_name
, /* _xcoff_put_symbol_name */
4023 _bfd_xcoff_put_ldsymbol_name
, /* _xcoff_put_ldsymbol_name */
4024 & xcoff_dynamic_reloc
, /* dynamic reloc howto */
4025 xcoff_create_csect_from_smclas
, /* _xcoff_create_csect_from_smclas */
4027 /* Lineno and reloc count overflow. */
4028 xcoff_is_lineno_count_overflow
,
4029 xcoff_is_reloc_count_overflow
,
4031 xcoff_loader_symbol_offset
,
4032 xcoff_loader_reloc_offset
,
4035 & xcoff_glink_code
[0],
4036 (36), /* _xcoff_glink_size */
4039 64, /* _xcoff_rtinit_size */
4040 xcoff_generate_rtinit
, /* _xcoff_generate_rtinit */
4043 /* The transfer vector that leads the outside world to all of the above. */
4044 const bfd_target rs6000coff_vec
=
4047 bfd_target_xcoff_flavour
,
4048 BFD_ENDIAN_BIG
, /* data byte order is big */
4049 BFD_ENDIAN_BIG
, /* header byte order is big */
4051 (HAS_RELOC
| EXEC_P
| /* object flags */
4052 HAS_LINENO
| HAS_DEBUG
| DYNAMIC
|
4053 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
),
4055 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
4056 0, /* leading char */
4057 '/', /* ar_pad_char */
4058 15, /* ar_max_namelen??? FIXMEmgo */
4061 bfd_getb64
, /* bfd_getx64 */
4062 bfd_getb_signed_64
, /* bfd_getx_signed_64 */
4063 bfd_putb64
, /* bfd_putx64 */
4064 bfd_getb32
, /* bfd_getx32 */
4065 bfd_getb_signed_32
, /* bfd_getx_signed_32 */
4066 bfd_putb32
, /* bfd_putx32 */
4067 bfd_getb16
, /* bfd_getx16 */
4068 bfd_getb_signed_16
, /* bfd_getx_signed_16 */
4069 bfd_putb16
, /* bfd_putx16 */
4072 bfd_getb64
, /* bfd_h_getx64 */
4073 bfd_getb_signed_64
, /* bfd_h_getx_signed_64 */
4074 bfd_putb64
, /* bfd_h_putx64 */
4075 bfd_getb32
, /* bfd_h_getx32 */
4076 bfd_getb_signed_32
, /* bfd_h_getx_signed_32 */
4077 bfd_putb32
, /* bfd_h_putx32 */
4078 bfd_getb16
, /* bfd_h_getx16 */
4079 bfd_getb_signed_16
, /* bfd_h_getx_signed_16 */
4080 bfd_putb16
, /* bfd_h_putx16 */
4082 { /* bfd_check_format */
4085 _bfd_xcoff_archive_p
,
4089 { /* bfd_set_format */
4092 _bfd_generic_mkarchive
,
4096 {/* bfd_write_contents */
4098 coff_write_object_contents
,
4099 _bfd_xcoff_write_archive_contents
,
4104 bfd_true
, /* _close_and_cleanup */
4105 bfd_true
, /* _bfd_free_cached_info */
4106 coff_new_section_hook
, /* _new_section_hook */
4107 _bfd_generic_get_section_contents
, /* _bfd_get_section_contents */
4108 /* _bfd_get_section_contents_in_window */
4109 _bfd_generic_get_section_contents_in_window
,
4112 _bfd_xcoff_copy_private_bfd_data
, /* _bfd_copy_private_bfd */
4113 /* _bfd_merge_private_bfd_data */
4114 ((boolean (*) (bfd
*, bfd
*)) bfd_true
),
4115 /* _bfd_copy_pivate_section_data */
4116 ((boolean (*) (bfd
*, asection
*, bfd
*, asection
*)) bfd_true
),
4117 /* _bfd_copy_private_symbol_data */
4118 ((boolean (*) (bfd
*, asymbol
*, bfd
*, asymbol
*)) bfd_true
),
4119 ((boolean (*) (bfd
*, flagword
)) bfd_true
), /* _bfd_set_private_flags */
4120 ((boolean (*) (bfd
*, void * )) bfd_true
), /* _bfd_print_private_bfd_data */
4123 coff_core_file_failing_command
, /* _core_file_failing_command */
4124 coff_core_file_failing_signal
, /* _core_file_failing_signal */
4125 /* _core_file_matches_executable_p */
4126 coff_core_file_matches_executable_p
,
4129 _bfd_xcoff_slurp_armap
, /* _slurp_armap */
4130 /* XCOFF archives do not have
4131 anything which corresponds to
4132 an extended name table. */
4133 bfd_false
, /* _slurp_extended_name_table */
4134 /* _construct_extended_name_table */
4135 ((boolean (*) (bfd
*, char **, bfd_size_type
*, const char **)) bfd_false
),
4136 bfd_dont_truncate_arname
, /* _truncate_arname */
4137 _bfd_xcoff_write_armap
, /* _write_armap */
4138 _bfd_xcoff_read_ar_hdr
, /* _read_ar_hdr */
4139 _bfd_xcoff_openr_next_archived_file
, /* _openr_next_archived_file */
4140 _bfd_generic_get_elt_at_index
, /* _get_elt_at_index */
4141 _bfd_xcoff_stat_arch_elt
, /* _generic_stat_arch_elt */
4142 /* XCOFF archives do not have
4144 bfd_true
, /* _update_armap_timestamp */
4147 coff_get_symtab_upper_bound
, /* _get_symtab_upper_bound */
4148 coff_get_symtab
, /* _get_symtab */
4149 coff_make_empty_symbol
, /* _make_empty_symbol */
4150 coff_print_symbol
, /* _print_symbol */
4151 coff_get_symbol_info
, /* _get_symbol_info */
4152 _bfd_xcoff_is_local_label_name
, /* _bfd_is_local_label_name */
4153 coff_get_lineno
, /* _get_lineno */
4154 coff_find_nearest_line
, /* _find_nearest_line */
4155 coff_bfd_make_debug_symbol
, /* _bfd_make_debug_symbol */
4156 _bfd_generic_read_minisymbols
, /* _read_minisymbols */
4157 _bfd_generic_minisymbol_to_symbol
, /* _minsymbol_to_symbol */
4160 coff_get_reloc_upper_bound
, /* _get_reloc_upper_bound */
4161 coff_canonicalize_reloc
, /* _cononicalize_reloc */
4162 _bfd_xcoff_reloc_type_lookup
, /* _bfd_reloc_type_lookup */
4165 coff_set_arch_mach
, /* _set_arch_mach */
4166 coff_set_section_contents
, /* _set_section_contents */
4169 _bfd_xcoff_sizeof_headers
, /* _sizeof_headers */
4170 /* _bfd_get_relocated_section_contents */
4171 bfd_generic_get_relocated_section_contents
,
4172 bfd_generic_relax_section
, /* _bfd_relax_section */
4173 _bfd_xcoff_bfd_link_hash_table_create
, /* _bfd_link_hash_table_create */
4174 _bfd_generic_link_hash_table_free
, /* _bfd_link_hash_table_free */
4175 _bfd_xcoff_bfd_link_add_symbols
, /* _bfd_link_add_symbols */
4176 _bfd_xcoff_bfd_final_link
, /* _bfd_filnal_link */
4177 _bfd_generic_link_split_section
, /* _bfd_link_split_section */
4178 bfd_generic_gc_sections
, /* _bfd_gc_sections */
4179 bfd_generic_merge_sections
, /* _bfd_merge_sections */
4182 /* _get_dynamic_symtab_upper_bound */
4183 _bfd_xcoff_get_dynamic_symtab_upper_bound
,
4184 _bfd_xcoff_canonicalize_dynamic_symtab
, /* _cononicalize_dynamic_symtab */
4185 _bfd_xcoff_get_dynamic_reloc_upper_bound
,/* _get_dynamic_reloc_upper_bound */
4186 _bfd_xcoff_canonicalize_dynamic_reloc
, /* _cononicalize_dynamic_reloc */
4188 /* Opposite endian version, none exists */
4192 (void *) &bfd_xcoff_backend_data
,
4196 * xcoff-powermac target
4198 * Only difference between this target and the rs6000 target is the
4199 * the default architecture and machine type used in coffcode.h
4201 * PowerPC Macs use the same magic numbers as RS/6000
4202 * (because that's how they were bootstrapped originally),
4203 * but they are always PowerPC architecture.
4205 static const struct xcoff_backend_data_rec bfd_pmac_xcoff_backend_data
=
4207 { /* COFF backend, defined in libcoff.h */
4208 _bfd_xcoff_swap_aux_in
, /* _bfd_coff_swap_aux_in */
4209 _bfd_xcoff_swap_sym_in
, /* _bfd_coff_swap_sym_in */
4210 coff_swap_lineno_in
, /* _bfd_coff_swap_lineno_in */
4211 _bfd_xcoff_swap_aux_out
, /* _bfd_swap_aux_out */
4212 _bfd_xcoff_swap_sym_out
, /* _bfd_swap_sym_out */
4213 coff_swap_lineno_out
, /* _bfd_swap_lineno_out */
4214 xcoff_swap_reloc_out
, /* _bfd_swap_reloc_out */
4215 coff_swap_filehdr_out
, /* _bfd_swap_filehdr_out */
4216 coff_swap_aouthdr_out
, /* _bfd_swap_aouthdr_out */
4217 coff_swap_scnhdr_out
, /* _bfd_swap_scnhdr_out */
4218 FILHSZ
, /* _bfd_filhsz */
4219 AOUTSZ
, /* _bfd_aoutsz */
4220 SCNHSZ
, /* _bfd_scnhsz */
4221 SYMESZ
, /* _bfd_symesz */
4222 AUXESZ
, /* _bfd_auxesz */
4223 RELSZ
, /* _bfd_relsz */
4224 LINESZ
, /* _bfd_linesz */
4225 FILNMLEN
, /* _bfd_filnmlen */
4226 true, /* _bfd_coff_long_filenames */
4227 false, /* _bfd_coff_long_section_names */
4228 (3), /* _bfd_coff_default_section_alignment_power */
4229 false, /* _bfd_coff_force_symnames_in_strings */
4230 2, /* _bfd_coff_debug_string_prefix_length */
4231 coff_swap_filehdr_in
, /* _bfd_coff_swap_filehdr_in */
4232 coff_swap_aouthdr_in
, /* _bfd_swap_aouthdr_in */
4233 coff_swap_scnhdr_in
, /* _bfd_swap_scnhdr_in */
4234 xcoff_swap_reloc_in
, /* _bfd_reloc_in */
4235 coff_bad_format_hook
, /* _bfd_bad_format_hook */
4236 coff_set_arch_mach_hook
, /* _bfd_set_arch_mach_hook */
4237 coff_mkobject_hook
, /* _bfd_mkobject_hook */
4238 styp_to_sec_flags
, /* _bfd_syp_to_sec_flags */
4239 coff_set_alignment_hook
, /* _bfd_set_alignment_hook */
4240 coff_slurp_symbol_table
, /* _bfd_coff_slurp_symbol_table */
4241 symname_in_debug_hook
, /* _coff_symname_in_debug_hook */
4242 coff_pointerize_aux_hook
, /* _bfd_coff_pointerize_aux_hook */
4243 coff_print_aux
, /* bfd_coff_print_aux */
4244 dummy_reloc16_extra_cases
, /* _bfd_coff_reloc16_extra_cases */
4245 dummy_reloc16_estimate
, /* _bfd_coff_reloc16_estimate */
4246 NULL
, /* bfd_coff_sym_is_global */
4247 /* _bfd_coff_compute_section_file_positions */
4248 coff_compute_section_file_positions
,
4249 NULL
, /* _bfd_coff_start_final_link */
4250 xcoff_ppc_relocate_section
, /* _bfd_coff_relocate_section */
4251 coff_rtype_to_howto
, /* _bfd_coff_rtype_to_howto */
4252 NULL
, /* _bfd_coff_addust_symndx */
4253 _bfd_generic_link_add_one_symbol
, /* _bfd_coff_add_one_symbol */
4254 coff_link_output_has_begun
, /* _bfd_coff_link_output_has_begun */
4255 coff_final_link_postscript
/* _bfd_coff_final_link_postscript */
4258 0x01DF, /* magic number */
4259 bfd_arch_powerpc
, /* architecture */
4260 bfd_mach_ppc
, /* machine */
4262 /* function pointers to xcoff specific swap routines */
4263 xcoff_swap_ldhdr_in
, /* _xcoff_swap_ldhdr_in */
4264 xcoff_swap_ldhdr_out
, /* _xcoff_swap_ldhdr_out */
4265 xcoff_swap_ldsym_in
, /* _xcoff_swap_ldsym_in */
4266 xcoff_swap_ldsym_out
, /* _xcoff_swap_ldsym_out */
4267 xcoff_swap_ldrel_in
, /* _xcoff_swap_ldrel_in */
4268 xcoff_swap_ldrel_out
, /* _xcoff_swap_ldrel_out */
4271 LDHDRSZ
, /* _xcoff_ldhdrsz */
4272 LDSYMSZ
, /* _xcoff_ldsymsz */
4273 LDRELSZ
, /* _xcoff_ldrelsz */
4274 12, /* _xcoff_function_descriptor_size */
4275 SMALL_AOUTSZ
, /* _xcoff_small_aout_header_size */
4278 1, /* _xcoff_ldhdr_version */
4280 /* xcoff vs xcoff64 putting symbol names */
4281 _bfd_xcoff_put_symbol_name
, /* _xcoff_put_symbol_name */
4282 _bfd_xcoff_put_ldsymbol_name
, /* _xcoff_put_ldsymbol_name */
4284 &xcoff_dynamic_reloc
, /* dynamic reloc howto */
4286 xcoff_create_csect_from_smclas
, /* _xcoff_create_csect_from_smclas */
4288 /* lineno and reloc count overflow */
4289 xcoff_is_lineno_count_overflow
,
4290 xcoff_is_reloc_count_overflow
,
4292 xcoff_loader_symbol_offset
,
4293 xcoff_loader_reloc_offset
,
4296 &xcoff_glink_code
[0],
4297 (36), /* _xcoff_glink_size */
4300 0, /* _xcoff_rtinit_size */
4301 xcoff_generate_rtinit
, /* _xcoff_generate_rtinit */
4304 /* The transfer vector that leads the outside world to all of the above. */
4305 const bfd_target pmac_xcoff_vec
=
4308 bfd_target_xcoff_flavour
,
4309 BFD_ENDIAN_BIG
, /* data byte order is big */
4310 BFD_ENDIAN_BIG
, /* header byte order is big */
4312 (HAS_RELOC
| EXEC_P
| /* object flags */
4313 HAS_LINENO
| HAS_DEBUG
| DYNAMIC
|
4314 HAS_SYMS
| HAS_LOCALS
| WP_TEXT
),
4316 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
4317 0, /* leading char */
4318 '/', /* ar_pad_char */
4319 15, /* ar_max_namelen??? FIXMEmgo */
4322 bfd_getb64
, /* bfd_getx64 */
4323 bfd_getb_signed_64
, /* bfd_getx_signed_64 */
4324 bfd_putb64
, /* bfd_putx64 */
4325 bfd_getb32
, /* bfd_getx32 */
4326 bfd_getb_signed_32
, /* bfd_getx_signed_32 */
4327 bfd_putb32
, /* bfd_putx32 */
4328 bfd_getb16
, /* bfd_getx16 */
4329 bfd_getb_signed_16
, /* bfd_getx_signed_16 */
4330 bfd_putb16
, /* bfd_putx16 */
4333 bfd_getb64
, /* bfd_h_getx64 */
4334 bfd_getb_signed_64
, /* bfd_h_getx_signed_64 */
4335 bfd_putb64
, /* bfd_h_putx64 */
4336 bfd_getb32
, /* bfd_h_getx32 */
4337 bfd_getb_signed_32
, /* bfd_h_getx_signed_32 */
4338 bfd_putb32
, /* bfd_h_putx32 */
4339 bfd_getb16
, /* bfd_h_getx16 */
4340 bfd_getb_signed_16
, /* bfd_h_getx_signed_16 */
4341 bfd_putb16
, /* bfd_h_putx16 */
4343 { /* bfd_check_format */
4346 _bfd_xcoff_archive_p
,
4350 { /* bfd_set_format */
4353 _bfd_generic_mkarchive
,
4357 {/* bfd_write_contents */
4359 coff_write_object_contents
,
4360 _bfd_xcoff_write_archive_contents
,
4365 bfd_true
, /* _close_and_cleanup */
4366 bfd_true
, /* _bfd_free_cached_info */
4367 coff_new_section_hook
, /* _new_section_hook */
4368 _bfd_generic_get_section_contents
, /* _bfd_get_section_contents */
4369 /* _bfd_get_section_contents_in_window */
4370 _bfd_generic_get_section_contents_in_window
,
4373 _bfd_xcoff_copy_private_bfd_data
, /* _bfd_copy_private_bfd */
4374 /* _bfd_merge_private_bfd_data */
4375 ((boolean (*) (bfd
*, bfd
*)) bfd_true
),
4376 /* _bfd_copy_pivate_section_data */
4377 ((boolean (*) (bfd
*, asection
*, bfd
*, asection
*)) bfd_true
),
4378 /* _bfd_copy_private_symbol_data */
4379 ((boolean (*) (bfd
*, asymbol
*, bfd
*, asymbol
*)) bfd_true
),
4380 ((boolean (*) (bfd
*, flagword
)) bfd_true
), /* _bfd_set_private_flags */
4381 ((boolean (*) (bfd
*, void * )) bfd_true
), /* _bfd_print_private_bfd_data */
4384 coff_core_file_failing_command
, /* _core_file_failing_command */
4385 coff_core_file_failing_signal
, /* _core_file_failing_signal */
4386 /* _core_file_matches_executable_p */
4387 coff_core_file_matches_executable_p
,
4390 _bfd_xcoff_slurp_armap
, /* _slurp_armap */
4391 /* XCOFF archives do not have
4392 anything which corresponds to
4393 an extended name table. */
4394 bfd_false
, /* _slurp_extended_name_table */
4395 /* _construct_extended_name_table */
4396 ((boolean (*) (bfd
*, char **, bfd_size_type
*, const char **)) bfd_false
),
4397 bfd_dont_truncate_arname
, /* _truncate_arname */
4398 _bfd_xcoff_write_armap
, /* _write_armap */
4399 _bfd_xcoff_read_ar_hdr
, /* _read_ar_hdr */
4400 _bfd_xcoff_openr_next_archived_file
, /* _openr_next_archived_file */
4401 _bfd_generic_get_elt_at_index
, /* _get_elt_at_index */
4402 _bfd_xcoff_stat_arch_elt
, /* _generic_stat_arch_elt */
4403 /* XCOFF archives do not have
4405 bfd_true
, /* _update_armap_timestamp */
4408 coff_get_symtab_upper_bound
, /* _get_symtab_upper_bound */
4409 coff_get_symtab
, /* _get_symtab */
4410 coff_make_empty_symbol
, /* _make_empty_symbol */
4411 coff_print_symbol
, /* _print_symbol */
4412 coff_get_symbol_info
, /* _get_symbol_info */
4413 _bfd_xcoff_is_local_label_name
, /* _bfd_is_local_label_name */
4414 coff_get_lineno
, /* _get_lineno */
4415 coff_find_nearest_line
, /* _find_nearest_line */
4416 coff_bfd_make_debug_symbol
, /* _bfd_make_debug_symbol */
4417 _bfd_generic_read_minisymbols
, /* _read_minisymbols */
4418 _bfd_generic_minisymbol_to_symbol
, /* _minsymbol_to_symbol */
4421 coff_get_reloc_upper_bound
, /* _get_reloc_upper_bound */
4422 coff_canonicalize_reloc
, /* _cononicalize_reloc */
4423 _bfd_xcoff_reloc_type_lookup
, /* _bfd_reloc_type_lookup */
4426 coff_set_arch_mach
, /* _set_arch_mach */
4427 coff_set_section_contents
, /* _set_section_contents */
4430 _bfd_xcoff_sizeof_headers
, /* _sizeof_headers */
4431 /* _bfd_get_relocated_section_contents */
4432 bfd_generic_get_relocated_section_contents
,
4433 bfd_generic_relax_section
, /* _bfd_relax_section */
4434 _bfd_xcoff_bfd_link_hash_table_create
, /* _bfd_link_hash_table_create */
4435 _bfd_generic_link_hash_table_free
, /* _bfd_link_hash_table_free */
4436 _bfd_xcoff_bfd_link_add_symbols
, /* _bfd_link_add_symbols */
4437 _bfd_xcoff_bfd_final_link
, /* _bfd_filnal_link */
4438 _bfd_generic_link_split_section
, /* _bfd_link_split_section */
4439 bfd_generic_gc_sections
, /* _bfd_gc_sections */
4440 bfd_generic_merge_sections
, /* _bfd_merge_sections */
4443 /* _get_dynamic_symtab_upper_bound */
4444 _bfd_xcoff_get_dynamic_symtab_upper_bound
,
4445 _bfd_xcoff_canonicalize_dynamic_symtab
, /* _cononicalize_dynamic_symtab */
4446 _bfd_xcoff_get_dynamic_reloc_upper_bound
,/* _get_dynamic_reloc_upper_bound */
4447 _bfd_xcoff_canonicalize_dynamic_reloc
, /* _cononicalize_dynamic_reloc */
4449 /* Opposite endian version, none exists */
4453 (void *) &bfd_pmac_xcoff_backend_data
,