13#ifndef LLVM_EXECUTIONENGINE_JITLINK_JITLINK_H
14#define LLVM_EXECUTIONENGINE_JITLINK_JITLINK_H
41#include <system_error>
82 :
Target(&
Target), Offset(Offset), Addend(Addend), K(K) {}
120 assert(!(IsDefined && IsAbsolute) &&
121 "Block cannot be both defined and absolute");
135 bool isDefined()
const {
return static_cast<bool>(IsDefined); }
136 bool isAbsolute()
const {
return static_cast<bool>(IsAbsolute); }
139 void setAbsolute(
bool IsAbsolute) {
140 assert(!IsDefined &&
"Cannot change the Absolute flag on a defined block");
141 this->IsAbsolute = IsAbsolute;
168 "Alignment offset cannot exceed alignment");
170 "Alignment offset exceeds maximum");
185 "Alignment offset cannot exceed alignment");
187 "Alignment offset exceeds maximum");
204 "Alignment offset cannot exceed alignment");
206 "Alignment offset exceeds maximum");
247 assert(Data &&
"Block does not contain content");
274 assert(Data &&
"Block does not contain content");
284 assert(MutableContent.
data() &&
"Setting null content");
285 Data = MutableContent.
data();
313 "Alignment offset can't exceed alignment");
321 "Adding edge to zero-fill block?");
331 return make_range(Edges.begin(), Edges.end());
336 return make_range(Edges.begin(), Edges.end());
342 [O](
const Edge &
E) {
return E.getOffset() == O; });
348 [O](
const Edge &
E) {
return E.getOffset() == O; });
368 static constexpr uint64_t MaxAlignmentOffset = (1ULL << 56) - 1;
370 void setSection(
Section &Parent) { this->Parent = &Parent; }
373 const char *Data =
nullptr;
375 std::vector<Edge> Edges;
380 uint64_t Delta = (
B.getAlignmentOffset() -
Addr) %
B.getAlignment();
438 Scope S,
bool IsLive,
bool IsCallable)
453 bool WeaklyReferenced) {
455 "Cannot create external symbol from defined block");
456 assert(
Name &&
"External symbol name cannot be empty");
460 Sym->setWeaklyReferenced(WeaklyReferenced);
466 orc::SymbolStringPtr &&
Name,
468 Scope S,
bool IsLive) {
469 assert(!Base.isDefined() &&
470 "Cannot create absolute symbol from a defined block");
481 "Symbol extends past end of block");
490 orc::SymbolStringPtr
Name,
492 Scope S,
bool IsLive,
bool IsCallable) {
494 "Symbol extends past end of block");
520 "Anonymous symbol has non-local scope");
532 assert(
Base &&
"Attempt to access null symbol");
533 return Base->isDefined();
539 assert(
Base &&
"Attempting to access null symbol");
544 void setLive(
bool IsLive) { this->IsLive = IsLive; }
550 void setCallable(
bool IsCallable) { this->IsCallable = IsCallable; }
554 assert(
Base &&
"Attempt to access null symbol");
555 return !
Base->isDefined() && !
Base->isAbsolute();
560 assert(
Base &&
"Attempt to access null symbol");
561 return Base->isAbsolute();
566 assert(
Base &&
"Cannot get underlying addressable for null symbol");
572 assert(
Base &&
"Cannot get underlying addressable for null symbol");
578 assert(
Base &&
"Cannot get block for null symbol");
579 assert(
Base->isDefined() &&
"Not a defined symbol");
580 return static_cast<Block &
>(*Base);
585 assert(
Base &&
"Cannot get block for null symbol");
586 assert(
Base->isDefined() &&
"Not a defined symbol");
587 return static_cast<const Block &
>(*Base);
606 assert(
Base &&
"Cannot set size for null Symbol");
608 "Non-zero size can only be set for defined symbols");
610 "Symbol size cannot extend past the end of its containing block");
635 "Linkage can only be applied to defined named symbols");
636 this->L =
static_cast<uint8_t>(L);
645 "Can not set anonymous symbol to non-local scope");
647 "Invalid visibility for symbol type");
648 this->S =
static_cast<uint8_t>(S);
656 assert(Flags <= 1 &&
"Add more bits to store more than single flag");
671 this->WeakRef = WeakRef;
676 assert(!
A.isDefined() && !
A.isAbsolute() &&
677 "Attempting to make external with defined or absolute block");
686 assert(!
A.isDefined() &&
A.isAbsolute() &&
687 "Attempting to make absolute with defined or external block");
692 void setBlock(Block &
B) { Base = &
B; }
694 static constexpr uint64_t MaxOffset = (1ULL << 59) - 1;
696 orc::SymbolStringPtr
Name =
nullptr;
697 Addressable *
Base =
nullptr;
710void printEdge(raw_ostream &
OS,
const Block &
B,
const Edge &
E,
711 StringRef EdgeKindName);
719 :
Name(
Name), Prot(Prot), SecOrdinal(SecOrdinal) {}
792 assert(!Symbols.
count(&
Sym) &&
"Symbol is already in this section");
796 void removeSymbol(Symbol &
Sym) {
801 void addBlock(Block &
B) {
802 assert(!
Blocks.count(&
B) &&
"Block is already in this section");
806 void removeBlock(Block &
B) {
811 void transferContentTo(Section &DstSection) {
812 if (&DstSection ==
this)
814 for (
auto *S : Symbols)
815 DstSection.addSymbol(*S);
817 DstSection.addBlock(*
B);
838 First = Last = *Sec.
blocks().begin();
847 assert((!Last || First) &&
"First can not be null if end is non-null");
851 assert((First || !Last) &&
"Last can not be null if start is non-null");
855 assert((First || !Last) &&
"Last can not be null if start is non-null");
871 Block *First =
nullptr;
872 Block *Last =
nullptr;
882 template <
typename... ArgTs>
895 template <
typename... ArgTs>
Block &createBlock(ArgTs &&... Args) {
897 new (
B)
Block(std::forward<ArgTs>(Args)...);
898 B->getSection().addBlock(*
B);
902 void destroyBlock(
Block &
B) {
907 void destroySymbol(
Symbol &S) {
917 getSectionConstBlocks(
const Section &S) {
922 getSectionSymbols(
Section &S) {
927 getSectionConstSymbols(
const Section &S) {
931 struct GetExternalSymbolMapEntryValue {
937 struct GetSectionMapEntryValue {
941 struct GetSectionMapEntryConstValue {
950 GetExternalSymbolMapEntryValue>;
958 template <
typename OuterItrT,
typename InnerItrT,
typename T,
960 typename OuterItrT::reference)>
963 nested_collection_iterator<OuterItrT, InnerItrT, T, getInnerRange>,
964 std::forward_iterator_tag, T> {
969 : OuterI(OuterI), OuterE(OuterE),
970 InnerI(getInnerBegin(OuterI, OuterE)) {
971 moveToNonEmptyInnerOrEnd();
975 return (OuterI ==
RHS.OuterI) && (InnerI ==
RHS.InnerI);
979 assert(InnerI != getInnerRange(*OuterI).end() &&
"Dereferencing end?");
985 moveToNonEmptyInnerOrEnd();
990 static InnerItrT getInnerBegin(OuterItrT OuterI, OuterItrT OuterE) {
991 return OuterI != OuterE ? getInnerRange(*OuterI).begin() : InnerItrT();
994 void moveToNonEmptyInnerOrEnd() {
995 while (OuterI != OuterE && InnerI == getInnerRange(*OuterI).end()) {
997 InnerI = getInnerBegin(OuterI, OuterE);
1001 OuterItrT OuterI, OuterE;
1007 Symbol *, getSectionSymbols>;
1012 getSectionConstSymbols>;
1016 Block *, getSectionBlocks>;
1021 getSectionConstBlocks>;
1025 LinkGraph(std::string Name, std::shared_ptr<orc::SymbolStringPool> SSP,
1029 Features(
std::
move(Features)),
1030 GetEdgeKindName(
std::
move(GetEdgeKindName)) {
1032 "Arch bitwidth is not a multiple of 8");
1043 const std::string &
getName()
const {
return Name; }
1073 auto *AllocatedBuffer =
Allocator.Allocate<
char>(Source.size());
1087 auto SourceStr = Source.toStringRef(TmpBuffer);
1088 auto *AllocatedBuffer =
Allocator.Allocate<
char>(SourceStr.size());
1100 return {Buf.data(), Buf.size()};
1109 char *AllocatedBuffer =
Allocator.Allocate<
char>(Source.size() + 1);
1111 AllocatedBuffer[Source.size()] =
'\0';
1126 auto SourceStr = Source.toStringRef(TmpBuffer);
1127 auto *AllocatedBuffer =
Allocator.Allocate<
char>(SourceStr.size() + 1);
1129 AllocatedBuffer[SourceStr.size()] =
'\0';
1135 assert(!Sections.count(Name) &&
"Duplicate section name");
1136 std::unique_ptr<Section> Sec(
new Section(Name, Prot, Sections.size()));
1137 return *Sections.insert(std::make_pair(Name, std::move(Sec))).first->second;
1144 return createBlock(Parent,
Content,
Address, Alignment, AlignmentOffset);
1153 return createBlock(Parent, MutableContent,
Address, Alignment,
1164 bool ZeroInitialize =
true) {
1168 return createBlock(Parent,
Content,
Address, Alignment, AlignmentOffset);
1175 return createBlock(Parent,
Size,
Address, Alignment, AlignmentOffset);
1181 reinterpret_cast<const uint8_t *
>(
B.getContent().data()),
B.getSize());
1189 reinterpret_cast<uint8_t *
>(
B.getMutableContent(*this).data()),
1234 template <
typename SplitOffsetRange>
1237 std::vector<Block *>
Blocks;
1240 if (std::empty(SplitOffsets))
1244 if (
B.isZeroFill()) {
1245 size_t OrigSize =
B.getSize();
1248 "Split offset must be inside block content");
1249 Blocks.back()->setZeroFillSize(
1252 B.getSection(),
B.getSize(),
B.getAddress() +
Offset,
1254 (
B.getAlignmentOffset() +
Offset) %
B.getAlignment()));
1256 Blocks.back()->setZeroFillSize(
1257 OrigSize - (
Blocks.back()->getAddress() -
B.getAddress()));
1266 "Split offset must be inside block content");
1270 (
B.getAlignmentOffset() +
Offset) %
B.getAlignment()));
1273 return splitBlockImpl(std::move(
Blocks), Cache);
1278 return SSP->intern(SymbolName);
1291 bool IsWeaklyReferenced) {
1292 assert(!ExternalSymbols.
contains(*Name) &&
"Duplicate external symbol");
1293 auto &
Sym = Symbol::constructExternal(
1301 bool IsWeaklyReferenced) {
1312 return Sym->getName() == Name;
1314 "Duplicate absolute symbol");
1316 std::move(Name),
Size, L, S, IsLive);
1333 IsCallable, IsLive);
1343 IsCallable, IsLive);
1349 bool IsCallable,
bool IsLive) {
1352 return Sym->getName() == Name;
1354 "Duplicate defined symbol");
1357 Size, L, S, IsLive, IsCallable);
1371 GetSectionMapEntryConstValue()),
1380 auto I = Sections.find(Name);
1381 if (
I == Sections.end())
1383 return I->second.get();
1401 GetExternalSymbolMapEntryValue()),
1403 GetExternalSymbolMapEntryValue()));
1410 if (
Sym->getName() == Name)
1421 if (
Sym->getName() == Name)
1442 if (
Sym->hasName() &&
Sym->getName() == Name)
1452 assert(!
Sym.isExternal() &&
"Symbol is already external");
1453 if (
Sym.isAbsolute()) {
1455 "Sym is not in the absolute symbols set");
1456 assert(
Sym.getOffset() == 0 &&
"Absolute not at offset 0");
1458 auto &
A =
Sym.getAddressable();
1459 A.setAbsolute(
false);
1462 assert(
Sym.isDefined() &&
"Sym is not a defined symbol");
1464 Sec.removeSymbol(
Sym);
1479 assert(!
Sym.isAbsolute() &&
"Symbol is already absolute");
1480 if (
Sym.isExternal()) {
1482 "Sym is not in the absolute symbols set");
1483 assert(
Sym.getOffset() == 0 &&
"External is not at offset 0");
1484 ExternalSymbols.
erase(*
Sym.getName());
1485 auto &
A =
Sym.getAddressable();
1486 A.setAbsolute(
true);
1490 assert(
Sym.isDefined() &&
"Sym is not a defined symbol");
1492 Sec.removeSymbol(
Sym);
1493 Sym.makeAbsolute(createAddressable(
Address));
1503 assert(!
Sym.isDefined() &&
"Sym is already a defined symbol");
1504 if (
Sym.isAbsolute()) {
1506 "Symbol is not in the absolutes set");
1510 "Symbol is not in the externals set");
1511 ExternalSymbols.
erase(*
Sym.getName());
1519 Sym.setLive(IsLive);
1521 destroyAddressable(OldBase);
1536 std::optional<orc::ExecutorAddrDiff> ExplicitNewSize) {
1537 auto &OldSection =
Sym.getBlock().getSection();
1538 Sym.setBlock(DestBlock);
1539 Sym.setOffset(NewOffset);
1540 if (ExplicitNewSize)
1541 Sym.setSize(*ExplicitNewSize);
1543 auto RemainingBlockSize = DestBlock.
getSize() - NewOffset;
1544 if (
Sym.getSize() > RemainingBlockSize)
1545 Sym.setSize(RemainingBlockSize);
1547 if (&DestBlock.
getSection() != &OldSection) {
1548 OldSection.removeSymbol(
Sym);
1561 auto &OldSection =
B.getSection();
1562 if (&OldSection == &NewSection)
1565 for (
auto *S : OldSection.symbols())
1568 for (
auto *S : AttachedSymbols) {
1569 OldSection.removeSymbol(*S);
1570 NewSection.addSymbol(*S);
1572 OldSection.removeBlock(
B);
1573 NewSection.addBlock(
B);
1582 bool PreserveSrcSection =
false) {
1583 if (&DstSection == &SrcSection)
1585 for (
auto *
B : SrcSection.
blocks())
1586 B->setSection(DstSection);
1587 SrcSection.transferContentTo(DstSection);
1588 if (!PreserveSrcSection)
1595 "Sym is not an external symbol");
1597 "Symbol is not in the externals set");
1598 ExternalSymbols.
erase(*
Sym.getName());
1601 [&](
Symbol *AS) {
return AS->Base == &
Base; }) &&
1602 "Base addressable still in use");
1604 destroyAddressable(
Base);
1610 "Sym is not an absolute symbol");
1612 "Symbol is not in the absolute symbols set");
1616 [&](
Symbol *AS) {
return AS->Base == &
Base; }) &&
1617 "Base addressable still in use");
1619 destroyAddressable(
Base);
1624 assert(
Sym.isDefined() &&
"Sym is not a defined symbol");
1625 Sym.getBlock().getSection().removeSymbol(
Sym);
1634 return &Sym->getBlock() == &B;
1636 "Block still has symbols attached");
1637 B.getSection().removeBlock(
B);
1644 assert(Sections.count(Sec.
getName()) &&
"Section not found");
1645 assert(Sections.find(Sec.
getName())->second.get() == &Sec &&
1646 "Section map entry invalid");
1647 Sections.erase(Sec.
getName());
1661 std::vector<Block *> splitBlockImpl(std::vector<Block *>
Blocks,
1669 std::shared_ptr<orc::SymbolStringPool> SSP;
1675 ExternalSymbolMap ExternalSymbols;
1676 AbsoluteSymbolSet AbsoluteSymbols;
1702 template <
typename PredFn = decltype(includeAllBlocks)>
1707 auto I = AddrToBlock.upper_bound(
B.getAddress());
1711 if (
I != AddrToBlock.end()) {
1712 if (
B.getAddress() +
B.getSize() >
I->second->getAddress())
1713 return overlapError(
B, *
I->second);
1718 if (
I != AddrToBlock.begin()) {
1719 auto &PrevBlock = *std::prev(
I)->second;
1720 if (PrevBlock.getAddress() + PrevBlock.getSize() >
B.getAddress())
1721 return overlapError(
B, PrevBlock);
1724 AddrToBlock.insert(
I, std::make_pair(
B.getAddress(), &
B));
1736 template <
typename BlockPtrRange,
1748 template <
typename BlockPtrRange>
1761 auto I = AddrToBlock.find(
Addr);
1762 if (
I == AddrToBlock.end())
1770 auto I = AddrToBlock.upper_bound(
Addr);
1771 if (
I == AddrToBlock.begin())
1773 auto *
B = std::prev(
I)->second;
1782 auto ExistingBlockEnd =
1784 return make_error<JITLinkError>(
1787 NewBlockEnd.getValue()) +
1790 ExistingBlockEnd.getValue()));
1807 template <
typename SymbolPtrCollection>
1809 for (
auto *
Sym : Symbols)
1816 auto I = AddrToSymbols.find(
Addr);
1817 if (
I == AddrToSymbols.end())
1823 std::map<orc::ExecutorAddr, SymbolVector> AddrToSymbols;
1908 virtual void anchor();
1912template <
typename Continuation>
1913std::unique_ptr<JITLinkAsyncLookupContinuation>
1918 Impl(Continuation
C) :
C(std::move(
C)) {}
1925 return std::make_unique<Impl>(std::move(Cont));
1953 std::unique_ptr<JITLinkAsyncLookupContinuation> LC) = 0;
2034template <
typename VisitorT,
typename... VisitorTs>
2036 VisitorTs &&...Vs) {
2037 if (!V.visitEdge(
G,
B,
E))
2047template <
typename... VisitorTs>
2051 std::vector<Block *> Worklist(
G.blocks().begin(),
G.blocks().end());
2053 for (
auto *
B : Worklist)
2054 for (
auto &
E :
B->edges())
2065 std::shared_ptr<orc::SymbolStringPool> SSP);
2068std::unique_ptr<LinkGraph>
2073void link(std::unique_ptr<LinkGraph>
G, std::unique_ptr<JITLinkContext> Ctx);
This file defines the BumpPtrAllocator interface.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file defines the DenseMap class.
This file defines the DenseSet and SmallDenseSet classes.
static void addSymbol(Object &Obj, const NewSymbolInfo &SymInfo, uint8_t DefaultVisibility)
DenseMap< Block *, BlockRelaxAux > Blocks
static void makeAbsolute(SmallVectorImpl< char > &Path)
Make Path absolute.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
const Value * getAddress(const DbgVariableIntrinsic *DVI)
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
ArrayRef< T > slice(size_t N, size_t M) const
slice(n, m) - Chop off the first N elements of the array, and keep M elements in the array.
Provides read only access to a subclass of BinaryStream.
Provides write only access to a subclass of WritableBinaryStream.
Allocate memory in an ever growing pool, as if by bump-pointer.
Implements a dense probed hash-table based set.
Base class for user error types.
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.
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
bool contains(StringRef Key) const
contains - Return true if the element is in the map, false otherwise.
StringMapIterator< Symbol * > iterator
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
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.
unsigned getArchPointerBitWidth() const
Returns the pointer width of this architecture.
bool isLittleEndian() const
Tests whether the target triple is little endian.
ArchType getArch() const
Get the parsed architecture type of this triple.
static unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch)
Returns the pointer width of this architecture.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM Value Representation.
std::pair< iterator, bool > insert(const ValueT &V)
ConstIterator const_iterator
bool erase(const ValueT &V)
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
CRTP base class which implements the entire standard iterator facade in terms of a minimal subset of ...
A range adaptor for a pair of iterators.
Base class for Addressable entities (externals, absolutes, blocks).
void setAddress(orc::ExecutorAddr Address)
Addressable & operator=(Addressable &&)=default
bool isDefined() const
Returns true if this is a defined addressable, in which case you can downcast this to a Block.
orc::ExecutorAddr getAddress() const
Addressable(Addressable &&)=delete
Addressable(orc::ExecutorAddr Address)
Addressable(const Addressable &)=delete
Addressable(orc::ExecutorAddr Address, bool IsDefined)
Addressable & operator=(const Addressable &)=default
Enables easy lookup of blocks by addresses.
const_iterator end() const
const_iterator begin() const
Iterates over (Address, Block*) pairs in ascending order of address.
Block * getBlockCovering(orc::ExecutorAddr Addr) const
Returns the block covering the given address, or nullptr if no such block exists.
Error addBlock(Block &B, PredFn Pred=includeAllBlocks)
Add a block to the map.
std::map< orc::ExecutorAddr, Block * > AddrToBlockMap
void addBlockWithoutChecking(Block &B)
Add a block to the map without checking for overlap with existing blocks.
BlockAddressMap()=default
static bool includeAllBlocks(const Block &B)
A block predicate that always adds all blocks.
AddrToBlockMap::const_iterator const_iterator
Error addBlocks(BlockPtrRange &&Blocks, PredFn Pred=includeAllBlocks)
Add a range of blocks to the map.
Block * getBlockAt(orc::ExecutorAddr Addr) const
Returns the block starting at the given address, or nullptr if no such block exists.
static bool includeNonNull(const Block &B)
A block predicate that always includes blocks with non-null addresses.
void addBlocksWithoutChecking(BlockPtrRange &&Blocks)
Add a range of blocks to the map without checking for overlap with existing blocks.
An Addressable with content and edges.
Block(const Block &)=delete
void addEdge(const Edge &E)
Add an edge by copying an existing one.
bool isContentMutable() const
Returns true if this block's content is mutable.
ArrayRef< char > getContent() const
Get the content for this block. Block must not be a zero-fill block.
iterator_range< const_edge_iterator > edges() const
Returns the list of edges attached to this content.
auto edges_at(Edge::OffsetT O) const
Returns an iterator over all edges at the given offset within the block.
uint64_t getAlignmentOffset() const
Get the alignment offset for this content.
uint64_t getAlignment() const
Get the alignment for this content.
bool isZeroFill() const
Returns true if this is a zero-fill block.
void setZeroFillSize(size_t Size)
Turns this block into a zero-fill block of the given size.
Block & operator=(Block &&)=delete
size_t edges_size() const
Return the size of the edges list.
edge_iterator removeEdge(edge_iterator I)
Remove the edge pointed to by the given iterator.
void addEdge(Edge::Kind K, Edge::OffsetT Offset, Symbol &Target, Edge::AddendT Addend)
Add an edge to this block.
void setMutableContent(MutableArrayRef< char > MutableContent)
Set mutable content for this block.
MutableArrayRef< char > getMutableContent(LinkGraph &G)
Get mutable content for this block.
void setContent(ArrayRef< char > Content)
Set the content for this block.
orc::ExecutorAddrRange getRange() const
Returns the address range of this defined addressable.
Section & getSection() const
Return the parent section for this block.
size_t getSize() const
Returns the size of this defined addressable.
void setAlignment(uint64_t Alignment)
Set the alignment for this content.
Block & operator=(const Block &)=delete
void setAlignmentOffset(uint64_t AlignmentOffset)
Set the alignment offset for this content.
iterator_range< edge_iterator > edges()
Return the list of edges attached to this content.
MutableArrayRef< char > getAlreadyMutableContent()
Get mutable content for this block.
orc::ExecutorAddr getFixupAddress(const Edge &E) const
Returns the address of the fixup for the given edge, which is equal to this block's address plus the ...
auto edges_at(Edge::OffsetT O)
Returns an iterator over all edges at the given offset within the block.
EdgeVector::iterator edge_iterator
EdgeVector::const_iterator const_edge_iterator
std::vector< Edge > EdgeVector
bool edges_empty() const
Returns true if the list of edges is empty.
Represents fixups and constraints in the LinkGraph.
Symbol & getTarget() const
Kind getRelocation() const
AddendT getAddend() const
bool isRelocation() const
OffsetT getOffset() const
void setTarget(Symbol &Target)
Edge(Kind K, OffsetT Offset, Symbol &Target, AddendT Addend)
void setAddend(AddendT Addend)
void setOffset(OffsetT Offset)
A function object to call with a resolved symbol map (See AsyncLookupResult) or an error if resolutio...
virtual ~JITLinkAsyncLookupContinuation()=default
virtual void run(Expected< AsyncLookupResult > LR)=0
Holds context for a single jitLink invocation.
virtual void notifyFinalized(JITLinkMemoryManager::FinalizedAlloc Alloc)=0
Called by JITLink to notify the context that the object has been finalized (i.e.
JITLinkContext(const JITLinkDylib *JD)
Create a JITLinkContext.
virtual ~JITLinkContext()
Destroy a JITLinkContext.
virtual Error modifyPassConfig(LinkGraph &G, PassConfiguration &Config)
Called by JITLink to modify the pass pipeline prior to linking.
const JITLinkDylib * getJITLinkDylib() const
Return the JITLinkDylib that this link is targeting, if any.
virtual void notifyFailed(Error Err)=0
Notify this context that linking failed.
virtual JITLinkMemoryManager & getMemoryManager()=0
Return the MemoryManager to be used for this link.
virtual void lookup(const LookupMap &Symbols, std::unique_ptr< JITLinkAsyncLookupContinuation > LC)=0
Called by JITLink to resolve external symbols.
virtual Error notifyResolved(LinkGraph &G)=0
Called by JITLink once all defined symbols in the graph have been assigned their final memory locatio...
virtual bool shouldAddDefaultTargetPasses(const Triple &TT) const
Called by JITLink prior to linking to determine whether default passes for the target should be added...
virtual LinkGraphPassFunction getMarkLivePass(const Triple &TT) const
Returns the mark-live pass to be used for this link.
Base class for errors originating in JIT linker, e.g.
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
JITLinkError(Twine ErrMsg)
const std::string & getErrorMessage() const
void log(raw_ostream &OS) const override
Print an error message to an output stream.
Represents a finalized allocation.
Manages allocations of JIT memory.
bool operator==(const nested_collection_iterator &RHS) const
nested_collection_iterator(OuterItrT OuterI, OuterItrT OuterE)
nested_collection_iterator()=default
nested_collection_iterator operator++()
Symbol * findExternalSymbolByName(const orc::SymbolStringPtrBase &Name)
Returns the external symbol with the given name if one exists, otherwise returns nullptr.
MutableArrayRef< char > allocateCString(Twine Source)
Allocate a copy of the given string using the LinkGraph's allocator.
void makeAbsolute(Symbol &Sym, orc::ExecutorAddr Address)
Make the given symbol an absolute with the given address (must not already be absolute).
orc::SymbolStringPtr intern(StringRef SymbolName)
Intern the given string in the LinkGraph's SymbolStringPool.
void mergeSections(Section &DstSection, Section &SrcSection, bool PreserveSrcSection=false)
Move all blocks and symbols from the source section to the destination section.
Symbol & addDefinedSymbol(Block &Content, orc::ExecutorAddrDiff Offset, StringRef Name, orc::ExecutorAddrDiff Size, Linkage L, Scope S, bool IsCallable, bool IsLive)
Add a named symbol.
void removeExternalSymbol(Symbol &Sym)
Removes an external symbol. Also removes the underlying Addressable.
Block & createContentBlock(Section &Parent, ArrayRef< char > Content, orc::ExecutorAddr Address, uint64_t Alignment, uint64_t AlignmentOffset)
Create a content block.
void removeDefinedSymbol(Symbol &Sym)
Removes defined symbols. Does not remove the underlying block.
MutableArrayRef< char > allocateContent(ArrayRef< char > Source)
Allocate a copy of the given string using the LinkGraph's allocator.
BinaryStreamWriter getBlockContentWriter(Block &B)
Returns a BinaryStreamWriter for the given block.
std::optional< SmallVector< Symbol *, 8 > > SplitBlockCache
Cache type for the splitBlock function.
const std::string & getName() const
Returns the name of this graph (usually the name of the original underlying MemoryBuffer).
mapped_iterator< SectionMap::iterator, GetSectionMapEntryValue > section_iterator
iterator_range< absolute_symbol_iterator > absolute_symbols()
Symbol & addExternalSymbol(orc::SymbolStringPtr Name, orc::ExecutorAddrDiff Size, bool IsWeaklyReferenced)
Add an external symbol.
size_t sections_size() const
nested_collection_iterator< section_iterator, Section::block_iterator, Block *, getSectionBlocks > block_iterator
void removeAbsoluteSymbol(Symbol &Sym)
Remove an absolute symbol. Also removes the underlying Addressable.
StringRef allocateName(Twine Source)
Allocate a copy of the given string using the LinkGraph's allocator and return it as a StringRef.
MutableArrayRef< char > allocateCString(StringRef Source)
Allocate a copy of the given string using the LinkGraph's allocator.
Symbol & addDefinedSymbol(Block &Content, orc::ExecutorAddrDiff Offset, orc::SymbolStringPtr Name, orc::ExecutorAddrDiff Size, Linkage L, Scope S, bool IsCallable, bool IsLive)
const SubtargetFeatures & getFeatures() const
Return the subtarget features for this Graph.
void removeSection(Section &Sec)
Remove a section.
void makeExternal(Symbol &Sym)
Make the given symbol external (must not already be external).
LinkGraph(LinkGraph &&)=delete
Symbol & addAbsoluteSymbol(StringRef Name, orc::ExecutorAddr Address, orc::ExecutorAddrDiff Size, Linkage L, Scope S, bool IsLive)
Block & createZeroFillBlock(Section &Parent, orc::ExecutorAddrDiff Size, orc::ExecutorAddr Address, uint64_t Alignment, uint64_t AlignmentOffset)
Create a zero-fill block.
orc::shared::AllocActions & allocActions()
Accessor for the AllocActions object for this graph.
mapped_iterator< SectionMap::const_iterator, GetSectionMapEntryConstValue > const_section_iterator
void dump(raw_ostream &OS)
Dump the graph.
MutableArrayRef< char > allocateContent(Twine Source)
Allocate a copy of the given string using the LinkGraph's allocator.
iterator_range< const_defined_symbol_iterator > defined_symbols() const
void removeBlock(Block &B)
Remove a block.
LinkGraph(std::string Name, std::shared_ptr< orc::SymbolStringPool > SSP, Triple TT, SubtargetFeatures Features, GetEdgeKindNameFunction GetEdgeKindName)
iterator_range< const_section_iterator > sections() const
std::vector< Block * > splitBlock(Block &B, SplitOffsetRange &&SplitOffsets, LinkGraph::SplitBlockCache *Cache=nullptr)
Splits block B into a sequence of smaller blocks.
LinkGraph & operator=(const LinkGraph &)=delete
iterator_range< external_symbol_iterator > external_symbols()
nested_collection_iterator< section_iterator, Section::symbol_iterator, Symbol *, getSectionSymbols > defined_symbol_iterator
Block & createMutableContentBlock(Section &Parent, MutableArrayRef< char > MutableContent, orc::ExecutorAddr Address, uint64_t Alignment, uint64_t AlignmentOffset)
Create a content block with initially mutable data.
unsigned getPointerSize() const
Returns the pointer size for use in this graph.
LinkGraph(const LinkGraph &)=delete
Symbol & addExternalSymbol(StringRef Name, orc::ExecutorAddrDiff Size, bool IsWeaklyReferenced)
iterator_range< block_iterator > blocks()
const char *(*)(Edge::Kind) GetEdgeKindNameFunction
void makeDefined(Symbol &Sym, Block &Content, orc::ExecutorAddrDiff Offset, orc::ExecutorAddrDiff Size, Linkage L, Scope S, bool IsLive)
Turn an absolute or external symbol into a defined one by attaching it to a block.
std::shared_ptr< orc::SymbolStringPool > getSymbolStringPool()
Section * findSectionByName(StringRef Name)
Returns the section with the given name if it exists, otherwise returns null.
Block & createMutableContentBlock(Section &Parent, size_t ContentSize, orc::ExecutorAddr Address, uint64_t Alignment, uint64_t AlignmentOffset, bool ZeroInitialize=true)
Create a content block with initially mutable data of the given size.
iterator_range< section_iterator > sections()
Symbol * findAbsoluteSymbolByName(const orc::SymbolStringPtrBase &Name)
nested_collection_iterator< const_section_iterator, Section::const_block_iterator, const Block *, getSectionConstBlocks > const_block_iterator
Symbol & addAbsoluteSymbol(orc::SymbolStringPtr Name, orc::ExecutorAddr Address, orc::ExecutorAddrDiff Size, Linkage L, Scope S, bool IsLive)
Add an absolute symbol.
void transferBlock(Block &B, Section &NewSection)
Transfers the given Block and all Symbols pointing to it to the given Section.
mapped_iterator< ExternalSymbolMap::iterator, GetExternalSymbolMapEntryValue > external_symbol_iterator
const Triple & getTargetTriple() const
Returns the target triple for this Graph.
nested_collection_iterator< const_section_iterator, Section::const_symbol_iterator, const Symbol *, getSectionConstSymbols > const_defined_symbol_iterator
iterator_range< const_block_iterator > blocks() const
Symbol & addAnonymousSymbol(Block &Content, orc::ExecutorAddrDiff Offset, orc::ExecutorAddrDiff Size, bool IsCallable, bool IsLive)
Add an anonymous symbol.
const char * getEdgeKindName(Edge::Kind K) const
Section & createSection(StringRef Name, orc::MemProt Prot)
Create a section with the given name, protection flags.
LinkGraph & operator=(LinkGraph &&)=delete
BinaryStreamReader getBlockContentReader(Block &B)
Returns a BinaryStreamReader for the given block.
MutableArrayRef< char > allocateBuffer(size_t Size)
Allocate a mutable buffer of the given size using the LinkGraph's allocator.
Symbol * findDefinedSymbolByName(const orc::SymbolStringPtrBase &Name)
Returns the defined symbol with the given name if one exists, otherwise returns nullptr.
llvm::endianness getEndianness() const
Returns the endianness of content in this graph.
iterator_range< defined_symbol_iterator > defined_symbols()
void transferDefinedSymbol(Symbol &Sym, Block &DestBlock, orc::ExecutorAddrDiff NewOffset, std::optional< orc::ExecutorAddrDiff > ExplicitNewSize)
Transfer a defined symbol from one block to another.
Represents a section address range via a pair of Block pointers to the first and last Blocks in the s...
Block * getFirstBlock() const
orc::ExecutorAddrRange getRange() const
orc::ExecutorAddr getEnd() const
orc::ExecutorAddrDiff getSize() const
orc::ExecutorAddr getStart() const
SectionRange(const Section &Sec)
Block * getLastBlock() const
Represents an object file section.
iterator_range< symbol_iterator > symbols()
Returns an iterator over the symbols defined in this section.
Section & operator=(const Section &)=delete
Section(const Section &)=delete
StringRef getName() const
Returns the name of this section.
SymbolSet::const_iterator const_symbol_iterator
SymbolSet::iterator symbol_iterator
SectionOrdinal getOrdinal() const
Returns the ordinal for this section.
BlockSet::const_iterator const_block_iterator
BlockSet::iterator block_iterator
iterator_range< block_iterator > blocks()
Returns an iterator over the blocks defined in this section.
orc::MemProt getMemProt() const
Returns the protection flags for this section.
iterator_range< const_symbol_iterator > symbols() const
Returns an iterator over the symbols defined in this section.
bool empty() const
Returns true if this section is empty (contains no blocks or symbols).
SymbolSet::size_type symbols_size() const
Return the number of symbols in this section.
iterator_range< const_block_iterator > blocks() const
Returns an iterator over the blocks defined in this section.
BlockSet::size_type blocks_size() const
Returns the number of blocks in this section.
void setMemProt(orc::MemProt Prot)
Set the protection flags for this section.
Section(Section &&)=delete
Section & operator=(Section &&)=delete
void setOrdinal(SectionOrdinal SecOrdinal)
Set the ordinal for this section.
void setMemLifetime(orc::MemLifetime ML)
Set the memory lifetime policy for this section.
orc::MemLifetime getMemLifetime() const
Get the memory lifetime policy for this section.
A map of addresses to Symbols.
const SymbolVector * getSymbolsAt(orc::ExecutorAddr Addr) const
Returns the list of symbols that start at the given address, or nullptr if no such symbols exist.
void addSymbols(SymbolPtrCollection &&Symbols)
Add all symbols in a given range to the SymbolAddressMap.
void addSymbol(Symbol &Sym)
Add a symbol to the SymbolAddressMap.
bool isExternal() const
Returns true if the underlying addressable is an unresolved external.
Symbol & operator=(Symbol &&)=delete
bool isCallable() const
Returns true is this symbol is callable.
void setScope(Scope S)
Set the visibility for this Symbol.
Symbol()=default
Create a null Symbol.
void setName(const orc::SymbolStringPtr Name)
Rename this symbol.
TargetFlagsType getTargetFlags() const
Get the target flags of this Symbol.
bool isLive() const
Returns true if this symbol is live (i.e.
const orc::SymbolStringPtr & getName() const
Returns the name of this symbol (empty if the symbol is anonymous).
bool isDefined() const
Returns true if this Symbol has content (potentially) defined within this object file (i....
Scope getScope() const
Get the visibility for this Symbol.
bool isAbsolute() const
Returns true if the underlying addressable is an absolute symbol.
const Block & getBlock() const
Return the Block for this Symbol (Symbol must be defined).
Addressable & getAddressable()
Return the addressable that this symbol points to.
Linkage getLinkage() const
Get the linkage for this Symbol.
void setTargetFlags(TargetFlagsType Flags)
Set the target flags for this Symbol.
orc::ExecutorAddrRange getRange() const
Returns the address range of this symbol.
orc::ExecutorAddr getAddress() const
Returns the address of this symbol.
ArrayRef< char > getSymbolContent() const
Returns the content in the underlying block covered by this symbol.
Symbol & operator=(const Symbol &)=delete
void setLive(bool IsLive)
Set this symbol's live bit.
void setLinkage(Linkage L)
Set the linkage for this Symbol.
Block & getBlock()
Return the Block for this Symbol (Symbol must be defined).
orc::ExecutorAddrDiff getSize() const
Returns the size of this symbol.
bool isSymbolZeroFill() const
Returns true if this symbol is backed by a zero-fill block.
orc::ExecutorAddrDiff getOffset() const
Returns the offset for this symbol within the underlying addressable.
void setOffset(orc::ExecutorAddrDiff NewOffset)
Symbol(const Symbol &)=delete
void setSize(orc::ExecutorAddrDiff Size)
Set the size of this symbol.
void setWeaklyReferenced(bool WeakRef)
Set the WeaklyReferenced value for this symbol.
const Addressable & getAddressable() const
Return the addressable that this symbol points to.
void setCallable(bool IsCallable)
Set this symbol's callable bit.
bool isWeaklyReferenced() const
Returns true if this is a weakly referenced external symbol.
bool hasName() const
Returns true if this symbol has a name.
Represents an address in the executor process.
uint64_t getValue() const
Base class for both owning and non-owning symbol-string ptrs.
Pointer to a pooled string representing a symbol name.
This class implements an extremely fast bulk output stream that can only output to a stream.
unique_function is a type-erasing functor similar to std::function.
@ C
The default llvm calling convention, compatible with C.
Error makeTargetOutOfRangeError(const LinkGraph &G, const Block &B, const Edge &E)
Create an out of range error for the given edge in the given block.
std::unique_ptr< JITLinkAsyncLookupContinuation > createLookupContinuation(Continuation Cont)
Create a lookup continuation from a function object.
const char * getGenericEdgeKindName(Edge::Kind K)
Returns the string name of the given generic edge kind, or "unknown" otherwise.
const char * getLinkageName(Linkage L)
For errors and debugging output.
SymbolLookupFlags
Flags for symbol lookup.
std::unique_ptr< LinkGraph > absoluteSymbolsLinkGraph(Triple TT, std::shared_ptr< orc::SymbolStringPool > SSP, orc::SymbolMap Symbols)
Create a LinkGraph defining the given absolute symbols.
uint64_t alignToBlock(uint64_t Addr, const Block &B)
Error makeAlignmentError(llvm::orc::ExecutorAddr Loc, uint64_t Value, int N, const Edge &E)
raw_ostream & operator<<(raw_ostream &OS, const Block &B)
PointerJumpStubCreator getPointerJumpStubCreator(const Triple &TT)
Get target-specific PointerJumpStubCreator.
void link(std::unique_ptr< LinkGraph > G, std::unique_ptr< JITLinkContext > Ctx)
Link the given graph.
void visitExistingEdges(LinkGraph &G, VisitorTs &&...Vs)
For each edge in the given graph, apply a list of visitors to the edge, stopping when the first visit...
Error markAllSymbolsLive(LinkGraph &G)
Marks all symbols in a graph live.
const char * getScopeName(Scope S)
For debugging output.
Expected< std::unique_ptr< LinkGraph > > createLinkGraphFromObject(MemoryBufferRef ObjectBuffer, std::shared_ptr< orc::SymbolStringPool > SSP)
Create a LinkGraph from the given object buffer.
Linkage
Describes symbol linkage. This can be used to resolve definition clashes.
void printEdge(raw_ostream &OS, const Block &B, const Edge &E, StringRef EdgeKindName)
Scope
Defines the scope in which this symbol should be visible: Default – Visible in the public interface o...
bool isCStringBlock(Block &B)
void visitEdge(LinkGraph &G, Block *B, Edge &E)
Base case for edge-visitors where the visitor-list is empty.
std::vector< LinkGraphPassFunction > LinkGraphPassList
A list of LinkGraph passes.
AnonymousPointerCreator getAnonymousPointerCreator(const Triple &TT)
Get target-specific AnonymousPointerCreator.
std::vector< AllocActionCallPair > AllocActions
A vector of allocation actions to be run for this allocation.
MemProt
Describes Read/Write/Exec permissions for memory.
uint64_t ExecutorAddrDiff
MemLifetime
Describes a memory lifetime policy for memory to be allocated by a JITLinkMemoryManager.
@ Standard
Standard memory should be allocated by the allocator and then deallocated when the deallocate method ...
This is an optimization pass for GlobalISel generic memory operations.
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
bool none_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::none_of which take ranges instead of having to pass begin/end explicitly.
iterator_range< filter_iterator< detail::IterOfRange< RangeT >, PredicateT > > make_filter_range(RangeT &&Range, PredicateT Pred)
Convenience function that takes a range of elements and a predicate, and return a new filter_iterator...
BumpPtrAllocatorImpl BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
OutputIt copy(R &&Range, OutputIt Out)
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
auto count_if(R &&Range, UnaryPredicate P)
Wrapper function around std::count_if to count the number of times an element satisfying a given pred...
Implement std::hash so that hash_code can be used in STL containers.
An LinkGraph pass configuration, consisting of a list of pre-prune, post-prune, and post-fixup passes...
LinkGraphPassList PostAllocationPasses
Post-allocation passes.
LinkGraphPassList PreFixupPasses
Pre-fixup passes.
LinkGraphPassList PostFixupPasses
Post-fixup passes.
LinkGraphPassList PostPrunePasses
Post-prune passes.
LinkGraphPassList PrePrunePasses
Pre-prune passes.
Represents an address range in the exceutor process.