14 #define DEBUG_TYPE "orc" 19 void LazyCallThroughManager::NotifyResolvedFunction::anchor() {}
23 std::unique_ptr<TrampolinePool> TP)
24 : ES(ES), ErrorHandlerAddr(ErrorHandlerAddr), TP(
std::move(TP)) {}
28 std::shared_ptr<NotifyResolvedFunction> NotifyResolved) {
29 std::lock_guard<std::mutex>
Lock(LCTMMutex);
30 auto Trampoline = TP->getTrampoline();
33 return Trampoline.takeError();
35 Reexports[*Trampoline] = std::make_pair(&SourceJD, std::move(SymbolName));
36 Notifiers[*Trampoline] = std::move(NotifyResolved);
46 std::lock_guard<std::mutex>
Lock(LCTMMutex);
47 auto I = Reexports.find(TrampolineAddr);
48 if (
I == Reexports.end())
49 return ErrorHandlerAddr;
50 SourceJD =
I->second.first;
51 SymbolName =
I->second.second;
54 auto LookupResult = ES.
lookup(
60 return ErrorHandlerAddr;
63 auto ResolvedAddr = LookupResult->getAddress();
65 std::shared_ptr<NotifyResolvedFunction> NotifyResolved =
nullptr;
67 std::lock_guard<std::mutex>
Lock(LCTMMutex);
68 auto I = Notifiers.find(TrampolineAddr);
69 if (
I != Notifiers.end()) {
70 NotifyResolved =
I->second;
76 if (
auto Err = (*NotifyResolved)(*SourceJD, SymbolName, ResolvedAddr)) {
78 return ErrorHandlerAddr;
90 return make_error<StringError>(
91 std::string(
"No callback manager available for ") + T.
str(),
96 return LocalLazyCallThroughManager::Create<OrcAArch64>(ES,
100 return LocalLazyCallThroughManager::Create<OrcI386>(ES, ErrorHandlerAddr);
103 return LocalLazyCallThroughManager::Create<OrcMips32Be>(ES,
107 return LocalLazyCallThroughManager::Create<OrcMips32Le>(ES,
112 return LocalLazyCallThroughManager::Create<OrcMips64>(ES, ErrorHandlerAddr);
115 if (T.
getOS() == Triple::OSType::Win32)
116 return LocalLazyCallThroughManager::Create<OrcX86_64_Win32>(
117 ES, ErrorHandlerAddr);
119 return LocalLazyCallThroughManager::Create<OrcX86_64_SysV>(
120 ES, ErrorHandlerAddr);
129 LCTManager(LCTManager), ISManager(ISManager), SourceJD(SourceJD),
130 CallableAliases(
std::move(CallableAliases)),
136 AliaseeTable(SrcJDLoc) {}
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), AliaseeTable));
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);
175 if (AliaseeTable !=
nullptr && !RequestedAliases.empty())
176 AliaseeTable->
trackImpls(RequestedAliases, &SourceJD);
185 for (
auto &Alias : RequestedAliases)
186 Stubs[Alias.first] = ISManager.
findStub(*Alias.first,
false);
193 void LazyReexportsMaterializationUnit::discard(
const JITDylib &JD,
196 "Symbol not covered by this MaterializationUnit");
197 CallableAliases.
erase(Name);
201 LazyReexportsMaterializationUnit::extractFlags(
const SymbolAliasMap &Aliases) {
203 for (
auto &KV : Aliases) {
204 assert(KV.second.AliasFlags.isCallable() &&
205 "Lazy re-exports must be callable symbols");
206 SymbolFlags[KV.first] = KV.second.AliasFlags;
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Base class for managing collections of named indirect stubs.
Error notifyEmitted()
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...
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
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...
LazyReexportsMaterializationUnit(LazyCallThroughManager &LCTManager, IndirectStubsManager &ISManager, JITDylib &SourceJD, SymbolAliasMap CallableAliases, ImplSymbolMap *SrcJDLoc, VModuleKey K)
JITTargetAddress callThroughToSymbol(JITTargetAddress TrampolineAddr)
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
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.
uint64_t JITTargetAddress
Represents an address in the target process's address space.
void trackImpls(SymbolAliasMap ImplMaps, JITDylib *SrcJD)
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)
std::unique_ptr< LazyReexportsMaterializationUnit > lazyReexports(LazyCallThroughManager &LCTManager, IndirectStubsManager &ISManager, JITDylib &SourceJD, SymbolAliasMap CallableAliases, ImplSymbolMap *SrcJDLoc=nullptr, VModuleKey K=VModuleKey())
Define lazy-reexports based on the given SymbolAliasMap.
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...
Error notifyResolved(const SymbolMap &Symbols)
Notifies the target JITDylib that the given symbols have been resolved.
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. ...
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 lookup(LookupKind K, const JITDylibSearchOrder &SearchOrder, SymbolLookupSet Symbols, SymbolState RequiredState, SymbolsResolvedCallback NotifyComplete, RegisterDependenciesFunction RegisterDependencies)
Search the given JITDylib list for the given symbols.
uint8_t uint64_t VModuleKey
VModuleKey provides a unique identifier (allocated and managed by ExecutionSessions) for a module add...
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...
Manages a set of 'lazy call-through' trampolines.
StringRef - Represent a constant reference to a string, i.e.
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...