15 #define DEBUG_TYPE "orc" 20 void LazyCallThroughManager::NotifyResolvedFunction::anchor() {}
24 std::unique_ptr<TrampolinePool> TP)
25 : ES(ES), ErrorHandlerAddr(ErrorHandlerAddr), TP(
std::move(TP)) {}
29 std::shared_ptr<NotifyResolvedFunction> NotifyResolved) {
30 std::lock_guard<std::mutex>
Lock(LCTMMutex);
31 auto Trampoline = TP->getTrampoline();
34 return Trampoline.takeError();
36 Reexports[*Trampoline] = std::make_pair(&SourceJD, std::move(SymbolName));
37 Notifiers[*Trampoline] = std::move(NotifyResolved);
47 std::lock_guard<std::mutex>
Lock(LCTMMutex);
48 auto I = Reexports.find(TrampolineAddr);
49 if (
I == Reexports.end())
50 return ErrorHandlerAddr;
51 SourceJD =
I->second.first;
52 SymbolName =
I->second.second;
60 return ErrorHandlerAddr;
63 assert(LookupResult->size() == 1 &&
"Unexpected number of results");
64 assert(LookupResult->count(SymbolName) &&
"Unexpected result");
66 auto ResolvedAddr = LookupResult->begin()->second.getAddress();
68 std::shared_ptr<NotifyResolvedFunction> NotifyResolved =
nullptr;
70 std::lock_guard<std::mutex>
Lock(LCTMMutex);
71 auto I = Notifiers.find(TrampolineAddr);
72 if (
I != Notifiers.end()) {
73 NotifyResolved =
I->second;
79 if (
auto Err = (*NotifyResolved)(*SourceJD, SymbolName, ResolvedAddr)) {
81 return ErrorHandlerAddr;
93 return make_error<StringError>(
94 std::string(
"No callback manager available for ") + T.
str(),
98 return LocalLazyCallThroughManager::Create<OrcAArch64>(ES,
102 return LocalLazyCallThroughManager::Create<OrcI386>(ES, ErrorHandlerAddr);
105 return LocalLazyCallThroughManager::Create<OrcMips32Be>(ES,
109 return LocalLazyCallThroughManager::Create<OrcMips32Le>(ES,
114 return LocalLazyCallThroughManager::Create<OrcMips64>(ES, ErrorHandlerAddr);
117 if (T.
getOS() == Triple::OSType::Win32)
118 return LocalLazyCallThroughManager::Create<OrcX86_64_Win32>(
119 ES, ErrorHandlerAddr);
121 return LocalLazyCallThroughManager::Create<OrcX86_64_SysV>(
122 ES, ErrorHandlerAddr);
130 LCTManager(LCTManager), ISManager(ISManager), SourceJD(SourceJD),
131 CallableAliases(
std::move(CallableAliases)),
139 return "<Lazy Reexports>";
142 void LazyReexportsMaterializationUnit::materialize(
147 for (
auto &RequestedSymbol : RequestedSymbols) {
148 auto I = CallableAliases.
find(RequestedSymbol);
149 assert(
I != CallableAliases.
end() &&
"Symbol not found in alias map?");
150 RequestedAliases[
I->first] = std::move(
I->second);
154 if (!CallableAliases.
empty())
156 std::move(CallableAliases)));
159 for (
auto &Alias : RequestedAliases) {
162 SourceJD, Alias.second.Aliasee, NotifyResolved);
164 if (!CallThroughTrampoline) {
166 CallThroughTrampoline.takeError());
171 StubInits[*Alias.first] =
172 std::make_pair(*CallThroughTrampoline, Alias.second.AliasFlags);
182 for (
auto &Alias : RequestedAliases)
183 Stubs[Alias.first] = ISManager.
findStub(*Alias.first,
false);
189 void LazyReexportsMaterializationUnit::discard(
const JITDylib &JD,
192 "Symbol not covered by this MaterializationUnit");
193 CallableAliases.
erase(Name);
197 LazyReexportsMaterializationUnit::extractFlags(
const SymbolAliasMap &Aliases) {
199 for (
auto &KV : Aliases) {
200 assert(KV.second.AliasFlags.isCallable() &&
201 "Lazy re-exports must be callable symbols");
202 SymbolFlags[KV.first] = KV.second.AliasFlags;
Base class for managing collections of named indirect stubs.
void emit()
Notifies the target JITDylib (and any pending queries on that JITDylib) that all symbols covered by t...
This class represents lattice values for constants.
static std::unique_ptr< NotifyResolvedFunction > createNotifyResolvedFunction(NotifyResolvedImpl NotifyResolved)
Create a shared NotifyResolvedFunction from a given type that is callable with the correct signature...
OSType getOS() const
getOS - Get the parsed operating system type of this triple.
void replace(std::unique_ptr< MaterializationUnit > MU)
Transfers responsibility to the given MaterializationUnit for all symbols defined by that Materializa...
uint64_t VModuleKey
VModuleKey provides a unique identifier (allocated and managed by ExecutionSessions) for a module add...
JITTargetAddress callThroughToSymbol(JITTargetAddress TrampolineAddr)
amdgpu Simplify well known AMD library false Value Value const Twine & Name
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
std::vector< std::pair< JITDylib *, bool > > JITDylibSearchList
A list of (JITDylib*, bool) pairs.
SymbolFlagsMap SymbolFlags
Tagged union holding either a T or a Error.
Tracks responsibility for materialization, and mediates interactions between MaterializationUnits and...
ArchType getArch() const
getArch - Get the parsed architecture type of this triple.
StringRef getName() const override
Return the name of this materialization unit.
LazyReexportsMaterializationUnit(LazyCallThroughManager &LCTManager, IndirectStubsManager &ISManager, JITDylib &SourceJD, SymbolAliasMap CallableAliases, VModuleKey K)
uint64_t JITTargetAddress
Represents an address in the target process's address space.
ExecutionSession & getExecutionSession() const
Get a reference to the ExecutionSession for this JITDylib.
const std::string & str() const
Pointer to a pooled string representing a symbol name.
iterator find(const_arg_type_t< KeyT > Val)
LazyCallThroughManager(ExecutionSession &ES, JITTargetAddress ErrorHandlerAddr, std::unique_ptr< TrampolinePool > TP)
bool erase(const KeyT &Val)
Triple - Helper class for working with autoconf configuration names.
A MaterializationUnit represents a set of symbol definitions that can be materialized as a group...
Expected< std::unique_ptr< LazyCallThroughManager > > createLocalLazyCallThroughManager(const Triple &T, ExecutionSession &ES, JITTargetAddress ErrorHandlerAddr)
Create a LocalLazyCallThroughManager from the given triple and execution session. ...
void resolve(const SymbolMap &Symbols)
Notifies the target JITDylib that the given symbols have been resolved.
std::unique_ptr< LazyReexportsMaterializationUnit > lazyReexports(LazyCallThroughManager &LCTManager, IndirectStubsManager &ISManager, JITDylib &SourceJD, SymbolAliasMap CallableAliases, VModuleKey K=VModuleKey())
Define lazy-reexports based on the given SymbolAliasMap.
SymbolNameSet getRequestedSymbols() const
Returns the names of any symbols covered by this MaterializationResponsibility object that have queri...
An ExecutionSession represents a running JIT program.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
void reportError(Error Err)
Report a error for this execution session.
Expected< JITTargetAddress > getCallThroughTrampoline(JITDylib &SourceJD, SymbolStringPtr SymbolName, std::shared_ptr< NotifyResolvedFunction > NotifyResolved)
virtual Error updatePointer(StringRef Name, JITTargetAddress NewAddr)=0
Change the value of the implementation pointer for the stub.
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
LLVM_NODISCARD bool empty() const
virtual JITEvaluatedSymbol findStub(StringRef Name, bool ExportedStubsOnly)=0
Find the stub with the given name.
virtual Error createStubs(const StubInitsMap &StubInits)=0
Create StubInits.size() stubs with the given names, target addresses, and flags.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void failMaterialization()
Notify all not-yet-emitted covered by this MaterializationResponsibility instance that an error has o...
void lookup(const JITDylibSearchList &SearchOrder, SymbolNameSet Symbols, SymbolsResolvedCallback OnResolve, SymbolsReadyCallback OnReady, RegisterDependenciesFunction RegisterDependencies)
Search the given JITDylib list for the given symbols.
Manages a set of 'lazy call-through' trampolines.
StringRef - Represent a constant reference to a string, i.e.
RegisterDependenciesFunction NoDependenciesToRegister
This can be used as the value for a RegisterDependenciesFunction if there are no dependants to regist...
A symbol table that supports asynchoronous symbol queries.
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...