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