xref: /linux-6.15/include/uapi/linux/a.out.h (revision 53c2bd67)
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 #ifndef _UAPI__A_OUT_GNU_H__
3 #define _UAPI__A_OUT_GNU_H__
4 
5 #define __GNU_EXEC_MACROS__
6 
7 #ifndef __STRUCT_EXEC_OVERRIDE__
8 
9 #include <asm/a.out.h>
10 
11 #endif /* __STRUCT_EXEC_OVERRIDE__ */
12 
13 #ifndef __ASSEMBLY__
14 
15 /* these go in the N_MACHTYPE field */
16 enum machine_type {
17 #if defined (M_OLDSUN2)
18   M__OLDSUN2 = M_OLDSUN2,
19 #else
20   M_OLDSUN2 = 0,
21 #endif
22 #if defined (M_68010)
23   M__68010 = M_68010,
24 #else
25   M_68010 = 1,
26 #endif
27 #if defined (M_68020)
28   M__68020 = M_68020,
29 #else
30   M_68020 = 2,
31 #endif
32 #if defined (M_SPARC)
33   M__SPARC = M_SPARC,
34 #else
35   M_SPARC = 3,
36 #endif
37   /* skip a bunch so we don't run into any of sun's numbers */
38   M_386 = 100,
39   M_MIPS1 = 151,	/* MIPS R3000/R3000 binary */
40   M_MIPS2 = 152		/* MIPS R6000/R4000 binary */
41 };
42 
43 #if !defined (N_MAGIC)
44 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
45 #endif
46 #define N_MACHTYPE(exec) ((enum machine_type)(((exec).a_info >> 16) & 0xff))
47 #define N_FLAGS(exec) (((exec).a_info >> 24) & 0xff)
48 #define N_SET_INFO(exec, magic, type, flags) \
49 	((exec).a_info = ((magic) & 0xffff) \
50 	 | (((int)(type) & 0xff) << 16) \
51 	 | (((flags) & 0xff) << 24))
52 #define N_SET_MAGIC(exec, magic) \
53 	((exec).a_info = (((exec).a_info & 0xffff0000) | ((magic) & 0xffff)))
54 
55 #define N_SET_MACHTYPE(exec, machtype) \
56 	((exec).a_info = \
57 	 ((exec).a_info&0xff00ffff) | ((((int)(machtype))&0xff) << 16))
58 
59 #define N_SET_FLAGS(exec, flags) \
60 	((exec).a_info = \
61 	 ((exec).a_info&0x00ffffff) | (((flags) & 0xff) << 24))
62 
63 /* Code indicating object file or impure executable.  */
64 #define OMAGIC 0407
65 /* Code indicating pure executable.  */
66 #define NMAGIC 0410
67 /* Code indicating demand-paged executable.  */
68 #define ZMAGIC 0413
69 /* This indicates a demand-paged executable with the header in the text.
70    The first page is unmapped to help trap NULL pointer references */
71 #define QMAGIC 0314
72 
73 #if !defined (N_BADMAG)
74 #define N_BADMAG(x)	  (N_MAGIC(x) != OMAGIC		\
75 			&& N_MAGIC(x) != NMAGIC		\
76   			&& N_MAGIC(x) != ZMAGIC \
77 		        && N_MAGIC(x) != QMAGIC)
78 #endif
79 
80 #define _N_HDROFF(x) (1024 - sizeof (struct exec))
81 
82 #if !defined (N_TXTOFF)
83 #define N_TXTOFF(x) \
84  (N_MAGIC(x) == ZMAGIC ? _N_HDROFF((x)) + sizeof (struct exec) : \
85   (N_MAGIC(x) == QMAGIC ? 0 : sizeof (struct exec)))
86 #endif
87 
88 #if !defined (N_DATOFF)
89 #define N_DATOFF(x) (N_TXTOFF(x) + (x).a_text)
90 #endif
91 
92 #if !defined (N_TRELOFF)
93 #define N_TRELOFF(x) (N_DATOFF(x) + (x).a_data)
94 #endif
95 
96 #if !defined (N_DRELOFF)
97 #define N_DRELOFF(x) (N_TRELOFF(x) + N_TRSIZE(x))
98 #endif
99 
100 #if !defined (N_SYMOFF)
101 #define N_SYMOFF(x) (N_DRELOFF(x) + N_DRSIZE(x))
102 #endif
103 
104 #if !defined (N_STROFF)
105 #define N_STROFF(x) (N_SYMOFF(x) + N_SYMSIZE(x))
106 #endif
107 
108 /* Address of text segment in memory after it is loaded.  */
109 #if !defined (N_TXTADDR)
110 #define N_TXTADDR(x) (N_MAGIC(x) == QMAGIC ? PAGE_SIZE : 0)
111 #endif
112 
113 /* Address of data segment in memory after it is loaded. */
114 #ifndef __KERNEL__
115 #include <unistd.h>
116 #endif
117 #if defined(__i386__) || defined(__mc68000__)
118 #define SEGMENT_SIZE	1024
119 #else
120 #ifndef SEGMENT_SIZE
121 #ifndef __KERNEL__
122 #define SEGMENT_SIZE   getpagesize()
123 #endif
124 #endif
125 #endif
126 
127 #define _N_SEGMENT_ROUND(x) ALIGN(x, SEGMENT_SIZE)
128 
129 #define _N_TXTENDADDR(x) (N_TXTADDR(x)+(x).a_text)
130 
131 #ifndef N_DATADDR
132 #define N_DATADDR(x) \
133     (N_MAGIC(x)==OMAGIC? (_N_TXTENDADDR(x)) \
134      : (_N_SEGMENT_ROUND (_N_TXTENDADDR(x))))
135 #endif
136 
137 /* Address of bss segment in memory after it is loaded.  */
138 #if !defined (N_BSSADDR)
139 #define N_BSSADDR(x) (N_DATADDR(x) + (x).a_data)
140 #endif
141 
142 #if !defined (N_NLIST_DECLARED)
143 struct nlist {
144   union {
145     char *n_name;
146     struct nlist *n_next;
147     long n_strx;
148   } n_un;
149   unsigned char n_type;
150   char n_other;
151   short n_desc;
152   unsigned long n_value;
153 };
154 #endif /* no N_NLIST_DECLARED.  */
155 
156 #if !defined (N_UNDF)
157 #define N_UNDF 0
158 #endif
159 #if !defined (N_ABS)
160 #define N_ABS 2
161 #endif
162 #if !defined (N_TEXT)
163 #define N_TEXT 4
164 #endif
165 #if !defined (N_DATA)
166 #define N_DATA 6
167 #endif
168 #if !defined (N_BSS)
169 #define N_BSS 8
170 #endif
171 #if !defined (N_FN)
172 #define N_FN 15
173 #endif
174 
175 #if !defined (N_EXT)
176 #define N_EXT 1
177 #endif
178 #if !defined (N_TYPE)
179 #define N_TYPE 036
180 #endif
181 #if !defined (N_STAB)
182 #define N_STAB 0340
183 #endif
184 
185 /* The following type indicates the definition of a symbol as being
186    an indirect reference to another symbol.  The other symbol
187    appears as an undefined reference, immediately following this symbol.
188 
189    Indirection is asymmetrical.  The other symbol's value will be used
190    to satisfy requests for the indirect symbol, but not vice versa.
191    If the other symbol does not have a definition, libraries will
192    be searched to find a definition.  */
193 #define N_INDR 0xa
194 
195 /* The following symbols refer to set elements.
196    All the N_SET[ATDB] symbols with the same name form one set.
197    Space is allocated for the set in the text section, and each set
198    element's value is stored into one word of the space.
199    The first word of the space is the length of the set (number of elements).
200 
201    The address of the set is made into an N_SETV symbol
202    whose name is the same as the name of the set.
203    This symbol acts like a N_DATA global symbol
204    in that it can satisfy undefined external references.  */
205 
206 /* These appear as input to LD, in a .o file.  */
207 #define	N_SETA	0x14		/* Absolute set element symbol */
208 #define	N_SETT	0x16		/* Text set element symbol */
209 #define	N_SETD	0x18		/* Data set element symbol */
210 #define	N_SETB	0x1A		/* Bss set element symbol */
211 
212 /* This is output from LD.  */
213 #define N_SETV	0x1C		/* Pointer to set vector in data area.  */
214 
215 #if !defined (N_RELOCATION_INFO_DECLARED)
216 /* This structure describes a single relocation to be performed.
217    The text-relocation section of the file is a vector of these structures,
218    all of which apply to the text section.
219    Likewise, the data-relocation section applies to the data section.  */
220 
221 struct relocation_info
222 {
223   /* Address (within segment) to be relocated.  */
224   int r_address;
225   /* The meaning of r_symbolnum depends on r_extern.  */
226   unsigned int r_symbolnum:24;
227   /* Nonzero means value is a pc-relative offset
228      and it should be relocated for changes in its own address
229      as well as for changes in the symbol or section specified.  */
230   unsigned int r_pcrel:1;
231   /* Length (as exponent of 2) of the field to be relocated.
232      Thus, a value of 2 indicates 1<<2 bytes.  */
233   unsigned int r_length:2;
234   /* 1 => relocate with value of symbol.
235           r_symbolnum is the index of the symbol
236 	  in file's the symbol table.
237      0 => relocate with the address of a segment.
238           r_symbolnum is N_TEXT, N_DATA, N_BSS or N_ABS
239 	  (the N_EXT bit may be set also, but signifies nothing).  */
240   unsigned int r_extern:1;
241   /* Four bits that aren't used, but when writing an object file
242      it is desirable to clear them.  */
243   unsigned int r_pad:4;
244 };
245 #endif /* no N_RELOCATION_INFO_DECLARED.  */
246 
247 #endif /*__ASSEMBLY__ */
248 #endif /* _UAPI__A_OUT_GNU_H__ */
249