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