RetroLinker
Linker for several 8-bit, 16-bit and 32-bit formats
Loading...
Searching...
No Matches
symbol.h
1#ifndef SYMBOLNAME_H
2#define SYMBOLNAME_H
3
4#include <iostream>
5#include <optional>
6#include <string>
7#include "../common.h"
8
9namespace Linker
10{
18 {
19 protected:
20 std::optional<std::string> library;
21 /* internal symbols: empty, imported symbols: refers to the library (NE, LE, PE) */
22 std::optional<std::string> name;
23 /* symbols imported by ordinal: empty (NE, LE, PE), other symbols: the name of the symbol */
24 std::optional<uint16_t> hint;
25 /* symbols imported not by ordinal: empty (NE, LE), except PE where it is a hint, other symbols: ordinal */
26
27 public:
31 SymbolName(std::string name)
32 : name(name)
33 {
34 }
35
39 SymbolName(std::string library, std::string name)
40 : library(library), name(name)
41 {
42 }
43
49 SymbolName(std::string library, std::string name, uint16_t hint)
50 : library(library), name(name), hint(hint)
51 {
52 }
53
59 SymbolName(std::string library, uint16_t ordinal)
60 : library(library), hint(ordinal)
61 {
62 }
63
67 bool LoadName(std::string& result) const;
68
72 bool LoadLibraryName(std::string& result) const;
73
77 bool LoadOrdinalOrHint(uint16_t& result) const;
78
82 bool GetLocalName(std::string& result) const;
83
87 bool GetImportedName(std::string& result_library, std::string& result_name) const;
88
92 bool GetImportedName(std::string& result_library, std::string& result_name, uint16_t& result_hint) const;
93
97 bool GetImportedOrdinal(std::string& result_library, uint16_t& result_ordinal) const;
98
102 bool operator ==(const SymbolName& other) const;
103
107 bool operator !=(const SymbolName& other) const;
108 };
109
113 std::ostream& operator<<(std::ostream& out, const SymbolName& symbol);
114
119 {
120 protected:
121 bool by_ordinal;
122 std::string name;
123 std::optional<uint16_t> ordinal;
124
125 public:
129 ExportedSymbol(std::string name)
130 : by_ordinal(false), name(name), ordinal()
131 {
132 }
133
139 ExportedSymbol(std::string name, uint16_t hint)
140 : by_ordinal(false), name(name), ordinal(hint)
141 {
142 }
143
147 ExportedSymbol(uint16_t ordinal, std::string internal_name)
148 : by_ordinal(true), name(internal_name), ordinal(ordinal)
149 {
150 }
151
152 bool IsExportedByOrdinal() const;
153
157 bool LoadName(std::string& result) const;
158
162 bool LoadOrdinalOrHint(uint16_t& result) const;
163
167 bool GetExportedByName(std::string& result) const;
168
172 bool GetExportedByName(std::string& result, uint16_t& hint) const;
173
177 bool GetExportedByOrdinal(uint16_t& result) const;
178
182 bool GetExportedByOrdinal(uint16_t& result, std::string& result_name) const;
183
187 bool operator ==(const ExportedSymbol& other) const;
188
192 bool operator !=(const ExportedSymbol& other) const;
193
197 bool operator <(const ExportedSymbol& other) const;
198
202 bool operator >=(const ExportedSymbol& other) const;
203
207 bool operator >(const ExportedSymbol& other) const;
208
212 bool operator <=(const ExportedSymbol& other) const;
213 };
214
218 std::ostream& operator<<(std::ostream& out, const ExportedSymbol& symbol);
219
224 {
225 public:
226 std::string name;
227 offset_t size, align;
228
229 CommonSymbol(std::string name = "", offset_t size = 0, offset_t align = 1)
230 : name(name), size(size), align(align)
231 {
232 }
233 };
234
235 std::ostream& operator<<(std::ostream& out, const CommonSymbol& symbol);
236}
237
238#endif /* SYMBOLNAME_H */
Represents a currently unallocated variable that should be allocated in the final stages of the linki...
Definition symbol.h:224
Represents a symbol to be exported from the module.
Definition symbol.h:119
bool operator>(const ExportedSymbol &other) const
Compares two symbols for ordering.
Definition symbol.cc:249
bool operator<(const ExportedSymbol &other) const
Compares two symbols for ordering.
Definition symbol.cc:236
bool GetExportedByName(std::string &result) const
For symbols exported by name, returns the name.
Definition symbol.cc:167
bool operator>=(const ExportedSymbol &other) const
Compares two symbols for ordering.
Definition symbol.cc:244
bool operator!=(const ExportedSymbol &other) const
Compares two symbols for inequality.
Definition symbol.cc:231
bool operator<=(const ExportedSymbol &other) const
Compares two symbols for ordering.
Definition symbol.cc:254
ExportedSymbol(std::string name, uint16_t hint)
Creates a symbol exported by name, with a corresponding hint.
Definition symbol.h:139
bool LoadName(std::string &result) const
Returns the name of the symbol.
Definition symbol.cc:148
bool LoadOrdinalOrHint(uint16_t &result) const
Returns the hint or ordinal of the symbol.
Definition symbol.cc:154
bool GetExportedByOrdinal(uint16_t &result) const
For symbols exported by ordinal, returns the ordinal.
Definition symbol.cc:197
ExportedSymbol(std::string name)
Creates a symbol exported by name.
Definition symbol.h:129
bool operator==(const ExportedSymbol &other) const
Compares two symbols for equality.
Definition symbol.cc:226
ExportedSymbol(uint16_t ordinal, std::string internal_name)
Creates a symbol exported by ordinal, with an associated internal name.
Definition symbol.h:147
Represents an (imported or internal) symbol name, which can be more complex than a string.
Definition symbol.h:18
bool GetImportedOrdinal(std::string &result_library, uint16_t &result_ordinal) const
For symbols imported by ordinal, returns the library and ordinal.
Definition symbol.cc:92
bool operator!=(const SymbolName &other) const
Compares two symbols for inequality.
Definition symbol.cc:112
SymbolName(std::string library, uint16_t ordinal)
Creates a symbol imported via ordinal, from a library.
Definition symbol.h:59
SymbolName(std::string name)
Creates an internal symbol with a name.
Definition symbol.h:31
bool GetLocalName(std::string &result) const
For local symbols, returns the name.
Definition symbol.cc:45
bool LoadName(std::string &result) const
Retrieves the name of the symbol, if it has one.
Definition symbol.cc:6
SymbolName(std::string library, std::string name)
Creates a symbol imported via name, from a library.
Definition symbol.h:39
SymbolName(std::string library, std::string name, uint16_t hint)
Creates a symbol imported via name and a hint, from a library.
Definition symbol.h:49
bool LoadOrdinalOrHint(uint16_t &result) const
Retrieves the ordinal of symbols imported by ordinal, or the hint for imported symbols with a hint.
Definition symbol.cc:32
bool LoadLibraryName(std::string &result) const
Retrieves the name of the library, if it is imported.
Definition symbol.cc:19
bool GetImportedName(std::string &result_library, std::string &result_name) const
For symbols imported by name, returns the library and name.
Definition symbol.cc:60
bool operator==(const SymbolName &other) const
Compares two symbols for equality.
Definition symbol.cc:107