SyterKit 0.4.0.x
SyterKit is a bare-metal framework
Loading...
Searching...
No Matches
elf.h
Go to the documentation of this file.
1#ifndef _UAPI_LINUX_ELF_H
2#define _UAPI_LINUX_ELF_H
3
4#include <elf-em.h>
5#include <types.h>
6
7#ifdef __cplusplus
8extern "C" {
9#endif// __cplusplus
10
11/* 32-bit ELF base types. */
17
18/* 64-bit ELF base types. */
19typedef __u64 Elf64_Addr;
22typedef __u64 Elf64_Off;
25typedef __u64 Elf64_Xword;
26typedef __s64 Elf64_Sxword;
27
28/* These constants are for the segment types stored in the image headers */
29#define PT_NULL 0
30#define PT_LOAD 1
31#define PT_DYNAMIC 2
32#define PT_INTERP 3
33#define PT_NOTE 4
34#define PT_SHLIB 5
35#define PT_PHDR 6
36#define PT_TLS 7 /* Thread local storage segment */
37#define PT_LOOS 0x60000000 /* OS-specific */
38#define PT_HIOS 0x6fffffff /* OS-specific */
39#define PT_LOPROC 0x70000000
40#define PT_HIPROC 0x7fffffff
41#define PT_GNU_EH_FRAME 0x6474e550
42
43#define PT_GNU_STACK (PT_LOOS + 0x474e551)
44
45/*
46 * Extended Numbering
47 *
48 * If the real number of program header table entries is larger than
49 * or equal to PN_XNUM(0xffff), it is set to sh_info field of the
50 * section header at index 0, and PN_XNUM is set to e_phnum
51 * field. Otherwise, the section header at index 0 is zero
52 * initialized, if it exists.
53 *
54 * Specifications are available in:
55 *
56 * - Oracle: Linker and Libraries.
57 * Part No: 817–1984–19, August 2011.
58 * http://docs.oracle.com/cd/E18752_01/pdf/817-1984.pdf
59 *
60 * - System V ABI AMD64 Architecture Processor Supplement
61 * Draft Version 0.99.4,
62 * January 13, 2010.
63 * http://www.cs.washington.edu/education/courses/cse351/12wi/supp-docs/abi.pdf
64 */
65#define PN_XNUM 0xffff
66
67/* These constants define the different elf file types */
68#define ET_NONE 0
69#define ET_REL 1
70#define ET_EXEC 2
71#define ET_DYN 3
72#define ET_CORE 4
73#define ET_LOPROC 0xff00
74#define ET_HIPROC 0xffff
75
76/* This is the info that is needed to parse the dynamic section of the file */
77#define DT_NULL 0
78#define DT_NEEDED 1
79#define DT_PLTRELSZ 2
80#define DT_PLTGOT 3
81#define DT_HASH 4
82#define DT_STRTAB 5
83#define DT_SYMTAB 6
84#define DT_RELA 7
85#define DT_RELASZ 8
86#define DT_RELAENT 9
87#define DT_STRSZ 10
88#define DT_SYMENT 11
89#define DT_INIT 12
90#define DT_FINI 13
91#define DT_SONAME 14
92#define DT_RPATH 15
93#define DT_SYMBOLIC 16
94#define DT_REL 17
95#define DT_RELSZ 18
96#define DT_RELENT 19
97#define DT_PLTREL 20
98#define DT_DEBUG 21
99#define DT_TEXTREL 22
100#define DT_JMPREL 23
101#define DT_ENCODING 32
102#define OLD_DT_LOOS 0x60000000
103#define DT_LOOS 0x6000000d
104#define DT_HIOS 0x6ffff000
105#define DT_VALRNGLO 0x6ffffd00
106#define DT_VALRNGHI 0x6ffffdff
107#define DT_ADDRRNGLO 0x6ffffe00
108#define DT_ADDRRNGHI 0x6ffffeff
109#define DT_VERSYM 0x6ffffff0
110#define DT_RELACOUNT 0x6ffffff9
111#define DT_RELCOUNT 0x6ffffffa
112#define DT_FLAGS_1 0x6ffffffb
113#define DT_VERDEF 0x6ffffffc
114#define DT_VERDEFNUM 0x6ffffffd
115#define DT_VERNEED 0x6ffffffe
116#define DT_VERNEEDNUM 0x6fffffff
117#define OLD_DT_HIOS 0x6fffffff
118#define DT_LOPROC 0x70000000
119#define DT_HIPROC 0x7fffffff
120
121/* This info is needed when parsing the symbol table */
122#define STB_LOCAL 0
123#define STB_GLOBAL 1
124#define STB_WEAK 2
125
126#define STT_NOTYPE 0
127#define STT_OBJECT 1
128#define STT_FUNC 2
129#define STT_SECTION 3
130#define STT_FILE 4
131#define STT_COMMON 5
132#define STT_TLS 6
133
134#define ELF_ST_BIND(x) ((x) >> 4)
135#define ELF_ST_TYPE(x) (((unsigned int) x) & 0xf)
136#define ELF32_ST_BIND(x) ELF_ST_BIND(x)
137#define ELF32_ST_TYPE(x) ELF_ST_TYPE(x)
138#define ELF64_ST_BIND(x) ELF_ST_BIND(x)
139#define ELF64_ST_TYPE(x) ELF_ST_TYPE(x)
140
148
149typedef struct {
150 Elf64_Sxword d_tag; /* entry tag value */
151 union {
154 } d_un;
155} Elf64_Dyn;
156
157/* The following are used with relocations */
158#define ELF32_R_SYM(x) ((x) >> 8)
159#define ELF32_R_TYPE(x) ((x) &0xff)
160
161#define ELF64_R_SYM(i) ((i) >> 32)
162#define ELF64_R_TYPE(i) ((i) &0xffffffff)
163
168
169typedef struct elf64_rel {
170 Elf64_Addr r_offset; /* Location at which to apply the action */
171 Elf64_Xword r_info; /* index and type of relocation */
173
179
180typedef struct elf64_rela {
181 Elf64_Addr r_offset; /* Location at which to apply the action */
182 Elf64_Xword r_info; /* index and type of relocation */
183 Elf64_Sxword r_addend; /* Constant addend used to compute value */
185
194
195typedef struct elf64_sym {
196 Elf64_Word st_name; /* Symbol name, index in string tbl */
197 unsigned char st_info; /* Type and binding attributes */
198 unsigned char st_other; /* No defined meaning, 0 */
199 Elf64_Half st_shndx; /* Associated section index */
200 Elf64_Addr st_value; /* Value of the symbol */
201 Elf64_Xword st_size; /* Associated symbol size */
203
204#define EI_NIDENT 16
205
222
239
240/* These constants define the permissions on sections in the program
241 header, p_flags. */
242#define PF_R 0x4
243#define PF_W 0x2
244#define PF_X 0x1
245
256
257typedef struct elf64_phdr {
260 Elf64_Off p_offset; /* Segment file offset */
261 Elf64_Addr p_vaddr; /* Segment virtual address */
262 Elf64_Addr p_paddr; /* Segment physical address */
263 Elf64_Xword p_filesz; /* Segment size in file */
264 Elf64_Xword p_memsz; /* Segment size in memory */
265 Elf64_Xword p_align; /* Segment alignment, file & memory */
267
268/* sh_type */
269#define SHT_NULL 0
270#define SHT_PROGBITS 1
271#define SHT_SYMTAB 2
272#define SHT_STRTAB 3
273#define SHT_RELA 4
274#define SHT_HASH 5
275#define SHT_DYNAMIC 6
276#define SHT_NOTE 7
277#define SHT_NOBITS 8
278#define SHT_REL 9
279#define SHT_SHLIB 10
280#define SHT_DYNSYM 11
281#define SHT_NUM 12
282#define SHT_LOPROC 0x70000000
283#define SHT_HIPROC 0x7fffffff
284#define SHT_LOUSER 0x80000000
285#define SHT_HIUSER 0xffffffff
286
287/* sh_flags */
288#define SHF_WRITE 0x1
289#define SHF_ALLOC 0x2
290#define SHF_EXECINSTR 0x4
291#define SHF_RELA_LIVEPATCH 0x00100000
292#define SHF_RO_AFTER_INIT 0x00200000
293#define SHF_MASKPROC 0xf0000000
294
295/* special section indexes */
296#define SHN_UNDEF 0
297#define SHN_LORESERVE 0xff00
298#define SHN_LOPROC 0xff00
299#define SHN_HIPROC 0xff1f
300#define SHN_LIVEPATCH 0xff20
301#define SHN_ABS 0xfff1
302#define SHN_COMMON 0xfff2
303#define SHN_HIRESERVE 0xffff
304
317
318typedef struct elf64_shdr {
319 Elf64_Word sh_name; /* Section name, index in string tbl */
320 Elf64_Word sh_type; /* Type of section */
321 Elf64_Xword sh_flags; /* Miscellaneous section attributes */
322 Elf64_Addr sh_addr; /* Section virtual addr at execution */
323 Elf64_Off sh_offset; /* Section file offset */
324 Elf64_Xword sh_size; /* Size of section in bytes */
325 Elf64_Word sh_link; /* Index of another section */
326 Elf64_Word sh_info; /* Additional section information */
327 Elf64_Xword sh_addralign; /* Section alignment */
328 Elf64_Xword sh_entsize; /* Entry size if section holds table */
330
331#define EI_MAG0 0 /* e_ident[] indexes */
332#define EI_MAG1 1
333#define EI_MAG2 2
334#define EI_MAG3 3
335#define EI_CLASS 4
336#define EI_DATA 5
337#define EI_VERSION 6
338#define EI_OSABI 7
339#define EI_PAD 8
340
341#define ELFMAG0 0x7f /* EI_MAG */
342#define ELFMAG1 'E'
343#define ELFMAG2 'L'
344#define ELFMAG3 'F'
345#define ELFMAG "\177ELF"
346#define SELFMAG 4
347
348#define ELFCLASSNONE 0 /* EI_CLASS */
349#define ELFCLASS32 1
350#define ELFCLASS64 2
351#define ELFCLASSNUM 3
352
353#define ELFDATANONE 0 /* e_ident[EI_DATA] */
354#define ELFDATA2LSB 1
355#define ELFDATA2MSB 2
356
357#define EV_NONE 0 /* e_version, EI_VERSION */
358#define EV_CURRENT 1
359#define EV_NUM 2
360
361#define ELFOSABI_NONE 0
362#define ELFOSABI_LINUX 3
363
364#ifndef ELF_OSABI
365#define ELF_OSABI ELFOSABI_NONE
366#endif
367
368/*
369 * Notes used in ET_CORE. Architectures export some of the arch register sets
370 * using the corresponding note types via the PTRACE_GETREGSET and
371 * PTRACE_SETREGSET requests.
372 */
373#define NT_PRSTATUS 1
374#define NT_PRFPREG 2
375#define NT_PRPSINFO 3
376#define NT_TASKSTRUCT 4
377#define NT_AUXV 6
378/*
379 * Note to userspace developers: size of NT_SIGINFO note may increase
380 * in the future to accomodate more fields, don't assume it is fixed!
381 */
382#define NT_SIGINFO 0x53494749
383#define NT_FILE 0x46494c45
384#define NT_PRXFPREG 0x46e62b7f /* copied from gdb5.1/include/elf/common.h */
385#define NT_PPC_VMX 0x100 /* PowerPC Altivec/VMX registers */
386#define NT_PPC_SPE 0x101 /* PowerPC SPE/EVR registers */
387#define NT_PPC_VSX 0x102 /* PowerPC VSX registers */
388#define NT_PPC_TAR 0x103 /* Target Address Register */
389#define NT_PPC_PPR 0x104 /* Program Priority Register */
390#define NT_PPC_DSCR 0x105 /* Data Stream Control Register */
391#define NT_PPC_EBB 0x106 /* Event Based Branch Registers */
392#define NT_PPC_PMU 0x107 /* Performance Monitor Registers */
393#define NT_PPC_TM_CGPR 0x108 /* TM checkpointed GPR Registers */
394#define NT_PPC_TM_CFPR 0x109 /* TM checkpointed FPR Registers */
395#define NT_PPC_TM_CVMX 0x10a /* TM checkpointed VMX Registers */
396#define NT_PPC_TM_CVSX 0x10b /* TM checkpointed VSX Registers */
397#define NT_PPC_TM_SPR 0x10c /* TM Special Purpose Registers */
398#define NT_PPC_TM_CTAR 0x10d /* TM checkpointed Target Address Register */
399#define NT_PPC_TM_CPPR 0x10e /* TM checkpointed Program Priority Register */
400#define NT_PPC_TM_CDSCR 0x10f /* TM checkpointed Data Stream Control Register */
401#define NT_386_TLS 0x200 /* i386 TLS slots (struct user_desc) */
402#define NT_386_IOPERM 0x201 /* x86 io permission bitmap (1=deny) */
403#define NT_X86_XSTATE 0x202 /* x86 extended state using xsave */
404#define NT_S390_HIGH_GPRS 0x300 /* s390 upper register halves */
405#define NT_S390_TIMER 0x301 /* s390 timer register */
406#define NT_S390_TODCMP 0x302 /* s390 TOD clock comparator register */
407#define NT_S390_TODPREG 0x303 /* s390 TOD programmable register */
408#define NT_S390_CTRS 0x304 /* s390 control registers */
409#define NT_S390_PREFIX 0x305 /* s390 prefix register */
410#define NT_S390_LAST_BREAK 0x306 /* s390 breaking event address */
411#define NT_S390_SYSTEM_CALL 0x307 /* s390 system call restart data */
412#define NT_S390_TDB 0x308 /* s390 transaction diagnostic block */
413#define NT_S390_VXRS_LOW 0x309 /* s390 vector registers 0-15 upper half */
414#define NT_S390_VXRS_HIGH 0x30a /* s390 vector registers 16-31 */
415#define NT_ARM_VFP 0x400 /* ARM VFP/NEON registers */
416#define NT_ARM_TLS 0x401 /* ARM TLS register */
417#define NT_ARM_HW_BREAK 0x402 /* ARM hardware breakpoint registers */
418#define NT_ARM_HW_WATCH 0x403 /* ARM hardware watchpoint registers */
419#define NT_ARM_SYSTEM_CALL 0x404 /* ARM system call number */
420#define NT_METAG_CBUF 0x500 /* Metag catch buffer registers */
421#define NT_METAG_RPIPE 0x501 /* Metag read pipeline state */
422#define NT_METAG_TLS 0x502 /* Metag TLS pointer */
423
424/* Note header in a PT_NOTE section */
425typedef struct elf32_note {
426 Elf32_Word n_namesz; /* Name size */
427 Elf32_Word n_descsz; /* Content size */
428 Elf32_Word n_type; /* Content type */
430
431/* Note header in a PT_NOTE section */
432typedef struct elf64_note {
433 Elf64_Word n_namesz; /* Name size */
434 Elf64_Word n_descsz; /* Content size */
435 Elf64_Word n_type; /* Content type */
437
438#ifdef __cplusplus
439}
440#endif// __cplusplus
441
442#endif /* _UAPI_LINUX_ELF_H */
struct elf32_rel Elf32_Rel
__s32 Elf64_Sword
Definition elf.h:23
__u16 Elf32_Half
Definition elf.h:13
struct elf32_rela Elf32_Rela
struct elf32_note Elf32_Nhdr
__u64 Elf64_Xword
Definition elf.h:25
struct elf64_sym Elf64_Sym
__u16 Elf64_Half
Definition elf.h:20
struct elf32_phdr Elf32_Phdr
__s16 Elf64_SHalf
Definition elf.h:21
struct elf32_sym Elf32_Sym
struct elf32_shdr Elf32_Shdr
__u64 Elf64_Off
Definition elf.h:22
struct elf32_hdr Elf32_Ehdr
struct elf64_rel Elf64_Rel
__s64 Elf64_Sxword
Definition elf.h:26
__u32 Elf32_Addr
Definition elf.h:12
__u32 Elf64_Word
Definition elf.h:24
struct elf64_rela Elf64_Rela
struct elf64_note Elf64_Nhdr
struct elf64_phdr Elf64_Phdr
__s32 Elf32_Sword
Definition elf.h:15
struct elf64_shdr Elf64_Shdr
#define EI_NIDENT
Definition elf.h:204
__u64 Elf64_Addr
Definition elf.h:19
__u32 Elf32_Word
Definition elf.h:16
struct elf64_hdr Elf64_Ehdr
__u32 Elf32_Off
Definition elf.h:14
struct dynamic Elf32_Dyn
__signed__ int __s32
Definition types.h:20
unsigned int __u32
Definition types.h:21
unsigned short __u16
Definition types.h:18
__signed__ short __s16
Definition types.h:17
Definition elf.h:149
Elf64_Addr d_ptr
Definition elf.h:153
Elf64_Sxword d_tag
Definition elf.h:150
Elf64_Xword d_val
Definition elf.h:152
Definition elf.h:141
Elf32_Sword d_tag
Definition elf.h:142
union dynamic::@61 d_un
Elf32_Addr d_ptr
Definition elf.h:145
Elf32_Sword d_val
Definition elf.h:144
Definition elf.h:206
Elf32_Half e_type
Definition elf.h:208
unsigned char e_ident[EI_NIDENT]
Definition elf.h:207
Elf32_Half e_ehsize
Definition elf.h:215
Elf32_Word e_version
Definition elf.h:210
Elf32_Half e_phentsize
Definition elf.h:216
Elf32_Word e_flags
Definition elf.h:214
Elf32_Off e_phoff
Definition elf.h:212
Elf32_Half e_shentsize
Definition elf.h:218
Elf32_Half e_shnum
Definition elf.h:219
Elf32_Half e_machine
Definition elf.h:209
Elf32_Half e_phnum
Definition elf.h:217
Elf32_Addr e_entry
Definition elf.h:211
Elf32_Half e_shstrndx
Definition elf.h:220
Elf32_Off e_shoff
Definition elf.h:213
Definition elf.h:425
Elf32_Word n_descsz
Definition elf.h:427
Elf32_Word n_type
Definition elf.h:428
Elf32_Word n_namesz
Definition elf.h:426
Definition elf.h:246
Elf32_Word p_align
Definition elf.h:254
Elf32_Word p_filesz
Definition elf.h:251
Elf32_Addr p_vaddr
Definition elf.h:249
Elf32_Addr p_paddr
Definition elf.h:250
Elf32_Word p_flags
Definition elf.h:253
Elf32_Word p_type
Definition elf.h:247
Elf32_Word p_memsz
Definition elf.h:252
Elf32_Off p_offset
Definition elf.h:248
Definition elf.h:164
Elf32_Addr r_offset
Definition elf.h:165
Elf32_Word r_info
Definition elf.h:166
Definition elf.h:174
Elf32_Addr r_offset
Definition elf.h:175
Elf32_Sword r_addend
Definition elf.h:177
Elf32_Word r_info
Definition elf.h:176
Definition elf.h:305
Elf32_Word sh_entsize
Definition elf.h:315
Elf32_Word sh_flags
Definition elf.h:308
Elf32_Word sh_size
Definition elf.h:311
Elf32_Off sh_offset
Definition elf.h:310
Elf32_Addr sh_addr
Definition elf.h:309
Elf32_Word sh_info
Definition elf.h:313
Elf32_Word sh_addralign
Definition elf.h:314
Elf32_Word sh_link
Definition elf.h:312
Elf32_Word sh_type
Definition elf.h:307
Elf32_Word sh_name
Definition elf.h:306
Definition elf.h:186
Elf32_Word st_name
Definition elf.h:187
unsigned char st_other
Definition elf.h:191
Elf32_Half st_shndx
Definition elf.h:192
Elf32_Word st_size
Definition elf.h:189
Elf32_Addr st_value
Definition elf.h:188
unsigned char st_info
Definition elf.h:190
Definition elf.h:223
Elf64_Half e_phentsize
Definition elf.h:233
Elf64_Half e_shentsize
Definition elf.h:235
Elf64_Word e_version
Definition elf.h:227
Elf64_Half e_shnum
Definition elf.h:236
Elf64_Half e_type
Definition elf.h:225
Elf64_Half e_phnum
Definition elf.h:234
Elf64_Addr e_entry
Definition elf.h:228
Elf64_Half e_shstrndx
Definition elf.h:237
Elf64_Half e_ehsize
Definition elf.h:232
Elf64_Half e_machine
Definition elf.h:226
Elf64_Off e_shoff
Definition elf.h:230
unsigned char e_ident[EI_NIDENT]
Definition elf.h:224
Elf64_Off e_phoff
Definition elf.h:229
Elf64_Word e_flags
Definition elf.h:231
Definition elf.h:432
Elf64_Word n_descsz
Definition elf.h:434
Elf64_Word n_namesz
Definition elf.h:433
Elf64_Word n_type
Definition elf.h:435
Definition elf.h:257
Elf64_Off p_offset
Definition elf.h:260
Elf64_Addr p_vaddr
Definition elf.h:261
Elf64_Xword p_memsz
Definition elf.h:264
Elf64_Word p_flags
Definition elf.h:259
Elf64_Xword p_filesz
Definition elf.h:263
Elf64_Word p_type
Definition elf.h:258
Elf64_Xword p_align
Definition elf.h:265
Elf64_Addr p_paddr
Definition elf.h:262
Definition elf.h:169
Elf64_Xword r_info
Definition elf.h:171
Elf64_Addr r_offset
Definition elf.h:170
Definition elf.h:180
Elf64_Sxword r_addend
Definition elf.h:183
Elf64_Xword r_info
Definition elf.h:182
Elf64_Addr r_offset
Definition elf.h:181
Definition elf.h:318
Elf64_Xword sh_size
Definition elf.h:324
Elf64_Word sh_info
Definition elf.h:326
Elf64_Word sh_type
Definition elf.h:320
Elf64_Word sh_link
Definition elf.h:325
Elf64_Xword sh_flags
Definition elf.h:321
Elf64_Addr sh_addr
Definition elf.h:322
Elf64_Xword sh_addralign
Definition elf.h:327
Elf64_Off sh_offset
Definition elf.h:323
Elf64_Word sh_name
Definition elf.h:319
Elf64_Xword sh_entsize
Definition elf.h:328
Definition elf.h:195
Elf64_Half st_shndx
Definition elf.h:199
unsigned char st_other
Definition elf.h:198
unsigned char st_info
Definition elf.h:197
Elf64_Word st_name
Definition elf.h:196
Elf64_Xword st_size
Definition elf.h:201
Elf64_Addr st_value
Definition elf.h:200