xref: /dflybsd-src/contrib/binutils-2.34/include/aout/aout64.h (revision b52ef7118d1621abed722c5bbbd542210290ecef)
1*fae548d3Szrj /* `a.out' object-file definitions, including extensions to 64-bit fields
2*fae548d3Szrj 
3*fae548d3Szrj    Copyright (C) 1999-2020 Free Software Foundation, Inc.
4*fae548d3Szrj 
5*fae548d3Szrj    This program is free software; you can redistribute it and/or modify
6*fae548d3Szrj    it under the terms of the GNU General Public License as published by
7*fae548d3Szrj    the Free Software Foundation; either version 3 of the License, or
8*fae548d3Szrj    (at your option) any later version.
9*fae548d3Szrj 
10*fae548d3Szrj    This program is distributed in the hope that it will be useful,
11*fae548d3Szrj    but WITHOUT ANY WARRANTY; without even the implied warranty of
12*fae548d3Szrj    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13*fae548d3Szrj    GNU General Public License for more details.
14*fae548d3Szrj 
15*fae548d3Szrj    You should have received a copy of the GNU General Public License
16*fae548d3Szrj    along with this program; if not, write to the Free Software
17*fae548d3Szrj    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
18*fae548d3Szrj    MA 02110-1301, USA.  */
19*fae548d3Szrj 
20*fae548d3Szrj #ifndef __A_OUT_64_H__
21*fae548d3Szrj #define __A_OUT_64_H__
22*fae548d3Szrj 
23*fae548d3Szrj #ifndef BYTES_IN_WORD
24*fae548d3Szrj #define BYTES_IN_WORD 4
25*fae548d3Szrj #endif
26*fae548d3Szrj 
27*fae548d3Szrj /* This is the layout on disk of the 32-bit or 64-bit exec header.  */
28*fae548d3Szrj 
29*fae548d3Szrj #ifndef external_exec
30*fae548d3Szrj struct external_exec
31*fae548d3Szrj {
32*fae548d3Szrj   bfd_byte e_info[4];		    /* Magic number and stuff.  */
33*fae548d3Szrj   bfd_byte e_text[BYTES_IN_WORD];   /* Length of text section in bytes.  */
34*fae548d3Szrj   bfd_byte e_data[BYTES_IN_WORD];   /* Length of data section in bytes.  */
35*fae548d3Szrj   bfd_byte e_bss[BYTES_IN_WORD];    /* Length of bss area in bytes.  */
36*fae548d3Szrj   bfd_byte e_syms[BYTES_IN_WORD];   /* Length of symbol table in bytes.  */
37*fae548d3Szrj   bfd_byte e_entry[BYTES_IN_WORD];  /* Start address.  */
38*fae548d3Szrj   bfd_byte e_trsize[BYTES_IN_WORD]; /* Length of text relocation info.  */
39*fae548d3Szrj   bfd_byte e_drsize[BYTES_IN_WORD]; /* Length of data relocation info.  */
40*fae548d3Szrj };
41*fae548d3Szrj 
42*fae548d3Szrj #define	EXEC_BYTES_SIZE	(4 + BYTES_IN_WORD * 7)
43*fae548d3Szrj 
44*fae548d3Szrj /* Magic numbers for a.out files.  */
45*fae548d3Szrj 
46*fae548d3Szrj #if ARCH_SIZE==64
47*fae548d3Szrj #define OMAGIC 0x1001		/* Code indicating object file.  */
48*fae548d3Szrj #define ZMAGIC 0x1002		/* Code indicating demand-paged executable.  */
49*fae548d3Szrj #define NMAGIC 0x1003		/* Code indicating pure executable.  */
50*fae548d3Szrj 
51*fae548d3Szrj /* There is no 64-bit QMAGIC as far as I know.  */
52*fae548d3Szrj 
53*fae548d3Szrj #define N_BADMAG(x)	  (N_MAGIC(x) != OMAGIC		\
54*fae548d3Szrj 			&& N_MAGIC(x) != NMAGIC		\
55*fae548d3Szrj   			&& N_MAGIC(x) != ZMAGIC)
56*fae548d3Szrj #else
57*fae548d3Szrj #define OMAGIC 0407		/* Object file or impure executable.  */
58*fae548d3Szrj #define NMAGIC 0410		/* Code indicating pure executable.  */
59*fae548d3Szrj #define ZMAGIC 0413		/* Code indicating demand-paged executable.  */
60*fae548d3Szrj #define BMAGIC 0415		/* Used by a b.out object.  */
61*fae548d3Szrj 
62*fae548d3Szrj /* This indicates a demand-paged executable with the header in the text.
63*fae548d3Szrj    It is used by 386BSD (and variants) and Linux, at least.  */
64*fae548d3Szrj #ifndef QMAGIC
65*fae548d3Szrj #define QMAGIC 0314
66*fae548d3Szrj #endif
67*fae548d3Szrj # ifndef N_BADMAG
68*fae548d3Szrj #  define N_BADMAG(x)	  (N_MAGIC(x) != OMAGIC		\
69*fae548d3Szrj 			&& N_MAGIC(x) != NMAGIC		\
70*fae548d3Szrj   			&& N_MAGIC(x) != ZMAGIC \
71*fae548d3Szrj 		        && N_MAGIC(x) != QMAGIC)
72*fae548d3Szrj # endif /* N_BADMAG */
73*fae548d3Szrj #endif
74*fae548d3Szrj 
75*fae548d3Szrj #endif
76*fae548d3Szrj 
77*fae548d3Szrj #ifdef QMAGIC
78*fae548d3Szrj #define N_IS_QMAGIC(x) (N_MAGIC (x) == QMAGIC)
79*fae548d3Szrj #else
80*fae548d3Szrj #define N_IS_QMAGIC(x) (0)
81*fae548d3Szrj #endif
82*fae548d3Szrj 
83*fae548d3Szrj /* The difference between TARGET_PAGE_SIZE and N_SEGSIZE is that TARGET_PAGE_SIZE is
84*fae548d3Szrj    the finest granularity at which you can page something, thus it
85*fae548d3Szrj    controls the padding (if any) before the text segment of a ZMAGIC
86*fae548d3Szrj    file.  N_SEGSIZE is the resolution at which things can be marked as
87*fae548d3Szrj    read-only versus read/write, so it controls the padding between the
88*fae548d3Szrj    text segment and the data segment (in memory; on disk the padding
89*fae548d3Szrj    between them is TARGET_PAGE_SIZE).  TARGET_PAGE_SIZE and N_SEGSIZE are the same
90*fae548d3Szrj    for most machines, but different for sun3.  */
91*fae548d3Szrj 
92*fae548d3Szrj /* By default, segment size is constant.  But some machines override this
93*fae548d3Szrj    to be a function of the a.out header (e.g. machine type).  */
94*fae548d3Szrj 
95*fae548d3Szrj #ifndef	N_SEGSIZE
96*fae548d3Szrj #define	N_SEGSIZE(x)	SEGMENT_SIZE
97*fae548d3Szrj #endif
98*fae548d3Szrj 
99*fae548d3Szrj /* Virtual memory address of the text section.
100*fae548d3Szrj    This is getting very complicated.  A good reason to discard a.out format
101*fae548d3Szrj    for something that specifies these fields explicitly.  But til then...
102*fae548d3Szrj 
103*fae548d3Szrj    * OMAGIC and NMAGIC files:
104*fae548d3Szrj        (object files: text for "relocatable addr 0" right after the header)
105*fae548d3Szrj        start at 0, offset is EXEC_BYTES_SIZE, size as stated.
106*fae548d3Szrj    * The text address, offset, and size of ZMAGIC files depend
107*fae548d3Szrj      on the entry point of the file:
108*fae548d3Szrj      * entry point below TEXT_START_ADDR:
109*fae548d3Szrj        (hack for SunOS shared libraries)
110*fae548d3Szrj        start at 0, offset is 0, size as stated.
111*fae548d3Szrj      * If N_HEADER_IN_TEXT(x) is true (which defaults to being the
112*fae548d3Szrj        case when the entry point is EXEC_BYTES_SIZE or further into a page):
113*fae548d3Szrj        no padding is needed; text can start after exec header.  Sun
114*fae548d3Szrj        considers the text segment of such files to include the exec header;
115*fae548d3Szrj        for BFD's purposes, we don't, which makes more work for us.
116*fae548d3Szrj        start at TEXT_START_ADDR + EXEC_BYTES_SIZE, offset is EXEC_BYTES_SIZE,
117*fae548d3Szrj        size as stated minus EXEC_BYTES_SIZE.
118*fae548d3Szrj      * If N_HEADER_IN_TEXT(x) is false (which defaults to being the case when
119*fae548d3Szrj        the entry point is less than EXEC_BYTES_SIZE into a page (e.g. page
120*fae548d3Szrj        aligned)): (padding is needed so that text can start at a page boundary)
121*fae548d3Szrj        start at TEXT_START_ADDR, offset TARGET_PAGE_SIZE, size as stated.
122*fae548d3Szrj 
123*fae548d3Szrj     Specific configurations may want to hardwire N_HEADER_IN_TEXT,
124*fae548d3Szrj     for efficiency or to allow people to play games with the entry point.
125*fae548d3Szrj     In that case, you would #define N_HEADER_IN_TEXT(x) as 1 for sunos,
126*fae548d3Szrj     and as 0 for most other hosts (Sony News, Vax Ultrix, etc).
127*fae548d3Szrj     (Do this in the appropriate bfd target file.)
128*fae548d3Szrj     (The default is a heuristic that will break if people try changing
129*fae548d3Szrj     the entry point, perhaps with the ld -e flag.)
130*fae548d3Szrj 
131*fae548d3Szrj     * QMAGIC is always like a ZMAGIC for which N_HEADER_IN_TEXT is true,
132*fae548d3Szrj     and for which the starting address is TARGET_PAGE_SIZE (or should this be
133*fae548d3Szrj     SEGMENT_SIZE?) (TEXT_START_ADDR only applies to ZMAGIC, not to QMAGIC).  */
134*fae548d3Szrj 
135*fae548d3Szrj /* This macro is only relevant for ZMAGIC files; QMAGIC always has the header
136*fae548d3Szrj    in the text.  */
137*fae548d3Szrj #ifndef N_HEADER_IN_TEXT
138*fae548d3Szrj #define N_HEADER_IN_TEXT(x) \
139*fae548d3Szrj   (((x)->a_entry & (TARGET_PAGE_SIZE-1)) >= EXEC_BYTES_SIZE)
140*fae548d3Szrj #endif
141*fae548d3Szrj 
142*fae548d3Szrj /* Sun shared libraries, not linux.  This macro is only relevant for ZMAGIC
143*fae548d3Szrj    files.  */
144*fae548d3Szrj #ifndef N_SHARED_LIB
145*fae548d3Szrj #define N_SHARED_LIB(x) (0)
146*fae548d3Szrj #endif
147*fae548d3Szrj 
148*fae548d3Szrj /* Returning 0 not TEXT_START_ADDR for OMAGIC and NMAGIC is based on
149*fae548d3Szrj    the assumption that we are dealing with a .o file, not an
150*fae548d3Szrj    executable.  This is necessary for OMAGIC (but means we don't work
151*fae548d3Szrj    right on the output from ld -N); more questionable for NMAGIC.  */
152*fae548d3Szrj 
153*fae548d3Szrj #ifndef N_TXTADDR
154*fae548d3Szrj #define N_TXTADDR(x) \
155*fae548d3Szrj     (/* The address of a QMAGIC file is always one page in,		\
156*fae548d3Szrj         with the header in the text.  */				\
157*fae548d3Szrj      N_IS_QMAGIC (x)							\
158*fae548d3Szrj      ? (bfd_vma) TARGET_PAGE_SIZE + EXEC_BYTES_SIZE			\
159*fae548d3Szrj      : (N_MAGIC (x) != ZMAGIC						\
160*fae548d3Szrj 	? (bfd_vma) 0	/* Object file or NMAGIC.  */			\
161*fae548d3Szrj 	: (N_SHARED_LIB (x)						\
162*fae548d3Szrj 	   ? (bfd_vma) 0						\
163*fae548d3Szrj 	   : (N_HEADER_IN_TEXT (x)					\
164*fae548d3Szrj 	      ? (bfd_vma) TEXT_START_ADDR + EXEC_BYTES_SIZE		\
165*fae548d3Szrj 	      : (bfd_vma) TEXT_START_ADDR))))
166*fae548d3Szrj #endif
167*fae548d3Szrj 
168*fae548d3Szrj /* If N_HEADER_IN_TEXT is not true for ZMAGIC, there is some padding
169*fae548d3Szrj    to make the text segment start at a certain boundary.  For most
170*fae548d3Szrj    systems, this boundary is TARGET_PAGE_SIZE.  But for Linux, in the
171*fae548d3Szrj    time-honored tradition of crazy ZMAGIC hacks, it is 1024 which is
172*fae548d3Szrj    not what TARGET_PAGE_SIZE needs to be for QMAGIC.  */
173*fae548d3Szrj 
174*fae548d3Szrj #ifndef ZMAGIC_DISK_BLOCK_SIZE
175*fae548d3Szrj #define ZMAGIC_DISK_BLOCK_SIZE TARGET_PAGE_SIZE
176*fae548d3Szrj #endif
177*fae548d3Szrj 
178*fae548d3Szrj #define N_DISK_BLOCK_SIZE(x) \
179*fae548d3Szrj   (N_MAGIC(x) == ZMAGIC ? ZMAGIC_DISK_BLOCK_SIZE : TARGET_PAGE_SIZE)
180*fae548d3Szrj 
181*fae548d3Szrj /* Offset in an a.out of the start of the text section. */
182*fae548d3Szrj #ifndef N_TXTOFF
183*fae548d3Szrj #define N_TXTOFF(x)							\
184*fae548d3Szrj     (/* For {O,N,Q}MAGIC, no padding.  */				\
185*fae548d3Szrj      N_MAGIC (x) != ZMAGIC						\
186*fae548d3Szrj      ? EXEC_BYTES_SIZE							\
187*fae548d3Szrj      : (N_SHARED_LIB (x)						\
188*fae548d3Szrj 	? 0								\
189*fae548d3Szrj 	: (N_HEADER_IN_TEXT (x)						\
190*fae548d3Szrj 	   ? EXEC_BYTES_SIZE		/* No padding.  */		\
191*fae548d3Szrj 	   : ZMAGIC_DISK_BLOCK_SIZE	/* A page of padding.  */)))
192*fae548d3Szrj #endif
193*fae548d3Szrj /* Size of the text section.  It's always as stated, except that we
194*fae548d3Szrj    offset it to `undo' the adjustment to N_TXTADDR and N_TXTOFF
195*fae548d3Szrj    for ZMAGIC files that nominally include the exec header
196*fae548d3Szrj    as part of the first page of text.  (BFD doesn't consider the
197*fae548d3Szrj    exec header to be part of the text segment.)  */
198*fae548d3Szrj #ifndef N_TXTSIZE
199*fae548d3Szrj #define	N_TXTSIZE(x) \
200*fae548d3Szrj   (/* For QMAGIC, we don't consider the header part of the text section.  */\
201*fae548d3Szrj    N_IS_QMAGIC (x)							\
202*fae548d3Szrj    ? (x)->a_text - EXEC_BYTES_SIZE					\
203*fae548d3Szrj    : ((N_MAGIC (x) != ZMAGIC || N_SHARED_LIB (x))			\
204*fae548d3Szrj       ? (x)->a_text							\
205*fae548d3Szrj       : (N_HEADER_IN_TEXT (x)						\
206*fae548d3Szrj 	 ? (x)->a_text - EXEC_BYTES_SIZE	/* No padding.  */	\
207*fae548d3Szrj 	 : (x)->a_text				/* A page of padding.  */ )))
208*fae548d3Szrj #endif
209*fae548d3Szrj /* The address of the data segment in virtual memory.
210*fae548d3Szrj    It is the text segment address, plus text segment size, rounded
211*fae548d3Szrj    up to a N_SEGSIZE boundary for pure or pageable files.  */
212*fae548d3Szrj #ifndef N_DATADDR
213*fae548d3Szrj #define N_DATADDR(x) \
214*fae548d3Szrj   (N_MAGIC (x) == OMAGIC						\
215*fae548d3Szrj    ? (N_TXTADDR (x) + N_TXTSIZE (x))					\
216*fae548d3Szrj    : (N_SEGSIZE (x) + ((N_TXTADDR (x) + N_TXTSIZE (x) - 1)		\
217*fae548d3Szrj 		       & ~ (bfd_vma) (N_SEGSIZE (x) - 1))))
218*fae548d3Szrj #endif
219*fae548d3Szrj /* The address of the BSS segment -- immediately after the data segment.  */
220*fae548d3Szrj 
221*fae548d3Szrj #define N_BSSADDR(x)	(N_DATADDR (x) + (x)->a_data)
222*fae548d3Szrj 
223*fae548d3Szrj /* Offsets of the various portions of the file after the text segment.  */
224*fae548d3Szrj 
225*fae548d3Szrj /* For {Q,Z}MAGIC, there is padding to make the data segment start on
226*fae548d3Szrj    a page boundary.  Most of the time the a_text field (and thus
227*fae548d3Szrj    N_TXTSIZE) already contains this padding.  It is possible that for
228*fae548d3Szrj    BSDI and/or 386BSD it sometimes doesn't contain the padding, and
229*fae548d3Szrj    perhaps we should be adding it here.  But this seems kind of
230*fae548d3Szrj    questionable and probably should be BSDI/386BSD-specific if we do
231*fae548d3Szrj    do it.
232*fae548d3Szrj 
233*fae548d3Szrj    For NMAGIC (at least for hp300 BSD, probably others), there is
234*fae548d3Szrj    padding in memory only, not on disk, so we must *not* ever pad here
235*fae548d3Szrj    for NMAGIC.  */
236*fae548d3Szrj 
237*fae548d3Szrj #ifndef N_DATOFF
238*fae548d3Szrj #define N_DATOFF(x)	(N_TXTOFF (x) + N_TXTSIZE (x))
239*fae548d3Szrj #endif
240*fae548d3Szrj #ifndef N_TRELOFF
241*fae548d3Szrj #define N_TRELOFF(x)	(N_DATOFF (x) + (x)->a_data)
242*fae548d3Szrj #endif
243*fae548d3Szrj #ifndef N_DRELOFF
244*fae548d3Szrj #define N_DRELOFF(x)	(N_TRELOFF (x) + (x)->a_trsize)
245*fae548d3Szrj #endif
246*fae548d3Szrj #ifndef N_SYMOFF
247*fae548d3Szrj #define N_SYMOFF(x)	(N_DRELOFF (x) + (x)->a_drsize)
248*fae548d3Szrj #endif
249*fae548d3Szrj #ifndef N_STROFF
250*fae548d3Szrj #define N_STROFF(x)	(N_SYMOFF (x) + (x)->a_syms)
251*fae548d3Szrj #endif
252*fae548d3Szrj 
253*fae548d3Szrj /* Symbols */
254*fae548d3Szrj #ifndef external_nlist
255*fae548d3Szrj struct external_nlist
256*fae548d3Szrj {
257*fae548d3Szrj   bfd_byte e_strx[BYTES_IN_WORD];	/* Index into string table of name.  */
258*fae548d3Szrj   bfd_byte e_type[1];			/* Type of symbol.  */
259*fae548d3Szrj   bfd_byte e_other[1];			/* Misc info (usually empty).  */
260*fae548d3Szrj   bfd_byte e_desc[2];			/* Description field.  */
261*fae548d3Szrj   bfd_byte e_value[BYTES_IN_WORD];	/* Value of symbol.  */
262*fae548d3Szrj };
263*fae548d3Szrj #define EXTERNAL_NLIST_SIZE (BYTES_IN_WORD+4+BYTES_IN_WORD)
264*fae548d3Szrj #endif
265*fae548d3Szrj 
266*fae548d3Szrj struct internal_nlist
267*fae548d3Szrj {
268*fae548d3Szrj   unsigned long n_strx;			/* Index into string table of name.  */
269*fae548d3Szrj   unsigned char n_type;			/* Type of symbol.  */
270*fae548d3Szrj   unsigned char n_other;		/* Misc info (usually empty).  */
271*fae548d3Szrj   unsigned short n_desc;		/* Description field.  */
272*fae548d3Szrj   bfd_vma n_value;			/* Value of symbol.  */
273*fae548d3Szrj };
274*fae548d3Szrj 
275*fae548d3Szrj /* The n_type field is the symbol type, containing:  */
276*fae548d3Szrj 
277*fae548d3Szrj #define N_UNDF	0	/* Undefined symbol.  */
278*fae548d3Szrj #define N_ABS 	2	/* Absolute symbol -- defined at particular addr.  */
279*fae548d3Szrj #define N_TEXT 	4	/* Text sym -- defined at offset in text seg.  */
280*fae548d3Szrj #define N_DATA 	6	/* Data sym -- defined at offset in data seg.  */
281*fae548d3Szrj #define N_BSS 	8	/* BSS  sym -- defined at offset in zero'd seg.  */
282*fae548d3Szrj #define	N_COMM	0x12	/* Common symbol (visible after shared lib dynlink).  */
283*fae548d3Szrj #define N_FN	0x1f	/* File name of .o file.  */
284*fae548d3Szrj #define	N_FN_SEQ 0x0C	/* N_FN from Sequent compilers (sigh).  */
285*fae548d3Szrj /* Note: N_EXT can only be usefully OR-ed with N_UNDF, N_ABS, N_TEXT,
286*fae548d3Szrj    N_DATA, or N_BSS.  When the low-order bit of other types is set,
287*fae548d3Szrj    (e.g. N_WARNING versus N_FN), they are two different types.  */
288*fae548d3Szrj #define N_EXT 	1	/* External symbol (as opposed to local-to-this-file).  */
289*fae548d3Szrj #define N_TYPE  0x1e
290*fae548d3Szrj #define N_STAB 	0xe0	/* If any of these bits are on, it's a debug symbol.  */
291*fae548d3Szrj 
292*fae548d3Szrj #define N_INDR 0x0a
293*fae548d3Szrj 
294*fae548d3Szrj /* The following symbols refer to set elements.
295*fae548d3Szrj    All the N_SET[ATDB] symbols with the same name form one set.
296*fae548d3Szrj    Space is allocated for the set in the text section, and each set
297*fae548d3Szrj    elements value is stored into one word of the space.
298*fae548d3Szrj    The first word of the space is the length of the set (number of elements).
299*fae548d3Szrj 
300*fae548d3Szrj    The address of the set is made into an N_SETV symbol
301*fae548d3Szrj    whose name is the same as the name of the set.
302*fae548d3Szrj    This symbol acts like a N_DATA global symbol
303*fae548d3Szrj    in that it can satisfy undefined external references.  */
304*fae548d3Szrj 
305*fae548d3Szrj /* These appear as input to LD, in a .o file.  */
306*fae548d3Szrj #define	N_SETA	0x14		/* Absolute set element symbol.  */
307*fae548d3Szrj #define	N_SETT	0x16		/* Text set element symbol.  */
308*fae548d3Szrj #define	N_SETD	0x18		/* Data set element symbol.  */
309*fae548d3Szrj #define	N_SETB	0x1A		/* Bss set element symbol.  */
310*fae548d3Szrj 
311*fae548d3Szrj /* This is output from LD.  */
312*fae548d3Szrj #define N_SETV	0x1C		/* Pointer to set vector in data area.  */
313*fae548d3Szrj 
314*fae548d3Szrj /* Warning symbol. The text gives a warning message, the next symbol
315*fae548d3Szrj    in the table will be undefined. When the symbol is referenced, the
316*fae548d3Szrj    message is printed.  */
317*fae548d3Szrj 
318*fae548d3Szrj #define	N_WARNING 0x1e
319*fae548d3Szrj 
320*fae548d3Szrj /* Weak symbols.  These are a GNU extension to the a.out format.  The
321*fae548d3Szrj    semantics are those of ELF weak symbols.  Weak symbols are always
322*fae548d3Szrj    externally visible.  The N_WEAK? values are squeezed into the
323*fae548d3Szrj    available slots.  The value of a N_WEAKU symbol is 0.  The values
324*fae548d3Szrj    of the other types are the definitions.  */
325*fae548d3Szrj #define N_WEAKU	0x0d		/* Weak undefined symbol.  */
326*fae548d3Szrj #define N_WEAKA 0x0e		/* Weak absolute symbol.  */
327*fae548d3Szrj #define N_WEAKT 0x0f		/* Weak text symbol.  */
328*fae548d3Szrj #define N_WEAKD 0x10		/* Weak data symbol.  */
329*fae548d3Szrj #define N_WEAKB 0x11		/* Weak bss symbol.  */
330*fae548d3Szrj 
331*fae548d3Szrj /* Relocations
332*fae548d3Szrj 
333*fae548d3Szrj   There	are two types of relocation flavours for a.out systems,
334*fae548d3Szrj   standard and extended. The standard form is used on systems where the
335*fae548d3Szrj   instruction has room for all the bits of an offset to the operand, whilst
336*fae548d3Szrj   the extended form is used when an address operand has to be split over n
337*fae548d3Szrj   instructions. Eg, on the 68k, each move instruction can reference
338*fae548d3Szrj   the target with a displacement of 16 or 32 bits. On the sparc, move
339*fae548d3Szrj   instructions use an offset of 14 bits, so the offset is stored in
340*fae548d3Szrj   the reloc field, and the data in the section is ignored.  */
341*fae548d3Szrj 
342*fae548d3Szrj /* This structure describes a single relocation to be performed.
343*fae548d3Szrj    The text-relocation section of the file is a vector of these structures,
344*fae548d3Szrj    all of which apply to the text section.
345*fae548d3Szrj    Likewise, the data-relocation section applies to the data section.  */
346*fae548d3Szrj 
347*fae548d3Szrj struct reloc_std_external
348*fae548d3Szrj {
349*fae548d3Szrj   bfd_byte r_address[BYTES_IN_WORD];	/* Offset of data to relocate.  */
350*fae548d3Szrj   bfd_byte r_index[3];			/* Symbol table index of symbol.  */
351*fae548d3Szrj   bfd_byte r_type[1];			/* Relocation type.  */
352*fae548d3Szrj };
353*fae548d3Szrj 
354*fae548d3Szrj #define	RELOC_STD_BITS_PCREL_BIG	((unsigned int) 0x80)
355*fae548d3Szrj #define	RELOC_STD_BITS_PCREL_LITTLE	((unsigned int) 0x01)
356*fae548d3Szrj 
357*fae548d3Szrj #define	RELOC_STD_BITS_LENGTH_BIG	((unsigned int) 0x60)
358*fae548d3Szrj #define	RELOC_STD_BITS_LENGTH_SH_BIG	5
359*fae548d3Szrj #define	RELOC_STD_BITS_LENGTH_LITTLE	((unsigned int) 0x06)
360*fae548d3Szrj #define	RELOC_STD_BITS_LENGTH_SH_LITTLE	1
361*fae548d3Szrj 
362*fae548d3Szrj #define	RELOC_STD_BITS_EXTERN_BIG	((unsigned int) 0x10)
363*fae548d3Szrj #define	RELOC_STD_BITS_EXTERN_LITTLE	((unsigned int) 0x08)
364*fae548d3Szrj 
365*fae548d3Szrj #define	RELOC_STD_BITS_BASEREL_BIG	((unsigned int) 0x08)
366*fae548d3Szrj #define	RELOC_STD_BITS_BASEREL_LITTLE	((unsigned int) 0x10)
367*fae548d3Szrj 
368*fae548d3Szrj #define	RELOC_STD_BITS_JMPTABLE_BIG	((unsigned int) 0x04)
369*fae548d3Szrj #define	RELOC_STD_BITS_JMPTABLE_LITTLE	((unsigned int) 0x20)
370*fae548d3Szrj 
371*fae548d3Szrj #define	RELOC_STD_BITS_RELATIVE_BIG	((unsigned int) 0x02)
372*fae548d3Szrj #define	RELOC_STD_BITS_RELATIVE_LITTLE	((unsigned int) 0x40)
373*fae548d3Szrj 
374*fae548d3Szrj #define	RELOC_STD_SIZE	(BYTES_IN_WORD + 3 + 1)		/* Bytes per relocation entry.  */
375*fae548d3Szrj 
376*fae548d3Szrj struct reloc_std_internal
377*fae548d3Szrj {
378*fae548d3Szrj   bfd_vma r_address;		/* Address (within segment) to be relocated.  */
379*fae548d3Szrj   /* The meaning of r_symbolnum depends on r_extern.  */
380*fae548d3Szrj   unsigned int r_symbolnum:24;
381*fae548d3Szrj   /* Nonzero means value is a pc-relative offset
382*fae548d3Szrj      and it should be relocated for changes in its own address
383*fae548d3Szrj      as well as for changes in the symbol or section specified.  */
384*fae548d3Szrj   unsigned int r_pcrel:1;
385*fae548d3Szrj   /* Length (as exponent of 2) of the field to be relocated.
386*fae548d3Szrj      Thus, a value of 2 indicates 1<<2 bytes.  */
387*fae548d3Szrj   unsigned int r_length:2;
388*fae548d3Szrj   /* 1 => relocate with value of symbol.
389*fae548d3Szrj      r_symbolnum is the index of the symbol
390*fae548d3Szrj      in files the symbol table.
391*fae548d3Szrj      0 => relocate with the address of a segment.
392*fae548d3Szrj      r_symbolnum is N_TEXT, N_DATA, N_BSS or N_ABS
393*fae548d3Szrj      (the N_EXT bit may be set also, but signifies nothing).  */
394*fae548d3Szrj   unsigned int r_extern:1;
395*fae548d3Szrj   /* The next three bits are for SunOS shared libraries, and seem to
396*fae548d3Szrj      be undocumented.  */
397*fae548d3Szrj   unsigned int r_baserel:1;	/* Linkage table relative.  */
398*fae548d3Szrj   unsigned int r_jmptable:1;	/* pc-relative to jump table.  */
399*fae548d3Szrj   unsigned int r_relative:1;	/* "relative relocation".  */
400*fae548d3Szrj   /* unused */
401*fae548d3Szrj   unsigned int r_pad:1;		/* Padding -- set to zero.  */
402*fae548d3Szrj };
403*fae548d3Szrj 
404*fae548d3Szrj 
405*fae548d3Szrj /* EXTENDED RELOCS.   */
406*fae548d3Szrj 
407*fae548d3Szrj struct reloc_ext_external
408*fae548d3Szrj {
409*fae548d3Szrj   bfd_byte r_address[BYTES_IN_WORD];	/* Offset of data to relocate.  */
410*fae548d3Szrj   bfd_byte r_index[3];			/* Symbol table index of symbol.  */
411*fae548d3Szrj   bfd_byte r_type[1];			/* Relocation type.  */
412*fae548d3Szrj   bfd_byte r_addend[BYTES_IN_WORD];	/* Datum addend.  */
413*fae548d3Szrj };
414*fae548d3Szrj 
415*fae548d3Szrj #ifndef RELOC_EXT_BITS_EXTERN_BIG
416*fae548d3Szrj #define	RELOC_EXT_BITS_EXTERN_BIG	((unsigned int) 0x80)
417*fae548d3Szrj #endif
418*fae548d3Szrj 
419*fae548d3Szrj #ifndef RELOC_EXT_BITS_EXTERN_LITTLE
420*fae548d3Szrj #define	RELOC_EXT_BITS_EXTERN_LITTLE	((unsigned int) 0x01)
421*fae548d3Szrj #endif
422*fae548d3Szrj 
423*fae548d3Szrj #ifndef RELOC_EXT_BITS_TYPE_BIG
424*fae548d3Szrj #define	RELOC_EXT_BITS_TYPE_BIG		((unsigned int) 0x1F)
425*fae548d3Szrj #endif
426*fae548d3Szrj 
427*fae548d3Szrj #ifndef RELOC_EXT_BITS_TYPE_SH_BIG
428*fae548d3Szrj #define	RELOC_EXT_BITS_TYPE_SH_BIG	0
429*fae548d3Szrj #endif
430*fae548d3Szrj 
431*fae548d3Szrj #ifndef RELOC_EXT_BITS_TYPE_LITTLE
432*fae548d3Szrj #define	RELOC_EXT_BITS_TYPE_LITTLE	((unsigned int) 0xF8)
433*fae548d3Szrj #endif
434*fae548d3Szrj 
435*fae548d3Szrj #ifndef RELOC_EXT_BITS_TYPE_SH_LITTLE
436*fae548d3Szrj #define	RELOC_EXT_BITS_TYPE_SH_LITTLE	3
437*fae548d3Szrj #endif
438*fae548d3Szrj 
439*fae548d3Szrj /* Bytes per relocation entry.  */
440*fae548d3Szrj #define	RELOC_EXT_SIZE	(BYTES_IN_WORD + 3 + 1 + BYTES_IN_WORD)
441*fae548d3Szrj 
442*fae548d3Szrj enum reloc_type
443*fae548d3Szrj {
444*fae548d3Szrj   /* Simple relocations.  */
445*fae548d3Szrj   RELOC_8,			/* data[0:7] = addend + sv 		*/
446*fae548d3Szrj   RELOC_16,			/* data[0:15] = addend + sv 		*/
447*fae548d3Szrj   RELOC_32,			/* data[0:31] = addend + sv 		*/
448*fae548d3Szrj   /* PC-rel displacement.  */
449*fae548d3Szrj   RELOC_DISP8,			/* data[0:7] = addend - pc + sv 	*/
450*fae548d3Szrj   RELOC_DISP16,			/* data[0:15] = addend - pc + sv 	*/
451*fae548d3Szrj   RELOC_DISP32,			/* data[0:31] = addend - pc + sv 	*/
452*fae548d3Szrj   /* Special.  */
453*fae548d3Szrj   RELOC_WDISP30,		/* data[0:29] = (addend + sv - pc)>>2 	*/
454*fae548d3Szrj   RELOC_WDISP22,		/* data[0:21] = (addend + sv - pc)>>2 	*/
455*fae548d3Szrj   RELOC_HI22,			/* data[0:21] = (addend + sv)>>10 	*/
456*fae548d3Szrj   RELOC_22,			/* data[0:21] = (addend + sv) 		*/
457*fae548d3Szrj   RELOC_13,			/* data[0:12] = (addend + sv)		*/
458*fae548d3Szrj   RELOC_LO10,			/* data[0:9] = (addend + sv)		*/
459*fae548d3Szrj   RELOC_SFA_BASE,
460*fae548d3Szrj   RELOC_SFA_OFF13,
461*fae548d3Szrj   /* P.I.C. (base-relative).  */
462*fae548d3Szrj   RELOC_BASE10,  		/* Not sure - maybe we can do this the */
463*fae548d3Szrj   RELOC_BASE13,			/* right way now */
464*fae548d3Szrj   RELOC_BASE22,
465*fae548d3Szrj   /* For some sort of pc-rel P.I.C. (?)  */
466*fae548d3Szrj   RELOC_PC10,
467*fae548d3Szrj   RELOC_PC22,
468*fae548d3Szrj   /* P.I.C. jump table.  */
469*fae548d3Szrj   RELOC_JMP_TBL,
470*fae548d3Szrj   /* Reputedly for shared libraries somehow.  */
471*fae548d3Szrj   RELOC_SEGOFF16,
472*fae548d3Szrj   RELOC_GLOB_DAT,
473*fae548d3Szrj   RELOC_JMP_SLOT,
474*fae548d3Szrj   RELOC_RELATIVE,
475*fae548d3Szrj 
476*fae548d3Szrj   RELOC_11,
477*fae548d3Szrj   RELOC_WDISP2_14,
478*fae548d3Szrj   RELOC_WDISP19,
479*fae548d3Szrj 
480*fae548d3Szrj   NO_RELOC
481*fae548d3Szrj   };
482*fae548d3Szrj 
483*fae548d3Szrj 
484*fae548d3Szrj struct reloc_internal
485*fae548d3Szrj {
486*fae548d3Szrj   bfd_vma r_address;		/* Offset of data to relocate.  */
487*fae548d3Szrj   long	r_index;		/* Symbol table index of symbol.  */
488*fae548d3Szrj   enum reloc_type r_type;	/* Relocation type.  */
489*fae548d3Szrj   bfd_vma r_addend;		/* Datum addend.  */
490*fae548d3Szrj };
491*fae548d3Szrj 
492*fae548d3Szrj /* Q.
493*fae548d3Szrj    Should the length of the string table be 4 bytes or 8 bytes ?
494*fae548d3Szrj 
495*fae548d3Szrj    Q.
496*fae548d3Szrj    What about archive indexes ?  */
497*fae548d3Szrj 
498*fae548d3Szrj #endif				/* __A_OUT_64_H__ */
499