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