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