* xcofflink.c: Extensive changes to support linking shared objects
[external/binutils.git] / bfd / coff-rs6000.c
1 /* BFD back-end for IBM RS/6000 "XCOFF" files.
2    Copyright 1990, 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
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.
9    Archive support from Damon A. Permezel.
10    Contributed by IBM Corporation and Cygnus Support.
11
12 This file is part of BFD, the Binary File Descriptor library.
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
27
28 /* Internalcoff.h and coffcode.h modify themselves based on this flag.  */
29 #define RS6000COFF_C 1
30
31 #include "bfd.h"
32 #include "sysdep.h"
33 #include "libbfd.h"
34 #include "obstack.h"
35 #include "coff/internal.h"
36 #include "coff/rs6000.h"
37 #include "libcoff.h"
38
39 /* The main body of code is in coffcode.h.  */
40
41 static boolean xcoff_mkobject PARAMS ((bfd *));
42 static boolean xcoff_copy_private_bfd_data PARAMS ((bfd *, bfd *));
43 static void xcoff_rtype2howto
44   PARAMS ((arelent *, struct internal_reloc *));
45 static reloc_howto_type *xcoff_reloc_type_lookup
46   PARAMS ((bfd *, bfd_reloc_code_real_type));
47 static boolean xcoff_slurp_armap PARAMS ((bfd *));
48 static const bfd_target *xcoff_archive_p PARAMS ((bfd *));
49 static PTR xcoff_read_ar_hdr PARAMS ((bfd *));
50 static bfd *xcoff_openr_next_archived_file PARAMS ((bfd *, bfd *));
51 static int xcoff_generic_stat_arch_elt PARAMS ((bfd *, struct stat *));
52 static const char *normalize_filename PARAMS ((bfd *));
53 static boolean xcoff_write_armap
54   PARAMS ((bfd *, unsigned int, struct orl *, unsigned int, int));
55 static boolean xcoff_write_archive_contents PARAMS ((bfd *));
56 \f
57 /* We use our own tdata type.  Its first field is the COFF tdata type,
58    so the COFF routines are compatible.  */
59
60 static boolean
61 xcoff_mkobject (abfd)
62      bfd *abfd;
63 {
64   coff_data_type *coff;
65
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 }
91
92 /* Copy XCOFF data from one BFD to another.  */
93
94 static boolean
95 xcoff_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
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
121 static reloc_howto_type xcoff_howto_table[] =
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 */                               
175          complain_overflow_bitfield, /* complain_on_overflow */
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 */                     
398          "R_CREL",              /* name */                                 
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 */                     
443          "R_RBR",               /* name */                                 
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 */                     
458          "R_RBRC",              /* name */                                 
459          true,                  /* partial_inplace */                      
460          0xffff,                /* src_mask */                             
461          0xffff,                /* dst_mask */                             
462          false)                 /* pcrel_offset */
463 };
464
465 static void
466 xcoff_rtype2howto (relent, internal)
467      arelent *relent;
468      struct internal_reloc *internal;
469 {
470   relent->howto = xcoff_howto_table + internal->r_type;
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.  */
476   if (relent->howto->bitsize != ((unsigned int) internal->r_size & 0x1f) + 1)
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
486 static reloc_howto_type *
487 xcoff_reloc_type_lookup (abfd, code)
488      bfd *abfd;
489      bfd_reloc_code_real_type code;
490 {
491   switch (code)
492     {
493     case BFD_RELOC_PPC_B26:
494       return &xcoff_howto_table[0xa];
495     case BFD_RELOC_PPC_BA26:
496       return &xcoff_howto_table[8];
497     case BFD_RELOC_PPC_TOC16:
498       return &xcoff_howto_table[3];
499     case BFD_RELOC_32:
500       return &xcoff_howto_table[0];
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   }
515 \f
516 #define COFF_DEFAULT_SECTION_ALIGNMENT_POWER (3)
517
518 #define COFF_LONG_FILENAMES
519
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
527 #include "coffcode.h"
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
572 struct 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 };
593
594 #define SIZEOF_AR_FILE_HDR (5 * 12 + SXCOFFARMAG)
595
596 /* Each XCOFF archive member starts with this (printable) structure.  */
597
598 struct 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 };
631
632 #define SIZEOF_AR_HDR (7 * 12 + 4)
633
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)
638
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)
644
645 /* XCOFF archives do not have anything which corresponds to an
646    extended name table.  */
647
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
653
654 /* XCOFF archives do not have a timestamp.  */
655
656 #define xcoff_update_armap_timestamp bfd_true
657
658 /* Read in the armap of an XCOFF archive.  */
659
660 static boolean
661 xcoff_slurp_armap (abfd)
662      bfd *abfd;
663 {
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     }
745
746   bfd_ardata (abfd)->symdef_count = c;
747   bfd_has_map (abfd) = true;
748
749   return true;
750 }
751
752 /* See if this is an XCOFF archive.  */
753
754 static const bfd_target *
755 xcoff_archive_p (abfd)
756      bfd *abfd;
757 {
758   struct xcoff_ar_file_hdr hdr;
759
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     }
767
768   if (strncmp (hdr.magic, XCOFFARMAG, SXCOFFARMAG) != 0)
769     {
770       bfd_set_error (bfd_error_wrong_format);
771       return NULL;
772     }
773
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));
779
780   if (bfd_ardata (abfd) == (struct artdata *) NULL)
781     {
782       bfd_set_error (bfd_error_no_memory);
783       return NULL;
784     }
785
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;
792
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     }
799
800   memcpy (bfd_ardata (abfd)->tdata, &hdr, SIZEOF_AR_FILE_HDR);
801
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     }
808
809   return abfd->xvec;
810 }
811
812 /* Read the archive header in an XCOFF archive.  */
813
814 static PTR
815 xcoff_read_ar_hdr (abfd)
816      bfd *abfd;
817 {
818   struct xcoff_ar_hdr hdr;
819   size_t namlen;
820   struct xcoff_ar_hdr *hdrp;
821   struct areltdata *ret;
822
823   if (bfd_read ((PTR) &hdr, SIZEOF_AR_HDR, 1, abfd) != SIZEOF_AR_HDR)
824     return NULL;
825
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)
835     return NULL;
836   ((char *) hdrp)[SIZEOF_AR_HDR + namlen] = '\0';
837
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;
851
852   return (PTR) ret;
853 }
854
855 /* Open the next element in an XCOFF archive.  */
856
857 static bfd *
858 xcoff_openr_next_archived_file (archive, last_file)
859      bfd *archive;
860      bfd *last_file;
861 {
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);
874
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     }
884
885   return _bfd_get_elt_at_filepos (archive, filestart);
886 }
887
888 /* Stat an element in an XCOFF archive.  */
889
890 static int
891 xcoff_generic_stat_arch_elt (abfd, s)
892      bfd *abfd;
893      struct stat *s;
894 {
895   struct xcoff_ar_hdr *hdrp;
896
897   if (abfd->arelt_data == NULL)
898     {
899       bfd_set_error (bfd_error_invalid_operation);
900       return -1;
901     }
902
903   hdrp = arch_xhdr (abfd);
904
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;
910
911   return 0;
912 }
913
914 /* Normalize a file name for inclusion in an archive.  */
915
916 static const char *
917 normalize_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;
930 }
931
932 /* Write out an XCOFF armap.  */
933
934 /*ARGSUSED*/
935 static boolean
936 xcoff_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;
942 {
943   struct xcoff_ar_hdr hdr;
944   char *p;
945   unsigned char buf[4];
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;
968   
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;
986         }
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     }
996
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;
1018 }
1019
1020 /* Write out an XCOFF archive.  We always write an entire archive,
1021    rather than fussing with the freelist and so forth.  */
1022
1023 static boolean
1024 xcoff_write_archive_contents (abfd)
1025      bfd *abfd;
1026 {
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);
1097               return false;
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))
1151         return false;
1152
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 }
1274 \f
1275 #define CORE_FILE_P _bfd_dummy_target
1276
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
1282 #ifdef AIX_CORE
1283 #undef CORE_FILE_P
1284 #define CORE_FILE_P rs6000coff_core_p
1285 extern const bfd_target * rs6000coff_core_p ();
1286 extern boolean rs6000coff_get_section_contents ();
1287 extern boolean rs6000coff_core_file_matches_executable_p ();
1288
1289 #undef  coff_core_file_matches_executable_p
1290 #define coff_core_file_matches_executable_p  \
1291                                      rs6000coff_core_file_matches_executable_p
1292
1293 extern 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
1297 extern 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
1301 #undef  coff_get_section_contents
1302 #define coff_get_section_contents       rs6000coff_get_section_contents
1303 #endif /* AIX_CORE */
1304
1305 #ifdef LYNX_CORE
1306
1307 #undef CORE_FILE_P
1308 #define CORE_FILE_P lynx_core_file_p
1309 extern const bfd_target *lynx_core_file_p PARAMS ((bfd *abfd));
1310
1311 extern 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
1316 extern 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
1320 extern 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
1324 #endif /* LYNX_CORE */
1325
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
1332 /* The transfer vector that leads the outside world to all of the above. */
1333
1334 const bfd_target rs6000coff_vec =
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 */
1342    HAS_LINENO | HAS_DEBUG | DYNAMIC |
1343    HAS_SYMS | HAS_LOCALS | WP_TEXT),
1344
1345   (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_RELOC), /* section flags */
1346   0,                            /* leading char */
1347   '/',                          /* ar_pad_char */
1348   15,                           /* ar_max_namelen??? FIXMEmgo */
1349
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 */
1356
1357   {_bfd_dummy_target, coff_object_p,    /* bfd_check_format */
1358      xcoff_archive_p, CORE_FILE_P},
1359   {bfd_false, coff_mkobject,            /* bfd_set_format */
1360      _bfd_generic_mkarchive, bfd_false},
1361   {bfd_false, coff_write_object_contents,       /* bfd_write_contents */
1362      xcoff_write_archive_contents, bfd_false},
1363
1364      BFD_JUMP_TABLE_GENERIC (coff),
1365      BFD_JUMP_TABLE_COPY (coff),
1366      BFD_JUMP_TABLE_CORE (coff),
1367      BFD_JUMP_TABLE_ARCHIVE (xcoff),
1368      BFD_JUMP_TABLE_SYMBOLS (coff),
1369      BFD_JUMP_TABLE_RELOCS (coff),
1370      BFD_JUMP_TABLE_WRITE (coff),
1371      BFD_JUMP_TABLE_LINK (_bfd_xcoff),
1372      BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
1373
1374   COFF_SWAP_TABLE,
1375 };