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