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. */
29 /* Internalcoff.h and coffcode.h modify themselves based on this flag. */
30 #define RS6000COFF_C 1
35 #include "coff/internal.h"
36 #include "coff/rs6000.h"
39 /* The main body of code is in coffcode.h. */
41 static boolean xcoff_mkobject PARAMS ((bfd *));
42 static boolean xcoff_copy_private_bfd_data PARAMS ((bfd *, bfd *));
43 static boolean xcoff_is_local_label_name PARAMS ((bfd *, const char *));
44 static void xcoff_rtype2howto
45 PARAMS ((arelent *, struct internal_reloc *));
46 static reloc_howto_type *xcoff_reloc_type_lookup
47 PARAMS ((bfd *, bfd_reloc_code_real_type));
48 static boolean xcoff_slurp_armap PARAMS ((bfd *));
49 static const bfd_target *xcoff_archive_p PARAMS ((bfd *));
50 static PTR xcoff_read_ar_hdr PARAMS ((bfd *));
51 static bfd *xcoff_openr_next_archived_file PARAMS ((bfd *, bfd *));
52 static int xcoff_generic_stat_arch_elt PARAMS ((bfd *, struct stat *));
53 static const char *normalize_filename PARAMS ((bfd *));
54 static boolean xcoff_write_armap
55 PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int));
56 static boolean xcoff_write_archive_contents PARAMS ((bfd *));
57 static int _bfd_xcoff_sizeof_headers PARAMS ((bfd *, boolean));
59 /* We use our own tdata type. Its first field is the COFF tdata type,
60 so the COFF routines are compatible. */
68 abfd->tdata.xcoff_obj_data =
69 ((struct xcoff_tdata *)
70 bfd_zalloc (abfd, sizeof (struct xcoff_tdata)));
71 if (abfd->tdata.xcoff_obj_data == NULL)
73 coff = coff_data (abfd);
74 coff->symbols = (coff_symbol_type *) NULL;
75 coff->conversion_table = (unsigned int *) NULL;
76 coff->raw_syments = (struct coff_ptr_struct *) NULL;
79 xcoff_data (abfd)->modtype = ('1' << 8) | 'L';
81 /* We set cputype to -1 to indicate that it has not been
83 xcoff_data (abfd)->cputype = -1;
85 xcoff_data (abfd)->csects = NULL;
86 xcoff_data (abfd)->debug_indices = NULL;
91 /* Copy XCOFF data from one BFD to another. */
94 xcoff_copy_private_bfd_data (ibfd, obfd)
98 struct xcoff_tdata *ix, *ox;
101 if (ibfd->xvec != obfd->xvec)
103 ix = xcoff_data (ibfd);
104 ox = xcoff_data (obfd);
105 ox->full_aouthdr = ix->full_aouthdr;
111 sec = coff_section_from_bfd_index (ibfd, ix->sntoc);
115 ox->sntoc = sec->output_section->target_index;
117 if (ix->snentry == 0)
121 sec = coff_section_from_bfd_index (ibfd, ix->snentry);
125 ox->snentry = sec->output_section->target_index;
127 ox->text_align_power = ix->text_align_power;
128 ox->data_align_power = ix->data_align_power;
129 ox->modtype = ix->modtype;
130 ox->cputype = ix->cputype;
131 ox->maxdata = ix->maxdata;
132 ox->maxstack = ix->maxstack;
136 /* I don't think XCOFF really has a notion of local labels based on
137 name. This will mean that ld -X doesn't actually strip anything.
138 The AIX native linker does not have a -X option, and it ignores the
142 xcoff_is_local_label_name (abfd, name)
143 bfd *abfd ATTRIBUTE_UNUSED;
144 const char *name ATTRIBUTE_UNUSED;
149 /* The XCOFF reloc table. Actually, XCOFF relocations specify the
150 bitsize and whether they are signed or not, along with a
151 conventional type. This table is for the types, which are used for
152 different algorithms for putting in the reloc. Many of these
153 relocs need special_function entries, which I have not written. */
155 static reloc_howto_type xcoff_howto_table[] =
157 /* Standard 32 bit relocation. */
160 2, /* size (0 = byte, 1 = short, 2 = long) */
162 false, /* pc_relative */
164 complain_overflow_bitfield, /* complain_on_overflow */
165 0, /* special_function */
167 true, /* partial_inplace */
168 0xffffffff, /* src_mask */
169 0xffffffff, /* dst_mask */
170 false), /* pcrel_offset */
172 /* 32 bit relocation, but store negative value. */
175 -2, /* size (0 = byte, 1 = short, 2 = long) */
177 false, /* pc_relative */
179 complain_overflow_bitfield, /* complain_on_overflow */
180 0, /* special_function */
182 true, /* partial_inplace */
183 0xffffffff, /* src_mask */
184 0xffffffff, /* dst_mask */
185 false), /* pcrel_offset */
187 /* 32 bit PC relative relocation. */
190 2, /* size (0 = byte, 1 = short, 2 = long) */
192 true, /* pc_relative */
194 complain_overflow_signed, /* complain_on_overflow */
195 0, /* special_function */
197 true, /* partial_inplace */
198 0xffffffff, /* src_mask */
199 0xffffffff, /* dst_mask */
200 false), /* pcrel_offset */
202 /* 16 bit TOC relative relocation. */
205 1, /* size (0 = byte, 1 = short, 2 = long) */
207 false, /* pc_relative */
209 complain_overflow_bitfield, /* complain_on_overflow */
210 0, /* special_function */
212 true, /* partial_inplace */
213 0xffff, /* src_mask */
214 0xffff, /* dst_mask */
215 false), /* pcrel_offset */
217 /* I don't really know what this is. */
220 2, /* size (0 = byte, 1 = short, 2 = long) */
222 false, /* pc_relative */
224 complain_overflow_bitfield, /* complain_on_overflow */
225 0, /* special_function */
227 true, /* partial_inplace */
228 0xffffffff, /* src_mask */
229 0xffffffff, /* dst_mask */
230 false), /* pcrel_offset */
232 /* External TOC relative symbol. */
235 2, /* size (0 = byte, 1 = short, 2 = long) */
237 false, /* pc_relative */
239 complain_overflow_bitfield, /* complain_on_overflow */
240 0, /* special_function */
242 true, /* partial_inplace */
243 0xffff, /* src_mask */
244 0xffff, /* dst_mask */
245 false), /* pcrel_offset */
247 /* Local TOC relative symbol. */
250 2, /* size (0 = byte, 1 = short, 2 = long) */
252 false, /* pc_relative */
254 complain_overflow_bitfield, /* complain_on_overflow */
255 0, /* special_function */
257 true, /* partial_inplace */
258 0xffff, /* src_mask */
259 0xffff, /* dst_mask */
260 false), /* pcrel_offset */
264 /* Non modifiable absolute branch. */
267 2, /* size (0 = byte, 1 = short, 2 = long) */
269 false, /* pc_relative */
271 complain_overflow_bitfield, /* complain_on_overflow */
272 0, /* special_function */
274 true, /* partial_inplace */
275 0x3fffffc, /* src_mask */
276 0x3fffffc, /* dst_mask */
277 false), /* pcrel_offset */
281 /* Non modifiable relative branch. */
282 HOWTO (0xa, /* type */
284 2, /* size (0 = byte, 1 = short, 2 = long) */
286 true, /* pc_relative */
288 complain_overflow_signed, /* complain_on_overflow */
289 0, /* special_function */
291 true, /* partial_inplace */
292 0x3fffffc, /* src_mask */
293 0x3fffffc, /* dst_mask */
294 false), /* pcrel_offset */
299 HOWTO (0xc, /* type */
301 2, /* size (0 = byte, 1 = short, 2 = long) */
303 false, /* pc_relative */
305 complain_overflow_bitfield, /* complain_on_overflow */
306 0, /* special_function */
308 true, /* partial_inplace */
309 0xffff, /* src_mask */
310 0xffff, /* dst_mask */
311 false), /* pcrel_offset */
314 HOWTO (0xd, /* type */
316 2, /* size (0 = byte, 1 = short, 2 = long) */
318 false, /* pc_relative */
320 complain_overflow_bitfield, /* complain_on_overflow */
321 0, /* special_function */
323 true, /* partial_inplace */
324 0xffff, /* src_mask */
325 0xffff, /* dst_mask */
326 false), /* pcrel_offset */
330 /* Non-relocating reference. */
331 HOWTO (0xf, /* type */
333 2, /* size (0 = byte, 1 = short, 2 = long) */
335 false, /* pc_relative */
337 complain_overflow_bitfield, /* complain_on_overflow */
338 0, /* special_function */
340 false, /* partial_inplace */
343 false), /* pcrel_offset */
348 /* TOC relative indirect load. */
349 HOWTO (0x12, /* type */
351 2, /* size (0 = byte, 1 = short, 2 = long) */
353 false, /* pc_relative */
355 complain_overflow_bitfield, /* complain_on_overflow */
356 0, /* special_function */
358 true, /* partial_inplace */
359 0xffff, /* src_mask */
360 0xffff, /* dst_mask */
361 false), /* pcrel_offset */
363 /* TOC relative load address. */
364 HOWTO (0x13, /* type */
366 2, /* size (0 = byte, 1 = short, 2 = long) */
368 false, /* pc_relative */
370 complain_overflow_bitfield, /* complain_on_overflow */
371 0, /* special_function */
373 true, /* partial_inplace */
374 0xffff, /* src_mask */
375 0xffff, /* dst_mask */
376 false), /* pcrel_offset */
378 /* Modifiable relative branch. */
379 HOWTO (0x14, /* type */
381 2, /* size (0 = byte, 1 = short, 2 = long) */
383 false, /* pc_relative */
385 complain_overflow_bitfield, /* complain_on_overflow */
386 0, /* special_function */
387 "R_RRTBI", /* name */
388 true, /* partial_inplace */
389 0xffffffff, /* src_mask */
390 0xffffffff, /* dst_mask */
391 false), /* pcrel_offset */
393 /* Modifiable absolute branch. */
394 HOWTO (0x15, /* type */
396 2, /* size (0 = byte, 1 = short, 2 = long) */
398 false, /* pc_relative */
400 complain_overflow_bitfield, /* complain_on_overflow */
401 0, /* special_function */
402 "R_RRTBA", /* name */
403 true, /* partial_inplace */
404 0xffffffff, /* src_mask */
405 0xffffffff, /* dst_mask */
406 false), /* pcrel_offset */
408 /* Modifiable call absolute indirect. */
409 HOWTO (0x16, /* type */
411 2, /* size (0 = byte, 1 = short, 2 = long) */
413 false, /* pc_relative */
415 complain_overflow_bitfield, /* complain_on_overflow */
416 0, /* special_function */
418 true, /* partial_inplace */
419 0xffff, /* src_mask */
420 0xffff, /* dst_mask */
421 false), /* pcrel_offset */
423 /* Modifiable call relative. */
424 HOWTO (0x17, /* type */
426 2, /* size (0 = byte, 1 = short, 2 = long) */
428 false, /* pc_relative */
430 complain_overflow_bitfield, /* complain_on_overflow */
431 0, /* special_function */
433 true, /* partial_inplace */
434 0xffff, /* src_mask */
435 0xffff, /* dst_mask */
436 false), /* pcrel_offset */
438 /* Modifiable branch absolute. */
439 HOWTO (0x18, /* type */
441 2, /* size (0 = byte, 1 = short, 2 = long) */
443 false, /* pc_relative */
445 complain_overflow_bitfield, /* complain_on_overflow */
446 0, /* special_function */
448 true, /* partial_inplace */
449 0xffff, /* src_mask */
450 0xffff, /* dst_mask */
451 false), /* pcrel_offset */
453 /* Modifiable branch absolute. */
454 HOWTO (0x19, /* type */
456 2, /* size (0 = byte, 1 = short, 2 = long) */
458 false, /* pc_relative */
460 complain_overflow_bitfield, /* complain_on_overflow */
461 0, /* special_function */
463 true, /* partial_inplace */
464 0xffff, /* src_mask */
465 0xffff, /* dst_mask */
466 false), /* pcrel_offset */
468 /* Modifiable branch relative. */
469 HOWTO (0x1a, /* type */
471 2, /* size (0 = byte, 1 = short, 2 = long) */
473 false, /* pc_relative */
475 complain_overflow_signed, /* complain_on_overflow */
476 0, /* special_function */
478 true, /* partial_inplace */
479 0xffff, /* src_mask */
480 0xffff, /* dst_mask */
481 false), /* pcrel_offset */
483 /* Modifiable branch absolute. */
484 HOWTO (0x1b, /* type */
486 2, /* size (0 = byte, 1 = short, 2 = long) */
488 false, /* pc_relative */
490 complain_overflow_bitfield, /* complain_on_overflow */
491 0, /* special_function */
493 true, /* partial_inplace */
494 0xffff, /* src_mask */
495 0xffff, /* dst_mask */
496 false) /* pcrel_offset */
499 /* These are the first two like the above but for 16-bit relocs. */
500 static reloc_howto_type xcoff_howto_table_16[] =
502 /* Standard 16 bit relocation. */
505 2, /* size (0 = byte, 1 = short, 2 = long) */
507 false, /* pc_relative */
509 complain_overflow_bitfield, /* complain_on_overflow */
510 0, /* special_function */
511 "R_POS_16", /* name */
512 true, /* partial_inplace */
513 0xffffffff, /* src_mask */
514 0xffffffff, /* dst_mask */
515 false), /* pcrel_offset */
517 /* 16 bit relocation, but store negative value. */
520 -2, /* size (0 = byte, 1 = short, 2 = long) */
522 false, /* pc_relative */
524 complain_overflow_bitfield, /* complain_on_overflow */
525 0, /* special_function */
526 "R_NEG_16", /* name */
527 true, /* partial_inplace */
528 0xffffffff, /* src_mask */
529 0xffffffff, /* dst_mask */
530 false), /* pcrel_offset */
532 /* 16 bit PC relative relocation. */
535 2, /* size (0 = byte, 1 = short, 2 = long) */
537 true, /* pc_relative */
539 complain_overflow_signed, /* complain_on_overflow */
540 0, /* special_function */
541 "R_REL_16", /* name */
542 true, /* partial_inplace */
543 0xffffffff, /* src_mask */
544 0xffffffff, /* dst_mask */
545 false), /* pcrel_offset */
549 xcoff_rtype2howto (relent, internal)
551 struct internal_reloc *internal;
553 relent->howto = xcoff_howto_table + internal->r_type;
555 if (relent->howto->bitsize != ((unsigned int) internal->r_size & 0x1f) + 1
557 < sizeof(xcoff_howto_table_16)/sizeof(xcoff_howto_table_16[0])))
558 relent->howto = xcoff_howto_table_16 + internal->r_type;
560 /* The r_size field of an XCOFF reloc encodes the bitsize of the
561 relocation, as well as indicating whether it is signed or not.
562 Doublecheck that the relocation information gathered from the
563 type matches this information. */
564 if (relent->howto->bitsize != ((unsigned int) internal->r_size & 0x1f) + 1)
567 if ((internal->r_size & 0x80) != 0
568 ? (relent->howto->complain_on_overflow != complain_overflow_signed)
569 : (relent->howto->complain_on_overflow != complain_overflow_bitfield))
574 static reloc_howto_type *
575 xcoff_reloc_type_lookup (abfd, code)
576 bfd *abfd ATTRIBUTE_UNUSED;
577 bfd_reloc_code_real_type code;
581 case BFD_RELOC_PPC_B26:
582 return &xcoff_howto_table[0xa];
583 case BFD_RELOC_PPC_BA26:
584 return &xcoff_howto_table[8];
585 case BFD_RELOC_PPC_TOC16:
586 return &xcoff_howto_table[3];
589 return &xcoff_howto_table[0];
595 #define SELECT_RELOC(internal, howto) \
597 internal.r_type = howto->type; \
599 ((howto->complain_on_overflow == complain_overflow_signed \
602 | (howto->bitsize - 1)); \
605 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
607 #define COFF_LONG_FILENAMES
609 #define RTYPE2HOWTO(cache_ptr, dst) xcoff_rtype2howto (cache_ptr, dst)
611 #define coff_mkobject xcoff_mkobject
612 #define coff_bfd_copy_private_bfd_data xcoff_copy_private_bfd_data
613 #define coff_bfd_is_local_label_name xcoff_is_local_label_name
614 #define coff_bfd_reloc_type_lookup xcoff_reloc_type_lookup
615 #define coff_relocate_section _bfd_ppc_xcoff_relocate_section
617 #include "coffcode.h"
619 /* XCOFF archive support. The original version of this code was by
620 Damon A. Permezel. It was enhanced to permit cross support, and
621 writing archive files, by Ian Lance Taylor, Cygnus Support.
623 XCOFF uses its own archive format. Everything is hooked together
624 with file offset links, so it is possible to rapidly update an
625 archive in place. Of course, we don't do that. An XCOFF archive
626 has a real file header, not just an ARMAG string. The structure of
627 the file header and of each archive header appear below.
629 An XCOFF archive also has a member table, which is a list of
630 elements in the archive (you can get that by looking through the
631 linked list, but you have to read a lot more of the file). The
632 member table has a normal archive header with an empty name. It is
633 normally (and perhaps must be) the second to last entry in the
634 archive. The member table data is almost printable ASCII. It
635 starts with a 12 character decimal string which is the number of
636 entries in the table. For each entry it has a 12 character decimal
637 string which is the offset in the archive of that member. These
638 entries are followed by a series of null terminated strings which
639 are the member names for each entry.
641 Finally, an XCOFF archive has a global symbol table, which is what
642 we call the armap. The global symbol table has a normal archive
643 header with an empty name. It is normally (and perhaps must be)
644 the last entry in the archive. The contents start with a four byte
645 binary number which is the number of entries. This is followed by
646 a that many four byte binary numbers; each is the file offset of an
647 entry in the archive. These numbers are followed by a series of
648 null terminated strings, which are symbol names.
650 AIX 4.3 introduced a new archive format which can handle larger
651 files and also 32- and 64-bit objects in the same archive. The
652 things said above remain true except that there is now more than
653 one global symbol table. The one is used to index 32-bit objects,
654 the other for 64-bit objects.
656 The new archives (recognizable by the new ARMAG string) has larger
657 field lengths so that we cannot really share any code. Also we have
658 to take care that we are not generating the new form of archives
659 on AIX 4.2 or earlier systems. */
661 /* XCOFF archives use this as a magic string. Note that both strings
662 have the same length. */
664 #define XCOFFARMAG "<aiaff>\012"
665 #define XCOFFARMAGBIG "<bigaf>\012"
666 #define SXCOFFARMAG 8
668 /* This terminates an XCOFF archive member name. */
670 #define XCOFFARFMAG "`\012"
671 #define SXCOFFARFMAG 2
673 /* XCOFF archives start with this (printable) structure. */
675 struct xcoff_ar_file_hdr
678 char magic[SXCOFFARMAG];
680 /* Offset of the member table (decimal ASCII string). */
683 /* Offset of the global symbol table (decimal ASCII string). */
686 /* Offset of the first member in the archive (decimal ASCII string). */
687 char firstmemoff[12];
689 /* Offset of the last member in the archive (decimal ASCII string). */
692 /* Offset of the first member on the free list (decimal ASCII
697 #define SIZEOF_AR_FILE_HDR (5 * 12 + SXCOFFARMAG)
699 /* This is the equivalent data structure for the big archive format. */
701 struct xcoff_ar_file_hdr_big
704 char magic[SXCOFFARMAG];
706 /* Offset of the member table (decimal ASCII string). */
709 /* Offset of the global symbol table for 32-bit objects (decimal ASCII
713 /* Offset of the global symbol table for 64-bit objects (decimal ASCII
717 /* Offset of the first member in the archive (decimal ASCII string). */
718 char firstmemoff[20];
720 /* Offset of the last member in the archive (decimal ASCII string). */
723 /* Offset of the first member on the free list (decimal ASCII
728 #define SIZEOF_AR_FILE_HDR_BIG (6 * 20 + SXCOFFARMAG)
731 /* Each XCOFF archive member starts with this (printable) structure. */
735 /* File size not including the header (decimal ASCII string). */
738 /* File offset of next archive member (decimal ASCII string). */
741 /* File offset of previous archive member (decimal ASCII string). */
744 /* File mtime (decimal ASCII string). */
747 /* File UID (decimal ASCII string). */
750 /* File GID (decimal ASCII string). */
753 /* File mode (octal ASCII string). */
756 /* Length of file name (decimal ASCII string). */
759 /* This structure is followed by the file name. The length of the
760 name is given in the namlen field. If the length of the name is
761 odd, the name is followed by a null byte. The name and optional
762 null byte are followed by XCOFFARFMAG, which is not included in
763 namlen. The contents of the archive member follow; the number of
764 bytes is given in the size field. */
767 #define SIZEOF_AR_HDR (7 * 12 + 4)
769 /* The equivalent for the big archive format. */
771 struct xcoff_ar_hdr_big
773 /* File size not including the header (decimal ASCII string). */
776 /* File offset of next archive member (decimal ASCII string). */
779 /* File offset of previous archive member (decimal ASCII string). */
782 /* File mtime (decimal ASCII string). */
785 /* File UID (decimal ASCII string). */
788 /* File GID (decimal ASCII string). */
791 /* File mode (octal ASCII string). */
794 /* Length of file name (decimal ASCII string). */
797 /* This structure is followed by the file name. The length of the
798 name is given in the namlen field. If the length of the name is
799 odd, the name is followed by a null byte. The name and optional
800 null byte are followed by XCOFFARFMAG, which is not included in
801 namlen. The contents of the archive member follow; the number of
802 bytes is given in the size field. */
805 #define SIZEOF_AR_HDR_BIG (3 * 20 + 4 * 12 + 4)
808 /* We often have to distinguish between the old and big file format.
809 Make it a bit cleaner. We can use `xcoff_ardata' here because the
810 `hdr' member has the same size and position in both formats. */
811 #define xcoff_big_format_p(abfd) \
812 (xcoff_ardata (abfd)->magic[1] == 'b')
814 /* We store a copy of the xcoff_ar_file_hdr in the tdata field of the
815 artdata structure. Similar for the big archive. */
816 #define xcoff_ardata(abfd) \
817 ((struct xcoff_ar_file_hdr *) bfd_ardata (abfd)->tdata)
818 #define xcoff_ardata_big(abfd) \
819 ((struct xcoff_ar_file_hdr_big *) bfd_ardata (abfd)->tdata)
821 /* We store a copy of the xcoff_ar_hdr in the arelt_data field of an
822 archive element. Similar for the big archive. */
823 #define arch_eltdata(bfd) ((struct areltdata *) ((bfd)->arelt_data))
824 #define arch_xhdr(bfd) \
825 ((struct xcoff_ar_hdr *) arch_eltdata (bfd)->arch_header)
826 #define arch_xhdr_big(bfd) \
827 ((struct xcoff_ar_hdr_big *) arch_eltdata (bfd)->arch_header)
829 /* XCOFF archives do not have anything which corresponds to an
830 extended name table. */
832 #define xcoff_slurp_extended_name_table bfd_false
833 #define xcoff_construct_extended_name_table \
834 ((boolean (*) PARAMS ((bfd *, char **, bfd_size_type *, const char **))) \
836 #define xcoff_truncate_arname bfd_dont_truncate_arname
838 /* We can use the standard get_elt_at_index routine. */
840 #define xcoff_get_elt_at_index _bfd_generic_get_elt_at_index
842 /* XCOFF archives do not have a timestamp. */
844 #define xcoff_update_armap_timestamp bfd_true
846 /* Read in the armap of an XCOFF archive. */
849 xcoff_slurp_armap (abfd)
855 bfd_byte *contents, *cend;
860 if (xcoff_ardata (abfd) == NULL)
862 bfd_has_map (abfd) = false;
866 if (! xcoff_big_format_p (abfd))
868 /* This is for the old format. */
869 struct xcoff_ar_hdr hdr;
871 off = strtol (xcoff_ardata (abfd)->symoff, (char **) NULL, 10);
874 bfd_has_map (abfd) = false;
878 if (bfd_seek (abfd, off, SEEK_SET) != 0)
881 /* The symbol table starts with a normal archive header. */
882 if (bfd_read ((PTR) &hdr, SIZEOF_AR_HDR, 1, abfd) != SIZEOF_AR_HDR)
885 /* Skip the name (normally empty). */
886 namlen = strtol (hdr.namlen, (char **) NULL, 10);
887 if (bfd_seek (abfd, ((namlen + 1) & ~1) + SXCOFFARFMAG, SEEK_CUR) != 0)
890 sz = strtol (hdr.size, (char **) NULL, 10);
894 /* This is for the new format. */
895 struct xcoff_ar_hdr_big hdr;
897 off = strtol (xcoff_ardata_big (abfd)->symoff, (char **) NULL, 10);
900 bfd_has_map (abfd) = false;
904 if (bfd_seek (abfd, off, SEEK_SET) != 0)
907 /* The symbol table starts with a normal archive header. */
908 if (bfd_read ((PTR) &hdr, SIZEOF_AR_HDR_BIG, 1, abfd)
909 != SIZEOF_AR_HDR_BIG)
912 /* Skip the name (normally empty). */
913 namlen = strtol (hdr.namlen, (char **) NULL, 10);
914 if (bfd_seek (abfd, ((namlen + 1) & ~1) + SXCOFFARFMAG, SEEK_CUR) != 0)
917 /* XXX This actually has to be a call to strtoll (at least on 32-bit
918 machines) since the field width is 20 and there numbers with more
919 than 32 bits can be represented. */
920 sz = strtol (hdr.size, (char **) NULL, 10);
923 /* Read in the entire symbol table. */
924 contents = (bfd_byte *) bfd_alloc (abfd, sz);
925 if (contents == NULL)
927 if (bfd_read ((PTR) contents, 1, sz, abfd) != sz)
930 /* The symbol table starts with a four byte count. */
931 c = bfd_h_get_32 (abfd, contents);
935 bfd_set_error (bfd_error_bad_value);
939 bfd_ardata (abfd)->symdefs = ((carsym *)
940 bfd_alloc (abfd, c * sizeof (carsym)));
941 if (bfd_ardata (abfd)->symdefs == NULL)
944 /* After the count comes a list of four byte file offsets. */
945 for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 4;
947 ++i, ++arsym, p += 4)
948 arsym->file_offset = bfd_h_get_32 (abfd, p);
950 /* After the file offsets come null terminated symbol names. */
951 cend = contents + sz;
952 for (i = 0, arsym = bfd_ardata (abfd)->symdefs;
954 ++i, ++arsym, p += strlen ((char *) p) + 1)
958 bfd_set_error (bfd_error_bad_value);
961 arsym->name = (char *) p;
964 bfd_ardata (abfd)->symdef_count = c;
965 bfd_has_map (abfd) = true;
970 /* See if this is an XCOFF archive. */
972 static const bfd_target *
973 xcoff_archive_p (abfd)
976 char magic[SXCOFFARMAG];
978 if (bfd_read ((PTR) magic, SXCOFFARMAG, 1, abfd) != SXCOFFARMAG)
980 if (bfd_get_error () != bfd_error_system_call)
981 bfd_set_error (bfd_error_wrong_format);
985 if (strncmp (magic, XCOFFARMAG, SXCOFFARMAG) != 0
986 && strncmp (magic, XCOFFARMAGBIG, SXCOFFARMAG) != 0)
988 bfd_set_error (bfd_error_wrong_format);
992 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
993 involves a cast, we can't do it as the left operand of
995 abfd->tdata.aout_ar_data =
996 (struct artdata *) bfd_zalloc (abfd, sizeof (struct artdata));
998 if (bfd_ardata (abfd) == (struct artdata *) NULL)
1001 bfd_ardata (abfd)->cache = NULL;
1002 bfd_ardata (abfd)->archive_head = NULL;
1003 bfd_ardata (abfd)->symdefs = NULL;
1004 bfd_ardata (abfd)->extended_names = NULL;
1006 /* Now handle the two formats. */
1007 if (magic[1] != 'b')
1009 /* This is the old format. */
1010 struct xcoff_ar_file_hdr hdr;
1012 /* Copy over the magic string. */
1013 memcpy (hdr.magic, magic, SXCOFFARMAG);
1015 /* Now read the rest of the file header. */
1016 if (bfd_read ((PTR) &hdr.memoff, SIZEOF_AR_FILE_HDR - SXCOFFARMAG, 1,
1017 abfd) != SIZEOF_AR_FILE_HDR - SXCOFFARMAG)
1019 if (bfd_get_error () != bfd_error_system_call)
1020 bfd_set_error (bfd_error_wrong_format);
1024 bfd_ardata (abfd)->first_file_filepos = strtol (hdr.firstmemoff,
1025 (char **) NULL, 10);
1027 bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, SIZEOF_AR_FILE_HDR);
1028 if (bfd_ardata (abfd)->tdata == NULL)
1031 memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR);
1035 /* This is the new format. */
1036 struct xcoff_ar_file_hdr_big hdr;
1038 /* Copy over the magic string. */
1039 memcpy (hdr.magic, magic, SXCOFFARMAG);
1041 /* Now read the rest of the file header. */
1042 if (bfd_read ((PTR) &hdr.memoff, SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG, 1,
1043 abfd) != SIZEOF_AR_FILE_HDR_BIG - SXCOFFARMAG)
1045 if (bfd_get_error () != bfd_error_system_call)
1046 bfd_set_error (bfd_error_wrong_format);
1050 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1051 machines) since the field width is 20 and there numbers with more
1052 than 32 bits can be represented. */
1053 bfd_ardata (abfd)->first_file_filepos = strtol (hdr.firstmemoff,
1054 (char **) NULL, 10);
1056 bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, SIZEOF_AR_FILE_HDR_BIG);
1057 if (bfd_ardata (abfd)->tdata == NULL)
1060 memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR_BIG);
1063 if (! xcoff_slurp_armap (abfd))
1065 bfd_release (abfd, bfd_ardata (abfd));
1066 abfd->tdata.aout_ar_data = (struct artdata *) NULL;
1073 /* Read the archive header in an XCOFF archive. */
1076 xcoff_read_ar_hdr (abfd)
1080 struct areltdata *ret;
1082 ret = (struct areltdata *) bfd_alloc (abfd, sizeof (struct areltdata));
1086 if (! xcoff_big_format_p (abfd))
1088 struct xcoff_ar_hdr hdr;
1089 struct xcoff_ar_hdr *hdrp;
1091 if (bfd_read ((PTR) &hdr, SIZEOF_AR_HDR, 1, abfd) != SIZEOF_AR_HDR)
1097 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1098 hdrp = (struct xcoff_ar_hdr *) bfd_alloc (abfd,
1099 SIZEOF_AR_HDR + namlen + 1);
1105 memcpy (hdrp, &hdr, SIZEOF_AR_HDR);
1106 if (bfd_read ((char *) hdrp + SIZEOF_AR_HDR, 1, namlen, abfd) != namlen)
1111 ((char *) hdrp)[SIZEOF_AR_HDR + namlen] = '\0';
1113 ret->arch_header = (char *) hdrp;
1114 ret->parsed_size = strtol (hdr.size, (char **) NULL, 10);
1115 ret->filename = (char *) hdrp + SIZEOF_AR_HDR;
1119 struct xcoff_ar_hdr_big hdr;
1120 struct xcoff_ar_hdr_big *hdrp;
1122 if (bfd_read ((PTR) &hdr, SIZEOF_AR_HDR_BIG, 1, abfd)
1123 != SIZEOF_AR_HDR_BIG)
1129 namlen = strtol (hdr.namlen, (char **) NULL, 10);
1130 hdrp = (struct xcoff_ar_hdr_big *) bfd_alloc (abfd,
1138 memcpy (hdrp, &hdr, SIZEOF_AR_HDR_BIG);
1139 if (bfd_read ((char *) hdrp + SIZEOF_AR_HDR_BIG, 1, namlen, abfd) != namlen)
1144 ((char *) hdrp)[SIZEOF_AR_HDR_BIG + namlen] = '\0';
1146 ret->arch_header = (char *) hdrp;
1147 /* XXX This actually has to be a call to strtoll (at least on 32-bit
1148 machines) since the field width is 20 and there numbers with more
1149 than 32 bits can be represented. */
1150 ret->parsed_size = strtol (hdr.size, (char **) NULL, 10);
1151 ret->filename = (char *) hdrp + SIZEOF_AR_HDR_BIG;
1154 /* Skip over the XCOFFARFMAG at the end of the file name. */
1155 if (bfd_seek (abfd, (namlen & 1) + SXCOFFARFMAG, SEEK_CUR) != 0)
1161 /* Open the next element in an XCOFF archive. */
1164 xcoff_openr_next_archived_file (archive, last_file)
1170 if (xcoff_ardata (archive) == NULL)
1172 bfd_set_error (bfd_error_invalid_operation);
1176 if (! xcoff_big_format_p (archive))
1178 if (last_file == NULL)
1179 filestart = bfd_ardata (archive)->first_file_filepos;
1181 filestart = strtol (arch_xhdr (last_file)->nextoff, (char **) NULL,
1185 || filestart == strtol (xcoff_ardata (archive)->memoff,
1187 || filestart == strtol (xcoff_ardata (archive)->symoff,
1188 (char **) NULL, 10))
1190 bfd_set_error (bfd_error_no_more_archived_files);
1196 if (last_file == NULL)
1197 filestart = bfd_ardata (archive)->first_file_filepos;
1199 /* XXX These actually have to be a calls to strtoll (at least
1200 on 32-bit machines) since the fields's width is 20 and
1201 there numbers with more than 32 bits can be represented. */
1202 filestart = strtol (arch_xhdr_big (last_file)->nextoff, (char **) NULL,
1205 /* XXX These actually have to be calls to strtoll (at least on 32-bit
1206 machines) since the fields's width is 20 and there numbers with more
1207 than 32 bits can be represented. */
1209 || filestart == strtol (xcoff_ardata_big (archive)->memoff,
1211 || filestart == strtol (xcoff_ardata_big (archive)->symoff,
1212 (char **) NULL, 10))
1214 bfd_set_error (bfd_error_no_more_archived_files);
1219 return _bfd_get_elt_at_filepos (archive, filestart);
1222 /* Stat an element in an XCOFF archive. */
1225 xcoff_generic_stat_arch_elt (abfd, s)
1229 if (abfd->arelt_data == NULL)
1231 bfd_set_error (bfd_error_invalid_operation);
1235 if (! xcoff_big_format_p (abfd))
1237 struct xcoff_ar_hdr *hdrp = arch_xhdr (abfd);
1239 s->st_mtime = strtol (hdrp->date, (char **) NULL, 10);
1240 s->st_uid = strtol (hdrp->uid, (char **) NULL, 10);
1241 s->st_gid = strtol (hdrp->gid, (char **) NULL, 10);
1242 s->st_mode = strtol (hdrp->mode, (char **) NULL, 8);
1243 s->st_size = arch_eltdata (abfd)->parsed_size;
1247 struct xcoff_ar_hdr_big *hdrp = arch_xhdr_big (abfd);
1249 s->st_mtime = strtol (hdrp->date, (char **) NULL, 10);
1250 s->st_uid = strtol (hdrp->uid, (char **) NULL, 10);
1251 s->st_gid = strtol (hdrp->gid, (char **) NULL, 10);
1252 s->st_mode = strtol (hdrp->mode, (char **) NULL, 8);
1253 s->st_size = arch_eltdata (abfd)->parsed_size;
1259 /* Normalize a file name for inclusion in an archive. */
1262 normalize_filename (abfd)
1266 const char *filename;
1268 file = bfd_get_filename (abfd);
1269 filename = strrchr (file, '/');
1270 if (filename != NULL)
1277 /* Write out an XCOFF armap. */
1281 xcoff_write_armap_old (abfd, elength, map, orl_count, stridx)
1283 unsigned int elength ATTRIBUTE_UNUSED;
1285 unsigned int orl_count;
1288 struct xcoff_ar_hdr hdr;
1290 unsigned char buf[4];
1295 memset (&hdr, 0, sizeof hdr);
1296 sprintf (hdr.size, "%ld", (long) (4 + orl_count * 4 + stridx));
1297 sprintf (hdr.nextoff, "%d", 0);
1298 memcpy (hdr.prevoff, xcoff_ardata (abfd)->memoff, 12);
1299 sprintf (hdr.date, "%d", 0);
1300 sprintf (hdr.uid, "%d", 0);
1301 sprintf (hdr.gid, "%d", 0);
1302 sprintf (hdr.mode, "%d", 0);
1303 sprintf (hdr.namlen, "%d", 0);
1305 /* We need spaces, not null bytes, in the header. */
1306 for (p = (char *) &hdr; p < (char *) &hdr + SIZEOF_AR_HDR; p++)
1310 if (bfd_write ((PTR) &hdr, SIZEOF_AR_HDR, 1, abfd) != SIZEOF_AR_HDR
1311 || bfd_write (XCOFFARFMAG, 1, SXCOFFARFMAG, abfd) != SXCOFFARFMAG)
1314 bfd_h_put_32 (abfd, orl_count, buf);
1315 if (bfd_write (buf, 1, 4, abfd) != 4)
1318 sub = abfd->archive_head;
1319 fileoff = SIZEOF_AR_FILE_HDR;
1321 while (sub != NULL && i < orl_count)
1325 while (((bfd *) (map[i]).pos) == sub)
1327 bfd_h_put_32 (abfd, fileoff, buf);
1328 if (bfd_write (buf, 1, 4, abfd) != 4)
1332 namlen = strlen (normalize_filename (sub));
1333 namlen = (namlen + 1) &~ 1;
1334 fileoff += (SIZEOF_AR_HDR
1337 + arelt_size (sub));
1338 fileoff = (fileoff + 1) &~ 1;
1342 for (i = 0; i < orl_count; i++)
1347 name = *map[i].name;
1348 namlen = strlen (name);
1349 if (bfd_write (name, 1, namlen + 1, abfd) != namlen + 1)
1353 if ((stridx & 1) != 0)
1358 if (bfd_write (&b, 1, 1, abfd) != 1)
1367 xcoff_write_armap_big (abfd, elength, map, orl_count, stridx)
1369 unsigned int elength ATTRIBUTE_UNUSED;
1371 unsigned int orl_count;
1374 struct xcoff_ar_hdr_big hdr;
1376 unsigned char buf[4];
1381 memset (&hdr, 0, sizeof hdr);
1382 /* XXX This call actually should use %lld (at least on 32-bit
1383 machines) since the fields's width is 20 and there numbers with
1384 more than 32 bits can be represented. */
1385 sprintf (hdr.size, "%ld", (long) (4 + orl_count * 4 + stridx));
1386 sprintf (hdr.nextoff, "%d", 0);
1387 memcpy (hdr.prevoff, xcoff_ardata (abfd)->memoff, 12);
1388 sprintf (hdr.date, "%d", 0);
1389 sprintf (hdr.uid, "%d", 0);
1390 sprintf (hdr.gid, "%d", 0);
1391 sprintf (hdr.mode, "%d", 0);
1392 sprintf (hdr.namlen, "%d", 0);
1394 /* We need spaces, not null bytes, in the header. */
1395 for (p = (char *) &hdr; p < (char *) &hdr + SIZEOF_AR_HDR_BIG; p++)
1399 if (bfd_write ((PTR) &hdr, SIZEOF_AR_HDR_BIG, 1, abfd) != SIZEOF_AR_HDR_BIG
1400 || bfd_write (XCOFFARFMAG, 1, SXCOFFARFMAG, abfd) != SXCOFFARFMAG)
1403 bfd_h_put_32 (abfd, orl_count, buf);
1404 if (bfd_write (buf, 1, 4, abfd) != 4)
1407 sub = abfd->archive_head;
1408 fileoff = SIZEOF_AR_FILE_HDR_BIG;
1410 while (sub != NULL && i < orl_count)
1414 while (((bfd *) (map[i]).pos) == sub)
1416 bfd_h_put_32 (abfd, fileoff, buf);
1417 if (bfd_write (buf, 1, 4, abfd) != 4)
1421 namlen = strlen (normalize_filename (sub));
1422 namlen = (namlen + 1) &~ 1;
1423 fileoff += (SIZEOF_AR_HDR_BIG
1426 + arelt_size (sub));
1427 fileoff = (fileoff + 1) &~ 1;
1431 for (i = 0; i < orl_count; i++)
1436 name = *map[i].name;
1437 namlen = strlen (name);
1438 if (bfd_write (name, 1, namlen + 1, abfd) != namlen + 1)
1442 if ((stridx & 1) != 0)
1447 if (bfd_write (&b, 1, 1, abfd) != 1)
1456 xcoff_write_armap (abfd, elength, map, orl_count, stridx)
1458 unsigned int elength ATTRIBUTE_UNUSED;
1460 unsigned int orl_count;
1463 if (! xcoff_big_format_p (abfd))
1464 return xcoff_write_armap_old (abfd, elength, map, orl_count, stridx);
1466 return xcoff_write_armap_big (abfd, elength, map, orl_count, stridx);
1469 /* Write out an XCOFF archive. We always write an entire archive,
1470 rather than fussing with the freelist and so forth. */
1473 xcoff_write_archive_contents_old (abfd)
1476 struct xcoff_ar_file_hdr fhdr;
1478 size_t total_namlen;
1482 file_ptr prevoff, nextoff;
1485 struct xcoff_ar_hdr ahdr;
1490 memset (&fhdr, 0, sizeof fhdr);
1491 strncpy (fhdr.magic, XCOFFARMAG, SXCOFFARMAG);
1492 sprintf (fhdr.firstmemoff, "%d", SIZEOF_AR_FILE_HDR);
1493 sprintf (fhdr.freeoff, "%d", 0);
1497 for (sub = abfd->archive_head; sub != NULL; sub = sub->next)
1500 total_namlen += strlen (normalize_filename (sub)) + 1;
1502 offsets = (file_ptr *) bfd_alloc (abfd, count * sizeof (file_ptr));
1503 if (offsets == NULL)
1506 if (bfd_seek (abfd, SIZEOF_AR_FILE_HDR, SEEK_SET) != 0)
1509 makemap = bfd_has_map (abfd);
1512 nextoff = SIZEOF_AR_FILE_HDR;
1513 for (sub = abfd->archive_head, i = 0; sub != NULL; sub = sub->next, i++)
1517 struct xcoff_ar_hdr *ahdrp;
1518 bfd_size_type remaining;
1520 if (makemap && ! hasobjects)
1522 if (bfd_check_format (sub, bfd_object))
1526 name = normalize_filename (sub);
1527 namlen = strlen (name);
1529 if (sub->arelt_data != NULL)
1530 ahdrp = arch_xhdr (sub);
1538 memset (&ahdr, 0, sizeof ahdr);
1540 if (stat (bfd_get_filename (sub), &s) != 0)
1542 bfd_set_error (bfd_error_system_call);
1546 sprintf (ahdrp->size, "%ld", (long) s.st_size);
1547 sprintf (ahdrp->date, "%ld", (long) s.st_mtime);
1548 sprintf (ahdrp->uid, "%ld", (long) s.st_uid);
1549 sprintf (ahdrp->gid, "%ld", (long) s.st_gid);
1550 sprintf (ahdrp->mode, "%o", (unsigned int) s.st_mode);
1552 if (sub->arelt_data == NULL)
1554 sub->arelt_data = bfd_alloc (sub, sizeof (struct areltdata));
1555 if (sub->arelt_data == NULL)
1559 arch_eltdata (sub)->parsed_size = s.st_size;
1562 sprintf (ahdrp->prevoff, "%ld", (long) prevoff);
1563 sprintf (ahdrp->namlen, "%ld", (long) namlen);
1565 /* If the length of the name is odd, we write out the null byte
1566 after the name as well. */
1567 namlen = (namlen + 1) &~ 1;
1569 remaining = arelt_size (sub);
1570 size = (SIZEOF_AR_HDR
1575 BFD_ASSERT (nextoff == bfd_tell (abfd));
1577 offsets[i] = nextoff;
1580 nextoff += size + (size & 1);
1582 sprintf (ahdrp->nextoff, "%ld", (long) nextoff);
1584 /* We need spaces, not null bytes, in the header. */
1585 for (p = (char *) ahdrp; p < (char *) ahdrp + SIZEOF_AR_HDR; p++)
1589 if (bfd_write ((PTR) ahdrp, 1, SIZEOF_AR_HDR, abfd) != SIZEOF_AR_HDR
1590 || bfd_write ((PTR) name, 1, namlen, abfd) != namlen
1591 || (bfd_write ((PTR) XCOFFARFMAG, 1, SXCOFFARFMAG, abfd)
1595 if (bfd_seek (sub, (file_ptr) 0, SEEK_SET) != 0)
1597 while (remaining != 0)
1600 bfd_byte buffer[DEFAULT_BUFFERSIZE];
1602 amt = sizeof buffer;
1603 if (amt > remaining)
1605 if (bfd_read (buffer, 1, amt, sub) != amt
1606 || bfd_write (buffer, 1, amt, abfd) != amt)
1611 if ((size & 1) != 0)
1616 if (bfd_write (&b, 1, 1, abfd) != 1)
1621 sprintf (fhdr.lastmemoff, "%ld", (long) prevoff);
1623 /* Write out the member table. */
1625 BFD_ASSERT (nextoff == bfd_tell (abfd));
1626 sprintf (fhdr.memoff, "%ld", (long) nextoff);
1628 memset (&ahdr, 0, sizeof ahdr);
1629 sprintf (ahdr.size, "%ld", (long) (12 + count * 12 + total_namlen));
1630 sprintf (ahdr.prevoff, "%ld", (long) prevoff);
1631 sprintf (ahdr.date, "%d", 0);
1632 sprintf (ahdr.uid, "%d", 0);
1633 sprintf (ahdr.gid, "%d", 0);
1634 sprintf (ahdr.mode, "%d", 0);
1635 sprintf (ahdr.namlen, "%d", 0);
1637 size = (SIZEOF_AR_HDR
1644 nextoff += size + (size & 1);
1646 if (makemap && hasobjects)
1647 sprintf (ahdr.nextoff, "%ld", (long) nextoff);
1649 sprintf (ahdr.nextoff, "%d", 0);
1651 /* We need spaces, not null bytes, in the header. */
1652 for (p = (char *) &ahdr; p < (char *) &ahdr + SIZEOF_AR_HDR; p++)
1656 if (bfd_write ((PTR) &ahdr, 1, SIZEOF_AR_HDR, abfd) != SIZEOF_AR_HDR
1657 || (bfd_write ((PTR) XCOFFARFMAG, 1, SXCOFFARFMAG, abfd)
1661 sprintf (decbuf, "%-12ld", (long) count);
1662 if (bfd_write ((PTR) decbuf, 1, 12, abfd) != 12)
1664 for (i = 0; i < count; i++)
1666 sprintf (decbuf, "%-12ld", (long) offsets[i]);
1667 if (bfd_write ((PTR) decbuf, 1, 12, abfd) != 12)
1670 for (sub = abfd->archive_head; sub != NULL; sub = sub->next)
1675 name = normalize_filename (sub);
1676 namlen = strlen (name);
1677 if (bfd_write ((PTR) name, 1, namlen + 1, abfd) != namlen + 1)
1680 if ((size & 1) != 0)
1685 if (bfd_write ((PTR) &b, 1, 1, abfd) != 1)
1689 /* Write out the armap, if appropriate. */
1691 if (! makemap || ! hasobjects)
1692 sprintf (fhdr.symoff, "%d", 0);
1695 BFD_ASSERT (nextoff == bfd_tell (abfd));
1696 sprintf (fhdr.symoff, "%ld", (long) nextoff);
1697 bfd_ardata (abfd)->tdata = (PTR) &fhdr;
1698 if (! _bfd_compute_and_write_armap (abfd, 0))
1702 /* Write out the archive file header. */
1704 /* We need spaces, not null bytes, in the header. */
1705 for (p = (char *) &fhdr; p < (char *) &fhdr + SIZEOF_AR_FILE_HDR; p++)
1709 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1710 || (bfd_write ((PTR) &fhdr, SIZEOF_AR_FILE_HDR, 1, abfd) !=
1711 SIZEOF_AR_FILE_HDR))
1718 xcoff_write_archive_contents_big (abfd)
1721 struct xcoff_ar_file_hdr_big fhdr;
1723 size_t total_namlen;
1727 file_ptr prevoff, nextoff;
1730 struct xcoff_ar_hdr_big ahdr;
1735 memset (&fhdr, 0, sizeof fhdr);
1736 strncpy (fhdr.magic, XCOFFARMAGBIG, SXCOFFARMAG);
1737 sprintf (fhdr.firstmemoff, "%d", SIZEOF_AR_FILE_HDR_BIG);
1738 sprintf (fhdr.freeoff, "%d", 0);
1742 for (sub = abfd->archive_head; sub != NULL; sub = sub->next)
1745 total_namlen += strlen (normalize_filename (sub)) + 1;
1747 offsets = (file_ptr *) bfd_alloc (abfd, count * sizeof (file_ptr));
1748 if (offsets == NULL)
1751 if (bfd_seek (abfd, SIZEOF_AR_FILE_HDR_BIG, SEEK_SET) != 0)
1754 makemap = bfd_has_map (abfd);
1757 nextoff = SIZEOF_AR_FILE_HDR_BIG;
1758 for (sub = abfd->archive_head, i = 0; sub != NULL; sub = sub->next, i++)
1762 struct xcoff_ar_hdr_big *ahdrp;
1763 bfd_size_type remaining;
1765 if (makemap && ! hasobjects)
1767 if (bfd_check_format (sub, bfd_object))
1771 name = normalize_filename (sub);
1772 namlen = strlen (name);
1774 if (sub->arelt_data != NULL)
1775 ahdrp = arch_xhdr_big (sub);
1783 memset (&ahdr, 0, sizeof ahdr);
1785 /* XXX This should actually be a call to stat64 (at least on
1786 32-bit machines). */
1787 if (stat (bfd_get_filename (sub), &s) != 0)
1789 bfd_set_error (bfd_error_system_call);
1793 /* XXX This call actually should use %lld (at least on 32-bit
1794 machines) since the fields's width is 20 and there numbers with
1795 more than 32 bits can be represented. */
1796 sprintf (ahdrp->size, "%ld", (long) s.st_size);
1797 sprintf (ahdrp->date, "%ld", (long) s.st_mtime);
1798 sprintf (ahdrp->uid, "%ld", (long) s.st_uid);
1799 sprintf (ahdrp->gid, "%ld", (long) s.st_gid);
1800 sprintf (ahdrp->mode, "%o", (unsigned int) s.st_mode);
1802 if (sub->arelt_data == NULL)
1804 sub->arelt_data = bfd_alloc (sub, sizeof (struct areltdata));
1805 if (sub->arelt_data == NULL)
1809 arch_eltdata (sub)->parsed_size = s.st_size;
1812 /* XXX These calls actually should use %lld (at least on 32-bit
1813 machines) since the fields's width is 20 and there numbers with
1814 more than 32 bits can be represented. */
1815 sprintf (ahdrp->prevoff, "%ld", (long) prevoff);
1816 sprintf (ahdrp->namlen, "%ld", (long) namlen);
1818 /* If the length of the name is odd, we write out the null byte
1819 after the name as well. */
1820 namlen = (namlen + 1) &~ 1;
1822 remaining = arelt_size (sub);
1823 size = (SIZEOF_AR_HDR_BIG
1828 BFD_ASSERT (nextoff == bfd_tell (abfd));
1830 offsets[i] = nextoff;
1833 nextoff += size + (size & 1);
1835 sprintf (ahdrp->nextoff, "%ld", (long) nextoff);
1837 /* We need spaces, not null bytes, in the header. */
1838 for (p = (char *) ahdrp; p < (char *) ahdrp + SIZEOF_AR_HDR_BIG; p++)
1842 if (bfd_write ((PTR) ahdrp, 1, SIZEOF_AR_HDR_BIG, abfd)
1843 != SIZEOF_AR_HDR_BIG
1844 || bfd_write ((PTR) name, 1, namlen, abfd) != namlen
1845 || (bfd_write ((PTR) XCOFFARFMAG, 1, SXCOFFARFMAG, abfd)
1849 if (bfd_seek (sub, (file_ptr) 0, SEEK_SET) != 0)
1851 while (remaining != 0)
1854 bfd_byte buffer[DEFAULT_BUFFERSIZE];
1856 amt = sizeof buffer;
1857 if (amt > remaining)
1859 if (bfd_read (buffer, 1, amt, sub) != amt
1860 || bfd_write (buffer, 1, amt, abfd) != amt)
1865 if ((size & 1) != 0)
1870 if (bfd_write (&b, 1, 1, abfd) != 1)
1875 /* XXX This call actually should use %lld (at least on 32-bit
1876 machines) since the fields's width is 20 and there numbers with
1877 more than 32 bits can be represented. */
1878 sprintf (fhdr.lastmemoff, "%ld", (long) prevoff);
1880 /* Write out the member table. */
1882 BFD_ASSERT (nextoff == bfd_tell (abfd));
1883 /* XXX This call actually should use %lld (at least on 32-bit
1884 machines) since the fields's width is 20 and there numbers with
1885 more than 32 bits can be represented. */
1886 sprintf (fhdr.memoff, "%ld", (long) nextoff);
1888 memset (&ahdr, 0, sizeof ahdr);
1889 /* XXX The next two calls actually should use %lld (at least on 32-bit
1890 machines) since the fields's width is 20 and there numbers with
1891 more than 32 bits can be represented. */
1892 sprintf (ahdr.size, "%ld", (long) (12 + count * 12 + total_namlen));
1893 sprintf (ahdr.prevoff, "%ld", (long) prevoff);
1894 sprintf (ahdr.date, "%d", 0);
1895 sprintf (ahdr.uid, "%d", 0);
1896 sprintf (ahdr.gid, "%d", 0);
1897 sprintf (ahdr.mode, "%d", 0);
1898 sprintf (ahdr.namlen, "%d", 0);
1900 size = (SIZEOF_AR_HDR_BIG
1907 nextoff += size + (size & 1);
1909 if (makemap && hasobjects)
1910 /* XXX This call actually should use %lld (at least on 32-bit
1911 machines) since the fields's width is 20 and there numbers with
1912 more than 32 bits can be represented. */
1913 sprintf (ahdr.nextoff, "%ld", (long) nextoff);
1915 sprintf (ahdr.nextoff, "%d", 0);
1917 /* We need spaces, not null bytes, in the header. */
1918 for (p = (char *) &ahdr; p < (char *) &ahdr + SIZEOF_AR_HDR_BIG; p++)
1922 if (bfd_write ((PTR) &ahdr, 1, SIZEOF_AR_HDR_BIG, abfd) != SIZEOF_AR_HDR_BIG
1923 || (bfd_write ((PTR) XCOFFARFMAG, 1, SXCOFFARFMAG, abfd)
1927 sprintf (decbuf, "%-12ld", (long) count);
1928 if (bfd_write ((PTR) decbuf, 1, 12, abfd) != 12)
1930 for (i = 0; i < count; i++)
1932 sprintf (decbuf, "%-12ld", (long) offsets[i]);
1933 if (bfd_write ((PTR) decbuf, 1, 12, abfd) != 12)
1936 for (sub = abfd->archive_head; sub != NULL; sub = sub->next)
1941 name = normalize_filename (sub);
1942 namlen = strlen (name);
1943 if (bfd_write ((PTR) name, 1, namlen + 1, abfd) != namlen + 1)
1946 if ((size & 1) != 0)
1951 if (bfd_write ((PTR) &b, 1, 1, abfd) != 1)
1955 /* Write out the armap, if appropriate. */
1957 if (! makemap || ! hasobjects)
1958 sprintf (fhdr.symoff, "%d", 0);
1961 BFD_ASSERT (nextoff == bfd_tell (abfd));
1962 /* XXX This call actually should use %lld (at least on 32-bit
1963 machines) since the fields's width is 20 and there numbers with
1964 more than 32 bits can be represented. */
1965 sprintf (fhdr.symoff, "%ld", (long) nextoff);
1966 bfd_ardata (abfd)->tdata = (PTR) &fhdr;
1967 if (! _bfd_compute_and_write_armap (abfd, 0))
1971 /* Write out the archive file header. */
1973 /* We need spaces, not null bytes, in the header. */
1974 for (p = (char *) &fhdr; p < (char *) &fhdr + SIZEOF_AR_FILE_HDR_BIG; p++)
1978 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1979 || (bfd_write ((PTR) &fhdr, SIZEOF_AR_FILE_HDR_BIG, 1, abfd) !=
1980 SIZEOF_AR_FILE_HDR_BIG))
1987 xcoff_write_archive_contents (abfd)
1990 if (! xcoff_big_format_p (abfd))
1991 return xcoff_write_archive_contents_old (abfd);
1993 return xcoff_write_archive_contents_big (abfd);
1996 /* We can't use the usual coff_sizeof_headers routine, because AIX
1997 always uses an a.out header. */
2001 _bfd_xcoff_sizeof_headers (abfd, reloc)
2003 boolean reloc ATTRIBUTE_UNUSED;
2008 if (xcoff_data (abfd)->full_aouthdr)
2011 size += SMALL_AOUTSZ;
2012 size += abfd->section_count * SCNHSZ;
2016 #define CORE_FILE_P _bfd_dummy_target
2018 #define coff_core_file_failing_command _bfd_nocore_core_file_failing_command
2019 #define coff_core_file_failing_signal _bfd_nocore_core_file_failing_signal
2020 #define coff_core_file_matches_executable_p \
2021 _bfd_nocore_core_file_matches_executable_p
2025 #define CORE_FILE_P rs6000coff_core_p
2026 extern const bfd_target * rs6000coff_core_p ();
2027 extern boolean rs6000coff_get_section_contents ();
2028 extern boolean rs6000coff_core_file_matches_executable_p ();
2030 #undef coff_core_file_matches_executable_p
2031 #define coff_core_file_matches_executable_p \
2032 rs6000coff_core_file_matches_executable_p
2034 extern char *rs6000coff_core_file_failing_command PARAMS ((bfd *abfd));
2035 #undef coff_core_file_failing_command
2036 #define coff_core_file_failing_command rs6000coff_core_file_failing_command
2038 extern int rs6000coff_core_file_failing_signal PARAMS ((bfd *abfd));
2039 #undef coff_core_file_failing_signal
2040 #define coff_core_file_failing_signal rs6000coff_core_file_failing_signal
2042 #undef coff_get_section_contents
2043 #define coff_get_section_contents rs6000coff_get_section_contents
2044 #endif /* AIX_CORE */
2049 #define CORE_FILE_P lynx_core_file_p
2050 extern const bfd_target *lynx_core_file_p PARAMS ((bfd *abfd));
2052 extern boolean lynx_core_file_matches_executable_p PARAMS ((bfd *core_bfd,
2054 #undef coff_core_file_matches_executable_p
2055 #define coff_core_file_matches_executable_p lynx_core_file_matches_executable_p
2057 extern char *lynx_core_file_failing_command PARAMS ((bfd *abfd));
2058 #undef coff_core_file_failing_command
2059 #define coff_core_file_failing_command lynx_core_file_failing_command
2061 extern int lynx_core_file_failing_signal PARAMS ((bfd *abfd));
2062 #undef coff_core_file_failing_signal
2063 #define coff_core_file_failing_signal lynx_core_file_failing_signal
2065 #endif /* LYNX_CORE */
2067 #define _bfd_xcoff_bfd_get_relocated_section_contents \
2068 coff_bfd_get_relocated_section_contents
2069 #define _bfd_xcoff_bfd_relax_section coff_bfd_relax_section
2070 #define _bfd_xcoff_bfd_gc_sections coff_bfd_gc_sections
2071 #define _bfd_xcoff_bfd_link_split_section coff_bfd_link_split_section
2073 /* The transfer vector that leads the outside world to all of the above. */
2085 "aixcoff-rs6000", /* name */
2087 bfd_target_coff_flavour,
2088 BFD_ENDIAN_BIG, /* data byte order is big */
2089 BFD_ENDIAN_BIG, /* header byte order is big */
2091 (HAS_RELOC | EXEC_P | /* object flags */
2092 HAS_LINENO | HAS_DEBUG | DYNAMIC |
2093 HAS_SYMS | HAS_LOCALS | WP_TEXT),
2095 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
2096 0, /* leading char */
2097 '/', /* ar_pad_char */
2098 15, /* ar_max_namelen??? FIXMEmgo */
2100 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
2101 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
2102 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
2103 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
2104 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
2105 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
2107 {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
2108 xcoff_archive_p, CORE_FILE_P},
2109 {bfd_false, coff_mkobject, /* bfd_set_format */
2110 _bfd_generic_mkarchive, bfd_false},
2111 {bfd_false, coff_write_object_contents, /* bfd_write_contents */
2112 xcoff_write_archive_contents, bfd_false},
2114 BFD_JUMP_TABLE_GENERIC (coff),
2115 BFD_JUMP_TABLE_COPY (coff),
2116 BFD_JUMP_TABLE_CORE (coff),
2117 BFD_JUMP_TABLE_ARCHIVE (xcoff),
2118 BFD_JUMP_TABLE_SYMBOLS (coff),
2119 BFD_JUMP_TABLE_RELOCS (coff),
2120 BFD_JUMP_TABLE_WRITE (coff),
2121 BFD_JUMP_TABLE_LINK (_bfd_xcoff),
2122 BFD_JUMP_TABLE_DYNAMIC (_bfd_xcoff),