11#include "../linker/module.h"
12#include "../linker/options.h"
13#include "../linker/segment.h"
14#include "../linker/segment_manager.h"
15#include "../linker/writer.h"
271 static const std::map<uint32_t, MachineType> MACHINE_TYPES;
307 constexpr size_t GetRelocationEntrySize()
const
309 switch(relocation_format)
336 static constexpr uint16_t
R_ABS = 0;
358 static constexpr uint16_t
R_AUX = 11;
572 static constexpr uint16_t R_Z80_IMM8 = 0x22;
573 static constexpr uint16_t R_Z80_IMM16 = 0x01;
574 static constexpr uint16_t R_Z80_IMM24 = 0x33;
575 static constexpr uint16_t R_Z80_IMM32 = 0x17;
576 static constexpr uint16_t R_Z80_OFF8 = 0x32;
577 static constexpr uint16_t R_Z80_JR = 0x02;
579 static constexpr uint16_t R_Z8K_IMM4L = 0x23;
580 static constexpr uint16_t R_Z8K_IMM4H = 0x24;
581 static constexpr uint16_t R_Z8K_DISP7 = 0x25;
582 static constexpr uint16_t R_Z8K_IMM8 = 0x22;
583 static constexpr uint16_t R_Z8K_IMM16 = 0x01;
584 static constexpr uint16_t R_Z8K_REL16 = 0x04;
585 static constexpr uint16_t R_Z8K_IMM32 = 0x11;
586 static constexpr uint16_t R_Z8K_JR = 0x02;
587 static constexpr uint16_t R_Z8K_CALLR = 0x05;
589 static constexpr uint16_t R_W65_ABS8 = 0x01;
590 static constexpr uint16_t R_W65_ABS16 = 0x02;
591 static constexpr uint16_t R_W65_ABS24 = 0x03;
592 static constexpr uint16_t R_W65_ABS8S8 = 0x04;
593 static constexpr uint16_t R_W65_ABS8S16 = 0x05;
594 static constexpr uint16_t R_W65_ABS16S8 = 0x06;
595 static constexpr uint16_t R_W65_ABS16S16 = 0x07;
596 static constexpr uint16_t R_W65_PCR8 = 0x08;
597 static constexpr uint16_t R_W65_PCR16 = 0x09;
598 static constexpr uint16_t R_W65_DP = 0x0A;
602 static constexpr uint8_t R_XCOFF_POS = 0x00;
603 static constexpr uint8_t R_XCOFF_NEG = 0x01;
604 static constexpr uint8_t R_XCOFF_REL = 0x02;
605 static constexpr uint8_t R_XCOFF_TOC = 0x03;
606 static constexpr uint8_t R_XCOFF_GL = 0x05;
607 static constexpr uint8_t R_XCOFF_TCL = 0x06;
608 static constexpr uint8_t R_XCOFF_BA = 0x08;
609 static constexpr uint8_t R_XCOFF_BR = 0x0A;
610 static constexpr uint8_t R_XCOFF_RL = 0x0C;
611 static constexpr uint8_t R_XCOFF_RLA = 0x0D;
612 static constexpr uint8_t R_XCOFF_REF = 0x0F;
613 static constexpr uint8_t R_XCOFF_TRL = 0x12;
614 static constexpr uint8_t R_XCOFF_TRLA = 0x13;
615 static constexpr uint8_t R_XCOFF_RBA = 0x18;
616 static constexpr uint8_t R_XCOFF_RBR = 0x1A;
617 static constexpr uint8_t R_XCOFF_TLS = 0x20;
618 static constexpr uint8_t R_XCOFF_TLS_IE = 0x21;
619 static constexpr uint8_t R_XCOFF_TLS_LD = 0x22;
620 static constexpr uint8_t R_XCOFF_TLS_LE = 0x23;
621 static constexpr uint8_t R_XCOFF_TLSM = 0x24;
622 static constexpr uint8_t R_XCOFF_TLSML = 0x25;
623 static constexpr uint8_t R_XCOFF_TOCU = 0x30;
624 static constexpr uint8_t R_XCOFF_TOCL = 0x31;
628 static constexpr uint16_t R_ECOFF_ABS = 0x00;
629 static constexpr uint16_t R_ECOFF_REFLONG = 0x01;
630 static constexpr uint16_t R_ECOFF_REFQUAD = 0x02;
631 static constexpr uint16_t R_ECOFF_GPREL32 = 0x03;
632 static constexpr uint16_t R_ECOFF_LITERAL = 0x04;
633 static constexpr uint16_t R_ECOFF_LITUSE = 0x05;
634 static constexpr uint16_t R_ECOFF_GPDISP = 0x06;
635 static constexpr uint16_t R_ECOFF_BRADDR = 0x07;
636 static constexpr uint16_t R_ECOFF_HINT = 0x08;
637 static constexpr uint16_t R_ECOFF_SREL16 = 0x09;
638 static constexpr uint16_t R_ECOFF_SREL32 = 0x0A;
639 static constexpr uint16_t R_ECOFF_SREL64 = 0x0B;
640 static constexpr uint16_t R_ECOFF_OP_PUSH = 0x0C;
641 static constexpr uint16_t R_ECOFF_OP_STORE = 0x0D;
642 static constexpr uint16_t R_ECOFF_OP_PSUB = 0x0E;
643 static constexpr uint16_t R_ECOFF_OP_PRSHIFT = 0x0F;
644 static constexpr uint16_t R_ECOFF_GPVALUE = 0x10;
645 static constexpr uint16_t R_ECOFF_GPRELHIGH = 0x11;
646 static constexpr uint16_t R_ECOFF_GPRELLOW = 0x12;
647 static constexpr uint16_t R_ECOFF_IMMED = 0x13;
648 static constexpr uint16_t R_ECOFF_TLS_LITERAL = 0x14;
649 static constexpr uint16_t R_ECOFF_TLS_HIGH = 0x15;
650 static constexpr uint16_t R_ECOFF_TLS_LOW = 0x16;
679 void Read(
const std::shared_ptr<Linker::Reader>& rd,
const COFFFormat& coff);
682 void WriteFile(
const std::shared_ptr<Linker::Writer>& wr,
const COFFFormat& coff)
const;
723 void Read(
const std::shared_ptr<Linker::Reader>& rd);
725 bool IsExternal()
const;
731 virtual void Read(
const std::shared_ptr<Linker::Reader>& rd) = 0;
732 virtual void Write(
const std::shared_ptr<Linker::Writer>& wr)
const = 0;
739 std::string file_name;
741 void Read(
const std::shared_ptr<Linker::Reader>& rd)
override;
742 void Write(
const std::shared_ptr<Linker::Writer>& wr)
const override;
750 int32_t section_length;
751 uint16_t relocation_entry_count;
752 uint16_t line_number_count;
754 void Read(
const std::shared_ptr<Linker::Reader>& rd)
override;
755 void Write(
const std::shared_ptr<Linker::Writer>& wr)
const override;
766 int32_t next_entry_index;
768 void Read(
const std::shared_ptr<Linker::Reader>& rd)
override;
769 void Write(
const std::shared_ptr<Linker::Writer>& wr)
const override;
782 void Read(
const std::shared_ptr<Linker::Reader>& rd)
override;
783 void Write(
const std::shared_ptr<Linker::Writer>& wr)
const override;
793 int32_t pointer_to_line_number;
794 int32_t next_entry_index;
795 uint16_t transfer_table_index;
797 void Read(
const std::shared_ptr<Linker::Reader>& rd)
override;
798 void Write(
const std::shared_ptr<Linker::Writer>& wr)
const override;
807 uint16_t declaration_line_number;
809 std::array<uint16_t, 4> dimensions;
811 void Read(
const std::shared_ptr<Linker::Reader>& rd)
override;
812 void Write(
const std::shared_ptr<Linker::Writer>& wr)
const override;
821 uint16_t line_number;
823 int32_t next_entry_index;
825 void Read(
const std::shared_ptr<Linker::Reader>& rd)
override;
826 void Write(
const std::shared_ptr<Linker::Writer>& wr)
const override;
838 void Read(
const std::shared_ptr<Linker::Reader>& rd)
override;
839 void Write(
const std::shared_ptr<Linker::Writer>& wr)
const override;
843 std::unique_ptr<AuxiliaryEntry> auxiliary_entry =
nullptr;
1020 std::shared_ptr<Linker::Contents>
image;
1029 static constexpr uint32_t
TEXT = 0x0020;
1031 static constexpr uint32_t
DATA = 0x0040;
1033 static constexpr uint32_t
BSS = 0x0080;
1039 static constexpr uint32_t
DSECT = 0x0001;
1043 static constexpr uint32_t
GROUP = 0x0004;
1045 static constexpr uint32_t
PAD = 0x0008;
1047 static constexpr uint32_t
COPY = 0x0010;
1049 static constexpr uint32_t
INFO = 0x0200;
1051 static constexpr uint32_t
OVER = 0x0400;
1053 static constexpr uint32_t
LIB = 0x0800;
1060 static constexpr uint32_t
RDATA = 0x00000100;
1062 static constexpr uint32_t
SDATA = 0x00000200;
1064 static constexpr uint32_t
SBSS = 0x00000400;
1066 static constexpr uint32_t
UCODE = 0x00000800;
1068 static constexpr uint32_t
GOT = 0x00001000;
1072 static constexpr uint32_t
DYNSYM = 0x00004000;
1076 static constexpr uint32_t
DYNSTR = 0x00010000;
1078 static constexpr uint32_t
HASH = 0x00020000;
1082 static constexpr uint32_t
MSYM = 0x00080000;
1088 static constexpr uint32_t
FINI = 0x01000000;
1092 static constexpr uint32_t
RCONST = 0x02200000;
1094 static constexpr uint32_t
XDATA = 0x02400000;
1098 static constexpr uint32_t
TLSBSS = 0x02600000;
1102 static constexpr uint32_t
PDATA = 0x02800000;
1104 static constexpr uint32_t
LITA = 0x04000000;
1106 static constexpr uint32_t
LIT8 = 0x08000000;
1108 static constexpr uint32_t
LIT4 = 0x10000000;
1112 static constexpr uint32_t
INIT = 0x80000000;
1129 static constexpr uint32_t
GPREL = 0x00008000;
1164 static constexpr uint32_t
PAD = 0x0008;
1166 static constexpr uint32_t
DWARF = 0x0010;
1170 static constexpr uint32_t
INFO = 0x0200;
1172 static constexpr uint32_t
TDATA = 0x0400;
1174 static constexpr uint32_t
TBSS = 0x0800;
1178 static constexpr uint32_t
DEBUG = 0x2000;
1189 static constexpr uint32_t
DSECT = 0x00000001;
1191 static constexpr uint32_t
NOLOAD = 0x00000002;
1193 static constexpr uint32_t
GROUP = 0x00000004;
1195 static constexpr uint32_t
PAD = 0x00000008;
1197 static constexpr uint32_t
COPY = 0x00000010;
1199 static constexpr uint32_t
BLOCK = 0x00010000;
1201 static constexpr uint32_t
PASS = 0x00020000;
1203 static constexpr uint32_t
CLINK = 0x00040000;
1205 static constexpr uint32_t
VECTOR = 0x00080000;
1207 static constexpr uint32_t
PADDED = 0x00100000;
1249 uint32_t srtl_load_bias = 0;
1250 uint32_t text_load_size = 0;
1251 uint32_t data_load_size = 0;
1252 uint32_t bss_load_size = 0;
1253 uint32_t stack_load_size = 0;
1254 uint32_t flags = 0x80;
1255 uint32_t reserved = 0;
1258 uint16_t major, minor;
1264 void AssignNameAndVersion(std::string name_and_version);
1265 offset_t ReadFile(
const std::shared_ptr<Linker::Reader>& rd, offset_t size,
bool& is_definition);
1266 offset_t ImageSize()
const;
1267 offset_t WriteFile(
const std::shared_ptr<Linker::Writer>& wr,
bool as_export =
false)
const;
1269 void Dump(
Dumper::Dumper& dump, std::optional<unsigned> index)
const;
1292 static std::shared_ptr<FlexOSLibrarySection> ReadFile(
const std::shared_ptr<Linker::Reader>& rd, offset_t size);
1293 std::shared_ptr<const Linker::Image>
AsImage()
const override;
1295 offset_t
WriteFile(
const std::shared_ptr<Linker::Writer>& wr)
const override;
1349 virtual void ReadFile(
const std::shared_ptr<Linker::Reader>& rd) = 0;
1350 virtual void WriteFile(
const std::shared_ptr<Linker::Writer>& wr)
const = 0;
1368 virtual std::string GetHeaderFormatName(
const COFFFormat& coff)
const;
1383 operator size_t()
const;
1398 std::unique_ptr<Linker::Buffer> buffer =
nullptr;
1401 : buffer(std::make_unique<Linker::Buffer>(size))
1405 uint32_t
GetSize()
const override;
1407 void ReadFile(
const std::shared_ptr<Linker::Reader>& rd)
override;
1409 void WriteFile(
const std::shared_ptr<Linker::Writer>& wr)
const override;
1461 uint32_t
GetSize()
const override;
1463 void ReadFile(
const std::shared_ptr<Linker::Reader>& rd)
override;
1465 void WriteFile(
const std::shared_ptr<Linker::Writer>& wr)
const override;
1469 std::string GetHeaderFormatName(
const COFFFormat& coff)
const override;
1484 uint32_t reserved1 = 0;
1485 uint32_t reserved2 = 0;
1492 uint32_t
GetSize()
const override;
1494 void ReadFile(
const std::shared_ptr<Linker::Reader>& rd)
override;
1496 void WriteFile(
const std::shared_ptr<Linker::Writer>& wr)
const override;
1500 std::string GetHeaderFormatName(
const COFFFormat& coff)
const override;
1532 uint32_t
GetSize()
const override;
1534 void ReadFile(
const std::shared_ptr<Linker::Reader>& rd)
override;
1536 void WriteFile(
const std::shared_ptr<Linker::Writer>& wr)
const override;
1544 std::string GetHeaderFormatName(
const COFFFormat& coff)
const override;
1559 uint32_t code_size = 0;
1560 uint32_t data_size = 0;
1561 uint32_t bss_size = 0;
1562 uint32_t symbol_table_size = 0;
1563 uint32_t entry_address = 0;
1564 uint32_t code_relocation_size = 0;
1565 uint32_t data_relocation_size = 0;
1567 uint32_t
GetSize()
const override;
1569 void ReadFile(
const std::shared_ptr<Linker::Reader>& wr)
override;
1571 void WriteFile(
const std::shared_ptr<Linker::Writer>& wr)
const override;
1577 std::string GetHeaderFormatName(
const COFFFormat& coff)
const override;
1590 uint32_t bss_address;
1594 uint32_t cpr_mask[4];
1603 uint32_t
GetSize()
const override;
1605 void ReadFile(
const std::shared_ptr<Linker::Reader>& rd)
override;
1607 void WriteFile(
const std::shared_ptr<Linker::Writer>& wr)
const override;
1611 std::string GetHeaderFormatName(
const COFFFormat& coff)
const override;
1629 static constexpr uint16_t SYM_STAMP = 0x030D;
1679 uint32_t
GetSize()
const override;
1681 void ReadFile(
const std::shared_ptr<Linker::Reader>& rd)
override;
1683 void WriteFile(
const std::shared_ptr<Linker::Writer>& wr)
const override;
1689 std::string GetHeaderFormatName(
const COFFFormat& coff)
const override;
1826 uint8_t shared_memory_page = 0;
1834 uint32_t
GetSize()
const override;
1836 void ReadFile(
const std::shared_ptr<Linker::Reader>& rd)
override;
1838 void WriteFile(
const std::shared_ptr<Linker::Writer>& wr)
const override;
1844 std::string GetHeaderFormatName(
const COFFFormat& coff)
const override;
1847 void Clear()
override;
1870 bool DetectCpuType(::EndianType expected);
1872 void DetectCpuType();
1874 void ReadFile(
const std::shared_ptr<Linker::Reader>& rd)
override;
1877 void ReadCOFFHeader(
const std::shared_ptr<Linker::Reader>& rd);
1878 void ReadOptionalHeader(
const std::shared_ptr<Linker::Reader>& rd);
1879 void ReadRestOfFile(
const std::shared_ptr<Linker::Reader>& rd);
1885 offset_t
WriteFile(
const std::shared_ptr<Linker::Writer>& wr)
const override;
1888 offset_t WriteFileContents(
const std::shared_ptr<Linker::Writer>& wr)
const;
1895 void SetupOptions(std::shared_ptr<Linker::OutputFormat> format)
override;
1897 bool option_segmentation =
false;
1903 std::string segment_prefix();
1905 std::string segment_of_prefix();
1910 std::string segmented_address_prefix();
1914 std::string segment_difference_prefix();
1971 bool option_unmapped_zero_page =
false;
1990 {
OMAGIC,
"Impure executable (OMAGIC)" },
1991 {
NMAGIC,
"Pure executable (NMAGIC)" },
1992 {
ZMAGIC,
"Demand paged executable (ZMAGIC)" },
2003 Linker::Option<bool> reloc{
"reloc",
"Generate FlexOS relocations (default for CDOS68K and FlexOS 386 libraries)"};
2004 Linker::Option<bool> noreloc{
"noreloc",
"Suppress FlexOS relocations (default for FlexOS 386 programs)"};
2008 COFFOptionCollector()
2010 InitializeFields(stub, type, Nflag, nflag, zflag, slib, reloc, noreloc);
2113 unsigned FormatAdditionalSectionFlags(std::string section_name)
const override;
2115 static std::vector<Linker::OptionDescription<void> *> ParameterNames;
2118 std::shared_ptr<Linker::OptionCollector>
GetOptions()
override;
2120 void SetOptions(std::map<std::string, std::string>& options)
override;
2143 void OnNewSegment(std::shared_ptr<Linker::Segment> segment)
override;
2145 void CreateDefaultSegments();
2152 std::shared_ptr<Linker::Segment>
GetSegment(std::shared_ptr<Section>& section);
2154 std::shared_ptr<Linker::Segment> GetCodeSegment();
2159 std::shared_ptr<Linker::Segment> GetDataSegment();
2161 std::shared_ptr<Linker::Segment> GetBssSegment();
2179 : MacintoshOutputDriver(
target)
2192 std::shared_ptr<COFFFormat> data_fork;
2194 std::shared_ptr<Apple::MacintoshResourceFileFormat> resource_fork;
2195 std::shared_ptr<Apple::FinderInfo> finder_info;
2197 std::map<std::string, std::string> options;
2199 std::string script_file;
2200 std::map<std::string, std::string> script_options;
This is not actually a file format, but an interface to permit generating multiple binary outputs for...
Definition macos.h:968
target_format_t
Represents the file type of the main file.
Definition macos.h:972
@ TARGET_DATA_FORK
Main file is a data fork, typically empty.
Definition macos.h:976
target_format_t target
Format of "filename".
Definition apple.h:746
produce_format_t produce
Bitset of other files to produce.
Definition apple.h:749
bool FormatSupportsResources() const override
Whether the format supports resources.
Definition coff.cc:4262
An abstract interface that separates structure and presentation of the data inside a file.
Definition dumper.h:1009
A brief record, such as a relocation or imported library.
Definition dumper.h:923
A record that represents a region within the file.
Definition dumper.h:902
Represents abstract data contents whose data can be written to a file.
Definition image.h:17
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
Encodes an object module file as a collection of sections, symbols and relocations.
Definition module.h:24
Helper class that contains the options interpreted by the format.
Definition options.h:499
Documents and handles command line options.
Definition options.h:306
A helper class to collect sections into segments.
Definition segment_manager.h:32