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