Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* BFD back-end for IBM RS/6000 "XCOFF" files. |
157090f7 | 2 | Copyright 1990-1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 |
5f771d47 | 3 | Free Software Foundation, Inc. |
2ce18a16 | 4 | Written by Metin G. Ozisik, Mimi Phuong-Thao Vo, and John Gilmore. |
252b5132 RH |
5 | Archive support from Damon A. Permezel. |
6 | Contributed by IBM Corporation and Cygnus Support. | |
7 | ||
8 | This file is part of BFD, the Binary File Descriptor library. | |
9 | ||
10 | This program is free software; you can redistribute it and/or modify | |
11 | it under the terms of the GNU General Public License as published by | |
12 | the Free Software Foundation; either version 2 of the License, or | |
13 | (at your option) any later version. | |
14 | ||
15 | This program is distributed in the hope that it will be useful, | |
16 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | GNU General Public License for more details. | |
19 | ||
20 | You should have received a copy of the GNU General Public License | |
21 | along with this program; if not, write to the Free Software | |
3e110533 | 22 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ |
252b5132 | 23 | |
252b5132 | 24 | #include "sysdep.h" |
3db64b00 | 25 | #include "bfd.h" |
beb1bf64 | 26 | #include "bfdlink.h" |
252b5132 RH |
27 | #include "libbfd.h" |
28 | #include "coff/internal.h" | |
beb1bf64 | 29 | #include "coff/xcoff.h" |
252b5132 RH |
30 | #include "coff/rs6000.h" |
31 | #include "libcoff.h" | |
beb1bf64 TR |
32 | #include "libxcoff.h" |
33 | ||
b34976b6 AM |
34 | extern bfd_boolean _bfd_xcoff_mkobject |
35 | PARAMS ((bfd *)); | |
36 | extern bfd_boolean _bfd_xcoff_copy_private_bfd_data | |
37 | PARAMS ((bfd *, bfd *)); | |
38 | extern bfd_boolean _bfd_xcoff_is_local_label_name | |
39 | PARAMS ((bfd *, const char *)); | |
beb1bf64 TR |
40 | extern reloc_howto_type *_bfd_xcoff_reloc_type_lookup |
41 | PARAMS ((bfd *, bfd_reloc_code_real_type)); | |
b34976b6 AM |
42 | extern bfd_boolean _bfd_xcoff_slurp_armap |
43 | PARAMS ((bfd *)); | |
44 | extern const bfd_target *_bfd_xcoff_archive_p | |
45 | PARAMS ((bfd *)); | |
46 | extern PTR _bfd_xcoff_read_ar_hdr | |
47 | PARAMS ((bfd *)); | |
48 | extern bfd *_bfd_xcoff_openr_next_archived_file | |
49 | PARAMS ((bfd *, bfd *)); | |
50 | extern int _bfd_xcoff_stat_arch_elt | |
51 | PARAMS ((bfd *, struct stat *)); | |
52 | extern bfd_boolean _bfd_xcoff_write_armap | |
beb1bf64 | 53 | PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int)); |
b34976b6 AM |
54 | extern bfd_boolean _bfd_xcoff_write_archive_contents |
55 | PARAMS ((bfd *)); | |
56 | extern int _bfd_xcoff_sizeof_headers | |
a6b96beb | 57 | PARAMS ((bfd *, struct bfd_link_info *)); |
b34976b6 AM |
58 | extern void _bfd_xcoff_swap_sym_in |
59 | PARAMS ((bfd *, PTR, PTR)); | |
60 | extern unsigned int _bfd_xcoff_swap_sym_out | |
61 | PARAMS ((bfd *, PTR, PTR)); | |
62 | extern void _bfd_xcoff_swap_aux_in | |
63 | PARAMS ((bfd *, PTR, int, int, int, int, PTR)); | |
64 | extern unsigned int _bfd_xcoff_swap_aux_out | |
65 | PARAMS ((bfd *, PTR, int, int, int, int, PTR)); | |
66 | static void xcoff_swap_reloc_in | |
67 | PARAMS ((bfd *, PTR, PTR)); | |
68 | static unsigned int xcoff_swap_reloc_out | |
69 | PARAMS ((bfd *, PTR, PTR)); | |
beb1bf64 | 70 | |
59862849 | 71 | /* Forward declare xcoff_rtype2howto for coffcode.h macro. */ |
b34976b6 AM |
72 | void xcoff_rtype2howto |
73 | PARAMS ((arelent *, struct internal_reloc *)); | |
beb1bf64 | 74 | |
f4ffd778 | 75 | /* coffcode.h needs these to be defined. */ |
beb1bf64 TR |
76 | #define RS6000COFF_C 1 |
77 | ||
78 | #define SELECT_RELOC(internal, howto) \ | |
79 | { \ | |
80 | internal.r_type = howto->type; \ | |
81 | internal.r_size = \ | |
82 | ((howto->complain_on_overflow == complain_overflow_signed \ | |
83 | ? 0x80 \ | |
84 | : 0) \ | |
85 | | (howto->bitsize - 1)); \ | |
86 | } | |
87 | ||
88 | #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3) | |
89 | #define COFF_LONG_FILENAMES | |
90 | #define NO_COFF_SYMBOLS | |
59862849 | 91 | #define RTYPE2HOWTO(cache_ptr, dst) xcoff_rtype2howto (cache_ptr, dst) |
dc810e39 AM |
92 | #define coff_mkobject _bfd_xcoff_mkobject |
93 | #define coff_bfd_copy_private_bfd_data _bfd_xcoff_copy_private_bfd_data | |
94 | #define coff_bfd_is_local_label_name _bfd_xcoff_is_local_label_name | |
95 | #define coff_bfd_reloc_type_lookup _bfd_xcoff_reloc_type_lookup | |
157090f7 | 96 | #define coff_bfd_reloc_name_lookup _bfd_xcoff_reloc_name_lookup |
b55039f4 | 97 | #ifdef AIX_CORE |
b34976b6 AM |
98 | extern const bfd_target * rs6000coff_core_p |
99 | PARAMS ((bfd *abfd)); | |
100 | extern bfd_boolean rs6000coff_core_file_matches_executable_p | |
69f284c7 | 101 | PARAMS ((bfd *cbfd, bfd *ebfd)); |
b34976b6 AM |
102 | extern char *rs6000coff_core_file_failing_command |
103 | PARAMS ((bfd *abfd)); | |
104 | extern int rs6000coff_core_file_failing_signal | |
105 | PARAMS ((bfd *abfd)); | |
beb1bf64 | 106 | #define CORE_FILE_P rs6000coff_core_p |
b55039f4 L |
107 | #define coff_core_file_failing_command \ |
108 | rs6000coff_core_file_failing_command | |
109 | #define coff_core_file_failing_signal \ | |
110 | rs6000coff_core_file_failing_signal | |
111 | #define coff_core_file_matches_executable_p \ | |
112 | rs6000coff_core_file_matches_executable_p | |
113 | #else | |
114 | #define CORE_FILE_P _bfd_dummy_target | |
115 | #define coff_core_file_failing_command \ | |
116 | _bfd_nocore_core_file_failing_command | |
117 | #define coff_core_file_failing_signal \ | |
118 | _bfd_nocore_core_file_failing_signal | |
119 | #define coff_core_file_matches_executable_p \ | |
120 | _bfd_nocore_core_file_matches_executable_p | |
121 | #endif | |
beb1bf64 TR |
122 | #define coff_SWAP_sym_in _bfd_xcoff_swap_sym_in |
123 | #define coff_SWAP_sym_out _bfd_xcoff_swap_sym_out | |
124 | #define coff_SWAP_aux_in _bfd_xcoff_swap_aux_in | |
125 | #define coff_SWAP_aux_out _bfd_xcoff_swap_aux_out | |
59862849 TR |
126 | #define coff_swap_reloc_in xcoff_swap_reloc_in |
127 | #define coff_swap_reloc_out xcoff_swap_reloc_out | |
128 | #define NO_COFF_RELOCS | |
beb1bf64 TR |
129 | |
130 | #include "coffcode.h" | |
14958a43 | 131 | |
252b5132 RH |
132 | /* The main body of code is in coffcode.h. */ |
133 | ||
b34976b6 AM |
134 | static const char *normalize_filename |
135 | PARAMS ((bfd *)); | |
136 | static bfd_boolean xcoff_write_armap_old | |
a7b97311 | 137 | PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int)); |
b34976b6 | 138 | static bfd_boolean xcoff_write_armap_big |
a7b97311 | 139 | PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int)); |
b34976b6 AM |
140 | static bfd_boolean xcoff_write_archive_contents_old |
141 | PARAMS ((bfd *)); | |
142 | static bfd_boolean xcoff_write_archive_contents_big | |
143 | PARAMS ((bfd *)); | |
a7b97311 | 144 | static void xcoff_swap_ldhdr_in |
814fa6ab | 145 | PARAMS ((bfd *, const PTR, struct internal_ldhdr *)); |
a7b97311 | 146 | static void xcoff_swap_ldhdr_out |
814fa6ab | 147 | PARAMS ((bfd *, const struct internal_ldhdr *, PTR)); |
a7b97311 | 148 | static void xcoff_swap_ldsym_in |
814fa6ab | 149 | PARAMS ((bfd *, const PTR, struct internal_ldsym *)); |
a7b97311 | 150 | static void xcoff_swap_ldsym_out |
814fa6ab | 151 | PARAMS ((bfd *, const struct internal_ldsym *, PTR)); |
a7b97311 | 152 | static void xcoff_swap_ldrel_in |
814fa6ab | 153 | PARAMS ((bfd *, const PTR, struct internal_ldrel *)); |
a7b97311 | 154 | static void xcoff_swap_ldrel_out |
814fa6ab | 155 | PARAMS ((bfd *, const struct internal_ldrel *, PTR)); |
b34976b6 | 156 | static bfd_boolean xcoff_ppc_relocate_section |
a7b97311 AM |
157 | PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, |
158 | struct internal_reloc *, struct internal_syment *, asection **)); | |
b34976b6 | 159 | static bfd_boolean _bfd_xcoff_put_ldsymbol_name |
a7b97311 AM |
160 | PARAMS ((bfd *, struct xcoff_loader_info *, struct internal_ldsym *, |
161 | const char *)); | |
162 | static asection *xcoff_create_csect_from_smclas | |
814fa6ab | 163 | PARAMS ((bfd *, union internal_auxent *, const char *)); |
b34976b6 AM |
164 | static bfd_boolean xcoff_is_lineno_count_overflow |
165 | PARAMS ((bfd *, bfd_vma)); | |
166 | static bfd_boolean xcoff_is_reloc_count_overflow | |
167 | PARAMS ((bfd *, bfd_vma)); | |
a7b97311 AM |
168 | static bfd_vma xcoff_loader_symbol_offset |
169 | PARAMS ((bfd *, struct internal_ldhdr *)); | |
170 | static bfd_vma xcoff_loader_reloc_offset | |
171 | PARAMS ((bfd *, struct internal_ldhdr *)); | |
b34976b6 AM |
172 | static bfd_boolean xcoff_generate_rtinit |
173 | PARAMS ((bfd *, const char *, const char *, bfd_boolean)); | |
174 | static bfd_boolean do_pad | |
175 | PARAMS ((bfd *, unsigned int)); | |
176 | static bfd_boolean do_copy | |
177 | PARAMS ((bfd *, bfd *)); | |
178 | static bfd_boolean do_shared_object_padding | |
9dadfa79 | 179 | PARAMS ((bfd *, bfd *, file_ptr *, int)); |
14958a43 | 180 | |
dbe341c6 | 181 | /* Relocation functions */ |
b34976b6 AM |
182 | static bfd_boolean xcoff_reloc_type_br |
183 | PARAMS ((XCOFF_RELOC_FUNCTION_ARGS)); | |
dbe341c6 | 184 | |
b34976b6 | 185 | static bfd_boolean xcoff_complain_overflow_dont_func |
dbe341c6 | 186 | PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS)); |
b34976b6 | 187 | static bfd_boolean xcoff_complain_overflow_bitfield_func |
dbe341c6 | 188 | PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS)); |
b34976b6 | 189 | static bfd_boolean xcoff_complain_overflow_signed_func |
dbe341c6 | 190 | PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS)); |
b34976b6 | 191 | static bfd_boolean xcoff_complain_overflow_unsigned_func |
dbe341c6 TR |
192 | PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS)); |
193 | ||
b34976b6 | 194 | bfd_boolean (*xcoff_calculate_relocation[XCOFF_MAX_CALCULATE_RELOCATION]) |
cf9ab45b | 195 | PARAMS ((XCOFF_RELOC_FUNCTION_ARGS)) = |
dbe341c6 | 196 | { |
cf9ab45b AM |
197 | xcoff_reloc_type_pos, /* R_POS (0x00) */ |
198 | xcoff_reloc_type_neg, /* R_NEG (0x01) */ | |
199 | xcoff_reloc_type_rel, /* R_REL (0x02) */ | |
200 | xcoff_reloc_type_toc, /* R_TOC (0x03) */ | |
dbe341c6 | 201 | xcoff_reloc_type_fail, /* R_RTB (0x04) */ |
cf9ab45b AM |
202 | xcoff_reloc_type_toc, /* R_GL (0x05) */ |
203 | xcoff_reloc_type_toc, /* R_TCL (0x06) */ | |
204 | xcoff_reloc_type_fail, /* (0x07) */ | |
205 | xcoff_reloc_type_ba, /* R_BA (0x08) */ | |
206 | xcoff_reloc_type_fail, /* (0x09) */ | |
207 | xcoff_reloc_type_br, /* R_BR (0x0a) */ | |
208 | xcoff_reloc_type_fail, /* (0x0b) */ | |
209 | xcoff_reloc_type_pos, /* R_RL (0x0c) */ | |
210 | xcoff_reloc_type_pos, /* R_RLA (0x0d) */ | |
211 | xcoff_reloc_type_fail, /* (0x0e) */ | |
dbe341c6 | 212 | xcoff_reloc_type_noop, /* R_REF (0x0f) */ |
cf9ab45b AM |
213 | xcoff_reloc_type_fail, /* (0x10) */ |
214 | xcoff_reloc_type_fail, /* (0x11) */ | |
215 | xcoff_reloc_type_toc, /* R_TRL (0x12) */ | |
216 | xcoff_reloc_type_toc, /* R_TRLA (0x13) */ | |
dbe341c6 TR |
217 | xcoff_reloc_type_fail, /* R_RRTBI (0x14) */ |
218 | xcoff_reloc_type_fail, /* R_RRTBA (0x15) */ | |
cf9ab45b | 219 | xcoff_reloc_type_ba, /* R_CAI (0x16) */ |
dbe341c6 | 220 | xcoff_reloc_type_crel, /* R_CREL (0x17) */ |
cf9ab45b AM |
221 | xcoff_reloc_type_ba, /* R_RBA (0x18) */ |
222 | xcoff_reloc_type_ba, /* R_RBAC (0x19) */ | |
223 | xcoff_reloc_type_br, /* R_RBR (0x1a) */ | |
224 | xcoff_reloc_type_ba, /* R_RBRC (0x1b) */ | |
dbe341c6 TR |
225 | }; |
226 | ||
b34976b6 | 227 | bfd_boolean (*xcoff_complain_overflow[XCOFF_MAX_COMPLAIN_OVERFLOW]) |
cf9ab45b | 228 | PARAMS ((XCOFF_COMPLAIN_FUNCTION_ARGS)) = |
dbe341c6 TR |
229 | { |
230 | xcoff_complain_overflow_dont_func, | |
231 | xcoff_complain_overflow_bitfield_func, | |
232 | xcoff_complain_overflow_signed_func, | |
233 | xcoff_complain_overflow_unsigned_func, | |
234 | }; | |
235 | ||
252b5132 RH |
236 | /* We use our own tdata type. Its first field is the COFF tdata type, |
237 | so the COFF routines are compatible. */ | |
238 | ||
b34976b6 | 239 | bfd_boolean |
7f6d05e8 | 240 | _bfd_xcoff_mkobject (abfd) |
252b5132 RH |
241 | bfd *abfd; |
242 | { | |
243 | coff_data_type *coff; | |
dc810e39 | 244 | bfd_size_type amt = sizeof (struct xcoff_tdata); |
252b5132 | 245 | |
dc810e39 | 246 | abfd->tdata.xcoff_obj_data = (struct xcoff_tdata *) bfd_zalloc (abfd, amt); |
252b5132 | 247 | if (abfd->tdata.xcoff_obj_data == NULL) |
b34976b6 | 248 | return FALSE; |
252b5132 RH |
249 | coff = coff_data (abfd); |
250 | coff->symbols = (coff_symbol_type *) NULL; | |
251 | coff->conversion_table = (unsigned int *) NULL; | |
252 | coff->raw_syments = (struct coff_ptr_struct *) NULL; | |
253 | coff->relocbase = 0; | |
254 | ||
255 | xcoff_data (abfd)->modtype = ('1' << 8) | 'L'; | |
256 | ||
257 | /* We set cputype to -1 to indicate that it has not been | |
258 | initialized. */ | |
259 | xcoff_data (abfd)->cputype = -1; | |
260 | ||
261 | xcoff_data (abfd)->csects = NULL; | |
262 | xcoff_data (abfd)->debug_indices = NULL; | |
263 | ||
beb1bf64 | 264 | /* text section alignment is different than the default */ |
f3813499 | 265 | bfd_xcoff_text_align_power (abfd) = 2; |
beb1bf64 | 266 | |
b34976b6 | 267 | return TRUE; |
252b5132 RH |
268 | } |
269 | ||
270 | /* Copy XCOFF data from one BFD to another. */ | |
271 | ||
b34976b6 | 272 | bfd_boolean |
7f6d05e8 | 273 | _bfd_xcoff_copy_private_bfd_data (ibfd, obfd) |
252b5132 RH |
274 | bfd *ibfd; |
275 | bfd *obfd; | |
276 | { | |
277 | struct xcoff_tdata *ix, *ox; | |
278 | asection *sec; | |
279 | ||
280 | if (ibfd->xvec != obfd->xvec) | |
b34976b6 | 281 | return TRUE; |
252b5132 RH |
282 | ix = xcoff_data (ibfd); |
283 | ox = xcoff_data (obfd); | |
284 | ox->full_aouthdr = ix->full_aouthdr; | |
285 | ox->toc = ix->toc; | |
286 | if (ix->sntoc == 0) | |
287 | ox->sntoc = 0; | |
288 | else | |
289 | { | |
290 | sec = coff_section_from_bfd_index (ibfd, ix->sntoc); | |
291 | if (sec == NULL) | |
292 | ox->sntoc = 0; | |
293 | else | |
294 | ox->sntoc = sec->output_section->target_index; | |
295 | } | |
296 | if (ix->snentry == 0) | |
297 | ox->snentry = 0; | |
298 | else | |
299 | { | |
300 | sec = coff_section_from_bfd_index (ibfd, ix->snentry); | |
301 | if (sec == NULL) | |
302 | ox->snentry = 0; | |
303 | else | |
304 | ox->snentry = sec->output_section->target_index; | |
305 | } | |
f3813499 TR |
306 | bfd_xcoff_text_align_power (obfd) = bfd_xcoff_text_align_power (ibfd); |
307 | bfd_xcoff_data_align_power (obfd) = bfd_xcoff_data_align_power (ibfd); | |
252b5132 RH |
308 | ox->modtype = ix->modtype; |
309 | ox->cputype = ix->cputype; | |
310 | ox->maxdata = ix->maxdata; | |
311 | ox->maxstack = ix->maxstack; | |
b34976b6 | 312 | return TRUE; |
252b5132 RH |
313 | } |
314 | ||
315 | /* I don't think XCOFF really has a notion of local labels based on | |
316 | name. This will mean that ld -X doesn't actually strip anything. | |
317 | The AIX native linker does not have a -X option, and it ignores the | |
318 | -x option. */ | |
319 | ||
b34976b6 | 320 | bfd_boolean |
7f6d05e8 | 321 | _bfd_xcoff_is_local_label_name (abfd, name) |
5f771d47 ILT |
322 | bfd *abfd ATTRIBUTE_UNUSED; |
323 | const char *name ATTRIBUTE_UNUSED; | |
252b5132 | 324 | { |
b34976b6 | 325 | return FALSE; |
252b5132 | 326 | } |
7f6d05e8 | 327 | \f |
14958a43 CP |
328 | void |
329 | _bfd_xcoff_swap_sym_in (abfd, ext1, in1) | |
cf9ab45b | 330 | bfd *abfd; |
7f6d05e8 CP |
331 | PTR ext1; |
332 | PTR in1; | |
333 | { | |
334 | SYMENT *ext = (SYMENT *)ext1; | |
f4ffd778 | 335 | struct internal_syment * in = (struct internal_syment *)in1; |
7f6d05e8 | 336 | |
f4ffd778 NC |
337 | if (ext->e.e_name[0] != 0) |
338 | { | |
cf9ab45b | 339 | memcpy (in->_n._n_name, ext->e.e_name, SYMNMLEN); |
f4ffd778 NC |
340 | } |
341 | else | |
342 | { | |
343 | in->_n._n_n._n_zeroes = 0; | |
dc810e39 | 344 | in->_n._n_n._n_offset = H_GET_32 (abfd, ext->e.e.e_offset); |
f4ffd778 | 345 | } |
7f6d05e8 | 346 | |
dc810e39 AM |
347 | in->n_value = H_GET_32 (abfd, ext->e_value); |
348 | in->n_scnum = H_GET_16 (abfd, ext->e_scnum); | |
349 | in->n_type = H_GET_16 (abfd, ext->e_type); | |
350 | in->n_sclass = H_GET_8 (abfd, ext->e_sclass); | |
351 | in->n_numaux = H_GET_8 (abfd, ext->e_numaux); | |
7f6d05e8 CP |
352 | } |
353 | ||
14958a43 CP |
354 | unsigned int |
355 | _bfd_xcoff_swap_sym_out (abfd, inp, extp) | |
cf9ab45b AM |
356 | bfd *abfd; |
357 | PTR inp; | |
358 | PTR extp; | |
7f6d05e8 CP |
359 | { |
360 | struct internal_syment *in = (struct internal_syment *)inp; | |
361 | SYMENT *ext =(SYMENT *)extp; | |
362 | ||
f4ffd778 NC |
363 | if (in->_n._n_name[0] != 0) |
364 | { | |
cf9ab45b | 365 | memcpy (ext->e.e_name, in->_n._n_name, SYMNMLEN); |
f4ffd778 NC |
366 | } |
367 | else | |
368 | { | |
dc810e39 AM |
369 | H_PUT_32 (abfd, 0, ext->e.e.e_zeroes); |
370 | H_PUT_32 (abfd, in->_n._n_n._n_offset, ext->e.e.e_offset); | |
f4ffd778 | 371 | } |
7f6d05e8 | 372 | |
dc810e39 AM |
373 | H_PUT_32 (abfd, in->n_value, ext->e_value); |
374 | H_PUT_16 (abfd, in->n_scnum, ext->e_scnum); | |
375 | H_PUT_16 (abfd, in->n_type, ext->e_type); | |
376 | H_PUT_8 (abfd, in->n_sclass, ext->e_sclass); | |
377 | H_PUT_8 (abfd, in->n_numaux, ext->e_numaux); | |
7f6d05e8 CP |
378 | return bfd_coff_symesz (abfd); |
379 | } | |
380 | ||
14958a43 CP |
381 | void |
382 | _bfd_xcoff_swap_aux_in (abfd, ext1, type, class, indx, numaux, in1) | |
cf9ab45b AM |
383 | bfd *abfd; |
384 | PTR ext1; | |
385 | int type; | |
386 | int class; | |
387 | int indx; | |
388 | int numaux; | |
389 | PTR in1; | |
7f6d05e8 | 390 | { |
f4ffd778 | 391 | AUXENT * ext = (AUXENT *)ext1; |
7f6d05e8 CP |
392 | union internal_auxent *in = (union internal_auxent *)in1; |
393 | ||
f4ffd778 NC |
394 | switch (class) |
395 | { | |
7f6d05e8 | 396 | case C_FILE: |
f4ffd778 NC |
397 | if (ext->x_file.x_fname[0] == 0) |
398 | { | |
7f6d05e8 | 399 | in->x_file.x_n.x_zeroes = 0; |
dc810e39 AM |
400 | in->x_file.x_n.x_offset = |
401 | H_GET_32 (abfd, ext->x_file.x_n.x_offset); | |
f4ffd778 NC |
402 | } |
403 | else | |
404 | { | |
405 | if (numaux > 1) | |
406 | { | |
407 | if (indx == 0) | |
408 | memcpy (in->x_file.x_fname, ext->x_file.x_fname, | |
409 | numaux * sizeof (AUXENT)); | |
410 | } | |
411 | else | |
412 | { | |
413 | memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN); | |
414 | } | |
415 | } | |
7f6d05e8 CP |
416 | goto end; |
417 | ||
418 | /* RS/6000 "csect" auxents */ | |
419 | case C_EXT: | |
420 | case C_HIDEXT: | |
421 | if (indx + 1 == numaux) | |
422 | { | |
dc810e39 AM |
423 | in->x_csect.x_scnlen.l = H_GET_32 (abfd, ext->x_csect.x_scnlen); |
424 | in->x_csect.x_parmhash = H_GET_32 (abfd, ext->x_csect.x_parmhash); | |
425 | in->x_csect.x_snhash = H_GET_16 (abfd, ext->x_csect.x_snhash); | |
7f6d05e8 CP |
426 | /* We don't have to hack bitfields in x_smtyp because it's |
427 | defined by shifts-and-ands, which are equivalent on all | |
428 | byte orders. */ | |
dc810e39 AM |
429 | in->x_csect.x_smtyp = H_GET_8 (abfd, ext->x_csect.x_smtyp); |
430 | in->x_csect.x_smclas = H_GET_8 (abfd, ext->x_csect.x_smclas); | |
431 | in->x_csect.x_stab = H_GET_32 (abfd, ext->x_csect.x_stab); | |
432 | in->x_csect.x_snstab = H_GET_16 (abfd, ext->x_csect.x_snstab); | |
7f6d05e8 CP |
433 | goto end; |
434 | } | |
435 | break; | |
436 | ||
437 | case C_STAT: | |
438 | case C_LEAFSTAT: | |
439 | case C_HIDDEN: | |
f4ffd778 NC |
440 | if (type == T_NULL) |
441 | { | |
dc810e39 AM |
442 | in->x_scn.x_scnlen = H_GET_32 (abfd, ext->x_scn.x_scnlen); |
443 | in->x_scn.x_nreloc = H_GET_16 (abfd, ext->x_scn.x_nreloc); | |
444 | in->x_scn.x_nlinno = H_GET_16 (abfd, ext->x_scn.x_nlinno); | |
7f6d05e8 | 445 | /* PE defines some extra fields; we zero them out for |
cf9ab45b | 446 | safety. */ |
7f6d05e8 CP |
447 | in->x_scn.x_checksum = 0; |
448 | in->x_scn.x_associated = 0; | |
449 | in->x_scn.x_comdat = 0; | |
450 | ||
451 | goto end; | |
452 | } | |
453 | break; | |
454 | } | |
455 | ||
dc810e39 AM |
456 | in->x_sym.x_tagndx.l = H_GET_32 (abfd, ext->x_sym.x_tagndx); |
457 | in->x_sym.x_tvndx = H_GET_16 (abfd, ext->x_sym.x_tvndx); | |
7f6d05e8 CP |
458 | |
459 | if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class)) | |
460 | { | |
dc810e39 AM |
461 | in->x_sym.x_fcnary.x_fcn.x_lnnoptr = |
462 | H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_lnnoptr); | |
463 | in->x_sym.x_fcnary.x_fcn.x_endndx.l = | |
464 | H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_endndx); | |
7f6d05e8 CP |
465 | } |
466 | else | |
467 | { | |
468 | in->x_sym.x_fcnary.x_ary.x_dimen[0] = | |
dc810e39 | 469 | H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[0]); |
7f6d05e8 | 470 | in->x_sym.x_fcnary.x_ary.x_dimen[1] = |
dc810e39 | 471 | H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[1]); |
7f6d05e8 | 472 | in->x_sym.x_fcnary.x_ary.x_dimen[2] = |
dc810e39 | 473 | H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[2]); |
7f6d05e8 | 474 | in->x_sym.x_fcnary.x_ary.x_dimen[3] = |
dc810e39 | 475 | H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[3]); |
7f6d05e8 | 476 | } |
7f6d05e8 | 477 | |
f4ffd778 NC |
478 | if (ISFCN (type)) |
479 | { | |
dc810e39 | 480 | in->x_sym.x_misc.x_fsize = H_GET_32 (abfd, ext->x_sym.x_misc.x_fsize); |
f4ffd778 NC |
481 | } |
482 | else | |
483 | { | |
dc810e39 AM |
484 | in->x_sym.x_misc.x_lnsz.x_lnno = |
485 | H_GET_16 (abfd, ext->x_sym.x_misc.x_lnsz.x_lnno); | |
486 | in->x_sym.x_misc.x_lnsz.x_size = | |
487 | H_GET_16 (abfd, ext->x_sym.x_misc.x_lnsz.x_size); | |
f4ffd778 | 488 | } |
7f6d05e8 | 489 | |
f4ffd778 NC |
490 | end: ; |
491 | /* The semicolon is because MSVC doesn't like labels at | |
492 | end of block. */ | |
7f6d05e8 CP |
493 | } |
494 | ||
beb1bf64 | 495 | |
b34976b6 AM |
496 | unsigned int _bfd_xcoff_swap_aux_out |
497 | PARAMS ((bfd *, PTR, int, int, int, int, PTR)); | |
beb1bf64 | 498 | |
14958a43 CP |
499 | unsigned int |
500 | _bfd_xcoff_swap_aux_out (abfd, inp, type, class, indx, numaux, extp) | |
917583ad NC |
501 | bfd * abfd; |
502 | PTR inp; | |
7f6d05e8 CP |
503 | int type; |
504 | int class; | |
505 | int indx ATTRIBUTE_UNUSED; | |
506 | int numaux ATTRIBUTE_UNUSED; | |
917583ad | 507 | PTR extp; |
7f6d05e8 CP |
508 | { |
509 | union internal_auxent *in = (union internal_auxent *)inp; | |
510 | AUXENT *ext = (AUXENT *)extp; | |
511 | ||
cf9ab45b | 512 | memset ((PTR)ext, 0, bfd_coff_auxesz (abfd)); |
7f6d05e8 CP |
513 | switch (class) |
514 | { | |
f4ffd778 NC |
515 | case C_FILE: |
516 | if (in->x_file.x_fname[0] == 0) | |
517 | { | |
dc810e39 AM |
518 | H_PUT_32 (abfd, 0, ext->x_file.x_n.x_zeroes); |
519 | H_PUT_32 (abfd, in->x_file.x_n.x_offset, ext->x_file.x_n.x_offset); | |
f4ffd778 NC |
520 | } |
521 | else | |
522 | { | |
523 | memcpy (ext->x_file.x_fname, in->x_file.x_fname, FILNMLEN); | |
524 | } | |
7f6d05e8 | 525 | goto end; |
f4ffd778 NC |
526 | |
527 | /* RS/6000 "csect" auxents */ | |
528 | case C_EXT: | |
529 | case C_HIDEXT: | |
530 | if (indx + 1 == numaux) | |
531 | { | |
dc810e39 AM |
532 | H_PUT_32 (abfd, in->x_csect.x_scnlen.l, ext->x_csect.x_scnlen); |
533 | H_PUT_32 (abfd, in->x_csect.x_parmhash, ext->x_csect.x_parmhash); | |
534 | H_PUT_16 (abfd, in->x_csect.x_snhash, ext->x_csect.x_snhash); | |
f4ffd778 NC |
535 | /* We don't have to hack bitfields in x_smtyp because it's |
536 | defined by shifts-and-ands, which are equivalent on all | |
537 | byte orders. */ | |
dc810e39 AM |
538 | H_PUT_8 (abfd, in->x_csect.x_smtyp, ext->x_csect.x_smtyp); |
539 | H_PUT_8 (abfd, in->x_csect.x_smclas, ext->x_csect.x_smclas); | |
540 | H_PUT_32 (abfd, in->x_csect.x_stab, ext->x_csect.x_stab); | |
541 | H_PUT_16 (abfd, in->x_csect.x_snstab, ext->x_csect.x_snstab); | |
f4ffd778 NC |
542 | goto end; |
543 | } | |
544 | break; | |
545 | ||
546 | case C_STAT: | |
547 | case C_LEAFSTAT: | |
548 | case C_HIDDEN: | |
549 | if (type == T_NULL) | |
550 | { | |
dc810e39 AM |
551 | H_PUT_32 (abfd, in->x_scn.x_scnlen, ext->x_scn.x_scnlen); |
552 | H_PUT_16 (abfd, in->x_scn.x_nreloc, ext->x_scn.x_nreloc); | |
553 | H_PUT_16 (abfd, in->x_scn.x_nlinno, ext->x_scn.x_nlinno); | |
f4ffd778 NC |
554 | goto end; |
555 | } | |
556 | break; | |
7f6d05e8 | 557 | } |
7f6d05e8 | 558 | |
dc810e39 AM |
559 | H_PUT_32 (abfd, in->x_sym.x_tagndx.l, ext->x_sym.x_tagndx); |
560 | H_PUT_16 (abfd, in->x_sym.x_tvndx, ext->x_sym.x_tvndx); | |
7f6d05e8 CP |
561 | |
562 | if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class)) | |
563 | { | |
dc810e39 AM |
564 | H_PUT_32 (abfd, in->x_sym.x_fcnary.x_fcn.x_lnnoptr, |
565 | ext->x_sym.x_fcnary.x_fcn.x_lnnoptr); | |
566 | H_PUT_32 (abfd, in->x_sym.x_fcnary.x_fcn.x_endndx.l, | |
567 | ext->x_sym.x_fcnary.x_fcn.x_endndx); | |
7f6d05e8 CP |
568 | } |
569 | else | |
570 | { | |
dc810e39 AM |
571 | H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[0], |
572 | ext->x_sym.x_fcnary.x_ary.x_dimen[0]); | |
573 | H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[1], | |
574 | ext->x_sym.x_fcnary.x_ary.x_dimen[1]); | |
575 | H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[2], | |
576 | ext->x_sym.x_fcnary.x_ary.x_dimen[2]); | |
577 | H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[3], | |
578 | ext->x_sym.x_fcnary.x_ary.x_dimen[3]); | |
7f6d05e8 CP |
579 | } |
580 | ||
581 | if (ISFCN (type)) | |
dc810e39 | 582 | H_PUT_32 (abfd, in->x_sym.x_misc.x_fsize, ext->x_sym.x_misc.x_fsize); |
7f6d05e8 CP |
583 | else |
584 | { | |
dc810e39 AM |
585 | H_PUT_16 (abfd, in->x_sym.x_misc.x_lnsz.x_lnno, |
586 | ext->x_sym.x_misc.x_lnsz.x_lnno); | |
587 | H_PUT_16 (abfd, in->x_sym.x_misc.x_lnsz.x_size, | |
588 | ext->x_sym.x_misc.x_lnsz.x_size); | |
7f6d05e8 CP |
589 | } |
590 | ||
591 | end: | |
592 | return bfd_coff_auxesz (abfd); | |
593 | } | |
beb1bf64 TR |
594 | |
595 | ||
252b5132 RH |
596 | \f |
597 | /* The XCOFF reloc table. Actually, XCOFF relocations specify the | |
598 | bitsize and whether they are signed or not, along with a | |
599 | conventional type. This table is for the types, which are used for | |
600 | different algorithms for putting in the reloc. Many of these | |
601 | relocs need special_function entries, which I have not written. */ | |
602 | ||
7f6d05e8 CP |
603 | |
604 | reloc_howto_type xcoff_howto_table[] = | |
252b5132 RH |
605 | { |
606 | /* Standard 32 bit relocation. */ | |
cf9ab45b AM |
607 | HOWTO (R_POS, /* type */ |
608 | 0, /* rightshift */ | |
609 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
610 | 32, /* bitsize */ | |
b34976b6 | 611 | FALSE, /* pc_relative */ |
cf9ab45b | 612 | 0, /* bitpos */ |
252b5132 | 613 | complain_overflow_bitfield, /* complain_on_overflow */ |
cf9ab45b AM |
614 | 0, /* special_function */ |
615 | "R_POS", /* name */ | |
b34976b6 | 616 | TRUE, /* partial_inplace */ |
cf9ab45b AM |
617 | 0xffffffff, /* src_mask */ |
618 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 619 | FALSE), /* pcrel_offset */ |
252b5132 RH |
620 | |
621 | /* 32 bit relocation, but store negative value. */ | |
cf9ab45b AM |
622 | HOWTO (R_NEG, /* type */ |
623 | 0, /* rightshift */ | |
624 | -2, /* size (0 = byte, 1 = short, 2 = long) */ | |
625 | 32, /* bitsize */ | |
b34976b6 | 626 | FALSE, /* pc_relative */ |
cf9ab45b | 627 | 0, /* bitpos */ |
252b5132 | 628 | complain_overflow_bitfield, /* complain_on_overflow */ |
cf9ab45b AM |
629 | 0, /* special_function */ |
630 | "R_NEG", /* name */ | |
b34976b6 | 631 | TRUE, /* partial_inplace */ |
cf9ab45b AM |
632 | 0xffffffff, /* src_mask */ |
633 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 634 | FALSE), /* pcrel_offset */ |
252b5132 RH |
635 | |
636 | /* 32 bit PC relative relocation. */ | |
cf9ab45b AM |
637 | HOWTO (R_REL, /* type */ |
638 | 0, /* rightshift */ | |
639 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
640 | 32, /* bitsize */ | |
b34976b6 | 641 | TRUE, /* pc_relative */ |
cf9ab45b | 642 | 0, /* bitpos */ |
252b5132 | 643 | complain_overflow_signed, /* complain_on_overflow */ |
cf9ab45b AM |
644 | 0, /* special_function */ |
645 | "R_REL", /* name */ | |
b34976b6 | 646 | TRUE, /* partial_inplace */ |
cf9ab45b AM |
647 | 0xffffffff, /* src_mask */ |
648 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 649 | FALSE), /* pcrel_offset */ |
c5930ee6 | 650 | |
252b5132 | 651 | /* 16 bit TOC relative relocation. */ |
cf9ab45b AM |
652 | HOWTO (R_TOC, /* type */ |
653 | 0, /* rightshift */ | |
654 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
655 | 16, /* bitsize */ | |
b34976b6 | 656 | FALSE, /* pc_relative */ |
cf9ab45b | 657 | 0, /* bitpos */ |
252b5132 | 658 | complain_overflow_bitfield, /* complain_on_overflow */ |
cf9ab45b AM |
659 | 0, /* special_function */ |
660 | "R_TOC", /* name */ | |
b34976b6 | 661 | TRUE, /* partial_inplace */ |
cf9ab45b AM |
662 | 0xffff, /* src_mask */ |
663 | 0xffff, /* dst_mask */ | |
b34976b6 | 664 | FALSE), /* pcrel_offset */ |
c5930ee6 | 665 | |
252b5132 | 666 | /* I don't really know what this is. */ |
cf9ab45b AM |
667 | HOWTO (R_RTB, /* type */ |
668 | 1, /* rightshift */ | |
669 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
670 | 32, /* bitsize */ | |
b34976b6 | 671 | FALSE, /* pc_relative */ |
cf9ab45b | 672 | 0, /* bitpos */ |
252b5132 | 673 | complain_overflow_bitfield, /* complain_on_overflow */ |
cf9ab45b AM |
674 | 0, /* special_function */ |
675 | "R_RTB", /* name */ | |
b34976b6 | 676 | TRUE, /* partial_inplace */ |
cf9ab45b AM |
677 | 0xffffffff, /* src_mask */ |
678 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 679 | FALSE), /* pcrel_offset */ |
c5930ee6 | 680 | |
252b5132 | 681 | /* External TOC relative symbol. */ |
cf9ab45b AM |
682 | HOWTO (R_GL, /* type */ |
683 | 0, /* rightshift */ | |
48bfecdd | 684 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
cf9ab45b | 685 | 16, /* bitsize */ |
b34976b6 | 686 | FALSE, /* pc_relative */ |
cf9ab45b | 687 | 0, /* bitpos */ |
252b5132 | 688 | complain_overflow_bitfield, /* complain_on_overflow */ |
cf9ab45b AM |
689 | 0, /* special_function */ |
690 | "R_GL", /* name */ | |
b34976b6 | 691 | TRUE, /* partial_inplace */ |
cf9ab45b AM |
692 | 0xffff, /* src_mask */ |
693 | 0xffff, /* dst_mask */ | |
b34976b6 | 694 | FALSE), /* pcrel_offset */ |
cf9ab45b AM |
695 | |
696 | /* Local TOC relative symbol. */ | |
697 | HOWTO (R_TCL, /* type */ | |
698 | 0, /* rightshift */ | |
48bfecdd | 699 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
cf9ab45b | 700 | 16, /* bitsize */ |
b34976b6 | 701 | FALSE, /* pc_relative */ |
cf9ab45b | 702 | 0, /* bitpos */ |
252b5132 | 703 | complain_overflow_bitfield, /* complain_on_overflow */ |
cf9ab45b AM |
704 | 0, /* special_function */ |
705 | "R_TCL", /* name */ | |
b34976b6 | 706 | TRUE, /* partial_inplace */ |
cf9ab45b AM |
707 | 0xffff, /* src_mask */ |
708 | 0xffff, /* dst_mask */ | |
b34976b6 | 709 | FALSE), /* pcrel_offset */ |
c5930ee6 | 710 | |
5f771d47 | 711 | EMPTY_HOWTO (7), |
c5930ee6 | 712 | |
252b5132 | 713 | /* Non modifiable absolute branch. */ |
cf9ab45b AM |
714 | HOWTO (R_BA, /* type */ |
715 | 0, /* rightshift */ | |
716 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
717 | 26, /* bitsize */ | |
b34976b6 | 718 | FALSE, /* pc_relative */ |
cf9ab45b | 719 | 0, /* bitpos */ |
252b5132 | 720 | complain_overflow_bitfield, /* complain_on_overflow */ |
cf9ab45b AM |
721 | 0, /* special_function */ |
722 | "R_BA_26", /* name */ | |
b34976b6 | 723 | TRUE, /* partial_inplace */ |
a78eab4e | 724 | 0x03fffffc, /* src_mask */ |
48bfecdd | 725 | 0x03fffffc, /* dst_mask */ |
b34976b6 | 726 | FALSE), /* pcrel_offset */ |
c5930ee6 | 727 | |
5f771d47 | 728 | EMPTY_HOWTO (9), |
252b5132 RH |
729 | |
730 | /* Non modifiable relative branch. */ | |
cf9ab45b AM |
731 | HOWTO (R_BR, /* type */ |
732 | 0, /* rightshift */ | |
733 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
734 | 26, /* bitsize */ | |
b34976b6 | 735 | TRUE, /* pc_relative */ |
cf9ab45b | 736 | 0, /* bitpos */ |
252b5132 | 737 | complain_overflow_signed, /* complain_on_overflow */ |
cf9ab45b AM |
738 | 0, /* special_function */ |
739 | "R_BR", /* name */ | |
b34976b6 | 740 | TRUE, /* partial_inplace */ |
a78eab4e | 741 | 0x03fffffc, /* src_mask */ |
48bfecdd | 742 | 0x03fffffc, /* dst_mask */ |
b34976b6 | 743 | FALSE), /* pcrel_offset */ |
c5930ee6 | 744 | |
5f771d47 | 745 | EMPTY_HOWTO (0xb), |
252b5132 RH |
746 | |
747 | /* Indirect load. */ | |
cf9ab45b AM |
748 | HOWTO (R_RL, /* type */ |
749 | 0, /* rightshift */ | |
48bfecdd | 750 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
cf9ab45b | 751 | 16, /* bitsize */ |
b34976b6 | 752 | FALSE, /* pc_relative */ |
cf9ab45b | 753 | 0, /* bitpos */ |
252b5132 | 754 | complain_overflow_bitfield, /* complain_on_overflow */ |
cf9ab45b AM |
755 | 0, /* special_function */ |
756 | "R_RL", /* name */ | |
b34976b6 | 757 | TRUE, /* partial_inplace */ |
cf9ab45b AM |
758 | 0xffff, /* src_mask */ |
759 | 0xffff, /* dst_mask */ | |
b34976b6 | 760 | FALSE), /* pcrel_offset */ |
c5930ee6 | 761 | |
252b5132 | 762 | /* Load address. */ |
cf9ab45b AM |
763 | HOWTO (R_RLA, /* type */ |
764 | 0, /* rightshift */ | |
48bfecdd | 765 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
cf9ab45b | 766 | 16, /* bitsize */ |
b34976b6 | 767 | FALSE, /* pc_relative */ |
cf9ab45b | 768 | 0, /* bitpos */ |
252b5132 | 769 | complain_overflow_bitfield, /* complain_on_overflow */ |
cf9ab45b AM |
770 | 0, /* special_function */ |
771 | "R_RLA", /* name */ | |
b34976b6 | 772 | TRUE, /* partial_inplace */ |
cf9ab45b AM |
773 | 0xffff, /* src_mask */ |
774 | 0xffff, /* dst_mask */ | |
b34976b6 | 775 | FALSE), /* pcrel_offset */ |
c5930ee6 | 776 | |
5f771d47 | 777 | EMPTY_HOWTO (0xe), |
c5930ee6 | 778 | |
252b5132 | 779 | /* Non-relocating reference. */ |
cf9ab45b AM |
780 | HOWTO (R_REF, /* type */ |
781 | 0, /* rightshift */ | |
782 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
783 | 32, /* bitsize */ | |
b34976b6 | 784 | FALSE, /* pc_relative */ |
cf9ab45b | 785 | 0, /* bitpos */ |
48bfecdd | 786 | complain_overflow_dont, /* complain_on_overflow */ |
cf9ab45b AM |
787 | 0, /* special_function */ |
788 | "R_REF", /* name */ | |
b34976b6 | 789 | FALSE, /* partial_inplace */ |
cf9ab45b AM |
790 | 0, /* src_mask */ |
791 | 0, /* dst_mask */ | |
b34976b6 | 792 | FALSE), /* pcrel_offset */ |
c5930ee6 | 793 | |
5f771d47 ILT |
794 | EMPTY_HOWTO (0x10), |
795 | EMPTY_HOWTO (0x11), | |
c5930ee6 | 796 | |
252b5132 | 797 | /* TOC relative indirect load. */ |
cf9ab45b AM |
798 | HOWTO (R_TRL, /* type */ |
799 | 0, /* rightshift */ | |
48bfecdd | 800 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
cf9ab45b | 801 | 16, /* bitsize */ |
b34976b6 | 802 | FALSE, /* pc_relative */ |
cf9ab45b | 803 | 0, /* bitpos */ |
252b5132 | 804 | complain_overflow_bitfield, /* complain_on_overflow */ |
cf9ab45b AM |
805 | 0, /* special_function */ |
806 | "R_TRL", /* name */ | |
b34976b6 | 807 | TRUE, /* partial_inplace */ |
cf9ab45b AM |
808 | 0xffff, /* src_mask */ |
809 | 0xffff, /* dst_mask */ | |
b34976b6 | 810 | FALSE), /* pcrel_offset */ |
c5930ee6 | 811 | |
252b5132 | 812 | /* TOC relative load address. */ |
cf9ab45b AM |
813 | HOWTO (R_TRLA, /* type */ |
814 | 0, /* rightshift */ | |
48bfecdd | 815 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
cf9ab45b | 816 | 16, /* bitsize */ |
b34976b6 | 817 | FALSE, /* pc_relative */ |
cf9ab45b | 818 | 0, /* bitpos */ |
252b5132 | 819 | complain_overflow_bitfield, /* complain_on_overflow */ |
cf9ab45b AM |
820 | 0, /* special_function */ |
821 | "R_TRLA", /* name */ | |
b34976b6 | 822 | TRUE, /* partial_inplace */ |
cf9ab45b AM |
823 | 0xffff, /* src_mask */ |
824 | 0xffff, /* dst_mask */ | |
b34976b6 | 825 | FALSE), /* pcrel_offset */ |
c5930ee6 | 826 | |
252b5132 | 827 | /* Modifiable relative branch. */ |
cf9ab45b AM |
828 | HOWTO (R_RRTBI, /* type */ |
829 | 1, /* rightshift */ | |
830 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
831 | 32, /* bitsize */ | |
b34976b6 | 832 | FALSE, /* pc_relative */ |
cf9ab45b | 833 | 0, /* bitpos */ |
252b5132 | 834 | complain_overflow_bitfield, /* complain_on_overflow */ |
cf9ab45b AM |
835 | 0, /* special_function */ |
836 | "R_RRTBI", /* name */ | |
b34976b6 | 837 | TRUE, /* partial_inplace */ |
cf9ab45b AM |
838 | 0xffffffff, /* src_mask */ |
839 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 840 | FALSE), /* pcrel_offset */ |
c5930ee6 | 841 | |
252b5132 | 842 | /* Modifiable absolute branch. */ |
cf9ab45b AM |
843 | HOWTO (R_RRTBA, /* type */ |
844 | 1, /* rightshift */ | |
845 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
846 | 32, /* bitsize */ | |
b34976b6 | 847 | FALSE, /* pc_relative */ |
cf9ab45b | 848 | 0, /* bitpos */ |
252b5132 | 849 | complain_overflow_bitfield, /* complain_on_overflow */ |
cf9ab45b AM |
850 | 0, /* special_function */ |
851 | "R_RRTBA", /* name */ | |
b34976b6 | 852 | TRUE, /* partial_inplace */ |
cf9ab45b AM |
853 | 0xffffffff, /* src_mask */ |
854 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 855 | FALSE), /* pcrel_offset */ |
c5930ee6 | 856 | |
252b5132 | 857 | /* Modifiable call absolute indirect. */ |
cf9ab45b AM |
858 | HOWTO (R_CAI, /* type */ |
859 | 0, /* rightshift */ | |
48bfecdd | 860 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
cf9ab45b | 861 | 16, /* bitsize */ |
b34976b6 | 862 | FALSE, /* pc_relative */ |
cf9ab45b | 863 | 0, /* bitpos */ |
252b5132 | 864 | complain_overflow_bitfield, /* complain_on_overflow */ |
cf9ab45b AM |
865 | 0, /* special_function */ |
866 | "R_CAI", /* name */ | |
b34976b6 | 867 | TRUE, /* partial_inplace */ |
cf9ab45b AM |
868 | 0xffff, /* src_mask */ |
869 | 0xffff, /* dst_mask */ | |
b34976b6 | 870 | FALSE), /* pcrel_offset */ |
c5930ee6 | 871 | |
252b5132 | 872 | /* Modifiable call relative. */ |
cf9ab45b AM |
873 | HOWTO (R_CREL, /* type */ |
874 | 0, /* rightshift */ | |
48bfecdd | 875 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
cf9ab45b | 876 | 16, /* bitsize */ |
b34976b6 | 877 | FALSE, /* pc_relative */ |
cf9ab45b | 878 | 0, /* bitpos */ |
252b5132 | 879 | complain_overflow_bitfield, /* complain_on_overflow */ |
cf9ab45b AM |
880 | 0, /* special_function */ |
881 | "R_CREL", /* name */ | |
b34976b6 | 882 | TRUE, /* partial_inplace */ |
cf9ab45b AM |
883 | 0xffff, /* src_mask */ |
884 | 0xffff, /* dst_mask */ | |
b34976b6 | 885 | FALSE), /* pcrel_offset */ |
c5930ee6 | 886 | |
252b5132 | 887 | /* Modifiable branch absolute. */ |
cf9ab45b AM |
888 | HOWTO (R_RBA, /* type */ |
889 | 0, /* rightshift */ | |
890 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
891 | 26, /* bitsize */ | |
b34976b6 | 892 | FALSE, /* pc_relative */ |
cf9ab45b | 893 | 0, /* bitpos */ |
252b5132 | 894 | complain_overflow_bitfield, /* complain_on_overflow */ |
cf9ab45b AM |
895 | 0, /* special_function */ |
896 | "R_RBA", /* name */ | |
b34976b6 | 897 | TRUE, /* partial_inplace */ |
a78eab4e | 898 | 0x03fffffc, /* src_mask */ |
48bfecdd | 899 | 0x03fffffc, /* dst_mask */ |
b34976b6 | 900 | FALSE), /* pcrel_offset */ |
c5930ee6 | 901 | |
252b5132 | 902 | /* Modifiable branch absolute. */ |
cf9ab45b AM |
903 | HOWTO (R_RBAC, /* type */ |
904 | 0, /* rightshift */ | |
905 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
906 | 32, /* bitsize */ | |
b34976b6 | 907 | FALSE, /* pc_relative */ |
cf9ab45b | 908 | 0, /* bitpos */ |
252b5132 | 909 | complain_overflow_bitfield, /* complain_on_overflow */ |
cf9ab45b AM |
910 | 0, /* special_function */ |
911 | "R_RBAC", /* name */ | |
b34976b6 | 912 | TRUE, /* partial_inplace */ |
a78eab4e | 913 | 0xffffffff, /* src_mask */ |
48bfecdd | 914 | 0xffffffff, /* dst_mask */ |
b34976b6 | 915 | FALSE), /* pcrel_offset */ |
c5930ee6 | 916 | |
252b5132 | 917 | /* Modifiable branch relative. */ |
cf9ab45b AM |
918 | HOWTO (R_RBR, /* type */ |
919 | 0, /* rightshift */ | |
920 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
921 | 26, /* bitsize */ | |
b34976b6 | 922 | FALSE, /* pc_relative */ |
cf9ab45b | 923 | 0, /* bitpos */ |
252b5132 | 924 | complain_overflow_signed, /* complain_on_overflow */ |
cf9ab45b AM |
925 | 0, /* special_function */ |
926 | "R_RBR_26", /* name */ | |
b34976b6 | 927 | TRUE, /* partial_inplace */ |
a78eab4e | 928 | 0x03fffffc, /* src_mask */ |
48bfecdd | 929 | 0x03fffffc, /* dst_mask */ |
b34976b6 | 930 | FALSE), /* pcrel_offset */ |
c5930ee6 | 931 | |
252b5132 | 932 | /* Modifiable branch absolute. */ |
cf9ab45b AM |
933 | HOWTO (R_RBRC, /* type */ |
934 | 0, /* rightshift */ | |
48bfecdd | 935 | 1, /* size (0 = byte, 1 = short, 2 = long) */ |
cf9ab45b | 936 | 16, /* bitsize */ |
b34976b6 | 937 | FALSE, /* pc_relative */ |
cf9ab45b | 938 | 0, /* bitpos */ |
252b5132 | 939 | complain_overflow_bitfield, /* complain_on_overflow */ |
cf9ab45b AM |
940 | 0, /* special_function */ |
941 | "R_RBRC", /* name */ | |
b34976b6 | 942 | TRUE, /* partial_inplace */ |
cf9ab45b AM |
943 | 0xffff, /* src_mask */ |
944 | 0xffff, /* dst_mask */ | |
b34976b6 | 945 | FALSE), /* pcrel_offset */ |
beb1bf64 | 946 | |
ff3a6ee3 | 947 | /* 16 bit Non modifiable absolute branch. */ |
cf9ab45b AM |
948 | HOWTO (R_BA, /* type */ |
949 | 0, /* rightshift */ | |
950 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
951 | 16, /* bitsize */ | |
b34976b6 | 952 | FALSE, /* pc_relative */ |
cf9ab45b | 953 | 0, /* bitpos */ |
ff3a6ee3 | 954 | complain_overflow_bitfield, /* complain_on_overflow */ |
cf9ab45b AM |
955 | 0, /* special_function */ |
956 | "R_BA_16", /* name */ | |
b34976b6 | 957 | TRUE, /* partial_inplace */ |
cf9ab45b AM |
958 | 0xfffc, /* src_mask */ |
959 | 0xfffc, /* dst_mask */ | |
b34976b6 | 960 | FALSE), /* pcrel_offset */ |
59862849 TR |
961 | |
962 | /* Modifiable branch relative. */ | |
cf9ab45b AM |
963 | HOWTO (R_RBR, /* type */ |
964 | 0, /* rightshift */ | |
965 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
966 | 16, /* bitsize */ | |
b34976b6 | 967 | FALSE, /* pc_relative */ |
cf9ab45b | 968 | 0, /* bitpos */ |
59862849 | 969 | complain_overflow_signed, /* complain_on_overflow */ |
cf9ab45b AM |
970 | 0, /* special_function */ |
971 | "R_RBR_16", /* name */ | |
b34976b6 | 972 | TRUE, /* partial_inplace */ |
cf9ab45b AM |
973 | 0xffff, /* src_mask */ |
974 | 0xffff, /* dst_mask */ | |
b34976b6 | 975 | FALSE), /* pcrel_offset */ |
59862849 | 976 | |
1b164155 | 977 | /* Modifiable branch relative. */ |
cf9ab45b AM |
978 | HOWTO (R_RBA, /* type */ |
979 | 0, /* rightshift */ | |
980 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
981 | 16, /* bitsize */ | |
b34976b6 | 982 | FALSE, /* pc_relative */ |
cf9ab45b | 983 | 0, /* bitpos */ |
1b164155 | 984 | complain_overflow_signed, /* complain_on_overflow */ |
cf9ab45b AM |
985 | 0, /* special_function */ |
986 | "R_RBA_16", /* name */ | |
b34976b6 | 987 | TRUE, /* partial_inplace */ |
cf9ab45b AM |
988 | 0xffff, /* src_mask */ |
989 | 0xffff, /* dst_mask */ | |
b34976b6 | 990 | FALSE), /* pcrel_offset */ |
1b164155 | 991 | |
252b5132 RH |
992 | }; |
993 | ||
7f6d05e8 | 994 | void |
59862849 | 995 | xcoff_rtype2howto (relent, internal) |
252b5132 RH |
996 | arelent *relent; |
997 | struct internal_reloc *internal; | |
998 | { | |
59862849 | 999 | if (internal->r_type > R_RBRC) |
beb1bf64 | 1000 | abort (); |
5ea1af0d | 1001 | |
59862849 TR |
1002 | /* Default howto layout works most of the time */ |
1003 | relent->howto = &xcoff_howto_table[internal->r_type]; | |
cf9ab45b | 1004 | |
5c4491d3 | 1005 | /* Special case some 16 bit reloc */ |
59862849 TR |
1006 | if (15 == (internal->r_size & 0x1f)) |
1007 | { | |
cf9ab45b | 1008 | if (R_BA == internal->r_type) |
59862849 | 1009 | relent->howto = &xcoff_howto_table[0x1c]; |
cf9ab45b | 1010 | else if (R_RBR == internal->r_type) |
59862849 | 1011 | relent->howto = &xcoff_howto_table[0x1d]; |
cf9ab45b | 1012 | else if (R_RBA == internal->r_type) |
1b164155 | 1013 | relent->howto = &xcoff_howto_table[0x1e]; |
59862849 | 1014 | } |
cf9ab45b | 1015 | |
252b5132 RH |
1016 | /* The r_size field of an XCOFF reloc encodes the bitsize of the |
1017 | relocation, as well as indicating whether it is signed or not. | |
1018 | Doublecheck that the relocation information gathered from the | |
c5930ee6 KH |
1019 | type matches this information. The bitsize is not significant |
1020 | for R_REF relocs. */ | |
1021 | if (relent->howto->dst_mask != 0 | |
dc810e39 | 1022 | && (relent->howto->bitsize |
59862849 | 1023 | != ((unsigned int) internal->r_size & 0x1f) + 1)) |
252b5132 | 1024 | abort (); |
252b5132 RH |
1025 | } |
1026 | ||
7f6d05e8 CP |
1027 | reloc_howto_type * |
1028 | _bfd_xcoff_reloc_type_lookup (abfd, code) | |
5f771d47 | 1029 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
1030 | bfd_reloc_code_real_type code; |
1031 | { | |
1032 | switch (code) | |
1033 | { | |
1034 | case BFD_RELOC_PPC_B26: | |
1035 | return &xcoff_howto_table[0xa]; | |
ff3a6ee3 | 1036 | case BFD_RELOC_PPC_BA16: |
59862849 | 1037 | return &xcoff_howto_table[0x1c]; |
252b5132 RH |
1038 | case BFD_RELOC_PPC_BA26: |
1039 | return &xcoff_howto_table[8]; | |
1040 | case BFD_RELOC_PPC_TOC16: | |
1041 | return &xcoff_howto_table[3]; | |
1042 | case BFD_RELOC_32: | |
1043 | case BFD_RELOC_CTOR: | |
1044 | return &xcoff_howto_table[0]; | |
1045 | default: | |
1046 | return NULL; | |
1047 | } | |
1048 | } | |
beb1bf64 | 1049 | |
157090f7 AM |
1050 | static reloc_howto_type * |
1051 | _bfd_xcoff_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, | |
1052 | const char *r_name) | |
1053 | { | |
1054 | unsigned int i; | |
1055 | ||
1056 | for (i = 0; | |
1057 | i < sizeof (xcoff_howto_table) / sizeof (xcoff_howto_table[0]); | |
1058 | i++) | |
1059 | if (xcoff_howto_table[i].name != NULL | |
1060 | && strcasecmp (xcoff_howto_table[i].name, r_name) == 0) | |
1061 | return &xcoff_howto_table[i]; | |
1062 | ||
1063 | return NULL; | |
1064 | } | |
252b5132 RH |
1065 | \f |
1066 | /* XCOFF archive support. The original version of this code was by | |
1067 | Damon A. Permezel. It was enhanced to permit cross support, and | |
1068 | writing archive files, by Ian Lance Taylor, Cygnus Support. | |
1069 | ||
1070 | XCOFF uses its own archive format. Everything is hooked together | |
1071 | with file offset links, so it is possible to rapidly update an | |
1072 | archive in place. Of course, we don't do that. An XCOFF archive | |
1073 | has a real file header, not just an ARMAG string. The structure of | |
1074 | the file header and of each archive header appear below. | |
1075 | ||
1076 | An XCOFF archive also has a member table, which is a list of | |
1077 | elements in the archive (you can get that by looking through the | |
1078 | linked list, but you have to read a lot more of the file). The | |
1079 | member table has a normal archive header with an empty name. It is | |
1080 | normally (and perhaps must be) the second to last entry in the | |
1081 | archive. The member table data is almost printable ASCII. It | |
1082 | starts with a 12 character decimal string which is the number of | |
1083 | entries in the table. For each entry it has a 12 character decimal | |
1084 | string which is the offset in the archive of that member. These | |
1085 | entries are followed by a series of null terminated strings which | |
1086 | are the member names for each entry. | |
1087 | ||
1088 | Finally, an XCOFF archive has a global symbol table, which is what | |
1089 | we call the armap. The global symbol table has a normal archive | |
1090 | header with an empty name. It is normally (and perhaps must be) | |
1091 | the last entry in the archive. The contents start with a four byte | |
1092 | binary number which is the number of entries. This is followed by | |
1093 | a that many four byte binary numbers; each is the file offset of an | |
1094 | entry in the archive. These numbers are followed by a series of | |
5ea1af0d GK |
1095 | null terminated strings, which are symbol names. |
1096 | ||
1097 | AIX 4.3 introduced a new archive format which can handle larger | |
1098 | files and also 32- and 64-bit objects in the same archive. The | |
1099 | things said above remain true except that there is now more than | |
1100 | one global symbol table. The one is used to index 32-bit objects, | |
1101 | the other for 64-bit objects. | |
1102 | ||
1103 | The new archives (recognizable by the new ARMAG string) has larger | |
1104 | field lengths so that we cannot really share any code. Also we have | |
1105 | to take care that we are not generating the new form of archives | |
1106 | on AIX 4.2 or earlier systems. */ | |
252b5132 | 1107 | |
5ea1af0d GK |
1108 | /* XCOFF archives use this as a magic string. Note that both strings |
1109 | have the same length. */ | |
252b5132 | 1110 | |
eb1e0e80 | 1111 | /* Set the magic for archive. */ |
252b5132 | 1112 | |
b34976b6 | 1113 | bfd_boolean |
eb1e0e80 NC |
1114 | bfd_xcoff_ar_archive_set_magic (abfd, magic) |
1115 | bfd *abfd ATTRIBUTE_UNUSED; | |
1116 | char *magic ATTRIBUTE_UNUSED; | |
1117 | { | |
1118 | /* Not supported yet. */ | |
b34976b6 | 1119 | return FALSE; |
eb1e0e80 NC |
1120 | /* bfd_xcoff_archive_set_magic (abfd, magic); */ |
1121 | } | |
252b5132 | 1122 | |
252b5132 RH |
1123 | /* Read in the armap of an XCOFF archive. */ |
1124 | ||
b34976b6 | 1125 | bfd_boolean |
7f6d05e8 | 1126 | _bfd_xcoff_slurp_armap (abfd) |
252b5132 RH |
1127 | bfd *abfd; |
1128 | { | |
1129 | file_ptr off; | |
252b5132 RH |
1130 | size_t namlen; |
1131 | bfd_size_type sz; | |
1132 | bfd_byte *contents, *cend; | |
31612ca6 | 1133 | bfd_vma c, i; |
252b5132 RH |
1134 | carsym *arsym; |
1135 | bfd_byte *p; | |
1136 | ||
1137 | if (xcoff_ardata (abfd) == NULL) | |
1138 | { | |
b34976b6 AM |
1139 | bfd_has_map (abfd) = FALSE; |
1140 | return TRUE; | |
252b5132 RH |
1141 | } |
1142 | ||
5ea1af0d | 1143 | if (! xcoff_big_format_p (abfd)) |
252b5132 | 1144 | { |
5ea1af0d GK |
1145 | /* This is for the old format. */ |
1146 | struct xcoff_ar_hdr hdr; | |
1147 | ||
1148 | off = strtol (xcoff_ardata (abfd)->symoff, (char **) NULL, 10); | |
1149 | if (off == 0) | |
1150 | { | |
b34976b6 AM |
1151 | bfd_has_map (abfd) = FALSE; |
1152 | return TRUE; | |
5ea1af0d GK |
1153 | } |
1154 | ||
1155 | if (bfd_seek (abfd, off, SEEK_SET) != 0) | |
b34976b6 | 1156 | return FALSE; |
5ea1af0d GK |
1157 | |
1158 | /* The symbol table starts with a normal archive header. */ | |
dc810e39 AM |
1159 | if (bfd_bread ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd) |
1160 | != SIZEOF_AR_HDR) | |
b34976b6 | 1161 | return FALSE; |
5ea1af0d GK |
1162 | |
1163 | /* Skip the name (normally empty). */ | |
1164 | namlen = strtol (hdr.namlen, (char **) NULL, 10); | |
dc810e39 AM |
1165 | off = ((namlen + 1) & ~ (size_t) 1) + SXCOFFARFMAG; |
1166 | if (bfd_seek (abfd, off, SEEK_CUR) != 0) | |
b34976b6 | 1167 | return FALSE; |
5ea1af0d GK |
1168 | |
1169 | sz = strtol (hdr.size, (char **) NULL, 10); | |
31612ca6 GK |
1170 | |
1171 | /* Read in the entire symbol table. */ | |
1172 | contents = (bfd_byte *) bfd_alloc (abfd, sz); | |
1173 | if (contents == NULL) | |
b34976b6 | 1174 | return FALSE; |
dc810e39 | 1175 | if (bfd_bread ((PTR) contents, sz, abfd) != sz) |
b34976b6 | 1176 | return FALSE; |
31612ca6 GK |
1177 | |
1178 | /* The symbol table starts with a four byte count. */ | |
dc810e39 AM |
1179 | c = H_GET_32 (abfd, contents); |
1180 | ||
31612ca6 GK |
1181 | if (c * 4 >= sz) |
1182 | { | |
1183 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 1184 | return FALSE; |
31612ca6 | 1185 | } |
dc810e39 AM |
1186 | |
1187 | bfd_ardata (abfd)->symdefs = | |
1188 | ((carsym *) bfd_alloc (abfd, c * sizeof (carsym))); | |
31612ca6 | 1189 | if (bfd_ardata (abfd)->symdefs == NULL) |
b34976b6 | 1190 | return FALSE; |
dc810e39 | 1191 | |
31612ca6 GK |
1192 | /* After the count comes a list of four byte file offsets. */ |
1193 | for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 4; | |
1194 | i < c; | |
1195 | ++i, ++arsym, p += 4) | |
dc810e39 | 1196 | arsym->file_offset = H_GET_32 (abfd, p); |
252b5132 | 1197 | } |
5ea1af0d GK |
1198 | else |
1199 | { | |
1200 | /* This is for the new format. */ | |
1201 | struct xcoff_ar_hdr_big hdr; | |
252b5132 | 1202 | |
5ea1af0d GK |
1203 | off = strtol (xcoff_ardata_big (abfd)->symoff, (char **) NULL, 10); |
1204 | if (off == 0) | |
1205 | { | |
b34976b6 AM |
1206 | bfd_has_map (abfd) = FALSE; |
1207 | return TRUE; | |
5ea1af0d | 1208 | } |
252b5132 | 1209 | |
5ea1af0d | 1210 | if (bfd_seek (abfd, off, SEEK_SET) != 0) |
b34976b6 | 1211 | return FALSE; |
252b5132 | 1212 | |
5ea1af0d | 1213 | /* The symbol table starts with a normal archive header. */ |
dc810e39 | 1214 | if (bfd_bread ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR_BIG, abfd) |
5ea1af0d | 1215 | != SIZEOF_AR_HDR_BIG) |
b34976b6 | 1216 | return FALSE; |
5ea1af0d GK |
1217 | |
1218 | /* Skip the name (normally empty). */ | |
1219 | namlen = strtol (hdr.namlen, (char **) NULL, 10); | |
dc810e39 AM |
1220 | off = ((namlen + 1) & ~ (size_t) 1) + SXCOFFARFMAG; |
1221 | if (bfd_seek (abfd, off, SEEK_CUR) != 0) | |
b34976b6 | 1222 | return FALSE; |
5ea1af0d GK |
1223 | |
1224 | /* XXX This actually has to be a call to strtoll (at least on 32-bit | |
1225 | machines) since the field width is 20 and there numbers with more | |
1226 | than 32 bits can be represented. */ | |
1227 | sz = strtol (hdr.size, (char **) NULL, 10); | |
252b5132 | 1228 | |
31612ca6 GK |
1229 | /* Read in the entire symbol table. */ |
1230 | contents = (bfd_byte *) bfd_alloc (abfd, sz); | |
1231 | if (contents == NULL) | |
b34976b6 | 1232 | return FALSE; |
dc810e39 | 1233 | if (bfd_bread ((PTR) contents, sz, abfd) != sz) |
b34976b6 | 1234 | return FALSE; |
252b5132 | 1235 | |
31612ca6 | 1236 | /* The symbol table starts with an eight byte count. */ |
dc810e39 | 1237 | c = H_GET_64 (abfd, contents); |
252b5132 | 1238 | |
31612ca6 GK |
1239 | if (c * 8 >= sz) |
1240 | { | |
1241 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 1242 | return FALSE; |
31612ca6 | 1243 | } |
dc810e39 AM |
1244 | |
1245 | bfd_ardata (abfd)->symdefs = | |
1246 | ((carsym *) bfd_alloc (abfd, c * sizeof (carsym))); | |
31612ca6 | 1247 | if (bfd_ardata (abfd)->symdefs == NULL) |
b34976b6 | 1248 | return FALSE; |
dc810e39 | 1249 | |
31612ca6 GK |
1250 | /* After the count comes a list of eight byte file offsets. */ |
1251 | for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 8; | |
1252 | i < c; | |
1253 | ++i, ++arsym, p += 8) | |
dc810e39 | 1254 | arsym->file_offset = H_GET_64 (abfd, p); |
252b5132 RH |
1255 | } |
1256 | ||
252b5132 RH |
1257 | /* After the file offsets come null terminated symbol names. */ |
1258 | cend = contents + sz; | |
1259 | for (i = 0, arsym = bfd_ardata (abfd)->symdefs; | |
1260 | i < c; | |
1261 | ++i, ++arsym, p += strlen ((char *) p) + 1) | |
1262 | { | |
1263 | if (p >= cend) | |
1264 | { | |
1265 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 1266 | return FALSE; |
252b5132 RH |
1267 | } |
1268 | arsym->name = (char *) p; | |
1269 | } | |
1270 | ||
1271 | bfd_ardata (abfd)->symdef_count = c; | |
b34976b6 | 1272 | bfd_has_map (abfd) = TRUE; |
252b5132 | 1273 | |
b34976b6 | 1274 | return TRUE; |
252b5132 RH |
1275 | } |
1276 | ||
1277 | /* See if this is an XCOFF archive. */ | |
1278 | ||
7f6d05e8 CP |
1279 | const bfd_target * |
1280 | _bfd_xcoff_archive_p (abfd) | |
252b5132 RH |
1281 | bfd *abfd; |
1282 | { | |
487e54f2 | 1283 | struct artdata *tdata_hold; |
5ea1af0d | 1284 | char magic[SXCOFFARMAG]; |
487e54f2 | 1285 | bfd_size_type amt = SXCOFFARMAG; |
252b5132 | 1286 | |
487e54f2 | 1287 | if (bfd_bread ((PTR) magic, amt, abfd) != amt) |
252b5132 RH |
1288 | { |
1289 | if (bfd_get_error () != bfd_error_system_call) | |
1290 | bfd_set_error (bfd_error_wrong_format); | |
1291 | return NULL; | |
1292 | } | |
1293 | ||
5ea1af0d GK |
1294 | if (strncmp (magic, XCOFFARMAG, SXCOFFARMAG) != 0 |
1295 | && strncmp (magic, XCOFFARMAGBIG, SXCOFFARMAG) != 0) | |
252b5132 RH |
1296 | { |
1297 | bfd_set_error (bfd_error_wrong_format); | |
1298 | return NULL; | |
1299 | } | |
1300 | ||
487e54f2 AM |
1301 | tdata_hold = bfd_ardata (abfd); |
1302 | ||
dc810e39 | 1303 | amt = sizeof (struct artdata); |
487e54f2 | 1304 | bfd_ardata (abfd) = (struct artdata *) bfd_zalloc (abfd, amt); |
252b5132 | 1305 | if (bfd_ardata (abfd) == (struct artdata *) NULL) |
487e54f2 | 1306 | goto error_ret_restore; |
252b5132 | 1307 | |
9e492e05 JJ |
1308 | /* Cleared by bfd_zalloc above. |
1309 | bfd_ardata (abfd)->cache = NULL; | |
1310 | bfd_ardata (abfd)->archive_head = NULL; | |
1311 | bfd_ardata (abfd)->symdefs = NULL; | |
1312 | bfd_ardata (abfd)->extended_names = NULL; | |
1313 | bfd_ardata (abfd)->extended_names_size = 0; */ | |
252b5132 | 1314 | |
5ea1af0d GK |
1315 | /* Now handle the two formats. */ |
1316 | if (magic[1] != 'b') | |
1317 | { | |
1318 | /* This is the old format. */ | |
1319 | struct xcoff_ar_file_hdr hdr; | |
252b5132 | 1320 | |
5ea1af0d GK |
1321 | /* Copy over the magic string. */ |
1322 | memcpy (hdr.magic, magic, SXCOFFARMAG); | |
1323 | ||
1324 | /* Now read the rest of the file header. */ | |
487e54f2 AM |
1325 | amt = SIZEOF_AR_FILE_HDR - SXCOFFARMAG; |
1326 | if (bfd_bread ((PTR) &hdr.memoff, amt, abfd) != amt) | |
5ea1af0d GK |
1327 | { |
1328 | if (bfd_get_error () != bfd_error_system_call) | |
1329 | bfd_set_error (bfd_error_wrong_format); | |
487e54f2 | 1330 | goto error_ret; |
5ea1af0d GK |
1331 | } |
1332 | ||
1333 | bfd_ardata (abfd)->first_file_filepos = strtol (hdr.firstmemoff, | |
1334 | (char **) NULL, 10); | |
1335 | ||
dc810e39 AM |
1336 | amt = SIZEOF_AR_FILE_HDR; |
1337 | bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, amt); | |
5ea1af0d | 1338 | if (bfd_ardata (abfd)->tdata == NULL) |
487e54f2 | 1339 | goto error_ret; |
5ea1af0d GK |
1340 | |
1341 | memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR); | |
1342 | } | |
1343 | else | |
1344 | { | |
1345 | /* This is the new format. */ | |
1346 | struct xcoff_ar_file_hdr_big hdr; | |
1347 | ||
1348 | /* Copy over the magic string. */ | |
1349 | memcpy (hdr.magic, magic, SXCOFFARMAG); | |
1350 | ||
1351 | /* Now read the rest of the file header. */ | |
487e54f2 AM |
1352 | amt = SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG; |
1353 | if (bfd_bread ((PTR) &hdr.memoff, amt, abfd) != amt) | |
5ea1af0d GK |
1354 | { |
1355 | if (bfd_get_error () != bfd_error_system_call) | |
1356 | bfd_set_error (bfd_error_wrong_format); | |
487e54f2 | 1357 | goto error_ret; |
5ea1af0d GK |
1358 | } |
1359 | ||
487e54f2 AM |
1360 | bfd_ardata (abfd)->first_file_filepos = bfd_scan_vma (hdr.firstmemoff, |
1361 | (const char **) 0, | |
1362 | 10); | |
5ea1af0d | 1363 | |
dc810e39 AM |
1364 | amt = SIZEOF_AR_FILE_HDR_BIG; |
1365 | bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, amt); | |
5ea1af0d | 1366 | if (bfd_ardata (abfd)->tdata == NULL) |
487e54f2 | 1367 | goto error_ret; |
5ea1af0d GK |
1368 | |
1369 | memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR_BIG); | |
1370 | } | |
252b5132 | 1371 | |
7f6d05e8 | 1372 | if (! _bfd_xcoff_slurp_armap (abfd)) |
252b5132 | 1373 | { |
487e54f2 | 1374 | error_ret: |
252b5132 | 1375 | bfd_release (abfd, bfd_ardata (abfd)); |
487e54f2 AM |
1376 | error_ret_restore: |
1377 | bfd_ardata (abfd) = tdata_hold; | |
252b5132 RH |
1378 | return NULL; |
1379 | } | |
1380 | ||
1381 | return abfd->xvec; | |
1382 | } | |
1383 | ||
1384 | /* Read the archive header in an XCOFF archive. */ | |
1385 | ||
7f6d05e8 CP |
1386 | PTR |
1387 | _bfd_xcoff_read_ar_hdr (abfd) | |
252b5132 RH |
1388 | bfd *abfd; |
1389 | { | |
dc810e39 | 1390 | bfd_size_type namlen; |
252b5132 | 1391 | struct areltdata *ret; |
dc810e39 | 1392 | bfd_size_type amt = sizeof (struct areltdata); |
252b5132 | 1393 | |
dc810e39 | 1394 | ret = (struct areltdata *) bfd_alloc (abfd, amt); |
252b5132 RH |
1395 | if (ret == NULL) |
1396 | return NULL; | |
5ea1af0d GK |
1397 | |
1398 | if (! xcoff_big_format_p (abfd)) | |
1399 | { | |
1400 | struct xcoff_ar_hdr hdr; | |
1401 | struct xcoff_ar_hdr *hdrp; | |
1402 | ||
dc810e39 AM |
1403 | if (bfd_bread ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd) |
1404 | != SIZEOF_AR_HDR) | |
5ea1af0d GK |
1405 | { |
1406 | free (ret); | |
1407 | return NULL; | |
1408 | } | |
1409 | ||
1410 | namlen = strtol (hdr.namlen, (char **) NULL, 10); | |
dc810e39 AM |
1411 | amt = SIZEOF_AR_HDR + namlen + 1; |
1412 | hdrp = (struct xcoff_ar_hdr *) bfd_alloc (abfd, amt); | |
5ea1af0d GK |
1413 | if (hdrp == NULL) |
1414 | { | |
1415 | free (ret); | |
1416 | return NULL; | |
1417 | } | |
1418 | memcpy (hdrp, &hdr, SIZEOF_AR_HDR); | |
dc810e39 | 1419 | if (bfd_bread ((char *) hdrp + SIZEOF_AR_HDR, namlen, abfd) != namlen) |
5ea1af0d GK |
1420 | { |
1421 | free (ret); | |
1422 | return NULL; | |
1423 | } | |
1424 | ((char *) hdrp)[SIZEOF_AR_HDR + namlen] = '\0'; | |
1425 | ||
1426 | ret->arch_header = (char *) hdrp; | |
1427 | ret->parsed_size = strtol (hdr.size, (char **) NULL, 10); | |
1428 | ret->filename = (char *) hdrp + SIZEOF_AR_HDR; | |
1429 | } | |
1430 | else | |
1431 | { | |
1432 | struct xcoff_ar_hdr_big hdr; | |
1433 | struct xcoff_ar_hdr_big *hdrp; | |
1434 | ||
dc810e39 | 1435 | if (bfd_bread ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR_BIG, abfd) |
5ea1af0d GK |
1436 | != SIZEOF_AR_HDR_BIG) |
1437 | { | |
1438 | free (ret); | |
1439 | return NULL; | |
1440 | } | |
1441 | ||
1442 | namlen = strtol (hdr.namlen, (char **) NULL, 10); | |
dc810e39 AM |
1443 | amt = SIZEOF_AR_HDR_BIG + namlen + 1; |
1444 | hdrp = (struct xcoff_ar_hdr_big *) bfd_alloc (abfd, amt); | |
5ea1af0d GK |
1445 | if (hdrp == NULL) |
1446 | { | |
1447 | free (ret); | |
1448 | return NULL; | |
1449 | } | |
1450 | memcpy (hdrp, &hdr, SIZEOF_AR_HDR_BIG); | |
dc810e39 | 1451 | if (bfd_bread ((char *) hdrp + SIZEOF_AR_HDR_BIG, namlen, abfd) != namlen) |
5ea1af0d GK |
1452 | { |
1453 | free (ret); | |
1454 | return NULL; | |
1455 | } | |
1456 | ((char *) hdrp)[SIZEOF_AR_HDR_BIG + namlen] = '\0'; | |
1457 | ||
1458 | ret->arch_header = (char *) hdrp; | |
1459 | /* XXX This actually has to be a call to strtoll (at least on 32-bit | |
1460 | machines) since the field width is 20 and there numbers with more | |
1461 | than 32 bits can be represented. */ | |
1462 | ret->parsed_size = strtol (hdr.size, (char **) NULL, 10); | |
1463 | ret->filename = (char *) hdrp + SIZEOF_AR_HDR_BIG; | |
1464 | } | |
252b5132 RH |
1465 | |
1466 | /* Skip over the XCOFFARFMAG at the end of the file name. */ | |
dc810e39 | 1467 | if (bfd_seek (abfd, (file_ptr) ((namlen & 1) + SXCOFFARFMAG), SEEK_CUR) != 0) |
252b5132 RH |
1468 | return NULL; |
1469 | ||
1470 | return (PTR) ret; | |
1471 | } | |
1472 | ||
1473 | /* Open the next element in an XCOFF archive. */ | |
1474 | ||
7f6d05e8 CP |
1475 | bfd * |
1476 | _bfd_xcoff_openr_next_archived_file (archive, last_file) | |
252b5132 RH |
1477 | bfd *archive; |
1478 | bfd *last_file; | |
1479 | { | |
1480 | file_ptr filestart; | |
1481 | ||
1482 | if (xcoff_ardata (archive) == NULL) | |
1483 | { | |
1484 | bfd_set_error (bfd_error_invalid_operation); | |
1485 | return NULL; | |
1486 | } | |
1487 | ||
5ea1af0d GK |
1488 | if (! xcoff_big_format_p (archive)) |
1489 | { | |
1490 | if (last_file == NULL) | |
1491 | filestart = bfd_ardata (archive)->first_file_filepos; | |
1492 | else | |
1493 | filestart = strtol (arch_xhdr (last_file)->nextoff, (char **) NULL, | |
1494 | 10); | |
1495 | ||
1496 | if (filestart == 0 | |
1497 | || filestart == strtol (xcoff_ardata (archive)->memoff, | |
1498 | (char **) NULL, 10) | |
1499 | || filestart == strtol (xcoff_ardata (archive)->symoff, | |
1500 | (char **) NULL, 10)) | |
1501 | { | |
1502 | bfd_set_error (bfd_error_no_more_archived_files); | |
1503 | return NULL; | |
1504 | } | |
1505 | } | |
252b5132 | 1506 | else |
252b5132 | 1507 | { |
5ea1af0d GK |
1508 | if (last_file == NULL) |
1509 | filestart = bfd_ardata (archive)->first_file_filepos; | |
1510 | else | |
1511 | /* XXX These actually have to be a calls to strtoll (at least | |
1512 | on 32-bit machines) since the fields's width is 20 and | |
1513 | there numbers with more than 32 bits can be represented. */ | |
1514 | filestart = strtol (arch_xhdr_big (last_file)->nextoff, (char **) NULL, | |
1515 | 10); | |
1516 | ||
1517 | /* XXX These actually have to be calls to strtoll (at least on 32-bit | |
1518 | machines) since the fields's width is 20 and there numbers with more | |
1519 | than 32 bits can be represented. */ | |
1520 | if (filestart == 0 | |
1521 | || filestart == strtol (xcoff_ardata_big (archive)->memoff, | |
1522 | (char **) NULL, 10) | |
1523 | || filestart == strtol (xcoff_ardata_big (archive)->symoff, | |
1524 | (char **) NULL, 10)) | |
1525 | { | |
1526 | bfd_set_error (bfd_error_no_more_archived_files); | |
1527 | return NULL; | |
1528 | } | |
252b5132 RH |
1529 | } |
1530 | ||
1531 | return _bfd_get_elt_at_filepos (archive, filestart); | |
1532 | } | |
1533 | ||
1534 | /* Stat an element in an XCOFF archive. */ | |
1535 | ||
7f6d05e8 | 1536 | int |
51b9608c | 1537 | _bfd_xcoff_stat_arch_elt (abfd, s) |
252b5132 RH |
1538 | bfd *abfd; |
1539 | struct stat *s; | |
1540 | { | |
252b5132 RH |
1541 | if (abfd->arelt_data == NULL) |
1542 | { | |
1543 | bfd_set_error (bfd_error_invalid_operation); | |
1544 | return -1; | |
1545 | } | |
1546 | ||
51b9608c | 1547 | if (! xcoff_big_format_p (abfd->my_archive)) |
5ea1af0d GK |
1548 | { |
1549 | struct xcoff_ar_hdr *hdrp = arch_xhdr (abfd); | |
1550 | ||
1551 | s->st_mtime = strtol (hdrp->date, (char **) NULL, 10); | |
1552 | s->st_uid = strtol (hdrp->uid, (char **) NULL, 10); | |
1553 | s->st_gid = strtol (hdrp->gid, (char **) NULL, 10); | |
1554 | s->st_mode = strtol (hdrp->mode, (char **) NULL, 8); | |
1555 | s->st_size = arch_eltdata (abfd)->parsed_size; | |
1556 | } | |
1557 | else | |
1558 | { | |
1559 | struct xcoff_ar_hdr_big *hdrp = arch_xhdr_big (abfd); | |
252b5132 | 1560 | |
5ea1af0d GK |
1561 | s->st_mtime = strtol (hdrp->date, (char **) NULL, 10); |
1562 | s->st_uid = strtol (hdrp->uid, (char **) NULL, 10); | |
1563 | s->st_gid = strtol (hdrp->gid, (char **) NULL, 10); | |
1564 | s->st_mode = strtol (hdrp->mode, (char **) NULL, 8); | |
1565 | s->st_size = arch_eltdata (abfd)->parsed_size; | |
1566 | } | |
252b5132 RH |
1567 | |
1568 | return 0; | |
1569 | } | |
1570 | ||
1571 | /* Normalize a file name for inclusion in an archive. */ | |
1572 | ||
1573 | static const char * | |
1574 | normalize_filename (abfd) | |
1575 | bfd *abfd; | |
1576 | { | |
1577 | const char *file; | |
1578 | const char *filename; | |
1579 | ||
1580 | file = bfd_get_filename (abfd); | |
1581 | filename = strrchr (file, '/'); | |
1582 | if (filename != NULL) | |
1583 | filename++; | |
1584 | else | |
1585 | filename = file; | |
1586 | return filename; | |
1587 | } | |
1588 | ||
1589 | /* Write out an XCOFF armap. */ | |
1590 | ||
b34976b6 | 1591 | static bfd_boolean |
5ea1af0d | 1592 | xcoff_write_armap_old (abfd, elength, map, orl_count, stridx) |
252b5132 | 1593 | bfd *abfd; |
5f771d47 | 1594 | unsigned int elength ATTRIBUTE_UNUSED; |
252b5132 RH |
1595 | struct orl *map; |
1596 | unsigned int orl_count; | |
1597 | int stridx; | |
1598 | { | |
1599 | struct xcoff_ar_hdr hdr; | |
1600 | char *p; | |
1601 | unsigned char buf[4]; | |
1602 | bfd *sub; | |
1603 | file_ptr fileoff; | |
1604 | unsigned int i; | |
1605 | ||
1606 | memset (&hdr, 0, sizeof hdr); | |
1607 | sprintf (hdr.size, "%ld", (long) (4 + orl_count * 4 + stridx)); | |
1608 | sprintf (hdr.nextoff, "%d", 0); | |
330693f5 | 1609 | memcpy (hdr.prevoff, xcoff_ardata (abfd)->memoff, XCOFFARMAG_ELEMENT_SIZE); |
252b5132 RH |
1610 | sprintf (hdr.date, "%d", 0); |
1611 | sprintf (hdr.uid, "%d", 0); | |
1612 | sprintf (hdr.gid, "%d", 0); | |
1613 | sprintf (hdr.mode, "%d", 0); | |
1614 | sprintf (hdr.namlen, "%d", 0); | |
1615 | ||
1616 | /* We need spaces, not null bytes, in the header. */ | |
1617 | for (p = (char *) &hdr; p < (char *) &hdr + SIZEOF_AR_HDR; p++) | |
1618 | if (*p == '\0') | |
1619 | *p = ' '; | |
1620 | ||
dc810e39 AM |
1621 | if (bfd_bwrite ((PTR) &hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd) |
1622 | != SIZEOF_AR_HDR | |
1623 | || (bfd_bwrite (XCOFFARFMAG, (bfd_size_type) SXCOFFARFMAG, abfd) | |
1624 | != SXCOFFARFMAG)) | |
b34976b6 | 1625 | return FALSE; |
5ea1af0d | 1626 | |
dc810e39 AM |
1627 | H_PUT_32 (abfd, orl_count, buf); |
1628 | if (bfd_bwrite (buf, (bfd_size_type) 4, abfd) != 4) | |
b34976b6 | 1629 | return FALSE; |
252b5132 RH |
1630 | |
1631 | sub = abfd->archive_head; | |
1632 | fileoff = SIZEOF_AR_FILE_HDR; | |
1633 | i = 0; | |
1634 | while (sub != NULL && i < orl_count) | |
1635 | { | |
1636 | size_t namlen; | |
1637 | ||
dc810e39 | 1638 | while (map[i].u.abfd == sub) |
252b5132 | 1639 | { |
dc810e39 AM |
1640 | H_PUT_32 (abfd, fileoff, buf); |
1641 | if (bfd_bwrite (buf, (bfd_size_type) 4, abfd) != 4) | |
b34976b6 | 1642 | return FALSE; |
252b5132 RH |
1643 | ++i; |
1644 | } | |
1645 | namlen = strlen (normalize_filename (sub)); | |
dc810e39 | 1646 | namlen = (namlen + 1) &~ (size_t) 1; |
252b5132 RH |
1647 | fileoff += (SIZEOF_AR_HDR |
1648 | + namlen | |
1649 | + SXCOFFARFMAG | |
1650 | + arelt_size (sub)); | |
1651 | fileoff = (fileoff + 1) &~ 1; | |
1652 | sub = sub->next; | |
1653 | } | |
1654 | ||
1655 | for (i = 0; i < orl_count; i++) | |
1656 | { | |
1657 | const char *name; | |
1658 | size_t namlen; | |
1659 | ||
1660 | name = *map[i].name; | |
1661 | namlen = strlen (name); | |
dc810e39 | 1662 | if (bfd_bwrite (name, (bfd_size_type) (namlen + 1), abfd) != namlen + 1) |
b34976b6 | 1663 | return FALSE; |
252b5132 RH |
1664 | } |
1665 | ||
1666 | if ((stridx & 1) != 0) | |
1667 | { | |
1668 | char b; | |
1669 | ||
1670 | b = '\0'; | |
dc810e39 | 1671 | if (bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1) |
b34976b6 | 1672 | return FALSE; |
252b5132 RH |
1673 | } |
1674 | ||
b34976b6 | 1675 | return TRUE; |
252b5132 RH |
1676 | } |
1677 | ||
330693f5 TR |
1678 | static char buff20[XCOFFARMAGBIG_ELEMENT_SIZE + 1]; |
1679 | #define FMT20 "%-20lld" | |
1680 | #define FMT12 "%-12d" | |
1681 | #define FMT12_OCTAL "%-12o" | |
1682 | #define FMT4 "%-4d" | |
1683 | #define PRINT20(d, v) \ | |
1684 | sprintf (buff20, FMT20, (long long)(v)), \ | |
1685 | memcpy ((void *) (d), buff20, 20) | |
1686 | ||
1687 | #define PRINT12(d, v) \ | |
1688 | sprintf (buff20, FMT12, (int)(v)), \ | |
cf9ab45b | 1689 | memcpy ((void *) (d), buff20, 12) |
330693f5 TR |
1690 | |
1691 | #define PRINT12_OCTAL(d, v) \ | |
1692 | sprintf (buff20, FMT12_OCTAL, (unsigned int)(v)), \ | |
1693 | memcpy ((void *) (d), buff20, 12) | |
1694 | ||
1695 | #define PRINT4(d, v) \ | |
1696 | sprintf (buff20, FMT4, (int)(v)), \ | |
cf9ab45b | 1697 | memcpy ((void *) (d), buff20, 4) |
330693f5 TR |
1698 | |
1699 | #define READ20(d, v) \ | |
1700 | buff20[20] = 0, \ | |
1701 | memcpy (buff20, (d), 20), \ | |
1dba4cb4 | 1702 | (v) = bfd_scan_vma (buff20, (const char **) NULL, 10) |
f4ffd778 | 1703 | |
b34976b6 | 1704 | static bfd_boolean |
eb1e0e80 NC |
1705 | do_pad (abfd, number) |
1706 | bfd *abfd; | |
1707 | unsigned int number; | |
1708 | { | |
1709 | bfd_byte b = 0; | |
1710 | ||
1711 | /* Limit pad to <= 4096. */ | |
1712 | if (number > 4096) | |
b34976b6 | 1713 | return FALSE; |
eb1e0e80 NC |
1714 | |
1715 | while (number--) | |
1716 | if (bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1) | |
b34976b6 | 1717 | return FALSE; |
eb1e0e80 | 1718 | |
b34976b6 | 1719 | return TRUE; |
eb1e0e80 NC |
1720 | } |
1721 | ||
b34976b6 | 1722 | static bfd_boolean |
eb1e0e80 NC |
1723 | do_copy (out_bfd, in_bfd) |
1724 | bfd *out_bfd; | |
1725 | bfd *in_bfd; | |
1726 | { | |
1727 | bfd_size_type remaining; | |
1728 | bfd_byte buffer[DEFAULT_BUFFERSIZE]; | |
1729 | ||
1730 | if (bfd_seek (in_bfd, (file_ptr) 0, SEEK_SET) != 0) | |
b34976b6 | 1731 | return FALSE; |
eb1e0e80 NC |
1732 | |
1733 | remaining = arelt_size (in_bfd); | |
1734 | ||
1735 | while (remaining >= DEFAULT_BUFFERSIZE) | |
1736 | { | |
1737 | if (bfd_bread (buffer, DEFAULT_BUFFERSIZE, in_bfd) != DEFAULT_BUFFERSIZE | |
1738 | || bfd_bwrite (buffer, DEFAULT_BUFFERSIZE, out_bfd) != DEFAULT_BUFFERSIZE) | |
b34976b6 | 1739 | return FALSE; |
eb1e0e80 NC |
1740 | |
1741 | remaining -= DEFAULT_BUFFERSIZE; | |
1742 | } | |
1743 | ||
1744 | if (remaining) | |
1745 | { | |
cf9ab45b | 1746 | if (bfd_bread (buffer, remaining, in_bfd) != remaining |
eb1e0e80 | 1747 | || bfd_bwrite (buffer, remaining, out_bfd) != remaining) |
b34976b6 | 1748 | return FALSE; |
eb1e0e80 NC |
1749 | } |
1750 | ||
b34976b6 | 1751 | return TRUE; |
eb1e0e80 NC |
1752 | } |
1753 | ||
b34976b6 | 1754 | static bfd_boolean |
eb1e0e80 NC |
1755 | do_shared_object_padding (out_bfd, in_bfd, offset, ar_header_size) |
1756 | bfd *out_bfd; | |
1757 | bfd *in_bfd; | |
9dadfa79 | 1758 | file_ptr *offset; |
eb1e0e80 NC |
1759 | int ar_header_size; |
1760 | { | |
1761 | if (bfd_check_format (in_bfd, bfd_object) | |
1762 | && bfd_get_flavour (in_bfd) == bfd_target_xcoff_flavour | |
1763 | && (in_bfd->flags & DYNAMIC) != 0) | |
1764 | { | |
1765 | bfd_size_type pad = 0; | |
1766 | int text_align_power; | |
1767 | ||
1768 | text_align_power = bfd_xcoff_text_align_power (in_bfd); | |
eb1e0e80 NC |
1769 | |
1770 | pad = 1 << text_align_power; | |
1771 | pad -= (*offset + ar_header_size) & (pad - 1); | |
1772 | ||
1773 | if (! do_pad (out_bfd, pad)) | |
b34976b6 | 1774 | return FALSE; |
eb1e0e80 NC |
1775 | |
1776 | *offset += pad; | |
1777 | } | |
1778 | ||
b34976b6 | 1779 | return TRUE; |
eb1e0e80 NC |
1780 | } |
1781 | ||
b34976b6 | 1782 | static bfd_boolean |
330693f5 | 1783 | xcoff_write_armap_big (abfd, elength, map, orl_count, stridx) |
252b5132 | 1784 | bfd *abfd; |
330693f5 | 1785 | unsigned int elength ATTRIBUTE_UNUSED; |
5ea1af0d GK |
1786 | struct orl *map; |
1787 | unsigned int orl_count; | |
330693f5 | 1788 | int stridx; |
252b5132 | 1789 | { |
330693f5 TR |
1790 | struct xcoff_ar_file_hdr_big *fhdr; |
1791 | bfd_vma i, sym_32, sym_64, str_32, str_64; | |
f4ffd778 | 1792 | const bfd_arch_info_type *arch_info = NULL; |
330693f5 TR |
1793 | bfd *current_bfd; |
1794 | size_t string_length; | |
9dadfa79 | 1795 | file_ptr nextoff, prevoff; |
cf9ab45b | 1796 | |
330693f5 TR |
1797 | /* First, we look through the symbols and work out which are |
1798 | from 32-bit objects and which from 64-bit ones. */ | |
1799 | sym_32 = sym_64 = str_32 = str_64 = 0; | |
252b5132 | 1800 | |
330693f5 TR |
1801 | current_bfd = abfd->archive_head; |
1802 | if (current_bfd != NULL) | |
1803 | arch_info = bfd_get_arch_info (current_bfd); | |
1804 | i = 0; | |
1805 | while (current_bfd != NULL && i < orl_count) | |
f4ffd778 | 1806 | { |
330693f5 TR |
1807 | while (map[i].u.abfd == current_bfd) |
1808 | { | |
1809 | string_length = strlen (*map[i].name) + 1; | |
252b5132 | 1810 | |
330693f5 TR |
1811 | if (arch_info->bits_per_address == 64) |
1812 | { | |
1813 | sym_64++; | |
1814 | str_64 += string_length; | |
1815 | } | |
1816 | else | |
1817 | { | |
1818 | sym_32++; | |
1819 | str_32 += string_length; | |
1820 | } | |
1821 | i++; | |
1822 | } | |
1823 | current_bfd = current_bfd->next; | |
1824 | if (current_bfd != NULL) | |
1825 | arch_info = bfd_get_arch_info (current_bfd); | |
1826 | } | |
5ea1af0d | 1827 | |
330693f5 TR |
1828 | /* A quick sanity check... */ |
1829 | BFD_ASSERT (sym_64 + sym_32 == orl_count); | |
1830 | /* Explicit cast to int for compiler. */ | |
1831 | BFD_ASSERT ((int)(str_64 + str_32) == stridx); | |
1a6df346 | 1832 | |
330693f5 | 1833 | fhdr = xcoff_ardata_big (abfd); |
252b5132 | 1834 | |
330693f5 TR |
1835 | /* xcoff_write_archive_contents_big passes nextoff in symoff. */ |
1836 | READ20 (fhdr->memoff, prevoff); | |
1837 | READ20 (fhdr->symoff, nextoff); | |
252b5132 | 1838 | |
330693f5 | 1839 | BFD_ASSERT (nextoff == bfd_tell (abfd)); |
5ea1af0d | 1840 | |
cf9ab45b AM |
1841 | /* Write out the symbol table. |
1842 | Layout : | |
1843 | ||
330693f5 | 1844 | standard big archive header |
cf9ab45b AM |
1845 | 0x0000 ar_size [0x14] |
1846 | 0x0014 ar_nxtmem [0x14] | |
1847 | 0x0028 ar_prvmem [0x14] | |
1848 | 0x003C ar_date [0x0C] | |
1849 | 0x0048 ar_uid [0x0C] | |
1850 | 0x0054 ar_gid [0x0C] | |
1851 | 0x0060 ar_mod [0x0C] | |
1852 | 0x006C ar_namelen[0x04] | |
1853 | 0x0070 ar_fmag [SXCOFFARFMAG] | |
1854 | ||
1855 | Symbol table | |
1856 | 0x0072 num_syms [0x08], binary | |
1857 | 0x0078 offsets [0x08 * num_syms], binary | |
1858 | 0x0086 + 0x08 * num_syms names [??] | |
1859 | ?? pad to even bytes. | |
330693f5 TR |
1860 | */ |
1861 | ||
cf9ab45b | 1862 | if (sym_32) |
330693f5 TR |
1863 | { |
1864 | struct xcoff_ar_hdr_big *hdr; | |
f075ee0c AM |
1865 | char *symbol_table; |
1866 | char *st; | |
330693f5 TR |
1867 | file_ptr fileoff; |
1868 | ||
cf9ab45b | 1869 | bfd_vma symbol_table_size = |
330693f5 TR |
1870 | SIZEOF_AR_HDR_BIG |
1871 | + SXCOFFARFMAG | |
cf9ab45b AM |
1872 | + 8 |
1873 | + 8 * sym_32 | |
330693f5 TR |
1874 | + str_32 + (str_32 & 1); |
1875 | ||
f075ee0c | 1876 | symbol_table = bfd_zmalloc (symbol_table_size); |
330693f5 | 1877 | if (symbol_table == NULL) |
b34976b6 | 1878 | return FALSE; |
330693f5 TR |
1879 | |
1880 | hdr = (struct xcoff_ar_hdr_big *) symbol_table; | |
cf9ab45b | 1881 | |
330693f5 | 1882 | PRINT20 (hdr->size, 8 + 8 * sym_32 + str_32 + (str_32 & 1)); |
cf9ab45b | 1883 | |
330693f5 TR |
1884 | if (sym_64) |
1885 | PRINT20 (hdr->nextoff, nextoff + symbol_table_size); | |
1a6df346 | 1886 | else |
330693f5 TR |
1887 | PRINT20 (hdr->nextoff, 0); |
1888 | ||
1889 | PRINT20 (hdr->prevoff, prevoff); | |
1890 | PRINT12 (hdr->date, 0); | |
1891 | PRINT12 (hdr->uid, 0); | |
1892 | PRINT12 (hdr->gid, 0); | |
1893 | PRINT12 (hdr->mode, 0); | |
1894 | PRINT4 (hdr->namlen, 0) ; | |
1895 | ||
1896 | st = symbol_table + SIZEOF_AR_HDR_BIG; | |
1897 | memcpy (st, XCOFFARFMAG, SXCOFFARFMAG); | |
1898 | st += SXCOFFARFMAG; | |
1899 | ||
1900 | bfd_h_put_64 (abfd, sym_32, st); | |
1901 | st += 8; | |
cf9ab45b | 1902 | |
330693f5 TR |
1903 | /* loop over the 32 bit offsets */ |
1904 | current_bfd = abfd->archive_head; | |
1905 | if (current_bfd != NULL) | |
1906 | arch_info = bfd_get_arch_info (current_bfd); | |
1907 | fileoff = SIZEOF_AR_FILE_HDR_BIG; | |
1908 | i = 0; | |
1909 | while (current_bfd != NULL && i < orl_count) | |
1910 | { | |
1911 | while (map[i].u.abfd == current_bfd) | |
1912 | { | |
1913 | if (arch_info->bits_per_address == 32) | |
1914 | { | |
1915 | bfd_h_put_64 (abfd, fileoff, st); | |
1916 | st += 8; | |
1917 | } | |
1918 | i++; | |
1919 | } | |
1920 | string_length = strlen (normalize_filename (current_bfd)); | |
1921 | string_length += string_length & 1; | |
1922 | fileoff += (SIZEOF_AR_HDR_BIG | |
1923 | + string_length | |
1924 | + SXCOFFARFMAG | |
1925 | + arelt_size (current_bfd)); | |
1926 | fileoff += fileoff & 1; | |
1927 | current_bfd = current_bfd->next; | |
1928 | if (current_bfd != NULL) | |
1929 | arch_info = bfd_get_arch_info (current_bfd); | |
1930 | } | |
1a6df346 | 1931 | |
330693f5 TR |
1932 | /* loop over the 32 bit symbol names */ |
1933 | current_bfd = abfd->archive_head; | |
1934 | if (current_bfd != NULL) | |
1935 | arch_info = bfd_get_arch_info (current_bfd); | |
1936 | i = 0; | |
1937 | while (current_bfd != NULL && i < orl_count) | |
1938 | { | |
1939 | while (map[i].u.abfd == current_bfd) | |
1940 | { | |
1941 | if (arch_info->bits_per_address == 32) | |
1942 | { | |
1943 | string_length = sprintf (st, "%s", *map[i].name); | |
1944 | st += string_length + 1; | |
1945 | } | |
1946 | i++; | |
1947 | } | |
1948 | current_bfd = current_bfd->next; | |
1949 | if (current_bfd != NULL) | |
1950 | arch_info = bfd_get_arch_info (current_bfd); | |
1951 | } | |
5ea1af0d | 1952 | |
330693f5 | 1953 | bfd_bwrite (symbol_table, symbol_table_size, abfd); |
1a6df346 | 1954 | |
330693f5 | 1955 | free (symbol_table); |
5ea1af0d | 1956 | |
330693f5 TR |
1957 | prevoff = nextoff; |
1958 | nextoff = nextoff + symbol_table_size; | |
5ea1af0d | 1959 | } |
cf9ab45b | 1960 | else |
330693f5 | 1961 | PRINT20 (fhdr->symoff, 0); |
cf9ab45b AM |
1962 | |
1963 | if (sym_64) | |
330693f5 TR |
1964 | { |
1965 | struct xcoff_ar_hdr_big *hdr; | |
f075ee0c AM |
1966 | char *symbol_table; |
1967 | char *st; | |
330693f5 TR |
1968 | file_ptr fileoff; |
1969 | ||
cf9ab45b | 1970 | bfd_vma symbol_table_size = |
330693f5 TR |
1971 | SIZEOF_AR_HDR_BIG |
1972 | + SXCOFFARFMAG | |
cf9ab45b AM |
1973 | + 8 |
1974 | + 8 * sym_64 | |
330693f5 TR |
1975 | + str_64 + (str_64 & 1); |
1976 | ||
f075ee0c | 1977 | symbol_table = bfd_zmalloc (symbol_table_size); |
330693f5 | 1978 | if (symbol_table == NULL) |
b34976b6 | 1979 | return FALSE; |
330693f5 TR |
1980 | |
1981 | hdr = (struct xcoff_ar_hdr_big *) symbol_table; | |
1982 | ||
1983 | PRINT20 (hdr->size, 8 + 8 * sym_64 + str_64 + (str_64 & 1)); | |
1984 | PRINT20 (hdr->nextoff, 0); | |
1985 | PRINT20 (hdr->prevoff, prevoff); | |
1986 | PRINT12 (hdr->date, 0); | |
1987 | PRINT12 (hdr->uid, 0); | |
1988 | PRINT12 (hdr->gid, 0); | |
1989 | PRINT12 (hdr->mode, 0); | |
1990 | PRINT4 (hdr->namlen, 0); | |
1991 | ||
1992 | st = symbol_table + SIZEOF_AR_HDR_BIG; | |
1993 | memcpy (st, XCOFFARFMAG, SXCOFFARFMAG); | |
1994 | st += SXCOFFARFMAG; | |
1995 | ||
1996 | bfd_h_put_64 (abfd, sym_64, st); | |
1997 | st += 8; | |
cf9ab45b | 1998 | |
330693f5 TR |
1999 | /* loop over the 64 bit offsets */ |
2000 | current_bfd = abfd->archive_head; | |
2001 | if (current_bfd != NULL) | |
2002 | arch_info = bfd_get_arch_info (current_bfd); | |
2003 | fileoff = SIZEOF_AR_FILE_HDR_BIG; | |
2004 | i = 0; | |
2005 | while (current_bfd != NULL && i < orl_count) | |
1a6df346 | 2006 | { |
330693f5 TR |
2007 | while (map[i].u.abfd == current_bfd) |
2008 | { | |
2009 | if (arch_info->bits_per_address == 64) | |
2010 | { | |
2011 | bfd_h_put_64 (abfd, fileoff, st); | |
2012 | st += 8; | |
2013 | } | |
2014 | i++; | |
2015 | } | |
2016 | string_length = strlen (normalize_filename (current_bfd)); | |
2017 | string_length += string_length & 1; | |
2018 | fileoff += (SIZEOF_AR_HDR_BIG | |
2019 | + string_length | |
2020 | + SXCOFFARFMAG | |
2021 | + arelt_size (current_bfd)); | |
2022 | fileoff += fileoff & 1; | |
2023 | current_bfd = current_bfd->next; | |
2024 | if (current_bfd != NULL) | |
2025 | arch_info = bfd_get_arch_info (current_bfd); | |
1a6df346 | 2026 | } |
330693f5 TR |
2027 | |
2028 | /* loop over the 64 bit symbol names */ | |
2029 | current_bfd = abfd->archive_head; | |
2030 | if (current_bfd != NULL) | |
2031 | arch_info = bfd_get_arch_info (current_bfd); | |
2032 | i = 0; | |
2033 | while (current_bfd != NULL && i < orl_count) | |
1a6df346 | 2034 | { |
330693f5 TR |
2035 | while (map[i].u.abfd == current_bfd) |
2036 | { | |
2037 | if (arch_info->bits_per_address == 64) | |
2038 | { | |
2039 | string_length = sprintf (st, "%s", *map[i].name); | |
2040 | st += string_length + 1; | |
2041 | } | |
2042 | i++; | |
2043 | } | |
2044 | current_bfd = current_bfd->next; | |
2045 | if (current_bfd != NULL) | |
2046 | arch_info = bfd_get_arch_info (current_bfd); | |
1a6df346 | 2047 | } |
1a6df346 | 2048 | |
330693f5 TR |
2049 | bfd_bwrite (symbol_table, symbol_table_size, abfd); |
2050 | ||
2051 | free (symbol_table); | |
dc810e39 | 2052 | |
330693f5 TR |
2053 | PRINT20 (fhdr->symoff64, nextoff); |
2054 | } | |
cf9ab45b | 2055 | else |
330693f5 | 2056 | PRINT20 (fhdr->symoff64, 0); |
cf9ab45b | 2057 | |
b34976b6 | 2058 | return TRUE; |
1a6df346 GK |
2059 | } |
2060 | ||
b34976b6 | 2061 | bfd_boolean |
7f6d05e8 | 2062 | _bfd_xcoff_write_armap (abfd, elength, map, orl_count, stridx) |
5ea1af0d GK |
2063 | bfd *abfd; |
2064 | unsigned int elength ATTRIBUTE_UNUSED; | |
2065 | struct orl *map; | |
2066 | unsigned int orl_count; | |
2067 | int stridx; | |
2068 | { | |
2069 | if (! xcoff_big_format_p (abfd)) | |
2070 | return xcoff_write_armap_old (abfd, elength, map, orl_count, stridx); | |
2071 | else | |
2072 | return xcoff_write_armap_big (abfd, elength, map, orl_count, stridx); | |
2073 | } | |
2074 | ||
2075 | /* Write out an XCOFF archive. We always write an entire archive, | |
2076 | rather than fussing with the freelist and so forth. */ | |
2077 | ||
b34976b6 | 2078 | static bfd_boolean |
5ea1af0d GK |
2079 | xcoff_write_archive_contents_old (abfd) |
2080 | bfd *abfd; | |
2081 | { | |
2082 | struct xcoff_ar_file_hdr fhdr; | |
dc810e39 AM |
2083 | bfd_size_type count; |
2084 | bfd_size_type total_namlen; | |
5ea1af0d | 2085 | file_ptr *offsets; |
b34976b6 AM |
2086 | bfd_boolean makemap; |
2087 | bfd_boolean hasobjects; | |
9dadfa79 | 2088 | file_ptr prevoff, nextoff; |
5ea1af0d | 2089 | bfd *sub; |
dc810e39 | 2090 | size_t i; |
5ea1af0d GK |
2091 | struct xcoff_ar_hdr ahdr; |
2092 | bfd_size_type size; | |
2093 | char *p; | |
330693f5 | 2094 | char decbuf[XCOFFARMAG_ELEMENT_SIZE + 1]; |
5ea1af0d GK |
2095 | |
2096 | memset (&fhdr, 0, sizeof fhdr); | |
f05742e6 | 2097 | (void) strncpy (fhdr.magic, XCOFFARMAG, SXCOFFARMAG); |
5ea1af0d GK |
2098 | sprintf (fhdr.firstmemoff, "%d", SIZEOF_AR_FILE_HDR); |
2099 | sprintf (fhdr.freeoff, "%d", 0); | |
2100 | ||
2101 | count = 0; | |
2102 | total_namlen = 0; | |
2103 | for (sub = abfd->archive_head; sub != NULL; sub = sub->next) | |
2104 | { | |
2105 | ++count; | |
2106 | total_namlen += strlen (normalize_filename (sub)) + 1; | |
2107 | } | |
2108 | offsets = (file_ptr *) bfd_alloc (abfd, count * sizeof (file_ptr)); | |
2109 | if (offsets == NULL) | |
b34976b6 | 2110 | return FALSE; |
5ea1af0d | 2111 | |
dc810e39 | 2112 | if (bfd_seek (abfd, (file_ptr) SIZEOF_AR_FILE_HDR, SEEK_SET) != 0) |
b34976b6 | 2113 | return FALSE; |
5ea1af0d GK |
2114 | |
2115 | makemap = bfd_has_map (abfd); | |
b34976b6 | 2116 | hasobjects = FALSE; |
5ea1af0d GK |
2117 | prevoff = 0; |
2118 | nextoff = SIZEOF_AR_FILE_HDR; | |
2119 | for (sub = abfd->archive_head, i = 0; sub != NULL; sub = sub->next, i++) | |
2120 | { | |
2121 | const char *name; | |
dc810e39 | 2122 | bfd_size_type namlen; |
252b5132 RH |
2123 | struct xcoff_ar_hdr *ahdrp; |
2124 | bfd_size_type remaining; | |
2125 | ||
2126 | if (makemap && ! hasobjects) | |
2127 | { | |
2128 | if (bfd_check_format (sub, bfd_object)) | |
b34976b6 | 2129 | hasobjects = TRUE; |
252b5132 RH |
2130 | } |
2131 | ||
2132 | name = normalize_filename (sub); | |
2133 | namlen = strlen (name); | |
2134 | ||
2135 | if (sub->arelt_data != NULL) | |
2136 | ahdrp = arch_xhdr (sub); | |
2137 | else | |
2138 | ahdrp = NULL; | |
2139 | ||
2140 | if (ahdrp == NULL) | |
2141 | { | |
2142 | struct stat s; | |
2143 | ||
2144 | memset (&ahdr, 0, sizeof ahdr); | |
2145 | ahdrp = &ahdr; | |
2146 | if (stat (bfd_get_filename (sub), &s) != 0) | |
2147 | { | |
2148 | bfd_set_error (bfd_error_system_call); | |
b34976b6 | 2149 | return FALSE; |
252b5132 RH |
2150 | } |
2151 | ||
2152 | sprintf (ahdrp->size, "%ld", (long) s.st_size); | |
2153 | sprintf (ahdrp->date, "%ld", (long) s.st_mtime); | |
2154 | sprintf (ahdrp->uid, "%ld", (long) s.st_uid); | |
2155 | sprintf (ahdrp->gid, "%ld", (long) s.st_gid); | |
2156 | sprintf (ahdrp->mode, "%o", (unsigned int) s.st_mode); | |
2157 | ||
2158 | if (sub->arelt_data == NULL) | |
2159 | { | |
dc810e39 AM |
2160 | size = sizeof (struct areltdata); |
2161 | sub->arelt_data = bfd_alloc (sub, size); | |
252b5132 | 2162 | if (sub->arelt_data == NULL) |
b34976b6 | 2163 | return FALSE; |
252b5132 RH |
2164 | } |
2165 | ||
2166 | arch_eltdata (sub)->parsed_size = s.st_size; | |
2167 | } | |
2168 | ||
2169 | sprintf (ahdrp->prevoff, "%ld", (long) prevoff); | |
2170 | sprintf (ahdrp->namlen, "%ld", (long) namlen); | |
2171 | ||
2172 | /* If the length of the name is odd, we write out the null byte | |
cf9ab45b | 2173 | after the name as well. */ |
dc810e39 | 2174 | namlen = (namlen + 1) &~ (bfd_size_type) 1; |
252b5132 RH |
2175 | |
2176 | remaining = arelt_size (sub); | |
2177 | size = (SIZEOF_AR_HDR | |
2178 | + namlen | |
2179 | + SXCOFFARFMAG | |
2180 | + remaining); | |
2181 | ||
2182 | BFD_ASSERT (nextoff == bfd_tell (abfd)); | |
2183 | ||
2184 | offsets[i] = nextoff; | |
2185 | ||
2186 | prevoff = nextoff; | |
2187 | nextoff += size + (size & 1); | |
2188 | ||
2189 | sprintf (ahdrp->nextoff, "%ld", (long) nextoff); | |
2190 | ||
2191 | /* We need spaces, not null bytes, in the header. */ | |
2192 | for (p = (char *) ahdrp; p < (char *) ahdrp + SIZEOF_AR_HDR; p++) | |
2193 | if (*p == '\0') | |
2194 | *p = ' '; | |
2195 | ||
dc810e39 AM |
2196 | if ((bfd_bwrite ((PTR) ahdrp, (bfd_size_type) SIZEOF_AR_HDR, abfd) |
2197 | != SIZEOF_AR_HDR) | |
b34976b6 AM |
2198 | || bfd_bwrite ((PTR) name, namlen, abfd) != namlen |
2199 | || bfd_bwrite ((PTR) XCOFFARFMAG, (bfd_size_type) SXCOFFARFMAG, | |
2200 | abfd) != SXCOFFARFMAG) | |
2201 | return FALSE; | |
252b5132 RH |
2202 | |
2203 | if (bfd_seek (sub, (file_ptr) 0, SEEK_SET) != 0) | |
b34976b6 | 2204 | return FALSE; |
252b5132 | 2205 | |
eb1e0e80 | 2206 | if (! do_copy (abfd, sub)) |
b34976b6 | 2207 | return FALSE; |
cf9ab45b | 2208 | |
eb1e0e80 | 2209 | if (! do_pad (abfd, size & 1)) |
b34976b6 | 2210 | return FALSE; |
252b5132 RH |
2211 | } |
2212 | ||
2213 | sprintf (fhdr.lastmemoff, "%ld", (long) prevoff); | |
2214 | ||
2215 | /* Write out the member table. */ | |
2216 | ||
2217 | BFD_ASSERT (nextoff == bfd_tell (abfd)); | |
2218 | sprintf (fhdr.memoff, "%ld", (long) nextoff); | |
2219 | ||
2220 | memset (&ahdr, 0, sizeof ahdr); | |
cf9ab45b AM |
2221 | sprintf (ahdr.size, "%ld", (long) (XCOFFARMAG_ELEMENT_SIZE |
2222 | + count * XCOFFARMAG_ELEMENT_SIZE | |
2223 | + total_namlen)); | |
252b5132 RH |
2224 | sprintf (ahdr.prevoff, "%ld", (long) prevoff); |
2225 | sprintf (ahdr.date, "%d", 0); | |
2226 | sprintf (ahdr.uid, "%d", 0); | |
2227 | sprintf (ahdr.gid, "%d", 0); | |
2228 | sprintf (ahdr.mode, "%d", 0); | |
2229 | sprintf (ahdr.namlen, "%d", 0); | |
2230 | ||
2231 | size = (SIZEOF_AR_HDR | |
330693f5 TR |
2232 | + XCOFFARMAG_ELEMENT_SIZE |
2233 | + count * XCOFFARMAG_ELEMENT_SIZE | |
252b5132 RH |
2234 | + total_namlen |
2235 | + SXCOFFARFMAG); | |
2236 | ||
2237 | prevoff = nextoff; | |
2238 | nextoff += size + (size & 1); | |
2239 | ||
2240 | if (makemap && hasobjects) | |
2241 | sprintf (ahdr.nextoff, "%ld", (long) nextoff); | |
2242 | else | |
2243 | sprintf (ahdr.nextoff, "%d", 0); | |
2244 | ||
2245 | /* We need spaces, not null bytes, in the header. */ | |
2246 | for (p = (char *) &ahdr; p < (char *) &ahdr + SIZEOF_AR_HDR; p++) | |
2247 | if (*p == '\0') | |
2248 | *p = ' '; | |
2249 | ||
dc810e39 AM |
2250 | if ((bfd_bwrite ((PTR) &ahdr, (bfd_size_type) SIZEOF_AR_HDR, abfd) |
2251 | != SIZEOF_AR_HDR) | |
2252 | || (bfd_bwrite ((PTR) XCOFFARFMAG, (bfd_size_type) SXCOFFARFMAG, abfd) | |
252b5132 | 2253 | != SXCOFFARFMAG)) |
b34976b6 | 2254 | return FALSE; |
252b5132 RH |
2255 | |
2256 | sprintf (decbuf, "%-12ld", (long) count); | |
330693f5 TR |
2257 | if (bfd_bwrite ((PTR) decbuf, (bfd_size_type) XCOFFARMAG_ELEMENT_SIZE, abfd) |
2258 | != XCOFFARMAG_ELEMENT_SIZE) | |
b34976b6 | 2259 | return FALSE; |
dc810e39 | 2260 | for (i = 0; i < (size_t) count; i++) |
252b5132 RH |
2261 | { |
2262 | sprintf (decbuf, "%-12ld", (long) offsets[i]); | |
cf9ab45b | 2263 | if (bfd_bwrite ((PTR) decbuf, (bfd_size_type) XCOFFARMAG_ELEMENT_SIZE, |
330693f5 | 2264 | abfd) != XCOFFARMAG_ELEMENT_SIZE) |
b34976b6 | 2265 | return FALSE; |
252b5132 RH |
2266 | } |
2267 | for (sub = abfd->archive_head; sub != NULL; sub = sub->next) | |
2268 | { | |
2269 | const char *name; | |
dc810e39 | 2270 | bfd_size_type namlen; |
252b5132 RH |
2271 | |
2272 | name = normalize_filename (sub); | |
2273 | namlen = strlen (name); | |
dc810e39 | 2274 | if (bfd_bwrite ((PTR) name, namlen + 1, abfd) != namlen + 1) |
b34976b6 | 2275 | return FALSE; |
252b5132 | 2276 | } |
252b5132 | 2277 | |
eb1e0e80 | 2278 | if (! do_pad (abfd, size & 1)) |
b34976b6 | 2279 | return FALSE; |
252b5132 RH |
2280 | |
2281 | /* Write out the armap, if appropriate. */ | |
252b5132 RH |
2282 | if (! makemap || ! hasobjects) |
2283 | sprintf (fhdr.symoff, "%d", 0); | |
2284 | else | |
2285 | { | |
2286 | BFD_ASSERT (nextoff == bfd_tell (abfd)); | |
2287 | sprintf (fhdr.symoff, "%ld", (long) nextoff); | |
2288 | bfd_ardata (abfd)->tdata = (PTR) &fhdr; | |
2289 | if (! _bfd_compute_and_write_armap (abfd, 0)) | |
b34976b6 | 2290 | return FALSE; |
252b5132 RH |
2291 | } |
2292 | ||
2293 | /* Write out the archive file header. */ | |
2294 | ||
2295 | /* We need spaces, not null bytes, in the header. */ | |
2296 | for (p = (char *) &fhdr; p < (char *) &fhdr + SIZEOF_AR_FILE_HDR; p++) | |
2297 | if (*p == '\0') | |
2298 | *p = ' '; | |
2299 | ||
2300 | if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0 | |
dc810e39 AM |
2301 | || (bfd_bwrite ((PTR) &fhdr, (bfd_size_type) SIZEOF_AR_FILE_HDR, abfd) |
2302 | != SIZEOF_AR_FILE_HDR)) | |
b34976b6 | 2303 | return FALSE; |
252b5132 | 2304 | |
b34976b6 | 2305 | return TRUE; |
252b5132 | 2306 | } |
5ea1af0d | 2307 | |
b34976b6 | 2308 | static bfd_boolean |
5ea1af0d GK |
2309 | xcoff_write_archive_contents_big (abfd) |
2310 | bfd *abfd; | |
2311 | { | |
2312 | struct xcoff_ar_file_hdr_big fhdr; | |
dc810e39 AM |
2313 | bfd_size_type count; |
2314 | bfd_size_type total_namlen; | |
5ea1af0d | 2315 | file_ptr *offsets; |
b34976b6 AM |
2316 | bfd_boolean makemap; |
2317 | bfd_boolean hasobjects; | |
9dadfa79 | 2318 | file_ptr prevoff, nextoff; |
330693f5 | 2319 | bfd *current_bfd; |
dc810e39 | 2320 | size_t i; |
330693f5 | 2321 | struct xcoff_ar_hdr_big *hdr, ahdr; |
5ea1af0d | 2322 | bfd_size_type size; |
f075ee0c | 2323 | char *member_table, *mt; |
330693f5 | 2324 | bfd_vma member_table_size; |
5ea1af0d | 2325 | |
eb1e0e80 | 2326 | memset (&fhdr, 0, SIZEOF_AR_FILE_HDR_BIG); |
330693f5 | 2327 | memcpy (fhdr.magic, XCOFFARMAGBIG, SXCOFFARMAG); |
5ea1af0d | 2328 | |
eb1e0e80 | 2329 | if (bfd_seek (abfd, (file_ptr) SIZEOF_AR_FILE_HDR_BIG, SEEK_SET) != 0) |
b34976b6 | 2330 | return FALSE; |
cf9ab45b | 2331 | |
eb1e0e80 NC |
2332 | /* Calculate count and total_namlen. */ |
2333 | makemap = bfd_has_map (abfd); | |
b34976b6 | 2334 | hasobjects = FALSE; |
cf9ab45b AM |
2335 | for (current_bfd = abfd->archive_head, count = 0, total_namlen = 0; |
2336 | current_bfd != NULL; | |
330693f5 | 2337 | current_bfd = current_bfd->next, count++) |
eb1e0e80 NC |
2338 | { |
2339 | total_namlen += strlen (normalize_filename (current_bfd)) + 1; | |
2340 | ||
2341 | if (makemap | |
2342 | && ! hasobjects | |
2343 | && bfd_check_format (current_bfd, bfd_object)) | |
b34976b6 | 2344 | hasobjects = TRUE; |
eb1e0e80 | 2345 | } |
330693f5 TR |
2346 | |
2347 | offsets = NULL; | |
2348 | if (count) | |
5ea1af0d | 2349 | { |
330693f5 TR |
2350 | offsets = (file_ptr *) bfd_malloc (count * sizeof (file_ptr)); |
2351 | if (offsets == NULL) | |
b34976b6 | 2352 | return FALSE; |
5ea1af0d | 2353 | } |
5ea1af0d | 2354 | |
5ea1af0d GK |
2355 | prevoff = 0; |
2356 | nextoff = SIZEOF_AR_FILE_HDR_BIG; | |
cf9ab45b AM |
2357 | for (current_bfd = abfd->archive_head, i = 0; |
2358 | current_bfd != NULL; | |
330693f5 | 2359 | current_bfd = current_bfd->next, i++) |
5ea1af0d GK |
2360 | { |
2361 | const char *name; | |
dc810e39 | 2362 | bfd_size_type namlen; |
5ea1af0d GK |
2363 | struct xcoff_ar_hdr_big *ahdrp; |
2364 | bfd_size_type remaining; | |
2365 | ||
330693f5 | 2366 | name = normalize_filename (current_bfd); |
5ea1af0d GK |
2367 | namlen = strlen (name); |
2368 | ||
330693f5 TR |
2369 | if (current_bfd->arelt_data != NULL) |
2370 | ahdrp = arch_xhdr_big (current_bfd); | |
5ea1af0d GK |
2371 | else |
2372 | ahdrp = NULL; | |
2373 | ||
2374 | if (ahdrp == NULL) | |
2375 | { | |
2376 | struct stat s; | |
2377 | ||
5ea1af0d GK |
2378 | ahdrp = &ahdr; |
2379 | /* XXX This should actually be a call to stat64 (at least on | |
cf9ab45b | 2380 | 32-bit machines). |
330693f5 TR |
2381 | XXX This call will fail if the original object is not found. */ |
2382 | if (stat (bfd_get_filename (current_bfd), &s) != 0) | |
5ea1af0d GK |
2383 | { |
2384 | bfd_set_error (bfd_error_system_call); | |
b34976b6 | 2385 | return FALSE; |
5ea1af0d GK |
2386 | } |
2387 | ||
330693f5 TR |
2388 | PRINT20 (ahdrp->size, s.st_size); |
2389 | PRINT12 (ahdrp->date, s.st_mtime); | |
2390 | PRINT12 (ahdrp->uid, s.st_uid); | |
2391 | PRINT12 (ahdrp->gid, s.st_gid); | |
2392 | PRINT12_OCTAL (ahdrp->mode, s.st_mode); | |
5ea1af0d | 2393 | |
330693f5 | 2394 | if (current_bfd->arelt_data == NULL) |
5ea1af0d | 2395 | { |
dc810e39 | 2396 | size = sizeof (struct areltdata); |
330693f5 TR |
2397 | current_bfd->arelt_data = bfd_alloc (current_bfd, size); |
2398 | if (current_bfd->arelt_data == NULL) | |
b34976b6 | 2399 | return FALSE; |
5ea1af0d GK |
2400 | } |
2401 | ||
330693f5 | 2402 | arch_eltdata (current_bfd)->parsed_size = s.st_size; |
5ea1af0d GK |
2403 | } |
2404 | ||
330693f5 TR |
2405 | PRINT20 (ahdrp->prevoff, prevoff); |
2406 | PRINT4 (ahdrp->namlen, namlen); | |
5ea1af0d GK |
2407 | |
2408 | /* If the length of the name is odd, we write out the null byte | |
cf9ab45b | 2409 | after the name as well. */ |
dc810e39 | 2410 | namlen = (namlen + 1) &~ (bfd_size_type) 1; |
5ea1af0d | 2411 | |
330693f5 | 2412 | remaining = arelt_size (current_bfd); |
5ea1af0d GK |
2413 | size = (SIZEOF_AR_HDR_BIG |
2414 | + namlen | |
2415 | + SXCOFFARFMAG | |
2416 | + remaining); | |
2417 | ||
2418 | BFD_ASSERT (nextoff == bfd_tell (abfd)); | |
2419 | ||
eb1e0e80 NC |
2420 | /* Check for xcoff shared objects. |
2421 | Their text section needs to be aligned wrt the archive file position. | |
2422 | This requires extra padding before the archive header. */ | |
2423 | if (! do_shared_object_padding (abfd, current_bfd, & nextoff, | |
cf9ab45b | 2424 | SIZEOF_AR_HDR_BIG + namlen |
eb1e0e80 | 2425 | + SXCOFFARFMAG)) |
b34976b6 | 2426 | return FALSE; |
eb1e0e80 | 2427 | |
5ea1af0d GK |
2428 | offsets[i] = nextoff; |
2429 | ||
2430 | prevoff = nextoff; | |
2431 | nextoff += size + (size & 1); | |
2432 | ||
330693f5 | 2433 | PRINT20 (ahdrp->nextoff, nextoff); |
5ea1af0d | 2434 | |
dc810e39 AM |
2435 | if ((bfd_bwrite ((PTR) ahdrp, (bfd_size_type) SIZEOF_AR_HDR_BIG, abfd) |
2436 | != SIZEOF_AR_HDR_BIG) | |
2437 | || bfd_bwrite ((PTR) name, (bfd_size_type) namlen, abfd) != namlen | |
cf9ab45b | 2438 | || (bfd_bwrite ((PTR) XCOFFARFMAG, (bfd_size_type) SXCOFFARFMAG, |
330693f5 | 2439 | abfd) != SXCOFFARFMAG)) |
b34976b6 | 2440 | return FALSE; |
5ea1af0d | 2441 | |
330693f5 | 2442 | if (bfd_seek (current_bfd, (file_ptr) 0, SEEK_SET) != 0) |
b34976b6 | 2443 | return FALSE; |
5ea1af0d | 2444 | |
eb1e0e80 | 2445 | if (! do_copy (abfd, current_bfd)) |
b34976b6 | 2446 | return FALSE; |
cf9ab45b | 2447 | |
eb1e0e80 | 2448 | if (! do_pad (abfd, size & 1)) |
b34976b6 | 2449 | return FALSE; |
5ea1af0d GK |
2450 | } |
2451 | ||
eb1e0e80 NC |
2452 | if (count) |
2453 | { | |
2454 | PRINT20 (fhdr.firstmemoff, offsets[0]); | |
2455 | PRINT20 (fhdr.lastmemoff, prevoff); | |
2456 | } | |
5ea1af0d | 2457 | |
cf9ab45b AM |
2458 | /* Write out the member table. |
2459 | Layout : | |
5ea1af0d | 2460 | |
330693f5 | 2461 | standard big archive header |
cf9ab45b AM |
2462 | 0x0000 ar_size [0x14] |
2463 | 0x0014 ar_nxtmem [0x14] | |
2464 | 0x0028 ar_prvmem [0x14] | |
2465 | 0x003C ar_date [0x0C] | |
2466 | 0x0048 ar_uid [0x0C] | |
2467 | 0x0054 ar_gid [0x0C] | |
2468 | 0x0060 ar_mod [0x0C] | |
2469 | 0x006C ar_namelen[0x04] | |
2470 | 0x0070 ar_fmag [0x02] | |
2471 | ||
2472 | Member table | |
2473 | 0x0072 count [0x14] | |
2474 | 0x0086 offsets [0x14 * counts] | |
2475 | 0x0086 + 0x14 * counts names [??] | |
2476 | ?? pad to even bytes. | |
330693f5 | 2477 | */ |
5ea1af0d | 2478 | |
330693f5 | 2479 | BFD_ASSERT (nextoff == bfd_tell (abfd)); |
5ea1af0d | 2480 | |
330693f5 TR |
2481 | member_table_size = (SIZEOF_AR_HDR_BIG |
2482 | + SXCOFFARFMAG | |
2483 | + XCOFFARMAGBIG_ELEMENT_SIZE | |
2484 | + count * XCOFFARMAGBIG_ELEMENT_SIZE | |
2485 | + total_namlen); | |
5ea1af0d | 2486 | |
330693f5 | 2487 | member_table_size += member_table_size & 1; |
f075ee0c | 2488 | member_table = bfd_zmalloc (member_table_size); |
330693f5 | 2489 | if (member_table == NULL) |
b34976b6 | 2490 | return FALSE; |
5ea1af0d | 2491 | |
330693f5 | 2492 | hdr = (struct xcoff_ar_hdr_big *) member_table; |
5ea1af0d | 2493 | |
cf9ab45b AM |
2494 | PRINT20 (hdr->size, (XCOFFARMAGBIG_ELEMENT_SIZE |
2495 | + count * XCOFFARMAGBIG_ELEMENT_SIZE | |
2496 | + total_namlen + (total_namlen & 1))); | |
2497 | if (makemap && hasobjects) | |
330693f5 TR |
2498 | PRINT20 (hdr->nextoff, nextoff + member_table_size); |
2499 | else | |
2500 | PRINT20 (hdr->nextoff, 0); | |
2501 | PRINT20 (hdr->prevoff, prevoff); | |
2502 | PRINT12 (hdr->date, 0); | |
2503 | PRINT12 (hdr->uid, 0); | |
2504 | PRINT12 (hdr->gid, 0); | |
2505 | PRINT12 (hdr->mode, 0); | |
2506 | PRINT4 (hdr->namlen, 0); | |
cf9ab45b | 2507 | |
330693f5 TR |
2508 | mt = member_table + SIZEOF_AR_HDR_BIG; |
2509 | memcpy (mt, XCOFFARFMAG, SXCOFFARFMAG); | |
2510 | mt += SXCOFFARFMAG; | |
5ea1af0d | 2511 | |
330693f5 TR |
2512 | PRINT20 (mt, count); |
2513 | mt += XCOFFARMAGBIG_ELEMENT_SIZE; | |
dc810e39 | 2514 | for (i = 0; i < (size_t) count; i++) |
5ea1af0d | 2515 | { |
330693f5 TR |
2516 | PRINT20 (mt, offsets[i]); |
2517 | mt += XCOFFARMAGBIG_ELEMENT_SIZE; | |
5ea1af0d | 2518 | } |
330693f5 | 2519 | |
cf9ab45b | 2520 | if (count) |
330693f5 TR |
2521 | { |
2522 | free (offsets); | |
2523 | offsets = NULL; | |
2524 | } | |
2525 | ||
cf9ab45b | 2526 | for (current_bfd = abfd->archive_head; current_bfd != NULL; |
330693f5 | 2527 | current_bfd = current_bfd->next) |
5ea1af0d GK |
2528 | { |
2529 | const char *name; | |
2530 | size_t namlen; | |
2531 | ||
330693f5 | 2532 | name = normalize_filename (current_bfd); |
cf9ab45b | 2533 | namlen = sprintf (mt, "%s", name); |
330693f5 | 2534 | mt += namlen + 1; |
5ea1af0d | 2535 | } |
cf9ab45b | 2536 | |
330693f5 | 2537 | if (bfd_bwrite (member_table, member_table_size, abfd) != member_table_size) |
b34976b6 | 2538 | return FALSE; |
5ea1af0d | 2539 | |
330693f5 | 2540 | free (member_table); |
330693f5 TR |
2541 | |
2542 | PRINT20 (fhdr.memoff, nextoff); | |
2543 | ||
2544 | prevoff = nextoff; | |
2545 | nextoff += member_table_size; | |
5ea1af0d GK |
2546 | |
2547 | /* Write out the armap, if appropriate. */ | |
2548 | ||
cf9ab45b | 2549 | if (! makemap || ! hasobjects) |
330693f5 | 2550 | PRINT20 (fhdr.symoff, 0); |
5ea1af0d GK |
2551 | else |
2552 | { | |
2553 | BFD_ASSERT (nextoff == bfd_tell (abfd)); | |
330693f5 TR |
2554 | |
2555 | /* Save nextoff in fhdr.symoff so the armap routine can use it. */ | |
2556 | PRINT20 (fhdr.symoff, nextoff); | |
cf9ab45b | 2557 | |
5ea1af0d GK |
2558 | bfd_ardata (abfd)->tdata = (PTR) &fhdr; |
2559 | if (! _bfd_compute_and_write_armap (abfd, 0)) | |
b34976b6 | 2560 | return FALSE; |
5ea1af0d GK |
2561 | } |
2562 | ||
2563 | /* Write out the archive file header. */ | |
2564 | ||
5ea1af0d | 2565 | if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0 |
cf9ab45b | 2566 | || (bfd_bwrite ((PTR) &fhdr, (bfd_size_type) SIZEOF_AR_FILE_HDR_BIG, |
330693f5 | 2567 | abfd) != SIZEOF_AR_FILE_HDR_BIG)) |
b34976b6 | 2568 | return FALSE; |
cf9ab45b | 2569 | |
b34976b6 | 2570 | return TRUE; |
5ea1af0d GK |
2571 | } |
2572 | ||
b34976b6 | 2573 | bfd_boolean |
7f6d05e8 | 2574 | _bfd_xcoff_write_archive_contents (abfd) |
5ea1af0d GK |
2575 | bfd *abfd; |
2576 | { | |
2577 | if (! xcoff_big_format_p (abfd)) | |
2578 | return xcoff_write_archive_contents_old (abfd); | |
2579 | else | |
2580 | return xcoff_write_archive_contents_big (abfd); | |
2581 | } | |
252b5132 RH |
2582 | \f |
2583 | /* We can't use the usual coff_sizeof_headers routine, because AIX | |
2584 | always uses an a.out header. */ | |
2585 | ||
7f6d05e8 | 2586 | int |
a6b96beb AM |
2587 | _bfd_xcoff_sizeof_headers (bfd *abfd, |
2588 | struct bfd_link_info *info ATTRIBUTE_UNUSED) | |
252b5132 RH |
2589 | { |
2590 | int size; | |
2591 | ||
2592 | size = FILHSZ; | |
2593 | if (xcoff_data (abfd)->full_aouthdr) | |
2594 | size += AOUTSZ; | |
2595 | else | |
2596 | size += SMALL_AOUTSZ; | |
2597 | size += abfd->section_count * SCNHSZ; | |
2598 | return size; | |
2599 | } | |
beb1bf64 TR |
2600 | \f |
2601 | /* Routines to swap information in the XCOFF .loader section. If we | |
2602 | ever need to write an XCOFF loader, this stuff will need to be | |
2603 | moved to another file shared by the linker (which XCOFF calls the | |
2604 | ``binder'') and the loader. */ | |
2605 | ||
2606 | /* Swap in the ldhdr structure. */ | |
2607 | ||
2608 | static void | |
814fa6ab | 2609 | xcoff_swap_ldhdr_in (abfd, s, dst) |
beb1bf64 | 2610 | bfd *abfd; |
814fa6ab | 2611 | const PTR s; |
beb1bf64 TR |
2612 | struct internal_ldhdr *dst; |
2613 | { | |
814fa6ab AM |
2614 | const struct external_ldhdr *src = (const struct external_ldhdr *) s; |
2615 | ||
beb1bf64 TR |
2616 | dst->l_version = bfd_get_32 (abfd, src->l_version); |
2617 | dst->l_nsyms = bfd_get_32 (abfd, src->l_nsyms); | |
2618 | dst->l_nreloc = bfd_get_32 (abfd, src->l_nreloc); | |
2619 | dst->l_istlen = bfd_get_32 (abfd, src->l_istlen); | |
2620 | dst->l_nimpid = bfd_get_32 (abfd, src->l_nimpid); | |
2621 | dst->l_impoff = bfd_get_32 (abfd, src->l_impoff); | |
2622 | dst->l_stlen = bfd_get_32 (abfd, src->l_stlen); | |
2623 | dst->l_stoff = bfd_get_32 (abfd, src->l_stoff); | |
2624 | } | |
2625 | ||
2626 | /* Swap out the ldhdr structure. */ | |
2627 | ||
2628 | static void | |
814fa6ab | 2629 | xcoff_swap_ldhdr_out (abfd, src, d) |
beb1bf64 TR |
2630 | bfd *abfd; |
2631 | const struct internal_ldhdr *src; | |
814fa6ab | 2632 | PTR d; |
beb1bf64 | 2633 | { |
814fa6ab AM |
2634 | struct external_ldhdr *dst = (struct external_ldhdr *) d; |
2635 | ||
dc810e39 | 2636 | bfd_put_32 (abfd, (bfd_vma) src->l_version, dst->l_version); |
beb1bf64 TR |
2637 | bfd_put_32 (abfd, src->l_nsyms, dst->l_nsyms); |
2638 | bfd_put_32 (abfd, src->l_nreloc, dst->l_nreloc); | |
2639 | bfd_put_32 (abfd, src->l_istlen, dst->l_istlen); | |
2640 | bfd_put_32 (abfd, src->l_nimpid, dst->l_nimpid); | |
2641 | bfd_put_32 (abfd, src->l_impoff, dst->l_impoff); | |
2642 | bfd_put_32 (abfd, src->l_stlen, dst->l_stlen); | |
2643 | bfd_put_32 (abfd, src->l_stoff, dst->l_stoff); | |
2644 | } | |
2645 | ||
2646 | /* Swap in the ldsym structure. */ | |
2647 | ||
2648 | static void | |
814fa6ab | 2649 | xcoff_swap_ldsym_in (abfd, s, dst) |
beb1bf64 | 2650 | bfd *abfd; |
814fa6ab | 2651 | const PTR s; |
beb1bf64 TR |
2652 | struct internal_ldsym *dst; |
2653 | { | |
814fa6ab AM |
2654 | const struct external_ldsym *src = (const struct external_ldsym *) s; |
2655 | ||
beb1bf64 TR |
2656 | if (bfd_get_32 (abfd, src->_l._l_l._l_zeroes) != 0) { |
2657 | memcpy (dst->_l._l_name, src->_l._l_name, SYMNMLEN); | |
2658 | } else { | |
2659 | dst->_l._l_l._l_zeroes = 0; | |
2660 | dst->_l._l_l._l_offset = bfd_get_32 (abfd, src->_l._l_l._l_offset); | |
2661 | } | |
2662 | dst->l_value = bfd_get_32 (abfd, src->l_value); | |
2663 | dst->l_scnum = bfd_get_16 (abfd, src->l_scnum); | |
2664 | dst->l_smtype = bfd_get_8 (abfd, src->l_smtype); | |
2665 | dst->l_smclas = bfd_get_8 (abfd, src->l_smclas); | |
2666 | dst->l_ifile = bfd_get_32 (abfd, src->l_ifile); | |
2667 | dst->l_parm = bfd_get_32 (abfd, src->l_parm); | |
2668 | } | |
2669 | ||
2670 | /* Swap out the ldsym structure. */ | |
2671 | ||
2672 | static void | |
814fa6ab | 2673 | xcoff_swap_ldsym_out (abfd, src, d) |
beb1bf64 TR |
2674 | bfd *abfd; |
2675 | const struct internal_ldsym *src; | |
814fa6ab | 2676 | PTR d; |
beb1bf64 | 2677 | { |
814fa6ab | 2678 | struct external_ldsym *dst = (struct external_ldsym *) d; |
beb1bf64 TR |
2679 | |
2680 | if (src->_l._l_l._l_zeroes != 0) | |
2681 | memcpy (dst->_l._l_name, src->_l._l_name, SYMNMLEN); | |
2682 | else | |
2683 | { | |
dc810e39 AM |
2684 | bfd_put_32 (abfd, (bfd_vma) 0, dst->_l._l_l._l_zeroes); |
2685 | bfd_put_32 (abfd, (bfd_vma) src->_l._l_l._l_offset, | |
2686 | dst->_l._l_l._l_offset); | |
beb1bf64 TR |
2687 | } |
2688 | bfd_put_32 (abfd, src->l_value, dst->l_value); | |
dc810e39 | 2689 | bfd_put_16 (abfd, (bfd_vma) src->l_scnum, dst->l_scnum); |
beb1bf64 TR |
2690 | bfd_put_8 (abfd, src->l_smtype, dst->l_smtype); |
2691 | bfd_put_8 (abfd, src->l_smclas, dst->l_smclas); | |
2692 | bfd_put_32 (abfd, src->l_ifile, dst->l_ifile); | |
2693 | bfd_put_32 (abfd, src->l_parm, dst->l_parm); | |
2694 | } | |
2695 | ||
59862849 TR |
2696 | static void |
2697 | xcoff_swap_reloc_in (abfd, s, d) | |
2698 | bfd *abfd; | |
2699 | PTR s; | |
2700 | PTR d; | |
2701 | { | |
2702 | struct external_reloc *src = (struct external_reloc *) s; | |
2703 | struct internal_reloc *dst = (struct internal_reloc *) d; | |
2704 | ||
2705 | memset (dst, 0, sizeof (struct internal_reloc)); | |
2706 | ||
2707 | dst->r_vaddr = bfd_get_32 (abfd, src->r_vaddr); | |
2708 | dst->r_symndx = bfd_get_32 (abfd, src->r_symndx); | |
2709 | dst->r_size = bfd_get_8 (abfd, src->r_size); | |
2710 | dst->r_type = bfd_get_8 (abfd, src->r_type); | |
2711 | } | |
2712 | ||
2713 | static unsigned int | |
2714 | xcoff_swap_reloc_out (abfd, s, d) | |
2715 | bfd *abfd; | |
2716 | PTR s; | |
2717 | PTR d; | |
2718 | { | |
2719 | struct internal_reloc *src = (struct internal_reloc *) s; | |
2720 | struct external_reloc *dst = (struct external_reloc *) d; | |
2721 | ||
2722 | bfd_put_32 (abfd, src->r_vaddr, dst->r_vaddr); | |
2723 | bfd_put_32 (abfd, src->r_symndx, dst->r_symndx); | |
2724 | bfd_put_8 (abfd, src->r_type, dst->r_type); | |
2725 | bfd_put_8 (abfd, src->r_size, dst->r_size); | |
2726 | ||
2727 | return bfd_coff_relsz (abfd); | |
2728 | } | |
2729 | ||
beb1bf64 TR |
2730 | /* Swap in the ldrel structure. */ |
2731 | ||
2732 | static void | |
814fa6ab | 2733 | xcoff_swap_ldrel_in (abfd, s, dst) |
beb1bf64 | 2734 | bfd *abfd; |
814fa6ab | 2735 | const PTR s; |
beb1bf64 TR |
2736 | struct internal_ldrel *dst; |
2737 | { | |
814fa6ab AM |
2738 | const struct external_ldrel *src = (const struct external_ldrel *) s; |
2739 | ||
beb1bf64 TR |
2740 | dst->l_vaddr = bfd_get_32 (abfd, src->l_vaddr); |
2741 | dst->l_symndx = bfd_get_32 (abfd, src->l_symndx); | |
2742 | dst->l_rtype = bfd_get_16 (abfd, src->l_rtype); | |
2743 | dst->l_rsecnm = bfd_get_16 (abfd, src->l_rsecnm); | |
2744 | } | |
2745 | ||
2746 | /* Swap out the ldrel structure. */ | |
2747 | ||
2748 | static void | |
814fa6ab | 2749 | xcoff_swap_ldrel_out (abfd, src, d) |
beb1bf64 TR |
2750 | bfd *abfd; |
2751 | const struct internal_ldrel *src; | |
814fa6ab | 2752 | PTR d; |
beb1bf64 | 2753 | { |
814fa6ab AM |
2754 | struct external_ldrel *dst = (struct external_ldrel *) d; |
2755 | ||
beb1bf64 TR |
2756 | bfd_put_32 (abfd, src->l_vaddr, dst->l_vaddr); |
2757 | bfd_put_32 (abfd, src->l_symndx, dst->l_symndx); | |
dc810e39 AM |
2758 | bfd_put_16 (abfd, (bfd_vma) src->l_rtype, dst->l_rtype); |
2759 | bfd_put_16 (abfd, (bfd_vma) src->l_rsecnm, dst->l_rsecnm); | |
beb1bf64 TR |
2760 | } |
2761 | \f | |
2762 | ||
b34976b6 | 2763 | bfd_boolean |
cf9ab45b | 2764 | xcoff_reloc_type_noop (input_bfd, input_section, output_bfd, rel, sym, howto, |
dbe341c6 TR |
2765 | val, addend, relocation, contents) |
2766 | bfd *input_bfd ATTRIBUTE_UNUSED; | |
2767 | asection *input_section ATTRIBUTE_UNUSED; | |
2768 | bfd *output_bfd ATTRIBUTE_UNUSED; | |
2769 | struct internal_reloc *rel ATTRIBUTE_UNUSED; | |
2770 | struct internal_syment *sym ATTRIBUTE_UNUSED; | |
2771 | struct reloc_howto_struct *howto ATTRIBUTE_UNUSED; | |
2772 | bfd_vma val ATTRIBUTE_UNUSED; | |
2773 | bfd_vma addend ATTRIBUTE_UNUSED; | |
2774 | bfd_vma *relocation ATTRIBUTE_UNUSED; | |
2775 | bfd_byte *contents ATTRIBUTE_UNUSED; | |
2776 | { | |
b34976b6 | 2777 | return TRUE; |
dbe341c6 TR |
2778 | } |
2779 | ||
b34976b6 | 2780 | bfd_boolean |
cf9ab45b | 2781 | xcoff_reloc_type_fail (input_bfd, input_section, output_bfd, rel, sym, howto, |
dbe341c6 TR |
2782 | val, addend, relocation, contents) |
2783 | bfd *input_bfd; | |
2784 | asection *input_section ATTRIBUTE_UNUSED; | |
2785 | bfd *output_bfd ATTRIBUTE_UNUSED; | |
2786 | struct internal_reloc *rel; | |
2787 | struct internal_syment *sym ATTRIBUTE_UNUSED; | |
2788 | struct reloc_howto_struct *howto ATTRIBUTE_UNUSED; | |
2789 | bfd_vma val ATTRIBUTE_UNUSED; | |
2790 | bfd_vma addend ATTRIBUTE_UNUSED; | |
2791 | bfd_vma *relocation ATTRIBUTE_UNUSED; | |
2792 | bfd_byte *contents ATTRIBUTE_UNUSED; | |
2793 | { | |
2794 | (*_bfd_error_handler) | |
2795 | (_("%s: unsupported relocation type 0x%02x"), | |
2796 | bfd_get_filename (input_bfd), (unsigned int) rel->r_type); | |
2797 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 2798 | return FALSE; |
dbe341c6 TR |
2799 | } |
2800 | ||
b34976b6 | 2801 | bfd_boolean |
cf9ab45b | 2802 | xcoff_reloc_type_pos (input_bfd, input_section, output_bfd, rel, sym, howto, |
dbe341c6 TR |
2803 | val, addend, relocation, contents) |
2804 | bfd *input_bfd ATTRIBUTE_UNUSED; | |
2805 | asection *input_section ATTRIBUTE_UNUSED; | |
2806 | bfd *output_bfd ATTRIBUTE_UNUSED; | |
2807 | struct internal_reloc *rel ATTRIBUTE_UNUSED; | |
2808 | struct internal_syment *sym ATTRIBUTE_UNUSED; | |
2809 | struct reloc_howto_struct *howto ATTRIBUTE_UNUSED; | |
2810 | bfd_vma val; | |
2811 | bfd_vma addend; | |
2812 | bfd_vma *relocation; | |
2813 | bfd_byte *contents ATTRIBUTE_UNUSED; | |
2814 | { | |
2815 | *relocation = val + addend; | |
b34976b6 | 2816 | return TRUE; |
dbe341c6 TR |
2817 | } |
2818 | ||
b34976b6 | 2819 | bfd_boolean |
cf9ab45b | 2820 | xcoff_reloc_type_neg (input_bfd, input_section, output_bfd, rel, sym, howto, |
dbe341c6 TR |
2821 | val, addend, relocation, contents) |
2822 | bfd *input_bfd ATTRIBUTE_UNUSED; | |
2823 | asection *input_section ATTRIBUTE_UNUSED; | |
2824 | bfd *output_bfd ATTRIBUTE_UNUSED; | |
2825 | struct internal_reloc *rel ATTRIBUTE_UNUSED; | |
2826 | struct internal_syment *sym ATTRIBUTE_UNUSED; | |
2827 | struct reloc_howto_struct *howto ATTRIBUTE_UNUSED; | |
2828 | bfd_vma val; | |
2829 | bfd_vma addend; | |
2830 | bfd_vma *relocation; | |
2831 | bfd_byte *contents ATTRIBUTE_UNUSED; | |
2832 | { | |
2833 | *relocation = addend - val; | |
b34976b6 | 2834 | return TRUE; |
dbe341c6 TR |
2835 | } |
2836 | ||
b34976b6 | 2837 | bfd_boolean |
cf9ab45b | 2838 | xcoff_reloc_type_rel (input_bfd, input_section, output_bfd, rel, sym, howto, |
dbe341c6 TR |
2839 | val, addend, relocation, contents) |
2840 | bfd *input_bfd ATTRIBUTE_UNUSED; | |
2841 | asection *input_section; | |
2842 | bfd *output_bfd ATTRIBUTE_UNUSED; | |
2843 | struct internal_reloc *rel ATTRIBUTE_UNUSED; | |
2844 | struct internal_syment *sym ATTRIBUTE_UNUSED; | |
2845 | struct reloc_howto_struct *howto; | |
2846 | bfd_vma val; | |
2847 | bfd_vma addend; | |
2848 | bfd_vma *relocation; | |
2849 | bfd_byte *contents ATTRIBUTE_UNUSED; | |
2850 | { | |
b34976b6 | 2851 | howto->pc_relative = TRUE; |
dbe341c6 TR |
2852 | |
2853 | /* A PC relative reloc includes the section address. */ | |
2854 | addend += input_section->vma; | |
2855 | ||
2856 | *relocation = val + addend; | |
cf9ab45b AM |
2857 | *relocation -= (input_section->output_section->vma |
2858 | + input_section->output_offset); | |
b34976b6 | 2859 | return TRUE; |
dbe341c6 | 2860 | } |
f1f0d9ab | 2861 | |
b34976b6 | 2862 | bfd_boolean |
cf9ab45b | 2863 | xcoff_reloc_type_toc (input_bfd, input_section, output_bfd, rel, sym, howto, |
dbe341c6 TR |
2864 | val, addend, relocation, contents) |
2865 | bfd *input_bfd; | |
2866 | asection *input_section ATTRIBUTE_UNUSED; | |
2867 | bfd *output_bfd; | |
2868 | struct internal_reloc *rel; | |
2869 | struct internal_syment *sym; | |
2870 | struct reloc_howto_struct *howto ATTRIBUTE_UNUSED; | |
2871 | bfd_vma val; | |
2872 | bfd_vma addend ATTRIBUTE_UNUSED; | |
2873 | bfd_vma *relocation; | |
2874 | bfd_byte *contents ATTRIBUTE_UNUSED; | |
2875 | { | |
2876 | struct xcoff_link_hash_entry *h; | |
2877 | ||
cf9ab45b | 2878 | if (0 > rel->r_symndx) |
b34976b6 | 2879 | return FALSE; |
dbe341c6 TR |
2880 | |
2881 | h = obj_xcoff_sym_hashes (input_bfd)[rel->r_symndx]; | |
2882 | ||
2883 | if (h != NULL && h->smclas != XMC_TD) | |
2884 | { | |
2885 | if (h->toc_section == NULL) | |
2886 | { | |
2887 | (*_bfd_error_handler) | |
2888 | (_("%s: TOC reloc at 0x%x to symbol `%s' with no TOC entry"), | |
2889 | bfd_get_filename (input_bfd), rel->r_vaddr, | |
2890 | h->root.root.string); | |
2891 | bfd_set_error (bfd_error_bad_value); | |
b34976b6 | 2892 | return FALSE; |
dbe341c6 | 2893 | } |
cf9ab45b | 2894 | |
dbe341c6 TR |
2895 | BFD_ASSERT ((h->flags & XCOFF_SET_TOC) == 0); |
2896 | val = (h->toc_section->output_section->vma | |
2897 | + h->toc_section->output_offset); | |
2898 | } | |
cf9ab45b AM |
2899 | |
2900 | *relocation = ((val - xcoff_data (output_bfd)->toc) | |
2901 | - (sym->n_value - xcoff_data (input_bfd)->toc)); | |
b34976b6 | 2902 | return TRUE; |
dbe341c6 | 2903 | } |
f1f0d9ab | 2904 | |
b34976b6 | 2905 | bfd_boolean |
cf9ab45b | 2906 | xcoff_reloc_type_ba (input_bfd, input_section, output_bfd, rel, sym, howto, |
dbe341c6 TR |
2907 | val, addend, relocation, contents) |
2908 | bfd *input_bfd ATTRIBUTE_UNUSED; | |
2909 | asection *input_section ATTRIBUTE_UNUSED; | |
2910 | bfd *output_bfd ATTRIBUTE_UNUSED; | |
2911 | struct internal_reloc *rel ATTRIBUTE_UNUSED; | |
2912 | struct internal_syment *sym ATTRIBUTE_UNUSED; | |
2913 | struct reloc_howto_struct *howto; | |
2914 | bfd_vma val; | |
2915 | bfd_vma addend; | |
2916 | bfd_vma *relocation; | |
2917 | bfd_byte *contents ATTRIBUTE_UNUSED; | |
2918 | { | |
a78eab4e AM |
2919 | howto->src_mask &= ~3; |
2920 | howto->dst_mask = howto->src_mask; | |
dbe341c6 TR |
2921 | |
2922 | *relocation = val + addend; | |
2923 | ||
b34976b6 | 2924 | return TRUE; |
dbe341c6 TR |
2925 | } |
2926 | ||
b34976b6 | 2927 | static bfd_boolean |
cf9ab45b | 2928 | xcoff_reloc_type_br (input_bfd, input_section, output_bfd, rel, sym, howto, |
dbe341c6 TR |
2929 | val, addend, relocation, contents) |
2930 | bfd *input_bfd; | |
2931 | asection *input_section; | |
2932 | bfd *output_bfd ATTRIBUTE_UNUSED; | |
2933 | struct internal_reloc *rel; | |
2934 | struct internal_syment *sym ATTRIBUTE_UNUSED; | |
2935 | struct reloc_howto_struct *howto; | |
2936 | bfd_vma val; | |
2937 | bfd_vma addend; | |
2938 | bfd_vma *relocation; | |
2939 | bfd_byte *contents; | |
2940 | { | |
2941 | struct xcoff_link_hash_entry *h; | |
2942 | ||
cf9ab45b | 2943 | if (0 > rel->r_symndx) |
b34976b6 | 2944 | return FALSE; |
dbe341c6 TR |
2945 | |
2946 | h = obj_xcoff_sym_hashes (input_bfd)[rel->r_symndx]; | |
2947 | ||
2948 | /* If we see an R_BR or R_RBR reloc which is jumping to global | |
2949 | linkage code, and it is followed by an appropriate cror nop | |
2950 | instruction, we replace the cror with lwz r2,20(r1). This | |
2951 | restores the TOC after the glink code. Contrariwise, if the | |
2952 | call is followed by a lwz r2,20(r1), but the call is not | |
2953 | going to global linkage code, we can replace the load with a | |
2954 | cror. */ | |
cf9ab45b AM |
2955 | if (NULL != h |
2956 | && bfd_link_hash_defined == h->root.type | |
eea6121a | 2957 | && rel->r_vaddr - input_section->vma + 8 <= input_section->size) |
dbe341c6 TR |
2958 | { |
2959 | bfd_byte *pnext; | |
2960 | unsigned long next; | |
cf9ab45b | 2961 | |
dbe341c6 TR |
2962 | pnext = contents + (rel->r_vaddr - input_section->vma) + 4; |
2963 | next = bfd_get_32 (input_bfd, pnext); | |
cf9ab45b | 2964 | |
dbe341c6 TR |
2965 | /* The _ptrgl function is magic. It is used by the AIX |
2966 | compiler to call a function through a pointer. */ | |
2967 | if (h->smclas == XMC_GL || strcmp (h->root.root.string, "._ptrgl") == 0) | |
2968 | { | |
cf9ab45b AM |
2969 | if (next == 0x4def7b82 /* cror 15,15,15 */ |
2970 | || next == 0x4ffffb82 /* cror 31,31,31 */ | |
2971 | || next == 0x60000000) /* ori r0,r0,0 */ | |
2972 | bfd_put_32 (input_bfd, 0x80410014, pnext); /* lwz r1,20(r1) */ | |
2973 | ||
2974 | } | |
2975 | else | |
2976 | { | |
2977 | if (next == 0x80410014) /* lwz r1,20(r1) */ | |
2978 | bfd_put_32 (input_bfd, 0x60000000, pnext); /* ori r0,r0,0 */ | |
2979 | } | |
2980 | } | |
2981 | else if (NULL != h && bfd_link_hash_undefined == h->root.type) | |
dbe341c6 TR |
2982 | { |
2983 | /* Normally, this relocation is against a defined symbol. In the | |
2984 | case where this is a partial link and the output section offset | |
cf9ab45b | 2985 | is greater than 2^25, the linker will return an invalid error |
dbe341c6 | 2986 | message that the relocation has been truncated. Yes it has been |
cf9ab45b | 2987 | truncated but no it not important. For this case, disable the |
dbe341c6 | 2988 | overflow checking. */ |
cf9ab45b | 2989 | |
dbe341c6 TR |
2990 | howto->complain_on_overflow = complain_overflow_dont; |
2991 | } | |
cf9ab45b | 2992 | |
b34976b6 | 2993 | howto->pc_relative = TRUE; |
a78eab4e AM |
2994 | howto->src_mask &= ~3; |
2995 | howto->dst_mask = howto->src_mask; | |
dbe341c6 TR |
2996 | |
2997 | /* A PC relative reloc includes the section address. */ | |
2998 | addend += input_section->vma; | |
cf9ab45b | 2999 | |
dbe341c6 | 3000 | *relocation = val + addend; |
cf9ab45b AM |
3001 | *relocation -= (input_section->output_section->vma |
3002 | + input_section->output_offset); | |
b34976b6 | 3003 | return TRUE; |
dbe341c6 TR |
3004 | } |
3005 | ||
b34976b6 | 3006 | bfd_boolean |
cf9ab45b | 3007 | xcoff_reloc_type_crel (input_bfd, input_section, output_bfd, rel, sym, howto, |
dbe341c6 TR |
3008 | val, addend, relocation, contents) |
3009 | bfd *input_bfd ATTRIBUTE_UNUSED; | |
3010 | asection *input_section; | |
3011 | bfd *output_bfd ATTRIBUTE_UNUSED; | |
3012 | struct internal_reloc *rel ATTRIBUTE_UNUSED; | |
3013 | struct internal_syment *sym ATTRIBUTE_UNUSED; | |
3014 | struct reloc_howto_struct *howto; | |
3015 | bfd_vma val ATTRIBUTE_UNUSED; | |
3016 | bfd_vma addend; | |
3017 | bfd_vma *relocation; | |
3018 | bfd_byte *contents ATTRIBUTE_UNUSED; | |
3019 | { | |
b34976b6 | 3020 | howto->pc_relative = TRUE; |
a78eab4e AM |
3021 | howto->src_mask &= ~3; |
3022 | howto->dst_mask = howto->src_mask; | |
dbe341c6 TR |
3023 | |
3024 | /* A PC relative reloc includes the section address. */ | |
3025 | addend += input_section->vma; | |
3026 | ||
3027 | *relocation = val + addend; | |
cf9ab45b AM |
3028 | *relocation -= (input_section->output_section->vma |
3029 | + input_section->output_offset); | |
b34976b6 | 3030 | return TRUE; |
dbe341c6 TR |
3031 | } |
3032 | ||
b34976b6 | 3033 | static bfd_boolean |
cf9ab45b | 3034 | xcoff_complain_overflow_dont_func (input_bfd, val, relocation, howto) |
dbe341c6 TR |
3035 | bfd *input_bfd ATTRIBUTE_UNUSED; |
3036 | bfd_vma val ATTRIBUTE_UNUSED; | |
3037 | bfd_vma relocation ATTRIBUTE_UNUSED; | |
3038 | struct reloc_howto_struct *howto ATTRIBUTE_UNUSED; | |
3039 | { | |
b34976b6 | 3040 | return FALSE; |
dbe341c6 TR |
3041 | } |
3042 | ||
b34976b6 | 3043 | static bfd_boolean |
cf9ab45b | 3044 | xcoff_complain_overflow_bitfield_func (input_bfd, val, relocation, howto) |
dbe341c6 TR |
3045 | bfd *input_bfd; |
3046 | bfd_vma val; | |
3047 | bfd_vma relocation; | |
cf9ab45b | 3048 | struct reloc_howto_struct *howto; |
dbe341c6 TR |
3049 | { |
3050 | bfd_vma addrmask, fieldmask, signmask, ss; | |
3051 | bfd_vma a, b, sum; | |
cf9ab45b | 3052 | |
dbe341c6 TR |
3053 | /* Get the values to be added together. For signed and unsigned |
3054 | relocations, we assume that all values should be truncated to | |
3055 | the size of an address. For bitfields, all the bits matter. | |
3056 | See also bfd_check_overflow. */ | |
3057 | fieldmask = N_ONES (howto->bitsize); | |
3058 | addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask; | |
3059 | a = relocation; | |
3060 | b = val & howto->src_mask; | |
3061 | ||
3062 | /* Much like unsigned, except no trimming with addrmask. In | |
3063 | addition, the sum overflows if there is a carry out of | |
3064 | the bfd_vma, i.e., the sum is less than either input | |
3065 | operand. */ | |
3066 | a >>= howto->rightshift; | |
3067 | b >>= howto->bitpos; | |
cf9ab45b | 3068 | |
dbe341c6 TR |
3069 | /* Bitfields are sometimes used for signed numbers; for |
3070 | example, a 13-bit field sometimes represents values in | |
3071 | 0..8191 and sometimes represents values in -4096..4095. | |
3072 | If the field is signed and a is -4095 (0x1001) and b is | |
3073 | -1 (0x1fff), the sum is -4096 (0x1000), but (0x1001 + | |
3074 | 0x1fff is 0x3000). It's not clear how to handle this | |
3075 | everywhere, since there is not way to know how many bits | |
3076 | are significant in the relocation, but the original code | |
3077 | assumed that it was fully sign extended, and we will keep | |
3078 | that assumption. */ | |
3079 | signmask = (fieldmask >> 1) + 1; | |
cf9ab45b | 3080 | |
dbe341c6 TR |
3081 | if ((a & ~ fieldmask) != 0) |
3082 | { | |
3083 | /* Some bits out of the field are set. This might not | |
3084 | be a problem: if this is a signed bitfield, it is OK | |
3085 | iff all the high bits are set, including the sign | |
3086 | bit. We'll try setting all but the most significant | |
3087 | bit in the original relocation value: if this is all | |
3088 | ones, we are OK, assuming a signed bitfield. */ | |
3089 | ss = (signmask << howto->rightshift) - 1; | |
3090 | if ((ss | relocation) != ~ (bfd_vma) 0) | |
b34976b6 | 3091 | return TRUE; |
dbe341c6 TR |
3092 | a &= fieldmask; |
3093 | } | |
cf9ab45b | 3094 | |
dbe341c6 | 3095 | /* We just assume (b & ~ fieldmask) == 0. */ |
cf9ab45b | 3096 | |
dbe341c6 TR |
3097 | /* We explicitly permit wrap around if this relocation |
3098 | covers the high bit of an address. The Linux kernel | |
3099 | relies on it, and it is the only way to write assembler | |
3100 | code which can run when loaded at a location 0x80000000 | |
3101 | away from the location at which it is linked. */ | |
3102 | if (howto->bitsize + howto->rightshift | |
3103 | == bfd_arch_bits_per_address (input_bfd)) | |
b34976b6 | 3104 | return FALSE; |
cf9ab45b | 3105 | |
dbe341c6 TR |
3106 | sum = a + b; |
3107 | if (sum < a || (sum & ~ fieldmask) != 0) | |
3108 | { | |
3109 | /* There was a carry out, or the field overflow. Test | |
3110 | for signed operands again. Here is the overflow test | |
3111 | is as for complain_overflow_signed. */ | |
3112 | if (((~ (a ^ b)) & (a ^ sum)) & signmask) | |
b34976b6 | 3113 | return TRUE; |
dbe341c6 | 3114 | } |
cf9ab45b | 3115 | |
b34976b6 | 3116 | return FALSE; |
dbe341c6 TR |
3117 | } |
3118 | ||
b34976b6 | 3119 | static bfd_boolean |
cf9ab45b | 3120 | xcoff_complain_overflow_signed_func (input_bfd, val, relocation, howto) |
dbe341c6 TR |
3121 | bfd *input_bfd; |
3122 | bfd_vma val; | |
3123 | bfd_vma relocation; | |
3124 | struct reloc_howto_struct *howto; | |
3125 | { | |
3126 | bfd_vma addrmask, fieldmask, signmask, ss; | |
3127 | bfd_vma a, b, sum; | |
cf9ab45b | 3128 | |
dbe341c6 TR |
3129 | /* Get the values to be added together. For signed and unsigned |
3130 | relocations, we assume that all values should be truncated to | |
3131 | the size of an address. For bitfields, all the bits matter. | |
3132 | See also bfd_check_overflow. */ | |
3133 | fieldmask = N_ONES (howto->bitsize); | |
3134 | addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask; | |
3135 | a = relocation; | |
3136 | b = val & howto->src_mask; | |
3137 | ||
3138 | a = (a & addrmask) >> howto->rightshift; | |
cf9ab45b | 3139 | |
dbe341c6 TR |
3140 | /* If any sign bits are set, all sign bits must be set. |
3141 | That is, A must be a valid negative address after | |
3142 | shifting. */ | |
3143 | signmask = ~ (fieldmask >> 1); | |
3144 | ss = a & signmask; | |
3145 | if (ss != 0 && ss != ((addrmask >> howto->rightshift) & signmask)) | |
b34976b6 | 3146 | return TRUE; |
cf9ab45b | 3147 | |
dbe341c6 TR |
3148 | /* We only need this next bit of code if the sign bit of B |
3149 | is below the sign bit of A. This would only happen if | |
3150 | SRC_MASK had fewer bits than BITSIZE. Note that if | |
3151 | SRC_MASK has more bits than BITSIZE, we can get into | |
3152 | trouble; we would need to verify that B is in range, as | |
3153 | we do for A above. */ | |
3154 | signmask = ((~ howto->src_mask) >> 1) & howto->src_mask; | |
3155 | if ((b & signmask) != 0) | |
3156 | { | |
3157 | /* Set all the bits above the sign bit. */ | |
3158 | b -= signmask <<= 1; | |
3159 | } | |
cf9ab45b | 3160 | |
dbe341c6 | 3161 | b = (b & addrmask) >> howto->bitpos; |
cf9ab45b | 3162 | |
dbe341c6 TR |
3163 | /* Now we can do the addition. */ |
3164 | sum = a + b; | |
cf9ab45b | 3165 | |
dbe341c6 TR |
3166 | /* See if the result has the correct sign. Bits above the |
3167 | sign bit are junk now; ignore them. If the sum is | |
3168 | positive, make sure we did not have all negative inputs; | |
3169 | if the sum is negative, make sure we did not have all | |
3170 | positive inputs. The test below looks only at the sign | |
3171 | bits, and it really just | |
3172 | SIGN (A) == SIGN (B) && SIGN (A) != SIGN (SUM) | |
3173 | */ | |
3174 | signmask = (fieldmask >> 1) + 1; | |
3175 | if (((~ (a ^ b)) & (a ^ sum)) & signmask) | |
b34976b6 | 3176 | return TRUE; |
cf9ab45b | 3177 | |
b34976b6 | 3178 | return FALSE; |
dbe341c6 TR |
3179 | } |
3180 | ||
b34976b6 | 3181 | static bfd_boolean |
cf9ab45b | 3182 | xcoff_complain_overflow_unsigned_func (input_bfd, val, relocation, howto) |
dbe341c6 TR |
3183 | bfd *input_bfd; |
3184 | bfd_vma val; | |
3185 | bfd_vma relocation; | |
cf9ab45b | 3186 | struct reloc_howto_struct *howto; |
dbe341c6 TR |
3187 | { |
3188 | bfd_vma addrmask, fieldmask; | |
3189 | bfd_vma a, b, sum; | |
cf9ab45b | 3190 | |
dbe341c6 TR |
3191 | /* Get the values to be added together. For signed and unsigned |
3192 | relocations, we assume that all values should be truncated to | |
3193 | the size of an address. For bitfields, all the bits matter. | |
3194 | See also bfd_check_overflow. */ | |
3195 | fieldmask = N_ONES (howto->bitsize); | |
3196 | addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask; | |
3197 | a = relocation; | |
3198 | b = val & howto->src_mask; | |
3199 | ||
3200 | /* Checking for an unsigned overflow is relatively easy: | |
3201 | trim the addresses and add, and trim the result as well. | |
3202 | Overflow is normally indicated when the result does not | |
3203 | fit in the field. However, we also need to consider the | |
3204 | case when, e.g., fieldmask is 0x7fffffff or smaller, an | |
3205 | input is 0x80000000, and bfd_vma is only 32 bits; then we | |
3206 | will get sum == 0, but there is an overflow, since the | |
3207 | inputs did not fit in the field. Instead of doing a | |
3208 | separate test, we can check for this by or-ing in the | |
3209 | operands when testing for the sum overflowing its final | |
3210 | field. */ | |
3211 | a = (a & addrmask) >> howto->rightshift; | |
3212 | b = (b & addrmask) >> howto->bitpos; | |
3213 | sum = (a + b) & addrmask; | |
3214 | if ((a | b | sum) & ~ fieldmask) | |
b34976b6 | 3215 | return TRUE; |
cf9ab45b | 3216 | |
b34976b6 | 3217 | return FALSE; |
dbe341c6 | 3218 | } |
beb1bf64 TR |
3219 | |
3220 | /* This is the relocation function for the RS/6000/POWER/PowerPC. | |
3221 | This is currently the only processor which uses XCOFF; I hope that | |
cf9ab45b | 3222 | will never change. |
beb1bf64 | 3223 | |
dbe341c6 TR |
3224 | I took the relocation type definitions from two documents: |
3225 | the PowerPC AIX Version 4 Application Binary Interface, First | |
3226 | Edition (April 1992), and the PowerOpen ABI, Big-Endian | |
3227 | 32-Bit Hardware Implementation (June 30, 1994). Differences | |
cf9ab45b | 3228 | between the documents are noted below. |
dbe341c6 | 3229 | |
cf9ab45b | 3230 | Unsupported r_type's |
dbe341c6 TR |
3231 | |
3232 | R_RTB: | |
3233 | R_RRTBI: | |
3234 | R_RRTBA: | |
cf9ab45b | 3235 | |
dbe341c6 TR |
3236 | These relocs are defined by the PowerPC ABI to be |
3237 | relative branches which use half of the difference | |
3238 | between the symbol and the program counter. I can't | |
3239 | quite figure out when this is useful. These relocs are | |
cf9ab45b | 3240 | not defined by the PowerOpen ABI. |
dbe341c6 TR |
3241 | |
3242 | Supported r_type's | |
3243 | ||
3244 | R_POS: | |
3245 | Simple positive relocation. | |
3246 | ||
3247 | R_NEG: | |
cf9ab45b | 3248 | Simple negative relocation. |
dbe341c6 TR |
3249 | |
3250 | R_REL: | |
3251 | Simple PC relative relocation. | |
3252 | ||
3253 | R_TOC: | |
3254 | TOC relative relocation. The value in the instruction in | |
3255 | the input file is the offset from the input file TOC to | |
3256 | the desired location. We want the offset from the final | |
3257 | TOC to the desired location. We have: | |
3258 | isym = iTOC + in | |
3259 | iinsn = in + o | |
3260 | osym = oTOC + on | |
3261 | oinsn = on + o | |
3262 | so we must change insn by on - in. | |
3263 | ||
3264 | R_GL: | |
3265 | GL linkage relocation. The value of this relocation | |
cf9ab45b | 3266 | is the address of the entry in the TOC section. |
dbe341c6 TR |
3267 | |
3268 | R_TCL: | |
3269 | Local object TOC address. I can't figure out the | |
cf9ab45b | 3270 | difference between this and case R_GL. |
dbe341c6 TR |
3271 | |
3272 | R_TRL: | |
3273 | TOC relative relocation. A TOC relative load instruction | |
3274 | which may be changed to a load address instruction. | |
cf9ab45b | 3275 | FIXME: We don't currently implement this optimization. |
dbe341c6 TR |
3276 | |
3277 | R_TRLA: | |
3278 | TOC relative relocation. This is a TOC relative load | |
3279 | address instruction which may be changed to a load | |
3280 | instruction. FIXME: I don't know if this is the correct | |
3281 | implementation. | |
3282 | ||
3283 | R_BA: | |
3284 | Absolute branch. We don't want to mess with the lower | |
cf9ab45b | 3285 | two bits of the instruction. |
dbe341c6 TR |
3286 | |
3287 | R_CAI: | |
3288 | The PowerPC ABI defines this as an absolute call which | |
3289 | may be modified to become a relative call. The PowerOpen | |
cf9ab45b AM |
3290 | ABI does not define this relocation type. |
3291 | ||
dbe341c6 TR |
3292 | R_RBA: |
3293 | Absolute branch which may be modified to become a | |
cf9ab45b | 3294 | relative branch. |
dbe341c6 TR |
3295 | |
3296 | R_RBAC: | |
3297 | The PowerPC ABI defines this as an absolute branch to a | |
3298 | fixed address which may be modified to an absolute branch | |
3299 | to a symbol. The PowerOpen ABI does not define this | |
cf9ab45b | 3300 | relocation type. |
dbe341c6 TR |
3301 | |
3302 | R_RBRC: | |
3303 | The PowerPC ABI defines this as an absolute branch to a | |
3304 | fixed address which may be modified to a relative branch. | |
cf9ab45b | 3305 | The PowerOpen ABI does not define this relocation type. |
dbe341c6 TR |
3306 | |
3307 | R_BR: | |
3308 | Relative branch. We don't want to mess with the lower | |
cf9ab45b | 3309 | two bits of the instruction. |
dbe341c6 TR |
3310 | |
3311 | R_CREL: | |
3312 | The PowerPC ABI defines this as a relative call which may | |
3313 | be modified to become an absolute call. The PowerOpen | |
cf9ab45b | 3314 | ABI does not define this relocation type. |
dbe341c6 TR |
3315 | |
3316 | R_RBR: | |
3317 | A relative branch which may be modified to become an | |
3318 | absolute branch. FIXME: We don't implement this, | |
3319 | although we should for symbols of storage mapping class | |
cf9ab45b | 3320 | XMC_XO. |
dbe341c6 TR |
3321 | |
3322 | R_RL: | |
3323 | The PowerPC AIX ABI describes this as a load which may be | |
3324 | changed to a load address. The PowerOpen ABI says this | |
cf9ab45b | 3325 | is the same as case R_POS. |
dbe341c6 TR |
3326 | |
3327 | R_RLA: | |
3328 | The PowerPC AIX ABI describes this as a load address | |
3329 | which may be changed to a load. The PowerOpen ABI says | |
cf9ab45b | 3330 | this is the same as R_POS. |
dbe341c6 TR |
3331 | */ |
3332 | ||
b34976b6 | 3333 | bfd_boolean |
beb1bf64 TR |
3334 | xcoff_ppc_relocate_section (output_bfd, info, input_bfd, |
3335 | input_section, contents, relocs, syms, | |
3336 | sections) | |
3337 | bfd *output_bfd; | |
3338 | struct bfd_link_info *info; | |
3339 | bfd *input_bfd; | |
3340 | asection *input_section; | |
3341 | bfd_byte *contents; | |
3342 | struct internal_reloc *relocs; | |
3343 | struct internal_syment *syms; | |
3344 | asection **sections; | |
3345 | { | |
3346 | struct internal_reloc *rel; | |
3347 | struct internal_reloc *relend; | |
3348 | ||
3349 | rel = relocs; | |
3350 | relend = rel + input_section->reloc_count; | |
beb1bf64 TR |
3351 | for (; rel < relend; rel++) |
3352 | { | |
3353 | long symndx; | |
3354 | struct xcoff_link_hash_entry *h; | |
3355 | struct internal_syment *sym; | |
3356 | bfd_vma addend; | |
3357 | bfd_vma val; | |
3358 | struct reloc_howto_struct howto; | |
dbe341c6 TR |
3359 | bfd_vma relocation; |
3360 | bfd_vma value_to_relocate; | |
3361 | bfd_vma address; | |
3362 | bfd_byte *location; | |
beb1bf64 TR |
3363 | |
3364 | /* Relocation type R_REF is a special relocation type which is | |
cf9ab45b AM |
3365 | merely used to prevent garbage collection from occurring for |
3366 | the csect including the symbol which it references. */ | |
beb1bf64 TR |
3367 | if (rel->r_type == R_REF) |
3368 | continue; | |
3369 | ||
dbe341c6 | 3370 | /* howto */ |
beb1bf64 TR |
3371 | howto.type = rel->r_type; |
3372 | howto.rightshift = 0; | |
beb1bf64 | 3373 | howto.bitsize = (rel->r_size & 0x1f) + 1; |
dbe341c6 | 3374 | howto.size = howto.bitsize > 16 ? 2 : 1; |
b34976b6 | 3375 | howto.pc_relative = FALSE; |
beb1bf64 | 3376 | howto.bitpos = 0; |
cf9ab45b AM |
3377 | howto.complain_on_overflow = (rel->r_size & 0x80 |
3378 | ? complain_overflow_signed | |
3379 | : complain_overflow_bitfield); | |
beb1bf64 TR |
3380 | howto.special_function = NULL; |
3381 | howto.name = "internal"; | |
b34976b6 | 3382 | howto.partial_inplace = TRUE; |
cf9ab45b | 3383 | howto.src_mask = howto.dst_mask = N_ONES (howto.bitsize); |
b34976b6 | 3384 | howto.pcrel_offset = FALSE; |
beb1bf64 | 3385 | |
dbe341c6 | 3386 | /* symbol */ |
beb1bf64 | 3387 | val = 0; |
dbe341c6 TR |
3388 | addend = 0; |
3389 | h = NULL; | |
3390 | sym = NULL; | |
cf9ab45b | 3391 | symndx = rel->r_symndx; |
beb1bf64 | 3392 | |
cf9ab45b | 3393 | if (-1 != symndx) |
beb1bf64 TR |
3394 | { |
3395 | asection *sec; | |
cf9ab45b | 3396 | |
dbe341c6 TR |
3397 | h = obj_xcoff_sym_hashes (input_bfd)[symndx]; |
3398 | sym = syms + symndx; | |
3399 | addend = - sym->n_value; | |
cf9ab45b AM |
3400 | |
3401 | if (NULL == h) | |
beb1bf64 TR |
3402 | { |
3403 | sec = sections[symndx]; | |
3404 | /* Hack to make sure we use the right TOC anchor value | |
dbe341c6 | 3405 | if this reloc is against the TOC anchor. */ |
beb1bf64 | 3406 | if (sec->name[3] == '0' |
dbe341c6 TR |
3407 | && strcmp (sec->name, ".tc0") == 0) |
3408 | val = xcoff_data (output_bfd)->toc; | |
f4ffd778 | 3409 | else |
dbe341c6 TR |
3410 | val = (sec->output_section->vma |
3411 | + sec->output_offset | |
3412 | + sym->n_value | |
3413 | - sec->vma); | |
cf9ab45b AM |
3414 | } |
3415 | else | |
dbe341c6 | 3416 | { |
cf9ab45b AM |
3417 | if (h->root.type == bfd_link_hash_defined |
3418 | || h->root.type == bfd_link_hash_defweak) | |
dbe341c6 TR |
3419 | { |
3420 | sec = h->root.u.def.section; | |
3421 | val = (h->root.u.def.value | |
3422 | + sec->output_section->vma | |
3423 | + sec->output_offset); | |
cf9ab45b AM |
3424 | } |
3425 | else if (h->root.type == bfd_link_hash_common) | |
f4ffd778 | 3426 | { |
dbe341c6 | 3427 | sec = h->root.u.c.p->section; |
f4ffd778 | 3428 | val = (sec->output_section->vma |
dbe341c6 | 3429 | + sec->output_offset); |
cf9ab45b AM |
3430 | |
3431 | } | |
3432 | else if ((0 == (h->flags & (XCOFF_DEF_DYNAMIC | XCOFF_IMPORT))) | |
1049f94e | 3433 | && ! info->relocatable) |
dbe341c6 TR |
3434 | { |
3435 | if (! ((*info->callbacks->undefined_symbol) | |
3436 | (info, h->root.root.string, input_bfd, input_section, | |
b34976b6 AM |
3437 | rel->r_vaddr - input_section->vma, TRUE))) |
3438 | return FALSE; | |
cf9ab45b | 3439 | |
dbe341c6 TR |
3440 | /* Don't try to process the reloc. It can't help, and |
3441 | it may generate another error. */ | |
3442 | continue; | |
f4ffd778 | 3443 | } |
beb1bf64 TR |
3444 | } |
3445 | } | |
beb1bf64 | 3446 | |
cf9ab45b AM |
3447 | if (rel->r_type >= XCOFF_MAX_CALCULATE_RELOCATION |
3448 | || !((*xcoff_calculate_relocation[rel->r_type]) | |
3449 | (input_bfd, input_section, output_bfd, rel, sym, &howto, val, | |
3450 | addend, &relocation, contents))) | |
b34976b6 | 3451 | return FALSE; |
cf9ab45b | 3452 | |
dbe341c6 TR |
3453 | /* address */ |
3454 | address = rel->r_vaddr - input_section->vma; | |
3455 | location = contents + address; | |
cf9ab45b | 3456 | |
eea6121a | 3457 | if (address > input_section->size) |
cf9ab45b | 3458 | abort (); |
dbe341c6 TR |
3459 | |
3460 | /* Get the value we are going to relocate. */ | |
3461 | if (1 == howto.size) | |
3462 | value_to_relocate = bfd_get_16 (input_bfd, location); | |
cf9ab45b | 3463 | else |
dbe341c6 | 3464 | value_to_relocate = bfd_get_32 (input_bfd, location); |
cf9ab45b AM |
3465 | |
3466 | /* overflow. | |
3467 | ||
dbe341c6 TR |
3468 | FIXME: We may drop bits during the addition |
3469 | which we don't check for. We must either check at every single | |
3470 | operation, which would be tedious, or we must do the computations | |
3471 | in a type larger than bfd_vma, which would be inefficient. */ | |
beb1bf64 | 3472 | |
cf9ab45b AM |
3473 | if ((unsigned int) howto.complain_on_overflow |
3474 | >= XCOFF_MAX_COMPLAIN_OVERFLOW) | |
3475 | abort (); | |
3476 | ||
3477 | if (((*xcoff_complain_overflow[howto.complain_on_overflow]) | |
3478 | (input_bfd, value_to_relocate, relocation, &howto))) | |
beb1bf64 | 3479 | { |
dbe341c6 TR |
3480 | const char *name; |
3481 | char buf[SYMNMLEN + 1]; | |
3482 | char reloc_type_name[10]; | |
cf9ab45b AM |
3483 | |
3484 | if (symndx == -1) | |
beb1bf64 | 3485 | { |
dbe341c6 | 3486 | name = "*ABS*"; |
cf9ab45b AM |
3487 | } |
3488 | else if (h != NULL) | |
beb1bf64 | 3489 | { |
dfeffb9f | 3490 | name = NULL; |
cf9ab45b AM |
3491 | } |
3492 | else | |
beb1bf64 | 3493 | { |
dbe341c6 TR |
3494 | name = _bfd_coff_internal_syment_name (input_bfd, sym, buf); |
3495 | if (name == NULL) | |
3496 | name = "UNKNOWN"; | |
beb1bf64 | 3497 | } |
dbe341c6 | 3498 | sprintf (reloc_type_name, "0x%02x", rel->r_type); |
cf9ab45b | 3499 | |
dbe341c6 | 3500 | if (! ((*info->callbacks->reloc_overflow) |
dfeffb9f L |
3501 | (info, (h ? &h->root : NULL), name, reloc_type_name, |
3502 | (bfd_vma) 0, input_bfd, input_section, | |
3503 | rel->r_vaddr - input_section->vma))) | |
b34976b6 | 3504 | return FALSE; |
beb1bf64 | 3505 | } |
cf9ab45b | 3506 | |
dbe341c6 | 3507 | /* Add RELOCATION to the right bits of VALUE_TO_RELOCATE. */ |
cf9ab45b AM |
3508 | value_to_relocate = ((value_to_relocate & ~howto.dst_mask) |
3509 | | (((value_to_relocate & howto.src_mask) | |
3510 | + relocation) & howto.dst_mask)); | |
3511 | ||
dbe341c6 TR |
3512 | /* Put the value back in the object file. */ |
3513 | if (1 == howto.size) | |
3514 | bfd_put_16 (input_bfd, value_to_relocate, location); | |
cf9ab45b | 3515 | else |
dbe341c6 | 3516 | bfd_put_32 (input_bfd, value_to_relocate, location); |
beb1bf64 TR |
3517 | } |
3518 | ||
b34976b6 | 3519 | return TRUE; |
beb1bf64 TR |
3520 | } |
3521 | ||
b34976b6 | 3522 | static bfd_boolean |
beb1bf64 TR |
3523 | _bfd_xcoff_put_ldsymbol_name (abfd, ldinfo, ldsym, name) |
3524 | bfd *abfd ATTRIBUTE_UNUSED; | |
3525 | struct xcoff_loader_info *ldinfo; | |
3526 | struct internal_ldsym *ldsym; | |
3527 | const char *name; | |
3528 | { | |
3529 | size_t len; | |
3530 | len = strlen (name); | |
3531 | ||
3532 | if (len <= SYMNMLEN) | |
3533 | strncpy (ldsym->_l._l_name, name, SYMNMLEN); | |
3534 | else | |
3535 | { | |
3536 | if (ldinfo->string_size + len + 3 > ldinfo->string_alc) | |
3537 | { | |
dc810e39 | 3538 | bfd_size_type newalc; |
f075ee0c | 3539 | char *newstrings; |
beb1bf64 TR |
3540 | |
3541 | newalc = ldinfo->string_alc * 2; | |
3542 | if (newalc == 0) | |
3543 | newalc = 32; | |
3544 | while (ldinfo->string_size + len + 3 > newalc) | |
3545 | newalc *= 2; | |
3546 | ||
f075ee0c | 3547 | newstrings = bfd_realloc (ldinfo->strings, newalc); |
beb1bf64 TR |
3548 | if (newstrings == NULL) |
3549 | { | |
b34976b6 AM |
3550 | ldinfo->failed = TRUE; |
3551 | return FALSE; | |
beb1bf64 TR |
3552 | } |
3553 | ldinfo->string_alc = newalc; | |
3554 | ldinfo->strings = newstrings; | |
3555 | } | |
3556 | ||
dc810e39 AM |
3557 | bfd_put_16 (ldinfo->output_bfd, (bfd_vma) (len + 1), |
3558 | ldinfo->strings + ldinfo->string_size); | |
beb1bf64 TR |
3559 | strcpy (ldinfo->strings + ldinfo->string_size + 2, name); |
3560 | ldsym->_l._l_l._l_zeroes = 0; | |
3561 | ldsym->_l._l_l._l_offset = ldinfo->string_size + 2; | |
3562 | ldinfo->string_size += len + 3; | |
3563 | } | |
3564 | ||
b34976b6 | 3565 | return TRUE; |
beb1bf64 TR |
3566 | } |
3567 | ||
b34976b6 | 3568 | static bfd_boolean |
dc810e39 | 3569 | _bfd_xcoff_put_symbol_name (bfd *abfd, struct bfd_strtab_hash *strtab, |
beb1bf64 | 3570 | struct internal_syment *sym, |
f4ffd778 NC |
3571 | const char *name) |
3572 | { | |
3573 | if (strlen (name) <= SYMNMLEN) | |
3574 | { | |
3575 | strncpy (sym->_n._n_name, name, SYMNMLEN); | |
3576 | } | |
3577 | else | |
3578 | { | |
b34976b6 | 3579 | bfd_boolean hash; |
f4ffd778 NC |
3580 | bfd_size_type indx; |
3581 | ||
b34976b6 | 3582 | hash = TRUE; |
f4ffd778 | 3583 | if ((abfd->flags & BFD_TRADITIONAL_FORMAT) != 0) |
b34976b6 AM |
3584 | hash = FALSE; |
3585 | indx = _bfd_stringtab_add (strtab, name, hash, FALSE); | |
f4ffd778 | 3586 | if (indx == (bfd_size_type) -1) |
b34976b6 | 3587 | return FALSE; |
f4ffd778 NC |
3588 | sym->_n._n_n._n_zeroes = 0; |
3589 | sym->_n._n_n._n_offset = STRING_SIZE_SIZE + indx; | |
3590 | } | |
b34976b6 | 3591 | return TRUE; |
beb1bf64 TR |
3592 | } |
3593 | ||
3594 | static asection * | |
dc810e39 | 3595 | xcoff_create_csect_from_smclas (abfd, aux, symbol_name) |
beb1bf64 TR |
3596 | bfd *abfd; |
3597 | union internal_auxent *aux; | |
814fa6ab | 3598 | const char *symbol_name; |
beb1bf64 | 3599 | { |
beb1bf64 TR |
3600 | asection *return_value = NULL; |
3601 | ||
f4ffd778 NC |
3602 | /* .sv64 = x_smclas == 17 |
3603 | This is an invalid csect for 32 bit apps. */ | |
3604 | static const char *names[19] = | |
3605 | { | |
beb1bf64 TR |
3606 | ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo", |
3607 | ".sv", ".bs", ".ds", ".uc", ".ti", ".tb", NULL, ".tc0", | |
dc810e39 | 3608 | ".td", NULL, ".sv3264" |
beb1bf64 TR |
3609 | }; |
3610 | ||
cf9ab45b AM |
3611 | if ((19 >= aux->x_csect.x_smclas) |
3612 | && (NULL != names[aux->x_csect.x_smclas])) | |
f4ffd778 | 3613 | { |
dc810e39 | 3614 | return_value = bfd_make_section_anyway |
f4ffd778 NC |
3615 | (abfd, names[aux->x_csect.x_smclas]); |
3616 | } | |
3617 | else | |
3618 | { | |
3619 | (*_bfd_error_handler) | |
d003868e AM |
3620 | (_("%B: symbol `%s' has unrecognized smclas %d"), |
3621 | abfd, symbol_name, aux->x_csect.x_smclas); | |
f4ffd778 NC |
3622 | bfd_set_error (bfd_error_bad_value); |
3623 | } | |
beb1bf64 TR |
3624 | |
3625 | return return_value; | |
3626 | } | |
3627 | ||
b34976b6 | 3628 | static bfd_boolean |
beb1bf64 TR |
3629 | xcoff_is_lineno_count_overflow (abfd, value) |
3630 | bfd *abfd ATTRIBUTE_UNUSED; | |
3631 | bfd_vma value; | |
3632 | { | |
f4ffd778 | 3633 | if (0xffff <= value) |
b34976b6 | 3634 | return TRUE; |
f4ffd778 | 3635 | |
b34976b6 | 3636 | return FALSE; |
beb1bf64 TR |
3637 | } |
3638 | ||
b34976b6 | 3639 | static bfd_boolean |
beb1bf64 TR |
3640 | xcoff_is_reloc_count_overflow (abfd, value) |
3641 | bfd *abfd ATTRIBUTE_UNUSED; | |
3642 | bfd_vma value; | |
3643 | { | |
f4ffd778 | 3644 | if (0xffff <= value) |
b34976b6 | 3645 | return TRUE; |
f4ffd778 | 3646 | |
b34976b6 | 3647 | return FALSE; |
beb1bf64 TR |
3648 | } |
3649 | ||
a7b97311 | 3650 | static bfd_vma |
beb1bf64 TR |
3651 | xcoff_loader_symbol_offset (abfd, ldhdr) |
3652 | bfd *abfd; | |
f4ffd778 | 3653 | struct internal_ldhdr *ldhdr ATTRIBUTE_UNUSED; |
beb1bf64 | 3654 | { |
cf9ab45b | 3655 | return bfd_xcoff_ldhdrsz (abfd); |
beb1bf64 TR |
3656 | } |
3657 | ||
a7b97311 | 3658 | static bfd_vma |
beb1bf64 TR |
3659 | xcoff_loader_reloc_offset (abfd, ldhdr) |
3660 | bfd *abfd; | |
f4ffd778 | 3661 | struct internal_ldhdr *ldhdr; |
beb1bf64 | 3662 | { |
cf9ab45b | 3663 | return bfd_xcoff_ldhdrsz (abfd) + ldhdr->l_nsyms * bfd_xcoff_ldsymsz (abfd); |
beb1bf64 TR |
3664 | } |
3665 | ||
b34976b6 | 3666 | static bfd_boolean |
69f284c7 | 3667 | xcoff_generate_rtinit (abfd, init, fini, rtld) |
9a4c7f16 TR |
3668 | bfd *abfd; |
3669 | const char *init; | |
3670 | const char *fini; | |
b34976b6 | 3671 | bfd_boolean rtld; |
9a4c7f16 TR |
3672 | { |
3673 | bfd_byte filehdr_ext[FILHSZ]; | |
3674 | bfd_byte scnhdr_ext[SCNHSZ]; | |
69f284c7 TR |
3675 | bfd_byte syment_ext[SYMESZ * 10]; |
3676 | bfd_byte reloc_ext[RELSZ * 3]; | |
9a4c7f16 TR |
3677 | bfd_byte *data_buffer; |
3678 | bfd_size_type data_buffer_size; | |
d426c6b0 | 3679 | bfd_byte *string_table = NULL, *st_tmp = NULL; |
9a4c7f16 TR |
3680 | bfd_size_type string_table_size; |
3681 | bfd_vma val; | |
3682 | size_t initsz, finisz; | |
3683 | struct internal_filehdr filehdr; | |
3684 | struct internal_scnhdr scnhdr; | |
3685 | struct internal_syment syment; | |
3686 | union internal_auxent auxent; | |
3687 | struct internal_reloc reloc; | |
cf9ab45b | 3688 | |
9a4c7f16 TR |
3689 | char *data_name = ".data"; |
3690 | char *rtinit_name = "__rtinit"; | |
69f284c7 | 3691 | char *rtld_name = "__rtld"; |
cf9ab45b | 3692 | |
69f284c7 | 3693 | if (! bfd_xcoff_rtinit_size (abfd)) |
b34976b6 | 3694 | return FALSE; |
9a4c7f16 TR |
3695 | |
3696 | initsz = (init == NULL ? 0 : 1 + strlen (init)); | |
3697 | finisz = (fini == NULL ? 0 : 1 + strlen (fini)); | |
3698 | ||
3699 | /* file header */ | |
3700 | memset (filehdr_ext, 0, FILHSZ); | |
3701 | memset (&filehdr, 0, sizeof (struct internal_filehdr)); | |
3702 | filehdr.f_magic = bfd_xcoff_magic_number (abfd); | |
cf9ab45b | 3703 | filehdr.f_nscns = 1; |
9a4c7f16 | 3704 | filehdr.f_timdat = 0; |
69f284c7 | 3705 | filehdr.f_nsyms = 0; /* at least 6, no more than 10 */ |
9a4c7f16 TR |
3706 | filehdr.f_symptr = 0; /* set below */ |
3707 | filehdr.f_opthdr = 0; | |
3708 | filehdr.f_flags = 0; | |
3709 | ||
3710 | /* section header */ | |
3711 | memset (scnhdr_ext, 0, SCNHSZ); | |
3712 | memset (&scnhdr, 0, sizeof (struct internal_scnhdr)); | |
3713 | memcpy (scnhdr.s_name, data_name, strlen (data_name)); | |
3714 | scnhdr.s_paddr = 0; | |
3715 | scnhdr.s_vaddr = 0; | |
3716 | scnhdr.s_size = 0; /* set below */ | |
3717 | scnhdr.s_scnptr = FILHSZ + SCNHSZ; | |
3718 | scnhdr.s_relptr = 0; /* set below */ | |
3719 | scnhdr.s_lnnoptr = 0; | |
3720 | scnhdr.s_nreloc = 0; /* either 1 or 2 */ | |
3721 | scnhdr.s_nlnno = 0; | |
3722 | scnhdr.s_flags = STYP_DATA; | |
3723 | ||
cf9ab45b AM |
3724 | /* .data |
3725 | 0x0000 0x00000000 : rtl | |
3726 | 0x0004 0x00000010 : offset to init, or 0 | |
3727 | 0x0008 0x00000028 : offset to fini, or 0 | |
3728 | 0x000C 0x0000000C : size of descriptor | |
3729 | 0x0010 0x00000000 : init, needs a reloc | |
3730 | 0x0014 0x00000040 : offset to init name | |
3731 | 0x0018 0x00000000 : flags, padded to a word | |
3732 | 0x001C 0x00000000 : empty init | |
3733 | 0x0020 0x00000000 : | |
3734 | 0x0024 0x00000000 : | |
3735 | 0x0028 0x00000000 : fini, needs a reloc | |
3736 | 0x002C 0x00000??? : offset to fini name | |
3737 | 0x0030 0x00000000 : flags, padded to a word | |
3738 | 0x0034 0x00000000 : empty fini | |
3739 | 0x0038 0x00000000 : | |
3740 | 0x003C 0x00000000 : | |
3741 | 0x0040 init name | |
9a4c7f16 TR |
3742 | 0x0040 + initsz fini name */ |
3743 | ||
3744 | data_buffer_size = 0x0040 + initsz + finisz; | |
2a52da53 | 3745 | data_buffer_size = (data_buffer_size + 7) &~ (bfd_size_type) 7; |
330693f5 | 3746 | data_buffer = NULL; |
9bab7074 | 3747 | data_buffer = (bfd_byte *) bfd_zmalloc (data_buffer_size); |
330693f5 | 3748 | if (data_buffer == NULL) |
b34976b6 | 3749 | return FALSE; |
9a4c7f16 | 3750 | |
cf9ab45b | 3751 | if (initsz) |
9a4c7f16 TR |
3752 | { |
3753 | val = 0x10; | |
3754 | bfd_h_put_32 (abfd, val, &data_buffer[0x04]); | |
3755 | val = 0x40; | |
3756 | bfd_h_put_32 (abfd, val, &data_buffer[0x14]); | |
3757 | memcpy (&data_buffer[val], init, initsz); | |
3758 | } | |
3759 | ||
cf9ab45b | 3760 | if (finisz) |
9a4c7f16 TR |
3761 | { |
3762 | val = 0x28; | |
3763 | bfd_h_put_32 (abfd, val, &data_buffer[0x08]); | |
3764 | val = 0x40 + initsz; | |
3765 | bfd_h_put_32 (abfd, val, &data_buffer[0x2C]); | |
3766 | memcpy (&data_buffer[val], fini, finisz); | |
3767 | } | |
3768 | ||
3769 | val = 0x0C; | |
3770 | bfd_h_put_32 (abfd, val, &data_buffer[0x0C]); | |
3771 | ||
3772 | scnhdr.s_size = data_buffer_size; | |
3773 | ||
3774 | /* string table */ | |
3775 | string_table_size = 0; | |
cf9ab45b | 3776 | if (initsz > 9) |
9a4c7f16 TR |
3777 | string_table_size += initsz; |
3778 | if (finisz > 9) | |
3779 | string_table_size += finisz; | |
3780 | if (string_table_size) | |
3781 | { | |
3782 | string_table_size += 4; | |
9bab7074 | 3783 | string_table = (bfd_byte *) bfd_zmalloc (string_table_size); |
021d6096 | 3784 | if (string_table == NULL) |
b34976b6 | 3785 | return FALSE; |
9bab7074 | 3786 | |
9a4c7f16 TR |
3787 | val = string_table_size; |
3788 | bfd_h_put_32 (abfd, val, &string_table[0]); | |
3789 | st_tmp = string_table + 4; | |
3790 | } | |
cf9ab45b AM |
3791 | |
3792 | /* symbols | |
9a4c7f16 TR |
3793 | 0. .data csect |
3794 | 2. __rtinit | |
cf9ab45b AM |
3795 | 4. init function |
3796 | 6. fini function | |
69f284c7 TR |
3797 | 8. __rtld */ |
3798 | memset (syment_ext, 0, 10 * SYMESZ); | |
3799 | memset (reloc_ext, 0, 3 * RELSZ); | |
9a4c7f16 TR |
3800 | |
3801 | /* .data csect */ | |
3802 | memset (&syment, 0, sizeof (struct internal_syment)); | |
3803 | memset (&auxent, 0, sizeof (union internal_auxent)); | |
3804 | memcpy (syment._n._n_name, data_name, strlen (data_name)); | |
3805 | syment.n_scnum = 1; | |
3806 | syment.n_sclass = C_HIDEXT; | |
3807 | syment.n_numaux = 1; | |
3808 | auxent.x_csect.x_scnlen.l = data_buffer_size; | |
3809 | auxent.x_csect.x_smtyp = 3 << 3 | XTY_SD; | |
3810 | auxent.x_csect.x_smclas = XMC_RW; | |
cf9ab45b | 3811 | bfd_coff_swap_sym_out (abfd, &syment, |
9a4c7f16 | 3812 | &syment_ext[filehdr.f_nsyms * SYMESZ]); |
cf9ab45b AM |
3813 | bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0, |
3814 | syment.n_numaux, | |
9a4c7f16 TR |
3815 | &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]); |
3816 | filehdr.f_nsyms += 2; | |
3817 | ||
3818 | /* __rtinit */ | |
3819 | memset (&syment, 0, sizeof (struct internal_syment)); | |
3820 | memset (&auxent, 0, sizeof (union internal_auxent)); | |
3821 | memcpy (syment._n._n_name, rtinit_name, strlen (rtinit_name)); | |
3822 | syment.n_scnum = 1; | |
3823 | syment.n_sclass = C_EXT; | |
3824 | syment.n_numaux = 1; | |
3825 | auxent.x_csect.x_smtyp = XTY_LD; | |
3826 | auxent.x_csect.x_smclas = XMC_RW; | |
cf9ab45b | 3827 | bfd_coff_swap_sym_out (abfd, &syment, |
9a4c7f16 | 3828 | &syment_ext[filehdr.f_nsyms * SYMESZ]); |
cf9ab45b AM |
3829 | bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0, |
3830 | syment.n_numaux, | |
9a4c7f16 TR |
3831 | &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]); |
3832 | filehdr.f_nsyms += 2; | |
3833 | ||
3834 | /* init */ | |
cf9ab45b | 3835 | if (initsz) |
9a4c7f16 TR |
3836 | { |
3837 | memset (&syment, 0, sizeof (struct internal_syment)); | |
3838 | memset (&auxent, 0, sizeof (union internal_auxent)); | |
3839 | ||
cf9ab45b | 3840 | if (initsz > 9) |
9a4c7f16 TR |
3841 | { |
3842 | syment._n._n_n._n_offset = st_tmp - string_table; | |
3843 | memcpy (st_tmp, init, initsz); | |
3844 | st_tmp += initsz; | |
3845 | } | |
3846 | else | |
3847 | memcpy (syment._n._n_name, init, initsz - 1); | |
3848 | ||
3849 | syment.n_sclass = C_EXT; | |
3850 | syment.n_numaux = 1; | |
cf9ab45b | 3851 | bfd_coff_swap_sym_out (abfd, &syment, |
9a4c7f16 | 3852 | &syment_ext[filehdr.f_nsyms * SYMESZ]); |
cf9ab45b AM |
3853 | bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0, |
3854 | syment.n_numaux, | |
9a4c7f16 TR |
3855 | &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]); |
3856 | ||
3857 | /* reloc */ | |
3858 | memset (&reloc, 0, sizeof (struct internal_reloc)); | |
3859 | reloc.r_vaddr = 0x0010; | |
3860 | reloc.r_symndx = filehdr.f_nsyms; | |
3861 | reloc.r_type = R_POS; | |
3862 | reloc.r_size = 31; | |
3863 | bfd_coff_swap_reloc_out (abfd, &reloc, &reloc_ext[0]); | |
3864 | ||
3865 | filehdr.f_nsyms += 2; | |
3866 | scnhdr.s_nreloc += 1; | |
3867 | } | |
cf9ab45b | 3868 | |
9a4c7f16 | 3869 | /* fini */ |
cf9ab45b | 3870 | if (finisz) |
9a4c7f16 TR |
3871 | { |
3872 | memset (&syment, 0, sizeof (struct internal_syment)); | |
3873 | memset (&auxent, 0, sizeof (union internal_auxent)); | |
3874 | ||
cf9ab45b | 3875 | if (finisz > 9) |
9a4c7f16 TR |
3876 | { |
3877 | syment._n._n_n._n_offset = st_tmp - string_table; | |
3878 | memcpy (st_tmp, fini, finisz); | |
3879 | st_tmp += finisz; | |
3880 | } | |
3881 | else | |
3882 | memcpy (syment._n._n_name, fini, finisz - 1); | |
3883 | ||
3884 | syment.n_sclass = C_EXT; | |
3885 | syment.n_numaux = 1; | |
cf9ab45b | 3886 | bfd_coff_swap_sym_out (abfd, &syment, |
9a4c7f16 | 3887 | &syment_ext[filehdr.f_nsyms * SYMESZ]); |
cf9ab45b AM |
3888 | bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0, |
3889 | syment.n_numaux, | |
9a4c7f16 TR |
3890 | &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]); |
3891 | ||
3892 | /* reloc */ | |
3893 | memset (&reloc, 0, sizeof (struct internal_reloc)); | |
3894 | reloc.r_vaddr = 0x0028; | |
3895 | reloc.r_symndx = filehdr.f_nsyms; | |
3896 | reloc.r_type = R_POS; | |
3897 | reloc.r_size = 31; | |
cf9ab45b | 3898 | bfd_coff_swap_reloc_out (abfd, &reloc, |
9a4c7f16 TR |
3899 | &reloc_ext[scnhdr.s_nreloc * RELSZ]); |
3900 | ||
3901 | filehdr.f_nsyms += 2; | |
3902 | scnhdr.s_nreloc += 1; | |
3903 | } | |
3904 | ||
69f284c7 TR |
3905 | if (rtld) |
3906 | { | |
3907 | memset (&syment, 0, sizeof (struct internal_syment)); | |
3908 | memset (&auxent, 0, sizeof (union internal_auxent)); | |
3909 | memcpy (syment._n._n_name, rtld_name, strlen (rtld_name)); | |
3910 | syment.n_sclass = C_EXT; | |
3911 | syment.n_numaux = 1; | |
cf9ab45b | 3912 | bfd_coff_swap_sym_out (abfd, &syment, |
69f284c7 | 3913 | &syment_ext[filehdr.f_nsyms * SYMESZ]); |
cf9ab45b AM |
3914 | bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0, |
3915 | syment.n_numaux, | |
69f284c7 TR |
3916 | &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]); |
3917 | ||
3918 | /* reloc */ | |
3919 | memset (&reloc, 0, sizeof (struct internal_reloc)); | |
3920 | reloc.r_vaddr = 0x0000; | |
3921 | reloc.r_symndx = filehdr.f_nsyms; | |
3922 | reloc.r_type = R_POS; | |
3923 | reloc.r_size = 31; | |
cf9ab45b | 3924 | bfd_coff_swap_reloc_out (abfd, &reloc, |
69f284c7 TR |
3925 | &reloc_ext[scnhdr.s_nreloc * RELSZ]); |
3926 | ||
3927 | filehdr.f_nsyms += 2; | |
3928 | scnhdr.s_nreloc += 1; | |
3929 | } | |
3930 | ||
9a4c7f16 TR |
3931 | scnhdr.s_relptr = scnhdr.s_scnptr + data_buffer_size; |
3932 | filehdr.f_symptr = scnhdr.s_relptr + scnhdr.s_nreloc * RELSZ; | |
3933 | ||
3934 | bfd_coff_swap_filehdr_out (abfd, &filehdr, filehdr_ext); | |
3935 | bfd_bwrite (filehdr_ext, FILHSZ, abfd); | |
3936 | bfd_coff_swap_scnhdr_out (abfd, &scnhdr, scnhdr_ext); | |
3937 | bfd_bwrite (scnhdr_ext, SCNHSZ, abfd); | |
3938 | bfd_bwrite (data_buffer, data_buffer_size, abfd); | |
3939 | bfd_bwrite (reloc_ext, scnhdr.s_nreloc * RELSZ, abfd); | |
3940 | bfd_bwrite (syment_ext, filehdr.f_nsyms * SYMESZ, abfd); | |
3941 | bfd_bwrite (string_table, string_table_size, abfd); | |
3942 | ||
330693f5 TR |
3943 | free (data_buffer); |
3944 | data_buffer = NULL; | |
3945 | ||
b34976b6 | 3946 | return TRUE; |
9a4c7f16 TR |
3947 | } |
3948 | ||
beb1bf64 TR |
3949 | |
3950 | static reloc_howto_type xcoff_dynamic_reloc = | |
cf9ab45b AM |
3951 | HOWTO (0, /* type */ |
3952 | 0, /* rightshift */ | |
3953 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
3954 | 32, /* bitsize */ | |
b34976b6 | 3955 | FALSE, /* pc_relative */ |
cf9ab45b | 3956 | 0, /* bitpos */ |
beb1bf64 | 3957 | complain_overflow_bitfield, /* complain_on_overflow */ |
cf9ab45b AM |
3958 | 0, /* special_function */ |
3959 | "R_POS", /* name */ | |
b34976b6 | 3960 | TRUE, /* partial_inplace */ |
cf9ab45b AM |
3961 | 0xffffffff, /* src_mask */ |
3962 | 0xffffffff, /* dst_mask */ | |
b34976b6 | 3963 | FALSE); /* pcrel_offset */ |
beb1bf64 | 3964 | |
dc810e39 AM |
3965 | /* glink |
3966 | ||
3967 | The first word of global linkage code must be modified by filling in | |
f4ffd778 NC |
3968 | the correct TOC offset. */ |
3969 | ||
beb1bf64 | 3970 | static unsigned long xcoff_glink_code[9] = |
f4ffd778 NC |
3971 | { |
3972 | 0x81820000, /* lwz r12,0(r2) */ | |
3973 | 0x90410014, /* stw r2,20(r1) */ | |
3974 | 0x800c0000, /* lwz r0,0(r12) */ | |
3975 | 0x804c0004, /* lwz r2,4(r12) */ | |
3976 | 0x7c0903a6, /* mtctr r0 */ | |
3977 | 0x4e800420, /* bctr */ | |
3978 | 0x00000000, /* start of traceback table */ | |
3979 | 0x000c8000, /* traceback table */ | |
3980 | 0x00000000, /* traceback table */ | |
3981 | }; | |
beb1bf64 TR |
3982 | |
3983 | ||
dc810e39 | 3984 | static const struct xcoff_backend_data_rec bfd_xcoff_backend_data = |
f4ffd778 NC |
3985 | { |
3986 | { /* COFF backend, defined in libcoff.h. */ | |
cf9ab45b AM |
3987 | _bfd_xcoff_swap_aux_in, |
3988 | _bfd_xcoff_swap_sym_in, | |
3989 | coff_swap_lineno_in, | |
3990 | _bfd_xcoff_swap_aux_out, | |
3991 | _bfd_xcoff_swap_sym_out, | |
3992 | coff_swap_lineno_out, | |
3993 | xcoff_swap_reloc_out, | |
3994 | coff_swap_filehdr_out, | |
3995 | coff_swap_aouthdr_out, | |
3996 | coff_swap_scnhdr_out, | |
3997 | FILHSZ, | |
3998 | AOUTSZ, | |
3999 | SCNHSZ, | |
4000 | SYMESZ, | |
4001 | AUXESZ, | |
4002 | RELSZ, | |
4003 | LINESZ, | |
4004 | FILNMLEN, | |
b34976b6 AM |
4005 | TRUE, /* _bfd_coff_long_filenames */ |
4006 | FALSE, /* _bfd_coff_long_section_names */ | |
cf9ab45b | 4007 | 3, /* _bfd_coff_default_section_alignment_power */ |
b34976b6 | 4008 | FALSE, /* _bfd_coff_force_symnames_in_strings */ |
cf9ab45b AM |
4009 | 2, /* _bfd_coff_debug_string_prefix_length */ |
4010 | coff_swap_filehdr_in, | |
4011 | coff_swap_aouthdr_in, | |
4012 | coff_swap_scnhdr_in, | |
4013 | xcoff_swap_reloc_in, | |
4014 | coff_bad_format_hook, | |
4015 | coff_set_arch_mach_hook, | |
4016 | coff_mkobject_hook, | |
4017 | styp_to_sec_flags, | |
4018 | coff_set_alignment_hook, | |
4019 | coff_slurp_symbol_table, | |
4020 | symname_in_debug_hook, | |
4021 | coff_pointerize_aux_hook, | |
4022 | coff_print_aux, | |
4023 | dummy_reloc16_extra_cases, | |
4024 | dummy_reloc16_estimate, | |
4025 | NULL, /* bfd_coff_sym_is_global */ | |
4026 | coff_compute_section_file_positions, | |
4027 | NULL, /* _bfd_coff_start_final_link */ | |
4028 | xcoff_ppc_relocate_section, | |
4029 | coff_rtype_to_howto, | |
4030 | NULL, /* _bfd_coff_adjust_symndx */ | |
4031 | _bfd_generic_link_add_one_symbol, | |
4032 | coff_link_output_has_begun, | |
4033 | coff_final_link_postscript | |
f4ffd778 NC |
4034 | }, |
4035 | ||
cf9ab45b AM |
4036 | 0x01DF, /* magic number */ |
4037 | bfd_arch_rs6000, | |
4038 | bfd_mach_rs6k, | |
dc810e39 | 4039 | |
f4ffd778 | 4040 | /* Function pointers to xcoff specific swap routines. */ |
cf9ab45b AM |
4041 | xcoff_swap_ldhdr_in, |
4042 | xcoff_swap_ldhdr_out, | |
4043 | xcoff_swap_ldsym_in, | |
4044 | xcoff_swap_ldsym_out, | |
4045 | xcoff_swap_ldrel_in, | |
4046 | xcoff_swap_ldrel_out, | |
f4ffd778 NC |
4047 | |
4048 | /* Sizes. */ | |
cf9ab45b AM |
4049 | LDHDRSZ, |
4050 | LDSYMSZ, | |
4051 | LDRELSZ, | |
4052 | 12, /* _xcoff_function_descriptor_size */ | |
4053 | SMALL_AOUTSZ, | |
f4ffd778 | 4054 | |
cf9ab45b AM |
4055 | /* Versions. */ |
4056 | 1, /* _xcoff_ldhdr_version */ | |
f4ffd778 | 4057 | |
cf9ab45b AM |
4058 | _bfd_xcoff_put_symbol_name, |
4059 | _bfd_xcoff_put_ldsymbol_name, | |
4060 | &xcoff_dynamic_reloc, | |
4061 | xcoff_create_csect_from_smclas, | |
f4ffd778 NC |
4062 | |
4063 | /* Lineno and reloc count overflow. */ | |
4064 | xcoff_is_lineno_count_overflow, | |
4065 | xcoff_is_reloc_count_overflow, | |
4066 | ||
4067 | xcoff_loader_symbol_offset, | |
4068 | xcoff_loader_reloc_offset, | |
4069 | ||
4070 | /* glink. */ | |
cf9ab45b AM |
4071 | &xcoff_glink_code[0], |
4072 | 36, /* _xcoff_glink_size */ | |
9a4c7f16 TR |
4073 | |
4074 | /* rtinit */ | |
cf9ab45b AM |
4075 | 64, /* _xcoff_rtinit_size */ |
4076 | xcoff_generate_rtinit, | |
4077 | }; | |
beb1bf64 | 4078 | |
eb1e0e80 | 4079 | /* The transfer vector that leads the outside world to all of the above. */ |
beb1bf64 | 4080 | const bfd_target rs6000coff_vec = |
cf9ab45b AM |
4081 | { |
4082 | "aixcoff-rs6000", | |
4083 | bfd_target_xcoff_flavour, | |
4084 | BFD_ENDIAN_BIG, /* data byte order is big */ | |
4085 | BFD_ENDIAN_BIG, /* header byte order is big */ | |
4086 | ||
4087 | (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | DYNAMIC | |
4088 | | HAS_SYMS | HAS_LOCALS | WP_TEXT), | |
4089 | ||
a7c71b0c | 4090 | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA, |
cf9ab45b AM |
4091 | 0, /* leading char */ |
4092 | '/', /* ar_pad_char */ | |
4093 | 15, /* ar_max_namelen */ | |
4094 | ||
4095 | /* data */ | |
4096 | bfd_getb64, | |
4097 | bfd_getb_signed_64, | |
4098 | bfd_putb64, | |
4099 | bfd_getb32, | |
4100 | bfd_getb_signed_32, | |
4101 | bfd_putb32, | |
4102 | bfd_getb16, | |
4103 | bfd_getb_signed_16, | |
4104 | bfd_putb16, | |
4105 | ||
4106 | /* hdrs */ | |
4107 | bfd_getb64, | |
4108 | bfd_getb_signed_64, | |
4109 | bfd_putb64, | |
4110 | bfd_getb32, | |
4111 | bfd_getb_signed_32, | |
4112 | bfd_putb32, | |
4113 | bfd_getb16, | |
4114 | bfd_getb_signed_16, | |
4115 | bfd_putb16, | |
4116 | ||
4117 | { /* bfd_check_format */ | |
4118 | _bfd_dummy_target, | |
4119 | coff_object_p, | |
4120 | _bfd_xcoff_archive_p, | |
4121 | CORE_FILE_P | |
4122 | }, | |
dc810e39 | 4123 | |
cf9ab45b AM |
4124 | { /* bfd_set_format */ |
4125 | bfd_false, | |
4126 | coff_mkobject, | |
4127 | _bfd_generic_mkarchive, | |
4128 | bfd_false | |
4129 | }, | |
4130 | ||
4131 | {/* bfd_write_contents */ | |
4132 | bfd_false, | |
4133 | coff_write_object_contents, | |
4134 | _bfd_xcoff_write_archive_contents, | |
4135 | bfd_false | |
4136 | }, | |
4137 | ||
4138 | /* Generic */ | |
4139 | bfd_true, | |
4140 | bfd_true, | |
4141 | coff_new_section_hook, | |
4142 | _bfd_generic_get_section_contents, | |
4143 | _bfd_generic_get_section_contents_in_window, | |
4144 | ||
4145 | /* Copy */ | |
4146 | _bfd_xcoff_copy_private_bfd_data, | |
b34976b6 | 4147 | ((bfd_boolean (*) (bfd *, bfd *)) bfd_true), |
60b48850 | 4148 | _bfd_generic_init_private_section_data, |
b34976b6 AM |
4149 | ((bfd_boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true), |
4150 | ((bfd_boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true), | |
80fccad2 | 4151 | ((bfd_boolean (*) (bfd *, bfd *)) bfd_true), |
b34976b6 AM |
4152 | ((bfd_boolean (*) (bfd *, flagword)) bfd_true), |
4153 | ((bfd_boolean (*) (bfd *, void * )) bfd_true), | |
cf9ab45b AM |
4154 | |
4155 | /* Core */ | |
4156 | coff_core_file_failing_command, | |
4157 | coff_core_file_failing_signal, | |
4158 | coff_core_file_matches_executable_p, | |
4159 | ||
4160 | /* Archive */ | |
4161 | _bfd_xcoff_slurp_armap, | |
dc810e39 | 4162 | bfd_false, |
b34976b6 | 4163 | ((bfd_boolean (*) (bfd *, char **, bfd_size_type *, const char **)) bfd_false), |
cf9ab45b AM |
4164 | bfd_dont_truncate_arname, |
4165 | _bfd_xcoff_write_armap, | |
4166 | _bfd_xcoff_read_ar_hdr, | |
4167 | _bfd_xcoff_openr_next_archived_file, | |
4168 | _bfd_generic_get_elt_at_index, | |
4169 | _bfd_xcoff_stat_arch_elt, | |
4170 | bfd_true, | |
4171 | ||
4172 | /* Symbols */ | |
4173 | coff_get_symtab_upper_bound, | |
6cee3f79 | 4174 | coff_canonicalize_symtab, |
cf9ab45b AM |
4175 | coff_make_empty_symbol, |
4176 | coff_print_symbol, | |
4177 | coff_get_symbol_info, | |
4178 | _bfd_xcoff_is_local_label_name, | |
7db6994f | 4179 | coff_bfd_is_target_special_symbol, |
cf9ab45b AM |
4180 | coff_get_lineno, |
4181 | coff_find_nearest_line, | |
4575b1b5 | 4182 | _bfd_generic_find_line, |
4ab527b0 | 4183 | coff_find_inliner_info, |
cf9ab45b AM |
4184 | coff_bfd_make_debug_symbol, |
4185 | _bfd_generic_read_minisymbols, | |
4186 | _bfd_generic_minisymbol_to_symbol, | |
4187 | ||
4188 | /* Reloc */ | |
4189 | coff_get_reloc_upper_bound, | |
4190 | coff_canonicalize_reloc, | |
4191 | _bfd_xcoff_reloc_type_lookup, | |
157090f7 | 4192 | _bfd_xcoff_reloc_name_lookup, |
cf9ab45b AM |
4193 | |
4194 | /* Write */ | |
4195 | coff_set_arch_mach, | |
4196 | coff_set_section_contents, | |
4197 | ||
4198 | /* Link */ | |
4199 | _bfd_xcoff_sizeof_headers, | |
4200 | bfd_generic_get_relocated_section_contents, | |
4201 | bfd_generic_relax_section, | |
4202 | _bfd_xcoff_bfd_link_hash_table_create, | |
4203 | _bfd_generic_link_hash_table_free, | |
4204 | _bfd_xcoff_bfd_link_add_symbols, | |
4205 | _bfd_generic_link_just_syms, | |
4206 | _bfd_xcoff_bfd_final_link, | |
4207 | _bfd_generic_link_split_section, | |
4208 | bfd_generic_gc_sections, | |
4209 | bfd_generic_merge_sections, | |
72adc230 | 4210 | bfd_generic_is_group_section, |
cf9ab45b | 4211 | bfd_generic_discard_group, |
082b7297 | 4212 | _bfd_generic_section_already_linked, |
cf9ab45b AM |
4213 | |
4214 | /* Dynamic */ | |
4215 | _bfd_xcoff_get_dynamic_symtab_upper_bound, | |
4216 | _bfd_xcoff_canonicalize_dynamic_symtab, | |
4c45e5c9 | 4217 | _bfd_nodynamic_get_synthetic_symtab, |
cf9ab45b AM |
4218 | _bfd_xcoff_get_dynamic_reloc_upper_bound, |
4219 | _bfd_xcoff_canonicalize_dynamic_reloc, | |
4220 | ||
4221 | /* Opposite endian version, none exists */ | |
4222 | NULL, | |
4223 | ||
4224 | (void *) &bfd_xcoff_backend_data, | |
4225 | }; | |
beb1bf64 | 4226 | |
cf9ab45b AM |
4227 | /* xcoff-powermac target |
4228 | Old target. | |
4229 | Only difference between this target and the rs6000 target is the | |
4230 | the default architecture and machine type used in coffcode.h | |
4231 | ||
4232 | PowerPC Macs use the same magic numbers as RS/6000 | |
4233 | (because that's how they were bootstrapped originally), | |
4234 | but they are always PowerPC architecture. */ | |
dc810e39 | 4235 | static const struct xcoff_backend_data_rec bfd_pmac_xcoff_backend_data = |
cf9ab45b AM |
4236 | { |
4237 | { /* COFF backend, defined in libcoff.h. */ | |
4238 | _bfd_xcoff_swap_aux_in, | |
4239 | _bfd_xcoff_swap_sym_in, | |
4240 | coff_swap_lineno_in, | |
4241 | _bfd_xcoff_swap_aux_out, | |
4242 | _bfd_xcoff_swap_sym_out, | |
4243 | coff_swap_lineno_out, | |
4244 | xcoff_swap_reloc_out, | |
4245 | coff_swap_filehdr_out, | |
4246 | coff_swap_aouthdr_out, | |
4247 | coff_swap_scnhdr_out, | |
4248 | FILHSZ, | |
4249 | AOUTSZ, | |
4250 | SCNHSZ, | |
4251 | SYMESZ, | |
4252 | AUXESZ, | |
4253 | RELSZ, | |
4254 | LINESZ, | |
4255 | FILNMLEN, | |
b34976b6 AM |
4256 | TRUE, /* _bfd_coff_long_filenames */ |
4257 | FALSE, /* _bfd_coff_long_section_names */ | |
cf9ab45b | 4258 | 3, /* _bfd_coff_default_section_alignment_power */ |
b34976b6 | 4259 | FALSE, /* _bfd_coff_force_symnames_in_strings */ |
cf9ab45b AM |
4260 | 2, /* _bfd_coff_debug_string_prefix_length */ |
4261 | coff_swap_filehdr_in, | |
4262 | coff_swap_aouthdr_in, | |
4263 | coff_swap_scnhdr_in, | |
4264 | xcoff_swap_reloc_in, | |
4265 | coff_bad_format_hook, | |
4266 | coff_set_arch_mach_hook, | |
4267 | coff_mkobject_hook, | |
4268 | styp_to_sec_flags, | |
4269 | coff_set_alignment_hook, | |
4270 | coff_slurp_symbol_table, | |
4271 | symname_in_debug_hook, | |
4272 | coff_pointerize_aux_hook, | |
4273 | coff_print_aux, | |
4274 | dummy_reloc16_extra_cases, | |
4275 | dummy_reloc16_estimate, | |
4276 | NULL, /* bfd_coff_sym_is_global */ | |
4277 | coff_compute_section_file_positions, | |
4278 | NULL, /* _bfd_coff_start_final_link */ | |
4279 | xcoff_ppc_relocate_section, | |
4280 | coff_rtype_to_howto, | |
4281 | NULL, /* _bfd_coff_adjust_symndx */ | |
4282 | _bfd_generic_link_add_one_symbol, | |
4283 | coff_link_output_has_begun, | |
4284 | coff_final_link_postscript | |
4285 | }, | |
4286 | ||
4287 | 0x01DF, /* magic number */ | |
4288 | bfd_arch_powerpc, | |
4289 | bfd_mach_ppc, | |
4290 | ||
4291 | /* Function pointers to xcoff specific swap routines. */ | |
4292 | xcoff_swap_ldhdr_in, | |
4293 | xcoff_swap_ldhdr_out, | |
4294 | xcoff_swap_ldsym_in, | |
4295 | xcoff_swap_ldsym_out, | |
4296 | xcoff_swap_ldrel_in, | |
4297 | xcoff_swap_ldrel_out, | |
4298 | ||
4299 | /* Sizes. */ | |
4300 | LDHDRSZ, | |
4301 | LDSYMSZ, | |
4302 | LDRELSZ, | |
4303 | 12, /* _xcoff_function_descriptor_size */ | |
4304 | SMALL_AOUTSZ, | |
4305 | ||
4306 | /* Versions. */ | |
4307 | 1, /* _xcoff_ldhdr_version */ | |
4308 | ||
4309 | _bfd_xcoff_put_symbol_name, | |
4310 | _bfd_xcoff_put_ldsymbol_name, | |
4311 | &xcoff_dynamic_reloc, | |
4312 | xcoff_create_csect_from_smclas, | |
4313 | ||
4314 | /* Lineno and reloc count overflow. */ | |
4315 | xcoff_is_lineno_count_overflow, | |
4316 | xcoff_is_reloc_count_overflow, | |
4317 | ||
4318 | xcoff_loader_symbol_offset, | |
4319 | xcoff_loader_reloc_offset, | |
beb1bf64 | 4320 | |
cf9ab45b AM |
4321 | /* glink. */ |
4322 | &xcoff_glink_code[0], | |
4323 | 36, /* _xcoff_glink_size */ | |
4324 | ||
4325 | /* rtinit */ | |
4326 | 0, /* _xcoff_rtinit_size */ | |
4327 | xcoff_generate_rtinit, | |
4328 | }; | |
4329 | ||
4330 | /* The transfer vector that leads the outside world to all of the above. */ | |
beb1bf64 | 4331 | const bfd_target pmac_xcoff_vec = |
cf9ab45b AM |
4332 | { |
4333 | "xcoff-powermac", | |
4334 | bfd_target_xcoff_flavour, | |
4335 | BFD_ENDIAN_BIG, /* data byte order is big */ | |
4336 | BFD_ENDIAN_BIG, /* header byte order is big */ | |
4337 | ||
4338 | (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | DYNAMIC | |
4339 | | HAS_SYMS | HAS_LOCALS | WP_TEXT), | |
4340 | ||
a7c71b0c | 4341 | SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA, |
cf9ab45b AM |
4342 | 0, /* leading char */ |
4343 | '/', /* ar_pad_char */ | |
4344 | 15, /* ar_max_namelen */ | |
4345 | ||
4346 | /* data */ | |
4347 | bfd_getb64, | |
4348 | bfd_getb_signed_64, | |
4349 | bfd_putb64, | |
4350 | bfd_getb32, | |
4351 | bfd_getb_signed_32, | |
4352 | bfd_putb32, | |
4353 | bfd_getb16, | |
4354 | bfd_getb_signed_16, | |
4355 | bfd_putb16, | |
4356 | ||
4357 | /* hdrs */ | |
4358 | bfd_getb64, | |
4359 | bfd_getb_signed_64, | |
4360 | bfd_putb64, | |
4361 | bfd_getb32, | |
4362 | bfd_getb_signed_32, | |
4363 | bfd_putb32, | |
4364 | bfd_getb16, | |
4365 | bfd_getb_signed_16, | |
4366 | bfd_putb16, | |
4367 | ||
4368 | { /* bfd_check_format */ | |
4369 | _bfd_dummy_target, | |
4370 | coff_object_p, | |
4371 | _bfd_xcoff_archive_p, | |
4372 | CORE_FILE_P | |
4373 | }, | |
4374 | ||
4375 | { /* bfd_set_format */ | |
4376 | bfd_false, | |
4377 | coff_mkobject, | |
4378 | _bfd_generic_mkarchive, | |
4379 | bfd_false | |
4380 | }, | |
4381 | ||
4382 | {/* bfd_write_contents */ | |
4383 | bfd_false, | |
4384 | coff_write_object_contents, | |
4385 | _bfd_xcoff_write_archive_contents, | |
4386 | bfd_false | |
4387 | }, | |
dc810e39 | 4388 | |
cf9ab45b AM |
4389 | /* Generic */ |
4390 | bfd_true, | |
4391 | bfd_true, | |
4392 | coff_new_section_hook, | |
4393 | _bfd_generic_get_section_contents, | |
4394 | _bfd_generic_get_section_contents_in_window, | |
4395 | ||
4396 | /* Copy */ | |
4397 | _bfd_xcoff_copy_private_bfd_data, | |
b34976b6 | 4398 | ((bfd_boolean (*) (bfd *, bfd *)) bfd_true), |
60b48850 | 4399 | _bfd_generic_init_private_section_data, |
b34976b6 AM |
4400 | ((bfd_boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true), |
4401 | ((bfd_boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true), | |
80fccad2 | 4402 | ((bfd_boolean (*) (bfd *, bfd *)) bfd_true), |
b34976b6 AM |
4403 | ((bfd_boolean (*) (bfd *, flagword)) bfd_true), |
4404 | ((bfd_boolean (*) (bfd *, void * )) bfd_true), | |
cf9ab45b AM |
4405 | |
4406 | /* Core */ | |
4407 | coff_core_file_failing_command, | |
4408 | coff_core_file_failing_signal, | |
4409 | coff_core_file_matches_executable_p, | |
4410 | ||
4411 | /* Archive */ | |
4412 | _bfd_xcoff_slurp_armap, | |
dc810e39 | 4413 | bfd_false, |
b34976b6 | 4414 | ((bfd_boolean (*) (bfd *, char **, bfd_size_type *, const char **)) bfd_false), |
cf9ab45b AM |
4415 | bfd_dont_truncate_arname, |
4416 | _bfd_xcoff_write_armap, | |
4417 | _bfd_xcoff_read_ar_hdr, | |
4418 | _bfd_xcoff_openr_next_archived_file, | |
4419 | _bfd_generic_get_elt_at_index, | |
4420 | _bfd_xcoff_stat_arch_elt, | |
4421 | bfd_true, | |
4422 | ||
4423 | /* Symbols */ | |
4424 | coff_get_symtab_upper_bound, | |
6cee3f79 | 4425 | coff_canonicalize_symtab, |
cf9ab45b AM |
4426 | coff_make_empty_symbol, |
4427 | coff_print_symbol, | |
4428 | coff_get_symbol_info, | |
4429 | _bfd_xcoff_is_local_label_name, | |
7db6994f | 4430 | coff_bfd_is_target_special_symbol, |
cf9ab45b AM |
4431 | coff_get_lineno, |
4432 | coff_find_nearest_line, | |
4575b1b5 | 4433 | _bfd_generic_find_line, |
4ab527b0 | 4434 | coff_find_inliner_info, |
cf9ab45b AM |
4435 | coff_bfd_make_debug_symbol, |
4436 | _bfd_generic_read_minisymbols, | |
4437 | _bfd_generic_minisymbol_to_symbol, | |
4438 | ||
4439 | /* Reloc */ | |
4440 | coff_get_reloc_upper_bound, | |
4441 | coff_canonicalize_reloc, | |
4442 | _bfd_xcoff_reloc_type_lookup, | |
157090f7 | 4443 | _bfd_xcoff_reloc_name_lookup, |
cf9ab45b AM |
4444 | |
4445 | /* Write */ | |
4446 | coff_set_arch_mach, | |
4447 | coff_set_section_contents, | |
4448 | ||
4449 | /* Link */ | |
4450 | _bfd_xcoff_sizeof_headers, | |
4451 | bfd_generic_get_relocated_section_contents, | |
4452 | bfd_generic_relax_section, | |
4453 | _bfd_xcoff_bfd_link_hash_table_create, | |
4454 | _bfd_generic_link_hash_table_free, | |
4455 | _bfd_xcoff_bfd_link_add_symbols, | |
4456 | _bfd_generic_link_just_syms, | |
4457 | _bfd_xcoff_bfd_final_link, | |
4458 | _bfd_generic_link_split_section, | |
4459 | bfd_generic_gc_sections, | |
4460 | bfd_generic_merge_sections, | |
72adc230 | 4461 | bfd_generic_is_group_section, |
cf9ab45b | 4462 | bfd_generic_discard_group, |
082b7297 | 4463 | _bfd_generic_section_already_linked, |
cf9ab45b AM |
4464 | |
4465 | /* Dynamic */ | |
4466 | _bfd_xcoff_get_dynamic_symtab_upper_bound, | |
4467 | _bfd_xcoff_canonicalize_dynamic_symtab, | |
4c45e5c9 | 4468 | _bfd_nodynamic_get_synthetic_symtab, |
cf9ab45b AM |
4469 | _bfd_xcoff_get_dynamic_reloc_upper_bound, |
4470 | _bfd_xcoff_canonicalize_dynamic_reloc, | |
4471 | ||
4472 | /* Opposite endian version, none exists */ | |
4473 | NULL, | |
4474 | ||
4475 | (void *) &bfd_pmac_xcoff_backend_data, | |
4476 | }; |