1 /* BFD back-end for IBM RS/6000 "XCOFF" files.
2 Copyright (C) 1990-2015 Free Software Foundation, Inc.
3 Written by Metin G. Ozisik, Mimi Phuong-Thao Vo, and John Gilmore.
4 Archive support from Damon A. Permezel.
5 Contributed by IBM Corporation and Cygnus Support.
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
22 MA 02110-1301, USA. */
25 #include "libiberty.h"
29 #include "coff/internal.h"
30 #include "coff/xcoff.h"
31 #include "coff/rs6000.h"
35 extern bfd_boolean _bfd_xcoff_mkobject (bfd *);
36 extern bfd_boolean _bfd_xcoff_copy_private_bfd_data (bfd *, bfd *);
37 extern bfd_boolean _bfd_xcoff_is_local_label_name (bfd *, const char *);
38 extern reloc_howto_type *_bfd_xcoff_reloc_type_lookup
39 (bfd *, bfd_reloc_code_real_type);
40 extern bfd_boolean _bfd_xcoff_slurp_armap (bfd *);
41 extern const bfd_target *_bfd_xcoff_archive_p (bfd *);
42 extern void * _bfd_xcoff_read_ar_hdr (bfd *);
43 extern bfd *_bfd_xcoff_openr_next_archived_file (bfd *, bfd *);
44 extern int _bfd_xcoff_stat_arch_elt (bfd *, struct stat *);
45 extern bfd_boolean _bfd_xcoff_write_armap
46 (bfd *, unsigned int, struct orl *, unsigned int, int);
47 extern bfd_boolean _bfd_xcoff_write_archive_contents (bfd *);
48 extern int _bfd_xcoff_sizeof_headers (bfd *, struct bfd_link_info *);
49 extern void _bfd_xcoff_swap_sym_in (bfd *, void *, void *);
50 extern unsigned int _bfd_xcoff_swap_sym_out (bfd *, void *, void *);
51 extern void _bfd_xcoff_swap_aux_in (bfd *, void *, int, int, int, int, void *);
52 extern unsigned int _bfd_xcoff_swap_aux_out
53 (bfd *, void *, int, int, int, int, void *);
54 static void xcoff_swap_reloc_in (bfd *, void *, void *);
55 static unsigned int xcoff_swap_reloc_out (bfd *, void *, void *);
57 /* Forward declare xcoff_rtype2howto for coffcode.h macro. */
58 void xcoff_rtype2howto (arelent *, struct internal_reloc *);
60 /* coffcode.h needs these to be defined. */
61 #define RS6000COFF_C 1
63 #define SELECT_RELOC(internal, howto) \
65 internal.r_type = howto->type; \
67 ((howto->complain_on_overflow == complain_overflow_signed \
70 | (howto->bitsize - 1)); \
73 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
74 #define COFF_LONG_FILENAMES
75 #define NO_COFF_SYMBOLS
76 #define RTYPE2HOWTO(cache_ptr, dst) xcoff_rtype2howto (cache_ptr, dst)
77 #define coff_mkobject _bfd_xcoff_mkobject
78 #define coff_bfd_is_local_label_name _bfd_xcoff_is_local_label_name
80 extern const bfd_target * rs6000coff_core_p (bfd *abfd);
81 extern bfd_boolean rs6000coff_core_file_matches_executable_p
82 (bfd *cbfd, bfd *ebfd);
83 extern char *rs6000coff_core_file_failing_command (bfd *abfd);
84 extern int rs6000coff_core_file_failing_signal (bfd *abfd);
85 #define CORE_FILE_P rs6000coff_core_p
86 #define coff_core_file_failing_command \
87 rs6000coff_core_file_failing_command
88 #define coff_core_file_failing_signal \
89 rs6000coff_core_file_failing_signal
90 #define coff_core_file_matches_executable_p \
91 rs6000coff_core_file_matches_executable_p
92 #define coff_core_file_pid \
93 _bfd_nocore_core_file_pid
95 #define CORE_FILE_P _bfd_dummy_target
96 #define coff_core_file_failing_command \
97 _bfd_nocore_core_file_failing_command
98 #define coff_core_file_failing_signal \
99 _bfd_nocore_core_file_failing_signal
100 #define coff_core_file_matches_executable_p \
101 _bfd_nocore_core_file_matches_executable_p
102 #define coff_core_file_pid \
103 _bfd_nocore_core_file_pid
105 #define coff_SWAP_sym_in _bfd_xcoff_swap_sym_in
106 #define coff_SWAP_sym_out _bfd_xcoff_swap_sym_out
107 #define coff_SWAP_aux_in _bfd_xcoff_swap_aux_in
108 #define coff_SWAP_aux_out _bfd_xcoff_swap_aux_out
109 #define coff_swap_reloc_in xcoff_swap_reloc_in
110 #define coff_swap_reloc_out xcoff_swap_reloc_out
111 #define NO_COFF_RELOCS
113 #ifndef bfd_pe_print_pdata
114 #define bfd_pe_print_pdata NULL
118 #include "coffcode.h"
120 /* The main body of code is in coffcode.h. */
122 static const char *normalize_filename (bfd *);
123 static bfd_boolean xcoff_write_armap_old
124 (bfd *, unsigned int, struct orl *, unsigned int, int);
125 static bfd_boolean xcoff_write_armap_big
126 (bfd *, unsigned int, struct orl *, unsigned int, int);
127 static bfd_boolean xcoff_write_archive_contents_old (bfd *);
128 static bfd_boolean xcoff_write_archive_contents_big (bfd *);
129 static void xcoff_swap_ldhdr_in (bfd *, const void *, struct internal_ldhdr *);
130 static void xcoff_swap_ldhdr_out (bfd *, const struct internal_ldhdr *, void *);
131 static void xcoff_swap_ldsym_in (bfd *, const void *, struct internal_ldsym *);
132 static void xcoff_swap_ldsym_out (bfd *, const struct internal_ldsym *, void *);
133 static void xcoff_swap_ldrel_in (bfd *, const void *, struct internal_ldrel *);
134 static void xcoff_swap_ldrel_out (bfd *, const struct internal_ldrel *, void *);
135 static bfd_boolean xcoff_ppc_relocate_section
136 (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
137 struct internal_reloc *, struct internal_syment *, asection **);
138 static bfd_boolean _bfd_xcoff_put_ldsymbol_name
139 (bfd *, struct xcoff_loader_info *, struct internal_ldsym *, const char *);
140 static asection *xcoff_create_csect_from_smclas
141 (bfd *, union internal_auxent *, const char *);
142 static bfd_boolean xcoff_is_lineno_count_overflow (bfd *, bfd_vma);
143 static bfd_boolean xcoff_is_reloc_count_overflow (bfd *, bfd_vma);
144 static bfd_vma xcoff_loader_symbol_offset (bfd *, struct internal_ldhdr *);
145 static bfd_vma xcoff_loader_reloc_offset (bfd *, struct internal_ldhdr *);
146 static bfd_boolean xcoff_generate_rtinit
147 (bfd *, const char *, const char *, bfd_boolean);
148 static bfd_boolean do_pad (bfd *, unsigned int);
149 static bfd_boolean do_copy (bfd *, bfd *);
151 /* Relocation functions */
152 static bfd_boolean xcoff_reloc_type_br (XCOFF_RELOC_FUNCTION_ARGS);
154 static bfd_boolean xcoff_complain_overflow_dont_func
155 (XCOFF_COMPLAIN_FUNCTION_ARGS);
156 static bfd_boolean xcoff_complain_overflow_bitfield_func
157 (XCOFF_COMPLAIN_FUNCTION_ARGS);
158 static bfd_boolean xcoff_complain_overflow_signed_func
159 (XCOFF_COMPLAIN_FUNCTION_ARGS);
160 static bfd_boolean xcoff_complain_overflow_unsigned_func
161 (XCOFF_COMPLAIN_FUNCTION_ARGS);
163 bfd_boolean (*xcoff_calculate_relocation[XCOFF_MAX_CALCULATE_RELOCATION])
164 (XCOFF_RELOC_FUNCTION_ARGS) =
166 xcoff_reloc_type_pos, /* R_POS (0x00) */
167 xcoff_reloc_type_neg, /* R_NEG (0x01) */
168 xcoff_reloc_type_rel, /* R_REL (0x02) */
169 xcoff_reloc_type_toc, /* R_TOC (0x03) */
170 xcoff_reloc_type_fail, /* R_RTB (0x04) */
171 xcoff_reloc_type_toc, /* R_GL (0x05) */
172 xcoff_reloc_type_toc, /* R_TCL (0x06) */
173 xcoff_reloc_type_fail, /* (0x07) */
174 xcoff_reloc_type_ba, /* R_BA (0x08) */
175 xcoff_reloc_type_fail, /* (0x09) */
176 xcoff_reloc_type_br, /* R_BR (0x0a) */
177 xcoff_reloc_type_fail, /* (0x0b) */
178 xcoff_reloc_type_pos, /* R_RL (0x0c) */
179 xcoff_reloc_type_pos, /* R_RLA (0x0d) */
180 xcoff_reloc_type_fail, /* (0x0e) */
181 xcoff_reloc_type_noop, /* R_REF (0x0f) */
182 xcoff_reloc_type_fail, /* (0x10) */
183 xcoff_reloc_type_fail, /* (0x11) */
184 xcoff_reloc_type_toc, /* R_TRL (0x12) */
185 xcoff_reloc_type_toc, /* R_TRLA (0x13) */
186 xcoff_reloc_type_fail, /* R_RRTBI (0x14) */
187 xcoff_reloc_type_fail, /* R_RRTBA (0x15) */
188 xcoff_reloc_type_ba, /* R_CAI (0x16) */
189 xcoff_reloc_type_crel, /* R_CREL (0x17) */
190 xcoff_reloc_type_ba, /* R_RBA (0x18) */
191 xcoff_reloc_type_ba, /* R_RBAC (0x19) */
192 xcoff_reloc_type_br, /* R_RBR (0x1a) */
193 xcoff_reloc_type_ba, /* R_RBRC (0x1b) */
196 bfd_boolean (*xcoff_complain_overflow[XCOFF_MAX_COMPLAIN_OVERFLOW])
197 (XCOFF_COMPLAIN_FUNCTION_ARGS) =
199 xcoff_complain_overflow_dont_func,
200 xcoff_complain_overflow_bitfield_func,
201 xcoff_complain_overflow_signed_func,
202 xcoff_complain_overflow_unsigned_func,
205 /* Information about one member of an archive. */
206 struct member_layout {
207 /* The archive member that this structure describes. */
210 /* The number of bytes of padding that must be inserted before the
211 start of the member in order to ensure that the section contents
212 are correctly aligned. */
213 unsigned int leading_padding;
215 /* The offset of MEMBER from the start of the archive (i.e. the end
216 of the leading padding). */
219 /* The normalized name of MEMBER. */
222 /* The length of NAME, without padding. */
223 bfd_size_type namlen;
225 /* The length of NAME, with padding. */
226 bfd_size_type padded_namlen;
228 /* The size of MEMBER's header, including the name and magic sequence. */
229 bfd_size_type header_size;
231 /* The size of the MEMBER's contents. */
232 bfd_size_type contents_size;
234 /* The number of bytes of padding that must be inserted after MEMBER
235 in order to preserve even alignment. */
236 bfd_size_type trailing_padding;
239 /* A structure used for iterating over the members of an archive. */
240 struct archive_iterator {
241 /* The archive itself. */
244 /* Information about the current archive member. */
245 struct member_layout current;
247 /* Information about the next archive member. MEMBER is null if there
248 are no more archive members, in which case OFFSET is the offset of
249 the first unused byte. */
250 struct member_layout next;
253 /* Initialize INFO so that it describes member MEMBER of archive ARCHIVE.
254 OFFSET is the even-padded offset of MEMBER, not including any leading
255 padding needed for section alignment. */
258 member_layout_init (struct member_layout *info, bfd *archive,
259 bfd *member, file_ptr offset)
261 info->member = member;
262 info->leading_padding = 0;
265 info->name = normalize_filename (member);
266 info->namlen = strlen (info->name);
267 info->padded_namlen = info->namlen + (info->namlen & 1);
268 if (xcoff_big_format_p (archive))
269 info->header_size = SIZEOF_AR_HDR_BIG;
271 info->header_size = SIZEOF_AR_HDR;
272 info->header_size += info->padded_namlen + SXCOFFARFMAG;
273 info->contents_size = arelt_size (member);
274 info->trailing_padding = info->contents_size & 1;
276 if (bfd_check_format (member, bfd_object)
277 && bfd_get_flavour (member) == bfd_target_xcoff_flavour
278 && (member->flags & DYNAMIC) != 0)
279 info->leading_padding
280 = (-(offset + info->header_size)
281 & ((1 << bfd_xcoff_text_align_power (member)) - 1));
283 info->offset = offset + info->leading_padding;
286 /* Set up ITERATOR to iterate through archive ARCHIVE. */
289 archive_iterator_begin (struct archive_iterator *iterator,
292 iterator->archive = archive;
293 member_layout_init (&iterator->next, archive, archive->archive_head,
294 xcoff_big_format_p (archive)
295 ? SIZEOF_AR_FILE_HDR_BIG
296 : SIZEOF_AR_FILE_HDR);
299 /* Make ITERATOR visit the first unvisited archive member. Return true
300 on success; return false if all members have been visited. */
303 archive_iterator_next (struct archive_iterator *iterator)
305 if (!iterator->next.member)
308 iterator->current = iterator->next;
309 member_layout_init (&iterator->next, iterator->archive,
310 iterator->current.member->archive_next,
311 iterator->current.offset
312 + iterator->current.header_size
313 + iterator->current.contents_size
314 + iterator->current.trailing_padding);
318 /* We use our own tdata type. Its first field is the COFF tdata type,
319 so the COFF routines are compatible. */
322 _bfd_xcoff_mkobject (bfd *abfd)
324 coff_data_type *coff;
325 bfd_size_type amt = sizeof (struct xcoff_tdata);
327 abfd->tdata.xcoff_obj_data = (struct xcoff_tdata *) bfd_zalloc (abfd, amt);
328 if (abfd->tdata.xcoff_obj_data == NULL)
330 coff = coff_data (abfd);
331 coff->symbols = (coff_symbol_type *) NULL;
332 coff->conversion_table = (unsigned int *) NULL;
333 coff->raw_syments = (struct coff_ptr_struct *) NULL;
336 xcoff_data (abfd)->modtype = ('1' << 8) | 'L';
338 /* We set cputype to -1 to indicate that it has not been
340 xcoff_data (abfd)->cputype = -1;
342 xcoff_data (abfd)->csects = NULL;
343 xcoff_data (abfd)->debug_indices = NULL;
345 /* text section alignment is different than the default */
346 bfd_xcoff_text_align_power (abfd) = 2;
351 /* Copy XCOFF data from one BFD to another. */
354 _bfd_xcoff_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
356 struct xcoff_tdata *ix, *ox;
359 if (ibfd->xvec != obfd->xvec)
361 ix = xcoff_data (ibfd);
362 ox = xcoff_data (obfd);
363 ox->full_aouthdr = ix->full_aouthdr;
369 sec = coff_section_from_bfd_index (ibfd, ix->sntoc);
373 ox->sntoc = sec->output_section->target_index;
375 if (ix->snentry == 0)
379 sec = coff_section_from_bfd_index (ibfd, ix->snentry);
383 ox->snentry = sec->output_section->target_index;
385 bfd_xcoff_text_align_power (obfd) = bfd_xcoff_text_align_power (ibfd);
386 bfd_xcoff_data_align_power (obfd) = bfd_xcoff_data_align_power (ibfd);
387 ox->modtype = ix->modtype;
388 ox->cputype = ix->cputype;
389 ox->maxdata = ix->maxdata;
390 ox->maxstack = ix->maxstack;
394 /* I don't think XCOFF really has a notion of local labels based on
395 name. This will mean that ld -X doesn't actually strip anything.
396 The AIX native linker does not have a -X option, and it ignores the
400 _bfd_xcoff_is_local_label_name (bfd *abfd ATTRIBUTE_UNUSED,
401 const char *name ATTRIBUTE_UNUSED)
406 static const struct dwarf_debug_section xcoff_debug_sections[] =
408 { ".dwabrev", NULL },
409 { ".dwarnge", NULL },
410 { NULL, NULL }, /* .debug_frame */
413 { NULL, NULL }, /* .debug_loc */
414 { NULL, NULL }, /* .debug_macinfo */
415 { NULL, NULL }, /* .debug_macro */
416 { ".dwpbnms", NULL },
417 { ".dwpbtyp", NULL },
418 { ".dwrnges", NULL },
419 { NULL, NULL }, /* .debug_static_func */
420 { NULL, NULL }, /* .debug_static_vars */
422 { NULL, NULL }, /* .debug_types */
423 /* GNU DWARF 1 extensions */
424 { NULL, NULL }, /* .debug_sfnames */
425 { NULL, NULL }, /* .debug_srcinfo */
426 /* SGI/MIPS DWARF 2 extensions */
427 { NULL, NULL }, /* .debug_funcnames */
428 { NULL, NULL }, /* .debug_typenames */
429 { NULL, NULL }, /* .debug_varnames */
430 { NULL, NULL }, /* .debug_weaknames */
435 _bfd_xcoff_swap_sym_in (bfd *abfd, void * ext1, void * in1)
437 SYMENT *ext = (SYMENT *)ext1;
438 struct internal_syment * in = (struct internal_syment *)in1;
440 if (ext->e.e_name[0] != 0)
442 memcpy (in->_n._n_name, ext->e.e_name, SYMNMLEN);
446 in->_n._n_n._n_zeroes = 0;
447 in->_n._n_n._n_offset = H_GET_32 (abfd, ext->e.e.e_offset);
450 in->n_value = H_GET_32 (abfd, ext->e_value);
451 in->n_scnum = H_GET_16 (abfd, ext->e_scnum);
452 in->n_type = H_GET_16 (abfd, ext->e_type);
453 in->n_sclass = H_GET_8 (abfd, ext->e_sclass);
454 in->n_numaux = H_GET_8 (abfd, ext->e_numaux);
458 _bfd_xcoff_swap_sym_out (bfd *abfd, void * inp, void * extp)
460 struct internal_syment *in = (struct internal_syment *)inp;
461 SYMENT *ext =(SYMENT *)extp;
463 if (in->_n._n_name[0] != 0)
465 memcpy (ext->e.e_name, in->_n._n_name, SYMNMLEN);
469 H_PUT_32 (abfd, 0, ext->e.e.e_zeroes);
470 H_PUT_32 (abfd, in->_n._n_n._n_offset, ext->e.e.e_offset);
473 H_PUT_32 (abfd, in->n_value, ext->e_value);
474 H_PUT_16 (abfd, in->n_scnum, ext->e_scnum);
475 H_PUT_16 (abfd, in->n_type, ext->e_type);
476 H_PUT_8 (abfd, in->n_sclass, ext->e_sclass);
477 H_PUT_8 (abfd, in->n_numaux, ext->e_numaux);
478 return bfd_coff_symesz (abfd);
482 _bfd_xcoff_swap_aux_in (bfd *abfd, void * ext1, int type, int in_class,
483 int indx, int numaux, void * in1)
485 AUXENT * ext = (AUXENT *)ext1;
486 union internal_auxent *in = (union internal_auxent *)in1;
491 if (ext->x_file.x_n.x_fname[0] == 0)
493 in->x_file.x_n.x_zeroes = 0;
494 in->x_file.x_n.x_offset =
495 H_GET_32 (abfd, ext->x_file.x_n.x_n.x_offset);
502 memcpy (in->x_file.x_fname, ext->x_file.x_n.x_fname,
503 numaux * sizeof (AUXENT));
507 memcpy (in->x_file.x_fname, ext->x_file.x_n.x_fname, FILNMLEN);
512 /* RS/6000 "csect" auxents */
516 if (indx + 1 == numaux)
518 in->x_csect.x_scnlen.l = H_GET_32 (abfd, ext->x_csect.x_scnlen);
519 in->x_csect.x_parmhash = H_GET_32 (abfd, ext->x_csect.x_parmhash);
520 in->x_csect.x_snhash = H_GET_16 (abfd, ext->x_csect.x_snhash);
521 /* We don't have to hack bitfields in x_smtyp because it's
522 defined by shifts-and-ands, which are equivalent on all
524 in->x_csect.x_smtyp = H_GET_8 (abfd, ext->x_csect.x_smtyp);
525 in->x_csect.x_smclas = H_GET_8 (abfd, ext->x_csect.x_smclas);
526 in->x_csect.x_stab = H_GET_32 (abfd, ext->x_csect.x_stab);
527 in->x_csect.x_snstab = H_GET_16 (abfd, ext->x_csect.x_snstab);
537 in->x_scn.x_scnlen = H_GET_32 (abfd, ext->x_scn.x_scnlen);
538 in->x_scn.x_nreloc = H_GET_16 (abfd, ext->x_scn.x_nreloc);
539 in->x_scn.x_nlinno = H_GET_16 (abfd, ext->x_scn.x_nlinno);
540 /* PE defines some extra fields; we zero them out for
542 in->x_scn.x_checksum = 0;
543 in->x_scn.x_associated = 0;
544 in->x_scn.x_comdat = 0;
551 in->x_sym.x_tagndx.l = H_GET_32 (abfd, ext->x_sym.x_tagndx);
552 in->x_sym.x_tvndx = H_GET_16 (abfd, ext->x_sym.x_tvndx);
554 if (in_class == C_BLOCK || in_class == C_FCN || ISFCN (type)
557 in->x_sym.x_fcnary.x_fcn.x_lnnoptr =
558 H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_lnnoptr);
559 in->x_sym.x_fcnary.x_fcn.x_endndx.l =
560 H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_endndx);
564 in->x_sym.x_fcnary.x_ary.x_dimen[0] =
565 H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
566 in->x_sym.x_fcnary.x_ary.x_dimen[1] =
567 H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
568 in->x_sym.x_fcnary.x_ary.x_dimen[2] =
569 H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
570 in->x_sym.x_fcnary.x_ary.x_dimen[3] =
571 H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
576 in->x_sym.x_misc.x_fsize = H_GET_32 (abfd, ext->x_sym.x_misc.x_fsize);
580 in->x_sym.x_misc.x_lnsz.x_lnno =
581 H_GET_16 (abfd, ext->x_sym.x_misc.x_lnsz.x_lnno);
582 in->x_sym.x_misc.x_lnsz.x_size =
583 H_GET_16 (abfd, ext->x_sym.x_misc.x_lnsz.x_size);
587 /* The semicolon is because MSVC doesn't like labels at
592 _bfd_xcoff_swap_aux_out (bfd *abfd, void * inp, int type, int in_class,
593 int indx ATTRIBUTE_UNUSED,
594 int numaux ATTRIBUTE_UNUSED,
597 union internal_auxent *in = (union internal_auxent *)inp;
598 AUXENT *ext = (AUXENT *)extp;
600 memset (ext, 0, bfd_coff_auxesz (abfd));
604 if (in->x_file.x_fname[0] == 0)
606 H_PUT_32 (abfd, 0, ext->x_file.x_n.x_n.x_zeroes);
607 H_PUT_32 (abfd, in->x_file.x_n.x_offset,
608 ext->x_file.x_n.x_n.x_offset);
612 memcpy (ext->x_file.x_n.x_fname, in->x_file.x_fname, FILNMLEN);
616 /* RS/6000 "csect" auxents */
620 if (indx + 1 == numaux)
622 H_PUT_32 (abfd, in->x_csect.x_scnlen.l, ext->x_csect.x_scnlen);
623 H_PUT_32 (abfd, in->x_csect.x_parmhash, ext->x_csect.x_parmhash);
624 H_PUT_16 (abfd, in->x_csect.x_snhash, ext->x_csect.x_snhash);
625 /* We don't have to hack bitfields in x_smtyp because it's
626 defined by shifts-and-ands, which are equivalent on all
628 H_PUT_8 (abfd, in->x_csect.x_smtyp, ext->x_csect.x_smtyp);
629 H_PUT_8 (abfd, in->x_csect.x_smclas, ext->x_csect.x_smclas);
630 H_PUT_32 (abfd, in->x_csect.x_stab, ext->x_csect.x_stab);
631 H_PUT_16 (abfd, in->x_csect.x_snstab, ext->x_csect.x_snstab);
641 H_PUT_32 (abfd, in->x_scn.x_scnlen, ext->x_scn.x_scnlen);
642 H_PUT_16 (abfd, in->x_scn.x_nreloc, ext->x_scn.x_nreloc);
643 H_PUT_16 (abfd, in->x_scn.x_nlinno, ext->x_scn.x_nlinno);
649 H_PUT_32 (abfd, in->x_sym.x_tagndx.l, ext->x_sym.x_tagndx);
650 H_PUT_16 (abfd, in->x_sym.x_tvndx, ext->x_sym.x_tvndx);
652 if (in_class == C_BLOCK || in_class == C_FCN || ISFCN (type)
655 H_PUT_32 (abfd, in->x_sym.x_fcnary.x_fcn.x_lnnoptr,
656 ext->x_sym.x_fcnary.x_fcn.x_lnnoptr);
657 H_PUT_32 (abfd, in->x_sym.x_fcnary.x_fcn.x_endndx.l,
658 ext->x_sym.x_fcnary.x_fcn.x_endndx);
662 H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[0],
663 ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
664 H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[1],
665 ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
666 H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[2],
667 ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
668 H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[3],
669 ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
673 H_PUT_32 (abfd, in->x_sym.x_misc.x_fsize, ext->x_sym.x_misc.x_fsize);
676 H_PUT_16 (abfd, in->x_sym.x_misc.x_lnsz.x_lnno,
677 ext->x_sym.x_misc.x_lnsz.x_lnno);
678 H_PUT_16 (abfd, in->x_sym.x_misc.x_lnsz.x_size,
679 ext->x_sym.x_misc.x_lnsz.x_size);
683 return bfd_coff_auxesz (abfd);
688 /* The XCOFF reloc table. Actually, XCOFF relocations specify the
689 bitsize and whether they are signed or not, along with a
690 conventional type. This table is for the types, which are used for
691 different algorithms for putting in the reloc. Many of these
692 relocs need special_function entries, which I have not written. */
695 reloc_howto_type xcoff_howto_table[] =
697 /* 0x00: Standard 32 bit relocation. */
698 HOWTO (R_POS, /* type */
700 2, /* size (0 = byte, 1 = short, 2 = long) */
702 FALSE, /* pc_relative */
704 complain_overflow_bitfield, /* complain_on_overflow */
705 0, /* special_function */
707 TRUE, /* partial_inplace */
708 0xffffffff, /* src_mask */
709 0xffffffff, /* dst_mask */
710 FALSE), /* pcrel_offset */
712 /* 0x01: 32 bit relocation, but store negative value. */
713 HOWTO (R_NEG, /* type */
715 -2, /* size (0 = byte, 1 = short, 2 = long) */
717 FALSE, /* pc_relative */
719 complain_overflow_bitfield, /* complain_on_overflow */
720 0, /* special_function */
722 TRUE, /* partial_inplace */
723 0xffffffff, /* src_mask */
724 0xffffffff, /* dst_mask */
725 FALSE), /* pcrel_offset */
727 /* 0x02: 32 bit PC relative relocation. */
728 HOWTO (R_REL, /* type */
730 2, /* size (0 = byte, 1 = short, 2 = long) */
732 TRUE, /* pc_relative */
734 complain_overflow_signed, /* complain_on_overflow */
735 0, /* special_function */
737 TRUE, /* partial_inplace */
738 0xffffffff, /* src_mask */
739 0xffffffff, /* dst_mask */
740 FALSE), /* pcrel_offset */
742 /* 0x03: 16 bit TOC relative relocation. */
743 HOWTO (R_TOC, /* type */
745 1, /* size (0 = byte, 1 = short, 2 = long) */
747 FALSE, /* pc_relative */
749 complain_overflow_bitfield, /* complain_on_overflow */
750 0, /* special_function */
752 TRUE, /* partial_inplace */
753 0xffff, /* src_mask */
754 0xffff, /* dst_mask */
755 FALSE), /* pcrel_offset */
757 /* 0x04: I don't really know what this is. */
758 HOWTO (R_RTB, /* type */
760 2, /* size (0 = byte, 1 = short, 2 = long) */
762 FALSE, /* pc_relative */
764 complain_overflow_bitfield, /* complain_on_overflow */
765 0, /* special_function */
767 TRUE, /* partial_inplace */
768 0xffffffff, /* src_mask */
769 0xffffffff, /* dst_mask */
770 FALSE), /* pcrel_offset */
772 /* 0x05: External TOC relative symbol. */
773 HOWTO (R_GL, /* type */
775 1, /* size (0 = byte, 1 = short, 2 = long) */
777 FALSE, /* pc_relative */
779 complain_overflow_bitfield, /* complain_on_overflow */
780 0, /* special_function */
782 TRUE, /* partial_inplace */
783 0xffff, /* src_mask */
784 0xffff, /* dst_mask */
785 FALSE), /* pcrel_offset */
787 /* 0x06: Local TOC relative symbol. */
788 HOWTO (R_TCL, /* type */
790 1, /* size (0 = byte, 1 = short, 2 = long) */
792 FALSE, /* pc_relative */
794 complain_overflow_bitfield, /* complain_on_overflow */
795 0, /* special_function */
797 TRUE, /* partial_inplace */
798 0xffff, /* src_mask */
799 0xffff, /* dst_mask */
800 FALSE), /* pcrel_offset */
804 /* 0x08: Non modifiable absolute branch. */
805 HOWTO (R_BA, /* type */
807 2, /* size (0 = byte, 1 = short, 2 = long) */
809 FALSE, /* pc_relative */
811 complain_overflow_bitfield, /* complain_on_overflow */
812 0, /* special_function */
813 "R_BA_26", /* name */
814 TRUE, /* partial_inplace */
815 0x03fffffc, /* src_mask */
816 0x03fffffc, /* dst_mask */
817 FALSE), /* pcrel_offset */
821 /* 0x0a: Non modifiable relative branch. */
822 HOWTO (R_BR, /* type */
824 2, /* size (0 = byte, 1 = short, 2 = long) */
826 TRUE, /* pc_relative */
828 complain_overflow_signed, /* complain_on_overflow */
829 0, /* special_function */
831 TRUE, /* partial_inplace */
832 0x03fffffc, /* src_mask */
833 0x03fffffc, /* dst_mask */
834 FALSE), /* pcrel_offset */
838 /* 0x0c: Indirect load. */
839 HOWTO (R_RL, /* type */
841 1, /* size (0 = byte, 1 = short, 2 = long) */
843 FALSE, /* pc_relative */
845 complain_overflow_bitfield, /* complain_on_overflow */
846 0, /* special_function */
848 TRUE, /* partial_inplace */
849 0xffff, /* src_mask */
850 0xffff, /* dst_mask */
851 FALSE), /* pcrel_offset */
853 /* 0x0d: Load address. */
854 HOWTO (R_RLA, /* type */
856 1, /* size (0 = byte, 1 = short, 2 = long) */
858 FALSE, /* pc_relative */
860 complain_overflow_bitfield, /* complain_on_overflow */
861 0, /* special_function */
863 TRUE, /* partial_inplace */
864 0xffff, /* src_mask */
865 0xffff, /* dst_mask */
866 FALSE), /* pcrel_offset */
870 /* 0x0f: Non-relocating reference. Bitsize is 1 so that r_rsize is 0. */
871 HOWTO (R_REF, /* type */
873 0, /* size (0 = byte, 1 = short, 2 = long) */
875 FALSE, /* pc_relative */
877 complain_overflow_dont, /* complain_on_overflow */
878 0, /* special_function */
880 FALSE, /* partial_inplace */
883 FALSE), /* pcrel_offset */
888 /* 0x12: TOC relative indirect load. */
889 HOWTO (R_TRL, /* type */
891 1, /* size (0 = byte, 1 = short, 2 = long) */
893 FALSE, /* pc_relative */
895 complain_overflow_bitfield, /* complain_on_overflow */
896 0, /* special_function */
898 TRUE, /* partial_inplace */
899 0xffff, /* src_mask */
900 0xffff, /* dst_mask */
901 FALSE), /* pcrel_offset */
903 /* 0x13: TOC relative load address. */
904 HOWTO (R_TRLA, /* type */
906 1, /* size (0 = byte, 1 = short, 2 = long) */
908 FALSE, /* pc_relative */
910 complain_overflow_bitfield, /* complain_on_overflow */
911 0, /* special_function */
913 TRUE, /* partial_inplace */
914 0xffff, /* src_mask */
915 0xffff, /* dst_mask */
916 FALSE), /* pcrel_offset */
918 /* 0x14: Modifiable relative branch. */
919 HOWTO (R_RRTBI, /* type */
921 2, /* size (0 = byte, 1 = short, 2 = long) */
923 FALSE, /* pc_relative */
925 complain_overflow_bitfield, /* complain_on_overflow */
926 0, /* special_function */
927 "R_RRTBI", /* name */
928 TRUE, /* partial_inplace */
929 0xffffffff, /* src_mask */
930 0xffffffff, /* dst_mask */
931 FALSE), /* pcrel_offset */
933 /* 0x15: Modifiable absolute branch. */
934 HOWTO (R_RRTBA, /* type */
936 2, /* size (0 = byte, 1 = short, 2 = long) */
938 FALSE, /* pc_relative */
940 complain_overflow_bitfield, /* complain_on_overflow */
941 0, /* special_function */
942 "R_RRTBA", /* name */
943 TRUE, /* partial_inplace */
944 0xffffffff, /* src_mask */
945 0xffffffff, /* dst_mask */
946 FALSE), /* pcrel_offset */
948 /* 0x16: Modifiable call absolute indirect. */
949 HOWTO (R_CAI, /* type */
951 1, /* size (0 = byte, 1 = short, 2 = long) */
953 FALSE, /* pc_relative */
955 complain_overflow_bitfield, /* complain_on_overflow */
956 0, /* special_function */
958 TRUE, /* partial_inplace */
959 0xffff, /* src_mask */
960 0xffff, /* dst_mask */
961 FALSE), /* pcrel_offset */
963 /* 0x17: Modifiable call relative. */
964 HOWTO (R_CREL, /* type */
966 1, /* size (0 = byte, 1 = short, 2 = long) */
968 FALSE, /* pc_relative */
970 complain_overflow_bitfield, /* complain_on_overflow */
971 0, /* special_function */
973 TRUE, /* partial_inplace */
974 0xffff, /* src_mask */
975 0xffff, /* dst_mask */
976 FALSE), /* pcrel_offset */
978 /* 0x18: Modifiable branch absolute. */
979 HOWTO (R_RBA, /* type */
981 2, /* size (0 = byte, 1 = short, 2 = long) */
983 FALSE, /* pc_relative */
985 complain_overflow_bitfield, /* complain_on_overflow */
986 0, /* special_function */
988 TRUE, /* partial_inplace */
989 0x03fffffc, /* src_mask */
990 0x03fffffc, /* dst_mask */
991 FALSE), /* pcrel_offset */
993 /* 0x19: Modifiable branch absolute. */
994 HOWTO (R_RBAC, /* type */
996 2, /* size (0 = byte, 1 = short, 2 = long) */
998 FALSE, /* pc_relative */
1000 complain_overflow_bitfield, /* complain_on_overflow */
1001 0, /* special_function */
1002 "R_RBAC", /* name */
1003 TRUE, /* partial_inplace */
1004 0xffffffff, /* src_mask */
1005 0xffffffff, /* dst_mask */
1006 FALSE), /* pcrel_offset */
1008 /* 0x1a: Modifiable branch relative. */
1009 HOWTO (R_RBR, /* type */
1011 2, /* size (0 = byte, 1 = short, 2 = long) */
1013 FALSE, /* pc_relative */
1015 complain_overflow_signed, /* complain_on_overflow */
1016 0, /* special_function */
1017 "R_RBR_26", /* name */
1018 TRUE, /* partial_inplace */
1019 0x03fffffc, /* src_mask */
1020 0x03fffffc, /* dst_mask */
1021 FALSE), /* pcrel_offset */
1023 /* 0x1b: Modifiable branch absolute. */
1024 HOWTO (R_RBRC, /* type */
1026 1, /* size (0 = byte, 1 = short, 2 = long) */
1028 FALSE, /* pc_relative */
1030 complain_overflow_bitfield, /* complain_on_overflow */
1031 0, /* special_function */
1032 "R_RBRC", /* name */
1033 TRUE, /* partial_inplace */
1034 0xffff, /* src_mask */
1035 0xffff, /* dst_mask */
1036 FALSE), /* pcrel_offset */
1038 /* 0x1c: 16 bit Non modifiable absolute branch. */
1039 HOWTO (R_BA, /* type */
1041 1, /* size (0 = byte, 1 = short, 2 = long) */
1043 FALSE, /* pc_relative */
1045 complain_overflow_bitfield, /* complain_on_overflow */
1046 0, /* special_function */
1047 "R_BA_16", /* name */
1048 TRUE, /* partial_inplace */
1049 0xfffc, /* src_mask */
1050 0xfffc, /* dst_mask */
1051 FALSE), /* pcrel_offset */
1053 /* 0x1d: Modifiable branch relative. */
1054 HOWTO (R_RBR, /* type */
1056 1, /* size (0 = byte, 1 = short, 2 = long) */
1058 TRUE, /* pc_relative */
1060 complain_overflow_signed, /* complain_on_overflow */
1061 0, /* special_function */
1062 "R_RBR_16", /* name */
1063 TRUE, /* partial_inplace */
1064 0xfffc, /* src_mask */
1065 0xfffc, /* dst_mask */
1066 FALSE), /* pcrel_offset */
1068 /* 0x1e: Modifiable branch relative. */
1069 HOWTO (R_RBA, /* type */
1071 1, /* size (0 = byte, 1 = short, 2 = long) */
1073 FALSE, /* pc_relative */
1075 complain_overflow_signed, /* complain_on_overflow */
1076 0, /* special_function */
1077 "R_RBA_16", /* name */
1078 TRUE, /* partial_inplace */
1079 0xffff, /* src_mask */
1080 0xffff, /* dst_mask */
1081 FALSE), /* pcrel_offset */
1085 xcoff_rtype2howto (arelent *relent, struct internal_reloc *internal)
1087 if (internal->r_type > R_RBRC)
1090 /* Default howto layout works most of the time */
1091 relent->howto = &xcoff_howto_table[internal->r_type];
1093 /* Special case some 16 bit reloc */
1094 if (15 == (internal->r_size & 0x1f))
1096 if (R_BA == internal->r_type)
1097 relent->howto = &xcoff_howto_table[0x1c];
1098 else if (R_RBR == internal->r_type)
1099 relent->howto = &xcoff_howto_table[0x1d];
1100 else if (R_RBA == internal->r_type)
1101 relent->howto = &xcoff_howto_table[0x1e];
1104 /* The r_size field of an XCOFF reloc encodes the bitsize of the
1105 relocation, as well as indicating whether it is signed or not.
1106 Doublecheck that the relocation information gathered from the
1107 type matches this information. The bitsize is not significant
1108 for R_REF relocs. */
1109 if (relent->howto->dst_mask != 0
1110 && (relent->howto->bitsize
1111 != ((unsigned int) internal->r_size & 0x1f) + 1))
1116 _bfd_xcoff_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1117 bfd_reloc_code_real_type code)
1121 case BFD_RELOC_PPC_B26:
1122 return &xcoff_howto_table[0xa];
1123 case BFD_RELOC_PPC_BA16:
1124 return &xcoff_howto_table[0x1c];
1125 case BFD_RELOC_PPC_BA26:
1126 return &xcoff_howto_table[8];
1127 case BFD_RELOC_PPC_TOC16:
1128 return &xcoff_howto_table[3];
1130 /* Note that this relocation is only internally used by gas. */
1131 return &xcoff_howto_table[0xc];
1132 case BFD_RELOC_PPC_B16:
1133 return &xcoff_howto_table[0x1d];
1135 case BFD_RELOC_CTOR:
1136 return &xcoff_howto_table[0];
1137 case BFD_RELOC_NONE:
1138 return &xcoff_howto_table[0xf];
1144 static reloc_howto_type *
1145 _bfd_xcoff_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1151 i < sizeof (xcoff_howto_table) / sizeof (xcoff_howto_table[0]);
1153 if (xcoff_howto_table[i].name != NULL
1154 && strcasecmp (xcoff_howto_table[i].name, r_name) == 0)
1155 return &xcoff_howto_table[i];
1160 /* XCOFF archive support. The original version of this code was by
1161 Damon A. Permezel. It was enhanced to permit cross support, and
1162 writing archive files, by Ian Lance Taylor, Cygnus Support.
1164 XCOFF uses its own archive format. Everything is hooked together
1165 with file offset links, so it is possible to rapidly update an
1166 archive in place. Of course, we don't do that. An XCOFF archive
1167 has a real file header, not just an ARMAG string. The structure of
1168 the file header and of each archive header appear below.
1170 An XCOFF archive also has a member table, which is a list of
1171 elements in the archive (you can get that by looking through the
1172 linked list, but you have to read a lot more of the file). The
1173 member table has a normal archive header with an empty name. It is
1174 normally (and perhaps must be) the second to last entry in the
1175 archive. The member table data is almost printable ASCII. It
1176 starts with a 12 character decimal string which is the number of
1177 entries in the table. For each entry it has a 12 character decimal
1178 string which is the offset in the archive of that member. These
1179 entries are followed by a series of null terminated strings which
1180 are the member names for each entry.
1182 Finally, an XCOFF archive has a global symbol table, which is what
1183 we call the armap. The global symbol table has a normal archive
1184 header with an empty name. It is normally (and perhaps must be)
1185 the last entry in the archive. The contents start with a four byte
1186 binary number which is the number of entries. This is followed by
1187 a that many four byte binary numbers; each is the file offset of an
1188 entry in the archive. These numbers are followed by a series of
1189 null terminated strings, which are symbol names.
1191 AIX 4.3 introduced a new archive format which can handle larger
1192 files and also 32- and 64-bit objects in the same archive. The
1193 things said above remain true except that there is now more than
1194 one global symbol table. The one is used to index 32-bit objects,
1195 the other for 64-bit objects.
1197 The new archives (recognizable by the new ARMAG string) has larger
1198 field lengths so that we cannot really share any code. Also we have
1199 to take care that we are not generating the new form of archives
1200 on AIX 4.2 or earlier systems. */
1202 /* XCOFF archives use this as a magic string. Note that both strings
1203 have the same length. */
1205 /* Set the magic for archive. */
1208 bfd_xcoff_ar_archive_set_magic (bfd *abfd ATTRIBUTE_UNUSED,
1209 char *magic ATTRIBUTE_UNUSED)
1211 /* Not supported yet. */
1213 /* bfd_xcoff_archive_set_magic (abfd, magic); */
1216 /* Read in the armap of an XCOFF archive. */
1219 _bfd_xcoff_slurp_armap (bfd *abfd)
1224 bfd_byte *contents, *cend;
1229 if (xcoff_ardata (abfd) == NULL)
1231 bfd_has_map (abfd) = FALSE;
1235 if (! xcoff_big_format_p (abfd))
1237 /* This is for the old format. */
1238 struct xcoff_ar_hdr hdr;
1240 off = strtol (xcoff_ardata (abfd)->symoff, (char **) NULL, 10);
1243 bfd_has_map (abfd) = FALSE;
1247 if (bfd_seek (abfd, off, SEEK_SET) != 0)
1250 /* The symbol table starts with a normal archive header. */
1251 if (bfd_bread (&hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
1255 /* Skip the name (normally empty). */
1256 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1257 off = ((namlen + 1) & ~ (size_t) 1) + SXCOFFARFMAG;
1258 if (bfd_seek (abfd, off, SEEK_CUR) != 0)
1261 sz = strtol (hdr.size, (char **) NULL, 10);
1263 /* Read in the entire symbol table. */
1264 contents = (bfd_byte *) bfd_alloc (abfd, sz);
1265 if (contents == NULL)
1267 if (bfd_bread (contents, sz, abfd) != sz)
1270 /* The symbol table starts with a four byte count. */
1271 c = H_GET_32 (abfd, contents);
1275 bfd_set_error (bfd_error_bad_value);
1279 bfd_ardata (abfd)->symdefs =
1280 ((carsym *) bfd_alloc (abfd, c * sizeof (carsym)));
1281 if (bfd_ardata (abfd)->symdefs == NULL)
1284 /* After the count comes a list of four byte file offsets. */
1285 for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 4;
1287 ++i, ++arsym, p += 4)
1288 arsym->file_offset = H_GET_32 (abfd, p);
1292 /* This is for the new format. */
1293 struct xcoff_ar_hdr_big hdr;
1295 off = strtol (xcoff_ardata_big (abfd)->symoff, (char **) NULL, 10);
1298 bfd_has_map (abfd) = FALSE;
1302 if (bfd_seek (abfd, off, SEEK_SET) != 0)
1305 /* The symbol table starts with a normal archive header. */
1306 if (bfd_bread (&hdr, (bfd_size_type) SIZEOF_AR_HDR_BIG, abfd)
1307 != SIZEOF_AR_HDR_BIG)
1310 /* Skip the name (normally empty). */
1311 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1312 off = ((namlen + 1) & ~ (size_t) 1) + SXCOFFARFMAG;
1313 if (bfd_seek (abfd, off, SEEK_CUR) != 0)
1316 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1317 machines) since the field width is 20 and there numbers with more
1318 than 32 bits can be represented. */
1319 sz = strtol (hdr.size, (char **) NULL, 10);
1321 /* Read in the entire symbol table. */
1322 contents = (bfd_byte *) bfd_alloc (abfd, sz);
1323 if (contents == NULL)
1325 if (bfd_bread (contents, sz, abfd) != sz)
1328 /* The symbol table starts with an eight byte count. */
1329 c = H_GET_64 (abfd, contents);
1333 bfd_set_error (bfd_error_bad_value);
1337 bfd_ardata (abfd)->symdefs =
1338 ((carsym *) bfd_alloc (abfd, c * sizeof (carsym)));
1339 if (bfd_ardata (abfd)->symdefs == NULL)
1342 /* After the count comes a list of eight byte file offsets. */
1343 for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 8;
1345 ++i, ++arsym, p += 8)
1346 arsym->file_offset = H_GET_64 (abfd, p);
1349 /* After the file offsets come null terminated symbol names. */
1350 cend = contents + sz;
1351 for (i = 0, arsym = bfd_ardata (abfd)->symdefs;
1353 ++i, ++arsym, p += strlen ((char *) p) + 1)
1357 bfd_set_error (bfd_error_bad_value);
1360 arsym->name = (char *) p;
1363 bfd_ardata (abfd)->symdef_count = c;
1364 bfd_has_map (abfd) = TRUE;
1369 /* See if this is an XCOFF archive. */
1372 _bfd_xcoff_archive_p (bfd *abfd)
1374 struct artdata *tdata_hold;
1375 char magic[SXCOFFARMAG];
1376 bfd_size_type amt = SXCOFFARMAG;
1378 if (bfd_bread (magic, amt, abfd) != amt)
1380 if (bfd_get_error () != bfd_error_system_call)
1381 bfd_set_error (bfd_error_wrong_format);
1385 if (strncmp (magic, XCOFFARMAG, SXCOFFARMAG) != 0
1386 && strncmp (magic, XCOFFARMAGBIG, SXCOFFARMAG) != 0)
1388 bfd_set_error (bfd_error_wrong_format);
1392 tdata_hold = bfd_ardata (abfd);
1394 amt = sizeof (struct artdata);
1395 bfd_ardata (abfd) = (struct artdata *) bfd_zalloc (abfd, amt);
1396 if (bfd_ardata (abfd) == (struct artdata *) NULL)
1397 goto error_ret_restore;
1399 /* Cleared by bfd_zalloc above.
1400 bfd_ardata (abfd)->cache = NULL;
1401 bfd_ardata (abfd)->archive_head = NULL;
1402 bfd_ardata (abfd)->symdefs = NULL;
1403 bfd_ardata (abfd)->extended_names = NULL;
1404 bfd_ardata (abfd)->extended_names_size = 0; */
1406 /* Now handle the two formats. */
1407 if (magic[1] != 'b')
1409 /* This is the old format. */
1410 struct xcoff_ar_file_hdr hdr;
1412 /* Copy over the magic string. */
1413 memcpy (hdr.magic, magic, SXCOFFARMAG);
1415 /* Now read the rest of the file header. */
1416 amt = SIZEOF_AR_FILE_HDR - SXCOFFARMAG;
1417 if (bfd_bread (&hdr.memoff, amt, abfd) != amt)
1419 if (bfd_get_error () != bfd_error_system_call)
1420 bfd_set_error (bfd_error_wrong_format);
1424 bfd_ardata (abfd)->first_file_filepos = strtol (hdr.firstmemoff,
1425 (char **) NULL, 10);
1427 amt = SIZEOF_AR_FILE_HDR;
1428 bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, amt);
1429 if (bfd_ardata (abfd)->tdata == NULL)
1432 memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR);
1436 /* This is the new format. */
1437 struct xcoff_ar_file_hdr_big hdr;
1439 /* Copy over the magic string. */
1440 memcpy (hdr.magic, magic, SXCOFFARMAG);
1442 /* Now read the rest of the file header. */
1443 amt = SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG;
1444 if (bfd_bread (&hdr.memoff, amt, abfd) != amt)
1446 if (bfd_get_error () != bfd_error_system_call)
1447 bfd_set_error (bfd_error_wrong_format);
1451 bfd_ardata (abfd)->first_file_filepos = bfd_scan_vma (hdr.firstmemoff,
1455 amt = SIZEOF_AR_FILE_HDR_BIG;
1456 bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, amt);
1457 if (bfd_ardata (abfd)->tdata == NULL)
1460 memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR_BIG);
1463 if (! _bfd_xcoff_slurp_armap (abfd))
1466 bfd_release (abfd, bfd_ardata (abfd));
1468 bfd_ardata (abfd) = tdata_hold;
1475 /* Read the archive header in an XCOFF archive. */
1478 _bfd_xcoff_read_ar_hdr (bfd *abfd)
1480 bfd_size_type namlen;
1481 struct areltdata *ret;
1482 bfd_size_type amt = sizeof (struct areltdata);
1484 ret = (struct areltdata *) bfd_zmalloc (amt);
1488 if (! xcoff_big_format_p (abfd))
1490 struct xcoff_ar_hdr hdr;
1491 struct xcoff_ar_hdr *hdrp;
1493 if (bfd_bread (&hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
1500 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1501 amt = SIZEOF_AR_HDR + namlen + 1;
1502 hdrp = (struct xcoff_ar_hdr *) bfd_alloc (abfd, amt);
1508 memcpy (hdrp, &hdr, SIZEOF_AR_HDR);
1509 if (bfd_bread ((char *) hdrp + SIZEOF_AR_HDR, namlen, abfd) != namlen)
1514 ((char *) hdrp)[SIZEOF_AR_HDR + namlen] = '\0';
1516 ret->arch_header = (char *) hdrp;
1517 ret->parsed_size = strtol (hdr.size, (char **) NULL, 10);
1518 ret->filename = (char *) hdrp + SIZEOF_AR_HDR;
1522 struct xcoff_ar_hdr_big hdr;
1523 struct xcoff_ar_hdr_big *hdrp;
1525 if (bfd_bread (&hdr, (bfd_size_type) SIZEOF_AR_HDR_BIG, abfd)
1526 != SIZEOF_AR_HDR_BIG)
1532 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1533 amt = SIZEOF_AR_HDR_BIG + namlen + 1;
1534 hdrp = (struct xcoff_ar_hdr_big *) bfd_alloc (abfd, amt);
1540 memcpy (hdrp, &hdr, SIZEOF_AR_HDR_BIG);
1541 if (bfd_bread ((char *) hdrp + SIZEOF_AR_HDR_BIG, namlen, abfd) != namlen)
1546 ((char *) hdrp)[SIZEOF_AR_HDR_BIG + namlen] = '\0';
1548 ret->arch_header = (char *) hdrp;
1549 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1550 machines) since the field width is 20 and there numbers with more
1551 than 32 bits can be represented. */
1552 ret->parsed_size = strtol (hdr.size, (char **) NULL, 10);
1553 ret->filename = (char *) hdrp + SIZEOF_AR_HDR_BIG;
1556 /* Skip over the XCOFFARFMAG at the end of the file name. */
1557 if (bfd_seek (abfd, (file_ptr) ((namlen & 1) + SXCOFFARFMAG), SEEK_CUR) != 0)
1563 /* Open the next element in an XCOFF archive. */
1566 _bfd_xcoff_openr_next_archived_file (bfd *archive, bfd *last_file)
1570 if (xcoff_ardata (archive) == NULL)
1572 bfd_set_error (bfd_error_invalid_operation);
1576 if (! xcoff_big_format_p (archive))
1578 if (last_file == NULL)
1579 filestart = bfd_ardata (archive)->first_file_filepos;
1581 filestart = strtol (arch_xhdr (last_file)->nextoff, (char **) NULL,
1585 || filestart == strtol (xcoff_ardata (archive)->memoff,
1587 || filestart == strtol (xcoff_ardata (archive)->symoff,
1588 (char **) NULL, 10))
1590 bfd_set_error (bfd_error_no_more_archived_files);
1596 if (last_file == NULL)
1597 filestart = bfd_ardata (archive)->first_file_filepos;
1599 /* XXX These actually have to be a calls to strtoll (at least
1600 on 32-bit machines) since the fields's width is 20 and
1601 there numbers with more than 32 bits can be represented. */
1602 filestart = strtol (arch_xhdr_big (last_file)->nextoff, (char **) NULL,
1605 /* XXX These actually have to be calls to strtoll (at least on 32-bit
1606 machines) since the fields's width is 20 and there numbers with more
1607 than 32 bits can be represented. */
1609 || filestart == strtol (xcoff_ardata_big (archive)->memoff,
1611 || filestart == strtol (xcoff_ardata_big (archive)->symoff,
1612 (char **) NULL, 10))
1614 bfd_set_error (bfd_error_no_more_archived_files);
1619 return _bfd_get_elt_at_filepos (archive, filestart);
1622 /* Stat an element in an XCOFF archive. */
1625 _bfd_xcoff_stat_arch_elt (bfd *abfd, struct stat *s)
1627 if (abfd->arelt_data == NULL)
1629 bfd_set_error (bfd_error_invalid_operation);
1633 if (! xcoff_big_format_p (abfd->my_archive))
1635 struct xcoff_ar_hdr *hdrp = arch_xhdr (abfd);
1637 s->st_mtime = strtol (hdrp->date, (char **) NULL, 10);
1638 s->st_uid = strtol (hdrp->uid, (char **) NULL, 10);
1639 s->st_gid = strtol (hdrp->gid, (char **) NULL, 10);
1640 s->st_mode = strtol (hdrp->mode, (char **) NULL, 8);
1641 s->st_size = arch_eltdata (abfd)->parsed_size;
1645 struct xcoff_ar_hdr_big *hdrp = arch_xhdr_big (abfd);
1647 s->st_mtime = strtol (hdrp->date, (char **) NULL, 10);
1648 s->st_uid = strtol (hdrp->uid, (char **) NULL, 10);
1649 s->st_gid = strtol (hdrp->gid, (char **) NULL, 10);
1650 s->st_mode = strtol (hdrp->mode, (char **) NULL, 8);
1651 s->st_size = arch_eltdata (abfd)->parsed_size;
1657 /* Normalize a file name for inclusion in an archive. */
1660 normalize_filename (bfd *abfd)
1663 const char *filename;
1665 file = bfd_get_filename (abfd);
1666 filename = strrchr (file, '/');
1667 if (filename != NULL)
1674 /* Write out an XCOFF armap. */
1677 xcoff_write_armap_old (bfd *abfd, unsigned int elength ATTRIBUTE_UNUSED,
1678 struct orl *map, unsigned int orl_count, int stridx)
1680 struct archive_iterator iterator;
1681 struct xcoff_ar_hdr hdr;
1683 unsigned char buf[4];
1686 memset (&hdr, 0, sizeof hdr);
1687 sprintf (hdr.size, "%ld", (long) (4 + orl_count * 4 + stridx));
1688 sprintf (hdr.nextoff, "%d", 0);
1689 memcpy (hdr.prevoff, xcoff_ardata (abfd)->memoff, XCOFFARMAG_ELEMENT_SIZE);
1690 sprintf (hdr.date, "%d", 0);
1691 sprintf (hdr.uid, "%d", 0);
1692 sprintf (hdr.gid, "%d", 0);
1693 sprintf (hdr.mode, "%d", 0);
1694 sprintf (hdr.namlen, "%d", 0);
1696 /* We need spaces, not null bytes, in the header. */
1697 for (p = (char *) &hdr; p < (char *) &hdr + SIZEOF_AR_HDR; p++)
1701 if (bfd_bwrite (&hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
1703 || (bfd_bwrite (XCOFFARFMAG, (bfd_size_type) SXCOFFARFMAG, abfd)
1707 H_PUT_32 (abfd, orl_count, buf);
1708 if (bfd_bwrite (buf, (bfd_size_type) 4, abfd) != 4)
1712 archive_iterator_begin (&iterator, abfd);
1713 while (i < orl_count && archive_iterator_next (&iterator))
1714 while (map[i].u.abfd == iterator.current.member)
1716 H_PUT_32 (abfd, iterator.current.offset, buf);
1717 if (bfd_bwrite (buf, (bfd_size_type) 4, abfd) != 4)
1722 for (i = 0; i < orl_count; i++)
1727 name = *map[i].name;
1728 namlen = strlen (name);
1729 if (bfd_bwrite (name, (bfd_size_type) (namlen + 1), abfd) != namlen + 1)
1733 if ((stridx & 1) != 0)
1738 if (bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
1745 static char buff20[XCOFFARMAGBIG_ELEMENT_SIZE + 1];
1746 #define FMT20 "%-20lld"
1747 #define FMT12 "%-12d"
1748 #define FMT12_OCTAL "%-12o"
1750 #define PRINT20(d, v) \
1751 sprintf (buff20, FMT20, (long long)(v)), \
1752 memcpy ((void *) (d), buff20, 20)
1754 #define PRINT12(d, v) \
1755 sprintf (buff20, FMT12, (int)(v)), \
1756 memcpy ((void *) (d), buff20, 12)
1758 #define PRINT12_OCTAL(d, v) \
1759 sprintf (buff20, FMT12_OCTAL, (unsigned int)(v)), \
1760 memcpy ((void *) (d), buff20, 12)
1762 #define PRINT4(d, v) \
1763 sprintf (buff20, FMT4, (int)(v)), \
1764 memcpy ((void *) (d), buff20, 4)
1766 #define READ20(d, v) \
1768 memcpy (buff20, (d), 20), \
1769 (v) = bfd_scan_vma (buff20, (const char **) NULL, 10)
1772 do_pad (bfd *abfd, unsigned int number)
1776 /* Limit pad to <= 4096. */
1781 if (bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
1788 do_copy (bfd *out_bfd, bfd *in_bfd)
1790 bfd_size_type remaining;
1791 bfd_byte buffer[DEFAULT_BUFFERSIZE];
1793 if (bfd_seek (in_bfd, (file_ptr) 0, SEEK_SET) != 0)
1796 remaining = arelt_size (in_bfd);
1798 while (remaining >= DEFAULT_BUFFERSIZE)
1800 if (bfd_bread (buffer, DEFAULT_BUFFERSIZE, in_bfd) != DEFAULT_BUFFERSIZE
1801 || bfd_bwrite (buffer, DEFAULT_BUFFERSIZE, out_bfd) != DEFAULT_BUFFERSIZE)
1804 remaining -= DEFAULT_BUFFERSIZE;
1809 if (bfd_bread (buffer, remaining, in_bfd) != remaining
1810 || bfd_bwrite (buffer, remaining, out_bfd) != remaining)
1818 xcoff_write_armap_big (bfd *abfd, unsigned int elength ATTRIBUTE_UNUSED,
1819 struct orl *map, unsigned int orl_count, int stridx)
1821 struct archive_iterator iterator;
1822 struct xcoff_ar_file_hdr_big *fhdr;
1823 bfd_vma i, sym_32, sym_64, str_32, str_64;
1824 const bfd_arch_info_type *arch_info;
1826 size_t string_length;
1827 file_ptr nextoff, prevoff;
1829 /* First, we look through the symbols and work out which are
1830 from 32-bit objects and which from 64-bit ones. */
1831 sym_32 = sym_64 = str_32 = str_64 = 0;
1834 for (current_bfd = abfd->archive_head;
1835 current_bfd != NULL && i < orl_count;
1836 current_bfd = current_bfd->archive_next)
1838 arch_info = bfd_get_arch_info (current_bfd);
1839 while (map[i].u.abfd == current_bfd)
1841 string_length = strlen (*map[i].name) + 1;
1842 if (arch_info->bits_per_address == 64)
1845 str_64 += string_length;
1850 str_32 += string_length;
1856 /* A quick sanity check... */
1857 BFD_ASSERT (sym_64 + sym_32 == orl_count);
1858 /* Explicit cast to int for compiler. */
1859 BFD_ASSERT ((int)(str_64 + str_32) == stridx);
1861 fhdr = xcoff_ardata_big (abfd);
1863 /* xcoff_write_archive_contents_big passes nextoff in symoff. */
1864 READ20 (fhdr->memoff, prevoff);
1865 READ20 (fhdr->symoff, nextoff);
1867 BFD_ASSERT (nextoff == bfd_tell (abfd));
1869 /* Write out the symbol table.
1872 standard big archive header
1873 0x0000 ar_size [0x14]
1874 0x0014 ar_nxtmem [0x14]
1875 0x0028 ar_prvmem [0x14]
1876 0x003C ar_date [0x0C]
1877 0x0048 ar_uid [0x0C]
1878 0x0054 ar_gid [0x0C]
1879 0x0060 ar_mod [0x0C]
1880 0x006C ar_namelen[0x04]
1881 0x0070 ar_fmag [SXCOFFARFMAG]
1884 0x0072 num_syms [0x08], binary
1885 0x0078 offsets [0x08 * num_syms], binary
1886 0x0086 + 0x08 * num_syms names [??]
1887 ?? pad to even bytes.
1892 struct xcoff_ar_hdr_big *hdr;
1896 bfd_vma symbol_table_size =
1901 + str_32 + (str_32 & 1);
1903 symbol_table = bfd_zmalloc (symbol_table_size);
1904 if (symbol_table == NULL)
1907 hdr = (struct xcoff_ar_hdr_big *) symbol_table;
1909 PRINT20 (hdr->size, 8 + 8 * sym_32 + str_32 + (str_32 & 1));
1912 PRINT20 (hdr->nextoff, nextoff + symbol_table_size);
1914 PRINT20 (hdr->nextoff, 0);
1916 PRINT20 (hdr->prevoff, prevoff);
1917 PRINT12 (hdr->date, 0);
1918 PRINT12 (hdr->uid, 0);
1919 PRINT12 (hdr->gid, 0);
1920 PRINT12 (hdr->mode, 0);
1921 PRINT4 (hdr->namlen, 0) ;
1923 st = symbol_table + SIZEOF_AR_HDR_BIG;
1924 memcpy (st, XCOFFARFMAG, SXCOFFARFMAG);
1927 bfd_h_put_64 (abfd, sym_32, st);
1930 /* loop over the 32 bit offsets */
1932 archive_iterator_begin (&iterator, abfd);
1933 while (i < orl_count && archive_iterator_next (&iterator))
1935 arch_info = bfd_get_arch_info (iterator.current.member);
1936 while (map[i].u.abfd == iterator.current.member)
1938 if (arch_info->bits_per_address == 32)
1940 bfd_h_put_64 (abfd, iterator.current.offset, st);
1947 /* loop over the 32 bit symbol names */
1949 for (current_bfd = abfd->archive_head;
1950 current_bfd != NULL && i < orl_count;
1951 current_bfd = current_bfd->archive_next)
1953 arch_info = bfd_get_arch_info (current_bfd);
1954 while (map[i].u.abfd == current_bfd)
1956 if (arch_info->bits_per_address == 32)
1958 string_length = sprintf (st, "%s", *map[i].name);
1959 st += string_length + 1;
1965 bfd_bwrite (symbol_table, symbol_table_size, abfd);
1967 free (symbol_table);
1970 nextoff = nextoff + symbol_table_size;
1973 PRINT20 (fhdr->symoff, 0);
1977 struct xcoff_ar_hdr_big *hdr;
1981 bfd_vma symbol_table_size =
1986 + str_64 + (str_64 & 1);
1988 symbol_table = bfd_zmalloc (symbol_table_size);
1989 if (symbol_table == NULL)
1992 hdr = (struct xcoff_ar_hdr_big *) symbol_table;
1994 PRINT20 (hdr->size, 8 + 8 * sym_64 + str_64 + (str_64 & 1));
1995 PRINT20 (hdr->nextoff, 0);
1996 PRINT20 (hdr->prevoff, prevoff);
1997 PRINT12 (hdr->date, 0);
1998 PRINT12 (hdr->uid, 0);
1999 PRINT12 (hdr->gid, 0);
2000 PRINT12 (hdr->mode, 0);
2001 PRINT4 (hdr->namlen, 0);
2003 st = symbol_table + SIZEOF_AR_HDR_BIG;
2004 memcpy (st, XCOFFARFMAG, SXCOFFARFMAG);
2007 bfd_h_put_64 (abfd, sym_64, st);
2010 /* loop over the 64 bit offsets */
2012 archive_iterator_begin (&iterator, abfd);
2013 while (i < orl_count && archive_iterator_next (&iterator))
2015 arch_info = bfd_get_arch_info (iterator.current.member);
2016 while (map[i].u.abfd == iterator.current.member)
2018 if (arch_info->bits_per_address == 64)
2020 bfd_h_put_64 (abfd, iterator.current.offset, st);
2027 /* loop over the 64 bit symbol names */
2029 for (current_bfd = abfd->archive_head;
2030 current_bfd != NULL && i < orl_count;
2031 current_bfd = current_bfd->archive_next)
2033 arch_info = bfd_get_arch_info (current_bfd);
2034 while (map[i].u.abfd == current_bfd)
2036 if (arch_info->bits_per_address == 64)
2038 string_length = sprintf (st, "%s", *map[i].name);
2039 st += string_length + 1;
2045 bfd_bwrite (symbol_table, symbol_table_size, abfd);
2047 free (symbol_table);
2049 PRINT20 (fhdr->symoff64, nextoff);
2052 PRINT20 (fhdr->symoff64, 0);
2058 _bfd_xcoff_write_armap (bfd *abfd, unsigned int elength ATTRIBUTE_UNUSED,
2059 struct orl *map, unsigned int orl_count, int stridx)
2061 if (! xcoff_big_format_p (abfd))
2062 return xcoff_write_armap_old (abfd, elength, map, orl_count, stridx);
2064 return xcoff_write_armap_big (abfd, elength, map, orl_count, stridx);
2067 /* Write out an XCOFF archive. We always write an entire archive,
2068 rather than fussing with the freelist and so forth. */
2071 xcoff_write_archive_contents_old (bfd *abfd)
2073 struct archive_iterator iterator;
2074 struct xcoff_ar_file_hdr fhdr;
2075 bfd_size_type count;
2076 bfd_size_type total_namlen;
2078 bfd_boolean makemap;
2079 bfd_boolean hasobjects;
2080 file_ptr prevoff, nextoff;
2083 struct xcoff_ar_hdr ahdr;
2086 char decbuf[XCOFFARMAG_ELEMENT_SIZE + 1];
2088 memset (&fhdr, 0, sizeof fhdr);
2089 (void) strncpy (fhdr.magic, XCOFFARMAG, SXCOFFARMAG);
2090 sprintf (fhdr.firstmemoff, "%d", SIZEOF_AR_FILE_HDR);
2091 sprintf (fhdr.freeoff, "%d", 0);
2095 for (sub = abfd->archive_head; sub != NULL; sub = sub->archive_next)
2098 total_namlen += strlen (normalize_filename (sub)) + 1;
2099 if (sub->arelt_data == NULL)
2101 sub->arelt_data = bfd_zmalloc (sizeof (struct areltdata));
2102 if (sub->arelt_data == NULL)
2105 if (arch_xhdr (sub) == NULL)
2107 struct xcoff_ar_hdr *ahdrp;
2110 if (stat (bfd_get_filename (sub), &s) != 0)
2112 bfd_set_error (bfd_error_system_call);
2116 ahdrp = bfd_zalloc (sub, sizeof (*ahdrp));
2120 sprintf (ahdrp->size, "%ld", (long) s.st_size);
2121 sprintf (ahdrp->date, "%ld", (long) s.st_mtime);
2122 sprintf (ahdrp->uid, "%ld", (long) s.st_uid);
2123 sprintf (ahdrp->gid, "%ld", (long) s.st_gid);
2124 sprintf (ahdrp->mode, "%o", (unsigned int) s.st_mode);
2126 arch_eltdata (sub)->arch_header = (char *) ahdrp;
2127 arch_eltdata (sub)->parsed_size = s.st_size;
2130 offsets = (file_ptr *) bfd_alloc (abfd, count * sizeof (file_ptr));
2131 if (offsets == NULL)
2134 if (bfd_seek (abfd, (file_ptr) SIZEOF_AR_FILE_HDR, SEEK_SET) != 0)
2137 makemap = bfd_has_map (abfd);
2140 for (archive_iterator_begin (&iterator, abfd), i = 0;
2141 archive_iterator_next (&iterator);
2144 bfd_size_type namlen;
2145 struct xcoff_ar_hdr *ahdrp;
2147 if (makemap && ! hasobjects)
2149 if (bfd_check_format (iterator.current.member, bfd_object))
2153 ahdrp = arch_xhdr (iterator.current.member);
2154 sprintf (ahdrp->prevoff, "%ld", (long) prevoff);
2155 sprintf (ahdrp->namlen, "%ld", (long) iterator.current.namlen);
2156 sprintf (ahdrp->nextoff, "%ld", (long) iterator.next.offset);
2158 /* We need spaces, not null bytes, in the header. */
2159 for (p = (char *) ahdrp; p < (char *) ahdrp + SIZEOF_AR_HDR; p++)
2163 if (!do_pad (abfd, iterator.current.leading_padding))
2166 BFD_ASSERT (iterator.current.offset == bfd_tell (abfd));
2167 namlen = iterator.current.padded_namlen;
2168 if (bfd_bwrite (ahdrp, SIZEOF_AR_HDR, abfd) != SIZEOF_AR_HDR
2169 || bfd_bwrite (iterator.current.name, namlen, abfd) != namlen
2170 || bfd_bwrite (XCOFFARFMAG, SXCOFFARFMAG, abfd) != SXCOFFARFMAG
2171 || bfd_seek (iterator.current.member, 0, SEEK_SET) != 0
2172 || !do_copy (abfd, iterator.current.member)
2173 || !do_pad (abfd, iterator.current.trailing_padding))
2176 offsets[i] = iterator.current.offset;
2177 prevoff = iterator.current.offset;
2180 sprintf (fhdr.lastmemoff, "%ld", (long) prevoff);
2182 /* Write out the member table. */
2184 nextoff = iterator.next.offset;
2185 BFD_ASSERT (nextoff == bfd_tell (abfd));
2186 sprintf (fhdr.memoff, "%ld", (long) nextoff);
2188 memset (&ahdr, 0, sizeof ahdr);
2189 sprintf (ahdr.size, "%ld", (long) (XCOFFARMAG_ELEMENT_SIZE
2190 + count * XCOFFARMAG_ELEMENT_SIZE
2192 sprintf (ahdr.prevoff, "%ld", (long) prevoff);
2193 sprintf (ahdr.date, "%d", 0);
2194 sprintf (ahdr.uid, "%d", 0);
2195 sprintf (ahdr.gid, "%d", 0);
2196 sprintf (ahdr.mode, "%d", 0);
2197 sprintf (ahdr.namlen, "%d", 0);
2199 size = (SIZEOF_AR_HDR
2200 + XCOFFARMAG_ELEMENT_SIZE
2201 + count * XCOFFARMAG_ELEMENT_SIZE
2206 nextoff += size + (size & 1);
2208 if (makemap && hasobjects)
2209 sprintf (ahdr.nextoff, "%ld", (long) nextoff);
2211 sprintf (ahdr.nextoff, "%d", 0);
2213 /* We need spaces, not null bytes, in the header. */
2214 for (p = (char *) &ahdr; p < (char *) &ahdr + SIZEOF_AR_HDR; p++)
2218 if ((bfd_bwrite (&ahdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
2220 || (bfd_bwrite (XCOFFARFMAG, (bfd_size_type) SXCOFFARFMAG, abfd)
2224 sprintf (decbuf, "%-12ld", (long) count);
2225 if (bfd_bwrite (decbuf, (bfd_size_type) XCOFFARMAG_ELEMENT_SIZE, abfd)
2226 != XCOFFARMAG_ELEMENT_SIZE)
2228 for (i = 0; i < (size_t) count; i++)
2230 sprintf (decbuf, "%-12ld", (long) offsets[i]);
2231 if (bfd_bwrite (decbuf, (bfd_size_type) XCOFFARMAG_ELEMENT_SIZE,
2232 abfd) != XCOFFARMAG_ELEMENT_SIZE)
2235 for (sub = abfd->archive_head; sub != NULL; sub = sub->archive_next)
2238 bfd_size_type namlen;
2240 name = normalize_filename (sub);
2241 namlen = strlen (name);
2242 if (bfd_bwrite (name, namlen + 1, abfd) != namlen + 1)
2246 if (! do_pad (abfd, size & 1))
2249 /* Write out the armap, if appropriate. */
2250 if (! makemap || ! hasobjects)
2251 sprintf (fhdr.symoff, "%d", 0);
2254 BFD_ASSERT (nextoff == bfd_tell (abfd));
2255 sprintf (fhdr.symoff, "%ld", (long) nextoff);
2256 bfd_ardata (abfd)->tdata = &fhdr;
2257 if (! _bfd_compute_and_write_armap (abfd, 0))
2261 /* Write out the archive file header. */
2263 /* We need spaces, not null bytes, in the header. */
2264 for (p = (char *) &fhdr; p < (char *) &fhdr + SIZEOF_AR_FILE_HDR; p++)
2268 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
2269 || (bfd_bwrite (&fhdr, (bfd_size_type) SIZEOF_AR_FILE_HDR, abfd)
2270 != SIZEOF_AR_FILE_HDR))
2277 xcoff_write_archive_contents_big (bfd *abfd)
2279 struct xcoff_ar_file_hdr_big fhdr;
2280 bfd_size_type count;
2281 bfd_size_type total_namlen;
2283 bfd_boolean makemap;
2284 bfd_boolean hasobjects;
2285 file_ptr prevoff, nextoff;
2288 struct xcoff_ar_hdr_big *hdr;
2290 char *member_table, *mt;
2291 bfd_vma member_table_size;
2292 struct archive_iterator iterator;
2294 memset (&fhdr, 0, SIZEOF_AR_FILE_HDR_BIG);
2295 memcpy (fhdr.magic, XCOFFARMAGBIG, SXCOFFARMAG);
2297 if (bfd_seek (abfd, (file_ptr) SIZEOF_AR_FILE_HDR_BIG, SEEK_SET) != 0)
2300 /* Calculate count and total_namlen. */
2301 makemap = bfd_has_map (abfd);
2303 for (current_bfd = abfd->archive_head, count = 0, total_namlen = 0;
2304 current_bfd != NULL;
2305 current_bfd = current_bfd->archive_next, count++)
2307 total_namlen += strlen (normalize_filename (current_bfd)) + 1;
2311 && bfd_check_format (current_bfd, bfd_object))
2314 if (current_bfd->arelt_data == NULL)
2316 size = sizeof (struct areltdata);
2317 current_bfd->arelt_data = bfd_zmalloc (size);
2318 if (current_bfd->arelt_data == NULL)
2322 if (arch_xhdr_big (current_bfd) == NULL)
2324 struct xcoff_ar_hdr_big *ahdrp;
2327 /* XXX This should actually be a call to stat64 (at least on
2329 XXX This call will fail if the original object is not found. */
2330 if (stat (bfd_get_filename (current_bfd), &s) != 0)
2332 bfd_set_error (bfd_error_system_call);
2336 ahdrp = bfd_zalloc (current_bfd, sizeof (*ahdrp));
2340 PRINT20 (ahdrp->size, s.st_size);
2341 PRINT12 (ahdrp->date, s.st_mtime);
2342 PRINT12 (ahdrp->uid, s.st_uid);
2343 PRINT12 (ahdrp->gid, s.st_gid);
2344 PRINT12_OCTAL (ahdrp->mode, s.st_mode);
2346 arch_eltdata (current_bfd)->arch_header = (char *) ahdrp;
2347 arch_eltdata (current_bfd)->parsed_size = s.st_size;
2354 offsets = (file_ptr *) bfd_malloc (count * sizeof (file_ptr));
2355 if (offsets == NULL)
2360 for (archive_iterator_begin (&iterator, abfd), i = 0;
2361 archive_iterator_next (&iterator);
2364 bfd_size_type namlen;
2365 struct xcoff_ar_hdr_big *ahdrp;
2367 ahdrp = arch_xhdr_big (iterator.current.member);
2368 PRINT20 (ahdrp->prevoff, prevoff);
2369 PRINT4 (ahdrp->namlen, iterator.current.namlen);
2370 PRINT20 (ahdrp->nextoff, iterator.next.offset);
2372 if (!do_pad (abfd, iterator.current.leading_padding))
2378 BFD_ASSERT (iterator.current.offset == bfd_tell (abfd));
2379 namlen = iterator.current.padded_namlen;
2380 if (bfd_bwrite (ahdrp, SIZEOF_AR_HDR_BIG, abfd) != SIZEOF_AR_HDR_BIG
2381 || bfd_bwrite (iterator.current.name, namlen, abfd) != namlen
2382 || bfd_bwrite (XCOFFARFMAG, SXCOFFARFMAG, abfd) != SXCOFFARFMAG
2383 || bfd_seek (iterator.current.member, 0, SEEK_SET) != 0
2384 || !do_copy (abfd, iterator.current.member)
2385 || !do_pad (abfd, iterator.current.trailing_padding))
2391 offsets[i] = iterator.current.offset;
2392 prevoff = iterator.current.offset;
2397 PRINT20 (fhdr.firstmemoff, offsets[0]);
2398 PRINT20 (fhdr.lastmemoff, prevoff);
2401 /* Write out the member table.
2404 standard big archive header
2405 0x0000 ar_size [0x14]
2406 0x0014 ar_nxtmem [0x14]
2407 0x0028 ar_prvmem [0x14]
2408 0x003C ar_date [0x0C]
2409 0x0048 ar_uid [0x0C]
2410 0x0054 ar_gid [0x0C]
2411 0x0060 ar_mod [0x0C]
2412 0x006C ar_namelen[0x04]
2413 0x0070 ar_fmag [0x02]
2417 0x0086 offsets [0x14 * counts]
2418 0x0086 + 0x14 * counts names [??]
2419 ?? pad to even bytes.
2422 nextoff = iterator.next.offset;
2423 BFD_ASSERT (nextoff == bfd_tell (abfd));
2425 member_table_size = (SIZEOF_AR_HDR_BIG
2427 + XCOFFARMAGBIG_ELEMENT_SIZE
2428 + count * XCOFFARMAGBIG_ELEMENT_SIZE
2431 member_table_size += member_table_size & 1;
2432 member_table = bfd_zmalloc (member_table_size);
2433 if (member_table == NULL)
2439 hdr = (struct xcoff_ar_hdr_big *) member_table;
2441 PRINT20 (hdr->size, (XCOFFARMAGBIG_ELEMENT_SIZE
2442 + count * XCOFFARMAGBIG_ELEMENT_SIZE
2443 + total_namlen + (total_namlen & 1)));
2444 if (makemap && hasobjects)
2445 PRINT20 (hdr->nextoff, nextoff + member_table_size);
2447 PRINT20 (hdr->nextoff, 0);
2448 PRINT20 (hdr->prevoff, prevoff);
2449 PRINT12 (hdr->date, 0);
2450 PRINT12 (hdr->uid, 0);
2451 PRINT12 (hdr->gid, 0);
2452 PRINT12 (hdr->mode, 0);
2453 PRINT4 (hdr->namlen, 0);
2455 mt = member_table + SIZEOF_AR_HDR_BIG;
2456 memcpy (mt, XCOFFARFMAG, SXCOFFARFMAG);
2459 PRINT20 (mt, count);
2460 mt += XCOFFARMAGBIG_ELEMENT_SIZE;
2461 for (i = 0; i < (size_t) count; i++)
2463 PRINT20 (mt, offsets[i]);
2464 mt += XCOFFARMAGBIG_ELEMENT_SIZE;
2473 for (current_bfd = abfd->archive_head;
2474 current_bfd != NULL;
2475 current_bfd = current_bfd->archive_next)
2480 name = normalize_filename (current_bfd);
2481 namlen = sprintf (mt, "%s", name);
2485 if (bfd_bwrite (member_table, member_table_size, abfd) != member_table_size)
2488 free (member_table);
2490 PRINT20 (fhdr.memoff, nextoff);
2493 nextoff += member_table_size;
2495 /* Write out the armap, if appropriate. */
2497 if (! makemap || ! hasobjects)
2498 PRINT20 (fhdr.symoff, 0);
2501 BFD_ASSERT (nextoff == bfd_tell (abfd));
2503 /* Save nextoff in fhdr.symoff so the armap routine can use it. */
2504 PRINT20 (fhdr.symoff, nextoff);
2506 bfd_ardata (abfd)->tdata = &fhdr;
2507 if (! _bfd_compute_and_write_armap (abfd, 0))
2511 /* Write out the archive file header. */
2513 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
2514 || (bfd_bwrite (&fhdr, (bfd_size_type) SIZEOF_AR_FILE_HDR_BIG,
2515 abfd) != SIZEOF_AR_FILE_HDR_BIG))
2522 _bfd_xcoff_write_archive_contents (bfd *abfd)
2524 if (! xcoff_big_format_p (abfd))
2525 return xcoff_write_archive_contents_old (abfd);
2527 return xcoff_write_archive_contents_big (abfd);
2530 /* We can't use the usual coff_sizeof_headers routine, because AIX
2531 always uses an a.out header. */
2534 _bfd_xcoff_sizeof_headers (bfd *abfd,
2535 struct bfd_link_info *info ATTRIBUTE_UNUSED)
2540 if (xcoff_data (abfd)->full_aouthdr)
2543 size += SMALL_AOUTSZ;
2544 size += abfd->section_count * SCNHSZ;
2546 if (info->strip != strip_all)
2548 /* There can be additional sections just for dealing with overflow in
2549 reloc and lineno counts. But the numbers of relocs and lineno aren't
2550 known when bfd_sizeof_headers is called, so we compute them by
2551 summing the numbers from input sections. */
2552 struct nbr_reloc_lineno
2554 unsigned int reloc_count;
2555 unsigned int lineno_count;
2557 struct nbr_reloc_lineno *n_rl;
2562 /* Although the number of sections is known, the maximum value of
2563 section->index isn't (because some sections may have been removed).
2564 Don't try to renumber sections, just compute the upper bound. */
2566 for (s = abfd->sections; s != NULL; s = s->next)
2567 if (s->index > max_index)
2568 max_index = s->index;
2570 /* Allocate the per section counters. It could be possible to use a
2571 preallocated array as the number of sections is limited on XCOFF,
2572 but this creates a maintainance issue. */
2573 n_rl = bfd_zmalloc ((max_index + 1) * sizeof (*n_rl));
2578 for (sub = info->input_bfds; sub != NULL; sub = sub->link.next)
2579 for (s = sub->sections; s != NULL; s = s->next)
2581 struct nbr_reloc_lineno *e = &n_rl[s->output_section->index];
2582 e->reloc_count += s->reloc_count;
2583 e->lineno_count += s->lineno_count;
2586 /* Add the size of a section for each section with an overflow. */
2587 for (s = abfd->sections; s != NULL; s = s->next)
2589 struct nbr_reloc_lineno *e = &n_rl[s->index];
2591 if (e->reloc_count >= 0xffff
2592 || (e->lineno_count >= 0xffff && info->strip != strip_debugger))
2602 /* Routines to swap information in the XCOFF .loader section. If we
2603 ever need to write an XCOFF loader, this stuff will need to be
2604 moved to another file shared by the linker (which XCOFF calls the
2605 ``binder'') and the loader. */
2607 /* Swap in the ldhdr structure. */
2610 xcoff_swap_ldhdr_in (bfd *abfd, const void * s, struct internal_ldhdr *dst)
2612 const struct external_ldhdr *src = (const struct external_ldhdr *) s;
2614 dst->l_version = bfd_get_32 (abfd, src->l_version);
2615 dst->l_nsyms = bfd_get_32 (abfd, src->l_nsyms);
2616 dst->l_nreloc = bfd_get_32 (abfd, src->l_nreloc);
2617 dst->l_istlen = bfd_get_32 (abfd, src->l_istlen);
2618 dst->l_nimpid = bfd_get_32 (abfd, src->l_nimpid);
2619 dst->l_impoff = bfd_get_32 (abfd, src->l_impoff);
2620 dst->l_stlen = bfd_get_32 (abfd, src->l_stlen);
2621 dst->l_stoff = bfd_get_32 (abfd, src->l_stoff);
2624 /* Swap out the ldhdr structure. */
2627 xcoff_swap_ldhdr_out (bfd *abfd, const struct internal_ldhdr *src, void * d)
2629 struct external_ldhdr *dst = (struct external_ldhdr *) d;
2631 bfd_put_32 (abfd, (bfd_vma) src->l_version, dst->l_version);
2632 bfd_put_32 (abfd, src->l_nsyms, dst->l_nsyms);
2633 bfd_put_32 (abfd, src->l_nreloc, dst->l_nreloc);
2634 bfd_put_32 (abfd, src->l_istlen, dst->l_istlen);
2635 bfd_put_32 (abfd, src->l_nimpid, dst->l_nimpid);
2636 bfd_put_32 (abfd, src->l_impoff, dst->l_impoff);
2637 bfd_put_32 (abfd, src->l_stlen, dst->l_stlen);
2638 bfd_put_32 (abfd, src->l_stoff, dst->l_stoff);
2641 /* Swap in the ldsym structure. */
2644 xcoff_swap_ldsym_in (bfd *abfd, const void * s, struct internal_ldsym *dst)
2646 const struct external_ldsym *src = (const struct external_ldsym *) s;
2648 if (bfd_get_32 (abfd, src->_l._l_l._l_zeroes) != 0) {
2649 memcpy (dst->_l._l_name, src->_l._l_name, SYMNMLEN);
2651 dst->_l._l_l._l_zeroes = 0;
2652 dst->_l._l_l._l_offset = bfd_get_32 (abfd, src->_l._l_l._l_offset);
2654 dst->l_value = bfd_get_32 (abfd, src->l_value);
2655 dst->l_scnum = bfd_get_16 (abfd, src->l_scnum);
2656 dst->l_smtype = bfd_get_8 (abfd, src->l_smtype);
2657 dst->l_smclas = bfd_get_8 (abfd, src->l_smclas);
2658 dst->l_ifile = bfd_get_32 (abfd, src->l_ifile);
2659 dst->l_parm = bfd_get_32 (abfd, src->l_parm);
2662 /* Swap out the ldsym structure. */
2665 xcoff_swap_ldsym_out (bfd *abfd, const struct internal_ldsym *src, void * d)
2667 struct external_ldsym *dst = (struct external_ldsym *) d;
2669 if (src->_l._l_l._l_zeroes != 0)
2670 memcpy (dst->_l._l_name, src->_l._l_name, SYMNMLEN);
2673 bfd_put_32 (abfd, (bfd_vma) 0, dst->_l._l_l._l_zeroes);
2674 bfd_put_32 (abfd, (bfd_vma) src->_l._l_l._l_offset,
2675 dst->_l._l_l._l_offset);
2677 bfd_put_32 (abfd, src->l_value, dst->l_value);
2678 bfd_put_16 (abfd, (bfd_vma) src->l_scnum, dst->l_scnum);
2679 bfd_put_8 (abfd, src->l_smtype, dst->l_smtype);
2680 bfd_put_8 (abfd, src->l_smclas, dst->l_smclas);
2681 bfd_put_32 (abfd, src->l_ifile, dst->l_ifile);
2682 bfd_put_32 (abfd, src->l_parm, dst->l_parm);
2686 xcoff_swap_reloc_in (bfd *abfd, void * s, void * d)
2688 struct external_reloc *src = (struct external_reloc *) s;
2689 struct internal_reloc *dst = (struct internal_reloc *) d;
2691 memset (dst, 0, sizeof (struct internal_reloc));
2693 dst->r_vaddr = bfd_get_32 (abfd, src->r_vaddr);
2694 dst->r_symndx = bfd_get_32 (abfd, src->r_symndx);
2695 dst->r_size = bfd_get_8 (abfd, src->r_size);
2696 dst->r_type = bfd_get_8 (abfd, src->r_type);
2700 xcoff_swap_reloc_out (bfd *abfd, void * s, void * d)
2702 struct internal_reloc *src = (struct internal_reloc *) s;
2703 struct external_reloc *dst = (struct external_reloc *) d;
2705 bfd_put_32 (abfd, src->r_vaddr, dst->r_vaddr);
2706 bfd_put_32 (abfd, src->r_symndx, dst->r_symndx);
2707 bfd_put_8 (abfd, src->r_type, dst->r_type);
2708 bfd_put_8 (abfd, src->r_size, dst->r_size);
2710 return bfd_coff_relsz (abfd);
2713 /* Swap in the ldrel structure. */
2716 xcoff_swap_ldrel_in (bfd *abfd, const void * s, struct internal_ldrel *dst)
2718 const struct external_ldrel *src = (const struct external_ldrel *) s;
2720 dst->l_vaddr = bfd_get_32 (abfd, src->l_vaddr);
2721 dst->l_symndx = bfd_get_32 (abfd, src->l_symndx);
2722 dst->l_rtype = bfd_get_16 (abfd, src->l_rtype);
2723 dst->l_rsecnm = bfd_get_16 (abfd, src->l_rsecnm);
2726 /* Swap out the ldrel structure. */
2729 xcoff_swap_ldrel_out (bfd *abfd, const struct internal_ldrel *src, void * d)
2731 struct external_ldrel *dst = (struct external_ldrel *) d;
2733 bfd_put_32 (abfd, src->l_vaddr, dst->l_vaddr);
2734 bfd_put_32 (abfd, src->l_symndx, dst->l_symndx);
2735 bfd_put_16 (abfd, (bfd_vma) src->l_rtype, dst->l_rtype);
2736 bfd_put_16 (abfd, (bfd_vma) src->l_rsecnm, dst->l_rsecnm);
2741 xcoff_reloc_type_noop (bfd *input_bfd ATTRIBUTE_UNUSED,
2742 asection *input_section ATTRIBUTE_UNUSED,
2743 bfd *output_bfd ATTRIBUTE_UNUSED,
2744 struct internal_reloc *rel ATTRIBUTE_UNUSED,
2745 struct internal_syment *sym ATTRIBUTE_UNUSED,
2746 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED,
2747 bfd_vma val ATTRIBUTE_UNUSED,
2748 bfd_vma addend ATTRIBUTE_UNUSED,
2749 bfd_vma *relocation ATTRIBUTE_UNUSED,
2750 bfd_byte *contents ATTRIBUTE_UNUSED)
2756 xcoff_reloc_type_fail (bfd *input_bfd,
2757 asection *input_section ATTRIBUTE_UNUSED,
2758 bfd *output_bfd ATTRIBUTE_UNUSED,
2759 struct internal_reloc *rel,
2760 struct internal_syment *sym ATTRIBUTE_UNUSED,
2761 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED,
2762 bfd_vma val ATTRIBUTE_UNUSED,
2763 bfd_vma addend ATTRIBUTE_UNUSED,
2764 bfd_vma *relocation ATTRIBUTE_UNUSED,
2765 bfd_byte *contents ATTRIBUTE_UNUSED)
2767 (*_bfd_error_handler)
2768 (_("%s: unsupported relocation type 0x%02x"),
2769 bfd_get_filename (input_bfd), (unsigned int) rel->r_type);
2770 bfd_set_error (bfd_error_bad_value);
2775 xcoff_reloc_type_pos (bfd *input_bfd ATTRIBUTE_UNUSED,
2776 asection *input_section ATTRIBUTE_UNUSED,
2777 bfd *output_bfd ATTRIBUTE_UNUSED,
2778 struct internal_reloc *rel ATTRIBUTE_UNUSED,
2779 struct internal_syment *sym ATTRIBUTE_UNUSED,
2780 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED,
2783 bfd_vma *relocation,
2784 bfd_byte *contents ATTRIBUTE_UNUSED)
2786 *relocation = val + addend;
2791 xcoff_reloc_type_neg (bfd *input_bfd ATTRIBUTE_UNUSED,
2792 asection *input_section ATTRIBUTE_UNUSED,
2793 bfd *output_bfd ATTRIBUTE_UNUSED,
2794 struct internal_reloc *rel ATTRIBUTE_UNUSED,
2795 struct internal_syment *sym ATTRIBUTE_UNUSED,
2796 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED,
2799 bfd_vma *relocation,
2800 bfd_byte *contents ATTRIBUTE_UNUSED)
2802 *relocation = addend - val;
2807 xcoff_reloc_type_rel (bfd *input_bfd ATTRIBUTE_UNUSED,
2808 asection *input_section,
2809 bfd *output_bfd ATTRIBUTE_UNUSED,
2810 struct internal_reloc *rel ATTRIBUTE_UNUSED,
2811 struct internal_syment *sym ATTRIBUTE_UNUSED,
2812 struct reloc_howto_struct *howto,
2815 bfd_vma *relocation,
2816 bfd_byte *contents ATTRIBUTE_UNUSED)
2818 howto->pc_relative = TRUE;
2820 /* A PC relative reloc includes the section address. */
2821 addend += input_section->vma;
2823 *relocation = val + addend;
2824 *relocation -= (input_section->output_section->vma
2825 + input_section->output_offset);
2830 xcoff_reloc_type_toc (bfd *input_bfd,
2831 asection *input_section ATTRIBUTE_UNUSED,
2833 struct internal_reloc *rel,
2834 struct internal_syment *sym,
2835 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED,
2837 bfd_vma addend ATTRIBUTE_UNUSED,
2838 bfd_vma *relocation,
2839 bfd_byte *contents ATTRIBUTE_UNUSED)
2841 struct xcoff_link_hash_entry *h;
2843 if (0 > rel->r_symndx)
2846 h = obj_xcoff_sym_hashes (input_bfd)[rel->r_symndx];
2848 if (h != NULL && h->smclas != XMC_TD)
2850 if (h->toc_section == NULL)
2852 (*_bfd_error_handler)
2853 (_("%s: TOC reloc at 0x%x to symbol `%s' with no TOC entry"),
2854 bfd_get_filename (input_bfd), rel->r_vaddr,
2855 h->root.root.string);
2856 bfd_set_error (bfd_error_bad_value);
2860 BFD_ASSERT ((h->flags & XCOFF_SET_TOC) == 0);
2861 val = (h->toc_section->output_section->vma
2862 + h->toc_section->output_offset);
2865 *relocation = ((val - xcoff_data (output_bfd)->toc)
2866 - (sym->n_value - xcoff_data (input_bfd)->toc));
2871 xcoff_reloc_type_ba (bfd *input_bfd ATTRIBUTE_UNUSED,
2872 asection *input_section ATTRIBUTE_UNUSED,
2873 bfd *output_bfd ATTRIBUTE_UNUSED,
2874 struct internal_reloc *rel ATTRIBUTE_UNUSED,
2875 struct internal_syment *sym ATTRIBUTE_UNUSED,
2876 struct reloc_howto_struct *howto,
2879 bfd_vma *relocation,
2880 bfd_byte *contents ATTRIBUTE_UNUSED)
2882 howto->src_mask &= ~3;
2883 howto->dst_mask = howto->src_mask;
2885 *relocation = val + addend;
2891 xcoff_reloc_type_br (bfd *input_bfd,
2892 asection *input_section,
2893 bfd *output_bfd ATTRIBUTE_UNUSED,
2894 struct internal_reloc *rel,
2895 struct internal_syment *sym ATTRIBUTE_UNUSED,
2896 struct reloc_howto_struct *howto,
2899 bfd_vma *relocation,
2902 struct xcoff_link_hash_entry *h;
2903 bfd_vma section_offset;
2905 if (0 > rel->r_symndx)
2908 h = obj_xcoff_sym_hashes (input_bfd)[rel->r_symndx];
2909 section_offset = rel->r_vaddr - input_section->vma;
2911 /* If we see an R_BR or R_RBR reloc which is jumping to global
2912 linkage code, and it is followed by an appropriate cror nop
2913 instruction, we replace the cror with lwz r2,20(r1). This
2914 restores the TOC after the glink code. Contrariwise, if the
2915 call is followed by a lwz r2,20(r1), but the call is not
2916 going to global linkage code, we can replace the load with a
2919 && (bfd_link_hash_defined == h->root.type
2920 || bfd_link_hash_defweak == h->root.type)
2921 && section_offset + 8 <= input_section->size)
2926 pnext = contents + section_offset + 4;
2927 next = bfd_get_32 (input_bfd, pnext);
2929 /* The _ptrgl function is magic. It is used by the AIX
2930 compiler to call a function through a pointer. */
2931 if (h->smclas == XMC_GL || strcmp (h->root.root.string, "._ptrgl") == 0)
2933 if (next == 0x4def7b82 /* cror 15,15,15 */
2934 || next == 0x4ffffb82 /* cror 31,31,31 */
2935 || next == 0x60000000) /* ori r0,r0,0 */
2936 bfd_put_32 (input_bfd, 0x80410014, pnext); /* lwz r2,20(r1) */
2941 if (next == 0x80410014) /* lwz r2,20(r1) */
2942 bfd_put_32 (input_bfd, 0x60000000, pnext); /* ori r0,r0,0 */
2945 else if (NULL != h && bfd_link_hash_undefined == h->root.type)
2947 /* Normally, this relocation is against a defined symbol. In the
2948 case where this is a partial link and the output section offset
2949 is greater than 2^25, the linker will return an invalid error
2950 message that the relocation has been truncated. Yes it has been
2951 truncated but no it not important. For this case, disable the
2952 overflow checking. */
2954 howto->complain_on_overflow = complain_overflow_dont;
2957 /* The original PC-relative relocation is biased by -r_vaddr, so adding
2958 the value below will give the absolute target address. */
2959 *relocation = val + addend + rel->r_vaddr;
2961 howto->src_mask &= ~3;
2962 howto->dst_mask = howto->src_mask;
2965 && (h->root.type == bfd_link_hash_defined
2966 || h->root.type == bfd_link_hash_defweak)
2967 && bfd_is_abs_section (h->root.u.def.section)
2968 && section_offset + 4 <= input_section->size)
2973 /* Turn the relative branch into an absolute one by setting the
2975 ptr = contents + section_offset;
2976 insn = bfd_get_32 (input_bfd, ptr);
2978 bfd_put_32 (input_bfd, insn, ptr);
2980 /* Make the howto absolute too. */
2981 howto->pc_relative = FALSE;
2982 howto->complain_on_overflow = complain_overflow_bitfield;
2986 /* Use a PC-relative howto and subtract the instruction's address
2987 from the target address we calculated above. */
2988 howto->pc_relative = TRUE;
2989 *relocation -= (input_section->output_section->vma
2990 + input_section->output_offset
2997 xcoff_reloc_type_crel (bfd *input_bfd ATTRIBUTE_UNUSED,
2998 asection *input_section,
2999 bfd *output_bfd ATTRIBUTE_UNUSED,
3000 struct internal_reloc *rel ATTRIBUTE_UNUSED,
3001 struct internal_syment *sym ATTRIBUTE_UNUSED,
3002 struct reloc_howto_struct *howto,
3003 bfd_vma val ATTRIBUTE_UNUSED,
3005 bfd_vma *relocation,
3006 bfd_byte *contents ATTRIBUTE_UNUSED)
3008 howto->pc_relative = TRUE;
3009 howto->src_mask &= ~3;
3010 howto->dst_mask = howto->src_mask;
3012 /* A PC relative reloc includes the section address. */
3013 addend += input_section->vma;
3015 *relocation = val + addend;
3016 *relocation -= (input_section->output_section->vma
3017 + input_section->output_offset);
3022 xcoff_complain_overflow_dont_func (bfd *input_bfd ATTRIBUTE_UNUSED,
3023 bfd_vma val ATTRIBUTE_UNUSED,
3024 bfd_vma relocation ATTRIBUTE_UNUSED,
3025 struct reloc_howto_struct *
3026 howto ATTRIBUTE_UNUSED)
3032 xcoff_complain_overflow_bitfield_func (bfd *input_bfd,
3035 struct reloc_howto_struct *howto)
3037 bfd_vma fieldmask, signmask, ss;
3040 /* Get the values to be added together. For signed and unsigned
3041 relocations, we assume that all values should be truncated to
3042 the size of an address. For bitfields, all the bits matter.
3043 See also bfd_check_overflow. */
3044 fieldmask = N_ONES (howto->bitsize);
3046 b = val & howto->src_mask;
3048 /* Much like unsigned, except no trimming with addrmask. In
3049 addition, the sum overflows if there is a carry out of
3050 the bfd_vma, i.e., the sum is less than either input
3052 a >>= howto->rightshift;
3053 b >>= howto->bitpos;
3055 /* Bitfields are sometimes used for signed numbers; for
3056 example, a 13-bit field sometimes represents values in
3057 0..8191 and sometimes represents values in -4096..4095.
3058 If the field is signed and a is -4095 (0x1001) and b is
3059 -1 (0x1fff), the sum is -4096 (0x1000), but (0x1001 +
3060 0x1fff is 0x3000). It's not clear how to handle this
3061 everywhere, since there is not way to know how many bits
3062 are significant in the relocation, but the original code
3063 assumed that it was fully sign extended, and we will keep
3065 signmask = (fieldmask >> 1) + 1;
3067 if ((a & ~ fieldmask) != 0)
3069 /* Some bits out of the field are set. This might not
3070 be a problem: if this is a signed bitfield, it is OK
3071 iff all the high bits are set, including the sign
3072 bit. We'll try setting all but the most significant
3073 bit in the original relocation value: if this is all
3074 ones, we are OK, assuming a signed bitfield. */
3075 ss = (signmask << howto->rightshift) - 1;
3076 if ((ss | relocation) != ~ (bfd_vma) 0)
3081 /* We just assume (b & ~ fieldmask) == 0. */
3083 /* We explicitly permit wrap around if this relocation
3084 covers the high bit of an address. The Linux kernel
3085 relies on it, and it is the only way to write assembler
3086 code which can run when loaded at a location 0x80000000
3087 away from the location at which it is linked. */
3088 if (howto->bitsize + howto->rightshift
3089 == bfd_arch_bits_per_address (input_bfd))
3093 if (sum < a || (sum & ~ fieldmask) != 0)
3095 /* There was a carry out, or the field overflow. Test
3096 for signed operands again. Here is the overflow test
3097 is as for complain_overflow_signed. */
3098 if (((~ (a ^ b)) & (a ^ sum)) & signmask)
3106 xcoff_complain_overflow_signed_func (bfd *input_bfd,
3109 struct reloc_howto_struct *howto)
3111 bfd_vma addrmask, fieldmask, signmask, ss;
3114 /* Get the values to be added together. For signed and unsigned
3115 relocations, we assume that all values should be truncated to
3116 the size of an address. For bitfields, all the bits matter.
3117 See also bfd_check_overflow. */
3118 fieldmask = N_ONES (howto->bitsize);
3119 addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask;
3121 b = val & howto->src_mask;
3123 a = (a & addrmask) >> howto->rightshift;
3125 /* If any sign bits are set, all sign bits must be set.
3126 That is, A must be a valid negative address after
3128 signmask = ~ (fieldmask >> 1);
3130 if (ss != 0 && ss != ((addrmask >> howto->rightshift) & signmask))
3133 /* We only need this next bit of code if the sign bit of B
3134 is below the sign bit of A. This would only happen if
3135 SRC_MASK had fewer bits than BITSIZE. Note that if
3136 SRC_MASK has more bits than BITSIZE, we can get into
3137 trouble; we would need to verify that B is in range, as
3138 we do for A above. */
3139 signmask = ((~ howto->src_mask) >> 1) & howto->src_mask;
3140 if ((b & signmask) != 0)
3142 /* Set all the bits above the sign bit. */
3143 b -= signmask <<= 1;
3146 b = (b & addrmask) >> howto->bitpos;
3148 /* Now we can do the addition. */
3151 /* See if the result has the correct sign. Bits above the
3152 sign bit are junk now; ignore them. If the sum is
3153 positive, make sure we did not have all negative inputs;
3154 if the sum is negative, make sure we did not have all
3155 positive inputs. The test below looks only at the sign
3156 bits, and it really just
3157 SIGN (A) == SIGN (B) && SIGN (A) != SIGN (SUM)
3159 signmask = (fieldmask >> 1) + 1;
3160 if (((~ (a ^ b)) & (a ^ sum)) & signmask)
3167 xcoff_complain_overflow_unsigned_func (bfd *input_bfd,
3170 struct reloc_howto_struct *howto)
3172 bfd_vma addrmask, fieldmask;
3175 /* Get the values to be added together. For signed and unsigned
3176 relocations, we assume that all values should be truncated to
3177 the size of an address. For bitfields, all the bits matter.
3178 See also bfd_check_overflow. */
3179 fieldmask = N_ONES (howto->bitsize);
3180 addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask;
3182 b = val & howto->src_mask;
3184 /* Checking for an unsigned overflow is relatively easy:
3185 trim the addresses and add, and trim the result as well.
3186 Overflow is normally indicated when the result does not
3187 fit in the field. However, we also need to consider the
3188 case when, e.g., fieldmask is 0x7fffffff or smaller, an
3189 input is 0x80000000, and bfd_vma is only 32 bits; then we
3190 will get sum == 0, but there is an overflow, since the
3191 inputs did not fit in the field. Instead of doing a
3192 separate test, we can check for this by or-ing in the
3193 operands when testing for the sum overflowing its final
3195 a = (a & addrmask) >> howto->rightshift;
3196 b = (b & addrmask) >> howto->bitpos;
3197 sum = (a + b) & addrmask;
3198 if ((a | b | sum) & ~ fieldmask)
3204 /* This is the relocation function for the RS/6000/POWER/PowerPC.
3205 This is currently the only processor which uses XCOFF; I hope that
3208 I took the relocation type definitions from two documents:
3209 the PowerPC AIX Version 4 Application Binary Interface, First
3210 Edition (April 1992), and the PowerOpen ABI, Big-Endian
3211 32-Bit Hardware Implementation (June 30, 1994). Differences
3212 between the documents are noted below.
3214 Unsupported r_type's
3220 These relocs are defined by the PowerPC ABI to be
3221 relative branches which use half of the difference
3222 between the symbol and the program counter. I can't
3223 quite figure out when this is useful. These relocs are
3224 not defined by the PowerOpen ABI.
3229 Simple positive relocation.
3232 Simple negative relocation.
3235 Simple PC relative relocation.
3238 TOC relative relocation. The value in the instruction in
3239 the input file is the offset from the input file TOC to
3240 the desired location. We want the offset from the final
3241 TOC to the desired location. We have:
3246 so we must change insn by on - in.
3249 GL linkage relocation. The value of this relocation
3250 is the address of the entry in the TOC section.
3253 Local object TOC address. I can't figure out the
3254 difference between this and case R_GL.
3257 TOC relative relocation. A TOC relative load instruction
3258 which may be changed to a load address instruction.
3259 FIXME: We don't currently implement this optimization.
3262 TOC relative relocation. This is a TOC relative load
3263 address instruction which may be changed to a load
3264 instruction. FIXME: I don't know if this is the correct
3268 Absolute branch. We don't want to mess with the lower
3269 two bits of the instruction.
3272 The PowerPC ABI defines this as an absolute call which
3273 may be modified to become a relative call. The PowerOpen
3274 ABI does not define this relocation type.
3277 Absolute branch which may be modified to become a
3281 The PowerPC ABI defines this as an absolute branch to a
3282 fixed address which may be modified to an absolute branch
3283 to a symbol. The PowerOpen ABI does not define this
3287 The PowerPC ABI defines this as an absolute branch to a
3288 fixed address which may be modified to a relative branch.
3289 The PowerOpen ABI does not define this relocation type.
3292 Relative branch. We don't want to mess with the lower
3293 two bits of the instruction.
3296 The PowerPC ABI defines this as a relative call which may
3297 be modified to become an absolute call. The PowerOpen
3298 ABI does not define this relocation type.
3301 A relative branch which may be modified to become an
3305 The PowerPC AIX ABI describes this as a load which may be
3306 changed to a load address. The PowerOpen ABI says this
3307 is the same as case R_POS.
3310 The PowerPC AIX ABI describes this as a load address
3311 which may be changed to a load. The PowerOpen ABI says
3312 this is the same as R_POS.
3316 xcoff_ppc_relocate_section (bfd *output_bfd,
3317 struct bfd_link_info *info,
3319 asection *input_section,
3321 struct internal_reloc *relocs,
3322 struct internal_syment *syms,
3323 asection **sections)
3325 struct internal_reloc *rel;
3326 struct internal_reloc *relend;
3329 relend = rel + input_section->reloc_count;
3330 for (; rel < relend; rel++)
3333 struct xcoff_link_hash_entry *h;
3334 struct internal_syment *sym;
3337 struct reloc_howto_struct howto;
3339 bfd_vma value_to_relocate;
3343 /* Relocation type R_REF is a special relocation type which is
3344 merely used to prevent garbage collection from occurring for
3345 the csect including the symbol which it references. */
3346 if (rel->r_type == R_REF)
3350 howto.type = rel->r_type;
3351 howto.rightshift = 0;
3352 howto.bitsize = (rel->r_size & 0x1f) + 1;
3353 howto.size = howto.bitsize > 16 ? 2 : 1;
3354 howto.pc_relative = FALSE;
3356 howto.complain_on_overflow = (rel->r_size & 0x80
3357 ? complain_overflow_signed
3358 : complain_overflow_bitfield);
3359 howto.special_function = NULL;
3360 howto.name = "internal";
3361 howto.partial_inplace = TRUE;
3362 howto.src_mask = howto.dst_mask = N_ONES (howto.bitsize);
3363 howto.pcrel_offset = FALSE;
3370 symndx = rel->r_symndx;
3376 h = obj_xcoff_sym_hashes (input_bfd)[symndx];
3377 sym = syms + symndx;
3378 addend = - sym->n_value;
3382 sec = sections[symndx];
3383 /* Hack to make sure we use the right TOC anchor value
3384 if this reloc is against the TOC anchor. */
3385 if (sec->name[3] == '0'
3386 && strcmp (sec->name, ".tc0") == 0)
3387 val = xcoff_data (output_bfd)->toc;
3389 val = (sec->output_section->vma
3390 + sec->output_offset
3396 if (info->unresolved_syms_in_objects != RM_IGNORE
3397 && (h->flags & XCOFF_WAS_UNDEFINED) != 0)
3399 if (! ((*info->callbacks->undefined_symbol)
3400 (info, h->root.root.string,
3401 input_bfd, input_section,
3402 rel->r_vaddr - input_section->vma,
3403 (info->unresolved_syms_in_objects
3404 == RM_GENERATE_ERROR))))
3407 if (h->root.type == bfd_link_hash_defined
3408 || h->root.type == bfd_link_hash_defweak)
3410 sec = h->root.u.def.section;
3411 val = (h->root.u.def.value
3412 + sec->output_section->vma
3413 + sec->output_offset);
3415 else if (h->root.type == bfd_link_hash_common)
3417 sec = h->root.u.c.p->section;
3418 val = (sec->output_section->vma
3419 + sec->output_offset);
3424 BFD_ASSERT (info->relocatable
3425 || (info->static_link
3426 && (h->flags & XCOFF_WAS_UNDEFINED) != 0)
3427 || (h->flags & XCOFF_DEF_DYNAMIC) != 0
3428 || (h->flags & XCOFF_IMPORT) != 0);
3433 if (rel->r_type >= XCOFF_MAX_CALCULATE_RELOCATION
3434 || !((*xcoff_calculate_relocation[rel->r_type])
3435 (input_bfd, input_section, output_bfd, rel, sym, &howto, val,
3436 addend, &relocation, contents)))
3440 address = rel->r_vaddr - input_section->vma;
3441 location = contents + address;
3443 if (address > input_section->size)
3446 /* Get the value we are going to relocate. */
3447 if (1 == howto.size)
3448 value_to_relocate = bfd_get_16 (input_bfd, location);
3450 value_to_relocate = bfd_get_32 (input_bfd, location);
3454 FIXME: We may drop bits during the addition
3455 which we don't check for. We must either check at every single
3456 operation, which would be tedious, or we must do the computations
3457 in a type larger than bfd_vma, which would be inefficient. */
3459 if ((unsigned int) howto.complain_on_overflow
3460 >= XCOFF_MAX_COMPLAIN_OVERFLOW)
3463 if (((*xcoff_complain_overflow[howto.complain_on_overflow])
3464 (input_bfd, value_to_relocate, relocation, &howto)))
3467 char buf[SYMNMLEN + 1];
3468 char reloc_type_name[10];
3480 name = _bfd_coff_internal_syment_name (input_bfd, sym, buf);
3484 sprintf (reloc_type_name, "0x%02x", rel->r_type);
3486 if (! ((*info->callbacks->reloc_overflow)
3487 (info, (h ? &h->root : NULL), name, reloc_type_name,
3488 (bfd_vma) 0, input_bfd, input_section,
3489 rel->r_vaddr - input_section->vma)))
3493 /* Add RELOCATION to the right bits of VALUE_TO_RELOCATE. */
3494 value_to_relocate = ((value_to_relocate & ~howto.dst_mask)
3495 | (((value_to_relocate & howto.src_mask)
3496 + relocation) & howto.dst_mask));
3498 /* Put the value back in the object file. */
3499 if (1 == howto.size)
3500 bfd_put_16 (input_bfd, value_to_relocate, location);
3502 bfd_put_32 (input_bfd, value_to_relocate, location);
3509 _bfd_xcoff_put_ldsymbol_name (bfd *abfd ATTRIBUTE_UNUSED,
3510 struct xcoff_loader_info *ldinfo,
3511 struct internal_ldsym *ldsym,
3515 len = strlen (name);
3517 if (len <= SYMNMLEN)
3518 strncpy (ldsym->_l._l_name, name, SYMNMLEN);
3521 if (ldinfo->string_size + len + 3 > ldinfo->string_alc)
3523 bfd_size_type newalc;
3526 newalc = ldinfo->string_alc * 2;
3529 while (ldinfo->string_size + len + 3 > newalc)
3532 newstrings = bfd_realloc (ldinfo->strings, newalc);
3533 if (newstrings == NULL)
3535 ldinfo->failed = TRUE;
3538 ldinfo->string_alc = newalc;
3539 ldinfo->strings = newstrings;
3542 bfd_put_16 (ldinfo->output_bfd, (bfd_vma) (len + 1),
3543 ldinfo->strings + ldinfo->string_size);
3544 strcpy (ldinfo->strings + ldinfo->string_size + 2, name);
3545 ldsym->_l._l_l._l_zeroes = 0;
3546 ldsym->_l._l_l._l_offset = ldinfo->string_size + 2;
3547 ldinfo->string_size += len + 3;
3554 _bfd_xcoff_put_symbol_name (bfd *abfd, struct bfd_strtab_hash *strtab,
3555 struct internal_syment *sym,
3558 if (strlen (name) <= SYMNMLEN)
3560 strncpy (sym->_n._n_name, name, SYMNMLEN);
3568 if ((abfd->flags & BFD_TRADITIONAL_FORMAT) != 0)
3570 indx = _bfd_stringtab_add (strtab, name, hash, FALSE);
3571 if (indx == (bfd_size_type) -1)
3573 sym->_n._n_n._n_zeroes = 0;
3574 sym->_n._n_n._n_offset = STRING_SIZE_SIZE + indx;
3580 xcoff_create_csect_from_smclas (bfd *abfd,
3581 union internal_auxent *aux,
3582 const char *symbol_name)
3584 asection *return_value = NULL;
3586 /* .sv64 = x_smclas == 17
3587 This is an invalid csect for 32 bit apps. */
3588 static const char * const names[] =
3590 ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo", /* 0 - 7 */
3591 ".sv", ".bs", ".ds", ".uc", ".ti", ".tb", NULL, ".tc0", /* 8 - 15 */
3592 ".td", NULL, ".sv3264", NULL, ".tl", ".ul", ".te"
3595 if ((aux->x_csect.x_smclas < ARRAY_SIZE (names))
3596 && (NULL != names[aux->x_csect.x_smclas]))
3598 return_value = bfd_make_section_anyway
3599 (abfd, names[aux->x_csect.x_smclas]);
3603 (*_bfd_error_handler)
3604 (_("%B: symbol `%s' has unrecognized smclas %d"),
3605 abfd, symbol_name, aux->x_csect.x_smclas);
3606 bfd_set_error (bfd_error_bad_value);
3609 return return_value;
3613 xcoff_is_lineno_count_overflow (bfd *abfd ATTRIBUTE_UNUSED, bfd_vma value)
3615 if (0xffff <= value)
3622 xcoff_is_reloc_count_overflow (bfd *abfd ATTRIBUTE_UNUSED, bfd_vma value)
3624 if (0xffff <= value)
3631 xcoff_loader_symbol_offset (bfd *abfd,
3632 struct internal_ldhdr *ldhdr ATTRIBUTE_UNUSED)
3634 return bfd_xcoff_ldhdrsz (abfd);
3638 xcoff_loader_reloc_offset (bfd *abfd, struct internal_ldhdr *ldhdr)
3640 return bfd_xcoff_ldhdrsz (abfd) + ldhdr->l_nsyms * bfd_xcoff_ldsymsz (abfd);
3644 xcoff_generate_rtinit (bfd *abfd, const char *init, const char *fini,
3647 bfd_byte filehdr_ext[FILHSZ];
3648 bfd_byte scnhdr_ext[SCNHSZ];
3649 bfd_byte syment_ext[SYMESZ * 10];
3650 bfd_byte reloc_ext[RELSZ * 3];
3651 bfd_byte *data_buffer;
3652 bfd_size_type data_buffer_size;
3653 bfd_byte *string_table = NULL, *st_tmp = NULL;
3654 bfd_size_type string_table_size;
3656 size_t initsz, finisz;
3657 struct internal_filehdr filehdr;
3658 struct internal_scnhdr scnhdr;
3659 struct internal_syment syment;
3660 union internal_auxent auxent;
3661 struct internal_reloc reloc;
3663 char *data_name = ".data";
3664 char *rtinit_name = "__rtinit";
3665 char *rtld_name = "__rtld";
3667 if (! bfd_xcoff_rtinit_size (abfd))
3670 initsz = (init == NULL ? 0 : 1 + strlen (init));
3671 finisz = (fini == NULL ? 0 : 1 + strlen (fini));
3674 memset (filehdr_ext, 0, FILHSZ);
3675 memset (&filehdr, 0, sizeof (struct internal_filehdr));
3676 filehdr.f_magic = bfd_xcoff_magic_number (abfd);
3677 filehdr.f_nscns = 1;
3678 filehdr.f_timdat = 0;
3679 filehdr.f_nsyms = 0; /* at least 6, no more than 10 */
3680 filehdr.f_symptr = 0; /* set below */
3681 filehdr.f_opthdr = 0;
3682 filehdr.f_flags = 0;
3684 /* section header */
3685 memset (scnhdr_ext, 0, SCNHSZ);
3686 memset (&scnhdr, 0, sizeof (struct internal_scnhdr));
3687 memcpy (scnhdr.s_name, data_name, strlen (data_name));
3690 scnhdr.s_size = 0; /* set below */
3691 scnhdr.s_scnptr = FILHSZ + SCNHSZ;
3692 scnhdr.s_relptr = 0; /* set below */
3693 scnhdr.s_lnnoptr = 0;
3694 scnhdr.s_nreloc = 0; /* either 1 or 2 */
3696 scnhdr.s_flags = STYP_DATA;
3699 0x0000 0x00000000 : rtl
3700 0x0004 0x00000010 : offset to init, or 0
3701 0x0008 0x00000028 : offset to fini, or 0
3702 0x000C 0x0000000C : size of descriptor
3703 0x0010 0x00000000 : init, needs a reloc
3704 0x0014 0x00000040 : offset to init name
3705 0x0018 0x00000000 : flags, padded to a word
3706 0x001C 0x00000000 : empty init
3709 0x0028 0x00000000 : fini, needs a reloc
3710 0x002C 0x00000??? : offset to fini name
3711 0x0030 0x00000000 : flags, padded to a word
3712 0x0034 0x00000000 : empty fini
3716 0x0040 + initsz fini name */
3718 data_buffer_size = 0x0040 + initsz + finisz;
3719 data_buffer_size = (data_buffer_size + 7) &~ (bfd_size_type) 7;
3721 data_buffer = (bfd_byte *) bfd_zmalloc (data_buffer_size);
3722 if (data_buffer == NULL)
3728 bfd_h_put_32 (abfd, val, &data_buffer[0x04]);
3730 bfd_h_put_32 (abfd, val, &data_buffer[0x14]);
3731 memcpy (&data_buffer[val], init, initsz);
3737 bfd_h_put_32 (abfd, val, &data_buffer[0x08]);
3738 val = 0x40 + initsz;
3739 bfd_h_put_32 (abfd, val, &data_buffer[0x2C]);
3740 memcpy (&data_buffer[val], fini, finisz);
3744 bfd_h_put_32 (abfd, val, &data_buffer[0x0C]);
3746 scnhdr.s_size = data_buffer_size;
3749 string_table_size = 0;
3751 string_table_size += initsz;
3753 string_table_size += finisz;
3754 if (string_table_size)
3756 string_table_size += 4;
3757 string_table = (bfd_byte *) bfd_zmalloc (string_table_size);
3758 if (string_table == NULL)
3761 val = string_table_size;
3762 bfd_h_put_32 (abfd, val, &string_table[0]);
3763 st_tmp = string_table + 4;
3772 memset (syment_ext, 0, 10 * SYMESZ);
3773 memset (reloc_ext, 0, 3 * RELSZ);
3776 memset (&syment, 0, sizeof (struct internal_syment));
3777 memset (&auxent, 0, sizeof (union internal_auxent));
3778 memcpy (syment._n._n_name, data_name, strlen (data_name));
3780 syment.n_sclass = C_HIDEXT;
3781 syment.n_numaux = 1;
3782 auxent.x_csect.x_scnlen.l = data_buffer_size;
3783 auxent.x_csect.x_smtyp = 3 << 3 | XTY_SD;
3784 auxent.x_csect.x_smclas = XMC_RW;
3785 bfd_coff_swap_sym_out (abfd, &syment,
3786 &syment_ext[filehdr.f_nsyms * SYMESZ]);
3787 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
3789 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
3790 filehdr.f_nsyms += 2;
3793 memset (&syment, 0, sizeof (struct internal_syment));
3794 memset (&auxent, 0, sizeof (union internal_auxent));
3795 memcpy (syment._n._n_name, rtinit_name, strlen (rtinit_name));
3797 syment.n_sclass = C_EXT;
3798 syment.n_numaux = 1;
3799 auxent.x_csect.x_smtyp = XTY_LD;
3800 auxent.x_csect.x_smclas = XMC_RW;
3801 bfd_coff_swap_sym_out (abfd, &syment,
3802 &syment_ext[filehdr.f_nsyms * SYMESZ]);
3803 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
3805 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
3806 filehdr.f_nsyms += 2;
3811 memset (&syment, 0, sizeof (struct internal_syment));
3812 memset (&auxent, 0, sizeof (union internal_auxent));
3816 syment._n._n_n._n_offset = st_tmp - string_table;
3817 memcpy (st_tmp, init, initsz);
3821 memcpy (syment._n._n_name, init, initsz - 1);
3823 syment.n_sclass = C_EXT;
3824 syment.n_numaux = 1;
3825 bfd_coff_swap_sym_out (abfd, &syment,
3826 &syment_ext[filehdr.f_nsyms * SYMESZ]);
3827 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
3829 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
3832 memset (&reloc, 0, sizeof (struct internal_reloc));
3833 reloc.r_vaddr = 0x0010;
3834 reloc.r_symndx = filehdr.f_nsyms;
3835 reloc.r_type = R_POS;
3837 bfd_coff_swap_reloc_out (abfd, &reloc, &reloc_ext[0]);
3839 filehdr.f_nsyms += 2;
3840 scnhdr.s_nreloc += 1;
3846 memset (&syment, 0, sizeof (struct internal_syment));
3847 memset (&auxent, 0, sizeof (union internal_auxent));
3851 syment._n._n_n._n_offset = st_tmp - string_table;
3852 memcpy (st_tmp, fini, finisz);
3856 memcpy (syment._n._n_name, fini, finisz - 1);
3858 syment.n_sclass = C_EXT;
3859 syment.n_numaux = 1;
3860 bfd_coff_swap_sym_out (abfd, &syment,
3861 &syment_ext[filehdr.f_nsyms * SYMESZ]);
3862 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
3864 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
3867 memset (&reloc, 0, sizeof (struct internal_reloc));
3868 reloc.r_vaddr = 0x0028;
3869 reloc.r_symndx = filehdr.f_nsyms;
3870 reloc.r_type = R_POS;
3872 bfd_coff_swap_reloc_out (abfd, &reloc,
3873 &reloc_ext[scnhdr.s_nreloc * RELSZ]);
3875 filehdr.f_nsyms += 2;
3876 scnhdr.s_nreloc += 1;
3881 memset (&syment, 0, sizeof (struct internal_syment));
3882 memset (&auxent, 0, sizeof (union internal_auxent));
3883 memcpy (syment._n._n_name, rtld_name, strlen (rtld_name));
3884 syment.n_sclass = C_EXT;
3885 syment.n_numaux = 1;
3886 bfd_coff_swap_sym_out (abfd, &syment,
3887 &syment_ext[filehdr.f_nsyms * SYMESZ]);
3888 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
3890 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
3893 memset (&reloc, 0, sizeof (struct internal_reloc));
3894 reloc.r_vaddr = 0x0000;
3895 reloc.r_symndx = filehdr.f_nsyms;
3896 reloc.r_type = R_POS;
3898 bfd_coff_swap_reloc_out (abfd, &reloc,
3899 &reloc_ext[scnhdr.s_nreloc * RELSZ]);
3901 filehdr.f_nsyms += 2;
3902 scnhdr.s_nreloc += 1;
3905 scnhdr.s_relptr = scnhdr.s_scnptr + data_buffer_size;
3906 filehdr.f_symptr = scnhdr.s_relptr + scnhdr.s_nreloc * RELSZ;
3908 bfd_coff_swap_filehdr_out (abfd, &filehdr, filehdr_ext);
3909 bfd_bwrite (filehdr_ext, FILHSZ, abfd);
3910 bfd_coff_swap_scnhdr_out (abfd, &scnhdr, scnhdr_ext);
3911 bfd_bwrite (scnhdr_ext, SCNHSZ, abfd);
3912 bfd_bwrite (data_buffer, data_buffer_size, abfd);
3913 bfd_bwrite (reloc_ext, scnhdr.s_nreloc * RELSZ, abfd);
3914 bfd_bwrite (syment_ext, filehdr.f_nsyms * SYMESZ, abfd);
3915 bfd_bwrite (string_table, string_table_size, abfd);
3924 static reloc_howto_type xcoff_dynamic_reloc =
3925 HOWTO (0, /* type */
3927 2, /* size (0 = byte, 1 = short, 2 = long) */
3929 FALSE, /* pc_relative */
3931 complain_overflow_bitfield, /* complain_on_overflow */
3932 0, /* special_function */
3934 TRUE, /* partial_inplace */
3935 0xffffffff, /* src_mask */
3936 0xffffffff, /* dst_mask */
3937 FALSE); /* pcrel_offset */
3941 The first word of global linkage code must be modified by filling in
3942 the correct TOC offset. */
3944 static unsigned long xcoff_glink_code[9] =
3946 0x81820000, /* lwz r12,0(r2) */
3947 0x90410014, /* stw r2,20(r1) */
3948 0x800c0000, /* lwz r0,0(r12) */
3949 0x804c0004, /* lwz r2,4(r12) */
3950 0x7c0903a6, /* mtctr r0 */
3951 0x4e800420, /* bctr */
3952 0x00000000, /* start of traceback table */
3953 0x000c8000, /* traceback table */
3954 0x00000000, /* traceback table */
3957 /* Table to convert DWARF flags to section names. */
3959 const struct xcoff_dwsect_name xcoff_dwsect_names[] = {
3960 { SSUBTYP_DWINFO, ".dwinfo", TRUE },
3961 { SSUBTYP_DWLINE, ".dwline", TRUE },
3962 { SSUBTYP_DWPBNMS, ".dwpbnms", TRUE },
3963 { SSUBTYP_DWPBTYP, ".dwpbtyp", TRUE },
3964 { SSUBTYP_DWARNGE, ".dwarnge", TRUE },
3965 { SSUBTYP_DWABREV, ".dwabrev", FALSE },
3966 { SSUBTYP_DWSTR, ".dwstr", TRUE },
3967 { SSUBTYP_DWRNGES, ".dwrnges", TRUE }
3970 /* For generic entry points. */
3971 #define _bfd_xcoff_close_and_cleanup _bfd_archive_close_and_cleanup
3972 #define _bfd_xcoff_bfd_free_cached_info bfd_true
3973 #define _bfd_xcoff_new_section_hook coff_new_section_hook
3974 #define _bfd_xcoff_get_section_contents _bfd_generic_get_section_contents
3975 #define _bfd_xcoff_get_section_contents_in_window \
3976 _bfd_generic_get_section_contents_in_window
3978 /* For copy private data entry points. */
3979 #define _bfd_xcoff_bfd_copy_private_bfd_data \
3980 _bfd_xcoff_copy_private_bfd_data
3981 #define _bfd_xcoff_bfd_merge_private_bfd_data \
3982 _bfd_generic_bfd_merge_private_bfd_data
3983 #define _bfd_xcoff_bfd_copy_private_section_data \
3984 _bfd_generic_bfd_copy_private_section_data
3985 #define _bfd_xcoff_bfd_copy_private_symbol_data \
3986 _bfd_generic_bfd_copy_private_symbol_data
3987 #define _bfd_xcoff_bfd_copy_private_header_data \
3988 _bfd_generic_bfd_copy_private_header_data
3989 #define _bfd_xcoff_bfd_set_private_flags \
3990 _bfd_generic_bfd_set_private_flags
3991 #define _bfd_xcoff_bfd_print_private_bfd_data \
3992 _bfd_generic_bfd_print_private_bfd_data
3994 /* For archive entry points. */
3995 #define _bfd_xcoff_slurp_extended_name_table \
3996 _bfd_noarchive_slurp_extended_name_table
3997 #define _bfd_xcoff_construct_extended_name_table \
3998 _bfd_noarchive_construct_extended_name_table
3999 #define _bfd_xcoff_truncate_arname bfd_dont_truncate_arname
4000 #define _bfd_xcoff_write_ar_hdr _bfd_generic_write_ar_hdr
4001 #define _bfd_xcoff_get_elt_at_index _bfd_generic_get_elt_at_index
4002 #define _bfd_xcoff_generic_stat_arch_elt _bfd_xcoff_stat_arch_elt
4003 #define _bfd_xcoff_update_armap_timestamp bfd_true
4005 /* For symbols entry points. */
4006 #define _bfd_xcoff_get_symtab_upper_bound coff_get_symtab_upper_bound
4007 #define _bfd_xcoff_canonicalize_symtab coff_canonicalize_symtab
4008 #define _bfd_xcoff_make_empty_symbol coff_make_empty_symbol
4009 #define _bfd_xcoff_print_symbol coff_print_symbol
4010 #define _bfd_xcoff_get_symbol_info coff_get_symbol_info
4011 #define _bfd_xcoff_get_symbol_version_string \
4012 _bfd_nosymbols_get_symbol_version_string
4013 #define _bfd_xcoff_bfd_is_local_label_name _bfd_xcoff_is_local_label_name
4014 #define _bfd_xcoff_bfd_is_target_special_symbol \
4015 coff_bfd_is_target_special_symbol
4016 #define _bfd_xcoff_get_lineno coff_get_lineno
4017 #define _bfd_xcoff_find_nearest_line coff_find_nearest_line
4018 #define _bfd_xcoff_find_line coff_find_line
4019 #define _bfd_xcoff_find_inliner_info coff_find_inliner_info
4020 #define _bfd_xcoff_bfd_make_debug_symbol coff_bfd_make_debug_symbol
4021 #define _bfd_xcoff_read_minisymbols _bfd_generic_read_minisymbols
4022 #define _bfd_xcoff_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
4024 /* For reloc entry points. */
4025 #define _bfd_xcoff_get_reloc_upper_bound coff_get_reloc_upper_bound
4026 #define _bfd_xcoff_canonicalize_reloc coff_canonicalize_reloc
4027 #define _bfd_xcoff_bfd_reloc_type_lookup _bfd_xcoff_reloc_type_lookup
4028 #define _bfd_xcoff_bfd_reloc_name_lookup _bfd_xcoff_reloc_name_lookup
4030 /* For link entry points. */
4031 #define _bfd_xcoff_bfd_get_relocated_section_contents \
4032 bfd_generic_get_relocated_section_contents
4033 #define _bfd_xcoff_bfd_relax_section bfd_generic_relax_section
4034 #define _bfd_xcoff_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
4035 #define _bfd_xcoff_bfd_link_just_syms _bfd_generic_link_just_syms
4036 #define _bfd_xcoff_bfd_copy_link_hash_symbol_type \
4037 _bfd_generic_copy_link_hash_symbol_type
4038 #define _bfd_xcoff_bfd_link_split_section _bfd_generic_link_split_section
4039 #define _bfd_xcoff_bfd_gc_sections bfd_generic_gc_sections
4040 #define _bfd_xcoff_bfd_lookup_section_flags bfd_generic_lookup_section_flags
4041 #define _bfd_xcoff_bfd_merge_sections bfd_generic_merge_sections
4042 #define _bfd_xcoff_bfd_is_group_section bfd_generic_is_group_section
4043 #define _bfd_xcoff_bfd_discard_group bfd_generic_discard_group
4044 #define _bfd_xcoff_section_already_linked _bfd_generic_section_already_linked
4045 #define _bfd_xcoff_bfd_define_common_symbol _bfd_xcoff_define_common_symbol
4047 /* For dynamic symbols and relocs entry points. */
4048 #define _bfd_xcoff_get_synthetic_symtab _bfd_nodynamic_get_synthetic_symtab
4050 static const struct xcoff_backend_data_rec bfd_xcoff_backend_data =
4052 { /* COFF backend, defined in libcoff.h. */
4053 _bfd_xcoff_swap_aux_in,
4054 _bfd_xcoff_swap_sym_in,
4055 coff_swap_lineno_in,
4056 _bfd_xcoff_swap_aux_out,
4057 _bfd_xcoff_swap_sym_out,
4058 coff_swap_lineno_out,
4059 xcoff_swap_reloc_out,
4060 coff_swap_filehdr_out,
4061 coff_swap_aouthdr_out,
4062 coff_swap_scnhdr_out,
4071 TRUE, /* _bfd_coff_long_filenames */
4072 XCOFF_NO_LONG_SECTION_NAMES, /* _bfd_coff_long_section_names */
4073 3, /* _bfd_coff_default_section_alignment_power */
4074 FALSE, /* _bfd_coff_force_symnames_in_strings */
4075 2, /* _bfd_coff_debug_string_prefix_length */
4076 32768, /* _bfd_coff_max_nscns */
4077 coff_swap_filehdr_in,
4078 coff_swap_aouthdr_in,
4079 coff_swap_scnhdr_in,
4080 xcoff_swap_reloc_in,
4081 coff_bad_format_hook,
4082 coff_set_arch_mach_hook,
4085 coff_set_alignment_hook,
4086 coff_slurp_symbol_table,
4087 symname_in_debug_hook,
4088 coff_pointerize_aux_hook,
4090 dummy_reloc16_extra_cases,
4091 dummy_reloc16_estimate,
4092 NULL, /* bfd_coff_sym_is_global */
4093 coff_compute_section_file_positions,
4094 NULL, /* _bfd_coff_start_final_link */
4095 xcoff_ppc_relocate_section,
4096 coff_rtype_to_howto,
4097 NULL, /* _bfd_coff_adjust_symndx */
4098 _bfd_generic_link_add_one_symbol,
4099 coff_link_output_has_begun,
4100 coff_final_link_postscript,
4101 NULL /* print_pdata. */
4104 0x01DF, /* magic number */
4108 /* Function pointers to xcoff specific swap routines. */
4109 xcoff_swap_ldhdr_in,
4110 xcoff_swap_ldhdr_out,
4111 xcoff_swap_ldsym_in,
4112 xcoff_swap_ldsym_out,
4113 xcoff_swap_ldrel_in,
4114 xcoff_swap_ldrel_out,
4120 12, /* _xcoff_function_descriptor_size */
4124 1, /* _xcoff_ldhdr_version */
4126 _bfd_xcoff_put_symbol_name,
4127 _bfd_xcoff_put_ldsymbol_name,
4128 &xcoff_dynamic_reloc,
4129 xcoff_create_csect_from_smclas,
4131 /* Lineno and reloc count overflow. */
4132 xcoff_is_lineno_count_overflow,
4133 xcoff_is_reloc_count_overflow,
4135 xcoff_loader_symbol_offset,
4136 xcoff_loader_reloc_offset,
4139 &xcoff_glink_code[0],
4140 36, /* _xcoff_glink_size */
4143 64, /* _xcoff_rtinit_size */
4144 xcoff_generate_rtinit,
4147 /* The transfer vector that leads the outside world to all of the above. */
4148 const bfd_target rs6000_xcoff_vec =
4151 bfd_target_xcoff_flavour,
4152 BFD_ENDIAN_BIG, /* data byte order is big */
4153 BFD_ENDIAN_BIG, /* header byte order is big */
4155 (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | DYNAMIC
4156 | HAS_SYMS | HAS_LOCALS | WP_TEXT),
4158 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA,
4159 0, /* leading char */
4160 '/', /* ar_pad_char */
4161 15, /* ar_max_namelen */
4162 0, /* match priority. */
4186 { /* bfd_check_format */
4189 _bfd_xcoff_archive_p,
4193 { /* bfd_set_format */
4196 _bfd_generic_mkarchive,
4200 {/* bfd_write_contents */
4202 coff_write_object_contents,
4203 _bfd_xcoff_write_archive_contents,
4207 BFD_JUMP_TABLE_GENERIC (_bfd_xcoff),
4208 BFD_JUMP_TABLE_COPY (_bfd_xcoff),
4209 BFD_JUMP_TABLE_CORE (coff),
4210 BFD_JUMP_TABLE_ARCHIVE (_bfd_xcoff),
4211 BFD_JUMP_TABLE_SYMBOLS (_bfd_xcoff),
4212 BFD_JUMP_TABLE_RELOCS (_bfd_xcoff),
4213 BFD_JUMP_TABLE_WRITE (coff),
4214 BFD_JUMP_TABLE_LINK (_bfd_xcoff),
4215 BFD_JUMP_TABLE_DYNAMIC (_bfd_xcoff),
4217 /* Opposite endian version, none exists */
4220 & bfd_xcoff_backend_data,
4223 /* xcoff-powermac target
4225 Only difference between this target and the rs6000 target is the
4226 the default architecture and machine type used in coffcode.h
4228 PowerPC Macs use the same magic numbers as RS/6000
4229 (because that's how they were bootstrapped originally),
4230 but they are always PowerPC architecture. */
4231 static const struct xcoff_backend_data_rec bfd_pmac_xcoff_backend_data =
4233 { /* COFF backend, defined in libcoff.h. */
4234 _bfd_xcoff_swap_aux_in,
4235 _bfd_xcoff_swap_sym_in,
4236 coff_swap_lineno_in,
4237 _bfd_xcoff_swap_aux_out,
4238 _bfd_xcoff_swap_sym_out,
4239 coff_swap_lineno_out,
4240 xcoff_swap_reloc_out,
4241 coff_swap_filehdr_out,
4242 coff_swap_aouthdr_out,
4243 coff_swap_scnhdr_out,
4252 TRUE, /* _bfd_coff_long_filenames */
4253 XCOFF_NO_LONG_SECTION_NAMES, /* _bfd_coff_long_section_names */
4254 3, /* _bfd_coff_default_section_alignment_power */
4255 FALSE, /* _bfd_coff_force_symnames_in_strings */
4256 2, /* _bfd_coff_debug_string_prefix_length */
4257 32768, /* _bfd_coff_max_nscns */
4258 coff_swap_filehdr_in,
4259 coff_swap_aouthdr_in,
4260 coff_swap_scnhdr_in,
4261 xcoff_swap_reloc_in,
4262 coff_bad_format_hook,
4263 coff_set_arch_mach_hook,
4266 coff_set_alignment_hook,
4267 coff_slurp_symbol_table,
4268 symname_in_debug_hook,
4269 coff_pointerize_aux_hook,
4271 dummy_reloc16_extra_cases,
4272 dummy_reloc16_estimate,
4273 NULL, /* bfd_coff_sym_is_global */
4274 coff_compute_section_file_positions,
4275 NULL, /* _bfd_coff_start_final_link */
4276 xcoff_ppc_relocate_section,
4277 coff_rtype_to_howto,
4278 NULL, /* _bfd_coff_adjust_symndx */
4279 _bfd_generic_link_add_one_symbol,
4280 coff_link_output_has_begun,
4281 coff_final_link_postscript,
4282 NULL /* print_pdata. */
4285 0x01DF, /* magic number */
4289 /* Function pointers to xcoff specific swap routines. */
4290 xcoff_swap_ldhdr_in,
4291 xcoff_swap_ldhdr_out,
4292 xcoff_swap_ldsym_in,
4293 xcoff_swap_ldsym_out,
4294 xcoff_swap_ldrel_in,
4295 xcoff_swap_ldrel_out,
4301 12, /* _xcoff_function_descriptor_size */
4305 1, /* _xcoff_ldhdr_version */
4307 _bfd_xcoff_put_symbol_name,
4308 _bfd_xcoff_put_ldsymbol_name,
4309 &xcoff_dynamic_reloc,
4310 xcoff_create_csect_from_smclas,
4312 /* Lineno and reloc count overflow. */
4313 xcoff_is_lineno_count_overflow,
4314 xcoff_is_reloc_count_overflow,
4316 xcoff_loader_symbol_offset,
4317 xcoff_loader_reloc_offset,
4320 &xcoff_glink_code[0],
4321 36, /* _xcoff_glink_size */
4324 0, /* _xcoff_rtinit_size */
4325 xcoff_generate_rtinit,
4328 /* The transfer vector that leads the outside world to all of the above. */
4329 const bfd_target powerpc_xcoff_vec =
4332 bfd_target_xcoff_flavour,
4333 BFD_ENDIAN_BIG, /* data byte order is big */
4334 BFD_ENDIAN_BIG, /* header byte order is big */
4336 (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | DYNAMIC
4337 | HAS_SYMS | HAS_LOCALS | WP_TEXT),
4339 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA,
4340 0, /* leading char */
4341 '/', /* ar_pad_char */
4342 15, /* ar_max_namelen */
4343 0, /* match priority. */
4367 { /* bfd_check_format */
4370 _bfd_xcoff_archive_p,
4374 { /* bfd_set_format */
4377 _bfd_generic_mkarchive,
4381 {/* bfd_write_contents */
4383 coff_write_object_contents,
4384 _bfd_xcoff_write_archive_contents,
4388 BFD_JUMP_TABLE_GENERIC (_bfd_xcoff),
4389 BFD_JUMP_TABLE_COPY (_bfd_xcoff),
4390 BFD_JUMP_TABLE_CORE (coff),
4391 BFD_JUMP_TABLE_ARCHIVE (_bfd_xcoff),
4392 BFD_JUMP_TABLE_SYMBOLS (_bfd_xcoff),
4393 BFD_JUMP_TABLE_RELOCS (_bfd_xcoff),
4394 BFD_JUMP_TABLE_WRITE (coff),
4395 BFD_JUMP_TABLE_LINK (_bfd_xcoff),
4396 BFD_JUMP_TABLE_DYNAMIC (_bfd_xcoff),
4398 /* Opposite endian version, none exists */
4401 & bfd_pmac_xcoff_backend_data,