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