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