13#ifndef LIB_EXECUTIONENGINE_JITLINK_MACHOLINKGRAPHBUILDER_H
14#define LIB_EXECUTIONENGINE_JITLINK_MACHOLINKGRAPHBUILDER_H
36 struct NormalizedSymbol {
45 assert((!
Name || !
Name->empty()) &&
"Name must be none or non-empty");
50 NormalizedSymbol &
operator=(
const NormalizedSymbol &) =
delete;
52 NormalizedSymbol &
operator=(NormalizedSymbol &&) =
delete;
54 std::optional<StringRef>
Name;
66 class NormalizedSection {
70 NormalizedSection() =
default;
79 const char *
Data =
nullptr;
87 std::shared_ptr<orc::SymbolStringPool> SSP,
Triple TT,
100 template <
typename... ArgTs>
111 auto I = IndexToSection.find(Index);
112 assert(
I != IndexToSection.end() &&
"No section recorded at index");
120 auto I = IndexToSection.find(Index);
121 if (
I == IndexToSection.end())
131 auto I = IndexToSymbol.find(Index);
132 if (
I == IndexToSymbol.end())
135 assert(
I->second &&
"Null symbol at index");
146 return std::prev(
I)->second;
163 static bool isAltEntry(
const NormalizedSymbol &NSym);
186 void setCanonicalSymbol(NormalizedSection &NSec,
Symbol &Sym) {
187 auto *&CanonicalSymEntry = NSec.CanonicalSymbols[Sym.
getAddress()];
191 assert((!CanonicalSymEntry || CanonicalSymEntry->getSize() == 0) &&
192 "Duplicate canonical symbol at address");
193 CanonicalSymEntry = &Sym;
196 Section &getCommonSection();
197 void addSectionStartSymAndBlock(
unsigned SecIndex, Section &GraphSec,
202 Error createNormalizedSections();
203 Error createNormalizedSymbols();
207 Error graphifyRegularSymbols();
213 Symbol &createStandardGraphSymbol(NormalizedSymbol &Sym,
Block &
B,
214 size_t Size,
bool IsText,
215 bool IsNoDeadStrip,
bool IsCanonical);
218 Error graphifySectionsWithCustomParsers();
221 Error graphifyCStringSection(NormalizedSection &NSec,
222 std::vector<NormalizedSymbol *> NSyms);
229 std::unique_ptr<LinkGraph>
G;
231 bool SubsectionsViaSymbols =
false;
233 Section *CommonSection =
nullptr;
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
friend class MachOLinkGraphBuilder
orc::ExecutorAddr Address
std::map< orc::ExecutorAddr, Symbol * > CanonicalSymbols
static bool isDebugSection(const NormalizedSection &NSec)
void addCustomSectionParser(StringRef SectionName, SectionParserFunction Parse)
const object::MachOObjectFile & getObject() const
virtual ~MachOLinkGraphBuilder()
virtual Error addRelocations()=0
std::function< Error(NormalizedSection &S)> SectionParserFunction
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...
Expected< NormalizedSymbol & > findSymbolByIndex(uint64_t Index)
Try to get the symbol at the given index.
LinkGraph & getGraph() const
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.
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.
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...
static bool isAltEntry(const NormalizedSymbol &NSym)
MachO::relocation_info getRelocationInfo(const object::relocation_iterator RelItr)
Expected< NormalizedSection & > findSectionByIndex(unsigned Index)
Try to get the section at the given index.
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)
BumpPtrAllocatorImpl BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
NormalizedSymbol & operator=(const NormalizedSymbol &)=delete
std::optional< StringRef > Name
friend class MachOLinkGraphBuilder
NormalizedSymbol(NormalizedSymbol &&)=delete
NormalizedSymbol & operator=(NormalizedSymbol &&)=delete
NormalizedSymbol(const NormalizedSymbol &)=delete