13#ifndef LIB_EXECUTIONENGINE_JITLINK_MACHOLINKGRAPHBUILDER_H
14#define LIB_EXECUTIONENGINE_JITLINK_MACHOLINKGRAPHBUILDER_H
34 struct NormalizedSymbol {
43 assert((!
Name || !
Name->empty()) &&
"Name must be none or non-empty");
48 NormalizedSymbol &
operator=(
const NormalizedSymbol &) =
delete;
50 NormalizedSymbol &
operator=(NormalizedSymbol &&) =
delete;
52 std::optional<StringRef>
Name;
64 class NormalizedSection {
68 NormalizedSection() =
default;
77 const char *
Data =
nullptr;
85 std::shared_ptr<orc::SymbolStringPool> SSP,
Triple TT,
98 template <
typename... ArgTs>
109 auto I = IndexToSection.find(Index);
110 assert(
I != IndexToSection.end() &&
"No section recorded at index");
118 auto I = IndexToSection.find(Index);
119 if (
I == IndexToSection.end())
129 auto I = IndexToSymbol.find(Index);
130 if (
I == IndexToSymbol.end())
133 assert(
I->second &&
"Null symbol at index");
144 return std::prev(
I)->second;
161 static bool isAltEntry(
const NormalizedSymbol &NSym);
181 void setCanonicalSymbol(NormalizedSection &NSec,
Symbol &Sym) {
182 auto *&CanonicalSymEntry = NSec.CanonicalSymbols[Sym.
getAddress()];
186 assert((!CanonicalSymEntry || CanonicalSymEntry->getSize() == 0) &&
187 "Duplicate canonical symbol at address");
188 CanonicalSymEntry = &Sym;
191 Section &getCommonSection();
192 void addSectionStartSymAndBlock(
unsigned SecIndex, Section &GraphSec,
197 Error createNormalizedSections();
198 Error createNormalizedSymbols();
202 Error graphifyRegularSymbols();
208 Symbol &createStandardGraphSymbol(NormalizedSymbol &Sym,
Block &
B,
209 size_t Size,
bool IsText,
210 bool IsNoDeadStrip,
bool IsCanonical);
213 Error graphifySectionsWithCustomParsers();
216 Error graphifyCStringSection(NormalizedSection &NSec,
217 std::vector<NormalizedSymbol *> NSyms);
224 std::unique_ptr<LinkGraph>
G;
226 bool SubsectionsViaSymbols =
false;
228 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")
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",...
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)
Error make_error(ArgTs &&... Args)
Make a Error instance representing failure using the given error info type.
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
NormalizedSymbol & operator=(const NormalizedSymbol &)=delete
std::optional< StringRef > Name
friend class MachOLinkGraphBuilder
NormalizedSymbol(NormalizedSymbol &&)=delete
NormalizedSymbol & operator=(NormalizedSymbol &&)=delete
NormalizedSymbol(const NormalizedSymbol &)=delete