21 void lookup(
const LookupSet &Symbols, OnResolvedFunction OnResolved) {
22 auto &ES = MR.getTargetJITDylib().getExecutionSession();
26 for (
auto &S : Symbols)
27 InternedSymbols.
insert(ES.intern(S));
32 auto OnResolvedWithUnwrap =
34 if (!InternedResult) {
35 OnResolved(InternedResult.takeError());
40 for (
auto &KV : *InternedResult)
41 Result[*KV.first] = std::move(KV.second);
46 auto OnReady = [&ES](
Error Err) { ES.reportError(std::move(Err)); };
50 MR.addDependenciesForAll(Deps);
54 MR.getTargetJITDylib().withSearchOrderDo(
56 ES.lookup(SearchOrder, InternedSymbols, OnResolvedWithUnwrap, OnReady,
57 RegisterDependencies);
63 for (
auto &KV : MR.getSymbols()) {
64 if (Symbols.count(*KV.first))
65 Result.insert(*KV.first);
83 :
ObjectLayer(ES), GetMemoryManager(GetMemoryManager),
84 NotifyLoaded(
std::move(NotifyLoaded)),
85 NotifyEmitted(
std::move(NotifyEmitted)) {}
88 std::unique_ptr<MemoryBuffer>
O) {
89 assert(O &&
"Object must not be null");
95 auto SharedR = std::make_shared<MaterializationResponsibility>(std::move(R));
103 SharedR->failMaterialization();
109 auto InternalSymbols = std::make_shared<std::set<StringRef>>();
111 for (
auto &Sym : (*Obj)->symbols()) {
113 if (
auto SymName = Sym.getName())
114 InternalSymbols->insert(*SymName);
116 ES.reportError(SymName.takeError());
129 auto Tmp = GetMemoryManager();
130 std::lock_guard<std::mutex>
Lock(RTDyldLayerMutex);
131 MemMgrs.push_back(std::move(Tmp));
132 MemMgr = MemMgrs.back().get();
135 JITDylibSearchOrderResolver
Resolver(*SharedR);
145 **Obj, std::move(O), *MemMgr, Resolver, ProcessAllSections,
146 [
this, K, SharedR, &Obj, InternalSymbols](
147 std::unique_ptr<RuntimeDyld::LoadedObjectInfo> LoadedObjInfo,
148 std::map<StringRef, JITEvaluatedSymbol> ResolvedSymbols) {
149 return onObjLoad(K, *SharedR, **Obj, std::move(LoadedObjInfo),
150 ResolvedSymbols, *InternalSymbols);
152 [
this, K, SharedR](
Error Err) {
153 onObjEmit(K, *SharedR, std::move(Err));
157 Error RTDyldObjectLinkingLayer::onObjLoad(
159 std::unique_ptr<RuntimeDyld::LoadedObjectInfo> LoadedObjInfo,
160 std::map<StringRef, JITEvaluatedSymbol> Resolved,
161 std::set<StringRef> &InternalSymbols) {
164 for (
auto &KV : Resolved) {
168 if (InternalSymbols.count(KV.first))
172 auto Flags = KV.second.getFlags();
176 if (OverrideObjectFlags || AutoClaimObjectSymbols) {
182 ExtraSymbolsToClaim[InternedName] = Flags;
188 if (!ExtraSymbolsToClaim.
empty())
195 NotifyLoaded(K, Obj, *LoadedObjInfo);
200 void RTDyldObjectLinkingLayer::onObjEmit(
VModuleKey K,
static Expected< OwningBinary< ObjectFile > > createObjectFile(StringRef ObjectPath)
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.
Error defineMaterializing(const SymbolFlagsMap &SymbolFlags)
Adds new symbols to the JITDylib and this responsibility instance.
This class is the base class for all object file types.
std::function< void(VModuleKey, const object::ObjectFile &Obj, const RuntimeDyld::LoadedObjectInfo &)> NotifyLoadedFunction
Functor for receiving object-loaded notifications.
void jitLinkForORC(object::ObjectFile &Obj, std::unique_ptr< MemoryBuffer > UnderlyingBuffer, RuntimeDyld::MemoryManager &MemMgr, JITSymbolResolver &Resolver, bool ProcessAllSections, std::function< Error(std::unique_ptr< LoadedObjectInfo >, std::map< StringRef, JITEvaluatedSymbol >)> OnLoaded, std::function< void(Error)> OnEmitted)
uint64_t VModuleKey
VModuleKey provides a unique identifier (allocated and managed by ExecutionSessions) for a module add...
SymbolStringPtr intern(StringRef SymName)
Add a symbol name to the SymbolStringPool and return a pointer to it.
std::vector< std::pair< JITDylib *, bool > > JITDylibSearchList
A list of (JITDylib*, bool) pairs.
Tagged union holding either a T or a Error.
static const uint16_t * lookup(unsigned opcode, unsigned domain, ArrayRef< uint16_t[3]> Table)
RTDyldObjectLinkingLayer(ExecutionSession &ES, GetMemoryManagerFunction GetMemoryManager, NotifyLoadedFunction NotifyLoaded=NotifyLoadedFunction(), NotifyEmittedFunction NotifyEmitted=NotifyEmittedFunction())
Construct an ObjectLinkingLayer with the given NotifyLoaded, and NotifyEmitted functors.
Tracks responsibility for materialization, and mediates interactions between MaterializationUnits and...
ExecutionSession & getExecutionSession()
Returns the execution session for this layer.
iterator find(const_arg_type_t< KeyT > Val)
VModuleKey getVModuleKey() const
Returns the VModuleKey for this instance.
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
std::pair< iterator, bool > insert(const ValueT &V)
std::function< void(VModuleKey)> NotifyEmittedFunction
Functor for receiving finalization notifications.
Symbol resolution interface.
static ErrorSuccess success()
Create a success value.
void resolve(const SymbolMap &Symbols)
Notifies the target JITDylib that the given symbols have been resolved.
std::function< std::unique_ptr< RuntimeDyld::MemoryManager >()> GetMemoryManagerFunction
An ExecutionSession represents a running JIT program.
Represents a symbol that has been evaluated to an address already.
void reportError(Error Err)
Report a error for this execution session.
LLVM_NODISCARD bool empty() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void failMaterialization()
Notify all not-yet-emitted covered by this MaterializationResponsibility instance that an error has o...
const SymbolFlagsMap & getSymbols()
Returns the symbol flags map for this responsibility instance.
Lightweight error class with error context and mandatory checking.
static JITSymbolFlags stripTransientFlags(JITSymbolFlags Orig)
Interface for Layers that accept object files.
void emit(MaterializationResponsibility R, std::unique_ptr< MemoryBuffer > O) override
Emit the object.