1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
typedef unsigned char u8int;
typedef unsigned short u16int;
typedef unsigned int u32int;
typedef signed int s32int;
typedef signed long long s64int;
typedef unsigned long long u64int;
#define ELFMAG "\177ELF"
enum {
ELFCLASS32 = 1,
ELFCLASS64 = 2,
ELFDATA2LSB = 1,
ELFDATA2MSB = 2,
ELFVERSION = 1,
ELFOSABI_SYSV = 0,
ELFOSABI_ARM = 97,
ELFOSABI_STANDALONE = 255,
ET_NONE = 0,
ET_REL, ET_EXEC, ET_DYN, ET_CORE,
EM_NONE = 0,
EM_386 = 3,
EM_486 = 6,
EM_MIPS = 8,
EM_MIPS_RS4_BE = 0xA,
EM_ARM = 0x28,
EM_X86_64 = 0x3E,
EM_ARM64 = 0xB7,
};
#define ELF_HDRIDENT \
union { \
char ident[16]; \
struct { \
u8int i_mag[4], \
i_class, \
i_data, \
i_version, \
i_osabi, \
i_abiversion, \
i_pad[7]; \
}; \
}
struct elf64hdr {
ELF_HDRIDENT;
u16int type,
machine;
u32int version;
u64int entry,
phoff,
shoff;
u32int flags;
u16int ehsize,
phentsize,
phnum,
shentsize,
shnum,
shstrndx;
};
_Static_assert(sizeof(struct elf64hdr) == 64, "");
struct elf32hdr {
ELF_HDRIDENT;
u16int type,
machine;
u32int version;
u32int entry,
phoff,
shoff;
u32int flags;
u16int ehsize,
phentsize,
phnum,
shentsize,
shnum,
shstrndx;
};
_Static_assert(sizeof(struct elf32hdr) == 52, "");
enum {
SHT_NULL = 0x0,
SHT_PROGBITS = 0x1,
SHT_SYMTAB = 0x2,
SHT_STRTAB = 0x3,
SHT_RELA = 0x4,
SHT_HASH = 0x5,
SHT_DYNAMIC = 0x6,
SHT_NOTE = 0x7,
SHT_NOBITS = 0x8,
SHT_REL = 0x9,
SHT_SHLIB = 0xA,
SHT_DYNSYM = 0xB,
SHT_INIT_ARRAY = 0xE,
SHT_FINI_ARRAY = 0xF,
SHT_PREINIT_ARRAY = 0x10,
SHT_GROUP = 0x12,
SHT_SYMTAB_SHNDX = 0x13,
};
enum {
SHF_WRITE = 0x1,
SHF_ALLOC = 0x2,
SHF_EXECINSTR = 0x4,
SHF_MERGE = 0x10,
SHF_STRINGS = 0x20,
SHF_INFO_LINK = 0x40,
SHF_LINK_ORDER = 0x80,
SHF_OS_NONCONFORMING = 0x100,
SHF_GROUP = 0x200,
SHF_TLS = 0x400,
};
struct elf64shdr {
u32int name,
type;
u64int flags,
addr,
offset,
size;
u32int link,
info;
u64int addralign,
entsize;
};
_Static_assert(sizeof(struct elf64shdr) == 64, "");
struct elf32shdr {
u32int name,
type,
flags,
addr,
offset,
size,
link,
info,
addralign,
entsize;
};
_Static_assert(sizeof(struct elf32shdr) == 40, "");
enum {
STB_LOCAL,
STB_GLOBAL,
STB_WEAK
};
enum {
STT_NOTYPE,
STT_OBJECT,
STT_FUNC,
STT_SECTION,
STT_FILE,
};
enum {
SHN_UND = 0,
SHN_ABS = 0xFFF1,
};
#define ELF_S_INFO(b,t) ((b) << 4 | (t))
struct elf64sym {
u32int name;
u8int info,
other;
u16int shndx;
u64int value,
size;
};
_Static_assert(sizeof(struct elf64sym) == 24, "");
struct elf32sym {
u32int name,
value,
size;
u8int info,
other;
u16int shndx;
};
_Static_assert(sizeof(struct elf32sym) == 16, "");
#define ELF64_R_INFO(s,t) ((u64int) (s) << 32 | (u32int)(t))
struct elf64rel {
u64int offset, info;
};
_Static_assert(sizeof(struct elf64rel) == 16, "");
#define ELF32_R_INFO(s,t) ((s) << 8 | (u8int)(t))
struct elf32rel {
u32int offset, info;
};
_Static_assert(sizeof(struct elf32rel) == 8, "");
struct elf64rela {
u64int offset, info;
s64int addend;
};
_Static_assert(sizeof(struct elf64rela) == 24, "");
struct elf32rela {
u32int offset, info;
s32int addend;
};
_Static_assert(sizeof(struct elf32rela) == 12, "");
/* vim:set ts=3 sw=3 expandtab: */
|