Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* BFD back-end for IBM RS/6000 "XCOFF" files. |
7898deda NC |
2 | Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, |
3 | 2000, 2001 | |
5f771d47 | 4 | Free Software Foundation, Inc. |
252b5132 RH |
5 | FIXME: Can someone provide a transliteration of this name into ASCII? |
6 | Using the following chars caused a compiler warning on HIUX (so I replaced | |
7 | them with octal escapes), and isn't useful without an understanding of what | |
8 | character set it is. | |
c5930ee6 | 9 | Written by Metin G. Ozisik, Mimi Ph\373\364ng-Th\345o V\365, |
252b5132 RH |
10 | and John Gilmore. |
11 | Archive support from Damon A. Permezel. | |
12 | Contributed by IBM Corporation and Cygnus Support. | |
13 | ||
14 | This file is part of BFD, the Binary File Descriptor library. | |
15 | ||
16 | This program is free software; you can redistribute it and/or modify | |
17 | it under the terms of the GNU General Public License as published by | |
18 | the Free Software Foundation; either version 2 of the License, or | |
19 | (at your option) any later version. | |
20 | ||
21 | This program is distributed in the hope that it will be useful, | |
22 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24 | GNU General Public License for more details. | |
25 | ||
26 | You should have received a copy of the GNU General Public License | |
27 | along with this program; if not, write to the Free Software | |
28 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
29 | ||
252b5132 RH |
30 | #include "bfd.h" |
31 | #include "sysdep.h" | |
beb1bf64 | 32 | #include "bfdlink.h" |
252b5132 RH |
33 | #include "libbfd.h" |
34 | #include "coff/internal.h" | |
beb1bf64 | 35 | #include "coff/xcoff.h" |
252b5132 RH |
36 | #include "coff/rs6000.h" |
37 | #include "libcoff.h" | |
beb1bf64 TR |
38 | #include "libxcoff.h" |
39 | ||
beb1bf64 TR |
40 | extern boolean _bfd_xcoff_mkobject PARAMS ((bfd *)); |
41 | extern boolean _bfd_xcoff_copy_private_bfd_data PARAMS ((bfd *, bfd *)); | |
42 | extern boolean _bfd_xcoff_is_local_label_name PARAMS ((bfd *, const char *)); | |
43 | extern reloc_howto_type *_bfd_xcoff_reloc_type_lookup | |
44 | PARAMS ((bfd *, bfd_reloc_code_real_type)); | |
45 | extern boolean _bfd_xcoff_slurp_armap PARAMS ((bfd *)); | |
46 | extern const bfd_target *_bfd_xcoff_archive_p PARAMS ((bfd *)); | |
47 | extern PTR _bfd_xcoff_read_ar_hdr PARAMS ((bfd *)); | |
48 | extern bfd *_bfd_xcoff_openr_next_archived_file PARAMS ((bfd *, bfd *)); | |
49 | extern int _bfd_xcoff_generic_stat_arch_elt PARAMS ((bfd *, struct stat *)); | |
50 | extern boolean _bfd_xcoff_write_armap | |
51 | PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int)); | |
52 | extern boolean _bfd_xcoff_write_archive_contents PARAMS ((bfd *)); | |
53 | extern int _bfd_xcoff_sizeof_headers PARAMS ((bfd *, boolean)); | |
54 | extern void _bfd_xcoff_swap_sym_in PARAMS ((bfd *, PTR, PTR)); | |
55 | extern unsigned int _bfd_xcoff_swap_sym_out PARAMS ((bfd *, PTR, PTR)); | |
56 | extern void _bfd_xcoff_swap_aux_in PARAMS ((bfd *, PTR, int, int, int, int, PTR)); | |
57 | extern unsigned int _bfd_xcoff_swap_aux_out PARAMS ((bfd *, PTR, int, int, int, int, PTR)); | |
58 | ||
59 | /* Forward declare _bfd_xcoff_rtype2howto for coffcode.h macro */ | |
60 | void _bfd_xcoff_rtype2howto PARAMS ((arelent *, struct internal_reloc *)); | |
61 | ||
62 | /* coffcode.h needs these to be defined */ | |
63 | #define RS6000COFF_C 1 | |
64 | ||
65 | #define SELECT_RELOC(internal, howto) \ | |
66 | { \ | |
67 | internal.r_type = howto->type; \ | |
68 | internal.r_size = \ | |
69 | ((howto->complain_on_overflow == complain_overflow_signed \ | |
70 | ? 0x80 \ | |
71 | : 0) \ | |
72 | | (howto->bitsize - 1)); \ | |
73 | } | |
74 | ||
75 | #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3) | |
76 | #define COFF_LONG_FILENAMES | |
77 | #define NO_COFF_SYMBOLS | |
78 | #define RTYPE2HOWTO(cache_ptr, dst) _bfd_xcoff_rtype2howto (cache_ptr, dst) | |
79 | #define coff_mkobject _bfd_xcoff_mkobject | |
80 | #define coff_bfd_copy_private_bfd_data _bfd_xcoff_copy_private_bfd_data | |
81 | #define coff_bfd_is_local_label_name _bfd_xcoff_is_local_label_name | |
82 | #define coff_bfd_reloc_type_lookup _bfd_xcoff_reloc_type_lookup | |
b55039f4 L |
83 | #ifdef AIX_CORE |
84 | extern const bfd_target * rs6000coff_core_p (); | |
85 | extern boolean rs6000coff_core_file_matches_executable_p (); | |
86 | extern char *rs6000coff_core_file_failing_command PARAMS ((bfd *abfd)); | |
87 | extern int rs6000coff_core_file_failing_signal PARAMS ((bfd *abfd)); | |
beb1bf64 | 88 | #define CORE_FILE_P rs6000coff_core_p |
b55039f4 L |
89 | #define coff_core_file_failing_command \ |
90 | rs6000coff_core_file_failing_command | |
91 | #define coff_core_file_failing_signal \ | |
92 | rs6000coff_core_file_failing_signal | |
93 | #define coff_core_file_matches_executable_p \ | |
94 | rs6000coff_core_file_matches_executable_p | |
95 | #else | |
96 | #define CORE_FILE_P _bfd_dummy_target | |
97 | #define coff_core_file_failing_command \ | |
98 | _bfd_nocore_core_file_failing_command | |
99 | #define coff_core_file_failing_signal \ | |
100 | _bfd_nocore_core_file_failing_signal | |
101 | #define coff_core_file_matches_executable_p \ | |
102 | _bfd_nocore_core_file_matches_executable_p | |
103 | #endif | |
beb1bf64 TR |
104 | #define coff_SWAP_sym_in _bfd_xcoff_swap_sym_in |
105 | #define coff_SWAP_sym_out _bfd_xcoff_swap_sym_out | |
106 | #define coff_SWAP_aux_in _bfd_xcoff_swap_aux_in | |
107 | #define coff_SWAP_aux_out _bfd_xcoff_swap_aux_out | |
108 | ||
109 | #include "coffcode.h" | |
14958a43 | 110 | |
252b5132 RH |
111 | /* The main body of code is in coffcode.h. */ |
112 | ||
252b5132 | 113 | static const char *normalize_filename PARAMS ((bfd *)); |
a7b97311 AM |
114 | static boolean xcoff_write_armap_old |
115 | PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int)); | |
116 | static boolean xcoff_write_one_armap_big | |
117 | PARAMS ((bfd *, struct orl *, unsigned int, unsigned int, unsigned int, | |
118 | int, const char *, char *)); | |
119 | static boolean xcoff_write_armap_big | |
120 | PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int)); | |
121 | static boolean xcoff_write_archive_contents_old PARAMS ((bfd *)); | |
122 | static boolean xcoff_write_archive_contents_big PARAMS ((bfd *)); | |
123 | static void xcoff_swap_ldhdr_in | |
124 | PARAMS ((bfd *, const struct external_ldhdr *, struct internal_ldhdr *)); | |
125 | static void xcoff_swap_ldhdr_out | |
126 | PARAMS ((bfd *, const struct internal_ldhdr *, struct external_ldhdr *)); | |
127 | static void xcoff_swap_ldsym_in | |
128 | PARAMS ((bfd *, const struct external_ldsym *, struct internal_ldsym *)); | |
129 | static void xcoff_swap_ldsym_out | |
130 | PARAMS ((bfd *, const struct internal_ldsym *, struct external_ldsym *)); | |
131 | static void xcoff_swap_ldrel_in | |
132 | PARAMS ((bfd *, const struct external_ldrel *, struct internal_ldrel *)); | |
133 | static void xcoff_swap_ldrel_out | |
134 | PARAMS ((bfd *, const struct internal_ldrel *, struct external_ldrel *)); | |
135 | static boolean xcoff_ppc_relocate_section | |
136 | PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, | |
137 | struct internal_reloc *, struct internal_syment *, asection **)); | |
138 | static boolean _bfd_xcoff_put_ldsymbol_name | |
139 | PARAMS ((bfd *, struct xcoff_loader_info *, struct internal_ldsym *, | |
140 | const char *)); | |
141 | static asection *xcoff_create_csect_from_smclas | |
142 | PARAMS ((bfd *, union internal_auxent *, char *)); | |
143 | static boolean xcoff_is_lineno_count_overflow PARAMS ((bfd *, bfd_vma)); | |
144 | static boolean xcoff_is_reloc_count_overflow PARAMS ((bfd *, bfd_vma)); | |
145 | static bfd_vma xcoff_loader_symbol_offset | |
146 | PARAMS ((bfd *, struct internal_ldhdr *)); | |
147 | static bfd_vma xcoff_loader_reloc_offset | |
148 | PARAMS ((bfd *, struct internal_ldhdr *)); | |
14958a43 | 149 | |
252b5132 RH |
150 | /* We use our own tdata type. Its first field is the COFF tdata type, |
151 | so the COFF routines are compatible. */ | |
152 | ||
7f6d05e8 CP |
153 | boolean |
154 | _bfd_xcoff_mkobject (abfd) | |
252b5132 RH |
155 | bfd *abfd; |
156 | { | |
157 | coff_data_type *coff; | |
158 | ||
159 | abfd->tdata.xcoff_obj_data = | |
160 | ((struct xcoff_tdata *) | |
161 | bfd_zalloc (abfd, sizeof (struct xcoff_tdata))); | |
162 | if (abfd->tdata.xcoff_obj_data == NULL) | |
163 | return false; | |
164 | coff = coff_data (abfd); | |
165 | coff->symbols = (coff_symbol_type *) NULL; | |
166 | coff->conversion_table = (unsigned int *) NULL; | |
167 | coff->raw_syments = (struct coff_ptr_struct *) NULL; | |
168 | coff->relocbase = 0; | |
169 | ||
170 | xcoff_data (abfd)->modtype = ('1' << 8) | 'L'; | |
171 | ||
172 | /* We set cputype to -1 to indicate that it has not been | |
173 | initialized. */ | |
174 | xcoff_data (abfd)->cputype = -1; | |
175 | ||
176 | xcoff_data (abfd)->csects = NULL; | |
177 | xcoff_data (abfd)->debug_indices = NULL; | |
178 | ||
beb1bf64 TR |
179 | /* text section alignment is different than the default */ |
180 | /* xcoff_data (abfd)->text_align_power = 5; */ | |
181 | ||
252b5132 RH |
182 | return true; |
183 | } | |
184 | ||
185 | /* Copy XCOFF data from one BFD to another. */ | |
186 | ||
7f6d05e8 CP |
187 | boolean |
188 | _bfd_xcoff_copy_private_bfd_data (ibfd, obfd) | |
252b5132 RH |
189 | bfd *ibfd; |
190 | bfd *obfd; | |
191 | { | |
192 | struct xcoff_tdata *ix, *ox; | |
193 | asection *sec; | |
194 | ||
195 | if (ibfd->xvec != obfd->xvec) | |
196 | return true; | |
197 | ix = xcoff_data (ibfd); | |
198 | ox = xcoff_data (obfd); | |
199 | ox->full_aouthdr = ix->full_aouthdr; | |
200 | ox->toc = ix->toc; | |
201 | if (ix->sntoc == 0) | |
202 | ox->sntoc = 0; | |
203 | else | |
204 | { | |
205 | sec = coff_section_from_bfd_index (ibfd, ix->sntoc); | |
206 | if (sec == NULL) | |
207 | ox->sntoc = 0; | |
208 | else | |
209 | ox->sntoc = sec->output_section->target_index; | |
210 | } | |
211 | if (ix->snentry == 0) | |
212 | ox->snentry = 0; | |
213 | else | |
214 | { | |
215 | sec = coff_section_from_bfd_index (ibfd, ix->snentry); | |
216 | if (sec == NULL) | |
217 | ox->snentry = 0; | |
218 | else | |
219 | ox->snentry = sec->output_section->target_index; | |
220 | } | |
221 | ox->text_align_power = ix->text_align_power; | |
222 | ox->data_align_power = ix->data_align_power; | |
223 | ox->modtype = ix->modtype; | |
224 | ox->cputype = ix->cputype; | |
225 | ox->maxdata = ix->maxdata; | |
226 | ox->maxstack = ix->maxstack; | |
227 | return true; | |
228 | } | |
229 | ||
230 | /* I don't think XCOFF really has a notion of local labels based on | |
231 | name. This will mean that ld -X doesn't actually strip anything. | |
232 | The AIX native linker does not have a -X option, and it ignores the | |
233 | -x option. */ | |
234 | ||
7f6d05e8 CP |
235 | boolean |
236 | _bfd_xcoff_is_local_label_name (abfd, name) | |
5f771d47 ILT |
237 | bfd *abfd ATTRIBUTE_UNUSED; |
238 | const char *name ATTRIBUTE_UNUSED; | |
252b5132 RH |
239 | { |
240 | return false; | |
241 | } | |
7f6d05e8 | 242 | \f |
beb1bf64 TR |
243 | |
244 | ||
14958a43 CP |
245 | void |
246 | _bfd_xcoff_swap_sym_in (abfd, ext1, in1) | |
7f6d05e8 CP |
247 | bfd *abfd; |
248 | PTR ext1; | |
249 | PTR in1; | |
250 | { | |
251 | SYMENT *ext = (SYMENT *)ext1; | |
252 | struct internal_syment *in = (struct internal_syment *)in1; | |
253 | ||
beb1bf64 TR |
254 | if(ext->e.e_name[0] != 0) { |
255 | memcpy(in->_n._n_name, ext->e.e_name, SYMNMLEN); | |
256 | } else { | |
257 | in->_n._n_n._n_zeroes = 0; | |
258 | in->_n._n_n._n_offset = | |
259 | bfd_h_get_32(abfd, (bfd_byte *) ext->e.e.e_offset); | |
260 | } | |
7f6d05e8 | 261 | |
beb1bf64 | 262 | in->n_value = bfd_h_get_32(abfd, (bfd_byte *) ext->e_value); |
7f6d05e8 CP |
263 | in->n_scnum = bfd_h_get_16(abfd, (bfd_byte *) ext->e_scnum); |
264 | in->n_type = bfd_h_get_16(abfd, (bfd_byte *) ext->e_type); | |
265 | in->n_sclass = bfd_h_get_8(abfd, ext->e_sclass); | |
266 | in->n_numaux = bfd_h_get_8(abfd, ext->e_numaux); | |
267 | } | |
268 | ||
14958a43 CP |
269 | unsigned int |
270 | _bfd_xcoff_swap_sym_out (abfd, inp, extp) | |
7f6d05e8 CP |
271 | bfd *abfd; |
272 | PTR inp; | |
273 | PTR extp; | |
274 | { | |
275 | struct internal_syment *in = (struct internal_syment *)inp; | |
276 | SYMENT *ext =(SYMENT *)extp; | |
277 | ||
beb1bf64 TR |
278 | if(in->_n._n_name[0] != 0) { |
279 | memcpy(ext->e.e_name, in->_n._n_name, SYMNMLEN); | |
280 | } else { | |
281 | bfd_h_put_32(abfd, 0, (bfd_byte *) ext->e.e.e_zeroes); | |
282 | bfd_h_put_32(abfd, in->_n._n_n._n_offset, | |
283 | (bfd_byte *) ext->e.e.e_offset); | |
284 | } | |
7f6d05e8 CP |
285 | |
286 | bfd_h_put_32(abfd, in->n_value , (bfd_byte *) ext->e_value); | |
287 | bfd_h_put_16(abfd, in->n_scnum , (bfd_byte *) ext->e_scnum); | |
288 | bfd_h_put_16(abfd, in->n_type , (bfd_byte *) ext->e_type); | |
289 | bfd_h_put_8(abfd, in->n_sclass , ext->e_sclass); | |
290 | bfd_h_put_8(abfd, in->n_numaux , ext->e_numaux); | |
291 | return bfd_coff_symesz (abfd); | |
292 | } | |
293 | ||
294 | #define PUTWORD bfd_h_put_32 | |
295 | #define PUTHALF bfd_h_put_16 | |
296 | #define PUTBYTE bfd_h_put_8 | |
297 | #define GETWORD bfd_h_get_32 | |
298 | #define GETHALF bfd_h_get_16 | |
299 | #define GETBYTE bfd_h_get_8 | |
300 | ||
14958a43 CP |
301 | void |
302 | _bfd_xcoff_swap_aux_in (abfd, ext1, type, class, indx, numaux, in1) | |
7f6d05e8 CP |
303 | bfd *abfd; |
304 | PTR ext1; | |
305 | int type; | |
306 | int class; | |
307 | int indx; | |
308 | int numaux; | |
309 | PTR in1; | |
310 | { | |
311 | AUXENT *ext = (AUXENT *)ext1; | |
312 | union internal_auxent *in = (union internal_auxent *)in1; | |
313 | ||
314 | switch (class) { | |
315 | case C_FILE: | |
316 | if (ext->x_file.x_fname[0] == 0) { | |
317 | in->x_file.x_n.x_zeroes = 0; | |
beb1bf64 | 318 | in->x_file.x_n.x_offset = |
7f6d05e8 CP |
319 | bfd_h_get_32(abfd, (bfd_byte *) ext->x_file.x_n.x_offset); |
320 | } else { | |
321 | if (numaux > 1) | |
322 | { | |
323 | if (indx == 0) | |
324 | memcpy (in->x_file.x_fname, ext->x_file.x_fname, | |
325 | numaux * sizeof (AUXENT)); | |
326 | } | |
327 | else | |
328 | { | |
329 | memcpy (in->x_file.x_fname, ext->x_file.x_fname, FILNMLEN); | |
330 | } | |
331 | } | |
332 | goto end; | |
333 | ||
334 | /* RS/6000 "csect" auxents */ | |
335 | case C_EXT: | |
336 | case C_HIDEXT: | |
337 | if (indx + 1 == numaux) | |
338 | { | |
beb1bf64 | 339 | in->x_csect.x_scnlen.l = |
7f6d05e8 CP |
340 | bfd_h_get_32 (abfd, ext->x_csect.x_scnlen); |
341 | in->x_csect.x_parmhash = bfd_h_get_32 (abfd, | |
342 | ext->x_csect.x_parmhash); | |
343 | in->x_csect.x_snhash = bfd_h_get_16 (abfd, ext->x_csect.x_snhash); | |
344 | /* We don't have to hack bitfields in x_smtyp because it's | |
345 | defined by shifts-and-ands, which are equivalent on all | |
346 | byte orders. */ | |
347 | in->x_csect.x_smtyp = bfd_h_get_8 (abfd, ext->x_csect.x_smtyp); | |
348 | in->x_csect.x_smclas = bfd_h_get_8 (abfd, ext->x_csect.x_smclas); | |
349 | in->x_csect.x_stab = bfd_h_get_32 (abfd, ext->x_csect.x_stab); | |
350 | in->x_csect.x_snstab = bfd_h_get_16 (abfd, ext->x_csect.x_snstab); | |
351 | goto end; | |
352 | } | |
353 | break; | |
354 | ||
355 | case C_STAT: | |
356 | case C_LEAFSTAT: | |
357 | case C_HIDDEN: | |
358 | if (type == T_NULL) { | |
beb1bf64 | 359 | in->x_scn.x_scnlen = bfd_h_get_32(abfd, |
7f6d05e8 | 360 | (bfd_byte *) ext->x_scn.x_scnlen); |
beb1bf64 | 361 | in->x_scn.x_nreloc = bfd_h_get_16(abfd, |
7f6d05e8 | 362 | (bfd_byte *) ext->x_scn.x_nreloc); |
beb1bf64 | 363 | in->x_scn.x_nlinno = bfd_h_get_16(abfd, |
7f6d05e8 CP |
364 | (bfd_byte *) ext->x_scn.x_nlinno); |
365 | /* PE defines some extra fields; we zero them out for | |
366 | safety. */ | |
367 | in->x_scn.x_checksum = 0; | |
368 | in->x_scn.x_associated = 0; | |
369 | in->x_scn.x_comdat = 0; | |
370 | ||
371 | goto end; | |
372 | } | |
373 | break; | |
374 | } | |
375 | ||
376 | in->x_sym.x_tagndx.l = bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_tagndx); | |
377 | in->x_sym.x_tvndx = bfd_h_get_16(abfd, (bfd_byte *) ext->x_sym.x_tvndx); | |
378 | ||
379 | if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class)) | |
380 | { | |
381 | in->x_sym.x_fcnary.x_fcn.x_lnnoptr = bfd_h_get_32(abfd, (bfd_byte *) | |
382 | ext->x_sym.x_fcnary.x_fcn.x_lnnoptr); | |
383 | in->x_sym.x_fcnary.x_fcn.x_endndx.l = bfd_h_get_32(abfd, (bfd_byte *) | |
384 | ext->x_sym.x_fcnary.x_fcn.x_endndx); | |
385 | } | |
386 | else | |
387 | { | |
388 | in->x_sym.x_fcnary.x_ary.x_dimen[0] = | |
389 | bfd_h_get_16 (abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[0]); | |
390 | in->x_sym.x_fcnary.x_ary.x_dimen[1] = | |
391 | bfd_h_get_16 (abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[1]); | |
392 | in->x_sym.x_fcnary.x_ary.x_dimen[2] = | |
393 | bfd_h_get_16 (abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[2]); | |
394 | in->x_sym.x_fcnary.x_ary.x_dimen[3] = | |
395 | bfd_h_get_16 (abfd, (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[3]); | |
396 | } | |
397 | if (ISFCN(type)) { | |
398 | in->x_sym.x_misc.x_fsize = bfd_h_get_32(abfd, (bfd_byte *) ext->x_sym.x_misc.x_fsize); | |
399 | } | |
400 | else { | |
401 | in->x_sym.x_misc.x_lnsz.x_lnno = bfd_h_get_16(abfd, (bfd_byte *) | |
402 | ext->x_sym.x_misc.x_lnsz.x_lnno); | |
403 | in->x_sym.x_misc.x_lnsz.x_size = bfd_h_get_16(abfd, (bfd_byte *) | |
404 | ext->x_sym.x_misc.x_lnsz.x_size); | |
405 | } | |
406 | ||
407 | end: ; | |
408 | /* the semicolon is because MSVC doesn't like labels at | |
beb1bf64 | 409 | end of block. */ |
7f6d05e8 CP |
410 | |
411 | } | |
412 | ||
beb1bf64 TR |
413 | |
414 | ||
14958a43 CP |
415 | unsigned int |
416 | _bfd_xcoff_swap_aux_out (abfd, inp, type, class, indx, numaux, extp) | |
7f6d05e8 CP |
417 | bfd *abfd; |
418 | PTR inp; | |
419 | int type; | |
420 | int class; | |
421 | int indx ATTRIBUTE_UNUSED; | |
422 | int numaux ATTRIBUTE_UNUSED; | |
423 | PTR extp; | |
424 | { | |
425 | union internal_auxent *in = (union internal_auxent *)inp; | |
426 | AUXENT *ext = (AUXENT *)extp; | |
427 | ||
428 | memset((PTR)ext, 0, bfd_coff_auxesz (abfd)); | |
429 | switch (class) | |
430 | { | |
431 | case C_FILE: | |
432 | if (in->x_file.x_fname[0] == 0) | |
433 | { | |
434 | PUTWORD(abfd, 0, (bfd_byte *) ext->x_file.x_n.x_zeroes); | |
435 | PUTWORD(abfd, | |
436 | in->x_file.x_n.x_offset, | |
437 | (bfd_byte *) ext->x_file.x_n.x_offset); | |
438 | } | |
439 | else | |
440 | { | |
441 | memcpy (ext->x_file.x_fname, in->x_file.x_fname, FILNMLEN); | |
442 | } | |
443 | goto end; | |
444 | ||
445 | /* RS/6000 "csect" auxents */ | |
446 | case C_EXT: | |
447 | case C_HIDEXT: | |
448 | if (indx + 1 == numaux) | |
449 | { | |
450 | PUTWORD (abfd, in->x_csect.x_scnlen.l,ext->x_csect.x_scnlen); | |
451 | PUTWORD (abfd, in->x_csect.x_parmhash, ext->x_csect.x_parmhash); | |
452 | PUTHALF (abfd, in->x_csect.x_snhash, ext->x_csect.x_snhash); | |
453 | /* We don't have to hack bitfields in x_smtyp because it's | |
454 | defined by shifts-and-ands, which are equivalent on all | |
455 | byte orders. */ | |
456 | PUTBYTE (abfd, in->x_csect.x_smtyp, ext->x_csect.x_smtyp); | |
457 | PUTBYTE (abfd, in->x_csect.x_smclas, ext->x_csect.x_smclas); | |
458 | PUTWORD (abfd, in->x_csect.x_stab, ext->x_csect.x_stab); | |
459 | PUTHALF (abfd, in->x_csect.x_snstab, ext->x_csect.x_snstab); | |
460 | goto end; | |
461 | } | |
462 | break; | |
463 | ||
464 | case C_STAT: | |
465 | case C_LEAFSTAT: | |
466 | case C_HIDDEN: | |
467 | if (type == T_NULL) { | |
468 | bfd_h_put_32(abfd, in->x_scn.x_scnlen, (bfd_byte *) ext->x_scn.x_scnlen); | |
469 | bfd_h_put_16(abfd, in->x_scn.x_nreloc, (bfd_byte *) ext->x_scn.x_nreloc); | |
470 | bfd_h_put_16(abfd, in->x_scn.x_nlinno, (bfd_byte *) ext->x_scn.x_nlinno); | |
471 | goto end; | |
472 | } | |
473 | break; | |
474 | } | |
475 | ||
476 | PUTWORD(abfd, in->x_sym.x_tagndx.l, (bfd_byte *) ext->x_sym.x_tagndx); | |
492055e6 | 477 | bfd_h_put_16 (abfd, in->x_sym.x_tvndx , (bfd_byte *) ext->x_sym.x_tvndx); |
7f6d05e8 CP |
478 | |
479 | if (class == C_BLOCK || class == C_FCN || ISFCN (type) || ISTAG (class)) | |
480 | { | |
beb1bf64 | 481 | bfd_h_put_32(abfd, in->x_sym.x_fcnary.x_fcn.x_lnnoptr, |
7f6d05e8 | 482 | (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_lnnoptr); |
beb1bf64 | 483 | PUTWORD(abfd, in->x_sym.x_fcnary.x_fcn.x_endndx.l, |
7f6d05e8 CP |
484 | (bfd_byte *) ext->x_sym.x_fcnary.x_fcn.x_endndx); |
485 | } | |
486 | else | |
487 | { | |
488 | bfd_h_put_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[0], | |
489 | (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[0]); | |
490 | bfd_h_put_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[1], | |
491 | (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[1]); | |
492 | bfd_h_put_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[2], | |
493 | (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[2]); | |
494 | bfd_h_put_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[3], | |
495 | (bfd_byte *) ext->x_sym.x_fcnary.x_ary.x_dimen[3]); | |
496 | } | |
497 | ||
498 | if (ISFCN (type)) | |
499 | PUTWORD (abfd, in->x_sym.x_misc.x_fsize, | |
500 | (bfd_byte *) ext->x_sym.x_misc.x_fsize); | |
501 | else | |
502 | { | |
beb1bf64 | 503 | bfd_h_put_16(abfd, in->x_sym.x_misc.x_lnsz.x_lnno, |
7f6d05e8 | 504 | (bfd_byte *)ext->x_sym.x_misc.x_lnsz.x_lnno); |
beb1bf64 | 505 | bfd_h_put_16(abfd, in->x_sym.x_misc.x_lnsz.x_size, |
7f6d05e8 CP |
506 | (bfd_byte *)ext->x_sym.x_misc.x_lnsz.x_size); |
507 | } | |
508 | ||
509 | end: | |
510 | return bfd_coff_auxesz (abfd); | |
511 | } | |
beb1bf64 TR |
512 | |
513 | ||
252b5132 RH |
514 | \f |
515 | /* The XCOFF reloc table. Actually, XCOFF relocations specify the | |
516 | bitsize and whether they are signed or not, along with a | |
517 | conventional type. This table is for the types, which are used for | |
518 | different algorithms for putting in the reloc. Many of these | |
519 | relocs need special_function entries, which I have not written. */ | |
520 | ||
7f6d05e8 CP |
521 | |
522 | reloc_howto_type xcoff_howto_table[] = | |
252b5132 RH |
523 | { |
524 | /* Standard 32 bit relocation. */ | |
c5930ee6 KH |
525 | HOWTO (0, /* type */ |
526 | 0, /* rightshift */ | |
527 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
528 | 32, /* bitsize */ | |
529 | false, /* pc_relative */ | |
530 | 0, /* bitpos */ | |
252b5132 | 531 | complain_overflow_bitfield, /* complain_on_overflow */ |
c5930ee6 KH |
532 | 0, /* special_function */ |
533 | "R_POS", /* name */ | |
534 | true, /* partial_inplace */ | |
535 | 0xffffffff, /* src_mask */ | |
536 | 0xffffffff, /* dst_mask */ | |
252b5132 RH |
537 | false), /* pcrel_offset */ |
538 | ||
539 | /* 32 bit relocation, but store negative value. */ | |
c5930ee6 KH |
540 | HOWTO (1, /* type */ |
541 | 0, /* rightshift */ | |
542 | -2, /* size (0 = byte, 1 = short, 2 = long) */ | |
543 | 32, /* bitsize */ | |
544 | false, /* pc_relative */ | |
545 | 0, /* bitpos */ | |
252b5132 | 546 | complain_overflow_bitfield, /* complain_on_overflow */ |
c5930ee6 KH |
547 | 0, /* special_function */ |
548 | "R_NEG", /* name */ | |
549 | true, /* partial_inplace */ | |
550 | 0xffffffff, /* src_mask */ | |
551 | 0xffffffff, /* dst_mask */ | |
252b5132 RH |
552 | false), /* pcrel_offset */ |
553 | ||
554 | /* 32 bit PC relative relocation. */ | |
c5930ee6 KH |
555 | HOWTO (2, /* type */ |
556 | 0, /* rightshift */ | |
557 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
558 | 32, /* bitsize */ | |
559 | true, /* pc_relative */ | |
560 | 0, /* bitpos */ | |
252b5132 | 561 | complain_overflow_signed, /* complain_on_overflow */ |
c5930ee6 KH |
562 | 0, /* special_function */ |
563 | "R_REL", /* name */ | |
564 | true, /* partial_inplace */ | |
565 | 0xffffffff, /* src_mask */ | |
566 | 0xffffffff, /* dst_mask */ | |
252b5132 | 567 | false), /* pcrel_offset */ |
c5930ee6 | 568 | |
252b5132 | 569 | /* 16 bit TOC relative relocation. */ |
c5930ee6 KH |
570 | HOWTO (3, /* type */ |
571 | 0, /* rightshift */ | |
572 | 1, /* size (0 = byte, 1 = short, 2 = long) */ | |
573 | 16, /* bitsize */ | |
574 | false, /* pc_relative */ | |
575 | 0, /* bitpos */ | |
252b5132 | 576 | complain_overflow_bitfield, /* complain_on_overflow */ |
c5930ee6 KH |
577 | 0, /* special_function */ |
578 | "R_TOC", /* name */ | |
579 | true, /* partial_inplace */ | |
580 | 0xffff, /* src_mask */ | |
581 | 0xffff, /* dst_mask */ | |
252b5132 | 582 | false), /* pcrel_offset */ |
c5930ee6 | 583 | |
252b5132 | 584 | /* I don't really know what this is. */ |
c5930ee6 KH |
585 | HOWTO (4, /* type */ |
586 | 1, /* rightshift */ | |
587 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
588 | 32, /* bitsize */ | |
589 | false, /* pc_relative */ | |
590 | 0, /* bitpos */ | |
252b5132 | 591 | complain_overflow_bitfield, /* complain_on_overflow */ |
c5930ee6 KH |
592 | 0, /* special_function */ |
593 | "R_RTB", /* name */ | |
594 | true, /* partial_inplace */ | |
595 | 0xffffffff, /* src_mask */ | |
596 | 0xffffffff, /* dst_mask */ | |
252b5132 | 597 | false), /* pcrel_offset */ |
c5930ee6 | 598 | |
252b5132 | 599 | /* External TOC relative symbol. */ |
c5930ee6 KH |
600 | HOWTO (5, /* type */ |
601 | 0, /* rightshift */ | |
602 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
603 | 16, /* bitsize */ | |
604 | false, /* pc_relative */ | |
605 | 0, /* bitpos */ | |
252b5132 | 606 | complain_overflow_bitfield, /* complain_on_overflow */ |
c5930ee6 KH |
607 | 0, /* special_function */ |
608 | "R_GL", /* name */ | |
609 | true, /* partial_inplace */ | |
610 | 0xffff, /* src_mask */ | |
611 | 0xffff, /* dst_mask */ | |
252b5132 | 612 | false), /* pcrel_offset */ |
c5930ee6 | 613 | |
252b5132 | 614 | /* Local TOC relative symbol. */ |
c5930ee6 KH |
615 | HOWTO (6, /* type */ |
616 | 0, /* rightshift */ | |
617 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
618 | 16, /* bitsize */ | |
619 | false, /* pc_relative */ | |
620 | 0, /* bitpos */ | |
252b5132 | 621 | complain_overflow_bitfield, /* complain_on_overflow */ |
c5930ee6 KH |
622 | 0, /* special_function */ |
623 | "R_TCL", /* name */ | |
624 | true, /* partial_inplace */ | |
625 | 0xffff, /* src_mask */ | |
626 | 0xffff, /* dst_mask */ | |
252b5132 | 627 | false), /* pcrel_offset */ |
c5930ee6 | 628 | |
5f771d47 | 629 | EMPTY_HOWTO (7), |
c5930ee6 | 630 | |
252b5132 | 631 | /* Non modifiable absolute branch. */ |
c5930ee6 KH |
632 | HOWTO (8, /* type */ |
633 | 0, /* rightshift */ | |
634 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
635 | 26, /* bitsize */ | |
636 | false, /* pc_relative */ | |
637 | 0, /* bitpos */ | |
252b5132 | 638 | complain_overflow_bitfield, /* complain_on_overflow */ |
c5930ee6 KH |
639 | 0, /* special_function */ |
640 | "R_BA", /* name */ | |
641 | true, /* partial_inplace */ | |
642 | 0x3fffffc, /* src_mask */ | |
643 | 0x3fffffc, /* dst_mask */ | |
252b5132 | 644 | false), /* pcrel_offset */ |
c5930ee6 | 645 | |
5f771d47 | 646 | EMPTY_HOWTO (9), |
252b5132 RH |
647 | |
648 | /* Non modifiable relative branch. */ | |
c5930ee6 KH |
649 | HOWTO (0xa, /* type */ |
650 | 0, /* rightshift */ | |
651 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
652 | 26, /* bitsize */ | |
653 | true, /* pc_relative */ | |
654 | 0, /* bitpos */ | |
252b5132 | 655 | complain_overflow_signed, /* complain_on_overflow */ |
c5930ee6 KH |
656 | 0, /* special_function */ |
657 | "R_BR", /* name */ | |
658 | true, /* partial_inplace */ | |
659 | 0x3fffffc, /* src_mask */ | |
660 | 0x3fffffc, /* dst_mask */ | |
252b5132 | 661 | false), /* pcrel_offset */ |
c5930ee6 | 662 | |
5f771d47 | 663 | EMPTY_HOWTO (0xb), |
252b5132 RH |
664 | |
665 | /* Indirect load. */ | |
c5930ee6 KH |
666 | HOWTO (0xc, /* type */ |
667 | 0, /* rightshift */ | |
668 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
669 | 16, /* bitsize */ | |
670 | false, /* pc_relative */ | |
671 | 0, /* bitpos */ | |
252b5132 | 672 | complain_overflow_bitfield, /* complain_on_overflow */ |
c5930ee6 KH |
673 | 0, /* special_function */ |
674 | "R_RL", /* name */ | |
675 | true, /* partial_inplace */ | |
676 | 0xffff, /* src_mask */ | |
677 | 0xffff, /* dst_mask */ | |
252b5132 | 678 | false), /* pcrel_offset */ |
c5930ee6 | 679 | |
252b5132 | 680 | /* Load address. */ |
c5930ee6 KH |
681 | HOWTO (0xd, /* type */ |
682 | 0, /* rightshift */ | |
683 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
684 | 16, /* bitsize */ | |
685 | false, /* pc_relative */ | |
686 | 0, /* bitpos */ | |
252b5132 | 687 | complain_overflow_bitfield, /* complain_on_overflow */ |
c5930ee6 KH |
688 | 0, /* special_function */ |
689 | "R_RLA", /* name */ | |
690 | true, /* partial_inplace */ | |
691 | 0xffff, /* src_mask */ | |
692 | 0xffff, /* dst_mask */ | |
252b5132 | 693 | false), /* pcrel_offset */ |
c5930ee6 | 694 | |
5f771d47 | 695 | EMPTY_HOWTO (0xe), |
c5930ee6 | 696 | |
252b5132 | 697 | /* Non-relocating reference. */ |
c5930ee6 KH |
698 | HOWTO (0xf, /* type */ |
699 | 0, /* rightshift */ | |
700 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
701 | 32, /* bitsize */ | |
702 | false, /* pc_relative */ | |
703 | 0, /* bitpos */ | |
252b5132 | 704 | complain_overflow_bitfield, /* complain_on_overflow */ |
c5930ee6 KH |
705 | 0, /* special_function */ |
706 | "R_REF", /* name */ | |
707 | false, /* partial_inplace */ | |
708 | 0, /* src_mask */ | |
709 | 0, /* dst_mask */ | |
252b5132 | 710 | false), /* pcrel_offset */ |
c5930ee6 | 711 | |
5f771d47 ILT |
712 | EMPTY_HOWTO (0x10), |
713 | EMPTY_HOWTO (0x11), | |
c5930ee6 | 714 | |
252b5132 | 715 | /* TOC relative indirect load. */ |
c5930ee6 KH |
716 | HOWTO (0x12, /* type */ |
717 | 0, /* rightshift */ | |
718 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
719 | 16, /* bitsize */ | |
720 | false, /* pc_relative */ | |
721 | 0, /* bitpos */ | |
252b5132 | 722 | complain_overflow_bitfield, /* complain_on_overflow */ |
c5930ee6 KH |
723 | 0, /* special_function */ |
724 | "R_TRL", /* name */ | |
725 | true, /* partial_inplace */ | |
726 | 0xffff, /* src_mask */ | |
727 | 0xffff, /* dst_mask */ | |
252b5132 | 728 | false), /* pcrel_offset */ |
c5930ee6 | 729 | |
252b5132 | 730 | /* TOC relative load address. */ |
c5930ee6 KH |
731 | HOWTO (0x13, /* type */ |
732 | 0, /* rightshift */ | |
733 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
734 | 16, /* bitsize */ | |
735 | false, /* pc_relative */ | |
736 | 0, /* bitpos */ | |
252b5132 | 737 | complain_overflow_bitfield, /* complain_on_overflow */ |
c5930ee6 KH |
738 | 0, /* special_function */ |
739 | "R_TRLA", /* name */ | |
740 | true, /* partial_inplace */ | |
741 | 0xffff, /* src_mask */ | |
742 | 0xffff, /* dst_mask */ | |
252b5132 | 743 | false), /* pcrel_offset */ |
c5930ee6 | 744 | |
252b5132 | 745 | /* Modifiable relative branch. */ |
c5930ee6 KH |
746 | HOWTO (0x14, /* type */ |
747 | 1, /* rightshift */ | |
748 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
749 | 32, /* bitsize */ | |
750 | false, /* pc_relative */ | |
751 | 0, /* bitpos */ | |
252b5132 | 752 | complain_overflow_bitfield, /* complain_on_overflow */ |
c5930ee6 KH |
753 | 0, /* special_function */ |
754 | "R_RRTBI", /* name */ | |
755 | true, /* partial_inplace */ | |
756 | 0xffffffff, /* src_mask */ | |
757 | 0xffffffff, /* dst_mask */ | |
252b5132 | 758 | false), /* pcrel_offset */ |
c5930ee6 | 759 | |
252b5132 | 760 | /* Modifiable absolute branch. */ |
c5930ee6 KH |
761 | HOWTO (0x15, /* type */ |
762 | 1, /* rightshift */ | |
763 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
764 | 32, /* bitsize */ | |
765 | false, /* pc_relative */ | |
766 | 0, /* bitpos */ | |
252b5132 | 767 | complain_overflow_bitfield, /* complain_on_overflow */ |
c5930ee6 KH |
768 | 0, /* special_function */ |
769 | "R_RRTBA", /* name */ | |
770 | true, /* partial_inplace */ | |
771 | 0xffffffff, /* src_mask */ | |
772 | 0xffffffff, /* dst_mask */ | |
252b5132 | 773 | false), /* pcrel_offset */ |
c5930ee6 | 774 | |
252b5132 | 775 | /* Modifiable call absolute indirect. */ |
c5930ee6 KH |
776 | HOWTO (0x16, /* type */ |
777 | 0, /* rightshift */ | |
778 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
779 | 16, /* bitsize */ | |
780 | false, /* pc_relative */ | |
781 | 0, /* bitpos */ | |
252b5132 | 782 | complain_overflow_bitfield, /* complain_on_overflow */ |
c5930ee6 KH |
783 | 0, /* special_function */ |
784 | "R_CAI", /* name */ | |
785 | true, /* partial_inplace */ | |
786 | 0xffff, /* src_mask */ | |
787 | 0xffff, /* dst_mask */ | |
252b5132 | 788 | false), /* pcrel_offset */ |
c5930ee6 | 789 | |
252b5132 | 790 | /* Modifiable call relative. */ |
c5930ee6 KH |
791 | HOWTO (0x17, /* type */ |
792 | 0, /* rightshift */ | |
793 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
794 | 16, /* bitsize */ | |
795 | false, /* pc_relative */ | |
796 | 0, /* bitpos */ | |
252b5132 | 797 | complain_overflow_bitfield, /* complain_on_overflow */ |
c5930ee6 KH |
798 | 0, /* special_function */ |
799 | "R_CREL", /* name */ | |
800 | true, /* partial_inplace */ | |
801 | 0xffff, /* src_mask */ | |
802 | 0xffff, /* dst_mask */ | |
252b5132 | 803 | false), /* pcrel_offset */ |
c5930ee6 | 804 | |
252b5132 | 805 | /* Modifiable branch absolute. */ |
c5930ee6 KH |
806 | HOWTO (0x18, /* type */ |
807 | 0, /* rightshift */ | |
808 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
809 | 26, /* bitsize */ | |
810 | false, /* pc_relative */ | |
811 | 0, /* bitpos */ | |
252b5132 | 812 | complain_overflow_bitfield, /* complain_on_overflow */ |
c5930ee6 KH |
813 | 0, /* special_function */ |
814 | "R_RBA", /* name */ | |
815 | true, /* partial_inplace */ | |
816 | 0xffff, /* src_mask */ | |
817 | 0xffff, /* dst_mask */ | |
252b5132 | 818 | false), /* pcrel_offset */ |
c5930ee6 | 819 | |
252b5132 | 820 | /* Modifiable branch absolute. */ |
c5930ee6 KH |
821 | HOWTO (0x19, /* type */ |
822 | 0, /* rightshift */ | |
823 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
824 | 32, /* bitsize */ | |
825 | false, /* pc_relative */ | |
826 | 0, /* bitpos */ | |
252b5132 | 827 | complain_overflow_bitfield, /* complain_on_overflow */ |
c5930ee6 KH |
828 | 0, /* special_function */ |
829 | "R_RBAC", /* name */ | |
830 | true, /* partial_inplace */ | |
831 | 0xffff, /* src_mask */ | |
832 | 0xffff, /* dst_mask */ | |
252b5132 | 833 | false), /* pcrel_offset */ |
c5930ee6 | 834 | |
252b5132 | 835 | /* Modifiable branch relative. */ |
c5930ee6 KH |
836 | HOWTO (0x1a, /* type */ |
837 | 0, /* rightshift */ | |
838 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
839 | 26, /* bitsize */ | |
840 | false, /* pc_relative */ | |
841 | 0, /* bitpos */ | |
252b5132 | 842 | complain_overflow_signed, /* complain_on_overflow */ |
c5930ee6 KH |
843 | 0, /* special_function */ |
844 | "R_RBR", /* name */ | |
845 | true, /* partial_inplace */ | |
846 | 0xffff, /* src_mask */ | |
847 | 0xffff, /* dst_mask */ | |
252b5132 | 848 | false), /* pcrel_offset */ |
c5930ee6 | 849 | |
252b5132 | 850 | /* Modifiable branch absolute. */ |
c5930ee6 KH |
851 | HOWTO (0x1b, /* type */ |
852 | 0, /* rightshift */ | |
853 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
854 | 16, /* bitsize */ | |
855 | false, /* pc_relative */ | |
856 | 0, /* bitpos */ | |
252b5132 | 857 | complain_overflow_bitfield, /* complain_on_overflow */ |
c5930ee6 KH |
858 | 0, /* special_function */ |
859 | "R_RBRC", /* name */ | |
860 | true, /* partial_inplace */ | |
861 | 0xffff, /* src_mask */ | |
862 | 0xffff, /* dst_mask */ | |
7f6d05e8 | 863 | false), /* pcrel_offset */ |
beb1bf64 | 864 | |
7f6d05e8 CP |
865 | HOWTO (0, /* type */ |
866 | 0, /* rightshift */ | |
867 | 4, /* size (0 = byte, 1 = short, 2 = long) */ | |
868 | 64, /* bitsize */ | |
869 | false, /* pc_relative */ | |
870 | 0, /* bitpos */ | |
871 | complain_overflow_bitfield, /* complain_on_overflow */ | |
872 | 0, /* special_function */ | |
873 | "R_POS", /* name */ | |
874 | true, /* partial_inplace */ | |
875 | MINUS_ONE, /* src_mask */ | |
876 | MINUS_ONE, /* dst_mask */ | |
252b5132 | 877 | false) /* pcrel_offset */ |
7f6d05e8 | 878 | |
252b5132 RH |
879 | }; |
880 | ||
7f6d05e8 CP |
881 | void |
882 | _bfd_xcoff_rtype2howto (relent, internal) | |
252b5132 RH |
883 | arelent *relent; |
884 | struct internal_reloc *internal; | |
885 | { | |
886 | relent->howto = xcoff_howto_table + internal->r_type; | |
887 | ||
beb1bf64 TR |
888 | /* Check for relocs we don't know of. */ |
889 | if (internal->r_type | |
890 | >= sizeof (xcoff_howto_table) / sizeof (xcoff_howto_table[0])) | |
891 | abort (); | |
892 | if (internal->r_type != relent->howto->type) | |
893 | abort (); | |
5ea1af0d | 894 | |
252b5132 RH |
895 | /* The r_size field of an XCOFF reloc encodes the bitsize of the |
896 | relocation, as well as indicating whether it is signed or not. | |
897 | Doublecheck that the relocation information gathered from the | |
c5930ee6 KH |
898 | type matches this information. The bitsize is not significant |
899 | for R_REF relocs. */ | |
900 | if (relent->howto->dst_mask != 0 | |
beb1bf64 | 901 | && (relent->howto->bitsize |
c5930ee6 | 902 | != ((unsigned int) internal->r_size & 0x3f) + 1)) |
252b5132 RH |
903 | abort (); |
904 | #if 0 | |
905 | if ((internal->r_size & 0x80) != 0 | |
906 | ? (relent->howto->complain_on_overflow != complain_overflow_signed) | |
907 | : (relent->howto->complain_on_overflow != complain_overflow_bitfield)) | |
908 | abort (); | |
909 | #endif | |
910 | } | |
911 | ||
7f6d05e8 CP |
912 | reloc_howto_type * |
913 | _bfd_xcoff_reloc_type_lookup (abfd, code) | |
5f771d47 | 914 | bfd *abfd ATTRIBUTE_UNUSED; |
252b5132 RH |
915 | bfd_reloc_code_real_type code; |
916 | { | |
917 | switch (code) | |
918 | { | |
919 | case BFD_RELOC_PPC_B26: | |
920 | return &xcoff_howto_table[0xa]; | |
921 | case BFD_RELOC_PPC_BA26: | |
922 | return &xcoff_howto_table[8]; | |
923 | case BFD_RELOC_PPC_TOC16: | |
924 | return &xcoff_howto_table[3]; | |
925 | case BFD_RELOC_32: | |
926 | case BFD_RELOC_CTOR: | |
927 | return &xcoff_howto_table[0]; | |
7f6d05e8 CP |
928 | case BFD_RELOC_64: |
929 | return &xcoff_howto_table[0x1c]; | |
252b5132 RH |
930 | default: |
931 | return NULL; | |
932 | } | |
933 | } | |
beb1bf64 | 934 | |
252b5132 RH |
935 | \f |
936 | /* XCOFF archive support. The original version of this code was by | |
937 | Damon A. Permezel. It was enhanced to permit cross support, and | |
938 | writing archive files, by Ian Lance Taylor, Cygnus Support. | |
939 | ||
940 | XCOFF uses its own archive format. Everything is hooked together | |
941 | with file offset links, so it is possible to rapidly update an | |
942 | archive in place. Of course, we don't do that. An XCOFF archive | |
943 | has a real file header, not just an ARMAG string. The structure of | |
944 | the file header and of each archive header appear below. | |
945 | ||
946 | An XCOFF archive also has a member table, which is a list of | |
947 | elements in the archive (you can get that by looking through the | |
948 | linked list, but you have to read a lot more of the file). The | |
949 | member table has a normal archive header with an empty name. It is | |
950 | normally (and perhaps must be) the second to last entry in the | |
951 | archive. The member table data is almost printable ASCII. It | |
952 | starts with a 12 character decimal string which is the number of | |
953 | entries in the table. For each entry it has a 12 character decimal | |
954 | string which is the offset in the archive of that member. These | |
955 | entries are followed by a series of null terminated strings which | |
956 | are the member names for each entry. | |
957 | ||
958 | Finally, an XCOFF archive has a global symbol table, which is what | |
959 | we call the armap. The global symbol table has a normal archive | |
960 | header with an empty name. It is normally (and perhaps must be) | |
961 | the last entry in the archive. The contents start with a four byte | |
962 | binary number which is the number of entries. This is followed by | |
963 | a that many four byte binary numbers; each is the file offset of an | |
964 | entry in the archive. These numbers are followed by a series of | |
5ea1af0d GK |
965 | null terminated strings, which are symbol names. |
966 | ||
967 | AIX 4.3 introduced a new archive format which can handle larger | |
968 | files and also 32- and 64-bit objects in the same archive. The | |
969 | things said above remain true except that there is now more than | |
970 | one global symbol table. The one is used to index 32-bit objects, | |
971 | the other for 64-bit objects. | |
972 | ||
973 | The new archives (recognizable by the new ARMAG string) has larger | |
974 | field lengths so that we cannot really share any code. Also we have | |
975 | to take care that we are not generating the new form of archives | |
976 | on AIX 4.2 or earlier systems. */ | |
252b5132 | 977 | |
5ea1af0d GK |
978 | /* XCOFF archives use this as a magic string. Note that both strings |
979 | have the same length. */ | |
252b5132 | 980 | |
252b5132 | 981 | |
252b5132 | 982 | |
252b5132 RH |
983 | /* Read in the armap of an XCOFF archive. */ |
984 | ||
7f6d05e8 CP |
985 | boolean |
986 | _bfd_xcoff_slurp_armap (abfd) | |
252b5132 RH |
987 | bfd *abfd; |
988 | { | |
989 | file_ptr off; | |
252b5132 RH |
990 | size_t namlen; |
991 | bfd_size_type sz; | |
992 | bfd_byte *contents, *cend; | |
31612ca6 | 993 | bfd_vma c, i; |
252b5132 RH |
994 | carsym *arsym; |
995 | bfd_byte *p; | |
996 | ||
997 | if (xcoff_ardata (abfd) == NULL) | |
998 | { | |
999 | bfd_has_map (abfd) = false; | |
1000 | return true; | |
1001 | } | |
1002 | ||
5ea1af0d | 1003 | if (! xcoff_big_format_p (abfd)) |
252b5132 | 1004 | { |
5ea1af0d GK |
1005 | /* This is for the old format. */ |
1006 | struct xcoff_ar_hdr hdr; | |
1007 | ||
1008 | off = strtol (xcoff_ardata (abfd)->symoff, (char **) NULL, 10); | |
1009 | if (off == 0) | |
1010 | { | |
1011 | bfd_has_map (abfd) = false; | |
1012 | return true; | |
1013 | } | |
1014 | ||
1015 | if (bfd_seek (abfd, off, SEEK_SET) != 0) | |
1016 | return false; | |
1017 | ||
1018 | /* The symbol table starts with a normal archive header. */ | |
1019 | if (bfd_read ((PTR) &hdr, SIZEOF_AR_HDR, 1, abfd) != SIZEOF_AR_HDR) | |
1020 | return false; | |
1021 | ||
1022 | /* Skip the name (normally empty). */ | |
1023 | namlen = strtol (hdr.namlen, (char **) NULL, 10); | |
1024 | if (bfd_seek (abfd, ((namlen + 1) & ~1) + SXCOFFARFMAG, SEEK_CUR) != 0) | |
1025 | return false; | |
1026 | ||
1027 | sz = strtol (hdr.size, (char **) NULL, 10); | |
31612ca6 GK |
1028 | |
1029 | /* Read in the entire symbol table. */ | |
1030 | contents = (bfd_byte *) bfd_alloc (abfd, sz); | |
1031 | if (contents == NULL) | |
1032 | return false; | |
1033 | if (bfd_read ((PTR) contents, 1, sz, abfd) != sz) | |
1034 | return false; | |
1035 | ||
1036 | /* The symbol table starts with a four byte count. */ | |
1037 | c = bfd_h_get_32 (abfd, contents); | |
beb1bf64 | 1038 | |
31612ca6 GK |
1039 | if (c * 4 >= sz) |
1040 | { | |
1041 | bfd_set_error (bfd_error_bad_value); | |
1042 | return false; | |
1043 | } | |
beb1bf64 | 1044 | |
31612ca6 GK |
1045 | bfd_ardata (abfd)->symdefs = ((carsym *) |
1046 | bfd_alloc (abfd, c * sizeof (carsym))); | |
1047 | if (bfd_ardata (abfd)->symdefs == NULL) | |
1048 | return false; | |
beb1bf64 | 1049 | |
31612ca6 GK |
1050 | /* After the count comes a list of four byte file offsets. */ |
1051 | for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 4; | |
1052 | i < c; | |
1053 | ++i, ++arsym, p += 4) | |
1054 | arsym->file_offset = bfd_h_get_32 (abfd, p); | |
252b5132 | 1055 | } |
5ea1af0d GK |
1056 | else |
1057 | { | |
1058 | /* This is for the new format. */ | |
1059 | struct xcoff_ar_hdr_big hdr; | |
252b5132 | 1060 | |
5ea1af0d GK |
1061 | off = strtol (xcoff_ardata_big (abfd)->symoff, (char **) NULL, 10); |
1062 | if (off == 0) | |
1063 | { | |
1064 | bfd_has_map (abfd) = false; | |
1065 | return true; | |
1066 | } | |
252b5132 | 1067 | |
5ea1af0d GK |
1068 | if (bfd_seek (abfd, off, SEEK_SET) != 0) |
1069 | return false; | |
252b5132 | 1070 | |
5ea1af0d GK |
1071 | /* The symbol table starts with a normal archive header. */ |
1072 | if (bfd_read ((PTR) &hdr, SIZEOF_AR_HDR_BIG, 1, abfd) | |
1073 | != SIZEOF_AR_HDR_BIG) | |
1074 | return false; | |
1075 | ||
1076 | /* Skip the name (normally empty). */ | |
1077 | namlen = strtol (hdr.namlen, (char **) NULL, 10); | |
1078 | if (bfd_seek (abfd, ((namlen + 1) & ~1) + SXCOFFARFMAG, SEEK_CUR) != 0) | |
1079 | return false; | |
1080 | ||
1081 | /* XXX This actually has to be a call to strtoll (at least on 32-bit | |
1082 | machines) since the field width is 20 and there numbers with more | |
1083 | than 32 bits can be represented. */ | |
1084 | sz = strtol (hdr.size, (char **) NULL, 10); | |
252b5132 | 1085 | |
31612ca6 GK |
1086 | /* Read in the entire symbol table. */ |
1087 | contents = (bfd_byte *) bfd_alloc (abfd, sz); | |
1088 | if (contents == NULL) | |
1089 | return false; | |
1090 | if (bfd_read ((PTR) contents, 1, sz, abfd) != sz) | |
1091 | return false; | |
252b5132 | 1092 | |
31612ca6 GK |
1093 | /* The symbol table starts with an eight byte count. */ |
1094 | c = bfd_h_get_64 (abfd, contents); | |
252b5132 | 1095 | |
31612ca6 GK |
1096 | if (c * 8 >= sz) |
1097 | { | |
1098 | bfd_set_error (bfd_error_bad_value); | |
1099 | return false; | |
1100 | } | |
beb1bf64 | 1101 | |
31612ca6 GK |
1102 | bfd_ardata (abfd)->symdefs = ((carsym *) |
1103 | bfd_alloc (abfd, c * sizeof (carsym))); | |
1104 | if (bfd_ardata (abfd)->symdefs == NULL) | |
1105 | return false; | |
beb1bf64 | 1106 | |
31612ca6 GK |
1107 | /* After the count comes a list of eight byte file offsets. */ |
1108 | for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 8; | |
1109 | i < c; | |
1110 | ++i, ++arsym, p += 8) | |
1111 | arsym->file_offset = bfd_h_get_64 (abfd, p); | |
252b5132 RH |
1112 | } |
1113 | ||
252b5132 RH |
1114 | /* After the file offsets come null terminated symbol names. */ |
1115 | cend = contents + sz; | |
1116 | for (i = 0, arsym = bfd_ardata (abfd)->symdefs; | |
1117 | i < c; | |
1118 | ++i, ++arsym, p += strlen ((char *) p) + 1) | |
1119 | { | |
1120 | if (p >= cend) | |
1121 | { | |
1122 | bfd_set_error (bfd_error_bad_value); | |
1123 | return false; | |
1124 | } | |
1125 | arsym->name = (char *) p; | |
1126 | } | |
1127 | ||
1128 | bfd_ardata (abfd)->symdef_count = c; | |
1129 | bfd_has_map (abfd) = true; | |
1130 | ||
1131 | return true; | |
1132 | } | |
1133 | ||
1134 | /* See if this is an XCOFF archive. */ | |
1135 | ||
7f6d05e8 CP |
1136 | const bfd_target * |
1137 | _bfd_xcoff_archive_p (abfd) | |
252b5132 RH |
1138 | bfd *abfd; |
1139 | { | |
5ea1af0d | 1140 | char magic[SXCOFFARMAG]; |
252b5132 | 1141 | |
5ea1af0d | 1142 | if (bfd_read ((PTR) magic, SXCOFFARMAG, 1, abfd) != SXCOFFARMAG) |
252b5132 RH |
1143 | { |
1144 | if (bfd_get_error () != bfd_error_system_call) | |
1145 | bfd_set_error (bfd_error_wrong_format); | |
1146 | return NULL; | |
1147 | } | |
1148 | ||
5ea1af0d GK |
1149 | if (strncmp (magic, XCOFFARMAG, SXCOFFARMAG) != 0 |
1150 | && strncmp (magic, XCOFFARMAGBIG, SXCOFFARMAG) != 0) | |
252b5132 RH |
1151 | { |
1152 | bfd_set_error (bfd_error_wrong_format); | |
1153 | return NULL; | |
1154 | } | |
1155 | ||
1156 | /* We are setting bfd_ardata(abfd) here, but since bfd_ardata | |
1157 | involves a cast, we can't do it as the left operand of | |
1158 | assignment. */ | |
1159 | abfd->tdata.aout_ar_data = | |
1160 | (struct artdata *) bfd_zalloc (abfd, sizeof (struct artdata)); | |
1161 | ||
1162 | if (bfd_ardata (abfd) == (struct artdata *) NULL) | |
1163 | return NULL; | |
1164 | ||
252b5132 RH |
1165 | bfd_ardata (abfd)->cache = NULL; |
1166 | bfd_ardata (abfd)->archive_head = NULL; | |
1167 | bfd_ardata (abfd)->symdefs = NULL; | |
1168 | bfd_ardata (abfd)->extended_names = NULL; | |
1169 | ||
5ea1af0d GK |
1170 | /* Now handle the two formats. */ |
1171 | if (magic[1] != 'b') | |
1172 | { | |
1173 | /* This is the old format. */ | |
1174 | struct xcoff_ar_file_hdr hdr; | |
252b5132 | 1175 | |
5ea1af0d GK |
1176 | /* Copy over the magic string. */ |
1177 | memcpy (hdr.magic, magic, SXCOFFARMAG); | |
1178 | ||
1179 | /* Now read the rest of the file header. */ | |
1180 | if (bfd_read ((PTR) &hdr.memoff, SIZEOF_AR_FILE_HDR - SXCOFFARMAG, 1, | |
1181 | abfd) != SIZEOF_AR_FILE_HDR - SXCOFFARMAG) | |
1182 | { | |
1183 | if (bfd_get_error () != bfd_error_system_call) | |
1184 | bfd_set_error (bfd_error_wrong_format); | |
1185 | return NULL; | |
1186 | } | |
1187 | ||
1188 | bfd_ardata (abfd)->first_file_filepos = strtol (hdr.firstmemoff, | |
1189 | (char **) NULL, 10); | |
1190 | ||
1191 | bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, SIZEOF_AR_FILE_HDR); | |
1192 | if (bfd_ardata (abfd)->tdata == NULL) | |
1193 | return NULL; | |
1194 | ||
1195 | memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR); | |
1196 | } | |
1197 | else | |
1198 | { | |
1199 | /* This is the new format. */ | |
1200 | struct xcoff_ar_file_hdr_big hdr; | |
1201 | ||
1202 | /* Copy over the magic string. */ | |
1203 | memcpy (hdr.magic, magic, SXCOFFARMAG); | |
1204 | ||
1205 | /* Now read the rest of the file header. */ | |
1206 | if (bfd_read ((PTR) &hdr.memoff, SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG, 1, | |
1207 | abfd) != SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG) | |
1208 | { | |
1209 | if (bfd_get_error () != bfd_error_system_call) | |
1210 | bfd_set_error (bfd_error_wrong_format); | |
1211 | return NULL; | |
1212 | } | |
1213 | ||
1214 | /* XXX This actually has to be a call to strtoll (at least on 32-bit | |
1215 | machines) since the field width is 20 and there numbers with more | |
1216 | than 32 bits can be represented. */ | |
1217 | bfd_ardata (abfd)->first_file_filepos = strtol (hdr.firstmemoff, | |
1218 | (char **) NULL, 10); | |
1219 | ||
1220 | bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, SIZEOF_AR_FILE_HDR_BIG); | |
1221 | if (bfd_ardata (abfd)->tdata == NULL) | |
1222 | return NULL; | |
1223 | ||
1224 | memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR_BIG); | |
1225 | } | |
252b5132 | 1226 | |
7f6d05e8 | 1227 | if (! _bfd_xcoff_slurp_armap (abfd)) |
252b5132 RH |
1228 | { |
1229 | bfd_release (abfd, bfd_ardata (abfd)); | |
1230 | abfd->tdata.aout_ar_data = (struct artdata *) NULL; | |
1231 | return NULL; | |
1232 | } | |
1233 | ||
1234 | return abfd->xvec; | |
1235 | } | |
1236 | ||
1237 | /* Read the archive header in an XCOFF archive. */ | |
1238 | ||
7f6d05e8 CP |
1239 | PTR |
1240 | _bfd_xcoff_read_ar_hdr (abfd) | |
252b5132 RH |
1241 | bfd *abfd; |
1242 | { | |
252b5132 | 1243 | size_t namlen; |
252b5132 RH |
1244 | struct areltdata *ret; |
1245 | ||
252b5132 RH |
1246 | ret = (struct areltdata *) bfd_alloc (abfd, sizeof (struct areltdata)); |
1247 | if (ret == NULL) | |
1248 | return NULL; | |
5ea1af0d GK |
1249 | |
1250 | if (! xcoff_big_format_p (abfd)) | |
1251 | { | |
1252 | struct xcoff_ar_hdr hdr; | |
1253 | struct xcoff_ar_hdr *hdrp; | |
1254 | ||
1255 | if (bfd_read ((PTR) &hdr, SIZEOF_AR_HDR, 1, abfd) != SIZEOF_AR_HDR) | |
1256 | { | |
1257 | free (ret); | |
1258 | return NULL; | |
1259 | } | |
1260 | ||
1261 | namlen = strtol (hdr.namlen, (char **) NULL, 10); | |
1262 | hdrp = (struct xcoff_ar_hdr *) bfd_alloc (abfd, | |
1263 | SIZEOF_AR_HDR + namlen + 1); | |
1264 | if (hdrp == NULL) | |
1265 | { | |
1266 | free (ret); | |
1267 | return NULL; | |
1268 | } | |
1269 | memcpy (hdrp, &hdr, SIZEOF_AR_HDR); | |
1270 | if (bfd_read ((char *) hdrp + SIZEOF_AR_HDR, 1, namlen, abfd) != namlen) | |
1271 | { | |
1272 | free (ret); | |
1273 | return NULL; | |
1274 | } | |
1275 | ((char *) hdrp)[SIZEOF_AR_HDR + namlen] = '\0'; | |
1276 | ||
1277 | ret->arch_header = (char *) hdrp; | |
1278 | ret->parsed_size = strtol (hdr.size, (char **) NULL, 10); | |
1279 | ret->filename = (char *) hdrp + SIZEOF_AR_HDR; | |
1280 | } | |
1281 | else | |
1282 | { | |
1283 | struct xcoff_ar_hdr_big hdr; | |
1284 | struct xcoff_ar_hdr_big *hdrp; | |
1285 | ||
1286 | if (bfd_read ((PTR) &hdr, SIZEOF_AR_HDR_BIG, 1, abfd) | |
1287 | != SIZEOF_AR_HDR_BIG) | |
1288 | { | |
1289 | free (ret); | |
1290 | return NULL; | |
1291 | } | |
1292 | ||
1293 | namlen = strtol (hdr.namlen, (char **) NULL, 10); | |
1294 | hdrp = (struct xcoff_ar_hdr_big *) bfd_alloc (abfd, | |
1295 | SIZEOF_AR_HDR_BIG | |
1296 | + namlen + 1); | |
1297 | if (hdrp == NULL) | |
1298 | { | |
1299 | free (ret); | |
1300 | return NULL; | |
1301 | } | |
1302 | memcpy (hdrp, &hdr, SIZEOF_AR_HDR_BIG); | |
1303 | if (bfd_read ((char *) hdrp + SIZEOF_AR_HDR_BIG, 1, namlen, abfd) != namlen) | |
1304 | { | |
1305 | free (ret); | |
1306 | return NULL; | |
1307 | } | |
1308 | ((char *) hdrp)[SIZEOF_AR_HDR_BIG + namlen] = '\0'; | |
1309 | ||
1310 | ret->arch_header = (char *) hdrp; | |
1311 | /* XXX This actually has to be a call to strtoll (at least on 32-bit | |
1312 | machines) since the field width is 20 and there numbers with more | |
1313 | than 32 bits can be represented. */ | |
1314 | ret->parsed_size = strtol (hdr.size, (char **) NULL, 10); | |
1315 | ret->filename = (char *) hdrp + SIZEOF_AR_HDR_BIG; | |
1316 | } | |
252b5132 RH |
1317 | |
1318 | /* Skip over the XCOFFARFMAG at the end of the file name. */ | |
1319 | if (bfd_seek (abfd, (namlen & 1) + SXCOFFARFMAG, SEEK_CUR) != 0) | |
1320 | return NULL; | |
1321 | ||
1322 | return (PTR) ret; | |
1323 | } | |
1324 | ||
1325 | /* Open the next element in an XCOFF archive. */ | |
1326 | ||
7f6d05e8 CP |
1327 | bfd * |
1328 | _bfd_xcoff_openr_next_archived_file (archive, last_file) | |
252b5132 RH |
1329 | bfd *archive; |
1330 | bfd *last_file; | |
1331 | { | |
1332 | file_ptr filestart; | |
1333 | ||
1334 | if (xcoff_ardata (archive) == NULL) | |
1335 | { | |
1336 | bfd_set_error (bfd_error_invalid_operation); | |
1337 | return NULL; | |
1338 | } | |
1339 | ||
5ea1af0d GK |
1340 | if (! xcoff_big_format_p (archive)) |
1341 | { | |
1342 | if (last_file == NULL) | |
1343 | filestart = bfd_ardata (archive)->first_file_filepos; | |
1344 | else | |
1345 | filestart = strtol (arch_xhdr (last_file)->nextoff, (char **) NULL, | |
1346 | 10); | |
1347 | ||
1348 | if (filestart == 0 | |
1349 | || filestart == strtol (xcoff_ardata (archive)->memoff, | |
1350 | (char **) NULL, 10) | |
1351 | || filestart == strtol (xcoff_ardata (archive)->symoff, | |
1352 | (char **) NULL, 10)) | |
1353 | { | |
1354 | bfd_set_error (bfd_error_no_more_archived_files); | |
1355 | return NULL; | |
1356 | } | |
1357 | } | |
252b5132 | 1358 | else |
252b5132 | 1359 | { |
5ea1af0d GK |
1360 | if (last_file == NULL) |
1361 | filestart = bfd_ardata (archive)->first_file_filepos; | |
1362 | else | |
1363 | /* XXX These actually have to be a calls to strtoll (at least | |
1364 | on 32-bit machines) since the fields's width is 20 and | |
1365 | there numbers with more than 32 bits can be represented. */ | |
1366 | filestart = strtol (arch_xhdr_big (last_file)->nextoff, (char **) NULL, | |
1367 | 10); | |
1368 | ||
1369 | /* XXX These actually have to be calls to strtoll (at least on 32-bit | |
1370 | machines) since the fields's width is 20 and there numbers with more | |
1371 | than 32 bits can be represented. */ | |
1372 | if (filestart == 0 | |
1373 | || filestart == strtol (xcoff_ardata_big (archive)->memoff, | |
1374 | (char **) NULL, 10) | |
1375 | || filestart == strtol (xcoff_ardata_big (archive)->symoff, | |
1376 | (char **) NULL, 10)) | |
1377 | { | |
1378 | bfd_set_error (bfd_error_no_more_archived_files); | |
1379 | return NULL; | |
1380 | } | |
252b5132 RH |
1381 | } |
1382 | ||
1383 | return _bfd_get_elt_at_filepos (archive, filestart); | |
1384 | } | |
1385 | ||
1386 | /* Stat an element in an XCOFF archive. */ | |
1387 | ||
7f6d05e8 CP |
1388 | int |
1389 | _bfd_xcoff_generic_stat_arch_elt (abfd, s) | |
252b5132 RH |
1390 | bfd *abfd; |
1391 | struct stat *s; | |
1392 | { | |
252b5132 RH |
1393 | if (abfd->arelt_data == NULL) |
1394 | { | |
1395 | bfd_set_error (bfd_error_invalid_operation); | |
1396 | return -1; | |
1397 | } | |
1398 | ||
5ea1af0d GK |
1399 | if (! xcoff_big_format_p (abfd)) |
1400 | { | |
1401 | struct xcoff_ar_hdr *hdrp = arch_xhdr (abfd); | |
1402 | ||
1403 | s->st_mtime = strtol (hdrp->date, (char **) NULL, 10); | |
1404 | s->st_uid = strtol (hdrp->uid, (char **) NULL, 10); | |
1405 | s->st_gid = strtol (hdrp->gid, (char **) NULL, 10); | |
1406 | s->st_mode = strtol (hdrp->mode, (char **) NULL, 8); | |
1407 | s->st_size = arch_eltdata (abfd)->parsed_size; | |
1408 | } | |
1409 | else | |
1410 | { | |
1411 | struct xcoff_ar_hdr_big *hdrp = arch_xhdr_big (abfd); | |
252b5132 | 1412 | |
5ea1af0d GK |
1413 | s->st_mtime = strtol (hdrp->date, (char **) NULL, 10); |
1414 | s->st_uid = strtol (hdrp->uid, (char **) NULL, 10); | |
1415 | s->st_gid = strtol (hdrp->gid, (char **) NULL, 10); | |
1416 | s->st_mode = strtol (hdrp->mode, (char **) NULL, 8); | |
1417 | s->st_size = arch_eltdata (abfd)->parsed_size; | |
1418 | } | |
252b5132 RH |
1419 | |
1420 | return 0; | |
1421 | } | |
1422 | ||
1423 | /* Normalize a file name for inclusion in an archive. */ | |
1424 | ||
1425 | static const char * | |
1426 | normalize_filename (abfd) | |
1427 | bfd *abfd; | |
1428 | { | |
1429 | const char *file; | |
1430 | const char *filename; | |
1431 | ||
1432 | file = bfd_get_filename (abfd); | |
1433 | filename = strrchr (file, '/'); | |
1434 | if (filename != NULL) | |
1435 | filename++; | |
1436 | else | |
1437 | filename = file; | |
1438 | return filename; | |
1439 | } | |
1440 | ||
1441 | /* Write out an XCOFF armap. */ | |
1442 | ||
beb1bf64 | 1443 | /*ARGSUSED*/ |
252b5132 | 1444 | static boolean |
5ea1af0d | 1445 | xcoff_write_armap_old (abfd, elength, map, orl_count, stridx) |
252b5132 | 1446 | bfd *abfd; |
5f771d47 | 1447 | unsigned int elength ATTRIBUTE_UNUSED; |
252b5132 RH |
1448 | struct orl *map; |
1449 | unsigned int orl_count; | |
1450 | int stridx; | |
1451 | { | |
1452 | struct xcoff_ar_hdr hdr; | |
1453 | char *p; | |
1454 | unsigned char buf[4]; | |
1455 | bfd *sub; | |
1456 | file_ptr fileoff; | |
1457 | unsigned int i; | |
1458 | ||
1459 | memset (&hdr, 0, sizeof hdr); | |
1460 | sprintf (hdr.size, "%ld", (long) (4 + orl_count * 4 + stridx)); | |
1461 | sprintf (hdr.nextoff, "%d", 0); | |
1462 | memcpy (hdr.prevoff, xcoff_ardata (abfd)->memoff, 12); | |
1463 | sprintf (hdr.date, "%d", 0); | |
1464 | sprintf (hdr.uid, "%d", 0); | |
1465 | sprintf (hdr.gid, "%d", 0); | |
1466 | sprintf (hdr.mode, "%d", 0); | |
1467 | sprintf (hdr.namlen, "%d", 0); | |
1468 | ||
1469 | /* We need spaces, not null bytes, in the header. */ | |
1470 | for (p = (char *) &hdr; p < (char *) &hdr + SIZEOF_AR_HDR; p++) | |
1471 | if (*p == '\0') | |
1472 | *p = ' '; | |
1473 | ||
1474 | if (bfd_write ((PTR) &hdr, SIZEOF_AR_HDR, 1, abfd) != SIZEOF_AR_HDR | |
1475 | || bfd_write (XCOFFARFMAG, 1, SXCOFFARFMAG, abfd) != SXCOFFARFMAG) | |
1476 | return false; | |
5ea1af0d | 1477 | |
252b5132 RH |
1478 | bfd_h_put_32 (abfd, orl_count, buf); |
1479 | if (bfd_write (buf, 1, 4, abfd) != 4) | |
1480 | return false; | |
1481 | ||
1482 | sub = abfd->archive_head; | |
1483 | fileoff = SIZEOF_AR_FILE_HDR; | |
1484 | i = 0; | |
1485 | while (sub != NULL && i < orl_count) | |
1486 | { | |
1487 | size_t namlen; | |
1488 | ||
1489 | while (((bfd *) (map[i]).pos) == sub) | |
1490 | { | |
1491 | bfd_h_put_32 (abfd, fileoff, buf); | |
1492 | if (bfd_write (buf, 1, 4, abfd) != 4) | |
1493 | return false; | |
1494 | ++i; | |
1495 | } | |
1496 | namlen = strlen (normalize_filename (sub)); | |
1497 | namlen = (namlen + 1) &~ 1; | |
1498 | fileoff += (SIZEOF_AR_HDR | |
1499 | + namlen | |
1500 | + SXCOFFARFMAG | |
1501 | + arelt_size (sub)); | |
1502 | fileoff = (fileoff + 1) &~ 1; | |
1503 | sub = sub->next; | |
1504 | } | |
1505 | ||
1506 | for (i = 0; i < orl_count; i++) | |
1507 | { | |
1508 | const char *name; | |
1509 | size_t namlen; | |
1510 | ||
1511 | name = *map[i].name; | |
1512 | namlen = strlen (name); | |
1513 | if (bfd_write (name, 1, namlen + 1, abfd) != namlen + 1) | |
1514 | return false; | |
1515 | } | |
1516 | ||
1517 | if ((stridx & 1) != 0) | |
1518 | { | |
1519 | char b; | |
1520 | ||
1521 | b = '\0'; | |
1522 | if (bfd_write (&b, 1, 1, abfd) != 1) | |
1523 | return false; | |
1524 | } | |
1525 | ||
1526 | return true; | |
1527 | } | |
1528 | ||
1a6df346 | 1529 | /* Write a single armap in the big format. */ |
252b5132 | 1530 | static boolean |
1a6df346 GK |
1531 | xcoff_write_one_armap_big (abfd, map, orl_count, orl_ccount, stridx, bits64, |
1532 | prevoff, nextoff) | |
252b5132 | 1533 | bfd *abfd; |
5ea1af0d GK |
1534 | struct orl *map; |
1535 | unsigned int orl_count; | |
1a6df346 GK |
1536 | unsigned int orl_ccount; |
1537 | unsigned int stridx; | |
1538 | int bits64; | |
1539 | const char *prevoff; | |
1540 | char *nextoff; | |
252b5132 | 1541 | { |
5ea1af0d GK |
1542 | struct xcoff_ar_hdr_big hdr; |
1543 | char *p; | |
1544 | unsigned char buf[4]; | |
252b5132 | 1545 | bfd *sub; |
5ea1af0d | 1546 | file_ptr fileoff; |
beb1bf64 | 1547 | const bfd_arch_info_type *arch_info; |
1a6df346 | 1548 | bfd *object_bfd; |
252b5132 | 1549 | unsigned int i; |
252b5132 | 1550 | |
5ea1af0d GK |
1551 | memset (&hdr, 0, sizeof hdr); |
1552 | /* XXX This call actually should use %lld (at least on 32-bit | |
1553 | machines) since the fields's width is 20 and there numbers with | |
1554 | more than 32 bits can be represented. */ | |
1a6df346 | 1555 | sprintf (hdr.size, "%ld", (long) (4 + orl_ccount * 4 + stridx)); |
beb1bf64 | 1556 | if (bits64) { |
1a6df346 | 1557 | sprintf (hdr.nextoff, "%d", 0); |
beb1bf64 TR |
1558 | } else { |
1559 | /* do explict cast to long to remove compiler warning */ | |
1560 | sprintf (hdr.nextoff, "%ld", (strtol (prevoff, (char **) NULL, 10) | |
1561 | + (long) (4 + orl_ccount * 4 + stridx))); | |
1562 | } | |
1563 | ||
1a6df346 | 1564 | memcpy (hdr.prevoff, prevoff, sizeof (hdr.prevoff)); |
5ea1af0d GK |
1565 | sprintf (hdr.date, "%d", 0); |
1566 | sprintf (hdr.uid, "%d", 0); | |
1567 | sprintf (hdr.gid, "%d", 0); | |
1568 | sprintf (hdr.mode, "%d", 0); | |
1569 | sprintf (hdr.namlen, "%d", 0); | |
252b5132 | 1570 | |
5ea1af0d GK |
1571 | /* We need spaces, not null bytes, in the header. */ |
1572 | for (p = (char *) &hdr; p < (char *) &hdr + SIZEOF_AR_HDR_BIG; p++) | |
1573 | if (*p == '\0') | |
1574 | *p = ' '; | |
1575 | ||
1a6df346 GK |
1576 | memcpy (nextoff, hdr.nextoff, sizeof (hdr.nextoff)); |
1577 | ||
5ea1af0d GK |
1578 | if (bfd_write ((PTR) &hdr, SIZEOF_AR_HDR_BIG, 1, abfd) != SIZEOF_AR_HDR_BIG |
1579 | || bfd_write (XCOFFARFMAG, 1, SXCOFFARFMAG, abfd) != SXCOFFARFMAG) | |
252b5132 RH |
1580 | return false; |
1581 | ||
1a6df346 | 1582 | bfd_h_put_32 (abfd, orl_ccount, buf); |
5ea1af0d | 1583 | if (bfd_write (buf, 1, 4, abfd) != 4) |
252b5132 RH |
1584 | return false; |
1585 | ||
5ea1af0d GK |
1586 | sub = abfd->archive_head; |
1587 | fileoff = SIZEOF_AR_FILE_HDR_BIG; | |
1588 | i = 0; | |
1589 | while (sub != NULL && i < orl_count) | |
252b5132 | 1590 | { |
5ea1af0d GK |
1591 | size_t namlen; |
1592 | ||
1a6df346 GK |
1593 | if ((bfd_arch_bits_per_address ((bfd *) map[i].pos) == 64) == bits64) |
1594 | while (((bfd *) (map[i]).pos) == sub) | |
1595 | { | |
1596 | bfd_h_put_32 (abfd, fileoff, buf); | |
1597 | if (bfd_write (buf, 1, 4, abfd) != 4) | |
1598 | return false; | |
1599 | i++; | |
1600 | } | |
1601 | else | |
1602 | while (((bfd *) (map[i]).pos) == sub) | |
1603 | i++; | |
1604 | ||
5ea1af0d GK |
1605 | namlen = strlen (normalize_filename (sub)); |
1606 | namlen = (namlen + 1) &~ 1; | |
1607 | fileoff += (SIZEOF_AR_HDR_BIG | |
1608 | + namlen | |
1609 | + SXCOFFARFMAG | |
1610 | + arelt_size (sub)); | |
1611 | fileoff = (fileoff + 1) &~ 1; | |
1612 | sub = sub->next; | |
1613 | } | |
1614 | ||
1a6df346 | 1615 | object_bfd = NULL; |
5ea1af0d GK |
1616 | for (i = 0; i < orl_count; i++) |
1617 | { | |
1618 | const char *name; | |
1619 | size_t namlen; | |
1a6df346 GK |
1620 | bfd *ob = (bfd *)map[i].pos; |
1621 | ||
1622 | if (ob != object_bfd) | |
1623 | arch_info = bfd_get_arch_info (ob); | |
beb1bf64 | 1624 | if ((arch_info->bits_per_address == 64) != bits64) |
1a6df346 | 1625 | continue; |
5ea1af0d GK |
1626 | |
1627 | name = *map[i].name; | |
1628 | namlen = strlen (name); | |
1629 | if (bfd_write (name, 1, namlen + 1, abfd) != namlen + 1) | |
1630 | return false; | |
1631 | } | |
1632 | ||
1633 | if ((stridx & 1) != 0) | |
1634 | { | |
1635 | char b; | |
1636 | ||
1637 | b = '\0'; | |
1638 | if (bfd_write (&b, 1, 1, abfd) != 1) | |
1639 | return false; | |
1640 | } | |
1641 | ||
1642 | return true; | |
1643 | } | |
1644 | ||
beb1bf64 | 1645 | /*ARGSUSED*/ |
1a6df346 GK |
1646 | static boolean |
1647 | xcoff_write_armap_big (abfd, elength, map, orl_count, stridx) | |
1648 | bfd *abfd; | |
1649 | unsigned int elength ATTRIBUTE_UNUSED; | |
1650 | struct orl *map; | |
1651 | unsigned int orl_count; | |
1652 | int stridx; | |
1653 | { | |
1654 | unsigned int i; | |
1655 | unsigned int orl_count_32, orl_count_64; | |
1656 | unsigned int stridx_32, stridx_64; | |
beb1bf64 | 1657 | const bfd_arch_info_type *arch_info; |
1a6df346 GK |
1658 | bfd *object_bfd; |
1659 | ||
1660 | /* First, we look through the symbols and work out which are | |
1661 | from 32-bit objects and which from 64-bit ones. */ | |
1662 | orl_count_32 = 0; | |
1663 | orl_count_64 = 0; | |
1664 | stridx_32 = 0; | |
1665 | stridx_64 = 0; | |
1666 | object_bfd = NULL; | |
1667 | for (i = 0; i < orl_count; i++) | |
1668 | { | |
1669 | bfd *ob = (bfd *)map[i].pos; | |
1670 | unsigned int len; | |
1671 | if (ob != object_bfd) | |
1672 | arch_info = bfd_get_arch_info (ob); | |
1673 | len = strlen (*map[i].name) + 1; | |
beb1bf64 | 1674 | if (arch_info->bits_per_address == 64) |
1a6df346 GK |
1675 | { |
1676 | orl_count_64++; | |
1677 | stridx_64 += len; | |
1678 | } | |
1679 | else | |
1680 | { | |
1681 | orl_count_32++; | |
1682 | stridx_32 += len; | |
1683 | } | |
1684 | object_bfd = ob; | |
1685 | } | |
beb1bf64 | 1686 | /* A quick sanity check... */ |
1a6df346 | 1687 | BFD_ASSERT (orl_count_64 + orl_count_32 == orl_count); |
beb1bf64 TR |
1688 | /* explicit cast to int for compiler */ |
1689 | BFD_ASSERT ((int)(stridx_64 + stridx_32) == stridx); | |
1a6df346 GK |
1690 | |
1691 | /* Now write out each map. */ | |
1692 | if (! xcoff_write_one_armap_big (abfd, map, orl_count, orl_count_32, | |
beb1bf64 | 1693 | stridx_32, false, |
1a6df346 GK |
1694 | xcoff_ardata_big (abfd)->memoff, |
1695 | xcoff_ardata_big (abfd)->symoff)) | |
1696 | return false; | |
1697 | if (! xcoff_write_one_armap_big (abfd, map, orl_count, orl_count_64, | |
1698 | stridx_64, true, | |
1699 | xcoff_ardata_big (abfd)->symoff, | |
1700 | xcoff_ardata_big (abfd)->symoff64)) | |
1701 | return false; | |
beb1bf64 | 1702 | |
1a6df346 GK |
1703 | return true; |
1704 | } | |
1705 | ||
beb1bf64 | 1706 | /*ARGSUSED*/ |
7f6d05e8 CP |
1707 | boolean |
1708 | _bfd_xcoff_write_armap (abfd, elength, map, orl_count, stridx) | |
5ea1af0d GK |
1709 | bfd *abfd; |
1710 | unsigned int elength ATTRIBUTE_UNUSED; | |
1711 | struct orl *map; | |
1712 | unsigned int orl_count; | |
1713 | int stridx; | |
1714 | { | |
1715 | if (! xcoff_big_format_p (abfd)) | |
1716 | return xcoff_write_armap_old (abfd, elength, map, orl_count, stridx); | |
1717 | else | |
1718 | return xcoff_write_armap_big (abfd, elength, map, orl_count, stridx); | |
1719 | } | |
1720 | ||
1721 | /* Write out an XCOFF archive. We always write an entire archive, | |
1722 | rather than fussing with the freelist and so forth. */ | |
1723 | ||
1724 | static boolean | |
1725 | xcoff_write_archive_contents_old (abfd) | |
1726 | bfd *abfd; | |
1727 | { | |
1728 | struct xcoff_ar_file_hdr fhdr; | |
1729 | size_t count; | |
1730 | size_t total_namlen; | |
1731 | file_ptr *offsets; | |
1732 | boolean makemap; | |
1733 | boolean hasobjects; | |
1734 | file_ptr prevoff, nextoff; | |
1735 | bfd *sub; | |
1736 | unsigned int i; | |
1737 | struct xcoff_ar_hdr ahdr; | |
1738 | bfd_size_type size; | |
1739 | char *p; | |
1740 | char decbuf[13]; | |
1741 | ||
1742 | memset (&fhdr, 0, sizeof fhdr); | |
1743 | strncpy (fhdr.magic, XCOFFARMAG, SXCOFFARMAG); | |
1744 | sprintf (fhdr.firstmemoff, "%d", SIZEOF_AR_FILE_HDR); | |
1745 | sprintf (fhdr.freeoff, "%d", 0); | |
1746 | ||
1747 | count = 0; | |
1748 | total_namlen = 0; | |
1749 | for (sub = abfd->archive_head; sub != NULL; sub = sub->next) | |
1750 | { | |
1751 | ++count; | |
1752 | total_namlen += strlen (normalize_filename (sub)) + 1; | |
1753 | } | |
1754 | offsets = (file_ptr *) bfd_alloc (abfd, count * sizeof (file_ptr)); | |
1755 | if (offsets == NULL) | |
1756 | return false; | |
1757 | ||
1758 | if (bfd_seek (abfd, SIZEOF_AR_FILE_HDR, SEEK_SET) != 0) | |
1759 | return false; | |
1760 | ||
1761 | makemap = bfd_has_map (abfd); | |
1762 | hasobjects = false; | |
1763 | prevoff = 0; | |
1764 | nextoff = SIZEOF_AR_FILE_HDR; | |
1765 | for (sub = abfd->archive_head, i = 0; sub != NULL; sub = sub->next, i++) | |
1766 | { | |
1767 | const char *name; | |
252b5132 RH |
1768 | size_t namlen; |
1769 | struct xcoff_ar_hdr *ahdrp; | |
1770 | bfd_size_type remaining; | |
1771 | ||
1772 | if (makemap && ! hasobjects) | |
1773 | { | |
1774 | if (bfd_check_format (sub, bfd_object)) | |
1775 | hasobjects = true; | |
1776 | } | |
1777 | ||
1778 | name = normalize_filename (sub); | |
1779 | namlen = strlen (name); | |
1780 | ||
1781 | if (sub->arelt_data != NULL) | |
1782 | ahdrp = arch_xhdr (sub); | |
1783 | else | |
1784 | ahdrp = NULL; | |
1785 | ||
1786 | if (ahdrp == NULL) | |
1787 | { | |
1788 | struct stat s; | |
1789 | ||
1790 | memset (&ahdr, 0, sizeof ahdr); | |
1791 | ahdrp = &ahdr; | |
1792 | if (stat (bfd_get_filename (sub), &s) != 0) | |
1793 | { | |
1794 | bfd_set_error (bfd_error_system_call); | |
1795 | return false; | |
1796 | } | |
1797 | ||
1798 | sprintf (ahdrp->size, "%ld", (long) s.st_size); | |
1799 | sprintf (ahdrp->date, "%ld", (long) s.st_mtime); | |
1800 | sprintf (ahdrp->uid, "%ld", (long) s.st_uid); | |
1801 | sprintf (ahdrp->gid, "%ld", (long) s.st_gid); | |
1802 | sprintf (ahdrp->mode, "%o", (unsigned int) s.st_mode); | |
1803 | ||
1804 | if (sub->arelt_data == NULL) | |
1805 | { | |
1806 | sub->arelt_data = bfd_alloc (sub, sizeof (struct areltdata)); | |
1807 | if (sub->arelt_data == NULL) | |
1808 | return false; | |
1809 | } | |
1810 | ||
1811 | arch_eltdata (sub)->parsed_size = s.st_size; | |
1812 | } | |
1813 | ||
1814 | sprintf (ahdrp->prevoff, "%ld", (long) prevoff); | |
1815 | sprintf (ahdrp->namlen, "%ld", (long) namlen); | |
1816 | ||
1817 | /* If the length of the name is odd, we write out the null byte | |
1818 | after the name as well. */ | |
1819 | namlen = (namlen + 1) &~ 1; | |
1820 | ||
1821 | remaining = arelt_size (sub); | |
1822 | size = (SIZEOF_AR_HDR | |
1823 | + namlen | |
1824 | + SXCOFFARFMAG | |
1825 | + remaining); | |
1826 | ||
1827 | BFD_ASSERT (nextoff == bfd_tell (abfd)); | |
1828 | ||
1829 | offsets[i] = nextoff; | |
1830 | ||
1831 | prevoff = nextoff; | |
1832 | nextoff += size + (size & 1); | |
1833 | ||
1834 | sprintf (ahdrp->nextoff, "%ld", (long) nextoff); | |
1835 | ||
1836 | /* We need spaces, not null bytes, in the header. */ | |
1837 | for (p = (char *) ahdrp; p < (char *) ahdrp + SIZEOF_AR_HDR; p++) | |
1838 | if (*p == '\0') | |
1839 | *p = ' '; | |
1840 | ||
1841 | if (bfd_write ((PTR) ahdrp, 1, SIZEOF_AR_HDR, abfd) != SIZEOF_AR_HDR | |
1842 | || bfd_write ((PTR) name, 1, namlen, abfd) != namlen | |
1843 | || (bfd_write ((PTR) XCOFFARFMAG, 1, SXCOFFARFMAG, abfd) | |
1844 | != SXCOFFARFMAG)) | |
1845 | return false; | |
1846 | ||
1847 | if (bfd_seek (sub, (file_ptr) 0, SEEK_SET) != 0) | |
1848 | return false; | |
1849 | while (remaining != 0) | |
1850 | { | |
1851 | bfd_size_type amt; | |
1852 | bfd_byte buffer[DEFAULT_BUFFERSIZE]; | |
1853 | ||
1854 | amt = sizeof buffer; | |
1855 | if (amt > remaining) | |
1856 | amt = remaining; | |
1857 | if (bfd_read (buffer, 1, amt, sub) != amt | |
1858 | || bfd_write (buffer, 1, amt, abfd) != amt) | |
1859 | return false; | |
1860 | remaining -= amt; | |
1861 | } | |
1862 | ||
1863 | if ((size & 1) != 0) | |
1864 | { | |
1865 | bfd_byte b; | |
1866 | ||
1867 | b = '\0'; | |
1868 | if (bfd_write (&b, 1, 1, abfd) != 1) | |
1869 | return false; | |
1870 | } | |
1871 | } | |
1872 | ||
1873 | sprintf (fhdr.lastmemoff, "%ld", (long) prevoff); | |
1874 | ||
1875 | /* Write out the member table. */ | |
1876 | ||
1877 | BFD_ASSERT (nextoff == bfd_tell (abfd)); | |
1878 | sprintf (fhdr.memoff, "%ld", (long) nextoff); | |
1879 | ||
1880 | memset (&ahdr, 0, sizeof ahdr); | |
1881 | sprintf (ahdr.size, "%ld", (long) (12 + count * 12 + total_namlen)); | |
1882 | sprintf (ahdr.prevoff, "%ld", (long) prevoff); | |
1883 | sprintf (ahdr.date, "%d", 0); | |
1884 | sprintf (ahdr.uid, "%d", 0); | |
1885 | sprintf (ahdr.gid, "%d", 0); | |
1886 | sprintf (ahdr.mode, "%d", 0); | |
1887 | sprintf (ahdr.namlen, "%d", 0); | |
1888 | ||
1889 | size = (SIZEOF_AR_HDR | |
1890 | + 12 | |
1891 | + count * 12 | |
1892 | + total_namlen | |
1893 | + SXCOFFARFMAG); | |
1894 | ||
1895 | prevoff = nextoff; | |
1896 | nextoff += size + (size & 1); | |
1897 | ||
1898 | if (makemap && hasobjects) | |
1899 | sprintf (ahdr.nextoff, "%ld", (long) nextoff); | |
1900 | else | |
1901 | sprintf (ahdr.nextoff, "%d", 0); | |
1902 | ||
1903 | /* We need spaces, not null bytes, in the header. */ | |
1904 | for (p = (char *) &ahdr; p < (char *) &ahdr + SIZEOF_AR_HDR; p++) | |
1905 | if (*p == '\0') | |
1906 | *p = ' '; | |
1907 | ||
1908 | if (bfd_write ((PTR) &ahdr, 1, SIZEOF_AR_HDR, abfd) != SIZEOF_AR_HDR | |
1909 | || (bfd_write ((PTR) XCOFFARFMAG, 1, SXCOFFARFMAG, abfd) | |
1910 | != SXCOFFARFMAG)) | |
1911 | return false; | |
1912 | ||
1913 | sprintf (decbuf, "%-12ld", (long) count); | |
1914 | if (bfd_write ((PTR) decbuf, 1, 12, abfd) != 12) | |
1915 | return false; | |
1916 | for (i = 0; i < count; i++) | |
1917 | { | |
1918 | sprintf (decbuf, "%-12ld", (long) offsets[i]); | |
1919 | if (bfd_write ((PTR) decbuf, 1, 12, abfd) != 12) | |
1920 | return false; | |
1921 | } | |
1922 | for (sub = abfd->archive_head; sub != NULL; sub = sub->next) | |
1923 | { | |
1924 | const char *name; | |
1925 | size_t namlen; | |
1926 | ||
1927 | name = normalize_filename (sub); | |
1928 | namlen = strlen (name); | |
1929 | if (bfd_write ((PTR) name, 1, namlen + 1, abfd) != namlen + 1) | |
1930 | return false; | |
1931 | } | |
1932 | if ((size & 1) != 0) | |
1933 | { | |
1934 | bfd_byte b; | |
1935 | ||
1936 | b = '\0'; | |
1937 | if (bfd_write ((PTR) &b, 1, 1, abfd) != 1) | |
1938 | return false; | |
1939 | } | |
1940 | ||
1941 | /* Write out the armap, if appropriate. */ | |
1942 | ||
1943 | if (! makemap || ! hasobjects) | |
1944 | sprintf (fhdr.symoff, "%d", 0); | |
1945 | else | |
1946 | { | |
1947 | BFD_ASSERT (nextoff == bfd_tell (abfd)); | |
1948 | sprintf (fhdr.symoff, "%ld", (long) nextoff); | |
1949 | bfd_ardata (abfd)->tdata = (PTR) &fhdr; | |
1950 | if (! _bfd_compute_and_write_armap (abfd, 0)) | |
1951 | return false; | |
1952 | } | |
1953 | ||
1954 | /* Write out the archive file header. */ | |
1955 | ||
1956 | /* We need spaces, not null bytes, in the header. */ | |
1957 | for (p = (char *) &fhdr; p < (char *) &fhdr + SIZEOF_AR_FILE_HDR; p++) | |
1958 | if (*p == '\0') | |
1959 | *p = ' '; | |
1960 | ||
1961 | if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0 | |
1962 | || (bfd_write ((PTR) &fhdr, SIZEOF_AR_FILE_HDR, 1, abfd) != | |
1963 | SIZEOF_AR_FILE_HDR)) | |
1964 | return false; | |
1965 | ||
1966 | return true; | |
1967 | } | |
5ea1af0d GK |
1968 | |
1969 | static boolean | |
1970 | xcoff_write_archive_contents_big (abfd) | |
1971 | bfd *abfd; | |
1972 | { | |
1973 | struct xcoff_ar_file_hdr_big fhdr; | |
1974 | size_t count; | |
1975 | size_t total_namlen; | |
1976 | file_ptr *offsets; | |
1977 | boolean makemap; | |
1978 | boolean hasobjects; | |
1979 | file_ptr prevoff, nextoff; | |
1980 | bfd *sub; | |
1981 | unsigned int i; | |
1982 | struct xcoff_ar_hdr_big ahdr; | |
1983 | bfd_size_type size; | |
1984 | char *p; | |
1985 | char decbuf[13]; | |
1986 | ||
1987 | memset (&fhdr, 0, sizeof fhdr); | |
1988 | strncpy (fhdr.magic, XCOFFARMAGBIG, SXCOFFARMAG); | |
1989 | sprintf (fhdr.firstmemoff, "%d", SIZEOF_AR_FILE_HDR_BIG); | |
1990 | sprintf (fhdr.freeoff, "%d", 0); | |
1991 | ||
1992 | count = 0; | |
1993 | total_namlen = 0; | |
1994 | for (sub = abfd->archive_head; sub != NULL; sub = sub->next) | |
1995 | { | |
1996 | ++count; | |
1997 | total_namlen += strlen (normalize_filename (sub)) + 1; | |
1998 | } | |
1999 | offsets = (file_ptr *) bfd_alloc (abfd, count * sizeof (file_ptr)); | |
2000 | if (offsets == NULL) | |
2001 | return false; | |
2002 | ||
2003 | if (bfd_seek (abfd, SIZEOF_AR_FILE_HDR_BIG, SEEK_SET) != 0) | |
2004 | return false; | |
2005 | ||
2006 | makemap = bfd_has_map (abfd); | |
2007 | hasobjects = false; | |
2008 | prevoff = 0; | |
2009 | nextoff = SIZEOF_AR_FILE_HDR_BIG; | |
2010 | for (sub = abfd->archive_head, i = 0; sub != NULL; sub = sub->next, i++) | |
2011 | { | |
2012 | const char *name; | |
2013 | size_t namlen; | |
2014 | struct xcoff_ar_hdr_big *ahdrp; | |
2015 | bfd_size_type remaining; | |
2016 | ||
2017 | if (makemap && ! hasobjects) | |
2018 | { | |
2019 | if (bfd_check_format (sub, bfd_object)) | |
2020 | hasobjects = true; | |
2021 | } | |
2022 | ||
2023 | name = normalize_filename (sub); | |
2024 | namlen = strlen (name); | |
2025 | ||
2026 | if (sub->arelt_data != NULL) | |
2027 | ahdrp = arch_xhdr_big (sub); | |
2028 | else | |
2029 | ahdrp = NULL; | |
2030 | ||
2031 | if (ahdrp == NULL) | |
2032 | { | |
2033 | struct stat s; | |
2034 | ||
2035 | memset (&ahdr, 0, sizeof ahdr); | |
2036 | ahdrp = &ahdr; | |
2037 | /* XXX This should actually be a call to stat64 (at least on | |
2038 | 32-bit machines). */ | |
2039 | if (stat (bfd_get_filename (sub), &s) != 0) | |
2040 | { | |
2041 | bfd_set_error (bfd_error_system_call); | |
2042 | return false; | |
2043 | } | |
2044 | ||
2045 | /* XXX This call actually should use %lld (at least on 32-bit | |
2046 | machines) since the fields's width is 20 and there numbers with | |
2047 | more than 32 bits can be represented. */ | |
2048 | sprintf (ahdrp->size, "%ld", (long) s.st_size); | |
2049 | sprintf (ahdrp->date, "%ld", (long) s.st_mtime); | |
2050 | sprintf (ahdrp->uid, "%ld", (long) s.st_uid); | |
2051 | sprintf (ahdrp->gid, "%ld", (long) s.st_gid); | |
2052 | sprintf (ahdrp->mode, "%o", (unsigned int) s.st_mode); | |
2053 | ||
2054 | if (sub->arelt_data == NULL) | |
2055 | { | |
2056 | sub->arelt_data = bfd_alloc (sub, sizeof (struct areltdata)); | |
2057 | if (sub->arelt_data == NULL) | |
2058 | return false; | |
2059 | } | |
2060 | ||
2061 | arch_eltdata (sub)->parsed_size = s.st_size; | |
2062 | } | |
2063 | ||
2064 | /* XXX These calls actually should use %lld (at least on 32-bit | |
2065 | machines) since the fields's width is 20 and there numbers with | |
2066 | more than 32 bits can be represented. */ | |
2067 | sprintf (ahdrp->prevoff, "%ld", (long) prevoff); | |
2068 | sprintf (ahdrp->namlen, "%ld", (long) namlen); | |
2069 | ||
2070 | /* If the length of the name is odd, we write out the null byte | |
2071 | after the name as well. */ | |
2072 | namlen = (namlen + 1) &~ 1; | |
2073 | ||
2074 | remaining = arelt_size (sub); | |
2075 | size = (SIZEOF_AR_HDR_BIG | |
2076 | + namlen | |
2077 | + SXCOFFARFMAG | |
2078 | + remaining); | |
2079 | ||
2080 | BFD_ASSERT (nextoff == bfd_tell (abfd)); | |
2081 | ||
2082 | offsets[i] = nextoff; | |
2083 | ||
2084 | prevoff = nextoff; | |
2085 | nextoff += size + (size & 1); | |
2086 | ||
2087 | sprintf (ahdrp->nextoff, "%ld", (long) nextoff); | |
2088 | ||
2089 | /* We need spaces, not null bytes, in the header. */ | |
2090 | for (p = (char *) ahdrp; p < (char *) ahdrp + SIZEOF_AR_HDR_BIG; p++) | |
2091 | if (*p == '\0') | |
2092 | *p = ' '; | |
2093 | ||
2094 | if (bfd_write ((PTR) ahdrp, 1, SIZEOF_AR_HDR_BIG, abfd) | |
2095 | != SIZEOF_AR_HDR_BIG | |
2096 | || bfd_write ((PTR) name, 1, namlen, abfd) != namlen | |
2097 | || (bfd_write ((PTR) XCOFFARFMAG, 1, SXCOFFARFMAG, abfd) | |
2098 | != SXCOFFARFMAG)) | |
2099 | return false; | |
2100 | ||
2101 | if (bfd_seek (sub, (file_ptr) 0, SEEK_SET) != 0) | |
2102 | return false; | |
2103 | while (remaining != 0) | |
2104 | { | |
2105 | bfd_size_type amt; | |
2106 | bfd_byte buffer[DEFAULT_BUFFERSIZE]; | |
2107 | ||
2108 | amt = sizeof buffer; | |
2109 | if (amt > remaining) | |
2110 | amt = remaining; | |
2111 | if (bfd_read (buffer, 1, amt, sub) != amt | |
2112 | || bfd_write (buffer, 1, amt, abfd) != amt) | |
2113 | return false; | |
2114 | remaining -= amt; | |
2115 | } | |
2116 | ||
2117 | if ((size & 1) != 0) | |
2118 | { | |
2119 | bfd_byte b; | |
2120 | ||
2121 | b = '\0'; | |
2122 | if (bfd_write (&b, 1, 1, abfd) != 1) | |
2123 | return false; | |
2124 | } | |
2125 | } | |
2126 | ||
2127 | /* XXX This call actually should use %lld (at least on 32-bit | |
2128 | machines) since the fields's width is 20 and there numbers with | |
2129 | more than 32 bits can be represented. */ | |
2130 | sprintf (fhdr.lastmemoff, "%ld", (long) prevoff); | |
2131 | ||
2132 | /* Write out the member table. */ | |
2133 | ||
2134 | BFD_ASSERT (nextoff == bfd_tell (abfd)); | |
2135 | /* XXX This call actually should use %lld (at least on 32-bit | |
2136 | machines) since the fields's width is 20 and there numbers with | |
2137 | more than 32 bits can be represented. */ | |
2138 | sprintf (fhdr.memoff, "%ld", (long) nextoff); | |
2139 | ||
2140 | memset (&ahdr, 0, sizeof ahdr); | |
2141 | /* XXX The next two calls actually should use %lld (at least on 32-bit | |
2142 | machines) since the fields's width is 20 and there numbers with | |
2143 | more than 32 bits can be represented. */ | |
2144 | sprintf (ahdr.size, "%ld", (long) (12 + count * 12 + total_namlen)); | |
2145 | sprintf (ahdr.prevoff, "%ld", (long) prevoff); | |
2146 | sprintf (ahdr.date, "%d", 0); | |
2147 | sprintf (ahdr.uid, "%d", 0); | |
2148 | sprintf (ahdr.gid, "%d", 0); | |
2149 | sprintf (ahdr.mode, "%d", 0); | |
2150 | sprintf (ahdr.namlen, "%d", 0); | |
2151 | ||
2152 | size = (SIZEOF_AR_HDR_BIG | |
2153 | + 12 | |
2154 | + count * 12 | |
2155 | + total_namlen | |
2156 | + SXCOFFARFMAG); | |
2157 | ||
2158 | prevoff = nextoff; | |
2159 | nextoff += size + (size & 1); | |
2160 | ||
2161 | if (makemap && hasobjects) | |
2162 | /* XXX This call actually should use %lld (at least on 32-bit | |
2163 | machines) since the fields's width is 20 and there numbers with | |
2164 | more than 32 bits can be represented. */ | |
2165 | sprintf (ahdr.nextoff, "%ld", (long) nextoff); | |
2166 | else | |
2167 | sprintf (ahdr.nextoff, "%d", 0); | |
2168 | ||
2169 | /* We need spaces, not null bytes, in the header. */ | |
2170 | for (p = (char *) &ahdr; p < (char *) &ahdr + SIZEOF_AR_HDR_BIG; p++) | |
2171 | if (*p == '\0') | |
2172 | *p = ' '; | |
2173 | ||
2174 | if (bfd_write ((PTR) &ahdr, 1, SIZEOF_AR_HDR_BIG, abfd) != SIZEOF_AR_HDR_BIG | |
2175 | || (bfd_write ((PTR) XCOFFARFMAG, 1, SXCOFFARFMAG, abfd) | |
2176 | != SXCOFFARFMAG)) | |
2177 | return false; | |
2178 | ||
2179 | sprintf (decbuf, "%-12ld", (long) count); | |
2180 | if (bfd_write ((PTR) decbuf, 1, 12, abfd) != 12) | |
2181 | return false; | |
2182 | for (i = 0; i < count; i++) | |
2183 | { | |
2184 | sprintf (decbuf, "%-12ld", (long) offsets[i]); | |
2185 | if (bfd_write ((PTR) decbuf, 1, 12, abfd) != 12) | |
2186 | return false; | |
2187 | } | |
2188 | for (sub = abfd->archive_head; sub != NULL; sub = sub->next) | |
2189 | { | |
2190 | const char *name; | |
2191 | size_t namlen; | |
2192 | ||
2193 | name = normalize_filename (sub); | |
2194 | namlen = strlen (name); | |
2195 | if (bfd_write ((PTR) name, 1, namlen + 1, abfd) != namlen + 1) | |
2196 | return false; | |
2197 | } | |
2198 | if ((size & 1) != 0) | |
2199 | { | |
2200 | bfd_byte b; | |
2201 | ||
2202 | b = '\0'; | |
2203 | if (bfd_write ((PTR) &b, 1, 1, abfd) != 1) | |
2204 | return false; | |
2205 | } | |
2206 | ||
2207 | /* Write out the armap, if appropriate. */ | |
2208 | ||
2209 | if (! makemap || ! hasobjects) | |
2210 | sprintf (fhdr.symoff, "%d", 0); | |
2211 | else | |
2212 | { | |
2213 | BFD_ASSERT (nextoff == bfd_tell (abfd)); | |
2214 | /* XXX This call actually should use %lld (at least on 32-bit | |
2215 | machines) since the fields's width is 20 and there numbers with | |
2216 | more than 32 bits can be represented. */ | |
5ea1af0d GK |
2217 | bfd_ardata (abfd)->tdata = (PTR) &fhdr; |
2218 | if (! _bfd_compute_and_write_armap (abfd, 0)) | |
2219 | return false; | |
2220 | } | |
2221 | ||
2222 | /* Write out the archive file header. */ | |
2223 | ||
2224 | /* We need spaces, not null bytes, in the header. */ | |
2225 | for (p = (char *) &fhdr; p < (char *) &fhdr + SIZEOF_AR_FILE_HDR_BIG; p++) | |
2226 | if (*p == '\0') | |
2227 | *p = ' '; | |
2228 | ||
2229 | if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0 | |
2230 | || (bfd_write ((PTR) &fhdr, SIZEOF_AR_FILE_HDR_BIG, 1, abfd) != | |
2231 | SIZEOF_AR_FILE_HDR_BIG)) | |
2232 | return false; | |
2233 | ||
2234 | return true; | |
2235 | } | |
2236 | ||
7f6d05e8 CP |
2237 | boolean |
2238 | _bfd_xcoff_write_archive_contents (abfd) | |
5ea1af0d GK |
2239 | bfd *abfd; |
2240 | { | |
2241 | if (! xcoff_big_format_p (abfd)) | |
2242 | return xcoff_write_archive_contents_old (abfd); | |
2243 | else | |
2244 | return xcoff_write_archive_contents_big (abfd); | |
2245 | } | |
252b5132 RH |
2246 | \f |
2247 | /* We can't use the usual coff_sizeof_headers routine, because AIX | |
2248 | always uses an a.out header. */ | |
2249 | ||
beb1bf64 | 2250 | /*ARGSUSED*/ |
7f6d05e8 | 2251 | int |
252b5132 RH |
2252 | _bfd_xcoff_sizeof_headers (abfd, reloc) |
2253 | bfd *abfd; | |
5f771d47 | 2254 | boolean reloc ATTRIBUTE_UNUSED; |
252b5132 RH |
2255 | { |
2256 | int size; | |
2257 | ||
2258 | size = FILHSZ; | |
2259 | if (xcoff_data (abfd)->full_aouthdr) | |
2260 | size += AOUTSZ; | |
2261 | else | |
2262 | size += SMALL_AOUTSZ; | |
2263 | size += abfd->section_count * SCNHSZ; | |
2264 | return size; | |
2265 | } | |
beb1bf64 TR |
2266 | \f |
2267 | /* Routines to swap information in the XCOFF .loader section. If we | |
2268 | ever need to write an XCOFF loader, this stuff will need to be | |
2269 | moved to another file shared by the linker (which XCOFF calls the | |
2270 | ``binder'') and the loader. */ | |
2271 | ||
2272 | /* Swap in the ldhdr structure. */ | |
2273 | ||
2274 | static void | |
2275 | xcoff_swap_ldhdr_in (abfd, src, dst) | |
2276 | bfd *abfd; | |
2277 | const struct external_ldhdr *src; | |
2278 | struct internal_ldhdr *dst; | |
2279 | { | |
2280 | dst->l_version = bfd_get_32 (abfd, src->l_version); | |
2281 | dst->l_nsyms = bfd_get_32 (abfd, src->l_nsyms); | |
2282 | dst->l_nreloc = bfd_get_32 (abfd, src->l_nreloc); | |
2283 | dst->l_istlen = bfd_get_32 (abfd, src->l_istlen); | |
2284 | dst->l_nimpid = bfd_get_32 (abfd, src->l_nimpid); | |
2285 | dst->l_impoff = bfd_get_32 (abfd, src->l_impoff); | |
2286 | dst->l_stlen = bfd_get_32 (abfd, src->l_stlen); | |
2287 | dst->l_stoff = bfd_get_32 (abfd, src->l_stoff); | |
2288 | } | |
2289 | ||
2290 | /* Swap out the ldhdr structure. */ | |
2291 | ||
2292 | static void | |
2293 | xcoff_swap_ldhdr_out (abfd, src, dst) | |
2294 | bfd *abfd; | |
2295 | const struct internal_ldhdr *src; | |
2296 | struct external_ldhdr *dst; | |
2297 | { | |
2298 | bfd_put_32 (abfd, src->l_version, dst->l_version); | |
2299 | bfd_put_32 (abfd, src->l_nsyms, dst->l_nsyms); | |
2300 | bfd_put_32 (abfd, src->l_nreloc, dst->l_nreloc); | |
2301 | bfd_put_32 (abfd, src->l_istlen, dst->l_istlen); | |
2302 | bfd_put_32 (abfd, src->l_nimpid, dst->l_nimpid); | |
2303 | bfd_put_32 (abfd, src->l_impoff, dst->l_impoff); | |
2304 | bfd_put_32 (abfd, src->l_stlen, dst->l_stlen); | |
2305 | bfd_put_32 (abfd, src->l_stoff, dst->l_stoff); | |
2306 | } | |
2307 | ||
2308 | /* Swap in the ldsym structure. */ | |
2309 | ||
2310 | static void | |
2311 | xcoff_swap_ldsym_in (abfd, src, dst) | |
2312 | bfd *abfd; | |
2313 | const struct external_ldsym *src; | |
2314 | struct internal_ldsym *dst; | |
2315 | { | |
2316 | if (bfd_get_32 (abfd, src->_l._l_l._l_zeroes) != 0) { | |
2317 | memcpy (dst->_l._l_name, src->_l._l_name, SYMNMLEN); | |
2318 | } else { | |
2319 | dst->_l._l_l._l_zeroes = 0; | |
2320 | dst->_l._l_l._l_offset = bfd_get_32 (abfd, src->_l._l_l._l_offset); | |
2321 | } | |
2322 | dst->l_value = bfd_get_32 (abfd, src->l_value); | |
2323 | dst->l_scnum = bfd_get_16 (abfd, src->l_scnum); | |
2324 | dst->l_smtype = bfd_get_8 (abfd, src->l_smtype); | |
2325 | dst->l_smclas = bfd_get_8 (abfd, src->l_smclas); | |
2326 | dst->l_ifile = bfd_get_32 (abfd, src->l_ifile); | |
2327 | dst->l_parm = bfd_get_32 (abfd, src->l_parm); | |
2328 | } | |
2329 | ||
2330 | /* Swap out the ldsym structure. */ | |
2331 | ||
2332 | static void | |
2333 | xcoff_swap_ldsym_out (abfd, src, dst) | |
2334 | bfd *abfd; | |
2335 | const struct internal_ldsym *src; | |
2336 | struct external_ldsym *dst; | |
2337 | { | |
2338 | ||
2339 | if (src->_l._l_l._l_zeroes != 0) | |
2340 | memcpy (dst->_l._l_name, src->_l._l_name, SYMNMLEN); | |
2341 | else | |
2342 | { | |
2343 | bfd_put_32 (abfd, 0, dst->_l._l_l._l_zeroes); | |
2344 | bfd_put_32 (abfd, src->_l._l_l._l_offset, dst->_l._l_l._l_offset); | |
2345 | } | |
2346 | bfd_put_32 (abfd, src->l_value, dst->l_value); | |
2347 | bfd_put_16 (abfd, src->l_scnum, dst->l_scnum); | |
2348 | bfd_put_8 (abfd, src->l_smtype, dst->l_smtype); | |
2349 | bfd_put_8 (abfd, src->l_smclas, dst->l_smclas); | |
2350 | bfd_put_32 (abfd, src->l_ifile, dst->l_ifile); | |
2351 | bfd_put_32 (abfd, src->l_parm, dst->l_parm); | |
2352 | } | |
2353 | ||
2354 | /* Swap in the ldrel structure. */ | |
2355 | ||
2356 | static void | |
2357 | xcoff_swap_ldrel_in (abfd, src, dst) | |
2358 | bfd *abfd; | |
2359 | const struct external_ldrel *src; | |
2360 | struct internal_ldrel *dst; | |
2361 | { | |
2362 | dst->l_vaddr = bfd_get_32 (abfd, src->l_vaddr); | |
2363 | dst->l_symndx = bfd_get_32 (abfd, src->l_symndx); | |
2364 | dst->l_rtype = bfd_get_16 (abfd, src->l_rtype); | |
2365 | dst->l_rsecnm = bfd_get_16 (abfd, src->l_rsecnm); | |
2366 | } | |
2367 | ||
2368 | /* Swap out the ldrel structure. */ | |
2369 | ||
2370 | static void | |
2371 | xcoff_swap_ldrel_out (abfd, src, dst) | |
2372 | bfd *abfd; | |
2373 | const struct internal_ldrel *src; | |
2374 | struct external_ldrel *dst; | |
2375 | { | |
2376 | bfd_put_32 (abfd, src->l_vaddr, dst->l_vaddr); | |
2377 | bfd_put_32 (abfd, src->l_symndx, dst->l_symndx); | |
2378 | bfd_put_16 (abfd, src->l_rtype, dst->l_rtype); | |
2379 | bfd_put_16 (abfd, src->l_rsecnm, dst->l_rsecnm); | |
2380 | } | |
2381 | \f | |
2382 | ||
2383 | ||
2384 | /* This is the relocation function for the RS/6000/POWER/PowerPC. | |
2385 | This is currently the only processor which uses XCOFF; I hope that | |
2386 | will never change. */ | |
2387 | ||
a7b97311 | 2388 | static boolean |
beb1bf64 TR |
2389 | xcoff_ppc_relocate_section (output_bfd, info, input_bfd, |
2390 | input_section, contents, relocs, syms, | |
2391 | sections) | |
2392 | bfd *output_bfd; | |
2393 | struct bfd_link_info *info; | |
2394 | bfd *input_bfd; | |
2395 | asection *input_section; | |
2396 | bfd_byte *contents; | |
2397 | struct internal_reloc *relocs; | |
2398 | struct internal_syment *syms; | |
2399 | asection **sections; | |
2400 | { | |
2401 | struct internal_reloc *rel; | |
2402 | struct internal_reloc *relend; | |
2403 | ||
2404 | rel = relocs; | |
2405 | relend = rel + input_section->reloc_count; | |
2406 | ||
2407 | for (; rel < relend; rel++) | |
2408 | { | |
2409 | long symndx; | |
2410 | struct xcoff_link_hash_entry *h; | |
2411 | struct internal_syment *sym; | |
2412 | bfd_vma addend; | |
2413 | bfd_vma val; | |
2414 | struct reloc_howto_struct howto; | |
2415 | bfd_reloc_status_type rstat; | |
2416 | ||
2417 | /* Relocation type R_REF is a special relocation type which is | |
2418 | merely used to prevent garbage collection from occurring for | |
2419 | the csect including the symbol which it references. */ | |
2420 | if (rel->r_type == R_REF) | |
2421 | continue; | |
2422 | ||
2423 | symndx = rel->r_symndx; | |
2424 | ||
2425 | if (symndx == -1) | |
2426 | { | |
2427 | h = NULL; | |
2428 | sym = NULL; | |
2429 | addend = 0; | |
2430 | } | |
2431 | else | |
2432 | { | |
2433 | h = obj_xcoff_sym_hashes (input_bfd)[symndx]; | |
2434 | sym = syms + symndx; | |
2435 | addend = - sym->n_value; | |
2436 | ||
2437 | } | |
2438 | ||
2439 | /* We build the howto information on the fly. */ | |
2440 | ||
2441 | howto.type = rel->r_type; | |
2442 | howto.rightshift = 0; | |
2443 | howto.size = 2; | |
2444 | howto.bitsize = (rel->r_size & 0x1f) + 1; | |
2445 | howto.pc_relative = false; | |
2446 | howto.bitpos = 0; | |
2447 | if ((rel->r_size & 0x80) != 0) | |
2448 | howto.complain_on_overflow = complain_overflow_signed; | |
2449 | else | |
2450 | howto.complain_on_overflow = complain_overflow_bitfield; | |
2451 | howto.special_function = NULL; | |
2452 | howto.name = "internal"; | |
2453 | howto.partial_inplace = true; | |
2454 | if (howto.bitsize == 32) | |
2455 | howto.src_mask = howto.dst_mask = 0xffffffff; | |
2456 | else | |
2457 | { | |
2458 | howto.src_mask = howto.dst_mask = (1 << howto.bitsize) - 1; | |
2459 | if (howto.bitsize == 16) | |
2460 | howto.size = 1; | |
2461 | } | |
2462 | howto.pcrel_offset = false; | |
2463 | ||
2464 | val = 0; | |
2465 | ||
2466 | if (h == NULL) | |
2467 | { | |
2468 | asection *sec; | |
2469 | ||
2470 | if (symndx == -1) | |
2471 | { | |
2472 | sec = bfd_abs_section_ptr; | |
2473 | val = 0; | |
2474 | } | |
2475 | else | |
2476 | { | |
2477 | sec = sections[symndx]; | |
2478 | /* Hack to make sure we use the right TOC anchor value | |
2479 | if this reloc is against the TOC anchor. */ | |
2480 | ||
2481 | if (sec->name[3] == '0' | |
2482 | && strcmp (sec->name, ".tc0") == 0) { | |
2483 | ||
2484 | val = xcoff_data (output_bfd)->toc; | |
2485 | } else { | |
2486 | ||
2487 | val = (sec->output_section->vma | |
2488 | + sec->output_offset | |
2489 | + sym->n_value | |
2490 | - sec->vma); | |
2491 | } | |
2492 | ||
2493 | } | |
2494 | } | |
2495 | else | |
2496 | { | |
2497 | if (h->root.type == bfd_link_hash_defined | |
2498 | || h->root.type == bfd_link_hash_defweak) | |
2499 | { | |
2500 | asection *sec; | |
2501 | ||
2502 | sec = h->root.u.def.section; | |
2503 | val = (h->root.u.def.value | |
2504 | + sec->output_section->vma | |
2505 | + sec->output_offset); | |
2506 | } | |
2507 | else if (h->root.type == bfd_link_hash_common) | |
2508 | { | |
2509 | asection *sec; | |
2510 | ||
2511 | sec = h->root.u.c.p->section; | |
2512 | val = (sec->output_section->vma | |
2513 | + sec->output_offset); | |
2514 | } | |
2515 | else if ((h->flags & XCOFF_DEF_DYNAMIC) != 0 | |
2516 | || (h->flags & XCOFF_IMPORT) != 0) | |
2517 | { | |
2518 | /* Every symbol in a shared object is defined somewhere. */ | |
2519 | val = 0; | |
2520 | } | |
2521 | else if (! info->relocateable) | |
2522 | { | |
2523 | if (! ((*info->callbacks->undefined_symbol) | |
2524 | (info, h->root.root.string, input_bfd, input_section, | |
2525 | rel->r_vaddr - input_section->vma, true))) | |
2526 | return false; | |
2527 | ||
2528 | /* Don't try to process the reloc. It can't help, and | |
2529 | it may generate another error. */ | |
2530 | continue; | |
2531 | } | |
2532 | } | |
2533 | ||
2534 | /* I took the relocation type definitions from two documents: | |
2535 | the PowerPC AIX Version 4 Application Binary Interface, First | |
2536 | Edition (April 1992), and the PowerOpen ABI, Big-Endian | |
2537 | 32-Bit Hardware Implementation (June 30, 1994). Differences | |
2538 | between the documents are noted below. */ | |
2539 | ||
2540 | switch (rel->r_type) | |
2541 | { | |
2542 | case R_RTB: | |
2543 | case R_RRTBI: | |
2544 | case R_RRTBA: | |
2545 | /* These relocs are defined by the PowerPC ABI to be | |
2546 | relative branches which use half of the difference | |
2547 | between the symbol and the program counter. I can't | |
2548 | quite figure out when this is useful. These relocs are | |
2549 | not defined by the PowerOpen ABI. */ | |
2550 | default: | |
2551 | (*_bfd_error_handler) | |
2552 | (_("%s: unsupported relocation type 0x%02x"), | |
2553 | bfd_get_filename (input_bfd), (unsigned int) rel->r_type); | |
2554 | bfd_set_error (bfd_error_bad_value); | |
2555 | return false; | |
2556 | case R_POS: | |
2557 | /* Simple positive relocation. */ | |
2558 | break; | |
2559 | case R_NEG: | |
2560 | /* Simple negative relocation. */ | |
2561 | val = - val; | |
2562 | break; | |
2563 | case R_REL: | |
2564 | /* Simple PC relative relocation. */ | |
2565 | howto.pc_relative = true; | |
2566 | break; | |
2567 | case R_TOC: | |
2568 | /* TOC relative relocation. The value in the instruction in | |
2569 | the input file is the offset from the input file TOC to | |
2570 | the desired location. We want the offset from the final | |
2571 | TOC to the desired location. We have: | |
2572 | isym = iTOC + in | |
2573 | iinsn = in + o | |
2574 | osym = oTOC + on | |
2575 | oinsn = on + o | |
2576 | so we must change insn by on - in. | |
2577 | */ | |
2578 | case R_GL: | |
2579 | /* Global linkage relocation. The value of this relocation | |
2580 | is the address of the entry in the TOC section. */ | |
2581 | case R_TCL: | |
2582 | /* Local object TOC address. I can't figure out the | |
2583 | difference between this and case R_GL. */ | |
2584 | case R_TRL: | |
2585 | /* TOC relative relocation. A TOC relative load instruction | |
2586 | which may be changed to a load address instruction. | |
2587 | FIXME: We don't currently implement this optimization. */ | |
2588 | case R_TRLA: | |
2589 | /* TOC relative relocation. This is a TOC relative load | |
2590 | address instruction which may be changed to a load | |
2591 | instruction. FIXME: I don't know if this is the correct | |
2592 | implementation. */ | |
2593 | if (h != NULL && h->smclas != XMC_TD) | |
2594 | { | |
2595 | if (h->toc_section == NULL) | |
2596 | { | |
2597 | (*_bfd_error_handler) | |
2598 | (_("%s: TOC reloc at 0x%x to symbol `%s' with no TOC entry"), | |
2599 | bfd_get_filename (input_bfd), rel->r_vaddr, | |
2600 | h->root.root.string); | |
2601 | bfd_set_error (bfd_error_bad_value); | |
2602 | return false; | |
2603 | } | |
2604 | ||
2605 | BFD_ASSERT ((h->flags & XCOFF_SET_TOC) == 0); | |
2606 | val = (h->toc_section->output_section->vma | |
2607 | + h->toc_section->output_offset); | |
2608 | } | |
2609 | ||
2610 | val = ((val - xcoff_data (output_bfd)->toc) | |
2611 | - (sym->n_value - xcoff_data (input_bfd)->toc)); | |
2612 | addend = 0; | |
2613 | break; | |
2614 | case R_BA: | |
2615 | /* Absolute branch. We don't want to mess with the lower | |
2616 | two bits of the instruction. */ | |
2617 | case R_CAI: | |
2618 | /* The PowerPC ABI defines this as an absolute call which | |
2619 | may be modified to become a relative call. The PowerOpen | |
2620 | ABI does not define this relocation type. */ | |
2621 | case R_RBA: | |
2622 | /* Absolute branch which may be modified to become a | |
2623 | relative branch. */ | |
2624 | case R_RBAC: | |
2625 | /* The PowerPC ABI defines this as an absolute branch to a | |
2626 | fixed address which may be modified to an absolute branch | |
2627 | to a symbol. The PowerOpen ABI does not define this | |
2628 | relocation type. */ | |
2629 | case R_RBRC: | |
2630 | /* The PowerPC ABI defines this as an absolute branch to a | |
2631 | fixed address which may be modified to a relative branch. | |
2632 | The PowerOpen ABI does not define this relocation type. */ | |
2633 | howto.src_mask &= ~3; | |
2634 | howto.dst_mask = howto.src_mask; | |
2635 | break; | |
2636 | case R_BR: | |
2637 | /* Relative branch. We don't want to mess with the lower | |
2638 | two bits of the instruction. */ | |
2639 | case R_CREL: | |
2640 | /* The PowerPC ABI defines this as a relative call which may | |
2641 | be modified to become an absolute call. The PowerOpen | |
2642 | ABI does not define this relocation type. */ | |
2643 | case R_RBR: | |
2644 | /* A relative branch which may be modified to become an | |
2645 | absolute branch. FIXME: We don't implement this, | |
2646 | although we should for symbols of storage mapping class | |
2647 | XMC_XO. */ | |
2648 | howto.pc_relative = true; | |
2649 | howto.src_mask &= ~3; | |
2650 | howto.dst_mask = howto.src_mask; | |
2651 | break; | |
2652 | case R_RL: | |
2653 | /* The PowerPC AIX ABI describes this as a load which may be | |
2654 | changed to a load address. The PowerOpen ABI says this | |
2655 | is the same as case R_POS. */ | |
2656 | break; | |
2657 | case R_RLA: | |
2658 | /* The PowerPC AIX ABI describes this as a load address | |
2659 | which may be changed to a load. The PowerOpen ABI says | |
2660 | this is the same as R_POS. */ | |
2661 | break; | |
2662 | } | |
2663 | ||
2664 | /* If we see an R_BR or R_RBR reloc which is jumping to global | |
2665 | linkage code, and it is followed by an appropriate cror nop | |
2666 | instruction, we replace the cror with lwz r2,20(r1). This | |
2667 | restores the TOC after the glink code. Contrariwise, if the | |
2668 | call is followed by a lwz r2,20(r1), but the call is not | |
2669 | going to global linkage code, we can replace the load with a | |
2670 | cror. */ | |
2671 | if ((rel->r_type == R_BR || rel->r_type == R_RBR) | |
2672 | && h != NULL | |
2673 | && h->root.type == bfd_link_hash_defined | |
2674 | && (rel->r_vaddr - input_section->vma + 8 | |
2675 | <= input_section->_cooked_size)) | |
2676 | { | |
2677 | bfd_byte *pnext; | |
2678 | unsigned long next; | |
2679 | ||
2680 | pnext = contents + (rel->r_vaddr - input_section->vma) + 4; | |
2681 | next = bfd_get_32 (input_bfd, pnext); | |
2682 | ||
2683 | /* The _ptrgl function is magic. It is used by the AIX | |
2684 | compiler to call a function through a pointer. */ | |
2685 | if (h->smclas == XMC_GL | |
2686 | || strcmp (h->root.root.string, "._ptrgl") == 0) | |
2687 | { | |
2688 | if (next == 0x4def7b82 /* cror 15,15,15 */ | |
2689 | || next == 0x4ffffb82 /* cror 31,31,31 */ | |
2690 | || next == 0x60000000) /* ori r0,r0,0 */ | |
2691 | bfd_put_32 (input_bfd, 0x80410014, pnext); /* lwz r1,20(r1) */ | |
2692 | } | |
2693 | else | |
2694 | { | |
2695 | if (next == 0x80410014) /* lwz r1,20(r1) */ | |
2696 | bfd_put_32 (input_bfd, 0x60000000, pnext); /* ori r0,r0,0 */ | |
2697 | } | |
2698 | } | |
2699 | ||
2700 | /* A PC relative reloc includes the section address. */ | |
2701 | if (howto.pc_relative) | |
2702 | addend += input_section->vma; | |
2703 | ||
2704 | rstat = _bfd_final_link_relocate (&howto, input_bfd, input_section, | |
2705 | contents, | |
2706 | rel->r_vaddr - input_section->vma, | |
2707 | val, addend); | |
2708 | ||
2709 | switch (rstat) | |
2710 | { | |
2711 | default: | |
2712 | abort (); | |
2713 | case bfd_reloc_ok: | |
2714 | break; | |
2715 | case bfd_reloc_overflow: | |
2716 | { | |
2717 | const char *name; | |
2718 | char buf[SYMNMLEN + 1]; | |
2719 | char howto_name[10]; | |
2720 | ||
2721 | if (symndx == -1) | |
2722 | name = "*ABS*"; | |
2723 | else if (h != NULL) | |
2724 | name = h->root.root.string; | |
2725 | else | |
2726 | { | |
2727 | ||
2728 | name = _bfd_coff_internal_syment_name (input_bfd, sym, buf); | |
2729 | ||
2730 | if (name == NULL) | |
2731 | return false; | |
2732 | } | |
2733 | sprintf (howto_name, "0x%02x", rel->r_type); | |
2734 | ||
2735 | if (! ((*info->callbacks->reloc_overflow) | |
2736 | (info, name, howto_name, (bfd_vma) 0, input_bfd, | |
2737 | input_section, rel->r_vaddr - input_section->vma))) | |
2738 | return false; | |
2739 | } | |
2740 | } | |
2741 | } | |
2742 | ||
2743 | return true; | |
2744 | } | |
2745 | ||
2746 | static boolean | |
2747 | _bfd_xcoff_put_ldsymbol_name (abfd, ldinfo, ldsym, name) | |
2748 | bfd *abfd ATTRIBUTE_UNUSED; | |
2749 | struct xcoff_loader_info *ldinfo; | |
2750 | struct internal_ldsym *ldsym; | |
2751 | const char *name; | |
2752 | { | |
2753 | size_t len; | |
2754 | len = strlen (name); | |
2755 | ||
2756 | if (len <= SYMNMLEN) | |
2757 | strncpy (ldsym->_l._l_name, name, SYMNMLEN); | |
2758 | else | |
2759 | { | |
2760 | if (ldinfo->string_size + len + 3 > ldinfo->string_alc) | |
2761 | { | |
2762 | size_t newalc; | |
2763 | bfd_byte *newstrings; | |
2764 | ||
2765 | newalc = ldinfo->string_alc * 2; | |
2766 | if (newalc == 0) | |
2767 | newalc = 32; | |
2768 | while (ldinfo->string_size + len + 3 > newalc) | |
2769 | newalc *= 2; | |
2770 | ||
2771 | newstrings = ((bfd_byte *) | |
2772 | bfd_realloc ((PTR) ldinfo->strings, newalc)); | |
2773 | if (newstrings == NULL) | |
2774 | { | |
2775 | ldinfo->failed = true; | |
2776 | return false; | |
2777 | } | |
2778 | ldinfo->string_alc = newalc; | |
2779 | ldinfo->strings = newstrings; | |
2780 | } | |
2781 | ||
2782 | bfd_put_16 (ldinfo->output_bfd, len + 1, | |
2783 | ldinfo->strings + ldinfo->string_size); | |
2784 | strcpy (ldinfo->strings + ldinfo->string_size + 2, name); | |
2785 | ldsym->_l._l_l._l_zeroes = 0; | |
2786 | ldsym->_l._l_l._l_offset = ldinfo->string_size + 2; | |
2787 | ldinfo->string_size += len + 3; | |
2788 | } | |
2789 | ||
2790 | return true; | |
2791 | } | |
2792 | ||
2793 | static boolean | |
2794 | _bfd_xcoff_put_symbol_name (bfd *abfd, struct bfd_strtab_hash *strtab, | |
2795 | struct internal_syment *sym, | |
2796 | const char *name) { | |
2797 | ||
2798 | if (strlen (name) <= SYMNMLEN) { | |
2799 | strncpy (sym->_n._n_name, name, SYMNMLEN); | |
2800 | } else { | |
2801 | boolean hash; | |
2802 | bfd_size_type indx; | |
2803 | ||
2804 | hash = true; | |
2805 | if ((abfd->flags & BFD_TRADITIONAL_FORMAT) != 0) | |
2806 | hash = false; | |
2807 | indx = _bfd_stringtab_add (strtab, name, hash, false); | |
2808 | if (indx == (bfd_size_type) -1) | |
2809 | return false; | |
2810 | sym->_n._n_n._n_zeroes = 0; | |
2811 | sym->_n._n_n._n_offset = STRING_SIZE_SIZE + indx; | |
2812 | } | |
2813 | return true; | |
2814 | } | |
2815 | ||
2816 | static asection * | |
2817 | xcoff_create_csect_from_smclas (abfd, aux, symbol_name) | |
2818 | bfd *abfd; | |
2819 | union internal_auxent *aux; | |
2820 | char *symbol_name; | |
2821 | { | |
2822 | ||
2823 | asection *return_value = NULL; | |
2824 | ||
2825 | /* | |
2826 | * .sv64 = x_smclas == 17 | |
2827 | * This is an invalid csect for 32 bit apps. | |
2828 | */ | |
2829 | static const char *names[19] = { | |
2830 | ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo", | |
2831 | ".sv", ".bs", ".ds", ".uc", ".ti", ".tb", NULL, ".tc0", | |
2832 | ".td", NULL, ".sv3264" | |
2833 | }; | |
2834 | ||
2835 | if ((19 >= aux->x_csect.x_smclas) && | |
2836 | (NULL != names[aux->x_csect.x_smclas])) { | |
2837 | ||
2838 | return_value = bfd_make_section_anyway | |
2839 | (abfd, names[aux->x_csect.x_smclas]); | |
2840 | ||
2841 | ||
2842 | } else { | |
2843 | (*_bfd_error_handler) | |
2844 | (_("%s: symbol `%s' has unrecognized smclas %d"), | |
2845 | bfd_get_filename (abfd), symbol_name, aux->x_csect.x_smclas); | |
2846 | bfd_set_error (bfd_error_bad_value); | |
2847 | } | |
2848 | ||
2849 | return return_value; | |
2850 | } | |
2851 | ||
a7b97311 | 2852 | static boolean |
beb1bf64 TR |
2853 | xcoff_is_lineno_count_overflow (abfd, value) |
2854 | bfd *abfd ATTRIBUTE_UNUSED; | |
2855 | bfd_vma value; | |
2856 | { | |
2857 | if (0xffff <= value) { | |
2858 | return true; | |
2859 | } | |
2860 | return false; | |
2861 | } | |
2862 | ||
a7b97311 | 2863 | static boolean |
beb1bf64 TR |
2864 | xcoff_is_reloc_count_overflow (abfd, value) |
2865 | bfd *abfd ATTRIBUTE_UNUSED; | |
2866 | bfd_vma value; | |
2867 | { | |
2868 | if (0xffff <= value) { | |
2869 | return true; | |
2870 | } | |
2871 | return false; | |
2872 | } | |
2873 | ||
a7b97311 | 2874 | static bfd_vma |
beb1bf64 TR |
2875 | xcoff_loader_symbol_offset (abfd, ldhdr) |
2876 | bfd *abfd; | |
2877 | struct internal_ldhdr *ldhdr ATTRIBUTE_UNUSED; | |
2878 | { | |
2879 | return bfd_xcoff_ldhdrsz(abfd); | |
2880 | } | |
2881 | ||
a7b97311 | 2882 | static bfd_vma |
beb1bf64 TR |
2883 | xcoff_loader_reloc_offset (abfd, ldhdr) |
2884 | bfd *abfd; | |
2885 | struct internal_ldhdr *ldhdr; | |
2886 | { | |
2887 | return bfd_xcoff_ldhdrsz(abfd) + | |
2888 | (ldhdr->l_nsyms * bfd_xcoff_ldsymsz(abfd)); | |
2889 | } | |
2890 | ||
2891 | ||
2892 | static reloc_howto_type xcoff_dynamic_reloc = | |
2893 | HOWTO (0, /* type */ | |
2894 | 0, /* rightshift */ | |
2895 | 2, /* size (0 = byte, 1 = short, 2 = long) */ | |
2896 | 32, /* bitsize */ | |
2897 | false, /* pc_relative */ | |
2898 | 0, /* bitpos */ | |
2899 | complain_overflow_bitfield, /* complain_on_overflow */ | |
2900 | 0, /* special_function */ | |
2901 | "R_POS", /* name */ | |
2902 | true, /* partial_inplace */ | |
2903 | 0xffffffff, /* src_mask */ | |
2904 | 0xffffffff, /* dst_mask */ | |
2905 | false); /* pcrel_offset */ | |
2906 | ||
2907 | /* | |
2908 | * glink | |
2909 | * | |
2910 | * The first word of global linkage code must be modified by filling in | |
2911 | * the correct TOC offset. | |
2912 | */ | |
2913 | static unsigned long xcoff_glink_code[9] = | |
2914 | { | |
2915 | 0x81820000, /* lwz r12,0(r2) */ | |
2916 | 0x90410014, /* stw r2,20(r1) */ | |
2917 | 0x800c0000, /* lwz r0,0(r12) */ | |
2918 | 0x804c0004, /* lwz r2,4(r12) */ | |
2919 | 0x7c0903a6, /* mtctr r0 */ | |
2920 | 0x4e800420, /* bctr */ | |
2921 | 0x00000000, /* start of traceback table */ | |
2922 | 0x000c8000, /* traceback table */ | |
2923 | 0x00000000, /* traceback table */ | |
2924 | }; | |
2925 | ||
2926 | ||
2927 | static const struct xcoff_backend_data_rec bfd_xcoff_backend_data = | |
2928 | { | |
2929 | { /* COFF backend, defined in libcoff.h */ | |
2930 | _bfd_xcoff_swap_aux_in, /* _bfd_coff_swap_aux_in */ | |
2931 | _bfd_xcoff_swap_sym_in, /* _bfd_coff_swap_sym_in */ | |
2932 | coff_swap_lineno_in, /* _bfd_coff_swap_lineno_in */ | |
2933 | _bfd_xcoff_swap_aux_out, /* _bfd_swap_aux_out */ | |
2934 | _bfd_xcoff_swap_sym_out, /* _bfd_swap_sym_out */ | |
2935 | coff_swap_lineno_out, /* _bfd_swap_lineno_out */ | |
2936 | coff_swap_reloc_out, /* _bfd_swap_reloc_out */ | |
2937 | coff_swap_filehdr_out, /* _bfd_swap_filehdr_out */ | |
2938 | coff_swap_aouthdr_out, /* _bfd_swap_aouthdr_out */ | |
2939 | coff_swap_scnhdr_out, /* _bfd_swap_scnhdr_out */ | |
2940 | FILHSZ, /* _bfd_filhsz */ | |
2941 | AOUTSZ, /* _bfd_aoutsz */ | |
2942 | SCNHSZ, /* _bfd_scnhsz */ | |
2943 | SYMESZ, /* _bfd_symesz */ | |
2944 | AUXESZ, /* _bfd_auxesz */ | |
2945 | RELSZ, /* _bfd_relsz */ | |
2946 | LINESZ, /* _bfd_linesz */ | |
2947 | FILNMLEN, /* _bfd_filnmlen */ | |
2948 | true, /* _bfd_coff_long_filenames */ | |
2949 | false, /* _bfd_coff_long_section_names */ | |
2950 | (3), /* _bfd_coff_default_section_alignment_power */ | |
2951 | false, /* _bfd_coff_force_symnames_in_strings */ | |
2952 | 2, /* _bfd_coff_debug_string_prefix_length */ | |
2953 | coff_swap_filehdr_in, /* _bfd_coff_swap_filehdr_in */ | |
2954 | coff_swap_aouthdr_in, /* _bfd_swap_aouthdr_in */ | |
2955 | coff_swap_scnhdr_in, /* _bfd_swap_scnhdr_in */ | |
2956 | coff_swap_reloc_in, /* _bfd_reloc_in */ | |
2957 | coff_bad_format_hook, /* _bfd_bad_format_hook */ | |
2958 | coff_set_arch_mach_hook, /* _bfd_set_arch_mach_hook */ | |
2959 | coff_mkobject_hook, /* _bfd_mkobject_hook */ | |
2960 | styp_to_sec_flags, /* _bfd_syp_to_sec_flags */ | |
2961 | coff_set_alignment_hook, /* _bfd_set_alignment_hook */ | |
2962 | coff_slurp_symbol_table, /* _bfd_coff_slurp_symbol_table */ | |
2963 | symname_in_debug_hook, /* _coff_symname_in_debug_hook */ | |
2964 | coff_pointerize_aux_hook, /* _bfd_coff_pointerize_aux_hook */ | |
2965 | coff_print_aux, /* bfd_coff_print_aux */ | |
2966 | dummy_reloc16_extra_cases, /* _bfd_coff_reloc16_extra_cases */ | |
2967 | dummy_reloc16_estimate, /* _bfd_coff_reloc16_estimate */ | |
2968 | NULL, /* bfd_coff_sym_is_global */ | |
2969 | /* _bfd_coff_compute_section_file_positions */ | |
2970 | coff_compute_section_file_positions, | |
2971 | NULL , /* _bfd_coff_start_final_link */ | |
2972 | xcoff_ppc_relocate_section, /* _bfd_coff_relocate_section */ | |
2973 | coff_rtype_to_howto, /* _bfd_coff_rtype_to_howto */ | |
2974 | NULL , /* _bfd_coff_addust_symndx */ | |
2975 | _bfd_generic_link_add_one_symbol, /* _bfd_coff_add_one_symbol */ | |
2976 | coff_link_output_has_begun, /* _bfd_coff_link_output_has_begun */ | |
2977 | coff_final_link_postscript /* _bfd_coff_final_link_postscript */ | |
2978 | }, | |
2979 | ||
2980 | 0x01DF, /* magic number */ | |
2981 | bfd_arch_rs6000, /* architecture */ | |
2982 | bfd_mach_rs6k, /* machine */ | |
2983 | ||
2984 | ||
2985 | /* function pointers to xcoff specific swap routines */ | |
2986 | xcoff_swap_ldhdr_in, /* _xcoff_swap_ldhdr_in */ | |
2987 | xcoff_swap_ldhdr_out, /* _xcoff_swap_ldhdr_out */ | |
2988 | xcoff_swap_ldsym_in, /* _xcoff_swap_ldsym_in */ | |
2989 | xcoff_swap_ldsym_out, /* _xcoff_swap_ldsym_out */ | |
2990 | xcoff_swap_ldrel_in, /* _xcoff_swap_ldrel_in */ | |
2991 | xcoff_swap_ldrel_out, /* _xcoff_swap_ldrel_out */ | |
2992 | ||
2993 | /* sizes */ | |
2994 | LDHDRSZ, /* _xcoff_ldhdrsz */ | |
2995 | LDSYMSZ, /* _xcoff_ldsymsz */ | |
2996 | LDRELSZ, /* _xcoff_ldrelsz */ | |
2997 | 12, /* _xcoff_function_descriptor_size */ | |
2998 | SMALL_AOUTSZ, /* _xcoff_small_aout_header_size */ | |
2999 | ||
3000 | /* versions */ | |
3001 | 1, /* _xcoff_ldhdr_version */ | |
3002 | ||
3003 | /* xcoff vs xcoff64 putting symbol names */ | |
3004 | _bfd_xcoff_put_symbol_name, /* _xcoff_put_symbol_name */ | |
3005 | _bfd_xcoff_put_ldsymbol_name, /* _xcoff_put_ldsymbol_name */ | |
3006 | ||
3007 | &xcoff_dynamic_reloc, /* dynamic reloc howto */ | |
3008 | ||
3009 | xcoff_create_csect_from_smclas, /* _xcoff_create_csect_from_smclas */ | |
3010 | ||
3011 | /* lineno and reloc count overflow */ | |
3012 | xcoff_is_lineno_count_overflow, | |
3013 | xcoff_is_reloc_count_overflow, | |
3014 | ||
3015 | xcoff_loader_symbol_offset, | |
3016 | xcoff_loader_reloc_offset, | |
3017 | ||
3018 | /* glink */ | |
3019 | &xcoff_glink_code[0], | |
3020 | (36), /* _xcoff_glink_size */ | |
3021 | ||
3022 | }; | |
3023 | ||
3024 | /* The transfer vector that leads the outside world to all of the above. */ | |
3025 | const bfd_target rs6000coff_vec = | |
3026 | { | |
3027 | "aixcoff-rs6000", | |
3028 | bfd_target_xcoff_flavour, | |
3029 | BFD_ENDIAN_BIG, /* data byte order is big */ | |
3030 | BFD_ENDIAN_BIG, /* header byte order is big */ | |
3031 | ||
3032 | (HAS_RELOC | EXEC_P | /* object flags */ | |
3033 | HAS_LINENO | HAS_DEBUG | DYNAMIC | | |
3034 | HAS_SYMS | HAS_LOCALS | WP_TEXT), | |
3035 | ||
3036 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ | |
3037 | 0, /* leading char */ | |
3038 | '/', /* ar_pad_char */ | |
3039 | 15, /* ar_max_namelen??? FIXMEmgo */ | |
3040 | ||
3041 | /* data */ | |
3042 | bfd_getb64, /* bfd_getx64 */ | |
3043 | bfd_getb_signed_64, /* bfd_getx_signed_64 */ | |
3044 | bfd_putb64, /* bfd_putx64 */ | |
3045 | bfd_getb32, /* bfd_getx32 */ | |
3046 | bfd_getb_signed_32, /* bfd_getx_signed_32 */ | |
3047 | bfd_putb32, /* bfd_putx32 */ | |
3048 | bfd_getb16, /* bfd_getx16 */ | |
3049 | bfd_getb_signed_16, /* bfd_getx_signed_16 */ | |
3050 | bfd_putb16, /* bfd_putx16 */ | |
3051 | ||
3052 | /* hdrs */ | |
3053 | bfd_getb64, /* bfd_h_getx64 */ | |
3054 | bfd_getb_signed_64, /* bfd_h_getx_signed_64 */ | |
3055 | bfd_putb64, /* bfd_h_putx64 */ | |
3056 | bfd_getb32, /* bfd_h_getx32 */ | |
3057 | bfd_getb_signed_32, /* bfd_h_getx_signed_32 */ | |
3058 | bfd_putb32, /* bfd_h_putx32 */ | |
3059 | bfd_getb16, /* bfd_h_getx16 */ | |
3060 | bfd_getb_signed_16, /* bfd_h_getx_signed_16 */ | |
3061 | bfd_putb16, /* bfd_h_putx16 */ | |
3062 | ||
3063 | { /* bfd_check_format */ | |
3064 | _bfd_dummy_target, | |
3065 | coff_object_p, | |
3066 | _bfd_xcoff_archive_p, | |
3067 | CORE_FILE_P | |
3068 | }, | |
3069 | ||
3070 | { /* bfd_set_format */ | |
3071 | bfd_false, | |
3072 | coff_mkobject, | |
3073 | _bfd_generic_mkarchive, | |
3074 | bfd_false | |
3075 | }, | |
3076 | ||
3077 | {/* bfd_write_contents */ | |
3078 | bfd_false, | |
3079 | coff_write_object_contents, | |
3080 | _bfd_xcoff_write_archive_contents, | |
3081 | bfd_false | |
3082 | }, | |
3083 | ||
3084 | /* Generic */ | |
3085 | bfd_true, /* _close_and_cleanup */ | |
3086 | bfd_true, /* _bfd_free_cached_info */ | |
3087 | coff_new_section_hook, /* _new_section_hook */ | |
3088 | _bfd_generic_get_section_contents, /* _bfd_get_section_contents */ | |
3089 | /* _bfd_get_section_contents_in_window */ | |
3090 | _bfd_generic_get_section_contents_in_window, | |
3091 | ||
3092 | /* Copy */ | |
3093 | _bfd_xcoff_copy_private_bfd_data, /* _bfd_copy_private_bfd */ | |
3094 | /* _bfd_merge_private_bfd_data */ | |
3095 | ((boolean (*) (bfd *, bfd *)) bfd_true), | |
3096 | /* _bfd_copy_pivate_section_data */ | |
3097 | ((boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true), | |
3098 | /* _bfd_copy_private_symbol_data */ | |
3099 | ((boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true), | |
3100 | ((boolean (*) (bfd *, flagword)) bfd_true), /* _bfd_set_private_flags */ | |
3101 | ((boolean (*) (bfd *, void * )) bfd_true), /* _bfd_print_private_bfd_data */ | |
3102 | ||
3103 | /* Core */ | |
b55039f4 L |
3104 | coff_core_file_failing_command, /* _core_file_failing_command */ |
3105 | coff_core_file_failing_signal, /* _core_file_failing_signal */ | |
beb1bf64 | 3106 | /* _core_file_matches_executable_p */ |
b55039f4 | 3107 | coff_core_file_matches_executable_p, |
beb1bf64 TR |
3108 | |
3109 | /* Archive */ | |
3110 | _bfd_xcoff_slurp_armap, /* _slurp_armap */ | |
3111 | /* XCOFF archives do not have | |
3112 | anything which corresponds to | |
3113 | an extended name table. */ | |
3114 | bfd_false, /* _slurp_extended_name_table */ | |
3115 | /* _construct_extended_name_table */ | |
3116 | ((boolean (*) (bfd *, char **, bfd_size_type *, const char **)) bfd_false), | |
3117 | bfd_dont_truncate_arname, /* _truncate_arname */ | |
3118 | _bfd_xcoff_write_armap, /* _write_armap */ | |
3119 | _bfd_xcoff_read_ar_hdr, /* _read_ar_hdr */ | |
3120 | _bfd_xcoff_openr_next_archived_file, /* _openr_next_archived_file */ | |
3121 | _bfd_generic_get_elt_at_index, /* _get_elt_at_index */ | |
3122 | _bfd_xcoff_generic_stat_arch_elt, /* _generic_dtat_arch_elt */ | |
3123 | /* XCOFF archives do not have | |
3124 | a timestamp. */ | |
3125 | bfd_true, /* _update_armap_timestamp */ | |
3126 | ||
3127 | /* Symbols */ | |
3128 | coff_get_symtab_upper_bound, /* _get_symtab_upper_bound */ | |
3129 | coff_get_symtab, /* _get_symtab */ | |
3130 | coff_make_empty_symbol, /* _make_empty_symbol */ | |
3131 | coff_print_symbol, /* _print_symbol */ | |
3132 | coff_get_symbol_info, /* _get_symbol_info */ | |
3133 | _bfd_xcoff_is_local_label_name, /* _bfd_is_local_label_name */ | |
3134 | coff_get_lineno, /* _get_lineno */ | |
3135 | coff_find_nearest_line, /* _find_nearest_line */ | |
3136 | coff_bfd_make_debug_symbol, /* _bfd_make_debug_symbol */ | |
3137 | _bfd_generic_read_minisymbols, /* _read_minisymbols */ | |
3138 | _bfd_generic_minisymbol_to_symbol, /* _minsymbol_to_symbol */ | |
3139 | ||
3140 | /* Reloc */ | |
3141 | coff_get_reloc_upper_bound, /* _get_reloc_upper_bound */ | |
3142 | coff_canonicalize_reloc, /* _cononicalize_reloc */ | |
3143 | _bfd_xcoff_reloc_type_lookup, /* _bfd_reloc_type_lookup */ | |
3144 | ||
3145 | /* Write */ | |
3146 | coff_set_arch_mach, /* _set_arch_mach */ | |
3147 | coff_set_section_contents, /* _set_section_contents */ | |
3148 | ||
3149 | /* Link */ | |
3150 | _bfd_xcoff_sizeof_headers, /* _sizeof_headers */ | |
3151 | /* _bfd_get_relocated_section_contents */ | |
3152 | bfd_generic_get_relocated_section_contents, | |
3153 | bfd_generic_relax_section, /* _bfd_relax_section */ | |
3154 | _bfd_xcoff_bfd_link_hash_table_create, /* _bfd_link_hash_table_create */ | |
3155 | _bfd_xcoff_bfd_link_add_symbols, /* _bfd_link_add_symbols */ | |
3156 | _bfd_xcoff_bfd_final_link, /* _bfd_filnal_link */ | |
3157 | _bfd_generic_link_split_section, /* _bfd_link_split_section */ | |
3158 | bfd_generic_gc_sections, /* _bfd_gc_sections */ | |
3159 | bfd_generic_merge_sections, /* _bfd_merge_sections */ | |
3160 | ||
3161 | /* Dynamic */ | |
3162 | /* _get_dynamic_symtab_upper_bound */ | |
3163 | _bfd_xcoff_get_dynamic_symtab_upper_bound, | |
3164 | _bfd_xcoff_canonicalize_dynamic_symtab, /* _cononicalize_dynamic_symtab */ | |
3165 | _bfd_xcoff_get_dynamic_reloc_upper_bound,/* _get_dynamic_reloc_upper_bound */ | |
3166 | _bfd_xcoff_canonicalize_dynamic_reloc, /* _cononicalize_dynamic_reloc */ | |
3167 | ||
3168 | /* Opposite endian version, none exists */ | |
3169 | NULL, | |
3170 | ||
3171 | /* back end data */ | |
3172 | (void *) &bfd_xcoff_backend_data, | |
3173 | }; | |
3174 | ||
3175 | /* | |
3176 | * xcoff-powermac target | |
3177 | * Old target. | |
3178 | * Only difference between this target and the rs6000 target is the | |
3179 | * the default architecture and machine type used in coffcode.h | |
3180 | * | |
3181 | * PowerPC Macs use the same magic numbers as RS/6000 | |
3182 | * (because that's how they were bootstrapped originally), | |
3183 | * but they are always PowerPC architecture. | |
3184 | */ | |
3185 | static const struct xcoff_backend_data_rec bfd_pmac_xcoff_backend_data = | |
3186 | { | |
3187 | { /* COFF backend, defined in libcoff.h */ | |
3188 | _bfd_xcoff_swap_aux_in, /* _bfd_coff_swap_aux_in */ | |
3189 | _bfd_xcoff_swap_sym_in, /* _bfd_coff_swap_sym_in */ | |
3190 | coff_swap_lineno_in, /* _bfd_coff_swap_lineno_in */ | |
3191 | _bfd_xcoff_swap_aux_out, /* _bfd_swap_aux_out */ | |
3192 | _bfd_xcoff_swap_sym_out, /* _bfd_swap_sym_out */ | |
3193 | coff_swap_lineno_out, /* _bfd_swap_lineno_out */ | |
3194 | coff_swap_reloc_out, /* _bfd_swap_reloc_out */ | |
3195 | coff_swap_filehdr_out, /* _bfd_swap_filehdr_out */ | |
3196 | coff_swap_aouthdr_out, /* _bfd_swap_aouthdr_out */ | |
3197 | coff_swap_scnhdr_out, /* _bfd_swap_scnhdr_out */ | |
3198 | FILHSZ, /* _bfd_filhsz */ | |
3199 | AOUTSZ, /* _bfd_aoutsz */ | |
3200 | SCNHSZ, /* _bfd_scnhsz */ | |
3201 | SYMESZ, /* _bfd_symesz */ | |
3202 | AUXESZ, /* _bfd_auxesz */ | |
3203 | RELSZ, /* _bfd_relsz */ | |
3204 | LINESZ, /* _bfd_linesz */ | |
3205 | FILNMLEN, /* _bfd_filnmlen */ | |
3206 | true, /* _bfd_coff_long_filenames */ | |
3207 | false, /* _bfd_coff_long_section_names */ | |
3208 | (3), /* _bfd_coff_default_section_alignment_power */ | |
3209 | false, /* _bfd_coff_force_symnames_in_strings */ | |
3210 | 2, /* _bfd_coff_debug_string_prefix_length */ | |
3211 | coff_swap_filehdr_in, /* _bfd_coff_swap_filehdr_in */ | |
3212 | coff_swap_aouthdr_in, /* _bfd_swap_aouthdr_in */ | |
3213 | coff_swap_scnhdr_in, /* _bfd_swap_scnhdr_in */ | |
3214 | coff_swap_reloc_in, /* _bfd_reloc_in */ | |
3215 | coff_bad_format_hook, /* _bfd_bad_format_hook */ | |
3216 | coff_set_arch_mach_hook, /* _bfd_set_arch_mach_hook */ | |
3217 | coff_mkobject_hook, /* _bfd_mkobject_hook */ | |
3218 | styp_to_sec_flags, /* _bfd_syp_to_sec_flags */ | |
3219 | coff_set_alignment_hook, /* _bfd_set_alignment_hook */ | |
3220 | coff_slurp_symbol_table, /* _bfd_coff_slurp_symbol_table */ | |
3221 | symname_in_debug_hook, /* _coff_symname_in_debug_hook */ | |
3222 | coff_pointerize_aux_hook, /* _bfd_coff_pointerize_aux_hook */ | |
3223 | coff_print_aux, /* bfd_coff_print_aux */ | |
3224 | dummy_reloc16_extra_cases, /* _bfd_coff_reloc16_extra_cases */ | |
3225 | dummy_reloc16_estimate, /* _bfd_coff_reloc16_estimate */ | |
3226 | NULL, /* bfd_coff_sym_is_global */ | |
3227 | /* _bfd_coff_compute_section_file_positions */ | |
3228 | coff_compute_section_file_positions, | |
3229 | NULL , /* _bfd_coff_start_final_link */ | |
3230 | xcoff_ppc_relocate_section, /* _bfd_coff_relocate_section */ | |
3231 | coff_rtype_to_howto, /* _bfd_coff_rtype_to_howto */ | |
3232 | NULL , /* _bfd_coff_addust_symndx */ | |
3233 | _bfd_generic_link_add_one_symbol, /* _bfd_coff_add_one_symbol */ | |
3234 | coff_link_output_has_begun, /* _bfd_coff_link_output_has_begun */ | |
3235 | coff_final_link_postscript /* _bfd_coff_final_link_postscript */ | |
3236 | }, | |
3237 | ||
3238 | 0x01DF, /* magic number */ | |
3239 | bfd_arch_powerpc, /* architecture */ | |
3240 | bfd_mach_ppc, /* machine */ | |
3241 | ||
3242 | /* function pointers to xcoff specific swap routines */ | |
3243 | xcoff_swap_ldhdr_in, /* _xcoff_swap_ldhdr_in */ | |
3244 | xcoff_swap_ldhdr_out, /* _xcoff_swap_ldhdr_out */ | |
3245 | xcoff_swap_ldsym_in, /* _xcoff_swap_ldsym_in */ | |
3246 | xcoff_swap_ldsym_out, /* _xcoff_swap_ldsym_out */ | |
3247 | xcoff_swap_ldrel_in, /* _xcoff_swap_ldrel_in */ | |
3248 | xcoff_swap_ldrel_out, /* _xcoff_swap_ldrel_out */ | |
3249 | ||
3250 | /* sizes */ | |
3251 | LDHDRSZ, /* _xcoff_ldhdrsz */ | |
3252 | LDSYMSZ, /* _xcoff_ldsymsz */ | |
3253 | LDRELSZ, /* _xcoff_ldrelsz */ | |
3254 | 12, /* _xcoff_function_descriptor_size */ | |
3255 | SMALL_AOUTSZ, /* _xcoff_small_aout_header_size */ | |
3256 | ||
3257 | /* versions */ | |
3258 | 1, /* _xcoff_ldhdr_version */ | |
3259 | ||
3260 | /* xcoff vs xcoff64 putting symbol names */ | |
3261 | _bfd_xcoff_put_symbol_name, /* _xcoff_put_symbol_name */ | |
3262 | _bfd_xcoff_put_ldsymbol_name, /* _xcoff_put_ldsymbol_name */ | |
3263 | ||
3264 | &xcoff_dynamic_reloc, /* dynamic reloc howto */ | |
3265 | ||
3266 | xcoff_create_csect_from_smclas, /* _xcoff_create_csect_from_smclas */ | |
3267 | ||
3268 | /* lineno and reloc count overflow */ | |
3269 | xcoff_is_lineno_count_overflow, | |
3270 | xcoff_is_reloc_count_overflow, | |
3271 | ||
3272 | xcoff_loader_symbol_offset, | |
3273 | xcoff_loader_reloc_offset, | |
3274 | ||
3275 | /* glink */ | |
3276 | &xcoff_glink_code[0], | |
3277 | (36), /* _xcoff_glink_size */ | |
3278 | ||
3279 | }; | |
3280 | ||
3281 | /* The transfer vector that leads the outside world to all of the above. */ | |
3282 | const bfd_target pmac_xcoff_vec = | |
3283 | { | |
3284 | "xcoff-powermac", | |
3285 | bfd_target_xcoff_flavour, | |
3286 | BFD_ENDIAN_BIG, /* data byte order is big */ | |
3287 | BFD_ENDIAN_BIG, /* header byte order is big */ | |
3288 | ||
3289 | (HAS_RELOC | EXEC_P | /* object flags */ | |
3290 | HAS_LINENO | HAS_DEBUG | DYNAMIC | | |
3291 | HAS_SYMS | HAS_LOCALS | WP_TEXT), | |
3292 | ||
3293 | (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */ | |
3294 | 0, /* leading char */ | |
3295 | '/', /* ar_pad_char */ | |
3296 | 15, /* ar_max_namelen??? FIXMEmgo */ | |
3297 | ||
3298 | /* data */ | |
3299 | bfd_getb64, /* bfd_getx64 */ | |
3300 | bfd_getb_signed_64, /* bfd_getx_signed_64 */ | |
3301 | bfd_putb64, /* bfd_putx64 */ | |
3302 | bfd_getb32, /* bfd_getx32 */ | |
3303 | bfd_getb_signed_32, /* bfd_getx_signed_32 */ | |
3304 | bfd_putb32, /* bfd_putx32 */ | |
3305 | bfd_getb16, /* bfd_getx16 */ | |
3306 | bfd_getb_signed_16, /* bfd_getx_signed_16 */ | |
3307 | bfd_putb16, /* bfd_putx16 */ | |
3308 | ||
3309 | /* hdrs */ | |
3310 | bfd_getb64, /* bfd_h_getx64 */ | |
3311 | bfd_getb_signed_64, /* bfd_h_getx_signed_64 */ | |
3312 | bfd_putb64, /* bfd_h_putx64 */ | |
3313 | bfd_getb32, /* bfd_h_getx32 */ | |
3314 | bfd_getb_signed_32, /* bfd_h_getx_signed_32 */ | |
3315 | bfd_putb32, /* bfd_h_putx32 */ | |
3316 | bfd_getb16, /* bfd_h_getx16 */ | |
3317 | bfd_getb_signed_16, /* bfd_h_getx_signed_16 */ | |
3318 | bfd_putb16, /* bfd_h_putx16 */ | |
3319 | ||
3320 | { /* bfd_check_format */ | |
3321 | _bfd_dummy_target, | |
3322 | coff_object_p, | |
3323 | _bfd_xcoff_archive_p, | |
3324 | CORE_FILE_P | |
3325 | }, | |
3326 | ||
3327 | { /* bfd_set_format */ | |
3328 | bfd_false, | |
3329 | coff_mkobject, | |
3330 | _bfd_generic_mkarchive, | |
3331 | bfd_false | |
3332 | }, | |
3333 | ||
3334 | {/* bfd_write_contents */ | |
3335 | bfd_false, | |
3336 | coff_write_object_contents, | |
3337 | _bfd_xcoff_write_archive_contents, | |
3338 | bfd_false | |
3339 | }, | |
3340 | ||
3341 | /* Generic */ | |
3342 | bfd_true, /* _close_and_cleanup */ | |
3343 | bfd_true, /* _bfd_free_cached_info */ | |
3344 | coff_new_section_hook, /* _new_section_hook */ | |
3345 | _bfd_generic_get_section_contents, /* _bfd_get_section_contents */ | |
3346 | /* _bfd_get_section_contents_in_window */ | |
3347 | _bfd_generic_get_section_contents_in_window, | |
3348 | ||
3349 | /* Copy */ | |
3350 | _bfd_xcoff_copy_private_bfd_data, /* _bfd_copy_private_bfd */ | |
3351 | /* _bfd_merge_private_bfd_data */ | |
3352 | ((boolean (*) (bfd *, bfd *)) bfd_true), | |
3353 | /* _bfd_copy_pivate_section_data */ | |
3354 | ((boolean (*) (bfd *, asection *, bfd *, asection *)) bfd_true), | |
3355 | /* _bfd_copy_private_symbol_data */ | |
3356 | ((boolean (*) (bfd *, asymbol *, bfd *, asymbol *)) bfd_true), | |
3357 | ((boolean (*) (bfd *, flagword)) bfd_true), /* _bfd_set_private_flags */ | |
3358 | ((boolean (*) (bfd *, void * )) bfd_true), /* _bfd_print_private_bfd_data */ | |
3359 | ||
3360 | /* Core */ | |
b55039f4 L |
3361 | coff_core_file_failing_command, /* _core_file_failing_command */ |
3362 | coff_core_file_failing_signal, /* _core_file_failing_signal */ | |
beb1bf64 | 3363 | /* _core_file_matches_executable_p */ |
b55039f4 | 3364 | coff_core_file_matches_executable_p, |
beb1bf64 TR |
3365 | |
3366 | /* Archive */ | |
3367 | _bfd_xcoff_slurp_armap, /* _slurp_armap */ | |
3368 | /* XCOFF archives do not have | |
3369 | anything which corresponds to | |
3370 | an extended name table. */ | |
3371 | bfd_false, /* _slurp_extended_name_table */ | |
3372 | /* _construct_extended_name_table */ | |
3373 | ((boolean (*) (bfd *, char **, bfd_size_type *, const char **)) bfd_false), | |
3374 | bfd_dont_truncate_arname, /* _truncate_arname */ | |
3375 | _bfd_xcoff_write_armap, /* _write_armap */ | |
3376 | _bfd_xcoff_read_ar_hdr, /* _read_ar_hdr */ | |
3377 | _bfd_xcoff_openr_next_archived_file, /* _openr_next_archived_file */ | |
3378 | _bfd_generic_get_elt_at_index, /* _get_elt_at_index */ | |
3379 | _bfd_xcoff_generic_stat_arch_elt, /* _generic_dtat_arch_elt */ | |
3380 | /* XCOFF archives do not have | |
3381 | a timestamp. */ | |
3382 | bfd_true, /* _update_armap_timestamp */ | |
3383 | ||
3384 | /* Symbols */ | |
3385 | coff_get_symtab_upper_bound, /* _get_symtab_upper_bound */ | |
3386 | coff_get_symtab, /* _get_symtab */ | |
3387 | coff_make_empty_symbol, /* _make_empty_symbol */ | |
3388 | coff_print_symbol, /* _print_symbol */ | |
3389 | coff_get_symbol_info, /* _get_symbol_info */ | |
3390 | _bfd_xcoff_is_local_label_name, /* _bfd_is_local_label_name */ | |
3391 | coff_get_lineno, /* _get_lineno */ | |
3392 | coff_find_nearest_line, /* _find_nearest_line */ | |
3393 | coff_bfd_make_debug_symbol, /* _bfd_make_debug_symbol */ | |
3394 | _bfd_generic_read_minisymbols, /* _read_minisymbols */ | |
3395 | _bfd_generic_minisymbol_to_symbol, /* _minsymbol_to_symbol */ | |
3396 | ||
3397 | /* Reloc */ | |
3398 | coff_get_reloc_upper_bound, /* _get_reloc_upper_bound */ | |
3399 | coff_canonicalize_reloc, /* _cononicalize_reloc */ | |
3400 | _bfd_xcoff_reloc_type_lookup, /* _bfd_reloc_type_lookup */ | |
3401 | ||
3402 | /* Write */ | |
3403 | coff_set_arch_mach, /* _set_arch_mach */ | |
3404 | coff_set_section_contents, /* _set_section_contents */ | |
3405 | ||
3406 | /* Link */ | |
3407 | _bfd_xcoff_sizeof_headers, /* _sizeof_headers */ | |
3408 | /* _bfd_get_relocated_section_contents */ | |
3409 | bfd_generic_get_relocated_section_contents, | |
3410 | bfd_generic_relax_section, /* _bfd_relax_section */ | |
3411 | _bfd_xcoff_bfd_link_hash_table_create, /* _bfd_link_hash_table_create */ | |
3412 | _bfd_xcoff_bfd_link_add_symbols, /* _bfd_link_add_symbols */ | |
3413 | _bfd_xcoff_bfd_final_link, /* _bfd_filnal_link */ | |
3414 | _bfd_generic_link_split_section, /* _bfd_link_split_section */ | |
3415 | bfd_generic_gc_sections, /* _bfd_gc_sections */ | |
3416 | bfd_generic_merge_sections, /* _bfd_merge_sections */ | |
3417 | ||
3418 | /* Dynamic */ | |
3419 | /* _get_dynamic_symtab_upper_bound */ | |
3420 | _bfd_xcoff_get_dynamic_symtab_upper_bound, | |
3421 | _bfd_xcoff_canonicalize_dynamic_symtab, /* _cononicalize_dynamic_symtab */ | |
3422 | _bfd_xcoff_get_dynamic_reloc_upper_bound,/* _get_dynamic_reloc_upper_bound */ | |
3423 | _bfd_xcoff_canonicalize_dynamic_reloc, /* _cononicalize_dynamic_reloc */ | |
3424 | ||
3425 | /* Opposite endian version, none exists */ | |
3426 | NULL, | |
3427 | ||
3428 | /* back end data */ | |
3429 | (void *) &bfd_pmac_xcoff_backend_data, | |
3430 | }; |