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