revert between 56095 -> 55830 in arch
[AROS.git] / compiler / include / dos / elf.h
blob9a40879246c96524b333dc74b84ae480067efb4a
1 #ifndef DOS_ELF_H
2 #define DOS_ELF_H
4 /*
5 Copyright (C) 1995-2019, The AROS Development Team. All rights reserved.
6 $Id$
8 Desc: Definition of ELF file structures.
9 Lang: english
12 #include <exec/types.h>
15 * Define one of ELF_64BIT or ELF_32BIT in your code if you want to enforce specific
16 * version of ELF structures. Otherwize it fails back to your native machine's size.
18 #ifdef ELF_64BIT
19 #define elf_ptr_t UQUAD
20 #define elf_uintptr_t UQUAD
21 #define elf_intptr_t QUAD
22 #endif
24 #ifdef ELF_32BIT
25 #define elf_ptr_t ULONG
26 #define elf_uintptr_t ULONG
27 #define elf_intptr_t LONG
28 #endif
30 #ifndef elf_ptr_t
31 #define elf_ptr_t APTR
32 #define elf_uintptr_t IPTR
33 #define elf_intptr_t SIPTR
35 #if (__WORDSIZE == 64)
36 #define ELF_64BIT
37 #endif
39 #endif
41 #define SHT_PROGBITS 1
42 #define SHT_SYMTAB 2
43 #define SHT_STRTAB 3
44 #define SHT_RELA 4
45 #define SHT_NOBITS 8
46 #define SHT_REL 9
47 #define SHT_SYMTAB_SHNDX 18
48 #define SHT_ARM_ATTRIBUTES 0x70000003
50 #define ET_REL 1
51 #define ET_EXEC 2
53 #define EM_386 3
54 #define EM_68K 4
55 #define EM_PPC 20
56 #define EM_ARM 40
57 #define EM_X86_64 62 /* AMD x86-64 */
59 #define R_386_NONE 0
60 #define R_386_32 1
61 #define R_386_PC32 2
63 /* AMD x86-64 relocations. */
64 #define R_X86_64_NONE 0 /* No reloc */
65 #define R_X86_64_64 1 /* Direct 64 bit */
66 #define R_X86_64_PC32 2 /* PC relative 32 bit signed */
67 #define R_X86_64_PLT32 4
68 #define R_X86_64_32 10
69 #define R_X86_64_32S 11
71 #define R_68K_NONE 0
72 #define R_68K_32 1
73 #define R_68K_16 2
74 #define R_68K_8 3
75 #define R_68K_PC32 4
76 #define R_68K_PC16 5
77 #define R_68K_PC8 6
79 #define R_PPC_NONE 0
80 #define R_PPC_ADDR32 1
81 #define R_PPC_ADDR16_LO 4
82 #define R_PPC_ADDR16_HA 6
83 #define R_PPC_REL24 10
84 #define R_PPC_REL32 26
85 #define R_PPC_REL16_LO 250
86 #define R_PPC_REL16_HA 252
88 #define R_ARM_NONE 0
89 #define R_ARM_PC24 1
90 #define R_ARM_ABS32 2
91 #define R_ARM_CALL 28
92 #define R_ARM_JUMP24 29
93 #define R_ARM_TARGET1 38
94 #define R_ARM_V4BX 40
95 #define R_ARM_TARGET2 41
96 #define R_ARM_PREL31 42
97 #define R_ARM_MOVW_ABS_NC 43
98 #define R_ARM_MOVT_ABS 44
99 #define R_ARM_THM_CALL 10
100 #define R_ARM_THM_JUMP24 30
101 #define R_ARM_THM_MOVW_ABS_NC 47
102 #define R_ARM_THM_MOVT_ABS 48
104 #define STT_NOTYPE 0
105 #define STT_OBJECT 1
106 #define STT_FUNC 2
107 #define STT_SECTION 3
108 #define STT_FILE 4
109 #define STT_LOPROC 13
110 #define STT_HIPROC 15
112 #define STB_LOCAL 0
113 #define STB_GLOBAL 1
114 #define STB_WEAK 2
115 #define STB_LOOS 10
116 #define STB_GNU_UNIQUE 10
117 #define STB_HIOS 12
118 #define STB_LOPROC 13
119 #define STB_HIPROC 15
121 #define SHN_UNDEF 0
122 #define SHN_LORESERVE 0xff00
123 #define SHN_ABS 0xfff1
124 #define SHN_COMMON 0xfff2
125 #define SHN_XINDEX 0xffff
126 #define SHN_HIRESERVE 0xffff
128 #define SHF_WRITE (1 << 0)
129 #define SHF_ALLOC (1 << 1)
130 #define SHF_EXECINSTR (1 << 2)
132 #define ELF_ST_TYPE(i) ((i) & 0x0F)
134 #define EI_VERSION 6
135 #define EV_CURRENT 1
137 #define EI_DATA 5
138 #define ELFDATA2LSB 1
139 #define ELFDATA2MSB 2
141 #define EI_CLASS 4
142 #define ELFCLASS32 1
143 #define ELFCLASS64 2 /* 64-bit objects */
145 #define EI_OSABI 7
146 #define EI_ABIVERSION 8
148 #define ELFOSABI_AROS 15
150 #define PF_X (1 << 0)
152 struct elfheader
154 UBYTE ident[16];
155 UWORD type;
156 UWORD machine;
157 ULONG version;
158 elf_ptr_t entry;
159 elf_uintptr_t phoff;
160 elf_uintptr_t shoff;
161 ULONG flags;
162 UWORD ehsize;
163 UWORD phentsize;
164 UWORD phnum;
165 UWORD shentsize;
166 UWORD shnum;
167 UWORD shstrndx;
170 struct sheader
172 ULONG name;
173 ULONG type;
174 elf_uintptr_t flags;
175 elf_ptr_t addr;
176 elf_uintptr_t offset;
177 elf_uintptr_t size;
178 ULONG link;
179 ULONG info;
180 elf_uintptr_t addralign;
181 elf_uintptr_t entsize;
184 #define PT_LOAD 1
186 #ifdef ELF_64BIT
188 struct pheader
190 ULONG type;
191 ULONG flags;
192 elf_uintptr_t offset;
193 elf_ptr_t vaddr;
194 elf_ptr_t paddr;
195 elf_uintptr_t filesz;
196 elf_uintptr_t memsz;
197 elf_uintptr_t align;
200 struct symbol
202 ULONG name; /* Offset of the name string in the string table */
203 UBYTE info; /* What kind of symbol is this ? (global, variable, etc) */
204 UBYTE other; /* undefined */
205 UWORD shindex; /* In which section is the symbol defined ? */
206 elf_uintptr_t value; /* Varies; eg. the offset of the symbol in its hunk */
207 elf_uintptr_t size; /* How much memory does the symbol occupy */
210 #define ELF_R_SYM(i) (ULONG)((i) >> 32)
211 #define ELF_R_TYPE(i) (ULONG)((i) & 0xffffffffULL)
212 #define ELF_R_INFO(sym, type) (((UQUAD)(sym) << 32) + (type))
214 #else
216 struct pheader
218 ULONG type;
219 ULONG offset;
220 elf_ptr_t vaddr;
221 elf_ptr_t paddr;
222 ULONG filesz;
223 ULONG memsz;
224 ULONG flags;
225 ULONG align;
228 struct symbol
230 ULONG name; /* Offset of the name string in the string table */
231 elf_uintptr_t value; /* Varies; eg. the offset of the symbol in its hunk */
232 elf_uintptr_t size; /* How much memory does the symbol occupy */
233 UBYTE info; /* What kind of symbol is this ? (global, variable, etc) */
234 UBYTE other; /* undefined */
235 UWORD shindex; /* In which section is the symbol defined ? */
238 #define ELF_R_SYM(val) ((val) >> 8)
239 #define ELF_R_TYPE(val) ((val) & 0xff)
240 #define ELF_R_INFO(sym, type) (((sym) << 8) + ((type) & 0xff))
242 #endif
244 #define ELF_S_BIND(val) ((val) >> 4)
245 #define ELF_S_TYPE(val) ((val) & 0xF)
246 #define ELF_S_INFO(bind, type) (((bind) << 4) + ((type) & 0xF))
248 struct rel
250 elf_uintptr_t offset; /* Address of the relocation relative to the section it refers to */
251 elf_uintptr_t info; /* Type of the relocation */
254 struct rela
256 elf_uintptr_t offset; /* Address of the relocation relative to the section it refers to */
257 elf_uintptr_t info; /* Type of the relocation */
258 elf_intptr_t addend; /* Constant addend used to compute value */
261 /* Note: the conversion below is not in line with ELF specification and is fixed in GNU binutils since 2008
262 * See: https://sourceware.org/bugzilla/show_bug.cgi?id=5900
264 /* convert section header number to array index */
265 /*#define SHINDEX(n) \
266 ((n) < SHN_LORESERVE ? (n) : ((n) <= SHN_HIRESERVE ? 0 : (n) - (SHN_HIRESERVE + 1 - SHN_LORESERVE)))*/
268 /* convert section header array index to section number */
269 /*#define SHNUM(i) \
270 ((i) < SHN_LORESERVE ? (i) : (i) + (SHN_HIRESERVE + 1 - SHN_LORESERVE))*/
272 /* ARM-specific attributes section definitions follow */
274 #define ATTR_VERSION_CURRENT 0x41
276 struct attrs_section
278 ULONG size;
279 char vendor[1]; /* NULL-terminated name */
280 /* Vendor-specific subsections follow */
283 struct attrs_subsection
285 UBYTE tag;
286 ULONG size;
287 } __attribute__((packed));
289 #define Tag_File 1
290 #define Tag_Section 2
291 #define Tag_Symbol 3
292 #define Tag_CPU_raw_name 4
293 #define Tag_CPU_name 5
294 #define Tag_CPU_arch 6
295 #define Tag_FP_arch 10
296 #define Tag_compatibility 32
297 #define Tag_also_compatible_with 65
298 #define Tag_conformance 67
300 /* Tag_CPU_arch values */
301 #define ELF_CPU_PREv4 0
302 #define ELF_CPU_ARMv4 1
303 #define ELF_CPU_ARMv4T 2
304 #define ELF_CPU_ARMv5T 3
305 #define ELF_CPU_ARMv5TE 4
306 #define ELF_CPU_ARMv5TEJ 5
307 #define ELF_CPU_ARMv6 6
308 #define ELF_CPU_ARMv6KZ 7
309 #define ELF_CPU_ARMv6T2 8
310 #define ELF_CPU_ARMv6K 9
311 #define ELF_CPU_ARMv7 10
312 #define ELF_CPU_ARM_v6M 11
313 #define ELF_CPU_ARMv6SM 12
314 #define ELF_CPU_ARMv7EM 13
316 /* Tag_FP_arch values */
317 #define ELF_FP_None 0
318 #define ELF_FP_v1 1
319 #define ELF_FP_v2 2
320 #define ELF_FP_v3 3
321 #define ELF_FP_v3_Short 4
322 #define ELF_FP_v4 5
323 #define ELF_FP_v4_Short 6
325 /* Machine's native values */
326 #ifdef ELF_64BIT
327 #define AROS_ELF_CLASS ELFCLASS64
328 #else
329 #define AROS_ELF_CLASS ELFCLASS32
330 #endif
332 #if AROS_BIG_ENDIAN
333 #define AROS_ELF_DATA ELFDATA2MSB
334 #else
335 #define AROS_ELF_DATA ELFDATA2LSB
336 #endif
338 #if defined(__i386__) || defined(__x86_64__)
339 #ifdef ELF_64BIT
340 #define AROS_ELF_MACHINE EM_X86_64
341 #define AROS_ELF_REL SHT_RELA
342 #define relo rela
343 #else
344 #define AROS_ELF_MACHINE EM_386
345 #define AROS_ELF_REL SHT_REL
346 #define relo rel
347 #endif
348 #endif
349 #ifdef __mc68000__
350 #define AROS_ELF_MACHINE EM_68K
351 #define AROS_ELF_REL SHT_RELA
352 #define relo rela
353 #endif
354 #ifdef __powerpc__
355 #define AROS_ELF_MACHINE EM_PPC
356 #define AROS_ELF_REL SHT_RELA
357 #define relo rela
358 #endif
359 #ifdef __arm__
360 #define AROS_ELF_MACHINE EM_ARM
361 #define AROS_ELF_REL SHT_RELA
362 #define relo rela
363 #endif
365 #endif