1 /* BFD back-end for IBM RS/6000 "XCOFF" files.
2 Copyright 1990-1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
3 2008, 2009, 2010, 2011, 2012
4 Free Software Foundation, Inc.
5 Written by Metin G. Ozisik, Mimi Phuong-Thao Vo, and John Gilmore.
6 Archive support from Damon A. Permezel.
7 Contributed by IBM Corporation and Cygnus Support.
9 This file is part of BFD, the Binary File Descriptor library.
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 3 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
24 MA 02110-1301, USA. */
30 #include "coff/internal.h"
31 #include "coff/xcoff.h"
32 #include "coff/rs6000.h"
36 extern bfd_boolean _bfd_xcoff_mkobject (bfd *);
37 extern bfd_boolean _bfd_xcoff_copy_private_bfd_data (bfd *, bfd *);
38 extern bfd_boolean _bfd_xcoff_is_local_label_name (bfd *, const char *);
39 extern reloc_howto_type *_bfd_xcoff_reloc_type_lookup
40 (bfd *, bfd_reloc_code_real_type);
41 extern bfd_boolean _bfd_xcoff_slurp_armap (bfd *);
42 extern const bfd_target *_bfd_xcoff_archive_p (bfd *);
43 extern void * _bfd_xcoff_read_ar_hdr (bfd *);
44 extern bfd *_bfd_xcoff_openr_next_archived_file (bfd *, bfd *);
45 extern int _bfd_xcoff_stat_arch_elt (bfd *, struct stat *);
46 extern bfd_boolean _bfd_xcoff_write_armap
47 (bfd *, unsigned int, struct orl *, unsigned int, int);
48 extern bfd_boolean _bfd_xcoff_write_archive_contents (bfd *);
49 extern int _bfd_xcoff_sizeof_headers (bfd *, struct bfd_link_info *);
50 extern void _bfd_xcoff_swap_sym_in (bfd *, void *, void *);
51 extern unsigned int _bfd_xcoff_swap_sym_out (bfd *, void *, void *);
52 extern void _bfd_xcoff_swap_aux_in (bfd *, void *, int, int, int, int, void *);
53 extern unsigned int _bfd_xcoff_swap_aux_out
54 (bfd *, void *, int, int, int, int, void *);
55 static void xcoff_swap_reloc_in (bfd *, void *, void *);
56 static unsigned int xcoff_swap_reloc_out (bfd *, void *, void *);
58 /* Forward declare xcoff_rtype2howto for coffcode.h macro. */
59 void xcoff_rtype2howto (arelent *, struct internal_reloc *);
61 /* coffcode.h needs these to be defined. */
62 #define RS6000COFF_C 1
64 #define SELECT_RELOC(internal, howto) \
66 internal.r_type = howto->type; \
68 ((howto->complain_on_overflow == complain_overflow_signed \
71 | (howto->bitsize - 1)); \
74 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
75 #define COFF_LONG_FILENAMES
76 #define NO_COFF_SYMBOLS
77 #define RTYPE2HOWTO(cache_ptr, dst) xcoff_rtype2howto (cache_ptr, dst)
78 #define coff_mkobject _bfd_xcoff_mkobject
79 #define coff_bfd_copy_private_bfd_data _bfd_xcoff_copy_private_bfd_data
80 #define coff_bfd_is_local_label_name _bfd_xcoff_is_local_label_name
81 #define coff_bfd_reloc_type_lookup _bfd_xcoff_reloc_type_lookup
82 #define coff_bfd_reloc_name_lookup _bfd_xcoff_reloc_name_lookup
84 extern const bfd_target * rs6000coff_core_p (bfd *abfd);
85 extern bfd_boolean rs6000coff_core_file_matches_executable_p
86 (bfd *cbfd, bfd *ebfd);
87 extern char *rs6000coff_core_file_failing_command (bfd *abfd);
88 extern int rs6000coff_core_file_failing_signal (bfd *abfd);
89 #define CORE_FILE_P rs6000coff_core_p
90 #define coff_core_file_failing_command \
91 rs6000coff_core_file_failing_command
92 #define coff_core_file_failing_signal \
93 rs6000coff_core_file_failing_signal
94 #define coff_core_file_matches_executable_p \
95 rs6000coff_core_file_matches_executable_p
96 #define coff_core_file_pid \
97 _bfd_nocore_core_file_pid
99 #define CORE_FILE_P _bfd_dummy_target
100 #define coff_core_file_failing_command \
101 _bfd_nocore_core_file_failing_command
102 #define coff_core_file_failing_signal \
103 _bfd_nocore_core_file_failing_signal
104 #define coff_core_file_matches_executable_p \
105 _bfd_nocore_core_file_matches_executable_p
106 #define coff_core_file_pid \
107 _bfd_nocore_core_file_pid
109 #define coff_SWAP_sym_in _bfd_xcoff_swap_sym_in
110 #define coff_SWAP_sym_out _bfd_xcoff_swap_sym_out
111 #define coff_SWAP_aux_in _bfd_xcoff_swap_aux_in
112 #define coff_SWAP_aux_out _bfd_xcoff_swap_aux_out
113 #define coff_swap_reloc_in xcoff_swap_reloc_in
114 #define coff_swap_reloc_out xcoff_swap_reloc_out
115 #define NO_COFF_RELOCS
117 #ifndef bfd_pe_print_pdata
118 #define bfd_pe_print_pdata NULL
121 #include "coffcode.h"
123 /* The main body of code is in coffcode.h. */
125 static const char *normalize_filename (bfd *);
126 static bfd_boolean xcoff_write_armap_old
127 (bfd *, unsigned int, struct orl *, unsigned int, int);
128 static bfd_boolean xcoff_write_armap_big
129 (bfd *, unsigned int, struct orl *, unsigned int, int);
130 static bfd_boolean xcoff_write_archive_contents_old (bfd *);
131 static bfd_boolean xcoff_write_archive_contents_big (bfd *);
132 static void xcoff_swap_ldhdr_in (bfd *, const void *, struct internal_ldhdr *);
133 static void xcoff_swap_ldhdr_out (bfd *, const struct internal_ldhdr *, void *);
134 static void xcoff_swap_ldsym_in (bfd *, const void *, struct internal_ldsym *);
135 static void xcoff_swap_ldsym_out (bfd *, const struct internal_ldsym *, void *);
136 static void xcoff_swap_ldrel_in (bfd *, const void *, struct internal_ldrel *);
137 static void xcoff_swap_ldrel_out (bfd *, const struct internal_ldrel *, void *);
138 static bfd_boolean xcoff_ppc_relocate_section
139 (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
140 struct internal_reloc *, struct internal_syment *, asection **);
141 static bfd_boolean _bfd_xcoff_put_ldsymbol_name
142 (bfd *, struct xcoff_loader_info *, struct internal_ldsym *, const char *);
143 static asection *xcoff_create_csect_from_smclas
144 (bfd *, union internal_auxent *, const char *);
145 static bfd_boolean xcoff_is_lineno_count_overflow (bfd *, bfd_vma);
146 static bfd_boolean xcoff_is_reloc_count_overflow (bfd *, bfd_vma);
147 static bfd_vma xcoff_loader_symbol_offset (bfd *, struct internal_ldhdr *);
148 static bfd_vma xcoff_loader_reloc_offset (bfd *, struct internal_ldhdr *);
149 static bfd_boolean xcoff_generate_rtinit
150 (bfd *, const char *, const char *, bfd_boolean);
151 static bfd_boolean do_pad (bfd *, unsigned int);
152 static bfd_boolean do_copy (bfd *, bfd *);
154 /* Relocation functions */
155 static bfd_boolean xcoff_reloc_type_br (XCOFF_RELOC_FUNCTION_ARGS);
157 static bfd_boolean xcoff_complain_overflow_dont_func
158 (XCOFF_COMPLAIN_FUNCTION_ARGS);
159 static bfd_boolean xcoff_complain_overflow_bitfield_func
160 (XCOFF_COMPLAIN_FUNCTION_ARGS);
161 static bfd_boolean xcoff_complain_overflow_signed_func
162 (XCOFF_COMPLAIN_FUNCTION_ARGS);
163 static bfd_boolean xcoff_complain_overflow_unsigned_func
164 (XCOFF_COMPLAIN_FUNCTION_ARGS);
166 bfd_boolean (*xcoff_calculate_relocation[XCOFF_MAX_CALCULATE_RELOCATION])
167 (XCOFF_RELOC_FUNCTION_ARGS) =
169 xcoff_reloc_type_pos, /* R_POS (0x00) */
170 xcoff_reloc_type_neg, /* R_NEG (0x01) */
171 xcoff_reloc_type_rel, /* R_REL (0x02) */
172 xcoff_reloc_type_toc, /* R_TOC (0x03) */
173 xcoff_reloc_type_fail, /* R_RTB (0x04) */
174 xcoff_reloc_type_toc, /* R_GL (0x05) */
175 xcoff_reloc_type_toc, /* R_TCL (0x06) */
176 xcoff_reloc_type_fail, /* (0x07) */
177 xcoff_reloc_type_ba, /* R_BA (0x08) */
178 xcoff_reloc_type_fail, /* (0x09) */
179 xcoff_reloc_type_br, /* R_BR (0x0a) */
180 xcoff_reloc_type_fail, /* (0x0b) */
181 xcoff_reloc_type_pos, /* R_RL (0x0c) */
182 xcoff_reloc_type_pos, /* R_RLA (0x0d) */
183 xcoff_reloc_type_fail, /* (0x0e) */
184 xcoff_reloc_type_noop, /* R_REF (0x0f) */
185 xcoff_reloc_type_fail, /* (0x10) */
186 xcoff_reloc_type_fail, /* (0x11) */
187 xcoff_reloc_type_toc, /* R_TRL (0x12) */
188 xcoff_reloc_type_toc, /* R_TRLA (0x13) */
189 xcoff_reloc_type_fail, /* R_RRTBI (0x14) */
190 xcoff_reloc_type_fail, /* R_RRTBA (0x15) */
191 xcoff_reloc_type_ba, /* R_CAI (0x16) */
192 xcoff_reloc_type_crel, /* R_CREL (0x17) */
193 xcoff_reloc_type_ba, /* R_RBA (0x18) */
194 xcoff_reloc_type_ba, /* R_RBAC (0x19) */
195 xcoff_reloc_type_br, /* R_RBR (0x1a) */
196 xcoff_reloc_type_ba, /* R_RBRC (0x1b) */
199 bfd_boolean (*xcoff_complain_overflow[XCOFF_MAX_COMPLAIN_OVERFLOW])
200 (XCOFF_COMPLAIN_FUNCTION_ARGS) =
202 xcoff_complain_overflow_dont_func,
203 xcoff_complain_overflow_bitfield_func,
204 xcoff_complain_overflow_signed_func,
205 xcoff_complain_overflow_unsigned_func,
208 /* Information about one member of an archive. */
209 struct member_layout {
210 /* The archive member that this structure describes. */
213 /* The number of bytes of padding that must be inserted before the
214 start of the member in order to ensure that the section contents
215 are correctly aligned. */
216 unsigned int leading_padding;
218 /* The offset of MEMBER from the start of the archive (i.e. the end
219 of the leading padding). */
222 /* The normalized name of MEMBER. */
225 /* The length of NAME, without padding. */
226 bfd_size_type namlen;
228 /* The length of NAME, with padding. */
229 bfd_size_type padded_namlen;
231 /* The size of MEMBER's header, including the name and magic sequence. */
232 bfd_size_type header_size;
234 /* The size of the MEMBER's contents. */
235 bfd_size_type contents_size;
237 /* The number of bytes of padding that must be inserted after MEMBER
238 in order to preserve even alignment. */
239 bfd_size_type trailing_padding;
242 /* A structure used for iterating over the members of an archive. */
243 struct archive_iterator {
244 /* The archive itself. */
247 /* Information about the current archive member. */
248 struct member_layout current;
250 /* Information about the next archive member. MEMBER is null if there
251 are no more archive members, in which case OFFSET is the offset of
252 the first unused byte. */
253 struct member_layout next;
256 /* Initialize INFO so that it describes member MEMBER of archive ARCHIVE.
257 OFFSET is the even-padded offset of MEMBER, not including any leading
258 padding needed for section alignment. */
261 member_layout_init (struct member_layout *info, bfd *archive,
262 bfd *member, file_ptr offset)
264 info->member = member;
265 info->leading_padding = 0;
268 info->name = normalize_filename (member);
269 info->namlen = strlen (info->name);
270 info->padded_namlen = info->namlen + (info->namlen & 1);
271 if (xcoff_big_format_p (archive))
272 info->header_size = SIZEOF_AR_HDR_BIG;
274 info->header_size = SIZEOF_AR_HDR;
275 info->header_size += info->padded_namlen + SXCOFFARFMAG;
276 info->contents_size = arelt_size (member);
277 info->trailing_padding = info->contents_size & 1;
279 if (bfd_check_format (member, bfd_object)
280 && bfd_get_flavour (member) == bfd_target_xcoff_flavour
281 && (member->flags & DYNAMIC) != 0)
282 info->leading_padding
283 = (-(offset + info->header_size)
284 & ((1 << bfd_xcoff_text_align_power (member)) - 1));
286 info->offset = offset + info->leading_padding;
289 /* Set up ITERATOR to iterate through archive ARCHIVE. */
292 archive_iterator_begin (struct archive_iterator *iterator,
295 iterator->archive = archive;
296 member_layout_init (&iterator->next, archive, archive->archive_head,
297 xcoff_big_format_p (archive)
298 ? SIZEOF_AR_FILE_HDR_BIG
299 : SIZEOF_AR_FILE_HDR);
302 /* Make ITERATOR visit the first unvisited archive member. Return true
303 on success; return false if all members have been visited. */
306 archive_iterator_next (struct archive_iterator *iterator)
308 if (!iterator->next.member)
311 iterator->current = iterator->next;
312 member_layout_init (&iterator->next, iterator->archive,
313 iterator->current.member->archive_next,
314 iterator->current.offset
315 + iterator->current.header_size
316 + iterator->current.contents_size
317 + iterator->current.trailing_padding);
321 /* We use our own tdata type. Its first field is the COFF tdata type,
322 so the COFF routines are compatible. */
325 _bfd_xcoff_mkobject (bfd *abfd)
327 coff_data_type *coff;
328 bfd_size_type amt = sizeof (struct xcoff_tdata);
330 abfd->tdata.xcoff_obj_data = (struct xcoff_tdata *) bfd_zalloc (abfd, amt);
331 if (abfd->tdata.xcoff_obj_data == NULL)
333 coff = coff_data (abfd);
334 coff->symbols = (coff_symbol_type *) NULL;
335 coff->conversion_table = (unsigned int *) NULL;
336 coff->raw_syments = (struct coff_ptr_struct *) NULL;
339 xcoff_data (abfd)->modtype = ('1' << 8) | 'L';
341 /* We set cputype to -1 to indicate that it has not been
343 xcoff_data (abfd)->cputype = -1;
345 xcoff_data (abfd)->csects = NULL;
346 xcoff_data (abfd)->debug_indices = NULL;
348 /* text section alignment is different than the default */
349 bfd_xcoff_text_align_power (abfd) = 2;
354 /* Copy XCOFF data from one BFD to another. */
357 _bfd_xcoff_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
359 struct xcoff_tdata *ix, *ox;
362 if (ibfd->xvec != obfd->xvec)
364 ix = xcoff_data (ibfd);
365 ox = xcoff_data (obfd);
366 ox->full_aouthdr = ix->full_aouthdr;
372 sec = coff_section_from_bfd_index (ibfd, ix->sntoc);
376 ox->sntoc = sec->output_section->target_index;
378 if (ix->snentry == 0)
382 sec = coff_section_from_bfd_index (ibfd, ix->snentry);
386 ox->snentry = sec->output_section->target_index;
388 bfd_xcoff_text_align_power (obfd) = bfd_xcoff_text_align_power (ibfd);
389 bfd_xcoff_data_align_power (obfd) = bfd_xcoff_data_align_power (ibfd);
390 ox->modtype = ix->modtype;
391 ox->cputype = ix->cputype;
392 ox->maxdata = ix->maxdata;
393 ox->maxstack = ix->maxstack;
397 /* I don't think XCOFF really has a notion of local labels based on
398 name. This will mean that ld -X doesn't actually strip anything.
399 The AIX native linker does not have a -X option, and it ignores the
403 _bfd_xcoff_is_local_label_name (bfd *abfd ATTRIBUTE_UNUSED,
404 const char *name ATTRIBUTE_UNUSED)
409 static const struct dwarf_debug_section xcoff_debug_sections[] =
411 { ".dwabrev", NULL },
412 { ".dwarnge", NULL },
413 { NULL, NULL }, /* .debug_frame */
416 { NULL, NULL }, /* .debug_loc */
417 { NULL, NULL }, /* .debug_macinfo */
418 { NULL, NULL }, /* .debug_macro */
419 { ".dwpbnms", NULL },
420 { ".dwpbtyp", NULL },
421 { ".dwrnges", NULL },
422 { NULL, NULL }, /* .debug_static_func */
423 { NULL, NULL }, /* .debug_static_vars */
425 { NULL, NULL }, /* .debug_types */
426 /* GNU DWARF 1 extensions */
427 { NULL, NULL }, /* .debug_sfnames */
428 { NULL, NULL }, /* .debug_srcinfo */
429 /* SGI/MIPS DWARF 2 extensions */
430 { NULL, NULL }, /* .debug_funcnames */
431 { NULL, NULL }, /* .debug_typenames */
432 { NULL, NULL }, /* .debug_varnames */
433 { NULL, NULL }, /* .debug_weaknames */
438 xcoff_find_nearest_line (bfd *abfd,
442 const char **filename_ptr,
443 const char **functionname_ptr,
444 unsigned int *line_ptr)
446 return coff_find_nearest_line_with_names (abfd, xcoff_debug_sections,
447 section, symbols, offset,
448 filename_ptr, functionname_ptr,
454 _bfd_xcoff_swap_sym_in (bfd *abfd, void * ext1, void * in1)
456 SYMENT *ext = (SYMENT *)ext1;
457 struct internal_syment * in = (struct internal_syment *)in1;
459 if (ext->e.e_name[0] != 0)
461 memcpy (in->_n._n_name, ext->e.e_name, SYMNMLEN);
465 in->_n._n_n._n_zeroes = 0;
466 in->_n._n_n._n_offset = H_GET_32 (abfd, ext->e.e.e_offset);
469 in->n_value = H_GET_32 (abfd, ext->e_value);
470 in->n_scnum = H_GET_16 (abfd, ext->e_scnum);
471 in->n_type = H_GET_16 (abfd, ext->e_type);
472 in->n_sclass = H_GET_8 (abfd, ext->e_sclass);
473 in->n_numaux = H_GET_8 (abfd, ext->e_numaux);
477 _bfd_xcoff_swap_sym_out (bfd *abfd, void * inp, void * extp)
479 struct internal_syment *in = (struct internal_syment *)inp;
480 SYMENT *ext =(SYMENT *)extp;
482 if (in->_n._n_name[0] != 0)
484 memcpy (ext->e.e_name, in->_n._n_name, SYMNMLEN);
488 H_PUT_32 (abfd, 0, ext->e.e.e_zeroes);
489 H_PUT_32 (abfd, in->_n._n_n._n_offset, ext->e.e.e_offset);
492 H_PUT_32 (abfd, in->n_value, ext->e_value);
493 H_PUT_16 (abfd, in->n_scnum, ext->e_scnum);
494 H_PUT_16 (abfd, in->n_type, ext->e_type);
495 H_PUT_8 (abfd, in->n_sclass, ext->e_sclass);
496 H_PUT_8 (abfd, in->n_numaux, ext->e_numaux);
497 return bfd_coff_symesz (abfd);
501 _bfd_xcoff_swap_aux_in (bfd *abfd, void * ext1, int type, int in_class,
502 int indx, int numaux, void * in1)
504 AUXENT * ext = (AUXENT *)ext1;
505 union internal_auxent *in = (union internal_auxent *)in1;
510 if (ext->x_file.x_n.x_fname[0] == 0)
512 in->x_file.x_n.x_zeroes = 0;
513 in->x_file.x_n.x_offset =
514 H_GET_32 (abfd, ext->x_file.x_n.x_n.x_offset);
521 memcpy (in->x_file.x_fname, ext->x_file.x_n.x_fname,
522 numaux * sizeof (AUXENT));
526 memcpy (in->x_file.x_fname, ext->x_file.x_n.x_fname, FILNMLEN);
531 /* RS/6000 "csect" auxents */
535 if (indx + 1 == numaux)
537 in->x_csect.x_scnlen.l = H_GET_32 (abfd, ext->x_csect.x_scnlen);
538 in->x_csect.x_parmhash = H_GET_32 (abfd, ext->x_csect.x_parmhash);
539 in->x_csect.x_snhash = H_GET_16 (abfd, ext->x_csect.x_snhash);
540 /* We don't have to hack bitfields in x_smtyp because it's
541 defined by shifts-and-ands, which are equivalent on all
543 in->x_csect.x_smtyp = H_GET_8 (abfd, ext->x_csect.x_smtyp);
544 in->x_csect.x_smclas = H_GET_8 (abfd, ext->x_csect.x_smclas);
545 in->x_csect.x_stab = H_GET_32 (abfd, ext->x_csect.x_stab);
546 in->x_csect.x_snstab = H_GET_16 (abfd, ext->x_csect.x_snstab);
556 in->x_scn.x_scnlen = H_GET_32 (abfd, ext->x_scn.x_scnlen);
557 in->x_scn.x_nreloc = H_GET_16 (abfd, ext->x_scn.x_nreloc);
558 in->x_scn.x_nlinno = H_GET_16 (abfd, ext->x_scn.x_nlinno);
559 /* PE defines some extra fields; we zero them out for
561 in->x_scn.x_checksum = 0;
562 in->x_scn.x_associated = 0;
563 in->x_scn.x_comdat = 0;
570 in->x_sym.x_tagndx.l = H_GET_32 (abfd, ext->x_sym.x_tagndx);
571 in->x_sym.x_tvndx = H_GET_16 (abfd, ext->x_sym.x_tvndx);
573 if (in_class == C_BLOCK || in_class == C_FCN || ISFCN (type)
576 in->x_sym.x_fcnary.x_fcn.x_lnnoptr =
577 H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_lnnoptr);
578 in->x_sym.x_fcnary.x_fcn.x_endndx.l =
579 H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_endndx);
583 in->x_sym.x_fcnary.x_ary.x_dimen[0] =
584 H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
585 in->x_sym.x_fcnary.x_ary.x_dimen[1] =
586 H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
587 in->x_sym.x_fcnary.x_ary.x_dimen[2] =
588 H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
589 in->x_sym.x_fcnary.x_ary.x_dimen[3] =
590 H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
595 in->x_sym.x_misc.x_fsize = H_GET_32 (abfd, ext->x_sym.x_misc.x_fsize);
599 in->x_sym.x_misc.x_lnsz.x_lnno =
600 H_GET_16 (abfd, ext->x_sym.x_misc.x_lnsz.x_lnno);
601 in->x_sym.x_misc.x_lnsz.x_size =
602 H_GET_16 (abfd, ext->x_sym.x_misc.x_lnsz.x_size);
606 /* The semicolon is because MSVC doesn't like labels at
611 _bfd_xcoff_swap_aux_out (bfd *abfd, void * inp, int type, int in_class,
612 int indx ATTRIBUTE_UNUSED,
613 int numaux ATTRIBUTE_UNUSED,
616 union internal_auxent *in = (union internal_auxent *)inp;
617 AUXENT *ext = (AUXENT *)extp;
619 memset (ext, 0, bfd_coff_auxesz (abfd));
623 if (in->x_file.x_fname[0] == 0)
625 H_PUT_32 (abfd, 0, ext->x_file.x_n.x_n.x_zeroes);
626 H_PUT_32 (abfd, in->x_file.x_n.x_offset,
627 ext->x_file.x_n.x_n.x_offset);
631 memcpy (ext->x_file.x_n.x_fname, in->x_file.x_fname, FILNMLEN);
635 /* RS/6000 "csect" auxents */
639 if (indx + 1 == numaux)
641 H_PUT_32 (abfd, in->x_csect.x_scnlen.l, ext->x_csect.x_scnlen);
642 H_PUT_32 (abfd, in->x_csect.x_parmhash, ext->x_csect.x_parmhash);
643 H_PUT_16 (abfd, in->x_csect.x_snhash, ext->x_csect.x_snhash);
644 /* We don't have to hack bitfields in x_smtyp because it's
645 defined by shifts-and-ands, which are equivalent on all
647 H_PUT_8 (abfd, in->x_csect.x_smtyp, ext->x_csect.x_smtyp);
648 H_PUT_8 (abfd, in->x_csect.x_smclas, ext->x_csect.x_smclas);
649 H_PUT_32 (abfd, in->x_csect.x_stab, ext->x_csect.x_stab);
650 H_PUT_16 (abfd, in->x_csect.x_snstab, ext->x_csect.x_snstab);
660 H_PUT_32 (abfd, in->x_scn.x_scnlen, ext->x_scn.x_scnlen);
661 H_PUT_16 (abfd, in->x_scn.x_nreloc, ext->x_scn.x_nreloc);
662 H_PUT_16 (abfd, in->x_scn.x_nlinno, ext->x_scn.x_nlinno);
668 H_PUT_32 (abfd, in->x_sym.x_tagndx.l, ext->x_sym.x_tagndx);
669 H_PUT_16 (abfd, in->x_sym.x_tvndx, ext->x_sym.x_tvndx);
671 if (in_class == C_BLOCK || in_class == C_FCN || ISFCN (type)
674 H_PUT_32 (abfd, in->x_sym.x_fcnary.x_fcn.x_lnnoptr,
675 ext->x_sym.x_fcnary.x_fcn.x_lnnoptr);
676 H_PUT_32 (abfd, in->x_sym.x_fcnary.x_fcn.x_endndx.l,
677 ext->x_sym.x_fcnary.x_fcn.x_endndx);
681 H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[0],
682 ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
683 H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[1],
684 ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
685 H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[2],
686 ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
687 H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[3],
688 ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
692 H_PUT_32 (abfd, in->x_sym.x_misc.x_fsize, ext->x_sym.x_misc.x_fsize);
695 H_PUT_16 (abfd, in->x_sym.x_misc.x_lnsz.x_lnno,
696 ext->x_sym.x_misc.x_lnsz.x_lnno);
697 H_PUT_16 (abfd, in->x_sym.x_misc.x_lnsz.x_size,
698 ext->x_sym.x_misc.x_lnsz.x_size);
702 return bfd_coff_auxesz (abfd);
707 /* The XCOFF reloc table. Actually, XCOFF relocations specify the
708 bitsize and whether they are signed or not, along with a
709 conventional type. This table is for the types, which are used for
710 different algorithms for putting in the reloc. Many of these
711 relocs need special_function entries, which I have not written. */
714 reloc_howto_type xcoff_howto_table[] =
716 /* Standard 32 bit relocation. */
717 HOWTO (R_POS, /* type */
719 2, /* size (0 = byte, 1 = short, 2 = long) */
721 FALSE, /* pc_relative */
723 complain_overflow_bitfield, /* complain_on_overflow */
724 0, /* special_function */
726 TRUE, /* partial_inplace */
727 0xffffffff, /* src_mask */
728 0xffffffff, /* dst_mask */
729 FALSE), /* pcrel_offset */
731 /* 32 bit relocation, but store negative value. */
732 HOWTO (R_NEG, /* type */
734 -2, /* size (0 = byte, 1 = short, 2 = long) */
736 FALSE, /* pc_relative */
738 complain_overflow_bitfield, /* complain_on_overflow */
739 0, /* special_function */
741 TRUE, /* partial_inplace */
742 0xffffffff, /* src_mask */
743 0xffffffff, /* dst_mask */
744 FALSE), /* pcrel_offset */
746 /* 32 bit PC relative relocation. */
747 HOWTO (R_REL, /* type */
749 2, /* size (0 = byte, 1 = short, 2 = long) */
751 TRUE, /* pc_relative */
753 complain_overflow_signed, /* complain_on_overflow */
754 0, /* special_function */
756 TRUE, /* partial_inplace */
757 0xffffffff, /* src_mask */
758 0xffffffff, /* dst_mask */
759 FALSE), /* pcrel_offset */
761 /* 16 bit TOC relative relocation. */
762 HOWTO (R_TOC, /* type */
764 1, /* size (0 = byte, 1 = short, 2 = long) */
766 FALSE, /* pc_relative */
768 complain_overflow_bitfield, /* complain_on_overflow */
769 0, /* special_function */
771 TRUE, /* partial_inplace */
772 0xffff, /* src_mask */
773 0xffff, /* dst_mask */
774 FALSE), /* pcrel_offset */
776 /* I don't really know what this is. */
777 HOWTO (R_RTB, /* type */
779 2, /* size (0 = byte, 1 = short, 2 = long) */
781 FALSE, /* pc_relative */
783 complain_overflow_bitfield, /* complain_on_overflow */
784 0, /* special_function */
786 TRUE, /* partial_inplace */
787 0xffffffff, /* src_mask */
788 0xffffffff, /* dst_mask */
789 FALSE), /* pcrel_offset */
791 /* External TOC relative symbol. */
792 HOWTO (R_GL, /* type */
794 1, /* size (0 = byte, 1 = short, 2 = long) */
796 FALSE, /* pc_relative */
798 complain_overflow_bitfield, /* complain_on_overflow */
799 0, /* special_function */
801 TRUE, /* partial_inplace */
802 0xffff, /* src_mask */
803 0xffff, /* dst_mask */
804 FALSE), /* pcrel_offset */
806 /* Local TOC relative symbol. */
807 HOWTO (R_TCL, /* type */
809 1, /* size (0 = byte, 1 = short, 2 = long) */
811 FALSE, /* pc_relative */
813 complain_overflow_bitfield, /* complain_on_overflow */
814 0, /* special_function */
816 TRUE, /* partial_inplace */
817 0xffff, /* src_mask */
818 0xffff, /* dst_mask */
819 FALSE), /* pcrel_offset */
823 /* Non modifiable absolute branch. */
824 HOWTO (R_BA, /* type */
826 2, /* size (0 = byte, 1 = short, 2 = long) */
828 FALSE, /* pc_relative */
830 complain_overflow_bitfield, /* complain_on_overflow */
831 0, /* special_function */
832 "R_BA_26", /* name */
833 TRUE, /* partial_inplace */
834 0x03fffffc, /* src_mask */
835 0x03fffffc, /* dst_mask */
836 FALSE), /* pcrel_offset */
840 /* Non modifiable relative branch. */
841 HOWTO (R_BR, /* type */
843 2, /* size (0 = byte, 1 = short, 2 = long) */
845 TRUE, /* pc_relative */
847 complain_overflow_signed, /* complain_on_overflow */
848 0, /* special_function */
850 TRUE, /* partial_inplace */
851 0x03fffffc, /* src_mask */
852 0x03fffffc, /* dst_mask */
853 FALSE), /* pcrel_offset */
858 HOWTO (R_RL, /* type */
860 1, /* size (0 = byte, 1 = short, 2 = long) */
862 FALSE, /* pc_relative */
864 complain_overflow_bitfield, /* complain_on_overflow */
865 0, /* special_function */
867 TRUE, /* partial_inplace */
868 0xffff, /* src_mask */
869 0xffff, /* dst_mask */
870 FALSE), /* pcrel_offset */
873 HOWTO (R_RLA, /* type */
875 1, /* size (0 = byte, 1 = short, 2 = long) */
877 FALSE, /* pc_relative */
879 complain_overflow_bitfield, /* complain_on_overflow */
880 0, /* special_function */
882 TRUE, /* partial_inplace */
883 0xffff, /* src_mask */
884 0xffff, /* dst_mask */
885 FALSE), /* pcrel_offset */
889 /* Non-relocating reference. Bitsize is 1 so that r_rsize is 0. */
890 HOWTO (R_REF, /* type */
892 0, /* size (0 = byte, 1 = short, 2 = long) */
894 FALSE, /* pc_relative */
896 complain_overflow_dont, /* complain_on_overflow */
897 0, /* special_function */
899 FALSE, /* partial_inplace */
902 FALSE), /* pcrel_offset */
907 /* TOC relative indirect load. */
908 HOWTO (R_TRL, /* type */
910 1, /* size (0 = byte, 1 = short, 2 = long) */
912 FALSE, /* pc_relative */
914 complain_overflow_bitfield, /* complain_on_overflow */
915 0, /* special_function */
917 TRUE, /* partial_inplace */
918 0xffff, /* src_mask */
919 0xffff, /* dst_mask */
920 FALSE), /* pcrel_offset */
922 /* TOC relative load address. */
923 HOWTO (R_TRLA, /* type */
925 1, /* size (0 = byte, 1 = short, 2 = long) */
927 FALSE, /* pc_relative */
929 complain_overflow_bitfield, /* complain_on_overflow */
930 0, /* special_function */
932 TRUE, /* partial_inplace */
933 0xffff, /* src_mask */
934 0xffff, /* dst_mask */
935 FALSE), /* pcrel_offset */
937 /* Modifiable relative branch. */
938 HOWTO (R_RRTBI, /* type */
940 2, /* size (0 = byte, 1 = short, 2 = long) */
942 FALSE, /* pc_relative */
944 complain_overflow_bitfield, /* complain_on_overflow */
945 0, /* special_function */
946 "R_RRTBI", /* name */
947 TRUE, /* partial_inplace */
948 0xffffffff, /* src_mask */
949 0xffffffff, /* dst_mask */
950 FALSE), /* pcrel_offset */
952 /* Modifiable absolute branch. */
953 HOWTO (R_RRTBA, /* type */
955 2, /* size (0 = byte, 1 = short, 2 = long) */
957 FALSE, /* pc_relative */
959 complain_overflow_bitfield, /* complain_on_overflow */
960 0, /* special_function */
961 "R_RRTBA", /* name */
962 TRUE, /* partial_inplace */
963 0xffffffff, /* src_mask */
964 0xffffffff, /* dst_mask */
965 FALSE), /* pcrel_offset */
967 /* Modifiable call absolute indirect. */
968 HOWTO (R_CAI, /* type */
970 1, /* size (0 = byte, 1 = short, 2 = long) */
972 FALSE, /* pc_relative */
974 complain_overflow_bitfield, /* complain_on_overflow */
975 0, /* special_function */
977 TRUE, /* partial_inplace */
978 0xffff, /* src_mask */
979 0xffff, /* dst_mask */
980 FALSE), /* pcrel_offset */
982 /* Modifiable call relative. */
983 HOWTO (R_CREL, /* type */
985 1, /* size (0 = byte, 1 = short, 2 = long) */
987 FALSE, /* pc_relative */
989 complain_overflow_bitfield, /* complain_on_overflow */
990 0, /* special_function */
992 TRUE, /* partial_inplace */
993 0xffff, /* src_mask */
994 0xffff, /* dst_mask */
995 FALSE), /* pcrel_offset */
997 /* Modifiable branch absolute. */
998 HOWTO (R_RBA, /* type */
1000 2, /* size (0 = byte, 1 = short, 2 = long) */
1002 FALSE, /* pc_relative */
1004 complain_overflow_bitfield, /* complain_on_overflow */
1005 0, /* special_function */
1007 TRUE, /* partial_inplace */
1008 0x03fffffc, /* src_mask */
1009 0x03fffffc, /* dst_mask */
1010 FALSE), /* pcrel_offset */
1012 /* Modifiable branch absolute. */
1013 HOWTO (R_RBAC, /* type */
1015 2, /* size (0 = byte, 1 = short, 2 = long) */
1017 FALSE, /* pc_relative */
1019 complain_overflow_bitfield, /* complain_on_overflow */
1020 0, /* special_function */
1021 "R_RBAC", /* name */
1022 TRUE, /* partial_inplace */
1023 0xffffffff, /* src_mask */
1024 0xffffffff, /* dst_mask */
1025 FALSE), /* pcrel_offset */
1027 /* Modifiable branch relative. */
1028 HOWTO (R_RBR, /* type */
1030 2, /* size (0 = byte, 1 = short, 2 = long) */
1032 FALSE, /* pc_relative */
1034 complain_overflow_signed, /* complain_on_overflow */
1035 0, /* special_function */
1036 "R_RBR_26", /* name */
1037 TRUE, /* partial_inplace */
1038 0x03fffffc, /* src_mask */
1039 0x03fffffc, /* dst_mask */
1040 FALSE), /* pcrel_offset */
1042 /* Modifiable branch absolute. */
1043 HOWTO (R_RBRC, /* type */
1045 1, /* size (0 = byte, 1 = short, 2 = long) */
1047 FALSE, /* pc_relative */
1049 complain_overflow_bitfield, /* complain_on_overflow */
1050 0, /* special_function */
1051 "R_RBRC", /* name */
1052 TRUE, /* partial_inplace */
1053 0xffff, /* src_mask */
1054 0xffff, /* dst_mask */
1055 FALSE), /* pcrel_offset */
1057 /* 16 bit Non modifiable absolute branch. */
1058 HOWTO (R_BA, /* type */
1060 1, /* size (0 = byte, 1 = short, 2 = long) */
1062 FALSE, /* pc_relative */
1064 complain_overflow_bitfield, /* complain_on_overflow */
1065 0, /* special_function */
1066 "R_BA_16", /* name */
1067 TRUE, /* partial_inplace */
1068 0xfffc, /* src_mask */
1069 0xfffc, /* dst_mask */
1070 FALSE), /* pcrel_offset */
1072 /* Modifiable branch relative. */
1073 HOWTO (R_RBR, /* type */
1075 1, /* size (0 = byte, 1 = short, 2 = long) */
1077 FALSE, /* pc_relative */
1079 complain_overflow_signed, /* complain_on_overflow */
1080 0, /* special_function */
1081 "R_RBR_16", /* name */
1082 TRUE, /* partial_inplace */
1083 0xffff, /* src_mask */
1084 0xffff, /* dst_mask */
1085 FALSE), /* pcrel_offset */
1087 /* Modifiable branch relative. */
1088 HOWTO (R_RBA, /* type */
1090 1, /* size (0 = byte, 1 = short, 2 = long) */
1092 FALSE, /* pc_relative */
1094 complain_overflow_signed, /* complain_on_overflow */
1095 0, /* special_function */
1096 "R_RBA_16", /* name */
1097 TRUE, /* partial_inplace */
1098 0xffff, /* src_mask */
1099 0xffff, /* dst_mask */
1100 FALSE), /* pcrel_offset */
1104 xcoff_rtype2howto (arelent *relent, struct internal_reloc *internal)
1106 if (internal->r_type > R_RBRC)
1109 /* Default howto layout works most of the time */
1110 relent->howto = &xcoff_howto_table[internal->r_type];
1112 /* Special case some 16 bit reloc */
1113 if (15 == (internal->r_size & 0x1f))
1115 if (R_BA == internal->r_type)
1116 relent->howto = &xcoff_howto_table[0x1c];
1117 else if (R_RBR == internal->r_type)
1118 relent->howto = &xcoff_howto_table[0x1d];
1119 else if (R_RBA == internal->r_type)
1120 relent->howto = &xcoff_howto_table[0x1e];
1123 /* The r_size field of an XCOFF reloc encodes the bitsize of the
1124 relocation, as well as indicating whether it is signed or not.
1125 Doublecheck that the relocation information gathered from the
1126 type matches this information. The bitsize is not significant
1127 for R_REF relocs. */
1128 if (relent->howto->dst_mask != 0
1129 && (relent->howto->bitsize
1130 != ((unsigned int) internal->r_size & 0x1f) + 1))
1135 _bfd_xcoff_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1136 bfd_reloc_code_real_type code)
1140 case BFD_RELOC_PPC_B26:
1141 return &xcoff_howto_table[0xa];
1142 case BFD_RELOC_PPC_BA16:
1143 return &xcoff_howto_table[0x1c];
1144 case BFD_RELOC_PPC_BA26:
1145 return &xcoff_howto_table[8];
1146 case BFD_RELOC_PPC_TOC16:
1147 return &xcoff_howto_table[3];
1149 /* Note that this relocation is only internally used by gas. */
1150 return &xcoff_howto_table[0xc];
1152 case BFD_RELOC_CTOR:
1153 return &xcoff_howto_table[0];
1154 case BFD_RELOC_NONE:
1155 return &xcoff_howto_table[0xf];
1161 static reloc_howto_type *
1162 _bfd_xcoff_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1168 i < sizeof (xcoff_howto_table) / sizeof (xcoff_howto_table[0]);
1170 if (xcoff_howto_table[i].name != NULL
1171 && strcasecmp (xcoff_howto_table[i].name, r_name) == 0)
1172 return &xcoff_howto_table[i];
1177 /* XCOFF archive support. The original version of this code was by
1178 Damon A. Permezel. It was enhanced to permit cross support, and
1179 writing archive files, by Ian Lance Taylor, Cygnus Support.
1181 XCOFF uses its own archive format. Everything is hooked together
1182 with file offset links, so it is possible to rapidly update an
1183 archive in place. Of course, we don't do that. An XCOFF archive
1184 has a real file header, not just an ARMAG string. The structure of
1185 the file header and of each archive header appear below.
1187 An XCOFF archive also has a member table, which is a list of
1188 elements in the archive (you can get that by looking through the
1189 linked list, but you have to read a lot more of the file). The
1190 member table has a normal archive header with an empty name. It is
1191 normally (and perhaps must be) the second to last entry in the
1192 archive. The member table data is almost printable ASCII. It
1193 starts with a 12 character decimal string which is the number of
1194 entries in the table. For each entry it has a 12 character decimal
1195 string which is the offset in the archive of that member. These
1196 entries are followed by a series of null terminated strings which
1197 are the member names for each entry.
1199 Finally, an XCOFF archive has a global symbol table, which is what
1200 we call the armap. The global symbol table has a normal archive
1201 header with an empty name. It is normally (and perhaps must be)
1202 the last entry in the archive. The contents start with a four byte
1203 binary number which is the number of entries. This is followed by
1204 a that many four byte binary numbers; each is the file offset of an
1205 entry in the archive. These numbers are followed by a series of
1206 null terminated strings, which are symbol names.
1208 AIX 4.3 introduced a new archive format which can handle larger
1209 files and also 32- and 64-bit objects in the same archive. The
1210 things said above remain true except that there is now more than
1211 one global symbol table. The one is used to index 32-bit objects,
1212 the other for 64-bit objects.
1214 The new archives (recognizable by the new ARMAG string) has larger
1215 field lengths so that we cannot really share any code. Also we have
1216 to take care that we are not generating the new form of archives
1217 on AIX 4.2 or earlier systems. */
1219 /* XCOFF archives use this as a magic string. Note that both strings
1220 have the same length. */
1222 /* Set the magic for archive. */
1225 bfd_xcoff_ar_archive_set_magic (bfd *abfd ATTRIBUTE_UNUSED,
1226 char *magic ATTRIBUTE_UNUSED)
1228 /* Not supported yet. */
1230 /* bfd_xcoff_archive_set_magic (abfd, magic); */
1233 /* Read in the armap of an XCOFF archive. */
1236 _bfd_xcoff_slurp_armap (bfd *abfd)
1241 bfd_byte *contents, *cend;
1246 if (xcoff_ardata (abfd) == NULL)
1248 bfd_has_map (abfd) = FALSE;
1252 if (! xcoff_big_format_p (abfd))
1254 /* This is for the old format. */
1255 struct xcoff_ar_hdr hdr;
1257 off = strtol (xcoff_ardata (abfd)->symoff, (char **) NULL, 10);
1260 bfd_has_map (abfd) = FALSE;
1264 if (bfd_seek (abfd, off, SEEK_SET) != 0)
1267 /* The symbol table starts with a normal archive header. */
1268 if (bfd_bread (&hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
1272 /* Skip the name (normally empty). */
1273 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1274 off = ((namlen + 1) & ~ (size_t) 1) + SXCOFFARFMAG;
1275 if (bfd_seek (abfd, off, SEEK_CUR) != 0)
1278 sz = strtol (hdr.size, (char **) NULL, 10);
1280 /* Read in the entire symbol table. */
1281 contents = (bfd_byte *) bfd_alloc (abfd, sz);
1282 if (contents == NULL)
1284 if (bfd_bread (contents, sz, abfd) != sz)
1287 /* The symbol table starts with a four byte count. */
1288 c = H_GET_32 (abfd, contents);
1292 bfd_set_error (bfd_error_bad_value);
1296 bfd_ardata (abfd)->symdefs =
1297 ((carsym *) bfd_alloc (abfd, c * sizeof (carsym)));
1298 if (bfd_ardata (abfd)->symdefs == NULL)
1301 /* After the count comes a list of four byte file offsets. */
1302 for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 4;
1304 ++i, ++arsym, p += 4)
1305 arsym->file_offset = H_GET_32 (abfd, p);
1309 /* This is for the new format. */
1310 struct xcoff_ar_hdr_big hdr;
1312 off = strtol (xcoff_ardata_big (abfd)->symoff, (char **) NULL, 10);
1315 bfd_has_map (abfd) = FALSE;
1319 if (bfd_seek (abfd, off, SEEK_SET) != 0)
1322 /* The symbol table starts with a normal archive header. */
1323 if (bfd_bread (&hdr, (bfd_size_type) SIZEOF_AR_HDR_BIG, abfd)
1324 != SIZEOF_AR_HDR_BIG)
1327 /* Skip the name (normally empty). */
1328 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1329 off = ((namlen + 1) & ~ (size_t) 1) + SXCOFFARFMAG;
1330 if (bfd_seek (abfd, off, SEEK_CUR) != 0)
1333 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1334 machines) since the field width is 20 and there numbers with more
1335 than 32 bits can be represented. */
1336 sz = strtol (hdr.size, (char **) NULL, 10);
1338 /* Read in the entire symbol table. */
1339 contents = (bfd_byte *) bfd_alloc (abfd, sz);
1340 if (contents == NULL)
1342 if (bfd_bread (contents, sz, abfd) != sz)
1345 /* The symbol table starts with an eight byte count. */
1346 c = H_GET_64 (abfd, contents);
1350 bfd_set_error (bfd_error_bad_value);
1354 bfd_ardata (abfd)->symdefs =
1355 ((carsym *) bfd_alloc (abfd, c * sizeof (carsym)));
1356 if (bfd_ardata (abfd)->symdefs == NULL)
1359 /* After the count comes a list of eight byte file offsets. */
1360 for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 8;
1362 ++i, ++arsym, p += 8)
1363 arsym->file_offset = H_GET_64 (abfd, p);
1366 /* After the file offsets come null terminated symbol names. */
1367 cend = contents + sz;
1368 for (i = 0, arsym = bfd_ardata (abfd)->symdefs;
1370 ++i, ++arsym, p += strlen ((char *) p) + 1)
1374 bfd_set_error (bfd_error_bad_value);
1377 arsym->name = (char *) p;
1380 bfd_ardata (abfd)->symdef_count = c;
1381 bfd_has_map (abfd) = TRUE;
1386 /* See if this is an XCOFF archive. */
1389 _bfd_xcoff_archive_p (bfd *abfd)
1391 struct artdata *tdata_hold;
1392 char magic[SXCOFFARMAG];
1393 bfd_size_type amt = SXCOFFARMAG;
1395 if (bfd_bread (magic, amt, abfd) != amt)
1397 if (bfd_get_error () != bfd_error_system_call)
1398 bfd_set_error (bfd_error_wrong_format);
1402 if (strncmp (magic, XCOFFARMAG, SXCOFFARMAG) != 0
1403 && strncmp (magic, XCOFFARMAGBIG, SXCOFFARMAG) != 0)
1405 bfd_set_error (bfd_error_wrong_format);
1409 tdata_hold = bfd_ardata (abfd);
1411 amt = sizeof (struct artdata);
1412 bfd_ardata (abfd) = (struct artdata *) bfd_zalloc (abfd, amt);
1413 if (bfd_ardata (abfd) == (struct artdata *) NULL)
1414 goto error_ret_restore;
1416 /* Cleared by bfd_zalloc above.
1417 bfd_ardata (abfd)->cache = NULL;
1418 bfd_ardata (abfd)->archive_head = NULL;
1419 bfd_ardata (abfd)->symdefs = NULL;
1420 bfd_ardata (abfd)->extended_names = NULL;
1421 bfd_ardata (abfd)->extended_names_size = 0; */
1423 /* Now handle the two formats. */
1424 if (magic[1] != 'b')
1426 /* This is the old format. */
1427 struct xcoff_ar_file_hdr hdr;
1429 /* Copy over the magic string. */
1430 memcpy (hdr.magic, magic, SXCOFFARMAG);
1432 /* Now read the rest of the file header. */
1433 amt = SIZEOF_AR_FILE_HDR - SXCOFFARMAG;
1434 if (bfd_bread (&hdr.memoff, amt, abfd) != amt)
1436 if (bfd_get_error () != bfd_error_system_call)
1437 bfd_set_error (bfd_error_wrong_format);
1441 bfd_ardata (abfd)->first_file_filepos = strtol (hdr.firstmemoff,
1442 (char **) NULL, 10);
1444 amt = SIZEOF_AR_FILE_HDR;
1445 bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, amt);
1446 if (bfd_ardata (abfd)->tdata == NULL)
1449 memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR);
1453 /* This is the new format. */
1454 struct xcoff_ar_file_hdr_big hdr;
1456 /* Copy over the magic string. */
1457 memcpy (hdr.magic, magic, SXCOFFARMAG);
1459 /* Now read the rest of the file header. */
1460 amt = SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG;
1461 if (bfd_bread (&hdr.memoff, amt, abfd) != amt)
1463 if (bfd_get_error () != bfd_error_system_call)
1464 bfd_set_error (bfd_error_wrong_format);
1468 bfd_ardata (abfd)->first_file_filepos = bfd_scan_vma (hdr.firstmemoff,
1472 amt = SIZEOF_AR_FILE_HDR_BIG;
1473 bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, amt);
1474 if (bfd_ardata (abfd)->tdata == NULL)
1477 memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR_BIG);
1480 if (! _bfd_xcoff_slurp_armap (abfd))
1483 bfd_release (abfd, bfd_ardata (abfd));
1485 bfd_ardata (abfd) = tdata_hold;
1492 /* Read the archive header in an XCOFF archive. */
1495 _bfd_xcoff_read_ar_hdr (bfd *abfd)
1497 bfd_size_type namlen;
1498 struct areltdata *ret;
1499 bfd_size_type amt = sizeof (struct areltdata);
1501 ret = (struct areltdata *) bfd_zmalloc (amt);
1505 if (! xcoff_big_format_p (abfd))
1507 struct xcoff_ar_hdr hdr;
1508 struct xcoff_ar_hdr *hdrp;
1510 if (bfd_bread (&hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
1517 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1518 amt = SIZEOF_AR_HDR + namlen + 1;
1519 hdrp = (struct xcoff_ar_hdr *) bfd_alloc (abfd, amt);
1525 memcpy (hdrp, &hdr, SIZEOF_AR_HDR);
1526 if (bfd_bread ((char *) hdrp + SIZEOF_AR_HDR, namlen, abfd) != namlen)
1531 ((char *) hdrp)[SIZEOF_AR_HDR + namlen] = '\0';
1533 ret->arch_header = (char *) hdrp;
1534 ret->parsed_size = strtol (hdr.size, (char **) NULL, 10);
1535 ret->filename = (char *) hdrp + SIZEOF_AR_HDR;
1539 struct xcoff_ar_hdr_big hdr;
1540 struct xcoff_ar_hdr_big *hdrp;
1542 if (bfd_bread (&hdr, (bfd_size_type) SIZEOF_AR_HDR_BIG, abfd)
1543 != SIZEOF_AR_HDR_BIG)
1549 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1550 amt = SIZEOF_AR_HDR_BIG + namlen + 1;
1551 hdrp = (struct xcoff_ar_hdr_big *) bfd_alloc (abfd, amt);
1557 memcpy (hdrp, &hdr, SIZEOF_AR_HDR_BIG);
1558 if (bfd_bread ((char *) hdrp + SIZEOF_AR_HDR_BIG, namlen, abfd) != namlen)
1563 ((char *) hdrp)[SIZEOF_AR_HDR_BIG + namlen] = '\0';
1565 ret->arch_header = (char *) hdrp;
1566 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1567 machines) since the field width is 20 and there numbers with more
1568 than 32 bits can be represented. */
1569 ret->parsed_size = strtol (hdr.size, (char **) NULL, 10);
1570 ret->filename = (char *) hdrp + SIZEOF_AR_HDR_BIG;
1573 /* Skip over the XCOFFARFMAG at the end of the file name. */
1574 if (bfd_seek (abfd, (file_ptr) ((namlen & 1) + SXCOFFARFMAG), SEEK_CUR) != 0)
1580 /* Open the next element in an XCOFF archive. */
1583 _bfd_xcoff_openr_next_archived_file (bfd *archive, bfd *last_file)
1587 if (xcoff_ardata (archive) == NULL)
1589 bfd_set_error (bfd_error_invalid_operation);
1593 if (! xcoff_big_format_p (archive))
1595 if (last_file == NULL)
1596 filestart = bfd_ardata (archive)->first_file_filepos;
1598 filestart = strtol (arch_xhdr (last_file)->nextoff, (char **) NULL,
1602 || filestart == strtol (xcoff_ardata (archive)->memoff,
1604 || filestart == strtol (xcoff_ardata (archive)->symoff,
1605 (char **) NULL, 10))
1607 bfd_set_error (bfd_error_no_more_archived_files);
1613 if (last_file == NULL)
1614 filestart = bfd_ardata (archive)->first_file_filepos;
1616 /* XXX These actually have to be a calls to strtoll (at least
1617 on 32-bit machines) since the fields's width is 20 and
1618 there numbers with more than 32 bits can be represented. */
1619 filestart = strtol (arch_xhdr_big (last_file)->nextoff, (char **) NULL,
1622 /* XXX These actually have to be calls to strtoll (at least on 32-bit
1623 machines) since the fields's width is 20 and there numbers with more
1624 than 32 bits can be represented. */
1626 || filestart == strtol (xcoff_ardata_big (archive)->memoff,
1628 || filestart == strtol (xcoff_ardata_big (archive)->symoff,
1629 (char **) NULL, 10))
1631 bfd_set_error (bfd_error_no_more_archived_files);
1636 return _bfd_get_elt_at_filepos (archive, filestart);
1639 /* Stat an element in an XCOFF archive. */
1642 _bfd_xcoff_stat_arch_elt (bfd *abfd, struct stat *s)
1644 if (abfd->arelt_data == NULL)
1646 bfd_set_error (bfd_error_invalid_operation);
1650 if (! xcoff_big_format_p (abfd->my_archive))
1652 struct xcoff_ar_hdr *hdrp = arch_xhdr (abfd);
1654 s->st_mtime = strtol (hdrp->date, (char **) NULL, 10);
1655 s->st_uid = strtol (hdrp->uid, (char **) NULL, 10);
1656 s->st_gid = strtol (hdrp->gid, (char **) NULL, 10);
1657 s->st_mode = strtol (hdrp->mode, (char **) NULL, 8);
1658 s->st_size = arch_eltdata (abfd)->parsed_size;
1662 struct xcoff_ar_hdr_big *hdrp = arch_xhdr_big (abfd);
1664 s->st_mtime = strtol (hdrp->date, (char **) NULL, 10);
1665 s->st_uid = strtol (hdrp->uid, (char **) NULL, 10);
1666 s->st_gid = strtol (hdrp->gid, (char **) NULL, 10);
1667 s->st_mode = strtol (hdrp->mode, (char **) NULL, 8);
1668 s->st_size = arch_eltdata (abfd)->parsed_size;
1674 /* Normalize a file name for inclusion in an archive. */
1677 normalize_filename (bfd *abfd)
1680 const char *filename;
1682 file = bfd_get_filename (abfd);
1683 filename = strrchr (file, '/');
1684 if (filename != NULL)
1691 /* Write out an XCOFF armap. */
1694 xcoff_write_armap_old (bfd *abfd, unsigned int elength ATTRIBUTE_UNUSED,
1695 struct orl *map, unsigned int orl_count, int stridx)
1697 struct archive_iterator iterator;
1698 struct xcoff_ar_hdr hdr;
1700 unsigned char buf[4];
1703 memset (&hdr, 0, sizeof hdr);
1704 sprintf (hdr.size, "%ld", (long) (4 + orl_count * 4 + stridx));
1705 sprintf (hdr.nextoff, "%d", 0);
1706 memcpy (hdr.prevoff, xcoff_ardata (abfd)->memoff, XCOFFARMAG_ELEMENT_SIZE);
1707 sprintf (hdr.date, "%d", 0);
1708 sprintf (hdr.uid, "%d", 0);
1709 sprintf (hdr.gid, "%d", 0);
1710 sprintf (hdr.mode, "%d", 0);
1711 sprintf (hdr.namlen, "%d", 0);
1713 /* We need spaces, not null bytes, in the header. */
1714 for (p = (char *) &hdr; p < (char *) &hdr + SIZEOF_AR_HDR; p++)
1718 if (bfd_bwrite (&hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
1720 || (bfd_bwrite (XCOFFARFMAG, (bfd_size_type) SXCOFFARFMAG, abfd)
1724 H_PUT_32 (abfd, orl_count, buf);
1725 if (bfd_bwrite (buf, (bfd_size_type) 4, abfd) != 4)
1729 archive_iterator_begin (&iterator, abfd);
1730 while (i < orl_count && archive_iterator_next (&iterator))
1731 while (map[i].u.abfd == iterator.current.member)
1733 H_PUT_32 (abfd, iterator.current.offset, buf);
1734 if (bfd_bwrite (buf, (bfd_size_type) 4, abfd) != 4)
1739 for (i = 0; i < orl_count; i++)
1744 name = *map[i].name;
1745 namlen = strlen (name);
1746 if (bfd_bwrite (name, (bfd_size_type) (namlen + 1), abfd) != namlen + 1)
1750 if ((stridx & 1) != 0)
1755 if (bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
1762 static char buff20[XCOFFARMAGBIG_ELEMENT_SIZE + 1];
1763 #define FMT20 "%-20lld"
1764 #define FMT12 "%-12d"
1765 #define FMT12_OCTAL "%-12o"
1767 #define PRINT20(d, v) \
1768 sprintf (buff20, FMT20, (long long)(v)), \
1769 memcpy ((void *) (d), buff20, 20)
1771 #define PRINT12(d, v) \
1772 sprintf (buff20, FMT12, (int)(v)), \
1773 memcpy ((void *) (d), buff20, 12)
1775 #define PRINT12_OCTAL(d, v) \
1776 sprintf (buff20, FMT12_OCTAL, (unsigned int)(v)), \
1777 memcpy ((void *) (d), buff20, 12)
1779 #define PRINT4(d, v) \
1780 sprintf (buff20, FMT4, (int)(v)), \
1781 memcpy ((void *) (d), buff20, 4)
1783 #define READ20(d, v) \
1785 memcpy (buff20, (d), 20), \
1786 (v) = bfd_scan_vma (buff20, (const char **) NULL, 10)
1789 do_pad (bfd *abfd, unsigned int number)
1793 /* Limit pad to <= 4096. */
1798 if (bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
1805 do_copy (bfd *out_bfd, bfd *in_bfd)
1807 bfd_size_type remaining;
1808 bfd_byte buffer[DEFAULT_BUFFERSIZE];
1810 if (bfd_seek (in_bfd, (file_ptr) 0, SEEK_SET) != 0)
1813 remaining = arelt_size (in_bfd);
1815 while (remaining >= DEFAULT_BUFFERSIZE)
1817 if (bfd_bread (buffer, DEFAULT_BUFFERSIZE, in_bfd) != DEFAULT_BUFFERSIZE
1818 || bfd_bwrite (buffer, DEFAULT_BUFFERSIZE, out_bfd) != DEFAULT_BUFFERSIZE)
1821 remaining -= DEFAULT_BUFFERSIZE;
1826 if (bfd_bread (buffer, remaining, in_bfd) != remaining
1827 || bfd_bwrite (buffer, remaining, out_bfd) != remaining)
1835 xcoff_write_armap_big (bfd *abfd, unsigned int elength ATTRIBUTE_UNUSED,
1836 struct orl *map, unsigned int orl_count, int stridx)
1838 struct archive_iterator iterator;
1839 struct xcoff_ar_file_hdr_big *fhdr;
1840 bfd_vma i, sym_32, sym_64, str_32, str_64;
1841 const bfd_arch_info_type *arch_info;
1843 size_t string_length;
1844 file_ptr nextoff, prevoff;
1846 /* First, we look through the symbols and work out which are
1847 from 32-bit objects and which from 64-bit ones. */
1848 sym_32 = sym_64 = str_32 = str_64 = 0;
1851 for (current_bfd = abfd->archive_head;
1852 current_bfd != NULL && i < orl_count;
1853 current_bfd = current_bfd->archive_next)
1855 arch_info = bfd_get_arch_info (current_bfd);
1856 while (map[i].u.abfd == current_bfd)
1858 string_length = strlen (*map[i].name) + 1;
1859 if (arch_info->bits_per_address == 64)
1862 str_64 += string_length;
1867 str_32 += string_length;
1873 /* A quick sanity check... */
1874 BFD_ASSERT (sym_64 + sym_32 == orl_count);
1875 /* Explicit cast to int for compiler. */
1876 BFD_ASSERT ((int)(str_64 + str_32) == stridx);
1878 fhdr = xcoff_ardata_big (abfd);
1880 /* xcoff_write_archive_contents_big passes nextoff in symoff. */
1881 READ20 (fhdr->memoff, prevoff);
1882 READ20 (fhdr->symoff, nextoff);
1884 BFD_ASSERT (nextoff == bfd_tell (abfd));
1886 /* Write out the symbol table.
1889 standard big archive header
1890 0x0000 ar_size [0x14]
1891 0x0014 ar_nxtmem [0x14]
1892 0x0028 ar_prvmem [0x14]
1893 0x003C ar_date [0x0C]
1894 0x0048 ar_uid [0x0C]
1895 0x0054 ar_gid [0x0C]
1896 0x0060 ar_mod [0x0C]
1897 0x006C ar_namelen[0x04]
1898 0x0070 ar_fmag [SXCOFFARFMAG]
1901 0x0072 num_syms [0x08], binary
1902 0x0078 offsets [0x08 * num_syms], binary
1903 0x0086 + 0x08 * num_syms names [??]
1904 ?? pad to even bytes.
1909 struct xcoff_ar_hdr_big *hdr;
1913 bfd_vma symbol_table_size =
1918 + str_32 + (str_32 & 1);
1920 symbol_table = bfd_zmalloc (symbol_table_size);
1921 if (symbol_table == NULL)
1924 hdr = (struct xcoff_ar_hdr_big *) symbol_table;
1926 PRINT20 (hdr->size, 8 + 8 * sym_32 + str_32 + (str_32 & 1));
1929 PRINT20 (hdr->nextoff, nextoff + symbol_table_size);
1931 PRINT20 (hdr->nextoff, 0);
1933 PRINT20 (hdr->prevoff, prevoff);
1934 PRINT12 (hdr->date, 0);
1935 PRINT12 (hdr->uid, 0);
1936 PRINT12 (hdr->gid, 0);
1937 PRINT12 (hdr->mode, 0);
1938 PRINT4 (hdr->namlen, 0) ;
1940 st = symbol_table + SIZEOF_AR_HDR_BIG;
1941 memcpy (st, XCOFFARFMAG, SXCOFFARFMAG);
1944 bfd_h_put_64 (abfd, sym_32, st);
1947 /* loop over the 32 bit offsets */
1949 archive_iterator_begin (&iterator, abfd);
1950 while (i < orl_count && archive_iterator_next (&iterator))
1952 arch_info = bfd_get_arch_info (iterator.current.member);
1953 while (map[i].u.abfd == iterator.current.member)
1955 if (arch_info->bits_per_address == 32)
1957 bfd_h_put_64 (abfd, iterator.current.offset, st);
1964 /* loop over the 32 bit symbol names */
1966 for (current_bfd = abfd->archive_head;
1967 current_bfd != NULL && i < orl_count;
1968 current_bfd = current_bfd->archive_next)
1970 arch_info = bfd_get_arch_info (current_bfd);
1971 while (map[i].u.abfd == current_bfd)
1973 if (arch_info->bits_per_address == 32)
1975 string_length = sprintf (st, "%s", *map[i].name);
1976 st += string_length + 1;
1982 bfd_bwrite (symbol_table, symbol_table_size, abfd);
1984 free (symbol_table);
1987 nextoff = nextoff + symbol_table_size;
1990 PRINT20 (fhdr->symoff, 0);
1994 struct xcoff_ar_hdr_big *hdr;
1998 bfd_vma symbol_table_size =
2003 + str_64 + (str_64 & 1);
2005 symbol_table = bfd_zmalloc (symbol_table_size);
2006 if (symbol_table == NULL)
2009 hdr = (struct xcoff_ar_hdr_big *) symbol_table;
2011 PRINT20 (hdr->size, 8 + 8 * sym_64 + str_64 + (str_64 & 1));
2012 PRINT20 (hdr->nextoff, 0);
2013 PRINT20 (hdr->prevoff, prevoff);
2014 PRINT12 (hdr->date, 0);
2015 PRINT12 (hdr->uid, 0);
2016 PRINT12 (hdr->gid, 0);
2017 PRINT12 (hdr->mode, 0);
2018 PRINT4 (hdr->namlen, 0);
2020 st = symbol_table + SIZEOF_AR_HDR_BIG;
2021 memcpy (st, XCOFFARFMAG, SXCOFFARFMAG);
2024 bfd_h_put_64 (abfd, sym_64, st);
2027 /* loop over the 64 bit offsets */
2029 archive_iterator_begin (&iterator, abfd);
2030 while (i < orl_count && archive_iterator_next (&iterator))
2032 arch_info = bfd_get_arch_info (iterator.current.member);
2033 while (map[i].u.abfd == iterator.current.member)
2035 if (arch_info->bits_per_address == 64)
2037 bfd_h_put_64 (abfd, iterator.current.offset, st);
2044 /* loop over the 64 bit symbol names */
2046 for (current_bfd = abfd->archive_head;
2047 current_bfd != NULL && i < orl_count;
2048 current_bfd = current_bfd->archive_next)
2050 arch_info = bfd_get_arch_info (current_bfd);
2051 while (map[i].u.abfd == current_bfd)
2053 if (arch_info->bits_per_address == 64)
2055 string_length = sprintf (st, "%s", *map[i].name);
2056 st += string_length + 1;
2062 bfd_bwrite (symbol_table, symbol_table_size, abfd);
2064 free (symbol_table);
2066 PRINT20 (fhdr->symoff64, nextoff);
2069 PRINT20 (fhdr->symoff64, 0);
2075 _bfd_xcoff_write_armap (bfd *abfd, unsigned int elength ATTRIBUTE_UNUSED,
2076 struct orl *map, unsigned int orl_count, int stridx)
2078 if (! xcoff_big_format_p (abfd))
2079 return xcoff_write_armap_old (abfd, elength, map, orl_count, stridx);
2081 return xcoff_write_armap_big (abfd, elength, map, orl_count, stridx);
2084 /* Write out an XCOFF archive. We always write an entire archive,
2085 rather than fussing with the freelist and so forth. */
2088 xcoff_write_archive_contents_old (bfd *abfd)
2090 struct archive_iterator iterator;
2091 struct xcoff_ar_file_hdr fhdr;
2092 bfd_size_type count;
2093 bfd_size_type total_namlen;
2095 bfd_boolean makemap;
2096 bfd_boolean hasobjects;
2097 file_ptr prevoff, nextoff;
2100 struct xcoff_ar_hdr ahdr;
2103 char decbuf[XCOFFARMAG_ELEMENT_SIZE + 1];
2105 memset (&fhdr, 0, sizeof fhdr);
2106 (void) strncpy (fhdr.magic, XCOFFARMAG, SXCOFFARMAG);
2107 sprintf (fhdr.firstmemoff, "%d", SIZEOF_AR_FILE_HDR);
2108 sprintf (fhdr.freeoff, "%d", 0);
2112 for (sub = abfd->archive_head; sub != NULL; sub = sub->archive_next)
2115 total_namlen += strlen (normalize_filename (sub)) + 1;
2116 if (sub->arelt_data == NULL)
2118 sub->arelt_data = bfd_zmalloc (sizeof (struct areltdata));
2119 if (sub->arelt_data == NULL)
2122 if (arch_xhdr (sub) == NULL)
2124 struct xcoff_ar_hdr *ahdrp;
2127 if (stat (bfd_get_filename (sub), &s) != 0)
2129 bfd_set_error (bfd_error_system_call);
2133 ahdrp = bfd_zalloc (sub, sizeof (*ahdrp));
2137 sprintf (ahdrp->size, "%ld", (long) s.st_size);
2138 sprintf (ahdrp->date, "%ld", (long) s.st_mtime);
2139 sprintf (ahdrp->uid, "%ld", (long) s.st_uid);
2140 sprintf (ahdrp->gid, "%ld", (long) s.st_gid);
2141 sprintf (ahdrp->mode, "%o", (unsigned int) s.st_mode);
2143 arch_eltdata (sub)->arch_header = (char *) ahdrp;
2144 arch_eltdata (sub)->parsed_size = s.st_size;
2147 offsets = (file_ptr *) bfd_alloc (abfd, count * sizeof (file_ptr));
2148 if (offsets == NULL)
2151 if (bfd_seek (abfd, (file_ptr) SIZEOF_AR_FILE_HDR, SEEK_SET) != 0)
2154 makemap = bfd_has_map (abfd);
2157 for (archive_iterator_begin (&iterator, abfd), i = 0;
2158 archive_iterator_next (&iterator);
2161 bfd_size_type namlen;
2162 struct xcoff_ar_hdr *ahdrp;
2164 if (makemap && ! hasobjects)
2166 if (bfd_check_format (iterator.current.member, bfd_object))
2170 ahdrp = arch_xhdr (iterator.current.member);
2171 sprintf (ahdrp->prevoff, "%ld", (long) prevoff);
2172 sprintf (ahdrp->namlen, "%ld", (long) iterator.current.namlen);
2173 sprintf (ahdrp->nextoff, "%ld", (long) iterator.next.offset);
2175 /* We need spaces, not null bytes, in the header. */
2176 for (p = (char *) ahdrp; p < (char *) ahdrp + SIZEOF_AR_HDR; p++)
2180 if (!do_pad (abfd, iterator.current.leading_padding))
2183 BFD_ASSERT (iterator.current.offset == bfd_tell (abfd));
2184 namlen = iterator.current.padded_namlen;
2185 if (bfd_bwrite (ahdrp, SIZEOF_AR_HDR, abfd) != SIZEOF_AR_HDR
2186 || bfd_bwrite (iterator.current.name, namlen, abfd) != namlen
2187 || bfd_bwrite (XCOFFARFMAG, SXCOFFARFMAG, abfd) != SXCOFFARFMAG
2188 || bfd_seek (iterator.current.member, 0, SEEK_SET) != 0
2189 || !do_copy (abfd, iterator.current.member)
2190 || !do_pad (abfd, iterator.current.trailing_padding))
2193 offsets[i] = iterator.current.offset;
2194 prevoff = iterator.current.offset;
2197 sprintf (fhdr.lastmemoff, "%ld", (long) prevoff);
2199 /* Write out the member table. */
2201 nextoff = iterator.next.offset;
2202 BFD_ASSERT (nextoff == bfd_tell (abfd));
2203 sprintf (fhdr.memoff, "%ld", (long) nextoff);
2205 memset (&ahdr, 0, sizeof ahdr);
2206 sprintf (ahdr.size, "%ld", (long) (XCOFFARMAG_ELEMENT_SIZE
2207 + count * XCOFFARMAG_ELEMENT_SIZE
2209 sprintf (ahdr.prevoff, "%ld", (long) prevoff);
2210 sprintf (ahdr.date, "%d", 0);
2211 sprintf (ahdr.uid, "%d", 0);
2212 sprintf (ahdr.gid, "%d", 0);
2213 sprintf (ahdr.mode, "%d", 0);
2214 sprintf (ahdr.namlen, "%d", 0);
2216 size = (SIZEOF_AR_HDR
2217 + XCOFFARMAG_ELEMENT_SIZE
2218 + count * XCOFFARMAG_ELEMENT_SIZE
2223 nextoff += size + (size & 1);
2225 if (makemap && hasobjects)
2226 sprintf (ahdr.nextoff, "%ld", (long) nextoff);
2228 sprintf (ahdr.nextoff, "%d", 0);
2230 /* We need spaces, not null bytes, in the header. */
2231 for (p = (char *) &ahdr; p < (char *) &ahdr + SIZEOF_AR_HDR; p++)
2235 if ((bfd_bwrite (&ahdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
2237 || (bfd_bwrite (XCOFFARFMAG, (bfd_size_type) SXCOFFARFMAG, abfd)
2241 sprintf (decbuf, "%-12ld", (long) count);
2242 if (bfd_bwrite (decbuf, (bfd_size_type) XCOFFARMAG_ELEMENT_SIZE, abfd)
2243 != XCOFFARMAG_ELEMENT_SIZE)
2245 for (i = 0; i < (size_t) count; i++)
2247 sprintf (decbuf, "%-12ld", (long) offsets[i]);
2248 if (bfd_bwrite (decbuf, (bfd_size_type) XCOFFARMAG_ELEMENT_SIZE,
2249 abfd) != XCOFFARMAG_ELEMENT_SIZE)
2252 for (sub = abfd->archive_head; sub != NULL; sub = sub->archive_next)
2255 bfd_size_type namlen;
2257 name = normalize_filename (sub);
2258 namlen = strlen (name);
2259 if (bfd_bwrite (name, namlen + 1, abfd) != namlen + 1)
2263 if (! do_pad (abfd, size & 1))
2266 /* Write out the armap, if appropriate. */
2267 if (! makemap || ! hasobjects)
2268 sprintf (fhdr.symoff, "%d", 0);
2271 BFD_ASSERT (nextoff == bfd_tell (abfd));
2272 sprintf (fhdr.symoff, "%ld", (long) nextoff);
2273 bfd_ardata (abfd)->tdata = &fhdr;
2274 if (! _bfd_compute_and_write_armap (abfd, 0))
2278 /* Write out the archive file header. */
2280 /* We need spaces, not null bytes, in the header. */
2281 for (p = (char *) &fhdr; p < (char *) &fhdr + SIZEOF_AR_FILE_HDR; p++)
2285 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
2286 || (bfd_bwrite (&fhdr, (bfd_size_type) SIZEOF_AR_FILE_HDR, abfd)
2287 != SIZEOF_AR_FILE_HDR))
2294 xcoff_write_archive_contents_big (bfd *abfd)
2296 struct xcoff_ar_file_hdr_big fhdr;
2297 bfd_size_type count;
2298 bfd_size_type total_namlen;
2300 bfd_boolean makemap;
2301 bfd_boolean hasobjects;
2302 file_ptr prevoff, nextoff;
2305 struct xcoff_ar_hdr_big *hdr;
2307 char *member_table, *mt;
2308 bfd_vma member_table_size;
2309 struct archive_iterator iterator;
2311 memset (&fhdr, 0, SIZEOF_AR_FILE_HDR_BIG);
2312 memcpy (fhdr.magic, XCOFFARMAGBIG, SXCOFFARMAG);
2314 if (bfd_seek (abfd, (file_ptr) SIZEOF_AR_FILE_HDR_BIG, SEEK_SET) != 0)
2317 /* Calculate count and total_namlen. */
2318 makemap = bfd_has_map (abfd);
2320 for (current_bfd = abfd->archive_head, count = 0, total_namlen = 0;
2321 current_bfd != NULL;
2322 current_bfd = current_bfd->archive_next, count++)
2324 total_namlen += strlen (normalize_filename (current_bfd)) + 1;
2328 && bfd_check_format (current_bfd, bfd_object))
2331 if (current_bfd->arelt_data == NULL)
2333 size = sizeof (struct areltdata);
2334 current_bfd->arelt_data = bfd_zmalloc (size);
2335 if (current_bfd->arelt_data == NULL)
2339 if (arch_xhdr_big (current_bfd) == NULL)
2341 struct xcoff_ar_hdr_big *ahdrp;
2344 /* XXX This should actually be a call to stat64 (at least on
2346 XXX This call will fail if the original object is not found. */
2347 if (stat (bfd_get_filename (current_bfd), &s) != 0)
2349 bfd_set_error (bfd_error_system_call);
2353 ahdrp = bfd_zalloc (current_bfd, sizeof (*ahdrp));
2357 PRINT20 (ahdrp->size, s.st_size);
2358 PRINT12 (ahdrp->date, s.st_mtime);
2359 PRINT12 (ahdrp->uid, s.st_uid);
2360 PRINT12 (ahdrp->gid, s.st_gid);
2361 PRINT12_OCTAL (ahdrp->mode, s.st_mode);
2363 arch_eltdata (current_bfd)->arch_header = (char *) ahdrp;
2364 arch_eltdata (current_bfd)->parsed_size = s.st_size;
2371 offsets = (file_ptr *) bfd_malloc (count * sizeof (file_ptr));
2372 if (offsets == NULL)
2377 for (archive_iterator_begin (&iterator, abfd), i = 0;
2378 archive_iterator_next (&iterator);
2381 bfd_size_type namlen;
2382 struct xcoff_ar_hdr_big *ahdrp;
2384 ahdrp = arch_xhdr_big (iterator.current.member);
2385 PRINT20 (ahdrp->prevoff, prevoff);
2386 PRINT4 (ahdrp->namlen, iterator.current.namlen);
2387 PRINT20 (ahdrp->nextoff, iterator.next.offset);
2389 if (!do_pad (abfd, iterator.current.leading_padding))
2392 BFD_ASSERT (iterator.current.offset == bfd_tell (abfd));
2393 namlen = iterator.current.padded_namlen;
2394 if (bfd_bwrite (ahdrp, SIZEOF_AR_HDR_BIG, abfd) != SIZEOF_AR_HDR_BIG
2395 || bfd_bwrite (iterator.current.name, namlen, abfd) != namlen
2396 || bfd_bwrite (XCOFFARFMAG, SXCOFFARFMAG, abfd) != SXCOFFARFMAG
2397 || bfd_seek (iterator.current.member, 0, SEEK_SET) != 0
2398 || !do_copy (abfd, iterator.current.member)
2399 || !do_pad (abfd, iterator.current.trailing_padding))
2402 offsets[i] = iterator.current.offset;
2403 prevoff = iterator.current.offset;
2408 PRINT20 (fhdr.firstmemoff, offsets[0]);
2409 PRINT20 (fhdr.lastmemoff, prevoff);
2412 /* Write out the member table.
2415 standard big archive header
2416 0x0000 ar_size [0x14]
2417 0x0014 ar_nxtmem [0x14]
2418 0x0028 ar_prvmem [0x14]
2419 0x003C ar_date [0x0C]
2420 0x0048 ar_uid [0x0C]
2421 0x0054 ar_gid [0x0C]
2422 0x0060 ar_mod [0x0C]
2423 0x006C ar_namelen[0x04]
2424 0x0070 ar_fmag [0x02]
2428 0x0086 offsets [0x14 * counts]
2429 0x0086 + 0x14 * counts names [??]
2430 ?? pad to even bytes.
2433 nextoff = iterator.next.offset;
2434 BFD_ASSERT (nextoff == bfd_tell (abfd));
2436 member_table_size = (SIZEOF_AR_HDR_BIG
2438 + XCOFFARMAGBIG_ELEMENT_SIZE
2439 + count * XCOFFARMAGBIG_ELEMENT_SIZE
2442 member_table_size += member_table_size & 1;
2443 member_table = bfd_zmalloc (member_table_size);
2444 if (member_table == NULL)
2447 hdr = (struct xcoff_ar_hdr_big *) member_table;
2449 PRINT20 (hdr->size, (XCOFFARMAGBIG_ELEMENT_SIZE
2450 + count * XCOFFARMAGBIG_ELEMENT_SIZE
2451 + total_namlen + (total_namlen & 1)));
2452 if (makemap && hasobjects)
2453 PRINT20 (hdr->nextoff, nextoff + member_table_size);
2455 PRINT20 (hdr->nextoff, 0);
2456 PRINT20 (hdr->prevoff, prevoff);
2457 PRINT12 (hdr->date, 0);
2458 PRINT12 (hdr->uid, 0);
2459 PRINT12 (hdr->gid, 0);
2460 PRINT12 (hdr->mode, 0);
2461 PRINT4 (hdr->namlen, 0);
2463 mt = member_table + SIZEOF_AR_HDR_BIG;
2464 memcpy (mt, XCOFFARFMAG, SXCOFFARFMAG);
2467 PRINT20 (mt, count);
2468 mt += XCOFFARMAGBIG_ELEMENT_SIZE;
2469 for (i = 0; i < (size_t) count; i++)
2471 PRINT20 (mt, offsets[i]);
2472 mt += XCOFFARMAGBIG_ELEMENT_SIZE;
2481 for (current_bfd = abfd->archive_head;
2482 current_bfd != NULL;
2483 current_bfd = current_bfd->archive_next)
2488 name = normalize_filename (current_bfd);
2489 namlen = sprintf (mt, "%s", name);
2493 if (bfd_bwrite (member_table, member_table_size, abfd) != member_table_size)
2496 free (member_table);
2498 PRINT20 (fhdr.memoff, nextoff);
2501 nextoff += member_table_size;
2503 /* Write out the armap, if appropriate. */
2505 if (! makemap || ! hasobjects)
2506 PRINT20 (fhdr.symoff, 0);
2509 BFD_ASSERT (nextoff == bfd_tell (abfd));
2511 /* Save nextoff in fhdr.symoff so the armap routine can use it. */
2512 PRINT20 (fhdr.symoff, nextoff);
2514 bfd_ardata (abfd)->tdata = &fhdr;
2515 if (! _bfd_compute_and_write_armap (abfd, 0))
2519 /* Write out the archive file header. */
2521 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
2522 || (bfd_bwrite (&fhdr, (bfd_size_type) SIZEOF_AR_FILE_HDR_BIG,
2523 abfd) != SIZEOF_AR_FILE_HDR_BIG))
2530 _bfd_xcoff_write_archive_contents (bfd *abfd)
2532 if (! xcoff_big_format_p (abfd))
2533 return xcoff_write_archive_contents_old (abfd);
2535 return xcoff_write_archive_contents_big (abfd);
2538 /* We can't use the usual coff_sizeof_headers routine, because AIX
2539 always uses an a.out header. */
2542 _bfd_xcoff_sizeof_headers (bfd *abfd,
2543 struct bfd_link_info *info ATTRIBUTE_UNUSED)
2548 if (xcoff_data (abfd)->full_aouthdr)
2551 size += SMALL_AOUTSZ;
2552 size += abfd->section_count * SCNHSZ;
2556 /* Routines to swap information in the XCOFF .loader section. If we
2557 ever need to write an XCOFF loader, this stuff will need to be
2558 moved to another file shared by the linker (which XCOFF calls the
2559 ``binder'') and the loader. */
2561 /* Swap in the ldhdr structure. */
2564 xcoff_swap_ldhdr_in (bfd *abfd, const void * s, struct internal_ldhdr *dst)
2566 const struct external_ldhdr *src = (const struct external_ldhdr *) s;
2568 dst->l_version = bfd_get_32 (abfd, src->l_version);
2569 dst->l_nsyms = bfd_get_32 (abfd, src->l_nsyms);
2570 dst->l_nreloc = bfd_get_32 (abfd, src->l_nreloc);
2571 dst->l_istlen = bfd_get_32 (abfd, src->l_istlen);
2572 dst->l_nimpid = bfd_get_32 (abfd, src->l_nimpid);
2573 dst->l_impoff = bfd_get_32 (abfd, src->l_impoff);
2574 dst->l_stlen = bfd_get_32 (abfd, src->l_stlen);
2575 dst->l_stoff = bfd_get_32 (abfd, src->l_stoff);
2578 /* Swap out the ldhdr structure. */
2581 xcoff_swap_ldhdr_out (bfd *abfd, const struct internal_ldhdr *src, void * d)
2583 struct external_ldhdr *dst = (struct external_ldhdr *) d;
2585 bfd_put_32 (abfd, (bfd_vma) src->l_version, dst->l_version);
2586 bfd_put_32 (abfd, src->l_nsyms, dst->l_nsyms);
2587 bfd_put_32 (abfd, src->l_nreloc, dst->l_nreloc);
2588 bfd_put_32 (abfd, src->l_istlen, dst->l_istlen);
2589 bfd_put_32 (abfd, src->l_nimpid, dst->l_nimpid);
2590 bfd_put_32 (abfd, src->l_impoff, dst->l_impoff);
2591 bfd_put_32 (abfd, src->l_stlen, dst->l_stlen);
2592 bfd_put_32 (abfd, src->l_stoff, dst->l_stoff);
2595 /* Swap in the ldsym structure. */
2598 xcoff_swap_ldsym_in (bfd *abfd, const void * s, struct internal_ldsym *dst)
2600 const struct external_ldsym *src = (const struct external_ldsym *) s;
2602 if (bfd_get_32 (abfd, src->_l._l_l._l_zeroes) != 0) {
2603 memcpy (dst->_l._l_name, src->_l._l_name, SYMNMLEN);
2605 dst->_l._l_l._l_zeroes = 0;
2606 dst->_l._l_l._l_offset = bfd_get_32 (abfd, src->_l._l_l._l_offset);
2608 dst->l_value = bfd_get_32 (abfd, src->l_value);
2609 dst->l_scnum = bfd_get_16 (abfd, src->l_scnum);
2610 dst->l_smtype = bfd_get_8 (abfd, src->l_smtype);
2611 dst->l_smclas = bfd_get_8 (abfd, src->l_smclas);
2612 dst->l_ifile = bfd_get_32 (abfd, src->l_ifile);
2613 dst->l_parm = bfd_get_32 (abfd, src->l_parm);
2616 /* Swap out the ldsym structure. */
2619 xcoff_swap_ldsym_out (bfd *abfd, const struct internal_ldsym *src, void * d)
2621 struct external_ldsym *dst = (struct external_ldsym *) d;
2623 if (src->_l._l_l._l_zeroes != 0)
2624 memcpy (dst->_l._l_name, src->_l._l_name, SYMNMLEN);
2627 bfd_put_32 (abfd, (bfd_vma) 0, dst->_l._l_l._l_zeroes);
2628 bfd_put_32 (abfd, (bfd_vma) src->_l._l_l._l_offset,
2629 dst->_l._l_l._l_offset);
2631 bfd_put_32 (abfd, src->l_value, dst->l_value);
2632 bfd_put_16 (abfd, (bfd_vma) src->l_scnum, dst->l_scnum);
2633 bfd_put_8 (abfd, src->l_smtype, dst->l_smtype);
2634 bfd_put_8 (abfd, src->l_smclas, dst->l_smclas);
2635 bfd_put_32 (abfd, src->l_ifile, dst->l_ifile);
2636 bfd_put_32 (abfd, src->l_parm, dst->l_parm);
2640 xcoff_swap_reloc_in (bfd *abfd, void * s, void * d)
2642 struct external_reloc *src = (struct external_reloc *) s;
2643 struct internal_reloc *dst = (struct internal_reloc *) d;
2645 memset (dst, 0, sizeof (struct internal_reloc));
2647 dst->r_vaddr = bfd_get_32 (abfd, src->r_vaddr);
2648 dst->r_symndx = bfd_get_32 (abfd, src->r_symndx);
2649 dst->r_size = bfd_get_8 (abfd, src->r_size);
2650 dst->r_type = bfd_get_8 (abfd, src->r_type);
2654 xcoff_swap_reloc_out (bfd *abfd, void * s, void * d)
2656 struct internal_reloc *src = (struct internal_reloc *) s;
2657 struct external_reloc *dst = (struct external_reloc *) d;
2659 bfd_put_32 (abfd, src->r_vaddr, dst->r_vaddr);
2660 bfd_put_32 (abfd, src->r_symndx, dst->r_symndx);
2661 bfd_put_8 (abfd, src->r_type, dst->r_type);
2662 bfd_put_8 (abfd, src->r_size, dst->r_size);
2664 return bfd_coff_relsz (abfd);
2667 /* Swap in the ldrel structure. */
2670 xcoff_swap_ldrel_in (bfd *abfd, const void * s, struct internal_ldrel *dst)
2672 const struct external_ldrel *src = (const struct external_ldrel *) s;
2674 dst->l_vaddr = bfd_get_32 (abfd, src->l_vaddr);
2675 dst->l_symndx = bfd_get_32 (abfd, src->l_symndx);
2676 dst->l_rtype = bfd_get_16 (abfd, src->l_rtype);
2677 dst->l_rsecnm = bfd_get_16 (abfd, src->l_rsecnm);
2680 /* Swap out the ldrel structure. */
2683 xcoff_swap_ldrel_out (bfd *abfd, const struct internal_ldrel *src, void * d)
2685 struct external_ldrel *dst = (struct external_ldrel *) d;
2687 bfd_put_32 (abfd, src->l_vaddr, dst->l_vaddr);
2688 bfd_put_32 (abfd, src->l_symndx, dst->l_symndx);
2689 bfd_put_16 (abfd, (bfd_vma) src->l_rtype, dst->l_rtype);
2690 bfd_put_16 (abfd, (bfd_vma) src->l_rsecnm, dst->l_rsecnm);
2695 xcoff_reloc_type_noop (bfd *input_bfd ATTRIBUTE_UNUSED,
2696 asection *input_section ATTRIBUTE_UNUSED,
2697 bfd *output_bfd ATTRIBUTE_UNUSED,
2698 struct internal_reloc *rel ATTRIBUTE_UNUSED,
2699 struct internal_syment *sym ATTRIBUTE_UNUSED,
2700 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED,
2701 bfd_vma val ATTRIBUTE_UNUSED,
2702 bfd_vma addend ATTRIBUTE_UNUSED,
2703 bfd_vma *relocation ATTRIBUTE_UNUSED,
2704 bfd_byte *contents ATTRIBUTE_UNUSED)
2710 xcoff_reloc_type_fail (bfd *input_bfd,
2711 asection *input_section ATTRIBUTE_UNUSED,
2712 bfd *output_bfd ATTRIBUTE_UNUSED,
2713 struct internal_reloc *rel,
2714 struct internal_syment *sym ATTRIBUTE_UNUSED,
2715 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED,
2716 bfd_vma val ATTRIBUTE_UNUSED,
2717 bfd_vma addend ATTRIBUTE_UNUSED,
2718 bfd_vma *relocation ATTRIBUTE_UNUSED,
2719 bfd_byte *contents ATTRIBUTE_UNUSED)
2721 (*_bfd_error_handler)
2722 (_("%s: unsupported relocation type 0x%02x"),
2723 bfd_get_filename (input_bfd), (unsigned int) rel->r_type);
2724 bfd_set_error (bfd_error_bad_value);
2729 xcoff_reloc_type_pos (bfd *input_bfd ATTRIBUTE_UNUSED,
2730 asection *input_section ATTRIBUTE_UNUSED,
2731 bfd *output_bfd ATTRIBUTE_UNUSED,
2732 struct internal_reloc *rel ATTRIBUTE_UNUSED,
2733 struct internal_syment *sym ATTRIBUTE_UNUSED,
2734 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED,
2737 bfd_vma *relocation,
2738 bfd_byte *contents ATTRIBUTE_UNUSED)
2740 *relocation = val + addend;
2745 xcoff_reloc_type_neg (bfd *input_bfd ATTRIBUTE_UNUSED,
2746 asection *input_section ATTRIBUTE_UNUSED,
2747 bfd *output_bfd ATTRIBUTE_UNUSED,
2748 struct internal_reloc *rel ATTRIBUTE_UNUSED,
2749 struct internal_syment *sym ATTRIBUTE_UNUSED,
2750 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED,
2753 bfd_vma *relocation,
2754 bfd_byte *contents ATTRIBUTE_UNUSED)
2756 *relocation = addend - val;
2761 xcoff_reloc_type_rel (bfd *input_bfd ATTRIBUTE_UNUSED,
2762 asection *input_section,
2763 bfd *output_bfd ATTRIBUTE_UNUSED,
2764 struct internal_reloc *rel ATTRIBUTE_UNUSED,
2765 struct internal_syment *sym ATTRIBUTE_UNUSED,
2766 struct reloc_howto_struct *howto,
2769 bfd_vma *relocation,
2770 bfd_byte *contents ATTRIBUTE_UNUSED)
2772 howto->pc_relative = TRUE;
2774 /* A PC relative reloc includes the section address. */
2775 addend += input_section->vma;
2777 *relocation = val + addend;
2778 *relocation -= (input_section->output_section->vma
2779 + input_section->output_offset);
2784 xcoff_reloc_type_toc (bfd *input_bfd,
2785 asection *input_section ATTRIBUTE_UNUSED,
2787 struct internal_reloc *rel,
2788 struct internal_syment *sym,
2789 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED,
2791 bfd_vma addend ATTRIBUTE_UNUSED,
2792 bfd_vma *relocation,
2793 bfd_byte *contents ATTRIBUTE_UNUSED)
2795 struct xcoff_link_hash_entry *h;
2797 if (0 > rel->r_symndx)
2800 h = obj_xcoff_sym_hashes (input_bfd)[rel->r_symndx];
2802 if (h != NULL && h->smclas != XMC_TD)
2804 if (h->toc_section == NULL)
2806 (*_bfd_error_handler)
2807 (_("%s: TOC reloc at 0x%x to symbol `%s' with no TOC entry"),
2808 bfd_get_filename (input_bfd), rel->r_vaddr,
2809 h->root.root.string);
2810 bfd_set_error (bfd_error_bad_value);
2814 BFD_ASSERT ((h->flags & XCOFF_SET_TOC) == 0);
2815 val = (h->toc_section->output_section->vma
2816 + h->toc_section->output_offset);
2819 *relocation = ((val - xcoff_data (output_bfd)->toc)
2820 - (sym->n_value - xcoff_data (input_bfd)->toc));
2825 xcoff_reloc_type_ba (bfd *input_bfd ATTRIBUTE_UNUSED,
2826 asection *input_section ATTRIBUTE_UNUSED,
2827 bfd *output_bfd ATTRIBUTE_UNUSED,
2828 struct internal_reloc *rel ATTRIBUTE_UNUSED,
2829 struct internal_syment *sym ATTRIBUTE_UNUSED,
2830 struct reloc_howto_struct *howto,
2833 bfd_vma *relocation,
2834 bfd_byte *contents ATTRIBUTE_UNUSED)
2836 howto->src_mask &= ~3;
2837 howto->dst_mask = howto->src_mask;
2839 *relocation = val + addend;
2845 xcoff_reloc_type_br (bfd *input_bfd,
2846 asection *input_section,
2847 bfd *output_bfd ATTRIBUTE_UNUSED,
2848 struct internal_reloc *rel,
2849 struct internal_syment *sym ATTRIBUTE_UNUSED,
2850 struct reloc_howto_struct *howto,
2853 bfd_vma *relocation,
2856 struct xcoff_link_hash_entry *h;
2857 bfd_vma section_offset;
2859 if (0 > rel->r_symndx)
2862 h = obj_xcoff_sym_hashes (input_bfd)[rel->r_symndx];
2863 section_offset = rel->r_vaddr - input_section->vma;
2865 /* If we see an R_BR or R_RBR reloc which is jumping to global
2866 linkage code, and it is followed by an appropriate cror nop
2867 instruction, we replace the cror with lwz r2,20(r1). This
2868 restores the TOC after the glink code. Contrariwise, if the
2869 call is followed by a lwz r2,20(r1), but the call is not
2870 going to global linkage code, we can replace the load with a
2873 && (bfd_link_hash_defined == h->root.type
2874 || bfd_link_hash_defweak == h->root.type)
2875 && section_offset + 8 <= input_section->size)
2880 pnext = contents + section_offset + 4;
2881 next = bfd_get_32 (input_bfd, pnext);
2883 /* The _ptrgl function is magic. It is used by the AIX
2884 compiler to call a function through a pointer. */
2885 if (h->smclas == XMC_GL || strcmp (h->root.root.string, "._ptrgl") == 0)
2887 if (next == 0x4def7b82 /* cror 15,15,15 */
2888 || next == 0x4ffffb82 /* cror 31,31,31 */
2889 || next == 0x60000000) /* ori r0,r0,0 */
2890 bfd_put_32 (input_bfd, 0x80410014, pnext); /* lwz r2,20(r1) */
2895 if (next == 0x80410014) /* lwz r2,20(r1) */
2896 bfd_put_32 (input_bfd, 0x60000000, pnext); /* ori r0,r0,0 */
2899 else if (NULL != h && bfd_link_hash_undefined == h->root.type)
2901 /* Normally, this relocation is against a defined symbol. In the
2902 case where this is a partial link and the output section offset
2903 is greater than 2^25, the linker will return an invalid error
2904 message that the relocation has been truncated. Yes it has been
2905 truncated but no it not important. For this case, disable the
2906 overflow checking. */
2908 howto->complain_on_overflow = complain_overflow_dont;
2911 /* The original PC-relative relocation is biased by -r_vaddr, so adding
2912 the value below will give the absolute target address. */
2913 *relocation = val + addend + rel->r_vaddr;
2915 howto->src_mask &= ~3;
2916 howto->dst_mask = howto->src_mask;
2919 && (h->root.type == bfd_link_hash_defined
2920 || h->root.type == bfd_link_hash_defweak)
2921 && bfd_is_abs_section (h->root.u.def.section)
2922 && section_offset + 4 <= input_section->size)
2927 /* Turn the relative branch into an absolute one by setting the
2929 ptr = contents + section_offset;
2930 insn = bfd_get_32 (input_bfd, ptr);
2932 bfd_put_32 (input_bfd, insn, ptr);
2934 /* Make the howto absolute too. */
2935 howto->pc_relative = FALSE;
2936 howto->complain_on_overflow = complain_overflow_bitfield;
2940 /* Use a PC-relative howto and subtract the instruction's address
2941 from the target address we calculated above. */
2942 howto->pc_relative = TRUE;
2943 *relocation -= (input_section->output_section->vma
2944 + input_section->output_offset
2951 xcoff_reloc_type_crel (bfd *input_bfd ATTRIBUTE_UNUSED,
2952 asection *input_section,
2953 bfd *output_bfd ATTRIBUTE_UNUSED,
2954 struct internal_reloc *rel ATTRIBUTE_UNUSED,
2955 struct internal_syment *sym ATTRIBUTE_UNUSED,
2956 struct reloc_howto_struct *howto,
2957 bfd_vma val ATTRIBUTE_UNUSED,
2959 bfd_vma *relocation,
2960 bfd_byte *contents ATTRIBUTE_UNUSED)
2962 howto->pc_relative = TRUE;
2963 howto->src_mask &= ~3;
2964 howto->dst_mask = howto->src_mask;
2966 /* A PC relative reloc includes the section address. */
2967 addend += input_section->vma;
2969 *relocation = val + addend;
2970 *relocation -= (input_section->output_section->vma
2971 + input_section->output_offset);
2976 xcoff_complain_overflow_dont_func (bfd *input_bfd ATTRIBUTE_UNUSED,
2977 bfd_vma val ATTRIBUTE_UNUSED,
2978 bfd_vma relocation ATTRIBUTE_UNUSED,
2979 struct reloc_howto_struct *
2980 howto ATTRIBUTE_UNUSED)
2986 xcoff_complain_overflow_bitfield_func (bfd *input_bfd,
2989 struct reloc_howto_struct *howto)
2991 bfd_vma fieldmask, signmask, ss;
2994 /* Get the values to be added together. For signed and unsigned
2995 relocations, we assume that all values should be truncated to
2996 the size of an address. For bitfields, all the bits matter.
2997 See also bfd_check_overflow. */
2998 fieldmask = N_ONES (howto->bitsize);
3000 b = val & howto->src_mask;
3002 /* Much like unsigned, except no trimming with addrmask. In
3003 addition, the sum overflows if there is a carry out of
3004 the bfd_vma, i.e., the sum is less than either input
3006 a >>= howto->rightshift;
3007 b >>= howto->bitpos;
3009 /* Bitfields are sometimes used for signed numbers; for
3010 example, a 13-bit field sometimes represents values in
3011 0..8191 and sometimes represents values in -4096..4095.
3012 If the field is signed and a is -4095 (0x1001) and b is
3013 -1 (0x1fff), the sum is -4096 (0x1000), but (0x1001 +
3014 0x1fff is 0x3000). It's not clear how to handle this
3015 everywhere, since there is not way to know how many bits
3016 are significant in the relocation, but the original code
3017 assumed that it was fully sign extended, and we will keep
3019 signmask = (fieldmask >> 1) + 1;
3021 if ((a & ~ fieldmask) != 0)
3023 /* Some bits out of the field are set. This might not
3024 be a problem: if this is a signed bitfield, it is OK
3025 iff all the high bits are set, including the sign
3026 bit. We'll try setting all but the most significant
3027 bit in the original relocation value: if this is all
3028 ones, we are OK, assuming a signed bitfield. */
3029 ss = (signmask << howto->rightshift) - 1;
3030 if ((ss | relocation) != ~ (bfd_vma) 0)
3035 /* We just assume (b & ~ fieldmask) == 0. */
3037 /* We explicitly permit wrap around if this relocation
3038 covers the high bit of an address. The Linux kernel
3039 relies on it, and it is the only way to write assembler
3040 code which can run when loaded at a location 0x80000000
3041 away from the location at which it is linked. */
3042 if (howto->bitsize + howto->rightshift
3043 == bfd_arch_bits_per_address (input_bfd))
3047 if (sum < a || (sum & ~ fieldmask) != 0)
3049 /* There was a carry out, or the field overflow. Test
3050 for signed operands again. Here is the overflow test
3051 is as for complain_overflow_signed. */
3052 if (((~ (a ^ b)) & (a ^ sum)) & signmask)
3060 xcoff_complain_overflow_signed_func (bfd *input_bfd,
3063 struct reloc_howto_struct *howto)
3065 bfd_vma addrmask, fieldmask, signmask, ss;
3068 /* Get the values to be added together. For signed and unsigned
3069 relocations, we assume that all values should be truncated to
3070 the size of an address. For bitfields, all the bits matter.
3071 See also bfd_check_overflow. */
3072 fieldmask = N_ONES (howto->bitsize);
3073 addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask;
3075 b = val & howto->src_mask;
3077 a = (a & addrmask) >> howto->rightshift;
3079 /* If any sign bits are set, all sign bits must be set.
3080 That is, A must be a valid negative address after
3082 signmask = ~ (fieldmask >> 1);
3084 if (ss != 0 && ss != ((addrmask >> howto->rightshift) & signmask))
3087 /* We only need this next bit of code if the sign bit of B
3088 is below the sign bit of A. This would only happen if
3089 SRC_MASK had fewer bits than BITSIZE. Note that if
3090 SRC_MASK has more bits than BITSIZE, we can get into
3091 trouble; we would need to verify that B is in range, as
3092 we do for A above. */
3093 signmask = ((~ howto->src_mask) >> 1) & howto->src_mask;
3094 if ((b & signmask) != 0)
3096 /* Set all the bits above the sign bit. */
3097 b -= signmask <<= 1;
3100 b = (b & addrmask) >> howto->bitpos;
3102 /* Now we can do the addition. */
3105 /* See if the result has the correct sign. Bits above the
3106 sign bit are junk now; ignore them. If the sum is
3107 positive, make sure we did not have all negative inputs;
3108 if the sum is negative, make sure we did not have all
3109 positive inputs. The test below looks only at the sign
3110 bits, and it really just
3111 SIGN (A) == SIGN (B) && SIGN (A) != SIGN (SUM)
3113 signmask = (fieldmask >> 1) + 1;
3114 if (((~ (a ^ b)) & (a ^ sum)) & signmask)
3121 xcoff_complain_overflow_unsigned_func (bfd *input_bfd,
3124 struct reloc_howto_struct *howto)
3126 bfd_vma addrmask, fieldmask;
3129 /* Get the values to be added together. For signed and unsigned
3130 relocations, we assume that all values should be truncated to
3131 the size of an address. For bitfields, all the bits matter.
3132 See also bfd_check_overflow. */
3133 fieldmask = N_ONES (howto->bitsize);
3134 addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask;
3136 b = val & howto->src_mask;
3138 /* Checking for an unsigned overflow is relatively easy:
3139 trim the addresses and add, and trim the result as well.
3140 Overflow is normally indicated when the result does not
3141 fit in the field. However, we also need to consider the
3142 case when, e.g., fieldmask is 0x7fffffff or smaller, an
3143 input is 0x80000000, and bfd_vma is only 32 bits; then we
3144 will get sum == 0, but there is an overflow, since the
3145 inputs did not fit in the field. Instead of doing a
3146 separate test, we can check for this by or-ing in the
3147 operands when testing for the sum overflowing its final
3149 a = (a & addrmask) >> howto->rightshift;
3150 b = (b & addrmask) >> howto->bitpos;
3151 sum = (a + b) & addrmask;
3152 if ((a | b | sum) & ~ fieldmask)
3158 /* This is the relocation function for the RS/6000/POWER/PowerPC.
3159 This is currently the only processor which uses XCOFF; I hope that
3162 I took the relocation type definitions from two documents:
3163 the PowerPC AIX Version 4 Application Binary Interface, First
3164 Edition (April 1992), and the PowerOpen ABI, Big-Endian
3165 32-Bit Hardware Implementation (June 30, 1994). Differences
3166 between the documents are noted below.
3168 Unsupported r_type's
3174 These relocs are defined by the PowerPC ABI to be
3175 relative branches which use half of the difference
3176 between the symbol and the program counter. I can't
3177 quite figure out when this is useful. These relocs are
3178 not defined by the PowerOpen ABI.
3183 Simple positive relocation.
3186 Simple negative relocation.
3189 Simple PC relative relocation.
3192 TOC relative relocation. The value in the instruction in
3193 the input file is the offset from the input file TOC to
3194 the desired location. We want the offset from the final
3195 TOC to the desired location. We have:
3200 so we must change insn by on - in.
3203 GL linkage relocation. The value of this relocation
3204 is the address of the entry in the TOC section.
3207 Local object TOC address. I can't figure out the
3208 difference between this and case R_GL.
3211 TOC relative relocation. A TOC relative load instruction
3212 which may be changed to a load address instruction.
3213 FIXME: We don't currently implement this optimization.
3216 TOC relative relocation. This is a TOC relative load
3217 address instruction which may be changed to a load
3218 instruction. FIXME: I don't know if this is the correct
3222 Absolute branch. We don't want to mess with the lower
3223 two bits of the instruction.
3226 The PowerPC ABI defines this as an absolute call which
3227 may be modified to become a relative call. The PowerOpen
3228 ABI does not define this relocation type.
3231 Absolute branch which may be modified to become a
3235 The PowerPC ABI defines this as an absolute branch to a
3236 fixed address which may be modified to an absolute branch
3237 to a symbol. The PowerOpen ABI does not define this
3241 The PowerPC ABI defines this as an absolute branch to a
3242 fixed address which may be modified to a relative branch.
3243 The PowerOpen ABI does not define this relocation type.
3246 Relative branch. We don't want to mess with the lower
3247 two bits of the instruction.
3250 The PowerPC ABI defines this as a relative call which may
3251 be modified to become an absolute call. The PowerOpen
3252 ABI does not define this relocation type.
3255 A relative branch which may be modified to become an
3259 The PowerPC AIX ABI describes this as a load which may be
3260 changed to a load address. The PowerOpen ABI says this
3261 is the same as case R_POS.
3264 The PowerPC AIX ABI describes this as a load address
3265 which may be changed to a load. The PowerOpen ABI says
3266 this is the same as R_POS.
3270 xcoff_ppc_relocate_section (bfd *output_bfd,
3271 struct bfd_link_info *info,
3273 asection *input_section,
3275 struct internal_reloc *relocs,
3276 struct internal_syment *syms,
3277 asection **sections)
3279 struct internal_reloc *rel;
3280 struct internal_reloc *relend;
3283 relend = rel + input_section->reloc_count;
3284 for (; rel < relend; rel++)
3287 struct xcoff_link_hash_entry *h;
3288 struct internal_syment *sym;
3291 struct reloc_howto_struct howto;
3293 bfd_vma value_to_relocate;
3297 /* Relocation type R_REF is a special relocation type which is
3298 merely used to prevent garbage collection from occurring for
3299 the csect including the symbol which it references. */
3300 if (rel->r_type == R_REF)
3304 howto.type = rel->r_type;
3305 howto.rightshift = 0;
3306 howto.bitsize = (rel->r_size & 0x1f) + 1;
3307 howto.size = howto.bitsize > 16 ? 2 : 1;
3308 howto.pc_relative = FALSE;
3310 howto.complain_on_overflow = (rel->r_size & 0x80
3311 ? complain_overflow_signed
3312 : complain_overflow_bitfield);
3313 howto.special_function = NULL;
3314 howto.name = "internal";
3315 howto.partial_inplace = TRUE;
3316 howto.src_mask = howto.dst_mask = N_ONES (howto.bitsize);
3317 howto.pcrel_offset = FALSE;
3324 symndx = rel->r_symndx;
3330 h = obj_xcoff_sym_hashes (input_bfd)[symndx];
3331 sym = syms + symndx;
3332 addend = - sym->n_value;
3336 sec = sections[symndx];
3337 /* Hack to make sure we use the right TOC anchor value
3338 if this reloc is against the TOC anchor. */
3339 if (sec->name[3] == '0'
3340 && strcmp (sec->name, ".tc0") == 0)
3341 val = xcoff_data (output_bfd)->toc;
3343 val = (sec->output_section->vma
3344 + sec->output_offset
3350 if (info->unresolved_syms_in_objects != RM_IGNORE
3351 && (h->flags & XCOFF_WAS_UNDEFINED) != 0)
3353 if (! ((*info->callbacks->undefined_symbol)
3354 (info, h->root.root.string,
3355 input_bfd, input_section,
3356 rel->r_vaddr - input_section->vma,
3357 (info->unresolved_syms_in_objects
3358 == RM_GENERATE_ERROR))))
3361 if (h->root.type == bfd_link_hash_defined
3362 || h->root.type == bfd_link_hash_defweak)
3364 sec = h->root.u.def.section;
3365 val = (h->root.u.def.value
3366 + sec->output_section->vma
3367 + sec->output_offset);
3369 else if (h->root.type == bfd_link_hash_common)
3371 sec = h->root.u.c.p->section;
3372 val = (sec->output_section->vma
3373 + sec->output_offset);
3378 BFD_ASSERT (info->relocatable
3379 || (info->static_link
3380 && (h->flags & XCOFF_WAS_UNDEFINED) != 0)
3381 || (h->flags & XCOFF_DEF_DYNAMIC) != 0
3382 || (h->flags & XCOFF_IMPORT) != 0);
3387 if (rel->r_type >= XCOFF_MAX_CALCULATE_RELOCATION
3388 || !((*xcoff_calculate_relocation[rel->r_type])
3389 (input_bfd, input_section, output_bfd, rel, sym, &howto, val,
3390 addend, &relocation, contents)))
3394 address = rel->r_vaddr - input_section->vma;
3395 location = contents + address;
3397 if (address > input_section->size)
3400 /* Get the value we are going to relocate. */
3401 if (1 == howto.size)
3402 value_to_relocate = bfd_get_16 (input_bfd, location);
3404 value_to_relocate = bfd_get_32 (input_bfd, location);
3408 FIXME: We may drop bits during the addition
3409 which we don't check for. We must either check at every single
3410 operation, which would be tedious, or we must do the computations
3411 in a type larger than bfd_vma, which would be inefficient. */
3413 if ((unsigned int) howto.complain_on_overflow
3414 >= XCOFF_MAX_COMPLAIN_OVERFLOW)
3417 if (((*xcoff_complain_overflow[howto.complain_on_overflow])
3418 (input_bfd, value_to_relocate, relocation, &howto)))
3421 char buf[SYMNMLEN + 1];
3422 char reloc_type_name[10];
3434 name = _bfd_coff_internal_syment_name (input_bfd, sym, buf);
3438 sprintf (reloc_type_name, "0x%02x", rel->r_type);
3440 if (! ((*info->callbacks->reloc_overflow)
3441 (info, (h ? &h->root : NULL), name, reloc_type_name,
3442 (bfd_vma) 0, input_bfd, input_section,
3443 rel->r_vaddr - input_section->vma)))
3447 /* Add RELOCATION to the right bits of VALUE_TO_RELOCATE. */
3448 value_to_relocate = ((value_to_relocate & ~howto.dst_mask)
3449 | (((value_to_relocate & howto.src_mask)
3450 + relocation) & howto.dst_mask));
3452 /* Put the value back in the object file. */
3453 if (1 == howto.size)
3454 bfd_put_16 (input_bfd, value_to_relocate, location);
3456 bfd_put_32 (input_bfd, value_to_relocate, location);
3463 _bfd_xcoff_put_ldsymbol_name (bfd *abfd ATTRIBUTE_UNUSED,
3464 struct xcoff_loader_info *ldinfo,
3465 struct internal_ldsym *ldsym,
3469 len = strlen (name);
3471 if (len <= SYMNMLEN)
3472 strncpy (ldsym->_l._l_name, name, SYMNMLEN);
3475 if (ldinfo->string_size + len + 3 > ldinfo->string_alc)
3477 bfd_size_type newalc;
3480 newalc = ldinfo->string_alc * 2;
3483 while (ldinfo->string_size + len + 3 > newalc)
3486 newstrings = bfd_realloc (ldinfo->strings, newalc);
3487 if (newstrings == NULL)
3489 ldinfo->failed = TRUE;
3492 ldinfo->string_alc = newalc;
3493 ldinfo->strings = newstrings;
3496 bfd_put_16 (ldinfo->output_bfd, (bfd_vma) (len + 1),
3497 ldinfo->strings + ldinfo->string_size);
3498 strcpy (ldinfo->strings + ldinfo->string_size + 2, name);
3499 ldsym->_l._l_l._l_zeroes = 0;
3500 ldsym->_l._l_l._l_offset = ldinfo->string_size + 2;
3501 ldinfo->string_size += len + 3;
3508 _bfd_xcoff_put_symbol_name (bfd *abfd, struct bfd_strtab_hash *strtab,
3509 struct internal_syment *sym,
3512 if (strlen (name) <= SYMNMLEN)
3514 strncpy (sym->_n._n_name, name, SYMNMLEN);
3522 if ((abfd->flags & BFD_TRADITIONAL_FORMAT) != 0)
3524 indx = _bfd_stringtab_add (strtab, name, hash, FALSE);
3525 if (indx == (bfd_size_type) -1)
3527 sym->_n._n_n._n_zeroes = 0;
3528 sym->_n._n_n._n_offset = STRING_SIZE_SIZE + indx;
3534 xcoff_create_csect_from_smclas (bfd *abfd,
3535 union internal_auxent *aux,
3536 const char *symbol_name)
3538 asection *return_value = NULL;
3540 /* .sv64 = x_smclas == 17
3541 This is an invalid csect for 32 bit apps. */
3542 static const char *names[19] =
3544 ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo",
3545 ".sv", ".bs", ".ds", ".uc", ".ti", ".tb", NULL, ".tc0",
3546 ".td", NULL, ".sv3264"
3549 if ((19 >= aux->x_csect.x_smclas)
3550 && (NULL != names[aux->x_csect.x_smclas]))
3552 return_value = bfd_make_section_anyway
3553 (abfd, names[aux->x_csect.x_smclas]);
3557 (*_bfd_error_handler)
3558 (_("%B: symbol `%s' has unrecognized smclas %d"),
3559 abfd, symbol_name, aux->x_csect.x_smclas);
3560 bfd_set_error (bfd_error_bad_value);
3563 return return_value;
3567 xcoff_is_lineno_count_overflow (bfd *abfd ATTRIBUTE_UNUSED, bfd_vma value)
3569 if (0xffff <= value)
3576 xcoff_is_reloc_count_overflow (bfd *abfd ATTRIBUTE_UNUSED, bfd_vma value)
3578 if (0xffff <= value)
3585 xcoff_loader_symbol_offset (bfd *abfd,
3586 struct internal_ldhdr *ldhdr ATTRIBUTE_UNUSED)
3588 return bfd_xcoff_ldhdrsz (abfd);
3592 xcoff_loader_reloc_offset (bfd *abfd, struct internal_ldhdr *ldhdr)
3594 return bfd_xcoff_ldhdrsz (abfd) + ldhdr->l_nsyms * bfd_xcoff_ldsymsz (abfd);
3598 xcoff_generate_rtinit (bfd *abfd, const char *init, const char *fini,
3601 bfd_byte filehdr_ext[FILHSZ];
3602 bfd_byte scnhdr_ext[SCNHSZ];
3603 bfd_byte syment_ext[SYMESZ * 10];
3604 bfd_byte reloc_ext[RELSZ * 3];
3605 bfd_byte *data_buffer;
3606 bfd_size_type data_buffer_size;
3607 bfd_byte *string_table = NULL, *st_tmp = NULL;
3608 bfd_size_type string_table_size;
3610 size_t initsz, finisz;
3611 struct internal_filehdr filehdr;
3612 struct internal_scnhdr scnhdr;
3613 struct internal_syment syment;
3614 union internal_auxent auxent;
3615 struct internal_reloc reloc;
3617 char *data_name = ".data";
3618 char *rtinit_name = "__rtinit";
3619 char *rtld_name = "__rtld";
3621 if (! bfd_xcoff_rtinit_size (abfd))
3624 initsz = (init == NULL ? 0 : 1 + strlen (init));
3625 finisz = (fini == NULL ? 0 : 1 + strlen (fini));
3628 memset (filehdr_ext, 0, FILHSZ);
3629 memset (&filehdr, 0, sizeof (struct internal_filehdr));
3630 filehdr.f_magic = bfd_xcoff_magic_number (abfd);
3631 filehdr.f_nscns = 1;
3632 filehdr.f_timdat = 0;
3633 filehdr.f_nsyms = 0; /* at least 6, no more than 10 */
3634 filehdr.f_symptr = 0; /* set below */
3635 filehdr.f_opthdr = 0;
3636 filehdr.f_flags = 0;
3638 /* section header */
3639 memset (scnhdr_ext, 0, SCNHSZ);
3640 memset (&scnhdr, 0, sizeof (struct internal_scnhdr));
3641 memcpy (scnhdr.s_name, data_name, strlen (data_name));
3644 scnhdr.s_size = 0; /* set below */
3645 scnhdr.s_scnptr = FILHSZ + SCNHSZ;
3646 scnhdr.s_relptr = 0; /* set below */
3647 scnhdr.s_lnnoptr = 0;
3648 scnhdr.s_nreloc = 0; /* either 1 or 2 */
3650 scnhdr.s_flags = STYP_DATA;
3653 0x0000 0x00000000 : rtl
3654 0x0004 0x00000010 : offset to init, or 0
3655 0x0008 0x00000028 : offset to fini, or 0
3656 0x000C 0x0000000C : size of descriptor
3657 0x0010 0x00000000 : init, needs a reloc
3658 0x0014 0x00000040 : offset to init name
3659 0x0018 0x00000000 : flags, padded to a word
3660 0x001C 0x00000000 : empty init
3663 0x0028 0x00000000 : fini, needs a reloc
3664 0x002C 0x00000??? : offset to fini name
3665 0x0030 0x00000000 : flags, padded to a word
3666 0x0034 0x00000000 : empty fini
3670 0x0040 + initsz fini name */
3672 data_buffer_size = 0x0040 + initsz + finisz;
3673 data_buffer_size = (data_buffer_size + 7) &~ (bfd_size_type) 7;
3675 data_buffer = (bfd_byte *) bfd_zmalloc (data_buffer_size);
3676 if (data_buffer == NULL)
3682 bfd_h_put_32 (abfd, val, &data_buffer[0x04]);
3684 bfd_h_put_32 (abfd, val, &data_buffer[0x14]);
3685 memcpy (&data_buffer[val], init, initsz);
3691 bfd_h_put_32 (abfd, val, &data_buffer[0x08]);
3692 val = 0x40 + initsz;
3693 bfd_h_put_32 (abfd, val, &data_buffer[0x2C]);
3694 memcpy (&data_buffer[val], fini, finisz);
3698 bfd_h_put_32 (abfd, val, &data_buffer[0x0C]);
3700 scnhdr.s_size = data_buffer_size;
3703 string_table_size = 0;
3705 string_table_size += initsz;
3707 string_table_size += finisz;
3708 if (string_table_size)
3710 string_table_size += 4;
3711 string_table = (bfd_byte *) bfd_zmalloc (string_table_size);
3712 if (string_table == NULL)
3715 val = string_table_size;
3716 bfd_h_put_32 (abfd, val, &string_table[0]);
3717 st_tmp = string_table + 4;
3726 memset (syment_ext, 0, 10 * SYMESZ);
3727 memset (reloc_ext, 0, 3 * RELSZ);
3730 memset (&syment, 0, sizeof (struct internal_syment));
3731 memset (&auxent, 0, sizeof (union internal_auxent));
3732 memcpy (syment._n._n_name, data_name, strlen (data_name));
3734 syment.n_sclass = C_HIDEXT;
3735 syment.n_numaux = 1;
3736 auxent.x_csect.x_scnlen.l = data_buffer_size;
3737 auxent.x_csect.x_smtyp = 3 << 3 | XTY_SD;
3738 auxent.x_csect.x_smclas = XMC_RW;
3739 bfd_coff_swap_sym_out (abfd, &syment,
3740 &syment_ext[filehdr.f_nsyms * SYMESZ]);
3741 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
3743 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
3744 filehdr.f_nsyms += 2;
3747 memset (&syment, 0, sizeof (struct internal_syment));
3748 memset (&auxent, 0, sizeof (union internal_auxent));
3749 memcpy (syment._n._n_name, rtinit_name, strlen (rtinit_name));
3751 syment.n_sclass = C_EXT;
3752 syment.n_numaux = 1;
3753 auxent.x_csect.x_smtyp = XTY_LD;
3754 auxent.x_csect.x_smclas = XMC_RW;
3755 bfd_coff_swap_sym_out (abfd, &syment,
3756 &syment_ext[filehdr.f_nsyms * SYMESZ]);
3757 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
3759 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
3760 filehdr.f_nsyms += 2;
3765 memset (&syment, 0, sizeof (struct internal_syment));
3766 memset (&auxent, 0, sizeof (union internal_auxent));
3770 syment._n._n_n._n_offset = st_tmp - string_table;
3771 memcpy (st_tmp, init, initsz);
3775 memcpy (syment._n._n_name, init, initsz - 1);
3777 syment.n_sclass = C_EXT;
3778 syment.n_numaux = 1;
3779 bfd_coff_swap_sym_out (abfd, &syment,
3780 &syment_ext[filehdr.f_nsyms * SYMESZ]);
3781 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
3783 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
3786 memset (&reloc, 0, sizeof (struct internal_reloc));
3787 reloc.r_vaddr = 0x0010;
3788 reloc.r_symndx = filehdr.f_nsyms;
3789 reloc.r_type = R_POS;
3791 bfd_coff_swap_reloc_out (abfd, &reloc, &reloc_ext[0]);
3793 filehdr.f_nsyms += 2;
3794 scnhdr.s_nreloc += 1;
3800 memset (&syment, 0, sizeof (struct internal_syment));
3801 memset (&auxent, 0, sizeof (union internal_auxent));
3805 syment._n._n_n._n_offset = st_tmp - string_table;
3806 memcpy (st_tmp, fini, finisz);
3810 memcpy (syment._n._n_name, fini, finisz - 1);
3812 syment.n_sclass = C_EXT;
3813 syment.n_numaux = 1;
3814 bfd_coff_swap_sym_out (abfd, &syment,
3815 &syment_ext[filehdr.f_nsyms * SYMESZ]);
3816 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
3818 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
3821 memset (&reloc, 0, sizeof (struct internal_reloc));
3822 reloc.r_vaddr = 0x0028;
3823 reloc.r_symndx = filehdr.f_nsyms;
3824 reloc.r_type = R_POS;
3826 bfd_coff_swap_reloc_out (abfd, &reloc,
3827 &reloc_ext[scnhdr.s_nreloc * RELSZ]);
3829 filehdr.f_nsyms += 2;
3830 scnhdr.s_nreloc += 1;
3835 memset (&syment, 0, sizeof (struct internal_syment));
3836 memset (&auxent, 0, sizeof (union internal_auxent));
3837 memcpy (syment._n._n_name, rtld_name, strlen (rtld_name));
3838 syment.n_sclass = C_EXT;
3839 syment.n_numaux = 1;
3840 bfd_coff_swap_sym_out (abfd, &syment,
3841 &syment_ext[filehdr.f_nsyms * SYMESZ]);
3842 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
3844 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
3847 memset (&reloc, 0, sizeof (struct internal_reloc));
3848 reloc.r_vaddr = 0x0000;
3849 reloc.r_symndx = filehdr.f_nsyms;
3850 reloc.r_type = R_POS;
3852 bfd_coff_swap_reloc_out (abfd, &reloc,
3853 &reloc_ext[scnhdr.s_nreloc * RELSZ]);
3855 filehdr.f_nsyms += 2;
3856 scnhdr.s_nreloc += 1;
3859 scnhdr.s_relptr = scnhdr.s_scnptr + data_buffer_size;
3860 filehdr.f_symptr = scnhdr.s_relptr + scnhdr.s_nreloc * RELSZ;
3862 bfd_coff_swap_filehdr_out (abfd, &filehdr, filehdr_ext);
3863 bfd_bwrite (filehdr_ext, FILHSZ, abfd);
3864 bfd_coff_swap_scnhdr_out (abfd, &scnhdr, scnhdr_ext);
3865 bfd_bwrite (scnhdr_ext, SCNHSZ, abfd);
3866 bfd_bwrite (data_buffer, data_buffer_size, abfd);
3867 bfd_bwrite (reloc_ext, scnhdr.s_nreloc * RELSZ, abfd);
3868 bfd_bwrite (syment_ext, filehdr.f_nsyms * SYMESZ, abfd);
3869 bfd_bwrite (string_table, string_table_size, abfd);
3878 static reloc_howto_type xcoff_dynamic_reloc =
3879 HOWTO (0, /* type */
3881 2, /* size (0 = byte, 1 = short, 2 = long) */
3883 FALSE, /* pc_relative */
3885 complain_overflow_bitfield, /* complain_on_overflow */
3886 0, /* special_function */
3888 TRUE, /* partial_inplace */
3889 0xffffffff, /* src_mask */
3890 0xffffffff, /* dst_mask */
3891 FALSE); /* pcrel_offset */
3895 The first word of global linkage code must be modified by filling in
3896 the correct TOC offset. */
3898 static unsigned long xcoff_glink_code[9] =
3900 0x81820000, /* lwz r12,0(r2) */
3901 0x90410014, /* stw r2,20(r1) */
3902 0x800c0000, /* lwz r0,0(r12) */
3903 0x804c0004, /* lwz r2,4(r12) */
3904 0x7c0903a6, /* mtctr r0 */
3905 0x4e800420, /* bctr */
3906 0x00000000, /* start of traceback table */
3907 0x000c8000, /* traceback table */
3908 0x00000000, /* traceback table */
3911 /* Table to convert DWARF flags to section names. */
3913 const struct xcoff_dwsect_name xcoff_dwsect_names[] = {
3914 { SSUBTYP_DWINFO, ".dwinfo", TRUE },
3915 { SSUBTYP_DWLINE, ".dwline", TRUE },
3916 { SSUBTYP_DWPBNMS, ".dwpbnms", TRUE },
3917 { SSUBTYP_DWPBTYP, ".dwpbtyp", TRUE },
3918 { SSUBTYP_DWARNGE, ".dwarnge", TRUE },
3919 { SSUBTYP_DWABREV, ".dwabrev", FALSE },
3920 { SSUBTYP_DWSTR, ".dwstr", TRUE },
3921 { SSUBTYP_DWRNGES, ".dwrnges", TRUE }
3924 static const struct xcoff_backend_data_rec bfd_xcoff_backend_data =
3926 { /* COFF backend, defined in libcoff.h. */
3927 _bfd_xcoff_swap_aux_in,
3928 _bfd_xcoff_swap_sym_in,
3929 coff_swap_lineno_in,
3930 _bfd_xcoff_swap_aux_out,
3931 _bfd_xcoff_swap_sym_out,
3932 coff_swap_lineno_out,
3933 xcoff_swap_reloc_out,
3934 coff_swap_filehdr_out,
3935 coff_swap_aouthdr_out,
3936 coff_swap_scnhdr_out,
3945 TRUE, /* _bfd_coff_long_filenames */
3946 XCOFF_NO_LONG_SECTION_NAMES, /* _bfd_coff_long_section_names */
3947 3, /* _bfd_coff_default_section_alignment_power */
3948 FALSE, /* _bfd_coff_force_symnames_in_strings */
3949 2, /* _bfd_coff_debug_string_prefix_length */
3950 coff_swap_filehdr_in,
3951 coff_swap_aouthdr_in,
3952 coff_swap_scnhdr_in,
3953 xcoff_swap_reloc_in,
3954 coff_bad_format_hook,
3955 coff_set_arch_mach_hook,
3958 coff_set_alignment_hook,
3959 coff_slurp_symbol_table,
3960 symname_in_debug_hook,
3961 coff_pointerize_aux_hook,
3963 dummy_reloc16_extra_cases,
3964 dummy_reloc16_estimate,
3965 NULL, /* bfd_coff_sym_is_global */
3966 coff_compute_section_file_positions,
3967 NULL, /* _bfd_coff_start_final_link */
3968 xcoff_ppc_relocate_section,
3969 coff_rtype_to_howto,
3970 NULL, /* _bfd_coff_adjust_symndx */
3971 _bfd_generic_link_add_one_symbol,
3972 coff_link_output_has_begun,
3973 coff_final_link_postscript,
3974 NULL /* print_pdata. */
3977 0x01DF, /* magic number */
3981 /* Function pointers to xcoff specific swap routines. */
3982 xcoff_swap_ldhdr_in,
3983 xcoff_swap_ldhdr_out,
3984 xcoff_swap_ldsym_in,
3985 xcoff_swap_ldsym_out,
3986 xcoff_swap_ldrel_in,
3987 xcoff_swap_ldrel_out,
3993 12, /* _xcoff_function_descriptor_size */
3997 1, /* _xcoff_ldhdr_version */
3999 _bfd_xcoff_put_symbol_name,
4000 _bfd_xcoff_put_ldsymbol_name,
4001 &xcoff_dynamic_reloc,
4002 xcoff_create_csect_from_smclas,
4004 /* Lineno and reloc count overflow. */
4005 xcoff_is_lineno_count_overflow,
4006 xcoff_is_reloc_count_overflow,
4008 xcoff_loader_symbol_offset,
4009 xcoff_loader_reloc_offset,
4012 &xcoff_glink_code[0],
4013 36, /* _xcoff_glink_size */
4016 64, /* _xcoff_rtinit_size */
4017 xcoff_generate_rtinit,
4020 /* The transfer vector that leads the outside world to all of the above. */
4021 const bfd_target rs6000coff_vec =
4024 bfd_target_xcoff_flavour,
4025 BFD_ENDIAN_BIG, /* data byte order is big */
4026 BFD_ENDIAN_BIG, /* header byte order is big */
4028 (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | DYNAMIC
4029 | HAS_SYMS | HAS_LOCALS | WP_TEXT),
4031 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA,
4032 0, /* leading char */
4033 '/', /* ar_pad_char */
4034 15, /* ar_max_namelen */
4035 0, /* match priority. */
4059 { /* bfd_check_format */
4062 _bfd_xcoff_archive_p,
4066 { /* bfd_set_format */
4069 _bfd_generic_mkarchive,
4073 {/* bfd_write_contents */
4075 coff_write_object_contents,
4076 _bfd_xcoff_write_archive_contents,
4081 _bfd_archive_close_and_cleanup,
4083 coff_new_section_hook,
4084 _bfd_generic_get_section_contents,
4085 _bfd_generic_get_section_contents_in_window,
4088 _bfd_xcoff_copy_private_bfd_data,
4089 _bfd_generic_bfd_merge_private_bfd_data,
4090 _bfd_generic_init_private_section_data,
4091 _bfd_generic_bfd_copy_private_section_data,
4092 _bfd_generic_bfd_copy_private_symbol_data,
4093 _bfd_generic_bfd_copy_private_header_data,
4094 _bfd_generic_bfd_set_private_flags,
4095 _bfd_generic_bfd_print_private_bfd_data,
4098 BFD_JUMP_TABLE_CORE (coff),
4101 _bfd_xcoff_slurp_armap,
4102 _bfd_noarchive_slurp_extended_name_table,
4103 _bfd_noarchive_construct_extended_name_table,
4104 bfd_dont_truncate_arname,
4105 _bfd_xcoff_write_armap,
4106 _bfd_xcoff_read_ar_hdr,
4107 _bfd_generic_write_ar_hdr,
4108 _bfd_xcoff_openr_next_archived_file,
4109 _bfd_generic_get_elt_at_index,
4110 _bfd_xcoff_stat_arch_elt,
4114 coff_get_symtab_upper_bound,
4115 coff_canonicalize_symtab,
4116 coff_make_empty_symbol,
4118 coff_get_symbol_info,
4119 _bfd_xcoff_is_local_label_name,
4120 coff_bfd_is_target_special_symbol,
4122 xcoff_find_nearest_line,
4123 _bfd_generic_find_nearest_line_discriminator,
4124 _bfd_generic_find_line,
4125 coff_find_inliner_info,
4126 coff_bfd_make_debug_symbol,
4127 _bfd_generic_read_minisymbols,
4128 _bfd_generic_minisymbol_to_symbol,
4131 coff_get_reloc_upper_bound,
4132 coff_canonicalize_reloc,
4133 _bfd_xcoff_reloc_type_lookup,
4134 _bfd_xcoff_reloc_name_lookup,
4138 coff_set_section_contents,
4141 _bfd_xcoff_sizeof_headers,
4142 bfd_generic_get_relocated_section_contents,
4143 bfd_generic_relax_section,
4144 _bfd_xcoff_bfd_link_hash_table_create,
4145 _bfd_generic_link_hash_table_free,
4146 _bfd_xcoff_bfd_link_add_symbols,
4147 _bfd_generic_link_just_syms,
4148 _bfd_generic_copy_link_hash_symbol_type,
4149 _bfd_xcoff_bfd_final_link,
4150 _bfd_generic_link_split_section,
4151 bfd_generic_gc_sections,
4152 bfd_generic_lookup_section_flags,
4153 bfd_generic_merge_sections,
4154 bfd_generic_is_group_section,
4155 bfd_generic_discard_group,
4156 _bfd_generic_section_already_linked,
4157 _bfd_xcoff_define_common_symbol,
4160 _bfd_xcoff_get_dynamic_symtab_upper_bound,
4161 _bfd_xcoff_canonicalize_dynamic_symtab,
4162 _bfd_nodynamic_get_synthetic_symtab,
4163 _bfd_xcoff_get_dynamic_reloc_upper_bound,
4164 _bfd_xcoff_canonicalize_dynamic_reloc,
4166 /* Opposite endian version, none exists */
4169 & bfd_xcoff_backend_data,
4172 /* xcoff-powermac target
4174 Only difference between this target and the rs6000 target is the
4175 the default architecture and machine type used in coffcode.h
4177 PowerPC Macs use the same magic numbers as RS/6000
4178 (because that's how they were bootstrapped originally),
4179 but they are always PowerPC architecture. */
4180 static const struct xcoff_backend_data_rec bfd_pmac_xcoff_backend_data =
4182 { /* COFF backend, defined in libcoff.h. */
4183 _bfd_xcoff_swap_aux_in,
4184 _bfd_xcoff_swap_sym_in,
4185 coff_swap_lineno_in,
4186 _bfd_xcoff_swap_aux_out,
4187 _bfd_xcoff_swap_sym_out,
4188 coff_swap_lineno_out,
4189 xcoff_swap_reloc_out,
4190 coff_swap_filehdr_out,
4191 coff_swap_aouthdr_out,
4192 coff_swap_scnhdr_out,
4201 TRUE, /* _bfd_coff_long_filenames */
4202 XCOFF_NO_LONG_SECTION_NAMES, /* _bfd_coff_long_section_names */
4203 3, /* _bfd_coff_default_section_alignment_power */
4204 FALSE, /* _bfd_coff_force_symnames_in_strings */
4205 2, /* _bfd_coff_debug_string_prefix_length */
4206 coff_swap_filehdr_in,
4207 coff_swap_aouthdr_in,
4208 coff_swap_scnhdr_in,
4209 xcoff_swap_reloc_in,
4210 coff_bad_format_hook,
4211 coff_set_arch_mach_hook,
4214 coff_set_alignment_hook,
4215 coff_slurp_symbol_table,
4216 symname_in_debug_hook,
4217 coff_pointerize_aux_hook,
4219 dummy_reloc16_extra_cases,
4220 dummy_reloc16_estimate,
4221 NULL, /* bfd_coff_sym_is_global */
4222 coff_compute_section_file_positions,
4223 NULL, /* _bfd_coff_start_final_link */
4224 xcoff_ppc_relocate_section,
4225 coff_rtype_to_howto,
4226 NULL, /* _bfd_coff_adjust_symndx */
4227 _bfd_generic_link_add_one_symbol,
4228 coff_link_output_has_begun,
4229 coff_final_link_postscript,
4230 NULL /* print_pdata. */
4233 0x01DF, /* magic number */
4237 /* Function pointers to xcoff specific swap routines. */
4238 xcoff_swap_ldhdr_in,
4239 xcoff_swap_ldhdr_out,
4240 xcoff_swap_ldsym_in,
4241 xcoff_swap_ldsym_out,
4242 xcoff_swap_ldrel_in,
4243 xcoff_swap_ldrel_out,
4249 12, /* _xcoff_function_descriptor_size */
4253 1, /* _xcoff_ldhdr_version */
4255 _bfd_xcoff_put_symbol_name,
4256 _bfd_xcoff_put_ldsymbol_name,
4257 &xcoff_dynamic_reloc,
4258 xcoff_create_csect_from_smclas,
4260 /* Lineno and reloc count overflow. */
4261 xcoff_is_lineno_count_overflow,
4262 xcoff_is_reloc_count_overflow,
4264 xcoff_loader_symbol_offset,
4265 xcoff_loader_reloc_offset,
4268 &xcoff_glink_code[0],
4269 36, /* _xcoff_glink_size */
4272 0, /* _xcoff_rtinit_size */
4273 xcoff_generate_rtinit,
4276 /* The transfer vector that leads the outside world to all of the above. */
4277 const bfd_target pmac_xcoff_vec =
4280 bfd_target_xcoff_flavour,
4281 BFD_ENDIAN_BIG, /* data byte order is big */
4282 BFD_ENDIAN_BIG, /* header byte order is big */
4284 (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | DYNAMIC
4285 | HAS_SYMS | HAS_LOCALS | WP_TEXT),
4287 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA,
4288 0, /* leading char */
4289 '/', /* ar_pad_char */
4290 15, /* ar_max_namelen */
4291 0, /* match priority. */
4315 { /* bfd_check_format */
4318 _bfd_xcoff_archive_p,
4322 { /* bfd_set_format */
4325 _bfd_generic_mkarchive,
4329 {/* bfd_write_contents */
4331 coff_write_object_contents,
4332 _bfd_xcoff_write_archive_contents,
4337 _bfd_archive_close_and_cleanup,
4339 coff_new_section_hook,
4340 _bfd_generic_get_section_contents,
4341 _bfd_generic_get_section_contents_in_window,
4344 _bfd_xcoff_copy_private_bfd_data,
4345 _bfd_generic_bfd_merge_private_bfd_data,
4346 _bfd_generic_init_private_section_data,
4347 _bfd_generic_bfd_copy_private_section_data,
4348 _bfd_generic_bfd_copy_private_symbol_data,
4349 _bfd_generic_bfd_copy_private_header_data,
4350 _bfd_generic_bfd_set_private_flags,
4351 _bfd_generic_bfd_print_private_bfd_data,
4354 BFD_JUMP_TABLE_CORE (coff),
4357 _bfd_xcoff_slurp_armap,
4358 _bfd_noarchive_slurp_extended_name_table,
4359 _bfd_noarchive_construct_extended_name_table,
4360 bfd_dont_truncate_arname,
4361 _bfd_xcoff_write_armap,
4362 _bfd_xcoff_read_ar_hdr,
4363 _bfd_generic_write_ar_hdr,
4364 _bfd_xcoff_openr_next_archived_file,
4365 _bfd_generic_get_elt_at_index,
4366 _bfd_xcoff_stat_arch_elt,
4370 coff_get_symtab_upper_bound,
4371 coff_canonicalize_symtab,
4372 coff_make_empty_symbol,
4374 coff_get_symbol_info,
4375 _bfd_xcoff_is_local_label_name,
4376 coff_bfd_is_target_special_symbol,
4378 xcoff_find_nearest_line,
4379 _bfd_generic_find_nearest_line_discriminator,
4380 _bfd_generic_find_line,
4381 coff_find_inliner_info,
4382 coff_bfd_make_debug_symbol,
4383 _bfd_generic_read_minisymbols,
4384 _bfd_generic_minisymbol_to_symbol,
4387 coff_get_reloc_upper_bound,
4388 coff_canonicalize_reloc,
4389 _bfd_xcoff_reloc_type_lookup,
4390 _bfd_xcoff_reloc_name_lookup,
4394 coff_set_section_contents,
4397 _bfd_xcoff_sizeof_headers,
4398 bfd_generic_get_relocated_section_contents,
4399 bfd_generic_relax_section,
4400 _bfd_xcoff_bfd_link_hash_table_create,
4401 _bfd_generic_link_hash_table_free,
4402 _bfd_xcoff_bfd_link_add_symbols,
4403 _bfd_generic_link_just_syms,
4404 _bfd_generic_copy_link_hash_symbol_type,
4405 _bfd_xcoff_bfd_final_link,
4406 _bfd_generic_link_split_section,
4407 bfd_generic_gc_sections,
4408 bfd_generic_lookup_section_flags,
4409 bfd_generic_merge_sections,
4410 bfd_generic_is_group_section,
4411 bfd_generic_discard_group,
4412 _bfd_generic_section_already_linked,
4413 _bfd_xcoff_define_common_symbol,
4416 _bfd_xcoff_get_dynamic_symtab_upper_bound,
4417 _bfd_xcoff_canonicalize_dynamic_symtab,
4418 _bfd_nodynamic_get_synthetic_symtab,
4419 _bfd_xcoff_get_dynamic_reloc_upper_bound,
4420 _bfd_xcoff_canonicalize_dynamic_reloc,
4422 /* Opposite endian version, none exists */
4425 & bfd_pmac_xcoff_backend_data,