13 #ifndef LIB_EXECUTIONENGINE_JITLINK_JITLINKGENERIC_H 14 #define LIB_EXECUTIONENGINE_JITLINK_JITLINKGENERIC_H 19 #define DEBUG_TYPE "jitlink" 23 class MemoryBufferRef;
36 : Ctx(
std::move(Ctx)), Passes(
std::move(Passes)) {
37 assert(this->Ctx &&
"Ctx can not be null");
60 void linkPhase1(std::unique_ptr<JITLinkerBase> Self);
67 void linkPhase2(std::unique_ptr<JITLinkerBase> Self,
91 uint64_t PAddr =
static_cast<uint64_t
>(
reinterpret_cast<uintptr_t
>(
P));
111 void deallocateAndBailOut(
Error Err);
115 std::unique_ptr<JITLinkContext> Ctx;
117 std::unique_ptr<LinkGraph>
G;
118 std::unique_ptr<JITLinkMemoryManager::Allocation> Alloc;
128 template <
typename... ArgTs>
static void link(ArgTs &&...
Args) {
129 auto L = std::make_unique<LinkerImpl>(std::forward<ArgTs>(
Args)...);
139 LTmp.linkPhase1(std::move(L));
143 const LinkerImpl &
impl()
const {
144 return static_cast<const LinkerImpl &
>(*this);
151 for (
auto &KV : Layout) {
152 auto &Prot = KV.first;
153 auto &SegLayout = KV.second;
156 static_cast<sys::Memory::ProtectionFlags>(Prot));
157 char *LastBlockEnd = SegMem.data();
158 char *BlockDataPtr = LastBlockEnd;
161 dbgs() <<
" Processing segment " 163 << (
const void *)SegMem.data() <<
" .. " 164 << (
const void *)((
char *)SegMem.data() + SegMem.size())
165 <<
" ]\n Processing content sections:\n";
168 for (
auto *
B : SegLayout.ContentBlocks) {
175 dbgs() <<
" Bumped block pointer to " 176 << (
const void *)BlockDataPtr <<
" to meet block alignment " 177 <<
B->getAlignment() <<
" and alignment offset " 178 <<
B->getAlignmentOffset() <<
"\n";
183 if (LastBlockEnd != BlockDataPtr)
184 dbgs() <<
" Zero padding from " << (
const void *)LastBlockEnd
185 <<
" to " << (
const void *)BlockDataPtr <<
"\n";
188 while (LastBlockEnd != BlockDataPtr)
193 dbgs() <<
" Copying block " << *
B <<
" content, " 194 <<
B->getContent().size() <<
" bytes, from " 195 << (
const void *)
B->getContent().data() <<
" to " 196 << (
const void *)BlockDataPtr <<
"\n";
198 memcpy(BlockDataPtr,
B->getContent().data(),
B->getContent().size());
202 for (
auto &
E :
B->edges()) {
205 if (!
E.isRelocation())
209 if (
auto Err =
impl().applyFixup(*
B,
E, BlockDataPtr))
214 B->setContent(
StringRef(BlockDataPtr,
B->getContent().size()));
217 LastBlockEnd = BlockDataPtr +
B->getContent().size();
218 BlockDataPtr = LastBlockEnd;
223 dbgs() <<
" Zero padding end of segment from " 224 << (
const void *)LastBlockEnd <<
" to " 225 << (
const void *)((
char *)SegMem.data() + SegMem.size()) <<
"\n";
227 while (LastBlockEnd != SegMem.data() + SegMem.size())
245 #undef DEBUG_TYPE // "jitlink" 247 #endif // LLVM_EXECUTIONENGINE_JITLINK_JITLINKGENERIC_H std::vector< Block * > BlocksList
static JITTargetAddress alignToBlock(JITTargetAddress Addr, Block &B)
This class represents lattice values for constants.
uint64_t getAlignment() const
Get the alignment for this content.
An Addressable with content and edges.
virtual MutableArrayRef< char > getWorkingMemory(ProtectionFlags Seg)=0
Should return the address of linker working memory for the segment with the given protection flags...
void linkPhase3(std::unique_ptr< JITLinkerBase > Self, Error Err)
Tagged union holding either a T or a Error.
place backedge safepoints impl
uint64_t JITTargetAddress
Represents an address in the target process's address space.
void prune(LinkGraph &G)
Removes dead symbols/blocks/addressables.
Base class for a JIT linker.
static void link(ArgTs &&... Args)
Link constructs a LinkerImpl instance and calls linkPhase1.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
virtual Expected< std::unique_ptr< LinkGraph > > buildGraph(MemoryBufferRef ObjBuffer)=0
static ErrorSuccess success()
Create a success value.
BlocksList ZeroFillBlocks
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static char * alignToBlock(char *P, Block &B)
JITLinkerBase(std::unique_ptr< JITLinkContext > Ctx, PassConfiguration Passes)
std::vector< LinkGraphPassFunction > LinkGraphPassList
A list of LinkGraph passes.
void linkPhase1(std::unique_ptr< JITLinkerBase > Self)
Represents an allocation created by the memory manager.
virtual StringRef getEdgeKindName(Edge::Kind K) const =0
An LinkGraph pass configuration, consisting of a list of pre-prune, post-prune, and post-fixup passes...
uint64_t getAlignmentOffset() const
Get the alignment offset for this content.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Lightweight error class with error context and mandatory checking.
This class implements an extremely fast bulk output stream that can only output to a stream...
StringRef - Represent a constant reference to a string, i.e.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
void linkPhase2(std::unique_ptr< JITLinkerBase > Self, Expected< AsyncLookupResult > LookupResult, SegmentLayoutMap Layout)