xref: /openbsd-src/gnu/usr.bin/binutils/bfd/libaout.h (revision 007c2a4539b8b8aaa95c5e73e77620090abe113b)
12159047fSniklas /* BFD back-end data structures for a.out (and similar) files.
2b55d4692Sfgsch    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3*007c2a45Smiod    2000, 2001, 2002, 2003
4b305b0f1Sespie    Free Software Foundation, Inc.
52159047fSniklas    Written by Cygnus Support.
62159047fSniklas 
72159047fSniklas    This file is part of BFD, the Binary File Descriptor library.
82159047fSniklas 
92159047fSniklas    This program is free software; you can redistribute it and/or modify
102159047fSniklas    it under the terms of the GNU General Public License as published by
112159047fSniklas    the Free Software Foundation; either version 2 of the License, or
122159047fSniklas    (at your option) any later version.
132159047fSniklas 
142159047fSniklas    This program is distributed in the hope that it will be useful,
152159047fSniklas    but WITHOUT ANY WARRANTY; without even the implied warranty of
162159047fSniklas    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
172159047fSniklas    GNU General Public License for more details.
182159047fSniklas 
192159047fSniklas    You should have received a copy of the GNU General Public License
202159047fSniklas    along with this program; if not, write to the Free Software
212159047fSniklas    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
222159047fSniklas 
232159047fSniklas #ifndef LIBAOUT_H
242159047fSniklas #define LIBAOUT_H
252159047fSniklas 
262159047fSniklas /* We try to encapsulate the differences in the various a.out file
272159047fSniklas    variants in a few routines, and otherwise share large masses of code.
282159047fSniklas    This means we only have to fix bugs in one place, most of the time.  */
292159047fSniklas 
302159047fSniklas #include "bfdlink.h"
312159047fSniklas 
32*007c2a45Smiod /* Macros for accessing components in an aout header.  */
33c074d1c9Sdrahn 
34*007c2a45Smiod #define H_PUT_64 bfd_h_put_64
35*007c2a45Smiod #define H_PUT_32 bfd_h_put_32
36*007c2a45Smiod #define H_PUT_16 bfd_h_put_16
37c074d1c9Sdrahn #define H_PUT_8 bfd_h_put_8
38*007c2a45Smiod #define H_PUT_S64 bfd_h_put_signed_64
39*007c2a45Smiod #define H_PUT_S32 bfd_h_put_signed_32
40*007c2a45Smiod #define H_PUT_S16 bfd_h_put_signed_16
41c074d1c9Sdrahn #define H_PUT_S8 bfd_h_put_signed_8
42*007c2a45Smiod #define H_GET_64 bfd_h_get_64
43*007c2a45Smiod #define H_GET_32 bfd_h_get_32
44*007c2a45Smiod #define H_GET_16 bfd_h_get_16
45c074d1c9Sdrahn #define H_GET_8 bfd_h_get_8
46*007c2a45Smiod #define H_GET_S64 bfd_h_get_signed_64
47*007c2a45Smiod #define H_GET_S32 bfd_h_get_signed_32
48*007c2a45Smiod #define H_GET_S16 bfd_h_get_signed_16
49c074d1c9Sdrahn #define H_GET_S8 bfd_h_get_signed_8
50c074d1c9Sdrahn 
512159047fSniklas /* Parameterize the a.out code based on whether it is being built
522159047fSniklas    for a 32-bit architecture or a 64-bit architecture.  */
53c074d1c9Sdrahn /* Do not "beautify" the CONCAT* macro args.  Traditional C will not
54c074d1c9Sdrahn    remove whitespace added here, and thus will fail to concatenate
55c074d1c9Sdrahn    the tokens.  */
562159047fSniklas #if ARCH_SIZE==64
57c074d1c9Sdrahn #define GET_WORD H_GET_64
58c074d1c9Sdrahn #define GET_SWORD H_GET_S64
59c074d1c9Sdrahn #define GET_MAGIC H_GET_32
60c074d1c9Sdrahn #define PUT_WORD H_PUT_64
61c074d1c9Sdrahn #define PUT_MAGIC H_PUT_32
622159047fSniklas #ifndef NAME
63c074d1c9Sdrahn #define NAME(x,y) CONCAT3 (x,_64_,y)
642159047fSniklas #endif
65c074d1c9Sdrahn #define JNAME(x) CONCAT2 (x,_64)
662159047fSniklas #define BYTES_IN_WORD 8
67c074d1c9Sdrahn #else
68c074d1c9Sdrahn #if ARCH_SIZE==16
69c074d1c9Sdrahn #define GET_WORD H_GET_16
70c074d1c9Sdrahn #define GET_SWORD H_GET_S16
71c074d1c9Sdrahn #define GET_MAGIC H_GET_16
72c074d1c9Sdrahn #define PUT_WORD H_PUT_16
73c074d1c9Sdrahn #define PUT_MAGIC H_PUT_16
742159047fSniklas #ifndef NAME
75c074d1c9Sdrahn #define NAME(x,y) CONCAT3 (x,_16_,y)
762159047fSniklas #endif
77c074d1c9Sdrahn #define JNAME(x) CONCAT2 (x,_16)
78c074d1c9Sdrahn #define BYTES_IN_WORD 2
79c074d1c9Sdrahn #else /* ARCH_SIZE == 32 */
80c074d1c9Sdrahn #define GET_WORD H_GET_32
81c074d1c9Sdrahn #define GET_SWORD H_GET_S32
82c074d1c9Sdrahn #define GET_MAGIC H_GET_32
83c074d1c9Sdrahn #define PUT_WORD H_PUT_32
84c074d1c9Sdrahn #define PUT_MAGIC H_PUT_32
85c074d1c9Sdrahn #ifndef NAME
86c074d1c9Sdrahn #define NAME(x,y) CONCAT3 (x,_32_,y)
87c074d1c9Sdrahn #endif
88c074d1c9Sdrahn #define JNAME(x) CONCAT2 (x,_32)
892159047fSniklas #define BYTES_IN_WORD 4
902159047fSniklas #endif /* ARCH_SIZE==32 */
91c074d1c9Sdrahn #endif /* ARCH_SIZE==64 */
922159047fSniklas 
932159047fSniklas /* Declare at file level, since used in parameter lists, which have
942159047fSniklas    weird scope.  */
952159047fSniklas struct external_exec;
962159047fSniklas struct external_nlist;
972159047fSniklas struct reloc_ext_external;
982159047fSniklas struct reloc_std_external;
992159047fSniklas 
1002159047fSniklas /* a.out backend linker hash table entries.  */
1012159047fSniklas 
1022159047fSniklas struct aout_link_hash_entry
1032159047fSniklas {
1042159047fSniklas   struct bfd_link_hash_entry root;
1052159047fSniklas   /* Whether this symbol has been written out.  */
106c074d1c9Sdrahn   bfd_boolean written;
1072159047fSniklas   /* Symbol index in output file.  */
1082159047fSniklas   int indx;
1092159047fSniklas };
1102159047fSniklas 
1112159047fSniklas /* a.out backend linker hash table.  */
1122159047fSniklas 
1132159047fSniklas struct aout_link_hash_table
1142159047fSniklas {
1152159047fSniklas   struct bfd_link_hash_table root;
1162159047fSniklas };
1172159047fSniklas 
1182159047fSniklas /* Look up an entry in an a.out link hash table.  */
1192159047fSniklas 
1202159047fSniklas #define aout_link_hash_lookup(table, string, create, copy, follow) \
1212159047fSniklas   ((struct aout_link_hash_entry *) \
1222159047fSniklas    bfd_link_hash_lookup (&(table)->root, (string), (create), (copy), (follow)))
1232159047fSniklas 
1242159047fSniklas /* Traverse an a.out link hash table.  */
1252159047fSniklas 
1262159047fSniklas #define aout_link_hash_traverse(table, func, info)			\
1272159047fSniklas   (bfd_link_hash_traverse						\
1282159047fSniklas    (&(table)->root,							\
129c074d1c9Sdrahn     (bfd_boolean (*) PARAMS ((struct bfd_link_hash_entry *, PTR))) (func), \
1302159047fSniklas     (info)))
1312159047fSniklas 
1322159047fSniklas /* Get the a.out link hash table from the info structure.  This is
1332159047fSniklas    just a cast.  */
1342159047fSniklas 
1352159047fSniklas #define aout_hash_table(p) ((struct aout_link_hash_table *) ((p)->hash))
1362159047fSniklas 
1372159047fSniklas /* Back-end information for various a.out targets.  */
1382159047fSniklas struct aout_backend_data
1392159047fSniklas {
1402159047fSniklas   /* Are ZMAGIC files mapped contiguously?  If so, the text section may
1412159047fSniklas      need more padding, if the segment size (granularity for memory access
1422159047fSniklas      control) is larger than the page size.  */
1432159047fSniklas   unsigned char zmagic_mapped_contiguous;
1442159047fSniklas   /* If this flag is set, ZMAGIC/NMAGIC file headers get mapped in with the
1452159047fSniklas      text section, which starts immediately after the file header.
1462159047fSniklas      If not, the text section starts on the next page.  */
1472159047fSniklas   unsigned char text_includes_header;
1482159047fSniklas 
149b305b0f1Sespie   /* If this flag is set, then if the entry address is not in the
150b305b0f1Sespie      first SEGMENT_SIZE bytes of the text section, it is taken to be
151b305b0f1Sespie      the address of the start of the text section.  This can be useful
152b305b0f1Sespie      for kernels.  */
153b305b0f1Sespie   unsigned char entry_is_text_address;
154b305b0f1Sespie 
1552159047fSniklas   /* The value to pass to N_SET_FLAGS.  */
1562159047fSniklas   unsigned char exec_hdr_flags;
1572159047fSniklas 
1582159047fSniklas   /* If the text section VMA isn't specified, and we need an absolute
1592159047fSniklas      address, use this as the default.  If we're producing a relocatable
1602159047fSniklas      file, zero is always used.  */
1612159047fSniklas   /* ?? Perhaps a callback would be a better choice?  Will this do anything
1622159047fSniklas      reasonable for a format that handles multiple CPUs with different
1632159047fSniklas      load addresses for each?  */
1642159047fSniklas   bfd_vma default_text_vma;
1652159047fSniklas 
1662159047fSniklas   /* Callback for setting the page and segment sizes, if they can't be
1672159047fSniklas      trivially determined from the architecture.  */
168c074d1c9Sdrahn   bfd_boolean (*set_sizes)
169c074d1c9Sdrahn     PARAMS ((bfd *));
1702159047fSniklas 
1712159047fSniklas   /* zmagic files only. For go32, the length of the exec header contributes
1722159047fSniklas      to the size of the text section in the file for alignment purposes but
1732159047fSniklas      does *not* get counted in the length of the text section. */
1742159047fSniklas   unsigned char exec_header_not_counted;
1752159047fSniklas 
1762159047fSniklas   /* Callback from the add symbols phase of the linker code to handle
1772159047fSniklas      a dynamic object.  */
178c074d1c9Sdrahn   bfd_boolean (*add_dynamic_symbols)
179c074d1c9Sdrahn     PARAMS ((bfd *, struct bfd_link_info *, struct external_nlist **,
1802159047fSniklas 	     bfd_size_type *, char **));
1812159047fSniklas 
1822159047fSniklas   /* Callback from the add symbols phase of the linker code to handle
1832159047fSniklas      adding a single symbol to the global linker hash table.  */
184c074d1c9Sdrahn   bfd_boolean (*add_one_symbol)
185c074d1c9Sdrahn     PARAMS ((struct bfd_link_info *, bfd *, const char *, flagword,
186c074d1c9Sdrahn 	     asection *, bfd_vma, const char *, bfd_boolean, bfd_boolean,
1872159047fSniklas 	     struct bfd_link_hash_entry **));
1882159047fSniklas 
1892159047fSniklas   /* Called to handle linking a dynamic object.  */
190c074d1c9Sdrahn   bfd_boolean (*link_dynamic_object)
191c074d1c9Sdrahn     PARAMS ((struct bfd_link_info *, bfd *));
1922159047fSniklas 
1932159047fSniklas   /* Called for each global symbol being written out by the linker.
1942159047fSniklas      This should write out the dynamic symbol information.  */
195c074d1c9Sdrahn   bfd_boolean (*write_dynamic_symbol)
196c074d1c9Sdrahn     PARAMS ((bfd *, struct bfd_link_info *, struct aout_link_hash_entry *));
1972159047fSniklas 
1982159047fSniklas   /* If this callback is not NULL, the linker calls it for each reloc.
1992159047fSniklas      RELOC is a pointer to the unswapped reloc.  If *SKIP is set to
200c074d1c9Sdrahn      TRUE, the reloc will be skipped.  *RELOCATION may be changed to
2012159047fSniklas      change the effects of the relocation.  */
202c074d1c9Sdrahn   bfd_boolean (*check_dynamic_reloc)
203c074d1c9Sdrahn     PARAMS ((struct bfd_link_info *info, bfd *input_bfd,
204c074d1c9Sdrahn 	     asection *input_section, struct aout_link_hash_entry *h,
205c074d1c9Sdrahn 	     PTR reloc, bfd_byte *contents, bfd_boolean *skip,
2062159047fSniklas 	     bfd_vma *relocation));
2072159047fSniklas 
2082159047fSniklas   /* Called at the end of a link to finish up any dynamic linking
2092159047fSniklas      information.  */
210c074d1c9Sdrahn   bfd_boolean (*finish_dynamic_link)
211c074d1c9Sdrahn     PARAMS ((bfd *, struct bfd_link_info *));
2122159047fSniklas };
2132159047fSniklas #define aout_backend_info(abfd) \
214c074d1c9Sdrahn 	((const struct aout_backend_data *)((abfd)->xvec->backend_data))
2152159047fSniklas 
2162159047fSniklas /* This is the layout in memory of a "struct exec" while we process it.
2172159047fSniklas    All 'lengths' are given as a number of bytes.
2182159047fSniklas    All 'alignments' are for relinkable files only;  an alignment of
2192159047fSniklas 	'n' indicates the corresponding segment must begin at an
2202159047fSniklas 	address that is a multiple of (2**n).  */
2212159047fSniklas 
2222159047fSniklas struct internal_exec
2232159047fSniklas {
2242159047fSniklas     long a_info;		/* Magic number and flags, packed */
2252159047fSniklas     bfd_vma a_text;		/* length of text, in bytes  */
2262159047fSniklas     bfd_vma a_data;		/* length of data, in bytes  */
2272159047fSniklas     bfd_vma a_bss;		/* length of uninitialized data area in mem */
2282159047fSniklas     bfd_vma a_syms;		/* length of symbol table data in file */
2292159047fSniklas     bfd_vma a_entry;		/* start address */
2302159047fSniklas     bfd_vma a_trsize;		/* length of text's relocation info, in bytes */
2312159047fSniklas     bfd_vma a_drsize;		/* length of data's relocation info, in bytes */
2322159047fSniklas     /* Added for i960 */
2332159047fSniklas     bfd_vma a_tload;		/* Text runtime load address */
2342159047fSniklas     bfd_vma a_dload;		/* Data runtime load address */
2352159047fSniklas     unsigned char a_talign;	/* Alignment of text segment */
2362159047fSniklas     unsigned char a_dalign;	/* Alignment of data segment */
2372159047fSniklas     unsigned char a_balign;	/* Alignment of bss segment */
2382159047fSniklas     char a_relaxable;           /* Enough info for linker relax */
2392159047fSniklas };
2402159047fSniklas 
2412159047fSniklas /* Magic number is written
2422159047fSniklas < MSB          >
2432159047fSniklas 3130292827262524232221201918171615141312111009080706050403020100
2442159047fSniklas < FLAGS        >< MACHINE TYPE ><  MAGIC NUMBER                >
2452159047fSniklas */
2462159047fSniklas /* Magic number for NetBSD is
2472159047fSniklas <MSB           >
2482159047fSniklas 3130292827262524232221201918171615141312111009080706050403020100
249c88b1d6cSniklas < FLAGS    >< MACHINE TYPE     ><  MAGIC NUMBER                >
2502159047fSniklas */
2512159047fSniklas 
2522159047fSniklas enum machine_type {
2532159047fSniklas   M_UNKNOWN = 0,
2542159047fSniklas   M_68010 = 1,
2552159047fSniklas   M_68020 = 2,
2562159047fSniklas   M_SPARC = 3,
257c074d1c9Sdrahn   /* Skip a bunch so we don't run into any of SUN's numbers.  */
258c074d1c9Sdrahn   /* Make these up for the ns32k.  */
2592159047fSniklas   M_NS32032 = (64),	/* ns32032 running ? */
2602159047fSniklas   M_NS32532 = (64 + 5),	/* ns32532 running mach */
2612159047fSniklas 
2622159047fSniklas   M_386 = 100,
2632159047fSniklas   M_29K = 101,          /* AMD 29000 */
2642159047fSniklas   M_386_DYNIX = 102,	/* Sequent running dynix */
2652159047fSniklas   M_ARM = 103,		/* Advanced Risc Machines ARM */
266b305b0f1Sespie   M_SPARCLET = 131,	/* SPARClet = M_SPARC + 128 */
2672159047fSniklas   M_386_NETBSD = 134,	/* NetBSD/i386 binary */
2682159047fSniklas   M_68K_NETBSD = 135,	/* NetBSD/m68k binary */
2692159047fSniklas   M_68K4K_NETBSD = 136,	/* NetBSD/m68k4k binary */
2702159047fSniklas   M_532_NETBSD = 137,	/* NetBSD/ns32k binary */
2712159047fSniklas   M_SPARC_NETBSD = 138,	/* NetBSD/sparc binary */
272b305b0f1Sespie   M_PMAX_NETBSD = 139,	/* NetBSD/pmax (MIPS little-endian) binary */
273c074d1c9Sdrahn   M_VAX_NETBSD = 140,	/* NetBSD/vax binary */
274b305b0f1Sespie   M_ALPHA_NETBSD = 141,	/* NetBSD/alpha binary */
275b305b0f1Sespie   M_ARM6_NETBSD = 143,	/* NetBSD/arm32 binary */
276b305b0f1Sespie   M_SPARCLET_1 = 147,	/* 0x93, reserved */
2777839e2deSkettenis   M_POWERPC_NETBSD = 149, /* NetBSD/powerpc (big-endian) binary */
278c074d1c9Sdrahn   M_VAX4K_NETBSD = 150,	/* NetBSD/vax 4K pages binary */
2792159047fSniklas   M_MIPS1 = 151,        /* MIPS R2000/R3000 binary */
2802159047fSniklas   M_MIPS2 = 152,        /* MIPS R4000/R6000 binary */
28193f6463eSkettenis   M_88K_OPENBSD = 153,	/* OpenBSD/m88k binary */
282285d8e81Skettenis   M_HPPA_OPENBSD = 154,	/* OpenBSD/hppa binary */
2837839e2deSkettenis   M_SPARC64_NETBSD = 156, /* NetBSD/sparc64 binary */
2847839e2deSkettenis   M_X86_64_NETBSD = 157, /* NetBSD/amd64 binary */
285b305b0f1Sespie   M_SPARCLET_2 = 163,	/* 0xa3, reserved */
286b305b0f1Sespie   M_SPARCLET_3 = 179,	/* 0xb3, reserved */
287b305b0f1Sespie   M_SPARCLET_4 = 195,	/* 0xc3, reserved */
2882159047fSniklas   M_HP200 = 200,	/* HP 200 (68010) BSD binary */
2892159047fSniklas   M_HP300 = (300 % 256), /* HP 300 (68020+68881) BSD binary */
290b305b0f1Sespie   M_HPUX = (0x20c % 256), /* HP 200/300 HPUX binary */
291b305b0f1Sespie   M_SPARCLET_5 = 211,	/* 0xd3, reserved */
292b305b0f1Sespie   M_SPARCLET_6 = 227,	/* 0xe3, reserved */
293b305b0f1Sespie   /*  M_SPARCLET_7 = 243	/ * 0xf3, reserved */
294b55d4692Sfgsch   M_SPARCLITE_LE = 243,
295b55d4692Sfgsch   M_CRIS = 255		/* Axis CRIS binary.  */
2962159047fSniklas };
2972159047fSniklas 
2982159047fSniklas #define N_DYNAMIC(exec) ((exec).a_info & 0x80000000)
2992159047fSniklas 
3002159047fSniklas #ifndef N_MAGIC
3012159047fSniklas # define N_MAGIC(exec) ((exec).a_info & 0xffff)
3022159047fSniklas #endif
3032159047fSniklas 
3042159047fSniklas #ifndef N_MACHTYPE
3052159047fSniklas # define N_MACHTYPE(exec) ((enum machine_type)(((exec).a_info >> 16) & 0xff))
3062159047fSniklas #endif
3072159047fSniklas 
3082159047fSniklas #ifndef N_FLAGS
3092159047fSniklas # define N_FLAGS(exec) (((exec).a_info >> 24) & 0xff)
3102159047fSniklas #endif
3112159047fSniklas 
3122159047fSniklas #ifndef N_SET_INFO
3132159047fSniklas # define N_SET_INFO(exec, magic, type, flags) \
3142159047fSniklas ((exec).a_info = ((magic) & 0xffff) \
3152159047fSniklas  | (((int)(type) & 0xff) << 16) \
3162159047fSniklas  | (((flags) & 0xff) << 24))
3172159047fSniklas #endif
3182159047fSniklas 
3192159047fSniklas #ifndef N_SET_DYNAMIC
3202159047fSniklas # define N_SET_DYNAMIC(exec, dynamic) \
321c074d1c9Sdrahn ((exec).a_info = (dynamic) ? (long) ((exec).a_info | 0x80000000) : \
3222159047fSniklas ((exec).a_info & 0x7fffffff))
3232159047fSniklas #endif
3242159047fSniklas 
3252159047fSniklas #ifndef N_SET_MAGIC
3262159047fSniklas # define N_SET_MAGIC(exec, magic) \
3272159047fSniklas ((exec).a_info = (((exec).a_info & 0xffff0000) | ((magic) & 0xffff)))
3282159047fSniklas #endif
3292159047fSniklas 
3302159047fSniklas #ifndef N_SET_MACHTYPE
3312159047fSniklas # define N_SET_MACHTYPE(exec, machtype) \
3322159047fSniklas ((exec).a_info = \
3332159047fSniklas  ((exec).a_info&0xff00ffff) | ((((int)(machtype))&0xff) << 16))
3342159047fSniklas #endif
3352159047fSniklas 
3362159047fSniklas #ifndef N_SET_FLAGS
3372159047fSniklas # define N_SET_FLAGS(exec, flags) \
3382159047fSniklas ((exec).a_info = \
3392159047fSniklas  ((exec).a_info&0x00ffffff) | (((flags) & 0xff) << 24))
3402159047fSniklas #endif
3412159047fSniklas 
3422159047fSniklas typedef struct aout_symbol {
3432159047fSniklas   asymbol symbol;
3442159047fSniklas   short desc;
3452159047fSniklas   char other;
3462159047fSniklas   unsigned char type;
3472159047fSniklas } aout_symbol_type;
3482159047fSniklas 
3492159047fSniklas /* The `tdata' struct for all a.out-like object file formats.
3502159047fSniklas    Various things depend on this struct being around any time an a.out
3512159047fSniklas    file is being handled.  An example is dbxread.c in GDB.  */
3522159047fSniklas 
3532159047fSniklas struct aoutdata {
3542159047fSniklas   struct internal_exec *hdr;		/* exec file header */
3552159047fSniklas   aout_symbol_type *symbols;		/* symtab for input bfd */
3562159047fSniklas 
357c074d1c9Sdrahn   /* For ease, we do this.  */
3582159047fSniklas   asection *textsec;
3592159047fSniklas   asection *datasec;
3602159047fSniklas   asection *bsssec;
3612159047fSniklas 
3622159047fSniklas   /* We remember these offsets so that after check_file_format, we have
3632159047fSniklas      no dependencies on the particular format of the exec_hdr.  */
3642159047fSniklas   file_ptr sym_filepos;
3652159047fSniklas   file_ptr str_filepos;
3662159047fSniklas 
367c074d1c9Sdrahn   /* Size of a relocation entry in external form.  */
3682159047fSniklas   unsigned reloc_entry_size;
3692159047fSniklas 
370c074d1c9Sdrahn   /* Size of a symbol table entry in external form.  */
3712159047fSniklas   unsigned symbol_entry_size;
3722159047fSniklas 
3732159047fSniklas   /* Page size - needed for alignment of demand paged files.  */
3742159047fSniklas   unsigned long page_size;
3752159047fSniklas 
3762159047fSniklas   /* Segment size - needed for alignment of demand paged files.  */
3772159047fSniklas   unsigned long segment_size;
3782159047fSniklas 
3792159047fSniklas   /* Zmagic disk block size - need to align the start of the text
3802159047fSniklas      section in ZMAGIC binaries.  Normally the same as page_size.  */
3812159047fSniklas   unsigned long zmagic_disk_block_size;
3822159047fSniklas 
3832159047fSniklas   unsigned exec_bytes_size;
3842159047fSniklas   unsigned vma_adjusted : 1;
3852159047fSniklas 
386c074d1c9Sdrahn   /* Used when a bfd supports several highly similar formats.  */
3872159047fSniklas   enum
3882159047fSniklas     {
3892159047fSniklas       default_format = 0,
3902159047fSniklas       /* Used on HP 9000/300 running HP/UX.  See hp300hpux.c.  */
3912159047fSniklas       gnu_encap_format,
3922159047fSniklas       /* Used on Linux, 386BSD, etc.  See include/aout/aout64.h.  */
3932159047fSniklas       q_magic_format
3942159047fSniklas     } subformat;
3952159047fSniklas 
3962159047fSniklas   enum
3972159047fSniklas     {
3982159047fSniklas       undecided_magic = 0,
3992159047fSniklas       z_magic,
4002159047fSniklas       o_magic,
4012159047fSniklas       n_magic
4022159047fSniklas     } magic;
4032159047fSniklas 
4042159047fSniklas   /* A buffer for find_nearest_line.  */
4052159047fSniklas   char *line_buf;
4062159047fSniklas 
4072159047fSniklas   /* The external symbol information.  */
4082159047fSniklas   struct external_nlist *external_syms;
4092159047fSniklas   bfd_size_type external_sym_count;
4102159047fSniklas   bfd_window sym_window;
4112159047fSniklas   char *external_strings;
4122159047fSniklas   bfd_size_type external_string_size;
4132159047fSniklas   bfd_window string_window;
4142159047fSniklas   struct aout_link_hash_entry **sym_hashes;
4152159047fSniklas 
4162159047fSniklas   /* A pointer for shared library information.  */
4172159047fSniklas   PTR dynamic_info;
4182159047fSniklas 
4192159047fSniklas   /* A mapping from local symbols to offsets into the global offset
4202159047fSniklas      table, used when linking on SunOS.  This is indexed by the symbol
4212159047fSniklas      index.  */
4222159047fSniklas   bfd_vma *local_got_offsets;
4232159047fSniklas };
4242159047fSniklas 
4252159047fSniklas struct  aout_data_struct {
4262159047fSniklas     struct aoutdata a;
4272159047fSniklas     struct internal_exec e;
4282159047fSniklas };
4292159047fSniklas 
4302159047fSniklas #define	adata(bfd)		((bfd)->tdata.aout_data->a)
4312159047fSniklas #define	exec_hdr(bfd)		(adata(bfd).hdr)
4322159047fSniklas #define	obj_aout_symbols(bfd)	(adata(bfd).symbols)
4332159047fSniklas #define	obj_textsec(bfd)	(adata(bfd).textsec)
4342159047fSniklas #define	obj_datasec(bfd)	(adata(bfd).datasec)
4352159047fSniklas #define	obj_bsssec(bfd)		(adata(bfd).bsssec)
4362159047fSniklas #define	obj_sym_filepos(bfd)	(adata(bfd).sym_filepos)
4372159047fSniklas #define	obj_str_filepos(bfd)	(adata(bfd).str_filepos)
4382159047fSniklas #define	obj_reloc_entry_size(bfd) (adata(bfd).reloc_entry_size)
4392159047fSniklas #define	obj_symbol_entry_size(bfd) (adata(bfd).symbol_entry_size)
4402159047fSniklas #define obj_aout_subformat(bfd)	(adata(bfd).subformat)
4412159047fSniklas #define obj_aout_external_syms(bfd) (adata(bfd).external_syms)
4422159047fSniklas #define obj_aout_external_sym_count(bfd) (adata(bfd).external_sym_count)
4432159047fSniklas #define obj_aout_sym_window(bfd) (adata(bfd).sym_window)
4442159047fSniklas #define obj_aout_external_strings(bfd) (adata(bfd).external_strings)
4452159047fSniklas #define obj_aout_external_string_size(bfd) (adata(bfd).external_string_size)
4462159047fSniklas #define obj_aout_string_window(bfd) (adata(bfd).string_window)
4472159047fSniklas #define obj_aout_sym_hashes(bfd) (adata(bfd).sym_hashes)
4482159047fSniklas #define obj_aout_dynamic_info(bfd) (adata(bfd).dynamic_info)
4492159047fSniklas 
4502159047fSniklas /* We take the address of the first element of an asymbol to ensure that the
451c074d1c9Sdrahn    macro is only ever applied to an asymbol.  */
4522159047fSniklas #define aout_symbol(asymbol) ((aout_symbol_type *)(&(asymbol)->the_bfd))
4532159047fSniklas 
4542159047fSniklas /* Information we keep for each a.out section.  This is currently only
4552159047fSniklas    used by the a.out backend linker.  */
4562159047fSniklas 
4572159047fSniklas struct aout_section_data_struct
4582159047fSniklas {
4592159047fSniklas   /* The unswapped relocation entries for this section.  */
4602159047fSniklas   PTR relocs;
4612159047fSniklas };
4622159047fSniklas 
4632159047fSniklas #define aout_section_data(s) \
4642159047fSniklas   ((struct aout_section_data_struct *) (s)->used_by_bfd)
4652159047fSniklas 
4662159047fSniklas #define set_aout_section_data(s,v) \
4672159047fSniklas   ((s)->used_by_bfd = (PTR)&(v)->relocs)
4682159047fSniklas 
469c074d1c9Sdrahn /* Prototype declarations for functions defined in aoutx.h.  */
4702159047fSniklas 
471c074d1c9Sdrahn extern bfd_boolean NAME(aout,squirt_out_relocs)
472c074d1c9Sdrahn   PARAMS ((bfd *, asection *));
4732159047fSniklas 
474c074d1c9Sdrahn extern bfd_boolean NAME(aout,make_sections)
475c074d1c9Sdrahn   PARAMS ((bfd *));
4762159047fSniklas 
477c074d1c9Sdrahn extern const bfd_target * NAME(aout,some_aout_object_p)
478c074d1c9Sdrahn   PARAMS ((bfd *, struct internal_exec *, const bfd_target *(*) (bfd *)));
4792159047fSniklas 
480c074d1c9Sdrahn extern bfd_boolean NAME(aout,mkobject)
481c074d1c9Sdrahn   PARAMS ((bfd *));
4822159047fSniklas 
483c074d1c9Sdrahn extern enum machine_type NAME(aout,machine_type)
484c074d1c9Sdrahn   PARAMS ((enum bfd_architecture, unsigned long, bfd_boolean *));
4852159047fSniklas 
486c074d1c9Sdrahn extern bfd_boolean NAME(aout,set_arch_mach)
487c074d1c9Sdrahn   PARAMS ((bfd *, enum bfd_architecture, unsigned long));
4882159047fSniklas 
489c074d1c9Sdrahn extern bfd_boolean NAME(aout,new_section_hook)
490c074d1c9Sdrahn   PARAMS ((bfd *, asection *));
4912159047fSniklas 
492c074d1c9Sdrahn extern bfd_boolean NAME(aout,set_section_contents)
493*007c2a45Smiod   PARAMS ((bfd *, sec_ptr, const PTR, file_ptr, bfd_size_type));
4942159047fSniklas 
495c074d1c9Sdrahn extern asymbol * NAME(aout,make_empty_symbol)
496c074d1c9Sdrahn   PARAMS ((bfd *));
4972159047fSniklas 
498c074d1c9Sdrahn extern bfd_boolean NAME(aout,translate_symbol_table)
499c074d1c9Sdrahn   PARAMS ((bfd *, aout_symbol_type *, struct external_nlist *, bfd_size_type,
500c074d1c9Sdrahn 	   char *, bfd_size_type, bfd_boolean));
5012159047fSniklas 
502c074d1c9Sdrahn extern bfd_boolean NAME(aout,slurp_symbol_table)
503c074d1c9Sdrahn   PARAMS ((bfd *));
5042159047fSniklas 
505c074d1c9Sdrahn extern bfd_boolean NAME(aout,write_syms)
506c074d1c9Sdrahn   PARAMS ((bfd *));
5072159047fSniklas 
508c074d1c9Sdrahn extern void NAME(aout,reclaim_symbol_table)
509c074d1c9Sdrahn   PARAMS ((bfd *));
5102159047fSniklas 
511c074d1c9Sdrahn extern long NAME(aout,get_symtab_upper_bound)
512c074d1c9Sdrahn   PARAMS ((bfd *));
5132159047fSniklas 
514*007c2a45Smiod extern long NAME(aout,canonicalize_symtab)
515c074d1c9Sdrahn   PARAMS ((bfd *, asymbol **));
5162159047fSniklas 
517c074d1c9Sdrahn extern void NAME(aout,swap_ext_reloc_in)
518c074d1c9Sdrahn   PARAMS ((bfd *, struct reloc_ext_external *, arelent *, asymbol **,
519c074d1c9Sdrahn 	   bfd_size_type));
520c074d1c9Sdrahn extern void NAME(aout,swap_std_reloc_in)
521c074d1c9Sdrahn   PARAMS ((bfd *, struct reloc_std_external *, arelent *, asymbol **,
522c074d1c9Sdrahn 	   bfd_size_type));
5232159047fSniklas 
524c074d1c9Sdrahn extern reloc_howto_type * NAME(aout,reloc_type_lookup)
525c074d1c9Sdrahn   PARAMS ((bfd *, bfd_reloc_code_real_type));
5262159047fSniklas 
527c074d1c9Sdrahn extern bfd_boolean NAME(aout,slurp_reloc_table)
528c074d1c9Sdrahn   PARAMS ((bfd *, sec_ptr, asymbol **));
5292159047fSniklas 
530c074d1c9Sdrahn extern long NAME(aout,canonicalize_reloc)
531c074d1c9Sdrahn   PARAMS ((bfd *, sec_ptr, arelent **, asymbol **));
5322159047fSniklas 
533c074d1c9Sdrahn extern long NAME(aout,get_reloc_upper_bound)
534c074d1c9Sdrahn   PARAMS ((bfd *, sec_ptr));
5352159047fSniklas 
536c074d1c9Sdrahn extern void NAME(aout,reclaim_reloc)
537c074d1c9Sdrahn   PARAMS ((bfd *, sec_ptr));
5382159047fSniklas 
539c074d1c9Sdrahn extern alent * NAME(aout,get_lineno)
540c074d1c9Sdrahn   PARAMS ((bfd *, asymbol *));
5412159047fSniklas 
542c074d1c9Sdrahn extern void NAME(aout,print_symbol)
543c074d1c9Sdrahn   PARAMS ((bfd *, PTR, asymbol *, bfd_print_symbol_type));
5442159047fSniklas 
545c074d1c9Sdrahn extern void NAME(aout,get_symbol_info)
546c074d1c9Sdrahn   PARAMS ((bfd *, asymbol *, symbol_info *));
5472159047fSniklas 
548c074d1c9Sdrahn extern bfd_boolean NAME(aout,find_nearest_line)
549c074d1c9Sdrahn   PARAMS ((bfd *, asection *, asymbol **, bfd_vma, const char **,
550c074d1c9Sdrahn 	   const char **, unsigned int *));
5512159047fSniklas 
552c074d1c9Sdrahn extern long NAME(aout,read_minisymbols)
553c074d1c9Sdrahn   PARAMS ((bfd *, bfd_boolean, PTR *, unsigned int *));
5542159047fSniklas 
555c074d1c9Sdrahn extern asymbol * NAME(aout,minisymbol_to_symbol)
556c074d1c9Sdrahn   PARAMS ((bfd *, bfd_boolean, const PTR, asymbol *));
5572159047fSniklas 
558c074d1c9Sdrahn extern int NAME(aout,sizeof_headers)
559c074d1c9Sdrahn   PARAMS ((bfd *, bfd_boolean));
5602159047fSniklas 
561c074d1c9Sdrahn extern bfd_boolean NAME(aout,adjust_sizes_and_vmas)
562c074d1c9Sdrahn   PARAMS ((bfd *, bfd_size_type *, file_ptr *));
5632159047fSniklas 
564c074d1c9Sdrahn extern void NAME(aout,swap_exec_header_in)
565c074d1c9Sdrahn   PARAMS ((bfd *, struct external_exec *, struct internal_exec *));
5662159047fSniklas 
567c074d1c9Sdrahn extern void NAME(aout,swap_exec_header_out)
568c074d1c9Sdrahn   PARAMS ((bfd *, struct internal_exec *, struct external_exec *));
5692159047fSniklas 
570c074d1c9Sdrahn extern struct bfd_hash_entry * NAME(aout,link_hash_newfunc)
5712159047fSniklas   PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
5722159047fSniklas 
573c074d1c9Sdrahn extern bfd_boolean NAME(aout,link_hash_table_init)
5742159047fSniklas   PARAMS ((struct aout_link_hash_table *, bfd *,
5752159047fSniklas 	   struct bfd_hash_entry *(*) (struct bfd_hash_entry *,
5762159047fSniklas 				       struct bfd_hash_table *,
5772159047fSniklas 				       const char *)));
5782159047fSniklas 
579c074d1c9Sdrahn extern struct bfd_link_hash_table * NAME(aout,link_hash_table_create)
580c074d1c9Sdrahn   PARAMS ((bfd *));
5812159047fSniklas 
582c074d1c9Sdrahn extern bfd_boolean NAME(aout,link_add_symbols)
583c074d1c9Sdrahn   PARAMS ((bfd *, struct bfd_link_info *));
5842159047fSniklas 
585c074d1c9Sdrahn extern bfd_boolean NAME(aout,final_link)
586c074d1c9Sdrahn   PARAMS ((bfd *, struct bfd_link_info *,
587c074d1c9Sdrahn 	   void (*) (bfd *, file_ptr *, file_ptr *, file_ptr *)));
5882159047fSniklas 
589c074d1c9Sdrahn extern bfd_boolean NAME(aout,bfd_free_cached_info)
590c074d1c9Sdrahn   PARAMS ((bfd *));
5912159047fSniklas 
5922159047fSniklas /* A.out uses the generic versions of these routines...  */
5932159047fSniklas 
594c074d1c9Sdrahn #define	aout_16_get_section_contents	_bfd_generic_get_section_contents
595c074d1c9Sdrahn 
5962159047fSniklas #define	aout_32_get_section_contents	_bfd_generic_get_section_contents
5972159047fSniklas 
5982159047fSniklas #define	aout_64_get_section_contents	_bfd_generic_get_section_contents
5992159047fSniklas #ifndef NO_WRITE_HEADER_KLUDGE
6002159047fSniklas #define NO_WRITE_HEADER_KLUDGE 0
6012159047fSniklas #endif
6022159047fSniklas 
603b305b0f1Sespie #ifndef aout_32_bfd_is_local_label_name
604b305b0f1Sespie #define aout_32_bfd_is_local_label_name bfd_generic_is_local_label_name
6052159047fSniklas #endif
6062159047fSniklas 
6072159047fSniklas #ifndef WRITE_HEADERS
6082159047fSniklas #define WRITE_HEADERS(abfd, execp)					      \
6092159047fSniklas       {									      \
6102159047fSniklas 	bfd_size_type text_size; /* dummy vars */			      \
6112159047fSniklas 	file_ptr text_end;						      \
6122159047fSniklas 	if (adata(abfd).magic == undecided_magic)			      \
6132159047fSniklas 	  NAME(aout,adjust_sizes_and_vmas) (abfd, &text_size, &text_end);     \
6142159047fSniklas     									      \
6152159047fSniklas 	execp->a_syms = bfd_get_symcount (abfd) * EXTERNAL_NLIST_SIZE;	      \
6162159047fSniklas 	execp->a_entry = bfd_get_start_address (abfd);			      \
6172159047fSniklas     									      \
6182159047fSniklas 	execp->a_trsize = ((obj_textsec (abfd)->reloc_count) *		      \
6192159047fSniklas 			   obj_reloc_entry_size (abfd));		      \
6202159047fSniklas 	execp->a_drsize = ((obj_datasec (abfd)->reloc_count) *		      \
6212159047fSniklas 			   obj_reloc_entry_size (abfd));		      \
6222159047fSniklas 	NAME(aout,swap_exec_header_out) (abfd, execp, &exec_bytes);	      \
6232159047fSniklas 									      \
624c074d1c9Sdrahn 	if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0		      \
625c074d1c9Sdrahn 	    || bfd_bwrite ((PTR) &exec_bytes, (bfd_size_type) EXEC_BYTES_SIZE, \
626c074d1c9Sdrahn 			  abfd) != EXEC_BYTES_SIZE)			      \
627c074d1c9Sdrahn 	  return FALSE;							      \
628c074d1c9Sdrahn 	/* Now write out reloc info, followed by syms and strings.  */	      \
6292159047fSniklas   									      \
6302159047fSniklas 	if (bfd_get_outsymbols (abfd) != (asymbol **) NULL		      \
6312159047fSniklas 	    && bfd_get_symcount (abfd) != 0) 				      \
6322159047fSniklas 	  {								      \
633c88b1d6cSniklas 	    if (bfd_seek (abfd, (file_ptr) (N_SYMOFF(*execp)), SEEK_SET) != 0)\
634c074d1c9Sdrahn 	      return FALSE;						      \
6352159047fSniklas 									      \
636c074d1c9Sdrahn 	    if (! NAME(aout,write_syms) (abfd))				      \
637c074d1c9Sdrahn 	      return FALSE;						      \
638c88b1d6cSniklas 	  }								      \
6392159047fSniklas 									      \
640c88b1d6cSniklas 	if (bfd_seek (abfd, (file_ptr) (N_TRELOFF(*execp)), SEEK_SET) != 0)   \
641c074d1c9Sdrahn 	  return FALSE;						      	      \
6422159047fSniklas 	if (!NAME(aout,squirt_out_relocs) (abfd, obj_textsec (abfd)))         \
643c074d1c9Sdrahn 	  return FALSE;						      	      \
6442159047fSniklas 									      \
645c88b1d6cSniklas 	if (bfd_seek (abfd, (file_ptr) (N_DRELOFF(*execp)), SEEK_SET) != 0)   \
646c074d1c9Sdrahn 	  return FALSE;						      	      \
6472159047fSniklas 	if (!NAME(aout,squirt_out_relocs) (abfd, obj_datasec (abfd)))         \
648c074d1c9Sdrahn 	  return FALSE;						      	      \
6492159047fSniklas       }
6502159047fSniklas #endif
6512159047fSniklas 
652c074d1c9Sdrahn /* Test if a read-only section can be merged with .text.  This is
653c074d1c9Sdrahn    possible if:
654c074d1c9Sdrahn 
655c074d1c9Sdrahn    1. Section has file contents and is read-only.
656c074d1c9Sdrahn    2. The VMA of the section is after the end of .text and before
657c074d1c9Sdrahn       the start of .data.
658c074d1c9Sdrahn    3. The image is demand-pageable (otherwise, a_text in the header
659c074d1c9Sdrahn       will not reflect the gap between .text and .data).  */
660c074d1c9Sdrahn 
661c074d1c9Sdrahn #define aout_section_merge_with_text_p(abfd, sec)			\
662c074d1c9Sdrahn   (((sec)->flags & (SEC_HAS_CONTENTS | SEC_READONLY)) ==		\
663c074d1c9Sdrahn       (SEC_HAS_CONTENTS | SEC_READONLY)					\
664c074d1c9Sdrahn    && obj_textsec (abfd) != NULL					\
665c074d1c9Sdrahn    && obj_datasec (abfd) != NULL					\
666c074d1c9Sdrahn    && (sec)->vma >= (obj_textsec (abfd)->vma +				\
667c074d1c9Sdrahn 		     obj_textsec (abfd)->_cooked_size)			\
668c074d1c9Sdrahn    && ((sec)->vma + (sec)->_cooked_size) <= obj_datasec (abfd)->vma	\
669c074d1c9Sdrahn    && ((abfd)->flags & D_PAGED) != 0)
670c074d1c9Sdrahn 
6712159047fSniklas #endif /* ! defined (LIBAOUT_H) */
672