1 /* BFD back-end for IBM RS/6000 "XCOFF" files.
2 Copyright 1990, 91, 92, 93, 94, 95, 96, 97, 98, 1999
3 Free Software Foundation, Inc.
4 FIXME: Can someone provide a transliteration of this name into ASCII?
5 Using the following chars caused a compiler warning on HIUX (so I replaced
6 them with octal escapes), and isn't useful without an understanding of what
8 Written by Metin G. Ozisik, Mimi Ph\373\364ng-Th\345o V\365,
10 Archive support from Damon A. Permezel.
11 Contributed by IBM Corporation and Cygnus Support.
13 This file is part of BFD, the Binary File Descriptor library.
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or
18 (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
32 #include "coff/internal.h"
33 #include "coff/rs6000.h"
35 #define TARGET_NAME "aixcoff-rs6000"
36 #define TARGET_SYM rs6000coff_vec
37 #include "xcoff-target.h"
39 /* The main body of code is in coffcode.h. */
41 static const char *normalize_filename
PARAMS ((bfd
*));
43 /* We use our own tdata type. Its first field is the COFF tdata type,
44 so the COFF routines are compatible. */
47 _bfd_xcoff_mkobject (abfd
)
52 abfd
->tdata
.xcoff_obj_data
=
53 ((struct xcoff_tdata
*)
54 bfd_zalloc (abfd
, sizeof (struct xcoff_tdata
)));
55 if (abfd
->tdata
.xcoff_obj_data
== NULL
)
57 coff
= coff_data (abfd
);
58 coff
->symbols
= (coff_symbol_type
*) NULL
;
59 coff
->conversion_table
= (unsigned int *) NULL
;
60 coff
->raw_syments
= (struct coff_ptr_struct
*) NULL
;
63 xcoff_data (abfd
)->modtype
= ('1' << 8) | 'L';
65 /* We set cputype to -1 to indicate that it has not been
67 xcoff_data (abfd
)->cputype
= -1;
69 xcoff_data (abfd
)->csects
= NULL
;
70 xcoff_data (abfd
)->debug_indices
= NULL
;
75 /* Copy XCOFF data from one BFD to another. */
78 _bfd_xcoff_copy_private_bfd_data (ibfd
, obfd
)
82 struct xcoff_tdata
*ix
, *ox
;
85 if (ibfd
->xvec
!= obfd
->xvec
)
87 ix
= xcoff_data (ibfd
);
88 ox
= xcoff_data (obfd
);
89 ox
->full_aouthdr
= ix
->full_aouthdr
;
95 sec
= coff_section_from_bfd_index (ibfd
, ix
->sntoc
);
99 ox
->sntoc
= sec
->output_section
->target_index
;
101 if (ix
->snentry
== 0)
105 sec
= coff_section_from_bfd_index (ibfd
, ix
->snentry
);
109 ox
->snentry
= sec
->output_section
->target_index
;
111 ox
->text_align_power
= ix
->text_align_power
;
112 ox
->data_align_power
= ix
->data_align_power
;
113 ox
->modtype
= ix
->modtype
;
114 ox
->cputype
= ix
->cputype
;
115 ox
->maxdata
= ix
->maxdata
;
116 ox
->maxstack
= ix
->maxstack
;
120 /* I don't think XCOFF really has a notion of local labels based on
121 name. This will mean that ld -X doesn't actually strip anything.
122 The AIX native linker does not have a -X option, and it ignores the
126 _bfd_xcoff_is_local_label_name (abfd
, name
)
127 bfd
*abfd ATTRIBUTE_UNUSED
;
128 const char *name ATTRIBUTE_UNUSED
;
134 _bfd_xcoff_swap_sym_in (abfd
, ext1
, in1
)
139 SYMENT
*ext
= (SYMENT
*)ext1
;
140 struct internal_syment
*in
= (struct internal_syment
*)in1
;
142 if (ext
->e
.e_name
[0] != 0)
144 memcpy(in
->_n
._n_name
, ext
->e
.e_name
, SYMNMLEN
);
148 in
->_n
._n_n
._n_zeroes
= 0;
149 in
->_n
._n_n
._n_offset
=
150 bfd_h_get_32(abfd
, (bfd_byte
*) ext
->e
.e
.e_offset
);
153 in
->n_value
= bfd_h_get_32(abfd
, (bfd_byte
*) ext
->e_value
);
154 in
->n_scnum
= bfd_h_get_16(abfd
, (bfd_byte
*) ext
->e_scnum
);
155 in
->n_type
= bfd_h_get_16(abfd
, (bfd_byte
*) ext
->e_type
);
156 in
->n_sclass
= bfd_h_get_8(abfd
, ext
->e_sclass
);
157 in
->n_numaux
= bfd_h_get_8(abfd
, ext
->e_numaux
);
161 _bfd_xcoff_swap_sym_out (abfd
, inp
, extp
)
166 struct internal_syment
*in
= (struct internal_syment
*)inp
;
167 SYMENT
*ext
=(SYMENT
*)extp
;
169 if (in
->_n
._n_name
[0] != 0)
171 memcpy(ext
->e
.e_name
, in
->_n
._n_name
, SYMNMLEN
);
175 bfd_h_put_32(abfd
, 0, (bfd_byte
*) ext
->e
.e
.e_zeroes
);
176 bfd_h_put_32(abfd
, in
->_n
._n_n
._n_offset
,
177 (bfd_byte
*) ext
->e
.e
.e_offset
);
180 bfd_h_put_32(abfd
, in
->n_value
, (bfd_byte
*) ext
->e_value
);
181 bfd_h_put_16(abfd
, in
->n_scnum
, (bfd_byte
*) ext
->e_scnum
);
182 bfd_h_put_16(abfd
, in
->n_type
, (bfd_byte
*) ext
->e_type
);
183 bfd_h_put_8(abfd
, in
->n_sclass
, ext
->e_sclass
);
184 bfd_h_put_8(abfd
, in
->n_numaux
, ext
->e_numaux
);
185 return bfd_coff_symesz (abfd
);
188 #define PUTWORD bfd_h_put_32
189 #define PUTHALF bfd_h_put_16
190 #define PUTBYTE bfd_h_put_8
191 #define GETWORD bfd_h_get_32
192 #define GETHALF bfd_h_get_16
193 #define GETBYTE bfd_h_get_8
196 _bfd_xcoff_swap_aux_in (abfd
, ext1
, type
, class, indx
, numaux
, in1
)
205 AUXENT
*ext
= (AUXENT
*)ext1
;
206 union internal_auxent
*in
= (union internal_auxent
*)in1
;
210 if (ext
->x_file
.x_fname
[0] == 0) {
211 in
->x_file
.x_n
.x_zeroes
= 0;
212 in
->x_file
.x_n
.x_offset
=
213 bfd_h_get_32(abfd
, (bfd_byte
*) ext
->x_file
.x_n
.x_offset
);
218 memcpy (in
->x_file
.x_fname
, ext
->x_file
.x_fname
,
219 numaux
* sizeof (AUXENT
));
223 memcpy (in
->x_file
.x_fname
, ext
->x_file
.x_fname
, FILNMLEN
);
228 /* RS/6000 "csect" auxents */
231 if (indx
+ 1 == numaux
)
233 in
->x_csect
.x_scnlen
.l
=
234 bfd_h_get_32 (abfd
, ext
->x_csect
.x_scnlen
);
235 in
->x_csect
.x_parmhash
= bfd_h_get_32 (abfd
,
236 ext
->x_csect
.x_parmhash
);
237 in
->x_csect
.x_snhash
= bfd_h_get_16 (abfd
, ext
->x_csect
.x_snhash
);
238 /* We don't have to hack bitfields in x_smtyp because it's
239 defined by shifts-and-ands, which are equivalent on all
241 in
->x_csect
.x_smtyp
= bfd_h_get_8 (abfd
, ext
->x_csect
.x_smtyp
);
242 in
->x_csect
.x_smclas
= bfd_h_get_8 (abfd
, ext
->x_csect
.x_smclas
);
243 in
->x_csect
.x_stab
= bfd_h_get_32 (abfd
, ext
->x_csect
.x_stab
);
244 in
->x_csect
.x_snstab
= bfd_h_get_16 (abfd
, ext
->x_csect
.x_snstab
);
252 if (type
== T_NULL
) {
253 in
->x_scn
.x_scnlen
= bfd_h_get_32(abfd
,
254 (bfd_byte
*) ext
->x_scn
.x_scnlen
);
255 in
->x_scn
.x_nreloc
= bfd_h_get_16(abfd
,
256 (bfd_byte
*) ext
->x_scn
.x_nreloc
);
257 in
->x_scn
.x_nlinno
= bfd_h_get_16(abfd
,
258 (bfd_byte
*) ext
->x_scn
.x_nlinno
);
259 /* PE defines some extra fields; we zero them out for
261 in
->x_scn
.x_checksum
= 0;
262 in
->x_scn
.x_associated
= 0;
263 in
->x_scn
.x_comdat
= 0;
270 in
->x_sym
.x_tagndx
.l
= bfd_h_get_32(abfd
, (bfd_byte
*) ext
->x_sym
.x_tagndx
);
271 in
->x_sym
.x_tvndx
= bfd_h_get_16(abfd
, (bfd_byte
*) ext
->x_sym
.x_tvndx
);
273 if (class == C_BLOCK
|| class == C_FCN
|| ISFCN (type
) || ISTAG (class))
275 in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
= bfd_h_get_32(abfd
, (bfd_byte
*)
276 ext
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
277 in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
= bfd_h_get_32(abfd
, (bfd_byte
*)
278 ext
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
282 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0] =
283 bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
284 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1] =
285 bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
286 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2] =
287 bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
288 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3] =
289 bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
292 in
->x_sym
.x_misc
.x_fsize
= bfd_h_get_32(abfd
, (bfd_byte
*) ext
->x_sym
.x_misc
.x_fsize
);
295 in
->x_sym
.x_misc
.x_lnsz
.x_lnno
= bfd_h_get_16(abfd
, (bfd_byte
*)
296 ext
->x_sym
.x_misc
.x_lnsz
.x_lnno
);
297 in
->x_sym
.x_misc
.x_lnsz
.x_size
= bfd_h_get_16(abfd
, (bfd_byte
*)
298 ext
->x_sym
.x_misc
.x_lnsz
.x_size
);
302 /* the semicolon is because MSVC doesn't like labels at
308 _bfd_xcoff_swap_aux_out (abfd
, inp
, type
, class, indx
, numaux
, extp
)
313 int indx ATTRIBUTE_UNUSED
;
314 int numaux ATTRIBUTE_UNUSED
;
317 union internal_auxent
*in
= (union internal_auxent
*)inp
;
318 AUXENT
*ext
= (AUXENT
*)extp
;
320 memset((PTR
)ext
, 0, bfd_coff_auxesz (abfd
));
324 if (in
->x_file
.x_fname
[0] == 0)
326 PUTWORD(abfd
, 0, (bfd_byte
*) ext
->x_file
.x_n
.x_zeroes
);
328 in
->x_file
.x_n
.x_offset
,
329 (bfd_byte
*) ext
->x_file
.x_n
.x_offset
);
333 memcpy (ext
->x_file
.x_fname
, in
->x_file
.x_fname
, FILNMLEN
);
337 /* RS/6000 "csect" auxents */
340 if (indx
+ 1 == numaux
)
342 PUTWORD (abfd
, in
->x_csect
.x_scnlen
.l
,ext
->x_csect
.x_scnlen
);
343 PUTWORD (abfd
, in
->x_csect
.x_parmhash
, ext
->x_csect
.x_parmhash
);
344 PUTHALF (abfd
, in
->x_csect
.x_snhash
, ext
->x_csect
.x_snhash
);
345 /* We don't have to hack bitfields in x_smtyp because it's
346 defined by shifts-and-ands, which are equivalent on all
348 PUTBYTE (abfd
, in
->x_csect
.x_smtyp
, ext
->x_csect
.x_smtyp
);
349 PUTBYTE (abfd
, in
->x_csect
.x_smclas
, ext
->x_csect
.x_smclas
);
350 PUTWORD (abfd
, in
->x_csect
.x_stab
, ext
->x_csect
.x_stab
);
351 PUTHALF (abfd
, in
->x_csect
.x_snstab
, ext
->x_csect
.x_snstab
);
359 if (type
== T_NULL
) {
360 bfd_h_put_32(abfd
, in
->x_scn
.x_scnlen
, (bfd_byte
*) ext
->x_scn
.x_scnlen
);
361 bfd_h_put_16(abfd
, in
->x_scn
.x_nreloc
, (bfd_byte
*) ext
->x_scn
.x_nreloc
);
362 bfd_h_put_16(abfd
, in
->x_scn
.x_nlinno
, (bfd_byte
*) ext
->x_scn
.x_nlinno
);
368 PUTWORD(abfd
, in
->x_sym
.x_tagndx
.l
, (bfd_byte
*) ext
->x_sym
.x_tagndx
);
369 bfd_h_put_16 (abfd
, in
->x_sym
.x_tvndx
, (bfd_byte
*) ext
->x_sym
.x_tvndx
);
371 if (class == C_BLOCK
|| class == C_FCN
|| ISFCN (type
) || ISTAG (class))
373 bfd_h_put_32(abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
,
374 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
375 PUTWORD(abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
,
376 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
380 bfd_h_put_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0],
381 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
382 bfd_h_put_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1],
383 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
384 bfd_h_put_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2],
385 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
386 bfd_h_put_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3],
387 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
391 PUTWORD (abfd
, in
->x_sym
.x_misc
.x_fsize
,
392 (bfd_byte
*) ext
->x_sym
.x_misc
.x_fsize
);
395 bfd_h_put_16(abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_lnno
,
396 (bfd_byte
*)ext
->x_sym
.x_misc
.x_lnsz
.x_lnno
);
397 bfd_h_put_16(abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_size
,
398 (bfd_byte
*)ext
->x_sym
.x_misc
.x_lnsz
.x_size
);
402 return bfd_coff_auxesz (abfd
);
405 /* The XCOFF reloc table. Actually, XCOFF relocations specify the
406 bitsize and whether they are signed or not, along with a
407 conventional type. This table is for the types, which are used for
408 different algorithms for putting in the reloc. Many of these
409 relocs need special_function entries, which I have not written. */
411 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
412 from smaller values. Start with zero, widen, *then* decrement. */
413 #define MINUS_ONE (((bfd_vma)0) - 1)
415 reloc_howto_type xcoff_howto_table
[] =
417 /* Standard 32 bit relocation. */
420 2, /* size (0 = byte, 1 = short, 2 = long) */
422 false, /* pc_relative */
424 complain_overflow_bitfield
, /* complain_on_overflow */
425 0, /* special_function */
427 true, /* partial_inplace */
428 0xffffffff, /* src_mask */
429 0xffffffff, /* dst_mask */
430 false), /* pcrel_offset */
432 /* 32 bit relocation, but store negative value. */
435 -2, /* size (0 = byte, 1 = short, 2 = long) */
437 false, /* pc_relative */
439 complain_overflow_bitfield
, /* complain_on_overflow */
440 0, /* special_function */
442 true, /* partial_inplace */
443 0xffffffff, /* src_mask */
444 0xffffffff, /* dst_mask */
445 false), /* pcrel_offset */
447 /* 32 bit PC relative relocation. */
450 2, /* size (0 = byte, 1 = short, 2 = long) */
452 true, /* pc_relative */
454 complain_overflow_signed
, /* complain_on_overflow */
455 0, /* special_function */
457 true, /* partial_inplace */
458 0xffffffff, /* src_mask */
459 0xffffffff, /* dst_mask */
460 false), /* pcrel_offset */
462 /* 16 bit TOC relative relocation. */
465 1, /* size (0 = byte, 1 = short, 2 = long) */
467 false, /* pc_relative */
469 complain_overflow_bitfield
, /* complain_on_overflow */
470 0, /* special_function */
472 true, /* partial_inplace */
473 0xffff, /* src_mask */
474 0xffff, /* dst_mask */
475 false), /* pcrel_offset */
477 /* I don't really know what this is. */
480 2, /* size (0 = byte, 1 = short, 2 = long) */
482 false, /* pc_relative */
484 complain_overflow_bitfield
, /* complain_on_overflow */
485 0, /* special_function */
487 true, /* partial_inplace */
488 0xffffffff, /* src_mask */
489 0xffffffff, /* dst_mask */
490 false), /* pcrel_offset */
492 /* External TOC relative symbol. */
495 2, /* size (0 = byte, 1 = short, 2 = long) */
497 false, /* pc_relative */
499 complain_overflow_bitfield
, /* complain_on_overflow */
500 0, /* special_function */
502 true, /* partial_inplace */
503 0xffff, /* src_mask */
504 0xffff, /* dst_mask */
505 false), /* pcrel_offset */
507 /* Local TOC relative symbol. */
510 2, /* size (0 = byte, 1 = short, 2 = long) */
512 false, /* pc_relative */
514 complain_overflow_bitfield
, /* complain_on_overflow */
515 0, /* special_function */
517 true, /* partial_inplace */
518 0xffff, /* src_mask */
519 0xffff, /* dst_mask */
520 false), /* pcrel_offset */
524 /* Non modifiable absolute branch. */
527 2, /* size (0 = byte, 1 = short, 2 = long) */
529 false, /* pc_relative */
531 complain_overflow_bitfield
, /* complain_on_overflow */
532 0, /* special_function */
534 true, /* partial_inplace */
535 0x3fffffc, /* src_mask */
536 0x3fffffc, /* dst_mask */
537 false), /* pcrel_offset */
541 /* Non modifiable relative branch. */
542 HOWTO (0xa, /* type */
544 2, /* size (0 = byte, 1 = short, 2 = long) */
546 true, /* pc_relative */
548 complain_overflow_signed
, /* complain_on_overflow */
549 0, /* special_function */
551 true, /* partial_inplace */
552 0x3fffffc, /* src_mask */
553 0x3fffffc, /* dst_mask */
554 false), /* pcrel_offset */
559 HOWTO (0xc, /* type */
561 2, /* size (0 = byte, 1 = short, 2 = long) */
563 false, /* pc_relative */
565 complain_overflow_bitfield
, /* complain_on_overflow */
566 0, /* special_function */
568 true, /* partial_inplace */
569 0xffff, /* src_mask */
570 0xffff, /* dst_mask */
571 false), /* pcrel_offset */
574 HOWTO (0xd, /* type */
576 2, /* size (0 = byte, 1 = short, 2 = long) */
578 false, /* pc_relative */
580 complain_overflow_bitfield
, /* complain_on_overflow */
581 0, /* special_function */
583 true, /* partial_inplace */
584 0xffff, /* src_mask */
585 0xffff, /* dst_mask */
586 false), /* pcrel_offset */
590 /* Non-relocating reference. */
591 HOWTO (0xf, /* type */
593 2, /* size (0 = byte, 1 = short, 2 = long) */
595 false, /* pc_relative */
597 complain_overflow_bitfield
, /* complain_on_overflow */
598 0, /* special_function */
600 false, /* partial_inplace */
603 false), /* pcrel_offset */
608 /* TOC relative indirect load. */
609 HOWTO (0x12, /* type */
611 2, /* size (0 = byte, 1 = short, 2 = long) */
613 false, /* pc_relative */
615 complain_overflow_bitfield
, /* complain_on_overflow */
616 0, /* special_function */
618 true, /* partial_inplace */
619 0xffff, /* src_mask */
620 0xffff, /* dst_mask */
621 false), /* pcrel_offset */
623 /* TOC relative load address. */
624 HOWTO (0x13, /* type */
626 2, /* size (0 = byte, 1 = short, 2 = long) */
628 false, /* pc_relative */
630 complain_overflow_bitfield
, /* complain_on_overflow */
631 0, /* special_function */
633 true, /* partial_inplace */
634 0xffff, /* src_mask */
635 0xffff, /* dst_mask */
636 false), /* pcrel_offset */
638 /* Modifiable relative branch. */
639 HOWTO (0x14, /* type */
641 2, /* size (0 = byte, 1 = short, 2 = long) */
643 false, /* pc_relative */
645 complain_overflow_bitfield
, /* complain_on_overflow */
646 0, /* special_function */
647 "R_RRTBI", /* name */
648 true, /* partial_inplace */
649 0xffffffff, /* src_mask */
650 0xffffffff, /* dst_mask */
651 false), /* pcrel_offset */
653 /* Modifiable absolute branch. */
654 HOWTO (0x15, /* type */
656 2, /* size (0 = byte, 1 = short, 2 = long) */
658 false, /* pc_relative */
660 complain_overflow_bitfield
, /* complain_on_overflow */
661 0, /* special_function */
662 "R_RRTBA", /* name */
663 true, /* partial_inplace */
664 0xffffffff, /* src_mask */
665 0xffffffff, /* dst_mask */
666 false), /* pcrel_offset */
668 /* Modifiable call absolute indirect. */
669 HOWTO (0x16, /* type */
671 2, /* size (0 = byte, 1 = short, 2 = long) */
673 false, /* pc_relative */
675 complain_overflow_bitfield
, /* complain_on_overflow */
676 0, /* special_function */
678 true, /* partial_inplace */
679 0xffff, /* src_mask */
680 0xffff, /* dst_mask */
681 false), /* pcrel_offset */
683 /* Modifiable call relative. */
684 HOWTO (0x17, /* type */
686 2, /* size (0 = byte, 1 = short, 2 = long) */
688 false, /* pc_relative */
690 complain_overflow_bitfield
, /* complain_on_overflow */
691 0, /* special_function */
693 true, /* partial_inplace */
694 0xffff, /* src_mask */
695 0xffff, /* dst_mask */
696 false), /* pcrel_offset */
698 /* Modifiable branch absolute. */
699 HOWTO (0x18, /* type */
701 2, /* size (0 = byte, 1 = short, 2 = long) */
703 false, /* pc_relative */
705 complain_overflow_bitfield
, /* complain_on_overflow */
706 0, /* special_function */
708 true, /* partial_inplace */
709 0xffff, /* src_mask */
710 0xffff, /* dst_mask */
711 false), /* pcrel_offset */
713 /* Modifiable branch absolute. */
714 HOWTO (0x19, /* type */
716 2, /* size (0 = byte, 1 = short, 2 = long) */
718 false, /* pc_relative */
720 complain_overflow_bitfield
, /* complain_on_overflow */
721 0, /* special_function */
723 true, /* partial_inplace */
724 0xffff, /* src_mask */
725 0xffff, /* dst_mask */
726 false), /* pcrel_offset */
728 /* Modifiable branch relative. */
729 HOWTO (0x1a, /* type */
731 2, /* size (0 = byte, 1 = short, 2 = long) */
733 false, /* pc_relative */
735 complain_overflow_signed
, /* complain_on_overflow */
736 0, /* special_function */
738 true, /* partial_inplace */
739 0xffff, /* src_mask */
740 0xffff, /* dst_mask */
741 false), /* pcrel_offset */
743 /* Modifiable branch absolute. */
744 HOWTO (0x1b, /* type */
746 2, /* size (0 = byte, 1 = short, 2 = long) */
748 false, /* pc_relative */
750 complain_overflow_bitfield
, /* complain_on_overflow */
751 0, /* special_function */
753 true, /* partial_inplace */
754 0xffff, /* src_mask */
755 0xffff, /* dst_mask */
756 false), /* pcrel_offset */
759 4, /* size (0 = byte, 1 = short, 2 = long) */
761 false, /* pc_relative */
763 complain_overflow_bitfield
, /* complain_on_overflow */
764 0, /* special_function */
766 true, /* partial_inplace */
767 MINUS_ONE
, /* src_mask */
768 MINUS_ONE
, /* dst_mask */
769 false) /* pcrel_offset */
773 /* These are the first two like the above but for 16-bit relocs. */
774 static reloc_howto_type xcoff_howto_table_16
[] =
776 /* Standard 16 bit relocation. */
779 2, /* size (0 = byte, 1 = short, 2 = long) */
781 false, /* pc_relative */
783 complain_overflow_bitfield
, /* complain_on_overflow */
784 0, /* special_function */
785 "R_POS_16", /* name */
786 true, /* partial_inplace */
787 0xffffffff, /* src_mask */
788 0xffffffff, /* dst_mask */
789 false), /* pcrel_offset */
791 /* 16 bit relocation, but store negative value. */
794 -2, /* size (0 = byte, 1 = short, 2 = long) */
796 false, /* pc_relative */
798 complain_overflow_bitfield
, /* complain_on_overflow */
799 0, /* special_function */
800 "R_NEG_16", /* name */
801 true, /* partial_inplace */
802 0xffffffff, /* src_mask */
803 0xffffffff, /* dst_mask */
804 false), /* pcrel_offset */
806 /* 16 bit PC relative relocation. */
809 2, /* size (0 = byte, 1 = short, 2 = long) */
811 true, /* pc_relative */
813 complain_overflow_signed
, /* complain_on_overflow */
814 0, /* special_function */
815 "R_REL_16", /* name */
816 true, /* partial_inplace */
817 0xffffffff, /* src_mask */
818 0xffffffff, /* dst_mask */
819 false) /* pcrel_offset */
823 _bfd_xcoff_rtype2howto (relent
, internal
)
825 struct internal_reloc
*internal
;
827 relent
->howto
= xcoff_howto_table
+ internal
->r_type
;
829 if (relent
->howto
->bitsize
!= ((unsigned int) internal
->r_size
& 0x1f) + 1
831 < sizeof (xcoff_howto_table_16
)/sizeof (xcoff_howto_table_16
[0])))
832 relent
->howto
= xcoff_howto_table_16
+ internal
->r_type
;
834 /* The r_size field of an XCOFF reloc encodes the bitsize of the
835 relocation, as well as indicating whether it is signed or not.
836 Doublecheck that the relocation information gathered from the
837 type matches this information. The bitsize is not significant
839 if (relent
->howto
->dst_mask
!= 0
840 && (relent
->howto
->bitsize
841 != ((unsigned int) internal
->r_size
& 0x3f) + 1))
844 if ((internal
->r_size
& 0x80) != 0
845 ? (relent
->howto
->complain_on_overflow
!= complain_overflow_signed
)
846 : (relent
->howto
->complain_on_overflow
!= complain_overflow_bitfield
))
852 _bfd_xcoff_reloc_type_lookup (abfd
, code
)
853 bfd
*abfd ATTRIBUTE_UNUSED
;
854 bfd_reloc_code_real_type code
;
858 case BFD_RELOC_PPC_B26
:
859 return &xcoff_howto_table
[0xa];
860 case BFD_RELOC_PPC_BA26
:
861 return &xcoff_howto_table
[8];
862 case BFD_RELOC_PPC_TOC16
:
863 return &xcoff_howto_table
[3];
866 return &xcoff_howto_table
[0];
868 return &xcoff_howto_table
[0x1c];
874 /* XCOFF archive support. The original version of this code was by
875 Damon A. Permezel. It was enhanced to permit cross support, and
876 writing archive files, by Ian Lance Taylor, Cygnus Support.
878 XCOFF uses its own archive format. Everything is hooked together
879 with file offset links, so it is possible to rapidly update an
880 archive in place. Of course, we don't do that. An XCOFF archive
881 has a real file header, not just an ARMAG string. The structure of
882 the file header and of each archive header appear below.
884 An XCOFF archive also has a member table, which is a list of
885 elements in the archive (you can get that by looking through the
886 linked list, but you have to read a lot more of the file). The
887 member table has a normal archive header with an empty name. It is
888 normally (and perhaps must be) the second to last entry in the
889 archive. The member table data is almost printable ASCII. It
890 starts with a 12 character decimal string which is the number of
891 entries in the table. For each entry it has a 12 character decimal
892 string which is the offset in the archive of that member. These
893 entries are followed by a series of null terminated strings which
894 are the member names for each entry.
896 Finally, an XCOFF archive has a global symbol table, which is what
897 we call the armap. The global symbol table has a normal archive
898 header with an empty name. It is normally (and perhaps must be)
899 the last entry in the archive. The contents start with a four byte
900 binary number which is the number of entries. This is followed by
901 a that many four byte binary numbers; each is the file offset of an
902 entry in the archive. These numbers are followed by a series of
903 null terminated strings, which are symbol names.
905 AIX 4.3 introduced a new archive format which can handle larger
906 files and also 32- and 64-bit objects in the same archive. The
907 things said above remain true except that there is now more than
908 one global symbol table. The one is used to index 32-bit objects,
909 the other for 64-bit objects.
911 The new archives (recognizable by the new ARMAG string) has larger
912 field lengths so that we cannot really share any code. Also we have
913 to take care that we are not generating the new form of archives
914 on AIX 4.2 or earlier systems. */
916 /* XCOFF archives use this as a magic string. Note that both strings
917 have the same length. */
919 #define XCOFFARMAG "<aiaff>\012"
920 #define XCOFFARMAGBIG "<bigaf>\012"
921 #define SXCOFFARMAG 8
923 /* This terminates an XCOFF archive member name. */
925 #define XCOFFARFMAG "`\012"
926 #define SXCOFFARFMAG 2
928 /* XCOFF archives start with this (printable) structure. */
930 struct xcoff_ar_file_hdr
933 char magic
[SXCOFFARMAG
];
935 /* Offset of the member table (decimal ASCII string). */
938 /* Offset of the global symbol table (decimal ASCII string). */
941 /* Offset of the first member in the archive (decimal ASCII string). */
942 char firstmemoff
[12];
944 /* Offset of the last member in the archive (decimal ASCII string). */
947 /* Offset of the first member on the free list (decimal ASCII
952 #define SIZEOF_AR_FILE_HDR (5 * 12 + SXCOFFARMAG)
954 /* This is the equivalent data structure for the big archive format. */
956 struct xcoff_ar_file_hdr_big
959 char magic
[SXCOFFARMAG
];
961 /* Offset of the member table (decimal ASCII string). */
964 /* Offset of the global symbol table for 32-bit objects (decimal ASCII
968 /* Offset of the global symbol table for 64-bit objects (decimal ASCII
972 /* Offset of the first member in the archive (decimal ASCII string). */
973 char firstmemoff
[20];
975 /* Offset of the last member in the archive (decimal ASCII string). */
978 /* Offset of the first member on the free list (decimal ASCII
983 #define SIZEOF_AR_FILE_HDR_BIG (6 * 20 + SXCOFFARMAG)
985 /* Each XCOFF archive member starts with this (printable) structure. */
989 /* File size not including the header (decimal ASCII string). */
992 /* File offset of next archive member (decimal ASCII string). */
995 /* File offset of previous archive member (decimal ASCII string). */
998 /* File mtime (decimal ASCII string). */
1001 /* File UID (decimal ASCII string). */
1004 /* File GID (decimal ASCII string). */
1007 /* File mode (octal ASCII string). */
1010 /* Length of file name (decimal ASCII string). */
1013 /* This structure is followed by the file name. The length of the
1014 name is given in the namlen field. If the length of the name is
1015 odd, the name is followed by a null byte. The name and optional
1016 null byte are followed by XCOFFARFMAG, which is not included in
1017 namlen. The contents of the archive member follow; the number of
1018 bytes is given in the size field. */
1021 #define SIZEOF_AR_HDR (7 * 12 + 4)
1023 /* The equivalent for the big archive format. */
1025 struct xcoff_ar_hdr_big
1027 /* File size not including the header (decimal ASCII string). */
1030 /* File offset of next archive member (decimal ASCII string). */
1033 /* File offset of previous archive member (decimal ASCII string). */
1036 /* File mtime (decimal ASCII string). */
1039 /* File UID (decimal ASCII string). */
1042 /* File GID (decimal ASCII string). */
1045 /* File mode (octal ASCII string). */
1048 /* Length of file name (decimal ASCII string). */
1051 /* This structure is followed by the file name. The length of the
1052 name is given in the namlen field. If the length of the name is
1053 odd, the name is followed by a null byte. The name and optional
1054 null byte are followed by XCOFFARFMAG, which is not included in
1055 namlen. The contents of the archive member follow; the number of
1056 bytes is given in the size field. */
1059 #define SIZEOF_AR_HDR_BIG (3 * 20 + 4 * 12 + 4)
1061 /* We often have to distinguish between the old and big file format.
1062 Make it a bit cleaner. We can use `xcoff_ardata' here because the
1063 `hdr' member has the same size and position in both formats. */
1064 #define xcoff_big_format_p(abfd) \
1065 (xcoff_ardata (abfd)->magic[1] == 'b')
1067 /* We store a copy of the xcoff_ar_file_hdr in the tdata field of the
1068 artdata structure. Similar for the big archive. */
1069 #define xcoff_ardata(abfd) \
1070 ((struct xcoff_ar_file_hdr *) bfd_ardata (abfd)->tdata)
1071 #define xcoff_ardata_big(abfd) \
1072 ((struct xcoff_ar_file_hdr_big *) bfd_ardata (abfd)->tdata)
1074 /* We store a copy of the xcoff_ar_hdr in the arelt_data field of an
1075 archive element. Similar for the big archive. */
1076 #define arch_eltdata(bfd) ((struct areltdata *) ((bfd)->arelt_data))
1077 #define arch_xhdr(bfd) \
1078 ((struct xcoff_ar_hdr *) arch_eltdata (bfd)->arch_header)
1079 #define arch_xhdr_big(bfd) \
1080 ((struct xcoff_ar_hdr_big *) arch_eltdata (bfd)->arch_header)
1082 /* Read in the armap of an XCOFF archive. */
1085 _bfd_xcoff_slurp_armap (abfd
)
1091 bfd_byte
*contents
, *cend
;
1096 if (xcoff_ardata (abfd
) == NULL
)
1098 bfd_has_map (abfd
) = false;
1102 if (! xcoff_big_format_p (abfd
))
1104 /* This is for the old format. */
1105 struct xcoff_ar_hdr hdr
;
1107 off
= strtol (xcoff_ardata (abfd
)->symoff
, (char **) NULL
, 10);
1110 bfd_has_map (abfd
) = false;
1114 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0)
1117 /* The symbol table starts with a normal archive header. */
1118 if (bfd_read ((PTR
) &hdr
, SIZEOF_AR_HDR
, 1, abfd
) != SIZEOF_AR_HDR
)
1121 /* Skip the name (normally empty). */
1122 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1123 if (bfd_seek (abfd
, ((namlen
+ 1) & ~1) + SXCOFFARFMAG
, SEEK_CUR
) != 0)
1126 sz
= strtol (hdr
.size
, (char **) NULL
, 10);
1128 /* Read in the entire symbol table. */
1129 contents
= (bfd_byte
*) bfd_alloc (abfd
, sz
);
1130 if (contents
== NULL
)
1132 if (bfd_read ((PTR
) contents
, 1, sz
, abfd
) != sz
)
1135 /* The symbol table starts with a four byte count. */
1136 c
= bfd_h_get_32 (abfd
, contents
);
1140 bfd_set_error (bfd_error_bad_value
);
1144 bfd_ardata (abfd
)->symdefs
= ((carsym
*)
1145 bfd_alloc (abfd
, c
* sizeof (carsym
)));
1146 if (bfd_ardata (abfd
)->symdefs
== NULL
)
1149 /* After the count comes a list of four byte file offsets. */
1150 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
, p
= contents
+ 4;
1152 ++i
, ++arsym
, p
+= 4)
1153 arsym
->file_offset
= bfd_h_get_32 (abfd
, p
);
1157 /* This is for the new format. */
1158 struct xcoff_ar_hdr_big hdr
;
1160 off
= strtol (xcoff_ardata_big (abfd
)->symoff
, (char **) NULL
, 10);
1163 bfd_has_map (abfd
) = false;
1167 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0)
1170 /* The symbol table starts with a normal archive header. */
1171 if (bfd_read ((PTR
) &hdr
, SIZEOF_AR_HDR_BIG
, 1, abfd
)
1172 != SIZEOF_AR_HDR_BIG
)
1175 /* Skip the name (normally empty). */
1176 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1177 if (bfd_seek (abfd
, ((namlen
+ 1) & ~1) + SXCOFFARFMAG
, SEEK_CUR
) != 0)
1180 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1181 machines) since the field width is 20 and there numbers with more
1182 than 32 bits can be represented. */
1183 sz
= strtol (hdr
.size
, (char **) NULL
, 10);
1185 /* Read in the entire symbol table. */
1186 contents
= (bfd_byte
*) bfd_alloc (abfd
, sz
);
1187 if (contents
== NULL
)
1189 if (bfd_read ((PTR
) contents
, 1, sz
, abfd
) != sz
)
1192 /* The symbol table starts with an eight byte count. */
1193 c
= bfd_h_get_64 (abfd
, contents
);
1197 bfd_set_error (bfd_error_bad_value
);
1201 bfd_ardata (abfd
)->symdefs
= ((carsym
*)
1202 bfd_alloc (abfd
, c
* sizeof (carsym
)));
1203 if (bfd_ardata (abfd
)->symdefs
== NULL
)
1206 /* After the count comes a list of eight byte file offsets. */
1207 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
, p
= contents
+ 8;
1209 ++i
, ++arsym
, p
+= 8)
1210 arsym
->file_offset
= bfd_h_get_64 (abfd
, p
);
1213 /* After the file offsets come null terminated symbol names. */
1214 cend
= contents
+ sz
;
1215 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
;
1217 ++i
, ++arsym
, p
+= strlen ((char *) p
) + 1)
1221 bfd_set_error (bfd_error_bad_value
);
1224 arsym
->name
= (char *) p
;
1227 bfd_ardata (abfd
)->symdef_count
= c
;
1228 bfd_has_map (abfd
) = true;
1233 /* See if this is an XCOFF archive. */
1236 _bfd_xcoff_archive_p (abfd
)
1239 char magic
[SXCOFFARMAG
];
1241 if (bfd_read ((PTR
) magic
, SXCOFFARMAG
, 1, abfd
) != SXCOFFARMAG
)
1243 if (bfd_get_error () != bfd_error_system_call
)
1244 bfd_set_error (bfd_error_wrong_format
);
1248 if (strncmp (magic
, XCOFFARMAG
, SXCOFFARMAG
) != 0
1249 && strncmp (magic
, XCOFFARMAGBIG
, SXCOFFARMAG
) != 0)
1251 bfd_set_error (bfd_error_wrong_format
);
1255 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
1256 involves a cast, we can't do it as the left operand of
1258 abfd
->tdata
.aout_ar_data
=
1259 (struct artdata
*) bfd_zalloc (abfd
, sizeof (struct artdata
));
1261 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
1264 bfd_ardata (abfd
)->cache
= NULL
;
1265 bfd_ardata (abfd
)->archive_head
= NULL
;
1266 bfd_ardata (abfd
)->symdefs
= NULL
;
1267 bfd_ardata (abfd
)->extended_names
= NULL
;
1269 /* Now handle the two formats. */
1270 if (magic
[1] != 'b')
1272 /* This is the old format. */
1273 struct xcoff_ar_file_hdr hdr
;
1275 /* Copy over the magic string. */
1276 memcpy (hdr
.magic
, magic
, SXCOFFARMAG
);
1278 /* Now read the rest of the file header. */
1279 if (bfd_read ((PTR
) &hdr
.memoff
, SIZEOF_AR_FILE_HDR
- SXCOFFARMAG
, 1,
1280 abfd
) != SIZEOF_AR_FILE_HDR
- SXCOFFARMAG
)
1282 if (bfd_get_error () != bfd_error_system_call
)
1283 bfd_set_error (bfd_error_wrong_format
);
1287 bfd_ardata (abfd
)->first_file_filepos
= strtol (hdr
.firstmemoff
,
1288 (char **) NULL
, 10);
1290 bfd_ardata (abfd
)->tdata
= bfd_zalloc (abfd
, SIZEOF_AR_FILE_HDR
);
1291 if (bfd_ardata (abfd
)->tdata
== NULL
)
1294 memcpy (bfd_ardata (abfd
)->tdata
, &hdr
, SIZEOF_AR_FILE_HDR
);
1298 /* This is the new format. */
1299 struct xcoff_ar_file_hdr_big hdr
;
1301 /* Copy over the magic string. */
1302 memcpy (hdr
.magic
, magic
, SXCOFFARMAG
);
1304 /* Now read the rest of the file header. */
1305 if (bfd_read ((PTR
) &hdr
.memoff
, SIZEOF_AR_FILE_HDR_BIG
- SXCOFFARMAG
, 1,
1306 abfd
) != SIZEOF_AR_FILE_HDR_BIG
- SXCOFFARMAG
)
1308 if (bfd_get_error () != bfd_error_system_call
)
1309 bfd_set_error (bfd_error_wrong_format
);
1313 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1314 machines) since the field width is 20 and there numbers with more
1315 than 32 bits can be represented. */
1316 bfd_ardata (abfd
)->first_file_filepos
= strtol (hdr
.firstmemoff
,
1317 (char **) NULL
, 10);
1319 bfd_ardata (abfd
)->tdata
= bfd_zalloc (abfd
, SIZEOF_AR_FILE_HDR_BIG
);
1320 if (bfd_ardata (abfd
)->tdata
== NULL
)
1323 memcpy (bfd_ardata (abfd
)->tdata
, &hdr
, SIZEOF_AR_FILE_HDR_BIG
);
1326 if (! _bfd_xcoff_slurp_armap (abfd
))
1328 bfd_release (abfd
, bfd_ardata (abfd
));
1329 abfd
->tdata
.aout_ar_data
= (struct artdata
*) NULL
;
1336 /* Read the archive header in an XCOFF archive. */
1339 _bfd_xcoff_read_ar_hdr (abfd
)
1343 struct areltdata
*ret
;
1345 ret
= (struct areltdata
*) bfd_alloc (abfd
, sizeof (struct areltdata
));
1349 if (! xcoff_big_format_p (abfd
))
1351 struct xcoff_ar_hdr hdr
;
1352 struct xcoff_ar_hdr
*hdrp
;
1354 if (bfd_read ((PTR
) &hdr
, SIZEOF_AR_HDR
, 1, abfd
) != SIZEOF_AR_HDR
)
1360 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1361 hdrp
= (struct xcoff_ar_hdr
*) bfd_alloc (abfd
,
1362 SIZEOF_AR_HDR
+ namlen
+ 1);
1368 memcpy (hdrp
, &hdr
, SIZEOF_AR_HDR
);
1369 if (bfd_read ((char *) hdrp
+ SIZEOF_AR_HDR
, 1, namlen
, abfd
) != namlen
)
1374 ((char *) hdrp
)[SIZEOF_AR_HDR
+ namlen
] = '\0';
1376 ret
->arch_header
= (char *) hdrp
;
1377 ret
->parsed_size
= strtol (hdr
.size
, (char **) NULL
, 10);
1378 ret
->filename
= (char *) hdrp
+ SIZEOF_AR_HDR
;
1382 struct xcoff_ar_hdr_big hdr
;
1383 struct xcoff_ar_hdr_big
*hdrp
;
1385 if (bfd_read ((PTR
) &hdr
, SIZEOF_AR_HDR_BIG
, 1, abfd
)
1386 != SIZEOF_AR_HDR_BIG
)
1392 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1393 hdrp
= (struct xcoff_ar_hdr_big
*) bfd_alloc (abfd
,
1401 memcpy (hdrp
, &hdr
, SIZEOF_AR_HDR_BIG
);
1402 if (bfd_read ((char *) hdrp
+ SIZEOF_AR_HDR_BIG
, 1, namlen
, abfd
) != namlen
)
1407 ((char *) hdrp
)[SIZEOF_AR_HDR_BIG
+ namlen
] = '\0';
1409 ret
->arch_header
= (char *) hdrp
;
1410 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1411 machines) since the field width is 20 and there numbers with more
1412 than 32 bits can be represented. */
1413 ret
->parsed_size
= strtol (hdr
.size
, (char **) NULL
, 10);
1414 ret
->filename
= (char *) hdrp
+ SIZEOF_AR_HDR_BIG
;
1417 /* Skip over the XCOFFARFMAG at the end of the file name. */
1418 if (bfd_seek (abfd
, (namlen
& 1) + SXCOFFARFMAG
, SEEK_CUR
) != 0)
1424 /* Open the next element in an XCOFF archive. */
1427 _bfd_xcoff_openr_next_archived_file (archive
, last_file
)
1433 if (xcoff_ardata (archive
) == NULL
)
1435 bfd_set_error (bfd_error_invalid_operation
);
1439 if (! xcoff_big_format_p (archive
))
1441 if (last_file
== NULL
)
1442 filestart
= bfd_ardata (archive
)->first_file_filepos
;
1444 filestart
= strtol (arch_xhdr (last_file
)->nextoff
, (char **) NULL
,
1448 || filestart
== strtol (xcoff_ardata (archive
)->memoff
,
1450 || filestart
== strtol (xcoff_ardata (archive
)->symoff
,
1451 (char **) NULL
, 10))
1453 bfd_set_error (bfd_error_no_more_archived_files
);
1459 if (last_file
== NULL
)
1460 filestart
= bfd_ardata (archive
)->first_file_filepos
;
1462 /* XXX These actually have to be a calls to strtoll (at least
1463 on 32-bit machines) since the fields's width is 20 and
1464 there numbers with more than 32 bits can be represented. */
1465 filestart
= strtol (arch_xhdr_big (last_file
)->nextoff
, (char **) NULL
,
1468 /* XXX These actually have to be calls to strtoll (at least on 32-bit
1469 machines) since the fields's width is 20 and there numbers with more
1470 than 32 bits can be represented. */
1472 || filestart
== strtol (xcoff_ardata_big (archive
)->memoff
,
1474 || filestart
== strtol (xcoff_ardata_big (archive
)->symoff
,
1475 (char **) NULL
, 10))
1477 bfd_set_error (bfd_error_no_more_archived_files
);
1482 return _bfd_get_elt_at_filepos (archive
, filestart
);
1485 /* Stat an element in an XCOFF archive. */
1488 _bfd_xcoff_generic_stat_arch_elt (abfd
, s
)
1492 if (abfd
->arelt_data
== NULL
)
1494 bfd_set_error (bfd_error_invalid_operation
);
1498 if (! xcoff_big_format_p (abfd
))
1500 struct xcoff_ar_hdr
*hdrp
= arch_xhdr (abfd
);
1502 s
->st_mtime
= strtol (hdrp
->date
, (char **) NULL
, 10);
1503 s
->st_uid
= strtol (hdrp
->uid
, (char **) NULL
, 10);
1504 s
->st_gid
= strtol (hdrp
->gid
, (char **) NULL
, 10);
1505 s
->st_mode
= strtol (hdrp
->mode
, (char **) NULL
, 8);
1506 s
->st_size
= arch_eltdata (abfd
)->parsed_size
;
1510 struct xcoff_ar_hdr_big
*hdrp
= arch_xhdr_big (abfd
);
1512 s
->st_mtime
= strtol (hdrp
->date
, (char **) NULL
, 10);
1513 s
->st_uid
= strtol (hdrp
->uid
, (char **) NULL
, 10);
1514 s
->st_gid
= strtol (hdrp
->gid
, (char **) NULL
, 10);
1515 s
->st_mode
= strtol (hdrp
->mode
, (char **) NULL
, 8);
1516 s
->st_size
= arch_eltdata (abfd
)->parsed_size
;
1522 /* Normalize a file name for inclusion in an archive. */
1525 normalize_filename (abfd
)
1529 const char *filename
;
1531 file
= bfd_get_filename (abfd
);
1532 filename
= strrchr (file
, '/');
1533 if (filename
!= NULL
)
1540 /* Write out an XCOFF armap. */
1543 xcoff_write_armap_old (abfd
, elength
, map
, orl_count
, stridx
)
1545 unsigned int elength ATTRIBUTE_UNUSED
;
1547 unsigned int orl_count
;
1550 struct xcoff_ar_hdr hdr
;
1552 unsigned char buf
[4];
1557 memset (&hdr
, 0, sizeof hdr
);
1558 sprintf (hdr
.size
, "%ld", (long) (4 + orl_count
* 4 + stridx
));
1559 sprintf (hdr
.nextoff
, "%d", 0);
1560 memcpy (hdr
.prevoff
, xcoff_ardata (abfd
)->memoff
, 12);
1561 sprintf (hdr
.date
, "%d", 0);
1562 sprintf (hdr
.uid
, "%d", 0);
1563 sprintf (hdr
.gid
, "%d", 0);
1564 sprintf (hdr
.mode
, "%d", 0);
1565 sprintf (hdr
.namlen
, "%d", 0);
1567 /* We need spaces, not null bytes, in the header. */
1568 for (p
= (char *) &hdr
; p
< (char *) &hdr
+ SIZEOF_AR_HDR
; p
++)
1572 if (bfd_write ((PTR
) &hdr
, SIZEOF_AR_HDR
, 1, abfd
) != SIZEOF_AR_HDR
1573 || bfd_write (XCOFFARFMAG
, 1, SXCOFFARFMAG
, abfd
) != SXCOFFARFMAG
)
1576 bfd_h_put_32 (abfd
, orl_count
, buf
);
1577 if (bfd_write (buf
, 1, 4, abfd
) != 4)
1580 sub
= abfd
->archive_head
;
1581 fileoff
= SIZEOF_AR_FILE_HDR
;
1583 while (sub
!= NULL
&& i
< orl_count
)
1587 while (((bfd
*) (map
[i
]).pos
) == sub
)
1589 bfd_h_put_32 (abfd
, fileoff
, buf
);
1590 if (bfd_write (buf
, 1, 4, abfd
) != 4)
1594 namlen
= strlen (normalize_filename (sub
));
1595 namlen
= (namlen
+ 1) &~ 1;
1596 fileoff
+= (SIZEOF_AR_HDR
1599 + arelt_size (sub
));
1600 fileoff
= (fileoff
+ 1) &~ 1;
1604 for (i
= 0; i
< orl_count
; i
++)
1609 name
= *map
[i
].name
;
1610 namlen
= strlen (name
);
1611 if (bfd_write (name
, 1, namlen
+ 1, abfd
) != namlen
+ 1)
1615 if ((stridx
& 1) != 0)
1620 if (bfd_write (&b
, 1, 1, abfd
) != 1)
1627 /* Write a single armap in the big format. */
1629 xcoff_write_one_armap_big (abfd
, map
, orl_count
, orl_ccount
, stridx
, bits64
,
1633 unsigned int orl_count
;
1634 unsigned int orl_ccount
;
1635 unsigned int stridx
;
1637 const char *prevoff
;
1640 struct xcoff_ar_hdr_big hdr
;
1642 unsigned char buf
[4];
1643 const bfd_arch_info_type
*arch_info
= NULL
;
1649 memset (&hdr
, 0, sizeof hdr
);
1650 /* XXX This call actually should use %lld (at least on 32-bit
1651 machines) since the fields's width is 20 and there numbers with
1652 more than 32 bits can be represented. */
1653 sprintf (hdr
.size
, "%ld", (long) (4 + orl_ccount
* 4 + stridx
));
1655 sprintf (hdr
.nextoff
, "%d", 0);
1657 sprintf (hdr
.nextoff
, "%ld", (strtol (prevoff
, (char **) NULL
, 10)
1658 + 4 + orl_ccount
* 4 + stridx
));
1659 memcpy (hdr
.prevoff
, prevoff
, sizeof (hdr
.prevoff
));
1660 sprintf (hdr
.date
, "%d", 0);
1661 sprintf (hdr
.uid
, "%d", 0);
1662 sprintf (hdr
.gid
, "%d", 0);
1663 sprintf (hdr
.mode
, "%d", 0);
1664 sprintf (hdr
.namlen
, "%d", 0);
1666 /* We need spaces, not null bytes, in the header. */
1667 for (p
= (char *) &hdr
; p
< (char *) &hdr
+ SIZEOF_AR_HDR_BIG
; p
++)
1671 memcpy (nextoff
, hdr
.nextoff
, sizeof (hdr
.nextoff
));
1673 if (bfd_write ((PTR
) &hdr
, SIZEOF_AR_HDR_BIG
, 1, abfd
) != SIZEOF_AR_HDR_BIG
1674 || bfd_write (XCOFFARFMAG
, 1, SXCOFFARFMAG
, abfd
) != SXCOFFARFMAG
)
1677 bfd_h_put_32 (abfd
, orl_ccount
, buf
);
1678 if (bfd_write (buf
, 1, 4, abfd
) != 4)
1681 sub
= abfd
->archive_head
;
1682 fileoff
= SIZEOF_AR_FILE_HDR_BIG
;
1684 while (sub
!= NULL
&& i
< orl_count
)
1688 if ((bfd_arch_bits_per_address ((bfd
*) map
[i
].pos
) == 64) == bits64
)
1689 while (((bfd
*) (map
[i
]).pos
) == sub
)
1691 bfd_h_put_32 (abfd
, fileoff
, buf
);
1692 if (bfd_write (buf
, 1, 4, abfd
) != 4)
1697 while (((bfd
*) (map
[i
]).pos
) == sub
)
1700 namlen
= strlen (normalize_filename (sub
));
1701 namlen
= (namlen
+ 1) &~ 1;
1702 fileoff
+= (SIZEOF_AR_HDR_BIG
1705 + arelt_size (sub
));
1706 fileoff
= (fileoff
+ 1) &~ 1;
1711 for (i
= 0; i
< orl_count
; i
++)
1715 bfd
*ob
= (bfd
*)map
[i
].pos
;
1717 if (ob
!= object_bfd
)
1718 arch_info
= bfd_get_arch_info (ob
);
1720 if (arch_info
&& (arch_info
->bits_per_address
== 64) != bits64
)
1723 name
= *map
[i
].name
;
1724 namlen
= strlen (name
);
1725 if (bfd_write (name
, 1, namlen
+ 1, abfd
) != namlen
+ 1)
1729 if ((stridx
& 1) != 0)
1734 if (bfd_write (&b
, 1, 1, abfd
) != 1)
1742 xcoff_write_armap_big (abfd
, elength
, map
, orl_count
, stridx
)
1744 unsigned int elength ATTRIBUTE_UNUSED
;
1746 unsigned int orl_count
;
1750 unsigned int orl_count_32
, orl_count_64
;
1751 unsigned int stridx_32
, stridx_64
;
1752 const bfd_arch_info_type
*arch_info
= NULL
;
1755 /* First, we look through the symbols and work out which are
1756 from 32-bit objects and which from 64-bit ones. */
1762 for (i
= 0; i
< orl_count
; i
++)
1764 bfd
*ob
= (bfd
*)map
[i
].pos
;
1766 if (ob
!= object_bfd
)
1767 arch_info
= bfd_get_arch_info (ob
);
1768 len
= strlen (*map
[i
].name
) + 1;
1769 if (arch_info
&& arch_info
->bits_per_address
== 64)
1781 /* A quick sanity check... */
1782 BFD_ASSERT (orl_count_64
+ orl_count_32
== orl_count
);
1783 BFD_ASSERT (stridx_64
+ stridx_32
== stridx
);
1785 /* Now write out each map. */
1786 if (! xcoff_write_one_armap_big (abfd
, map
, orl_count
, orl_count_32
,
1788 xcoff_ardata_big (abfd
)->memoff
,
1789 xcoff_ardata_big (abfd
)->symoff
))
1791 if (! xcoff_write_one_armap_big (abfd
, map
, orl_count
, orl_count_64
,
1793 xcoff_ardata_big (abfd
)->symoff
,
1794 xcoff_ardata_big (abfd
)->symoff64
))
1801 _bfd_xcoff_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
1803 unsigned int elength ATTRIBUTE_UNUSED
;
1805 unsigned int orl_count
;
1808 if (! xcoff_big_format_p (abfd
))
1809 return xcoff_write_armap_old (abfd
, elength
, map
, orl_count
, stridx
);
1811 return xcoff_write_armap_big (abfd
, elength
, map
, orl_count
, stridx
);
1814 /* Write out an XCOFF archive. We always write an entire archive,
1815 rather than fussing with the freelist and so forth. */
1818 xcoff_write_archive_contents_old (abfd
)
1821 struct xcoff_ar_file_hdr fhdr
;
1823 size_t total_namlen
;
1827 file_ptr prevoff
, nextoff
;
1830 struct xcoff_ar_hdr ahdr
;
1835 memset (&fhdr
, 0, sizeof fhdr
);
1836 strncpy (fhdr
.magic
, XCOFFARMAG
, SXCOFFARMAG
);
1837 sprintf (fhdr
.firstmemoff
, "%d", SIZEOF_AR_FILE_HDR
);
1838 sprintf (fhdr
.freeoff
, "%d", 0);
1842 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->next
)
1845 total_namlen
+= strlen (normalize_filename (sub
)) + 1;
1847 offsets
= (file_ptr
*) bfd_alloc (abfd
, count
* sizeof (file_ptr
));
1848 if (offsets
== NULL
)
1851 if (bfd_seek (abfd
, SIZEOF_AR_FILE_HDR
, SEEK_SET
) != 0)
1854 makemap
= bfd_has_map (abfd
);
1857 nextoff
= SIZEOF_AR_FILE_HDR
;
1858 for (sub
= abfd
->archive_head
, i
= 0; sub
!= NULL
; sub
= sub
->next
, i
++)
1862 struct xcoff_ar_hdr
*ahdrp
;
1863 bfd_size_type remaining
;
1865 if (makemap
&& ! hasobjects
)
1867 if (bfd_check_format (sub
, bfd_object
))
1871 name
= normalize_filename (sub
);
1872 namlen
= strlen (name
);
1874 if (sub
->arelt_data
!= NULL
)
1875 ahdrp
= arch_xhdr (sub
);
1883 memset (&ahdr
, 0, sizeof ahdr
);
1885 if (stat (bfd_get_filename (sub
), &s
) != 0)
1887 bfd_set_error (bfd_error_system_call
);
1891 sprintf (ahdrp
->size
, "%ld", (long) s
.st_size
);
1892 sprintf (ahdrp
->date
, "%ld", (long) s
.st_mtime
);
1893 sprintf (ahdrp
->uid
, "%ld", (long) s
.st_uid
);
1894 sprintf (ahdrp
->gid
, "%ld", (long) s
.st_gid
);
1895 sprintf (ahdrp
->mode
, "%o", (unsigned int) s
.st_mode
);
1897 if (sub
->arelt_data
== NULL
)
1899 sub
->arelt_data
= bfd_alloc (sub
, sizeof (struct areltdata
));
1900 if (sub
->arelt_data
== NULL
)
1904 arch_eltdata (sub
)->parsed_size
= s
.st_size
;
1907 sprintf (ahdrp
->prevoff
, "%ld", (long) prevoff
);
1908 sprintf (ahdrp
->namlen
, "%ld", (long) namlen
);
1910 /* If the length of the name is odd, we write out the null byte
1911 after the name as well. */
1912 namlen
= (namlen
+ 1) &~ 1;
1914 remaining
= arelt_size (sub
);
1915 size
= (SIZEOF_AR_HDR
1920 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
1922 offsets
[i
] = nextoff
;
1925 nextoff
+= size
+ (size
& 1);
1927 sprintf (ahdrp
->nextoff
, "%ld", (long) nextoff
);
1929 /* We need spaces, not null bytes, in the header. */
1930 for (p
= (char *) ahdrp
; p
< (char *) ahdrp
+ SIZEOF_AR_HDR
; p
++)
1934 if (bfd_write ((PTR
) ahdrp
, 1, SIZEOF_AR_HDR
, abfd
) != SIZEOF_AR_HDR
1935 || bfd_write ((PTR
) name
, 1, namlen
, abfd
) != namlen
1936 || (bfd_write ((PTR
) XCOFFARFMAG
, 1, SXCOFFARFMAG
, abfd
)
1940 if (bfd_seek (sub
, (file_ptr
) 0, SEEK_SET
) != 0)
1942 while (remaining
!= 0)
1945 bfd_byte buffer
[DEFAULT_BUFFERSIZE
];
1947 amt
= sizeof buffer
;
1948 if (amt
> remaining
)
1950 if (bfd_read (buffer
, 1, amt
, sub
) != amt
1951 || bfd_write (buffer
, 1, amt
, abfd
) != amt
)
1956 if ((size
& 1) != 0)
1961 if (bfd_write (&b
, 1, 1, abfd
) != 1)
1966 sprintf (fhdr
.lastmemoff
, "%ld", (long) prevoff
);
1968 /* Write out the member table. */
1970 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
1971 sprintf (fhdr
.memoff
, "%ld", (long) nextoff
);
1973 memset (&ahdr
, 0, sizeof ahdr
);
1974 sprintf (ahdr
.size
, "%ld", (long) (12 + count
* 12 + total_namlen
));
1975 sprintf (ahdr
.prevoff
, "%ld", (long) prevoff
);
1976 sprintf (ahdr
.date
, "%d", 0);
1977 sprintf (ahdr
.uid
, "%d", 0);
1978 sprintf (ahdr
.gid
, "%d", 0);
1979 sprintf (ahdr
.mode
, "%d", 0);
1980 sprintf (ahdr
.namlen
, "%d", 0);
1982 size
= (SIZEOF_AR_HDR
1989 nextoff
+= size
+ (size
& 1);
1991 if (makemap
&& hasobjects
)
1992 sprintf (ahdr
.nextoff
, "%ld", (long) nextoff
);
1994 sprintf (ahdr
.nextoff
, "%d", 0);
1996 /* We need spaces, not null bytes, in the header. */
1997 for (p
= (char *) &ahdr
; p
< (char *) &ahdr
+ SIZEOF_AR_HDR
; p
++)
2001 if (bfd_write ((PTR
) &ahdr
, 1, SIZEOF_AR_HDR
, abfd
) != SIZEOF_AR_HDR
2002 || (bfd_write ((PTR
) XCOFFARFMAG
, 1, SXCOFFARFMAG
, abfd
)
2006 sprintf (decbuf
, "%-12ld", (long) count
);
2007 if (bfd_write ((PTR
) decbuf
, 1, 12, abfd
) != 12)
2009 for (i
= 0; i
< count
; i
++)
2011 sprintf (decbuf
, "%-12ld", (long) offsets
[i
]);
2012 if (bfd_write ((PTR
) decbuf
, 1, 12, abfd
) != 12)
2015 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->next
)
2020 name
= normalize_filename (sub
);
2021 namlen
= strlen (name
);
2022 if (bfd_write ((PTR
) name
, 1, namlen
+ 1, abfd
) != namlen
+ 1)
2025 if ((size
& 1) != 0)
2030 if (bfd_write ((PTR
) &b
, 1, 1, abfd
) != 1)
2034 /* Write out the armap, if appropriate. */
2036 if (! makemap
|| ! hasobjects
)
2037 sprintf (fhdr
.symoff
, "%d", 0);
2040 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2041 sprintf (fhdr
.symoff
, "%ld", (long) nextoff
);
2042 bfd_ardata (abfd
)->tdata
= (PTR
) &fhdr
;
2043 if (! _bfd_compute_and_write_armap (abfd
, 0))
2047 /* Write out the archive file header. */
2049 /* We need spaces, not null bytes, in the header. */
2050 for (p
= (char *) &fhdr
; p
< (char *) &fhdr
+ SIZEOF_AR_FILE_HDR
; p
++)
2054 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
2055 || (bfd_write ((PTR
) &fhdr
, SIZEOF_AR_FILE_HDR
, 1, abfd
) !=
2056 SIZEOF_AR_FILE_HDR
))
2063 xcoff_write_archive_contents_big (abfd
)
2066 struct xcoff_ar_file_hdr_big fhdr
;
2068 size_t total_namlen
;
2072 file_ptr prevoff
, nextoff
;
2075 struct xcoff_ar_hdr_big ahdr
;
2080 memset (&fhdr
, 0, sizeof fhdr
);
2081 strncpy (fhdr
.magic
, XCOFFARMAGBIG
, SXCOFFARMAG
);
2082 sprintf (fhdr
.firstmemoff
, "%d", SIZEOF_AR_FILE_HDR_BIG
);
2083 sprintf (fhdr
.freeoff
, "%d", 0);
2087 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->next
)
2090 total_namlen
+= strlen (normalize_filename (sub
)) + 1;
2092 offsets
= (file_ptr
*) bfd_alloc (abfd
, count
* sizeof (file_ptr
));
2093 if (offsets
== NULL
)
2096 if (bfd_seek (abfd
, SIZEOF_AR_FILE_HDR_BIG
, SEEK_SET
) != 0)
2099 makemap
= bfd_has_map (abfd
);
2102 nextoff
= SIZEOF_AR_FILE_HDR_BIG
;
2103 for (sub
= abfd
->archive_head
, i
= 0; sub
!= NULL
; sub
= sub
->next
, i
++)
2107 struct xcoff_ar_hdr_big
*ahdrp
;
2108 bfd_size_type remaining
;
2110 if (makemap
&& ! hasobjects
)
2112 if (bfd_check_format (sub
, bfd_object
))
2116 name
= normalize_filename (sub
);
2117 namlen
= strlen (name
);
2119 if (sub
->arelt_data
!= NULL
)
2120 ahdrp
= arch_xhdr_big (sub
);
2128 memset (&ahdr
, 0, sizeof ahdr
);
2130 /* XXX This should actually be a call to stat64 (at least on
2131 32-bit machines). */
2132 if (stat (bfd_get_filename (sub
), &s
) != 0)
2134 bfd_set_error (bfd_error_system_call
);
2138 /* XXX This call actually should use %lld (at least on 32-bit
2139 machines) since the fields's width is 20 and there numbers with
2140 more than 32 bits can be represented. */
2141 sprintf (ahdrp
->size
, "%ld", (long) s
.st_size
);
2142 sprintf (ahdrp
->date
, "%ld", (long) s
.st_mtime
);
2143 sprintf (ahdrp
->uid
, "%ld", (long) s
.st_uid
);
2144 sprintf (ahdrp
->gid
, "%ld", (long) s
.st_gid
);
2145 sprintf (ahdrp
->mode
, "%o", (unsigned int) s
.st_mode
);
2147 if (sub
->arelt_data
== NULL
)
2149 sub
->arelt_data
= bfd_alloc (sub
, sizeof (struct areltdata
));
2150 if (sub
->arelt_data
== NULL
)
2154 arch_eltdata (sub
)->parsed_size
= s
.st_size
;
2157 /* XXX These calls actually should use %lld (at least on 32-bit
2158 machines) since the fields's width is 20 and there numbers with
2159 more than 32 bits can be represented. */
2160 sprintf (ahdrp
->prevoff
, "%ld", (long) prevoff
);
2161 sprintf (ahdrp
->namlen
, "%ld", (long) namlen
);
2163 /* If the length of the name is odd, we write out the null byte
2164 after the name as well. */
2165 namlen
= (namlen
+ 1) &~ 1;
2167 remaining
= arelt_size (sub
);
2168 size
= (SIZEOF_AR_HDR_BIG
2173 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2175 offsets
[i
] = nextoff
;
2178 nextoff
+= size
+ (size
& 1);
2180 sprintf (ahdrp
->nextoff
, "%ld", (long) nextoff
);
2182 /* We need spaces, not null bytes, in the header. */
2183 for (p
= (char *) ahdrp
; p
< (char *) ahdrp
+ SIZEOF_AR_HDR_BIG
; p
++)
2187 if (bfd_write ((PTR
) ahdrp
, 1, SIZEOF_AR_HDR_BIG
, abfd
)
2188 != SIZEOF_AR_HDR_BIG
2189 || bfd_write ((PTR
) name
, 1, namlen
, abfd
) != namlen
2190 || (bfd_write ((PTR
) XCOFFARFMAG
, 1, SXCOFFARFMAG
, abfd
)
2194 if (bfd_seek (sub
, (file_ptr
) 0, SEEK_SET
) != 0)
2196 while (remaining
!= 0)
2199 bfd_byte buffer
[DEFAULT_BUFFERSIZE
];
2201 amt
= sizeof buffer
;
2202 if (amt
> remaining
)
2204 if (bfd_read (buffer
, 1, amt
, sub
) != amt
2205 || bfd_write (buffer
, 1, amt
, abfd
) != amt
)
2210 if ((size
& 1) != 0)
2215 if (bfd_write (&b
, 1, 1, abfd
) != 1)
2220 /* XXX This call actually should use %lld (at least on 32-bit
2221 machines) since the fields's width is 20 and there numbers with
2222 more than 32 bits can be represented. */
2223 sprintf (fhdr
.lastmemoff
, "%ld", (long) prevoff
);
2225 /* Write out the member table. */
2227 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2228 /* XXX This call actually should use %lld (at least on 32-bit
2229 machines) since the fields's width is 20 and there numbers with
2230 more than 32 bits can be represented. */
2231 sprintf (fhdr
.memoff
, "%ld", (long) nextoff
);
2233 memset (&ahdr
, 0, sizeof ahdr
);
2234 /* XXX The next two calls actually should use %lld (at least on 32-bit
2235 machines) since the fields's width is 20 and there numbers with
2236 more than 32 bits can be represented. */
2237 sprintf (ahdr
.size
, "%ld", (long) (12 + count
* 12 + total_namlen
));
2238 sprintf (ahdr
.prevoff
, "%ld", (long) prevoff
);
2239 sprintf (ahdr
.date
, "%d", 0);
2240 sprintf (ahdr
.uid
, "%d", 0);
2241 sprintf (ahdr
.gid
, "%d", 0);
2242 sprintf (ahdr
.mode
, "%d", 0);
2243 sprintf (ahdr
.namlen
, "%d", 0);
2245 size
= (SIZEOF_AR_HDR_BIG
2252 nextoff
+= size
+ (size
& 1);
2254 if (makemap
&& hasobjects
)
2255 /* XXX This call actually should use %lld (at least on 32-bit
2256 machines) since the fields's width is 20 and there numbers with
2257 more than 32 bits can be represented. */
2258 sprintf (ahdr
.nextoff
, "%ld", (long) nextoff
);
2260 sprintf (ahdr
.nextoff
, "%d", 0);
2262 /* We need spaces, not null bytes, in the header. */
2263 for (p
= (char *) &ahdr
; p
< (char *) &ahdr
+ SIZEOF_AR_HDR_BIG
; p
++)
2267 if (bfd_write ((PTR
) &ahdr
, 1, SIZEOF_AR_HDR_BIG
, abfd
) != SIZEOF_AR_HDR_BIG
2268 || (bfd_write ((PTR
) XCOFFARFMAG
, 1, SXCOFFARFMAG
, abfd
)
2272 sprintf (decbuf
, "%-12ld", (long) count
);
2273 if (bfd_write ((PTR
) decbuf
, 1, 12, abfd
) != 12)
2275 for (i
= 0; i
< count
; i
++)
2277 sprintf (decbuf
, "%-12ld", (long) offsets
[i
]);
2278 if (bfd_write ((PTR
) decbuf
, 1, 12, abfd
) != 12)
2281 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->next
)
2286 name
= normalize_filename (sub
);
2287 namlen
= strlen (name
);
2288 if (bfd_write ((PTR
) name
, 1, namlen
+ 1, abfd
) != namlen
+ 1)
2291 if ((size
& 1) != 0)
2296 if (bfd_write ((PTR
) &b
, 1, 1, abfd
) != 1)
2300 /* Write out the armap, if appropriate. */
2302 if (! makemap
|| ! hasobjects
)
2303 sprintf (fhdr
.symoff
, "%d", 0);
2306 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2307 /* XXX This call actually should use %lld (at least on 32-bit
2308 machines) since the fields's width is 20 and there numbers with
2309 more than 32 bits can be represented. */
2310 bfd_ardata (abfd
)->tdata
= (PTR
) &fhdr
;
2311 if (! _bfd_compute_and_write_armap (abfd
, 0))
2315 /* Write out the archive file header. */
2317 /* We need spaces, not null bytes, in the header. */
2318 for (p
= (char *) &fhdr
; p
< (char *) &fhdr
+ SIZEOF_AR_FILE_HDR_BIG
; p
++)
2322 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
2323 || (bfd_write ((PTR
) &fhdr
, SIZEOF_AR_FILE_HDR_BIG
, 1, abfd
) !=
2324 SIZEOF_AR_FILE_HDR_BIG
))
2331 _bfd_xcoff_write_archive_contents (abfd
)
2334 if (! xcoff_big_format_p (abfd
))
2335 return xcoff_write_archive_contents_old (abfd
);
2337 return xcoff_write_archive_contents_big (abfd
);
2340 /* We can't use the usual coff_sizeof_headers routine, because AIX
2341 always uses an a.out header. */
2344 _bfd_xcoff_sizeof_headers (abfd
, reloc
)
2346 boolean reloc ATTRIBUTE_UNUSED
;
2351 if (xcoff_data (abfd
)->full_aouthdr
)
2354 size
+= SMALL_AOUTSZ
;
2355 size
+= abfd
->section_count
* SCNHSZ
;