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. */
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"
41 /* The main body of code is in coffcode.h. */
43 static const char *normalize_filename
PARAMS ((bfd
*));
45 /* We use our own tdata type. Its first field is the COFF tdata type,
46 so the COFF routines are compatible. */
49 _bfd_xcoff_mkobject (abfd
)
54 abfd
->tdata
.xcoff_obj_data
=
55 ((struct xcoff_tdata
*)
56 bfd_zalloc (abfd
, sizeof (struct xcoff_tdata
)));
57 if (abfd
->tdata
.xcoff_obj_data
== NULL
)
59 coff
= coff_data (abfd
);
60 coff
->symbols
= (coff_symbol_type
*) NULL
;
61 coff
->conversion_table
= (unsigned int *) NULL
;
62 coff
->raw_syments
= (struct coff_ptr_struct
*) NULL
;
65 xcoff_data (abfd
)->modtype
= ('1' << 8) | 'L';
67 /* We set cputype to -1 to indicate that it has not been
69 xcoff_data (abfd
)->cputype
= -1;
71 xcoff_data (abfd
)->csects
= NULL
;
72 xcoff_data (abfd
)->debug_indices
= NULL
;
77 /* Copy XCOFF data from one BFD to another. */
80 _bfd_xcoff_copy_private_bfd_data (ibfd
, obfd
)
84 struct xcoff_tdata
*ix
, *ox
;
87 if (ibfd
->xvec
!= obfd
->xvec
)
89 ix
= xcoff_data (ibfd
);
90 ox
= xcoff_data (obfd
);
91 ox
->full_aouthdr
= ix
->full_aouthdr
;
97 sec
= coff_section_from_bfd_index (ibfd
, ix
->sntoc
);
101 ox
->sntoc
= sec
->output_section
->target_index
;
103 if (ix
->snentry
== 0)
107 sec
= coff_section_from_bfd_index (ibfd
, ix
->snentry
);
111 ox
->snentry
= sec
->output_section
->target_index
;
113 ox
->text_align_power
= ix
->text_align_power
;
114 ox
->data_align_power
= ix
->data_align_power
;
115 ox
->modtype
= ix
->modtype
;
116 ox
->cputype
= ix
->cputype
;
117 ox
->maxdata
= ix
->maxdata
;
118 ox
->maxstack
= ix
->maxstack
;
122 /* I don't think XCOFF really has a notion of local labels based on
123 name. This will mean that ld -X doesn't actually strip anything.
124 The AIX native linker does not have a -X option, and it ignores the
128 _bfd_xcoff_is_local_label_name (abfd
, name
)
129 bfd
*abfd ATTRIBUTE_UNUSED
;
130 const char *name ATTRIBUTE_UNUSED
;
138 _bfd_xcoff_swap_sym_in (abfd
, ext1
, in1
)
143 SYMENT
*ext
= (SYMENT
*)ext1
;
144 struct internal_syment
*in
= (struct internal_syment
*)in1
;
147 if(ext
->e
.e_name
[0] != 0)
149 memcpy(in
->_n
._n_name
, ext
->e
.e_name
, SYMNMLEN
);
153 in
->_n
._n_n
._n_zeroes
= 0;
154 in
->_n
._n_n
._n_offset
=
155 bfd_h_get_32(abfd
, (bfd_byte
*) ext
->e
.e
.e_offset
);
158 in
->n_value
= bfd_h_get_32(abfd
, (bfd_byte
*) ext
->e_value
);
159 in
->n_scnum
= bfd_h_get_16(abfd
, (bfd_byte
*) ext
->e_scnum
);
160 in
->n_type
= bfd_h_get_16(abfd
, (bfd_byte
*) ext
->e_type
);
161 in
->n_sclass
= bfd_h_get_8(abfd
, ext
->e_sclass
);
162 in
->n_numaux
= bfd_h_get_8(abfd
, ext
->e_numaux
);
166 _bfd_xcoff_swap_sym_out (abfd
, inp
, extp
)
171 struct internal_syment
*in
= (struct internal_syment
*)inp
;
172 SYMENT
*ext
=(SYMENT
*)extp
;
174 if(in
->_n
._n_name
[0] != 0)
176 memcpy(ext
->e
.e_name
, in
->_n
._n_name
, SYMNMLEN
);
180 bfd_h_put_32(abfd
, 0, (bfd_byte
*) ext
->e
.e
.e_zeroes
);
181 bfd_h_put_32(abfd
, in
->_n
._n_n
._n_offset
,
182 (bfd_byte
*) ext
->e
.e
.e_offset
);
185 bfd_h_put_32(abfd
, in
->n_value
, (bfd_byte
*) ext
->e_value
);
186 bfd_h_put_16(abfd
, in
->n_scnum
, (bfd_byte
*) ext
->e_scnum
);
187 bfd_h_put_16(abfd
, in
->n_type
, (bfd_byte
*) ext
->e_type
);
188 bfd_h_put_8(abfd
, in
->n_sclass
, ext
->e_sclass
);
189 bfd_h_put_8(abfd
, in
->n_numaux
, ext
->e_numaux
);
190 return bfd_coff_symesz (abfd
);
193 #define PUTWORD bfd_h_put_32
194 #define PUTHALF bfd_h_put_16
195 #define PUTBYTE bfd_h_put_8
196 #define GETWORD bfd_h_get_32
197 #define GETHALF bfd_h_get_16
198 #define GETBYTE bfd_h_get_8
201 _bfd_xcoff_swap_aux_in (abfd
, ext1
, type
, class, indx
, numaux
, in1
)
210 AUXENT
*ext
= (AUXENT
*)ext1
;
211 union internal_auxent
*in
= (union internal_auxent
*)in1
;
215 if (ext
->x_file
.x_fname
[0] == 0) {
216 in
->x_file
.x_n
.x_zeroes
= 0;
217 in
->x_file
.x_n
.x_offset
=
218 bfd_h_get_32(abfd
, (bfd_byte
*) ext
->x_file
.x_n
.x_offset
);
223 memcpy (in
->x_file
.x_fname
, ext
->x_file
.x_fname
,
224 numaux
* sizeof (AUXENT
));
228 memcpy (in
->x_file
.x_fname
, ext
->x_file
.x_fname
, FILNMLEN
);
233 /* RS/6000 "csect" auxents */
236 if (indx
+ 1 == numaux
)
238 in
->x_csect
.x_scnlen
.l
=
239 bfd_h_get_32 (abfd
, ext
->x_csect
.x_scnlen
);
240 in
->x_csect
.x_parmhash
= bfd_h_get_32 (abfd
,
241 ext
->x_csect
.x_parmhash
);
242 in
->x_csect
.x_snhash
= bfd_h_get_16 (abfd
, ext
->x_csect
.x_snhash
);
243 /* We don't have to hack bitfields in x_smtyp because it's
244 defined by shifts-and-ands, which are equivalent on all
246 in
->x_csect
.x_smtyp
= bfd_h_get_8 (abfd
, ext
->x_csect
.x_smtyp
);
247 in
->x_csect
.x_smclas
= bfd_h_get_8 (abfd
, ext
->x_csect
.x_smclas
);
248 in
->x_csect
.x_stab
= bfd_h_get_32 (abfd
, ext
->x_csect
.x_stab
);
249 in
->x_csect
.x_snstab
= bfd_h_get_16 (abfd
, ext
->x_csect
.x_snstab
);
257 if (type
== T_NULL
) {
258 in
->x_scn
.x_scnlen
= bfd_h_get_32(abfd
,
259 (bfd_byte
*) ext
->x_scn
.x_scnlen
);
260 in
->x_scn
.x_nreloc
= bfd_h_get_16(abfd
,
261 (bfd_byte
*) ext
->x_scn
.x_nreloc
);
262 in
->x_scn
.x_nlinno
= bfd_h_get_16(abfd
,
263 (bfd_byte
*) ext
->x_scn
.x_nlinno
);
264 /* PE defines some extra fields; we zero them out for
266 in
->x_scn
.x_checksum
= 0;
267 in
->x_scn
.x_associated
= 0;
268 in
->x_scn
.x_comdat
= 0;
275 in
->x_sym
.x_tagndx
.l
= bfd_h_get_32(abfd
, (bfd_byte
*) ext
->x_sym
.x_tagndx
);
276 in
->x_sym
.x_tvndx
= bfd_h_get_16(abfd
, (bfd_byte
*) ext
->x_sym
.x_tvndx
);
278 if (class == C_BLOCK
|| class == C_FCN
|| ISFCN (type
) || ISTAG (class))
280 in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
= bfd_h_get_32(abfd
, (bfd_byte
*)
281 ext
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
282 in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
= bfd_h_get_32(abfd
, (bfd_byte
*)
283 ext
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
287 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0] =
288 bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
289 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1] =
290 bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
291 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2] =
292 bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
293 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3] =
294 bfd_h_get_16 (abfd
, (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
297 in
->x_sym
.x_misc
.x_fsize
= bfd_h_get_32(abfd
, (bfd_byte
*) ext
->x_sym
.x_misc
.x_fsize
);
300 in
->x_sym
.x_misc
.x_lnsz
.x_lnno
= bfd_h_get_16(abfd
, (bfd_byte
*)
301 ext
->x_sym
.x_misc
.x_lnsz
.x_lnno
);
302 in
->x_sym
.x_misc
.x_lnsz
.x_size
= bfd_h_get_16(abfd
, (bfd_byte
*)
303 ext
->x_sym
.x_misc
.x_lnsz
.x_size
);
307 /* the semicolon is because MSVC doesn't like labels at
315 _bfd_xcoff_swap_aux_out (abfd
, inp
, type
, class, indx
, numaux
, extp
)
320 int indx ATTRIBUTE_UNUSED
;
321 int numaux ATTRIBUTE_UNUSED
;
324 union internal_auxent
*in
= (union internal_auxent
*)inp
;
325 AUXENT
*ext
= (AUXENT
*)extp
;
327 memset((PTR
)ext
, 0, bfd_coff_auxesz (abfd
));
331 if (in
->x_file
.x_fname
[0] == 0)
333 PUTWORD(abfd
, 0, (bfd_byte
*) ext
->x_file
.x_n
.x_zeroes
);
335 in
->x_file
.x_n
.x_offset
,
336 (bfd_byte
*) ext
->x_file
.x_n
.x_offset
);
340 memcpy (ext
->x_file
.x_fname
, in
->x_file
.x_fname
, FILNMLEN
);
344 /* RS/6000 "csect" auxents */
347 if (indx
+ 1 == numaux
)
349 PUTWORD (abfd
, in
->x_csect
.x_scnlen
.l
,ext
->x_csect
.x_scnlen
);
350 PUTWORD (abfd
, in
->x_csect
.x_parmhash
, ext
->x_csect
.x_parmhash
);
351 PUTHALF (abfd
, in
->x_csect
.x_snhash
, ext
->x_csect
.x_snhash
);
352 /* We don't have to hack bitfields in x_smtyp because it's
353 defined by shifts-and-ands, which are equivalent on all
355 PUTBYTE (abfd
, in
->x_csect
.x_smtyp
, ext
->x_csect
.x_smtyp
);
356 PUTBYTE (abfd
, in
->x_csect
.x_smclas
, ext
->x_csect
.x_smclas
);
357 PUTWORD (abfd
, in
->x_csect
.x_stab
, ext
->x_csect
.x_stab
);
358 PUTHALF (abfd
, in
->x_csect
.x_snstab
, ext
->x_csect
.x_snstab
);
366 if (type
== T_NULL
) {
367 bfd_h_put_32(abfd
, in
->x_scn
.x_scnlen
, (bfd_byte
*) ext
->x_scn
.x_scnlen
);
368 bfd_h_put_16(abfd
, in
->x_scn
.x_nreloc
, (bfd_byte
*) ext
->x_scn
.x_nreloc
);
369 bfd_h_put_16(abfd
, in
->x_scn
.x_nlinno
, (bfd_byte
*) ext
->x_scn
.x_nlinno
);
375 PUTWORD(abfd
, in
->x_sym
.x_tagndx
.l
, (bfd_byte
*) ext
->x_sym
.x_tagndx
);
376 PUTWORD(abfd
, in
->x_sym
.x_tvndx
, (bfd_byte
*) ext
->x_sym
.x_tvndx
);
378 if (class == C_BLOCK
|| class == C_FCN
|| ISFCN (type
) || ISTAG (class))
380 bfd_h_put_32(abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
,
381 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
382 PUTWORD(abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
,
383 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
387 bfd_h_put_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0],
388 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
389 bfd_h_put_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1],
390 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
391 bfd_h_put_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2],
392 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
393 bfd_h_put_16 (abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3],
394 (bfd_byte
*) ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
398 PUTWORD (abfd
, in
->x_sym
.x_misc
.x_fsize
,
399 (bfd_byte
*) ext
->x_sym
.x_misc
.x_fsize
);
402 bfd_h_put_16(abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_lnno
,
403 (bfd_byte
*)ext
->x_sym
.x_misc
.x_lnsz
.x_lnno
);
404 bfd_h_put_16(abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_size
,
405 (bfd_byte
*)ext
->x_sym
.x_misc
.x_lnsz
.x_size
);
409 return bfd_coff_auxesz (abfd
);
414 /* The XCOFF reloc table. Actually, XCOFF relocations specify the
415 bitsize and whether they are signed or not, along with a
416 conventional type. This table is for the types, which are used for
417 different algorithms for putting in the reloc. Many of these
418 relocs need special_function entries, which I have not written. */
420 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
421 from smaller values. Start with zero, widen, *then* decrement. */
422 #define MINUS_ONE (((bfd_vma)0) - 1)
424 reloc_howto_type xcoff_howto_table
[] =
426 /* Standard 32 bit relocation. */
429 2, /* size (0 = byte, 1 = short, 2 = long) */
431 false, /* pc_relative */
433 complain_overflow_bitfield
, /* complain_on_overflow */
434 0, /* special_function */
436 true, /* partial_inplace */
437 0xffffffff, /* src_mask */
438 0xffffffff, /* dst_mask */
439 false), /* pcrel_offset */
441 /* 32 bit relocation, but store negative value. */
444 -2, /* size (0 = byte, 1 = short, 2 = long) */
446 false, /* pc_relative */
448 complain_overflow_bitfield
, /* complain_on_overflow */
449 0, /* special_function */
451 true, /* partial_inplace */
452 0xffffffff, /* src_mask */
453 0xffffffff, /* dst_mask */
454 false), /* pcrel_offset */
456 /* 32 bit PC relative relocation. */
459 2, /* size (0 = byte, 1 = short, 2 = long) */
461 true, /* pc_relative */
463 complain_overflow_signed
, /* complain_on_overflow */
464 0, /* special_function */
466 true, /* partial_inplace */
467 0xffffffff, /* src_mask */
468 0xffffffff, /* dst_mask */
469 false), /* pcrel_offset */
471 /* 16 bit TOC relative relocation. */
474 1, /* size (0 = byte, 1 = short, 2 = long) */
476 false, /* pc_relative */
478 complain_overflow_bitfield
, /* complain_on_overflow */
479 0, /* special_function */
481 true, /* partial_inplace */
482 0xffff, /* src_mask */
483 0xffff, /* dst_mask */
484 false), /* pcrel_offset */
486 /* I don't really know what this is. */
489 2, /* size (0 = byte, 1 = short, 2 = long) */
491 false, /* pc_relative */
493 complain_overflow_bitfield
, /* complain_on_overflow */
494 0, /* special_function */
496 true, /* partial_inplace */
497 0xffffffff, /* src_mask */
498 0xffffffff, /* dst_mask */
499 false), /* pcrel_offset */
501 /* External TOC relative symbol. */
504 2, /* size (0 = byte, 1 = short, 2 = long) */
506 false, /* pc_relative */
508 complain_overflow_bitfield
, /* complain_on_overflow */
509 0, /* special_function */
511 true, /* partial_inplace */
512 0xffff, /* src_mask */
513 0xffff, /* dst_mask */
514 false), /* pcrel_offset */
516 /* Local TOC relative symbol. */
519 2, /* size (0 = byte, 1 = short, 2 = long) */
521 false, /* pc_relative */
523 complain_overflow_bitfield
, /* complain_on_overflow */
524 0, /* special_function */
526 true, /* partial_inplace */
527 0xffff, /* src_mask */
528 0xffff, /* dst_mask */
529 false), /* pcrel_offset */
533 /* Non modifiable absolute branch. */
536 2, /* size (0 = byte, 1 = short, 2 = long) */
538 false, /* pc_relative */
540 complain_overflow_bitfield
, /* complain_on_overflow */
541 0, /* special_function */
543 true, /* partial_inplace */
544 0x3fffffc, /* src_mask */
545 0x3fffffc, /* dst_mask */
546 false), /* pcrel_offset */
550 /* Non modifiable relative branch. */
551 HOWTO (0xa, /* type */
553 2, /* size (0 = byte, 1 = short, 2 = long) */
555 true, /* pc_relative */
557 complain_overflow_signed
, /* complain_on_overflow */
558 0, /* special_function */
560 true, /* partial_inplace */
561 0x3fffffc, /* src_mask */
562 0x3fffffc, /* dst_mask */
563 false), /* pcrel_offset */
568 HOWTO (0xc, /* type */
570 2, /* size (0 = byte, 1 = short, 2 = long) */
572 false, /* pc_relative */
574 complain_overflow_bitfield
, /* complain_on_overflow */
575 0, /* special_function */
577 true, /* partial_inplace */
578 0xffff, /* src_mask */
579 0xffff, /* dst_mask */
580 false), /* pcrel_offset */
583 HOWTO (0xd, /* type */
585 2, /* size (0 = byte, 1 = short, 2 = long) */
587 false, /* pc_relative */
589 complain_overflow_bitfield
, /* complain_on_overflow */
590 0, /* special_function */
592 true, /* partial_inplace */
593 0xffff, /* src_mask */
594 0xffff, /* dst_mask */
595 false), /* pcrel_offset */
599 /* Non-relocating reference. */
600 HOWTO (0xf, /* type */
602 2, /* size (0 = byte, 1 = short, 2 = long) */
604 false, /* pc_relative */
606 complain_overflow_bitfield
, /* complain_on_overflow */
607 0, /* special_function */
609 false, /* partial_inplace */
612 false), /* pcrel_offset */
617 /* TOC relative indirect load. */
618 HOWTO (0x12, /* type */
620 2, /* size (0 = byte, 1 = short, 2 = long) */
622 false, /* pc_relative */
624 complain_overflow_bitfield
, /* complain_on_overflow */
625 0, /* special_function */
627 true, /* partial_inplace */
628 0xffff, /* src_mask */
629 0xffff, /* dst_mask */
630 false), /* pcrel_offset */
632 /* TOC relative load address. */
633 HOWTO (0x13, /* type */
635 2, /* size (0 = byte, 1 = short, 2 = long) */
637 false, /* pc_relative */
639 complain_overflow_bitfield
, /* complain_on_overflow */
640 0, /* special_function */
642 true, /* partial_inplace */
643 0xffff, /* src_mask */
644 0xffff, /* dst_mask */
645 false), /* pcrel_offset */
647 /* Modifiable relative branch. */
648 HOWTO (0x14, /* type */
650 2, /* size (0 = byte, 1 = short, 2 = long) */
652 false, /* pc_relative */
654 complain_overflow_bitfield
, /* complain_on_overflow */
655 0, /* special_function */
656 "R_RRTBI", /* name */
657 true, /* partial_inplace */
658 0xffffffff, /* src_mask */
659 0xffffffff, /* dst_mask */
660 false), /* pcrel_offset */
662 /* Modifiable absolute branch. */
663 HOWTO (0x15, /* type */
665 2, /* size (0 = byte, 1 = short, 2 = long) */
667 false, /* pc_relative */
669 complain_overflow_bitfield
, /* complain_on_overflow */
670 0, /* special_function */
671 "R_RRTBA", /* name */
672 true, /* partial_inplace */
673 0xffffffff, /* src_mask */
674 0xffffffff, /* dst_mask */
675 false), /* pcrel_offset */
677 /* Modifiable call absolute indirect. */
678 HOWTO (0x16, /* type */
680 2, /* size (0 = byte, 1 = short, 2 = long) */
682 false, /* pc_relative */
684 complain_overflow_bitfield
, /* complain_on_overflow */
685 0, /* special_function */
687 true, /* partial_inplace */
688 0xffff, /* src_mask */
689 0xffff, /* dst_mask */
690 false), /* pcrel_offset */
692 /* Modifiable call relative. */
693 HOWTO (0x17, /* type */
695 2, /* size (0 = byte, 1 = short, 2 = long) */
697 false, /* pc_relative */
699 complain_overflow_bitfield
, /* complain_on_overflow */
700 0, /* special_function */
702 true, /* partial_inplace */
703 0xffff, /* src_mask */
704 0xffff, /* dst_mask */
705 false), /* pcrel_offset */
707 /* Modifiable branch absolute. */
708 HOWTO (0x18, /* type */
710 2, /* size (0 = byte, 1 = short, 2 = long) */
712 false, /* pc_relative */
714 complain_overflow_bitfield
, /* complain_on_overflow */
715 0, /* special_function */
717 true, /* partial_inplace */
718 0xffff, /* src_mask */
719 0xffff, /* dst_mask */
720 false), /* pcrel_offset */
722 /* Modifiable branch absolute. */
723 HOWTO (0x19, /* type */
725 2, /* size (0 = byte, 1 = short, 2 = long) */
727 false, /* pc_relative */
729 complain_overflow_bitfield
, /* complain_on_overflow */
730 0, /* special_function */
732 true, /* partial_inplace */
733 0xffff, /* src_mask */
734 0xffff, /* dst_mask */
735 false), /* pcrel_offset */
737 /* Modifiable branch relative. */
738 HOWTO (0x1a, /* type */
740 2, /* size (0 = byte, 1 = short, 2 = long) */
742 false, /* pc_relative */
744 complain_overflow_signed
, /* complain_on_overflow */
745 0, /* special_function */
747 true, /* partial_inplace */
748 0xffff, /* src_mask */
749 0xffff, /* dst_mask */
750 false), /* pcrel_offset */
752 /* Modifiable branch absolute. */
753 HOWTO (0x1b, /* type */
755 2, /* size (0 = byte, 1 = short, 2 = long) */
757 false, /* pc_relative */
759 complain_overflow_bitfield
, /* complain_on_overflow */
760 0, /* special_function */
762 true, /* partial_inplace */
763 0xffff, /* src_mask */
764 0xffff, /* dst_mask */
765 false), /* pcrel_offset */
768 4, /* size (0 = byte, 1 = short, 2 = long) */
770 false, /* pc_relative */
772 complain_overflow_bitfield
, /* complain_on_overflow */
773 0, /* special_function */
775 true, /* partial_inplace */
776 MINUS_ONE
, /* src_mask */
777 MINUS_ONE
, /* dst_mask */
778 false) /* pcrel_offset */
782 /* These are the first two like the above but for 16-bit relocs. */
783 static reloc_howto_type xcoff_howto_table_16
[] =
785 /* Standard 16 bit relocation. */
788 2, /* size (0 = byte, 1 = short, 2 = long) */
790 false, /* pc_relative */
792 complain_overflow_bitfield
, /* complain_on_overflow */
793 0, /* special_function */
794 "R_POS_16", /* name */
795 true, /* partial_inplace */
796 0xffffffff, /* src_mask */
797 0xffffffff, /* dst_mask */
798 false), /* pcrel_offset */
800 /* 16 bit relocation, but store negative value. */
803 -2, /* size (0 = byte, 1 = short, 2 = long) */
805 false, /* pc_relative */
807 complain_overflow_bitfield
, /* complain_on_overflow */
808 0, /* special_function */
809 "R_NEG_16", /* name */
810 true, /* partial_inplace */
811 0xffffffff, /* src_mask */
812 0xffffffff, /* dst_mask */
813 false), /* pcrel_offset */
815 /* 16 bit PC relative relocation. */
818 2, /* size (0 = byte, 1 = short, 2 = long) */
820 true, /* pc_relative */
822 complain_overflow_signed
, /* complain_on_overflow */
823 0, /* special_function */
824 "R_REL_16", /* name */
825 true, /* partial_inplace */
826 0xffffffff, /* src_mask */
827 0xffffffff, /* dst_mask */
828 false) /* pcrel_offset */
832 _bfd_xcoff_rtype2howto (relent
, internal
)
834 struct internal_reloc
*internal
;
836 relent
->howto
= xcoff_howto_table
+ internal
->r_type
;
838 if (relent
->howto
->bitsize
!= ((unsigned int) internal
->r_size
& 0x1f) + 1
840 < sizeof(xcoff_howto_table_16
)/sizeof(xcoff_howto_table_16
[0])))
841 relent
->howto
= xcoff_howto_table_16
+ internal
->r_type
;
843 /* The r_size field of an XCOFF reloc encodes the bitsize of the
844 relocation, as well as indicating whether it is signed or not.
845 Doublecheck that the relocation information gathered from the
846 type matches this information. */
847 if (relent
->howto
->bitsize
!= ((unsigned int) internal
->r_size
& 0x1f) + 1)
850 if ((internal
->r_size
& 0x80) != 0
851 ? (relent
->howto
->complain_on_overflow
!= complain_overflow_signed
)
852 : (relent
->howto
->complain_on_overflow
!= complain_overflow_bitfield
))
858 _bfd_xcoff_reloc_type_lookup (abfd
, code
)
859 bfd
*abfd ATTRIBUTE_UNUSED
;
860 bfd_reloc_code_real_type code
;
864 case BFD_RELOC_PPC_B26
:
865 return &xcoff_howto_table
[0xa];
866 case BFD_RELOC_PPC_BA26
:
867 return &xcoff_howto_table
[8];
868 case BFD_RELOC_PPC_TOC16
:
869 return &xcoff_howto_table
[3];
872 return &xcoff_howto_table
[0];
874 return &xcoff_howto_table
[0x1c];
881 /* XCOFF archive support. The original version of this code was by
882 Damon A. Permezel. It was enhanced to permit cross support, and
883 writing archive files, by Ian Lance Taylor, Cygnus Support.
885 XCOFF uses its own archive format. Everything is hooked together
886 with file offset links, so it is possible to rapidly update an
887 archive in place. Of course, we don't do that. An XCOFF archive
888 has a real file header, not just an ARMAG string. The structure of
889 the file header and of each archive header appear below.
891 An XCOFF archive also has a member table, which is a list of
892 elements in the archive (you can get that by looking through the
893 linked list, but you have to read a lot more of the file). The
894 member table has a normal archive header with an empty name. It is
895 normally (and perhaps must be) the second to last entry in the
896 archive. The member table data is almost printable ASCII. It
897 starts with a 12 character decimal string which is the number of
898 entries in the table. For each entry it has a 12 character decimal
899 string which is the offset in the archive of that member. These
900 entries are followed by a series of null terminated strings which
901 are the member names for each entry.
903 Finally, an XCOFF archive has a global symbol table, which is what
904 we call the armap. The global symbol table has a normal archive
905 header with an empty name. It is normally (and perhaps must be)
906 the last entry in the archive. The contents start with a four byte
907 binary number which is the number of entries. This is followed by
908 a that many four byte binary numbers; each is the file offset of an
909 entry in the archive. These numbers are followed by a series of
910 null terminated strings, which are symbol names.
912 AIX 4.3 introduced a new archive format which can handle larger
913 files and also 32- and 64-bit objects in the same archive. The
914 things said above remain true except that there is now more than
915 one global symbol table. The one is used to index 32-bit objects,
916 the other for 64-bit objects.
918 The new archives (recognizable by the new ARMAG string) has larger
919 field lengths so that we cannot really share any code. Also we have
920 to take care that we are not generating the new form of archives
921 on AIX 4.2 or earlier systems. */
923 /* XCOFF archives use this as a magic string. Note that both strings
924 have the same length. */
926 #define XCOFFARMAG "<aiaff>\012"
927 #define XCOFFARMAGBIG "<bigaf>\012"
928 #define SXCOFFARMAG 8
930 /* This terminates an XCOFF archive member name. */
932 #define XCOFFARFMAG "`\012"
933 #define SXCOFFARFMAG 2
935 /* XCOFF archives start with this (printable) structure. */
937 struct xcoff_ar_file_hdr
940 char magic
[SXCOFFARMAG
];
942 /* Offset of the member table (decimal ASCII string). */
945 /* Offset of the global symbol table (decimal ASCII string). */
948 /* Offset of the first member in the archive (decimal ASCII string). */
949 char firstmemoff
[12];
951 /* Offset of the last member in the archive (decimal ASCII string). */
954 /* Offset of the first member on the free list (decimal ASCII
959 #define SIZEOF_AR_FILE_HDR (5 * 12 + SXCOFFARMAG)
961 /* This is the equivalent data structure for the big archive format. */
963 struct xcoff_ar_file_hdr_big
966 char magic
[SXCOFFARMAG
];
968 /* Offset of the member table (decimal ASCII string). */
971 /* Offset of the global symbol table for 32-bit objects (decimal ASCII
975 /* Offset of the global symbol table for 64-bit objects (decimal ASCII
979 /* Offset of the first member in the archive (decimal ASCII string). */
980 char firstmemoff
[20];
982 /* Offset of the last member in the archive (decimal ASCII string). */
985 /* Offset of the first member on the free list (decimal ASCII
990 #define SIZEOF_AR_FILE_HDR_BIG (6 * 20 + SXCOFFARMAG)
993 /* Each XCOFF archive member starts with this (printable) structure. */
997 /* File size not including the header (decimal ASCII string). */
1000 /* File offset of next archive member (decimal ASCII string). */
1003 /* File offset of previous archive member (decimal ASCII string). */
1006 /* File mtime (decimal ASCII string). */
1009 /* File UID (decimal ASCII string). */
1012 /* File GID (decimal ASCII string). */
1015 /* File mode (octal ASCII string). */
1018 /* Length of file name (decimal ASCII string). */
1021 /* This structure is followed by the file name. The length of the
1022 name is given in the namlen field. If the length of the name is
1023 odd, the name is followed by a null byte. The name and optional
1024 null byte are followed by XCOFFARFMAG, which is not included in
1025 namlen. The contents of the archive member follow; the number of
1026 bytes is given in the size field. */
1029 #define SIZEOF_AR_HDR (7 * 12 + 4)
1031 /* The equivalent for the big archive format. */
1033 struct xcoff_ar_hdr_big
1035 /* File size not including the header (decimal ASCII string). */
1038 /* File offset of next archive member (decimal ASCII string). */
1041 /* File offset of previous archive member (decimal ASCII string). */
1044 /* File mtime (decimal ASCII string). */
1047 /* File UID (decimal ASCII string). */
1050 /* File GID (decimal ASCII string). */
1053 /* File mode (octal ASCII string). */
1056 /* Length of file name (decimal ASCII string). */
1059 /* This structure is followed by the file name. The length of the
1060 name is given in the namlen field. If the length of the name is
1061 odd, the name is followed by a null byte. The name and optional
1062 null byte are followed by XCOFFARFMAG, which is not included in
1063 namlen. The contents of the archive member follow; the number of
1064 bytes is given in the size field. */
1067 #define SIZEOF_AR_HDR_BIG (3 * 20 + 4 * 12 + 4)
1070 /* We often have to distinguish between the old and big file format.
1071 Make it a bit cleaner. We can use `xcoff_ardata' here because the
1072 `hdr' member has the same size and position in both formats. */
1073 #define xcoff_big_format_p(abfd) \
1074 (xcoff_ardata (abfd)->magic[1] == 'b')
1076 /* We store a copy of the xcoff_ar_file_hdr in the tdata field of the
1077 artdata structure. Similar for the big archive. */
1078 #define xcoff_ardata(abfd) \
1079 ((struct xcoff_ar_file_hdr *) bfd_ardata (abfd)->tdata)
1080 #define xcoff_ardata_big(abfd) \
1081 ((struct xcoff_ar_file_hdr_big *) bfd_ardata (abfd)->tdata)
1083 /* We store a copy of the xcoff_ar_hdr in the arelt_data field of an
1084 archive element. Similar for the big archive. */
1085 #define arch_eltdata(bfd) ((struct areltdata *) ((bfd)->arelt_data))
1086 #define arch_xhdr(bfd) \
1087 ((struct xcoff_ar_hdr *) arch_eltdata (bfd)->arch_header)
1088 #define arch_xhdr_big(bfd) \
1089 ((struct xcoff_ar_hdr_big *) arch_eltdata (bfd)->arch_header)
1091 /* Read in the armap of an XCOFF archive. */
1094 _bfd_xcoff_slurp_armap (abfd
)
1100 bfd_byte
*contents
, *cend
;
1105 if (xcoff_ardata (abfd
) == NULL
)
1107 bfd_has_map (abfd
) = false;
1111 if (! xcoff_big_format_p (abfd
))
1113 /* This is for the old format. */
1114 struct xcoff_ar_hdr hdr
;
1116 off
= strtol (xcoff_ardata (abfd
)->symoff
, (char **) NULL
, 10);
1119 bfd_has_map (abfd
) = false;
1123 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0)
1126 /* The symbol table starts with a normal archive header. */
1127 if (bfd_read ((PTR
) &hdr
, SIZEOF_AR_HDR
, 1, abfd
) != SIZEOF_AR_HDR
)
1130 /* Skip the name (normally empty). */
1131 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1132 if (bfd_seek (abfd
, ((namlen
+ 1) & ~1) + SXCOFFARFMAG
, SEEK_CUR
) != 0)
1135 sz
= strtol (hdr
.size
, (char **) NULL
, 10);
1137 /* Read in the entire symbol table. */
1138 contents
= (bfd_byte
*) bfd_alloc (abfd
, sz
);
1139 if (contents
== NULL
)
1141 if (bfd_read ((PTR
) contents
, 1, sz
, abfd
) != sz
)
1144 /* The symbol table starts with a four byte count. */
1145 c
= bfd_h_get_32 (abfd
, contents
);
1149 bfd_set_error (bfd_error_bad_value
);
1153 bfd_ardata (abfd
)->symdefs
= ((carsym
*)
1154 bfd_alloc (abfd
, c
* sizeof (carsym
)));
1155 if (bfd_ardata (abfd
)->symdefs
== NULL
)
1158 /* After the count comes a list of four byte file offsets. */
1159 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
, p
= contents
+ 4;
1161 ++i
, ++arsym
, p
+= 4)
1162 arsym
->file_offset
= bfd_h_get_32 (abfd
, p
);
1166 /* This is for the new format. */
1167 struct xcoff_ar_hdr_big hdr
;
1169 off
= strtol (xcoff_ardata_big (abfd
)->symoff
, (char **) NULL
, 10);
1172 bfd_has_map (abfd
) = false;
1176 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0)
1179 /* The symbol table starts with a normal archive header. */
1180 if (bfd_read ((PTR
) &hdr
, SIZEOF_AR_HDR_BIG
, 1, abfd
)
1181 != SIZEOF_AR_HDR_BIG
)
1184 /* Skip the name (normally empty). */
1185 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1186 if (bfd_seek (abfd
, ((namlen
+ 1) & ~1) + SXCOFFARFMAG
, SEEK_CUR
) != 0)
1189 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1190 machines) since the field width is 20 and there numbers with more
1191 than 32 bits can be represented. */
1192 sz
= strtol (hdr
.size
, (char **) NULL
, 10);
1194 /* Read in the entire symbol table. */
1195 contents
= (bfd_byte
*) bfd_alloc (abfd
, sz
);
1196 if (contents
== NULL
)
1198 if (bfd_read ((PTR
) contents
, 1, sz
, abfd
) != sz
)
1201 /* The symbol table starts with an eight byte count. */
1202 c
= bfd_h_get_64 (abfd
, contents
);
1206 bfd_set_error (bfd_error_bad_value
);
1210 bfd_ardata (abfd
)->symdefs
= ((carsym
*)
1211 bfd_alloc (abfd
, c
* sizeof (carsym
)));
1212 if (bfd_ardata (abfd
)->symdefs
== NULL
)
1215 /* After the count comes a list of eight byte file offsets. */
1216 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
, p
= contents
+ 8;
1218 ++i
, ++arsym
, p
+= 8)
1219 arsym
->file_offset
= bfd_h_get_64 (abfd
, p
);
1222 /* After the file offsets come null terminated symbol names. */
1223 cend
= contents
+ sz
;
1224 for (i
= 0, arsym
= bfd_ardata (abfd
)->symdefs
;
1226 ++i
, ++arsym
, p
+= strlen ((char *) p
) + 1)
1230 bfd_set_error (bfd_error_bad_value
);
1233 arsym
->name
= (char *) p
;
1236 bfd_ardata (abfd
)->symdef_count
= c
;
1237 bfd_has_map (abfd
) = true;
1242 /* See if this is an XCOFF archive. */
1245 _bfd_xcoff_archive_p (abfd
)
1248 char magic
[SXCOFFARMAG
];
1250 if (bfd_read ((PTR
) magic
, SXCOFFARMAG
, 1, abfd
) != SXCOFFARMAG
)
1252 if (bfd_get_error () != bfd_error_system_call
)
1253 bfd_set_error (bfd_error_wrong_format
);
1257 if (strncmp (magic
, XCOFFARMAG
, SXCOFFARMAG
) != 0
1258 && strncmp (magic
, XCOFFARMAGBIG
, SXCOFFARMAG
) != 0)
1260 bfd_set_error (bfd_error_wrong_format
);
1264 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
1265 involves a cast, we can't do it as the left operand of
1267 abfd
->tdata
.aout_ar_data
=
1268 (struct artdata
*) bfd_zalloc (abfd
, sizeof (struct artdata
));
1270 if (bfd_ardata (abfd
) == (struct artdata
*) NULL
)
1273 bfd_ardata (abfd
)->cache
= NULL
;
1274 bfd_ardata (abfd
)->archive_head
= NULL
;
1275 bfd_ardata (abfd
)->symdefs
= NULL
;
1276 bfd_ardata (abfd
)->extended_names
= NULL
;
1278 /* Now handle the two formats. */
1279 if (magic
[1] != 'b')
1281 /* This is the old format. */
1282 struct xcoff_ar_file_hdr hdr
;
1284 /* Copy over the magic string. */
1285 memcpy (hdr
.magic
, magic
, SXCOFFARMAG
);
1287 /* Now read the rest of the file header. */
1288 if (bfd_read ((PTR
) &hdr
.memoff
, SIZEOF_AR_FILE_HDR
- SXCOFFARMAG
, 1,
1289 abfd
) != SIZEOF_AR_FILE_HDR
- SXCOFFARMAG
)
1291 if (bfd_get_error () != bfd_error_system_call
)
1292 bfd_set_error (bfd_error_wrong_format
);
1296 bfd_ardata (abfd
)->first_file_filepos
= strtol (hdr
.firstmemoff
,
1297 (char **) NULL
, 10);
1299 bfd_ardata (abfd
)->tdata
= bfd_zalloc (abfd
, SIZEOF_AR_FILE_HDR
);
1300 if (bfd_ardata (abfd
)->tdata
== NULL
)
1303 memcpy (bfd_ardata (abfd
)->tdata
, &hdr
, SIZEOF_AR_FILE_HDR
);
1307 /* This is the new format. */
1308 struct xcoff_ar_file_hdr_big hdr
;
1310 /* Copy over the magic string. */
1311 memcpy (hdr
.magic
, magic
, SXCOFFARMAG
);
1313 /* Now read the rest of the file header. */
1314 if (bfd_read ((PTR
) &hdr
.memoff
, SIZEOF_AR_FILE_HDR_BIG
- SXCOFFARMAG
, 1,
1315 abfd
) != SIZEOF_AR_FILE_HDR_BIG
- SXCOFFARMAG
)
1317 if (bfd_get_error () != bfd_error_system_call
)
1318 bfd_set_error (bfd_error_wrong_format
);
1322 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1323 machines) since the field width is 20 and there numbers with more
1324 than 32 bits can be represented. */
1325 bfd_ardata (abfd
)->first_file_filepos
= strtol (hdr
.firstmemoff
,
1326 (char **) NULL
, 10);
1328 bfd_ardata (abfd
)->tdata
= bfd_zalloc (abfd
, SIZEOF_AR_FILE_HDR_BIG
);
1329 if (bfd_ardata (abfd
)->tdata
== NULL
)
1332 memcpy (bfd_ardata (abfd
)->tdata
, &hdr
, SIZEOF_AR_FILE_HDR_BIG
);
1335 if (! _bfd_xcoff_slurp_armap (abfd
))
1337 bfd_release (abfd
, bfd_ardata (abfd
));
1338 abfd
->tdata
.aout_ar_data
= (struct artdata
*) NULL
;
1345 /* Read the archive header in an XCOFF archive. */
1348 _bfd_xcoff_read_ar_hdr (abfd
)
1352 struct areltdata
*ret
;
1354 ret
= (struct areltdata
*) bfd_alloc (abfd
, sizeof (struct areltdata
));
1358 if (! xcoff_big_format_p (abfd
))
1360 struct xcoff_ar_hdr hdr
;
1361 struct xcoff_ar_hdr
*hdrp
;
1363 if (bfd_read ((PTR
) &hdr
, SIZEOF_AR_HDR
, 1, abfd
) != SIZEOF_AR_HDR
)
1369 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1370 hdrp
= (struct xcoff_ar_hdr
*) bfd_alloc (abfd
,
1371 SIZEOF_AR_HDR
+ namlen
+ 1);
1377 memcpy (hdrp
, &hdr
, SIZEOF_AR_HDR
);
1378 if (bfd_read ((char *) hdrp
+ SIZEOF_AR_HDR
, 1, namlen
, abfd
) != namlen
)
1383 ((char *) hdrp
)[SIZEOF_AR_HDR
+ namlen
] = '\0';
1385 ret
->arch_header
= (char *) hdrp
;
1386 ret
->parsed_size
= strtol (hdr
.size
, (char **) NULL
, 10);
1387 ret
->filename
= (char *) hdrp
+ SIZEOF_AR_HDR
;
1391 struct xcoff_ar_hdr_big hdr
;
1392 struct xcoff_ar_hdr_big
*hdrp
;
1394 if (bfd_read ((PTR
) &hdr
, SIZEOF_AR_HDR_BIG
, 1, abfd
)
1395 != SIZEOF_AR_HDR_BIG
)
1401 namlen
= strtol (hdr
.namlen
, (char **) NULL
, 10);
1402 hdrp
= (struct xcoff_ar_hdr_big
*) bfd_alloc (abfd
,
1410 memcpy (hdrp
, &hdr
, SIZEOF_AR_HDR_BIG
);
1411 if (bfd_read ((char *) hdrp
+ SIZEOF_AR_HDR_BIG
, 1, namlen
, abfd
) != namlen
)
1416 ((char *) hdrp
)[SIZEOF_AR_HDR_BIG
+ namlen
] = '\0';
1418 ret
->arch_header
= (char *) hdrp
;
1419 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1420 machines) since the field width is 20 and there numbers with more
1421 than 32 bits can be represented. */
1422 ret
->parsed_size
= strtol (hdr
.size
, (char **) NULL
, 10);
1423 ret
->filename
= (char *) hdrp
+ SIZEOF_AR_HDR_BIG
;
1426 /* Skip over the XCOFFARFMAG at the end of the file name. */
1427 if (bfd_seek (abfd
, (namlen
& 1) + SXCOFFARFMAG
, SEEK_CUR
) != 0)
1433 /* Open the next element in an XCOFF archive. */
1436 _bfd_xcoff_openr_next_archived_file (archive
, last_file
)
1442 if (xcoff_ardata (archive
) == NULL
)
1444 bfd_set_error (bfd_error_invalid_operation
);
1448 if (! xcoff_big_format_p (archive
))
1450 if (last_file
== NULL
)
1451 filestart
= bfd_ardata (archive
)->first_file_filepos
;
1453 filestart
= strtol (arch_xhdr (last_file
)->nextoff
, (char **) NULL
,
1457 || filestart
== strtol (xcoff_ardata (archive
)->memoff
,
1459 || filestart
== strtol (xcoff_ardata (archive
)->symoff
,
1460 (char **) NULL
, 10))
1462 bfd_set_error (bfd_error_no_more_archived_files
);
1468 if (last_file
== NULL
)
1469 filestart
= bfd_ardata (archive
)->first_file_filepos
;
1471 /* XXX These actually have to be a calls to strtoll (at least
1472 on 32-bit machines) since the fields's width is 20 and
1473 there numbers with more than 32 bits can be represented. */
1474 filestart
= strtol (arch_xhdr_big (last_file
)->nextoff
, (char **) NULL
,
1477 /* XXX These actually have to be calls to strtoll (at least on 32-bit
1478 machines) since the fields's width is 20 and there numbers with more
1479 than 32 bits can be represented. */
1481 || filestart
== strtol (xcoff_ardata_big (archive
)->memoff
,
1483 || filestart
== strtol (xcoff_ardata_big (archive
)->symoff
,
1484 (char **) NULL
, 10))
1486 bfd_set_error (bfd_error_no_more_archived_files
);
1491 return _bfd_get_elt_at_filepos (archive
, filestart
);
1494 /* Stat an element in an XCOFF archive. */
1497 _bfd_xcoff_generic_stat_arch_elt (abfd
, s
)
1501 if (abfd
->arelt_data
== NULL
)
1503 bfd_set_error (bfd_error_invalid_operation
);
1507 if (! xcoff_big_format_p (abfd
))
1509 struct xcoff_ar_hdr
*hdrp
= arch_xhdr (abfd
);
1511 s
->st_mtime
= strtol (hdrp
->date
, (char **) NULL
, 10);
1512 s
->st_uid
= strtol (hdrp
->uid
, (char **) NULL
, 10);
1513 s
->st_gid
= strtol (hdrp
->gid
, (char **) NULL
, 10);
1514 s
->st_mode
= strtol (hdrp
->mode
, (char **) NULL
, 8);
1515 s
->st_size
= arch_eltdata (abfd
)->parsed_size
;
1519 struct xcoff_ar_hdr_big
*hdrp
= arch_xhdr_big (abfd
);
1521 s
->st_mtime
= strtol (hdrp
->date
, (char **) NULL
, 10);
1522 s
->st_uid
= strtol (hdrp
->uid
, (char **) NULL
, 10);
1523 s
->st_gid
= strtol (hdrp
->gid
, (char **) NULL
, 10);
1524 s
->st_mode
= strtol (hdrp
->mode
, (char **) NULL
, 8);
1525 s
->st_size
= arch_eltdata (abfd
)->parsed_size
;
1531 /* Normalize a file name for inclusion in an archive. */
1534 normalize_filename (abfd
)
1538 const char *filename
;
1540 file
= bfd_get_filename (abfd
);
1541 filename
= strrchr (file
, '/');
1542 if (filename
!= NULL
)
1549 /* Write out an XCOFF armap. */
1553 xcoff_write_armap_old (abfd
, elength
, map
, orl_count
, stridx
)
1555 unsigned int elength ATTRIBUTE_UNUSED
;
1557 unsigned int orl_count
;
1560 struct xcoff_ar_hdr hdr
;
1562 unsigned char buf
[4];
1567 memset (&hdr
, 0, sizeof hdr
);
1568 sprintf (hdr
.size
, "%ld", (long) (4 + orl_count
* 4 + stridx
));
1569 sprintf (hdr
.nextoff
, "%d", 0);
1570 memcpy (hdr
.prevoff
, xcoff_ardata (abfd
)->memoff
, 12);
1571 sprintf (hdr
.date
, "%d", 0);
1572 sprintf (hdr
.uid
, "%d", 0);
1573 sprintf (hdr
.gid
, "%d", 0);
1574 sprintf (hdr
.mode
, "%d", 0);
1575 sprintf (hdr
.namlen
, "%d", 0);
1577 /* We need spaces, not null bytes, in the header. */
1578 for (p
= (char *) &hdr
; p
< (char *) &hdr
+ SIZEOF_AR_HDR
; p
++)
1582 if (bfd_write ((PTR
) &hdr
, SIZEOF_AR_HDR
, 1, abfd
) != SIZEOF_AR_HDR
1583 || bfd_write (XCOFFARFMAG
, 1, SXCOFFARFMAG
, abfd
) != SXCOFFARFMAG
)
1586 bfd_h_put_32 (abfd
, orl_count
, buf
);
1587 if (bfd_write (buf
, 1, 4, abfd
) != 4)
1590 sub
= abfd
->archive_head
;
1591 fileoff
= SIZEOF_AR_FILE_HDR
;
1593 while (sub
!= NULL
&& i
< orl_count
)
1597 while (((bfd
*) (map
[i
]).pos
) == sub
)
1599 bfd_h_put_32 (abfd
, fileoff
, buf
);
1600 if (bfd_write (buf
, 1, 4, abfd
) != 4)
1604 namlen
= strlen (normalize_filename (sub
));
1605 namlen
= (namlen
+ 1) &~ 1;
1606 fileoff
+= (SIZEOF_AR_HDR
1609 + arelt_size (sub
));
1610 fileoff
= (fileoff
+ 1) &~ 1;
1614 for (i
= 0; i
< orl_count
; i
++)
1619 name
= *map
[i
].name
;
1620 namlen
= strlen (name
);
1621 if (bfd_write (name
, 1, namlen
+ 1, abfd
) != namlen
+ 1)
1625 if ((stridx
& 1) != 0)
1630 if (bfd_write (&b
, 1, 1, abfd
) != 1)
1637 /* Write a single armap in the big format. */
1639 xcoff_write_one_armap_big (abfd
, map
, orl_count
, orl_ccount
, stridx
, bits64
,
1643 unsigned int orl_count
;
1644 unsigned int orl_ccount
;
1645 unsigned int stridx
;
1647 const char *prevoff
;
1650 struct xcoff_ar_hdr_big hdr
;
1652 unsigned char buf
[4];
1655 const bfd_arch_info_type
*arch_info
;
1659 memset (&hdr
, 0, sizeof hdr
);
1660 /* XXX This call actually should use %lld (at least on 32-bit
1661 machines) since the fields's width is 20 and there numbers with
1662 more than 32 bits can be represented. */
1663 sprintf (hdr
.size
, "%ld", (long) (4 + orl_ccount
* 4 + stridx
));
1665 sprintf (hdr
.nextoff
, "%d", 0);
1667 sprintf (hdr
.nextoff
, "%d", (strtol (prevoff
, (char **) NULL
, 10)
1668 + 4 + orl_ccount
* 4 + stridx
));
1669 memcpy (hdr
.prevoff
, prevoff
, sizeof (hdr
.prevoff
));
1670 sprintf (hdr
.date
, "%d", 0);
1671 sprintf (hdr
.uid
, "%d", 0);
1672 sprintf (hdr
.gid
, "%d", 0);
1673 sprintf (hdr
.mode
, "%d", 0);
1674 sprintf (hdr
.namlen
, "%d", 0);
1676 /* We need spaces, not null bytes, in the header. */
1677 for (p
= (char *) &hdr
; p
< (char *) &hdr
+ SIZEOF_AR_HDR_BIG
; p
++)
1681 memcpy (nextoff
, hdr
.nextoff
, sizeof (hdr
.nextoff
));
1683 if (bfd_write ((PTR
) &hdr
, SIZEOF_AR_HDR_BIG
, 1, abfd
) != SIZEOF_AR_HDR_BIG
1684 || bfd_write (XCOFFARFMAG
, 1, SXCOFFARFMAG
, abfd
) != SXCOFFARFMAG
)
1687 bfd_h_put_32 (abfd
, orl_ccount
, buf
);
1688 if (bfd_write (buf
, 1, 4, abfd
) != 4)
1691 sub
= abfd
->archive_head
;
1692 fileoff
= SIZEOF_AR_FILE_HDR_BIG
;
1694 while (sub
!= NULL
&& i
< orl_count
)
1698 if ((bfd_arch_bits_per_address ((bfd
*) map
[i
].pos
) == 64) == bits64
)
1699 while (((bfd
*) (map
[i
]).pos
) == sub
)
1701 bfd_h_put_32 (abfd
, fileoff
, buf
);
1702 if (bfd_write (buf
, 1, 4, abfd
) != 4)
1707 while (((bfd
*) (map
[i
]).pos
) == sub
)
1710 namlen
= strlen (normalize_filename (sub
));
1711 namlen
= (namlen
+ 1) &~ 1;
1712 fileoff
+= (SIZEOF_AR_HDR_BIG
1715 + arelt_size (sub
));
1716 fileoff
= (fileoff
+ 1) &~ 1;
1721 for (i
= 0; i
< orl_count
; i
++)
1725 bfd
*ob
= (bfd
*)map
[i
].pos
;
1727 if (ob
!= object_bfd
)
1728 arch_info
= bfd_get_arch_info (ob
);
1729 if ((arch_info
->bits_per_address
== 64) != bits64
)
1732 name
= *map
[i
].name
;
1733 namlen
= strlen (name
);
1734 if (bfd_write (name
, 1, namlen
+ 1, abfd
) != namlen
+ 1)
1738 if ((stridx
& 1) != 0)
1743 if (bfd_write (&b
, 1, 1, abfd
) != 1)
1752 xcoff_write_armap_big (abfd
, elength
, map
, orl_count
, stridx
)
1754 unsigned int elength ATTRIBUTE_UNUSED
;
1756 unsigned int orl_count
;
1760 unsigned int orl_count_32
, orl_count_64
;
1761 unsigned int stridx_32
, stridx_64
;
1762 const bfd_arch_info_type
*arch_info
;
1765 /* First, we look through the symbols and work out which are
1766 from 32-bit objects and which from 64-bit ones. */
1772 for (i
= 0; i
< orl_count
; i
++)
1774 bfd
*ob
= (bfd
*)map
[i
].pos
;
1776 if (ob
!= object_bfd
)
1777 arch_info
= bfd_get_arch_info (ob
);
1778 len
= strlen (*map
[i
].name
) + 1;
1779 if (arch_info
->bits_per_address
== 64)
1791 /* A quick sanity check... */
1792 BFD_ASSERT (orl_count_64
+ orl_count_32
== orl_count
);
1793 BFD_ASSERT (stridx_64
+ stridx_32
== stridx
);
1795 /* Now write out each map. */
1796 if (! xcoff_write_one_armap_big (abfd
, map
, orl_count
, orl_count_32
,
1798 xcoff_ardata_big (abfd
)->memoff
,
1799 xcoff_ardata_big (abfd
)->symoff
))
1801 if (! xcoff_write_one_armap_big (abfd
, map
, orl_count
, orl_count_64
,
1803 xcoff_ardata_big (abfd
)->symoff
,
1804 xcoff_ardata_big (abfd
)->symoff64
))
1812 _bfd_xcoff_write_armap (abfd
, elength
, map
, orl_count
, stridx
)
1814 unsigned int elength ATTRIBUTE_UNUSED
;
1816 unsigned int orl_count
;
1819 if (! xcoff_big_format_p (abfd
))
1820 return xcoff_write_armap_old (abfd
, elength
, map
, orl_count
, stridx
);
1822 return xcoff_write_armap_big (abfd
, elength
, map
, orl_count
, stridx
);
1825 /* Write out an XCOFF archive. We always write an entire archive,
1826 rather than fussing with the freelist and so forth. */
1829 xcoff_write_archive_contents_old (abfd
)
1832 struct xcoff_ar_file_hdr fhdr
;
1834 size_t total_namlen
;
1838 file_ptr prevoff
, nextoff
;
1841 struct xcoff_ar_hdr ahdr
;
1846 memset (&fhdr
, 0, sizeof fhdr
);
1847 strncpy (fhdr
.magic
, XCOFFARMAG
, SXCOFFARMAG
);
1848 sprintf (fhdr
.firstmemoff
, "%d", SIZEOF_AR_FILE_HDR
);
1849 sprintf (fhdr
.freeoff
, "%d", 0);
1853 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->next
)
1856 total_namlen
+= strlen (normalize_filename (sub
)) + 1;
1858 offsets
= (file_ptr
*) bfd_alloc (abfd
, count
* sizeof (file_ptr
));
1859 if (offsets
== NULL
)
1862 if (bfd_seek (abfd
, SIZEOF_AR_FILE_HDR
, SEEK_SET
) != 0)
1865 makemap
= bfd_has_map (abfd
);
1868 nextoff
= SIZEOF_AR_FILE_HDR
;
1869 for (sub
= abfd
->archive_head
, i
= 0; sub
!= NULL
; sub
= sub
->next
, i
++)
1873 struct xcoff_ar_hdr
*ahdrp
;
1874 bfd_size_type remaining
;
1876 if (makemap
&& ! hasobjects
)
1878 if (bfd_check_format (sub
, bfd_object
))
1882 name
= normalize_filename (sub
);
1883 namlen
= strlen (name
);
1885 if (sub
->arelt_data
!= NULL
)
1886 ahdrp
= arch_xhdr (sub
);
1894 memset (&ahdr
, 0, sizeof ahdr
);
1896 if (stat (bfd_get_filename (sub
), &s
) != 0)
1898 bfd_set_error (bfd_error_system_call
);
1902 sprintf (ahdrp
->size
, "%ld", (long) s
.st_size
);
1903 sprintf (ahdrp
->date
, "%ld", (long) s
.st_mtime
);
1904 sprintf (ahdrp
->uid
, "%ld", (long) s
.st_uid
);
1905 sprintf (ahdrp
->gid
, "%ld", (long) s
.st_gid
);
1906 sprintf (ahdrp
->mode
, "%o", (unsigned int) s
.st_mode
);
1908 if (sub
->arelt_data
== NULL
)
1910 sub
->arelt_data
= bfd_alloc (sub
, sizeof (struct areltdata
));
1911 if (sub
->arelt_data
== NULL
)
1915 arch_eltdata (sub
)->parsed_size
= s
.st_size
;
1918 sprintf (ahdrp
->prevoff
, "%ld", (long) prevoff
);
1919 sprintf (ahdrp
->namlen
, "%ld", (long) namlen
);
1921 /* If the length of the name is odd, we write out the null byte
1922 after the name as well. */
1923 namlen
= (namlen
+ 1) &~ 1;
1925 remaining
= arelt_size (sub
);
1926 size
= (SIZEOF_AR_HDR
1931 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
1933 offsets
[i
] = nextoff
;
1936 nextoff
+= size
+ (size
& 1);
1938 sprintf (ahdrp
->nextoff
, "%ld", (long) nextoff
);
1940 /* We need spaces, not null bytes, in the header. */
1941 for (p
= (char *) ahdrp
; p
< (char *) ahdrp
+ SIZEOF_AR_HDR
; p
++)
1945 if (bfd_write ((PTR
) ahdrp
, 1, SIZEOF_AR_HDR
, abfd
) != SIZEOF_AR_HDR
1946 || bfd_write ((PTR
) name
, 1, namlen
, abfd
) != namlen
1947 || (bfd_write ((PTR
) XCOFFARFMAG
, 1, SXCOFFARFMAG
, abfd
)
1951 if (bfd_seek (sub
, (file_ptr
) 0, SEEK_SET
) != 0)
1953 while (remaining
!= 0)
1956 bfd_byte buffer
[DEFAULT_BUFFERSIZE
];
1958 amt
= sizeof buffer
;
1959 if (amt
> remaining
)
1961 if (bfd_read (buffer
, 1, amt
, sub
) != amt
1962 || bfd_write (buffer
, 1, amt
, abfd
) != amt
)
1967 if ((size
& 1) != 0)
1972 if (bfd_write (&b
, 1, 1, abfd
) != 1)
1977 sprintf (fhdr
.lastmemoff
, "%ld", (long) prevoff
);
1979 /* Write out the member table. */
1981 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
1982 sprintf (fhdr
.memoff
, "%ld", (long) nextoff
);
1984 memset (&ahdr
, 0, sizeof ahdr
);
1985 sprintf (ahdr
.size
, "%ld", (long) (12 + count
* 12 + total_namlen
));
1986 sprintf (ahdr
.prevoff
, "%ld", (long) prevoff
);
1987 sprintf (ahdr
.date
, "%d", 0);
1988 sprintf (ahdr
.uid
, "%d", 0);
1989 sprintf (ahdr
.gid
, "%d", 0);
1990 sprintf (ahdr
.mode
, "%d", 0);
1991 sprintf (ahdr
.namlen
, "%d", 0);
1993 size
= (SIZEOF_AR_HDR
2000 nextoff
+= size
+ (size
& 1);
2002 if (makemap
&& hasobjects
)
2003 sprintf (ahdr
.nextoff
, "%ld", (long) nextoff
);
2005 sprintf (ahdr
.nextoff
, "%d", 0);
2007 /* We need spaces, not null bytes, in the header. */
2008 for (p
= (char *) &ahdr
; p
< (char *) &ahdr
+ SIZEOF_AR_HDR
; p
++)
2012 if (bfd_write ((PTR
) &ahdr
, 1, SIZEOF_AR_HDR
, abfd
) != SIZEOF_AR_HDR
2013 || (bfd_write ((PTR
) XCOFFARFMAG
, 1, SXCOFFARFMAG
, abfd
)
2017 sprintf (decbuf
, "%-12ld", (long) count
);
2018 if (bfd_write ((PTR
) decbuf
, 1, 12, abfd
) != 12)
2020 for (i
= 0; i
< count
; i
++)
2022 sprintf (decbuf
, "%-12ld", (long) offsets
[i
]);
2023 if (bfd_write ((PTR
) decbuf
, 1, 12, abfd
) != 12)
2026 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->next
)
2031 name
= normalize_filename (sub
);
2032 namlen
= strlen (name
);
2033 if (bfd_write ((PTR
) name
, 1, namlen
+ 1, abfd
) != namlen
+ 1)
2036 if ((size
& 1) != 0)
2041 if (bfd_write ((PTR
) &b
, 1, 1, abfd
) != 1)
2045 /* Write out the armap, if appropriate. */
2047 if (! makemap
|| ! hasobjects
)
2048 sprintf (fhdr
.symoff
, "%d", 0);
2051 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2052 sprintf (fhdr
.symoff
, "%ld", (long) nextoff
);
2053 bfd_ardata (abfd
)->tdata
= (PTR
) &fhdr
;
2054 if (! _bfd_compute_and_write_armap (abfd
, 0))
2058 /* Write out the archive file header. */
2060 /* We need spaces, not null bytes, in the header. */
2061 for (p
= (char *) &fhdr
; p
< (char *) &fhdr
+ SIZEOF_AR_FILE_HDR
; p
++)
2065 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
2066 || (bfd_write ((PTR
) &fhdr
, SIZEOF_AR_FILE_HDR
, 1, abfd
) !=
2067 SIZEOF_AR_FILE_HDR
))
2074 xcoff_write_archive_contents_big (abfd
)
2077 struct xcoff_ar_file_hdr_big fhdr
;
2079 size_t total_namlen
;
2083 file_ptr prevoff
, nextoff
;
2086 struct xcoff_ar_hdr_big ahdr
;
2091 memset (&fhdr
, 0, sizeof fhdr
);
2092 strncpy (fhdr
.magic
, XCOFFARMAGBIG
, SXCOFFARMAG
);
2093 sprintf (fhdr
.firstmemoff
, "%d", SIZEOF_AR_FILE_HDR_BIG
);
2094 sprintf (fhdr
.freeoff
, "%d", 0);
2098 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->next
)
2101 total_namlen
+= strlen (normalize_filename (sub
)) + 1;
2103 offsets
= (file_ptr
*) bfd_alloc (abfd
, count
* sizeof (file_ptr
));
2104 if (offsets
== NULL
)
2107 if (bfd_seek (abfd
, SIZEOF_AR_FILE_HDR_BIG
, SEEK_SET
) != 0)
2110 makemap
= bfd_has_map (abfd
);
2113 nextoff
= SIZEOF_AR_FILE_HDR_BIG
;
2114 for (sub
= abfd
->archive_head
, i
= 0; sub
!= NULL
; sub
= sub
->next
, i
++)
2118 struct xcoff_ar_hdr_big
*ahdrp
;
2119 bfd_size_type remaining
;
2121 if (makemap
&& ! hasobjects
)
2123 if (bfd_check_format (sub
, bfd_object
))
2127 name
= normalize_filename (sub
);
2128 namlen
= strlen (name
);
2130 if (sub
->arelt_data
!= NULL
)
2131 ahdrp
= arch_xhdr_big (sub
);
2139 memset (&ahdr
, 0, sizeof ahdr
);
2141 /* XXX This should actually be a call to stat64 (at least on
2142 32-bit machines). */
2143 if (stat (bfd_get_filename (sub
), &s
) != 0)
2145 bfd_set_error (bfd_error_system_call
);
2149 /* XXX This call actually should use %lld (at least on 32-bit
2150 machines) since the fields's width is 20 and there numbers with
2151 more than 32 bits can be represented. */
2152 sprintf (ahdrp
->size
, "%ld", (long) s
.st_size
);
2153 sprintf (ahdrp
->date
, "%ld", (long) s
.st_mtime
);
2154 sprintf (ahdrp
->uid
, "%ld", (long) s
.st_uid
);
2155 sprintf (ahdrp
->gid
, "%ld", (long) s
.st_gid
);
2156 sprintf (ahdrp
->mode
, "%o", (unsigned int) s
.st_mode
);
2158 if (sub
->arelt_data
== NULL
)
2160 sub
->arelt_data
= bfd_alloc (sub
, sizeof (struct areltdata
));
2161 if (sub
->arelt_data
== NULL
)
2165 arch_eltdata (sub
)->parsed_size
= s
.st_size
;
2168 /* XXX These calls actually should use %lld (at least on 32-bit
2169 machines) since the fields's width is 20 and there numbers with
2170 more than 32 bits can be represented. */
2171 sprintf (ahdrp
->prevoff
, "%ld", (long) prevoff
);
2172 sprintf (ahdrp
->namlen
, "%ld", (long) namlen
);
2174 /* If the length of the name is odd, we write out the null byte
2175 after the name as well. */
2176 namlen
= (namlen
+ 1) &~ 1;
2178 remaining
= arelt_size (sub
);
2179 size
= (SIZEOF_AR_HDR_BIG
2184 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2186 offsets
[i
] = nextoff
;
2189 nextoff
+= size
+ (size
& 1);
2191 sprintf (ahdrp
->nextoff
, "%ld", (long) nextoff
);
2193 /* We need spaces, not null bytes, in the header. */
2194 for (p
= (char *) ahdrp
; p
< (char *) ahdrp
+ SIZEOF_AR_HDR_BIG
; p
++)
2198 if (bfd_write ((PTR
) ahdrp
, 1, SIZEOF_AR_HDR_BIG
, abfd
)
2199 != SIZEOF_AR_HDR_BIG
2200 || bfd_write ((PTR
) name
, 1, namlen
, abfd
) != namlen
2201 || (bfd_write ((PTR
) XCOFFARFMAG
, 1, SXCOFFARFMAG
, abfd
)
2205 if (bfd_seek (sub
, (file_ptr
) 0, SEEK_SET
) != 0)
2207 while (remaining
!= 0)
2210 bfd_byte buffer
[DEFAULT_BUFFERSIZE
];
2212 amt
= sizeof buffer
;
2213 if (amt
> remaining
)
2215 if (bfd_read (buffer
, 1, amt
, sub
) != amt
2216 || bfd_write (buffer
, 1, amt
, abfd
) != amt
)
2221 if ((size
& 1) != 0)
2226 if (bfd_write (&b
, 1, 1, abfd
) != 1)
2231 /* XXX This call actually should use %lld (at least on 32-bit
2232 machines) since the fields's width is 20 and there numbers with
2233 more than 32 bits can be represented. */
2234 sprintf (fhdr
.lastmemoff
, "%ld", (long) prevoff
);
2236 /* Write out the member table. */
2238 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2239 /* XXX This call actually should use %lld (at least on 32-bit
2240 machines) since the fields's width is 20 and there numbers with
2241 more than 32 bits can be represented. */
2242 sprintf (fhdr
.memoff
, "%ld", (long) nextoff
);
2244 memset (&ahdr
, 0, sizeof ahdr
);
2245 /* XXX The next two calls actually should use %lld (at least on 32-bit
2246 machines) since the fields's width is 20 and there numbers with
2247 more than 32 bits can be represented. */
2248 sprintf (ahdr
.size
, "%ld", (long) (12 + count
* 12 + total_namlen
));
2249 sprintf (ahdr
.prevoff
, "%ld", (long) prevoff
);
2250 sprintf (ahdr
.date
, "%d", 0);
2251 sprintf (ahdr
.uid
, "%d", 0);
2252 sprintf (ahdr
.gid
, "%d", 0);
2253 sprintf (ahdr
.mode
, "%d", 0);
2254 sprintf (ahdr
.namlen
, "%d", 0);
2256 size
= (SIZEOF_AR_HDR_BIG
2263 nextoff
+= size
+ (size
& 1);
2265 if (makemap
&& hasobjects
)
2266 /* XXX This call actually should use %lld (at least on 32-bit
2267 machines) since the fields's width is 20 and there numbers with
2268 more than 32 bits can be represented. */
2269 sprintf (ahdr
.nextoff
, "%ld", (long) nextoff
);
2271 sprintf (ahdr
.nextoff
, "%d", 0);
2273 /* We need spaces, not null bytes, in the header. */
2274 for (p
= (char *) &ahdr
; p
< (char *) &ahdr
+ SIZEOF_AR_HDR_BIG
; p
++)
2278 if (bfd_write ((PTR
) &ahdr
, 1, SIZEOF_AR_HDR_BIG
, abfd
) != SIZEOF_AR_HDR_BIG
2279 || (bfd_write ((PTR
) XCOFFARFMAG
, 1, SXCOFFARFMAG
, abfd
)
2283 sprintf (decbuf
, "%-12ld", (long) count
);
2284 if (bfd_write ((PTR
) decbuf
, 1, 12, abfd
) != 12)
2286 for (i
= 0; i
< count
; i
++)
2288 sprintf (decbuf
, "%-12ld", (long) offsets
[i
]);
2289 if (bfd_write ((PTR
) decbuf
, 1, 12, abfd
) != 12)
2292 for (sub
= abfd
->archive_head
; sub
!= NULL
; sub
= sub
->next
)
2297 name
= normalize_filename (sub
);
2298 namlen
= strlen (name
);
2299 if (bfd_write ((PTR
) name
, 1, namlen
+ 1, abfd
) != namlen
+ 1)
2302 if ((size
& 1) != 0)
2307 if (bfd_write ((PTR
) &b
, 1, 1, abfd
) != 1)
2311 /* Write out the armap, if appropriate. */
2313 if (! makemap
|| ! hasobjects
)
2314 sprintf (fhdr
.symoff
, "%d", 0);
2317 BFD_ASSERT (nextoff
== bfd_tell (abfd
));
2318 /* XXX This call actually should use %lld (at least on 32-bit
2319 machines) since the fields's width is 20 and there numbers with
2320 more than 32 bits can be represented. */
2321 bfd_ardata (abfd
)->tdata
= (PTR
) &fhdr
;
2322 if (! _bfd_compute_and_write_armap (abfd
, 0))
2326 /* Write out the archive file header. */
2328 /* We need spaces, not null bytes, in the header. */
2329 for (p
= (char *) &fhdr
; p
< (char *) &fhdr
+ SIZEOF_AR_FILE_HDR_BIG
; p
++)
2333 if (bfd_seek (abfd
, (file_ptr
) 0, SEEK_SET
) != 0
2334 || (bfd_write ((PTR
) &fhdr
, SIZEOF_AR_FILE_HDR_BIG
, 1, abfd
) !=
2335 SIZEOF_AR_FILE_HDR_BIG
))
2342 _bfd_xcoff_write_archive_contents (abfd
)
2345 if (! xcoff_big_format_p (abfd
))
2346 return xcoff_write_archive_contents_old (abfd
);
2348 return xcoff_write_archive_contents_big (abfd
);
2351 /* We can't use the usual coff_sizeof_headers routine, because AIX
2352 always uses an a.out header. */
2356 _bfd_xcoff_sizeof_headers (abfd
, reloc
)
2358 boolean reloc ATTRIBUTE_UNUSED
;
2363 if (xcoff_data (abfd
)->full_aouthdr
)
2366 size
+= SMALL_AOUTSZ
;
2367 size
+= abfd
->section_count
* SCNHSZ
;