elf.h: added
[neatlibc.git] / elf.h
blob3ec16f1523a3e0b0eb888dbec144f7dda01b34a5
1 #ifndef _ELF_H
2 #define _ELF_H
4 #include <stdint.h>
6 typedef uint16_t Elf32_Half;
8 typedef uint32_t Elf32_Word;
9 typedef int32_t Elf32_Sword;
11 typedef uint32_t Elf32_Addr;
12 typedef uint32_t Elf32_Off;
13 typedef uint16_t Elf32_Section;
15 #define EI_NIDENT (16)
17 typedef struct {
18 unsigned char e_ident[EI_NIDENT];
19 Elf32_Half e_type;
20 Elf32_Half e_machine;
21 Elf32_Word e_version;
22 Elf32_Addr e_entry;
23 Elf32_Off e_phoff;
24 Elf32_Off e_shoff;
25 Elf32_Word e_flags;
26 Elf32_Half e_ehsize;
27 Elf32_Half e_phentsize;
28 Elf32_Half e_phnum;
29 Elf32_Half e_shentsize;
30 Elf32_Half e_shnum;
31 Elf32_Half e_shstrndx;
32 } Elf32_Ehdr;
34 #define ELFMAG "\177ELF"
35 #define SELFMAG 4
37 #define EI_CLASS 4
38 #define ELFCLASSNONE 0
39 #define ELFCLASS32 1
40 #define ELFCLASS64 2
41 #define ELFCLASSNUM 3
43 #define EI_DATA 5
44 #define ELFDATANONE 0
45 #define ELFDATA2LSB 1
46 #define ELFDATA2MSB 2
47 #define ELFDATANUM 3
49 #define EI_VERSION 6
51 #define EI_OSABI 7
52 #define ELFOSABI_NONE 0
53 #define ELFOSABI_SYSV 0
54 #define ELFOSABI_HPUX 1
55 #define ELFOSABI_NETBSD 2
56 #define ELFOSABI_LINUX 3
57 #define ELFOSABI_SOLARIS 6
58 #define ELFOSABI_AIX 7
59 #define ELFOSABI_IRIX 8
60 #define ELFOSABI_FREEBSD 9
61 #define ELFOSABI_TRU64 10
62 #define ELFOSABI_MODESTO 11
63 #define ELFOSABI_OPENBSD 12
64 #define ELFOSABI_ARM 97
65 #define ELFOSABI_STANDALONE 255
67 #define EI_ABIVERSION 8
69 #define EI_PAD 9
71 #define ET_NONE 0
72 #define ET_REL 1
73 #define ET_EXEC 2
74 #define ET_DYN 3
75 #define ET_CORE 4
76 #define ET_NUM 5
77 #define ET_LOOS 0xfe00
78 #define ET_HIOS 0xfeff
79 #define ET_LOPROC 0xff00
80 #define ET_HIPROC 0xffff
82 #define EM_NONE 0
83 #define EM_M32 1
84 #define EM_SPARC 2
85 #define EM_386 3
86 #define EM_68K 4
87 #define EM_88K 5
88 #define EM_860 7
89 #define EM_MIPS 8
90 #define EM_S370 9
91 #define EM_MIPS_RS3_LE 10
93 #define EM_PARISC 15
94 #define EM_VPP500 17
95 #define EM_SPARC32PLUS 18
96 #define EM_960 19
97 #define EM_PPC 20
98 #define EM_PPC64 21
99 #define EM_S390 22
101 #define EM_V800 36
102 #define EM_FR20 37
103 #define EM_RH32 38
104 #define EM_RCE 39
105 #define EM_ARM 40
106 #define EM_FAKE_ALPHA 41
107 #define EM_SH 42
108 #define EM_SPARCV9 43
109 #define EM_TRICORE 44
110 #define EM_ARC 45
111 #define EM_H8_300 46
112 #define EM_H8_300H 47
113 #define EM_H8S 48
114 #define EM_H8_500 49
115 #define EM_IA_64 50
116 #define EM_MIPS_X 51
117 #define EM_COLDFIRE 52
118 #define EM_68HC12 53
119 #define EM_MMA 54
120 #define EM_PCP 55
121 #define EM_NCPU 56
122 #define EM_NDR1 57
123 #define EM_STARCORE 58
124 #define EM_ME16 59
125 #define EM_ST100 60
126 #define EM_TINYJ 61
127 #define EM_X86_64 62
128 #define EM_PDSP 63
130 #define EM_FX66 66
131 #define EM_ST9PLUS 67
132 #define EM_ST7 68
133 #define EM_68HC16 69
134 #define EM_68HC11 70
135 #define EM_68HC08 71
136 #define EM_68HC05 72
137 #define EM_SVX 73
138 #define EM_ST19 74
139 #define EM_VAX 75
140 #define EM_CRIS 76
141 #define EM_JAVELIN 77
142 #define EM_FIREPATH 78
143 #define EM_ZSP 79
144 #define EM_MMIX 80
145 #define EM_HUANY 81
146 #define EM_PRISM 82
147 #define EM_AVR 83
148 #define EM_FR30 84
149 #define EM_D10V 85
150 #define EM_D30V 86
151 #define EM_V850 87
152 #define EM_M32R 88
153 #define EM_MN10300 89
154 #define EM_MN10200 90
155 #define EM_PJ 91
156 #define EM_OPENRISC 92
157 #define EM_ARC_A5 93
158 #define EM_XTENSA 94
159 #define EM_NUM 95
160 #define EM_ALPHA 0x9026
162 #define EV_NONE 0
163 #define EV_CURRENT 1
164 #define EV_NUM 2
166 typedef struct {
167 Elf32_Word sh_name;
168 Elf32_Word sh_type;
169 Elf32_Word sh_flags;
170 Elf32_Addr sh_addr;
171 Elf32_Off sh_offset;
172 Elf32_Word sh_size;
173 Elf32_Word sh_link;
174 Elf32_Word sh_info;
175 Elf32_Word sh_addralign;
176 Elf32_Word sh_entsize;
177 } Elf32_Shdr;
179 #define SHN_UNDEF 0
180 #define SHN_LORESERVE 0xff00
181 #define SHN_LOPROC 0xff00
182 #define SHN_BEFORE 0xff00
184 #define SHN_AFTER 0xff01
186 #define SHN_HIPROC 0xff1f
187 #define SHN_LOOS 0xff20
188 #define SHN_HIOS 0xff3f
189 #define SHN_ABS 0xfff1
190 #define SHN_COMMON 0xfff2
191 #define SHN_XINDEX 0xffff
192 #define SHN_HIRESERVE 0xffff
194 #define SHT_NULL 0
195 #define SHT_PROGBITS 1
196 #define SHT_SYMTAB 2
197 #define SHT_STRTAB 3
198 #define SHT_RELA 4
199 #define SHT_HASH 5
200 #define SHT_DYNAMIC 6
201 #define SHT_NOTE 7
202 #define SHT_NOBITS 8
203 #define SHT_REL 9
204 #define SHT_SHLIB 10
205 #define SHT_DYNSYM 11
206 #define SHT_INIT_ARRAY 14
207 #define SHT_FINI_ARRAY 15
208 #define SHT_PREINIT_ARRAY 16
209 #define SHT_GROUP 17
210 #define SHT_SYMTAB_SHNDX 18
211 #define SHT_NUM 19
212 #define SHT_LOPROC 0x70000000
213 #define SHT_HIPROC 0x7fffffff
214 #define SHT_LOUSER 0x80000000
215 #define SHT_HIUSER 0x8fffffff
217 #define SHF_WRITE (1 << 0)
218 #define SHF_ALLOC (1 << 1)
219 #define SHF_EXECINSTR (1 << 2)
220 #define SHF_MERGE (1 << 4)
221 #define SHF_STRINGS (1 << 5)
222 #define SHF_INFO_LINK (1 << 6)
223 #define SHF_LINK_ORDER (1 << 7)
224 #define SHF_OS_NONCONFORMING (1 << 8)
226 #define SHF_GROUP (1 << 9)
227 #define SHF_TLS (1 << 10)
228 #define SHF_MASKOS 0x0ff00000
229 #define SHF_MASKPROC 0xf0000000
230 #define SHF_ORDERED (1 << 30)
231 #define SHF_EXCLUDE (1 << 31)
233 #define GRP_COMDAT 0x1
235 typedef struct {
236 Elf32_Word st_name;
237 Elf32_Addr st_value;
238 Elf32_Word st_size;
239 unsigned char st_info;
240 unsigned char st_other;
241 Elf32_Section st_shndx;
242 } Elf32_Sym;
244 #define ELF32_ST_BIND(val) (((unsigned char) (val)) >> 4)
245 #define ELF32_ST_TYPE(val) ((val) & 0xf)
246 #define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf))
248 #define ELF64_ST_BIND(val) ELF32_ST_BIND (val)
249 #define ELF64_ST_TYPE(val) ELF32_ST_TYPE (val)
250 #define ELF64_ST_INFO(bind, type) ELF32_ST_INFO ((bind), (type))
252 #define STB_LOCAL 0
253 #define STB_GLOBAL 1
254 #define STB_WEAK 2
255 #define STB_NUM 3
256 #define STB_LOOS 10
257 #define STB_GNU_UNIQUE 10
258 #define STB_HIOS 12
259 #define STB_LOPROC 13
260 #define STB_HIPROC 15
262 #define STT_NOTYPE 0
263 #define STT_OBJECT 1
264 #define STT_FUNC 2
265 #define STT_SECTION 3
266 #define STT_FILE 4
267 #define STT_COMMON 5
268 #define STT_TLS 6
269 #define STT_NUM 7
270 #define STT_LOOS 10
271 #define STT_GNU_IFUNC 10
272 #define STT_HIOS 12
273 #define STT_LOPROC 13
274 #define STT_HIPROC 15
276 #define STN_UNDEF 0
278 #define ELF32_ST_VISIBILITY(o) ((o) & 0x03)
279 #define ELF64_ST_VISIBILITY(o) ELF32_ST_VISIBILITY (o)
281 #define STV_DEFAULT 0
282 #define STV_INTERNAL 1
283 #define STV_HIDDEN 2
284 #define STV_PROTECTED 3
287 typedef struct {
288 Elf32_Addr r_offset;
289 Elf32_Word r_info;
290 } Elf32_Rel;
293 typedef struct {
294 Elf32_Addr r_offset;
295 Elf32_Word r_info;
296 Elf32_Sword r_addend;
297 } Elf32_Rela;
299 #define ELF32_R_SYM(val) ((val) >> 8)
300 #define ELF32_R_TYPE(val) ((val) & 0xff)
301 #define ELF32_R_INFO(sym, type) (((sym) << 8) + ((type) & 0xff))
303 typedef struct {
304 Elf32_Word p_type;
305 Elf32_Off p_offset;
306 Elf32_Addr p_vaddr;
307 Elf32_Addr p_paddr;
308 Elf32_Word p_filesz;
309 Elf32_Word p_memsz;
310 Elf32_Word p_flags;
311 Elf32_Word p_align;
312 } Elf32_Phdr;
314 #define PT_NULL 0
315 #define PT_LOAD 1
316 #define PT_DYNAMIC 2
317 #define PT_INTERP 3
318 #define PT_NOTE 4
319 #define PT_SHLIB 5
320 #define PT_PHDR 6
321 #define PT_TLS 7
322 #define PT_NUM 8
323 #define PT_LOPROC 0x70000000
324 #define PT_HIPROC 0x7fffffff
326 #define PF_X (1 << 0)
327 #define PF_W (1 << 1)
328 #define PF_R (1 << 2)
329 #define PF_MASKOS 0x0ff00000
330 #define PF_MASKPROC 0xf0000000
332 #define NT_PRSTATUS 1
333 #define NT_FPREGSET 2
334 #define NT_PRPSINFO 3
335 #define NT_PRXREG 4
336 #define NT_TASKSTRUCT 4
337 #define NT_PLATFORM 5
338 #define NT_AUXV 6
339 #define NT_GWINDOWS 7
340 #define NT_ASRS 8
341 #define NT_PSTATUS 10
342 #define NT_PSINFO 13
343 #define NT_PRCRED 14
344 #define NT_UTSNAME 15
345 #define NT_LWPSTATUS 16
346 #define NT_LWPSINFO 17
347 #define NT_PRFPXREG 20
348 #define NT_PRXFPREG 0x46e62b7f
349 #define NT_PPC_VMX 0x100
350 #define NT_PPC_SPE 0x101
351 #define NT_PPC_VSX 0x102
352 #define NT_386_TLS 0x200
353 #define NT_386_IOPERM 0x201
354 #define NT_VERSION 1
356 #define R_386_NONE 0
357 #define R_386_32 1
358 #define R_386_PC32 2
359 #define R_386_GOT32 3
360 #define R_386_PLT32 4
361 #define R_386_COPY 5
362 #define R_386_GLOB_DAT 6
363 #define R_386_JMP_SLOT 7
364 #define R_386_RELATIVE 8
365 #define R_386_GOTOFF 9
366 #define R_386_GOTPC 10
367 #define R_386_32PLT 11
368 #define R_386_TLS_TPOFF 14
369 #define R_386_TLS_IE 15
370 #define R_386_TLS_GOTIE 16
371 #define R_386_TLS_LE 17
372 #define R_386_TLS_GD 18
373 #define R_386_TLS_LDM 19
374 #define R_386_16 20
375 #define R_386_PC16 21
376 #define R_386_8 22
377 #define R_386_PC8 23
378 #define R_386_TLS_GD_32 24
379 #define R_386_TLS_GD_PUSH 25
380 #define R_386_TLS_GD_CALL 26
381 #define R_386_TLS_GD_POP 27
382 #define R_386_TLS_LDM_32 28
383 #define R_386_TLS_LDM_PUSH 29
384 #define R_386_TLS_LDM_CALL 30
385 #define R_386_TLS_LDM_POP 31
386 #define R_386_TLS_LDO_32 32
387 #define R_386_TLS_IE_32 33
388 #define R_386_TLS_LE_32 34
389 #define R_386_TLS_DTPMOD32 35
390 #define R_386_TLS_DTPOFF32 36
391 #define R_386_TLS_TPOFF32 37
392 #define R_386_TLS_GOTDESC 39
393 #define R_386_TLS_DESC_CALL 40
394 #define R_386_TLS_DESC 41
395 #define R_386_IRELATIVE 42
396 #define R_386_NUM 43
398 #define EF_ARM_RELEXEC 0x01
399 #define EF_ARM_HASENTRY 0x02
400 #define EF_ARM_INTERWORK 0x04
401 #define EF_ARM_APCS_26 0x08
402 #define EF_ARM_APCS_FLOAT 0x10
403 #define EF_ARM_PIC 0x20
404 #define EF_ARM_ALIGN8 0x40
405 #define EF_ARM_NEW_ABI 0x80
406 #define EF_ARM_OLD_ABI 0x100
407 #define EF_ARM_SOFT_FLOAT 0x200
408 #define EF_ARM_VFP_FLOAT 0x400
409 #define EF_ARM_MAVERICK_FLOAT 0x800
411 #define EF_ARM_SYMSARESORTED 0x04
412 #define EF_ARM_DYNSYMSUSESEGIDX 0x08
413 #define EF_ARM_MAPSYMSFIRST 0x10
414 #define EF_ARM_EABIMASK 0XFF000000
416 #define EF_ARM_BE8 0x00800000
417 #define EF_ARM_LE8 0x00400000
419 #define EF_ARM_EABI_VERSION(flags) ((flags) & EF_ARM_EABIMASK)
420 #define EF_ARM_EABI_UNKNOWN 0x00000000
421 #define EF_ARM_EABI_VER1 0x01000000
422 #define EF_ARM_EABI_VER2 0x02000000
423 #define EF_ARM_EABI_VER3 0x03000000
424 #define EF_ARM_EABI_VER4 0x04000000
425 #define EF_ARM_EABI_VER5 0x05000000
427 #define STT_ARM_TFUNC STT_LOPROC
428 #define STT_ARM_16BIT STT_HIPROC
430 #define SHF_ARM_ENTRYSECT 0x10000000
431 #define SHF_ARM_COMDEF 0x80000000
433 #define PF_ARM_SB 0x10000000
435 #define PF_ARM_PI 0x20000000
436 #define PF_ARM_ABS 0x40000000
438 #define PT_ARM_EXIDX (PT_LOPROC + 1)
440 #define SHT_ARM_EXIDX (SHT_LOPROC + 1)
441 #define SHT_ARM_PREEMPTMAP (SHT_LOPROC + 2)
442 #define SHT_ARM_ATTRIBUTES (SHT_LOPROC + 3)
444 #define R_ARM_NONE 0
445 #define R_ARM_PC24 1
446 #define R_ARM_ABS32 2
447 #define R_ARM_REL32 3
448 #define R_ARM_PC13 4
449 #define R_ARM_ABS16 5
450 #define R_ARM_ABS12 6
451 #define R_ARM_THM_ABS5 7
452 #define R_ARM_ABS8 8
453 #define R_ARM_SBREL32 9
454 #define R_ARM_THM_PC22 10
455 #define R_ARM_THM_PC8 11
456 #define R_ARM_AMP_VCALL9 12
457 #define R_ARM_SWI24 13
458 #define R_ARM_THM_SWI8 14
459 #define R_ARM_XPC25 15
460 #define R_ARM_THM_XPC22 16
461 #define R_ARM_TLS_DTPMOD32 17
462 #define R_ARM_TLS_DTPOFF32 18
463 #define R_ARM_TLS_TPOFF32 19
464 #define R_ARM_COPY 20
465 #define R_ARM_GLOB_DAT 21
466 #define R_ARM_JUMP_SLOT 22
467 #define R_ARM_RELATIVE 23
468 #define R_ARM_GOTOFF 24
469 #define R_ARM_GOTPC 25
470 #define R_ARM_GOT32 26
471 #define R_ARM_PLT32 27
472 #define R_ARM_ALU_PCREL_7_0 32
473 #define R_ARM_ALU_PCREL_15_8 33
474 #define R_ARM_ALU_PCREL_23_15 34
475 #define R_ARM_LDR_SBREL_11_0 35
476 #define R_ARM_ALU_SBREL_19_12 36
477 #define R_ARM_ALU_SBREL_27_20 37
478 #define R_ARM_GNU_VTENTRY 100
479 #define R_ARM_GNU_VTINHERIT 101
480 #define R_ARM_THM_PC11 102
481 #define R_ARM_THM_PC9 103
482 #define R_ARM_TLS_GD32 104
484 #define R_ARM_TLS_LDM32 105
486 #define R_ARM_TLS_LDO32 106
488 #define R_ARM_TLS_IE32 107
490 #define R_ARM_TLS_LE32 108
492 #define R_ARM_RXPC25 249
493 #define R_ARM_RSBREL32 250
494 #define R_ARM_THM_RPC22 251
495 #define R_ARM_RREL32 252
496 #define R_ARM_RABS22 253
497 #define R_ARM_RPC24 254
498 #define R_ARM_RBASE 255
500 #define R_ARM_NUM 256
502 #endif