12a6b7db3Sskrll /* Internal format of XCOFF object file data structures for BFD.
22a6b7db3Sskrll 
3*f22f0ef4Schristos    Copyright (C) 1995-2022 Free Software Foundation, Inc.
42a6b7db3Sskrll    Written by Ian Lance Taylor <ian@cygnus.com>, Cygnus Support.
52a6b7db3Sskrll 
62a6b7db3Sskrll    This file is part of BFD, the Binary File Descriptor library.
72a6b7db3Sskrll 
82a6b7db3Sskrll    This program is free software; you can redistribute it and/or modify
92a6b7db3Sskrll    it under the terms of the GNU General Public License as published by
10b075ecf2Schristos    the Free Software Foundation; either version 3 of the License, or
112a6b7db3Sskrll    (at your option) any later version.
122a6b7db3Sskrll 
132a6b7db3Sskrll    This program is distributed in the hope that it will be useful,
142a6b7db3Sskrll    but WITHOUT ANY WARRANTY; without even the implied warranty of
152a6b7db3Sskrll    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
162a6b7db3Sskrll    GNU General Public License for more details.
172a6b7db3Sskrll 
182a6b7db3Sskrll    You should have received a copy of the GNU General Public License
192a6b7db3Sskrll    along with this program; if not, write to the Free Software
20b075ecf2Schristos    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21b075ecf2Schristos    MA 02110-1301, USA.  */
222a6b7db3Sskrll 
232a6b7db3Sskrll #ifndef _INTERNAL_XCOFF_H
242a6b7db3Sskrll #define _INTERNAL_XCOFF_H
252a6b7db3Sskrll 
2605caefcfSchristos /* XCOFF specific f_flags.  */
2705caefcfSchristos 
2805caefcfSchristos /* File was profiled with fdpr.  */
2905caefcfSchristos #define F_FDPR_PROF 0x0010
3005caefcfSchristos 
3105caefcfSchristos /* File was reordered with fdpr.  */
3205caefcfSchristos #define F_FDPR_OPTI 0x0020
3305caefcfSchristos 
3405caefcfSchristos /* File use very large program support.  */
3505caefcfSchristos #define F_DSA       0x0040
3605caefcfSchristos 
3705caefcfSchristos /* One aux header specifying medium page sizes is non-zero.  */
3805caefcfSchristos #define F_VARPG     0x0100
3905caefcfSchristos 
4005caefcfSchristos /* Read/write sections are non-executable.  */
4105caefcfSchristos #define F_NONEXEC   0x8000
4205caefcfSchristos 
432a6b7db3Sskrll /* Linker */
442a6b7db3Sskrll 
452a6b7db3Sskrll /* Names of "special" sections.  */
462a6b7db3Sskrll #define _TEXT	".text"
472a6b7db3Sskrll #define _DATA	".data"
482a6b7db3Sskrll #define _BSS	".bss"
49*f22f0ef4Schristos #define _TDATA	".tdata"
50*f22f0ef4Schristos #define _TBSS	".tbss"
512a6b7db3Sskrll #define _PAD	".pad"
522a6b7db3Sskrll #define _LOADER	".loader"
532a6b7db3Sskrll #define _EXCEPT ".except"
542a6b7db3Sskrll #define _TYPCHK ".typchk"
552a6b7db3Sskrll 
5605caefcfSchristos /* XCOFF uses special .dwXXX sections with the type STYP_DWARF.  */
5705caefcfSchristos #define STYP_DWARF  0x0010
5805caefcfSchristos 
5905caefcfSchristos /* High-order 16-bits dwarf subtypes.  */
6005caefcfSchristos #define SSUBTYP_DWINFO  0x10000
6105caefcfSchristos #define SSUBTYP_DWLINE  0x20000
6205caefcfSchristos #define SSUBTYP_DWPBNMS 0x30000
6305caefcfSchristos #define SSUBTYP_DWPBTYP 0x40000
6405caefcfSchristos #define SSUBTYP_DWARNGE 0x50000
6505caefcfSchristos #define SSUBTYP_DWABREV 0x60000
6605caefcfSchristos #define SSUBTYP_DWSTR   0x70000
6705caefcfSchristos #define SSUBTYP_DWRNGES 0x80000
68*f22f0ef4Schristos #define SSUBTYP_DWLOC   0x90000
69*f22f0ef4Schristos #define SSUBTYP_DWFRAME 0xA0000
70*f22f0ef4Schristos #define SSUBTYP_DWMAC   0xB0000
7105caefcfSchristos 
722a6b7db3Sskrll /* XCOFF uses a special .loader section with type STYP_LOADER.  */
732a6b7db3Sskrll #define STYP_LOADER 0x1000
742a6b7db3Sskrll 
752a6b7db3Sskrll /* Specifies an exception section.  A section of this type provides
762a6b7db3Sskrll    information to identify the reason that a trap or ececptin occured within
772a6b7db3Sskrll    and executable object program */
782a6b7db3Sskrll #define STYP_EXCEPT 0x0100
792a6b7db3Sskrll 
8005caefcfSchristos /* Specifies an initialized thread-local data section.  */
8105caefcfSchristos #define STYP_TDATA  0x0400
8205caefcfSchristos 
8305caefcfSchristos /* Specifies an uninitialized thread-local data section.  */
8405caefcfSchristos #define STYP_TBSS   0x0800
8505caefcfSchristos 
8605caefcfSchristos /* XCOFF uses a special .debug section with type STYP_DEBUG.  */
8705caefcfSchristos #define STYP_DEBUG  0x2000
8805caefcfSchristos 
892a6b7db3Sskrll /* Specifies a type check section.  A section of this type contains parameter
902a6b7db3Sskrll    argument type check strings used by the AIX binder.  */
912a6b7db3Sskrll #define STYP_TYPCHK 0x4000
922a6b7db3Sskrll 
9305caefcfSchristos /* XCOFF handles line number or relocation overflow by creating
9405caefcfSchristos    another section header with STYP_OVRFLO set.  */
9505caefcfSchristos #define STYP_OVRFLO 0x8000
9605caefcfSchristos 
972a6b7db3Sskrll #define	RS6K_AOUTHDR_OMAGIC 0x0107 /* old: text & data writeable */
982a6b7db3Sskrll #define	RS6K_AOUTHDR_NMAGIC 0x0108 /* new: text r/o, data r/w */
992a6b7db3Sskrll #define	RS6K_AOUTHDR_ZMAGIC 0x010B /* paged: text r/o, both page-aligned */
1002a6b7db3Sskrll 
101*f22f0ef4Schristos /* Flags for aouthdr o_flags */
102*f22f0ef4Schristos #define RS6K_AOUTHDR_TLS_LE    0x80  /* TLS local-exec code was generated */
103*f22f0ef4Schristos #define RS6K_AOUTHDR_RAS       0x40  /* kernel module is key & recovery safe */
104*f22f0ef4Schristos #define RS6K_AOUTHDR_ALGNTDATA 0xf   /* TLS alignment */
105*f22f0ef4Schristos 
106*f22f0ef4Schristos /* Flags for aouthdr o_x64flags */
107*f22f0ef4Schristos #define RS6K_AOUTHDR_SHR_SYMTAB  0x8000
108*f22f0ef4Schristos #define RS6K_AOUTHDR_FORK_POLICY 0x4000
109*f22f0ef4Schristos #define RS6K_AOUTHDR_FORK_COR    0x2000
110*f22f0ef4Schristos 
111*f22f0ef4Schristos 
1122a6b7db3Sskrll /* XCOFF relocation types.
1132a6b7db3Sskrll    The relocations are described in the function
1142a6b7db3Sskrll    xcoff[64]_ppc_relocate_section in coff64-rs6000.c and coff-rs6000.c  */
1152a6b7db3Sskrll 
1162a6b7db3Sskrll #define R_POS    (0x00)
1172a6b7db3Sskrll #define R_NEG    (0x01)
1182a6b7db3Sskrll #define R_REL    (0x02)
1192a6b7db3Sskrll #define R_TOC    (0x03)
120*f22f0ef4Schristos #define R_TRL    (0x04)
1212a6b7db3Sskrll #define R_GL     (0x05)
1222a6b7db3Sskrll #define R_TCL    (0x06)
1232a6b7db3Sskrll #define R_BA     (0x08)
1242a6b7db3Sskrll #define R_BR     (0x0a)
1252a6b7db3Sskrll #define R_RL     (0x0c)
1262a6b7db3Sskrll #define R_RLA    (0x0d)
1272a6b7db3Sskrll #define R_REF    (0x0f)
1282a6b7db3Sskrll #define R_TRLA   (0x13)
1292a6b7db3Sskrll #define R_RRTBI  (0x14)
1302a6b7db3Sskrll #define R_RRTBA  (0x15)
1312a6b7db3Sskrll #define R_CAI    (0x16)
1322a6b7db3Sskrll #define R_CREL   (0x17)
1332a6b7db3Sskrll #define R_RBA    (0x18)
1342a6b7db3Sskrll #define R_RBAC   (0x19)
1352a6b7db3Sskrll #define R_RBR    (0x1a)
1362a6b7db3Sskrll #define R_RBRC   (0x1b)
13705caefcfSchristos #define R_TLS    (0x20)
13805caefcfSchristos #define R_TLS_IE (0x21)
13905caefcfSchristos #define R_TLS_LD (0x22)
14005caefcfSchristos #define R_TLS_LE (0x23)
14105caefcfSchristos #define R_TLSM   (0x24)
14205caefcfSchristos #define R_TLSML  (0x25)
14305caefcfSchristos #define R_TOCU   (0x30)
14405caefcfSchristos #define R_TOCL   (0x31)
1452a6b7db3Sskrll 
1462a6b7db3Sskrll /* Storage class #defines, from /usr/include/storclass.h that are not already
1472a6b7db3Sskrll    defined in internal.h */
1482a6b7db3Sskrll 
1492a6b7db3Sskrll /* Comment string in .info section */
1502a6b7db3Sskrll #define	C_INFO		110
1512a6b7db3Sskrll 
15205caefcfSchristos /* Dwarf symbol.  */
15305caefcfSchristos #define C_DWARF		112
15405caefcfSchristos 
1552a6b7db3Sskrll /* Auxillary Symbol Entries  */
1562a6b7db3Sskrll 
1572a6b7db3Sskrll /* x_smtyp values:  */
1582a6b7db3Sskrll #define	SMTYP_ALIGN(x)	((x) >> 3)	/* log2 of alignment */
1592a6b7db3Sskrll #define	SMTYP_SMTYP(x)	((x) & 0x7)	/* symbol type */
1602a6b7db3Sskrll /* Symbol type values:  */
1612a6b7db3Sskrll #define	XTY_ER	0		/* External reference */
1622a6b7db3Sskrll #define	XTY_SD	1		/* Csect definition */
1632a6b7db3Sskrll #define	XTY_LD	2		/* Label definition */
1642a6b7db3Sskrll #define XTY_CM	3		/* .BSS */
1652a6b7db3Sskrll #define	XTY_EM	4		/* Error message */
1662a6b7db3Sskrll #define	XTY_US	5		/* "Reserved for internal use" */
1672a6b7db3Sskrll 
1682a6b7db3Sskrll /* x_smclas values:  */
1692a6b7db3Sskrll #define	XMC_PR	0		/* Read-only program code */
1702a6b7db3Sskrll #define	XMC_RO	1		/* Read-only constant */
1712a6b7db3Sskrll #define	XMC_DB	2		/* Read-only debug dictionary table */
1722a6b7db3Sskrll #define	XMC_TC	3		/* Read-write general TOC entry */
1732a6b7db3Sskrll #define	XMC_UA	4		/* Read-write unclassified */
1742a6b7db3Sskrll #define	XMC_RW	5		/* Read-write data */
1752a6b7db3Sskrll #define	XMC_GL	6		/* Read-only global linkage */
1762a6b7db3Sskrll #define	XMC_XO	7		/* Read-only extended operation */
1772a6b7db3Sskrll #define	XMC_SV	8		/* Read-only supervisor call */
1782a6b7db3Sskrll #define	XMC_BS	9		/* Read-write BSS */
1792a6b7db3Sskrll #define	XMC_DS	10		/* Read-write descriptor csect */
1802a6b7db3Sskrll #define	XMC_UC	11		/* Read-write unnamed Fortran common */
1812a6b7db3Sskrll #define	XMC_TI	12		/* Read-only traceback index csect */
1822a6b7db3Sskrll #define	XMC_TB	13		/* Read-only traceback table csect */
1832a6b7db3Sskrll /* 		14	??? */
1842a6b7db3Sskrll #define	XMC_TC0	15		/* Read-write TOC anchor */
1852a6b7db3Sskrll #define XMC_TD	16		/* Read-write data in TOC */
1862a6b7db3Sskrll #define	XMC_SV64   17		/* Read-only 64 bit supervisor call */
1872a6b7db3Sskrll #define	XMC_SV3264 18		/* Read-only 32 or 64 bit supervisor call */
1885ba6b03cSchristos /*                19   ??? */
1895ba6b03cSchristos #define XMC_TL     20          /* Read-write initialized TLS data */
190*f22f0ef4Schristos #define XMC_UL     21          /* Read-write uninitialized TLS data */
1915ba6b03cSchristos #define XMC_TE     22          /* Same as XMC_TC but mapped after it */
1922a6b7db3Sskrll 
193*f22f0ef4Schristos /* x_ftype values:  */
194*f22f0ef4Schristos #define XFT_FN 0    /* Specifies the source-file name */
195*f22f0ef4Schristos #define XFT_CT 1    /* Specifies the compiler time stamp */
196*f22f0ef4Schristos #define XFT_CV 2    /* Specifies the compiler version number */
197*f22f0ef4Schristos #define XFT_CD 128  /*Specifies compiler-defined information */
198*f22f0ef4Schristos 
1992a6b7db3Sskrll /* The ldhdr structure.  This appears at the start of the .loader
2002a6b7db3Sskrll    section.  */
2012a6b7db3Sskrll 
2022a6b7db3Sskrll struct internal_ldhdr
2032a6b7db3Sskrll {
2042a6b7db3Sskrll   /* The version number:
2052a6b7db3Sskrll      1 : 32 bit
2062a6b7db3Sskrll      2 : 64 bit */
2072a6b7db3Sskrll   unsigned long l_version;
2082a6b7db3Sskrll 
2092a6b7db3Sskrll   /* The number of symbol table entries.  */
2102a6b7db3Sskrll   bfd_size_type l_nsyms;
2112a6b7db3Sskrll 
2122a6b7db3Sskrll   /* The number of relocation table entries.  */
2132a6b7db3Sskrll   bfd_size_type l_nreloc;
2142a6b7db3Sskrll 
2152a6b7db3Sskrll   /* The length of the import file string table.  */
2162a6b7db3Sskrll   bfd_size_type l_istlen;
2172a6b7db3Sskrll 
2182a6b7db3Sskrll   /* The number of import files.  */
2192a6b7db3Sskrll   bfd_size_type l_nimpid;
2202a6b7db3Sskrll 
2212a6b7db3Sskrll   /* The offset from the start of the .loader section to the first
2222a6b7db3Sskrll      entry in the import file table.  */
2232a6b7db3Sskrll   bfd_size_type l_impoff;
2242a6b7db3Sskrll 
2252a6b7db3Sskrll   /* The length of the string table.  */
2262a6b7db3Sskrll   bfd_size_type l_stlen;
2272a6b7db3Sskrll 
2282a6b7db3Sskrll   /* The offset from the start of the .loader section to the first
2292a6b7db3Sskrll      entry in the string table.  */
2302a6b7db3Sskrll   bfd_size_type l_stoff;
2312a6b7db3Sskrll 
2322a6b7db3Sskrll   /* The offset to start of the symbol table, only in XCOFF64 */
2332a6b7db3Sskrll   bfd_vma l_symoff;
2342a6b7db3Sskrll 
2352a6b7db3Sskrll   /* The offset to the start of the relocation table, only in XCOFF64 */
2362a6b7db3Sskrll   bfd_vma l_rldoff;
2372a6b7db3Sskrll };
2382a6b7db3Sskrll 
2392a6b7db3Sskrll /* The ldsym structure.  This is used to represent a symbol in the
2402a6b7db3Sskrll    .loader section.  */
2412a6b7db3Sskrll 
2422a6b7db3Sskrll struct internal_ldsym
2432a6b7db3Sskrll {
2442a6b7db3Sskrll   union
2452a6b7db3Sskrll   {
2462a6b7db3Sskrll     /* The symbol name if <= SYMNMLEN characters.  */
2472a6b7db3Sskrll     char _l_name[SYMNMLEN];
2482a6b7db3Sskrll     struct
2492a6b7db3Sskrll     {
2502a6b7db3Sskrll       /* Zero if the symbol name is more than SYMNMLEN characters.  */
2512a6b7db3Sskrll 	long _l_zeroes;
2522a6b7db3Sskrll 
2532a6b7db3Sskrll       /* The offset in the string table if the symbol name is more
2542a6b7db3Sskrll 	 than SYMNMLEN characters.  */
2552a6b7db3Sskrll       long _l_offset;
2562a6b7db3Sskrll     }
2572a6b7db3Sskrll     _l_l;
2582a6b7db3Sskrll   }
2592a6b7db3Sskrll   _l;
2602a6b7db3Sskrll 
2612a6b7db3Sskrll   /* The symbol value.  */
2622a6b7db3Sskrll   bfd_vma l_value;
2632a6b7db3Sskrll 
2642a6b7db3Sskrll   /* The symbol section number.  */
2652a6b7db3Sskrll   short l_scnum;
2662a6b7db3Sskrll 
2672a6b7db3Sskrll   /* The symbol type and flags.  */
2682a6b7db3Sskrll   char l_smtype;
2692a6b7db3Sskrll 
2702a6b7db3Sskrll   /* The symbol storage class.  */
2712a6b7db3Sskrll   char l_smclas;
2722a6b7db3Sskrll 
2732a6b7db3Sskrll   /* The import file ID.  */
2742a6b7db3Sskrll   bfd_size_type l_ifile;
2752a6b7db3Sskrll 
2762a6b7db3Sskrll   /* Offset to the parameter type check string.  */
2772a6b7db3Sskrll   bfd_size_type l_parm;
2782a6b7db3Sskrll };
2792a6b7db3Sskrll 
2802a6b7db3Sskrll /* These flags are for the l_smtype field (the lower three bits are an
2812a6b7db3Sskrll    XTY_* value).  */
2822a6b7db3Sskrll 
2832a6b7db3Sskrll /* Imported symbol.  */
2842a6b7db3Sskrll #define L_IMPORT (0x40)
2852a6b7db3Sskrll /* Entry point.  */
2862a6b7db3Sskrll #define L_ENTRY (0x20)
2872a6b7db3Sskrll /* Exported symbol.  */
2882a6b7db3Sskrll #define L_EXPORT (0x10)
289b075ecf2Schristos /* Weak symbol.  */
290b075ecf2Schristos #define L_WEAK (0x08)
2912a6b7db3Sskrll 
2922a6b7db3Sskrll /* The ldrel structure.  This is used to represent a reloc in the
2932a6b7db3Sskrll    .loader section.  */
2942a6b7db3Sskrll 
2952a6b7db3Sskrll struct internal_ldrel
2962a6b7db3Sskrll {
2972a6b7db3Sskrll   /* The reloc address.  */
2982a6b7db3Sskrll   bfd_vma l_vaddr;
2992a6b7db3Sskrll 
3002a6b7db3Sskrll   /* The symbol table index in the .loader section symbol table.  */
3012a6b7db3Sskrll   bfd_size_type l_symndx;
3022a6b7db3Sskrll 
3032a6b7db3Sskrll   /* The relocation type and size.  */
3042a6b7db3Sskrll   short l_rtype;
3052a6b7db3Sskrll 
3062a6b7db3Sskrll   /* The section number this relocation applies to.  */
3072a6b7db3Sskrll   short l_rsecnm;
3082a6b7db3Sskrll };
3092a6b7db3Sskrll 
3102a6b7db3Sskrll /* An entry in the XCOFF linker hash table.  */
3112a6b7db3Sskrll struct xcoff_link_hash_entry
3122a6b7db3Sskrll {
3132a6b7db3Sskrll   struct bfd_link_hash_entry root;
3142a6b7db3Sskrll 
3152a6b7db3Sskrll   /* Symbol index in output file.  Set to -1 initially.  Set to -2 if
3162a6b7db3Sskrll      there is a reloc against this symbol.  */
3172a6b7db3Sskrll   long indx;
3182a6b7db3Sskrll 
3192a6b7db3Sskrll   /* If we have created a TOC entry for this symbol, this is the .tc
3202a6b7db3Sskrll      section which holds it.  */
3212a6b7db3Sskrll   asection *toc_section;
3222a6b7db3Sskrll 
3232a6b7db3Sskrll   union
3242a6b7db3Sskrll   {
3252a6b7db3Sskrll     /* If we have created a TOC entry (the XCOFF_SET_TOC flag is
3262a6b7db3Sskrll        set), this is the offset in toc_section.  */
3272a6b7db3Sskrll     bfd_vma toc_offset;
3282a6b7db3Sskrll 
3292a6b7db3Sskrll     /* If the TOC entry comes from an input file, this is set to the
3302a6b7db3Sskrll        symbol index of the C_HIDEXT XMC_TC or XMC_TD symbol.  */
3312a6b7db3Sskrll     long toc_indx;
3322a6b7db3Sskrll   }
3332a6b7db3Sskrll   u;
3342a6b7db3Sskrll 
3352a6b7db3Sskrll   /* If this symbol is a function entry point which is called, this
3362a6b7db3Sskrll      field holds a pointer to the function descriptor.  If this symbol
3372a6b7db3Sskrll      is a function descriptor, this field holds a pointer to the
3382a6b7db3Sskrll      function entry point.  */
3392a6b7db3Sskrll   struct xcoff_link_hash_entry *descriptor;
3402a6b7db3Sskrll 
3412a6b7db3Sskrll   /* The .loader symbol table entry, if there is one.  */
3422a6b7db3Sskrll   struct internal_ldsym *ldsym;
3432a6b7db3Sskrll 
3442a6b7db3Sskrll   /* If XCOFF_BUILT_LDSYM is set, this is the .loader symbol table
3452a6b7db3Sskrll      index.  If XCOFF_BUILD_LDSYM is clear, and XCOFF_IMPORT is set,
3462a6b7db3Sskrll      this is the l_ifile value.  */
3472a6b7db3Sskrll   long ldindx;
3482a6b7db3Sskrll 
3492a6b7db3Sskrll   /* Some linker flags.  */
3502a6b7db3Sskrll   unsigned long flags;
3512a6b7db3Sskrll 
352*f22f0ef4Schristos   /* Symbol visibility, using the same define than n_type.  */
353*f22f0ef4Schristos   unsigned short visibility;
354*f22f0ef4Schristos 
3552a6b7db3Sskrll   /* The storage mapping class.  */
3562a6b7db3Sskrll   unsigned char smclas;
3572a6b7db3Sskrll };
3582a6b7db3Sskrll 
3592a6b7db3Sskrll /*  Flags for xcoff_link_hash_entry.  */
3602a6b7db3Sskrll 
3612a6b7db3Sskrll /* Symbol is referenced by a regular object. */
3622a6b7db3Sskrll #define XCOFF_REF_REGULAR      0x00000001
3632a6b7db3Sskrll /* Symbol is defined by a regular object. */
3642a6b7db3Sskrll #define XCOFF_DEF_REGULAR      0x00000002
3652a6b7db3Sskrll /* Symbol is defined by a dynamic object. */
3662a6b7db3Sskrll #define XCOFF_DEF_DYNAMIC      0x00000004
3672a6b7db3Sskrll /* Symbol is used in a reloc being copied into the .loader section.  */
3682a6b7db3Sskrll #define XCOFF_LDREL            0x00000008
3692a6b7db3Sskrll /* Symbol is the entry point.  */
3702a6b7db3Sskrll #define XCOFF_ENTRY            0x00000010
371b075ecf2Schristos /* Symbol is for a function and is the target of a relocation.
372b075ecf2Schristos    The relocation may or may not be a branch-type relocation.  */
3732a6b7db3Sskrll #define XCOFF_CALLED           0x00000020
3742a6b7db3Sskrll /* Symbol needs the TOC entry filled in.  */
3752a6b7db3Sskrll #define XCOFF_SET_TOC          0x00000040
376b075ecf2Schristos /* Symbol is implicitly or explicitly imported.  */
3772a6b7db3Sskrll #define XCOFF_IMPORT           0x00000080
3782a6b7db3Sskrll /* Symbol is explicitly exported.  */
3792a6b7db3Sskrll #define XCOFF_EXPORT           0x00000100
3802a6b7db3Sskrll /* Symbol has been processed by xcoff_build_ldsyms.  */
3812a6b7db3Sskrll #define XCOFF_BUILT_LDSYM      0x00000200
3822a6b7db3Sskrll /* Symbol is mentioned by a section which was not garbage collected. */
3832a6b7db3Sskrll #define XCOFF_MARK             0x00000400
3842a6b7db3Sskrll /* Symbol size is recorded in size_list list from hash table.  */
3852a6b7db3Sskrll #define XCOFF_HAS_SIZE         0x00000800
3862a6b7db3Sskrll /* Symbol is a function descriptor.  */
3872a6b7db3Sskrll #define XCOFF_DESCRIPTOR       0x00001000
3882a6b7db3Sskrll /* Multiple definitions have been for the symbol. */
3892a6b7db3Sskrll #define XCOFF_MULTIPLY_DEFINED 0x00002000
3902a6b7db3Sskrll /* Symbol is the __rtinit symbol.  */
3912a6b7db3Sskrll #define XCOFF_RTINIT           0x00004000
3922a6b7db3Sskrll /* Symbol is an imported 32 bit syscall.  */
3932a6b7db3Sskrll #define XCOFF_SYSCALL32        0x00008000
3942a6b7db3Sskrll /* Symbol is an imported 64 bit syscall.  */
3952a6b7db3Sskrll #define XCOFF_SYSCALL64        0x00010000
396b075ecf2Schristos /* Symbol was not explicitly defined by the time it was marked.  */
397b075ecf2Schristos #define XCOFF_WAS_UNDEFINED    0x00020000
398b075ecf2Schristos /* We have assigned an output XCOFF entry to this symbol.  */
399b075ecf2Schristos #define XCOFF_ALLOCATED	       0x00040000
4002a6b7db3Sskrll 
4012a6b7db3Sskrll /* The XCOFF linker hash table.  */
4022a6b7db3Sskrll 
4032a6b7db3Sskrll #define XCOFF_NUMBER_OF_SPECIAL_SECTIONS 6
4042a6b7db3Sskrll #define XCOFF_SPECIAL_SECTION_TEXT       0
4052a6b7db3Sskrll #define XCOFF_SPECIAL_SECTION_ETEXT      1
4062a6b7db3Sskrll #define XCOFF_SPECIAL_SECTION_DATA       2
4072a6b7db3Sskrll #define XCOFF_SPECIAL_SECTION_EDATA      3
4082a6b7db3Sskrll #define XCOFF_SPECIAL_SECTION_END        4
4092a6b7db3Sskrll #define XCOFF_SPECIAL_SECTION_END2       5
4102a6b7db3Sskrll 
411b075ecf2Schristos /* These flags indicate which of -bexpall and -bexpfull are in effect.  */
412b075ecf2Schristos #define XCOFF_EXPALL 1
413b075ecf2Schristos #define XCOFF_EXPFULL 2
4142a6b7db3Sskrll 
4152a6b7db3Sskrll /* This structure is used to pass information through
4162a6b7db3Sskrll    xcoff_link_hash_traverse.  */
4172a6b7db3Sskrll 
4182a6b7db3Sskrll struct xcoff_loader_info
4192a6b7db3Sskrll {
4202a6b7db3Sskrll   /* Set if a problem occurred.  */
421*f22f0ef4Schristos   bool failed;
4222a6b7db3Sskrll 
4232a6b7db3Sskrll   /* Output BFD.  */
4242a6b7db3Sskrll   bfd *output_bfd;
4252a6b7db3Sskrll 
4262a6b7db3Sskrll   /* Link information structure.  */
4272a6b7db3Sskrll   struct bfd_link_info *info;
4282a6b7db3Sskrll 
429b075ecf2Schristos   /* A mask of XCOFF_EXPALL and XCOFF_EXPFULL flags.  */
430b075ecf2Schristos   unsigned int auto_export_flags;
4312a6b7db3Sskrll 
4322a6b7db3Sskrll   /* Number of ldsym structures.  */
4332a6b7db3Sskrll   size_t ldsym_count;
4342a6b7db3Sskrll 
435*f22f0ef4Schristos   /* A count of non TOC relative relocs which will need to be
436*f22f0ef4Schristos      allocated in the .loader section.  */
437*f22f0ef4Schristos   size_t ldrel_count;
438*f22f0ef4Schristos 
4392a6b7db3Sskrll   /* Size of string table.  */
4402a6b7db3Sskrll   size_t string_size;
4412a6b7db3Sskrll 
4422a6b7db3Sskrll   /* String table.  */
4432a6b7db3Sskrll   char *strings;
4442a6b7db3Sskrll 
4452a6b7db3Sskrll   /* Allocated size of string table.  */
4462a6b7db3Sskrll   size_t string_alc;
447*f22f0ef4Schristos 
448*f22f0ef4Schristos   /* The libpath being used.  */
449*f22f0ef4Schristos   const char *libpath;
4502a6b7db3Sskrll };
4512a6b7db3Sskrll 
4522a6b7db3Sskrll /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
4532a6b7db3Sskrll    from smaller values.  Start with zero, widen, *then* decrement.  */
4542a6b7db3Sskrll #define MINUS_ONE       (((bfd_vma) 0) - 1)
4552a6b7db3Sskrll 
4562a6b7db3Sskrll /* __rtinit, from /usr/include/rtinit.h.  */
4572a6b7db3Sskrll struct __rtinit
4582a6b7db3Sskrll {
4592a6b7db3Sskrll   /* Pointer to runtime linker.
4602a6b7db3Sskrll      XXX: Is the parameter really void?  */
4612a6b7db3Sskrll   int	(*rtl) (void);
4622a6b7db3Sskrll 
4632a6b7db3Sskrll   /* Offset to array of init functions, 0 if none. */
4642a6b7db3Sskrll   int	init_offset;
4652a6b7db3Sskrll 
4662a6b7db3Sskrll   /* Offset to array of fini functions, 0 if none. */
4672a6b7db3Sskrll   int	fini_offset;
4682a6b7db3Sskrll 
4692a6b7db3Sskrll   /* Size of __RTINIT_DESCRIPTOR. This value should be used instead of
4702a6b7db3Sskrll      sizeof(__RTINIT_DESCRIPTOR). */
4712a6b7db3Sskrll   int	__rtinit_descriptor_size;
4722a6b7db3Sskrll };
4732a6b7db3Sskrll 
4742a6b7db3Sskrll #define RTINIT_DESCRIPTOR_SIZE (12)
4752a6b7db3Sskrll 
4762a6b7db3Sskrll struct __rtinit_descriptor
4772a6b7db3Sskrll {
4782a6b7db3Sskrll   /* Init/fini function. */
4792a6b7db3Sskrll   int	f;
4802a6b7db3Sskrll 
4812a6b7db3Sskrll   /* Offset, relative to the start of the __rtinit symbol, to name of the
4822a6b7db3Sskrll      function. */
4832a6b7db3Sskrll 
4842a6b7db3Sskrll   int	name_offset;
4852a6b7db3Sskrll 
4862a6b7db3Sskrll   /* Flags */
4872a6b7db3Sskrll   unsigned char	flags;
4882a6b7db3Sskrll };
4892a6b7db3Sskrll 
4902a6b7db3Sskrll /* Archive */
4912a6b7db3Sskrll 
4922a6b7db3Sskrll #define XCOFFARMAG    "<aiaff>\012"
4932a6b7db3Sskrll #define XCOFFARMAGBIG "<bigaf>\012"
4942a6b7db3Sskrll #define SXCOFFARMAG   8
4952a6b7db3Sskrll 
4962a6b7db3Sskrll /* The size of the ascii archive elements */
4972a6b7db3Sskrll #define XCOFFARMAG_ELEMENT_SIZE 12
4982a6b7db3Sskrll #define XCOFFARMAGBIG_ELEMENT_SIZE 20
4992a6b7db3Sskrll 
5002a6b7db3Sskrll /* This terminates an XCOFF archive member name.  */
5012a6b7db3Sskrll 
5022a6b7db3Sskrll #define XCOFFARFMAG "`\012"
5032a6b7db3Sskrll #define SXCOFFARFMAG 2
5042a6b7db3Sskrll 
5052a6b7db3Sskrll /* XCOFF archives start with this (printable) structure.  */
5062a6b7db3Sskrll 
5072a6b7db3Sskrll struct xcoff_ar_file_hdr
5082a6b7db3Sskrll {
5092a6b7db3Sskrll   /* Magic string.  */
5102a6b7db3Sskrll   char magic[SXCOFFARMAG];
5112a6b7db3Sskrll 
5122a6b7db3Sskrll   /* Offset of the member table (decimal ASCII string).  */
5132a6b7db3Sskrll   char memoff[XCOFFARMAG_ELEMENT_SIZE];
5142a6b7db3Sskrll 
5152a6b7db3Sskrll   /* Offset of the global symbol table (decimal ASCII string).  */
5162a6b7db3Sskrll   char symoff[XCOFFARMAG_ELEMENT_SIZE];
5172a6b7db3Sskrll 
5182a6b7db3Sskrll   /* Offset of the first member in the archive (decimal ASCII string).  */
5192a6b7db3Sskrll   char firstmemoff[XCOFFARMAG_ELEMENT_SIZE];
5202a6b7db3Sskrll 
5212a6b7db3Sskrll   /* Offset of the last member in the archive (decimal ASCII string).  */
5222a6b7db3Sskrll   char lastmemoff[XCOFFARMAG_ELEMENT_SIZE];
5232a6b7db3Sskrll 
5242a6b7db3Sskrll   /* Offset of the first member on the free list (decimal ASCII
5252a6b7db3Sskrll      string).  */
5262a6b7db3Sskrll   char freeoff[XCOFFARMAG_ELEMENT_SIZE];
5272a6b7db3Sskrll };
5282a6b7db3Sskrll 
5292a6b7db3Sskrll #define SIZEOF_AR_FILE_HDR (SXCOFFARMAG + 5 * XCOFFARMAG_ELEMENT_SIZE)
5302a6b7db3Sskrll 
5312a6b7db3Sskrll /* This is the equivalent data structure for the big archive format.  */
5322a6b7db3Sskrll 
5332a6b7db3Sskrll struct xcoff_ar_file_hdr_big
5342a6b7db3Sskrll {
5352a6b7db3Sskrll   /* Magic string.  */
5362a6b7db3Sskrll   char magic[SXCOFFARMAG];
5372a6b7db3Sskrll 
5382a6b7db3Sskrll   /* Offset of the member table (decimal ASCII string).  */
5392a6b7db3Sskrll   char memoff[XCOFFARMAGBIG_ELEMENT_SIZE];
5402a6b7db3Sskrll 
5412a6b7db3Sskrll   /* Offset of the global symbol table for 32-bit objects (decimal ASCII
5422a6b7db3Sskrll      string).  */
5432a6b7db3Sskrll   char symoff[XCOFFARMAGBIG_ELEMENT_SIZE];
5442a6b7db3Sskrll 
5452a6b7db3Sskrll   /* Offset of the global symbol table for 64-bit objects (decimal ASCII
5462a6b7db3Sskrll      string).  */
5472a6b7db3Sskrll   char symoff64[XCOFFARMAGBIG_ELEMENT_SIZE];
5482a6b7db3Sskrll 
5492a6b7db3Sskrll   /* Offset of the first member in the archive (decimal ASCII string).  */
5502a6b7db3Sskrll   char firstmemoff[XCOFFARMAGBIG_ELEMENT_SIZE];
5512a6b7db3Sskrll 
5522a6b7db3Sskrll   /* Offset of the last member in the archive (decimal ASCII string).  */
5532a6b7db3Sskrll   char lastmemoff[XCOFFARMAGBIG_ELEMENT_SIZE];
5542a6b7db3Sskrll 
5552a6b7db3Sskrll   /* Offset of the first member on the free list (decimal ASCII
5562a6b7db3Sskrll      string).  */
5572a6b7db3Sskrll   char freeoff[XCOFFARMAGBIG_ELEMENT_SIZE];
5582a6b7db3Sskrll };
5592a6b7db3Sskrll 
5602a6b7db3Sskrll #define SIZEOF_AR_FILE_HDR_BIG (SXCOFFARMAG + 6 * XCOFFARMAGBIG_ELEMENT_SIZE)
5612a6b7db3Sskrll 
5622a6b7db3Sskrll /* Each XCOFF archive member starts with this (printable) structure.  */
5632a6b7db3Sskrll 
5642a6b7db3Sskrll struct xcoff_ar_hdr
5652a6b7db3Sskrll {
5662a6b7db3Sskrll   /* File size not including the header (decimal ASCII string).  */
5672a6b7db3Sskrll   char size[XCOFFARMAG_ELEMENT_SIZE];
5682a6b7db3Sskrll 
5692a6b7db3Sskrll   /* File offset of next archive member (decimal ASCII string).  */
5702a6b7db3Sskrll   char nextoff[XCOFFARMAG_ELEMENT_SIZE];
5712a6b7db3Sskrll 
5722a6b7db3Sskrll   /* File offset of previous archive member (decimal ASCII string).  */
5732a6b7db3Sskrll   char prevoff[XCOFFARMAG_ELEMENT_SIZE];
5742a6b7db3Sskrll 
5752a6b7db3Sskrll   /* File mtime (decimal ASCII string).  */
5762a6b7db3Sskrll   char date[12];
5772a6b7db3Sskrll 
5782a6b7db3Sskrll   /* File UID (decimal ASCII string).  */
5792a6b7db3Sskrll   char uid[12];
5802a6b7db3Sskrll 
5812a6b7db3Sskrll   /* File GID (decimal ASCII string).  */
5822a6b7db3Sskrll   char gid[12];
5832a6b7db3Sskrll 
5842a6b7db3Sskrll   /* File mode (octal ASCII string).  */
5852a6b7db3Sskrll   char mode[12];
5862a6b7db3Sskrll 
5872a6b7db3Sskrll   /* Length of file name (decimal ASCII string).  */
5882a6b7db3Sskrll   char namlen[4];
5892a6b7db3Sskrll 
5902a6b7db3Sskrll   /* This structure is followed by the file name.  The length of the
5912a6b7db3Sskrll      name is given in the namlen field.  If the length of the name is
5922a6b7db3Sskrll      odd, the name is followed by a null byte.  The name and optional
5932a6b7db3Sskrll      null byte are followed by XCOFFARFMAG, which is not included in
5942a6b7db3Sskrll      namlen.  The contents of the archive member follow; the number of
5952a6b7db3Sskrll      bytes is given in the size field.  */
5962a6b7db3Sskrll };
5972a6b7db3Sskrll 
5982a6b7db3Sskrll #define SIZEOF_AR_HDR (3 * XCOFFARMAG_ELEMENT_SIZE + 4 * 12 + 4)
5992a6b7db3Sskrll 
6002a6b7db3Sskrll /* The equivalent for the big archive format.  */
6012a6b7db3Sskrll 
6022a6b7db3Sskrll struct xcoff_ar_hdr_big
6032a6b7db3Sskrll {
6042a6b7db3Sskrll   /* File size not including the header (decimal ASCII string).  */
6052a6b7db3Sskrll   char size[XCOFFARMAGBIG_ELEMENT_SIZE];
6062a6b7db3Sskrll 
6072a6b7db3Sskrll   /* File offset of next archive member (decimal ASCII string).  */
6082a6b7db3Sskrll   char nextoff[XCOFFARMAGBIG_ELEMENT_SIZE];
6092a6b7db3Sskrll 
6102a6b7db3Sskrll   /* File offset of previous archive member (decimal ASCII string).  */
6112a6b7db3Sskrll   char prevoff[XCOFFARMAGBIG_ELEMENT_SIZE];
6122a6b7db3Sskrll 
6132a6b7db3Sskrll   /* File mtime (decimal ASCII string).  */
6142a6b7db3Sskrll   char date[12];
6152a6b7db3Sskrll 
6162a6b7db3Sskrll   /* File UID (decimal ASCII string).  */
6172a6b7db3Sskrll   char uid[12];
6182a6b7db3Sskrll 
6192a6b7db3Sskrll   /* File GID (decimal ASCII string).  */
6202a6b7db3Sskrll   char gid[12];
6212a6b7db3Sskrll 
6222a6b7db3Sskrll   /* File mode (octal ASCII string).  */
6232a6b7db3Sskrll   char mode[12];
6242a6b7db3Sskrll 
6252a6b7db3Sskrll   /* Length of file name (decimal ASCII string).  */
6262a6b7db3Sskrll   char namlen[4];
6272a6b7db3Sskrll 
6282a6b7db3Sskrll   /* This structure is followed by the file name.  The length of the
6292a6b7db3Sskrll      name is given in the namlen field.  If the length of the name is
6302a6b7db3Sskrll      odd, the name is followed by a null byte.  The name and optional
6312a6b7db3Sskrll      null byte are followed by XCOFFARFMAG, which is not included in
6322a6b7db3Sskrll      namlen.  The contents of the archive member follow; the number of
6332a6b7db3Sskrll      bytes is given in the size field.  */
6342a6b7db3Sskrll };
6352a6b7db3Sskrll 
6362a6b7db3Sskrll #define SIZEOF_AR_HDR_BIG (3 * XCOFFARMAGBIG_ELEMENT_SIZE + 4 * 12 + 4)
6372a6b7db3Sskrll 
6382a6b7db3Sskrll /* We often have to distinguish between the old and big file format.
6392a6b7db3Sskrll    Make it a bit cleaner.  We can use `xcoff_ardata' here because the
6402a6b7db3Sskrll    `hdr' member has the same size and position in both formats.
6412a6b7db3Sskrll    <bigaf> is the default format, return TRUE even when xcoff_ardata is
6422a6b7db3Sskrll    NULL. */
6432a6b7db3Sskrll #ifndef SMALL_ARCHIVE
6442a6b7db3Sskrll /* Creates big archives by default */
6452a6b7db3Sskrll #define xcoff_big_format_p(abfd) \
6462a6b7db3Sskrll   ((NULL != bfd_ardata (abfd) && NULL == xcoff_ardata (abfd)) || \
6472a6b7db3Sskrll    ((NULL != bfd_ardata (abfd)) && \
6482a6b7db3Sskrll     (NULL != xcoff_ardata (abfd)) && \
6492a6b7db3Sskrll     (xcoff_ardata (abfd)->magic[1] == 'b')))
6502a6b7db3Sskrll #else
6512a6b7db3Sskrll /* Creates small archives by default. */
6522a6b7db3Sskrll #define xcoff_big_format_p(abfd) \
6532a6b7db3Sskrll   (((NULL != bfd_ardata (abfd)) && \
6542a6b7db3Sskrll     (NULL != xcoff_ardata (abfd)) && \
6552a6b7db3Sskrll     (xcoff_ardata (abfd)->magic[1] == 'b')))
6562a6b7db3Sskrll #endif
6572a6b7db3Sskrll 
6582a6b7db3Sskrll /* We store a copy of the xcoff_ar_file_hdr in the tdata field of the
6592a6b7db3Sskrll    artdata structure.  Similar for the big archive.  */
6602a6b7db3Sskrll #define xcoff_ardata(abfd) \
6612a6b7db3Sskrll   ((struct xcoff_ar_file_hdr *) bfd_ardata (abfd)->tdata)
6622a6b7db3Sskrll #define xcoff_ardata_big(abfd) \
6632a6b7db3Sskrll   ((struct xcoff_ar_file_hdr_big *) bfd_ardata (abfd)->tdata)
6642a6b7db3Sskrll 
6652a6b7db3Sskrll /* We store a copy of the xcoff_ar_hdr in the arelt_data field of an
6662a6b7db3Sskrll    archive element.  Similar for the big archive.  */
6672a6b7db3Sskrll #define arch_eltdata(bfd) ((struct areltdata *) ((bfd)->arelt_data))
6682a6b7db3Sskrll #define arch_xhdr(bfd) \
6692a6b7db3Sskrll   ((struct xcoff_ar_hdr *) arch_eltdata (bfd)->arch_header)
6702a6b7db3Sskrll #define arch_xhdr_big(bfd) \
6712a6b7db3Sskrll   ((struct xcoff_ar_hdr_big *) arch_eltdata (bfd)->arch_header)
6722a6b7db3Sskrll 
673b075ecf2Schristos /* True if symbols of class CLASS are external.  */
674b075ecf2Schristos #define EXTERN_SYM_P(CLASS) \
675b075ecf2Schristos   ((CLASS) == C_EXT || (CLASS) == C_AIX_WEAKEXT)
676b075ecf2Schristos 
6772a6b7db3Sskrll #endif /* _INTERNAL_XCOFF_H */
678