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