1 /* BFD back-end for IBM RS/6000 "XCOFF" files.
2 Copyright (C) 1990-2014 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
117 #include "coffcode.h"
119 /* The main body of code is in coffcode.h. */
121 static const char *normalize_filename (bfd *);
122 static bfd_boolean xcoff_write_armap_old
123 (bfd *, unsigned int, struct orl *, unsigned int, int);
124 static bfd_boolean xcoff_write_armap_big
125 (bfd *, unsigned int, struct orl *, unsigned int, int);
126 static bfd_boolean xcoff_write_archive_contents_old (bfd *);
127 static bfd_boolean xcoff_write_archive_contents_big (bfd *);
128 static void xcoff_swap_ldhdr_in (bfd *, const void *, struct internal_ldhdr *);
129 static void xcoff_swap_ldhdr_out (bfd *, const struct internal_ldhdr *, void *);
130 static void xcoff_swap_ldsym_in (bfd *, const void *, struct internal_ldsym *);
131 static void xcoff_swap_ldsym_out (bfd *, const struct internal_ldsym *, void *);
132 static void xcoff_swap_ldrel_in (bfd *, const void *, struct internal_ldrel *);
133 static void xcoff_swap_ldrel_out (bfd *, const struct internal_ldrel *, void *);
134 static bfd_boolean xcoff_ppc_relocate_section
135 (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
136 struct internal_reloc *, struct internal_syment *, asection **);
137 static bfd_boolean _bfd_xcoff_put_ldsymbol_name
138 (bfd *, struct xcoff_loader_info *, struct internal_ldsym *, const char *);
139 static asection *xcoff_create_csect_from_smclas
140 (bfd *, union internal_auxent *, const char *);
141 static bfd_boolean xcoff_is_lineno_count_overflow (bfd *, bfd_vma);
142 static bfd_boolean xcoff_is_reloc_count_overflow (bfd *, bfd_vma);
143 static bfd_vma xcoff_loader_symbol_offset (bfd *, struct internal_ldhdr *);
144 static bfd_vma xcoff_loader_reloc_offset (bfd *, struct internal_ldhdr *);
145 static bfd_boolean xcoff_generate_rtinit
146 (bfd *, const char *, const char *, bfd_boolean);
147 static bfd_boolean do_pad (bfd *, unsigned int);
148 static bfd_boolean do_copy (bfd *, bfd *);
150 /* Relocation functions */
151 static bfd_boolean xcoff_reloc_type_br (XCOFF_RELOC_FUNCTION_ARGS);
153 static bfd_boolean xcoff_complain_overflow_dont_func
154 (XCOFF_COMPLAIN_FUNCTION_ARGS);
155 static bfd_boolean xcoff_complain_overflow_bitfield_func
156 (XCOFF_COMPLAIN_FUNCTION_ARGS);
157 static bfd_boolean xcoff_complain_overflow_signed_func
158 (XCOFF_COMPLAIN_FUNCTION_ARGS);
159 static bfd_boolean xcoff_complain_overflow_unsigned_func
160 (XCOFF_COMPLAIN_FUNCTION_ARGS);
162 bfd_boolean (*xcoff_calculate_relocation[XCOFF_MAX_CALCULATE_RELOCATION])
163 (XCOFF_RELOC_FUNCTION_ARGS) =
165 xcoff_reloc_type_pos, /* R_POS (0x00) */
166 xcoff_reloc_type_neg, /* R_NEG (0x01) */
167 xcoff_reloc_type_rel, /* R_REL (0x02) */
168 xcoff_reloc_type_toc, /* R_TOC (0x03) */
169 xcoff_reloc_type_fail, /* R_RTB (0x04) */
170 xcoff_reloc_type_toc, /* R_GL (0x05) */
171 xcoff_reloc_type_toc, /* R_TCL (0x06) */
172 xcoff_reloc_type_fail, /* (0x07) */
173 xcoff_reloc_type_ba, /* R_BA (0x08) */
174 xcoff_reloc_type_fail, /* (0x09) */
175 xcoff_reloc_type_br, /* R_BR (0x0a) */
176 xcoff_reloc_type_fail, /* (0x0b) */
177 xcoff_reloc_type_pos, /* R_RL (0x0c) */
178 xcoff_reloc_type_pos, /* R_RLA (0x0d) */
179 xcoff_reloc_type_fail, /* (0x0e) */
180 xcoff_reloc_type_noop, /* R_REF (0x0f) */
181 xcoff_reloc_type_fail, /* (0x10) */
182 xcoff_reloc_type_fail, /* (0x11) */
183 xcoff_reloc_type_toc, /* R_TRL (0x12) */
184 xcoff_reloc_type_toc, /* R_TRLA (0x13) */
185 xcoff_reloc_type_fail, /* R_RRTBI (0x14) */
186 xcoff_reloc_type_fail, /* R_RRTBA (0x15) */
187 xcoff_reloc_type_ba, /* R_CAI (0x16) */
188 xcoff_reloc_type_crel, /* R_CREL (0x17) */
189 xcoff_reloc_type_ba, /* R_RBA (0x18) */
190 xcoff_reloc_type_ba, /* R_RBAC (0x19) */
191 xcoff_reloc_type_br, /* R_RBR (0x1a) */
192 xcoff_reloc_type_ba, /* R_RBRC (0x1b) */
195 bfd_boolean (*xcoff_complain_overflow[XCOFF_MAX_COMPLAIN_OVERFLOW])
196 (XCOFF_COMPLAIN_FUNCTION_ARGS) =
198 xcoff_complain_overflow_dont_func,
199 xcoff_complain_overflow_bitfield_func,
200 xcoff_complain_overflow_signed_func,
201 xcoff_complain_overflow_unsigned_func,
204 /* Information about one member of an archive. */
205 struct member_layout {
206 /* The archive member that this structure describes. */
209 /* The number of bytes of padding that must be inserted before the
210 start of the member in order to ensure that the section contents
211 are correctly aligned. */
212 unsigned int leading_padding;
214 /* The offset of MEMBER from the start of the archive (i.e. the end
215 of the leading padding). */
218 /* The normalized name of MEMBER. */
221 /* The length of NAME, without padding. */
222 bfd_size_type namlen;
224 /* The length of NAME, with padding. */
225 bfd_size_type padded_namlen;
227 /* The size of MEMBER's header, including the name and magic sequence. */
228 bfd_size_type header_size;
230 /* The size of the MEMBER's contents. */
231 bfd_size_type contents_size;
233 /* The number of bytes of padding that must be inserted after MEMBER
234 in order to preserve even alignment. */
235 bfd_size_type trailing_padding;
238 /* A structure used for iterating over the members of an archive. */
239 struct archive_iterator {
240 /* The archive itself. */
243 /* Information about the current archive member. */
244 struct member_layout current;
246 /* Information about the next archive member. MEMBER is null if there
247 are no more archive members, in which case OFFSET is the offset of
248 the first unused byte. */
249 struct member_layout next;
252 /* Initialize INFO so that it describes member MEMBER of archive ARCHIVE.
253 OFFSET is the even-padded offset of MEMBER, not including any leading
254 padding needed for section alignment. */
257 member_layout_init (struct member_layout *info, bfd *archive,
258 bfd *member, file_ptr offset)
260 info->member = member;
261 info->leading_padding = 0;
264 info->name = normalize_filename (member);
265 info->namlen = strlen (info->name);
266 info->padded_namlen = info->namlen + (info->namlen & 1);
267 if (xcoff_big_format_p (archive))
268 info->header_size = SIZEOF_AR_HDR_BIG;
270 info->header_size = SIZEOF_AR_HDR;
271 info->header_size += info->padded_namlen + SXCOFFARFMAG;
272 info->contents_size = arelt_size (member);
273 info->trailing_padding = info->contents_size & 1;
275 if (bfd_check_format (member, bfd_object)
276 && bfd_get_flavour (member) == bfd_target_xcoff_flavour
277 && (member->flags & DYNAMIC) != 0)
278 info->leading_padding
279 = (-(offset + info->header_size)
280 & ((1 << bfd_xcoff_text_align_power (member)) - 1));
282 info->offset = offset + info->leading_padding;
285 /* Set up ITERATOR to iterate through archive ARCHIVE. */
288 archive_iterator_begin (struct archive_iterator *iterator,
291 iterator->archive = archive;
292 member_layout_init (&iterator->next, archive, archive->archive_head,
293 xcoff_big_format_p (archive)
294 ? SIZEOF_AR_FILE_HDR_BIG
295 : SIZEOF_AR_FILE_HDR);
298 /* Make ITERATOR visit the first unvisited archive member. Return true
299 on success; return false if all members have been visited. */
302 archive_iterator_next (struct archive_iterator *iterator)
304 if (!iterator->next.member)
307 iterator->current = iterator->next;
308 member_layout_init (&iterator->next, iterator->archive,
309 iterator->current.member->archive_next,
310 iterator->current.offset
311 + iterator->current.header_size
312 + iterator->current.contents_size
313 + iterator->current.trailing_padding);
317 /* We use our own tdata type. Its first field is the COFF tdata type,
318 so the COFF routines are compatible. */
321 _bfd_xcoff_mkobject (bfd *abfd)
323 coff_data_type *coff;
324 bfd_size_type amt = sizeof (struct xcoff_tdata);
326 abfd->tdata.xcoff_obj_data = (struct xcoff_tdata *) bfd_zalloc (abfd, amt);
327 if (abfd->tdata.xcoff_obj_data == NULL)
329 coff = coff_data (abfd);
330 coff->symbols = (coff_symbol_type *) NULL;
331 coff->conversion_table = (unsigned int *) NULL;
332 coff->raw_syments = (struct coff_ptr_struct *) NULL;
335 xcoff_data (abfd)->modtype = ('1' << 8) | 'L';
337 /* We set cputype to -1 to indicate that it has not been
339 xcoff_data (abfd)->cputype = -1;
341 xcoff_data (abfd)->csects = NULL;
342 xcoff_data (abfd)->debug_indices = NULL;
344 /* text section alignment is different than the default */
345 bfd_xcoff_text_align_power (abfd) = 2;
350 /* Copy XCOFF data from one BFD to another. */
353 _bfd_xcoff_copy_private_bfd_data (bfd *ibfd, bfd *obfd)
355 struct xcoff_tdata *ix, *ox;
358 if (ibfd->xvec != obfd->xvec)
360 ix = xcoff_data (ibfd);
361 ox = xcoff_data (obfd);
362 ox->full_aouthdr = ix->full_aouthdr;
368 sec = coff_section_from_bfd_index (ibfd, ix->sntoc);
372 ox->sntoc = sec->output_section->target_index;
374 if (ix->snentry == 0)
378 sec = coff_section_from_bfd_index (ibfd, ix->snentry);
382 ox->snentry = sec->output_section->target_index;
384 bfd_xcoff_text_align_power (obfd) = bfd_xcoff_text_align_power (ibfd);
385 bfd_xcoff_data_align_power (obfd) = bfd_xcoff_data_align_power (ibfd);
386 ox->modtype = ix->modtype;
387 ox->cputype = ix->cputype;
388 ox->maxdata = ix->maxdata;
389 ox->maxstack = ix->maxstack;
393 /* I don't think XCOFF really has a notion of local labels based on
394 name. This will mean that ld -X doesn't actually strip anything.
395 The AIX native linker does not have a -X option, and it ignores the
399 _bfd_xcoff_is_local_label_name (bfd *abfd ATTRIBUTE_UNUSED,
400 const char *name ATTRIBUTE_UNUSED)
405 static const struct dwarf_debug_section xcoff_debug_sections[] =
407 { ".dwabrev", NULL },
408 { ".dwarnge", NULL },
409 { NULL, NULL }, /* .debug_frame */
412 { NULL, NULL }, /* .debug_loc */
413 { NULL, NULL }, /* .debug_macinfo */
414 { NULL, NULL }, /* .debug_macro */
415 { ".dwpbnms", NULL },
416 { ".dwpbtyp", NULL },
417 { ".dwrnges", NULL },
418 { NULL, NULL }, /* .debug_static_func */
419 { NULL, NULL }, /* .debug_static_vars */
421 { NULL, NULL }, /* .debug_types */
422 /* GNU DWARF 1 extensions */
423 { NULL, NULL }, /* .debug_sfnames */
424 { NULL, NULL }, /* .debug_srcinfo */
425 /* SGI/MIPS DWARF 2 extensions */
426 { NULL, NULL }, /* .debug_funcnames */
427 { NULL, NULL }, /* .debug_typenames */
428 { NULL, NULL }, /* .debug_varnames */
429 { NULL, NULL }, /* .debug_weaknames */
434 xcoff_find_nearest_line (bfd *abfd,
438 const char **filename_ptr,
439 const char **functionname_ptr,
440 unsigned int *line_ptr)
442 return coff_find_nearest_line_with_names (abfd, xcoff_debug_sections,
443 section, symbols, offset,
444 filename_ptr, functionname_ptr,
449 xcoff_find_nearest_line_discriminator (bfd *abfd,
453 const char **filename_ptr,
454 const char **functionname_ptr,
455 unsigned int *line_ptr,
456 unsigned int *discriminator)
459 return coff_find_nearest_line_with_names (abfd, xcoff_debug_sections,
460 section, symbols, offset,
461 filename_ptr, functionname_ptr,
467 _bfd_xcoff_swap_sym_in (bfd *abfd, void * ext1, void * in1)
469 SYMENT *ext = (SYMENT *)ext1;
470 struct internal_syment * in = (struct internal_syment *)in1;
472 if (ext->e.e_name[0] != 0)
474 memcpy (in->_n._n_name, ext->e.e_name, SYMNMLEN);
478 in->_n._n_n._n_zeroes = 0;
479 in->_n._n_n._n_offset = H_GET_32 (abfd, ext->e.e.e_offset);
482 in->n_value = H_GET_32 (abfd, ext->e_value);
483 in->n_scnum = H_GET_16 (abfd, ext->e_scnum);
484 in->n_type = H_GET_16 (abfd, ext->e_type);
485 in->n_sclass = H_GET_8 (abfd, ext->e_sclass);
486 in->n_numaux = H_GET_8 (abfd, ext->e_numaux);
490 _bfd_xcoff_swap_sym_out (bfd *abfd, void * inp, void * extp)
492 struct internal_syment *in = (struct internal_syment *)inp;
493 SYMENT *ext =(SYMENT *)extp;
495 if (in->_n._n_name[0] != 0)
497 memcpy (ext->e.e_name, in->_n._n_name, SYMNMLEN);
501 H_PUT_32 (abfd, 0, ext->e.e.e_zeroes);
502 H_PUT_32 (abfd, in->_n._n_n._n_offset, ext->e.e.e_offset);
505 H_PUT_32 (abfd, in->n_value, ext->e_value);
506 H_PUT_16 (abfd, in->n_scnum, ext->e_scnum);
507 H_PUT_16 (abfd, in->n_type, ext->e_type);
508 H_PUT_8 (abfd, in->n_sclass, ext->e_sclass);
509 H_PUT_8 (abfd, in->n_numaux, ext->e_numaux);
510 return bfd_coff_symesz (abfd);
514 _bfd_xcoff_swap_aux_in (bfd *abfd, void * ext1, int type, int in_class,
515 int indx, int numaux, void * in1)
517 AUXENT * ext = (AUXENT *)ext1;
518 union internal_auxent *in = (union internal_auxent *)in1;
523 if (ext->x_file.x_n.x_fname[0] == 0)
525 in->x_file.x_n.x_zeroes = 0;
526 in->x_file.x_n.x_offset =
527 H_GET_32 (abfd, ext->x_file.x_n.x_n.x_offset);
534 memcpy (in->x_file.x_fname, ext->x_file.x_n.x_fname,
535 numaux * sizeof (AUXENT));
539 memcpy (in->x_file.x_fname, ext->x_file.x_n.x_fname, FILNMLEN);
544 /* RS/6000 "csect" auxents */
548 if (indx + 1 == numaux)
550 in->x_csect.x_scnlen.l = H_GET_32 (abfd, ext->x_csect.x_scnlen);
551 in->x_csect.x_parmhash = H_GET_32 (abfd, ext->x_csect.x_parmhash);
552 in->x_csect.x_snhash = H_GET_16 (abfd, ext->x_csect.x_snhash);
553 /* We don't have to hack bitfields in x_smtyp because it's
554 defined by shifts-and-ands, which are equivalent on all
556 in->x_csect.x_smtyp = H_GET_8 (abfd, ext->x_csect.x_smtyp);
557 in->x_csect.x_smclas = H_GET_8 (abfd, ext->x_csect.x_smclas);
558 in->x_csect.x_stab = H_GET_32 (abfd, ext->x_csect.x_stab);
559 in->x_csect.x_snstab = H_GET_16 (abfd, ext->x_csect.x_snstab);
569 in->x_scn.x_scnlen = H_GET_32 (abfd, ext->x_scn.x_scnlen);
570 in->x_scn.x_nreloc = H_GET_16 (abfd, ext->x_scn.x_nreloc);
571 in->x_scn.x_nlinno = H_GET_16 (abfd, ext->x_scn.x_nlinno);
572 /* PE defines some extra fields; we zero them out for
574 in->x_scn.x_checksum = 0;
575 in->x_scn.x_associated = 0;
576 in->x_scn.x_comdat = 0;
583 in->x_sym.x_tagndx.l = H_GET_32 (abfd, ext->x_sym.x_tagndx);
584 in->x_sym.x_tvndx = H_GET_16 (abfd, ext->x_sym.x_tvndx);
586 if (in_class == C_BLOCK || in_class == C_FCN || ISFCN (type)
589 in->x_sym.x_fcnary.x_fcn.x_lnnoptr =
590 H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_lnnoptr);
591 in->x_sym.x_fcnary.x_fcn.x_endndx.l =
592 H_GET_32 (abfd, ext->x_sym.x_fcnary.x_fcn.x_endndx);
596 in->x_sym.x_fcnary.x_ary.x_dimen[0] =
597 H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
598 in->x_sym.x_fcnary.x_ary.x_dimen[1] =
599 H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
600 in->x_sym.x_fcnary.x_ary.x_dimen[2] =
601 H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
602 in->x_sym.x_fcnary.x_ary.x_dimen[3] =
603 H_GET_16 (abfd, ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
608 in->x_sym.x_misc.x_fsize = H_GET_32 (abfd, ext->x_sym.x_misc.x_fsize);
612 in->x_sym.x_misc.x_lnsz.x_lnno =
613 H_GET_16 (abfd, ext->x_sym.x_misc.x_lnsz.x_lnno);
614 in->x_sym.x_misc.x_lnsz.x_size =
615 H_GET_16 (abfd, ext->x_sym.x_misc.x_lnsz.x_size);
619 /* The semicolon is because MSVC doesn't like labels at
624 _bfd_xcoff_swap_aux_out (bfd *abfd, void * inp, int type, int in_class,
625 int indx ATTRIBUTE_UNUSED,
626 int numaux ATTRIBUTE_UNUSED,
629 union internal_auxent *in = (union internal_auxent *)inp;
630 AUXENT *ext = (AUXENT *)extp;
632 memset (ext, 0, bfd_coff_auxesz (abfd));
636 if (in->x_file.x_fname[0] == 0)
638 H_PUT_32 (abfd, 0, ext->x_file.x_n.x_n.x_zeroes);
639 H_PUT_32 (abfd, in->x_file.x_n.x_offset,
640 ext->x_file.x_n.x_n.x_offset);
644 memcpy (ext->x_file.x_n.x_fname, in->x_file.x_fname, FILNMLEN);
648 /* RS/6000 "csect" auxents */
652 if (indx + 1 == numaux)
654 H_PUT_32 (abfd, in->x_csect.x_scnlen.l, ext->x_csect.x_scnlen);
655 H_PUT_32 (abfd, in->x_csect.x_parmhash, ext->x_csect.x_parmhash);
656 H_PUT_16 (abfd, in->x_csect.x_snhash, ext->x_csect.x_snhash);
657 /* We don't have to hack bitfields in x_smtyp because it's
658 defined by shifts-and-ands, which are equivalent on all
660 H_PUT_8 (abfd, in->x_csect.x_smtyp, ext->x_csect.x_smtyp);
661 H_PUT_8 (abfd, in->x_csect.x_smclas, ext->x_csect.x_smclas);
662 H_PUT_32 (abfd, in->x_csect.x_stab, ext->x_csect.x_stab);
663 H_PUT_16 (abfd, in->x_csect.x_snstab, ext->x_csect.x_snstab);
673 H_PUT_32 (abfd, in->x_scn.x_scnlen, ext->x_scn.x_scnlen);
674 H_PUT_16 (abfd, in->x_scn.x_nreloc, ext->x_scn.x_nreloc);
675 H_PUT_16 (abfd, in->x_scn.x_nlinno, ext->x_scn.x_nlinno);
681 H_PUT_32 (abfd, in->x_sym.x_tagndx.l, ext->x_sym.x_tagndx);
682 H_PUT_16 (abfd, in->x_sym.x_tvndx, ext->x_sym.x_tvndx);
684 if (in_class == C_BLOCK || in_class == C_FCN || ISFCN (type)
687 H_PUT_32 (abfd, in->x_sym.x_fcnary.x_fcn.x_lnnoptr,
688 ext->x_sym.x_fcnary.x_fcn.x_lnnoptr);
689 H_PUT_32 (abfd, in->x_sym.x_fcnary.x_fcn.x_endndx.l,
690 ext->x_sym.x_fcnary.x_fcn.x_endndx);
694 H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[0],
695 ext->x_sym.x_fcnary.x_ary.x_dimen[0]);
696 H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[1],
697 ext->x_sym.x_fcnary.x_ary.x_dimen[1]);
698 H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[2],
699 ext->x_sym.x_fcnary.x_ary.x_dimen[2]);
700 H_PUT_16 (abfd, in->x_sym.x_fcnary.x_ary.x_dimen[3],
701 ext->x_sym.x_fcnary.x_ary.x_dimen[3]);
705 H_PUT_32 (abfd, in->x_sym.x_misc.x_fsize, ext->x_sym.x_misc.x_fsize);
708 H_PUT_16 (abfd, in->x_sym.x_misc.x_lnsz.x_lnno,
709 ext->x_sym.x_misc.x_lnsz.x_lnno);
710 H_PUT_16 (abfd, in->x_sym.x_misc.x_lnsz.x_size,
711 ext->x_sym.x_misc.x_lnsz.x_size);
715 return bfd_coff_auxesz (abfd);
720 /* The XCOFF reloc table. Actually, XCOFF relocations specify the
721 bitsize and whether they are signed or not, along with a
722 conventional type. This table is for the types, which are used for
723 different algorithms for putting in the reloc. Many of these
724 relocs need special_function entries, which I have not written. */
727 reloc_howto_type xcoff_howto_table[] =
729 /* 0x00: Standard 32 bit relocation. */
730 HOWTO (R_POS, /* type */
732 2, /* size (0 = byte, 1 = short, 2 = long) */
734 FALSE, /* pc_relative */
736 complain_overflow_bitfield, /* complain_on_overflow */
737 0, /* special_function */
739 TRUE, /* partial_inplace */
740 0xffffffff, /* src_mask */
741 0xffffffff, /* dst_mask */
742 FALSE), /* pcrel_offset */
744 /* 0x01: 32 bit relocation, but store negative value. */
745 HOWTO (R_NEG, /* type */
747 -2, /* size (0 = byte, 1 = short, 2 = long) */
749 FALSE, /* pc_relative */
751 complain_overflow_bitfield, /* complain_on_overflow */
752 0, /* special_function */
754 TRUE, /* partial_inplace */
755 0xffffffff, /* src_mask */
756 0xffffffff, /* dst_mask */
757 FALSE), /* pcrel_offset */
759 /* 0x02: 32 bit PC relative relocation. */
760 HOWTO (R_REL, /* type */
762 2, /* size (0 = byte, 1 = short, 2 = long) */
764 TRUE, /* pc_relative */
766 complain_overflow_signed, /* complain_on_overflow */
767 0, /* special_function */
769 TRUE, /* partial_inplace */
770 0xffffffff, /* src_mask */
771 0xffffffff, /* dst_mask */
772 FALSE), /* pcrel_offset */
774 /* 0x03: 16 bit TOC relative relocation. */
775 HOWTO (R_TOC, /* type */
777 1, /* size (0 = byte, 1 = short, 2 = long) */
779 FALSE, /* pc_relative */
781 complain_overflow_bitfield, /* complain_on_overflow */
782 0, /* special_function */
784 TRUE, /* partial_inplace */
785 0xffff, /* src_mask */
786 0xffff, /* dst_mask */
787 FALSE), /* pcrel_offset */
789 /* 0x04: I don't really know what this is. */
790 HOWTO (R_RTB, /* type */
792 2, /* size (0 = byte, 1 = short, 2 = long) */
794 FALSE, /* pc_relative */
796 complain_overflow_bitfield, /* complain_on_overflow */
797 0, /* special_function */
799 TRUE, /* partial_inplace */
800 0xffffffff, /* src_mask */
801 0xffffffff, /* dst_mask */
802 FALSE), /* pcrel_offset */
804 /* 0x05: External TOC relative symbol. */
805 HOWTO (R_GL, /* type */
807 1, /* size (0 = byte, 1 = short, 2 = long) */
809 FALSE, /* pc_relative */
811 complain_overflow_bitfield, /* complain_on_overflow */
812 0, /* special_function */
814 TRUE, /* partial_inplace */
815 0xffff, /* src_mask */
816 0xffff, /* dst_mask */
817 FALSE), /* pcrel_offset */
819 /* 0x06: Local TOC relative symbol. */
820 HOWTO (R_TCL, /* type */
822 1, /* size (0 = byte, 1 = short, 2 = long) */
824 FALSE, /* pc_relative */
826 complain_overflow_bitfield, /* complain_on_overflow */
827 0, /* special_function */
829 TRUE, /* partial_inplace */
830 0xffff, /* src_mask */
831 0xffff, /* dst_mask */
832 FALSE), /* pcrel_offset */
836 /* 0x08: Non modifiable absolute branch. */
837 HOWTO (R_BA, /* type */
839 2, /* size (0 = byte, 1 = short, 2 = long) */
841 FALSE, /* pc_relative */
843 complain_overflow_bitfield, /* complain_on_overflow */
844 0, /* special_function */
845 "R_BA_26", /* name */
846 TRUE, /* partial_inplace */
847 0x03fffffc, /* src_mask */
848 0x03fffffc, /* dst_mask */
849 FALSE), /* pcrel_offset */
853 /* 0x0a: Non modifiable relative branch. */
854 HOWTO (R_BR, /* type */
856 2, /* size (0 = byte, 1 = short, 2 = long) */
858 TRUE, /* pc_relative */
860 complain_overflow_signed, /* complain_on_overflow */
861 0, /* special_function */
863 TRUE, /* partial_inplace */
864 0x03fffffc, /* src_mask */
865 0x03fffffc, /* dst_mask */
866 FALSE), /* pcrel_offset */
870 /* 0x0c: Indirect load. */
871 HOWTO (R_RL, /* type */
873 1, /* size (0 = byte, 1 = short, 2 = long) */
875 FALSE, /* pc_relative */
877 complain_overflow_bitfield, /* complain_on_overflow */
878 0, /* special_function */
880 TRUE, /* partial_inplace */
881 0xffff, /* src_mask */
882 0xffff, /* dst_mask */
883 FALSE), /* pcrel_offset */
885 /* 0x0d: Load address. */
886 HOWTO (R_RLA, /* type */
888 1, /* size (0 = byte, 1 = short, 2 = long) */
890 FALSE, /* pc_relative */
892 complain_overflow_bitfield, /* complain_on_overflow */
893 0, /* special_function */
895 TRUE, /* partial_inplace */
896 0xffff, /* src_mask */
897 0xffff, /* dst_mask */
898 FALSE), /* pcrel_offset */
902 /* 0x0f: Non-relocating reference. Bitsize is 1 so that r_rsize is 0. */
903 HOWTO (R_REF, /* type */
905 0, /* size (0 = byte, 1 = short, 2 = long) */
907 FALSE, /* pc_relative */
909 complain_overflow_dont, /* complain_on_overflow */
910 0, /* special_function */
912 FALSE, /* partial_inplace */
915 FALSE), /* pcrel_offset */
920 /* 0x12: TOC relative indirect load. */
921 HOWTO (R_TRL, /* type */
923 1, /* size (0 = byte, 1 = short, 2 = long) */
925 FALSE, /* pc_relative */
927 complain_overflow_bitfield, /* complain_on_overflow */
928 0, /* special_function */
930 TRUE, /* partial_inplace */
931 0xffff, /* src_mask */
932 0xffff, /* dst_mask */
933 FALSE), /* pcrel_offset */
935 /* 0x13: TOC relative load address. */
936 HOWTO (R_TRLA, /* type */
938 1, /* size (0 = byte, 1 = short, 2 = long) */
940 FALSE, /* pc_relative */
942 complain_overflow_bitfield, /* complain_on_overflow */
943 0, /* special_function */
945 TRUE, /* partial_inplace */
946 0xffff, /* src_mask */
947 0xffff, /* dst_mask */
948 FALSE), /* pcrel_offset */
950 /* 0x14: Modifiable relative branch. */
951 HOWTO (R_RRTBI, /* type */
953 2, /* size (0 = byte, 1 = short, 2 = long) */
955 FALSE, /* pc_relative */
957 complain_overflow_bitfield, /* complain_on_overflow */
958 0, /* special_function */
959 "R_RRTBI", /* name */
960 TRUE, /* partial_inplace */
961 0xffffffff, /* src_mask */
962 0xffffffff, /* dst_mask */
963 FALSE), /* pcrel_offset */
965 /* 0x15: Modifiable absolute branch. */
966 HOWTO (R_RRTBA, /* type */
968 2, /* size (0 = byte, 1 = short, 2 = long) */
970 FALSE, /* pc_relative */
972 complain_overflow_bitfield, /* complain_on_overflow */
973 0, /* special_function */
974 "R_RRTBA", /* name */
975 TRUE, /* partial_inplace */
976 0xffffffff, /* src_mask */
977 0xffffffff, /* dst_mask */
978 FALSE), /* pcrel_offset */
980 /* 0x16: Modifiable call absolute indirect. */
981 HOWTO (R_CAI, /* type */
983 1, /* size (0 = byte, 1 = short, 2 = long) */
985 FALSE, /* pc_relative */
987 complain_overflow_bitfield, /* complain_on_overflow */
988 0, /* special_function */
990 TRUE, /* partial_inplace */
991 0xffff, /* src_mask */
992 0xffff, /* dst_mask */
993 FALSE), /* pcrel_offset */
995 /* 0x17: Modifiable call relative. */
996 HOWTO (R_CREL, /* type */
998 1, /* size (0 = byte, 1 = short, 2 = long) */
1000 FALSE, /* pc_relative */
1002 complain_overflow_bitfield, /* complain_on_overflow */
1003 0, /* special_function */
1004 "R_CREL", /* name */
1005 TRUE, /* partial_inplace */
1006 0xffff, /* src_mask */
1007 0xffff, /* dst_mask */
1008 FALSE), /* pcrel_offset */
1010 /* 0x18: Modifiable branch absolute. */
1011 HOWTO (R_RBA, /* type */
1013 2, /* size (0 = byte, 1 = short, 2 = long) */
1015 FALSE, /* pc_relative */
1017 complain_overflow_bitfield, /* complain_on_overflow */
1018 0, /* special_function */
1020 TRUE, /* partial_inplace */
1021 0x03fffffc, /* src_mask */
1022 0x03fffffc, /* dst_mask */
1023 FALSE), /* pcrel_offset */
1025 /* 0x19: Modifiable branch absolute. */
1026 HOWTO (R_RBAC, /* type */
1028 2, /* size (0 = byte, 1 = short, 2 = long) */
1030 FALSE, /* pc_relative */
1032 complain_overflow_bitfield, /* complain_on_overflow */
1033 0, /* special_function */
1034 "R_RBAC", /* name */
1035 TRUE, /* partial_inplace */
1036 0xffffffff, /* src_mask */
1037 0xffffffff, /* dst_mask */
1038 FALSE), /* pcrel_offset */
1040 /* 0x1a: Modifiable branch relative. */
1041 HOWTO (R_RBR, /* type */
1043 2, /* size (0 = byte, 1 = short, 2 = long) */
1045 FALSE, /* pc_relative */
1047 complain_overflow_signed, /* complain_on_overflow */
1048 0, /* special_function */
1049 "R_RBR_26", /* name */
1050 TRUE, /* partial_inplace */
1051 0x03fffffc, /* src_mask */
1052 0x03fffffc, /* dst_mask */
1053 FALSE), /* pcrel_offset */
1055 /* 0x1b: Modifiable branch absolute. */
1056 HOWTO (R_RBRC, /* type */
1058 1, /* size (0 = byte, 1 = short, 2 = long) */
1060 FALSE, /* pc_relative */
1062 complain_overflow_bitfield, /* complain_on_overflow */
1063 0, /* special_function */
1064 "R_RBRC", /* name */
1065 TRUE, /* partial_inplace */
1066 0xffff, /* src_mask */
1067 0xffff, /* dst_mask */
1068 FALSE), /* pcrel_offset */
1070 /* 0x1c: 16 bit Non modifiable absolute branch. */
1071 HOWTO (R_BA, /* type */
1073 1, /* size (0 = byte, 1 = short, 2 = long) */
1075 FALSE, /* pc_relative */
1077 complain_overflow_bitfield, /* complain_on_overflow */
1078 0, /* special_function */
1079 "R_BA_16", /* name */
1080 TRUE, /* partial_inplace */
1081 0xfffc, /* src_mask */
1082 0xfffc, /* dst_mask */
1083 FALSE), /* pcrel_offset */
1085 /* 0x1d: Modifiable branch relative. */
1086 HOWTO (R_RBR, /* type */
1088 1, /* size (0 = byte, 1 = short, 2 = long) */
1090 TRUE, /* pc_relative */
1092 complain_overflow_signed, /* complain_on_overflow */
1093 0, /* special_function */
1094 "R_RBR_16", /* name */
1095 TRUE, /* partial_inplace */
1096 0xfffc, /* src_mask */
1097 0xfffc, /* dst_mask */
1098 FALSE), /* pcrel_offset */
1100 /* 0x1e: Modifiable branch relative. */
1101 HOWTO (R_RBA, /* type */
1103 1, /* size (0 = byte, 1 = short, 2 = long) */
1105 FALSE, /* pc_relative */
1107 complain_overflow_signed, /* complain_on_overflow */
1108 0, /* special_function */
1109 "R_RBA_16", /* name */
1110 TRUE, /* partial_inplace */
1111 0xffff, /* src_mask */
1112 0xffff, /* dst_mask */
1113 FALSE), /* pcrel_offset */
1117 xcoff_rtype2howto (arelent *relent, struct internal_reloc *internal)
1119 if (internal->r_type > R_RBRC)
1122 /* Default howto layout works most of the time */
1123 relent->howto = &xcoff_howto_table[internal->r_type];
1125 /* Special case some 16 bit reloc */
1126 if (15 == (internal->r_size & 0x1f))
1128 if (R_BA == internal->r_type)
1129 relent->howto = &xcoff_howto_table[0x1c];
1130 else if (R_RBR == internal->r_type)
1131 relent->howto = &xcoff_howto_table[0x1d];
1132 else if (R_RBA == internal->r_type)
1133 relent->howto = &xcoff_howto_table[0x1e];
1136 /* The r_size field of an XCOFF reloc encodes the bitsize of the
1137 relocation, as well as indicating whether it is signed or not.
1138 Doublecheck that the relocation information gathered from the
1139 type matches this information. The bitsize is not significant
1140 for R_REF relocs. */
1141 if (relent->howto->dst_mask != 0
1142 && (relent->howto->bitsize
1143 != ((unsigned int) internal->r_size & 0x1f) + 1))
1148 _bfd_xcoff_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1149 bfd_reloc_code_real_type code)
1153 case BFD_RELOC_PPC_B26:
1154 return &xcoff_howto_table[0xa];
1155 case BFD_RELOC_PPC_BA16:
1156 return &xcoff_howto_table[0x1c];
1157 case BFD_RELOC_PPC_BA26:
1158 return &xcoff_howto_table[8];
1159 case BFD_RELOC_PPC_TOC16:
1160 return &xcoff_howto_table[3];
1162 /* Note that this relocation is only internally used by gas. */
1163 return &xcoff_howto_table[0xc];
1164 case BFD_RELOC_PPC_B16:
1165 return &xcoff_howto_table[0x1d];
1167 case BFD_RELOC_CTOR:
1168 return &xcoff_howto_table[0];
1169 case BFD_RELOC_NONE:
1170 return &xcoff_howto_table[0xf];
1176 static reloc_howto_type *
1177 _bfd_xcoff_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
1183 i < sizeof (xcoff_howto_table) / sizeof (xcoff_howto_table[0]);
1185 if (xcoff_howto_table[i].name != NULL
1186 && strcasecmp (xcoff_howto_table[i].name, r_name) == 0)
1187 return &xcoff_howto_table[i];
1192 /* XCOFF archive support. The original version of this code was by
1193 Damon A. Permezel. It was enhanced to permit cross support, and
1194 writing archive files, by Ian Lance Taylor, Cygnus Support.
1196 XCOFF uses its own archive format. Everything is hooked together
1197 with file offset links, so it is possible to rapidly update an
1198 archive in place. Of course, we don't do that. An XCOFF archive
1199 has a real file header, not just an ARMAG string. The structure of
1200 the file header and of each archive header appear below.
1202 An XCOFF archive also has a member table, which is a list of
1203 elements in the archive (you can get that by looking through the
1204 linked list, but you have to read a lot more of the file). The
1205 member table has a normal archive header with an empty name. It is
1206 normally (and perhaps must be) the second to last entry in the
1207 archive. The member table data is almost printable ASCII. It
1208 starts with a 12 character decimal string which is the number of
1209 entries in the table. For each entry it has a 12 character decimal
1210 string which is the offset in the archive of that member. These
1211 entries are followed by a series of null terminated strings which
1212 are the member names for each entry.
1214 Finally, an XCOFF archive has a global symbol table, which is what
1215 we call the armap. The global symbol table has a normal archive
1216 header with an empty name. It is normally (and perhaps must be)
1217 the last entry in the archive. The contents start with a four byte
1218 binary number which is the number of entries. This is followed by
1219 a that many four byte binary numbers; each is the file offset of an
1220 entry in the archive. These numbers are followed by a series of
1221 null terminated strings, which are symbol names.
1223 AIX 4.3 introduced a new archive format which can handle larger
1224 files and also 32- and 64-bit objects in the same archive. The
1225 things said above remain true except that there is now more than
1226 one global symbol table. The one is used to index 32-bit objects,
1227 the other for 64-bit objects.
1229 The new archives (recognizable by the new ARMAG string) has larger
1230 field lengths so that we cannot really share any code. Also we have
1231 to take care that we are not generating the new form of archives
1232 on AIX 4.2 or earlier systems. */
1234 /* XCOFF archives use this as a magic string. Note that both strings
1235 have the same length. */
1237 /* Set the magic for archive. */
1240 bfd_xcoff_ar_archive_set_magic (bfd *abfd ATTRIBUTE_UNUSED,
1241 char *magic ATTRIBUTE_UNUSED)
1243 /* Not supported yet. */
1245 /* bfd_xcoff_archive_set_magic (abfd, magic); */
1248 /* Read in the armap of an XCOFF archive. */
1251 _bfd_xcoff_slurp_armap (bfd *abfd)
1256 bfd_byte *contents, *cend;
1261 if (xcoff_ardata (abfd) == NULL)
1263 bfd_has_map (abfd) = FALSE;
1267 if (! xcoff_big_format_p (abfd))
1269 /* This is for the old format. */
1270 struct xcoff_ar_hdr hdr;
1272 off = strtol (xcoff_ardata (abfd)->symoff, (char **) NULL, 10);
1275 bfd_has_map (abfd) = FALSE;
1279 if (bfd_seek (abfd, off, SEEK_SET) != 0)
1282 /* The symbol table starts with a normal archive header. */
1283 if (bfd_bread (&hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
1287 /* Skip the name (normally empty). */
1288 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1289 off = ((namlen + 1) & ~ (size_t) 1) + SXCOFFARFMAG;
1290 if (bfd_seek (abfd, off, SEEK_CUR) != 0)
1293 sz = strtol (hdr.size, (char **) NULL, 10);
1295 /* Read in the entire symbol table. */
1296 contents = (bfd_byte *) bfd_alloc (abfd, sz);
1297 if (contents == NULL)
1299 if (bfd_bread (contents, sz, abfd) != sz)
1302 /* The symbol table starts with a four byte count. */
1303 c = H_GET_32 (abfd, contents);
1307 bfd_set_error (bfd_error_bad_value);
1311 bfd_ardata (abfd)->symdefs =
1312 ((carsym *) bfd_alloc (abfd, c * sizeof (carsym)));
1313 if (bfd_ardata (abfd)->symdefs == NULL)
1316 /* After the count comes a list of four byte file offsets. */
1317 for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 4;
1319 ++i, ++arsym, p += 4)
1320 arsym->file_offset = H_GET_32 (abfd, p);
1324 /* This is for the new format. */
1325 struct xcoff_ar_hdr_big hdr;
1327 off = strtol (xcoff_ardata_big (abfd)->symoff, (char **) NULL, 10);
1330 bfd_has_map (abfd) = FALSE;
1334 if (bfd_seek (abfd, off, SEEK_SET) != 0)
1337 /* The symbol table starts with a normal archive header. */
1338 if (bfd_bread (&hdr, (bfd_size_type) SIZEOF_AR_HDR_BIG, abfd)
1339 != SIZEOF_AR_HDR_BIG)
1342 /* Skip the name (normally empty). */
1343 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1344 off = ((namlen + 1) & ~ (size_t) 1) + SXCOFFARFMAG;
1345 if (bfd_seek (abfd, off, SEEK_CUR) != 0)
1348 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1349 machines) since the field width is 20 and there numbers with more
1350 than 32 bits can be represented. */
1351 sz = strtol (hdr.size, (char **) NULL, 10);
1353 /* Read in the entire symbol table. */
1354 contents = (bfd_byte *) bfd_alloc (abfd, sz);
1355 if (contents == NULL)
1357 if (bfd_bread (contents, sz, abfd) != sz)
1360 /* The symbol table starts with an eight byte count. */
1361 c = H_GET_64 (abfd, contents);
1365 bfd_set_error (bfd_error_bad_value);
1369 bfd_ardata (abfd)->symdefs =
1370 ((carsym *) bfd_alloc (abfd, c * sizeof (carsym)));
1371 if (bfd_ardata (abfd)->symdefs == NULL)
1374 /* After the count comes a list of eight byte file offsets. */
1375 for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 8;
1377 ++i, ++arsym, p += 8)
1378 arsym->file_offset = H_GET_64 (abfd, p);
1381 /* After the file offsets come null terminated symbol names. */
1382 cend = contents + sz;
1383 for (i = 0, arsym = bfd_ardata (abfd)->symdefs;
1385 ++i, ++arsym, p += strlen ((char *) p) + 1)
1389 bfd_set_error (bfd_error_bad_value);
1392 arsym->name = (char *) p;
1395 bfd_ardata (abfd)->symdef_count = c;
1396 bfd_has_map (abfd) = TRUE;
1401 /* See if this is an XCOFF archive. */
1404 _bfd_xcoff_archive_p (bfd *abfd)
1406 struct artdata *tdata_hold;
1407 char magic[SXCOFFARMAG];
1408 bfd_size_type amt = SXCOFFARMAG;
1410 if (bfd_bread (magic, amt, abfd) != amt)
1412 if (bfd_get_error () != bfd_error_system_call)
1413 bfd_set_error (bfd_error_wrong_format);
1417 if (strncmp (magic, XCOFFARMAG, SXCOFFARMAG) != 0
1418 && strncmp (magic, XCOFFARMAGBIG, SXCOFFARMAG) != 0)
1420 bfd_set_error (bfd_error_wrong_format);
1424 tdata_hold = bfd_ardata (abfd);
1426 amt = sizeof (struct artdata);
1427 bfd_ardata (abfd) = (struct artdata *) bfd_zalloc (abfd, amt);
1428 if (bfd_ardata (abfd) == (struct artdata *) NULL)
1429 goto error_ret_restore;
1431 /* Cleared by bfd_zalloc above.
1432 bfd_ardata (abfd)->cache = NULL;
1433 bfd_ardata (abfd)->archive_head = NULL;
1434 bfd_ardata (abfd)->symdefs = NULL;
1435 bfd_ardata (abfd)->extended_names = NULL;
1436 bfd_ardata (abfd)->extended_names_size = 0; */
1438 /* Now handle the two formats. */
1439 if (magic[1] != 'b')
1441 /* This is the old format. */
1442 struct xcoff_ar_file_hdr hdr;
1444 /* Copy over the magic string. */
1445 memcpy (hdr.magic, magic, SXCOFFARMAG);
1447 /* Now read the rest of the file header. */
1448 amt = SIZEOF_AR_FILE_HDR - SXCOFFARMAG;
1449 if (bfd_bread (&hdr.memoff, amt, abfd) != amt)
1451 if (bfd_get_error () != bfd_error_system_call)
1452 bfd_set_error (bfd_error_wrong_format);
1456 bfd_ardata (abfd)->first_file_filepos = strtol (hdr.firstmemoff,
1457 (char **) NULL, 10);
1459 amt = SIZEOF_AR_FILE_HDR;
1460 bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, amt);
1461 if (bfd_ardata (abfd)->tdata == NULL)
1464 memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR);
1468 /* This is the new format. */
1469 struct xcoff_ar_file_hdr_big hdr;
1471 /* Copy over the magic string. */
1472 memcpy (hdr.magic, magic, SXCOFFARMAG);
1474 /* Now read the rest of the file header. */
1475 amt = SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG;
1476 if (bfd_bread (&hdr.memoff, amt, abfd) != amt)
1478 if (bfd_get_error () != bfd_error_system_call)
1479 bfd_set_error (bfd_error_wrong_format);
1483 bfd_ardata (abfd)->first_file_filepos = bfd_scan_vma (hdr.firstmemoff,
1487 amt = SIZEOF_AR_FILE_HDR_BIG;
1488 bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, amt);
1489 if (bfd_ardata (abfd)->tdata == NULL)
1492 memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR_BIG);
1495 if (! _bfd_xcoff_slurp_armap (abfd))
1498 bfd_release (abfd, bfd_ardata (abfd));
1500 bfd_ardata (abfd) = tdata_hold;
1507 /* Read the archive header in an XCOFF archive. */
1510 _bfd_xcoff_read_ar_hdr (bfd *abfd)
1512 bfd_size_type namlen;
1513 struct areltdata *ret;
1514 bfd_size_type amt = sizeof (struct areltdata);
1516 ret = (struct areltdata *) bfd_zmalloc (amt);
1520 if (! xcoff_big_format_p (abfd))
1522 struct xcoff_ar_hdr hdr;
1523 struct xcoff_ar_hdr *hdrp;
1525 if (bfd_bread (&hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
1532 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1533 amt = SIZEOF_AR_HDR + namlen + 1;
1534 hdrp = (struct xcoff_ar_hdr *) bfd_alloc (abfd, amt);
1540 memcpy (hdrp, &hdr, SIZEOF_AR_HDR);
1541 if (bfd_bread ((char *) hdrp + SIZEOF_AR_HDR, namlen, abfd) != namlen)
1546 ((char *) hdrp)[SIZEOF_AR_HDR + namlen] = '\0';
1548 ret->arch_header = (char *) hdrp;
1549 ret->parsed_size = strtol (hdr.size, (char **) NULL, 10);
1550 ret->filename = (char *) hdrp + SIZEOF_AR_HDR;
1554 struct xcoff_ar_hdr_big hdr;
1555 struct xcoff_ar_hdr_big *hdrp;
1557 if (bfd_bread (&hdr, (bfd_size_type) SIZEOF_AR_HDR_BIG, abfd)
1558 != SIZEOF_AR_HDR_BIG)
1564 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1565 amt = SIZEOF_AR_HDR_BIG + namlen + 1;
1566 hdrp = (struct xcoff_ar_hdr_big *) bfd_alloc (abfd, amt);
1572 memcpy (hdrp, &hdr, SIZEOF_AR_HDR_BIG);
1573 if (bfd_bread ((char *) hdrp + SIZEOF_AR_HDR_BIG, namlen, abfd) != namlen)
1578 ((char *) hdrp)[SIZEOF_AR_HDR_BIG + namlen] = '\0';
1580 ret->arch_header = (char *) hdrp;
1581 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1582 machines) since the field width is 20 and there numbers with more
1583 than 32 bits can be represented. */
1584 ret->parsed_size = strtol (hdr.size, (char **) NULL, 10);
1585 ret->filename = (char *) hdrp + SIZEOF_AR_HDR_BIG;
1588 /* Skip over the XCOFFARFMAG at the end of the file name. */
1589 if (bfd_seek (abfd, (file_ptr) ((namlen & 1) + SXCOFFARFMAG), SEEK_CUR) != 0)
1595 /* Open the next element in an XCOFF archive. */
1598 _bfd_xcoff_openr_next_archived_file (bfd *archive, bfd *last_file)
1602 if (xcoff_ardata (archive) == NULL)
1604 bfd_set_error (bfd_error_invalid_operation);
1608 if (! xcoff_big_format_p (archive))
1610 if (last_file == NULL)
1611 filestart = bfd_ardata (archive)->first_file_filepos;
1613 filestart = strtol (arch_xhdr (last_file)->nextoff, (char **) NULL,
1617 || filestart == strtol (xcoff_ardata (archive)->memoff,
1619 || filestart == strtol (xcoff_ardata (archive)->symoff,
1620 (char **) NULL, 10))
1622 bfd_set_error (bfd_error_no_more_archived_files);
1628 if (last_file == NULL)
1629 filestart = bfd_ardata (archive)->first_file_filepos;
1631 /* XXX These actually have to be a calls to strtoll (at least
1632 on 32-bit machines) since the fields's width is 20 and
1633 there numbers with more than 32 bits can be represented. */
1634 filestart = strtol (arch_xhdr_big (last_file)->nextoff, (char **) NULL,
1637 /* XXX These actually have to be calls to strtoll (at least on 32-bit
1638 machines) since the fields's width is 20 and there numbers with more
1639 than 32 bits can be represented. */
1641 || filestart == strtol (xcoff_ardata_big (archive)->memoff,
1643 || filestart == strtol (xcoff_ardata_big (archive)->symoff,
1644 (char **) NULL, 10))
1646 bfd_set_error (bfd_error_no_more_archived_files);
1651 return _bfd_get_elt_at_filepos (archive, filestart);
1654 /* Stat an element in an XCOFF archive. */
1657 _bfd_xcoff_stat_arch_elt (bfd *abfd, struct stat *s)
1659 if (abfd->arelt_data == NULL)
1661 bfd_set_error (bfd_error_invalid_operation);
1665 if (! xcoff_big_format_p (abfd->my_archive))
1667 struct xcoff_ar_hdr *hdrp = arch_xhdr (abfd);
1669 s->st_mtime = strtol (hdrp->date, (char **) NULL, 10);
1670 s->st_uid = strtol (hdrp->uid, (char **) NULL, 10);
1671 s->st_gid = strtol (hdrp->gid, (char **) NULL, 10);
1672 s->st_mode = strtol (hdrp->mode, (char **) NULL, 8);
1673 s->st_size = arch_eltdata (abfd)->parsed_size;
1677 struct xcoff_ar_hdr_big *hdrp = arch_xhdr_big (abfd);
1679 s->st_mtime = strtol (hdrp->date, (char **) NULL, 10);
1680 s->st_uid = strtol (hdrp->uid, (char **) NULL, 10);
1681 s->st_gid = strtol (hdrp->gid, (char **) NULL, 10);
1682 s->st_mode = strtol (hdrp->mode, (char **) NULL, 8);
1683 s->st_size = arch_eltdata (abfd)->parsed_size;
1689 /* Normalize a file name for inclusion in an archive. */
1692 normalize_filename (bfd *abfd)
1695 const char *filename;
1697 file = bfd_get_filename (abfd);
1698 filename = strrchr (file, '/');
1699 if (filename != NULL)
1706 /* Write out an XCOFF armap. */
1709 xcoff_write_armap_old (bfd *abfd, unsigned int elength ATTRIBUTE_UNUSED,
1710 struct orl *map, unsigned int orl_count, int stridx)
1712 struct archive_iterator iterator;
1713 struct xcoff_ar_hdr hdr;
1715 unsigned char buf[4];
1718 memset (&hdr, 0, sizeof hdr);
1719 sprintf (hdr.size, "%ld", (long) (4 + orl_count * 4 + stridx));
1720 sprintf (hdr.nextoff, "%d", 0);
1721 memcpy (hdr.prevoff, xcoff_ardata (abfd)->memoff, XCOFFARMAG_ELEMENT_SIZE);
1722 sprintf (hdr.date, "%d", 0);
1723 sprintf (hdr.uid, "%d", 0);
1724 sprintf (hdr.gid, "%d", 0);
1725 sprintf (hdr.mode, "%d", 0);
1726 sprintf (hdr.namlen, "%d", 0);
1728 /* We need spaces, not null bytes, in the header. */
1729 for (p = (char *) &hdr; p < (char *) &hdr + SIZEOF_AR_HDR; p++)
1733 if (bfd_bwrite (&hdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
1735 || (bfd_bwrite (XCOFFARFMAG, (bfd_size_type) SXCOFFARFMAG, abfd)
1739 H_PUT_32 (abfd, orl_count, buf);
1740 if (bfd_bwrite (buf, (bfd_size_type) 4, abfd) != 4)
1744 archive_iterator_begin (&iterator, abfd);
1745 while (i < orl_count && archive_iterator_next (&iterator))
1746 while (map[i].u.abfd == iterator.current.member)
1748 H_PUT_32 (abfd, iterator.current.offset, buf);
1749 if (bfd_bwrite (buf, (bfd_size_type) 4, abfd) != 4)
1754 for (i = 0; i < orl_count; i++)
1759 name = *map[i].name;
1760 namlen = strlen (name);
1761 if (bfd_bwrite (name, (bfd_size_type) (namlen + 1), abfd) != namlen + 1)
1765 if ((stridx & 1) != 0)
1770 if (bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
1777 static char buff20[XCOFFARMAGBIG_ELEMENT_SIZE + 1];
1778 #define FMT20 "%-20lld"
1779 #define FMT12 "%-12d"
1780 #define FMT12_OCTAL "%-12o"
1782 #define PRINT20(d, v) \
1783 sprintf (buff20, FMT20, (long long)(v)), \
1784 memcpy ((void *) (d), buff20, 20)
1786 #define PRINT12(d, v) \
1787 sprintf (buff20, FMT12, (int)(v)), \
1788 memcpy ((void *) (d), buff20, 12)
1790 #define PRINT12_OCTAL(d, v) \
1791 sprintf (buff20, FMT12_OCTAL, (unsigned int)(v)), \
1792 memcpy ((void *) (d), buff20, 12)
1794 #define PRINT4(d, v) \
1795 sprintf (buff20, FMT4, (int)(v)), \
1796 memcpy ((void *) (d), buff20, 4)
1798 #define READ20(d, v) \
1800 memcpy (buff20, (d), 20), \
1801 (v) = bfd_scan_vma (buff20, (const char **) NULL, 10)
1804 do_pad (bfd *abfd, unsigned int number)
1808 /* Limit pad to <= 4096. */
1813 if (bfd_bwrite (&b, (bfd_size_type) 1, abfd) != 1)
1820 do_copy (bfd *out_bfd, bfd *in_bfd)
1822 bfd_size_type remaining;
1823 bfd_byte buffer[DEFAULT_BUFFERSIZE];
1825 if (bfd_seek (in_bfd, (file_ptr) 0, SEEK_SET) != 0)
1828 remaining = arelt_size (in_bfd);
1830 while (remaining >= DEFAULT_BUFFERSIZE)
1832 if (bfd_bread (buffer, DEFAULT_BUFFERSIZE, in_bfd) != DEFAULT_BUFFERSIZE
1833 || bfd_bwrite (buffer, DEFAULT_BUFFERSIZE, out_bfd) != DEFAULT_BUFFERSIZE)
1836 remaining -= DEFAULT_BUFFERSIZE;
1841 if (bfd_bread (buffer, remaining, in_bfd) != remaining
1842 || bfd_bwrite (buffer, remaining, out_bfd) != remaining)
1850 xcoff_write_armap_big (bfd *abfd, unsigned int elength ATTRIBUTE_UNUSED,
1851 struct orl *map, unsigned int orl_count, int stridx)
1853 struct archive_iterator iterator;
1854 struct xcoff_ar_file_hdr_big *fhdr;
1855 bfd_vma i, sym_32, sym_64, str_32, str_64;
1856 const bfd_arch_info_type *arch_info;
1858 size_t string_length;
1859 file_ptr nextoff, prevoff;
1861 /* First, we look through the symbols and work out which are
1862 from 32-bit objects and which from 64-bit ones. */
1863 sym_32 = sym_64 = str_32 = str_64 = 0;
1866 for (current_bfd = abfd->archive_head;
1867 current_bfd != NULL && i < orl_count;
1868 current_bfd = current_bfd->archive_next)
1870 arch_info = bfd_get_arch_info (current_bfd);
1871 while (map[i].u.abfd == current_bfd)
1873 string_length = strlen (*map[i].name) + 1;
1874 if (arch_info->bits_per_address == 64)
1877 str_64 += string_length;
1882 str_32 += string_length;
1888 /* A quick sanity check... */
1889 BFD_ASSERT (sym_64 + sym_32 == orl_count);
1890 /* Explicit cast to int for compiler. */
1891 BFD_ASSERT ((int)(str_64 + str_32) == stridx);
1893 fhdr = xcoff_ardata_big (abfd);
1895 /* xcoff_write_archive_contents_big passes nextoff in symoff. */
1896 READ20 (fhdr->memoff, prevoff);
1897 READ20 (fhdr->symoff, nextoff);
1899 BFD_ASSERT (nextoff == bfd_tell (abfd));
1901 /* Write out the symbol table.
1904 standard big archive header
1905 0x0000 ar_size [0x14]
1906 0x0014 ar_nxtmem [0x14]
1907 0x0028 ar_prvmem [0x14]
1908 0x003C ar_date [0x0C]
1909 0x0048 ar_uid [0x0C]
1910 0x0054 ar_gid [0x0C]
1911 0x0060 ar_mod [0x0C]
1912 0x006C ar_namelen[0x04]
1913 0x0070 ar_fmag [SXCOFFARFMAG]
1916 0x0072 num_syms [0x08], binary
1917 0x0078 offsets [0x08 * num_syms], binary
1918 0x0086 + 0x08 * num_syms names [??]
1919 ?? pad to even bytes.
1924 struct xcoff_ar_hdr_big *hdr;
1928 bfd_vma symbol_table_size =
1933 + str_32 + (str_32 & 1);
1935 symbol_table = bfd_zmalloc (symbol_table_size);
1936 if (symbol_table == NULL)
1939 hdr = (struct xcoff_ar_hdr_big *) symbol_table;
1941 PRINT20 (hdr->size, 8 + 8 * sym_32 + str_32 + (str_32 & 1));
1944 PRINT20 (hdr->nextoff, nextoff + symbol_table_size);
1946 PRINT20 (hdr->nextoff, 0);
1948 PRINT20 (hdr->prevoff, prevoff);
1949 PRINT12 (hdr->date, 0);
1950 PRINT12 (hdr->uid, 0);
1951 PRINT12 (hdr->gid, 0);
1952 PRINT12 (hdr->mode, 0);
1953 PRINT4 (hdr->namlen, 0) ;
1955 st = symbol_table + SIZEOF_AR_HDR_BIG;
1956 memcpy (st, XCOFFARFMAG, SXCOFFARFMAG);
1959 bfd_h_put_64 (abfd, sym_32, st);
1962 /* loop over the 32 bit offsets */
1964 archive_iterator_begin (&iterator, abfd);
1965 while (i < orl_count && archive_iterator_next (&iterator))
1967 arch_info = bfd_get_arch_info (iterator.current.member);
1968 while (map[i].u.abfd == iterator.current.member)
1970 if (arch_info->bits_per_address == 32)
1972 bfd_h_put_64 (abfd, iterator.current.offset, st);
1979 /* loop over the 32 bit symbol names */
1981 for (current_bfd = abfd->archive_head;
1982 current_bfd != NULL && i < orl_count;
1983 current_bfd = current_bfd->archive_next)
1985 arch_info = bfd_get_arch_info (current_bfd);
1986 while (map[i].u.abfd == current_bfd)
1988 if (arch_info->bits_per_address == 32)
1990 string_length = sprintf (st, "%s", *map[i].name);
1991 st += string_length + 1;
1997 bfd_bwrite (symbol_table, symbol_table_size, abfd);
1999 free (symbol_table);
2002 nextoff = nextoff + symbol_table_size;
2005 PRINT20 (fhdr->symoff, 0);
2009 struct xcoff_ar_hdr_big *hdr;
2013 bfd_vma symbol_table_size =
2018 + str_64 + (str_64 & 1);
2020 symbol_table = bfd_zmalloc (symbol_table_size);
2021 if (symbol_table == NULL)
2024 hdr = (struct xcoff_ar_hdr_big *) symbol_table;
2026 PRINT20 (hdr->size, 8 + 8 * sym_64 + str_64 + (str_64 & 1));
2027 PRINT20 (hdr->nextoff, 0);
2028 PRINT20 (hdr->prevoff, prevoff);
2029 PRINT12 (hdr->date, 0);
2030 PRINT12 (hdr->uid, 0);
2031 PRINT12 (hdr->gid, 0);
2032 PRINT12 (hdr->mode, 0);
2033 PRINT4 (hdr->namlen, 0);
2035 st = symbol_table + SIZEOF_AR_HDR_BIG;
2036 memcpy (st, XCOFFARFMAG, SXCOFFARFMAG);
2039 bfd_h_put_64 (abfd, sym_64, st);
2042 /* loop over the 64 bit offsets */
2044 archive_iterator_begin (&iterator, abfd);
2045 while (i < orl_count && archive_iterator_next (&iterator))
2047 arch_info = bfd_get_arch_info (iterator.current.member);
2048 while (map[i].u.abfd == iterator.current.member)
2050 if (arch_info->bits_per_address == 64)
2052 bfd_h_put_64 (abfd, iterator.current.offset, st);
2059 /* loop over the 64 bit symbol names */
2061 for (current_bfd = abfd->archive_head;
2062 current_bfd != NULL && i < orl_count;
2063 current_bfd = current_bfd->archive_next)
2065 arch_info = bfd_get_arch_info (current_bfd);
2066 while (map[i].u.abfd == current_bfd)
2068 if (arch_info->bits_per_address == 64)
2070 string_length = sprintf (st, "%s", *map[i].name);
2071 st += string_length + 1;
2077 bfd_bwrite (symbol_table, symbol_table_size, abfd);
2079 free (symbol_table);
2081 PRINT20 (fhdr->symoff64, nextoff);
2084 PRINT20 (fhdr->symoff64, 0);
2090 _bfd_xcoff_write_armap (bfd *abfd, unsigned int elength ATTRIBUTE_UNUSED,
2091 struct orl *map, unsigned int orl_count, int stridx)
2093 if (! xcoff_big_format_p (abfd))
2094 return xcoff_write_armap_old (abfd, elength, map, orl_count, stridx);
2096 return xcoff_write_armap_big (abfd, elength, map, orl_count, stridx);
2099 /* Write out an XCOFF archive. We always write an entire archive,
2100 rather than fussing with the freelist and so forth. */
2103 xcoff_write_archive_contents_old (bfd *abfd)
2105 struct archive_iterator iterator;
2106 struct xcoff_ar_file_hdr fhdr;
2107 bfd_size_type count;
2108 bfd_size_type total_namlen;
2110 bfd_boolean makemap;
2111 bfd_boolean hasobjects;
2112 file_ptr prevoff, nextoff;
2115 struct xcoff_ar_hdr ahdr;
2118 char decbuf[XCOFFARMAG_ELEMENT_SIZE + 1];
2120 memset (&fhdr, 0, sizeof fhdr);
2121 (void) strncpy (fhdr.magic, XCOFFARMAG, SXCOFFARMAG);
2122 sprintf (fhdr.firstmemoff, "%d", SIZEOF_AR_FILE_HDR);
2123 sprintf (fhdr.freeoff, "%d", 0);
2127 for (sub = abfd->archive_head; sub != NULL; sub = sub->archive_next)
2130 total_namlen += strlen (normalize_filename (sub)) + 1;
2131 if (sub->arelt_data == NULL)
2133 sub->arelt_data = bfd_zmalloc (sizeof (struct areltdata));
2134 if (sub->arelt_data == NULL)
2137 if (arch_xhdr (sub) == NULL)
2139 struct xcoff_ar_hdr *ahdrp;
2142 if (stat (bfd_get_filename (sub), &s) != 0)
2144 bfd_set_error (bfd_error_system_call);
2148 ahdrp = bfd_zalloc (sub, sizeof (*ahdrp));
2152 sprintf (ahdrp->size, "%ld", (long) s.st_size);
2153 sprintf (ahdrp->date, "%ld", (long) s.st_mtime);
2154 sprintf (ahdrp->uid, "%ld", (long) s.st_uid);
2155 sprintf (ahdrp->gid, "%ld", (long) s.st_gid);
2156 sprintf (ahdrp->mode, "%o", (unsigned int) s.st_mode);
2158 arch_eltdata (sub)->arch_header = (char *) ahdrp;
2159 arch_eltdata (sub)->parsed_size = s.st_size;
2162 offsets = (file_ptr *) bfd_alloc (abfd, count * sizeof (file_ptr));
2163 if (offsets == NULL)
2166 if (bfd_seek (abfd, (file_ptr) SIZEOF_AR_FILE_HDR, SEEK_SET) != 0)
2169 makemap = bfd_has_map (abfd);
2172 for (archive_iterator_begin (&iterator, abfd), i = 0;
2173 archive_iterator_next (&iterator);
2176 bfd_size_type namlen;
2177 struct xcoff_ar_hdr *ahdrp;
2179 if (makemap && ! hasobjects)
2181 if (bfd_check_format (iterator.current.member, bfd_object))
2185 ahdrp = arch_xhdr (iterator.current.member);
2186 sprintf (ahdrp->prevoff, "%ld", (long) prevoff);
2187 sprintf (ahdrp->namlen, "%ld", (long) iterator.current.namlen);
2188 sprintf (ahdrp->nextoff, "%ld", (long) iterator.next.offset);
2190 /* We need spaces, not null bytes, in the header. */
2191 for (p = (char *) ahdrp; p < (char *) ahdrp + SIZEOF_AR_HDR; p++)
2195 if (!do_pad (abfd, iterator.current.leading_padding))
2198 BFD_ASSERT (iterator.current.offset == bfd_tell (abfd));
2199 namlen = iterator.current.padded_namlen;
2200 if (bfd_bwrite (ahdrp, SIZEOF_AR_HDR, abfd) != SIZEOF_AR_HDR
2201 || bfd_bwrite (iterator.current.name, namlen, abfd) != namlen
2202 || bfd_bwrite (XCOFFARFMAG, SXCOFFARFMAG, abfd) != SXCOFFARFMAG
2203 || bfd_seek (iterator.current.member, 0, SEEK_SET) != 0
2204 || !do_copy (abfd, iterator.current.member)
2205 || !do_pad (abfd, iterator.current.trailing_padding))
2208 offsets[i] = iterator.current.offset;
2209 prevoff = iterator.current.offset;
2212 sprintf (fhdr.lastmemoff, "%ld", (long) prevoff);
2214 /* Write out the member table. */
2216 nextoff = iterator.next.offset;
2217 BFD_ASSERT (nextoff == bfd_tell (abfd));
2218 sprintf (fhdr.memoff, "%ld", (long) nextoff);
2220 memset (&ahdr, 0, sizeof ahdr);
2221 sprintf (ahdr.size, "%ld", (long) (XCOFFARMAG_ELEMENT_SIZE
2222 + count * XCOFFARMAG_ELEMENT_SIZE
2224 sprintf (ahdr.prevoff, "%ld", (long) prevoff);
2225 sprintf (ahdr.date, "%d", 0);
2226 sprintf (ahdr.uid, "%d", 0);
2227 sprintf (ahdr.gid, "%d", 0);
2228 sprintf (ahdr.mode, "%d", 0);
2229 sprintf (ahdr.namlen, "%d", 0);
2231 size = (SIZEOF_AR_HDR
2232 + XCOFFARMAG_ELEMENT_SIZE
2233 + count * XCOFFARMAG_ELEMENT_SIZE
2238 nextoff += size + (size & 1);
2240 if (makemap && hasobjects)
2241 sprintf (ahdr.nextoff, "%ld", (long) nextoff);
2243 sprintf (ahdr.nextoff, "%d", 0);
2245 /* We need spaces, not null bytes, in the header. */
2246 for (p = (char *) &ahdr; p < (char *) &ahdr + SIZEOF_AR_HDR; p++)
2250 if ((bfd_bwrite (&ahdr, (bfd_size_type) SIZEOF_AR_HDR, abfd)
2252 || (bfd_bwrite (XCOFFARFMAG, (bfd_size_type) SXCOFFARFMAG, abfd)
2256 sprintf (decbuf, "%-12ld", (long) count);
2257 if (bfd_bwrite (decbuf, (bfd_size_type) XCOFFARMAG_ELEMENT_SIZE, abfd)
2258 != XCOFFARMAG_ELEMENT_SIZE)
2260 for (i = 0; i < (size_t) count; i++)
2262 sprintf (decbuf, "%-12ld", (long) offsets[i]);
2263 if (bfd_bwrite (decbuf, (bfd_size_type) XCOFFARMAG_ELEMENT_SIZE,
2264 abfd) != XCOFFARMAG_ELEMENT_SIZE)
2267 for (sub = abfd->archive_head; sub != NULL; sub = sub->archive_next)
2270 bfd_size_type namlen;
2272 name = normalize_filename (sub);
2273 namlen = strlen (name);
2274 if (bfd_bwrite (name, namlen + 1, abfd) != namlen + 1)
2278 if (! do_pad (abfd, size & 1))
2281 /* Write out the armap, if appropriate. */
2282 if (! makemap || ! hasobjects)
2283 sprintf (fhdr.symoff, "%d", 0);
2286 BFD_ASSERT (nextoff == bfd_tell (abfd));
2287 sprintf (fhdr.symoff, "%ld", (long) nextoff);
2288 bfd_ardata (abfd)->tdata = &fhdr;
2289 if (! _bfd_compute_and_write_armap (abfd, 0))
2293 /* Write out the archive file header. */
2295 /* We need spaces, not null bytes, in the header. */
2296 for (p = (char *) &fhdr; p < (char *) &fhdr + SIZEOF_AR_FILE_HDR; p++)
2300 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
2301 || (bfd_bwrite (&fhdr, (bfd_size_type) SIZEOF_AR_FILE_HDR, abfd)
2302 != SIZEOF_AR_FILE_HDR))
2309 xcoff_write_archive_contents_big (bfd *abfd)
2311 struct xcoff_ar_file_hdr_big fhdr;
2312 bfd_size_type count;
2313 bfd_size_type total_namlen;
2315 bfd_boolean makemap;
2316 bfd_boolean hasobjects;
2317 file_ptr prevoff, nextoff;
2320 struct xcoff_ar_hdr_big *hdr;
2322 char *member_table, *mt;
2323 bfd_vma member_table_size;
2324 struct archive_iterator iterator;
2326 memset (&fhdr, 0, SIZEOF_AR_FILE_HDR_BIG);
2327 memcpy (fhdr.magic, XCOFFARMAGBIG, SXCOFFARMAG);
2329 if (bfd_seek (abfd, (file_ptr) SIZEOF_AR_FILE_HDR_BIG, SEEK_SET) != 0)
2332 /* Calculate count and total_namlen. */
2333 makemap = bfd_has_map (abfd);
2335 for (current_bfd = abfd->archive_head, count = 0, total_namlen = 0;
2336 current_bfd != NULL;
2337 current_bfd = current_bfd->archive_next, count++)
2339 total_namlen += strlen (normalize_filename (current_bfd)) + 1;
2343 && bfd_check_format (current_bfd, bfd_object))
2346 if (current_bfd->arelt_data == NULL)
2348 size = sizeof (struct areltdata);
2349 current_bfd->arelt_data = bfd_zmalloc (size);
2350 if (current_bfd->arelt_data == NULL)
2354 if (arch_xhdr_big (current_bfd) == NULL)
2356 struct xcoff_ar_hdr_big *ahdrp;
2359 /* XXX This should actually be a call to stat64 (at least on
2361 XXX This call will fail if the original object is not found. */
2362 if (stat (bfd_get_filename (current_bfd), &s) != 0)
2364 bfd_set_error (bfd_error_system_call);
2368 ahdrp = bfd_zalloc (current_bfd, sizeof (*ahdrp));
2372 PRINT20 (ahdrp->size, s.st_size);
2373 PRINT12 (ahdrp->date, s.st_mtime);
2374 PRINT12 (ahdrp->uid, s.st_uid);
2375 PRINT12 (ahdrp->gid, s.st_gid);
2376 PRINT12_OCTAL (ahdrp->mode, s.st_mode);
2378 arch_eltdata (current_bfd)->arch_header = (char *) ahdrp;
2379 arch_eltdata (current_bfd)->parsed_size = s.st_size;
2386 offsets = (file_ptr *) bfd_malloc (count * sizeof (file_ptr));
2387 if (offsets == NULL)
2392 for (archive_iterator_begin (&iterator, abfd), i = 0;
2393 archive_iterator_next (&iterator);
2396 bfd_size_type namlen;
2397 struct xcoff_ar_hdr_big *ahdrp;
2399 ahdrp = arch_xhdr_big (iterator.current.member);
2400 PRINT20 (ahdrp->prevoff, prevoff);
2401 PRINT4 (ahdrp->namlen, iterator.current.namlen);
2402 PRINT20 (ahdrp->nextoff, iterator.next.offset);
2404 if (!do_pad (abfd, iterator.current.leading_padding))
2410 BFD_ASSERT (iterator.current.offset == bfd_tell (abfd));
2411 namlen = iterator.current.padded_namlen;
2412 if (bfd_bwrite (ahdrp, SIZEOF_AR_HDR_BIG, abfd) != SIZEOF_AR_HDR_BIG
2413 || bfd_bwrite (iterator.current.name, namlen, abfd) != namlen
2414 || bfd_bwrite (XCOFFARFMAG, SXCOFFARFMAG, abfd) != SXCOFFARFMAG
2415 || bfd_seek (iterator.current.member, 0, SEEK_SET) != 0
2416 || !do_copy (abfd, iterator.current.member)
2417 || !do_pad (abfd, iterator.current.trailing_padding))
2423 offsets[i] = iterator.current.offset;
2424 prevoff = iterator.current.offset;
2429 PRINT20 (fhdr.firstmemoff, offsets[0]);
2430 PRINT20 (fhdr.lastmemoff, prevoff);
2433 /* Write out the member table.
2436 standard big archive header
2437 0x0000 ar_size [0x14]
2438 0x0014 ar_nxtmem [0x14]
2439 0x0028 ar_prvmem [0x14]
2440 0x003C ar_date [0x0C]
2441 0x0048 ar_uid [0x0C]
2442 0x0054 ar_gid [0x0C]
2443 0x0060 ar_mod [0x0C]
2444 0x006C ar_namelen[0x04]
2445 0x0070 ar_fmag [0x02]
2449 0x0086 offsets [0x14 * counts]
2450 0x0086 + 0x14 * counts names [??]
2451 ?? pad to even bytes.
2454 nextoff = iterator.next.offset;
2455 BFD_ASSERT (nextoff == bfd_tell (abfd));
2457 member_table_size = (SIZEOF_AR_HDR_BIG
2459 + XCOFFARMAGBIG_ELEMENT_SIZE
2460 + count * XCOFFARMAGBIG_ELEMENT_SIZE
2463 member_table_size += member_table_size & 1;
2464 member_table = bfd_zmalloc (member_table_size);
2465 if (member_table == NULL)
2471 hdr = (struct xcoff_ar_hdr_big *) member_table;
2473 PRINT20 (hdr->size, (XCOFFARMAGBIG_ELEMENT_SIZE
2474 + count * XCOFFARMAGBIG_ELEMENT_SIZE
2475 + total_namlen + (total_namlen & 1)));
2476 if (makemap && hasobjects)
2477 PRINT20 (hdr->nextoff, nextoff + member_table_size);
2479 PRINT20 (hdr->nextoff, 0);
2480 PRINT20 (hdr->prevoff, prevoff);
2481 PRINT12 (hdr->date, 0);
2482 PRINT12 (hdr->uid, 0);
2483 PRINT12 (hdr->gid, 0);
2484 PRINT12 (hdr->mode, 0);
2485 PRINT4 (hdr->namlen, 0);
2487 mt = member_table + SIZEOF_AR_HDR_BIG;
2488 memcpy (mt, XCOFFARFMAG, SXCOFFARFMAG);
2491 PRINT20 (mt, count);
2492 mt += XCOFFARMAGBIG_ELEMENT_SIZE;
2493 for (i = 0; i < (size_t) count; i++)
2495 PRINT20 (mt, offsets[i]);
2496 mt += XCOFFARMAGBIG_ELEMENT_SIZE;
2505 for (current_bfd = abfd->archive_head;
2506 current_bfd != NULL;
2507 current_bfd = current_bfd->archive_next)
2512 name = normalize_filename (current_bfd);
2513 namlen = sprintf (mt, "%s", name);
2517 if (bfd_bwrite (member_table, member_table_size, abfd) != member_table_size)
2520 free (member_table);
2522 PRINT20 (fhdr.memoff, nextoff);
2525 nextoff += member_table_size;
2527 /* Write out the armap, if appropriate. */
2529 if (! makemap || ! hasobjects)
2530 PRINT20 (fhdr.symoff, 0);
2533 BFD_ASSERT (nextoff == bfd_tell (abfd));
2535 /* Save nextoff in fhdr.symoff so the armap routine can use it. */
2536 PRINT20 (fhdr.symoff, nextoff);
2538 bfd_ardata (abfd)->tdata = &fhdr;
2539 if (! _bfd_compute_and_write_armap (abfd, 0))
2543 /* Write out the archive file header. */
2545 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
2546 || (bfd_bwrite (&fhdr, (bfd_size_type) SIZEOF_AR_FILE_HDR_BIG,
2547 abfd) != SIZEOF_AR_FILE_HDR_BIG))
2554 _bfd_xcoff_write_archive_contents (bfd *abfd)
2556 if (! xcoff_big_format_p (abfd))
2557 return xcoff_write_archive_contents_old (abfd);
2559 return xcoff_write_archive_contents_big (abfd);
2562 /* We can't use the usual coff_sizeof_headers routine, because AIX
2563 always uses an a.out header. */
2566 _bfd_xcoff_sizeof_headers (bfd *abfd,
2567 struct bfd_link_info *info ATTRIBUTE_UNUSED)
2572 if (xcoff_data (abfd)->full_aouthdr)
2575 size += SMALL_AOUTSZ;
2576 size += abfd->section_count * SCNHSZ;
2578 if (info->strip != strip_all)
2580 /* There can be additional sections just for dealing with overflow in
2581 reloc and lineno counts. But the numbers of relocs and lineno aren't
2582 known when bfd_sizeof_headers is called, so we compute them by
2583 summing the numbers from input sections. */
2584 struct nbr_reloc_lineno
2586 unsigned int reloc_count;
2587 unsigned int lineno_count;
2589 struct nbr_reloc_lineno *n_rl;
2594 /* Although the number of sections is known, the maximum value of
2595 section->index isn't (because some sections may have been removed).
2596 Don't try to renumber sections, just compute the upper bound. */
2598 for (s = abfd->sections; s != NULL; s = s->next)
2599 if (s->index > max_index)
2600 max_index = s->index;
2602 /* Allocate the per section counters. It could be possible to use a
2603 preallocated array as the number of sections is limited on XCOFF,
2604 but this creates a maintainance issue. */
2605 n_rl = bfd_zmalloc ((max_index + 1) * sizeof (*n_rl));
2610 for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
2611 for (s = sub->sections; s != NULL; s = s->next)
2613 struct nbr_reloc_lineno *e = &n_rl[s->output_section->index];
2614 e->reloc_count += s->reloc_count;
2615 e->lineno_count += s->lineno_count;
2618 /* Add the size of a section for each section with an overflow. */
2619 for (s = abfd->sections; s != NULL; s = s->next)
2621 struct nbr_reloc_lineno *e = &n_rl[s->index];
2623 if (e->reloc_count >= 0xffff
2624 || (e->lineno_count >= 0xffff && info->strip != strip_debugger))
2634 /* Routines to swap information in the XCOFF .loader section. If we
2635 ever need to write an XCOFF loader, this stuff will need to be
2636 moved to another file shared by the linker (which XCOFF calls the
2637 ``binder'') and the loader. */
2639 /* Swap in the ldhdr structure. */
2642 xcoff_swap_ldhdr_in (bfd *abfd, const void * s, struct internal_ldhdr *dst)
2644 const struct external_ldhdr *src = (const struct external_ldhdr *) s;
2646 dst->l_version = bfd_get_32 (abfd, src->l_version);
2647 dst->l_nsyms = bfd_get_32 (abfd, src->l_nsyms);
2648 dst->l_nreloc = bfd_get_32 (abfd, src->l_nreloc);
2649 dst->l_istlen = bfd_get_32 (abfd, src->l_istlen);
2650 dst->l_nimpid = bfd_get_32 (abfd, src->l_nimpid);
2651 dst->l_impoff = bfd_get_32 (abfd, src->l_impoff);
2652 dst->l_stlen = bfd_get_32 (abfd, src->l_stlen);
2653 dst->l_stoff = bfd_get_32 (abfd, src->l_stoff);
2656 /* Swap out the ldhdr structure. */
2659 xcoff_swap_ldhdr_out (bfd *abfd, const struct internal_ldhdr *src, void * d)
2661 struct external_ldhdr *dst = (struct external_ldhdr *) d;
2663 bfd_put_32 (abfd, (bfd_vma) src->l_version, dst->l_version);
2664 bfd_put_32 (abfd, src->l_nsyms, dst->l_nsyms);
2665 bfd_put_32 (abfd, src->l_nreloc, dst->l_nreloc);
2666 bfd_put_32 (abfd, src->l_istlen, dst->l_istlen);
2667 bfd_put_32 (abfd, src->l_nimpid, dst->l_nimpid);
2668 bfd_put_32 (abfd, src->l_impoff, dst->l_impoff);
2669 bfd_put_32 (abfd, src->l_stlen, dst->l_stlen);
2670 bfd_put_32 (abfd, src->l_stoff, dst->l_stoff);
2673 /* Swap in the ldsym structure. */
2676 xcoff_swap_ldsym_in (bfd *abfd, const void * s, struct internal_ldsym *dst)
2678 const struct external_ldsym *src = (const struct external_ldsym *) s;
2680 if (bfd_get_32 (abfd, src->_l._l_l._l_zeroes) != 0) {
2681 memcpy (dst->_l._l_name, src->_l._l_name, SYMNMLEN);
2683 dst->_l._l_l._l_zeroes = 0;
2684 dst->_l._l_l._l_offset = bfd_get_32 (abfd, src->_l._l_l._l_offset);
2686 dst->l_value = bfd_get_32 (abfd, src->l_value);
2687 dst->l_scnum = bfd_get_16 (abfd, src->l_scnum);
2688 dst->l_smtype = bfd_get_8 (abfd, src->l_smtype);
2689 dst->l_smclas = bfd_get_8 (abfd, src->l_smclas);
2690 dst->l_ifile = bfd_get_32 (abfd, src->l_ifile);
2691 dst->l_parm = bfd_get_32 (abfd, src->l_parm);
2694 /* Swap out the ldsym structure. */
2697 xcoff_swap_ldsym_out (bfd *abfd, const struct internal_ldsym *src, void * d)
2699 struct external_ldsym *dst = (struct external_ldsym *) d;
2701 if (src->_l._l_l._l_zeroes != 0)
2702 memcpy (dst->_l._l_name, src->_l._l_name, SYMNMLEN);
2705 bfd_put_32 (abfd, (bfd_vma) 0, dst->_l._l_l._l_zeroes);
2706 bfd_put_32 (abfd, (bfd_vma) src->_l._l_l._l_offset,
2707 dst->_l._l_l._l_offset);
2709 bfd_put_32 (abfd, src->l_value, dst->l_value);
2710 bfd_put_16 (abfd, (bfd_vma) src->l_scnum, dst->l_scnum);
2711 bfd_put_8 (abfd, src->l_smtype, dst->l_smtype);
2712 bfd_put_8 (abfd, src->l_smclas, dst->l_smclas);
2713 bfd_put_32 (abfd, src->l_ifile, dst->l_ifile);
2714 bfd_put_32 (abfd, src->l_parm, dst->l_parm);
2718 xcoff_swap_reloc_in (bfd *abfd, void * s, void * d)
2720 struct external_reloc *src = (struct external_reloc *) s;
2721 struct internal_reloc *dst = (struct internal_reloc *) d;
2723 memset (dst, 0, sizeof (struct internal_reloc));
2725 dst->r_vaddr = bfd_get_32 (abfd, src->r_vaddr);
2726 dst->r_symndx = bfd_get_32 (abfd, src->r_symndx);
2727 dst->r_size = bfd_get_8 (abfd, src->r_size);
2728 dst->r_type = bfd_get_8 (abfd, src->r_type);
2732 xcoff_swap_reloc_out (bfd *abfd, void * s, void * d)
2734 struct internal_reloc *src = (struct internal_reloc *) s;
2735 struct external_reloc *dst = (struct external_reloc *) d;
2737 bfd_put_32 (abfd, src->r_vaddr, dst->r_vaddr);
2738 bfd_put_32 (abfd, src->r_symndx, dst->r_symndx);
2739 bfd_put_8 (abfd, src->r_type, dst->r_type);
2740 bfd_put_8 (abfd, src->r_size, dst->r_size);
2742 return bfd_coff_relsz (abfd);
2745 /* Swap in the ldrel structure. */
2748 xcoff_swap_ldrel_in (bfd *abfd, const void * s, struct internal_ldrel *dst)
2750 const struct external_ldrel *src = (const struct external_ldrel *) s;
2752 dst->l_vaddr = bfd_get_32 (abfd, src->l_vaddr);
2753 dst->l_symndx = bfd_get_32 (abfd, src->l_symndx);
2754 dst->l_rtype = bfd_get_16 (abfd, src->l_rtype);
2755 dst->l_rsecnm = bfd_get_16 (abfd, src->l_rsecnm);
2758 /* Swap out the ldrel structure. */
2761 xcoff_swap_ldrel_out (bfd *abfd, const struct internal_ldrel *src, void * d)
2763 struct external_ldrel *dst = (struct external_ldrel *) d;
2765 bfd_put_32 (abfd, src->l_vaddr, dst->l_vaddr);
2766 bfd_put_32 (abfd, src->l_symndx, dst->l_symndx);
2767 bfd_put_16 (abfd, (bfd_vma) src->l_rtype, dst->l_rtype);
2768 bfd_put_16 (abfd, (bfd_vma) src->l_rsecnm, dst->l_rsecnm);
2773 xcoff_reloc_type_noop (bfd *input_bfd ATTRIBUTE_UNUSED,
2774 asection *input_section ATTRIBUTE_UNUSED,
2775 bfd *output_bfd ATTRIBUTE_UNUSED,
2776 struct internal_reloc *rel ATTRIBUTE_UNUSED,
2777 struct internal_syment *sym ATTRIBUTE_UNUSED,
2778 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED,
2779 bfd_vma val ATTRIBUTE_UNUSED,
2780 bfd_vma addend ATTRIBUTE_UNUSED,
2781 bfd_vma *relocation ATTRIBUTE_UNUSED,
2782 bfd_byte *contents ATTRIBUTE_UNUSED)
2788 xcoff_reloc_type_fail (bfd *input_bfd,
2789 asection *input_section ATTRIBUTE_UNUSED,
2790 bfd *output_bfd ATTRIBUTE_UNUSED,
2791 struct internal_reloc *rel,
2792 struct internal_syment *sym ATTRIBUTE_UNUSED,
2793 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED,
2794 bfd_vma val ATTRIBUTE_UNUSED,
2795 bfd_vma addend ATTRIBUTE_UNUSED,
2796 bfd_vma *relocation ATTRIBUTE_UNUSED,
2797 bfd_byte *contents ATTRIBUTE_UNUSED)
2799 (*_bfd_error_handler)
2800 (_("%s: unsupported relocation type 0x%02x"),
2801 bfd_get_filename (input_bfd), (unsigned int) rel->r_type);
2802 bfd_set_error (bfd_error_bad_value);
2807 xcoff_reloc_type_pos (bfd *input_bfd ATTRIBUTE_UNUSED,
2808 asection *input_section ATTRIBUTE_UNUSED,
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 ATTRIBUTE_UNUSED,
2815 bfd_vma *relocation,
2816 bfd_byte *contents ATTRIBUTE_UNUSED)
2818 *relocation = val + addend;
2823 xcoff_reloc_type_neg (bfd *input_bfd ATTRIBUTE_UNUSED,
2824 asection *input_section ATTRIBUTE_UNUSED,
2825 bfd *output_bfd ATTRIBUTE_UNUSED,
2826 struct internal_reloc *rel ATTRIBUTE_UNUSED,
2827 struct internal_syment *sym ATTRIBUTE_UNUSED,
2828 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED,
2831 bfd_vma *relocation,
2832 bfd_byte *contents ATTRIBUTE_UNUSED)
2834 *relocation = addend - val;
2839 xcoff_reloc_type_rel (bfd *input_bfd ATTRIBUTE_UNUSED,
2840 asection *input_section,
2841 bfd *output_bfd ATTRIBUTE_UNUSED,
2842 struct internal_reloc *rel ATTRIBUTE_UNUSED,
2843 struct internal_syment *sym ATTRIBUTE_UNUSED,
2844 struct reloc_howto_struct *howto,
2847 bfd_vma *relocation,
2848 bfd_byte *contents ATTRIBUTE_UNUSED)
2850 howto->pc_relative = TRUE;
2852 /* A PC relative reloc includes the section address. */
2853 addend += input_section->vma;
2855 *relocation = val + addend;
2856 *relocation -= (input_section->output_section->vma
2857 + input_section->output_offset);
2862 xcoff_reloc_type_toc (bfd *input_bfd,
2863 asection *input_section ATTRIBUTE_UNUSED,
2865 struct internal_reloc *rel,
2866 struct internal_syment *sym,
2867 struct reloc_howto_struct *howto ATTRIBUTE_UNUSED,
2869 bfd_vma addend ATTRIBUTE_UNUSED,
2870 bfd_vma *relocation,
2871 bfd_byte *contents ATTRIBUTE_UNUSED)
2873 struct xcoff_link_hash_entry *h;
2875 if (0 > rel->r_symndx)
2878 h = obj_xcoff_sym_hashes (input_bfd)[rel->r_symndx];
2880 if (h != NULL && h->smclas != XMC_TD)
2882 if (h->toc_section == NULL)
2884 (*_bfd_error_handler)
2885 (_("%s: TOC reloc at 0x%x to symbol `%s' with no TOC entry"),
2886 bfd_get_filename (input_bfd), rel->r_vaddr,
2887 h->root.root.string);
2888 bfd_set_error (bfd_error_bad_value);
2892 BFD_ASSERT ((h->flags & XCOFF_SET_TOC) == 0);
2893 val = (h->toc_section->output_section->vma
2894 + h->toc_section->output_offset);
2897 *relocation = ((val - xcoff_data (output_bfd)->toc)
2898 - (sym->n_value - xcoff_data (input_bfd)->toc));
2903 xcoff_reloc_type_ba (bfd *input_bfd ATTRIBUTE_UNUSED,
2904 asection *input_section ATTRIBUTE_UNUSED,
2905 bfd *output_bfd ATTRIBUTE_UNUSED,
2906 struct internal_reloc *rel ATTRIBUTE_UNUSED,
2907 struct internal_syment *sym ATTRIBUTE_UNUSED,
2908 struct reloc_howto_struct *howto,
2911 bfd_vma *relocation,
2912 bfd_byte *contents ATTRIBUTE_UNUSED)
2914 howto->src_mask &= ~3;
2915 howto->dst_mask = howto->src_mask;
2917 *relocation = val + addend;
2923 xcoff_reloc_type_br (bfd *input_bfd,
2924 asection *input_section,
2925 bfd *output_bfd ATTRIBUTE_UNUSED,
2926 struct internal_reloc *rel,
2927 struct internal_syment *sym ATTRIBUTE_UNUSED,
2928 struct reloc_howto_struct *howto,
2931 bfd_vma *relocation,
2934 struct xcoff_link_hash_entry *h;
2935 bfd_vma section_offset;
2937 if (0 > rel->r_symndx)
2940 h = obj_xcoff_sym_hashes (input_bfd)[rel->r_symndx];
2941 section_offset = rel->r_vaddr - input_section->vma;
2943 /* If we see an R_BR or R_RBR reloc which is jumping to global
2944 linkage code, and it is followed by an appropriate cror nop
2945 instruction, we replace the cror with lwz r2,20(r1). This
2946 restores the TOC after the glink code. Contrariwise, if the
2947 call is followed by a lwz r2,20(r1), but the call is not
2948 going to global linkage code, we can replace the load with a
2951 && (bfd_link_hash_defined == h->root.type
2952 || bfd_link_hash_defweak == h->root.type)
2953 && section_offset + 8 <= input_section->size)
2958 pnext = contents + section_offset + 4;
2959 next = bfd_get_32 (input_bfd, pnext);
2961 /* The _ptrgl function is magic. It is used by the AIX
2962 compiler to call a function through a pointer. */
2963 if (h->smclas == XMC_GL || strcmp (h->root.root.string, "._ptrgl") == 0)
2965 if (next == 0x4def7b82 /* cror 15,15,15 */
2966 || next == 0x4ffffb82 /* cror 31,31,31 */
2967 || next == 0x60000000) /* ori r0,r0,0 */
2968 bfd_put_32 (input_bfd, 0x80410014, pnext); /* lwz r2,20(r1) */
2973 if (next == 0x80410014) /* lwz r2,20(r1) */
2974 bfd_put_32 (input_bfd, 0x60000000, pnext); /* ori r0,r0,0 */
2977 else if (NULL != h && bfd_link_hash_undefined == h->root.type)
2979 /* Normally, this relocation is against a defined symbol. In the
2980 case where this is a partial link and the output section offset
2981 is greater than 2^25, the linker will return an invalid error
2982 message that the relocation has been truncated. Yes it has been
2983 truncated but no it not important. For this case, disable the
2984 overflow checking. */
2986 howto->complain_on_overflow = complain_overflow_dont;
2989 /* The original PC-relative relocation is biased by -r_vaddr, so adding
2990 the value below will give the absolute target address. */
2991 *relocation = val + addend + rel->r_vaddr;
2993 howto->src_mask &= ~3;
2994 howto->dst_mask = howto->src_mask;
2997 && (h->root.type == bfd_link_hash_defined
2998 || h->root.type == bfd_link_hash_defweak)
2999 && bfd_is_abs_section (h->root.u.def.section)
3000 && section_offset + 4 <= input_section->size)
3005 /* Turn the relative branch into an absolute one by setting the
3007 ptr = contents + section_offset;
3008 insn = bfd_get_32 (input_bfd, ptr);
3010 bfd_put_32 (input_bfd, insn, ptr);
3012 /* Make the howto absolute too. */
3013 howto->pc_relative = FALSE;
3014 howto->complain_on_overflow = complain_overflow_bitfield;
3018 /* Use a PC-relative howto and subtract the instruction's address
3019 from the target address we calculated above. */
3020 howto->pc_relative = TRUE;
3021 *relocation -= (input_section->output_section->vma
3022 + input_section->output_offset
3029 xcoff_reloc_type_crel (bfd *input_bfd ATTRIBUTE_UNUSED,
3030 asection *input_section,
3031 bfd *output_bfd ATTRIBUTE_UNUSED,
3032 struct internal_reloc *rel ATTRIBUTE_UNUSED,
3033 struct internal_syment *sym ATTRIBUTE_UNUSED,
3034 struct reloc_howto_struct *howto,
3035 bfd_vma val ATTRIBUTE_UNUSED,
3037 bfd_vma *relocation,
3038 bfd_byte *contents ATTRIBUTE_UNUSED)
3040 howto->pc_relative = TRUE;
3041 howto->src_mask &= ~3;
3042 howto->dst_mask = howto->src_mask;
3044 /* A PC relative reloc includes the section address. */
3045 addend += input_section->vma;
3047 *relocation = val + addend;
3048 *relocation -= (input_section->output_section->vma
3049 + input_section->output_offset);
3054 xcoff_complain_overflow_dont_func (bfd *input_bfd ATTRIBUTE_UNUSED,
3055 bfd_vma val ATTRIBUTE_UNUSED,
3056 bfd_vma relocation ATTRIBUTE_UNUSED,
3057 struct reloc_howto_struct *
3058 howto ATTRIBUTE_UNUSED)
3064 xcoff_complain_overflow_bitfield_func (bfd *input_bfd,
3067 struct reloc_howto_struct *howto)
3069 bfd_vma fieldmask, signmask, ss;
3072 /* Get the values to be added together. For signed and unsigned
3073 relocations, we assume that all values should be truncated to
3074 the size of an address. For bitfields, all the bits matter.
3075 See also bfd_check_overflow. */
3076 fieldmask = N_ONES (howto->bitsize);
3078 b = val & howto->src_mask;
3080 /* Much like unsigned, except no trimming with addrmask. In
3081 addition, the sum overflows if there is a carry out of
3082 the bfd_vma, i.e., the sum is less than either input
3084 a >>= howto->rightshift;
3085 b >>= howto->bitpos;
3087 /* Bitfields are sometimes used for signed numbers; for
3088 example, a 13-bit field sometimes represents values in
3089 0..8191 and sometimes represents values in -4096..4095.
3090 If the field is signed and a is -4095 (0x1001) and b is
3091 -1 (0x1fff), the sum is -4096 (0x1000), but (0x1001 +
3092 0x1fff is 0x3000). It's not clear how to handle this
3093 everywhere, since there is not way to know how many bits
3094 are significant in the relocation, but the original code
3095 assumed that it was fully sign extended, and we will keep
3097 signmask = (fieldmask >> 1) + 1;
3099 if ((a & ~ fieldmask) != 0)
3101 /* Some bits out of the field are set. This might not
3102 be a problem: if this is a signed bitfield, it is OK
3103 iff all the high bits are set, including the sign
3104 bit. We'll try setting all but the most significant
3105 bit in the original relocation value: if this is all
3106 ones, we are OK, assuming a signed bitfield. */
3107 ss = (signmask << howto->rightshift) - 1;
3108 if ((ss | relocation) != ~ (bfd_vma) 0)
3113 /* We just assume (b & ~ fieldmask) == 0. */
3115 /* We explicitly permit wrap around if this relocation
3116 covers the high bit of an address. The Linux kernel
3117 relies on it, and it is the only way to write assembler
3118 code which can run when loaded at a location 0x80000000
3119 away from the location at which it is linked. */
3120 if (howto->bitsize + howto->rightshift
3121 == bfd_arch_bits_per_address (input_bfd))
3125 if (sum < a || (sum & ~ fieldmask) != 0)
3127 /* There was a carry out, or the field overflow. Test
3128 for signed operands again. Here is the overflow test
3129 is as for complain_overflow_signed. */
3130 if (((~ (a ^ b)) & (a ^ sum)) & signmask)
3138 xcoff_complain_overflow_signed_func (bfd *input_bfd,
3141 struct reloc_howto_struct *howto)
3143 bfd_vma addrmask, fieldmask, signmask, ss;
3146 /* Get the values to be added together. For signed and unsigned
3147 relocations, we assume that all values should be truncated to
3148 the size of an address. For bitfields, all the bits matter.
3149 See also bfd_check_overflow. */
3150 fieldmask = N_ONES (howto->bitsize);
3151 addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask;
3153 b = val & howto->src_mask;
3155 a = (a & addrmask) >> howto->rightshift;
3157 /* If any sign bits are set, all sign bits must be set.
3158 That is, A must be a valid negative address after
3160 signmask = ~ (fieldmask >> 1);
3162 if (ss != 0 && ss != ((addrmask >> howto->rightshift) & signmask))
3165 /* We only need this next bit of code if the sign bit of B
3166 is below the sign bit of A. This would only happen if
3167 SRC_MASK had fewer bits than BITSIZE. Note that if
3168 SRC_MASK has more bits than BITSIZE, we can get into
3169 trouble; we would need to verify that B is in range, as
3170 we do for A above. */
3171 signmask = ((~ howto->src_mask) >> 1) & howto->src_mask;
3172 if ((b & signmask) != 0)
3174 /* Set all the bits above the sign bit. */
3175 b -= signmask <<= 1;
3178 b = (b & addrmask) >> howto->bitpos;
3180 /* Now we can do the addition. */
3183 /* See if the result has the correct sign. Bits above the
3184 sign bit are junk now; ignore them. If the sum is
3185 positive, make sure we did not have all negative inputs;
3186 if the sum is negative, make sure we did not have all
3187 positive inputs. The test below looks only at the sign
3188 bits, and it really just
3189 SIGN (A) == SIGN (B) && SIGN (A) != SIGN (SUM)
3191 signmask = (fieldmask >> 1) + 1;
3192 if (((~ (a ^ b)) & (a ^ sum)) & signmask)
3199 xcoff_complain_overflow_unsigned_func (bfd *input_bfd,
3202 struct reloc_howto_struct *howto)
3204 bfd_vma addrmask, fieldmask;
3207 /* Get the values to be added together. For signed and unsigned
3208 relocations, we assume that all values should be truncated to
3209 the size of an address. For bitfields, all the bits matter.
3210 See also bfd_check_overflow. */
3211 fieldmask = N_ONES (howto->bitsize);
3212 addrmask = N_ONES (bfd_arch_bits_per_address (input_bfd)) | fieldmask;
3214 b = val & howto->src_mask;
3216 /* Checking for an unsigned overflow is relatively easy:
3217 trim the addresses and add, and trim the result as well.
3218 Overflow is normally indicated when the result does not
3219 fit in the field. However, we also need to consider the
3220 case when, e.g., fieldmask is 0x7fffffff or smaller, an
3221 input is 0x80000000, and bfd_vma is only 32 bits; then we
3222 will get sum == 0, but there is an overflow, since the
3223 inputs did not fit in the field. Instead of doing a
3224 separate test, we can check for this by or-ing in the
3225 operands when testing for the sum overflowing its final
3227 a = (a & addrmask) >> howto->rightshift;
3228 b = (b & addrmask) >> howto->bitpos;
3229 sum = (a + b) & addrmask;
3230 if ((a | b | sum) & ~ fieldmask)
3236 /* This is the relocation function for the RS/6000/POWER/PowerPC.
3237 This is currently the only processor which uses XCOFF; I hope that
3240 I took the relocation type definitions from two documents:
3241 the PowerPC AIX Version 4 Application Binary Interface, First
3242 Edition (April 1992), and the PowerOpen ABI, Big-Endian
3243 32-Bit Hardware Implementation (June 30, 1994). Differences
3244 between the documents are noted below.
3246 Unsupported r_type's
3252 These relocs are defined by the PowerPC ABI to be
3253 relative branches which use half of the difference
3254 between the symbol and the program counter. I can't
3255 quite figure out when this is useful. These relocs are
3256 not defined by the PowerOpen ABI.
3261 Simple positive relocation.
3264 Simple negative relocation.
3267 Simple PC relative relocation.
3270 TOC relative relocation. The value in the instruction in
3271 the input file is the offset from the input file TOC to
3272 the desired location. We want the offset from the final
3273 TOC to the desired location. We have:
3278 so we must change insn by on - in.
3281 GL linkage relocation. The value of this relocation
3282 is the address of the entry in the TOC section.
3285 Local object TOC address. I can't figure out the
3286 difference between this and case R_GL.
3289 TOC relative relocation. A TOC relative load instruction
3290 which may be changed to a load address instruction.
3291 FIXME: We don't currently implement this optimization.
3294 TOC relative relocation. This is a TOC relative load
3295 address instruction which may be changed to a load
3296 instruction. FIXME: I don't know if this is the correct
3300 Absolute branch. We don't want to mess with the lower
3301 two bits of the instruction.
3304 The PowerPC ABI defines this as an absolute call which
3305 may be modified to become a relative call. The PowerOpen
3306 ABI does not define this relocation type.
3309 Absolute branch which may be modified to become a
3313 The PowerPC ABI defines this as an absolute branch to a
3314 fixed address which may be modified to an absolute branch
3315 to a symbol. The PowerOpen ABI does not define this
3319 The PowerPC ABI defines this as an absolute branch to a
3320 fixed address which may be modified to a relative branch.
3321 The PowerOpen ABI does not define this relocation type.
3324 Relative branch. We don't want to mess with the lower
3325 two bits of the instruction.
3328 The PowerPC ABI defines this as a relative call which may
3329 be modified to become an absolute call. The PowerOpen
3330 ABI does not define this relocation type.
3333 A relative branch which may be modified to become an
3337 The PowerPC AIX ABI describes this as a load which may be
3338 changed to a load address. The PowerOpen ABI says this
3339 is the same as case R_POS.
3342 The PowerPC AIX ABI describes this as a load address
3343 which may be changed to a load. The PowerOpen ABI says
3344 this is the same as R_POS.
3348 xcoff_ppc_relocate_section (bfd *output_bfd,
3349 struct bfd_link_info *info,
3351 asection *input_section,
3353 struct internal_reloc *relocs,
3354 struct internal_syment *syms,
3355 asection **sections)
3357 struct internal_reloc *rel;
3358 struct internal_reloc *relend;
3361 relend = rel + input_section->reloc_count;
3362 for (; rel < relend; rel++)
3365 struct xcoff_link_hash_entry *h;
3366 struct internal_syment *sym;
3369 struct reloc_howto_struct howto;
3371 bfd_vma value_to_relocate;
3375 /* Relocation type R_REF is a special relocation type which is
3376 merely used to prevent garbage collection from occurring for
3377 the csect including the symbol which it references. */
3378 if (rel->r_type == R_REF)
3382 howto.type = rel->r_type;
3383 howto.rightshift = 0;
3384 howto.bitsize = (rel->r_size & 0x1f) + 1;
3385 howto.size = howto.bitsize > 16 ? 2 : 1;
3386 howto.pc_relative = FALSE;
3388 howto.complain_on_overflow = (rel->r_size & 0x80
3389 ? complain_overflow_signed
3390 : complain_overflow_bitfield);
3391 howto.special_function = NULL;
3392 howto.name = "internal";
3393 howto.partial_inplace = TRUE;
3394 howto.src_mask = howto.dst_mask = N_ONES (howto.bitsize);
3395 howto.pcrel_offset = FALSE;
3402 symndx = rel->r_symndx;
3408 h = obj_xcoff_sym_hashes (input_bfd)[symndx];
3409 sym = syms + symndx;
3410 addend = - sym->n_value;
3414 sec = sections[symndx];
3415 /* Hack to make sure we use the right TOC anchor value
3416 if this reloc is against the TOC anchor. */
3417 if (sec->name[3] == '0'
3418 && strcmp (sec->name, ".tc0") == 0)
3419 val = xcoff_data (output_bfd)->toc;
3421 val = (sec->output_section->vma
3422 + sec->output_offset
3428 if (info->unresolved_syms_in_objects != RM_IGNORE
3429 && (h->flags & XCOFF_WAS_UNDEFINED) != 0)
3431 if (! ((*info->callbacks->undefined_symbol)
3432 (info, h->root.root.string,
3433 input_bfd, input_section,
3434 rel->r_vaddr - input_section->vma,
3435 (info->unresolved_syms_in_objects
3436 == RM_GENERATE_ERROR))))
3439 if (h->root.type == bfd_link_hash_defined
3440 || h->root.type == bfd_link_hash_defweak)
3442 sec = h->root.u.def.section;
3443 val = (h->root.u.def.value
3444 + sec->output_section->vma
3445 + sec->output_offset);
3447 else if (h->root.type == bfd_link_hash_common)
3449 sec = h->root.u.c.p->section;
3450 val = (sec->output_section->vma
3451 + sec->output_offset);
3456 BFD_ASSERT (info->relocatable
3457 || (info->static_link
3458 && (h->flags & XCOFF_WAS_UNDEFINED) != 0)
3459 || (h->flags & XCOFF_DEF_DYNAMIC) != 0
3460 || (h->flags & XCOFF_IMPORT) != 0);
3465 if (rel->r_type >= XCOFF_MAX_CALCULATE_RELOCATION
3466 || !((*xcoff_calculate_relocation[rel->r_type])
3467 (input_bfd, input_section, output_bfd, rel, sym, &howto, val,
3468 addend, &relocation, contents)))
3472 address = rel->r_vaddr - input_section->vma;
3473 location = contents + address;
3475 if (address > input_section->size)
3478 /* Get the value we are going to relocate. */
3479 if (1 == howto.size)
3480 value_to_relocate = bfd_get_16 (input_bfd, location);
3482 value_to_relocate = bfd_get_32 (input_bfd, location);
3486 FIXME: We may drop bits during the addition
3487 which we don't check for. We must either check at every single
3488 operation, which would be tedious, or we must do the computations
3489 in a type larger than bfd_vma, which would be inefficient. */
3491 if ((unsigned int) howto.complain_on_overflow
3492 >= XCOFF_MAX_COMPLAIN_OVERFLOW)
3495 if (((*xcoff_complain_overflow[howto.complain_on_overflow])
3496 (input_bfd, value_to_relocate, relocation, &howto)))
3499 char buf[SYMNMLEN + 1];
3500 char reloc_type_name[10];
3512 name = _bfd_coff_internal_syment_name (input_bfd, sym, buf);
3516 sprintf (reloc_type_name, "0x%02x", rel->r_type);
3518 if (! ((*info->callbacks->reloc_overflow)
3519 (info, (h ? &h->root : NULL), name, reloc_type_name,
3520 (bfd_vma) 0, input_bfd, input_section,
3521 rel->r_vaddr - input_section->vma)))
3525 /* Add RELOCATION to the right bits of VALUE_TO_RELOCATE. */
3526 value_to_relocate = ((value_to_relocate & ~howto.dst_mask)
3527 | (((value_to_relocate & howto.src_mask)
3528 + relocation) & howto.dst_mask));
3530 /* Put the value back in the object file. */
3531 if (1 == howto.size)
3532 bfd_put_16 (input_bfd, value_to_relocate, location);
3534 bfd_put_32 (input_bfd, value_to_relocate, location);
3541 _bfd_xcoff_put_ldsymbol_name (bfd *abfd ATTRIBUTE_UNUSED,
3542 struct xcoff_loader_info *ldinfo,
3543 struct internal_ldsym *ldsym,
3547 len = strlen (name);
3549 if (len <= SYMNMLEN)
3550 strncpy (ldsym->_l._l_name, name, SYMNMLEN);
3553 if (ldinfo->string_size + len + 3 > ldinfo->string_alc)
3555 bfd_size_type newalc;
3558 newalc = ldinfo->string_alc * 2;
3561 while (ldinfo->string_size + len + 3 > newalc)
3564 newstrings = bfd_realloc (ldinfo->strings, newalc);
3565 if (newstrings == NULL)
3567 ldinfo->failed = TRUE;
3570 ldinfo->string_alc = newalc;
3571 ldinfo->strings = newstrings;
3574 bfd_put_16 (ldinfo->output_bfd, (bfd_vma) (len + 1),
3575 ldinfo->strings + ldinfo->string_size);
3576 strcpy (ldinfo->strings + ldinfo->string_size + 2, name);
3577 ldsym->_l._l_l._l_zeroes = 0;
3578 ldsym->_l._l_l._l_offset = ldinfo->string_size + 2;
3579 ldinfo->string_size += len + 3;
3586 _bfd_xcoff_put_symbol_name (bfd *abfd, struct bfd_strtab_hash *strtab,
3587 struct internal_syment *sym,
3590 if (strlen (name) <= SYMNMLEN)
3592 strncpy (sym->_n._n_name, name, SYMNMLEN);
3600 if ((abfd->flags & BFD_TRADITIONAL_FORMAT) != 0)
3602 indx = _bfd_stringtab_add (strtab, name, hash, FALSE);
3603 if (indx == (bfd_size_type) -1)
3605 sym->_n._n_n._n_zeroes = 0;
3606 sym->_n._n_n._n_offset = STRING_SIZE_SIZE + indx;
3612 xcoff_create_csect_from_smclas (bfd *abfd,
3613 union internal_auxent *aux,
3614 const char *symbol_name)
3616 asection *return_value = NULL;
3618 /* .sv64 = x_smclas == 17
3619 This is an invalid csect for 32 bit apps. */
3620 static const char * const names[] =
3622 ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo", /* 0 - 7 */
3623 ".sv", ".bs", ".ds", ".uc", ".ti", ".tb", NULL, ".tc0", /* 8 - 15 */
3624 ".td", NULL, ".sv3264", NULL, ".tl", ".ul", ".te"
3627 if ((aux->x_csect.x_smclas < ARRAY_SIZE (names))
3628 && (NULL != names[aux->x_csect.x_smclas]))
3630 return_value = bfd_make_section_anyway
3631 (abfd, names[aux->x_csect.x_smclas]);
3635 (*_bfd_error_handler)
3636 (_("%B: symbol `%s' has unrecognized smclas %d"),
3637 abfd, symbol_name, aux->x_csect.x_smclas);
3638 bfd_set_error (bfd_error_bad_value);
3641 return return_value;
3645 xcoff_is_lineno_count_overflow (bfd *abfd ATTRIBUTE_UNUSED, bfd_vma value)
3647 if (0xffff <= value)
3654 xcoff_is_reloc_count_overflow (bfd *abfd ATTRIBUTE_UNUSED, bfd_vma value)
3656 if (0xffff <= value)
3663 xcoff_loader_symbol_offset (bfd *abfd,
3664 struct internal_ldhdr *ldhdr ATTRIBUTE_UNUSED)
3666 return bfd_xcoff_ldhdrsz (abfd);
3670 xcoff_loader_reloc_offset (bfd *abfd, struct internal_ldhdr *ldhdr)
3672 return bfd_xcoff_ldhdrsz (abfd) + ldhdr->l_nsyms * bfd_xcoff_ldsymsz (abfd);
3676 xcoff_generate_rtinit (bfd *abfd, const char *init, const char *fini,
3679 bfd_byte filehdr_ext[FILHSZ];
3680 bfd_byte scnhdr_ext[SCNHSZ];
3681 bfd_byte syment_ext[SYMESZ * 10];
3682 bfd_byte reloc_ext[RELSZ * 3];
3683 bfd_byte *data_buffer;
3684 bfd_size_type data_buffer_size;
3685 bfd_byte *string_table = NULL, *st_tmp = NULL;
3686 bfd_size_type string_table_size;
3688 size_t initsz, finisz;
3689 struct internal_filehdr filehdr;
3690 struct internal_scnhdr scnhdr;
3691 struct internal_syment syment;
3692 union internal_auxent auxent;
3693 struct internal_reloc reloc;
3695 char *data_name = ".data";
3696 char *rtinit_name = "__rtinit";
3697 char *rtld_name = "__rtld";
3699 if (! bfd_xcoff_rtinit_size (abfd))
3702 initsz = (init == NULL ? 0 : 1 + strlen (init));
3703 finisz = (fini == NULL ? 0 : 1 + strlen (fini));
3706 memset (filehdr_ext, 0, FILHSZ);
3707 memset (&filehdr, 0, sizeof (struct internal_filehdr));
3708 filehdr.f_magic = bfd_xcoff_magic_number (abfd);
3709 filehdr.f_nscns = 1;
3710 filehdr.f_timdat = 0;
3711 filehdr.f_nsyms = 0; /* at least 6, no more than 10 */
3712 filehdr.f_symptr = 0; /* set below */
3713 filehdr.f_opthdr = 0;
3714 filehdr.f_flags = 0;
3716 /* section header */
3717 memset (scnhdr_ext, 0, SCNHSZ);
3718 memset (&scnhdr, 0, sizeof (struct internal_scnhdr));
3719 memcpy (scnhdr.s_name, data_name, strlen (data_name));
3722 scnhdr.s_size = 0; /* set below */
3723 scnhdr.s_scnptr = FILHSZ + SCNHSZ;
3724 scnhdr.s_relptr = 0; /* set below */
3725 scnhdr.s_lnnoptr = 0;
3726 scnhdr.s_nreloc = 0; /* either 1 or 2 */
3728 scnhdr.s_flags = STYP_DATA;
3731 0x0000 0x00000000 : rtl
3732 0x0004 0x00000010 : offset to init, or 0
3733 0x0008 0x00000028 : offset to fini, or 0
3734 0x000C 0x0000000C : size of descriptor
3735 0x0010 0x00000000 : init, needs a reloc
3736 0x0014 0x00000040 : offset to init name
3737 0x0018 0x00000000 : flags, padded to a word
3738 0x001C 0x00000000 : empty init
3741 0x0028 0x00000000 : fini, needs a reloc
3742 0x002C 0x00000??? : offset to fini name
3743 0x0030 0x00000000 : flags, padded to a word
3744 0x0034 0x00000000 : empty fini
3748 0x0040 + initsz fini name */
3750 data_buffer_size = 0x0040 + initsz + finisz;
3751 data_buffer_size = (data_buffer_size + 7) &~ (bfd_size_type) 7;
3753 data_buffer = (bfd_byte *) bfd_zmalloc (data_buffer_size);
3754 if (data_buffer == NULL)
3760 bfd_h_put_32 (abfd, val, &data_buffer[0x04]);
3762 bfd_h_put_32 (abfd, val, &data_buffer[0x14]);
3763 memcpy (&data_buffer[val], init, initsz);
3769 bfd_h_put_32 (abfd, val, &data_buffer[0x08]);
3770 val = 0x40 + initsz;
3771 bfd_h_put_32 (abfd, val, &data_buffer[0x2C]);
3772 memcpy (&data_buffer[val], fini, finisz);
3776 bfd_h_put_32 (abfd, val, &data_buffer[0x0C]);
3778 scnhdr.s_size = data_buffer_size;
3781 string_table_size = 0;
3783 string_table_size += initsz;
3785 string_table_size += finisz;
3786 if (string_table_size)
3788 string_table_size += 4;
3789 string_table = (bfd_byte *) bfd_zmalloc (string_table_size);
3790 if (string_table == NULL)
3793 val = string_table_size;
3794 bfd_h_put_32 (abfd, val, &string_table[0]);
3795 st_tmp = string_table + 4;
3804 memset (syment_ext, 0, 10 * SYMESZ);
3805 memset (reloc_ext, 0, 3 * RELSZ);
3808 memset (&syment, 0, sizeof (struct internal_syment));
3809 memset (&auxent, 0, sizeof (union internal_auxent));
3810 memcpy (syment._n._n_name, data_name, strlen (data_name));
3812 syment.n_sclass = C_HIDEXT;
3813 syment.n_numaux = 1;
3814 auxent.x_csect.x_scnlen.l = data_buffer_size;
3815 auxent.x_csect.x_smtyp = 3 << 3 | XTY_SD;
3816 auxent.x_csect.x_smclas = XMC_RW;
3817 bfd_coff_swap_sym_out (abfd, &syment,
3818 &syment_ext[filehdr.f_nsyms * SYMESZ]);
3819 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
3821 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
3822 filehdr.f_nsyms += 2;
3825 memset (&syment, 0, sizeof (struct internal_syment));
3826 memset (&auxent, 0, sizeof (union internal_auxent));
3827 memcpy (syment._n._n_name, rtinit_name, strlen (rtinit_name));
3829 syment.n_sclass = C_EXT;
3830 syment.n_numaux = 1;
3831 auxent.x_csect.x_smtyp = XTY_LD;
3832 auxent.x_csect.x_smclas = XMC_RW;
3833 bfd_coff_swap_sym_out (abfd, &syment,
3834 &syment_ext[filehdr.f_nsyms * SYMESZ]);
3835 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
3837 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
3838 filehdr.f_nsyms += 2;
3843 memset (&syment, 0, sizeof (struct internal_syment));
3844 memset (&auxent, 0, sizeof (union internal_auxent));
3848 syment._n._n_n._n_offset = st_tmp - string_table;
3849 memcpy (st_tmp, init, initsz);
3853 memcpy (syment._n._n_name, init, initsz - 1);
3855 syment.n_sclass = C_EXT;
3856 syment.n_numaux = 1;
3857 bfd_coff_swap_sym_out (abfd, &syment,
3858 &syment_ext[filehdr.f_nsyms * SYMESZ]);
3859 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
3861 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
3864 memset (&reloc, 0, sizeof (struct internal_reloc));
3865 reloc.r_vaddr = 0x0010;
3866 reloc.r_symndx = filehdr.f_nsyms;
3867 reloc.r_type = R_POS;
3869 bfd_coff_swap_reloc_out (abfd, &reloc, &reloc_ext[0]);
3871 filehdr.f_nsyms += 2;
3872 scnhdr.s_nreloc += 1;
3878 memset (&syment, 0, sizeof (struct internal_syment));
3879 memset (&auxent, 0, sizeof (union internal_auxent));
3883 syment._n._n_n._n_offset = st_tmp - string_table;
3884 memcpy (st_tmp, fini, finisz);
3888 memcpy (syment._n._n_name, fini, finisz - 1);
3890 syment.n_sclass = C_EXT;
3891 syment.n_numaux = 1;
3892 bfd_coff_swap_sym_out (abfd, &syment,
3893 &syment_ext[filehdr.f_nsyms * SYMESZ]);
3894 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
3896 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
3899 memset (&reloc, 0, sizeof (struct internal_reloc));
3900 reloc.r_vaddr = 0x0028;
3901 reloc.r_symndx = filehdr.f_nsyms;
3902 reloc.r_type = R_POS;
3904 bfd_coff_swap_reloc_out (abfd, &reloc,
3905 &reloc_ext[scnhdr.s_nreloc * RELSZ]);
3907 filehdr.f_nsyms += 2;
3908 scnhdr.s_nreloc += 1;
3913 memset (&syment, 0, sizeof (struct internal_syment));
3914 memset (&auxent, 0, sizeof (union internal_auxent));
3915 memcpy (syment._n._n_name, rtld_name, strlen (rtld_name));
3916 syment.n_sclass = C_EXT;
3917 syment.n_numaux = 1;
3918 bfd_coff_swap_sym_out (abfd, &syment,
3919 &syment_ext[filehdr.f_nsyms * SYMESZ]);
3920 bfd_coff_swap_aux_out (abfd, &auxent, syment.n_type, syment.n_sclass, 0,
3922 &syment_ext[(filehdr.f_nsyms + 1) * SYMESZ]);
3925 memset (&reloc, 0, sizeof (struct internal_reloc));
3926 reloc.r_vaddr = 0x0000;
3927 reloc.r_symndx = filehdr.f_nsyms;
3928 reloc.r_type = R_POS;
3930 bfd_coff_swap_reloc_out (abfd, &reloc,
3931 &reloc_ext[scnhdr.s_nreloc * RELSZ]);
3933 filehdr.f_nsyms += 2;
3934 scnhdr.s_nreloc += 1;
3937 scnhdr.s_relptr = scnhdr.s_scnptr + data_buffer_size;
3938 filehdr.f_symptr = scnhdr.s_relptr + scnhdr.s_nreloc * RELSZ;
3940 bfd_coff_swap_filehdr_out (abfd, &filehdr, filehdr_ext);
3941 bfd_bwrite (filehdr_ext, FILHSZ, abfd);
3942 bfd_coff_swap_scnhdr_out (abfd, &scnhdr, scnhdr_ext);
3943 bfd_bwrite (scnhdr_ext, SCNHSZ, abfd);
3944 bfd_bwrite (data_buffer, data_buffer_size, abfd);
3945 bfd_bwrite (reloc_ext, scnhdr.s_nreloc * RELSZ, abfd);
3946 bfd_bwrite (syment_ext, filehdr.f_nsyms * SYMESZ, abfd);
3947 bfd_bwrite (string_table, string_table_size, abfd);
3956 static reloc_howto_type xcoff_dynamic_reloc =
3957 HOWTO (0, /* type */
3959 2, /* size (0 = byte, 1 = short, 2 = long) */
3961 FALSE, /* pc_relative */
3963 complain_overflow_bitfield, /* complain_on_overflow */
3964 0, /* special_function */
3966 TRUE, /* partial_inplace */
3967 0xffffffff, /* src_mask */
3968 0xffffffff, /* dst_mask */
3969 FALSE); /* pcrel_offset */
3973 The first word of global linkage code must be modified by filling in
3974 the correct TOC offset. */
3976 static unsigned long xcoff_glink_code[9] =
3978 0x81820000, /* lwz r12,0(r2) */
3979 0x90410014, /* stw r2,20(r1) */
3980 0x800c0000, /* lwz r0,0(r12) */
3981 0x804c0004, /* lwz r2,4(r12) */
3982 0x7c0903a6, /* mtctr r0 */
3983 0x4e800420, /* bctr */
3984 0x00000000, /* start of traceback table */
3985 0x000c8000, /* traceback table */
3986 0x00000000, /* traceback table */
3989 /* Table to convert DWARF flags to section names. */
3991 const struct xcoff_dwsect_name xcoff_dwsect_names[] = {
3992 { SSUBTYP_DWINFO, ".dwinfo", TRUE },
3993 { SSUBTYP_DWLINE, ".dwline", TRUE },
3994 { SSUBTYP_DWPBNMS, ".dwpbnms", TRUE },
3995 { SSUBTYP_DWPBTYP, ".dwpbtyp", TRUE },
3996 { SSUBTYP_DWARNGE, ".dwarnge", TRUE },
3997 { SSUBTYP_DWABREV, ".dwabrev", FALSE },
3998 { SSUBTYP_DWSTR, ".dwstr", TRUE },
3999 { SSUBTYP_DWRNGES, ".dwrnges", TRUE }
4002 /* For generic entry points. */
4003 #define _bfd_xcoff_close_and_cleanup _bfd_archive_close_and_cleanup
4004 #define _bfd_xcoff_bfd_free_cached_info bfd_true
4005 #define _bfd_xcoff_new_section_hook coff_new_section_hook
4006 #define _bfd_xcoff_get_section_contents _bfd_generic_get_section_contents
4007 #define _bfd_xcoff_get_section_contents_in_window \
4008 _bfd_generic_get_section_contents_in_window
4010 /* For copy private data entry points. */
4011 #define _bfd_xcoff_bfd_copy_private_bfd_data \
4012 _bfd_xcoff_copy_private_bfd_data
4013 #define _bfd_xcoff_bfd_merge_private_bfd_data \
4014 _bfd_generic_bfd_merge_private_bfd_data
4015 #define _bfd_xcoff_bfd_copy_private_section_data \
4016 _bfd_generic_bfd_copy_private_section_data
4017 #define _bfd_xcoff_bfd_copy_private_symbol_data \
4018 _bfd_generic_bfd_copy_private_symbol_data
4019 #define _bfd_xcoff_bfd_copy_private_header_data \
4020 _bfd_generic_bfd_copy_private_header_data
4021 #define _bfd_xcoff_bfd_set_private_flags \
4022 _bfd_generic_bfd_set_private_flags
4023 #define _bfd_xcoff_bfd_print_private_bfd_data \
4024 _bfd_generic_bfd_print_private_bfd_data
4026 /* For archive entry points. */
4027 #define _bfd_xcoff_slurp_extended_name_table \
4028 _bfd_noarchive_slurp_extended_name_table
4029 #define _bfd_xcoff_construct_extended_name_table \
4030 _bfd_noarchive_construct_extended_name_table
4031 #define _bfd_xcoff_truncate_arname bfd_dont_truncate_arname
4032 #define _bfd_xcoff_write_ar_hdr _bfd_generic_write_ar_hdr
4033 #define _bfd_xcoff_get_elt_at_index _bfd_generic_get_elt_at_index
4034 #define _bfd_xcoff_generic_stat_arch_elt _bfd_xcoff_stat_arch_elt
4035 #define _bfd_xcoff_update_armap_timestamp bfd_true
4037 /* For symbols entry points. */
4038 #define _bfd_xcoff_get_symtab_upper_bound coff_get_symtab_upper_bound
4039 #define _bfd_xcoff_canonicalize_symtab coff_canonicalize_symtab
4040 #define _bfd_xcoff_make_empty_symbol coff_make_empty_symbol
4041 #define _bfd_xcoff_print_symbol coff_print_symbol
4042 #define _bfd_xcoff_get_symbol_info coff_get_symbol_info
4043 #define _bfd_xcoff_bfd_is_local_label_name _bfd_xcoff_is_local_label_name
4044 #define _bfd_xcoff_bfd_is_target_special_symbol \
4045 coff_bfd_is_target_special_symbol
4046 #define _bfd_xcoff_get_lineno coff_get_lineno
4047 #define _bfd_xcoff_find_nearest_line xcoff_find_nearest_line
4048 #define _bfd_generic_find_nearest_line_discriminator \
4049 xcoff_find_nearest_line_discriminator
4050 #define _bfd_xcoff_find_inliner_info coff_find_inliner_info
4051 #define _bfd_xcoff_bfd_make_debug_symbol coff_bfd_make_debug_symbol
4052 #define _bfd_xcoff_read_minisymbols _bfd_generic_read_minisymbols
4053 #define _bfd_xcoff_minisymbol_to_symbol _bfd_generic_minisymbol_to_symbol
4055 /* For reloc entry points. */
4056 #define _bfd_xcoff_get_reloc_upper_bound coff_get_reloc_upper_bound
4057 #define _bfd_xcoff_canonicalize_reloc coff_canonicalize_reloc
4058 #define _bfd_xcoff_bfd_reloc_type_lookup _bfd_xcoff_reloc_type_lookup
4059 #define _bfd_xcoff_bfd_reloc_name_lookup _bfd_xcoff_reloc_name_lookup
4061 /* For link entry points. */
4062 #define _bfd_xcoff_bfd_get_relocated_section_contents \
4063 bfd_generic_get_relocated_section_contents
4064 #define _bfd_xcoff_bfd_relax_section bfd_generic_relax_section
4065 #define _bfd_xcoff_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
4066 #define _bfd_xcoff_bfd_link_just_syms _bfd_generic_link_just_syms
4067 #define _bfd_xcoff_bfd_copy_link_hash_symbol_type \
4068 _bfd_generic_copy_link_hash_symbol_type
4069 #define _bfd_xcoff_bfd_link_split_section _bfd_generic_link_split_section
4070 #define _bfd_xcoff_bfd_gc_sections bfd_generic_gc_sections
4071 #define _bfd_xcoff_bfd_lookup_section_flags bfd_generic_lookup_section_flags
4072 #define _bfd_xcoff_bfd_merge_sections bfd_generic_merge_sections
4073 #define _bfd_xcoff_bfd_is_group_section bfd_generic_is_group_section
4074 #define _bfd_xcoff_bfd_discard_group bfd_generic_discard_group
4075 #define _bfd_xcoff_section_already_linked _bfd_generic_section_already_linked
4076 #define _bfd_xcoff_bfd_define_common_symbol _bfd_xcoff_define_common_symbol
4078 /* For dynamic symbols and relocs entry points. */
4079 #define _bfd_xcoff_get_synthetic_symtab _bfd_nodynamic_get_synthetic_symtab
4081 static const struct xcoff_backend_data_rec bfd_xcoff_backend_data =
4083 { /* COFF backend, defined in libcoff.h. */
4084 _bfd_xcoff_swap_aux_in,
4085 _bfd_xcoff_swap_sym_in,
4086 coff_swap_lineno_in,
4087 _bfd_xcoff_swap_aux_out,
4088 _bfd_xcoff_swap_sym_out,
4089 coff_swap_lineno_out,
4090 xcoff_swap_reloc_out,
4091 coff_swap_filehdr_out,
4092 coff_swap_aouthdr_out,
4093 coff_swap_scnhdr_out,
4102 TRUE, /* _bfd_coff_long_filenames */
4103 XCOFF_NO_LONG_SECTION_NAMES, /* _bfd_coff_long_section_names */
4104 3, /* _bfd_coff_default_section_alignment_power */
4105 FALSE, /* _bfd_coff_force_symnames_in_strings */
4106 2, /* _bfd_coff_debug_string_prefix_length */
4107 coff_swap_filehdr_in,
4108 coff_swap_aouthdr_in,
4109 coff_swap_scnhdr_in,
4110 xcoff_swap_reloc_in,
4111 coff_bad_format_hook,
4112 coff_set_arch_mach_hook,
4115 coff_set_alignment_hook,
4116 coff_slurp_symbol_table,
4117 symname_in_debug_hook,
4118 coff_pointerize_aux_hook,
4120 dummy_reloc16_extra_cases,
4121 dummy_reloc16_estimate,
4122 NULL, /* bfd_coff_sym_is_global */
4123 coff_compute_section_file_positions,
4124 NULL, /* _bfd_coff_start_final_link */
4125 xcoff_ppc_relocate_section,
4126 coff_rtype_to_howto,
4127 NULL, /* _bfd_coff_adjust_symndx */
4128 _bfd_generic_link_add_one_symbol,
4129 coff_link_output_has_begun,
4130 coff_final_link_postscript,
4131 NULL /* print_pdata. */
4134 0x01DF, /* magic number */
4138 /* Function pointers to xcoff specific swap routines. */
4139 xcoff_swap_ldhdr_in,
4140 xcoff_swap_ldhdr_out,
4141 xcoff_swap_ldsym_in,
4142 xcoff_swap_ldsym_out,
4143 xcoff_swap_ldrel_in,
4144 xcoff_swap_ldrel_out,
4150 12, /* _xcoff_function_descriptor_size */
4154 1, /* _xcoff_ldhdr_version */
4156 _bfd_xcoff_put_symbol_name,
4157 _bfd_xcoff_put_ldsymbol_name,
4158 &xcoff_dynamic_reloc,
4159 xcoff_create_csect_from_smclas,
4161 /* Lineno and reloc count overflow. */
4162 xcoff_is_lineno_count_overflow,
4163 xcoff_is_reloc_count_overflow,
4165 xcoff_loader_symbol_offset,
4166 xcoff_loader_reloc_offset,
4169 &xcoff_glink_code[0],
4170 36, /* _xcoff_glink_size */
4173 64, /* _xcoff_rtinit_size */
4174 xcoff_generate_rtinit,
4177 /* The transfer vector that leads the outside world to all of the above. */
4178 const bfd_target rs6000coff_vec =
4181 bfd_target_xcoff_flavour,
4182 BFD_ENDIAN_BIG, /* data byte order is big */
4183 BFD_ENDIAN_BIG, /* header byte order is big */
4185 (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | DYNAMIC
4186 | HAS_SYMS | HAS_LOCALS | WP_TEXT),
4188 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA,
4189 0, /* leading char */
4190 '/', /* ar_pad_char */
4191 15, /* ar_max_namelen */
4192 0, /* match priority. */
4216 { /* bfd_check_format */
4219 _bfd_xcoff_archive_p,
4223 { /* bfd_set_format */
4226 _bfd_generic_mkarchive,
4230 {/* bfd_write_contents */
4232 coff_write_object_contents,
4233 _bfd_xcoff_write_archive_contents,
4237 BFD_JUMP_TABLE_GENERIC (_bfd_xcoff),
4238 BFD_JUMP_TABLE_COPY (_bfd_xcoff),
4239 BFD_JUMP_TABLE_CORE (coff),
4240 BFD_JUMP_TABLE_ARCHIVE (_bfd_xcoff),
4241 BFD_JUMP_TABLE_SYMBOLS (_bfd_xcoff),
4242 BFD_JUMP_TABLE_RELOCS (_bfd_xcoff),
4243 BFD_JUMP_TABLE_WRITE (coff),
4244 BFD_JUMP_TABLE_LINK (_bfd_xcoff),
4245 BFD_JUMP_TABLE_DYNAMIC (_bfd_xcoff),
4247 /* Opposite endian version, none exists */
4250 & bfd_xcoff_backend_data,
4253 /* xcoff-powermac target
4255 Only difference between this target and the rs6000 target is the
4256 the default architecture and machine type used in coffcode.h
4258 PowerPC Macs use the same magic numbers as RS/6000
4259 (because that's how they were bootstrapped originally),
4260 but they are always PowerPC architecture. */
4261 static const struct xcoff_backend_data_rec bfd_pmac_xcoff_backend_data =
4263 { /* COFF backend, defined in libcoff.h. */
4264 _bfd_xcoff_swap_aux_in,
4265 _bfd_xcoff_swap_sym_in,
4266 coff_swap_lineno_in,
4267 _bfd_xcoff_swap_aux_out,
4268 _bfd_xcoff_swap_sym_out,
4269 coff_swap_lineno_out,
4270 xcoff_swap_reloc_out,
4271 coff_swap_filehdr_out,
4272 coff_swap_aouthdr_out,
4273 coff_swap_scnhdr_out,
4282 TRUE, /* _bfd_coff_long_filenames */
4283 XCOFF_NO_LONG_SECTION_NAMES, /* _bfd_coff_long_section_names */
4284 3, /* _bfd_coff_default_section_alignment_power */
4285 FALSE, /* _bfd_coff_force_symnames_in_strings */
4286 2, /* _bfd_coff_debug_string_prefix_length */
4287 coff_swap_filehdr_in,
4288 coff_swap_aouthdr_in,
4289 coff_swap_scnhdr_in,
4290 xcoff_swap_reloc_in,
4291 coff_bad_format_hook,
4292 coff_set_arch_mach_hook,
4295 coff_set_alignment_hook,
4296 coff_slurp_symbol_table,
4297 symname_in_debug_hook,
4298 coff_pointerize_aux_hook,
4300 dummy_reloc16_extra_cases,
4301 dummy_reloc16_estimate,
4302 NULL, /* bfd_coff_sym_is_global */
4303 coff_compute_section_file_positions,
4304 NULL, /* _bfd_coff_start_final_link */
4305 xcoff_ppc_relocate_section,
4306 coff_rtype_to_howto,
4307 NULL, /* _bfd_coff_adjust_symndx */
4308 _bfd_generic_link_add_one_symbol,
4309 coff_link_output_has_begun,
4310 coff_final_link_postscript,
4311 NULL /* print_pdata. */
4314 0x01DF, /* magic number */
4318 /* Function pointers to xcoff specific swap routines. */
4319 xcoff_swap_ldhdr_in,
4320 xcoff_swap_ldhdr_out,
4321 xcoff_swap_ldsym_in,
4322 xcoff_swap_ldsym_out,
4323 xcoff_swap_ldrel_in,
4324 xcoff_swap_ldrel_out,
4330 12, /* _xcoff_function_descriptor_size */
4334 1, /* _xcoff_ldhdr_version */
4336 _bfd_xcoff_put_symbol_name,
4337 _bfd_xcoff_put_ldsymbol_name,
4338 &xcoff_dynamic_reloc,
4339 xcoff_create_csect_from_smclas,
4341 /* Lineno and reloc count overflow. */
4342 xcoff_is_lineno_count_overflow,
4343 xcoff_is_reloc_count_overflow,
4345 xcoff_loader_symbol_offset,
4346 xcoff_loader_reloc_offset,
4349 &xcoff_glink_code[0],
4350 36, /* _xcoff_glink_size */
4353 0, /* _xcoff_rtinit_size */
4354 xcoff_generate_rtinit,
4357 /* The transfer vector that leads the outside world to all of the above. */
4358 const bfd_target pmac_xcoff_vec =
4361 bfd_target_xcoff_flavour,
4362 BFD_ENDIAN_BIG, /* data byte order is big */
4363 BFD_ENDIAN_BIG, /* header byte order is big */
4365 (HAS_RELOC | EXEC_P | HAS_LINENO | HAS_DEBUG | DYNAMIC
4366 | HAS_SYMS | HAS_LOCALS | WP_TEXT),
4368 SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC | SEC_CODE | SEC_DATA,
4369 0, /* leading char */
4370 '/', /* ar_pad_char */
4371 15, /* ar_max_namelen */
4372 0, /* match priority. */
4396 { /* bfd_check_format */
4399 _bfd_xcoff_archive_p,
4403 { /* bfd_set_format */
4406 _bfd_generic_mkarchive,
4410 {/* bfd_write_contents */
4412 coff_write_object_contents,
4413 _bfd_xcoff_write_archive_contents,
4417 BFD_JUMP_TABLE_GENERIC (_bfd_xcoff),
4418 BFD_JUMP_TABLE_COPY (_bfd_xcoff),
4419 BFD_JUMP_TABLE_CORE (coff),
4420 BFD_JUMP_TABLE_ARCHIVE (_bfd_xcoff),
4421 BFD_JUMP_TABLE_SYMBOLS (_bfd_xcoff),
4422 BFD_JUMP_TABLE_RELOCS (_bfd_xcoff),
4423 BFD_JUMP_TABLE_WRITE (coff),
4424 BFD_JUMP_TABLE_LINK (_bfd_xcoff),
4425 BFD_JUMP_TABLE_DYNAMIC (_bfd_xcoff),
4427 /* Opposite endian version, none exists */
4430 & bfd_pmac_xcoff_backend_data,