1 /* BFD back-end for IBM RS/6000 "XCOFF" files.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4 Free Software Foundation, Inc.
5 FIXME: Can someone provide a transliteration of this name into ASCII?
6 Using the following chars caused a compiler warning on HIUX (so I replaced
7 them with octal escapes), and isn't useful without an understanding of what
9 Written by Metin G. Ozisik, Mimi Ph\373\364ng-Th\345o V\365,
11 Archive support from Damon A. Permezel.
12 Contributed by IBM Corporation and Cygnus Support.
14 This file is part of BFD, the Binary File Descriptor library.
16 This program is free software; you can redistribute it and/or modify
17 it under the terms of the GNU General Public License as published by
18 the Free Software Foundation; either version 2 of the License, or
19 (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
33 #include "coff/internal.h"
34 #include "coff/rs6000.h"
36 #define TARGET_NAME "aixcoff-rs6000"
37 #define TARGET_SYM rs6000coff_vec
38 #include "xcoff-target.h"
40 /* The main body of code is in coffcode.h. */
42 static const char *normalize_filename
PARAMS ((bfd
*));
44 /* We use our own tdata type. Its first field is the COFF tdata type,
45 so the COFF routines are compatible. */
48 _bfd_xcoff_mkobject (abfd
)
53 abfd
->tdata
.xcoff_obj_data
=
54 ((struct xcoff_tdata
*)
55 bfd_zalloc (abfd
, sizeof (struct xcoff_tdata
)));
56 if (abfd
->tdata
.xcoff_obj_data
== NULL
)
58 coff
= coff_data (abfd
);
59 coff
->symbols
= (coff_symbol_type
*) NULL
;
60 coff
->conversion_table
= (unsigned int *) NULL
;
61 coff
->raw_syments
= (struct coff_ptr_struct
*) NULL
;
64 xcoff_data (abfd
)->modtype
= ('1' << 8) | 'L';
66 /* We set cputype to -1 to indicate that it has not been
68 xcoff_data (abfd
)->cputype
= -1;
70 xcoff_data (abfd
)->csects
= NULL
;
71 xcoff_data (abfd
)->debug_indices
= NULL
;
76 /* Copy XCOFF data from one BFD to another. */
79 _bfd_xcoff_copy_private_bfd_data (ibfd
, obfd
)
83 struct xcoff_tdata
*ix
, *ox
;
86 if (ibfd
->xvec
!= obfd
->xvec
)
88 ix
= xcoff_data (ibfd
);
89 ox
= xcoff_data (obfd
);
90 ox
->full_aouthdr
= ix
->full_aouthdr
;
96 sec
= coff_section_from_bfd_index (ibfd
, ix
->sntoc
);
100 ox
->sntoc
= sec
->output_section
->target_index
;
102 if (ix
->snentry
== 0)
106 sec
= coff_section_from_bfd_index (ibfd
, ix
->snentry
);
110 ox
->snentry
= sec
->output_section
->target_index
;
112 ox
->text_align_power
= ix
->text_align_power
;
113 ox
->data_align_power
= ix
->data_align_power
;
114 ox
->modtype
= ix
->modtype
;
115 ox
->cputype
= ix
->cputype
;
116 ox
->maxdata
= ix
->maxdata
;
117 ox
->maxstack
= ix
->maxstack
;
121 /* I don't think XCOFF really has a notion of local labels based on
122 name. This will mean that ld -X doesn't actually strip anything.
123 The AIX native linker does not have a -X option, and it ignores the
127 _bfd_xcoff_is_local_label_name (abfd
, name
)
128 bfd
*abfd ATTRIBUTE_UNUSED
;
129 const char *name ATTRIBUTE_UNUSED
;
135 _bfd_xcoff_swap_sym_in (abfd
, ext1
, in1
)
140 SYMENT
*ext
= (SYMENT
*)ext1
;
141 struct internal_syment
*in
= (struct internal_syment
*)in1
;
143 if (ext
->e
.e_name
[0] != 0)
145 memcpy(in
->_n
._n_name
, ext
->e
.e_name
, SYMNMLEN
);
149 in
->_n
._n_n
._n_zeroes
= 0;
150 in
->_n
._n_n
._n_offset
=
151 bfd_h_get_32(abfd
, (bfd_byte
*) ext
->e
.e
.e_offset
);
154 in
->n_value
= bfd_h_get_32(abfd
, (bfd_byte
*) ext
->e_value
);
155 in
->n_scnum
= bfd_h_get_16(abfd
, (bfd_byte
*) ext
->e_scnum
);
156 in
->n_type
= bfd_h_get_16(abfd
, (bfd_byte
*) ext
->e_type
);
157 in
->n_sclass
= bfd_h_get_8(abfd
, ext
->e_sclass
);
158 in
->n_numaux
= bfd_h_get_8(abfd
, ext
->e_numaux
);
162 _bfd_xcoff_swap_sym_out (abfd
, inp
, extp
)
167 struct internal_syment
*in
= (struct internal_syment
*)inp
;
168 SYMENT
*ext
=(SYMENT
*)extp
;
170 if (in
->_n
._n_name
[0] != 0)
172 memcpy(ext
->e
.e_name
, in
->_n
._n_name
, SYMNMLEN
);
176 bfd_h_put_32(abfd
, 0, (bfd_byte
*) ext
->e
.e
.e_zeroes
);
177 bfd_h_put_32(abfd
, in
->_n
._n_n
._n_offset
,
178 (bfd_byte
*) ext
->e
.e
.e_offset
);
181 bfd_h_put_32(abfd
, in
->n_value
, (bfd_byte
*) ext
->e_value
);
182 bfd_h_put_16(abfd
, in
->n_scnum
, (bfd_byte
*) ext
->e_scnum
);
183 bfd_h_put_16(abfd
, in
->n_type
, (bfd_byte
*) ext
->e_type
);
184 bfd_h_put_8(abfd
, in
->n_sclass
, ext
->e_sclass
);
185 bfd_h_put_8(abfd
, in
->n_numaux
, ext
->e_numaux
);
186 return bfd_coff_symesz (abfd
);
189 #define PUTWORD bfd_h_put_32
190 #define PUTHALF bfd_h_put_16
191 #define PUTBYTE bfd_h_put_8
192 #define GETWORD bfd_h_get_32
193 #define GETHALF bfd_h_get_16
194 #define GETBYTE bfd_h_get_8
197 _bfd_xcoff_swap_aux_in (abfd
, ext1
, type
, class, indx
, numaux
, in1
)
206 AUXENT
*ext
= (AUXENT
*)ext1
;
207 union internal_auxent
*in
= (union internal_auxent
*)in1
;
211 if (ext
->x_file
.x_fname
[0] == 0) {
212 in
->x_file
.x_n
.x_zeroes
= 0;
213 in
->x_file
.x_n
.x_offset
=
214 bfd_h_get_32(abfd
, (bfd_byte
*) ext
->x_file
.x_n
.x_offset
);
219 memcpy (in
->x_file
.x_fname
, ext
->x_file
.x_fname
,
220 numaux
* sizeof (AUXENT
));
224 memcpy (in
->x_file
.x_fname
, ext
->x_file
.x_fname
, FILNMLEN
);
229 /* RS/6000 "csect" auxents */
232 if (indx
+ 1 == numaux
)
234 in
->x_csect
.x_scnlen
.l
=
235 bfd_h_get_32 (abfd
, ext
->x_csect
.x_scnlen
);
236 in
->x_csect
.x_parmhash
= bfd_h_get_32 (abfd
,
237 ext
->x_csect
.x_parmhash
);
238 in
->x_csect
.x_snhash
= bfd_h_get_16 (abfd
, ext
->x_csect
.x_snhash
);
239 /* We don't have to hack bitfields in x_smtyp because it's
240 defined by shifts-and-ands, which are equivalent on all
242 in
->x_csect
.x_smtyp
= bfd_h_get_8 (abfd
, ext
->x_csect
.x_smtyp
);
243 in
->x_csect
.x_smclas
= bfd_h_get_8 (abfd
, ext
->x_csect
.x_smclas
);
244 in
->x_csect
.x_stab
= bfd_h_get_32 (abfd
, ext
->x_csect
.x_stab
);
245 in
->x_csect
.x_snstab
= bfd_h_get_16 (abfd
, ext
->x_csect
.x_snstab
);
253 if (type
== T_NULL
) {
254 in
->x_scn
.x_scnlen
= bfd_h_get_32(abfd
,
255 (bfd_byte
*) ext
->x_scn
.x_scnlen
);
256 in
->x_scn
.x_nreloc
= bfd_h_get_16(abfd
,
257 (bfd_byte
*) ext
->x_scn
.x_nreloc
);
258 in
->x_scn
.x_nlinno
= bfd_h_get_16(abfd
,
259 (bfd_byte
*) ext
->x_scn
.x_nlinno
);
260 /* PE defines some extra fields; we zero them out for
262 in
->x_scn
.x_checksum
= 0;
263 in
->x_scn
.x_associated
= 0;
264 in
->x_scn
.x_comdat
= 0;
271 in
->x_sym
.x_tagndx
.l
= bfd_h_get_32(abfd
, (bfd_byte
*) ext
->x_sym
.x_tagndx
);
272 in
->x_sym
.x_tvndx
= bfd_h_get_16(abfd
, (bfd_byte
*) ext
->x_sym
.x_tvndx
);
274 if (class == C_BLOCK
|| class == C_FCN
|| ISFCN (type
) || ISTAG (class))
276 in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
= bfd_h_get_32(abfd
, (bfd_byte
*)
277 ext
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
278 in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
= bfd_h_get_32(abfd
, (bfd_byte
*)
279 ext
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
283 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0] =
284 bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
285 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1] =
286 bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
287 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2] =
288 bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
289 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3] =
290 bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
293 in
->x_sym
.x_misc
.x_fsize
= bfd_h_get_32(abfd
, (bfd_byte
*) ext
->x_sym
.x_misc
.x_fsize
);
296 in
->x_sym
.x_misc
.x_lnsz
.x_lnno
= bfd_h_get_16(abfd
, (bfd_byte
*)
297 ext
->x_sym
.x_misc
.x_lnsz
.x_lnno
);
298 in
->x_sym
.x_misc
.x_lnsz
.x_size
= bfd_h_get_16(abfd
, (bfd_byte
*)
299 ext
->x_sym
.x_misc
.x_lnsz
.x_size
);
303 /* the semicolon is because MSVC doesn't like labels at
309 _bfd_xcoff_swap_aux_out (abfd
, inp
, type
, class, indx
, numaux
, extp
)
314 int indx ATTRIBUTE_UNUSED
;
315 int numaux ATTRIBUTE_UNUSED
;
318 union internal_auxent
*in
= (union internal_auxent
*)inp
;
319 AUXENT
*ext
= (AUXENT
*)extp
;
321 memset((PTR
)ext
, 0, bfd_coff_auxesz (abfd
));
325 if (in
->x_file
.x_fname
[0] == 0)
327 PUTWORD(abfd
, 0, (bfd_byte
*) ext
->x_file
.x_n
.x_zeroes
);
329 in
->x_file
.x_n
.x_offset
,
330 (bfd_byte
*) ext
->x_file
.x_n
.x_offset
);
334 memcpy (ext
->x_file
.x_fname
, in
->x_file
.x_fname
, FILNMLEN
);
338 /* RS/6000 "csect" auxents */
341 if (indx
+ 1 == numaux
)
343 PUTWORD (abfd
, in
->x_csect
.x_scnlen
.l
,ext
->x_csect
.x_scnlen
);
344 PUTWORD (abfd
, in
->x_csect
.x_parmhash
, ext
->x_csect
.x_parmhash
);
345 PUTHALF (abfd
, in
->x_csect
.x_snhash
, ext
->x_csect
.x_snhash
);
346 /* We don't have to hack bitfields in x_smtyp because it's
347 defined by shifts-and-ands, which are equivalent on all
349 PUTBYTE (abfd
, in
->x_csect
.x_smtyp
, ext
->x_csect
.x_smtyp
);
350 PUTBYTE (abfd
, in
->x_csect
.x_smclas
, ext
->x_csect
.x_smclas
);
351 PUTWORD (abfd
, in
->x_csect
.x_stab
, ext
->x_csect
.x_stab
);
352 PUTHALF (abfd
, in
->x_csect
.x_snstab
, ext
->x_csect
.x_snstab
);
360 if (type
== T_NULL
) {
361 bfd_h_put_32(abfd
, in
->x_scn
.x_scnlen
, (bfd_byte
*) ext
->x_scn
.x_scnlen
);
362 bfd_h_put_16(abfd
, in
->x_scn
.x_nreloc
, (bfd_byte
*) ext
->x_scn
.x_nreloc
);
363 bfd_h_put_16(abfd
, in
->x_scn
.x_nlinno
, (bfd_byte
*) ext
->x_scn
.x_nlinno
);
369 PUTWORD(abfd
, in
->x_sym
.x_tagndx
.l
, (bfd_byte
*) ext
->x_sym
.x_tagndx
);
370 bfd_h_put_16 (abfd
, in
->x_sym
.x_tvndx
, (bfd_byte
*) ext
->x_sym
.x_tvndx
);
372 if (class == C_BLOCK
|| class == C_FCN
|| ISFCN (type
) || ISTAG (class))
374 bfd_h_put_32(abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
,
375 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
376 PUTWORD(abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
,
377 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
381 bfd_h_put_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0],
382 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
383 bfd_h_put_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1],
384 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
385 bfd_h_put_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2],
386 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
387 bfd_h_put_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3],
388 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
392 PUTWORD (abfd
, in
->x_sym
.x_misc
.x_fsize
,
393 (bfd_byte
*) ext
->x_sym
.x_misc
.x_fsize
);
396 bfd_h_put_16(abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_lnno
,
397 (bfd_byte
*)ext
->x_sym
.x_misc
.x_lnsz
.x_lnno
);
398 bfd_h_put_16(abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_size
,
399 (bfd_byte
*)ext
->x_sym
.x_misc
.x_lnsz
.x_size
);
403 return bfd_coff_auxesz (abfd
);
406 /* The XCOFF reloc table. Actually, XCOFF relocations specify the
407 bitsize and whether they are signed or not, along with a
408 conventional type. This table is for the types, which are used for
409 different algorithms for putting in the reloc. Many of these
410 relocs need special_function entries, which I have not written. */
412 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
413 from smaller values. Start with zero, widen, *then* decrement. */
414 #define MINUS_ONE (((bfd_vma)0) - 1)
416 reloc_howto_type xcoff_howto_table
[] =
418 /* Standard 32 bit relocation. */
421 2, /* size (0 = byte, 1 = short, 2 = long) */
423 false, /* pc_relative */
425 complain_overflow_bitfield
, /* complain_on_overflow */
426 0, /* special_function */
428 true, /* partial_inplace */
429 0xffffffff, /* src_mask */
430 0xffffffff, /* dst_mask */
431 false), /* pcrel_offset */
433 /* 32 bit relocation, but store negative value. */
436 -2, /* size (0 = byte, 1 = short, 2 = long) */
438 false, /* pc_relative */
440 complain_overflow_bitfield
, /* complain_on_overflow */
441 0, /* special_function */
443 true, /* partial_inplace */
444 0xffffffff, /* src_mask */
445 0xffffffff, /* dst_mask */
446 false), /* pcrel_offset */
448 /* 32 bit PC relative relocation. */
451 2, /* size (0 = byte, 1 = short, 2 = long) */
453 true, /* pc_relative */
455 complain_overflow_signed
, /* complain_on_overflow */
456 0, /* special_function */
458 true, /* partial_inplace */
459 0xffffffff, /* src_mask */
460 0xffffffff, /* dst_mask */
461 false), /* pcrel_offset */
463 /* 16 bit TOC relative relocation. */
466 1, /* size (0 = byte, 1 = short, 2 = long) */
468 false, /* pc_relative */
470 complain_overflow_bitfield
, /* complain_on_overflow */
471 0, /* special_function */
473 true, /* partial_inplace */
474 0xffff, /* src_mask */
475 0xffff, /* dst_mask */
476 false), /* pcrel_offset */
478 /* I don't really know what this is. */
481 2, /* size (0 = byte, 1 = short, 2 = long) */
483 false, /* pc_relative */
485 complain_overflow_bitfield
, /* complain_on_overflow */
486 0, /* special_function */
488 true, /* partial_inplace */
489 0xffffffff, /* src_mask */
490 0xffffffff, /* dst_mask */
491 false), /* pcrel_offset */
493 /* External TOC relative symbol. */
496 2, /* size (0 = byte, 1 = short, 2 = long) */
498 false, /* pc_relative */
500 complain_overflow_bitfield
, /* complain_on_overflow */
501 0, /* special_function */
503 true, /* partial_inplace */
504 0xffff, /* src_mask */
505 0xffff, /* dst_mask */
506 false), /* pcrel_offset */
508 /* Local TOC relative symbol. */
511 2, /* size (0 = byte, 1 = short, 2 = long) */
513 false, /* pc_relative */
515 complain_overflow_bitfield
, /* complain_on_overflow */
516 0, /* special_function */
518 true, /* partial_inplace */
519 0xffff, /* src_mask */
520 0xffff, /* dst_mask */
521 false), /* pcrel_offset */
525 /* Non modifiable absolute branch. */
528 2, /* size (0 = byte, 1 = short, 2 = long) */
530 false, /* pc_relative */
532 complain_overflow_bitfield
, /* complain_on_overflow */
533 0, /* special_function */
535 true, /* partial_inplace */
536 0x3fffffc, /* src_mask */
537 0x3fffffc, /* dst_mask */
538 false), /* pcrel_offset */
542 /* Non modifiable relative branch. */
543 HOWTO (0xa, /* type */
545 2, /* size (0 = byte, 1 = short, 2 = long) */
547 true, /* pc_relative */
549 complain_overflow_signed
, /* complain_on_overflow */
550 0, /* special_function */
552 true, /* partial_inplace */
553 0x3fffffc, /* src_mask */
554 0x3fffffc, /* dst_mask */
555 false), /* pcrel_offset */
560 HOWTO (0xc, /* type */
562 2, /* size (0 = byte, 1 = short, 2 = long) */
564 false, /* pc_relative */
566 complain_overflow_bitfield
, /* complain_on_overflow */
567 0, /* special_function */
569 true, /* partial_inplace */
570 0xffff, /* src_mask */
571 0xffff, /* dst_mask */
572 false), /* pcrel_offset */
575 HOWTO (0xd, /* type */
577 2, /* size (0 = byte, 1 = short, 2 = long) */
579 false, /* pc_relative */
581 complain_overflow_bitfield
, /* complain_on_overflow */
582 0, /* special_function */
584 true, /* partial_inplace */
585 0xffff, /* src_mask */
586 0xffff, /* dst_mask */
587 false), /* pcrel_offset */
591 /* Non-relocating reference. */
592 HOWTO (0xf, /* type */
594 2, /* size (0 = byte, 1 = short, 2 = long) */
596 false, /* pc_relative */
598 complain_overflow_bitfield
, /* complain_on_overflow */
599 0, /* special_function */
601 false, /* partial_inplace */
604 false), /* pcrel_offset */
609 /* TOC relative indirect load. */
610 HOWTO (0x12, /* type */
612 2, /* size (0 = byte, 1 = short, 2 = long) */
614 false, /* pc_relative */
616 complain_overflow_bitfield
, /* complain_on_overflow */
617 0, /* special_function */
619 true, /* partial_inplace */
620 0xffff, /* src_mask */
621 0xffff, /* dst_mask */
622 false), /* pcrel_offset */
624 /* TOC relative load address. */
625 HOWTO (0x13, /* type */
627 2, /* size (0 = byte, 1 = short, 2 = long) */
629 false, /* pc_relative */
631 complain_overflow_bitfield
, /* complain_on_overflow */
632 0, /* special_function */
634 true, /* partial_inplace */
635 0xffff, /* src_mask */
636 0xffff, /* dst_mask */
637 false), /* pcrel_offset */
639 /* Modifiable relative branch. */
640 HOWTO (0x14, /* type */
642 2, /* size (0 = byte, 1 = short, 2 = long) */
644 false, /* pc_relative */
646 complain_overflow_bitfield
, /* complain_on_overflow */
647 0, /* special_function */
648 "R_RRTBI", /* name */
649 true, /* partial_inplace */
650 0xffffffff, /* src_mask */
651 0xffffffff, /* dst_mask */
652 false), /* pcrel_offset */
654 /* Modifiable absolute branch. */
655 HOWTO (0x15, /* type */
657 2, /* size (0 = byte, 1 = short, 2 = long) */
659 false, /* pc_relative */
661 complain_overflow_bitfield
, /* complain_on_overflow */
662 0, /* special_function */
663 "R_RRTBA", /* name */
664 true, /* partial_inplace */
665 0xffffffff, /* src_mask */
666 0xffffffff, /* dst_mask */
667 false), /* pcrel_offset */
669 /* Modifiable call absolute indirect. */
670 HOWTO (0x16, /* type */
672 2, /* size (0 = byte, 1 = short, 2 = long) */
674 false, /* pc_relative */
676 complain_overflow_bitfield
, /* complain_on_overflow */
677 0, /* special_function */
679 true, /* partial_inplace */
680 0xffff, /* src_mask */
681 0xffff, /* dst_mask */
682 false), /* pcrel_offset */
684 /* Modifiable call relative. */
685 HOWTO (0x17, /* type */
687 2, /* size (0 = byte, 1 = short, 2 = long) */
689 false, /* pc_relative */
691 complain_overflow_bitfield
, /* complain_on_overflow */
692 0, /* special_function */
694 true, /* partial_inplace */
695 0xffff, /* src_mask */
696 0xffff, /* dst_mask */
697 false), /* pcrel_offset */
699 /* Modifiable branch absolute. */
700 HOWTO (0x18, /* type */
702 2, /* size (0 = byte, 1 = short, 2 = long) */
704 false, /* pc_relative */
706 complain_overflow_bitfield
, /* complain_on_overflow */
707 0, /* special_function */
709 true, /* partial_inplace */
710 0xffff, /* src_mask */
711 0xffff, /* dst_mask */
712 false), /* pcrel_offset */
714 /* Modifiable branch absolute. */
715 HOWTO (0x19, /* type */
717 2, /* size (0 = byte, 1 = short, 2 = long) */
719 false, /* pc_relative */
721 complain_overflow_bitfield
, /* complain_on_overflow */
722 0, /* special_function */
724 true, /* partial_inplace */
725 0xffff, /* src_mask */
726 0xffff, /* dst_mask */
727 false), /* pcrel_offset */
729 /* Modifiable branch relative. */
730 HOWTO (0x1a, /* type */
732 2, /* size (0 = byte, 1 = short, 2 = long) */
734 false, /* pc_relative */
736 complain_overflow_signed
, /* complain_on_overflow */
737 0, /* special_function */
739 true, /* partial_inplace */
740 0xffff, /* src_mask */
741 0xffff, /* dst_mask */
742 false), /* pcrel_offset */
744 /* Modifiable branch absolute. */
745 HOWTO (0x1b, /* 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 0xffff, /* src_mask */
756 0xffff, /* dst_mask */
757 false), /* pcrel_offset */
760 4, /* size (0 = byte, 1 = short, 2 = long) */
762 false, /* pc_relative */
764 complain_overflow_bitfield
, /* complain_on_overflow */
765 0, /* special_function */
767 true, /* partial_inplace */
768 MINUS_ONE
, /* src_mask */
769 MINUS_ONE
, /* dst_mask */
770 false) /* pcrel_offset */
774 /* These are the first two like the above but for 16-bit relocs. */
775 static reloc_howto_type xcoff_howto_table_16
[] =
777 /* Standard 16 bit relocation. */
780 2, /* size (0 = byte, 1 = short, 2 = long) */
782 false, /* pc_relative */
784 complain_overflow_bitfield
, /* complain_on_overflow */
785 0, /* special_function */
786 "R_POS_16", /* name */
787 true, /* partial_inplace */
788 0xffffffff, /* src_mask */
789 0xffffffff, /* dst_mask */
790 false), /* pcrel_offset */
792 /* 16 bit relocation, but store negative value. */
795 -2, /* size (0 = byte, 1 = short, 2 = long) */
797 false, /* pc_relative */
799 complain_overflow_bitfield
, /* complain_on_overflow */
800 0, /* special_function */
801 "R_NEG_16", /* name */
802 true, /* partial_inplace */
803 0xffffffff, /* src_mask */
804 0xffffffff, /* dst_mask */
805 false), /* pcrel_offset */
807 /* 16 bit PC relative relocation. */
810 2, /* size (0 = byte, 1 = short, 2 = long) */
812 true, /* pc_relative */
814 complain_overflow_signed
, /* complain_on_overflow */
815 0, /* special_function */
816 "R_REL_16", /* name */
817 true, /* partial_inplace */
818 0xffffffff, /* src_mask */
819 0xffffffff, /* dst_mask */
820 false) /* pcrel_offset */
824 _bfd_xcoff_rtype2howto (relent
, internal
)
826 struct internal_reloc
*internal
;
828 relent
->howto
= xcoff_howto_table
+ internal
->r_type
;
830 if (relent
->howto
->bitsize
!= ((unsigned int) internal
->r_size
& 0x1f) + 1
832 < sizeof (xcoff_howto_table_16
)/sizeof (xcoff_howto_table_16
[0])))
833 relent
->howto
= xcoff_howto_table_16
+ internal
->r_type
;
835 /* The r_size field of an XCOFF reloc encodes the bitsize of the
836 relocation, as well as indicating whether it is signed or not.
837 Doublecheck that the relocation information gathered from the
838 type matches this information. The bitsize is not significant
840 if (relent
->howto
->dst_mask
!= 0
841 && (relent
->howto
->bitsize
842 != ((unsigned int) internal
->r_size
& 0x3f) + 1))
845 if ((internal
->r_size
& 0x80) != 0
846 ? (relent
->howto
->complain_on_overflow
!= complain_overflow_signed
)
847 : (relent
->howto
->complain_on_overflow
!= complain_overflow_bitfield
))
853 _bfd_xcoff_reloc_type_lookup (abfd
, code
)
854 bfd
*abfd ATTRIBUTE_UNUSED
;
855 bfd_reloc_code_real_type code
;
859 case BFD_RELOC_PPC_B26
:
860 return &xcoff_howto_table
[0xa];
861 case BFD_RELOC_PPC_BA26
:
862 return &xcoff_howto_table
[8];
863 case BFD_RELOC_PPC_TOC16
:
864 return &xcoff_howto_table
[3];
867 return &xcoff_howto_table
[0];
869 return &xcoff_howto_table
[0x1c];
875 /* XCOFF archive support. The original version of this code was by
876 Damon A. Permezel. It was enhanced to permit cross support, and
877 writing archive files, by Ian Lance Taylor, Cygnus Support.
879 XCOFF uses its own archive format. Everything is hooked together
880 with file offset links, so it is possible to rapidly update an
881 archive in place. Of course, we don't do that. An XCOFF archive
882 has a real file header, not just an ARMAG string. The structure of
883 the file header and of each archive header appear below.
885 An XCOFF archive also has a member table, which is a list of
886 elements in the archive (you can get that by looking through the
887 linked list, but you have to read a lot more of the file). The
888 member table has a normal archive header with an empty name. It is
889 normally (and perhaps must be) the second to last entry in the
890 archive. The member table data is almost printable ASCII. It
891 starts with a 12 character decimal string which is the number of
892 entries in the table. For each entry it has a 12 character decimal
893 string which is the offset in the archive of that member. These
894 entries are followed by a series of null terminated strings which
895 are the member names for each entry.
897 Finally, an XCOFF archive has a global symbol table, which is what
898 we call the armap. The global symbol table has a normal archive
899 header with an empty name. It is normally (and perhaps must be)
900 the last entry in the archive. The contents start with a four byte
901 binary number which is the number of entries. This is followed by
902 a that many four byte binary numbers; each is the file offset of an
903 entry in the archive. These numbers are followed by a series of
904 null terminated strings, which are symbol names.
906 AIX 4.3 introduced a new archive format which can handle larger
907 files and also 32- and 64-bit objects in the same archive. The
908 things said above remain true except that there is now more than
909 one global symbol table. The one is used to index 32-bit objects,
910 the other for 64-bit objects.
912 The new archives (recognizable by the new ARMAG string) has larger
913 field lengths so that we cannot really share any code. Also we have
914 to take care that we are not generating the new form of archives
915 on AIX 4.2 or earlier systems. */
917 /* XCOFF archives use this as a magic string. Note that both strings
918 have the same length. */
920 #define XCOFFARMAG "<aiaff>\012"
921 #define XCOFFARMAGBIG "<bigaf>\012"
922 #define SXCOFFARMAG 8
924 /* This terminates an XCOFF archive member name. */
926 #define XCOFFARFMAG "`\012"
927 #define SXCOFFARFMAG 2
929 /* XCOFF archives start with this (printable) structure. */
931 struct xcoff_ar_file_hdr
934 char magic
[SXCOFFARMAG
];
936 /* Offset of the member table (decimal ASCII string). */
939 /* Offset of the global symbol table (decimal ASCII string). */
942 /* Offset of the first member in the archive (decimal ASCII string). */
943 char firstmemoff
[12];
945 /* Offset of the last member in the archive (decimal ASCII string). */
948 /* Offset of the first member on the free list (decimal ASCII
953 #define SIZEOF_AR_FILE_HDR (5 * 12 + SXCOFFARMAG)
955 /* This is the equivalent data structure for the big archive format. */
957 struct xcoff_ar_file_hdr_big
960 char magic
[SXCOFFARMAG
];
962 /* Offset of the member table (decimal ASCII string). */
965 /* Offset of the global symbol table for 32-bit objects (decimal ASCII
969 /* Offset of the global symbol table for 64-bit objects (decimal ASCII
973 /* Offset of the first member in the archive (decimal ASCII string). */
974 char firstmemoff
[20];
976 /* Offset of the last member in the archive (decimal ASCII string). */
979 /* Offset of the first member on the free list (decimal ASCII
984 #define SIZEOF_AR_FILE_HDR_BIG (6 * 20 + SXCOFFARMAG)
986 /* Each XCOFF archive member starts with this (printable) structure. */
990 /* File size not including the header (decimal ASCII string). */
993 /* File offset of next archive member (decimal ASCII string). */
996 /* File offset of previous archive member (decimal ASCII string). */
999 /* File mtime (decimal ASCII string). */
1002 /* File UID (decimal ASCII string). */
1005 /* File GID (decimal ASCII string). */
1008 /* File mode (octal ASCII string). */
1011 /* Length of file name (decimal ASCII string). */
1014 /* This structure is followed by the file name. The length of the
1015 name is given in the namlen field. If the length of the name is
1016 odd, the name is followed by a null byte. The name and optional
1017 null byte are followed by XCOFFARFMAG, which is not included in
1018 namlen. The contents of the archive member follow; the number of
1019 bytes is given in the size field. */
1022 #define SIZEOF_AR_HDR (7 * 12 + 4)
1024 /* The equivalent for the big archive format. */
1026 struct xcoff_ar_hdr_big
1028 /* File size not including the header (decimal ASCII string). */
1031 /* File offset of next archive member (decimal ASCII string). */
1034 /* File offset of previous archive member (decimal ASCII string). */
1037 /* File mtime (decimal ASCII string). */
1040 /* File UID (decimal ASCII string). */
1043 /* File GID (decimal ASCII string). */
1046 /* File mode (octal ASCII string). */
1049 /* Length of file name (decimal ASCII string). */
1052 /* This structure is followed by the file name. The length of the
1053 name is given in the namlen field. If the length of the name is
1054 odd, the name is followed by a null byte. The name and optional
1055 null byte are followed by XCOFFARFMAG, which is not included in
1056 namlen. The contents of the archive member follow; the number of
1057 bytes is given in the size field. */
1060 #define SIZEOF_AR_HDR_BIG (3 * 20 + 4 * 12 + 4)
1062 /* We often have to distinguish between the old and big file format.
1063 Make it a bit cleaner. We can use `xcoff_ardata' here because the
1064 `hdr' member has the same size and position in both formats. */
1065 #define xcoff_big_format_p(abfd) \
1066 (xcoff_ardata (abfd)->magic[1] == 'b')
1068 /* We store a copy of the xcoff_ar_file_hdr in the tdata field of the
1069 artdata structure. Similar for the big archive. */
1070 #define xcoff_ardata(abfd) \
1071 ((struct xcoff_ar_file_hdr *) bfd_ardata (abfd)->tdata)
1072 #define xcoff_ardata_big(abfd) \
1073 ((struct xcoff_ar_file_hdr_big *) bfd_ardata (abfd)->tdata)
1075 /* We store a copy of the xcoff_ar_hdr in the arelt_data field of an
1076 archive element. Similar for the big archive. */
1077 #define arch_eltdata(bfd) ((struct areltdata *) ((bfd)->arelt_data))
1078 #define arch_xhdr(bfd) \
1079 ((struct xcoff_ar_hdr *) arch_eltdata (bfd)->arch_header)
1080 #define arch_xhdr_big(bfd) \
1081 ((struct xcoff_ar_hdr_big *) arch_eltdata (bfd)->arch_header)
1083 /* Read in the armap of an XCOFF archive. */
1086 _bfd_xcoff_slurp_armap (abfd
)
1092 bfd_byte
*contents
, *cend
;
1097 if (xcoff_ardata (abfd
) == NULL
)
1099 bfd_has_map (abfd
) = false;
1103 if (! xcoff_big_format_p (abfd
))
1105 /* This is for the old format. */
1106 struct xcoff_ar_hdr hdr
;
1108 off
= strtol (xcoff_ardata (abfd
)->symoff
, (char **) NULL
, 10);
1111 bfd_has_map (abfd
) = false;
1115 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0)
1118 /* The symbol table starts with a normal archive header. */
1119 if (bfd_read ((PTR
) &hdr
, SIZEOF_AR_HDR
, 1, abfd
) != SIZEOF_AR_HDR
)
1122 /* Skip the name (normally empty). */
1123 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1124 if (bfd_seek (abfd
, ((namlen
+ 1) & ~1) + SXCOFFARFMAG
, SEEK_CUR
) != 0)
1127 sz
= strtol (hdr
.size
, (char **) NULL
, 10);
1129 /* Read in the entire symbol table. */
1130 contents
= (bfd_byte
*) bfd_alloc (abfd
, sz
);
1131 if (contents
== NULL
)
1133 if (bfd_read ((PTR
) contents
, 1, sz
, abfd
) != sz
)
1136 /* The symbol table starts with a four byte count. */
1137 c
= bfd_h_get_32 (abfd
, contents
);
1141 bfd_set_error (bfd_error_bad_value
);
1145 bfd_ardata (abfd
)->symdefs
= ((carsym
*)
1146 bfd_alloc (abfd
, c
* sizeof (carsym
)));
1147 if (bfd_ardata (abfd
)->symdefs
== NULL
)
1150 /* After the count comes a list of four byte file offsets. */
1151 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
, p
= contents
+ 4;
1153 ++i
, ++arsym
, p
+= 4)
1154 arsym
->file_offset
= bfd_h_get_32 (abfd
, p
);
1158 /* This is for the new format. */
1159 struct xcoff_ar_hdr_big hdr
;
1161 off
= strtol (xcoff_ardata_big (abfd
)->symoff
, (char **) NULL
, 10);
1164 bfd_has_map (abfd
) = false;
1168 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0)
1171 /* The symbol table starts with a normal archive header. */
1172 if (bfd_read ((PTR
) &hdr
, SIZEOF_AR_HDR_BIG
, 1, abfd
)
1173 != SIZEOF_AR_HDR_BIG
)
1176 /* Skip the name (normally empty). */
1177 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1178 if (bfd_seek (abfd
, ((namlen
+ 1) & ~1) + SXCOFFARFMAG
, SEEK_CUR
) != 0)
1181 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1182 machines) since the field width is 20 and there numbers with more
1183 than 32 bits can be represented. */
1184 sz
= strtol (hdr
.size
, (char **) NULL
, 10);
1186 /* Read in the entire symbol table. */
1187 contents
= (bfd_byte
*) bfd_alloc (abfd
, sz
);
1188 if (contents
== NULL
)
1190 if (bfd_read ((PTR
) contents
, 1, sz
, abfd
) != sz
)
1193 /* The symbol table starts with an eight byte count. */
1194 c
= bfd_h_get_64 (abfd
, contents
);
1198 bfd_set_error (bfd_error_bad_value
);
1202 bfd_ardata (abfd
)->symdefs
= ((carsym
*)
1203 bfd_alloc (abfd
, c
* sizeof (carsym
)));
1204 if (bfd_ardata (abfd
)->symdefs
== NULL
)
1207 /* After the count comes a list of eight byte file offsets. */
1208 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
, p
= contents
+ 8;
1210 ++i
, ++arsym
, p
+= 8)
1211 arsym
->file_offset
= bfd_h_get_64 (abfd
, p
);
1214 /* After the file offsets come null terminated symbol names. */
1215 cend
= contents
+ sz
;
1216 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
;
1218 ++i
, ++arsym
, p
+= strlen ((char *) p
) + 1)
1222 bfd_set_error (bfd_error_bad_value
);
1225 arsym
->name
= (char *) p
;
1228 bfd_ardata (abfd
)->symdef_count
= c
;
1229 bfd_has_map (abfd
) = true;
1234 /* See if this is an XCOFF archive. */
1237 _bfd_xcoff_archive_p (abfd
)
1240 char magic
[SXCOFFARMAG
];
1242 if (bfd_read ((PTR
) magic
, SXCOFFARMAG
, 1, abfd
) != SXCOFFARMAG
)
1244 if (bfd_get_error () != bfd_error_system_call
)
1245 bfd_set_error (bfd_error_wrong_format
);
1249 if (strncmp (magic
, XCOFFARMAG
, SXCOFFARMAG
) != 0
1250 && strncmp (magic
, XCOFFARMAGBIG
, SXCOFFARMAG
) != 0)
1252 bfd_set_error (bfd_error_wrong_format
);
1256 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
1257 involves a cast, we can't do it as the left operand of
1259 abfd
->tdata
.aout_ar_data
=
1260 (struct artdata
*) bfd_zalloc (abfd
, sizeof (struct artdata
));
1262 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
1265 bfd_ardata (abfd
)->cache
= NULL
;
1266 bfd_ardata (abfd
)->archive_head
= NULL
;
1267 bfd_ardata (abfd
)->symdefs
= NULL
;
1268 bfd_ardata (abfd
)->extended_names
= NULL
;
1270 /* Now handle the two formats. */
1271 if (magic
[1] != 'b')
1273 /* This is the old format. */
1274 struct xcoff_ar_file_hdr hdr
;
1276 /* Copy over the magic string. */
1277 memcpy (hdr
.magic
, magic
, SXCOFFARMAG
);
1279 /* Now read the rest of the file header. */
1280 if (bfd_read ((PTR
) &hdr
.memoff
, SIZEOF_AR_FILE_HDR
- SXCOFFARMAG
, 1,
1281 abfd
) != SIZEOF_AR_FILE_HDR
- SXCOFFARMAG
)
1283 if (bfd_get_error () != bfd_error_system_call
)
1284 bfd_set_error (bfd_error_wrong_format
);
1288 bfd_ardata (abfd
)->first_file_filepos
= strtol (hdr
.firstmemoff
,
1289 (char **) NULL
, 10);
1291 bfd_ardata (abfd
)->tdata
= bfd_zalloc (abfd
, SIZEOF_AR_FILE_HDR
);
1292 if (bfd_ardata (abfd
)->tdata
== NULL
)
1295 memcpy (bfd_ardata (abfd
)->tdata
, &hdr
, SIZEOF_AR_FILE_HDR
);
1299 /* This is the new format. */
1300 struct xcoff_ar_file_hdr_big hdr
;
1302 /* Copy over the magic string. */
1303 memcpy (hdr
.magic
, magic
, SXCOFFARMAG
);
1305 /* Now read the rest of the file header. */
1306 if (bfd_read ((PTR
) &hdr
.memoff
, SIZEOF_AR_FILE_HDR_BIG
- SXCOFFARMAG
, 1,
1307 abfd
) != SIZEOF_AR_FILE_HDR_BIG
- SXCOFFARMAG
)
1309 if (bfd_get_error () != bfd_error_system_call
)
1310 bfd_set_error (bfd_error_wrong_format
);
1314 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1315 machines) since the field width is 20 and there numbers with more
1316 than 32 bits can be represented. */
1317 bfd_ardata (abfd
)->first_file_filepos
= strtol (hdr
.firstmemoff
,
1318 (char **) NULL
, 10);
1320 bfd_ardata (abfd
)->tdata
= bfd_zalloc (abfd
, SIZEOF_AR_FILE_HDR_BIG
);
1321 if (bfd_ardata (abfd
)->tdata
== NULL
)
1324 memcpy (bfd_ardata (abfd
)->tdata
, &hdr
, SIZEOF_AR_FILE_HDR_BIG
);
1327 if (! _bfd_xcoff_slurp_armap (abfd
))
1329 bfd_release (abfd
, bfd_ardata (abfd
));
1330 abfd
->tdata
.aout_ar_data
= (struct artdata
*) NULL
;
1337 /* Read the archive header in an XCOFF archive. */
1340 _bfd_xcoff_read_ar_hdr (abfd
)
1344 struct areltdata
*ret
;
1346 ret
= (struct areltdata
*) bfd_alloc (abfd
, sizeof (struct areltdata
));
1350 if (! xcoff_big_format_p (abfd
))
1352 struct xcoff_ar_hdr hdr
;
1353 struct xcoff_ar_hdr
*hdrp
;
1355 if (bfd_read ((PTR
) &hdr
, SIZEOF_AR_HDR
, 1, abfd
) != SIZEOF_AR_HDR
)
1361 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1362 hdrp
= (struct xcoff_ar_hdr
*) bfd_alloc (abfd
,
1363 SIZEOF_AR_HDR
+ namlen
+ 1);
1369 memcpy (hdrp
, &hdr
, SIZEOF_AR_HDR
);
1370 if (bfd_read ((char *) hdrp
+ SIZEOF_AR_HDR
, 1, namlen
, abfd
) != namlen
)
1375 ((char *) hdrp
)[SIZEOF_AR_HDR
+ namlen
] = '\0';
1377 ret
->arch_header
= (char *) hdrp
;
1378 ret
->parsed_size
= strtol (hdr
.size
, (char **) NULL
, 10);
1379 ret
->filename
= (char *) hdrp
+ SIZEOF_AR_HDR
;
1383 struct xcoff_ar_hdr_big hdr
;
1384 struct xcoff_ar_hdr_big
*hdrp
;
1386 if (bfd_read ((PTR
) &hdr
, SIZEOF_AR_HDR_BIG
, 1, abfd
)
1387 != SIZEOF_AR_HDR_BIG
)
1393 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1394 hdrp
= (struct xcoff_ar_hdr_big
*) bfd_alloc (abfd
,
1402 memcpy (hdrp
, &hdr
, SIZEOF_AR_HDR_BIG
);
1403 if (bfd_read ((char *) hdrp
+ SIZEOF_AR_HDR_BIG
, 1, namlen
, abfd
) != namlen
)
1408 ((char *) hdrp
)[SIZEOF_AR_HDR_BIG
+ namlen
] = '\0';
1410 ret
->arch_header
= (char *) hdrp
;
1411 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1412 machines) since the field width is 20 and there numbers with more
1413 than 32 bits can be represented. */
1414 ret
->parsed_size
= strtol (hdr
.size
, (char **) NULL
, 10);
1415 ret
->filename
= (char *) hdrp
+ SIZEOF_AR_HDR_BIG
;
1418 /* Skip over the XCOFFARFMAG at the end of the file name. */
1419 if (bfd_seek (abfd
, (namlen
& 1) + SXCOFFARFMAG
, SEEK_CUR
) != 0)
1425 /* Open the next element in an XCOFF archive. */
1428 _bfd_xcoff_openr_next_archived_file (archive
, last_file
)
1434 if (xcoff_ardata (archive
) == NULL
)
1436 bfd_set_error (bfd_error_invalid_operation
);
1440 if (! xcoff_big_format_p (archive
))
1442 if (last_file
== NULL
)
1443 filestart
= bfd_ardata (archive
)->first_file_filepos
;
1445 filestart
= strtol (arch_xhdr (last_file
)->nextoff
, (char **) NULL
,
1449 || filestart
== strtol (xcoff_ardata (archive
)->memoff
,
1451 || filestart
== strtol (xcoff_ardata (archive
)->symoff
,
1452 (char **) NULL
, 10))
1454 bfd_set_error (bfd_error_no_more_archived_files
);
1460 if (last_file
== NULL
)
1461 filestart
= bfd_ardata (archive
)->first_file_filepos
;
1463 /* XXX These actually have to be a calls to strtoll (at least
1464 on 32-bit machines) since the fields's width is 20 and
1465 there numbers with more than 32 bits can be represented. */
1466 filestart
= strtol (arch_xhdr_big (last_file
)->nextoff
, (char **) NULL
,
1469 /* XXX These actually have to be calls to strtoll (at least on 32-bit
1470 machines) since the fields's width is 20 and there numbers with more
1471 than 32 bits can be represented. */
1473 || filestart
== strtol (xcoff_ardata_big (archive
)->memoff
,
1475 || filestart
== strtol (xcoff_ardata_big (archive
)->symoff
,
1476 (char **) NULL
, 10))
1478 bfd_set_error (bfd_error_no_more_archived_files
);
1483 return _bfd_get_elt_at_filepos (archive
, filestart
);
1486 /* Stat an element in an XCOFF archive. */
1489 _bfd_xcoff_generic_stat_arch_elt (abfd
, s
)
1493 if (abfd
->arelt_data
== NULL
)
1495 bfd_set_error (bfd_error_invalid_operation
);
1499 if (! xcoff_big_format_p (abfd
))
1501 struct xcoff_ar_hdr
*hdrp
= arch_xhdr (abfd
);
1503 s
->st_mtime
= strtol (hdrp
->date
, (char **) NULL
, 10);
1504 s
->st_uid
= strtol (hdrp
->uid
, (char **) NULL
, 10);
1505 s
->st_gid
= strtol (hdrp
->gid
, (char **) NULL
, 10);
1506 s
->st_mode
= strtol (hdrp
->mode
, (char **) NULL
, 8);
1507 s
->st_size
= arch_eltdata (abfd
)->parsed_size
;
1511 struct xcoff_ar_hdr_big
*hdrp
= arch_xhdr_big (abfd
);
1513 s
->st_mtime
= strtol (hdrp
->date
, (char **) NULL
, 10);
1514 s
->st_uid
= strtol (hdrp
->uid
, (char **) NULL
, 10);
1515 s
->st_gid
= strtol (hdrp
->gid
, (char **) NULL
, 10);
1516 s
->st_mode
= strtol (hdrp
->mode
, (char **) NULL
, 8);
1517 s
->st_size
= arch_eltdata (abfd
)->parsed_size
;
1523 /* Normalize a file name for inclusion in an archive. */
1526 normalize_filename (abfd
)
1530 const char *filename
;
1532 file
= bfd_get_filename (abfd
);
1533 filename
= strrchr (file
, '/');
1534 if (filename
!= NULL
)
1541 /* Write out an XCOFF armap. */
1544 xcoff_write_armap_old (abfd
, elength
, map
, orl_count
, stridx
)
1546 unsigned int elength ATTRIBUTE_UNUSED
;
1548 unsigned int orl_count
;
1551 struct xcoff_ar_hdr hdr
;
1553 unsigned char buf
[4];
1558 memset (&hdr
, 0, sizeof hdr
);
1559 sprintf (hdr
.size
, "%ld", (long) (4 + orl_count
* 4 + stridx
));
1560 sprintf (hdr
.nextoff
, "%d", 0);
1561 memcpy (hdr
.prevoff
, xcoff_ardata (abfd
)->memoff
, 12);
1562 sprintf (hdr
.date
, "%d", 0);
1563 sprintf (hdr
.uid
, "%d", 0);
1564 sprintf (hdr
.gid
, "%d", 0);
1565 sprintf (hdr
.mode
, "%d", 0);
1566 sprintf (hdr
.namlen
, "%d", 0);
1568 /* We need spaces, not null bytes, in the header. */
1569 for (p
= (char *) &hdr
; p
< (char *) &hdr
+ SIZEOF_AR_HDR
; p
++)
1573 if (bfd_write ((PTR
) &hdr
, SIZEOF_AR_HDR
, 1, abfd
) != SIZEOF_AR_HDR
1574 || bfd_write (XCOFFARFMAG
, 1, SXCOFFARFMAG
, abfd
) != SXCOFFARFMAG
)
1577 bfd_h_put_32 (abfd
, orl_count
, buf
);
1578 if (bfd_write (buf
, 1, 4, abfd
) != 4)
1581 sub
= abfd
->archive_head
;
1582 fileoff
= SIZEOF_AR_FILE_HDR
;
1584 while (sub
!= NULL
&& i
< orl_count
)
1588 while (((bfd
*) (map
[i
]).pos
) == sub
)
1590 bfd_h_put_32 (abfd
, fileoff
, buf
);
1591 if (bfd_write (buf
, 1, 4, abfd
) != 4)
1595 namlen
= strlen (normalize_filename (sub
));
1596 namlen
= (namlen
+ 1) &~ 1;
1597 fileoff
+= (SIZEOF_AR_HDR
1600 + arelt_size (sub
));
1601 fileoff
= (fileoff
+ 1) &~ 1;
1605 for (i
= 0; i
< orl_count
; i
++)
1610 name
= *map
[i
].name
;
1611 namlen
= strlen (name
);
1612 if (bfd_write (name
, 1, namlen
+ 1, abfd
) != namlen
+ 1)
1616 if ((stridx
& 1) != 0)
1621 if (bfd_write (&b
, 1, 1, abfd
) != 1)
1628 /* Write a single armap in the big format. */
1630 xcoff_write_one_armap_big (abfd
, map
, orl_count
, orl_ccount
, stridx
, bits64
,
1634 unsigned int orl_count
;
1635 unsigned int orl_ccount
;
1636 unsigned int stridx
;
1638 const char *prevoff
;
1641 struct xcoff_ar_hdr_big hdr
;
1643 unsigned char buf
[4];
1644 const bfd_arch_info_type
*arch_info
= NULL
;
1650 memset (&hdr
, 0, sizeof hdr
);
1651 /* XXX This call actually should use %lld (at least on 32-bit
1652 machines) since the fields's width is 20 and there numbers with
1653 more than 32 bits can be represented. */
1654 sprintf (hdr
.size
, "%ld", (long) (4 + orl_ccount
* 4 + stridx
));
1656 sprintf (hdr
.nextoff
, "%d", 0);
1658 sprintf (hdr
.nextoff
, "%ld", (strtol (prevoff
, (char **) NULL
, 10)
1659 + 4 + orl_ccount
* 4 + stridx
));
1660 memcpy (hdr
.prevoff
, prevoff
, sizeof (hdr
.prevoff
));
1661 sprintf (hdr
.date
, "%d", 0);
1662 sprintf (hdr
.uid
, "%d", 0);
1663 sprintf (hdr
.gid
, "%d", 0);
1664 sprintf (hdr
.mode
, "%d", 0);
1665 sprintf (hdr
.namlen
, "%d", 0);
1667 /* We need spaces, not null bytes, in the header. */
1668 for (p
= (char *) &hdr
; p
< (char *) &hdr
+ SIZEOF_AR_HDR_BIG
; p
++)
1672 memcpy (nextoff
, hdr
.nextoff
, sizeof (hdr
.nextoff
));
1674 if (bfd_write ((PTR
) &hdr
, SIZEOF_AR_HDR_BIG
, 1, abfd
) != SIZEOF_AR_HDR_BIG
1675 || bfd_write (XCOFFARFMAG
, 1, SXCOFFARFMAG
, abfd
) != SXCOFFARFMAG
)
1678 bfd_h_put_32 (abfd
, orl_ccount
, buf
);
1679 if (bfd_write (buf
, 1, 4, abfd
) != 4)
1682 sub
= abfd
->archive_head
;
1683 fileoff
= SIZEOF_AR_FILE_HDR_BIG
;
1685 while (sub
!= NULL
&& i
< orl_count
)
1689 if ((bfd_arch_bits_per_address ((bfd
*) map
[i
].pos
) == 64) == bits64
)
1690 while (((bfd
*) (map
[i
]).pos
) == sub
)
1692 bfd_h_put_32 (abfd
, fileoff
, buf
);
1693 if (bfd_write (buf
, 1, 4, abfd
) != 4)
1698 while (((bfd
*) (map
[i
]).pos
) == sub
)
1701 namlen
= strlen (normalize_filename (sub
));
1702 namlen
= (namlen
+ 1) &~ 1;
1703 fileoff
+= (SIZEOF_AR_HDR_BIG
1706 + arelt_size (sub
));
1707 fileoff
= (fileoff
+ 1) &~ 1;
1712 for (i
= 0; i
< orl_count
; i
++)
1716 bfd
*ob
= (bfd
*)map
[i
].pos
;
1718 if (ob
!= object_bfd
)
1719 arch_info
= bfd_get_arch_info (ob
);
1721 if (arch_info
&& (arch_info
->bits_per_address
== 64) != bits64
)
1724 name
= *map
[i
].name
;
1725 namlen
= strlen (name
);
1726 if (bfd_write (name
, 1, namlen
+ 1, abfd
) != namlen
+ 1)
1730 if ((stridx
& 1) != 0)
1735 if (bfd_write (&b
, 1, 1, abfd
) != 1)
1743 xcoff_write_armap_big (abfd
, elength
, map
, orl_count
, stridx
)
1745 unsigned int elength ATTRIBUTE_UNUSED
;
1747 unsigned int orl_count
;
1751 unsigned int orl_count_32
, orl_count_64
;
1752 unsigned int stridx_32
, stridx_64
;
1753 const bfd_arch_info_type
*arch_info
= NULL
;
1756 /* First, we look through the symbols and work out which are
1757 from 32-bit objects and which from 64-bit ones. */
1763 for (i
= 0; i
< orl_count
; i
++)
1765 bfd
*ob
= (bfd
*)map
[i
].pos
;
1767 if (ob
!= object_bfd
)
1768 arch_info
= bfd_get_arch_info (ob
);
1769 len
= strlen (*map
[i
].name
) + 1;
1770 if (arch_info
&& arch_info
->bits_per_address
== 64)
1782 /* A quick sanity check... */
1783 BFD_ASSERT (orl_count_64
+ orl_count_32
== orl_count
);
1784 BFD_ASSERT (stridx_64
+ stridx_32
== stridx
);
1786 /* Now write out each map. */
1787 if (! xcoff_write_one_armap_big (abfd
, map
, orl_count
, orl_count_32
,
1789 xcoff_ardata_big (abfd
)->memoff
,
1790 xcoff_ardata_big (abfd
)->symoff
))
1792 if (! xcoff_write_one_armap_big (abfd
, map
, orl_count
, orl_count_64
,
1794 xcoff_ardata_big (abfd
)->symoff
,
1795 xcoff_ardata_big (abfd
)->symoff64
))
1802 _bfd_xcoff_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
1804 unsigned int elength ATTRIBUTE_UNUSED
;
1806 unsigned int orl_count
;
1809 if (! xcoff_big_format_p (abfd
))
1810 return xcoff_write_armap_old (abfd
, elength
, map
, orl_count
, stridx
);
1812 return xcoff_write_armap_big (abfd
, elength
, map
, orl_count
, stridx
);
1815 /* Write out an XCOFF archive. We always write an entire archive,
1816 rather than fussing with the freelist and so forth. */
1819 xcoff_write_archive_contents_old (abfd
)
1822 struct xcoff_ar_file_hdr fhdr
;
1824 size_t total_namlen
;
1828 file_ptr prevoff
, nextoff
;
1831 struct xcoff_ar_hdr ahdr
;
1836 memset (&fhdr
, 0, sizeof fhdr
);
1837 strncpy (fhdr
.magic
, XCOFFARMAG
, SXCOFFARMAG
);
1838 sprintf (fhdr
.firstmemoff
, "%d", SIZEOF_AR_FILE_HDR
);
1839 sprintf (fhdr
.freeoff
, "%d", 0);
1843 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->next
)
1846 total_namlen
+= strlen (normalize_filename (sub
)) + 1;
1848 offsets
= (file_ptr
*) bfd_alloc (abfd
, count
* sizeof (file_ptr
));
1849 if (offsets
== NULL
)
1852 if (bfd_seek (abfd
, SIZEOF_AR_FILE_HDR
, SEEK_SET
) != 0)
1855 makemap
= bfd_has_map (abfd
);
1858 nextoff
= SIZEOF_AR_FILE_HDR
;
1859 for (sub
= abfd
->archive_head
, i
= 0; sub
!= NULL
; sub
= sub
->next
, i
++)
1863 struct xcoff_ar_hdr
*ahdrp
;
1864 bfd_size_type remaining
;
1866 if (makemap
&& ! hasobjects
)
1868 if (bfd_check_format (sub
, bfd_object
))
1872 name
= normalize_filename (sub
);
1873 namlen
= strlen (name
);
1875 if (sub
->arelt_data
!= NULL
)
1876 ahdrp
= arch_xhdr (sub
);
1884 memset (&ahdr
, 0, sizeof ahdr
);
1886 if (stat (bfd_get_filename (sub
), &s
) != 0)
1888 bfd_set_error (bfd_error_system_call
);
1892 sprintf (ahdrp
->size
, "%ld", (long) s
.st_size
);
1893 sprintf (ahdrp
->date
, "%ld", (long) s
.st_mtime
);
1894 sprintf (ahdrp
->uid
, "%ld", (long) s
.st_uid
);
1895 sprintf (ahdrp
->gid
, "%ld", (long) s
.st_gid
);
1896 sprintf (ahdrp
->mode
, "%o", (unsigned int) s
.st_mode
);
1898 if (sub
->arelt_data
== NULL
)
1900 sub
->arelt_data
= bfd_alloc (sub
, sizeof (struct areltdata
));
1901 if (sub
->arelt_data
== NULL
)
1905 arch_eltdata (sub
)->parsed_size
= s
.st_size
;
1908 sprintf (ahdrp
->prevoff
, "%ld", (long) prevoff
);
1909 sprintf (ahdrp
->namlen
, "%ld", (long) namlen
);
1911 /* If the length of the name is odd, we write out the null byte
1912 after the name as well. */
1913 namlen
= (namlen
+ 1) &~ 1;
1915 remaining
= arelt_size (sub
);
1916 size
= (SIZEOF_AR_HDR
1921 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
1923 offsets
[i
] = nextoff
;
1926 nextoff
+= size
+ (size
& 1);
1928 sprintf (ahdrp
->nextoff
, "%ld", (long) nextoff
);
1930 /* We need spaces, not null bytes, in the header. */
1931 for (p
= (char *) ahdrp
; p
< (char *) ahdrp
+ SIZEOF_AR_HDR
; p
++)
1935 if (bfd_write ((PTR
) ahdrp
, 1, SIZEOF_AR_HDR
, abfd
) != SIZEOF_AR_HDR
1936 || bfd_write ((PTR
) name
, 1, namlen
, abfd
) != namlen
1937 || (bfd_write ((PTR
) XCOFFARFMAG
, 1, SXCOFFARFMAG
, abfd
)
1941 if (bfd_seek (sub
, (file_ptr
) 0, SEEK_SET
) != 0)
1943 while (remaining
!= 0)
1946 bfd_byte buffer
[DEFAULT_BUFFERSIZE
];
1948 amt
= sizeof buffer
;
1949 if (amt
> remaining
)
1951 if (bfd_read (buffer
, 1, amt
, sub
) != amt
1952 || bfd_write (buffer
, 1, amt
, abfd
) != amt
)
1957 if ((size
& 1) != 0)
1962 if (bfd_write (&b
, 1, 1, abfd
) != 1)
1967 sprintf (fhdr
.lastmemoff
, "%ld", (long) prevoff
);
1969 /* Write out the member table. */
1971 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
1972 sprintf (fhdr
.memoff
, "%ld", (long) nextoff
);
1974 memset (&ahdr
, 0, sizeof ahdr
);
1975 sprintf (ahdr
.size
, "%ld", (long) (12 + count
* 12 + total_namlen
));
1976 sprintf (ahdr
.prevoff
, "%ld", (long) prevoff
);
1977 sprintf (ahdr
.date
, "%d", 0);
1978 sprintf (ahdr
.uid
, "%d", 0);
1979 sprintf (ahdr
.gid
, "%d", 0);
1980 sprintf (ahdr
.mode
, "%d", 0);
1981 sprintf (ahdr
.namlen
, "%d", 0);
1983 size
= (SIZEOF_AR_HDR
1990 nextoff
+= size
+ (size
& 1);
1992 if (makemap
&& hasobjects
)
1993 sprintf (ahdr
.nextoff
, "%ld", (long) nextoff
);
1995 sprintf (ahdr
.nextoff
, "%d", 0);
1997 /* We need spaces, not null bytes, in the header. */
1998 for (p
= (char *) &ahdr
; p
< (char *) &ahdr
+ SIZEOF_AR_HDR
; p
++)
2002 if (bfd_write ((PTR
) &ahdr
, 1, SIZEOF_AR_HDR
, abfd
) != SIZEOF_AR_HDR
2003 || (bfd_write ((PTR
) XCOFFARFMAG
, 1, SXCOFFARFMAG
, abfd
)
2007 sprintf (decbuf
, "%-12ld", (long) count
);
2008 if (bfd_write ((PTR
) decbuf
, 1, 12, abfd
) != 12)
2010 for (i
= 0; i
< count
; i
++)
2012 sprintf (decbuf
, "%-12ld", (long) offsets
[i
]);
2013 if (bfd_write ((PTR
) decbuf
, 1, 12, abfd
) != 12)
2016 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->next
)
2021 name
= normalize_filename (sub
);
2022 namlen
= strlen (name
);
2023 if (bfd_write ((PTR
) name
, 1, namlen
+ 1, abfd
) != namlen
+ 1)
2026 if ((size
& 1) != 0)
2031 if (bfd_write ((PTR
) &b
, 1, 1, abfd
) != 1)
2035 /* Write out the armap, if appropriate. */
2037 if (! makemap
|| ! hasobjects
)
2038 sprintf (fhdr
.symoff
, "%d", 0);
2041 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2042 sprintf (fhdr
.symoff
, "%ld", (long) nextoff
);
2043 bfd_ardata (abfd
)->tdata
= (PTR
) &fhdr
;
2044 if (! _bfd_compute_and_write_armap (abfd
, 0))
2048 /* Write out the archive file header. */
2050 /* We need spaces, not null bytes, in the header. */
2051 for (p
= (char *) &fhdr
; p
< (char *) &fhdr
+ SIZEOF_AR_FILE_HDR
; p
++)
2055 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
2056 || (bfd_write ((PTR
) &fhdr
, SIZEOF_AR_FILE_HDR
, 1, abfd
) !=
2057 SIZEOF_AR_FILE_HDR
))
2064 xcoff_write_archive_contents_big (abfd
)
2067 struct xcoff_ar_file_hdr_big fhdr
;
2069 size_t total_namlen
;
2073 file_ptr prevoff
, nextoff
;
2076 struct xcoff_ar_hdr_big ahdr
;
2081 memset (&fhdr
, 0, sizeof fhdr
);
2082 strncpy (fhdr
.magic
, XCOFFARMAGBIG
, SXCOFFARMAG
);
2083 sprintf (fhdr
.firstmemoff
, "%d", SIZEOF_AR_FILE_HDR_BIG
);
2084 sprintf (fhdr
.freeoff
, "%d", 0);
2088 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->next
)
2091 total_namlen
+= strlen (normalize_filename (sub
)) + 1;
2093 offsets
= (file_ptr
*) bfd_alloc (abfd
, count
* sizeof (file_ptr
));
2094 if (offsets
== NULL
)
2097 if (bfd_seek (abfd
, SIZEOF_AR_FILE_HDR_BIG
, SEEK_SET
) != 0)
2100 makemap
= bfd_has_map (abfd
);
2103 nextoff
= SIZEOF_AR_FILE_HDR_BIG
;
2104 for (sub
= abfd
->archive_head
, i
= 0; sub
!= NULL
; sub
= sub
->next
, i
++)
2108 struct xcoff_ar_hdr_big
*ahdrp
;
2109 bfd_size_type remaining
;
2111 if (makemap
&& ! hasobjects
)
2113 if (bfd_check_format (sub
, bfd_object
))
2117 name
= normalize_filename (sub
);
2118 namlen
= strlen (name
);
2120 if (sub
->arelt_data
!= NULL
)
2121 ahdrp
= arch_xhdr_big (sub
);
2129 memset (&ahdr
, 0, sizeof ahdr
);
2131 /* XXX This should actually be a call to stat64 (at least on
2132 32-bit machines). */
2133 if (stat (bfd_get_filename (sub
), &s
) != 0)
2135 bfd_set_error (bfd_error_system_call
);
2139 /* XXX This call actually should use %lld (at least on 32-bit
2140 machines) since the fields's width is 20 and there numbers with
2141 more than 32 bits can be represented. */
2142 sprintf (ahdrp
->size
, "%ld", (long) s
.st_size
);
2143 sprintf (ahdrp
->date
, "%ld", (long) s
.st_mtime
);
2144 sprintf (ahdrp
->uid
, "%ld", (long) s
.st_uid
);
2145 sprintf (ahdrp
->gid
, "%ld", (long) s
.st_gid
);
2146 sprintf (ahdrp
->mode
, "%o", (unsigned int) s
.st_mode
);
2148 if (sub
->arelt_data
== NULL
)
2150 sub
->arelt_data
= bfd_alloc (sub
, sizeof (struct areltdata
));
2151 if (sub
->arelt_data
== NULL
)
2155 arch_eltdata (sub
)->parsed_size
= s
.st_size
;
2158 /* XXX These calls actually should use %lld (at least on 32-bit
2159 machines) since the fields's width is 20 and there numbers with
2160 more than 32 bits can be represented. */
2161 sprintf (ahdrp
->prevoff
, "%ld", (long) prevoff
);
2162 sprintf (ahdrp
->namlen
, "%ld", (long) namlen
);
2164 /* If the length of the name is odd, we write out the null byte
2165 after the name as well. */
2166 namlen
= (namlen
+ 1) &~ 1;
2168 remaining
= arelt_size (sub
);
2169 size
= (SIZEOF_AR_HDR_BIG
2174 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2176 offsets
[i
] = nextoff
;
2179 nextoff
+= size
+ (size
& 1);
2181 sprintf (ahdrp
->nextoff
, "%ld", (long) nextoff
);
2183 /* We need spaces, not null bytes, in the header. */
2184 for (p
= (char *) ahdrp
; p
< (char *) ahdrp
+ SIZEOF_AR_HDR_BIG
; p
++)
2188 if (bfd_write ((PTR
) ahdrp
, 1, SIZEOF_AR_HDR_BIG
, abfd
)
2189 != SIZEOF_AR_HDR_BIG
2190 || bfd_write ((PTR
) name
, 1, namlen
, abfd
) != namlen
2191 || (bfd_write ((PTR
) XCOFFARFMAG
, 1, SXCOFFARFMAG
, abfd
)
2195 if (bfd_seek (sub
, (file_ptr
) 0, SEEK_SET
) != 0)
2197 while (remaining
!= 0)
2200 bfd_byte buffer
[DEFAULT_BUFFERSIZE
];
2202 amt
= sizeof buffer
;
2203 if (amt
> remaining
)
2205 if (bfd_read (buffer
, 1, amt
, sub
) != amt
2206 || bfd_write (buffer
, 1, amt
, abfd
) != amt
)
2211 if ((size
& 1) != 0)
2216 if (bfd_write (&b
, 1, 1, abfd
) != 1)
2221 /* XXX This call actually should use %lld (at least on 32-bit
2222 machines) since the fields's width is 20 and there numbers with
2223 more than 32 bits can be represented. */
2224 sprintf (fhdr
.lastmemoff
, "%ld", (long) prevoff
);
2226 /* Write out the member table. */
2228 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2229 /* XXX This call actually should use %lld (at least on 32-bit
2230 machines) since the fields's width is 20 and there numbers with
2231 more than 32 bits can be represented. */
2232 sprintf (fhdr
.memoff
, "%ld", (long) nextoff
);
2234 memset (&ahdr
, 0, sizeof ahdr
);
2235 /* XXX The next two calls actually should use %lld (at least on 32-bit
2236 machines) since the fields's width is 20 and there numbers with
2237 more than 32 bits can be represented. */
2238 sprintf (ahdr
.size
, "%ld", (long) (12 + count
* 12 + total_namlen
));
2239 sprintf (ahdr
.prevoff
, "%ld", (long) prevoff
);
2240 sprintf (ahdr
.date
, "%d", 0);
2241 sprintf (ahdr
.uid
, "%d", 0);
2242 sprintf (ahdr
.gid
, "%d", 0);
2243 sprintf (ahdr
.mode
, "%d", 0);
2244 sprintf (ahdr
.namlen
, "%d", 0);
2246 size
= (SIZEOF_AR_HDR_BIG
2253 nextoff
+= size
+ (size
& 1);
2255 if (makemap
&& hasobjects
)
2256 /* XXX This call actually should use %lld (at least on 32-bit
2257 machines) since the fields's width is 20 and there numbers with
2258 more than 32 bits can be represented. */
2259 sprintf (ahdr
.nextoff
, "%ld", (long) nextoff
);
2261 sprintf (ahdr
.nextoff
, "%d", 0);
2263 /* We need spaces, not null bytes, in the header. */
2264 for (p
= (char *) &ahdr
; p
< (char *) &ahdr
+ SIZEOF_AR_HDR_BIG
; p
++)
2268 if (bfd_write ((PTR
) &ahdr
, 1, SIZEOF_AR_HDR_BIG
, abfd
) != SIZEOF_AR_HDR_BIG
2269 || (bfd_write ((PTR
) XCOFFARFMAG
, 1, SXCOFFARFMAG
, abfd
)
2273 sprintf (decbuf
, "%-12ld", (long) count
);
2274 if (bfd_write ((PTR
) decbuf
, 1, 12, abfd
) != 12)
2276 for (i
= 0; i
< count
; i
++)
2278 sprintf (decbuf
, "%-12ld", (long) offsets
[i
]);
2279 if (bfd_write ((PTR
) decbuf
, 1, 12, abfd
) != 12)
2282 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->next
)
2287 name
= normalize_filename (sub
);
2288 namlen
= strlen (name
);
2289 if (bfd_write ((PTR
) name
, 1, namlen
+ 1, abfd
) != namlen
+ 1)
2292 if ((size
& 1) != 0)
2297 if (bfd_write ((PTR
) &b
, 1, 1, abfd
) != 1)
2301 /* Write out the armap, if appropriate. */
2303 if (! makemap
|| ! hasobjects
)
2304 sprintf (fhdr
.symoff
, "%d", 0);
2307 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2308 /* XXX This call actually should use %lld (at least on 32-bit
2309 machines) since the fields's width is 20 and there numbers with
2310 more than 32 bits can be represented. */
2311 bfd_ardata (abfd
)->tdata
= (PTR
) &fhdr
;
2312 if (! _bfd_compute_and_write_armap (abfd
, 0))
2316 /* Write out the archive file header. */
2318 /* We need spaces, not null bytes, in the header. */
2319 for (p
= (char *) &fhdr
; p
< (char *) &fhdr
+ SIZEOF_AR_FILE_HDR_BIG
; p
++)
2323 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
2324 || (bfd_write ((PTR
) &fhdr
, SIZEOF_AR_FILE_HDR_BIG
, 1, abfd
) !=
2325 SIZEOF_AR_FILE_HDR_BIG
))
2332 _bfd_xcoff_write_archive_contents (abfd
)
2335 if (! xcoff_big_format_p (abfd
))
2336 return xcoff_write_archive_contents_old (abfd
);
2338 return xcoff_write_archive_contents_big (abfd
);
2341 /* We can't use the usual coff_sizeof_headers routine, because AIX
2342 always uses an a.out header. */
2345 _bfd_xcoff_sizeof_headers (abfd
, reloc
)
2347 boolean reloc ATTRIBUTE_UNUSED
;
2352 if (xcoff_data (abfd
)->full_aouthdr
)
2355 size
+= SMALL_AOUTSZ
;
2356 size
+= abfd
->section_count
* SCNHSZ
;