* scripttempl/aix.sc: Move special symbols inside sections.
[deliverable/binutils-gdb.git] / bfd / coff-rs6000.c
CommitLineData
f4bd7a8f 1/* BFD back-end for IBM RS/6000 "XCOFF" files.
bb2deaf2 2 Copyright 1990, 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
f4bd7a8f
DM
3 FIXME: Can someone provide a transliteration of this name into ASCII?
4 Using the following chars caused a compiler warning on HIUX (so I replaced
5 them with octal escapes), and isn't useful without an understanding of what
6 character set it is.
7 Written by Metin G. Ozisik, Mimi Ph\373\364ng-Th\345o V\365,
8 and John Gilmore.
ba9137fe
JG
9 Archive support from Damon A. Permezel.
10 Contributed by IBM Corporation and Cygnus Support.
11
12This file is part of BFD, the Binary File Descriptor library.
13
14This program is free software; you can redistribute it and/or modify
15it under the terms of the GNU General Public License as published by
16the Free Software Foundation; either version 2 of the License, or
17(at your option) any later version.
18
19This program is distributed in the hope that it will be useful,
20but WITHOUT ANY WARRANTY; without even the implied warranty of
21MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22GNU General Public License for more details.
23
24You should have received a copy of the GNU General Public License
25along with this program; if not, write to the Free Software
ae115e51 26Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
ba9137fe 27
ba9137fe
JG
28/* Internalcoff.h and coffcode.h modify themselves based on this flag. */
29#define RS6000COFF_C 1
30
ba9137fe 31#include "bfd.h"
156e3852 32#include "sysdep.h"
ba9137fe
JG
33#include "libbfd.h"
34#include "obstack.h"
294eaca4
SC
35#include "coff/internal.h"
36#include "coff/rs6000.h"
ba9137fe
JG
37#include "libcoff.h"
38
aadf04f7
SS
39/* The main body of code is in coffcode.h. */
40
41static boolean xcoff_mkobject PARAMS ((bfd *));
42static boolean xcoff_copy_private_bfd_data PARAMS ((bfd *, bfd *));
43static void xcoff_rtype2howto
44 PARAMS ((arelent *, struct internal_reloc *));
45static reloc_howto_type *xcoff_reloc_type_lookup
46 PARAMS ((bfd *, bfd_reloc_code_real_type));
bb2deaf2
ILT
47static boolean xcoff_slurp_armap PARAMS ((bfd *));
48static const bfd_target *xcoff_archive_p PARAMS ((bfd *));
49static PTR xcoff_read_ar_hdr PARAMS ((bfd *));
50static bfd *xcoff_openr_next_archived_file PARAMS ((bfd *, bfd *));
51static int xcoff_generic_stat_arch_elt PARAMS ((bfd *, struct stat *));
52static const char *normalize_filename PARAMS ((bfd *));
53static boolean xcoff_write_armap
54 PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int));
55static boolean xcoff_write_archive_contents PARAMS ((bfd *));
aadf04f7
SS
56\f
57/* We use our own tdata type. Its first field is the COFF tdata type,
58 so the COFF routines are compatible. */
bb2deaf2 59
aadf04f7
SS
60static boolean
61xcoff_mkobject (abfd)
62 bfd *abfd;
63{
64 coff_data_type *coff;
ba9137fe 65
aadf04f7
SS
66 abfd->tdata.xcoff_obj_data =
67 ((struct xcoff_tdata *)
68 bfd_zalloc (abfd, sizeof (struct xcoff_tdata)));
69 if (abfd->tdata.xcoff_obj_data == NULL)
70 {
71 bfd_set_error (bfd_error_no_memory);
72 return false;
73 }
74 coff = coff_data (abfd);
75 coff->symbols = (coff_symbol_type *) NULL;
76 coff->conversion_table = (unsigned int *) NULL;
77 coff->raw_syments = (struct coff_ptr_struct *) NULL;
78 coff->relocbase = 0;
79
80 xcoff_data (abfd)->modtype = ('1' << 8) | 'L';
81
82 /* We set cputype to -1 to indicate that it has not been
83 initialized. */
84 xcoff_data (abfd)->cputype = -1;
85
86 xcoff_data (abfd)->csects = NULL;
87 xcoff_data (abfd)->debug_indices = NULL;
88
89 return true;
90}
ae115e51 91
aadf04f7
SS
92/* Copy XCOFF data from one BFD to another. */
93
94static boolean
95xcoff_copy_private_bfd_data (ibfd, obfd)
96 bfd *ibfd;
97 bfd *obfd;
98{
99 struct xcoff_tdata *ix, *ox;
100
101 if (ibfd->xvec != obfd->xvec)
102 return true;
103 ix = xcoff_data (ibfd);
104 ox = xcoff_data (obfd);
105 ox->toc = ix->toc;
106 ox->text_align_power = ix->text_align_power;
107 ox->data_align_power = ix->data_align_power;
108 ox->modtype = ix->modtype;
109 ox->cputype = ix->cputype;
110 ox->maxdata = ix->maxdata;
111 ox->maxstack = ix->maxstack;
112 return true;
113}
114\f
8b8ddedb
SG
115/* The XCOFF reloc table. Actually, XCOFF relocations specify the
116 bitsize and whether they are signed or not, along with a
117 conventional type. This table is for the types, which are used for
118 different algorithms for putting in the reloc. Many of these
119 relocs need special_function entries, which I have not written. */
120
aadf04f7 121static reloc_howto_type xcoff_howto_table[] =
8b8ddedb
SG
122{
123 /* Standard 32 bit relocation. */
124 HOWTO (0, /* type */
125 0, /* rightshift */
126 2, /* size (0 = byte, 1 = short, 2 = long) */
127 32, /* bitsize */
128 false, /* pc_relative */
129 0, /* bitpos */
130 complain_overflow_bitfield, /* complain_on_overflow */
131 0, /* special_function */
132 "R_POS", /* name */
133 true, /* partial_inplace */
134 0xffffffff, /* src_mask */
135 0xffffffff, /* dst_mask */
136 false), /* pcrel_offset */
137
138 /* 32 bit relocation, but store negative value. */
139 HOWTO (1, /* type */
140 0, /* rightshift */
141 -2, /* size (0 = byte, 1 = short, 2 = long) */
142 32, /* bitsize */
143 false, /* pc_relative */
144 0, /* bitpos */
145 complain_overflow_bitfield, /* complain_on_overflow */
146 0, /* special_function */
147 "R_NEG", /* name */
148 true, /* partial_inplace */
149 0xffffffff, /* src_mask */
150 0xffffffff, /* dst_mask */
151 false), /* pcrel_offset */
152
153 /* 32 bit PC relative relocation. */
154 HOWTO (2, /* type */
155 0, /* rightshift */
156 2, /* size (0 = byte, 1 = short, 2 = long) */
157 32, /* bitsize */
158 true, /* pc_relative */
159 0, /* bitpos */
160 complain_overflow_signed, /* complain_on_overflow */
161 0, /* special_function */
162 "R_REL", /* name */
163 true, /* partial_inplace */
164 0xffffffff, /* src_mask */
165 0xffffffff, /* dst_mask */
166 false), /* pcrel_offset */
167
168 /* 16 bit TOC relative relocation. */
169 HOWTO (3, /* type */
170 0, /* rightshift */
171 1, /* size (0 = byte, 1 = short, 2 = long) */
172 16, /* bitsize */
173 false, /* pc_relative */
174 0, /* bitpos */
aadf04f7 175 complain_overflow_bitfield, /* complain_on_overflow */
8b8ddedb
SG
176 0, /* special_function */
177 "R_TOC", /* name */
178 true, /* partial_inplace */
179 0xffff, /* src_mask */
180 0xffff, /* dst_mask */
181 false), /* pcrel_offset */
182
183 /* I don't really know what this is. */
184 HOWTO (4, /* type */
185 1, /* rightshift */
186 2, /* size (0 = byte, 1 = short, 2 = long) */
187 32, /* bitsize */
188 false, /* pc_relative */
189 0, /* bitpos */
190 complain_overflow_bitfield, /* complain_on_overflow */
191 0, /* special_function */
192 "R_RTB", /* name */
193 true, /* partial_inplace */
194 0xffffffff, /* src_mask */
195 0xffffffff, /* dst_mask */
196 false), /* pcrel_offset */
197
198 /* External TOC relative symbol. */
199 HOWTO (5, /* type */
200 0, /* rightshift */
201 2, /* size (0 = byte, 1 = short, 2 = long) */
202 16, /* bitsize */
203 false, /* pc_relative */
204 0, /* bitpos */
205 complain_overflow_bitfield, /* complain_on_overflow */
206 0, /* special_function */
207 "R_GL", /* name */
208 true, /* partial_inplace */
209 0xffff, /* src_mask */
210 0xffff, /* dst_mask */
211 false), /* pcrel_offset */
212
213 /* Local TOC relative symbol. */
214 HOWTO (6, /* type */
215 0, /* rightshift */
216 2, /* size (0 = byte, 1 = short, 2 = long) */
217 16, /* bitsize */
218 false, /* pc_relative */
219 0, /* bitpos */
220 complain_overflow_bitfield, /* complain_on_overflow */
221 0, /* special_function */
222 "R_TCL", /* name */
223 true, /* partial_inplace */
224 0xffff, /* src_mask */
225 0xffff, /* dst_mask */
226 false), /* pcrel_offset */
227
228 { 7 },
229
230 /* Non modifiable absolute branch. */
231 HOWTO (8, /* type */
232 0, /* rightshift */
233 2, /* size (0 = byte, 1 = short, 2 = long) */
234 26, /* bitsize */
235 false, /* pc_relative */
236 0, /* bitpos */
237 complain_overflow_bitfield, /* complain_on_overflow */
238 0, /* special_function */
239 "R_BA", /* name */
240 true, /* partial_inplace */
241 0x3fffffc, /* src_mask */
242 0x3fffffc, /* dst_mask */
243 false), /* pcrel_offset */
244
245 { 9 },
246
247 /* Non modifiable relative branch. */
248 HOWTO (0xa, /* type */
249 0, /* rightshift */
250 2, /* size (0 = byte, 1 = short, 2 = long) */
251 26, /* bitsize */
252 true, /* pc_relative */
253 0, /* bitpos */
254 complain_overflow_signed, /* complain_on_overflow */
255 0, /* special_function */
256 "R_BR", /* name */
257 true, /* partial_inplace */
258 0x3fffffc, /* src_mask */
259 0x3fffffc, /* dst_mask */
260 false), /* pcrel_offset */
261
262 { 0xb },
263
264 /* Indirect load. */
265 HOWTO (0xc, /* type */
266 0, /* rightshift */
267 2, /* size (0 = byte, 1 = short, 2 = long) */
268 16, /* bitsize */
269 false, /* pc_relative */
270 0, /* bitpos */
271 complain_overflow_bitfield, /* complain_on_overflow */
272 0, /* special_function */
273 "R_RL", /* name */
274 true, /* partial_inplace */
275 0xffff, /* src_mask */
276 0xffff, /* dst_mask */
277 false), /* pcrel_offset */
278
279 /* Load address. */
280 HOWTO (0xd, /* type */
281 0, /* rightshift */
282 2, /* size (0 = byte, 1 = short, 2 = long) */
283 16, /* bitsize */
284 false, /* pc_relative */
285 0, /* bitpos */
286 complain_overflow_bitfield, /* complain_on_overflow */
287 0, /* special_function */
288 "R_RLA", /* name */
289 true, /* partial_inplace */
290 0xffff, /* src_mask */
291 0xffff, /* dst_mask */
292 false), /* pcrel_offset */
293
294 { 0xe },
295
296 /* Non-relocating reference. */
297 HOWTO (0xf, /* type */
298 0, /* rightshift */
299 2, /* size (0 = byte, 1 = short, 2 = long) */
300 32, /* bitsize */
301 false, /* pc_relative */
302 0, /* bitpos */
303 complain_overflow_bitfield, /* complain_on_overflow */
304 0, /* special_function */
305 "R_REF", /* name */
306 false, /* partial_inplace */
307 0, /* src_mask */
308 0, /* dst_mask */
309 false), /* pcrel_offset */
310
311 { 0x10 },
312 { 0x11 },
313
314 /* TOC relative indirect load. */
315 HOWTO (0x12, /* type */
316 0, /* rightshift */
317 2, /* size (0 = byte, 1 = short, 2 = long) */
318 16, /* bitsize */
319 false, /* pc_relative */
320 0, /* bitpos */
321 complain_overflow_bitfield, /* complain_on_overflow */
322 0, /* special_function */
323 "R_TRL", /* name */
324 true, /* partial_inplace */
325 0xffff, /* src_mask */
326 0xffff, /* dst_mask */
327 false), /* pcrel_offset */
328
329 /* TOC relative load address. */
330 HOWTO (0x13, /* type */
331 0, /* rightshift */
332 2, /* size (0 = byte, 1 = short, 2 = long) */
333 16, /* bitsize */
334 false, /* pc_relative */
335 0, /* bitpos */
336 complain_overflow_bitfield, /* complain_on_overflow */
337 0, /* special_function */
338 "R_TRLA", /* name */
339 true, /* partial_inplace */
340 0xffff, /* src_mask */
341 0xffff, /* dst_mask */
342 false), /* pcrel_offset */
343
344 /* Modifiable relative branch. */
345 HOWTO (0x14, /* type */
346 1, /* rightshift */
347 2, /* size (0 = byte, 1 = short, 2 = long) */
348 32, /* bitsize */
349 false, /* pc_relative */
350 0, /* bitpos */
351 complain_overflow_bitfield, /* complain_on_overflow */
352 0, /* special_function */
353 "R_RRTBI", /* name */
354 true, /* partial_inplace */
355 0xffffffff, /* src_mask */
356 0xffffffff, /* dst_mask */
357 false), /* pcrel_offset */
358
359 /* Modifiable absolute branch. */
360 HOWTO (0x15, /* type */
361 1, /* rightshift */
362 2, /* size (0 = byte, 1 = short, 2 = long) */
363 32, /* bitsize */
364 false, /* pc_relative */
365 0, /* bitpos */
366 complain_overflow_bitfield, /* complain_on_overflow */
367 0, /* special_function */
368 "R_RRTBA", /* name */
369 true, /* partial_inplace */
370 0xffffffff, /* src_mask */
371 0xffffffff, /* dst_mask */
372 false), /* pcrel_offset */
373
374 /* Modifiable call absolute indirect. */
375 HOWTO (0x16, /* type */
376 0, /* rightshift */
377 2, /* size (0 = byte, 1 = short, 2 = long) */
378 16, /* bitsize */
379 false, /* pc_relative */
380 0, /* bitpos */
381 complain_overflow_bitfield, /* complain_on_overflow */
382 0, /* special_function */
383 "R_CAI", /* name */
384 true, /* partial_inplace */
385 0xffff, /* src_mask */
386 0xffff, /* dst_mask */
387 false), /* pcrel_offset */
388
389 /* Modifiable call relative. */
390 HOWTO (0x17, /* type */
391 0, /* rightshift */
392 2, /* size (0 = byte, 1 = short, 2 = long) */
393 16, /* bitsize */
394 false, /* pc_relative */
395 0, /* bitpos */
396 complain_overflow_bitfield, /* complain_on_overflow */
397 0, /* special_function */
28a0c103 398 "R_CREL", /* name */
8b8ddedb
SG
399 true, /* partial_inplace */
400 0xffff, /* src_mask */
401 0xffff, /* dst_mask */
402 false), /* pcrel_offset */
403
404 /* Modifiable branch absolute. */
405 HOWTO (0x18, /* type */
406 0, /* rightshift */
407 2, /* size (0 = byte, 1 = short, 2 = long) */
408 16, /* bitsize */
409 false, /* pc_relative */
410 0, /* bitpos */
411 complain_overflow_bitfield, /* complain_on_overflow */
412 0, /* special_function */
413 "R_RBA", /* name */
414 true, /* partial_inplace */
415 0xffff, /* src_mask */
416 0xffff, /* dst_mask */
417 false), /* pcrel_offset */
418
419 /* Modifiable branch absolute. */
420 HOWTO (0x19, /* type */
421 0, /* rightshift */
422 2, /* size (0 = byte, 1 = short, 2 = long) */
423 16, /* bitsize */
424 false, /* pc_relative */
425 0, /* bitpos */
426 complain_overflow_bitfield, /* complain_on_overflow */
427 0, /* special_function */
428 "R_RBAC", /* name */
429 true, /* partial_inplace */
430 0xffff, /* src_mask */
431 0xffff, /* dst_mask */
432 false), /* pcrel_offset */
433
434 /* Modifiable branch relative. */
435 HOWTO (0x1a, /* type */
436 0, /* rightshift */
437 2, /* size (0 = byte, 1 = short, 2 = long) */
438 26, /* bitsize */
439 false, /* pc_relative */
440 0, /* bitpos */
441 complain_overflow_signed, /* complain_on_overflow */
442 0, /* special_function */
28a0c103 443 "R_RBR", /* name */
8b8ddedb
SG
444 true, /* partial_inplace */
445 0xffff, /* src_mask */
446 0xffff, /* dst_mask */
447 false), /* pcrel_offset */
448
449 /* Modifiable branch absolute. */
450 HOWTO (0x1b, /* type */
451 0, /* rightshift */
452 2, /* size (0 = byte, 1 = short, 2 = long) */
453 16, /* bitsize */
454 false, /* pc_relative */
455 0, /* bitpos */
456 complain_overflow_bitfield, /* complain_on_overflow */
457 0, /* special_function */
28a0c103 458 "R_RBRC", /* name */
8b8ddedb
SG
459 true, /* partial_inplace */
460 0xffff, /* src_mask */
461 0xffff, /* dst_mask */
462 false) /* pcrel_offset */
463};
464
8b8ddedb 465static void
aadf04f7 466xcoff_rtype2howto (relent, internal)
8b8ddedb
SG
467 arelent *relent;
468 struct internal_reloc *internal;
469{
aadf04f7 470 relent->howto = xcoff_howto_table + internal->r_type;
8b8ddedb
SG
471
472 /* The r_size field of an XCOFF reloc encodes the bitsize of the
473 relocation, as well as indicating whether it is signed or not.
474 Doublecheck that the relocation information gathered from the
475 type matches this information. */
ae115e51 476 if (relent->howto->bitsize != ((unsigned int) internal->r_size & 0x1f) + 1)
8b8ddedb
SG
477 abort ();
478#if 0
479 if ((internal->r_size & 0x80) != 0
480 ? (relent->howto->complain_on_overflow != complain_overflow_signed)
481 : (relent->howto->complain_on_overflow != complain_overflow_bitfield))
482 abort ();
483#endif
484}
485
ae115e51 486static reloc_howto_type *
aadf04f7 487xcoff_reloc_type_lookup (abfd, code)
8b8ddedb
SG
488 bfd *abfd;
489 bfd_reloc_code_real_type code;
490{
491 switch (code)
492 {
493 case BFD_RELOC_PPC_B26:
aadf04f7 494 return &xcoff_howto_table[0xa];
8b8ddedb 495 case BFD_RELOC_PPC_BA26:
aadf04f7 496 return &xcoff_howto_table[8];
8b8ddedb 497 case BFD_RELOC_PPC_TOC16:
aadf04f7 498 return &xcoff_howto_table[3];
8b8ddedb 499 case BFD_RELOC_32:
aadf04f7 500 return &xcoff_howto_table[0];
8b8ddedb
SG
501 default:
502 return NULL;
503 }
504}
505
506#define SELECT_RELOC(internal, howto) \
507 { \
508 internal.r_type = howto->type; \
509 internal.r_size = \
510 ((howto->complain_on_overflow == complain_overflow_signed \
511 ? 0x80 \
512 : 0) \
513 | (howto->bitsize - 1)); \
514 }
aadf04f7
SS
515\f
516#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
8b8ddedb
SG
517
518#define COFF_LONG_FILENAMES
f4bd7a8f 519
aadf04f7
SS
520#define RTYPE2HOWTO(cache_ptr, dst) xcoff_rtype2howto (cache_ptr, dst)
521
522#define coff_mkobject xcoff_mkobject
523#define coff_bfd_copy_private_bfd_data xcoff_copy_private_bfd_data
524#define coff_bfd_reloc_type_lookup xcoff_reloc_type_lookup
525#define coff_relocate_section _bfd_ppc_xcoff_relocate_section
526
c9301d7b 527#include "coffcode.h"
bb2deaf2
ILT
528\f
529/* XCOFF archive support. The original version of this code was by
530 Damon A. Permezel. It was enhanced to permit cross support, and
531 writing archive files, by Ian Lance Taylor, Cygnus Support.
532
533 XCOFF uses its own archive format. Everything is hooked together
534 with file offset links, so it is possible to rapidly update an
535 archive in place. Of course, we don't do that. An XCOFF archive
536 has a real file header, not just an ARMAG string. The structure of
537 the file header and of each archive header appear below.
538
539 An XCOFF archive also has a member table, which is a list of
540 elements in the archive (you can get that by looking through the
541 linked list, but you have to read a lot more of the file). The
542 member table has a normal archive header with an empty name. It is
543 normally (and perhaps must be) the second to last entry in the
544 archive. The member table data is almost printable ASCII. It
545 starts with a 12 character decimal string which is the number of
546 entries in the table. For each entry it has a 12 character decimal
547 string which is the offset in the archive of that member. These
548 entries are followed by a series of null terminated strings which
549 are the member names for each entry.
550
551 Finally, an XCOFF archive has a global symbol table, which is what
552 we call the armap. The global symbol table has a normal archive
553 header with an empty name. It is normally (and perhaps must be)
554 the last entry in the archive. The contents start with a four byte
555 binary number which is the number of entries. This is followed by
556 a that many four byte binary numbers; each is the file offset of an
557 entry in the archive. These numbers are followed by a series of
558 null terminated strings, which are symbol names. */
559
560/* XCOFF archives use this as a magic string. */
561
562#define XCOFFARMAG "<aiaff>\012"
563#define SXCOFFARMAG 8
564
565/* This terminates an XCOFF archive member name. */
566
567#define XCOFFARFMAG "`\012"
568#define SXCOFFARFMAG 2
569
570/* XCOFF archives start with this (printable) structure. */
571
572struct xcoff_ar_file_hdr
573{
574 /* Magic string. */
575 char magic[SXCOFFARMAG];
576
577 /* Offset of the member table (decimal ASCII string). */
578 char memoff[12];
579
580 /* Offset of the global symbol table (decimal ASCII string). */
581 char symoff[12];
582
583 /* Offset of the first member in the archive (decimal ASCII string). */
584 char firstmemoff[12];
585
586 /* Offset of the last member in the archive (decimal ASCII string). */
587 char lastmemoff[12];
588
589 /* Offset of the first member on the free list (decimal ASCII
590 string). */
591 char freeoff[12];
592};
ba9137fe 593
bb2deaf2 594#define SIZEOF_AR_FILE_HDR (5 * 12 + SXCOFFARMAG)
ba9137fe 595
bb2deaf2
ILT
596/* Each XCOFF archive member starts with this (printable) structure. */
597
598struct xcoff_ar_hdr
599{
600 /* File size not including the header (decimal ASCII string). */
601 char size[12];
602
603 /* File offset of next archive member (decimal ASCII string). */
604 char nextoff[12];
605
606 /* File offset of previous archive member (decimal ASCII string). */
607 char prevoff[12];
608
609 /* File mtime (decimal ASCII string). */
610 char date[12];
611
612 /* File UID (decimal ASCII string). */
613 char uid[12];
614
615 /* File GID (decimal ASCII string). */
616 char gid[12];
617
618 /* File mode (octal ASCII string). */
619 char mode[12];
620
621 /* Length of file name (decimal ASCII string). */
622 char namlen[4];
623
624 /* This structure is followed by the file name. The length of the
625 name is given in the namlen field. If the length of the name is
626 odd, the name is followed by a null byte. The name and optional
627 null byte are followed by XCOFFARFMAG, which is not included in
628 namlen. The contents of the archive member follow; the number of
629 bytes is given in the size field. */
630};
ba9137fe 631
bb2deaf2 632#define SIZEOF_AR_HDR (7 * 12 + 4)
ba9137fe 633
bb2deaf2
ILT
634/* We store a copy of the xcoff_ar_file_hdr in the tdata field of the
635 artdata structure. */
636#define xcoff_ardata(abfd) \
637 ((struct xcoff_ar_file_hdr *) bfd_ardata (abfd)->tdata)
ba9137fe 638
bb2deaf2
ILT
639/* We store a copy of the xcoff_ar_hdr in the arelt_data field of an
640 archive element. */
641#define arch_eltdata(bfd) ((struct areltdata *) ((bfd)->arelt_data))
642#define arch_xhdr(bfd) \
643 ((struct xcoff_ar_hdr *) arch_eltdata (bfd)->arch_header)
ba9137fe 644
bb2deaf2
ILT
645/* XCOFF archives do not have anything which corresponds to an
646 extended name table. */
ba9137fe 647
bb2deaf2
ILT
648#define xcoff_slurp_extended_name_table bfd_false
649#define xcoff_construct_extended_name_table \
650 ((boolean (*) PARAMS ((bfd *, char **, bfd_size_type *, const char **))) \
651 bfd_false)
652#define xcoff_truncate_arname bfd_dont_truncate_arname
ba9137fe 653
bb2deaf2 654/* XCOFF archives do not have a timestamp. */
ba9137fe 655
bb2deaf2 656#define xcoff_update_armap_timestamp bfd_true
ba9137fe 657
bb2deaf2 658/* Read in the armap of an XCOFF archive. */
ba9137fe
JG
659
660static boolean
bb2deaf2 661xcoff_slurp_armap (abfd)
ba9137fe
JG
662 bfd *abfd;
663{
bb2deaf2
ILT
664 file_ptr off;
665 struct xcoff_ar_hdr hdr;
666 size_t namlen;
667 bfd_size_type sz;
668 bfd_byte *contents, *cend;
669 unsigned int c, i;
670 carsym *arsym;
671 bfd_byte *p;
672
673 if (xcoff_ardata (abfd) == NULL)
674 {
675 bfd_has_map (abfd) = false;
676 return true;
677 }
678
679 off = strtol (xcoff_ardata (abfd)->symoff, (char **) NULL, 10);
680 if (off == 0)
681 {
682 bfd_has_map (abfd) = false;
683 return true;
684 }
685
686 if (bfd_seek (abfd, off, SEEK_SET) != 0)
687 return false;
688
689 /* The symbol table starts with a normal archive header. */
690 if (bfd_read ((PTR) &hdr, SIZEOF_AR_HDR, 1, abfd) != SIZEOF_AR_HDR)
691 return false;
692
693 /* Skip the name (normally empty). */
694 namlen = strtol (hdr.namlen, (char **) NULL, 10);
695 if (bfd_seek (abfd, ((namlen + 1) & ~1) + SXCOFFARFMAG, SEEK_CUR) != 0)
696 return false;
697
698 /* Read in the entire symbol table. */
699 sz = strtol (hdr.size, (char **) NULL, 10);
700 contents = (bfd_byte *) bfd_alloc (abfd, sz);
701 if (contents == NULL)
702 {
703 bfd_set_error (bfd_error_no_memory);
704 return false;
705 }
706 if (bfd_read ((PTR) contents, 1, sz, abfd) != sz)
707 return false;
708
709 /* The symbol table starts with a four byte count. */
710 c = bfd_h_get_32 (abfd, contents);
711
712 if (c * 4 >= sz)
713 {
714 bfd_set_error (bfd_error_bad_value);
715 return false;
716 }
717
718 bfd_ardata (abfd)->symdefs = ((carsym *)
719 bfd_alloc (abfd, c * sizeof (carsym)));
720 if (bfd_ardata (abfd)->symdefs == NULL)
721 {
722 bfd_set_error (bfd_error_no_memory);
723 return false;
724 }
725
726 /* After the count comes a list of four byte file offsets. */
727 for (i = 0, arsym = bfd_ardata (abfd)->symdefs, p = contents + 4;
728 i < c;
729 ++i, ++arsym, p += 4)
730 arsym->file_offset = bfd_h_get_32 (abfd, p);
731
732 /* After the file offsets come null terminated symbol names. */
733 cend = contents + sz;
734 for (i = 0, arsym = bfd_ardata (abfd)->symdefs;
735 i < c;
736 ++i, ++arsym, p += strlen ((char *) p) + 1)
737 {
738 if (p >= cend)
739 {
740 bfd_set_error (bfd_error_bad_value);
741 return false;
742 }
743 arsym->name = (char *) p;
744 }
ba9137fe 745
bb2deaf2
ILT
746 bfd_ardata (abfd)->symdef_count = c;
747 bfd_has_map (abfd) = true;
ba9137fe 748
bb2deaf2
ILT
749 return true;
750}
ba9137fe 751
bb2deaf2 752/* See if this is an XCOFF archive. */
ba9137fe 753
bb2deaf2
ILT
754static const bfd_target *
755xcoff_archive_p (abfd)
ba9137fe
JG
756 bfd *abfd;
757{
bb2deaf2 758 struct xcoff_ar_file_hdr hdr;
ba9137fe 759
bb2deaf2
ILT
760 if (bfd_read ((PTR) &hdr, SIZEOF_AR_FILE_HDR, 1, abfd)
761 != SIZEOF_AR_FILE_HDR)
762 {
763 if (bfd_get_error () != bfd_error_system_call)
764 bfd_set_error (bfd_error_wrong_format);
765 return NULL;
766 }
ba9137fe 767
bb2deaf2
ILT
768 if (strncmp (hdr.magic, XCOFFARMAG, SXCOFFARMAG) != 0)
769 {
770 bfd_set_error (bfd_error_wrong_format);
771 return NULL;
772 }
ba9137fe 773
bb2deaf2
ILT
774 /* We are setting bfd_ardata(abfd) here, but since bfd_ardata
775 involves a cast, we can't do it as the left operand of
776 assignment. */
777 abfd->tdata.aout_ar_data =
778 (struct artdata *) bfd_zalloc (abfd, sizeof (struct artdata));
ba9137fe 779
bb2deaf2
ILT
780 if (bfd_ardata (abfd) == (struct artdata *) NULL)
781 {
782 bfd_set_error (bfd_error_no_memory);
783 return NULL;
784 }
ba9137fe 785
bb2deaf2
ILT
786 bfd_ardata (abfd)->first_file_filepos = strtol (hdr.firstmemoff,
787 (char **) NULL, 10);
788 bfd_ardata (abfd)->cache = NULL;
789 bfd_ardata (abfd)->archive_head = NULL;
790 bfd_ardata (abfd)->symdefs = NULL;
791 bfd_ardata (abfd)->extended_names = NULL;
ba9137fe 792
bb2deaf2
ILT
793 bfd_ardata (abfd)->tdata = bfd_zalloc (abfd, SIZEOF_AR_FILE_HDR);
794 if (bfd_ardata (abfd)->tdata == NULL)
795 {
796 bfd_set_error (bfd_error_no_memory);
797 return NULL;
798 }
ba9137fe 799
bb2deaf2 800 memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR);
ba9137fe 801
bb2deaf2
ILT
802 if (! xcoff_slurp_armap (abfd))
803 {
804 bfd_release (abfd, bfd_ardata (abfd));
805 abfd->tdata.aout_ar_data = (struct artdata *) NULL;
806 return NULL;
807 }
ba9137fe 808
bb2deaf2 809 return abfd->xvec;
ba9137fe
JG
810}
811
bb2deaf2 812/* Read the archive header in an XCOFF archive. */
c9301d7b 813
bb2deaf2
ILT
814static PTR
815xcoff_read_ar_hdr (abfd)
816 bfd *abfd;
c9301d7b 817{
bb2deaf2
ILT
818 struct xcoff_ar_hdr hdr;
819 size_t namlen;
820 struct xcoff_ar_hdr *hdrp;
821 struct areltdata *ret;
c9301d7b 822
bb2deaf2 823 if (bfd_read ((PTR) &hdr, SIZEOF_AR_HDR, 1, abfd) != SIZEOF_AR_HDR)
c9301d7b 824 return NULL;
c9301d7b 825
bb2deaf2
ILT
826 namlen = strtol (hdr.namlen, (char **) NULL, 10);
827 hdrp = bfd_alloc (abfd, SIZEOF_AR_HDR + namlen + 1);
828 if (hdrp == NULL)
829 {
830 bfd_set_error (bfd_error_no_memory);
831 return NULL;
832 }
833 memcpy (hdrp, &hdr, SIZEOF_AR_HDR);
834 if (bfd_read ((char *) hdrp + SIZEOF_AR_HDR, 1, namlen, abfd) != namlen)
c9301d7b 835 return NULL;
bb2deaf2 836 ((char *) hdrp)[SIZEOF_AR_HDR + namlen] = '\0';
c9301d7b 837
bb2deaf2
ILT
838 ret = (struct areltdata *) bfd_alloc (abfd, sizeof (struct areltdata));
839 if (ret == NULL)
840 {
841 bfd_set_error (bfd_error_no_memory);
842 return NULL;
843 }
844 ret->arch_header = (char *) hdrp;
845 ret->parsed_size = strtol (hdr.size, (char **) NULL, 10);
846 ret->filename = (char *) hdrp + SIZEOF_AR_HDR;
847
848 /* Skip over the XCOFFARFMAG at the end of the file name. */
849 if (bfd_seek (abfd, (namlen & 1) + SXCOFFARFMAG, SEEK_CUR) != 0)
850 return NULL;
c9301d7b 851
bb2deaf2 852 return (PTR) ret;
c9301d7b
SC
853}
854
bb2deaf2
ILT
855/* Open the next element in an XCOFF archive. */
856
ba9137fe 857static bfd *
bb2deaf2
ILT
858xcoff_openr_next_archived_file (archive, last_file)
859 bfd *archive;
860 bfd *last_file;
ba9137fe 861{
bb2deaf2
ILT
862 file_ptr filestart;
863
864 if (xcoff_ardata (archive) == NULL)
865 {
866 bfd_set_error (bfd_error_invalid_operation);
867 return NULL;
868 }
869
870 if (last_file == NULL)
871 filestart = bfd_ardata (archive)->first_file_filepos;
872 else
873 filestart = strtol (arch_xhdr (last_file)->nextoff, (char **) NULL, 10);
ba9137fe 874
bb2deaf2
ILT
875 if (filestart == 0
876 || filestart == strtol (xcoff_ardata (archive)->memoff,
877 (char **) NULL, 10)
878 || filestart == strtol (xcoff_ardata (archive)->symoff,
879 (char **) NULL, 10))
880 {
881 bfd_set_error (bfd_error_no_more_archived_files);
882 return NULL;
883 }
ba9137fe 884
bb2deaf2 885 return _bfd_get_elt_at_filepos (archive, filestart);
ba9137fe
JG
886}
887
bb2deaf2 888/* Stat an element in an XCOFF archive. */
ba9137fe 889
aadf04f7 890static int
bb2deaf2 891xcoff_generic_stat_arch_elt (abfd, s)
ba9137fe 892 bfd *abfd;
bb2deaf2 893 struct stat *s;
ba9137fe 894{
bb2deaf2 895 struct xcoff_ar_hdr *hdrp;
ba9137fe 896
bb2deaf2
ILT
897 if (abfd->arelt_data == NULL)
898 {
899 bfd_set_error (bfd_error_invalid_operation);
900 return -1;
901 }
ba9137fe 902
bb2deaf2 903 hdrp = arch_xhdr (abfd);
ba9137fe 904
bb2deaf2
ILT
905 s->st_mtime = strtol (hdrp->date, (char **) NULL, 10);
906 s->st_uid = strtol (hdrp->uid, (char **) NULL, 10);
907 s->st_gid = strtol (hdrp->gid, (char **) NULL, 10);
908 s->st_mode = strtol (hdrp->mode, (char **) NULL, 8);
909 s->st_size = arch_eltdata (abfd)->parsed_size;
ba9137fe 910
bb2deaf2
ILT
911 return 0;
912}
ba9137fe 913
bb2deaf2
ILT
914/* Normalize a file name for inclusion in an archive. */
915
916static const char *
917normalize_filename (abfd)
918 bfd *abfd;
919{
920 const char *file;
921 const char *filename;
922
923 file = bfd_get_filename (abfd);
924 filename = strrchr (file, '/');
925 if (filename != NULL)
926 filename++;
927 else
928 filename = file;
929 return filename;
ba9137fe
JG
930}
931
bb2deaf2 932/* Write out an XCOFF armap. */
ba9137fe 933
bb2deaf2
ILT
934/*ARGSUSED*/
935static boolean
936xcoff_write_armap (abfd, elength, map, orl_count, stridx)
937 bfd *abfd;
938 unsigned int elength;
939 struct orl *map;
940 unsigned int orl_count;
941 int stridx;
ba9137fe 942{
bb2deaf2
ILT
943 struct xcoff_ar_hdr hdr;
944 char *p;
aadf04f7 945 unsigned char buf[4];
bb2deaf2
ILT
946 bfd *sub;
947 file_ptr fileoff;
948 unsigned int i;
949
950 memset (&hdr, 0, sizeof hdr);
951 sprintf (hdr.size, "%ld", (long) (4 + orl_count * 4 + stridx));
952 sprintf (hdr.nextoff, "%d", 0);
953 memcpy (hdr.prevoff, xcoff_ardata (abfd)->memoff, 12);
954 sprintf (hdr.date, "%d", 0);
955 sprintf (hdr.uid, "%d", 0);
956 sprintf (hdr.gid, "%d", 0);
957 sprintf (hdr.mode, "%d", 0);
958 sprintf (hdr.namlen, "%d", 0);
959
960 /* We need spaces, not null bytes, in the header. */
961 for (p = (char *) &hdr; p < (char *) &hdr + SIZEOF_AR_HDR; p++)
962 if (*p == '\0')
963 *p = ' ';
964
965 if (bfd_write ((PTR) &hdr, SIZEOF_AR_HDR, 1, abfd) != SIZEOF_AR_HDR
966 || bfd_write (XCOFFARFMAG, 1, SXCOFFARFMAG, abfd) != SXCOFFARFMAG)
967 return false;
ba9137fe 968
bb2deaf2
ILT
969 bfd_h_put_32 (abfd, orl_count, buf);
970 if (bfd_write (buf, 1, 4, abfd) != 4)
971 return false;
972
973 sub = abfd->archive_head;
974 fileoff = SIZEOF_AR_FILE_HDR;
975 i = 0;
976 while (sub != NULL && i < orl_count)
977 {
978 size_t namlen;
979
980 while (((bfd *) (map[i]).pos) == sub)
981 {
982 bfd_h_put_32 (abfd, fileoff, buf);
983 if (bfd_write (buf, 1, 4, abfd) != 4)
984 return false;
985 ++i;
ba9137fe 986 }
bb2deaf2
ILT
987 namlen = strlen (normalize_filename (sub));
988 namlen = (namlen + 1) &~ 1;
989 fileoff += (SIZEOF_AR_HDR
990 + namlen
991 + SXCOFFARFMAG
992 + arelt_size (sub));
993 fileoff = (fileoff + 1) &~ 1;
994 sub = sub->next;
995 }
ba9137fe 996
bb2deaf2
ILT
997 for (i = 0; i < orl_count; i++)
998 {
999 const char *name;
1000 size_t namlen;
1001
1002 name = *map[i].name;
1003 namlen = strlen (name);
1004 if (bfd_write (name, 1, namlen + 1, abfd) != namlen + 1)
1005 return false;
1006 }
1007
1008 if ((stridx & 1) != 0)
1009 {
1010 char b;
1011
1012 b = '\0';
1013 if (bfd_write (&b, 1, 1, abfd) != 1)
1014 return false;
1015 }
1016
1017 return true;
ba9137fe
JG
1018}
1019
bb2deaf2
ILT
1020/* Write out an XCOFF archive. We always write an entire archive,
1021 rather than fussing with the freelist and so forth. */
1022
ba9137fe 1023static boolean
bb2deaf2
ILT
1024xcoff_write_archive_contents (abfd)
1025 bfd *abfd;
ba9137fe 1026{
bb2deaf2
ILT
1027 struct xcoff_ar_file_hdr fhdr;
1028 size_t count;
1029 size_t total_namlen;
1030 file_ptr *offsets;
1031 boolean makemap;
1032 boolean hasobjects;
1033 file_ptr prevoff, nextoff;
1034 bfd *sub;
1035 unsigned int i;
1036 struct xcoff_ar_hdr ahdr;
1037 bfd_size_type size;
1038 char *p;
1039 char decbuf[13];
1040
1041 memset (&fhdr, 0, sizeof fhdr);
1042 strncpy (fhdr.magic, XCOFFARMAG, SXCOFFARMAG);
1043 sprintf (fhdr.firstmemoff, "%d", SIZEOF_AR_FILE_HDR);
1044 sprintf (fhdr.freeoff, "%d", 0);
1045
1046 count = 0;
1047 total_namlen = 0;
1048 for (sub = abfd->archive_head; sub != NULL; sub = sub->next)
1049 {
1050 ++count;
1051 total_namlen += strlen (normalize_filename (sub)) + 1;
1052 }
1053 offsets = (file_ptr *) bfd_alloc (abfd, count * sizeof (file_ptr));
1054 if (offsets == NULL)
1055 {
1056 bfd_set_error (bfd_error_no_memory);
1057 return false;
1058 }
1059
1060 if (bfd_seek (abfd, SIZEOF_AR_FILE_HDR, SEEK_SET) != 0)
1061 return false;
1062
1063 makemap = bfd_has_map (abfd);
1064 hasobjects = false;
1065 prevoff = 0;
1066 nextoff = SIZEOF_AR_FILE_HDR;
1067 for (sub = abfd->archive_head, i = 0; sub != NULL; sub = sub->next, i++)
1068 {
1069 const char *name;
1070 size_t namlen;
1071 struct xcoff_ar_hdr *ahdrp;
1072 bfd_size_type remaining;
1073
1074 if (makemap && ! hasobjects)
1075 {
1076 if (bfd_check_format (sub, bfd_object))
1077 hasobjects = true;
1078 }
1079
1080 name = normalize_filename (sub);
1081 namlen = strlen (name);
1082
1083 if (sub->arelt_data != NULL)
1084 ahdrp = arch_xhdr (sub);
1085 else
1086 ahdrp = NULL;
1087
1088 if (ahdrp == NULL)
1089 {
1090 struct stat s;
1091
1092 memset (&ahdr, 0, sizeof ahdr);
1093 ahdrp = &ahdr;
1094 if (stat (bfd_get_filename (sub), &s) != 0)
1095 {
1096 bfd_set_error (bfd_error_system_call);
45b5d2f0 1097 return false;
bb2deaf2
ILT
1098 }
1099
1100 sprintf (ahdrp->size, "%ld", (long) s.st_size);
1101 sprintf (ahdrp->date, "%ld", (long) s.st_mtime);
1102 sprintf (ahdrp->uid, "%ld", (long) s.st_uid);
1103 sprintf (ahdrp->gid, "%ld", (long) s.st_gid);
1104 sprintf (ahdrp->mode, "%o", (unsigned int) s.st_mode);
1105
1106 if (sub->arelt_data == NULL)
1107 {
1108 sub->arelt_data = ((struct areltdata *)
1109 bfd_alloc (sub, sizeof (struct areltdata)));
1110 if (sub->arelt_data == NULL)
1111 {
1112 bfd_set_error (bfd_error_no_memory);
1113 return false;
1114 }
1115 }
1116
1117 arch_eltdata (sub)->parsed_size = s.st_size;
1118 }
1119
1120 sprintf (ahdrp->prevoff, "%ld", (long) prevoff);
1121 sprintf (ahdrp->namlen, "%ld", (long) namlen);
1122
1123 /* If the length of the name is odd, we write out the null byte
1124 after the name as well. */
1125 namlen = (namlen + 1) &~ 1;
1126
1127 remaining = arelt_size (sub);
1128 size = (SIZEOF_AR_HDR
1129 + namlen
1130 + SXCOFFARFMAG
1131 + remaining);
1132
1133 BFD_ASSERT (nextoff == bfd_tell (abfd));
1134
1135 offsets[i] = nextoff;
1136
1137 prevoff = nextoff;
1138 nextoff += size + (size & 1);
1139
1140 sprintf (ahdrp->nextoff, "%ld", (long) nextoff);
1141
1142 /* We need spaces, not null bytes, in the header. */
1143 for (p = (char *) ahdrp; p < (char *) ahdrp + SIZEOF_AR_HDR; p++)
1144 if (*p == '\0')
1145 *p = ' ';
1146
1147 if (bfd_write ((PTR) ahdrp, 1, SIZEOF_AR_HDR, abfd) != SIZEOF_AR_HDR
1148 || bfd_write ((PTR) name, 1, namlen, abfd) != namlen
1149 || (bfd_write ((PTR) XCOFFARFMAG, 1, SXCOFFARFMAG, abfd)
1150 != SXCOFFARFMAG))
ba9137fe 1151 return false;
c9301d7b 1152
bb2deaf2
ILT
1153 if (bfd_seek (sub, (file_ptr) 0, SEEK_SET) != 0)
1154 return false;
1155 while (remaining != 0)
1156 {
1157 bfd_size_type amt;
1158 bfd_byte buffer[DEFAULT_BUFFERSIZE];
1159
1160 amt = sizeof buffer;
1161 if (amt > remaining)
1162 amt = remaining;
1163 if (bfd_read (buffer, 1, amt, sub) != amt
1164 || bfd_write (buffer, 1, amt, abfd) != amt)
1165 return false;
1166 remaining -= amt;
1167 }
1168
1169 if ((size & 1) != 0)
1170 {
1171 bfd_byte b;
1172
1173 b = '\0';
1174 if (bfd_write (&b, 1, 1, abfd) != 1)
1175 return false;
1176 }
1177 }
1178
1179 sprintf (fhdr.lastmemoff, "%ld", (long) prevoff);
1180
1181 /* Write out the member table. */
1182
1183 BFD_ASSERT (nextoff == bfd_tell (abfd));
1184 sprintf (fhdr.memoff, "%ld", (long) nextoff);
1185
1186 memset (&ahdr, 0, sizeof ahdr);
1187 sprintf (ahdr.size, "%ld", (long) (12 + count * 12 + total_namlen));
1188 sprintf (ahdr.prevoff, "%ld", (long) prevoff);
1189 sprintf (ahdr.date, "%d", 0);
1190 sprintf (ahdr.uid, "%d", 0);
1191 sprintf (ahdr.gid, "%d", 0);
1192 sprintf (ahdr.mode, "%d", 0);
1193 sprintf (ahdr.namlen, "%d", 0);
1194
1195 size = (SIZEOF_AR_HDR
1196 + 12
1197 + count * 12
1198 + total_namlen
1199 + SXCOFFARFMAG);
1200
1201 prevoff = nextoff;
1202 nextoff += size + (size & 1);
1203
1204 if (makemap && hasobjects)
1205 sprintf (ahdr.nextoff, "%ld", (long) nextoff);
1206 else
1207 sprintf (ahdr.nextoff, "%d", 0);
1208
1209 /* We need spaces, not null bytes, in the header. */
1210 for (p = (char *) &ahdr; p < (char *) &ahdr + SIZEOF_AR_HDR; p++)
1211 if (*p == '\0')
1212 *p = ' ';
1213
1214 if (bfd_write ((PTR) &ahdr, 1, SIZEOF_AR_HDR, abfd) != SIZEOF_AR_HDR
1215 || (bfd_write ((PTR) XCOFFARFMAG, 1, SXCOFFARFMAG, abfd)
1216 != SXCOFFARFMAG))
1217 return false;
1218
1219 sprintf (decbuf, "%-12ld", (long) count);
1220 if (bfd_write ((PTR) decbuf, 1, 12, abfd) != 12)
1221 return false;
1222 for (i = 0; i < count; i++)
1223 {
1224 sprintf (decbuf, "%-12ld", (long) offsets[i]);
1225 if (bfd_write ((PTR) decbuf, 1, 12, abfd) != 12)
1226 return false;
1227 }
1228 for (sub = abfd->archive_head; sub != NULL; sub = sub->next)
1229 {
1230 const char *name;
1231 size_t namlen;
1232
1233 name = normalize_filename (sub);
1234 namlen = strlen (name);
1235 if (bfd_write ((PTR) name, 1, namlen + 1, abfd) != namlen + 1)
1236 return false;
1237 }
1238 if ((size & 1) != 0)
1239 {
1240 bfd_byte b;
1241
1242 b = '\0';
1243 if (bfd_write ((PTR) &b, 1, 1, abfd) != 1)
1244 return false;
1245 }
1246
1247 /* Write out the armap, if appropriate. */
1248
1249 if (! makemap || ! hasobjects)
1250 sprintf (fhdr.symoff, "%d", 0);
1251 else
1252 {
1253 BFD_ASSERT (nextoff == bfd_tell (abfd));
1254 sprintf (fhdr.symoff, "%ld", (long) nextoff);
1255 bfd_ardata (abfd)->tdata = (PTR) &fhdr;
1256 if (! _bfd_compute_and_write_armap (abfd, 0))
1257 return false;
1258 }
1259
1260 /* Write out the archive file header. */
1261
1262 /* We need spaces, not null bytes, in the header. */
1263 for (p = (char *) &fhdr; p < (char *) &fhdr + SIZEOF_AR_FILE_HDR; p++)
1264 if (*p == '\0')
1265 *p = ' ';
1266
1267 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
1268 || (bfd_write ((PTR) &fhdr, SIZEOF_AR_FILE_HDR, 1, abfd) !=
1269 SIZEOF_AR_FILE_HDR))
1270 return false;
1271
1272 return true;
1273}
294eaca4 1274\f
8b8ddedb
SG
1275#define CORE_FILE_P _bfd_dummy_target
1276
6812b607
ILT
1277#define coff_core_file_failing_command _bfd_nocore_core_file_failing_command
1278#define coff_core_file_failing_signal _bfd_nocore_core_file_failing_signal
1279#define coff_core_file_matches_executable_p \
1280 _bfd_nocore_core_file_matches_executable_p
1281
ae115e51 1282#ifdef AIX_CORE
8b8ddedb
SG
1283#undef CORE_FILE_P
1284#define CORE_FILE_P rs6000coff_core_p
ae115e51 1285extern const bfd_target * rs6000coff_core_p ();
294eaca4
SC
1286extern boolean rs6000coff_get_section_contents ();
1287extern boolean rs6000coff_core_file_matches_executable_p ();
c9301d7b
SC
1288
1289#undef coff_core_file_matches_executable_p
1290#define coff_core_file_matches_executable_p \
1291 rs6000coff_core_file_matches_executable_p
ba9137fe 1292
bb2deaf2
ILT
1293extern char *rs6000coff_core_file_failing_command PARAMS ((bfd *abfd));
1294#undef coff_core_file_failing_command
1295#define coff_core_file_failing_command rs6000coff_core_file_failing_command
1296
1297extern int rs6000coff_core_file_failing_signal PARAMS ((bfd *abfd));
1298#undef coff_core_file_failing_signal
1299#define coff_core_file_failing_signal rs6000coff_core_file_failing_signal
1300
c9301d7b
SC
1301#undef coff_get_section_contents
1302#define coff_get_section_contents rs6000coff_get_section_contents
ae115e51 1303#endif /* AIX_CORE */
8b8ddedb 1304
ae115e51 1305#ifdef LYNX_CORE
8b8ddedb
SG
1306
1307#undef CORE_FILE_P
1308#define CORE_FILE_P lynx_core_file_p
ae115e51 1309extern const bfd_target *lynx_core_file_p PARAMS ((bfd *abfd));
8b8ddedb
SG
1310
1311extern boolean lynx_core_file_matches_executable_p PARAMS ((bfd *core_bfd,
1312 bfd *exec_bfd));
1313#undef coff_core_file_matches_executable_p
1314#define coff_core_file_matches_executable_p lynx_core_file_matches_executable_p
1315
1316extern char *lynx_core_file_failing_command PARAMS ((bfd *abfd));
1317#undef coff_core_file_failing_command
1318#define coff_core_file_failing_command lynx_core_file_failing_command
1319
1320extern int lynx_core_file_failing_signal PARAMS ((bfd *abfd));
1321#undef coff_core_file_failing_signal
1322#define coff_core_file_failing_signal lynx_core_file_failing_signal
1323
ae115e51 1324#endif /* LYNX_CORE */
ba9137fe 1325
aadf04f7
SS
1326#define _bfd_xcoff_sizeof_headers coff_sizeof_headers
1327#define _bfd_xcoff_bfd_get_relocated_section_contents \
1328 coff_bfd_get_relocated_section_contents
1329#define _bfd_xcoff_bfd_relax_section coff_bfd_relax_section
1330#define _bfd_xcoff_bfd_link_split_section coff_bfd_link_split_section
1331
c9301d7b
SC
1332/* The transfer vector that leads the outside world to all of the above. */
1333
ae115e51 1334const bfd_target rs6000coff_vec =
c9301d7b
SC
1335{
1336 "aixcoff-rs6000", /* name */
1337 bfd_target_coff_flavour,
1338 true, /* data byte order is big */
1339 true, /* header byte order is big */
1340
1341 (HAS_RELOC | EXEC_P | /* object flags */
aadf04f7 1342 HAS_LINENO | HAS_DEBUG | DYNAMIC |
f4bd7a8f 1343 HAS_SYMS | HAS_LOCALS | WP_TEXT),
c9301d7b
SC
1344
1345 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
294eaca4 1346 0, /* leading char */
c9301d7b
SC
1347 '/', /* ar_pad_char */
1348 15, /* ar_max_namelen??? FIXMEmgo */
c9301d7b 1349
f4bd7a8f
DM
1350 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
1351 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
1352 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* data */
1353 bfd_getb64, bfd_getb_signed_64, bfd_putb64,
1354 bfd_getb32, bfd_getb_signed_32, bfd_putb32,
1355 bfd_getb16, bfd_getb_signed_16, bfd_putb16, /* hdrs */
c9301d7b
SC
1356
1357 {_bfd_dummy_target, coff_object_p, /* bfd_check_format */
bb2deaf2
ILT
1358 xcoff_archive_p, CORE_FILE_P},
1359 {bfd_false, coff_mkobject, /* bfd_set_format */
1360 _bfd_generic_mkarchive, bfd_false},
c9301d7b 1361 {bfd_false, coff_write_object_contents, /* bfd_write_contents */
bb2deaf2 1362 xcoff_write_archive_contents, bfd_false},
c9301d7b 1363
6812b607
ILT
1364 BFD_JUMP_TABLE_GENERIC (coff),
1365 BFD_JUMP_TABLE_COPY (coff),
1366 BFD_JUMP_TABLE_CORE (coff),
bb2deaf2 1367 BFD_JUMP_TABLE_ARCHIVE (xcoff),
6812b607
ILT
1368 BFD_JUMP_TABLE_SYMBOLS (coff),
1369 BFD_JUMP_TABLE_RELOCS (coff),
1370 BFD_JUMP_TABLE_WRITE (coff),
aadf04f7 1371 BFD_JUMP_TABLE_LINK (_bfd_xcoff),
ae115e51 1372 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
6812b607 1373
f4bd7a8f 1374 COFF_SWAP_TABLE,
c9301d7b 1375};
This page took 0.229635 seconds and 4 git commands to generate.