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();
34 Reexports[*Trampoline] =
ReexportsEntry{&SourceJD, std::move(SymbolName)};
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()) {
62 NotifyResolved = std::move(
I->second);
67 return NotifyResolved ? NotifyResolved(ResolvedAddr) :
Error::success();
81 auto Callback = [
this, TrampolineAddr, SymbolName = Entry->SymbolName,
82 NotifyLandingResolved = std::move(NotifyLandingResolved)](
86 assert(
Result->count(SymbolName) &&
"Unexpected result value");
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<OrcLoongArch64>(
124 ES, ErrorHandlerAddr);
127 return LocalLazyCallThroughManager::Create<OrcMips32Be>(ES,
131 return LocalLazyCallThroughManager::Create<OrcMips32Le>(ES,
136 return LocalLazyCallThroughManager::Create<OrcMips64>(ES, ErrorHandlerAddr);
139 return LocalLazyCallThroughManager::Create<OrcRiscv64>(ES,
144 return LocalLazyCallThroughManager::Create<OrcX86_64_Win32>(
145 ES, ErrorHandlerAddr);
147 return LocalLazyCallThroughManager::Create<OrcX86_64_SysV>(
148 ES, ErrorHandlerAddr);
156 LCTManager(LCTManager), ISManager(ISManager), SourceJD(SourceJD),
157 CallableAliases(
std::
move(CallableAliases)), AliaseeTable(SrcJDLoc) {}
160 return "<Lazy Reexports>";
163void LazyReexportsMaterializationUnit::materialize(
164 std::unique_ptr<MaterializationResponsibility> R) {
165 auto RequestedSymbols = R->getRequestedSymbols();
168 for (
auto &RequestedSymbol : RequestedSymbols) {
169 auto I = CallableAliases.
find(RequestedSymbol);
170 assert(
I != CallableAliases.
end() &&
"Symbol not found in alias map?");
171 RequestedAliases[
I->first] = std::move(
I->second);
175 if (!CallableAliases.
empty())
176 if (
auto Err = R->replace(
lazyReexports(LCTManager, ISManager, SourceJD,
177 std::move(CallableAliases),
179 R->getExecutionSession().reportError(std::move(Err));
180 R->failMaterialization();
185 for (
auto &Alias : RequestedAliases) {
188 SourceJD, Alias.second.Aliasee,
189 [&ISManager = this->ISManager,
191 return ISManager.updatePointer(*StubSym, ResolvedAddr);
194 if (!CallThroughTrampoline) {
196 CallThroughTrampoline.takeError());
197 R->failMaterialization();
201 StubInits[*Alias.first] =
202 std::make_pair(*CallThroughTrampoline, Alias.second.AliasFlags);
205 if (AliaseeTable !=
nullptr && !RequestedAliases.empty())
206 AliaseeTable->
trackImpls(RequestedAliases, &SourceJD);
210 R->failMaterialization();
215 for (
auto &Alias : RequestedAliases)
216 Stubs[Alias.first] = ISManager.
findStub(*Alias.first,
false);
223void LazyReexportsMaterializationUnit::discard(
const JITDylib &JD,
224 const SymbolStringPtr &
Name) {
226 "Symbol not covered by this MaterializationUnit");
230MaterializationUnit::Interface
231LazyReexportsMaterializationUnit::extractFlags(
const SymbolAliasMap &Aliases) {
233 for (
auto &KV : Aliases) {
234 assert(KV.second.AliasFlags.isCallable() &&
235 "Lazy re-exports must be callable symbols");
238 return MaterializationUnit::Interface(std::move(
SymbolFlags),
nullptr);
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
iterator find(const_arg_type_t< KeyT > Val)
bool erase(const KeyT &Val)
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
StringRef - Represent a constant reference to a string, i.e.
Triple - Helper class for working with autoconf configuration names.
An ExecutionSession represents a running JIT program.
void reportError(Error Err)
Report a error for this execution session.
void lookup(LookupKind K, const JITDylibSearchOrder &SearchOrder, SymbolLookupSet Symbols, SymbolState RequiredState, SymbolsResolvedCallback NotifyComplete, RegisterDependenciesFunction RegisterDependencies)
Search the given JITDylibs for the given symbols.
void trackImpls(SymbolAliasMap ImplMaps, JITDylib *SrcJD)
Base class for managing collections of named indirect stubs.
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.
StringMap< std::pair< JITTargetAddress, JITSymbolFlags > > StubInitsMap
Map type for initializing the manager. See init.
Represents a JIT'd dynamic library.
ExecutionSession & getExecutionSession() const
Get a reference to the ExecutionSession for this JITDylib.
Manages a set of 'lazy call-through' trampolines.
void resolveTrampolineLandingAddress(JITTargetAddress TrampolineAddr, TrampolinePool::NotifyLandingResolvedFunction NotifyLandingResolved)
JITTargetAddress reportCallThroughError(Error Err)
Expected< JITTargetAddress > getCallThroughTrampoline(JITDylib &SourceJD, SymbolStringPtr SymbolName, NotifyResolvedFunction NotifyResolved)
Error notifyResolved(JITTargetAddress TrampolineAddr, JITTargetAddress ResolvedAddr)
LazyCallThroughManager(ExecutionSession &ES, JITTargetAddress ErrorHandlerAddr, TrampolinePool *TP)
Expected< ReexportsEntry > findReexport(JITTargetAddress TrampolineAddr)
StringRef getName() const override
Return the name of this materialization unit.
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,...
SymbolFlagsMap SymbolFlags
A set of symbols to look up, each associated with a SymbolLookupFlags value.
Pointer to a pooled string representing a symbol name.
Base class for pools of compiler re-entry trampolines.
Expected< JITTargetAddress > getTrampoline()
Get an available trampoline address.
unique_function is a type-erasing functor similar to std::function.
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...
DenseMap< SymbolStringPtr, JITEvaluatedSymbol > SymbolMap
A map from symbol names (as SymbolStringPtrs) to JITSymbols (address/flags pairs).
DenseMap< SymbolStringPtr, SymbolAliasMapEntry > SymbolAliasMap
A map of Symbols to (Symbol, Flags) pairs.
DenseMap< SymbolStringPtr, JITSymbolFlags > SymbolFlagsMap
A map from symbol names (as SymbolStringPtrs) to JITSymbolFlags.
std::unique_ptr< LazyReexportsMaterializationUnit > lazyReexports(LazyCallThroughManager &LCTManager, IndirectStubsManager &ISManager, JITDylib &SourceJD, SymbolAliasMap CallableAliases, ImplSymbolMap *SrcJDLoc=nullptr)
Define lazy-reexports based on the given SymbolAliasMap.
RegisterDependenciesFunction NoDependenciesToRegister
This can be used as the value for a RegisterDependenciesFunction if there are no dependants to regist...
Expected< std::unique_ptr< LazyCallThroughManager > > createLocalLazyCallThroughManager(const Triple &T, ExecutionSession &ES, JITTargetAddress ErrorHandlerAddr)
Create a LocalLazyCallThroughManager from the given triple and execution session.
@ Ready
Emitted to memory, but waiting on transitive dependencies.
This is an optimization pass for GlobalISel generic memory operations.
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
uint64_t JITTargetAddress
Represents an address in the target process's address space.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.