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