RetroLinker
Linker for several 8-bit, 16-bit and 32-bit formats
Loading...
Searching...
No Matches
coff.h
1#ifndef COFF_H
2#define COFF_H
3
4#include <array>
5#include <map>
6#include "cpm68k.h"
7#include "mzexe.h"
8#include "../common.h"
9#include "../linker/module.h"
10#include "../linker/options.h"
11#include "../linker/segment.h"
12#include "../linker/segment_manager.h"
13#include "../linker/writer.h"
14
15namespace COFF
16{
27 class COFFFormat : public virtual Linker::InputFormat, public virtual Linker::SegmentManager
28 {
29 public:
30 /* * * General members * * */
31
35 enum cpu
36 {
37 CPU_UNKNOWN = 0,
38
40
45 CPU_I386 = 0x014C,
46
51 CPU_M68K = 0x0150,
52
54
59 CPU_W65 = 0x6500,
60
65 CPU_Z80 = 0x805A,
66
71 CPU_Z8K = 0x8000,
72
74
79 CPU_I86 = 0x0148,
80
85 CPU_I286 = 0x014A,
86
91 CPU_NS32K = 0x0154,
92
97 CPU_I370 = 0x0158,
98
103 CPU_MIPS = 0x0160,
104
109 CPU_M88K = 0x016D,
110
115 CPU_WE32K = 0x0170,
116
121 CPU_VAX = 0x017D,
122
127 CPU_AM29K = 0x017A,
128
133 CPU_ALPHA = 0x0183,
134
139 CPU_PPC = 0x01DF,
140
145 CPU_PPC64 = 0x01F7,
146
148 CPU_SHARC = 0x521C,
149
151
152 CPU_C5400 = 0x0098,
153 CPU_C6000 = 0x0099,
154 CPU_C5500 = 0x009C,
155 CPU_MSP430 = 0x00A0,
156
158
163 CPU_I860 = 0x014D,
164
169 CPU_SH = 0x01A2,
170
175 CPU_ARM = 0x01C0,
176
181 CPU_AM33 = 0x01D3,
182
187 CPU_IA64 = 0x0200,
188
193 CPU_HPPA = 0x0290,
194
199 CPU_EFI = 0x0EBC,
200
205 CPU_RISCV32 = 0x5032,
206
211 CPU_RISCV64 = 0x5064,
212
217 CPU_RISCV128 = 0x5128,
218
223 CPU_AMD64 = 0x8664,
224
229 CPU_M32R = 0x9041,
230
235 CPU_ARM64 = 0xAA64,
236
238 // for now, there are no overloaded values
239 };
240
243 {
245 COFF = 1,
247 ECOFF = 2,
258 };
259
260 static constexpr COFFVariantType AnyCOFFVariant = COFFVariantType(0);
261
263 {
264 cpu actual_cpu;
265 ::EndianType endian;
266 COFFVariantType coff_variant = AnyCOFFVariant;
267 };
268
269 static const std::map<uint32_t, MachineType> MACHINE_TYPES;
270
271 offset_t file_size;
272
274 char signature[2] = { };
275
279 ::EndianType GetEndianType() const;
280
302
303 relocation_format_type relocation_format;
304
305 constexpr size_t GetRelocationEntrySize() const
306 {
307 switch(relocation_format)
308 {
309 case COFF_10:
310 return 10;
311 case COFF_14:
312 return 14;
313 case COFF_16:
314 return 16;
315 case ECOFF_8:
316 return 8;
317 case ECOFF_16:
318 return 16;
319 case XCOFF_10:
320 return 10;
321 case XCOFF_14:
322 return 14;
323 case TICOFF_10:
324 return 10;
325 case TICOFF_12:
326 return 12;
327 }
328 assert(false);
329 }
330
331 // UNIX relocations
332
334 static constexpr uint16_t R_ABS = 0;
336 static constexpr uint16_t R_DIR16 = 1;
338 static constexpr uint16_t R_REL16 = 2;
340 static constexpr uint16_t R_IND16 = 3;
342 static constexpr uint16_t R_DIR24 = 4;
344 static constexpr uint16_t R_REL24 = 5;
346 static constexpr uint16_t R_DIR32 = 6;
348 static constexpr uint16_t R_OFF8 = 7;
350 static constexpr uint16_t R_OFF16 = 8;
352 static constexpr uint16_t R_SEG12 = 9;
354 static constexpr uint16_t R_DIR32S = 10;
356 static constexpr uint16_t R_AUX = 11;
358 static constexpr uint16_t R_OPT16 = 12;
360 static constexpr uint16_t R_IND24 = 13;
362 static constexpr uint16_t R_IND32 = 14;
364 static constexpr uint16_t R_RELBYTE = 15;
366 static constexpr uint16_t R_RELWORD = 16;
368 static constexpr uint16_t R_RELLONG = 17;
370 static constexpr uint16_t R_PCRBYTE = 18;
372 static constexpr uint16_t R_PCRWORD = 19;
374 static constexpr uint16_t R_PCRLONG = 20;
375
376 // Microsoft relocations (Intel 386)
377
379 static constexpr uint16_t REL_I386_ABSOLUTE = 0;
381 static constexpr uint16_t REL_I386_DIR16 = 1;
383 static constexpr uint16_t REL_I386_REL16 = 2;
385 static constexpr uint16_t REL_I386_DIR32 = 6;
387 static constexpr uint16_t REL_I386_DIR32NB = 7;
389 static constexpr uint16_t REL_I386_SEG12 = 9;
391 static constexpr uint16_t REL_I386_SECTION = 10;
393 static constexpr uint16_t REL_I386_SECREL = 11;
395 static constexpr uint16_t REL_I386_TOKEN = 12;
397 static constexpr uint16_t REL_I386_SECREL7 = 13;
399 static constexpr uint16_t REL_I386_REL32 = 20;
400
401 // Microsoft relocations (AMD64)
402
404 static constexpr uint16_t REL_AMD64_ABSOLUTE = 0;
406 static constexpr uint16_t REL_AMD64_ADDR64 = 1;
408 static constexpr uint16_t REL_AMD64_ADDR32 = 2;
410 static constexpr uint16_t REL_AMD64_ADDR32NB = 3;
412 static constexpr uint16_t REL_AMD64_REL32 = 4;
414 static constexpr uint16_t REL_AMD64_REL32_1 = 5;
416 static constexpr uint16_t REL_AMD64_REL32_2 = 6;
418 static constexpr uint16_t REL_AMD64_REL32_3 = 7;
420 static constexpr uint16_t REL_AMD64_REL32_4 = 8;
422 static constexpr uint16_t REL_AMD64_REL32_5 = 9;
424 static constexpr uint16_t REL_AMD64_SECTION = 10;
426 static constexpr uint16_t REL_AMD64_SECREL = 11;
428 static constexpr uint16_t REL_AMD64_SECREL7 = 12;
430 static constexpr uint16_t REL_AMD64_TOKEN = 13;
432 static constexpr uint16_t REL_AMD64_SREL32 = 14;
434 static constexpr uint16_t REL_AMD64_PAIR = 15;
436 static constexpr uint16_t REL_AMD64_SSPAN32 = 16;
437
438 // Microsoft relocations (ARM)
439
441 static constexpr uint16_t REL_ARM_ABSOLUTE = 0;
443 static constexpr uint16_t REL_ARM_ADDR32 = 1;
445 static constexpr uint16_t REL_ARM_ADDR32NB = 2;
447 static constexpr uint16_t REL_ARM_BRANCH24 = 3;
449 static constexpr uint16_t REL_ARM_BRANCH11 = 4;
451 static constexpr uint16_t REL_ARM_REL32 = 10;
453 static constexpr uint16_t REL_ARM_SECTION = 14;
455 static constexpr uint16_t REL_ARM_SECREL = 15;
457 static constexpr uint16_t REL_ARM_MOV32 = 16;
459 static constexpr uint16_t REL_THUMB_MOV32 = 17;
461 static constexpr uint16_t REL_THUMB_BRANCH24 = 20;
463 static constexpr uint16_t REL_THUMB_BLX23 = 21;
465 static constexpr uint16_t REL_ARM_PAIR = 22;
466
467 // Microsoft relocations (ARM64)
468
470 static constexpr uint16_t REL_ARM64_ABSOLUTE = 0;
472 static constexpr uint16_t REL_ARM64_ADDR32 = 1;
474 static constexpr uint16_t REL_ARM64_ADDR32NB = 2;
476 static constexpr uint16_t REL_ARM64_BRANCH26 = 3;
478 static constexpr uint16_t REL_ARM64_PAGEBASE_REL21 = 4;
480 static constexpr uint16_t REL_ARM64_REL21 = 5;
482 static constexpr uint16_t REL_ARM64_PAGEOFFSET_12A = 6;
484 static constexpr uint16_t REL_ARM64_PAGEOFFSET_12L = 7;
486 static constexpr uint16_t REL_ARM64_SECREL = 8;
488 static constexpr uint16_t REL_ARM64_SECREL_LOW12A = 9;
490 static constexpr uint16_t REL_ARM64_SECREL_HIGH12A = 10;
492 static constexpr uint16_t REL_ARM64_SECREL_LOW12L = 11;
494 static constexpr uint16_t REL_ARM64_TOKEN = 12;
496 static constexpr uint16_t REL_ARM64_SECTION = 13;
498 static constexpr uint16_t REL_ARM64_ADDR64 = 14;
500 static constexpr uint16_t REL_ARM64_BRANCH19 = 15;
502 static constexpr uint16_t REL_ARM64_BRANCH14 = 16;
504 static constexpr uint16_t REL_ARM64_REL32 = 17;
505
506 // TODO: Microsoft relocations (MIPS)
507
508 // Microsoft relocations (Alpha)
509
511 static constexpr uint16_t REL_ALPHA_ABSOLUTE = 0;
513 static constexpr uint16_t REL_ALPHA_REFLONG = 1;
515 static constexpr uint16_t REL_ALPHA_REFQUAD = 2;
517 static constexpr uint16_t REL_ALPHA_GPREL32 = 3;
519 static constexpr uint16_t REL_ALPHA_LITERAL = 4;
521 static constexpr uint16_t REL_ALPHA_LITUSE = 5;
523 static constexpr uint16_t REL_ALPHA_GPDISP = 6;
525 static constexpr uint16_t REL_ALPHA_BRADDR = 7;
527 static constexpr uint16_t REL_ALPHA_HINT = 8;
529 static constexpr uint16_t REL_ALPHA_INLINE_REFLONG = 9;
531 static constexpr uint16_t REL_ALPHA_REFHI = 10;
533 static constexpr uint16_t REL_ALPHA_REFLO = 11;
535 static constexpr uint16_t REL_ALPHA_PAIR = 12;
537 static constexpr uint16_t REL_ALPHA_MATCH = 13;
539 static constexpr uint16_t REL_ALPHA_SECTION = 14;
541 static constexpr uint16_t REL_ALPHA_SECREL = 15;
543 static constexpr uint16_t REL_ALPHA_REFLONGNB = 16;
545 static constexpr uint16_t REL_ALPHA_SECRELLO = 17;
547 static constexpr uint16_t REL_ALPHA_SECRELHI = 18;
549 static constexpr uint16_t REL_ALPHA_REFQ3 = 19;
551 static constexpr uint16_t REL_ALPHA_REFQ2 = 20;
553 static constexpr uint16_t REL_ALPHA_REFQ1 = 21;
555 static constexpr uint16_t REL_ALPHA_GPRELLO = 22;
557 static constexpr uint16_t REL_ALPHA_GPRELHI = 23;
558
559 // TODO: Microsoft relocations (PowerPC)
560 // TODO: Microsoft relocations (IA64)
561
562 // TODO: Microsoft relocations (SuperH)
563
564 // Other relocation types
565
566 // https://github.com/aixoss/binutils/blob/master/include/coff/internal.h
567 // https://github.com/aixoss/binutils/blob/master/include/coff/z80.h
568 // https://github.com/aixoss/binutils/blob/master/include/coff/z8k.h
569
570 static constexpr uint16_t R_Z80_IMM8 = 0x22;
571 static constexpr uint16_t R_Z80_IMM16 = 0x01;
572 static constexpr uint16_t R_Z80_IMM24 = 0x33;
573 static constexpr uint16_t R_Z80_IMM32 = 0x17;
574 static constexpr uint16_t R_Z80_OFF8 = 0x32;
575 static constexpr uint16_t R_Z80_JR = 0x02;
576
577 static constexpr uint16_t R_Z8K_IMM4L = 0x23;
578 static constexpr uint16_t R_Z8K_IMM4H = 0x24;
579 static constexpr uint16_t R_Z8K_DISP7 = 0x25; /* djnz */
580 static constexpr uint16_t R_Z8K_IMM8 = 0x22;
581 static constexpr uint16_t R_Z8K_IMM16 = 0x01;
582 static constexpr uint16_t R_Z8K_REL16 = 0x04;
583 static constexpr uint16_t R_Z8K_IMM32 = 0x11;
584 static constexpr uint16_t R_Z8K_JR = 0x02; /* jr */
585 static constexpr uint16_t R_Z8K_CALLR = 0x05; /* callr */
586
587 static constexpr uint16_t R_W65_ABS8 = 0x01;
588 static constexpr uint16_t R_W65_ABS16 = 0x02;
589 static constexpr uint16_t R_W65_ABS24 = 0x03;
590 static constexpr uint16_t R_W65_ABS8S8 = 0x04;
591 static constexpr uint16_t R_W65_ABS8S16 = 0x05;
592 static constexpr uint16_t R_W65_ABS16S8 = 0x06;
593 static constexpr uint16_t R_W65_ABS16S16 = 0x07;
594 static constexpr uint16_t R_W65_PCR8 = 0x08;
595 static constexpr uint16_t R_W65_PCR16 = 0x09;
596 static constexpr uint16_t R_W65_DP = 0x0A;
597
602 {
603 public:
607 offset_t address;
611 uint32_t symbol_index;
615 uint32_t offset;
619 uint16_t type;
623 uint16_t information;
624
625 void Read(Linker::Reader& rd, const COFFFormat& coff);
626
627 size_t GetSize(const COFFFormat& coff) const;
628 void WriteFile(Linker::Writer& wr, const COFFFormat& coff) const;
629 void FillEntry(Dumper::Entry& entry, const COFFFormat& coff) const;
630 };
631
635 class Symbol
636 {
637 public:
641 std::string name;
645 uint32_t name_index;
649 uint32_t value;
657 uint16_t type;
668
669 void Read(Linker::Reader& rd);
670
671 bool IsExternal() const;
672
674 {
675 public:
676 virtual ~AuxiliaryEntry() = default;
677 virtual void Read(Linker::Reader& rd) = 0;
678 virtual void Write(Linker::Writer& wr) const = 0;
679 virtual void FillDumpData(Dumper::Entry& entry) const = 0;
680 };
681
683 {
684 public:
685 std::string file_name;
686
687 void Read(Linker::Reader& rd) override;
688 void Write(Linker::Writer& wr) const override;
689 void FillDumpData(Dumper::Entry& entry) const override;
690 };
691
693 {
694 public:
695 // TODO
696 int32_t section_length;
697 uint16_t relocation_entry_count;
698 uint16_t line_number_count;
699
700 void Read(Linker::Reader& rd) override;
701 void Write(Linker::Writer& wr) const override;
702 void FillDumpData(Dumper::Entry& entry) const override;
703 };
704
706 {
707 public:
708 // TODO
709 // skip 6 bytes
710 uint16_t size;
711 // skip 4 bytes
712 int32_t next_entry_index;
713
714 void Read(Linker::Reader& rd) override;
715 void Write(Linker::Writer& wr) const override;
716 void FillDumpData(Dumper::Entry& entry) const override;
717 };
718
720 {
721 public:
722 // TODO
723 int32_t tag_index;
724 // skip 2 bytes
725 uint16_t size;
726 // skip 4 bytes
727
728 void Read(Linker::Reader& rd) override;
729 void Write(Linker::Writer& wr) const override;
730 void FillDumpData(Dumper::Entry& entry) const override;
731 };
732
734 {
735 public:
736 // TODO
737 int32_t tag_index;
738 int32_t size;
739 int32_t pointer_to_line_number;
740 int32_t next_entry_index;
741 uint16_t transfer_table_index;
742
743 void Read(Linker::Reader& rd) override;
744 void Write(Linker::Writer& wr) const override;
745 void FillDumpData(Dumper::Entry& entry) const override;
746 };
747
749 {
750 public:
751 // TODO
752 int32_t tag_index;
753 uint16_t declaration_line_number;
754 uint16_t size;
755 std::array<uint16_t, 4> dimensions;
756
757 void Read(Linker::Reader& rd) override;
758 void Write(Linker::Writer& wr) const override;
759 void FillDumpData(Dumper::Entry& entry) const override;
760 };
761
763 {
764 public:
765 // TODO
766 // skip 4 bytes
767 uint16_t line_number;
768 // skip 6 bytes
769 int32_t next_entry_index; // TODO: only for beginning
770
771 void Read(Linker::Reader& rd) override;
772 void Write(Linker::Writer& wr) const override;
773 void FillDumpData(Dumper::Entry& entry) const override;
774 };
775
777 {
778 public:
779 // TODO
780 int32_t tag_index;
781 // skip 2 bytes
782 uint16_t size;
783
784 void Read(Linker::Reader& rd) override;
785 void Write(Linker::Writer& wr) const override;
786 void FillDumpData(Dumper::Entry& entry) const override;
787 };
788
789 std::unique_ptr<AuxiliaryEntry> auxiliary_entry = nullptr;
790
791 enum
792 {
794 C_EFCN = uint8_t(-1),
795 C_NULL = 0,
833 C_BLOCK = 100,
841 C_LINE,
850 };
851
852 enum
853 {
855 N_DEBUG = uint16_t(-2),
857 N_ABS = uint16_t(-1),
860 };
861
862 enum
863 {
864 T_NULL = 0,
895 };
896
897 enum
898 {
907 };
908 };
909
914 {
915 public:
919 std::string name;
925 offset_t physical_address = 0;
929 offset_t address = 0;
933 offset_t size = 0;
937 offset_t section_pointer = 0;
941 offset_t relocation_pointer = 0;
949 uint32_t relocation_count = 0;
953 uint32_t line_number_count = 0;
957 uint32_t flags = 0;
961 uint16_t memory_page_number = 0;
962
966 std::shared_ptr<Linker::Contents> image;
967
971 std::vector<std::unique_ptr<Relocation>> relocations;
972
973 /* COFF section flags (common to all variants) */
975 static constexpr uint32_t TEXT = 0x0020;
977 static constexpr uint32_t DATA = 0x0040;
979 static constexpr uint32_t BSS = 0x0080;
980
981 /* UNIX COFF section flags */
983 {
985 static constexpr uint32_t DSECT = 0x0001;
987 static constexpr uint32_t NOLOAD = 0x0002;
989 static constexpr uint32_t GROUP = 0x0004;
991 static constexpr uint32_t PAD = 0x0008;
993 static constexpr uint32_t COPY = 0x0010;
995 static constexpr uint32_t INFO = 0x0200;
997 static constexpr uint32_t OVER = 0x0400;
999 static constexpr uint32_t LIB = 0x0800;
1000 };
1001
1002 /* ECOFF section flags */
1004 {
1006 static constexpr uint32_t RDATA = 0x00000100;
1008 static constexpr uint32_t SDATA = 0x00000200;
1010 static constexpr uint32_t SBSS = 0x00000400;
1012 static constexpr uint32_t UCODE = 0x00000800;
1014 static constexpr uint32_t GOT = 0x00001000;
1016 static constexpr uint32_t DYNAMIC = 0x00002000;
1018 static constexpr uint32_t DYNSYM = 0x00004000;
1020 static constexpr uint32_t REL_DYN = 0x00008000;
1022 static constexpr uint32_t DYNSTR = 0x00010000;
1024 static constexpr uint32_t HASH = 0x00020000;
1026 static constexpr uint32_t DSOLIST = 0x00040000;
1028 static constexpr uint32_t MSYM = 0x00080000;
1030 static constexpr uint32_t EXTMASK = 0x0FF00000;
1032 static constexpr uint32_t CONFLICT = 0x00100000;
1034 static constexpr uint32_t FINI = 0x01000000;
1036 static constexpr uint32_t COMMENT = 0x02000000;
1038 static constexpr uint32_t RCONST = 0x02200000;
1040 static constexpr uint32_t XDATA = 0x02400000;
1042 static constexpr uint32_t TLSDATA = 0x02500000;
1044 static constexpr uint32_t TLSBSS = 0x02600000;
1046 static constexpr uint32_t TLSINIT = 0x02700000;
1048 static constexpr uint32_t PDATA = 0x02800000;
1050 static constexpr uint32_t LITA = 0x04000000;
1052 static constexpr uint32_t LIT8 = 0x08000000;
1054 static constexpr uint32_t LIT4 = 0x10000000;
1056 static constexpr uint32_t NRELOC_OVERFLOWED = 0x20000000;
1058 static constexpr uint32_t INIT = 0x80000000;
1059 };
1060
1061 /* PE section flags */
1063 {
1065 static constexpr uint32_t TYPE_NO_PAD = 0x00000008;
1067 static constexpr uint32_t LNK_OTHER = 0x00000100;
1069 static constexpr uint32_t LNK_INFO = 0x00000200;
1071 static constexpr uint32_t LNK_REMOVE = 0x00000800;
1073 static constexpr uint32_t LNK_COMDAT = 0x00001000;
1075 static constexpr uint32_t GPREL = 0x00008000;
1077 static constexpr uint32_t MEM_PURGEABLE = 0x00010000;
1079 static constexpr uint32_t MEM_16BIT = 0x00020000;
1081 static constexpr uint32_t MEM_LOCKED = 0x00040000;
1083 static constexpr uint32_t MEM_PRELOAD = 0x00080000;
1085 static constexpr uint32_t ALIGN_MASK = 0x00F00000;
1087 static constexpr uint32_t ALIGN_SHIFT = 20;
1089 static constexpr uint32_t LNK_NRELOC_OVFL = 0x01000000;
1091 static constexpr uint32_t MEM_DISCARDABLE = 0x02000000;
1093 static constexpr uint32_t MEM_NOT_CACHED = 0x04000000;
1095 static constexpr uint32_t MEM_NOT_PAGED = 0x08000000;
1097 static constexpr uint32_t MEM_SHARED = 0x10000000;
1099 static constexpr uint32_t MEM_EXECUTE = 0x20000000;
1101 static constexpr uint32_t MEM_READ = 0x40000000;
1103 static constexpr uint32_t MEM_WRITE = 0x80000000;
1104 };
1105
1106 /* XCOFF section flags */
1108 {
1110 static constexpr uint32_t PAD = 0x0008;
1112 static constexpr uint32_t DWARF = 0x0010;
1114 static constexpr uint32_t EXCEPT = 0x0100;
1116 static constexpr uint32_t INFO = 0x0200;
1118 static constexpr uint32_t TDATA = 0x0400;
1120 static constexpr uint32_t TBSS = 0x0800;
1122 static constexpr uint32_t LOADER = 0x1000;
1124 static constexpr uint32_t DEBUG = 0x2000;
1126 static constexpr uint32_t TYPCHK = 0x4000;
1128 static constexpr uint32_t OVERFLO = 0x8000;
1129 };
1130
1131 /* TICOFF section flags */
1133 {
1135 static constexpr uint32_t DSECT = 0x00000001;
1137 static constexpr uint32_t NOLOAD = 0x00000002;
1139 static constexpr uint32_t GROUP = 0x00000004;
1141 static constexpr uint32_t PAD = 0x00000008;
1143 static constexpr uint32_t COPY = 0x00000010;
1145 static constexpr uint32_t BLOCK = 0x00010000;
1147 static constexpr uint32_t PASS = 0x00020000;
1149 static constexpr uint32_t CLINK = 0x00040000;
1151 static constexpr uint32_t VECTOR = 0x00080000;
1153 static constexpr uint32_t PADDED = 0x00100000;
1154 };
1155
1156 void Clear();
1157
1158 Section(uint32_t flags = 0, std::shared_ptr<Linker::Contents> image = nullptr)
1159 : flags(flags), image(image)
1160 {
1161 }
1162
1163 virtual ~Section();
1164
1165 bool PresentInFile(COFFVariantType coff_variant) const;
1166 bool PresentInMemory(COFFVariantType coff_variant) const;
1167
1169 void ReadSectionHeader(Linker::Reader& rd, COFFFormat& coff_format);
1170
1172 void WriteSectionHeader(Linker::Writer& wr, const COFFFormat& coff_format);
1173
1175 virtual uint32_t ImageSize(const COFFFormat& coff_format) const;
1176
1178 virtual void ReadSectionData(Linker::Reader& rd, const COFFFormat& coff_format);
1180 virtual void WriteSectionData(Linker::Writer& wr, const COFFFormat& coff_format) const;
1182 virtual void Dump(Dumper::Dumper& dump, const COFFFormat& format, unsigned section_index) const;
1183 };
1184
1188 std::vector<std::shared_ptr<Section>> sections;
1189
1193 uint16_t section_count = 0;
1197 uint32_t timestamp = 0;
1205 uint32_t symbol_count = 0;
1209 std::vector<std::unique_ptr<Symbol>> symbols;
1217 uint16_t flags = 0;
1221 uint16_t target = 0;
1222
1227 {
1228 public:
1229 virtual ~OptionalHeader();
1233 virtual uint32_t GetSize() const = 0;
1234 virtual void ReadFile(Linker::Reader& rd) = 0;
1235 virtual void WriteFile(Linker::Writer& wr) const = 0;
1241 virtual offset_t CalculateValues(COFFFormat& coff) = 0;
1245 virtual void PostReadFile(COFFFormat& coff, Linker::Reader& rd);
1249 virtual void PostWriteFile(const COFFFormat& coff, Linker::Writer& wr) const;
1250
1251 virtual void Dump(const COFFFormat& coff, Dumper::Dumper& dump) const;
1252 };
1253
1257 std::unique_ptr<OptionalHeader> optional_header = nullptr;
1258
1260 {
1261 size_t size;
1262 CDOS68K_Relocation(size_t size = 0)
1263 : size(size)
1264 {
1265 }
1266 operator size_t() const;
1267 static CDOS68K_Relocation Create(size_t size, uint32_t offset, const COFFFormat& format);
1268 };
1269
1273 std::map<uint32_t, CDOS68K_Relocation> relocations; /* CDOS68K */
1274
1279 {
1280 public:
1281 std::unique_ptr<Linker::Buffer> buffer = nullptr;
1282
1283 UnknownOptionalHeader(offset_t size)
1284 : buffer(std::make_unique<Linker::Buffer>(size))
1285 {
1286 }
1287
1288 uint32_t GetSize() const override;
1289
1290 void ReadFile(Linker::Reader& rd) override;
1291
1292 void WriteFile(Linker::Writer& wr) const override;
1293
1294 offset_t CalculateValues(COFFFormat& coff) override;
1295
1296 void Dump(const COFFFormat& coff, Dumper::Dumper& dump) const override;
1297 };
1298
1303 {
1304 public:
1308 uint16_t magic = 0;
1312 uint16_t version_stamp = 0;
1313
1317 uint32_t code_size = 0;
1321 uint32_t data_size = 0;
1325 uint32_t bss_size = 0;
1329 uint32_t entry_address = 0;
1333 uint32_t code_address = 0;
1337 uint32_t data_address = 0;
1338
1339 AOutHeader(uint16_t magic = 0)
1340 : magic(magic)
1341 {
1342 }
1343
1344 uint32_t GetSize() const override;
1345
1346 void ReadFile(Linker::Reader& rd) override;
1347
1348 void WriteFile(Linker::Writer& wr) const override;
1349
1350 offset_t CalculateValues(COFFFormat& coff) override;
1351
1352 protected:
1353 virtual void DumpFields(const COFFFormat& coff, Dumper::Dumper& dump, Dumper::Region& header_region) const;
1354
1355 public:
1356 void Dump(const COFFFormat& coff, Dumper::Dumper& dump) const override;
1357 };
1358
1363 {
1364 public:
1365 uint32_t reserved1 = 0;
1366 uint32_t reserved2 = 0;
1367
1368 AOutHeader3B20(uint16_t magic = 0)
1369 : AOutHeader(magic)
1370 {
1371 }
1372
1373 uint32_t GetSize() const override;
1374
1375 void ReadFile(Linker::Reader& rd) override;
1376
1377 void WriteFile(Linker::Writer& wr) const override;
1378
1379 //offset_t CalculateValues(COFFFormat& coff) override;
1380
1381 protected:
1382 void DumpFields(const COFFFormat& coff, Dumper::Dumper& dump, Dumper::Region& header_region) const override;
1383
1384 //public:
1385 // void Dump(const COFFFormat& coff, Dumper::Dumper& dump) const override;
1386 };
1387
1393 {
1394 public:
1395 FlexOSAOutHeader(uint16_t magic = 0)
1396 : AOutHeader(magic)
1397 {
1398 }
1399
1407 uint32_t stack_size = 0;
1408
1409 /* TODO: magic not needed for CDOS68K? */
1410
1411 uint32_t GetSize() const override;
1412
1413 void ReadFile(Linker::Reader& rd) override;
1414
1415 void WriteFile(Linker::Writer& wr) const override;
1416
1417 offset_t CalculateValues(COFFFormat& coff) override;
1418
1419 void PostReadFile(COFFFormat& coff, Linker::Reader& rd) override;
1420
1421 void PostWriteFile(const COFFFormat& coff, Linker::Writer& wr) const override;
1422
1423 protected:
1424 void DumpFields(const COFFFormat& coff, Dumper::Dumper& dump, Dumper::Region& header_region) const override;
1425 };
1426
1432 {
1433 public:
1434 /* Note: untested */
1435 uint32_t info = 0;
1436 uint32_t code_size = 0;
1437 uint32_t data_size = 0;
1438 uint32_t bss_size = 0;
1439 uint32_t symbol_table_size = 0;
1440 uint32_t entry_address = 0;
1441 uint32_t code_relocation_size = 0;
1442 uint32_t data_relocation_size = 0;
1443
1444 uint32_t GetSize() const override;
1445
1446 void ReadFile(Linker::Reader& wr) override;
1447
1448 void WriteFile(Linker::Writer& wr) const override;
1449
1450 offset_t CalculateValues(COFFFormat& coff) override;
1451
1452 void Dump(const COFFFormat& coff, Dumper::Dumper& dump) const override;
1453 };
1454
1461 {
1462 public:
1463 // https://web.archive.org/web/20140723105157/http://www-scf.usc.edu/~csci402/ncode/coff_8h-source.html
1464 /* bss_start */
1465 uint32_t bss_address;
1466 /* gpr_mask */
1467 uint32_t gpr_mask;
1468 /* cprmask */
1469 uint32_t cpr_mask[4];
1470 /* gp_value */
1471 uint32_t gp_value;
1472
1473 MIPSAOutHeader(uint16_t magic = 0)
1474 : AOutHeader(magic)
1475 {
1476 }
1477
1478 uint32_t GetSize() const override;
1479
1480 void ReadFile(Linker::Reader& rd) override;
1481
1482 void WriteFile(Linker::Writer& wr) const override;
1483
1484 offset_t CalculateValues(COFFFormat& coff) override;
1485
1486 protected:
1487 void DumpFields(const COFFFormat& coff, Dumper::Dumper& dump, Dumper::Region& header_region) const override;
1488 };
1489
1496 {
1497 public:
1501 uint16_t magic = 0;
1502 static constexpr uint16_t SYM_STAMP = 0x030D;
1506 uint16_t version_stamp = SYM_STAMP;
1510 uint16_t build_revision = 0;
1511
1515 uint64_t code_size = 0;
1519 uint64_t data_size = 0;
1523 uint64_t bss_size = 0;
1527 uint64_t entry_address = 0;
1531 uint64_t code_address = 0;
1535 uint64_t data_address = 0;
1539 uint64_t bss_address = 0;
1541 uint32_t gpr_mask = 0;
1543 uint32_t fpr_mask = 0;
1545 uint64_t global_pointer = 0;
1546
1547 ECOFFAOutHeader(uint16_t magic = 0)
1548 : magic(magic)
1549 {
1550 }
1551
1552 uint32_t GetSize() const override;
1553
1554 void ReadFile(Linker::Reader& rd) override;
1555
1556 void WriteFile(Linker::Writer& wr) const override;
1557
1558 offset_t CalculateValues(COFFFormat& coff) override;
1559
1560 void Dump(const COFFFormat& coff, Dumper::Dumper& dump) const override;
1561 };
1562
1569 {
1570 public:
1572 bool is64 = false;
1576 uint16_t magic = 0;
1580 uint16_t version_stamp = 0;
1584 uint64_t code_size = 0;
1588 uint64_t data_size = 0;
1592 uint64_t bss_size = 0;
1596 uint64_t entry_address = 0;
1600 uint64_t code_address = 0;
1604 uint64_t data_address = 0;
1608 uint64_t toc_address = 0;
1612 uint16_t entry_section = 0;
1616 uint16_t code_section = 0;
1620 uint16_t data_section = 0;
1624 uint16_t toc_section = 0;
1628 uint16_t loader_section = 0;
1632 uint16_t bss_section = 0;
1636 uint16_t code_align = 0;
1640 uint16_t data_align = 0;
1644 uint16_t module_type = 0;
1648 uint8_t cpu_flags = 0;
1652 uint8_t cpu_type = 0;
1660 uint64_t maximum_data_size = 0;
1664 uint32_t debugger_data = 0;
1668 uint8_t code_page_size = 0;
1672 uint8_t text_page_size = 0;
1676 uint8_t stack_page_size = 0;
1680 uint8_t flags = 0;
1684 uint16_t tdata_section = 0;
1688 uint16_t tbss_section = 0;
1692 uint32_t xcoff64_flags = 0;
1693#if 0
1697 uint8_t shared_memory_page = 0;
1698#endif
1699
1700 XCOFFAOutHeader(bool is64, uint16_t magic = 0)
1701 : is64(is64), magic(magic)
1702 {
1703 }
1704
1705 uint32_t GetSize() const override;
1706
1707 void ReadFile(Linker::Reader& rd) override;
1708
1709 void WriteFile(Linker::Writer& wr) const override;
1710
1711 offset_t CalculateValues(COFFFormat& coff) override;
1712
1713 void Dump(const COFFFormat& coff, Dumper::Dumper& dump) const override;
1714 };
1715
1716 void Clear() override;
1717
1719 void AssignMagicValue(uint16_t value, ::EndianType as_endian_type);
1721 void AssignMagicValue(uint16_t value);
1723 void AssignMagicValue();
1724
1725 COFFVariantType coff_variant = AnyCOFFVariant;
1726
1732 cpu cpu_type = CPU_UNKNOWN;
1733
1737 ::EndianType endiantype = ::UndefinedEndian;
1738
1739 bool DetectCpuType(::EndianType expected);
1740
1741 void DetectCpuType();
1742
1743 void ReadFile(Linker::Reader& rd) override;
1744
1745 protected:
1746 void ReadCOFFHeader(Linker::Reader& rd);
1747 void ReadOptionalHeader(Linker::Reader& rd);
1748 void ReadRestOfFile(Linker::Reader& rd);
1749
1750 public:
1751 offset_t ImageSize() const override;
1752
1754 offset_t WriteFile(Linker::Writer& wr) const override;
1755
1756 protected:
1757 offset_t WriteFileContents(Linker::Writer& wr) const;
1758
1759 public:
1760 void Dump(Dumper::Dumper& dump) const override;
1761
1762 /* * * Reader members * * */
1763
1764 void SetupOptions(std::shared_ptr<Linker::OutputFormat> format) override;
1765
1766 bool option_segmentation = false;
1767
1768 bool FormatRequiresDataStreamFix() const override;
1769
1770 private:
1771 /* symbols */
1772 std::string segment_prefix();
1773
1774 std::string segment_of_prefix();
1775
1779 std::string segmented_address_prefix();
1780
1781#if 0
1782 // TODO: can this be used?
1783 std::string segment_difference_prefix();
1784#endif
1785
1786 enum
1787 {
1788 /* section number */
1789 N_UNDEF = 0,
1790 N_ABS = 0xFFFF,
1791 N_DEBUG = 0xFFFE,
1792
1793 /* storage class */
1794 C_EXT = 2,
1795 C_STAT = 3,
1796 C_LABEL = 6,
1797 };
1798
1799 public:
1801 void GenerateModule(Linker::Module& module) const override;
1802
1803 /* * * Writer members * * */
1804
1809 {
1813 OMAGIC = 0x0107,
1817 NMAGIC = 0x0108,
1821 ZMAGIC = 0x010B,
1825 SHMAGIC = 0x012B,
1830 };
1831 opthdr_magic_type magic_type = opthdr_magic_type(0);
1832 bool option_unmapped_zero_page = false;
1833
1835 {
1836 public:
1837 class MagicEnumeration : public Linker::Enumeration<opthdr_magic_type>
1838 {
1839 public:
1841 : Enumeration(
1842 "OMAGIC", OMAGIC,
1843 "IMPURE", OMAGIC,
1844 "NMAGIC", NMAGIC,
1845 "ROTEXT", NMAGIC,
1846 "PURE", NMAGIC,
1847 "ZMAGIC", ZMAGIC,
1848 "DEMANDPAGED", ZMAGIC)
1849 {
1850 descriptions = {
1851 { OMAGIC, "Impure executable (OMAGIC)" },
1852 { NMAGIC, "Pure executable (NMAGIC)" },
1853 { ZMAGIC, "Demand paged executable (ZMAGIC)" },
1854 };
1855 }
1856 };
1857
1858 Linker::Option<std::string> stub{"stub", "Filename for stub that gets prepended to executable"};
1859 Linker::Option<Linker::ItemOf<MagicEnumeration>> type{"type", "Executable type"};
1860 Linker::Option<bool> Nflag{"N", "Impure executable (OMAGIC)"};
1861 Linker::Option<bool> nflag{"n", "Pure executable (NMAGIC)"};
1862 Linker::Option<bool> zflag{"z", "Demand paged executable (ZMAGIC)"};
1863
1864 // TODO: make stack size a parameter (for FlexOS)
1865
1866 COFFOptionCollector()
1867 {
1868 InitializeFields(stub, type, Nflag, nflag, zflag);
1869 }
1870 };
1871
1872 // for DJGPP binaries
1873 mutable Microsoft::MZSimpleStubWriter stub;
1874
1921
1926
1930 uint32_t stub_size = 0;
1931
1935 std::shared_ptr<Linker::Segment> stack;
1939 uint32_t entry_address = 0; /* TODO */
1944
1945 COFFFormat(format_type type = GENERIC, COFFVariantType coff_variant = COFF, EndianType endiantype = ::UndefinedEndian)
1946 : coff_variant(coff_variant), endiantype(endiantype), type(type)
1947 {
1948 }
1949
1950 ~COFFFormat()
1951 {
1952 Clear();
1953 }
1954
1955 unsigned FormatAdditionalSectionFlags(std::string section_name) const override;
1956
1957 static std::vector<Linker::OptionDescription<void> *> ParameterNames;
1958 std::vector<Linker::OptionDescription<void> *> GetLinkerScriptParameterNames() override;
1959
1960 std::shared_ptr<Linker::OptionCollector> GetOptions() override;
1961
1962 void SetOptions(std::map<std::string, std::string>& options) override;
1963
1965 enum
1966 {
1981 };
1982
1983 void OnNewSegment(std::shared_ptr<Linker::Segment> segment) override;
1984
1985 void CreateDefaultSegments();
1986
1987 std::unique_ptr<Script::List> GetScript(Linker::Module& module);
1988
1989 void Link(Linker::Module& module);
1990
1992 std::shared_ptr<Linker::Segment> GetSegment(std::shared_ptr<Section>& section);
1993
1994 std::shared_ptr<Linker::Segment> GetCodeSegment();
1995
1996 std::shared_ptr<Linker::Segment> GetDataSegment();
1997
1998 std::shared_ptr<Linker::Segment> GetBssSegment();
1999
2000 void ProcessModule(Linker::Module& module) override;
2001
2002 void CalculateValues() override;
2003
2004 void GenerateFile(std::string filename, Linker::Module& module) override;
2005
2007 std::string GetDefaultExtension(Linker::Module& module, std::string filename) const override;
2008 };
2009
2010}
2011
2012#endif /* COFF_H */
AT&T 3B20 36 byte a.out optional header.
Definition coff.h:1363
uint32_t GetSize() const override
Returns size of optional header.
Definition coff.cc:1443
A standard 28 byte a.out optional header, used by AT&T UNIX and DJGPP.
Definition coff.h:1303
uint32_t code_address
Address of code (COFF name: text_start)
Definition coff.h:1333
uint16_t version_stamp
Version stamp (COFF name: vstamp)
Definition coff.h:1312
uint32_t entry_address
Initial value of eip (COFF name: entry)
Definition coff.h:1329
uint16_t magic
Type of executable, most typically ZMAGIC (COFF name: magic)
Definition coff.h:1308
uint32_t code_size
Code size (COFF name: tsize)
Definition coff.h:1317
uint32_t GetSize() const override
Returns size of optional header.
Definition coff.cc:1358
uint32_t data_size
Data size (COFF name: dsize)
Definition coff.h:1321
uint32_t bss_size
BSS size (COFF name: bsize)
Definition coff.h:1325
uint32_t data_address
Address of data (COFF name: data_start)
Definition coff.h:1337
ECOFF optional header.
Definition coff.h:1496
uint64_t bss_address
Base address for bss segment (ECOFF name: bss_start)
Definition coff.h:1539
uint32_t gpr_mask
unused (ECOFF name: gprmask)
Definition coff.h:1541
uint16_t magic
Type of executable.
Definition coff.h:1501
uint64_t data_size
Size of data segment (ECOFF name: dsize)
Definition coff.h:1519
uint32_t GetSize() const override
Returns size of optional header.
Definition coff.cc:1644
uint16_t version_stamp
Object file version stamp (ECOFF name: vstamp)
Definition coff.h:1506
uint64_t bss_size
Size of bss segment (ECOFF name: bsize)
Definition coff.h:1523
uint32_t fpr_mask
unused (ECOFF name: fprmask)
Definition coff.h:1543
uint64_t global_pointer
Initial global pointer value (ECOFF name: gp_value)
Definition coff.h:1545
uint64_t data_address
Base address for data segment (ECOFF name: data_start)
Definition coff.h:1535
uint64_t code_address
Base address for code segment (ECOFF name: text_start)
Definition coff.h:1531
uint16_t build_revision
Revision build of system tools (ECOFF name: bldrev)
Definition coff.h:1510
uint64_t code_size
Size of code segment (ECOFF name: tsize)
Definition coff.h:1515
uint64_t entry_address
Virtual address of execution start (ECOFF name: entry)
Definition coff.h:1527
Concurrent DOS 68K/FlexOS 386 optional header Concurrent DOS 68K uses the typical a....
Definition coff.h:1393
uint32_t GetSize() const override
Returns size of optional header.
Definition coff.cc:1483
void PostReadFile(COFFFormat &coff, Linker::Reader &rd) override
Retrieves any additional data from the file corresponding to this type of optional header.
Definition coff.cc:1510
void PostWriteFile(const COFFFormat &coff, Linker::Writer &wr) const override
Stores any additional data in the file corresponding to this type of optional header.
Definition coff.cc:1519
uint32_t stack_size
Size of stack for execution.
Definition coff.h:1407
uint32_t relocations_offset
The offset to the crunched relocation data within the file.
Definition coff.h:1403
GNU a.out optional header TODO.
Definition coff.h:1432
uint32_t GetSize() const override
Returns size of optional header.
Definition coff.cc:1537
56 byte long header used on MIPS
Definition coff.h:1461
uint32_t GetSize() const override
Returns size of optional header.
Definition coff.cc:1598
An abstract class to represent the optional header.
Definition coff.h:1227
virtual uint32_t GetSize() const =0
Returns size of optional header.
virtual offset_t CalculateValues(COFFFormat &coff)=0
Sets up fields to be consistent.
virtual void PostReadFile(COFFFormat &coff, Linker::Reader &rd)
Retrieves any additional data from the file corresponding to this type of optional header.
Definition coff.cc:1311
virtual void PostWriteFile(const COFFFormat &coff, Linker::Writer &wr) const
Stores any additional data in the file corresponding to this type of optional header.
Definition coff.cc:1315
A generic COFF relocation.
Definition coff.h:602
uint32_t offset
(COFF name: r_offset)
Definition coff.h:615
uint32_t symbol_index
Index of symbol in symbol table (COFF name: r_symndx)
Definition coff.h:611
uint16_t information
Assorted information (COFF name: r_bits, r_size, r_stuff etc.)
Definition coff.h:623
offset_t address
Address of the relocation (COFF name: r_vaddr)
Definition coff.h:607
uint16_t type
Type of relocation (COFF name: r_type)
Definition coff.h:619
A COFF section.
Definition coff.h:914
std::string name
The name of the section (COFF name: s_name)
Definition coff.h:919
offset_t relocation_pointer
Offset to COFF relocations (COFF name: s_relptr)
Definition coff.h:941
uint32_t relocation_count
COFF relocation count (COFF name: s_nreloc)
Definition coff.h:949
virtual void Dump(Dumper::Dumper &dump, const COFFFormat &format, unsigned section_index) const
Displays the section information and contents.
Definition coff.cc:1109
offset_t size
The size of the section (COFF name: s_size)
Definition coff.h:933
offset_t address
The virtual address of the section (COFF name: s_vaddr)
Definition coff.h:929
static constexpr uint32_t BSS
COFF section flag: Section contains uninitialized data (COFF name: STYP_BSS)
Definition coff.h:979
std::vector< std::unique_ptr< Relocation > > relocations
Collection of COFF relocations.
Definition coff.h:971
uint16_t memory_page_number
TICOFF specific field.
Definition coff.h:961
offset_t line_number_pointer
unused (COFF name: s_lnnoptr)
Definition coff.h:945
void ReadSectionHeader(Linker::Reader &rd, COFFFormat &coff_format)
Reads an entry in the section header table.
Definition coff.cc:923
static constexpr uint32_t DATA
COFF section flag: Section contains initialized data (COFF name: STYP_DATA)
Definition coff.h:977
virtual void WriteSectionData(Linker::Writer &wr, const COFFFormat &coff_format) const
Writes the section contents to a stream, can be overloaded by subclasses.
Definition coff.cc:1103
virtual void ReadSectionData(Linker::Reader &rd, const COFFFormat &coff_format)
Reads the section contents from a stream, can be overloaded by subclasses.
Definition coff.cc:1097
offset_t section_pointer
Offset of stored image data from COFF header start (COFF name: s_scnptr)
Definition coff.h:937
void WriteSectionHeader(Linker::Writer &wr, const COFFFormat &coff_format)
Writes an entry in the section header table.
Definition coff.cc:1017
offset_t physical_address
The physical address of the section (expected to be identical to the virtual address) (COFF name: s_p...
Definition coff.h:925
static constexpr uint32_t TEXT
COFF section flag: Section contains executable instructions (COFF name: STYP_TEXT)
Definition coff.h:975
uint32_t line_number_count
unused (COFF name: s_nlnno)
Definition coff.h:953
uint32_t flags
COFF section flags, determines the type of the section (text, data, bss, etc.) (COFF name: s_flags)
Definition coff.h:957
std::shared_ptr< Linker::Contents > image
The stored image data.
Definition coff.h:966
A COFF symbol.
Definition coff.h:636
std::string name
Symbol name (COFF name: n_name, if it fits inside field)
Definition coff.h:641
uint16_t section_number
The number of the section, with special values 0 (N_UNDEF), 1 (N_ABS) and 2 (N_DEBUG) (COFF name: n_s...
Definition coff.h:653
@ N_UNDEF
Undefined external symbol.
Definition coff.h:859
@ N_ABS
Absolute symbol.
Definition coff.h:857
@ N_DEBUG
Debugging symbol.
Definition coff.h:855
uint16_t type
The symbol type (COFF name: n_type)
Definition coff.h:657
@ DT_NON
Not a derived type.
Definition coff.h:900
@ DT_FCN
Function returning.
Definition coff.h:904
@ DT_ARY
Array of.
Definition coff.h:906
@ DT_PTR
Pointer to.
Definition coff.h:902
uint8_t storage_class
COFF name: n_sclass, typical values are 2 (C_EXT), 3 (C_STAT)
Definition coff.h:663
@ C_UNTAG
union tag
Definition coff.h:819
@ C_MOU
member of union
Definition coff.h:817
@ C_EFCN
Pysical end of function.
Definition coff.h:794
@ C_ULABEL
undefined label
Definition coff.h:809
@ C_AUTO
Automatic variable.
Definition coff.h:797
@ C_EXTDEF
external definition
Definition coff.h:805
@ C_SHADOW
shadow symbol
Definition coff.h:847
@ C_ALIAS
duplicated tag
Definition coff.h:843
@ C_FIELD
bit field
Definition coff.h:831
@ C_TPDEF
type definition
Definition coff.h:821
@ C_STAT
static variable
Definition coff.h:801
@ C_FCN
begin/end function
Definition coff.h:835
@ C_LABEL
label
Definition coff.h:807
@ C_WEAKEXT
external with weak linkage
Definition coff.h:849
@ C_MOS
member of structure
Definition coff.h:811
@ C_REGPARM
register parameter
Definition coff.h:829
@ C_FILE
file name
Definition coff.h:839
@ C_REG
register variable
Definition coff.h:803
@ C_USTATIC
uninitialized static
Definition coff.h:823
@ C_MOE
member of enumeration
Definition coff.h:827
@ C_EXT
external symbol
Definition coff.h:799
@ C_STRTAG
structure tag
Definition coff.h:815
@ C_ARG
function argument
Definition coff.h:813
@ C_EOS
end of structure
Definition coff.h:837
@ C_BLOCK
begin/end block
Definition coff.h:833
@ C_HIDDEN
static but avoids name conflict
Definition coff.h:845
@ C_ENTAG
enumeration tag
Definition coff.h:825
uint32_t name_index
The index of the symbol name within the string table, if not stored directly in the entry,...
Definition coff.h:645
uint8_t auxiliary_count
Signifies how many extra entries are present, these should be skipped, 0 is a typical value (COFF nam...
Definition coff.h:667
uint32_t value
The actual value of the symbol (COFF name: n_value)
Definition coff.h:649
@ T_MOE
Member of enumeration.
Definition coff.h:886
@ T_UNION
Union (C keyword union)
Definition coff.h:882
@ T_USHORT
Unsigned short integer (C type unsigned short)
Definition coff.h:890
@ T_ULONG
Unsigned long integer (C type unsigned long)
Definition coff.h:894
@ T_ENUM
Enumeration (C keyword enum)
Definition coff.h:884
@ T_CHAR
Character (C type char)
Definition coff.h:868
@ T_LONG
Long integer (C type long)
Definition coff.h:874
@ T_STRUCT
Structure (C keyword struct)
Definition coff.h:880
@ T_ARG
Function argument.
Definition coff.h:866
@ T_UINT
Unsigned integer (C type unsigned int)
Definition coff.h:892
@ T_UCHAR
Unsigned character (C type unsigned char)
Definition coff.h:888
@ T_DOUBLE
Double (C type double)
Definition coff.h:878
@ T_INT
Integer (C type int)
Definition coff.h:872
@ T_SHORT
Short integer (C type short)
Definition coff.h:870
@ T_FLOAT
Float (C type float)
Definition coff.h:876
A simplified class to represent an optional header of unknown structure.
Definition coff.h:1279
uint32_t GetSize() const override
Returns size of optional header.
Definition coff.cc:1333
XCOFF optional header.
Definition coff.h:1569
uint16_t code_align
Maximum alignment of text (XCOFF name: algntext)
Definition coff.h:1636
uint16_t version_stamp
Object file version stamp (XCOFF name: vstamp)
Definition coff.h:1580
bool is64
False for XCOFF32, true for XCOFF64.
Definition coff.h:1572
uint64_t maximum_stack_size
Maximum stack size (XCOFF name: maxstack)
Definition coff.h:1656
uint16_t magic
Type of executable (XCOFF name: mflag)
Definition coff.h:1576
uint64_t data_size
Size of data segment (XCOFF name: dsize)
Definition coff.h:1588
uint32_t xcoff64_flags
XCOFF64 specific flags (XCOFF64 name: x64flags)
Definition coff.h:1692
uint16_t toc_section
Section number for TOC (XCOFF name: sntoc)
Definition coff.h:1624
uint32_t debugger_data
Reserved for debugger (XCOFF name: debugger)
Definition coff.h:1664
uint64_t code_size
Size of code segment (XCOFF name: tsize)
Definition coff.h:1584
uint16_t entry_section
Section number for entry point (XCOFF name: snentry)
Definition coff.h:1612
uint8_t text_page_size
Requested data page size (XCOFF name: datapsize)
Definition coff.h:1672
uint64_t data_address
Base address for data segment (XCOFF name: data_start)
Definition coff.h:1604
uint16_t tbss_section
Section number for tbss (XCOFF name: sntbss)
Definition coff.h:1688
uint16_t loader_section
Section number for loader data (XCOFF name: snloader)
Definition coff.h:1628
uint64_t bss_size
Size of bss segment (XCOFF name: bsize)
Definition coff.h:1592
uint8_t cpu_type
CPU type (XCOFF name: cputype)
Definition coff.h:1652
uint8_t stack_page_size
Requested stack page size (XCOFF name: stackpsize)
Definition coff.h:1676
uint8_t cpu_flags
CPU flags (XCOFF name: cpuflag)
Definition coff.h:1648
uint16_t module_type
Module type (XCOFF name: modtype)
Definition coff.h:1644
uint16_t data_section
Section number for data (XCOFF name: sndata)
Definition coff.h:1620
uint64_t code_address
Base address for code segment (XCOFF name: text_start)
Definition coff.h:1600
uint16_t data_align
Maximum alignment of data (XCOFF name: algndata)
Definition coff.h:1640
uint16_t code_section
Section number for text (XCOFF name: sntext)
Definition coff.h:1616
uint64_t entry_address
Virtual address of execution start (XCOFF name: entry)
Definition coff.h:1596
uint64_t toc_address
Address of TOC (XCOFF name: toc)
Definition coff.h:1608
uint8_t flags
Flags.
Definition coff.h:1680
uint8_t code_page_size
Requested code page size (XCOFF name: textpsize)
Definition coff.h:1668
uint32_t GetSize() const override
Returns size of optional header.
Definition coff.cc:1695
uint16_t bss_section
Section number for bss (XCOFF name: snbss)
Definition coff.h:1632
uint16_t tdata_section
Section number for tdata (XCOFF name: sntdata)
Definition coff.h:1684
uint64_t maximum_data_size
Maximum data size (XCOFF name: maxdata)
Definition coff.h:1660
The UNIX COFF file format.
Definition coff.h:28
void Clear() override
Resets all fields to their default values, deallocate memory.
Definition coff.cc:1836
static constexpr uint16_t R_REL16
16-bit relative address of symbol
Definition coff.h:338
static constexpr uint16_t REL_ALPHA_PAIR
Displacement value for a preceding REFHI, SECRELHI, REFQ3 or REFQ2 relocation.
Definition coff.h:535
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 coff.cc:2550
COFFVariantType
Variants of the COFF file format.
Definition coff.h:243
@ COFF
Standard COFF variant (also for 32-bit ECOFF for MIPS)
Definition coff.h:245
@ ECOFF
ECOFF 64-bit version.
Definition coff.h:247
@ XCOFF32
32-bit XCOFF from IBM
Definition coff.h:249
@ TICOFF
Texas Instruments COFF variant (COFF2)
Definition coff.h:255
@ XCOFF64
64-bit XCOFF from IBM
Definition coff.h:251
@ PECOFF
Microsoft PE/COFF variant.
Definition coff.h:253
@ TICOFF1
Texas Instruments COFF variant (COFF1)
Definition coff.h:257
static constexpr uint16_t REL_AMD64_REL32_4
32-bit relative address of symbol minus 4
Definition coff.h:420
std::vector< std::shared_ptr< Section > > sections
The list of COFF sections.
Definition coff.h:1188
static constexpr uint16_t REL_ALPHA_GPDISP
reserved
Definition coff.h:523
static constexpr uint16_t R_RELWORD
16-bit direct (symbol relative) address of symbol
Definition coff.h:366
static constexpr uint16_t REL_ARM64_SECREL_LOW12A
Low 12 bits of offset from section start for ADD/ADDS.
Definition coff.h:488
static constexpr uint16_t REL_AMD64_SECTION
16-bit section index (debugging)
Definition coff.h:424
void CalculateValues() override
Intermediate step between processing module and generating output file to set up headers and manageme...
Definition coff.cc:3268
format_type
Represents the type of target system, which will determine the CPU type and several other fields.
Definition coff.h:1879
@ UNIX_3B5
AT&T UNIX System V Release 3 for the AT&T 3B5 and 3B15 (WE32K)
Definition coff.h:1895
@ UNIX
AT&T UNIX System V Release 1-3.
Definition coff.h:1887
@ UNIX_3B2
AT&T UNIX System V Release 3 for the AT&T 3B2 (WE32K)
Definition coff.h:1899
@ CDOS386
FlexOS 386 executable.
Definition coff.h:1911
@ WINDOWS
Windows Portable Executable (used only by PE)
Definition coff.h:1915
@ UNIX_3B20
AT&T UNIX System V Release 3 for the AT&T 3B20 (WE32K)
Definition coff.h:1891
@ GENERIC
An unspecified value, probably will not work.
Definition coff.h:1883
@ DJGPP
DJGPP COFF executable.
Definition coff.h:1903
@ CDOS68K
Concurrent DOS 68K executable (untested but confident)
Definition coff.h:1907
uint32_t optional_header_size
The size of the optional header (COFF: f_opthdr)
Definition coff.h:1213
static constexpr uint16_t REL_ARM64_BRANCH26
26-bit ARM relative address of symbol
Definition coff.h:476
@ FLAG_NO_SYMBOLS
F_LSYMS.
Definition coff.h:1974
@ FLAG_NO_RELOCATIONS
F_RELFLG.
Definition coff.h:1968
@ FLAG_32BIT_LITTLE_ENDIAN
F_AR32WR.
Definition coff.h:1978
@ FLAG_32BIT_BIG_ENDIAN
F_AR32W.
Definition coff.h:1980
@ FLAG_NO_LINE_NUMBERS
F_LNNO.
Definition coff.h:1972
@ FLAG_PDP11_ENDIAN
F_AR16WR.
Definition coff.h:1976
@ FLAG_EXECUTABLE
F_EXEC.
Definition coff.h:1970
static constexpr uint16_t REL_AMD64_REL32_2
32-bit relative address of symbol minus 2
Definition coff.h:416
static constexpr uint16_t REL_ARM64_BRANCH19
19-bit relative address of symbol
Definition coff.h:500
static constexpr uint16_t REL_ALPHA_REFLONG
32-bit virtual address of symbol
Definition coff.h:513
static constexpr uint16_t R_PCRLONG
32-bit PC relative address of symbol
Definition coff.h:374
static constexpr uint16_t REL_ALPHA_MATCH
Displacement value for a preceding REFLONG relocation.
Definition coff.h:537
static constexpr uint16_t REL_AMD64_SSPAN32
?
Definition coff.h:436
static constexpr uint16_t R_RELLONG
32-bit direct (symbol relative) address of symbol
Definition coff.h:368
static constexpr uint16_t REL_ALPHA_LITUSE
reserved
Definition coff.h:521
static constexpr uint16_t REL_ARM64_PAGEOFFSET_12L
12-bit page offset of symbol for LDR
Definition coff.h:484
static constexpr uint16_t R_DIR32
32-bit direct address of symbol
Definition coff.h:346
static constexpr uint16_t R_ABS
No relocation.
Definition coff.h:334
std::shared_ptr< Linker::Segment > GetSegment(std::shared_ptr< Section > &section)
Return the segment stored inside the section, note that this only works for binary generation.
Definition coff.cc:3173
static constexpr uint16_t REL_AMD64_REL32
32-bit relative address of symbol
Definition coff.h:412
static constexpr uint16_t REL_ALPHA_REFQ1
The least significant 16 bits of the 64-bit virtual address of symbol.
Definition coff.h:553
static constexpr uint16_t REL_ALPHA_INLINE_REFLONG
32-bit virtual address of symbol split into two 16-bit values; this relocation must be followed by an...
Definition coff.h:529
static constexpr uint16_t REL_ARM_MOV32
Two 32-bit ARM instructions with 32 bits of the virtual address of the symbol.
Definition coff.h:457
static constexpr uint16_t REL_I386_DIR32
32-bit virtual address of symbol
Definition coff.h:385
static constexpr uint16_t R_DIR32S
(WE32K) 32-bit direct address of symbol, byte swapped
Definition coff.h:354
static constexpr uint16_t REL_ARM_REL32
32-bit relative address of symbol
Definition coff.h:451
static constexpr uint16_t REL_ALPHA_SECREL
32-bit offset from section start (debugging)
Definition coff.h:541
static constexpr uint16_t REL_ALPHA_LITERAL
16-bit global pointer relative address of symbol
Definition coff.h:519
static constexpr uint16_t REL_I386_SECREL7
7-bit offset from section base
Definition coff.h:397
static constexpr uint16_t REL_AMD64_SECREL7
7-bit offset from section base
Definition coff.h:428
std::shared_ptr< Linker::OptionCollector > GetOptions() override
Returns object containing a sequence of option fields provided with the -S command line flag.
Definition coff.cc:2936
static constexpr uint16_t REL_ALPHA_GPRELHI
High 16 bits of 32-bit global pointer relative address of symbol.
Definition coff.h:557
static constexpr uint16_t REL_I386_SECTION
16-bit section index (debugging)
Definition coff.h:391
std::vector< Linker::OptionDescription< void > * > GetLinkerScriptParameterNames() override
Returns a list of the parameters used in the linker scripts, used for documentation.
Definition coff.cc:2931
void Dump(Dumper::Dumper &dump) const override
Display file contents in a nice manner.
Definition coff.cc:2299
static constexpr uint16_t REL_ARM64_PAGEOFFSET_12A
12-bit page offset of symbol for ADD/ADDS
Definition coff.h:482
static constexpr uint16_t REL_ARM64_SECREL_HIGH12A
Bits 12 to 23 of offset from section start for ADD/ADDS.
Definition coff.h:490
static constexpr uint16_t REL_ALPHA_ABSOLUTE
No relocation.
Definition coff.h:511
static constexpr uint16_t REL_I386_REL32
32-bit relative address of symbol
Definition coff.h:399
static constexpr uint16_t REL_ALPHA_REFQ2
The third most significant 16 bits of the 64-bit virtual address of symbol; this relocation must be f...
Definition coff.h:551
offset_t WriteFile(Linker::Writer &wr) const override
Stores data in memory to file.
Definition coff.cc:2210
format_type type
A representation of the format to generate.
Definition coff.h:1920
static constexpr uint16_t REL_ALPHA_REFHI
High 16 bits of 32-bit virtual address of symbol; this relocation must be followed by a PAIR relocati...
Definition coff.h:531
static constexpr uint16_t REL_ARM_BRANCH11
Two 16-bit instructions with 11 bits of the relative address of symbol each.
Definition coff.h:449
static constexpr uint16_t REL_THUMB_BLX23
23-bit Thumb BLX relative address of symbol
Definition coff.h:463
static constexpr uint16_t REL_ARM_ABSOLUTE
No relocation.
Definition coff.h:441
static constexpr uint16_t REL_ALPHA_REFLO
Low 16 bits of 32-bit virtual address of symbol.
Definition coff.h:533
static constexpr uint16_t REL_ALPHA_SECRELHI
High 16 bits of 32-bit offset from section start; this relocation must be followed by a PAIR relocati...
Definition coff.h:547
char signature[2]
The actual value of the magic number (COFF name: f_magic)
Definition coff.h:274
static constexpr uint16_t REL_ALPHA_GPREL32
32-bit global pointer relative address of symbol
Definition coff.h:517
static constexpr uint16_t REL_AMD64_REL32_3
32-bit relative address of symbol minus 3
Definition coff.h:418
static constexpr uint16_t REL_ARM_ADDR32
32-bit virtual address of symbol
Definition coff.h:443
std::vector< std::unique_ptr< Symbol > > symbols
The symbols stored inside the COFF file.
Definition coff.h:1209
bool FormatRequiresDataStreamFix() const override
Whether the generated file might contain bugs that require fixing.
Definition coff.cc:2545
static constexpr uint16_t REL_THUMB_MOV32
Two 32-bit Thumb instructions with 32 bits of the virtual address of the symbol.
Definition coff.h:459
static constexpr uint16_t R_OFF16
8-bit high byte of address of symbol
Definition coff.h:350
cpu
Represents the first 16-bit word of a COFF file.
Definition coff.h:36
@ CPU_IA64
Intel Itanium architecture, also known as IA-64.
Definition coff.h:187
@ CPU_ALPHA
DEC Alpha.
Definition coff.h:133
@ CPU_PPC
IBM PowerPC, 32-bit.
Definition coff.h:139
@ CPU_AMD64
x86-64, introduced by AMD
Definition coff.h:223
@ CPU_VAX
DEC VAX.
Definition coff.h:121
@ CPU_I86
Intel x86-16, introduced with the Intel 8086.
Definition coff.h:79
@ CPU_M32R
Mitsubishi M32R.
Definition coff.h:229
@ CPU_AM33
Matsushita AM33.
Definition coff.h:181
@ CPU_RISCV32
RISC-V 32.
Definition coff.h:205
@ CPU_Z8K
Zilog Z8000.
Definition coff.h:71
@ CPU_I286
Intel x86-16, introduced with the Intel 286.
Definition coff.h:85
@ CPU_Z80
Zilog Z80.
Definition coff.h:65
@ CPU_I370
IBM System/370.
Definition coff.h:97
@ CPU_NS32K
National Semiconductor NS32000.
Definition coff.h:91
@ CPU_PPC64
IBM PowerPC, 64-bit.
Definition coff.h:145
@ CPU_I386
Intel x86-32, introduced with the Intel 80386.
Definition coff.h:45
@ CPU_ARM
ARM, also known as ARM32 or AArch32; also represents Thumb.
Definition coff.h:175
@ CPU_EFI
EFI bytecode.
Definition coff.h:199
@ CPU_M68K
Motorola 68000 and compatibles.
Definition coff.h:51
@ CPU_I860
Intel i860.
Definition coff.h:163
@ CPU_WE32K
AT&T Bellmac 32, Western Electric 32000 and family.
Definition coff.h:115
@ CPU_M88K
Motorola 88000.
Definition coff.h:109
@ CPU_SH
Hitachi SuperH family.
Definition coff.h:169
@ CPU_HPPA
Hewlett-Packard PA-RISC.
Definition coff.h:193
@ CPU_SHARC
SHARC from Analog Devices.
Definition coff.h:148
@ CPU_ARM64
ARM64, also known as AArch64.
Definition coff.h:235
@ CPU_MIPS
MIPS architecture.
Definition coff.h:103
@ CPU_W65
WDC 65C816.
Definition coff.h:59
@ CPU_RISCV64
RISC-V 64.
Definition coff.h:211
@ CPU_RISCV128
RISC-V 128.
Definition coff.h:217
@ CPU_AM29K
AMD 29000.
Definition coff.h:127
static constexpr uint16_t REL_ARM64_ADDR32
32-bit virtual address of symbol
Definition coff.h:472
static constexpr uint16_t REL_ARM_SECREL
32-bit offset from section start (debugging)
Definition coff.h:455
static constexpr uint16_t R_SEG12
(Intel x86) 16-bit segment selector of symbol
Definition coff.h:352
static constexpr uint16_t REL_AMD64_ABSOLUTE
No relocation.
Definition coff.h:404
static constexpr uint16_t R_IND16
16-bit indirect address of symbol
Definition coff.h:340
static constexpr uint16_t REL_ARM64_REL32
32-bit relative address of symbol
Definition coff.h:504
::EndianType endiantype
The byte order.
Definition coff.h:1737
uint32_t relocations_offset
Concurrent DOS 68K: Offset to relocations.
Definition coff.h:1943
static constexpr uint16_t REL_ALPHA_REFQ3
The second most significant 16 bits of the 64-bit virtual address of symbol; this relocation must be ...
Definition coff.h:549
static constexpr uint16_t REL_AMD64_PAIR
?
Definition coff.h:434
static constexpr uint16_t REL_ARM64_TOKEN
CLR token.
Definition coff.h:494
static constexpr uint16_t REL_AMD64_REL32_5
32-bit relative address of symbol minus 5
Definition coff.h:422
bool option_no_relocation
Suppress relocation generation, only relevant for Concurrent DOS 68K, since the other target formats ...
Definition coff.h:1925
static constexpr uint16_t REL_ALPHA_REFQUAD
64-bit virtual address of symbol
Definition coff.h:515
static constexpr uint16_t R_PCRWORD
16-bit PC relative address of symbol
Definition coff.h:372
static constexpr uint16_t REL_I386_TOKEN
CLR token.
Definition coff.h:395
static constexpr uint16_t R_IND32
32-bit indirect address of symbol
Definition coff.h:362
static constexpr uint16_t REL_I386_SEG12
16-bit segment selector of symbol (not supported)
Definition coff.h:389
uint32_t stub_size
Size of MZ stub, only used for DJGPP COFF executables.
Definition coff.h:1930
std::shared_ptr< Linker::Segment > stack
Concurrent DOS 68K and FlexOS 386: The stack segment, not stored as part of any section.
Definition coff.h:1935
void SetupOptions(std::shared_ptr< Linker::OutputFormat > format) override
Initializes the reader for linking purposes.
Definition coff.cc:2540
void ReadFile(Linker::Reader &rd) override
Loads file into memory.
Definition coff.cc:1919
static constexpr uint16_t REL_ARM_BRANCH24
24-bit ARM relative address of symbol
Definition coff.h:447
static constexpr uint16_t REL_ARM_ADDR32NB
32-bit relative virtual address of symbol
Definition coff.h:445
void GenerateFile(std::string filename, Linker::Module &module) override
The main function that handles processing, calculating and generating the final image.
Definition coff.cc:3436
uint16_t section_count
Section count (COFF name: f_nscns)
Definition coff.h:1193
static constexpr uint16_t REL_ARM_SECTION
16-bit section index (debugging)
Definition coff.h:453
static constexpr uint16_t R_DIR24
24-bit direct address of symbol
Definition coff.h:342
static constexpr uint16_t REL_ARM64_REL21
12-bit relative address of symbol for ADR
Definition coff.h:480
uint16_t target
TI system target ID.
Definition coff.h:1221
static constexpr uint16_t REL_ALPHA_SECTION
16-bit section index (debugging)
Definition coff.h:539
uint32_t entry_address
Entry address, gets stored in optional header later.
Definition coff.h:1939
relocation_format_type
Definition coff.h:282
@ TICOFF_10
A 10-byte relocation used for TICOFF.
Definition coff.h:298
@ ECOFF_8
An 8-byte relocation, used for 32-bit ECOFF MIPS binaries.
Definition coff.h:290
@ XCOFF_10
A 10-byte relocation, used for 32-bit XCOFF32 binaries.
Definition coff.h:294
@ ECOFF_16
A 16-byte relocation, used for 64-bit ECOFF Alpha binaries.
Definition coff.h:292
@ XCOFF_14
A 14-byte relocation, used for 64-bit XCOFF64 binaries.
Definition coff.h:296
@ TICOFF_12
A 12-byte relocation used for TICOFF.
Definition coff.h:300
@ COFF_16
A 16-byte relocation, as stored by the Z80/Z8000 GNU assembler.
Definition coff.h:288
@ COFF_14
A 14-byte relocation.
Definition coff.h:286
@ COFF_10
The standard 10-byte UNIX COFF relocation format, also used for Microsoft PE COFF objects.
Definition coff.h:284
static constexpr uint16_t REL_ARM64_ADDR64
64-bit virtual address of symbol
Definition coff.h:498
static constexpr uint16_t REL_AMD64_ADDR32
32-bit virtual address of symbol
Definition coff.h:408
static constexpr uint16_t R_IND24
24-bit indirect address of symbol
Definition coff.h:360
static constexpr uint16_t REL_ARM64_ABSOLUTE
No relocation.
Definition coff.h:470
opthdr_magic_type
Value stored as the magic of the a.out header.
Definition coff.h:1809
@ SHMAGIC
Shared library.
Definition coff.h:1825
@ MAGIC_FLEXOS386
Magic number required by FlexOS 386.
Definition coff.h:1829
@ NMAGIC
Shared text - text segment is write protected, data segment follows on the next page.
Definition coff.h:1817
@ ZMAGIC
Demand paged.
Definition coff.h:1821
@ OMAGIC
Impure format - text segment is not write protected, text and data segment are contiguous.
Definition coff.h:1813
static constexpr uint16_t REL_THUMB_BRANCH24
24-bit Thumb relative address of symbol
Definition coff.h:461
static constexpr uint16_t R_OPT16
16-bit (WE32K) optimized indirect address of symbol
Definition coff.h:358
static constexpr uint16_t REL_AMD64_SECREL
32-bit offset from section start (debugging)
Definition coff.h:426
uint32_t symbol_count
The number of symbols (COFF name: f_nsyms)
Definition coff.h:1205
void AssignMagicValue()
Loads the currently set CPU value in the currently set byte order into the COFF header signature.
Definition coff.cc:1858
static constexpr uint16_t REL_I386_SECREL
32-bit offset from section start (debugging)
Definition coff.h:393
static constexpr uint16_t REL_ALPHA_SECRELLO
Low 16 bits of 32-bit offset from section start (debugging)
Definition coff.h:545
static constexpr uint16_t REL_I386_DIR32NB
32-bit relative virtual address of symbol
Definition coff.h:387
static constexpr uint16_t R_PCRBYTE
8-bit PC relative address of symbol
Definition coff.h:370
static constexpr uint16_t R_DIR16
16-bit direct address of symbol
Definition coff.h:336
static constexpr uint16_t REL_ARM64_ADDR32NB
32-bit relative virtual address of symbol
Definition coff.h:474
static constexpr uint16_t REL_I386_ABSOLUTE
No relocation.
Definition coff.h:379
static constexpr uint16_t REL_ARM64_BRANCH14
14-bit relative address of symbol for TBZ/TBNZ
Definition coff.h:502
void SetOptions(std::map< std::string, std::string > &options) override
Passes command line parameters as settings over to format object.
Definition coff.cc:2941
static constexpr uint16_t REL_I386_DIR16
16-bit virtual address of symbol (not supported)
Definition coff.h:381
static constexpr uint16_t R_REL24
24-bit relative address of symbol
Definition coff.h:344
void ProcessModule(Linker::Module &module) override
Processes the module object and initializes format fields.
Definition coff.cc:3208
::EndianType GetEndianType() const
Retrieves the natural byte order for the architecture.
Definition coff.cc:130
static constexpr uint16_t R_OFF8
8-bit low byte of address of symbol
Definition coff.h:348
static constexpr uint16_t REL_ARM64_SECTION
16-bit section index (debugging)
Definition coff.h:496
offset_t symbol_table_offset
Offset to the first symbol (COFF name: f_symptr)
Definition coff.h:1201
std::map< uint32_t, CDOS68K_Relocation > relocations
Concurrent DOS 68K requires a special block of data to represent "crunched" relocations (see CPM68KWr...
Definition coff.h:1273
static constexpr uint16_t R_AUX
Auxiliary relocation.
Definition coff.h:356
static constexpr uint16_t REL_ALPHA_HINT
14-bit hint for jump target
Definition coff.h:527
static constexpr uint16_t REL_ARM64_PAGEBASE_REL21
Page base of symbol for ADRP.
Definition coff.h:478
void OnNewSegment(std::shared_ptr< Linker::Segment > segment) override
Callback function when allocating a new segment When the linker script runs, it creates segments cons...
Definition coff.cc:2982
static constexpr uint16_t REL_AMD64_SREL32
?
Definition coff.h:432
static constexpr uint16_t REL_AMD64_ADDR64
64-bit virtual address of symbol
Definition coff.h:406
static constexpr uint16_t REL_ALPHA_BRADDR
21-bit relative address of symbol
Definition coff.h:525
std::string GetDefaultExtension(Linker::Module &module, std::string filename) const override
Appends a default extension to the filename.
Definition coff.cc:3596
static constexpr uint16_t REL_ARM64_SECREL
32-bit offset from section start (debugging)
Definition coff.h:486
offset_t ImageSize() const override
Retrieves size of stored data.
Definition coff.cc:2222
static constexpr uint16_t REL_ARM_PAIR
?
Definition coff.h:465
static constexpr uint16_t REL_AMD64_ADDR32NB
32-bit relative virtual address of symbol
Definition coff.h:410
static constexpr uint16_t REL_ALPHA_REFLONGNB
32-bit relative virtual address of symbol
Definition coff.h:543
std::unique_ptr< OptionalHeader > optional_header
The optional header instance used for reading/writing the COFF file.
Definition coff.h:1257
static constexpr uint16_t REL_I386_REL16
16-bit relative address of symbol (not supported)
Definition coff.h:383
static constexpr uint16_t REL_AMD64_REL32_1
32-bit relative address of symbol minus 1
Definition coff.h:414
static constexpr uint16_t REL_AMD64_TOKEN
CLR token.
Definition coff.h:430
uint16_t flags
COFF flags, such as whether the file is executable (f_flags)
Definition coff.h:1217
static constexpr uint16_t R_RELBYTE
8-bit direct (symbol relative) address of symbol
Definition coff.h:364
cpu cpu_type
The CPU type, reflected by the first 16-bit word of a COFF file.
Definition coff.h:1732
static constexpr uint16_t REL_ARM64_SECREL_LOW12L
Low 12 bits of offset from section start for LDR.
Definition coff.h:492
uint32_t timestamp
Time stamp, unused (COFF name: f_timdat)
Definition coff.h:1197
static constexpr uint16_t REL_ALPHA_GPRELLO
Low 16 bits of 32-bit global pointer relative address of symbol.
Definition coff.h:555
An abstract interface that separates structure and presentation of the data inside a file.
Definition dumper.h:773
A brief record, such as a relocation or imported library.
Definition dumper.h:687
A record that represents a region within the file.
Definition dumper.h:666
A representation of an enumeration with associated string representations for each value.
Definition options.h:15
std::map< value_type, std::string > descriptions
An empty dictionary that explains the value types in detail.
Definition options.h:20
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
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
Documents and handles command line options.
Definition options.h:306
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
A helper class, encapsulating functionality needed to export binary data.
Definition writer.h:15
Definition mzexe.h:274
Definition coff.h:263
static constexpr uint32_t INFO
COFF section flag: Comment section (COFF name: STYP_INFO)
Definition coff.h:995
static constexpr uint32_t NOLOAD
COFF section flag: Noload section (COFF name: STYP_NOLOAD)
Definition coff.h:987
static constexpr uint32_t OVER
COFF section flag: Overlay section (COFF name: STYP_OVER)
Definition coff.h:997
static constexpr uint32_t COPY
COFF section flag: Copy section (COFF name: STYP_COPY)
Definition coff.h:993
static constexpr uint32_t PAD
COFF section flag: Padding section (COFF name: STYP_PAD)
Definition coff.h:991
static constexpr uint32_t LIB
COFF section flag: Library section (also used by X/GEM to store library information) (COFF name: STYP...
Definition coff.h:999
static constexpr uint32_t DSECT
COFF section flag: Dummy section (COFF name: STYP_DSECT)
Definition coff.h:985
static constexpr uint32_t GROUP
COFF section flag: Grouped section, formed from input sections (COFF name: STYP_GROUP)
Definition coff.h:989
static constexpr uint32_t SDATA
ECOFF section flag: "Small data" (ECOFF name: STYP_SDATA)
Definition coff.h:1008
static constexpr uint32_t DYNSYM
ECOFF section flag: Dynamic linking symbol table (ECOFF name: STYP_DYNSYM)
Definition coff.h:1018
static constexpr uint32_t REL_DYN
ECOFF section flag: Dynamic relocation information (ECOFF name: STYP_REL_DYN)
Definition coff.h:1020
static constexpr uint32_t XDATA
ECOFF section flag: Exception scope table (ECOFF name: STYP_XDATA)
Definition coff.h:1040
static constexpr uint32_t MSYM
ECOFF section flag: Additional dynamic linking symbol table (ECOFF name: STYP_MSYM)
Definition coff.h:1028
static constexpr uint32_t LITA
ECOFF section flag: Address literals (ECOFF name: STYP_LITA)
Definition coff.h:1050
static constexpr uint32_t GOT
ECOFF section flag: Global offset table (ECOFF name: STYP_GOT)
Definition coff.h:1014
static constexpr uint32_t SBSS
ECOFF section flag: "Small bss" (ECOFF name: STYP_SBSS)
Definition coff.h:1010
static constexpr uint32_t DYNSTR
ECOFF section flag: Dynamic linking string table (ECOFF name: STYP_DYNSTR)
Definition coff.h:1022
static constexpr uint32_t TLSINIT
ECOFF section flag: Initialization for TLS data (ECOFF name: STYP_TLSINIT)
Definition coff.h:1046
static constexpr uint32_t NRELOC_OVERFLOWED
ECOFF section flag: the s_nreloc field overflowed (ECOFF name: S_NRELOC_OVFL)
Definition coff.h:1056
static constexpr uint32_t HASH
ECOFF section flag: Dynamic symbol hash table (ECOFF name: STYP_HASH)
Definition coff.h:1024
static constexpr uint32_t EXTMASK
ECOFF section flag: Multiple bit flag values.
Definition coff.h:1030
static constexpr uint32_t TLSBSS
ECOFF section flag: Uninitialized TLS data (ECOFF name: STYP_TLSBSS)
Definition coff.h:1044
static constexpr uint32_t FINI
ECOFF section flag: Termination text (ECOFF name: STYP_FINI)
Definition coff.h:1034
static constexpr uint32_t LIT4
ECOFF section flag: 4-byte literals (ECOFF name: STYP_LIT8)
Definition coff.h:1054
static constexpr uint32_t RDATA
ECOFF section flag: Section contains read-only data (ECOFF name: STYP_RDATA)
Definition coff.h:1006
static constexpr uint32_t INIT
ECOFF section flag: Initialization text (ECOFF name: STYP_INIT)
Definition coff.h:1058
static constexpr uint32_t TLSDATA
ECOFF section flag: Initialized TLS data (ECOFF name: STYP_TLSDATA)
Definition coff.h:1042
static constexpr uint32_t COMMENT
ECOFF section flag: Comment section (ECOFF name: STYP_COMMENT)
Definition coff.h:1036
static constexpr uint32_t LIT8
ECOFF section flag: 8-byte literals (ECOFF name: STYP_LIT8)
Definition coff.h:1052
static constexpr uint32_t CONFLICT
ECOFF section flag: Additional dynamic linking information (ECOFF name: STYP_CONFLICT)
Definition coff.h:1032
static constexpr uint32_t PDATA
ECOFF section flag: Exception procedure table (ECOFF name: STYP_PDATA)
Definition coff.h:1048
static constexpr uint32_t DSOLIST
ECOFF section flag: Shared library dependency list (ECOFF name: STYP_DSOLIST)
Definition coff.h:1026
static constexpr uint32_t UCODE
ECOFF section flag: (ECOFF name: STYP_UCODE)
Definition coff.h:1012
static constexpr uint32_t RCONST
ECOFF section flag: Read-only constants (ECOFF name: STYP_RCONST)
Definition coff.h:1038
static constexpr uint32_t DYNAMIC
ECOFF section flag: Dynamic linking information (ECOFF name: STYP_DYNAMIC)
Definition coff.h:1016
static constexpr uint32_t LNK_INFO
PE section flag: Section contains comments.
Definition coff.h:1069
static constexpr uint32_t MEM_NOT_PAGED
PE section flag: Section is not pageable.
Definition coff.h:1095
static constexpr uint32_t GPREL
PE section flag: Section data accessed through the global pointer.
Definition coff.h:1075
static constexpr uint32_t MEM_LOCKED
PE section flag: reserved.
Definition coff.h:1081
static constexpr uint32_t LNK_COMDAT
PE section flag: Section contains COMDAT data.
Definition coff.h:1073
static constexpr uint32_t MEM_NOT_CACHED
PE section flag: Section cannot be cached.
Definition coff.h:1093
static constexpr uint32_t MEM_WRITE
PE section flag: Section can be written to.
Definition coff.h:1103
static constexpr uint32_t LNK_OTHER
PE section flag: reserved.
Definition coff.h:1067
static constexpr uint32_t MEM_PURGEABLE
PE section flag: reserved.
Definition coff.h:1077
static constexpr uint32_t MEM_16BIT
PE section flag: reserved.
Definition coff.h:1079
static constexpr uint32_t MEM_PRELOAD
PE section flag: reserved.
Definition coff.h:1083
static constexpr uint32_t ALIGN_SHIFT
PE section flag: alignment shift.
Definition coff.h:1087
static constexpr uint32_t MEM_SHARED
PE section flag: Section can be shared in memory.
Definition coff.h:1097
static constexpr uint32_t ALIGN_MASK
PE section flag: alignment mask.
Definition coff.h:1085
static constexpr uint32_t LNK_NRELOC_OVFL
PE section flag: Section contains more than 65535 relocations.
Definition coff.h:1089
static constexpr uint32_t TYPE_NO_PAD
PE section flag: Section should not be padded.
Definition coff.h:1065
static constexpr uint32_t MEM_EXECUTE
PE section flag: Section data can be executed.
Definition coff.h:1099
static constexpr uint32_t MEM_READ
PE section flag: Section can be read from.
Definition coff.h:1101
static constexpr uint32_t LNK_REMOVE
PE section flag: Section should be removed when generating image.
Definition coff.h:1071
static constexpr uint32_t MEM_DISCARDABLE
PE section flag: Section can be discarded.
Definition coff.h:1091
static constexpr uint32_t PASS
TI COFF section flag: Section should not be changed (TI COFF name: STYP_PASS)
Definition coff.h:1147
static constexpr uint32_t VECTOR
TI COFF section flag: Section contains vector table (TI COFF name: STYP_VECTOR)
Definition coff.h:1151
static constexpr uint32_t CLINK
TI COFF section flag: Conditional linking required (TI COFF name: STYP_CLINK)
Definition coff.h:1149
static constexpr uint32_t NOLOAD
COFF section flag: Noload section (COFF name: STYP_NOLOAD)
Definition coff.h:1137
static constexpr uint32_t COPY
COFF section flag: Copy section (COFF name: STYP_COPY)
Definition coff.h:1143
static constexpr uint32_t DSECT
COFF section flag: Dummy section (COFF name: STYP_DSECT)
Definition coff.h:1135
static constexpr uint32_t PAD
COFF section flag: Padding section (COFF name: STYP_PAD)
Definition coff.h:1141
static constexpr uint32_t PADDED
TI COFF section flag: Section has been padded (TI COFF name: STYP_PADDED)
Definition coff.h:1153
static constexpr uint32_t GROUP
COFF section flag: Grouped section, formed from input sections (COFF name: STYP_GROUP)
Definition coff.h:1139
static constexpr uint32_t BLOCK
TI COFF section flag: Alignment used as a blocking factor (TI COFF name: STYP_BLOCK)
Definition coff.h:1145
static constexpr uint32_t OVERFLO
XCOFF section flag: (XCOFF name: STYP_OVERFLO)
Definition coff.h:1128
static constexpr uint32_t INFO
XCOFF section flag: Comment section (XCOFF name: STYP_INFO)
Definition coff.h:1116
static constexpr uint32_t DWARF
XCOFF section flag: DWARF relocation section (XCOFF name: STYP_DWARF)
Definition coff.h:1112
static constexpr uint32_t EXCEPT
XCOFF section flag: Exception section (XCOFF name: STYP_EXCEPT)
Definition coff.h:1114
static constexpr uint32_t TYPCHK
XCOFF section flag: Type-check section (XCOFF name: STYP_TYPCHK)
Definition coff.h:1126
static constexpr uint32_t LOADER
XCOFF section flag: Loader section (XCOFF name: STYP_LOADER)
Definition coff.h:1122
static constexpr uint32_t TBSS
XCOFF section flag: Uninitialized thread-local data (XCOFF name: STYP_TBSS)
Definition coff.h:1120
static constexpr uint32_t TDATA
XCOFF section flag: Initialized thread-local data (XCOFF name: STYP_TDATA)
Definition coff.h:1118
static constexpr uint32_t DEBUG
XCOFF section flag: Debug section (XCOFF name: STYP_DEBUG)
Definition coff.h:1124
static constexpr uint32_t PAD
XCOFF section flag: Padding section (XCOFF name: STYP_PAD)
Definition coff.h:1110