RetroLinker
Linker for several 8-bit, 16-bit and 32-bit formats
|
The UNIX COFF file format. More...
#include <coff.h>
Classes | |
class | AOutHeader |
A standard 28 byte a.out optional header, used by DJGPP. More... | |
class | FlexOSAOutHeader |
Concurrent DOS 68K/FlexOS 386 optional header Concurrent DOS 68K uses the typical a.out header with two additional fields for the offset to relocations and the size of the stack. More... | |
class | GNUAOutHeader |
GNU a.out optional header TODO. More... | |
struct | MachineType |
class | MIPSAOutHeader |
A standard 28 byte a.out optional header, used by DJGPP. More... | |
class | OptionalHeader |
An abstract class to represent the optional header. More... | |
class | Relocation |
A generic COFF relocation. More... | |
class | Section |
A COFF section. More... | |
class | Symbol |
A COFF symbol. More... | |
class | UnknownOptionalHeader |
A simplified class to represent an optional header of unknown structure. More... | |
class | ZilogRelocation |
A relocation, as stored by the Z80/Z8000 backend. More... | |
Public Types | |
enum | cpu { CPU_UNKNOWN = 0 , CPU_I386 = 0x014C , CPU_M68K = 0x0150 , CPU_W65 = 0x6500 , CPU_Z80 = 0x805A , CPU_Z8K = 0x8000 , CPU_I86 = 0x0148 , CPU_NS32K = 0x0154 , CPU_I370 = 0x0158 , CPU_MIPS = 0x0160 , CPU_M88K = 0x016D , CPU_WE32K = 0x0170 , CPU_VAX = 0x0178 , CPU_AM29K = 0x017A , CPU_ALPHA = 0x0183 , CPU_PPC = 0x01DF , CPU_PPC64 = 0x01F7 , CPU_SHARC = 0x521C } |
Represents the first 16-bit word of a COFF file. | |
enum | format_type { GENERIC , DJGPP , CDOS68K , CDOS386 } |
Represents the type of target system, which will determine the CPU type and several other fields. More... | |
enum | { FLAG_NO_RELOCATIONS = 0x0001 , FLAG_EXECUTABLE = 0x0002 , FLAG_NO_LINE_NUMBERS = 0x0004 , FLAG_NO_SYMBOLS = 0x0008 , FLAG_32BIT_LITTLE_ENDIAN = 0x0100 , FLAG_32BIT_BIG_ENDIAN = 0x0200 , ZMAGIC = 0x010B } |
COFF file header flags, most of these are obsolete, we only use them as precombined flag sets. More... | |
Public Member Functions | |
::EndianType | GetEndianType () const |
Retrieves the natural byte order for the architecture. | |
void | Clear () override |
Resets all fields to their default values, deallocate memory. | |
void | AssignMagicValue () |
bool | DetectCpuType (::EndianType expected) |
void | DetectCpuType () |
void | ReadFile (Linker::Reader &rd) override |
Loads file into memory. | |
void | WriteFile (Linker::Writer &wr) override |
Stores data in memory to file. | |
void | Dump (Dumper::Dumper &dump) override |
Display file contents in a nice manner. | |
void | SetupOptions (std::shared_ptr< Linker::OutputFormat > format) override |
Initializes the reader for linking purposes. | |
bool | FormatRequiresDataStreamFix () const override |
Whether the generated file might contain bugs that require fixing. | |
void | ProduceModule (Linker::Module &module, Linker::Reader &rd) override |
Reads a file and loads the information into a module object. | |
COFFFormat (format_type type=GENERIC) | |
unsigned | FormatAdditionalSectionFlags (std::string section_name) const override |
void | SetOptions (std::map< std::string, std::string > &options) override |
Passes command line parameters as settings over to format object. | |
void | OnNewSegment (std::shared_ptr< Linker::Segment > segment) override |
Callback function when allocating a new segment When the linker script runs, it creates segments consecutively. Overriding this method permits the output format to handle the allocated segment. | |
void | CreateDefaultSegments () |
std::unique_ptr< Script::List > | GetScript (Linker::Module &module) |
void | Link (Linker::Module &module) |
std::shared_ptr< Linker::Segment > | GetSegment (std::unique_ptr< Section > §ion) |
Return the segment stored inside the section, note that this only works for binary generation. | |
std::shared_ptr< Linker::Segment > | GetCodeSegment () |
std::shared_ptr< Linker::Segment > | GetDataSegment () |
std::shared_ptr< Linker::Segment > | GetBssSegment () |
void | ProcessModule (Linker::Module &module) override |
Processes the module object and initializes format fields. | |
void | CalculateValues () override |
Intermediate step between processing module and generating output file to set up headers and management sections It is expected that after a module is processed, additional steps are required to evaluate the final values of the fields. | |
void | GenerateFile (std::string filename, Linker::Module &module) override |
The main function that handles processing, calculating and generating the final image. | |
std::string | GetDefaultExtension (Linker::Module &module, std::string filename) override |
Appends a default extension to the filename. | |
Public Member Functions inherited from Linker::InputFormat | |
virtual bool | FormatProvidesSegmentation () const |
Whether the format enables multiple x86 segments. | |
virtual bool | FormatProvidesResources () const |
Whether the format supports resources. | |
virtual bool | FormatProvidesLibraries () const |
Whether the format enables importing/exporting libraries. | |
Public Member Functions inherited from Linker::Format | |
Format (offset_t file_offset=0) | |
Public Member Functions inherited from Linker::OutputFormat | |
virtual bool | AddSupplementaryOutputFormat (std::string subformat) |
If the output format actually drives multiple output formats (resource file, apple double, etc.), specify multiple types, return false if unknown. | |
std::optional< std::string > | FetchOption (std::map< std::string, std::string > &options, std::string name) |
Convenience method to look up option by name. | |
std::string | FetchOption (std::map< std::string, std::string > &options, std::string name, std::string default_value) |
Convenience method to look up option by name, returning default value if name is missing. | |
std::optional< offset_t > | FetchIntegerOption (std::map< std::string, std::string > &options, std::string name) |
Convenience method to look up option by name and convert it to integer. | |
virtual void | SetModel (std::string model) |
Sets the way memory is organized, typically modifying a built-in script. | |
virtual void | SetLinkScript (std::string script_file, std::map< std::string, std::string > &options) |
Selects a script file to use for linking. | |
virtual std::string | GetDefaultExtension (Linker::Module &module) |
Provides a default filename for the output file. | |
virtual bool | FormatSupportsSegmentation () const |
Whether the format supports multiple segments. | |
virtual bool | FormatIs16bit () const |
Whether the format is 16-bit or not. | |
virtual bool | FormatIsLinear () const |
Whether the address space is linear or segmented. | |
virtual bool | FormatSupportsResources () const |
Whether the format supports resources. | |
virtual bool | FormatSupportsLibraries () const |
Whether the format supports libraries. | |
Public Member Functions inherited from Linker::LinkerManager | |
void | ClearLinkerManager () |
void | SetLinkScript (std::string script_file, std::map< std::string, std::string > &options) |
Sets up the linker script and linker parameters. | |
bool | SetLinkerParameter (std::map< std::string, std::string > &options, std::string key) |
Sets a single linker parameter, if inside options. | |
bool | SetLinkerParameter (std::map< std::string, std::string > &options, std::string key, std::string variable) |
Sets a single linker parameter, if inside options. | |
std::unique_ptr< Script::List > | GetScript (Linker::Module &module) |
Compiles the linker script into an internal format. | |
offset_t | GetCurrentAddress () const |
Retrieves current address pointer. | |
void | SetCurrentAddress (offset_t address) |
Moves the current address pointer further, and if the current segment already contains data, fill it up to the point. | |
void | AlignCurrentAddress (offset_t align) |
Aligns current address to alignment, using SetCurrentAddress. | |
void | SetLatestBase (offset_t address) |
Sets the base of the current section (the value from which offsets are counted from) | |
void | FinishCurrentSegment () |
Closes the current segment, sets current_segment to null. | |
std::shared_ptr< Segment > | AppendSegment (std::string name) |
Terminates the current segment (if there is one), creates a new segment and attaches it to the image. | |
std::shared_ptr< Segment > | FetchSegment (std::string name) |
Attempts to fetch a segment, returns null if not found. | |
void | AppendSection (std::shared_ptr< Section > section) |
Adds a new section to the current segment, sets the base to the same as the segment. | |
void | ProcessScript (std::unique_ptr< Script::List > &directives, Module &module) |
Executes a parsed linker script on a module and collects segments The function OnNewSegment can be defined to handle each newly allocated segment. | |
void | ProcessAction (std::unique_ptr< Script::Node > &action, Module &module) |
void | PostProcessAction (std::unique_ptr< Script::Node > &action, Module &module) |
void | ProcessCommand (std::unique_ptr< Script::Node > &command, Module &module) |
bool | CheckPredicate (std::unique_ptr< Script::Node > &predicate, std::shared_ptr< Section > section, Module &module) |
offset_t | EvaluateExpression (std::unique_ptr< Script::Node > &expression, Module &module) |
Static Public Member Functions | |
static std::shared_ptr< COFFFormat > | CreateWriter (format_type type) |
Public Attributes | |
char | signature [2] = { } |
The actual value of the magic number (COFF name: f_magic) | |
std::vector< std::unique_ptr< Section > > | sections |
The list of COFF sections. | |
uint16_t | section_count = 0 |
Section count (COFF name: f_nscns) | |
uint32_t | timestamp = 0 |
Time stamp, unused (COFF name: f_timdat) | |
uint32_t | symbol_table_offset = 0 |
Offset to the first symbol (COFF name: f_symptr) | |
uint32_t | symbol_count = 0 |
The number of symbols (COFF name: f_nsyms) | |
std::vector< std::unique_ptr< Symbol > > | symbols |
The symbols stored inside the COFF file. | |
uint32_t | optional_header_size = 0 |
The size of the optional header (COFF: f_opthdr) | |
uint16_t | flags = 0 |
COFF flags, such as whether the file is executable (f_flags) | |
std::unique_ptr< OptionalHeader > | optional_header = nullptr |
The optional header instance used for reading/writing the COFF file. | |
std::map< uint32_t, size_t > | relocations |
Concurrent DOS 68K requires a special block of data to represent "crunched" relocations (see CPM68KWriter for more details) | |
cpu | cpu_type = CPU_UNKNOWN |
The CPU type, reflected by the first 16-bit word of a COFF file. | |
::EndianType | endiantype = ::EndianType(0) |
The byte order. | |
bool | option_segmentation = false |
format_type | type = GENERIC |
A representation of the format to generate. | |
bool | option_no_relocation = false |
Suppress relocation generation, only relevant for Concurrent DOS 68K, since the other target formats do not store relocations. | |
uint32_t | stub_size = 0 |
Size of MZ stub, only used for DJGPP COFF executables. | |
std::shared_ptr< Linker::Segment > | stack |
Concurrent DOS 68K and FlexOS 386: The stack segment, not stored as part of any section. | |
uint32_t | entry_address = 0 |
Entry address, gets stored in optional header later. | |
uint32_t | relocations_offset = 0 |
Concurrent DOS 68K: Offset to relocations. | |
Public Attributes inherited from Linker::Format | |
offset_t | file_offset |
Public Attributes inherited from Linker::LinkerManager | |
offset_t | current_base = 0 |
The base address of the current section. | |
std::vector< std::shared_ptr< Segment > > | segment_vector |
Ordered sequence of segments. | |
std::map< std::string, std::shared_ptr< Segment > > | segment_map |
Map of segments from their names. | |
std::shared_ptr< Segment > | current_segment |
Currently processed segment. | |
std::map< std::string, Location > | linker_parameters |
Parameters that permit customizing the linker script. | |
std::string | linker_script |
Contents of the linker script. | |
Static Public Attributes | |
static const std::map< uint32_t, MachineType > | MACHINE_TYPES |
Additional Inherited Members | |
Protected Member Functions inherited from Microsoft::MZSimpleStubWriter | |
MZSimpleStubWriter (std::string stub_file="") | |
bool | OpenAndCheckValidFile () |
offset_t | GetStubImageSize () |
void | WriteStubImage (std::ostream &out) |
void | WriteStubImage (Linker::Writer &wr) |
Protected Attributes inherited from Linker::LinkerManager | |
offset_t | current_address = 0 |
Holds the current address value when there is no current_segment. | |
bool | current_is_template = false |
bool | current_is_template_head = false |
offset_t | template_counter = 0 |
std::string | current_template_name |
Protected Attributes inherited from Microsoft::MZSimpleStubWriter | |
std::string | stub_file |
bool | stub_file_valid = true |
std::ifstream | stub |
offset_t | stub_size = -1 |
The UNIX COFF file format.
Originally introduced in UNIX System V, it replaced the previous a.out format. It was later adopted, often with extensions, on many UNIX and non-UNIX operating systems.
The current implementation supports the following formats:
anonymous enum |
|
overridevirtual |
Intermediate step between processing module and generating output file to set up headers and management sections It is expected that after a module is processed, additional steps are required to evaluate the final values of the fields.
Reimplemented from Linker::OutputFormat.
|
overridevirtual |
Resets all fields to their default values, deallocate memory.
Reimplemented from Linker::Format.
|
overridevirtual |
Display file contents in a nice manner.
Reimplemented from Linker::Format.
|
overridevirtual |
Reimplemented from Linker::OutputFormat.
|
overridevirtual |
Whether the generated file might contain bugs that require fixing.
Reimplemented from Linker::InputFormat.
|
overridevirtual |
The main function that handles processing, calculating and generating the final image.
Reimplemented from Linker::OutputFormat.
|
overridevirtual |
Appends a default extension to the filename.
A typical behavior would be to append .exe at the end of the filename. The default action is to leave it intact.
Reimplemented from Linker::OutputFormat.
Reimplemented in Microsoft::PEFormat.
|
overridevirtual |
Callback function when allocating a new segment When the linker script runs, it creates segments consecutively. Overriding this method permits the output format to handle the allocated segment.
Reimplemented from Linker::LinkerManager.
|
overridevirtual |
Processes the module object and initializes format fields.
Reimplemented from Linker::OutputFormat.
|
overridevirtual |
Reads a file and loads the information into a module object.
Implements Linker::InputFormat.
|
overridevirtual |
|
overridevirtual |
Passes command line parameters as settings over to format object.
Reimplemented from Linker::OutputFormat.
|
overridevirtual |
Initializes the reader for linking purposes.
format | The output format that will be used. This is required to know which extra special features need to be implemented (such as segmentation). |
Reimplemented from Linker::InputFormat.
|
overridevirtual |
cpu COFF::COFFFormat::cpu_type = CPU_UNKNOWN |
The CPU type, reflected by the first 16-bit word of a COFF file.
The byte order has to be determined heuristically.