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