VSF Documented
elf.h
Go to the documentation of this file.
1#ifndef __ELF_H__
2#define __ELF_H__
3
4#include <stdint.h>
5
6// http://www.skyfree.org/linux/references/ELF_Format.pdf
7
8/*----------------------------------------------------------------------------*
9 * ELF32 *
10 *----------------------------------------------------------------------------*/
11
17
18typedef struct Elf32_Hdr {
19#define EI_MAG0 0
20# define ELFMAG0 0x7F
21#define EI_MAG1 1
22# define ELFMAG1 'E'
23#define EI_MAG2 2
24# define ELFMAG2 'L'
25#define EI_MAG3 3
26# define ELFMAG3 'F'
27#define EI_CLASS 4
28# define ELFCLASSNONE 0
29# define ELFCLASS32 1
30# define ELFCLASS64 2
31#define EI_DATA 5
32# define ELFDATANONE 0
33# define ELFDATA2LSB 1
34# define ELFDATA2MSB 2
35#define EI_VERSION 6
36#define EI_PAD 7
37#define EI_NIDENT 16
38 unsigned char e_ident[EI_NIDENT];
39
40#define ET_NONE 0
41#define ET_REL 1
42#define ET_EXEC 2
43#define ET_DYN 3
44#define ET_CORE 4
45#define ET_LOPROC 0xFF00
46#define ET_HIPROC 0xFFFF
48
49#define EM_NONE 0
50#define EM_M32 1
51#define EM_SPARC 2
52#define EM_386 3
53#define EM_68K 4
54#define EM_88K 5
55#define EM_860 7
56#define EM_MIPS 8
57#define EM_ARM 0x28
59
60#define EV_NONE 0
61#define EV_CURRENT 1
63
75
76#define SHN_UNDEF 0
77#define SHN_LORESERVE 0xFF00
78#define SHN_LOPROC 0xFF00
79#define SHN_HIPROC 0xFF1F
80#define SHN_ABS 0xFFF1
81#define SHN_COMMON 0xFFF2
82#define SHN_HIRESERVE 0xFFFF
83
84typedef struct Elf32_Shdr {
86
87#define SHT_NULL 0
88#define SHT_PROGBITS 1
89#define SHT_SYMTAB 2
90#define SHT_STRTAB 3
91#define SHT_RELA 4
92#define SHT_HASH 5
93#define SHT_DYNAMIC 6
94#define SHT_NOTE 7
95#define SHT_NOBITS 8
96#define SHT_REL 9
97#define SHT_SHLIB 10
98#define SHT_DYNSYM 11
99#define SHT_LOPROC 0x70000000
100#define SHT_HIPROC 0x7FFFFFFF
101#define SHT_LOUSER 0x80000000
102#define SHT_HIUSER 0x8FFFFFFF
104
105#define SHF_WRITE 0x1
106#define SHF_ALLOC 0x2
107#define SHF_EXECINSTR 0x4
108#define SHF_MASKPROC 0xF0000000
110
119
120typedef struct Elf32_Sym {
124
125#define STB_LOCAL 0
126#define STB_GLOBAL 1
127#define STB_WEAK 2
128#define STB_LOPROC 13
129#define STB_HIPROC 15
130#define STT_NOTYPE 0
131#define STT_OBJECT 1
132#define STT_FUNC 2
133#define STT_SECTION 3
134#define STT_FILE 4
135#define STT_LOPROC 13
136#define STT_HIPROC 15
137#define ELF32_ST_BIND(__INFO) ((__INFO) >> 4)
138#define ELF32_ST_TYPE(__INFO) ((__INFO) & 0xF)
139#define ELF32_ST_INFO(__BIND, __TYPE) (((__BIND) << 4) + ((__TYPE) & 0xF))
140 unsigned char st_info;
141
142#define STV_DEFAULT 0
143#define STV_INTERNAL 1
144#define STV_HIDDEN 2
145#define STV_PROTECTED 3
146#define STV_EXPORTED 4
147#define STV_SINGLETON 5
148#define STV_ELIMINATE 6
149#define ELF32_ST_VIS(__OTHER) ((__OTHER) & 3)
150 unsigned char st_other;
151
154
155typedef struct Elf32_Rel {
157
158#define ELF32_R_SYM(__INFO) ((__INFO) >> 8)
159#define ELF32_R_TYPE(__INFO) ((unsigned char)(__INFO))
160#define ELF32_R_INFO(__SYM, __TYPE) (((__SYM) << 8) + (unsigned char)(__TYPE))
163
169
170typedef struct Elf32_Phdr {
171#define PT_NULL 0
172#define PT_LOAD 1
173#define PT_DYNAMIC 2
174#define PT_INTERP 3
175#define PT_NOTE 4
176#define PT_SHLIB 5
177#define PT_PHDR 6
178#define PT_LOPROC 0x70000000
179#define PT_HIPROC 0x7FFFFFFF
181
187#define PF_R 0x4
188#define PF_W 0x2
189#define PF_X 0x1
193
194typedef struct Elf32_Dyn {
195#define DT_NULL 0
196#define DT_NEEDED 1
197#define DT_PLTRELSZ 2
198#define DT_PLTGOT 3
199#define DT_HASH 4
200#define DT_STRTAB 5
201#define DT_SYMTAB 6
202#define DT_RELA 7
203#define DT_RELASZ 8
204#define DT_RELAENT 9
205#define DT_STRSZ 10
206#define DT_SYMENT 11
207#define DT_INIT 12
208#define DT_FINI 13
209#define DT_SONAME 14
210#define DT_RPATH 15
211#define DT_SYMBOLIC 16
212#define DT_REL 17
213#define DT_RELSZ 18
214#define DT_RELENT 19
215#define DT_PLTREL 20
216#define DT_INIT_ARRAY 25
217#define DT_FINI_ARRAY 26
218#define DT_INIT_ARRAYSZ 27
219#define DT_FINI_ARRAYSZ 28
220#define DT_DEBUG 21
221#define DT_TEXTREL 22
222#define DT_JMPREL 23
223#define DT_LOPROC 0x70000000
224#define DT_HIPROC 0x7FFFFFFF
226
227 union {
232
233/*----------------------------------------------------------------------------*
234 * ELF64 *
235 *----------------------------------------------------------------------------*/
236
245
246typedef struct {
247 unsigned char e_ident[EI_NIDENT]; /* File identification. */
248 Elf64_Half e_type; /* File type. */
249 Elf64_Half e_machine; /* Machine architecture. */
250 Elf64_Word e_version; /* ELF format version. */
251 Elf64_Addr e_entry; /* Entry point. */
252 Elf64_Off e_phoff; /* Program header file offset. */
253 Elf64_Off e_shoff; /* Section header file offset. */
254 Elf64_Word e_flags; /* Architecture-specific flags. */
255 Elf64_Half e_ehsize; /* Size of ELF header in bytes. */
256 Elf64_Half e_phentsize; /* Size of program header entry. */
257 Elf64_Half e_phnum; /* Number of program header entries. */
258 Elf64_Half e_shentsize; /* Size of section header entry. */
259 Elf64_Half e_shnum; /* Number of section header entries. */
260 Elf64_Half e_shstrndx; /* Section name strings section. */
261} Elf64_Hdr;
262
263typedef struct {
264 Elf64_Word sh_name; /* Section name (index into the section header string table). */
265 Elf64_Word sh_type; /* Section type. */
266 Elf64_Xword sh_flags; /* Section flags. */
267 Elf64_Addr sh_addr; /* Address in memory image. */
268 Elf64_Off sh_offset; /* Offset in file. */
269 Elf64_Xword sh_size; /* Size in bytes. */
270 Elf64_Word sh_link; /* Index of a related section. */
271 Elf64_Word sh_info; /* Depends on section type. */
272 Elf64_Xword sh_addralign; /* Alignment in bytes. */
273 Elf64_Xword sh_entsize; /* Size of each entry in section. */
274} Elf64_Shdr;
275
276typedef struct {
277 Elf64_Word p_type; /* Entry type. */
278 Elf64_Word p_flags; /* Access permission flags. */
279 Elf64_Off p_offset; /* File offset of contents. */
280 Elf64_Addr p_vaddr; /* Virtual address in memory image. */
281 Elf64_Addr p_paddr; /* Physical address (not used). */
282 Elf64_Xword p_filesz; /* Size of contents in file. */
283 Elf64_Xword p_memsz; /* Size of contents in memory. */
284 Elf64_Xword p_align; /* Alignment in memory and file. */
285} Elf64_Phdr;
286
287typedef struct {
288 Elf64_Sxword d_tag; /* Entry type. */
289 union {
290 Elf64_Xword d_val; /* Integer value. */
291 Elf64_Addr d_ptr; /* Address value. */
292 } d_un;
293} Elf64_Dyn;
294
295typedef struct {
296 Elf64_Addr r_offset; /* Location to be relocated. */
297
298#define ELF64_R_SYM(__INFO) ((__INFO) >> 32)
299#define ELF64_R_TYPE(__INFO) ((__INFO) & 0xffffffffL)
300#define ELF64_R_INFO(__SYM, __TYPE) (((__SYM) << 32) + ((__TYPE) & 0xffffffffL))
301 Elf64_Xword r_info; /* Relocation type and symbol index. */
302} Elf64_Rel;
303
304typedef struct {
305 Elf64_Addr r_offset; /* Location to be relocated. */
306 Elf64_Xword r_info; /* Relocation type and symbol index. */
307 Elf64_Sxword r_addend; /* Addend. */
308} Elf64_Rela;
309
310typedef struct {
311 Elf64_Word st_name; /* String table index of name. */
312
313#define ELF64_ST_BIND(__INFO) ((__INFO) >> 4)
314#define ELF64_ST_TYPE(__INFO) ((__INFO) & 0xF)
315#define ELF64_ST_INFO(__BIND, __TYPE) (((__BIND) << 4) + ((__TYPE) & 0xF))
316 unsigned char st_info; /* Type and binding information. */
317
318#define ELF64_ST_VIS(__OTHER) ((__OTHER) & 3)
319 unsigned char st_other; /* Reserved (not used). */
320 Elf64_Half st_shndx; /* Section index of symbol. */
321 Elf64_Addr st_value; /* Symbol value. */
322 Elf64_Xword st_size; /* Size of associated object. */
323} Elf64_Sym;
324
325/*----------------------------------------------------------------------------*
326 * Common *
327 *----------------------------------------------------------------------------*/
328
329#ifdef __VSF64__
330# define Elf_Addr Elf64_Addr
331# define Elf_Off Elf64_Off
332# define Elf_Word Elf64_Word
333# define Elf_Sword Elf64_Sword
334# define Elf_Half Elf64_Half
335
336# define Elf_Hdr Elf64_Hdr
337# define Elf_Shdr Elf64_Shdr
338# define Elf_Sym Elf64_Sym
339# define Elf_Rel Elf64_Rel
340# define Elf_Rela Elf64_Rela
341# define Elf_Phdr Elf64_Phdr
342# define Elf_Dyn Elf64_Dyn
343
344# define ELF_R_SYM ELF64_R_SYM
345# define ELF_R_TYPE ELF64_R_TYPE
346# define ELF_R_INFO ELF64_R_INFO
347
348# define ELF_ST_BIND ELF64_ST_BIND
349# define ELF_ST_TYPE ELF64_ST_TYPE
350# define ELF_ST_VIS ELF64_ST_VIS
351#else
352# define Elf_Addr Elf32_Addr
353# define Elf_Off Elf32_Off
354# define Elf_Word Elf32_Word
355# define Elf_Sword Elf32_Sword
356# define Elf_Half Elf32_Half
357
358# define Elf_Hdr Elf32_Hdr
359# define Elf_Shdr Elf32_Shdr
360# define Elf_Sym Elf32_Sym
361# define Elf_Rel Elf32_Rel
362# define Elf_Rela Elf32_Rela
363# define Elf_Phdr Elf32_Phdr
364# define Elf_Dyn Elf32_Dyn
365
366# define ELF_R_SYM ELF32_R_SYM
367# define ELF_R_TYPE ELF32_R_TYPE
368# define ELF_R_INFO ELF32_R_INFO
369
370# define ELF_ST_BIND ELF32_ST_BIND
371# define ELF_ST_TYPE ELF32_ST_TYPE
372# define ELF_ST_VIS ELF32_ST_VIS
373#endif
374
375#endif // __ELF_H__
struct Elf32_Phdr Elf32_Phdr
struct Elf32_Rela Elf32_Rela
struct Elf32_Shdr Elf32_Shdr
struct Elf32_Sym Elf32_Sym
uint16_t Elf32_Half
Definition elf.h:16
int32_t Elf32_Sword
Definition elf.h:15
int32_t Elf64_Sword
Definition elf.h:240
uint32_t Elf32_Addr
Definition elf.h:12
uint64_t Elf64_Xword
Definition elf.h:244
int64_t Elf64_Sxword
Definition elf.h:241
uint32_t Elf32_Off
Definition elf.h:13
uint64_t Elf64_Off
Definition elf.h:239
struct Elf32_Rel Elf32_Rel
uint32_t Elf64_Word
Definition elf.h:242
uint64_t Elf64_Lword
Definition elf.h:243
struct Elf32_Hdr Elf32_Hdr
struct Elf32_Dyn Elf32_Dyn
uint16_t Elf64_Half
Definition elf.h:238
#define EI_NIDENT
Definition elf.h:37
uint64_t Elf64_Addr
Definition elf.h:237
uint32_t Elf32_Word
Definition elf.h:14
unsigned short uint16_t
Definition stdint.h:7
unsigned uint32_t
Definition stdint.h:9
unsigned long long uint64_t
Definition stdint.h:11
int int32_t
Definition stdint.h:8
long long int64_t
Definition stdint.h:10
Definition elf.h:194
Elf32_Word d_val
Definition elf.h:228
Elf32_Sword d_tag
Definition elf.h:225
union Elf32_Dyn::@935 d_un
Elf32_Addr d_ptr
Definition elf.h:229
Definition elf.h:18
Elf32_Half e_ehsize
Definition elf.h:68
Elf32_Word e_version
Definition elf.h:62
unsigned char e_ident[EI_NIDENT]
Definition elf.h:38
Elf32_Word e_flags
Definition elf.h:67
Elf32_Half e_shentsize
Definition elf.h:71
Elf32_Half e_shstrndx
Definition elf.h:73
Elf32_Addr e_entry
Definition elf.h:64
Elf32_Half e_shnum
Definition elf.h:72
Elf32_Off e_shoff
Definition elf.h:66
Elf32_Half e_machine
Definition elf.h:58
Elf32_Half e_type
Definition elf.h:47
Elf32_Half e_phentsize
Definition elf.h:69
Elf32_Half e_phnum
Definition elf.h:70
Elf32_Off e_phoff
Definition elf.h:65
Definition elf.h:170
Elf32_Addr p_vaddr
Definition elf.h:183
Elf32_Word p_flags
Definition elf.h:190
Elf32_Word p_type
Definition elf.h:180
Elf32_Off p_offset
Definition elf.h:182
Elf32_Word p_filesz
Definition elf.h:185
Elf32_Word p_memsz
Definition elf.h:186
Elf32_Addr p_paddr
Definition elf.h:184
Elf32_Word p_align
Definition elf.h:191
Definition elf.h:155
Elf32_Word r_info
Definition elf.h:161
Elf32_Addr r_offset
Definition elf.h:156
Definition elf.h:164
Elf32_Sword r_addend
Definition elf.h:167
Elf32_Addr r_offset
Definition elf.h:165
Elf32_Word r_info
Definition elf.h:166
Definition elf.h:84
Elf32_Word sh_entsize
Definition elf.h:117
Elf32_Word sh_flags
Definition elf.h:109
Elf32_Word sh_addralign
Definition elf.h:116
Elf32_Off sh_offset
Definition elf.h:112
Elf32_Word sh_name
Definition elf.h:85
Elf32_Addr sh_addr
Definition elf.h:111
Elf32_Word sh_size
Definition elf.h:113
Elf32_Word sh_type
Definition elf.h:103
Elf32_Word sh_link
Definition elf.h:114
Elf32_Word sh_info
Definition elf.h:115
Definition elf.h:120
Elf32_Word st_size
Definition elf.h:123
unsigned char st_other
Definition elf.h:150
Elf32_Half st_shndx
Definition elf.h:152
Elf32_Word st_name
Definition elf.h:121
unsigned char st_info
Definition elf.h:140
Elf32_Addr st_value
Definition elf.h:122
Definition elf.h:287
Elf64_Addr d_ptr
Definition elf.h:291
Elf64_Sxword d_tag
Definition elf.h:288
Elf64_Xword d_val
Definition elf.h:290
Definition elf.h:246
Elf64_Half e_phentsize
Definition elf.h:256
Elf64_Half e_shstrndx
Definition elf.h:260
Elf64_Off e_shoff
Definition elf.h:253
Elf64_Half e_type
Definition elf.h:248
Elf64_Half e_ehsize
Definition elf.h:255
Elf64_Half e_machine
Definition elf.h:249
Elf64_Addr e_entry
Definition elf.h:251
Elf64_Half e_phnum
Definition elf.h:257
Elf64_Half e_shentsize
Definition elf.h:258
Elf64_Word e_version
Definition elf.h:250
Elf64_Word e_flags
Definition elf.h:254
Elf64_Half e_shnum
Definition elf.h:259
Elf64_Off e_phoff
Definition elf.h:252
Definition elf.h:276
Elf64_Xword p_memsz
Definition elf.h:283
Elf64_Addr p_vaddr
Definition elf.h:280
Elf64_Addr p_paddr
Definition elf.h:281
Elf64_Off p_offset
Definition elf.h:279
Elf64_Xword p_align
Definition elf.h:284
Elf64_Word p_flags
Definition elf.h:278
Elf64_Word p_type
Definition elf.h:277
Elf64_Xword p_filesz
Definition elf.h:282
Definition elf.h:295
Elf64_Xword r_info
Definition elf.h:301
Elf64_Addr r_offset
Definition elf.h:296
Definition elf.h:304
Elf64_Sxword r_addend
Definition elf.h:307
Elf64_Addr r_offset
Definition elf.h:305
Elf64_Xword r_info
Definition elf.h:306
Definition elf.h:263
Elf64_Word sh_name
Definition elf.h:264
Elf64_Xword sh_flags
Definition elf.h:266
Elf64_Word sh_link
Definition elf.h:270
Elf64_Word sh_type
Definition elf.h:265
Elf64_Word sh_info
Definition elf.h:271
Elf64_Xword sh_entsize
Definition elf.h:273
Elf64_Xword sh_size
Definition elf.h:269
Elf64_Xword sh_addralign
Definition elf.h:272
Elf64_Addr sh_addr
Definition elf.h:267
Elf64_Off sh_offset
Definition elf.h:268
Definition elf.h:310
Elf64_Half st_shndx
Definition elf.h:320
Elf64_Word st_name
Definition elf.h:311
Elf64_Addr st_value
Definition elf.h:321
unsigned char st_info
Definition elf.h:316
unsigned char st_other
Definition elf.h:319
Elf64_Xword st_size
Definition elf.h:322
Generated from commit: vsfteam/vsf@2a137b0