Go to the documentation of this file.
14 #define DEBUG_TYPE "orc"
21 : ES(ES), ErrorHandlerAddr(ErrorHandlerAddr), TP(TP) {}
26 assert(TP &&
"TrampolinePool not set");
28 std::lock_guard<std::mutex>
Lock(LCTMMutex);
32 return Trampoline.takeError();
35 Notifiers[*Trampoline] =
std::move(NotifyResolved);
41 return ErrorHandlerAddr;
46 std::lock_guard<std::mutex>
Lock(LCTMMutex);
47 auto I = Reexports.find(TrampolineAddr);
48 if (
I == Reexports.end())
50 "Missing reexport for trampoline address %p",
59 std::lock_guard<std::mutex>
Lock(LCTMMutex);
60 auto I = Notifiers.find(TrampolineAddr);
61 if (
I != Notifiers.end()) {
67 return NotifyResolved ? NotifyResolved(ResolvedAddr) :
Error::success();
81 auto Callback = [
this, TrampolineAddr,
SymbolName = Entry->SymbolName,
82 NotifyLandingResolved =
std::move(NotifyLandingResolved)](
85 assert(Result->size() == 1 &&
"Unexpected result size");
92 NotifyLandingResolved(LandingAddr);
108 switch (
T.getArch()) {
110 return make_error<StringError>(
111 std::string(
"No callback manager available for ") +
T.str(),
116 return LocalLazyCallThroughManager::Create<OrcAArch64>(ES,
120 return LocalLazyCallThroughManager::Create<OrcI386>(ES, ErrorHandlerAddr);
123 return LocalLazyCallThroughManager::Create<OrcMips32Be>(ES,
127 return LocalLazyCallThroughManager::Create<OrcMips32Le>(ES,
132 return LocalLazyCallThroughManager::Create<OrcMips64>(ES, ErrorHandlerAddr);
135 return LocalLazyCallThroughManager::Create<OrcRiscv64>(ES,
139 if (
T.getOS() == Triple::OSType::Win32)
140 return LocalLazyCallThroughManager::Create<OrcX86_64_Win32>(
141 ES, ErrorHandlerAddr);
143 return LocalLazyCallThroughManager::Create<OrcX86_64_SysV>(
144 ES, ErrorHandlerAddr);
152 LCTManager(LCTManager), ISManager(ISManager), SourceJD(SourceJD),
153 CallableAliases(
std::
move(CallableAliases)), AliaseeTable(SrcJDLoc) {}
156 return "<Lazy Reexports>";
159 void LazyReexportsMaterializationUnit::materialize(
160 std::unique_ptr<MaterializationResponsibility> R) {
161 auto RequestedSymbols = R->getRequestedSymbols();
164 for (
auto &RequestedSymbol : RequestedSymbols) {
165 auto I = CallableAliases.
find(RequestedSymbol);
166 assert(
I != CallableAliases.
end() &&
"Symbol not found in alias map?");
171 if (!CallableAliases.
empty())
172 if (
auto Err = R->replace(
lazyReexports(LCTManager, ISManager, SourceJD,
175 R->getExecutionSession().reportError(
std::move(Err));
176 R->failMaterialization();
181 for (
auto &Alias : RequestedAliases) {
184 SourceJD, Alias.second.Aliasee,
185 [&ISManager =
this->ISManager,
187 return ISManager.updatePointer(*StubSym, ResolvedAddr);
190 if (!CallThroughTrampoline) {
192 CallThroughTrampoline.takeError());
193 R->failMaterialization();
197 StubInits[*Alias.first] =
198 std::make_pair(*CallThroughTrampoline, Alias.second.AliasFlags);
201 if (AliaseeTable !=
nullptr && !RequestedAliases.empty())
202 AliaseeTable->
trackImpls(RequestedAliases, &SourceJD);
206 R->failMaterialization();
211 for (
auto &Alias : RequestedAliases)
212 Stubs[Alias.first] = ISManager.
findStub(*Alias.first,
false);
219 void LazyReexportsMaterializationUnit::discard(
const JITDylib &JD,
220 const SymbolStringPtr &
Name) {
222 "Symbol not covered by this MaterializationUnit");
226 MaterializationUnit::Interface
227 LazyReexportsMaterializationUnit::extractFlags(
const SymbolAliasMap &Aliases) {
229 for (
auto &KV : Aliases) {
230 assert(KV.second.AliasFlags.isCallable() &&
231 "Lazy re-exports must be callable symbols");
virtual Error createStubs(const StubInitsMap &StubInits)=0
Create StubInits.size() stubs with the given names, target addresses, and flags.
This is an optimization pass for GlobalISel generic memory operations.
Represents a JIT'd dynamic library.
void reportError(Error Err)
Report a error for this execution session.
unique_function is a type-erasing functor similar to std::function.
Base class for managing collections of named indirect stubs.
A set of symbols to look up, each associated with a SymbolLookupFlags value.
Pointer to a pooled string representing a symbol name.
static ErrorSuccess success()
Create a success value.
Triple - Helper class for working with autoconf configuration names.
bool erase(const KeyT &Val)
Manages a set of 'lazy call-through' trampolines.
StringMap< std::pair< JITTargetAddress, JITSymbolFlags > > StubInitsMap
Map type for initializing the manager. See init.
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
std::unique_ptr< LazyReexportsMaterializationUnit > lazyReexports(LazyCallThroughManager &LCTManager, IndirectStubsManager &ISManager, JITDylib &SourceJD, SymbolAliasMap CallableAliases, ImplSymbolMap *SrcJDLoc=nullptr)
Define lazy-reexports based on the given SymbolAliasMap.
Tagged union holding either a T or a Error.
LazyReexportsMaterializationUnit(LazyCallThroughManager &LCTManager, IndirectStubsManager &ISManager, JITDylib &SourceJD, SymbolAliasMap CallableAliases, ImplSymbolMap *SrcJDLoc)
A MaterializationUnit represents a set of symbol definitions that can be materialized as a group,...
RegisterDependenciesFunction NoDependenciesToRegister
This can be used as the value for a RegisterDependenciesFunction if there are no dependants to regist...
DenseMap< SymbolStringPtr, JITEvaluatedSymbol > SymbolMap
A map from symbol names (as SymbolStringPtrs) to JITSymbols (address/flags pairs).
Expected< ReexportsEntry > findReexport(JITTargetAddress TrampolineAddr)
Base class for pools of compiler re-entry trampolines.
DenseMap< SymbolStringPtr, SymbolAliasMapEntry > SymbolAliasMap
A map of Symbols to (Symbol, Flags) pairs.
StringRef getName() const override
Return the name of this materialization unit.
Expected< JITTargetAddress > getCallThroughTrampoline(JITDylib &SourceJD, SymbolStringPtr SymbolName, NotifyResolvedFunction NotifyResolved)
JITTargetAddress reportCallThroughError(Error Err)
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
iterator find(const_arg_type_t< KeyT > Val)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
StringRef - Represent a constant reference to a string, i.e.
Analysis the ScalarEvolution expression for r is this
@ Ready
Emitted to memory, but waiting on transitive dependencies.
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Expected< std::unique_ptr< LazyCallThroughManager > > createLocalLazyCallThroughManager(const Triple &T, ExecutionSession &ES, JITTargetAddress ErrorHandlerAddr)
Create a LocalLazyCallThroughManager from the given triple and execution session.
DenseMap< SymbolStringPtr, JITSymbolFlags > SymbolFlagsMap
A map from symbol names (as SymbolStringPtrs) to JITSymbolFlags.
LLVM_NODISCARD bool empty() const
void trackImpls(SymbolAliasMap ImplMaps, JITDylib *SrcJD)
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Error notifyResolved(JITTargetAddress TrampolineAddr, JITTargetAddress ResolvedAddr)
Lightweight error class with error context and mandatory checking.
An ExecutionSession represents a running JIT program.
uint64_t JITTargetAddress
Represents an address in the target process's address space.
LazyCallThroughManager(ExecutionSession &ES, JITTargetAddress ErrorHandlerAddr, TrampolinePool *TP)
void lookup(LookupKind K, const JITDylibSearchOrder &SearchOrder, SymbolLookupSet Symbols, SymbolState RequiredState, SymbolsResolvedCallback NotifyComplete, RegisterDependenciesFunction RegisterDependencies)
Search the given JITDylibs for the given symbols.
ExecutionSession & getExecutionSession() const
Get a reference to the ExecutionSession for this JITDylib.
void resolveTrampolineLandingAddress(JITTargetAddress TrampolineAddr, TrampolinePool::NotifyLandingResolvedFunction NotifyLandingResolved)
SymbolFlagsMap SymbolFlags
JITDylibSearchOrder makeJITDylibSearchOrder(ArrayRef< JITDylib * > JDs, JITDylibLookupFlags Flags=JITDylibLookupFlags::MatchExportedSymbolsOnly)
Convenience function for creating a search order from an ArrayRef of JITDylib*, all with the same fla...
virtual JITEvaluatedSymbol findStub(StringRef Name, bool ExportedStubsOnly)=0
Find the stub with the given name.
Expected< JITTargetAddress > getTrampoline()
Get an available trampoline address.