LLVM: lib/ExecutionEngine/JITLink/MachOLinkGraphBuilder.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef LIB_EXECUTIONENGINE_JITLINK_MACHOLINKGRAPHBUILDER_H
14#define LIB_EXECUTIONENGINE_JITLINK_MACHOLINKGRAPHBUILDER_H
15
20
23
24namespace llvm {
26
28public:
31
32protected:
33
34 struct NormalizedSymbol {
36
37 private:
43 assert(( ||
->empty()) && "Name must be none or non-empty");
44 }
45
46 public:
48 NormalizedSymbol &operator=(const NormalizedSymbol &) = delete;
50 NormalizedSymbol &operator=(NormalizedSymbol &&) = delete;
51
60 };
61
62
63
64 class NormalizedSection {
66
67 private:
68 NormalizedSection() = default;
69
70 public:
77 const char *Data = nullptr;
80 };
81
83
85 std::shared_ptrorc::SymbolStringPool SSP, Triple TT,
89
91
94
96
97
98 template <typename... ArgTs>
105
106
107
109 auto I = IndexToSection.find(Index);
110 assert(I != IndexToSection.end() && "No section recorded at index");
111 return I->second;
112 }
113
114
115
116
118 auto I = IndexToSection.find(Index);
119 if (I == IndexToSection.end())
121 formatv("{0:d}", Index));
122 return I->second;
123 }
124
125
126
127
129 auto I = IndexToSymbol.find(Index);
130 if (I == IndexToSymbol.end())
132 formatv("{0:d}", Index));
133 assert(I->second && "Null symbol at index");
134 return *I->second;
135 }
136
137
138
143 return nullptr;
144 return std::prev(I)->second;
145 }
146
147
148
152 if (Sym)
154 return *Sym;
157 }
158
161 static bool isAltEntry(const NormalizedSymbol &NSym);
162
163 static bool isDebugSection(const NormalizedSection &NSec);
165
179
180private:
183
184 void setCanonicalSymbol(NormalizedSection &NSec, Symbol &Sym) {
185 auto *&CanonicalSymEntry = NSec.CanonicalSymbols[Sym.getAddress()];
186
187
188
189 assert((!CanonicalSymEntry || CanonicalSymEntry->getSize() == 0) &&
190 "Duplicate canonical symbol at address");
191 CanonicalSymEntry = &Sym;
192 }
193
194 Section &getCommonSection();
195 void addSectionStartSymAndBlock(unsigned SecIndex, Section &GraphSec,
198 uint32_t Alignment, bool IsLive);
199
200 Error createNormalizedSections();
201 Error createNormalizedSymbols();
202
203
204
205 Error graphifyRegularSymbols();
206
207
208
209
210
211 Symbol &createStandardGraphSymbol(NormalizedSymbol &Sym, Block &B,
212 size_t Size, bool IsText,
213 bool IsNoDeadStrip, bool IsCanonical);
214
215
216 Error graphifySectionsWithCustomParsers();
217
218
219 Error graphifyCStringSection(NormalizedSection &NSec,
220 std::vector<NormalizedSymbol *> NSyms);
221
222
223
225
227 std::unique_ptr G;
228
229 bool SubsectionsViaSymbols = false;
231 Section *CommonSection = nullptr;
232
235};
236
237}
238}
239
240#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
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.
Tagged union holding either a T or a Error.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
StringRef - Represent a constant reference to a string, i.e.
Manages the enabling and disabling of subtarget specific features.
Triple - Helper class for working with autoconf configuration names.
The instances of the Type class are immutable: once they are created, they are never changed.
const char *(*)(Edge::Kind) GetEdgeKindNameFunction
Section * GraphSection
Definition MachOLinkGraphBuilder.h:78
friend class MachOLinkGraphBuilder
Definition MachOLinkGraphBuilder.h:65
uint32_t Flags
Definition MachOLinkGraphBuilder.h:76
orc::ExecutorAddr Address
Definition MachOLinkGraphBuilder.h:73
char SectName[17]
Definition MachOLinkGraphBuilder.h:71
std::map< orc::ExecutorAddr, Symbol * > CanonicalSymbols
Definition MachOLinkGraphBuilder.h:79
uint64_t Alignment
Definition MachOLinkGraphBuilder.h:75
uint64_t Size
Definition MachOLinkGraphBuilder.h:74
char SegName[17]
Definition MachOLinkGraphBuilder.h:72
const char * Data
Definition MachOLinkGraphBuilder.h:77
static bool isDebugSection(const NormalizedSection &NSec)
void addCustomSectionParser(StringRef SectionName, SectionParserFunction Parse)
const object::MachOObjectFile & getObject() const
Definition MachOLinkGraphBuilder.h:90
virtual ~MachOLinkGraphBuilder()
virtual Error addRelocations()=0
std::function< Error(NormalizedSection &S)> SectionParserFunction
Definition MachOLinkGraphBuilder.h:82
static Scope getScope(StringRef Name, uint8_t Type)
static bool isZeroFillSection(const NormalizedSection &NSec)
Expected< Symbol & > findSymbolByAddress(NormalizedSection &NSec, orc::ExecutorAddr Address)
Returns the symbol with the highest address not greater than the search address, or an error if no su...
Definition MachOLinkGraphBuilder.h:149
Expected< NormalizedSymbol & > findSymbolByIndex(uint64_t Index)
Try to get the symbol at the given index.
Definition MachOLinkGraphBuilder.h:128
LinkGraph & getGraph() const
Definition MachOLinkGraphBuilder.h:88
Expected< std::unique_ptr< LinkGraph > > buildGraph()
NormalizedSection & getSectionByIndex(unsigned Index)
Index is zero-based (MachO section indexes are usually one-based) and assumed to be in-range.
Definition MachOLinkGraphBuilder.h:108
MachOLinkGraphBuilder(const object::MachOObjectFile &Obj, std::shared_ptr< orc::SymbolStringPool > SSP, Triple TT, SubtargetFeatures Features, LinkGraph::GetEdgeKindNameFunction GetEdgeKindName)
NormalizedSymbol & createNormalizedSymbol(ArgTs &&... Args)
Create a symbol.
Definition MachOLinkGraphBuilder.h:99
static Linkage getLinkage(uint16_t Desc)
Symbol * getSymbolByAddress(NormalizedSection &NSec, orc::ExecutorAddr Address)
Returns the symbol with the highest address not greater than the search address, or null if no such s...
Definition MachOLinkGraphBuilder.h:139
static bool isAltEntry(const NormalizedSymbol &NSym)
MachO::relocation_info getRelocationInfo(const object::relocation_iterator RelItr)
Definition MachOLinkGraphBuilder.h:167
Expected< NormalizedSection & > findSectionByIndex(unsigned Index)
Try to get the section at the given index.
Definition MachOLinkGraphBuilder.h:117
Represents an object file section.
orc::ExecutorAddr getAddress() const
Returns the address of this symbol.
MachO::any_relocation_info getRelocation(DataRefImpl Rel) const
DataRefImpl getRawDataRefImpl() const
Represents an address in the executor process.
Linkage
Describes symbol linkage. This can be used to resolve definition clashes.
Scope
Defines the scope in which this symbol should be visible: Default – Visible in the public interface o...
content_iterator< RelocationRef > relocation_iterator
uint64_t ExecutorAddrDiff
This is an optimization pass for GlobalISel generic memory operations.
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
NormalizedSymbol & operator=(const NormalizedSymbol &)=delete
uint8_t Type
Definition MachOLinkGraphBuilder.h:54
std::optional< StringRef > Name
Definition MachOLinkGraphBuilder.h:52
Symbol * GraphSymbol
Definition MachOLinkGraphBuilder.h:59
friend class MachOLinkGraphBuilder
Definition MachOLinkGraphBuilder.h:35
Linkage L
Definition MachOLinkGraphBuilder.h:57
uint8_t Sect
Definition MachOLinkGraphBuilder.h:55
uint16_t Desc
Definition MachOLinkGraphBuilder.h:56
uint64_t Value
Definition MachOLinkGraphBuilder.h:53
NormalizedSymbol(NormalizedSymbol &&)=delete
NormalizedSymbol & operator=(NormalizedSymbol &&)=delete
Scope S
Definition MachOLinkGraphBuilder.h:58
NormalizedSymbol(const NormalizedSymbol &)=delete