10#include "relocation.h"
11#include "symbol_definition.h"
12#include "symbol_name.h"
86 ::EndianType endiantype = ::UndefinedEndian;
90 std::vector<std::shared_ptr<Section>> sections;
91 std::map<std::string, std::shared_ptr<Section>> section_names;
93 std::map<std::string, SymbolDefinition> global_symbols;
95 std::map<std::string, SymbolDefinition> local_symbols;
96 std::vector<SymbolName> imported_symbols;
97 std::map<ExportedSymbolName, Location> exported_symbols;
113 std::vector<Relocation> relocations;
121 std::map<Location, size_t> relocation_indexes;
138 void SetupOptions(
char special_char, std::shared_ptr<OutputFormat> output_format, std::shared_ptr<const InputFormat> input_format);
142 char special_prefix_char =
'$';
143 std::weak_ptr<OutputFormat> output_format;
144 std::weak_ptr<const InputFormat> input_format;
147 std::string section_prefix();
148 std::string segment_prefix();
149 std::string segment_of_prefix();
150 std::string segment_at_prefix();
151 std::string segment_at_section_prefix();
152 std::string with_respect_to_segment_prefix();
153 std::string segment_difference_prefix();
154 std::string import_prefix();
155 std::string segment_of_import_prefix();
156 std::string export_prefix();
157 std::string fix_byte_prefix();
160 std::string resource_prefix();
162 bool parse_imported_name(std::string reference_name,
SymbolName& symbol);
246 void AddSection(std::shared_ptr<Section> section);
249 void _AddSection(std::shared_ptr<Section> section);
255 const std::vector<std::shared_ptr<Section>>&
Sections()
const;
270 std::shared_ptr<Section>
FindSection(std::string name);
275 std::shared_ptr<Section>
FetchSection(std::string name,
unsigned default_flags);
285 void Append(std::shared_ptr<Section> dst, std::shared_ptr<Section> src);
295 void AllocateSymbols(std::string default_section_name =
".bss",
bool force_create_segment =
false);
300 void AllocateStack(offset_t stack_size, std::string default_section_name =
".stack");
Represents a symbol to be exported from the module.
Definition symbol_name.h:144
Represents a single offset within a section, or an absolute location in memory if the section is null...
Definition location.h:17
Helper class that collects object files and libraries, and includes library objects for required symb...
Definition module_collector.h:25
Encodes an object module file as a collection of sections, symbols and relocations.
Definition module.h:24
std::shared_ptr< Section > FindSection(std::string name)
Searches for a section with a specific name.
Definition module.cc:1040
const std::vector< SymbolName > & GetImportedSymbols() const
Retrieves list of all imported symbols.
Definition module.cc:909
bool AddUndefinedSymbol(std::string symbol_name)
Processes undefined symbol for extended syntax.
Definition module.cc:541
bool AddGlobalSymbol(std::string name, Location location)
Adds and processes exported symbol for extended syntax.
Definition module.cc:271
std::vector< SymbolDefinition > symbol_sequence
Sorted collection of all symbols appearing in the module, duplicates removed.
Definition module.h:88
void Append(std::shared_ptr< Section > dst, std::shared_ptr< Section > src)
Appends two sections by shifting all symbols locations and relocation targets in the second one.
Definition module.cc:1074
bool is_included
Set to true if module is included in the linking process, relevant for libraries.
Definition module.h:130
const std::vector< std::shared_ptr< Section > > & Sections() const
Retrieves list of all sections.
Definition module.cc:1023
std::shared_ptr< Section > FetchSection(std::string name, unsigned default_flags)
Searches or creates a section with a specific name, with the assigned flags.
Definition module.cc:1046
bool AddLocalSymbol(std::string name, Location location)
Adds an internal symbol.
Definition module.cc:239
const std::map< ExportedSymbolName, Location > & GetExportedSymbols() const
Retrieves map of all exported symbols and their locations.
Definition module.cc:914
void AddSection(std::shared_ptr< Section > section)
Adds a new section.
Definition module.cc:941
bool FindGlobalSymbol(std::string name, Location &location)
Searches for a global or weak symbol.
Definition module.cc:928
bool AddWeakSymbol(std::string name, Location location)
Adds a weakly bound symbol.
Definition module.cc:359
void RemoveSections()
Removes all sections from internal list, without deleting them.
Definition module.cc:1034
void ResolveLocalRelocations()
Attempts to resolve the local targets of all relocations.
Definition module.cc:1057
void AllocateStack(offset_t stack_size, std::string default_section_name=".stack")
Unless .stack_top is defined or stack_size is zero, makes sure a .stack segment exists and is at leas...
Definition module.cc:1174
void AddImportedSymbol(SymbolName name)
Adds an imported symbol (Microsoft format: library name + symbol name + ordinal/hint)
Definition module.cc:528
void SetupOptions(char special_char, std::shared_ptr< OutputFormat > output_format, std::shared_ptr< const InputFormat > input_format)
Initializes the reader for linking purposes.
Definition module.cc:77
std::vector< Relocation > & GetRelocations()
Returns all the relocations within the module.
Definition module.cc:72
cpu_type
Supported CPU types.
Definition module.h:38
@ MIPS
MIPS.
Definition module.h:71
@ PPC64
IBM PowerPC (64-bit)
Definition module.h:63
@ Z8K
Zilog Z8000.
Definition module.h:59
@ ARM64
AArch64 or ARM64 (64-bit)
Definition module.h:67
@ X86_64
Intel and AMD 64-bit x86.
Definition module.h:47
@ IA64
Intel Itanium.
Definition module.h:79
@ SH
Hitachi SuperH.
Definition module.h:75
@ MOS6502
MOS 6502.
Definition module.h:55
@ I86
Intel 8086 and 80286.
Definition module.h:43
@ W65K
WDC 65C816.
Definition module.h:57
@ PPC
IBM PowerPC (32-bit)
Definition module.h:61
@ M68K
Motorla 68000 and 68020.
Definition module.h:53
@ PDP11
PDP-11.
Definition module.h:69
@ I80
Intel 8080 and Zilog Z80.
Definition module.h:41
@ M6809
Motorla 6809.
Definition module.h:51
@ ALPHA
DEC Alpha.
Definition module.h:77
@ ARM
ARM (32-bit)
Definition module.h:65
@ I386
Intel 80386.
Definition module.h:45
@ M6800
Motorla 6800.
Definition module.h:49
@ SPARC
Sun SPARC.
Definition module.h:73
bool FindLocalSymbol(std::string name, Location &location)
Searches for a local symbol.
Definition module.cc:919
void AddExportedSymbol(ExportedSymbolName name, Location symbol)
Adds an exported symbol (Microsoft format: library name + symbol name + ordinal/hint)
Definition module.cc:536
void DeleteSection(size_t index)
Deletes a specific sections.
Definition module.cc:1028
void AllocateSymbols(std::string default_section_name=".bss", bool force_create_segment=false)
All common symbols are converted to global symbols and assigned addresses within a their section.
Definition module.cc:1153
std::string file_name
Stores source/destination file name.
Definition module.h:27
cpu_type cpu
Encodes the CPU for the target.
Definition module.h:85
bool AddLocalCommonSymbol(SymbolDefinition symbol)
Adds a local common symbol.
Definition module.cc:490
void AddRelocation(Relocation relocation)
Adds and processes relocation for extended syntax.
Definition module.cc:623
bool AddCommonSymbol(SymbolDefinition symbol)
Adds a common symbol.
Definition module.cc:421
A representation of a value within some binary data that has to be fixed up once the exact position o...
Definition relocation.h:27
Represents a symbol definition.
Definition symbol_definition.h:16
Represents an (imported or internal) symbol name, which can be more complex than a string.
Definition symbol_name.h:18