1131722Sobrien/* Internal format of XCOFF object file data structures for BFD.
2131722Sobrien
3218822Sdim   Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005
4131722Sobrien   Free Software Foundation, Inc.
5131722Sobrien   Written by Ian Lance Taylor <ian@cygnus.com>, Cygnus Support.
6131722Sobrien
7131722Sobrien   This file is part of BFD, the Binary File Descriptor library.
8131722Sobrien
9131722Sobrien   This program is free software; you can redistribute it and/or modify
10131722Sobrien   it under the terms of the GNU General Public License as published by
11131722Sobrien   the Free Software Foundation; either version 2 of the License, or
12131722Sobrien   (at your option) any later version.
13131722Sobrien
14131722Sobrien   This program is distributed in the hope that it will be useful,
15131722Sobrien   but WITHOUT ANY WARRANTY; without even the implied warranty of
16131722Sobrien   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17131722Sobrien   GNU General Public License for more details.
18131722Sobrien
19131722Sobrien   You should have received a copy of the GNU General Public License
20131722Sobrien   along with this program; if not, write to the Free Software
21218822Sdim   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
22131722Sobrien
23131722Sobrien#ifndef _INTERNAL_XCOFF_H
24131722Sobrien#define _INTERNAL_XCOFF_H
25131722Sobrien
26131722Sobrien/* Linker */
27131722Sobrien
28131722Sobrien/* Names of "special" sections.  */
29131722Sobrien#define _TEXT	".text"
30131722Sobrien#define _DATA	".data"
31131722Sobrien#define _BSS	".bss"
32131722Sobrien#define _PAD	".pad"
33131722Sobrien#define _LOADER	".loader"
34131722Sobrien#define _EXCEPT ".except"
35131722Sobrien#define _TYPCHK ".typchk"
36131722Sobrien
37131722Sobrien/* XCOFF uses a special .loader section with type STYP_LOADER.  */
38131722Sobrien#define STYP_LOADER 0x1000
39131722Sobrien
40131722Sobrien/* XCOFF uses a special .debug section with type STYP_DEBUG.  */
41131722Sobrien#define STYP_DEBUG 0x2000
42131722Sobrien
43131722Sobrien/* XCOFF handles line number or relocation overflow by creating
44131722Sobrien   another section header with STYP_OVRFLO set.  */
45131722Sobrien#define STYP_OVRFLO 0x8000
46131722Sobrien
47131722Sobrien/* Specifies an exception section.  A section of this type provides
48131722Sobrien   information to identify the reason that a trap or ececptin occured within
49131722Sobrien   and executable object program */
50131722Sobrien#define STYP_EXCEPT 0x0100
51131722Sobrien
52131722Sobrien/* Specifies a type check section.  A section of this type contains parameter
53131722Sobrien   argument type check strings used by the AIX binder.  */
54131722Sobrien#define STYP_TYPCHK 0x4000
55131722Sobrien
56131722Sobrien#define	RS6K_AOUTHDR_OMAGIC 0x0107 /* old: text & data writeable */
57131722Sobrien#define	RS6K_AOUTHDR_NMAGIC 0x0108 /* new: text r/o, data r/w */
58131722Sobrien#define	RS6K_AOUTHDR_ZMAGIC 0x010B /* paged: text r/o, both page-aligned */
59131722Sobrien
60131722Sobrien/* XCOFF relocation types.
61131722Sobrien   The relocations are described in the function
62131722Sobrien   xcoff[64]_ppc_relocate_section in coff64-rs6000.c and coff-rs6000.c  */
63131722Sobrien
64131722Sobrien#define R_POS   (0x00)
65131722Sobrien#define R_NEG   (0x01)
66131722Sobrien#define R_REL   (0x02)
67131722Sobrien#define R_TOC   (0x03)
68131722Sobrien#define R_RTB   (0x04)
69131722Sobrien#define R_GL    (0x05)
70131722Sobrien#define R_TCL   (0x06)
71131722Sobrien#define R_BA    (0x08)
72131722Sobrien#define R_BR    (0x0a)
73131722Sobrien#define R_RL    (0x0c)
74131722Sobrien#define R_RLA   (0x0d)
75131722Sobrien#define R_REF   (0x0f)
76131722Sobrien#define R_TRL   (0x12)
77131722Sobrien#define R_TRLA  (0x13)
78131722Sobrien#define R_RRTBI (0x14)
79131722Sobrien#define R_RRTBA (0x15)
80131722Sobrien#define R_CAI   (0x16)
81131722Sobrien#define R_CREL  (0x17)
82131722Sobrien#define R_RBA   (0x18)
83131722Sobrien#define R_RBAC  (0x19)
84131722Sobrien#define R_RBR   (0x1a)
85131722Sobrien#define R_RBRC  (0x1b)
86131722Sobrien
87131722Sobrien/* Storage class #defines, from /usr/include/storclass.h that are not already
88131722Sobrien   defined in internal.h */
89131722Sobrien
90131722Sobrien/* Comment string in .info section */
91131722Sobrien#define	C_INFO		110
92131722Sobrien
93131722Sobrien/* Auxillary Symbol Entries  */
94131722Sobrien
95131722Sobrien/* x_smtyp values:  */
96131722Sobrien#define	SMTYP_ALIGN(x)	((x) >> 3)	/* log2 of alignment */
97131722Sobrien#define	SMTYP_SMTYP(x)	((x) & 0x7)	/* symbol type */
98131722Sobrien/* Symbol type values:  */
99131722Sobrien#define	XTY_ER	0		/* External reference */
100131722Sobrien#define	XTY_SD	1		/* Csect definition */
101131722Sobrien#define	XTY_LD	2		/* Label definition */
102131722Sobrien#define XTY_CM	3		/* .BSS */
103131722Sobrien#define	XTY_EM	4		/* Error message */
104131722Sobrien#define	XTY_US	5		/* "Reserved for internal use" */
105131722Sobrien
106131722Sobrien/* x_smclas values:  */
107131722Sobrien#define	XMC_PR	0		/* Read-only program code */
108131722Sobrien#define	XMC_RO	1		/* Read-only constant */
109131722Sobrien#define	XMC_DB	2		/* Read-only debug dictionary table */
110131722Sobrien#define	XMC_TC	3		/* Read-write general TOC entry */
111131722Sobrien#define	XMC_UA	4		/* Read-write unclassified */
112131722Sobrien#define	XMC_RW	5		/* Read-write data */
113131722Sobrien#define	XMC_GL	6		/* Read-only global linkage */
114131722Sobrien#define	XMC_XO	7		/* Read-only extended operation */
115131722Sobrien#define	XMC_SV	8		/* Read-only supervisor call */
116131722Sobrien#define	XMC_BS	9		/* Read-write BSS */
117131722Sobrien#define	XMC_DS	10		/* Read-write descriptor csect */
118131722Sobrien#define	XMC_UC	11		/* Read-write unnamed Fortran common */
119131722Sobrien#define	XMC_TI	12		/* Read-only traceback index csect */
120131722Sobrien#define	XMC_TB	13		/* Read-only traceback table csect */
121131722Sobrien/* 		14	??? */
122131722Sobrien#define	XMC_TC0	15		/* Read-write TOC anchor */
123131722Sobrien#define XMC_TD	16		/* Read-write data in TOC */
124131722Sobrien#define	XMC_SV64   17		/* Read-only 64 bit supervisor call */
125131722Sobrien#define	XMC_SV3264 18		/* Read-only 32 or 64 bit supervisor call */
126131722Sobrien
127131722Sobrien/* The ldhdr structure.  This appears at the start of the .loader
128131722Sobrien   section.  */
129131722Sobrien
130131722Sobrienstruct internal_ldhdr
131131722Sobrien{
132131722Sobrien  /* The version number:
133131722Sobrien     1 : 32 bit
134131722Sobrien     2 : 64 bit */
135131722Sobrien  unsigned long l_version;
136131722Sobrien
137131722Sobrien  /* The number of symbol table entries.  */
138131722Sobrien  bfd_size_type l_nsyms;
139131722Sobrien
140131722Sobrien  /* The number of relocation table entries.  */
141131722Sobrien  bfd_size_type l_nreloc;
142131722Sobrien
143131722Sobrien  /* The length of the import file string table.  */
144131722Sobrien  bfd_size_type l_istlen;
145131722Sobrien
146131722Sobrien  /* The number of import files.  */
147131722Sobrien  bfd_size_type l_nimpid;
148131722Sobrien
149131722Sobrien  /* The offset from the start of the .loader section to the first
150131722Sobrien     entry in the import file table.  */
151131722Sobrien  bfd_size_type l_impoff;
152131722Sobrien
153131722Sobrien  /* The length of the string table.  */
154131722Sobrien  bfd_size_type l_stlen;
155131722Sobrien
156131722Sobrien  /* The offset from the start of the .loader section to the first
157131722Sobrien     entry in the string table.  */
158131722Sobrien  bfd_size_type l_stoff;
159131722Sobrien
160131722Sobrien  /* The offset to start of the symbol table, only in XCOFF64 */
161131722Sobrien  bfd_vma l_symoff;
162131722Sobrien
163131722Sobrien  /* The offset to the start of the relocation table, only in XCOFF64 */
164131722Sobrien  bfd_vma l_rldoff;
165131722Sobrien};
166131722Sobrien
167131722Sobrien/* The ldsym structure.  This is used to represent a symbol in the
168131722Sobrien   .loader section.  */
169131722Sobrien
170131722Sobrienstruct internal_ldsym
171131722Sobrien{
172131722Sobrien  union
173131722Sobrien  {
174131722Sobrien    /* The symbol name if <= SYMNMLEN characters.  */
175131722Sobrien    char _l_name[SYMNMLEN];
176131722Sobrien    struct
177131722Sobrien    {
178131722Sobrien      /* Zero if the symbol name is more than SYMNMLEN characters.  */
179131722Sobrien	long _l_zeroes;
180131722Sobrien
181131722Sobrien      /* The offset in the string table if the symbol name is more
182131722Sobrien	 than SYMNMLEN characters.  */
183131722Sobrien      long _l_offset;
184131722Sobrien    }
185131722Sobrien    _l_l;
186131722Sobrien  }
187131722Sobrien  _l;
188131722Sobrien
189131722Sobrien  /* The symbol value.  */
190131722Sobrien  bfd_vma l_value;
191131722Sobrien
192131722Sobrien  /* The symbol section number.  */
193131722Sobrien  short l_scnum;
194131722Sobrien
195131722Sobrien  /* The symbol type and flags.  */
196131722Sobrien  char l_smtype;
197131722Sobrien
198131722Sobrien  /* The symbol storage class.  */
199131722Sobrien  char l_smclas;
200131722Sobrien
201131722Sobrien  /* The import file ID.  */
202131722Sobrien  bfd_size_type l_ifile;
203131722Sobrien
204131722Sobrien  /* Offset to the parameter type check string.  */
205131722Sobrien  bfd_size_type l_parm;
206131722Sobrien};
207131722Sobrien
208131722Sobrien/* These flags are for the l_smtype field (the lower three bits are an
209131722Sobrien   XTY_* value).  */
210131722Sobrien
211131722Sobrien/* Imported symbol.  */
212131722Sobrien#define L_IMPORT (0x40)
213131722Sobrien/* Entry point.  */
214131722Sobrien#define L_ENTRY (0x20)
215131722Sobrien/* Exported symbol.  */
216131722Sobrien#define L_EXPORT (0x10)
217131722Sobrien
218131722Sobrien/* The ldrel structure.  This is used to represent a reloc in the
219131722Sobrien   .loader section.  */
220131722Sobrien
221131722Sobrienstruct internal_ldrel
222131722Sobrien{
223131722Sobrien  /* The reloc address.  */
224131722Sobrien  bfd_vma l_vaddr;
225131722Sobrien
226131722Sobrien  /* The symbol table index in the .loader section symbol table.  */
227131722Sobrien  bfd_size_type l_symndx;
228131722Sobrien
229131722Sobrien  /* The relocation type and size.  */
230131722Sobrien  short l_rtype;
231131722Sobrien
232131722Sobrien  /* The section number this relocation applies to.  */
233131722Sobrien  short l_rsecnm;
234131722Sobrien};
235131722Sobrien
236131722Sobrien/* An entry in the XCOFF linker hash table.  */
237131722Sobrienstruct xcoff_link_hash_entry
238131722Sobrien{
239131722Sobrien  struct bfd_link_hash_entry root;
240131722Sobrien
241131722Sobrien  /* Symbol index in output file.  Set to -1 initially.  Set to -2 if
242131722Sobrien     there is a reloc against this symbol.  */
243131722Sobrien  long indx;
244131722Sobrien
245131722Sobrien  /* If we have created a TOC entry for this symbol, this is the .tc
246131722Sobrien     section which holds it.  */
247131722Sobrien  asection *toc_section;
248131722Sobrien
249131722Sobrien  union
250131722Sobrien  {
251131722Sobrien    /* If we have created a TOC entry (the XCOFF_SET_TOC flag is
252131722Sobrien       set), this is the offset in toc_section.  */
253131722Sobrien    bfd_vma toc_offset;
254131722Sobrien
255131722Sobrien    /* If the TOC entry comes from an input file, this is set to the
256131722Sobrien       symbol index of the C_HIDEXT XMC_TC or XMC_TD symbol.  */
257131722Sobrien    long toc_indx;
258131722Sobrien  }
259131722Sobrien  u;
260131722Sobrien
261131722Sobrien  /* If this symbol is a function entry point which is called, this
262131722Sobrien     field holds a pointer to the function descriptor.  If this symbol
263131722Sobrien     is a function descriptor, this field holds a pointer to the
264131722Sobrien     function entry point.  */
265131722Sobrien  struct xcoff_link_hash_entry *descriptor;
266131722Sobrien
267131722Sobrien  /* The .loader symbol table entry, if there is one.  */
268131722Sobrien  struct internal_ldsym *ldsym;
269131722Sobrien
270131722Sobrien  /* If XCOFF_BUILT_LDSYM is set, this is the .loader symbol table
271131722Sobrien     index.  If XCOFF_BUILD_LDSYM is clear, and XCOFF_IMPORT is set,
272131722Sobrien     this is the l_ifile value.  */
273131722Sobrien  long ldindx;
274131722Sobrien
275131722Sobrien  /* Some linker flags.  */
276131722Sobrien  unsigned long flags;
277131722Sobrien
278131722Sobrien  /* The storage mapping class.  */
279131722Sobrien  unsigned char smclas;
280131722Sobrien};
281131722Sobrien
282131722Sobrien/*  Flags for xcoff_link_hash_entry.  */
283131722Sobrien
284131722Sobrien/* Symbol is referenced by a regular object. */
285131722Sobrien#define XCOFF_REF_REGULAR      0x00000001
286131722Sobrien/* Symbol is defined by a regular object. */
287131722Sobrien#define XCOFF_DEF_REGULAR      0x00000002
288131722Sobrien/* Symbol is defined by a dynamic object. */
289131722Sobrien#define XCOFF_DEF_DYNAMIC      0x00000004
290131722Sobrien/* Symbol is used in a reloc being copied into the .loader section.  */
291131722Sobrien#define XCOFF_LDREL            0x00000008
292131722Sobrien/* Symbol is the entry point.  */
293131722Sobrien#define XCOFF_ENTRY            0x00000010
294131722Sobrien/* Symbol is called; this is, it appears in a R_BR reloc.  */
295131722Sobrien#define XCOFF_CALLED           0x00000020
296131722Sobrien/* Symbol needs the TOC entry filled in.  */
297131722Sobrien#define XCOFF_SET_TOC          0x00000040
298131722Sobrien/* Symbol is explicitly imported.  */
299131722Sobrien#define XCOFF_IMPORT           0x00000080
300131722Sobrien/* Symbol is explicitly exported.  */
301131722Sobrien#define XCOFF_EXPORT           0x00000100
302131722Sobrien/* Symbol has been processed by xcoff_build_ldsyms.  */
303131722Sobrien#define XCOFF_BUILT_LDSYM      0x00000200
304131722Sobrien/* Symbol is mentioned by a section which was not garbage collected. */
305131722Sobrien#define XCOFF_MARK             0x00000400
306131722Sobrien/* Symbol size is recorded in size_list list from hash table.  */
307131722Sobrien#define XCOFF_HAS_SIZE         0x00000800
308131722Sobrien/* Symbol is a function descriptor.  */
309131722Sobrien#define XCOFF_DESCRIPTOR       0x00001000
310131722Sobrien/* Multiple definitions have been for the symbol. */
311131722Sobrien#define XCOFF_MULTIPLY_DEFINED 0x00002000
312131722Sobrien/* Symbol is the __rtinit symbol.  */
313131722Sobrien#define XCOFF_RTINIT           0x00004000
314131722Sobrien/* Symbol is an imported 32 bit syscall.  */
315131722Sobrien#define XCOFF_SYSCALL32        0x00008000
316131722Sobrien/* Symbol is an imported 64 bit syscall.  */
317131722Sobrien#define XCOFF_SYSCALL64        0x00010000
318131722Sobrien
319131722Sobrien/* The XCOFF linker hash table.  */
320131722Sobrien
321131722Sobrien#define XCOFF_NUMBER_OF_SPECIAL_SECTIONS 6
322131722Sobrien#define XCOFF_SPECIAL_SECTION_TEXT       0
323131722Sobrien#define XCOFF_SPECIAL_SECTION_ETEXT      1
324131722Sobrien#define XCOFF_SPECIAL_SECTION_DATA       2
325131722Sobrien#define XCOFF_SPECIAL_SECTION_EDATA      3
326131722Sobrien#define XCOFF_SPECIAL_SECTION_END        4
327131722Sobrien#define XCOFF_SPECIAL_SECTION_END2       5
328131722Sobrien
329131722Sobrienstruct xcoff_link_hash_table
330131722Sobrien{
331131722Sobrien  struct bfd_link_hash_table root;
332131722Sobrien
333131722Sobrien  /* The .debug string hash table.  We need to compute this while
334131722Sobrien     reading the input files, so that we know how large the .debug
335131722Sobrien     section will be before we assign section positions.  */
336131722Sobrien  struct bfd_strtab_hash *debug_strtab;
337131722Sobrien
338131722Sobrien  /* The .debug section we will use for the final output.  */
339131722Sobrien  asection *debug_section;
340131722Sobrien
341131722Sobrien  /* The .loader section we will use for the final output.  */
342131722Sobrien  asection *loader_section;
343131722Sobrien
344131722Sobrien  /* A count of non TOC relative relocs which will need to be
345131722Sobrien     allocated in the .loader section.  */
346131722Sobrien  size_t ldrel_count;
347131722Sobrien
348131722Sobrien  /* The .loader section header.  */
349131722Sobrien  struct internal_ldhdr ldhdr;
350131722Sobrien
351131722Sobrien  /* The .gl section we use to hold global linkage code.  */
352131722Sobrien  asection *linkage_section;
353131722Sobrien
354131722Sobrien  /* The .tc section we use to hold toc entries we build for global
355131722Sobrien     linkage code.  */
356131722Sobrien  asection *toc_section;
357131722Sobrien
358131722Sobrien  /* The .ds section we use to hold function descriptors which we
359131722Sobrien     create for exported symbols.  */
360131722Sobrien  asection *descriptor_section;
361131722Sobrien
362131722Sobrien  /* The list of import files.  */
363131722Sobrien  struct xcoff_import_file *imports;
364131722Sobrien
365131722Sobrien  /* Required alignment of sections within the output file.  */
366131722Sobrien  unsigned long file_align;
367131722Sobrien
368131722Sobrien  /* Whether the .text section must be read-only.  */
369131722Sobrien  bfd_boolean textro;
370131722Sobrien
371131722Sobrien  /* Whether garbage collection was done.  */
372131722Sobrien  bfd_boolean gc;
373131722Sobrien
374131722Sobrien  /* A linked list of symbols for which we have size information.  */
375131722Sobrien  struct xcoff_link_size_list
376131722Sobrien  {
377131722Sobrien    struct xcoff_link_size_list *next;
378131722Sobrien    struct xcoff_link_hash_entry *h;
379131722Sobrien    bfd_size_type size;
380131722Sobrien  }
381131722Sobrien  *size_list;
382131722Sobrien
383131722Sobrien  /* Magic sections: _text, _etext, _data, _edata, _end, end. */
384131722Sobrien  asection *special_sections[XCOFF_NUMBER_OF_SPECIAL_SECTIONS];
385131722Sobrien};
386131722Sobrien
387131722Sobrien
388131722Sobrien/* This structure is used to pass information through
389131722Sobrien   xcoff_link_hash_traverse.  */
390131722Sobrien
391131722Sobrienstruct xcoff_loader_info
392131722Sobrien{
393131722Sobrien  /* Set if a problem occurred.  */
394131722Sobrien  bfd_boolean failed;
395131722Sobrien
396131722Sobrien  /* Output BFD.  */
397131722Sobrien  bfd *output_bfd;
398131722Sobrien
399131722Sobrien  /* Link information structure.  */
400131722Sobrien  struct bfd_link_info *info;
401131722Sobrien
402131722Sobrien  /* Whether all defined symbols should be exported.  */
403131722Sobrien  bfd_boolean export_defineds;
404131722Sobrien
405131722Sobrien  /* Number of ldsym structures.  */
406131722Sobrien  size_t ldsym_count;
407131722Sobrien
408131722Sobrien  /* Size of string table.  */
409131722Sobrien  size_t string_size;
410131722Sobrien
411131722Sobrien  /* String table.  */
412218822Sdim  char *strings;
413131722Sobrien
414131722Sobrien  /* Allocated size of string table.  */
415131722Sobrien  size_t string_alc;
416131722Sobrien};
417131722Sobrien
418131722Sobrien/* In case we're on a 32-bit machine, construct a 64-bit "-1" value
419131722Sobrien   from smaller values.  Start with zero, widen, *then* decrement.  */
420131722Sobrien#define MINUS_ONE       (((bfd_vma) 0) - 1)
421131722Sobrien
422131722Sobrien/* __rtinit, from /usr/include/rtinit.h.  */
423131722Sobrienstruct __rtinit
424131722Sobrien{
425131722Sobrien  /* Pointer to runtime linker.
426131722Sobrien     XXX: Is the parameter really void?  */
427131722Sobrien  int	(*rtl) (void);
428131722Sobrien
429131722Sobrien  /* Offset to array of init functions, 0 if none. */
430131722Sobrien  int	init_offset;
431131722Sobrien
432131722Sobrien  /* Offset to array of fini functions, 0 if none. */
433131722Sobrien  int	fini_offset;
434131722Sobrien
435131722Sobrien  /* Size of __RTINIT_DESCRIPTOR. This value should be used instead of
436131722Sobrien     sizeof(__RTINIT_DESCRIPTOR). */
437131722Sobrien  int	__rtinit_descriptor_size;
438131722Sobrien};
439131722Sobrien
440131722Sobrien#define RTINIT_DESCRIPTOR_SIZE (12)
441131722Sobrien
442131722Sobrienstruct __rtinit_descriptor
443131722Sobrien{
444131722Sobrien  /* Init/fini function. */
445131722Sobrien  int	f;
446131722Sobrien
447131722Sobrien  /* Offset, relative to the start of the __rtinit symbol, to name of the
448131722Sobrien     function. */
449131722Sobrien
450131722Sobrien  int	name_offset;
451131722Sobrien
452131722Sobrien  /* Flags */
453131722Sobrien  unsigned char	flags;
454131722Sobrien};
455131722Sobrien
456131722Sobrien/* Archive */
457131722Sobrien
458131722Sobrien#define XCOFFARMAG    "<aiaff>\012"
459131722Sobrien#define XCOFFARMAGBIG "<bigaf>\012"
460131722Sobrien#define SXCOFFARMAG   8
461131722Sobrien
462131722Sobrien/* The size of the ascii archive elements */
463131722Sobrien#define XCOFFARMAG_ELEMENT_SIZE 12
464131722Sobrien#define XCOFFARMAGBIG_ELEMENT_SIZE 20
465131722Sobrien
466131722Sobrien/* This terminates an XCOFF archive member name.  */
467131722Sobrien
468131722Sobrien#define XCOFFARFMAG "`\012"
469131722Sobrien#define SXCOFFARFMAG 2
470131722Sobrien
471131722Sobrien/* XCOFF archives start with this (printable) structure.  */
472131722Sobrien
473131722Sobrienstruct xcoff_ar_file_hdr
474131722Sobrien{
475131722Sobrien  /* Magic string.  */
476131722Sobrien  char magic[SXCOFFARMAG];
477131722Sobrien
478131722Sobrien  /* Offset of the member table (decimal ASCII string).  */
479131722Sobrien  char memoff[XCOFFARMAG_ELEMENT_SIZE];
480131722Sobrien
481131722Sobrien  /* Offset of the global symbol table (decimal ASCII string).  */
482131722Sobrien  char symoff[XCOFFARMAG_ELEMENT_SIZE];
483131722Sobrien
484131722Sobrien  /* Offset of the first member in the archive (decimal ASCII string).  */
485131722Sobrien  char firstmemoff[XCOFFARMAG_ELEMENT_SIZE];
486131722Sobrien
487131722Sobrien  /* Offset of the last member in the archive (decimal ASCII string).  */
488131722Sobrien  char lastmemoff[XCOFFARMAG_ELEMENT_SIZE];
489131722Sobrien
490131722Sobrien  /* Offset of the first member on the free list (decimal ASCII
491131722Sobrien     string).  */
492131722Sobrien  char freeoff[XCOFFARMAG_ELEMENT_SIZE];
493131722Sobrien};
494131722Sobrien
495131722Sobrien#define SIZEOF_AR_FILE_HDR (SXCOFFARMAG + 5 * XCOFFARMAG_ELEMENT_SIZE)
496131722Sobrien
497131722Sobrien/* This is the equivalent data structure for the big archive format.  */
498131722Sobrien
499131722Sobrienstruct xcoff_ar_file_hdr_big
500131722Sobrien{
501131722Sobrien  /* Magic string.  */
502131722Sobrien  char magic[SXCOFFARMAG];
503131722Sobrien
504131722Sobrien  /* Offset of the member table (decimal ASCII string).  */
505131722Sobrien  char memoff[XCOFFARMAGBIG_ELEMENT_SIZE];
506131722Sobrien
507131722Sobrien  /* Offset of the global symbol table for 32-bit objects (decimal ASCII
508131722Sobrien     string).  */
509131722Sobrien  char symoff[XCOFFARMAGBIG_ELEMENT_SIZE];
510131722Sobrien
511131722Sobrien  /* Offset of the global symbol table for 64-bit objects (decimal ASCII
512131722Sobrien     string).  */
513131722Sobrien  char symoff64[XCOFFARMAGBIG_ELEMENT_SIZE];
514131722Sobrien
515131722Sobrien  /* Offset of the first member in the archive (decimal ASCII string).  */
516131722Sobrien  char firstmemoff[XCOFFARMAGBIG_ELEMENT_SIZE];
517131722Sobrien
518131722Sobrien  /* Offset of the last member in the archive (decimal ASCII string).  */
519131722Sobrien  char lastmemoff[XCOFFARMAGBIG_ELEMENT_SIZE];
520131722Sobrien
521131722Sobrien  /* Offset of the first member on the free list (decimal ASCII
522131722Sobrien     string).  */
523131722Sobrien  char freeoff[XCOFFARMAGBIG_ELEMENT_SIZE];
524131722Sobrien};
525131722Sobrien
526131722Sobrien#define SIZEOF_AR_FILE_HDR_BIG (SXCOFFARMAG + 6 * XCOFFARMAGBIG_ELEMENT_SIZE)
527131722Sobrien
528131722Sobrien/* Each XCOFF archive member starts with this (printable) structure.  */
529131722Sobrien
530131722Sobrienstruct xcoff_ar_hdr
531131722Sobrien{
532131722Sobrien  /* File size not including the header (decimal ASCII string).  */
533131722Sobrien  char size[XCOFFARMAG_ELEMENT_SIZE];
534131722Sobrien
535131722Sobrien  /* File offset of next archive member (decimal ASCII string).  */
536131722Sobrien  char nextoff[XCOFFARMAG_ELEMENT_SIZE];
537131722Sobrien
538131722Sobrien  /* File offset of previous archive member (decimal ASCII string).  */
539131722Sobrien  char prevoff[XCOFFARMAG_ELEMENT_SIZE];
540131722Sobrien
541131722Sobrien  /* File mtime (decimal ASCII string).  */
542131722Sobrien  char date[12];
543131722Sobrien
544131722Sobrien  /* File UID (decimal ASCII string).  */
545131722Sobrien  char uid[12];
546131722Sobrien
547131722Sobrien  /* File GID (decimal ASCII string).  */
548131722Sobrien  char gid[12];
549131722Sobrien
550131722Sobrien  /* File mode (octal ASCII string).  */
551131722Sobrien  char mode[12];
552131722Sobrien
553131722Sobrien  /* Length of file name (decimal ASCII string).  */
554131722Sobrien  char namlen[4];
555131722Sobrien
556131722Sobrien  /* This structure is followed by the file name.  The length of the
557131722Sobrien     name is given in the namlen field.  If the length of the name is
558131722Sobrien     odd, the name is followed by a null byte.  The name and optional
559131722Sobrien     null byte are followed by XCOFFARFMAG, which is not included in
560131722Sobrien     namlen.  The contents of the archive member follow; the number of
561131722Sobrien     bytes is given in the size field.  */
562131722Sobrien};
563131722Sobrien
564131722Sobrien#define SIZEOF_AR_HDR (3 * XCOFFARMAG_ELEMENT_SIZE + 4 * 12 + 4)
565131722Sobrien
566131722Sobrien/* The equivalent for the big archive format.  */
567131722Sobrien
568131722Sobrienstruct xcoff_ar_hdr_big
569131722Sobrien{
570131722Sobrien  /* File size not including the header (decimal ASCII string).  */
571131722Sobrien  char size[XCOFFARMAGBIG_ELEMENT_SIZE];
572131722Sobrien
573131722Sobrien  /* File offset of next archive member (decimal ASCII string).  */
574131722Sobrien  char nextoff[XCOFFARMAGBIG_ELEMENT_SIZE];
575131722Sobrien
576131722Sobrien  /* File offset of previous archive member (decimal ASCII string).  */
577131722Sobrien  char prevoff[XCOFFARMAGBIG_ELEMENT_SIZE];
578131722Sobrien
579131722Sobrien  /* File mtime (decimal ASCII string).  */
580131722Sobrien  char date[12];
581131722Sobrien
582131722Sobrien  /* File UID (decimal ASCII string).  */
583131722Sobrien  char uid[12];
584131722Sobrien
585131722Sobrien  /* File GID (decimal ASCII string).  */
586131722Sobrien  char gid[12];
587131722Sobrien
588131722Sobrien  /* File mode (octal ASCII string).  */
589131722Sobrien  char mode[12];
590131722Sobrien
591131722Sobrien  /* Length of file name (decimal ASCII string).  */
592131722Sobrien  char namlen[4];
593131722Sobrien
594131722Sobrien  /* This structure is followed by the file name.  The length of the
595131722Sobrien     name is given in the namlen field.  If the length of the name is
596131722Sobrien     odd, the name is followed by a null byte.  The name and optional
597131722Sobrien     null byte are followed by XCOFFARFMAG, which is not included in
598131722Sobrien     namlen.  The contents of the archive member follow; the number of
599131722Sobrien     bytes is given in the size field.  */
600131722Sobrien};
601131722Sobrien
602131722Sobrien#define SIZEOF_AR_HDR_BIG (3 * XCOFFARMAGBIG_ELEMENT_SIZE + 4 * 12 + 4)
603131722Sobrien
604131722Sobrien/* We often have to distinguish between the old and big file format.
605131722Sobrien   Make it a bit cleaner.  We can use `xcoff_ardata' here because the
606131722Sobrien   `hdr' member has the same size and position in both formats.
607131722Sobrien   <bigaf> is the default format, return TRUE even when xcoff_ardata is
608131722Sobrien   NULL. */
609131722Sobrien#ifndef SMALL_ARCHIVE
610131722Sobrien/* Creates big archives by default */
611131722Sobrien#define xcoff_big_format_p(abfd) \
612131722Sobrien  ((NULL != bfd_ardata (abfd) && NULL == xcoff_ardata (abfd)) || \
613131722Sobrien   ((NULL != bfd_ardata (abfd)) && \
614131722Sobrien    (NULL != xcoff_ardata (abfd)) && \
615131722Sobrien    (xcoff_ardata (abfd)->magic[1] == 'b')))
616131722Sobrien#else
617131722Sobrien/* Creates small archives by default. */
618131722Sobrien#define xcoff_big_format_p(abfd) \
619131722Sobrien  (((NULL != bfd_ardata (abfd)) && \
620131722Sobrien    (NULL != xcoff_ardata (abfd)) && \
621131722Sobrien    (xcoff_ardata (abfd)->magic[1] == 'b')))
622131722Sobrien#endif
623131722Sobrien
624131722Sobrien/* We store a copy of the xcoff_ar_file_hdr in the tdata field of the
625131722Sobrien   artdata structure.  Similar for the big archive.  */
626131722Sobrien#define xcoff_ardata(abfd) \
627131722Sobrien  ((struct xcoff_ar_file_hdr *) bfd_ardata (abfd)->tdata)
628131722Sobrien#define xcoff_ardata_big(abfd) \
629131722Sobrien  ((struct xcoff_ar_file_hdr_big *) bfd_ardata (abfd)->tdata)
630131722Sobrien
631131722Sobrien/* We store a copy of the xcoff_ar_hdr in the arelt_data field of an
632131722Sobrien   archive element.  Similar for the big archive.  */
633131722Sobrien#define arch_eltdata(bfd) ((struct areltdata *) ((bfd)->arelt_data))
634131722Sobrien#define arch_xhdr(bfd) \
635131722Sobrien  ((struct xcoff_ar_hdr *) arch_eltdata (bfd)->arch_header)
636131722Sobrien#define arch_xhdr_big(bfd) \
637131722Sobrien  ((struct xcoff_ar_hdr_big *) arch_eltdata (bfd)->arch_header)
638131722Sobrien
639131722Sobrien#endif /* _INTERNAL_XCOFF_H */
640