5 Copyright (C) 1995-2019, The AROS Development Team. All rights reserved.
8 Desc: Definition of ELF file structures.
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.
19 #define elf_ptr_t UQUAD
20 #define elf_uintptr_t UQUAD
21 #define elf_intptr_t QUAD
25 #define elf_ptr_t ULONG
26 #define elf_uintptr_t ULONG
27 #define elf_intptr_t LONG
31 #define elf_ptr_t APTR
32 #define elf_uintptr_t IPTR
33 #define elf_intptr_t SIPTR
35 #if (__WORDSIZE == 64)
41 #define SHT_PROGBITS 1
47 #define SHT_SYMTAB_SHNDX 18
48 #define SHT_ARM_ATTRIBUTES 0x70000003
57 #define EM_X86_64 62 /* AMD x86-64 */
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
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
92 #define R_ARM_JUMP24 29
93 #define R_ARM_TARGET1 38
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
107 #define STT_SECTION 3
109 #define STT_LOPROC 13
110 #define STT_HIPROC 15
116 #define STB_GNU_UNIQUE 10
118 #define STB_LOPROC 13
119 #define STB_HIPROC 15
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)
138 #define ELFDATA2LSB 1
139 #define ELFDATA2MSB 2
143 #define ELFCLASS64 2 /* 64-bit objects */
146 #define EI_ABIVERSION 8
148 #define ELFOSABI_AROS 15
150 #define PF_X (1 << 0)
176 elf_uintptr_t offset
;
180 elf_uintptr_t addralign
;
181 elf_uintptr_t entsize
;
192 elf_uintptr_t offset
;
195 elf_uintptr_t filesz
;
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))
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))
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))
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 */
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 */
270 ((i) < SHN_LORESERVE ? (i) : (i) + (SHN_HIRESERVE + 1 - SHN_LORESERVE))*/
272 /* ARM-specific attributes section definitions follow */
274 #define ATTR_VERSION_CURRENT 0x41
279 char vendor
[1]; /* NULL-terminated name */
280 /* Vendor-specific subsections follow */
283 struct attrs_subsection
287 } __attribute__((packed
));
290 #define Tag_Section 2
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
321 #define ELF_FP_v3_Short 4
323 #define ELF_FP_v4_Short 6
325 /* Machine's native values */
327 #define AROS_ELF_CLASS ELFCLASS64
329 #define AROS_ELF_CLASS ELFCLASS32
333 #define AROS_ELF_DATA ELFDATA2MSB
335 #define AROS_ELF_DATA ELFDATA2LSB
338 #if defined(__i386__) || defined(__x86_64__)
340 #define AROS_ELF_MACHINE EM_X86_64
341 #define AROS_ELF_REL SHT_RELA
344 #define AROS_ELF_MACHINE EM_386
345 #define AROS_ELF_REL SHT_REL
350 #define AROS_ELF_MACHINE EM_68K
351 #define AROS_ELF_REL SHT_RELA
355 #define AROS_ELF_MACHINE EM_PPC
356 #define AROS_ELF_REL SHT_RELA
360 #define AROS_ELF_MACHINE EM_ARM
361 #define AROS_ELF_REL SHT_RELA