Fixed compatibility of output.
[AROS.git] / compiler / include / dos / elf.h
blob7ed20a387ccb87e504197ef11e5b1349b6bea2bf
1 #ifndef DOS_ELF_H
2 #define DOS_ELF_H
4 /*
5 Copyright © 1995-2011, 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_32 10
68 #define R_X86_64_32S 11
70 #define R_68K_NONE 0
71 #define R_68K_32 1
72 #define R_68K_16 2
73 #define R_68K_8 3
74 #define R_68K_PC32 4
75 #define R_68K_PC16 5
76 #define R_68K_PC8 6
78 #define R_PPC_NONE 0
79 #define R_PPC_ADDR32 1
80 #define R_PPC_ADDR16_LO 4
81 #define R_PPC_ADDR16_HA 6
82 #define R_PPC_REL24 10
83 #define R_PPC_REL32 26
84 #define R_PPC_REL16_LO 250
85 #define R_PPC_REL16_HA 252
87 #define R_ARM_NONE 0
88 #define R_ARM_PC24 1
89 #define R_ARM_ABS32 2
90 #define R_ARM_CALL 28
91 #define R_ARM_JUMP24 29
92 #define R_ARM_TARGET1 38
93 #define R_ARM_V4BX 40
94 #define R_ARM_TARGET2 41
95 #define R_ARM_PREL31 42
96 #define R_ARM_MOVW_ABS_NC 43
97 #define R_ARM_MOVT_ABS 44
98 #define R_ARM_THM_CALL 10
99 #define R_ARM_THM_JUMP24 30
100 #define R_ARM_THM_MOVW_ABS_NC 47
101 #define R_ARM_THM_MOVT_ABS 48
103 #define STT_NOTYPE 0
104 #define STT_OBJECT 1
105 #define STT_FUNC 2
106 #define STT_SECTION 3
107 #define STT_FILE 4
108 #define STT_LOPROC 13
109 #define STT_HIPROC 15
111 #define STB_LOCAL 0
112 #define STB_GLOBAL 1
113 #define STB_WEAK 2
114 #define STB_LOOS 10
115 #define STB_GNU_UNIQUE 10
116 #define STB_HIOS 12
117 #define STB_LOPROC 13
118 #define STB_HIPROC 15
120 #define SHN_UNDEF 0
121 #define SHN_LORESERVE 0xff00
122 #define SHN_ABS 0xfff1
123 #define SHN_COMMON 0xfff2
124 #define SHN_XINDEX 0xffff
125 #define SHN_HIRESERVE 0xffff
127 #define SHF_WRITE (1 << 0)
128 #define SHF_ALLOC (1 << 1)
129 #define SHF_EXECINSTR (1 << 2)
131 #define ELF_ST_TYPE(i) ((i) & 0x0F)
133 #define EI_VERSION 6
134 #define EV_CURRENT 1
136 #define EI_DATA 5
137 #define ELFDATA2LSB 1
138 #define ELFDATA2MSB 2
140 #define EI_CLASS 4
141 #define ELFCLASS32 1
142 #define ELFCLASS64 2 /* 64-bit objects */
144 #define EI_OSABI 7
145 #define EI_ABIVERSION 8
147 #define ELFOSABI_AROS 15
149 #define PF_X (1 << 0)
151 struct elfheader
153 UBYTE ident[16];
154 UWORD type;
155 UWORD machine;
156 ULONG version;
157 elf_ptr_t entry;
158 elf_uintptr_t phoff;
159 elf_uintptr_t shoff;
160 ULONG flags;
161 UWORD ehsize;
162 UWORD phentsize;
163 UWORD phnum;
164 UWORD shentsize;
165 UWORD shnum;
166 UWORD shstrndx;
169 struct sheader
171 ULONG name;
172 ULONG type;
173 elf_uintptr_t flags;
174 elf_ptr_t addr;
175 elf_uintptr_t offset;
176 elf_uintptr_t size;
177 ULONG link;
178 ULONG info;
179 elf_uintptr_t addralign;
180 elf_uintptr_t entsize;
183 #define PT_LOAD 1
185 #ifdef ELF_64BIT
187 struct pheader
189 ULONG type;
190 ULONG flags;
191 elf_uintptr_t offset;
192 elf_ptr_t vaddr;
193 elf_ptr_t paddr;
194 elf_uintptr_t filesz;
195 elf_uintptr_t memsz;
196 elf_uintptr_t align;
199 struct symbol
201 ULONG name; /* Offset of the name string in the string table */
202 UBYTE info; /* What kind of symbol is this ? (global, variable, etc) */
203 UBYTE other; /* undefined */
204 UWORD shindex; /* In which section is the symbol defined ? */
205 elf_uintptr_t value; /* Varies; eg. the offset of the symbol in its hunk */
206 elf_uintptr_t size; /* How much memory does the symbol occupy */
209 #define ELF_R_SYM(i) (ULONG)((i) >> 32)
210 #define ELF_R_TYPE(i) (ULONG)((i) & 0xffffffffULL)
211 #define ELF_R_INFO(sym, type) (((UQUAD)(sym) << 32) + (type))
213 #else
215 struct pheader
217 ULONG type;
218 ULONG offset;
219 elf_ptr_t vaddr;
220 elf_ptr_t paddr;
221 ULONG filesz;
222 ULONG memsz;
223 ULONG flags;
224 ULONG align;
227 struct symbol
229 ULONG name; /* Offset of the name string in the string table */
230 elf_uintptr_t value; /* Varies; eg. the offset of the symbol in its hunk */
231 elf_uintptr_t size; /* How much memory does the symbol occupy */
232 UBYTE info; /* What kind of symbol is this ? (global, variable, etc) */
233 UBYTE other; /* undefined */
234 UWORD shindex; /* In which section is the symbol defined ? */
237 #define ELF_R_SYM(val) ((val) >> 8)
238 #define ELF_R_TYPE(val) ((val) & 0xff)
239 #define ELF_R_INFO(sym, type) (((sym) << 8) + ((type) & 0xff))
241 #endif
243 #define ELF_S_BIND(val) ((val) >> 4)
244 #define ELF_S_TYPE(val) ((val) & 0xF)
245 #define ELF_S_INFO(bind, type) (((bind) << 4) + ((type) & 0xF))
247 struct rel
249 elf_uintptr_t offset; /* Address of the relocation relative to the section it refers to */
250 elf_uintptr_t info; /* Type of the relocation */
253 struct rela
255 elf_uintptr_t offset; /* Address of the relocation relative to the section it refers to */
256 elf_uintptr_t info; /* Type of the relocation */
257 elf_intptr_t addend; /* Constant addend used to compute value */
260 /* Note: the conversion below is not in line with ELF specification and is fixed in GNU binutils since 2008
261 * See: https://sourceware.org/bugzilla/show_bug.cgi?id=5900
263 /* convert section header number to array index */
264 /*#define SHINDEX(n) \
265 ((n) < SHN_LORESERVE ? (n) : ((n) <= SHN_HIRESERVE ? 0 : (n) - (SHN_HIRESERVE + 1 - SHN_LORESERVE)))*/
267 /* convert section header array index to section number */
268 /*#define SHNUM(i) \
269 ((i) < SHN_LORESERVE ? (i) : (i) + (SHN_HIRESERVE + 1 - SHN_LORESERVE))*/
271 /* ARM-specific attributes section definitions follow */
273 #define ATTR_VERSION_CURRENT 0x41
275 struct attrs_section
277 ULONG size;
278 char vendor[1]; /* NULL-terminated name */
279 /* Vendor-specific subsections follow */
282 struct attrs_subsection
284 UBYTE tag;
285 ULONG size;
286 } __attribute__((packed));
288 #define Tag_File 1
289 #define Tag_Section 2
290 #define Tag_Symbol 3
291 #define Tag_CPU_raw_name 4
292 #define Tag_CPU_name 5
293 #define Tag_CPU_arch 6
294 #define Tag_FP_arch 10
295 #define Tag_compatibility 32
296 #define Tag_also_compatible_with 65
297 #define Tag_conformance 67
299 /* Tag_CPU_arch values */
300 #define ELF_CPU_PREv4 0
301 #define ELF_CPU_ARMv4 1
302 #define ELF_CPU_ARMv4T 2
303 #define ELF_CPU_ARMv5T 3
304 #define ELF_CPU_ARMv5TE 4
305 #define ELF_CPU_ARMv5TEJ 5
306 #define ELF_CPU_ARMv6 6
307 #define ELF_CPU_ARMv6KZ 7
308 #define ELF_CPU_ARMv6T2 8
309 #define ELF_CPU_ARMv6K 9
310 #define ELF_CPU_ARMv7 10
311 #define ELF_CPU_ARM_v6M 11
312 #define ELF_CPU_ARMv6SM 12
313 #define ELF_CPU_ARMv7EM 13
315 /* Tag_FP_arch values */
316 #define ELF_FP_None 0
317 #define ELF_FP_v1 1
318 #define ELF_FP_v2 2
319 #define ELF_FP_v3 3
320 #define ELF_FP_v3_Short 4
321 #define ELF_FP_v4 5
322 #define ELF_FP_v4_Short 6
324 /* Machine's native values */
325 #ifdef ELF_64BIT
326 #define AROS_ELF_CLASS ELFCLASS64
327 #else
328 #define AROS_ELF_CLASS ELFCLASS32
329 #endif
331 #if AROS_BIG_ENDIAN
332 #define AROS_ELF_DATA ELFDATA2MSB
333 #else
334 #define AROS_ELF_DATA ELFDATA2LSB
335 #endif
337 #if defined(__i386__) || defined(__x86_64__)
338 #ifdef ELF_64BIT
339 #define AROS_ELF_MACHINE EM_X86_64
340 #define AROS_ELF_REL SHT_RELA
341 #define relo rela
342 #else
343 #define AROS_ELF_MACHINE EM_386
344 #define AROS_ELF_REL SHT_REL
345 #define relo rel
346 #endif
347 #endif
348 #ifdef __mc68000__
349 #define AROS_ELF_MACHINE EM_68K
350 #define AROS_ELF_REL SHT_RELA
351 #define relo rela
352 #endif
353 #ifdef __powerpc__
354 #define AROS_ELF_MACHINE EM_PPC
355 #define AROS_ELF_REL SHT_RELA
356 #define relo rela
357 #endif
358 #ifdef __arm__
359 #define AROS_ELF_MACHINE EM_ARM
360 #define AROS_ELF_REL SHT_REL
361 #define relo rel
362 #endif
364 #endif