RetroLinker
Linker for several 8-bit, 16-bit and 32-bit formats
Loading...
Searching...
No Matches
elf.h
1#ifndef ELF_H
2#define ELF_H
3
4#include <sstream>
5#include <vector>
6#include "../common.h"
7#include "../dumper/dumper.h"
8#include "../linker/buffer.h"
9#include "../linker/format.h"
10#include "../linker/module.h"
11#include "../linker/options.h"
12#include "../linker/reader.h"
13#include "../linker/segment_manager.h"
14
15namespace ELF
16{
29 class ELFFormat : public virtual Linker::InputFormat, public virtual Linker::SegmentManager
30 {
31 public:
32 /* * * General members * * */
33
34 static constexpr uint8_t EI_OSABI = 7;
35 static constexpr uint8_t EI_ABIVERSION = 8;
36 static constexpr uint8_t EI_CLASS = 4;
37 static constexpr uint8_t EI_DATA = 5;
38
39 static constexpr uint8_t ELFCLASSNONE = 0;
40 static constexpr uint8_t ELFCLASS32 = 1;
41 static constexpr uint8_t ELFCLASS64 = 2;
42
43 static constexpr uint8_t ELFDATANONE = 0;
44 static constexpr uint8_t ELFDATA2LSB = 1;
45 static constexpr uint8_t ELFDATA2MSB = 2;
46
47 static constexpr uint8_t EV_NONE = 0;
48 static constexpr uint8_t EV_CURRENT = 1;
49
50 static constexpr uint8_t ELFOSABI_NONE = 0;
51
52 static constexpr offset_t SHF_WRITE = 0x0001;
53 static constexpr offset_t SHF_ALLOC = 0x0002;
54 static constexpr offset_t SHF_EXECINSTR = 0x0004;
55 static constexpr offset_t SHF_MERGE = 0x0010;
56 static constexpr offset_t SHF_STRINGS = 0x0020;
57 static constexpr offset_t SHF_INFO_LINK = 0x0040;
58 static constexpr offset_t SHF_LINK_ORDER = 0x0080;
59 static constexpr offset_t SHF_OS_NONCONFORMING = 0x0100;
60 static constexpr offset_t SHF_GROUP = 0x0200;
61 static constexpr offset_t SHF_TLS = 0x0400;
62 static constexpr offset_t SHF_COMPRESSED = 0x0800;
63 /* GNU specific */
64 static constexpr offset_t SHF_GNU_RETAIN = 0x00200000;
65 static constexpr offset_t SHF_GNU_MBIND = 0x01000000;
66 static constexpr offset_t SHF_EXCLUDE = 0x80000000;
67 /* OS/2 specific */
68 static constexpr offset_t SHF_BEGIN = 0x01000000;
69 static constexpr offset_t SHF_END = 0x02000000;
70
71 static constexpr uint16_t SHN_UNDEF = 0;
72 static constexpr uint16_t SHN_LORESERVE = 0xFF00;
73 static constexpr uint16_t SHN_ABS = 0xFFF1;
74 static constexpr uint16_t SHN_COMMON = 0xFFF2;
75 static constexpr uint16_t SHN_XINDEX = 0xFFFF;
76
77 static constexpr uint8_t STB_LOCAL = 0;
78 static constexpr uint8_t STB_GLOBAL = 1;
79 static constexpr uint8_t STB_WEAK = 2;
80 static constexpr uint8_t STB_ENTRY = 12; /* IBM OS/2 */
81
82 static constexpr uint8_t STT_NOTYPE = 0;
83 static constexpr uint8_t STT_OBJECT = 1;
84 static constexpr uint8_t STT_FUNC = 2;
85 static constexpr uint8_t STT_SECTION = 3;
86 static constexpr uint8_t STT_FILE = 4;
87 static constexpr uint8_t STT_COMMON = 5;
88 static constexpr uint8_t STT_TLS = 6;
89 static constexpr uint8_t STT_IMPORT = 11; /* IBM OS/2 */
90
91 static constexpr uint8_t STV_DEFAULT = 0;
92 static constexpr uint8_t STV_INTERNAL = 1;
93 static constexpr uint8_t STV_HIDDEN = 2;
94 static constexpr uint8_t STV_PROTECTED = 3;
95
96 static constexpr offset_t R_386_8 = 22;
97 static constexpr offset_t R_386_PC8 = 23;
98 static constexpr offset_t R_386_16 = 20;
99 static constexpr offset_t R_386_PC16 = 21;
100 static constexpr offset_t R_386_32 = 1;
101 static constexpr offset_t R_386_PC32 = 2;
102 static constexpr offset_t R_386_GOT32 = 3;
103 static constexpr offset_t R_386_GOTPC = 10;
104 static constexpr offset_t R_386_GOTOFF = 9;
105 static constexpr offset_t R_386_PLT32 = 4;
107 static constexpr offset_t R_386_SEG16 = 45;
109 static constexpr offset_t R_386_SUB16 = 46;
111 static constexpr offset_t R_386_SUB32 = 47;
113 static constexpr offset_t R_386_SEGRELATIVE = 48;
115 static constexpr offset_t R_386_OZSEG16 = 80;
117 static constexpr offset_t R_386_OZRELSEG16 = 81;
118
119 static constexpr offset_t R_X86_64_8 = 14;
120 static constexpr offset_t R_X86_64_PC8 = 15;
121 static constexpr offset_t R_X86_64_16 = 12;
122 static constexpr offset_t R_X86_64_PC16 = 13;
123 static constexpr offset_t R_X86_64_32 = 10;
124 static constexpr offset_t R_X86_64_32S = 11;
125 static constexpr offset_t R_X86_64_PC32 = 2;
126 static constexpr offset_t R_X86_64_PLT32 = 4;
127 static constexpr offset_t R_X86_64_64 = 1;
128 static constexpr offset_t R_X86_64_PC64 = 24;
129
130 static constexpr offset_t R_68K_8 = 3;
131 static constexpr offset_t R_68K_PC8 = 6;
132 static constexpr offset_t R_68K_16 = 2;
133 static constexpr offset_t R_68K_PC16 = 5;
134 static constexpr offset_t R_68K_32 = 1;
135 static constexpr offset_t R_68K_PC32 = 4;
136 static constexpr offset_t R_68K_GOT8 = 9;
137 static constexpr offset_t R_68K_GOT8O = 12;
138 static constexpr offset_t R_68K_GOT16 = 8;
139 static constexpr offset_t R_68K_GOT16O = 11;
140 static constexpr offset_t R_68K_GOT32 = 7;
141 static constexpr offset_t R_68K_GOT32O = 10;
142 static constexpr offset_t R_68K_PLT8 = 15;
143 static constexpr offset_t R_68K_PLT8O = 18;
144 static constexpr offset_t R_68K_PLT16 = 14;
145 static constexpr offset_t R_68K_PLT16O = 17;
146 static constexpr offset_t R_68K_PLT32 = 13;
147 static constexpr offset_t R_68K_PLT32O = 16;
148
149 static constexpr offset_t R_ARM_ABS8 = 8;
150 static constexpr offset_t R_ARM_ABS16 = 16;
151 static constexpr offset_t R_ARM_ABS32 = 2;
152 static constexpr offset_t R_ARM_REL32 = 3;
153 static constexpr offset_t R_ARM_CALL = 28;
154 static constexpr offset_t R_ARM_JUMP24 = 29;
155 static constexpr offset_t R_ARM_PC24 = 1;
156 static constexpr offset_t R_ARM_V4BX = 40;
157
158 static constexpr offset_t R_PPC_ADDR14 = 7;
159 static constexpr offset_t R_PPC_ADDR14_BRTAKEN = 8;
160 static constexpr offset_t R_PPC_ADDR14_BRNTAKEN = 9;
161 static constexpr offset_t R_PPC_REL14 = 11;
162 static constexpr offset_t R_PPC_REL14_BRTAKEN = 12;
163 static constexpr offset_t R_PPC_REL14_BRNTAKEN = 13;
164 static constexpr offset_t R_PPC_ADDR16 = 3;
165 static constexpr offset_t R_PPC_UADDR16 = 25;
166 static constexpr offset_t R_PPC_ADDR16_LO = 4;
167 static constexpr offset_t R_PPC_ADDR16_HI = 5;
168 static constexpr offset_t R_PPC_ADDR16_HA = 6;
169 static constexpr offset_t R_PPC_ADDR24 = 2;
170 static constexpr offset_t R_PPC_REL24 = 10;
171 static constexpr offset_t R_PPC_ADDR30 = 37;
172 static constexpr offset_t R_PPC_ADDR32 = 1;
173 static constexpr offset_t R_PPC_UADDR32 = 24;
174 static constexpr offset_t R_PPC_REL32 = 26;
175 static constexpr offset_t R_PPC64_ADDR64 = 38;
176 static constexpr offset_t R_PPC64_UADDR64 = 43;
177 static constexpr offset_t R_PPC64_REL64 = 44;
178
179 /* https://github.com/bminor/binutils-gdb/blob/master/include/elf/vax.h */
180 static constexpr offset_t R_VAX_8 = 3;
181 static constexpr offset_t R_VAX_PC8 = 6;
182 static constexpr offset_t R_VAX_16 = 2;
183 static constexpr offset_t R_VAX_PC16 = 5;
184 static constexpr offset_t R_VAX_32 = 1;
185 static constexpr offset_t R_VAX_PC32 = 4;
186 static constexpr offset_t R_VAX_GOT32 = 7;
187 static constexpr offset_t R_VAX_PLT32 = 13;
188
189 static constexpr offset_t R_Z80_8 = 1;
190 static constexpr offset_t R_Z80_8_DIS = 2;
191 static constexpr offset_t R_Z80_8_PCREL = 3;
192 static constexpr offset_t R_Z80_16 = 4;
193 static constexpr offset_t R_Z80_24 = 5;
194 static constexpr offset_t R_Z80_32 = 6;
195
196 static constexpr offset_t DT_NULL = 0;
197 static constexpr offset_t DT_NEEDED = 1;
198 static constexpr offset_t DT_PLTRELSZ = 2;
199 static constexpr offset_t DT_PLTGOT = 3;
200 static constexpr offset_t DT_HASH = 4;
201 static constexpr offset_t DT_STRTAB = 5;
202 static constexpr offset_t DT_SYMTAB = 6;
203 static constexpr offset_t DT_RELA = 7;
204 static constexpr offset_t DT_RELASZ = 8;
205 static constexpr offset_t DT_RELAENT = 9;
206 static constexpr offset_t DT_STRSZ = 10;
207 static constexpr offset_t DT_SYMENT = 11;
208 static constexpr offset_t DT_INIT = 12;
209 static constexpr offset_t DT_FINI = 13;
210 static constexpr offset_t DT_SONAME = 14;
211 static constexpr offset_t DT_RPATH = 15;
212 static constexpr offset_t DT_SYMBOLIC = 16;
213 static constexpr offset_t DT_REL = 17;
214 static constexpr offset_t DT_RELSZ = 18;
215 static constexpr offset_t DT_RELENT = 19;
216 static constexpr offset_t DT_PLTREL = 20;
217 static constexpr offset_t DT_DEBUG = 21;
218 static constexpr offset_t DT_TEXTREL = 22;
219 static constexpr offset_t DT_JMPREL = 23;
220 static constexpr offset_t DT_BIND_NOW = 24;
221 static constexpr offset_t DT_INIT_ARRAY = 25;
222 static constexpr offset_t DT_FINI_ARRAY = 26;
223 static constexpr offset_t DT_INIT_ARRAYSZ = 27;
224 static constexpr offset_t DT_FINI_ARRAYSZ = 28;
225 static constexpr offset_t DT_RUNPATH = 29;
226 static constexpr offset_t DT_FLAGS = 30;
227 static constexpr offset_t DT_ENCODING = 31;
228 static constexpr offset_t DT_PREINIT_ARRAY = 32;
229 static constexpr offset_t DT_PREINIT_ARRAYSZ = 33;
230 static constexpr offset_t DT_SYMTAB_SHNDX = 34;
231 static constexpr offset_t DT_RELRSZ = 35;
232 static constexpr offset_t DT_RELR = 36;
233 static constexpr offset_t DT_RELRENT = 37;
234 /* IBM OS/2 specific */
235 static constexpr offset_t DT_EXPORT = 0x60000001;
236 static constexpr offset_t DT_EXPORTSZ = 0x60000002;
237 static constexpr offset_t DT_EXPENT = 0x60000003;
238 static constexpr offset_t DT_IMPORT = 0x60000004;
239 static constexpr offset_t DT_IMPORTSZ = 0x60000005;
240 static constexpr offset_t DT_IMPENT = 0x60000006;
241 static constexpr offset_t DT_IT = 0x60000007;
242 static constexpr offset_t DT_ITPRTY = 0x60000008;
243 static constexpr offset_t DT_INITTERM = 0x60000009;
244 static constexpr offset_t DT_STACKSZ = 0x6000000A;
245 /* GNU binutils */
246 static constexpr offset_t DT_GNU_FLAGS1 = 0x6FFFFDF4;
247 static constexpr offset_t DT_GNU_PRELINKED = 0x6FFFFDF5;
248 static constexpr offset_t DT_GNU_CONFLICTSZ = 0x6FFFFDF6;
249 static constexpr offset_t DT_GNU_LIBLISTSZ = 0x6FFFFDF7;
250 static constexpr offset_t DT_CHECKSUM = 0x6FFFFDF8;
251 static constexpr offset_t DT_PLTPADSZ = 0x6FFFFDF9;
252 static constexpr offset_t DT_MOVEENT = 0x6FFFFDFA;
253 static constexpr offset_t DT_MOVESZ = 0x6FFFFDFB;
254 static constexpr offset_t DT_FEATURE = 0x6FFFFDFC;
255 static constexpr offset_t DT_POSTFLAG_1 = 0x6FFFFDFD;
256 static constexpr offset_t DT_SYMINSZ = 0x6FFFFDFE;
257 static constexpr offset_t DT_SYMINENT = 0x6FFFFDFF;
258 static constexpr offset_t DT_GNU_HASH = 0x6FFFFEF5;
259 static constexpr offset_t DT_TLSDESC_PLT = 0x6FFFFEF6;
260 static constexpr offset_t DT_TLSDESC_GOT = 0x6FFFFEF7;
261 static constexpr offset_t DT_GNU_CONFLICT = 0x6FFFFFEF8;
262 static constexpr offset_t DT_GNU_LIBLIST = 0x6FFFFEF9;
263 static constexpr offset_t DT_CONFIG = 0x6FFFFEFA;
264 static constexpr offset_t DT_DEPAUDIT = 0x6FFFFEFB;
265 static constexpr offset_t DT_AUDIT = 0x6FFFFEFC;
266 static constexpr offset_t DT_PLTPAD = 0x6FFFFEFD;
267 static constexpr offset_t DT_MOVETAB = 0x6FFFFEFE;
268 static constexpr offset_t DT_SYMINFO = 0x6FFFFEFF;
269 static constexpr offset_t DT_VERSYM = 0x6FFFFFF0;
270 static constexpr offset_t DT_RELACOUNT = 0x6FFFFFF9;
271 static constexpr offset_t DT_RELCOUNT = 0x6FFFFFFA;
272 static constexpr offset_t DT_FLAGS_1 = 0x6FFFFFFB;
273 static constexpr offset_t DT_VERDEF = 0x6FFFFFFC;
274 static constexpr offset_t DT_VERDEFNUM = 0x6FFFFFFD;
275 static constexpr offset_t DT_VERNEED = 0x6FFFFFFE;
276 static constexpr offset_t DT_VERNEEDNUM = 0x6FFFFFFF;
277 static constexpr offset_t DT_AUXILIARY = 0x7FFFFFFD;
278 static constexpr offset_t DT_USED = 0x7FFFFFFE;
279 static constexpr offset_t DT_FILTER = 0x7FFFFFFFF;
280
281 offset_t file_offset = 0;
282
283 uint8_t file_class = 0;
284 EndianType endiantype = ::LittleEndian;
285
286 uint8_t data_encoding = 0;
287 size_t wordbytes = 4;
288
289 enum cpu_type
290 {
291 EM_NONE = 0,
292 EM_M32 = 1,
293 EM_SPARC = 2,
294 EM_386 = 3,
295 EM_68K = 4,
296 EM_88K = 5,
297 EM_IAMCU = 6,
298 EM_860 = 7,
299 EM_MIPS = 8,
300 EM_S370 = 9,
301 EM_MIPS_RS3_LE = 10,
302 EM_OLD_SPARCV9 = 11, // https://github.com/bminor/binutils-gdb/blob/master/include/elf/common.h
303
304 EM_PARISC = 15,
305
306 EM_VPP500 = 17,
307 EM_SPARC32PLUS = 18,
308 EM_960 = 19,
309 EM_PPC = 20,
310 EM_PPC64 = 21,
311 EM_S390 = 22,
312 EM_SPU = 23,
313
314 EM_V800 = 36,
315 EM_FR20 = 37,
316 EM_RH32 = 38,
317 EM_MCORE = 39,
318 EM_RCE = EM_MCORE,
319 EM_ARM = 40,
320 EM_ALPHA = 41,
321 EM_SH = 42,
322 EM_SPARCV9 = 43,
323 EM_TRICORE = 44,
324 EM_ARC = 45,
325 EM_H8_300 = 46,
326 EM_H8_300H = 47,
327 EM_H8S = 48,
328 EM_H8_500 = 49,
329 EM_IA_64 = 50,
330 EM_MIPS_X = 51,
331 EM_COLDFIRE = 52,
332 EM_68HC12 = 53,
333 EM_MMA = 54,
334 EM_PCP = 55,
335 EM_NCPU = 56,
336 EM_NDR1 = 57,
337 EM_STARCORE = 58,
338 EM_ME16 = 59,
339 EM_ST100 = 60,
340 EM_TINYJ = 61,
341 EM_X86_64 = 62,
342 EM_PDSP = 63,
343 EM_PDP10 = 64,
344 EM_PDP11 = 65,
345 EM_FX66 = 66,
346 EM_ST9PLUS = 67,
347 EM_ST7 = 68,
348 EM_68HC16 = 69,
349 EM_68HC11 = 70,
350 EM_68HC08 = 71,
351 EM_68HC05 = 72,
352 EM_SVX = 73,
353 EM_ST19 = 74,
354 EM_VAX = 75,
355 EM_CRIS = 76,
356 EM_JAVELIN = 77,
357 EM_FIREPATH = 78,
358 EM_ZSP = 79,
359 EM_MMIX = 80,
360 EM_HUANY = 81,
361 EM_PRISM = 82,
362 EM_AVR = 83,
363 EM_FR30 = 84,
364 EM_D10V = 85,
365 EM_D30V = 86,
366 EM_V850 = 87,
367 EM_M32R = 88,
368 EM_MN10300 = 89,
369 EM_MN10200 = 90,
370 EM_PJ = 91,
371 EM_OPENRISC = 92,
372 EM_ARC_COMPACT = 93,
373 EM_ARC_A5 = EM_ARC_COMPACT,
374 EM_XTENSA = 94,
375 EM_SCORE_OLD = 95,
376 EM_VIDEOCORE = 95,
377 EM_TMM_GPP = 96,
378 EM_NS32K = 97,
379 EM_TPC = 98,
380 EM_PJ_OLD = 99,
381 EM_SNP1K = 99,
382 EM_ST200 = 100,
383 EM_IP2K = 101,
384 EM_MAX = 102,
385 EM_CR = 103,
386 EM_F2MC16 = 104,
387 EM_MSP430 = 105,
388 EM_BLACKFIN = 106,
389 EM_SE_C33 = 107,
390 EM_SEP = 108,
391 EM_ARCA = 109,
392 EM_UNICORE = 110,
393 EM_EXCESS = 111,
394 EM_DXP = 112,
395 EM_ALTERA_NIOS32 = 113,
396 EM_CRX = 114,
397 EM_CR16_OLD = 115,
398 EM_XGATE = 115,
399 EM_C166 = 116,
400 EM_M16C = 117,
401 EM_DSPIC30F = 118,
402 EM_CE = 119,
403 EM_M32C = 120,
404
405 EM_TSK3000 = 131,
406 EM_RS08 = 132,
407 EM_SHARC = 133,
408 EM_ECOG2 = 134,
409 EM_SCORE7 = 135,
410 EM_DSP24 = 136,
411 EM_VIDEOCORE3 = 137,
412 EM_LATTICEMICO32 = 138,
413 EM_SE_CE17 = 139,
414 EM_TI_C6000 = 140,
415 EM_TI_C2000 = 141,
416 EM_TI_C5500 = 142,
417 EM_TI_ARP32 = 143,
418 EM_TI_PRU = 144,
419
420 EM_MMDSP_PLUS = 160,
421 EM_CYPRESS_M8C = 161,
422 EM_R32C = 162,
423 EM_TRIMEDIA = 163,
424 EM_QDSP6 = 164,
425 EM_8051 = 165,
426 EM_STXP7X = 166,
427 EM_NDS32 = 167,
428 EM_ECOG1 = 168,
429 EM_ECOG1X = EM_ECOG1,
430 EM_MAXQ30 = 169,
431 EM_XIMO16 = 170,
432 EM_MANIK = 171,
433 EM_CRAYNV2 = 172,
434 EM_RX = 173,
435 EM_METAG = 174,
436 EM_MCST_ELBRUS = 175,
437 EM_ECOG16 = 176,
438 EM_CR16 = 177,
439 EM_ETPU = 178,
440 EM_SLE9X = 179,
441 EM_L10M = 180,
442 EM_K10M = 181,
443 EM_INTEL182 = 182,
444 EM_AARCH64 = 183,
445 EM_ARM184 = 184,
446 EM_AVR32 = 185,
447 EM_STM8 = 186,
448 EM_TILE64 = 187,
449 EM_TILEPRO = 188,
450 EM_MICROBLAZE = 189,
451 EM_CUDA = 190,
452 EM_TILEGX = 191,
453 EM_CLOUDSHIELD = 192,
454 EM_COREA_1ST = 193,
455 EM_COREA_2ND = 194,
456 EM_ARC_COMPACT2 = 195,
457 EM_OPEN8 = 196,
458 EM_RL78 = 197,
459 EM_VIDEOCORE5 = 198,
460 EM_78KOR = 199,
461 EM_56800EX = 200,
462 EM_BA1 = 201,
463 EM_BA2 = 202,
464 EM_XCORE = 203,
465 EM_MCHP_PIC = 204,
466 EM_INTELGT = 205, // https://github.com/bminor/binutils-gdb/blob/master/include/elf/common.h
467 EM_INTEL206 = 206,
468 EM_INTEL207 = 207,
469 EM_INTEL208 = 208,
470 EM_INTEL209 = 209,
471 EM_KM32 = 210,
472 EM_KMX32 = 211,
473 EM_KMX16 = 212,
474 EM_KMX8 = 213,
475 EM_KVARC = 214,
476 EM_CDP = 215,
477 EM_COGE = 216,
478 EM_COOL = 217,
479 EM_NORC = 218,
480 EM_CSR_KALIMBA = 219,
481 EM_Z80 = 220,
482 EM_VISIUM = 221,
483 EM_FT32 = 222,
484 EM_MOXIE = 223,
485 EM_AMDGPU = 224,
486
487 EM_RISCV = 243,
488 // https://github.com/bminor/binutils-gdb/blob/master/include/elf/common.h
489 EM_LANAI = 244,
490 EM_CEVA = 245,
491 EM_CEVA_X2 = 246,
492 EM_BPF = 247,
493 EM_GRAPHCORE_IPU = 248,
494 EM_IMG1 = 249,
495 EM_NFP = 250,
496 EM_VE = 251,
497 EM_CSKY = 252,
498 EM_ARC_COMPACT3_64 = 253,
499 EM_MCS6502 = 254,
500 EM_ARC_COMPACT3 = 255,
501 EM_KVX = 256,
502 EM_65816 = 257,
503 EM_LOONGARCH = 258,
504 EM_KF32 = 259,
505 EM_U16_U8CORE = 260,
506 EM_TACHYUM = 261,
507 EM_56800EF = 262,
508
509 // apparently used by BeOS for the AT&T Hobbit
510 EM_HOBBIT = 925,
511
512 // https://llvm-mos.org/wiki/ELF_specification
513 EM_MOS = 6502,
514 };
515 cpu_type cpu = EM_NONE;
516
517 uint8_t header_version = 0;
518 uint8_t osabi = 0;
519 uint8_t abi_version = 0;
520
521 enum file_type
522 {
523 ET_NONE = 0,
524 ET_REL = 1,
525 ET_EXEC = 2,
526 ET_DYN = 3,
527 ET_CORE = 4,
528 };
529 file_type object_file_type = ET_NONE;
530 uint16_t file_version = 0;
531
532 offset_t entry = 0;
533 offset_t program_header_offset = 0;
534 offset_t section_header_offset = 0;
535 uint32_t flags = 0;
536 uint16_t elf_header_size = 0;
537 uint16_t program_header_entry_size = 0;
538 uint16_t section_header_entry_size = 0;
539 uint32_t section_name_string_table = 0;
540
542 {
543 public:
544 virtual void AddDumperFields(std::unique_ptr<Dumper::Region>& region, Dumper::Dumper& dump, const ELFFormat& fmt, unsigned index) const;
545 virtual void Dump(Dumper::Dumper& dump, const ELFFormat& fmt, unsigned index) const;
546 };
547
548 class Symbol
549 {
550 public:
551 uint32_t name_offset = 0;
552 std::string name;
553 offset_t value = 0, size = 0;
554 uint8_t bind = 0, type = 0, other = 0;
555 uint32_t shndx = 0;
556 uint32_t sh_link = 0;
557 bool defined = false;
558 bool unallocated = false;
559 Linker::Location location;
560 Linker::SymbolDefinition specification;
561 };
562
564 {
565 public:
566 size_t wordbytes;
567 offset_t entsize;
568 /* used for SHT_SYMTAB and SHT_DYNSYM */
569 std::vector<Symbol> symbols;
570
571 SymbolTable(size_t wordbytes, offset_t entsize)
572 : wordbytes(wordbytes), entsize(entsize)
573 {
574 }
575
576 offset_t ImageSize() const override;
577 offset_t WriteFile(const std::shared_ptr<Linker::Writer>& wr) const override;
578 void Dump(Dumper::Dumper& dump, const ELFFormat& fmt, unsigned index) const override;
579 };
580
582 {
583 public:
584 offset_t size;
585 /* used for SHT_STRTAB */
586 std::vector<std::string> strings;
587
588 StringTable(offset_t size)
589 : size(size)
590 {
591 }
592
593 offset_t ImageSize() const override;
594 offset_t WriteFile(const std::shared_ptr<Linker::Writer>& wr) const override;
595 void Dump(Dumper::Dumper& dump, const ELFFormat& fmt, unsigned index) const override;
596 };
597
598 class Array : public SectionContents
599 {
600 public:
601 offset_t entsize;
602 /* used for SHT_SYMTAB_SHNDX, SHT_INIT_ARRAY/SHT_FINI_ARRAY/SHT_PREINIT_ARRAY, SHT_GROUP */
603 std::vector<offset_t> array;
604
605 Array(offset_t entsize)
606 : entsize(entsize)
607 {
608 }
609
610 offset_t ImageSize() const override;
611 offset_t WriteFile(const std::shared_ptr<Linker::Writer>& wr) const override;
612 void Dump(Dumper::Dumper& dump, const ELFFormat& fmt, unsigned index) const override;
613 };
614
615 class SectionGroup : public Array
616 {
617 public:
618 offset_t flags = 0;
619
620 SectionGroup(offset_t entsize)
621 : Array(entsize)
622 {
623 }
624
625 offset_t ImageSize() const override;
626 offset_t WriteFile(const std::shared_ptr<Linker::Writer>& wr) const override;
627 void Dump(Dumper::Dumper& dump, const ELFFormat& fmt, unsigned index) const override;
628 void AddDumperFields(std::unique_ptr<Dumper::Region>& region, Dumper::Dumper& dump, const ELFFormat& fmt, unsigned index) const override;
629 };
630
631 class IndexArray : public Array
632 {
633 public:
634 IndexArray(offset_t entsize)
635 : Array(entsize)
636 {
637 }
638
639 void Dump(Dumper::Dumper& dump, const ELFFormat& fmt, unsigned index) const override;
640 };
641
643 {
644 public:
645 offset_t offset = 0;
646 uint32_t type = 0;
647 uint32_t symbol = 0;
648 int64_t addend = 0;
649 uint32_t sh_link = 0, sh_info = 0;
650 bool addend_from_section_data = false;
651
652 size_t GetSize(cpu_type cpu) const;
653 std::string GetName(cpu_type cpu) const;
654 };
655
657 {
658 public:
659 size_t wordbytes;
660 offset_t entsize;
661 /* used for SHT_REL, SHT_RELA */
662 std::vector<Relocation> relocations;
663
664 Relocations(size_t wordbytes, offset_t entsize)
665 : wordbytes(wordbytes), entsize(entsize)
666 {
667 }
668
669 offset_t ImageSize() const override;
670 offset_t WriteFile(const std::shared_ptr<Linker::Writer>& wr) const override;
671 void Dump(Dumper::Dumper& dump, const ELFFormat& fmt, unsigned index) const override;
672 };
673
675 {
676 public:
677 std::vector<uint32_t> buckets;
678 std::vector<uint32_t> chains;
679
680 static uint32_t Hash(const std::string& name);
681
682 offset_t ImageSize() const override;
683 offset_t WriteFile(const std::shared_ptr<Linker::Writer>& wr) const override;
684 void Dump(Dumper::Dumper& dump, const ELFFormat& fmt, unsigned index) const override;
685 void AddDumperFields(std::unique_ptr<Dumper::Region>& region, Dumper::Dumper& dump, const ELFFormat& fmt, unsigned index) const override;
686 };
687
689 {
690 public:
691 offset_t tag;
692 offset_t value;
693 std::string name;
694
696 : tag(0), value(0)
697 {
698 }
699
700 DynamicObject(offset_t tag, offset_t value)
701 : tag(tag), value(value)
702 {
703 }
704 };
705
707 {
708 public:
709 size_t wordbytes;
710 offset_t entsize;
711 /* used for SHT_DYNAMIC */
712 std::vector<DynamicObject> dynamic;
713
714 DynamicSection(size_t wordbytes, offset_t entsize)
715 : wordbytes(wordbytes), entsize(entsize)
716 {
717 }
718
719 offset_t ImageSize() const override;
720 offset_t WriteFile(const std::shared_ptr<Linker::Writer>& wr) const override;
721 void Dump(Dumper::Dumper& dump, const ELFFormat& fmt, unsigned index) const override;
722 };
723
724 class Note
725 {
726 public:
727 std::string name;
728 std::string descriptor;
729 offset_t type;
730 };
731
733 {
734 public:
735 offset_t size;
736
737 /* used for SHT_NOTE */
738 std::vector<Note> notes;
739
740 NotesSection(offset_t size)
741 : size(size)
742 {
743 }
744
745 offset_t ImageSize() const override;
746 offset_t WriteFile(const std::shared_ptr<Linker::Writer>& wr) const override;
747 void Dump(Dumper::Dumper& dump, const ELFFormat& fmt, unsigned index) const override;
748 };
749
751 {
752 public:
754 {
755 public:
756 uint32_t hash = 0;
757 uint16_t flags = 0;
758 uint16_t other = 0;
759 uint32_t name_offset = 0;
760 std::string name;
761 uint32_t offset_next_entry = 0;
762 };
763
764 uint16_t version = 0;
765 uint32_t file_name_offset = 0;
766 std::string file_name;
767 uint32_t offset_auxiliary_array = 0;
768 std::vector<Auxiliary> auxiliary_array;
769 uint32_t offset_next_entry = 0;
770 };
771
773 {
774 public:
775 std::vector<VersionRequirement> requirements;
776
777 offset_t ImageSize() const override;
778 offset_t WriteFile(const std::shared_ptr<Linker::Writer>& wr) const override;
779 void Dump(Dumper::Dumper& dump, const ELFFormat& fmt, unsigned index) const override;
780 };
781
782 /* IBM OS/2 extension */
784 {
785 public:
786 enum system_type : uint32_t
787 {
788 EOS_NONE = 0,
789 EOS_PN = 1,
790 EOS_SVR4 = 2,
791 EOS_AIX = 3,
792 EOS_OS2 = 4,
793 };
794 system_type os_type = EOS_NONE;
795 uint32_t os_size = 0;
796 bool IsOS2Specific() const;
798 {
799 /* OS/2 specific */
800 enum os2_session : uint8_t
801 {
802 OS2_SES_NONE = 0,
803 OS2_SES_FS = 1,
804 OS2_SES_PM = 2,
805 OS2_SES_VIO = 3,
806 };
807 os2_session sessiontype = OS2_SES_NONE;
808 uint8_t sessionflags;
809 } os2;
810 /* unspecified */
811 std::vector<uint8_t> os_specific;
812
813 offset_t ImageSize() const override;
814 offset_t WriteFile(const std::shared_ptr<Linker::Writer>& wr) const override;
815 void AddDumperFields(std::unique_ptr<Dumper::Region>& region, Dumper::Dumper& dump, const ELFFormat& fmt, unsigned index) const override;
816 };
817
818 /* IBM OS/2 extension */
820 {
821 public:
822 uint32_t ordinal = 0, name_offset = 0;
823 std::string name;
824 enum import_type
825 {
826 IMP_IGNORED = 0,
827 IMP_STR_IDX = 1,
828 IMP_DT_IDX = 2,
829 };
830 import_type type = IMP_IGNORED;
831 uint32_t dll = 0;
832 std::string dll_name;
833 };
834
835 /* IBM OS/2 extension */
837 {
838 public:
839 offset_t entsize;
840 std::vector<IBMImportEntry> imports;
841
842 IBMImportTable(offset_t entsize)
843 : entsize(entsize)
844 {
845 }
846
847 offset_t ImageSize() const override;
848 offset_t WriteFile(const std::shared_ptr<Linker::Writer>& wr) const override;
849 void Dump(Dumper::Dumper& dump, const ELFFormat& fmt, unsigned index) const override;
850 };
851
852 /* IBM OS/2 extension */
854 {
855 public:
856 uint32_t ordinal = 0, symbol_index = 0, name_offset = 0;
857 std::string name;
858 uint32_t sh_link = 0, sh_info = 0;
859 };
860
861 /* IBM OS/2 extension */
863 {
864 public:
865 offset_t entsize;
866 std::vector<IBMExportEntry> exports;
867
868 IBMExportTable(offset_t entsize)
869 : entsize(entsize)
870 {
871 }
872
873 offset_t ImageSize() const override;
874 offset_t WriteFile(const std::shared_ptr<Linker::Writer>& wr) const override;
875 void Dump(Dumper::Dumper& dump, const ELFFormat& fmt, unsigned index) const override;
876 };
877
878 /* IBM OS/2 extension */
880 {
881 public:
882 uint32_t type = 0;
883 uint32_t ordinal = 0;
884 uint32_t name_offset = 0;
885 std::string name;
886 uint32_t data_offset = 0;
887 uint32_t data_size = 0;
888 std::shared_ptr<Linker::Contents> data;
889 };
890
891 /* IBM OS/2 extension */
893 {
894 public:
895#if 0
896 uint32_t offset = 0;
897 uint32_t size = 0;
898#endif
899
900 offset_t offset = 0;
901
902 uint16_t version = 0;
903 uint16_t flags = 0;
904 uint32_t name_offset = 0;
905 std::string name;
906 uint32_t item_array_offset = 0;
907 uint32_t item_array_entry_size = 0;
908 uint32_t header_size = 0;
909 uint32_t string_table_offset = 0;
910 uint32_t locale_offset = 0;
911
912 char16_t country[2] = { };
913 char16_t language[2] = { };
914
915 std::vector<IBMResource> resources;
916
917 offset_t ImageSize() const override;
918 offset_t WriteFile(const std::shared_ptr<Linker::Writer>& wr) const override;
919 void Dump(Dumper::Dumper& dump, const ELFFormat& fmt, unsigned index) const override;
920 void AddDumperFields(std::unique_ptr<Dumper::Region>& region, Dumper::Dumper& dump, const ELFFormat& fmt, unsigned index) const override;
921 };
922
923#if 0
924 /* IBM OS/2 extension */
925 class IBMResourceFile
926 {
927 public:
928 uint8_t file_class = 0;
929 EndianType endiantype = ::LittleEndian;
930
931 uint8_t data_encoding = 0;
932 size_t wordbytes = 4;
933
934 uint8_t version = 0;
935
936 uint32_t header_size = 0;
937 uint32_t resource_collection_offset = 0;
938 std::vector<IBMResourceCollection> resource_collections;
939 };
940#endif
941
943 {
944 public:
945 uint32_t name_offset = 0;
946 std::string name;
947 enum section_type
948 {
949 SHT_NULL = 0,
950 SHT_PROGBITS = 1,
951 SHT_SYMTAB = 2,
952 SHT_STRTAB = 3,
953 SHT_RELA = 4,
954 SHT_HASH = 5,
955 SHT_DYNAMIC = 6,
956 SHT_NOTE = 7,
957 SHT_NOBITS = 8,
958 SHT_REL = 9,
959 SHT_SHLIB = 10, /* reserved */
960 SHT_DYNSYM = 11,
961 SHT_INIT_ARRAY = 14,
962 SHT_FINI_ARRAY = 15,
963 SHT_PREINIT_ARRAY = 16,
964 SHT_GROUP = 17,
965 SHT_SYMTAB_SHNDX = 18,
966 /* IBM OS/2 specific */
967 SHT_OS = 0x60000001,
968 SHT_IMPORTS = 0x60000002,
969 SHT_EXPORTS = 0x60000003,
970 SHT_RES = 0x60000004,
971
972 SHT_OLD_OS = 12,
973 SHT_OLD_IMPORTS = 13,
974 SHT_OLD_EXPORTS = 14,
975 SHT_OLD_RES = 15,
976
977 /* GNU extensions */
978 SHT_GNU_INCREMENTAL_INPUTS = 0x6FFF4700,
979 SHT_GNU_ATTRIBUTES = 0x6FFFFFF5,
980 SHT_GNU_HASH = 0x6FFFFFF6,
981 SHT_GNU_LIBLIST = 0x6FFFFFF7,
982 SHT_SUNW_verdef = 0x6FFFFFFD,
983 SHT_SUNW_verneed = 0x6FFFFFFE,
984 SHT_SUNW_versym = 0x6FFFFFFF,
985 };
986 section_type type = SHT_NULL;
987 uint32_t link = 0, info = 0;
988 offset_t flags = 0;
989 offset_t address = 0, file_offset = 0, size = 0, align = 0, entsize = 0;
990
991 std::shared_ptr<Linker::Contents> contents;
992
993 std::shared_ptr<Linker::Section> GetSection();
994 const std::shared_ptr<Linker::Section> GetSection() const;
995
996 std::shared_ptr<SymbolTable> GetSymbolTable();
997 const std::shared_ptr<SymbolTable> GetSymbolTable() const;
998
999#if 0
1000 std::shared_ptr<StringTable> GetStringTable();
1001#endif
1002 std::shared_ptr<Array> GetArray();
1003
1004 std::shared_ptr<Relocations> GetRelocations();
1005 const std::shared_ptr<Relocations> GetRelocations() const;
1006
1007 std::shared_ptr<DynamicSection> GetDynamicSection();
1008
1009#if 0
1010 std::shared_ptr<NotesSection> GetNotesSection();
1011
1012 std::shared_ptr<IBMSystemInfo> GetIBMSystemInfo();
1013#endif
1014
1015 std::shared_ptr<IBMImportTable> GetIBMImportTable();
1016 std::shared_ptr<IBMExportTable> GetIBMExportTable();
1017
1018 bool GetFileSize() const;
1019
1020 void Dump(Dumper::Dumper& dump, const ELFFormat& fmt, unsigned index) const;
1021
1022 static std::shared_ptr<Linker::Section> ReadProgBits(const std::shared_ptr<Linker::Reader>& rd, offset_t file_offset, const std::string& name, offset_t size);
1023 static std::shared_ptr<Linker::Section> ReadNoBits(const std::string& name, offset_t size);
1024 static std::shared_ptr<SymbolTable> ReadSymbolTable(const std::shared_ptr<Linker::Reader>& rd, offset_t file_offset, offset_t section_size, offset_t entsize, uint32_t section_link, size_t wordbytes);
1025 static std::shared_ptr<Relocations> ReadRelocations(const std::shared_ptr<Linker::Reader>& rd, Section::section_type type, offset_t file_offset, offset_t section_size, offset_t entsize, uint32_t section_link, uint32_t section_info, size_t wordbytes);
1026 static std::shared_ptr<StringTable> ReadStringTable(const std::shared_ptr<Linker::Reader>& rd, offset_t file_offset, offset_t section_size);
1027 static std::shared_ptr<Array> ReadArray(const std::shared_ptr<Linker::Reader>& rd, offset_t file_offset, offset_t section_size, offset_t entsize);
1028 static std::shared_ptr<SectionGroup> ReadSectionGroup(const std::shared_ptr<Linker::Reader>& rd, offset_t file_offset, offset_t section_size, offset_t entsize);
1029 static std::shared_ptr<IndexArray> ReadIndexArray(const std::shared_ptr<Linker::Reader>& rd, offset_t file_offset, offset_t section_size, offset_t entsize);
1030 static std::shared_ptr<HashTable> ReadHashTable(const std::shared_ptr<Linker::Reader>& rd, offset_t file_offset);
1031 static std::shared_ptr<DynamicSection> ReadDynamic(const std::shared_ptr<Linker::Reader>& rd, offset_t file_offset, offset_t section_size, offset_t entsize, size_t wordbytes);
1032 static std::shared_ptr<NotesSection> ReadNote(const std::shared_ptr<Linker::Reader>& rd, offset_t file_offset, offset_t section_size);
1033 static std::shared_ptr<VersionRequirements> ReadVersionRequirements(const std::shared_ptr<Linker::Reader>& rd, offset_t file_offset, offset_t section_link, offset_t section_info);
1034 static std::shared_ptr<IBMSystemInfo> ReadIBMSystemInfo(const std::shared_ptr<Linker::Reader>& rd, offset_t file_offset);
1035 static std::shared_ptr<IBMImportTable> ReadIBMImportTable(const std::shared_ptr<Linker::Reader>& rd, offset_t file_offset, offset_t section_size, offset_t entsize);
1036 static std::shared_ptr<IBMExportTable> ReadIBMExportTable(const std::shared_ptr<Linker::Reader>& rd, offset_t file_offset, offset_t section_size, offset_t entsize);
1037 static std::shared_ptr<IBMResourceCollection> ReadIBMResourceCollection(const std::shared_ptr<Linker::Reader>& rd, offset_t file_offset);
1038 };
1039 std::vector<Section> sections;
1040
1042 {
1043 public:
1044 enum segment_type
1045 {
1046 PT_NULL = 0,
1047 PT_LOAD = 1,
1048 PT_DYNAMIC = 2,
1049 PT_INTERP = 3,
1050 PT_NOTE = 4,
1051 PT_SHLIB = 5,
1052 PT_PHDR = 6,
1053 PT_TLS = 7,
1054 /* IBM OS/2 specific */
1055 PT_OS = 0x60000001,
1056 PT_RES = 0x60000002,
1057
1058 PT_OLD_OS = 7,
1059 PT_OLD_RES = 9,
1060 /* SUN, GNU, OpenBSD extensions */
1061 PT_SUNW_EH_FRAME = 0x6474E550,
1062 PT_GNU_STACK = 0x6474E551,
1063 PT_GNU_RELRO = 0x6474E552,
1064 PT_GNU_PROPERTY = 0x6474E553,
1065 PT_GNU_SFRAME = 0x6474E554,
1066 PT_GNU_MBIND_LO = 0x6474E555,
1067 PT_GNU_MBIND_HI = 0x6474F554,
1068 PT_OPENBSD_MUTABLE = 0x65A3DBE5,
1069 PT_OPENBSD_RANDOMIZE = 0x65A3DBE6,
1070 PT_OPENBSD_WXNEEDED = 0x65A3DBE7,
1071 PT_OPENBSD_NOBTCFI = 0x65A3DBE8,
1072 PT_OPENBSD_BOOTDATA = 0x65A41BE6,
1073 };
1074 segment_type type;
1075 enum
1076 {
1078 PF_X = 0x00000001,
1080 PF_W = 0x00000002,
1082 PF_R = 0x00000004,
1083 };
1084 uint32_t flags = 0;
1085 offset_t offset = 0, vaddr = 0, paddr = 0, filesz = 0, memsz = 0, align = 0;
1086
1087 struct Part
1088 {
1089 public:
1091 {
1096 };
1097 part_type type;
1098
1099 uint32_t index;
1100 offset_t offset, size;
1101 Part(part_type type, uint32_t index, offset_t offset, offset_t size)
1102 : type(type), index(index), offset(offset), size(size)
1103 {
1104 }
1105
1106 offset_t GetOffset(const ELFFormat& fmt) const;
1107 offset_t GetActualSize(const ELFFormat& fmt) const;
1108 };
1109
1110 std::vector<Part> parts;
1111 };
1112 std::vector<Segment> segments;
1113
1114 class Block
1115 {
1116 public:
1117 offset_t offset = 0;
1118 offset_t size = 0;
1119 std::shared_ptr<Linker::Contents> image;
1120 Block(offset_t offset = 0, offset_t size = 0)
1121 : offset(offset), size(size)
1122 {
1123 }
1124 };
1126 std::vector<Block> blocks;
1127
1128 /* AT&T Hobbit BeOS specific */
1129
1135 {
1136 char type[4];
1137 offset_t unknown1, offset, size, unknown2;
1138 std::shared_ptr<Linker::Buffer> image;
1139 };
1140 offset_t hobbit_beos_resource_offset = 0;
1141 std::vector<HobbitBeOSResource> hobbit_beos_resources;
1142
1143 ELFFormat()
1144 {
1145 }
1146
1147 void ReadFile(const std::shared_ptr<Linker::Reader>& rd) override;
1148
1150 offset_t WriteFile(const std::shared_ptr<Linker::Writer>& wr) const override;
1151
1152 void Dump(Dumper::Dumper& dump) const override;
1153
1157 bool IsOldOS2Format() const;
1158
1159 /* * * Reader members * * */
1160
1161 bool option_16bit = true;
1162 bool option_linear = false;
1166 bool option_pmode = false;
1167#if 0
1171 bool option_absolute_symbols = false;
1172#endif
1173
1174 void SetupOptions(std::shared_ptr<Linker::OutputFormat> format) override;
1175
1177 void GenerateModule(Linker::Module& module) const override;
1178 void CalculateValues() override;
1179
1180 /* * * Writer members * * */
1181
1182 enum operating_system_type
1183 {
1184 Linux,
1185 AmigaOS, // TODO
1186 OS2, // TODO
1187 OS2beta, // TODO
1188 DJGPP, // TODO
1189 };
1190 operating_system_type operating_system = Linux;
1191
1192 offset_t image_base;
1193 offset_t header_size;
1194 bool create_header_segment;
1195 bool include_header_segment;
1196 offset_t segment_align;
1197 offset_t section_align;
1198
1200 {
1201 public:
1203 {
1204 //InitializeFields();
1205 }
1206 };
1207
1208 //static std::shared_ptr<PEFormat> CreateConsoleApplication(target_type target = TargetWinNT, PEOptionalHeader::SubsystemType subsystem = PEOptionalHeader::WindowsCUI);
1209 //static std::shared_ptr<PEFormat> CreateGUIApplication(target_type target = TargetWinNT, PEOptionalHeader::SubsystemType subsystem = PEOptionalHeader::WindowsGUI);
1210 //static std::shared_ptr<PEFormat> CreateLibraryModule(target_type target = TargetWinNT);
1211 //static std::shared_ptr<PEFormat> CreateDeviceDriver(target_type target = TargetWinNT);
1212 //std::shared_ptr<PEFormat> SimulateLinker(compatibility_type compatibility);
1213
1214 bool FormatSupportsLibraries() const override;
1215
1216 //unsigned FormatAdditionalSectionFlags(std::string section_name) const override;
1217
1218 //std::shared_ptr<Resource>& AddResource(std::shared_ptr<Resource>& resource);
1219
1220 static std::vector<Linker::OptionDescription<void> *> ParameterNames;
1221 std::vector<Linker::OptionDescription<void> *> GetLinkerScriptParameterNames() override;
1222 std::shared_ptr<Linker::OptionCollector> GetOptions() override;
1223
1224 void SetOptions(std::map<std::string, std::string>& options) override;
1225 void OnNewSegment(std::shared_ptr<Linker::Segment> segment) override;
1226
1227 std::unique_ptr<Script::List> GetScript(Linker::Module& module);
1228 void Link(Linker::Module& module);
1229
1230 void ProcessModule(Linker::Module& module) override;
1231 void GenerateFile(std::string filename, Linker::Module& module) override;
1233 std::string GetDefaultExtension(Linker::Module& module, std::string filename) const override;
1234 };
1235
1241 class FatELFFormat : public virtual Linker::OutputFormat
1242 {
1243 public:
1244 struct Record
1245 {
1246 ELFFormat::cpu_type cpu = ELFFormat::EM_NONE;
1247 uint8_t osabi = 0;
1248 uint8_t abi_version = 0;
1249 uint8_t file_class = 0;
1250 uint8_t data_encoding = 0;
1251 uint64_t offset = 0;
1252 uint64_t size = 0;
1253 std::shared_ptr<Linker::Contents> image;
1254
1255 static Record Read(const std::shared_ptr<Linker::Reader>& rd);
1256 void Write(const std::shared_ptr<Linker::Writer>& wr) const;
1257 };
1258 uint16_t version = ELFFormat::EV_CURRENT;
1259 std::vector<Record> records;
1260
1261 offset_t ImageSize() const override;
1262 void ReadFile(const std::shared_ptr<Linker::Reader>& rd) override;
1263
1265 offset_t WriteFile(const std::shared_ptr<Linker::Writer>& wr) const override;
1266
1267 void Dump(Dumper::Dumper& dump) const override;
1268 void CalculateValues() override;
1269 };
1270}
1271
1272#endif /* ELF_H */
An abstract interface that separates structure and presentation of the data inside a file.
Definition dumper.h:1009
Definition elf.h:599
offset_t WriteFile(const std::shared_ptr< Linker::Writer > &wr) const override
Writes data of non-zero filled sections.
Definition elf.cc:156
offset_t ImageSize() const override
Retrieves the offset of the byte after the last one belonging to this format from the first one.
Definition elf.cc:151
Definition elf.h:1115
Definition elf.h:689
Definition elf.h:707
offset_t WriteFile(const std::shared_ptr< Linker::Writer > &wr) const override
Writes data of non-zero filled sections.
Definition elf.cc:606
offset_t ImageSize() const override
Retrieves the offset of the byte after the last one belonging to this format from the first one.
Definition elf.cc:601
Definition elf.h:675
offset_t WriteFile(const std::shared_ptr< Linker::Writer > &wr) const override
Writes data of non-zero filled sections.
Definition elf.cc:756
offset_t ImageSize() const override
Retrieves the offset of the byte after the last one belonging to this format from the first one.
Definition elf.cc:751
Definition elf.h:854
Definition elf.h:863
offset_t ImageSize() const override
Retrieves the offset of the byte after the last one belonging to this format from the first one.
Definition elf.cc:985
offset_t WriteFile(const std::shared_ptr< Linker::Writer > &wr) const override
Writes data of non-zero filled sections.
Definition elf.cc:990
Definition elf.h:820
Definition elf.h:837
offset_t ImageSize() const override
Retrieves the offset of the byte after the last one belonging to this format from the first one.
Definition elf.cc:937
offset_t WriteFile(const std::shared_ptr< Linker::Writer > &wr) const override
Writes data of non-zero filled sections.
Definition elf.cc:942
offset_t ImageSize() const override
Retrieves the offset of the byte after the last one belonging to this format from the first one.
Definition elf.cc:1025
offset_t WriteFile(const std::shared_ptr< Linker::Writer > &wr) const override
Writes data of non-zero filled sections.
Definition elf.cc:1031
Definition elf.h:880
Definition elf.h:784
offset_t WriteFile(const std::shared_ptr< Linker::Writer > &wr) const override
Writes data of non-zero filled sections.
Definition elf.cc:884
offset_t ImageSize() const override
Retrieves the offset of the byte after the last one belonging to this format from the first one.
Definition elf.cc:879
Definition elf.h:632
Definition elf.h:725
Definition elf.h:733
offset_t WriteFile(const std::shared_ptr< Linker::Writer > &wr) const override
Writes data of non-zero filled sections.
Definition elf.cc:810
offset_t ImageSize() const override
Retrieves the offset of the byte after the last one belonging to this format from the first one.
Definition elf.cc:805
Definition elf.h:643
Definition elf.h:657
offset_t ImageSize() const override
Retrieves the offset of the byte after the last one belonging to this format from the first one.
Definition elf.cc:544
offset_t WriteFile(const std::shared_ptr< Linker::Writer > &wr) const override
Writes data of non-zero filled sections.
Definition elf.cc:549
Definition elf.h:616
offset_t WriteFile(const std::shared_ptr< Linker::Writer > &wr) const override
Writes data of non-zero filled sections.
Definition elf.cc:185
offset_t ImageSize() const override
Retrieves the offset of the byte after the last one belonging to this format from the first one.
Definition elf.cc:180
Definition elf.h:943
Definition elf.h:1042
@ PF_X
Executable segment.
Definition elf.h:1078
@ PF_W
Writable segment.
Definition elf.h:1080
@ PF_R
Readable segment.
Definition elf.h:1082
Definition elf.h:582
offset_t ImageSize() const override
Retrieves the offset of the byte after the last one belonging to this format from the first one.
Definition elf.cc:119
offset_t WriteFile(const std::shared_ptr< Linker::Writer > &wr) const override
Writes data of non-zero filled sections.
Definition elf.cc:124
Definition elf.h:564
offset_t ImageSize() const override
Retrieves the offset of the byte after the last one belonging to this format from the first one.
Definition elf.cc:25
offset_t WriteFile(const std::shared_ptr< Linker::Writer > &wr) const override
Writes data of non-zero filled sections.
Definition elf.cc:30
Definition elf.h:549
offset_t ImageSize() const override
Retrieves the offset of the byte after the last one belonging to this format from the first one.
Definition elf.cc:854
offset_t WriteFile(const std::shared_ptr< Linker::Writer > &wr) const override
Writes data of non-zero filled sections.
Definition elf.cc:860
ELF object and executable format.
Definition elf.h:30
void SetupOptions(std::shared_ptr< Linker::OutputFormat > format) override
Initializes the reader for linking purposes.
Definition elf.cc:2754
static constexpr offset_t R_386_SUB32
Extension, see here: https://gitlab.com/tkchia/build-ia16/-/blob/master/elf16-writeup....
Definition elf.h:111
std::vector< Linker::OptionDescription< void > * > GetLinkerScriptParameterNames() override
Returns a list of the parameters used in the linker scripts, used for documentation.
Definition elf.cc:3345
static constexpr offset_t R_386_SUB16
Extension, see here: https://gitlab.com/tkchia/build-ia16/-/blob/master/elf16-writeup....
Definition elf.h:109
void ReadFile(const std::shared_ptr< Linker::Reader > &rd) override
Loads file into memory.
Definition elf.cc:1671
static constexpr offset_t R_386_OZRELSEG16
Extension, see here: https://gitlab.com/tkchia/build-ia16/-/blob/master/elf16-writeup....
Definition elf.h:117
std::string GetDefaultExtension(Linker::Module &module, std::string filename) const override
Appends a default extension to the filename.
Definition elf.cc:3693
void SetOptions(std::map< std::string, std::string > &options) override
Passes command line parameters as settings over to format object.
Definition elf.cc:3355
static constexpr offset_t R_386_SEGRELATIVE
Extension, see here: https://gitlab.com/tkchia/build-ia16/-/blob/master/elf16-writeup....
Definition elf.h:113
void CalculateValues() override
Intermediate step between processing module and generating output file to set up headers and manageme...
Definition elf.cc:3223
std::shared_ptr< Linker::OptionCollector > GetOptions() override
Returns object containing a sequence of option fields provided with the -S command line flag.
Definition elf.cc:3350
void Dump(Dumper::Dumper &dump) const override
Display file contents in a nice manner.
Definition elf.cc:2284
bool IsOldOS2Format() const
Attempts to heuristically determine if it is in a beta OS/2 format.
Definition elf.cc:2718
offset_t WriteFile(const std::shared_ptr< Linker::Writer > &wr) const override
Stores data in memory to file.
Definition elf.cc:2170
void ProcessModule(Linker::Module &module) override
Processes the module object and initializes format fields.
Definition elf.cc:3458
bool option_pmode
Set when the generated format runs in protected mode.
Definition elf.h:1166
std::vector< Block > blocks
Collection of blocks of data that do not belong to any section.
Definition elf.h:1126
void GenerateFile(std::string filename, Linker::Module &module) override
The main function that handles processing, calculating and generating the final image.
Definition elf.cc:3569
void GenerateModule(Linker::Module &module) const override
Loads the information into a module object, a convenience method when there is a single module genera...
Definition elf.cc:2761
static constexpr offset_t R_386_OZSEG16
Extension, see here: https://gitlab.com/tkchia/build-ia16/-/blob/master/elf16-writeup....
Definition elf.h:115
bool FormatSupportsLibraries() const override
Whether the format supports libraries.
Definition elf.cc:3332
static constexpr offset_t R_386_SEG16
Extension, see here: https://gitlab.com/tkchia/build-ia16/-/blob/master/elf16-writeup....
Definition elf.h:107
FatELF developed by icculus (Ryan C. Gordon) to contain multiple ELF binaries for different architect...
Definition elf.h:1242
void ReadFile(const std::shared_ptr< Linker::Reader > &rd) override
Loads file into memory.
Definition elf.cc:3749
offset_t WriteFile(const std::shared_ptr< Linker::Writer > &wr) const override
Stores data in memory to file.
Definition elf.cc:3775
void Dump(Dumper::Dumper &dump) const override
Display file contents in a nice manner.
Definition elf.cc:3800
offset_t ImageSize() const override
Retrieves the offset of the byte after the last one belonging to this format from the first one.
Definition elf.cc:3736
void CalculateValues() override
Intermediate step between processing module and generating output file to set up headers and manageme...
Definition elf.cc:3821
Represents abstract data contents whose data can be written to a file.
Definition image.h:17
offset_t WriteFile(const std::shared_ptr< Writer > &wr) const override=0
Stores data in memory to file.
A class that provides a general interface to loading a module.
Definition format.h:218
virtual void GenerateModule(ModuleCollector &linker, std::string file_name, bool is_library=false) const
Loads the information into a module object.
Definition format.cc:226
Represents a single offset within a section, or an absolute location in memory if the section is null...
Definition location.h:17
Encodes an object module file as a collection of sections, symbols and relocations.
Definition module.h:24
Helper class that contains the options interpreted by the format.
Definition options.h:499
A class that provides a general interface to setting up generation for a format.
Definition format.h:69
virtual std::string GetDefaultExtension(Module &module, std::string filename) const
Appends a default extension to the filename.
A helper class to collect sections into segments.
Definition segment_manager.h:32
Represents a symbol definition.
Definition symbol_definition.h:16
Resources for the prototype BeOS Development Release for the AT&T Hobbit.
Definition elf.h:1135
Definition elf.h:1088
part_type
Definition elf.h:1091
Definition elf.h:1245