LLVM: lib/ExecutionEngine/JITLink/COFFLinkGraphBuilder.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef LIB_EXECUTIONENGINE_JITLINK_COFFLINKGRAPHBUILDER_H
14#define LIB_EXECUTIONENGINE_JITLINK_COFFLINKGRAPHBUILDER_H
15
19
23
24#define DEBUG_TYPE "jitlink"
25
26namespace llvm {
27namespace jitlink {
28
30public:
33
34protected:
37
39 std::shared_ptrorc::SymbolStringPool SSP, Triple TT,
42
44
46
48
51
54 assert(!GraphSymbols[SymIndex] && "Duplicate symbol at index");
55 GraphSymbols[SymIndex] = &Sym;
57 SymbolSets[SecIndex].insert({Sym.getOffset(), &Sym});
58 }
59
61 if (SymIndex < 0 ||
62 SymIndex >= static_cast<COFFSymbolIndex>(GraphSymbols.size()))
63 return nullptr;
64 return GraphSymbols[SymIndex];
65 }
66
68 assert(!GraphBlocks[SecIndex] && "Duplicate section at index");
70 GraphBlocks[SecIndex] = B;
71 }
72
74 if (SecIndex <= 0 ||
75 SecIndex >= static_cast<COFFSectionIndex>(GraphSymbols.size()))
76 return nullptr;
77 return GraphBlocks[SecIndex];
78 }
79
81 auto &ImageBase = G->addExternalSymbol(G->intern(Name), 0, true);
83 return ImageBase;
84 }
85
87 return Obj.sections();
88 }
89
90
91
92
93
94
95 template
97 RelocHandlerFunction &&Func,
98 bool ProcessDebugSections = false);
99
100
101
102
103 template <typename ClassT, typename RelocHandlerMethod>
105 RelocHandlerMethod &&Method,
106 bool ProcessDebugSections = false) {
108 RelSec,
109 [Instance, Method](const auto &Rel, const auto &Target, auto &GS) {
110 return (Instance->*Method)(Rel, Target, GS);
111 },
112 ProcessDebugSections);
113 }
114
115private:
116
117
118 struct ComdatExportRequest {
122 };
123 std::vector<std::optional> PendingComdatExports;
124
125
126
127 struct WeakExternalRequest {
132 };
133 std::vector WeakExternalRequests;
134
135
136
137 using SymbolSet = std::set<std::pair<orc::ExecutorAddrDiff, Symbol *>>;
138 std::vector SymbolSets;
139
140 Section &getCommonSection();
141
143 orc::SymbolStringPtr SymbolName,
144 object::COFFSymbolRef Symbol,
145 const object::coff_section *Section);
146 Expected<Symbol *> createAliasSymbol(orc::SymbolStringPtr SymbolName,
147 Linkage L, Scope S, Symbol &Target);
148 Expected<Symbol *> createDefinedSymbol(COFFSymbolIndex SymIndex,
149 orc::SymbolStringPtr SymbolName,
150 object::COFFSymbolRef Symbol,
151 const object::coff_section *Section);
152 Expected<Symbol *> createCOMDATExportRequest(
154 const object::coff_aux_section_definition *Definition);
155 Expected<Symbol *> exportCOMDATSymbol(COFFSymbolIndex SymIndex,
156 orc::SymbolStringPtr SymbolName,
157 object::COFFSymbolRef Symbol);
158
159 Error handleDirectiveSection(StringRef Str);
160 Error flushWeakAliasRequests();
161 Error handleAlternateNames();
162 Error calculateImplicitSizeOfSymbols();
163
164 static uint64_t getSectionAddress(const object::COFFObjectFile &Obj,
165 const object::coff_section *Section);
166 static uint64_t getSectionSize(const object::COFFObjectFile &Obj,
167 const object::coff_section *Section);
168 static bool isComdatSection(const object::coff_section *Section);
169 static unsigned getPointerSize(const object::COFFObjectFile &Obj);
170 static llvm::endianness getEndianness(const object::COFFObjectFile &Obj);
171 static StringRef getDLLImportStubPrefix() { return "__imp_"; }
172 static StringRef getDirectiveSectionName() { return ".drectve"; }
174 const object::coff_section *Sec,
175 object::COFFSymbolRef Sym);
176
177 const object::COFFObjectFile &Obj;
178 std::unique_ptr G;
179 COFFDirectiveParser DirectiveParser;
180
181 Section *CommonSection = nullptr;
182 std::vector<Block *> GraphBlocks;
183 std::vector<Symbol *> GraphSymbols;
184
185 DenseMap<orc::SymbolStringPtr, orc::SymbolStringPtr> AlternateNames;
186 DenseMap<orc::SymbolStringPtr, Symbol *> ExternalSymbols;
187 DenseMap<orc::SymbolStringPtr, Symbol *> DefinedSymbols;
188};
189
190template
192 RelocHandlerFunction &&Func,
193 bool ProcessDebugSections) {
194
195 auto COFFRelSect = Obj.getCOFFSection(RelSec);
196
197
199 if (!Name)
200 return Name.takeError();
201
202
203 if (*Name == ".voltbl")
206
207
209 if (!BlockToFix)
211 "Referencing a section that wasn't added to the graph: " + *Name,
213
214
215 for (const auto &R : RelSec.relocations())
216 if (Error Err = Func(R, RelSec, *BlockToFix))
217 return Err;
218
221}
222
224public:
226 : ImageBaseName(ImageBaseName) {}
228 void reset() { ImageBase = std::nullopt; }
229
230private:
232 std::optional<Symbol *> ImageBase;
233};
234
235}
236}
237
238#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static std::optional< TypeSize > getPointerSize(const Value *V, const DataLayout &DL, const TargetLibraryInfo &TLI, const Function *F)
This file defines the DenseMap class.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
StringRef - Represent a constant reference to a string, i.e.
Manages the enabling and disabling of subtarget specific features.
Target - Wrapper for Target specific information.
Triple - Helper class for working with autoconf configuration names.
An Addressable with content and edges.
Expected< std::unique_ptr< LinkGraph > > buildGraph()
virtual Error addRelocations()=0
Error forEachRelocation(const object::SectionRef &RelSec, RelocHandlerFunction &&Func, bool ProcessDebugSections=false)
Traverse all matching relocation records in the given section.
Definition COFFLinkGraphBuilder.h:191
int32_t COFFSymbolIndex
Definition COFFLinkGraphBuilder.h:36
Symbol * getGraphSymbol(COFFSymbolIndex SymIndex) const
Definition COFFLinkGraphBuilder.h:60
Error forEachRelocation(const object::SectionRef &RelSec, ClassT *Instance, RelocHandlerMethod &&Method, bool ProcessDebugSections=false)
Traverse all matching relocation records in the given section.
Definition COFFLinkGraphBuilder.h:104
COFFLinkGraphBuilder(const object::COFFObjectFile &Obj, std::shared_ptr< orc::SymbolStringPool > SSP, Triple TT, SubtargetFeatures Features, LinkGraph::GetEdgeKindNameFunction GetEdgeKindName)
object::COFFObjectFile::section_iterator_range sections() const
Definition COFFLinkGraphBuilder.h:86
virtual ~COFFLinkGraphBuilder()
Block * getGraphBlock(COFFSectionIndex SecIndex) const
Definition COFFLinkGraphBuilder.h:73
void setGraphSymbol(COFFSectionIndex SecIndex, COFFSymbolIndex SymIndex, Symbol &Sym)
Definition COFFLinkGraphBuilder.h:52
void setGraphBlock(COFFSectionIndex SecIndex, Block *B)
Definition COFFLinkGraphBuilder.h:67
LinkGraph & getGraph() const
Definition COFFLinkGraphBuilder.h:43
int32_t COFFSectionIndex
Definition COFFLinkGraphBuilder.h:35
Symbol & addImageBaseSymbol(StringRef Name="__ImageBase")
Definition COFFLinkGraphBuilder.h:80
const object::COFFObjectFile & getObject() const
Definition COFFLinkGraphBuilder.h:45
GetImageBaseSymbol(StringRef ImageBaseName="__ImageBase")
Definition COFFLinkGraphBuilder.h:225
void reset()
Definition COFFLinkGraphBuilder.h:228
Symbol * operator()(LinkGraph &G)
const char *(*)(Edge::Kind) GetEdgeKindNameFunction
void setLive(bool IsLive)
Set this symbol's live bit.
orc::ExecutorAddrDiff getOffset() const
Returns the offset for this symbol within the underlying addressable.
iterator_range< section_iterator > section_iterator_range
This is a value type class that represents a single section in the list of sections in the object fil...
uint64_t getIndex() const
iterator_range< relocation_iterator > relocations() const
bool isReservedSectionNumber(int32_t SectionNumber)
Linkage
Describes symbol linkage. This can be used to resolve definition clashes.
uint64_t ExecutorAddrDiff
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.