LLVM 22.0.0git
IndirectionUtils.h
Go to the documentation of this file.
1//===- IndirectionUtils.h - Utilities for adding indirections ---*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// Contains utilities for adding indirections and breaking up modules.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_EXECUTIONENGINE_ORC_INDIRECTIONUTILS_H
14#define LLVM_EXECUTIONENGINE_ORC_INDIRECTIONUTILS_H
15
16#include "llvm/ADT/StringMap.h"
17#include "llvm/ADT/StringRef.h"
23#include "llvm/Support/Error.h"
24#include "llvm/Support/Memory.h"
27#include <algorithm>
28#include <cassert>
29#include <cstdint>
30#include <functional>
31#include <future>
32#include <map>
33#include <memory>
34#include <system_error>
35#include <utility>
36#include <vector>
37
38namespace llvm {
39
40class Constant;
41class Function;
42class FunctionType;
43class GlobalAlias;
44class GlobalVariable;
45class Module;
46class PointerType;
47class Triple;
48class Twine;
49class Value;
50class MCDisassembler;
51class MCInstrAnalysis;
52
53namespace jitlink {
54class LinkGraph;
55class Symbol;
56} // namespace jitlink
57
58namespace orc {
59
60/// Base class for pools of compiler re-entry trampolines.
61/// These trampolines are callable addresses that save all register state
62/// before calling a supplied function to return the trampoline landing
63/// address, then restore all state before jumping to that address. They
64/// are used by various ORC APIs to support lazy compilation
66public:
68 unique_function<void(ExecutorAddr) const>;
69
71 ExecutorAddr TrampolineAddr,
72 NotifyLandingResolvedFunction OnLandingResolved) const>;
73
74 virtual ~TrampolinePool();
75
76 /// Get an available trampoline address.
77 /// Returns an error if no trampoline can be created.
79 std::lock_guard<std::mutex> Lock(TPMutex);
80 if (AvailableTrampolines.empty()) {
81 if (auto Err = grow())
82 return std::move(Err);
83 }
84 assert(!AvailableTrampolines.empty() && "Failed to grow trampoline pool");
85 auto TrampolineAddr = AvailableTrampolines.back();
86 AvailableTrampolines.pop_back();
87 return TrampolineAddr;
88 }
89
90 /// Returns the given trampoline to the pool for re-use.
91 void releaseTrampoline(ExecutorAddr TrampolineAddr) {
92 std::lock_guard<std::mutex> Lock(TPMutex);
93 AvailableTrampolines.push_back(TrampolineAddr);
94 }
95
96protected:
97 virtual Error grow() = 0;
98
99 std::mutex TPMutex;
100 std::vector<ExecutorAddr> AvailableTrampolines;
101};
102
103/// A trampoline pool for trampolines within the current process.
104template <typename ORCABI> class LocalTrampolinePool : public TrampolinePool {
105public:
106 /// Creates a LocalTrampolinePool with the given RunCallback function.
107 /// Returns an error if this function is unable to correctly allocate, write
108 /// and protect the resolver code block.
111 Error Err = Error::success();
112
113 auto LTP = std::unique_ptr<LocalTrampolinePool>(
114 new LocalTrampolinePool(std::move(ResolveLanding), Err));
115
116 if (Err)
117 return std::move(Err);
118 return std::move(LTP);
119 }
120
121private:
122 static JITTargetAddress reenter(void *TrampolinePoolPtr, void *TrampolineId) {
124 static_cast<LocalTrampolinePool *>(TrampolinePoolPtr);
125
126 std::promise<ExecutorAddr> LandingAddressP;
127 auto LandingAddressF = LandingAddressP.get_future();
128
129 TrampolinePool->ResolveLanding(ExecutorAddr::fromPtr(TrampolineId),
130 [&](ExecutorAddr LandingAddress) {
131 LandingAddressP.set_value(LandingAddress);
132 });
133 return LandingAddressF.get().getValue();
134 }
135
136 LocalTrampolinePool(ResolveLandingFunction ResolveLanding, Error &Err)
137 : ResolveLanding(std::move(ResolveLanding)) {
138
139 ErrorAsOutParameter _(Err);
140
141 /// Try to set up the resolver block.
142 std::error_code EC;
143 ResolverBlock = sys::OwningMemoryBlock(sys::Memory::allocateMappedMemory(
144 ORCABI::ResolverCodeSize, nullptr,
146 if (EC) {
147 Err = errorCodeToError(EC);
148 return;
149 }
150
151 ORCABI::writeResolverCode(static_cast<char *>(ResolverBlock.base()),
152 ExecutorAddr::fromPtr(ResolverBlock.base()),
153 ExecutorAddr::fromPtr(&reenter),
155
159 if (EC) {
160 Err = errorCodeToError(EC);
161 return;
162 }
163 }
164
165 Error grow() override {
166 assert(AvailableTrampolines.empty() && "Growing prematurely?");
167
168 std::error_code EC;
169 auto TrampolineBlock =
170 sys::OwningMemoryBlock(sys::Memory::allocateMappedMemory(
173 if (EC)
174 return errorCodeToError(EC);
175
176 unsigned NumTrampolines =
177 (sys::Process::getPageSizeEstimate() - ORCABI::PointerSize) /
178 ORCABI::TrampolineSize;
179
180 char *TrampolineMem = static_cast<char *>(TrampolineBlock.base());
181 ORCABI::writeTrampolines(
182 TrampolineMem, ExecutorAddr::fromPtr(TrampolineMem),
183 ExecutorAddr::fromPtr(ResolverBlock.base()), NumTrampolines);
184
185 for (unsigned I = 0; I < NumTrampolines; ++I)
186 AvailableTrampolines.push_back(
187 ExecutorAddr::fromPtr(TrampolineMem + (I * ORCABI::TrampolineSize)));
188
190 TrampolineBlock.getMemoryBlock(),
192 return errorCodeToError(EC);
193
194 TrampolineBlocks.push_back(std::move(TrampolineBlock));
195 return Error::success();
196 }
197
198 ResolveLandingFunction ResolveLanding;
199
200 sys::OwningMemoryBlock ResolverBlock;
201 std::vector<sys::OwningMemoryBlock> TrampolineBlocks;
202};
203
204/// Target-independent base class for compile callback management.
206public:
207 using CompileFunction = std::function<ExecutorAddr()>;
208
209 virtual ~JITCompileCallbackManager() = default;
210
211 /// Reserve a compile callback.
213
214 /// Execute the callback for the given trampoline id. Called by the JIT
215 /// to compile functions on demand.
217
218protected:
219 /// Construct a JITCompileCallbackManager.
220 JITCompileCallbackManager(std::unique_ptr<TrampolinePool> TP,
222 ExecutorAddr ErrorHandlerAddress)
223 : TP(std::move(TP)), ES(ES),
224 CallbacksJD(ES.createBareJITDylib("<Callbacks>")),
225 ErrorHandlerAddress(ErrorHandlerAddress) {}
226
227 void setTrampolinePool(std::unique_ptr<TrampolinePool> TP) {
228 this->TP = std::move(TP);
229 }
230
231private:
232 std::mutex CCMgrMutex;
233 std::unique_ptr<TrampolinePool> TP;
235 JITDylib &CallbacksJD;
236 ExecutorAddr ErrorHandlerAddress;
237 std::map<ExecutorAddr, SymbolStringPtr> AddrToSymbol;
238 size_t NextCallbackId = 0;
239};
240
241/// Manage compile callbacks for in-process JITs.
242template <typename ORCABI>
244public:
245 /// Create a new LocalJITCompileCallbackManager.
247 Create(ExecutionSession &ES, ExecutorAddr ErrorHandlerAddress) {
248 Error Err = Error::success();
249 auto CCMgr = std::unique_ptr<LocalJITCompileCallbackManager>(
250 new LocalJITCompileCallbackManager(ES, ErrorHandlerAddress, Err));
251 if (Err)
252 return std::move(Err);
253 return std::move(CCMgr);
254 }
255
256private:
257 /// Construct a InProcessJITCompileCallbackManager.
258 /// @param ErrorHandlerAddress The address of an error handler in the target
259 /// process to be used if a compile callback fails.
261 ExecutorAddr ErrorHandlerAddress, Error &Err)
262 : JITCompileCallbackManager(nullptr, ES, ErrorHandlerAddress) {
263 using NotifyLandingResolvedFunction =
265
268 [this](ExecutorAddr TrampolineAddr,
269 NotifyLandingResolvedFunction NotifyLandingResolved) {
270 NotifyLandingResolved(executeCompileCallback(TrampolineAddr));
271 });
272
273 if (!TP) {
274 Err = TP.takeError();
275 return;
276 }
277
278 setTrampolinePool(std::move(*TP));
279 }
280};
281
282/// Base class for managing collections of named indirect stubs.
284public:
285 /// Map type for initializing the manager. See init.
287
288 virtual ~IndirectStubsManager() = default;
289
290 /// Create a single stub with the given name, target address and flags.
291 virtual Error createStub(StringRef StubName, ExecutorAddr StubAddr,
292 JITSymbolFlags StubFlags) = 0;
293
294 /// Create StubInits.size() stubs with the given names, target
295 /// addresses, and flags.
296 virtual Error createStubs(const StubInitsMap &StubInits) = 0;
297
298 /// Find the stub with the given name. If ExportedStubsOnly is true,
299 /// this will only return a result if the stub's flags indicate that it
300 /// is exported.
302 bool ExportedStubsOnly) = 0;
303
304 /// Find the implementation-pointer for the stub.
306
307 /// Change the value of the implementation pointer for the stub.
309
310 /// --- RedirectableSymbolManager implementation ---
311 Error redirect(JITDylib &JD, const SymbolMap &NewDests) override;
312
313 void
314 emitRedirectableSymbols(std::unique_ptr<MaterializationResponsibility> MR,
315 SymbolMap InitialDests) override;
316
317private:
318 void anchor() override;
319};
320
321template <typename ORCABI> class LocalIndirectStubsInfo {
322public:
324 : NumStubs(NumStubs), StubsMem(std::move(StubsMem)) {}
325
326 static Expected<LocalIndirectStubsInfo> create(unsigned MinStubs,
327 unsigned PageSize) {
328 auto ISAS = getIndirectStubsBlockSizes<ORCABI>(MinStubs, PageSize);
329
330 assert((ISAS.StubBytes % PageSize == 0) &&
331 "StubBytes is not a page size multiple");
332 uint64_t PointerAlloc = alignTo(ISAS.PointerBytes, PageSize);
333
334 // Allocate memory for stubs and pointers in one call.
335 std::error_code EC;
336 auto StubsAndPtrsMem =
338 ISAS.StubBytes + PointerAlloc, nullptr,
340 if (EC)
341 return errorCodeToError(EC);
342
343 sys::MemoryBlock StubsBlock(StubsAndPtrsMem.base(), ISAS.StubBytes);
344 auto StubsBlockMem = static_cast<char *>(StubsAndPtrsMem.base());
345 auto PtrBlockAddress =
346 ExecutorAddr::fromPtr(StubsBlockMem) + ISAS.StubBytes;
347
348 ORCABI::writeIndirectStubsBlock(StubsBlockMem,
349 ExecutorAddr::fromPtr(StubsBlockMem),
350 PtrBlockAddress, ISAS.NumStubs);
351
354 return errorCodeToError(EC);
355
356 return LocalIndirectStubsInfo(ISAS.NumStubs, std::move(StubsAndPtrsMem));
357 }
358
359 unsigned getNumStubs() const { return NumStubs; }
360
361 void *getStub(unsigned Idx) const {
362 return static_cast<char *>(StubsMem.base()) + Idx * ORCABI::StubSize;
363 }
364
365 void **getPtr(unsigned Idx) const {
366 char *PtrsBase =
367 static_cast<char *>(StubsMem.base()) + NumStubs * ORCABI::StubSize;
368 return reinterpret_cast<void **>(PtrsBase) + Idx;
369 }
370
371private:
372 unsigned NumStubs = 0;
373 sys::OwningMemoryBlock StubsMem;
374};
375
376/// IndirectStubsManager implementation for the host architecture, e.g.
377/// OrcX86_64. (See OrcArchitectureSupport.h).
378template <typename TargetT>
380public:
382 JITSymbolFlags StubFlags) override {
383 std::lock_guard<std::mutex> Lock(StubsMutex);
384 if (auto Err = reserveStubs(1))
385 return Err;
386
387 createStubInternal(StubName, StubAddr, StubFlags);
388
389 return Error::success();
390 }
391
392 Error createStubs(const StubInitsMap &StubInits) override {
393 std::lock_guard<std::mutex> Lock(StubsMutex);
394 if (auto Err = reserveStubs(StubInits.size()))
395 return Err;
396
397 for (const auto &Entry : StubInits)
398 createStubInternal(Entry.first(), Entry.second.first,
399 Entry.second.second);
400
401 return Error::success();
402 }
403
404 ExecutorSymbolDef findStub(StringRef Name, bool ExportedStubsOnly) override {
405 std::lock_guard<std::mutex> Lock(StubsMutex);
406 auto I = StubIndexes.find(Name);
407 if (I == StubIndexes.end())
408 return ExecutorSymbolDef();
409 auto Key = I->second.first;
410 void *StubPtr = IndirectStubsInfos[Key.first].getStub(Key.second);
411 assert(StubPtr && "Missing stub address");
412 auto StubAddr = ExecutorAddr::fromPtr(StubPtr);
413 auto StubSymbol = ExecutorSymbolDef(StubAddr, I->second.second);
414 if (ExportedStubsOnly && !StubSymbol.getFlags().isExported())
415 return ExecutorSymbolDef();
416 return StubSymbol;
417 }
418
420 std::lock_guard<std::mutex> Lock(StubsMutex);
421 auto I = StubIndexes.find(Name);
422 if (I == StubIndexes.end())
423 return ExecutorSymbolDef();
424 auto Key = I->second.first;
425 void *PtrPtr = IndirectStubsInfos[Key.first].getPtr(Key.second);
426 assert(PtrPtr && "Missing pointer address");
427 auto PtrAddr = ExecutorAddr::fromPtr(PtrPtr);
428 return ExecutorSymbolDef(PtrAddr, I->second.second);
429 }
430
432 using AtomicIntPtr = std::atomic<uintptr_t>;
433
434 std::lock_guard<std::mutex> Lock(StubsMutex);
435 auto I = StubIndexes.find(Name);
436 assert(I != StubIndexes.end() && "No stub pointer for symbol");
437 auto Key = I->second.first;
438 AtomicIntPtr *AtomicStubPtr = reinterpret_cast<AtomicIntPtr *>(
439 IndirectStubsInfos[Key.first].getPtr(Key.second));
440 *AtomicStubPtr = static_cast<uintptr_t>(NewAddr.getValue());
441 return Error::success();
442 }
443
444private:
445 Error reserveStubs(unsigned NumStubs) {
446 if (NumStubs <= FreeStubs.size())
447 return Error::success();
448
449 unsigned NewStubsRequired = NumStubs - FreeStubs.size();
450 unsigned NewBlockId = IndirectStubsInfos.size();
451 auto ISI =
452 LocalIndirectStubsInfo<TargetT>::create(NewStubsRequired, PageSize);
453 if (!ISI)
454 return ISI.takeError();
455 for (unsigned I = 0; I < ISI->getNumStubs(); ++I)
456 FreeStubs.push_back(std::make_pair(NewBlockId, I));
457 IndirectStubsInfos.push_back(std::move(*ISI));
458 return Error::success();
459 }
460
461 void createStubInternal(StringRef StubName, ExecutorAddr InitAddr,
462 JITSymbolFlags StubFlags) {
463 auto Key = FreeStubs.back();
464 FreeStubs.pop_back();
465 *IndirectStubsInfos[Key.first].getPtr(Key.second) =
466 InitAddr.toPtr<void *>();
467 StubIndexes[StubName] = std::make_pair(Key, StubFlags);
468 }
469
470 unsigned PageSize = sys::Process::getPageSizeEstimate();
471 std::mutex StubsMutex;
472 std::vector<LocalIndirectStubsInfo<TargetT>> IndirectStubsInfos;
473 using StubKey = std::pair<uint16_t, uint16_t>;
474 std::vector<StubKey> FreeStubs;
475 StringMap<std::pair<StubKey, JITSymbolFlags>> StubIndexes;
476};
477
478/// Create a local compile callback manager.
479///
480/// The given target triple will determine the ABI, and the given
481/// ErrorHandlerAddress will be used by the resulting compile callback
482/// manager if a compile callback fails.
483LLVM_ABI Expected<std::unique_ptr<JITCompileCallbackManager>>
484createLocalCompileCallbackManager(const Triple &T, ExecutionSession &ES,
485 ExecutorAddr ErrorHandlerAddress);
486
487/// Create a local indirect stubs manager builder.
488///
489/// The given target triple will determine the ABI.
490LLVM_ABI std::function<std::unique_ptr<IndirectStubsManager>()>
492
493/// Build a function pointer of FunctionType with the given constant
494/// address.
495///
496/// Usage example: Turn a trampoline address into a function pointer constant
497/// for use in a stub.
499
500/// Create a function pointer with the given type, name, and initializer
501/// in the given Module.
502LLVM_ABI GlobalVariable *createImplPointer(PointerType &PT, Module &M,
503 const Twine &Name,
504 Constant *Initializer);
505
506/// Turn a function declaration into a stub function that makes an
507/// indirect call using the given function pointer.
508LLVM_ABI void makeStub(Function &F, Value &ImplPointer);
509
510/// Promotes private symbols to global hidden, and renames to prevent clashes
511/// with other promoted symbols. The same SymbolPromoter instance should be
512/// used for all symbols to be added to a single JITDylib.
514public:
515 /// Promote symbols in the given module. Returns the set of global values
516 /// that have been renamed/promoted.
517 LLVM_ABI std::vector<GlobalValue *> operator()(Module &M);
518
519private:
520 unsigned NextId = 0;
521};
522
523/// Clone a function declaration into a new module.
524///
525/// This function can be used as the first step towards creating a callback
526/// stub (see makeStub).
527///
528/// If the VMap argument is non-null, a mapping will be added between F and
529/// the new declaration, and between each of F's arguments and the new
530/// declaration's arguments. This map can then be passed in to moveFunction to
531/// move the function body if required. Note: When moving functions between
532/// modules with these utilities, all decls should be cloned (and added to a
533/// single VMap) before any bodies are moved. This will ensure that references
534/// between functions all refer to the versions in the new module.
536 ValueToValueMapTy *VMap = nullptr);
537
538/// Clone a global variable declaration into a new module.
541 ValueToValueMapTy *VMap = nullptr);
542
543/// Clone a global alias declaration into a new module.
545 const GlobalAlias &OrigA,
546 ValueToValueMapTy &VMap);
547
548/// Introduce relocations to \p Sym in its own definition if there are any
549/// pointers formed via PC-relative address that do not already have a
550/// relocation.
551///
552/// This is useful when introducing indirection via a stub function at link time
553/// without compiler support. If a function pointer is formed without a
554/// relocation, e.g. in the definition of \c foo
555///
556/// \code
557/// _foo:
558/// leaq -7(%rip), rax # form pointer to _foo without relocation
559/// _bar:
560/// leaq (%rip), %rax # uses X86_64_RELOC_SIGNED to '_foo'
561/// \endcode
562///
563/// the pointer to \c _foo computed by \c _foo and \c _bar may differ if we
564/// introduce a stub for _foo. If the pointer is used as a key, this may be
565/// observable to the program. This pass will attempt to introduce the missing
566/// "self-relocation" on the leaq instruction.
567///
568/// This is based on disassembly and should be considered "best effort". It may
569/// silently fail to add relocations.
572 MCInstrAnalysis &MIA);
573
574} // end namespace orc
575
576} // end namespace llvm
577
578#endif // LLVM_EXECUTIONENGINE_ORC_INDIRECTIONUTILS_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
#define LLVM_ABI
Definition: Compiler.h:213
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
uint64_t Addr
std::string Name
Symbol * Sym
Definition: ELF_riscv.cpp:479
#define _
static cl::opt< int > PageSize("imp-null-check-page-size", cl::desc("The page size of the target in bytes"), cl::init(4096), cl::Hidden)
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
#define G(x, y, z)
Definition: MD5.cpp:56
Machine Check Debug Module
Provides a library for accessing information about this process and other processes on the operating ...
Helper for Errors used as out-parameters.
Definition: Error.h:1144
Lightweight error class with error context and mandatory checking.
Definition: Error.h:159
static ErrorSuccess success()
Create a success value.
Definition: Error.h:336
Tagged union holding either a T or a Error.
Definition: Error.h:485
Flags for symbols in the JIT.
Definition: JITSymbol.h:75
Superclass for all disassemblers.
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
unsigned size() const
Definition: StringMap.h:109
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:133
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
An ExecutionSession represents a running JIT program.
Definition: Core.h:1355
Represents an address in the executor process.
uint64_t getValue() const
static ExecutorAddr fromPtr(T *Ptr, UnwrapFn &&Unwrap=UnwrapFn())
Create an ExecutorAddr from the given pointer.
Represents a defining location for a JIT symbol.
Base class for managing collections of named indirect stubs.
virtual Error createStub(StringRef StubName, ExecutorAddr StubAddr, JITSymbolFlags StubFlags)=0
Create a single stub with the given name, target address and flags.
virtual ExecutorSymbolDef findStub(StringRef Name, bool ExportedStubsOnly)=0
Find the stub with the given name.
virtual ExecutorSymbolDef findPointer(StringRef Name)=0
Find the implementation-pointer for the stub.
virtual Error updatePointer(StringRef Name, ExecutorAddr NewAddr)=0
Change the value of the implementation pointer for the stub.
virtual ~IndirectStubsManager()=default
virtual Error createStubs(const StubInitsMap &StubInits)=0
Create StubInits.size() stubs with the given names, target addresses, and flags.
Target-independent base class for compile callback management.
JITCompileCallbackManager(std::unique_ptr< TrampolinePool > TP, ExecutionSession &ES, ExecutorAddr ErrorHandlerAddress)
Construct a JITCompileCallbackManager.
LLVM_ABI ExecutorAddr executeCompileCallback(ExecutorAddr TrampolineAddr)
Execute the callback for the given trampoline id.
virtual ~JITCompileCallbackManager()=default
LLVM_ABI Expected< ExecutorAddr > getCompileCallback(CompileFunction Compile)
Reserve a compile callback.
void setTrampolinePool(std::unique_ptr< TrampolinePool > TP)
std::function< ExecutorAddr()> CompileFunction
Represents a JIT'd dynamic library.
Definition: Core.h:902
void * getStub(unsigned Idx) const
LocalIndirectStubsInfo(unsigned NumStubs, sys::OwningMemoryBlock StubsMem)
static Expected< LocalIndirectStubsInfo > create(unsigned MinStubs, unsigned PageSize)
void ** getPtr(unsigned Idx) const
IndirectStubsManager implementation for the host architecture, e.g.
Error createStub(StringRef StubName, ExecutorAddr StubAddr, JITSymbolFlags StubFlags) override
Create a single stub with the given name, target address and flags.
ExecutorSymbolDef findPointer(StringRef Name) override
Find the implementation-pointer for the stub.
Error updatePointer(StringRef Name, ExecutorAddr NewAddr) override
Change the value of the implementation pointer for the stub.
ExecutorSymbolDef findStub(StringRef Name, bool ExportedStubsOnly) override
Find the stub with the given name.
Error createStubs(const StubInitsMap &StubInits) override
Create StubInits.size() stubs with the given names, target addresses, and flags.
Manage compile callbacks for in-process JITs.
static Expected< std::unique_ptr< LocalJITCompileCallbackManager > > Create(ExecutionSession &ES, ExecutorAddr ErrorHandlerAddress)
Create a new LocalJITCompileCallbackManager.
A trampoline pool for trampolines within the current process.
static Expected< std::unique_ptr< LocalTrampolinePool > > Create(ResolveLandingFunction ResolveLanding)
Creates a LocalTrampolinePool with the given RunCallback function.
Base class for managing redirectable symbols in which a call gets redirected to another symbol in run...
Promotes private symbols to global hidden, and renames to prevent clashes with other promoted symbols...
LLVM_ABI std::vector< GlobalValue * > operator()(Module &M)
Promote symbols in the given module.
Base class for pools of compiler re-entry trampolines.
std::vector< ExecutorAddr > AvailableTrampolines
virtual Error grow()=0
unique_function< void(ExecutorAddr) const > NotifyLandingResolvedFunction
unique_function< void(ExecutorAddr TrampolineAddr, NotifyLandingResolvedFunction OnLandingResolved) const > ResolveLandingFunction
void releaseTrampoline(ExecutorAddr TrampolineAddr)
Returns the given trampoline to the pool for re-use.
Expected< ExecutorAddr > getTrampoline()
Get an available trampoline address.
This class encapsulates the notion of a memory block which has an address and a size.
Definition: Memory.h:33
static LLVM_ABI std::error_code protectMappedMemory(const MemoryBlock &Block, unsigned Flags)
This method sets the protection flags for a block of memory to the state specified by /p Flags.
static LLVM_ABI MemoryBlock allocateMappedMemory(size_t NumBytes, const MemoryBlock *const NearBlock, unsigned Flags, std::error_code &EC)
This method allocates a block of memory that is suitable for loading dynamically generated code (e....
Owning version of MemoryBlock.
Definition: Memory.h:139
MemoryBlock getMemoryBlock() const
Definition: Memory.h:160
void * base() const
Definition: Memory.h:156
static unsigned getPageSizeEstimate()
Get the process's estimated page size.
Definition: Process.h:62
unique_function is a type-erasing functor similar to std::function.
LLVM_ABI Constant * createIRTypedAddress(FunctionType &FT, ExecutorAddr Addr)
Build a function pointer of FunctionType with the given constant address.
LLVM_ABI Expected< std::unique_ptr< JITCompileCallbackManager > > createLocalCompileCallbackManager(const Triple &T, ExecutionSession &ES, ExecutorAddr ErrorHandlerAddress)
Create a local compile callback manager.
LLVM_ABI void makeStub(Function &F, Value &ImplPointer)
Turn a function declaration into a stub function that makes an indirect call using the given function...
LLVM_ABI Error addFunctionPointerRelocationsToCurrentSymbol(jitlink::Symbol &Sym, jitlink::LinkGraph &G, MCDisassembler &Disassembler, MCInstrAnalysis &MIA)
Introduce relocations to Sym in its own definition if there are any pointers formed via PC-relative a...
LLVM_ABI GlobalVariable * cloneGlobalVariableDecl(Module &Dst, const GlobalVariable &GV, ValueToValueMapTy *VMap=nullptr)
Clone a global variable declaration into a new module.
LLVM_ABI Function * cloneFunctionDecl(Module &Dst, const Function &F, ValueToValueMapTy *VMap=nullptr)
Clone a function declaration into a new module.
LLVM_ABI std::function< std::unique_ptr< IndirectStubsManager >()> createLocalIndirectStubsManagerBuilder(const Triple &T)
Create a local indirect stubs manager builder.
LLVM_ABI GlobalAlias * cloneGlobalAliasDecl(Module &Dst, const GlobalAlias &OrigA, ValueToValueMapTy &VMap)
Clone a global alias declaration into a new module.
LLVM_ABI GlobalVariable * createImplPointer(PointerType &PT, Module &M, const Twine &Name, Constant *Initializer)
Create a function pointer with the given type, name, and initializer in the given Module.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
uint64_t alignTo(uint64_t Size, Align A)
Returns a multiple of A needed to store Size bytes.
Definition: Alignment.h:155
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1886
LLVM_ABI Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Definition: Error.cpp:111
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:856