22 auto &ES = MR.getTargetVSO().getExecutionSession();
25 for (
auto &S : Symbols)
26 InternedSymbols.insert(ES.getSymbolStringPool().intern(S));
29 MR.addDependenciesForAll(Deps);
33 MR.getTargetVSO().withSearchOrderDo([&](
const VSOList &VSOs) {
34 return ES.lookup(VSOs, InternedSymbols, RegisterDependencies,
false);
38 return InternedResult.takeError();
41 for (
auto &KV : *InternedResult)
42 Result[*KV.first] = std::move(KV.second);
48 auto &ES = MR.getTargetVSO().getExecutionSession();
52 for (
auto &S : Symbols)
53 InternedSymbols.insert(ES.getSymbolStringPool().intern(S));
56 MR.getTargetVSO().withSearchOrderDo([&](
const VSOList &VSOs) {
61 assert(VSOs.front() &&
"VSOList entry can not be null");
62 InternedResult = VSOs.front()->lookupFlags(InternedSymbols);
65 LookupFlagsResult Result;
66 for (
auto &KV : InternedResult)
67 Result[*KV.first] = std::move(KV.second);
84 :
ObjectLayer(ES), GetMemoryManager(GetMemoryManager),
85 NotifyLoaded(
std::move(NotifyLoaded)),
86 NotifyFinalized(
std::move(NotifyFinalized)), ProcessAllSections(
false) {}
90 std::unique_ptr<MemoryBuffer>
O) {
91 assert(O &&
"Object must not be null");
101 auto MemoryManager = GetMemoryManager(K);
104 auto RTDyld = llvm::make_unique<RuntimeDyld>(*MemoryManager, Resolver);
105 RTDyld->setProcessAllSections(ProcessAllSections);
108 std::lock_guard<std::mutex>
Lock(RTDyldLayerMutex);
110 assert(!ActiveRTDylds.count(K) &&
111 "An active RTDyld already exists for this key?");
112 ActiveRTDylds[K] = RTDyld.get();
114 assert(!MemMgrs.count(K) &&
115 "A memory manager already exists for this key?");
116 MemMgrs[K] = std::move(MemoryManager);
119 auto Info = RTDyld->loadObject(**ObjFile);
122 std::set<StringRef> InternalSymbols;
123 for (
auto &Sym : (*ObjFile)->symbols()) {
125 if (
auto SymName = Sym.getName())
126 InternalSymbols.insert(*SymName);
128 ES.reportError(SymName.takeError());
136 for (
auto &KV : RTDyld->getSymbolTable())
137 if (!InternalSymbols.count(KV.first))
138 Symbols[ES.getSymbolStringPool().intern(KV.first)] = KV.second;
144 NotifyLoaded(K, **ObjFile, *Info);
146 RTDyld->finalizeWithMemoryManagerLocking();
149 std::lock_guard<std::mutex>
Lock(RTDyldLayerMutex);
150 ActiveRTDylds.erase(K);
153 if (RTDyld->hasError()) {
154 ES.reportError(make_error<StringError>(RTDyld->getErrorString(),
168 std::lock_guard<std::mutex>
Lock(RTDyldLayerMutex);
169 auto ActiveRTDyldItr = ActiveRTDylds.find(K);
171 assert(ActiveRTDyldItr != ActiveRTDylds.end() &&
172 "No active RTDyld instance found for key");
173 ActiveRTDyldItr->second->mapSectionAddress(LocalAddress, TargetAddr);
static Expected< OwningBinary< ObjectFile > > createObjectFile(StringRef ObjectPath)
Compute iterated dominance frontiers using a linear time algorithm.
std::map< SymbolStringPtr, JITEvaluatedSymbol > SymbolMap
A map from symbol names (as SymbolStringPtrs) to JITSymbols (address/flags pairs).
uint64_t VModuleKey
VModuleKey provides a unique identifier (allocated and managed by ExecutionSessions) for a module add...
std::map< SymbolStringPtr, JITSymbolFlags > SymbolFlagsMap
A map from symbol names (as SymbolStringPtrs) to JITSymbolFlags.
Tagged union holding either a T or a Error.
Tracks responsibility for materialization, and mediates interactions between MaterializationUnits and...
ExecutionSession & getExecutionSession()
Returns the execution session for this layer.
uint64_t JITTargetAddress
Represents an address in the target process's address space.
void reportError(Error Err)
Report a error for this execution session.
RTDyldObjectLinkingLayer2(ExecutionSession &ES, GetMemoryManagerFunction GetMemoryManager, NotifyLoadedFunction NotifyLoaded=NotifyLoadedFunction(), NotifyFinalizedFunction NotifyFinalized=NotifyFinalizedFunction())
Construct an ObjectLinkingLayer with the given NotifyLoaded, and NotifyFinalized functors.
void mapSectionAddress(VModuleKey K, const void *LocalAddress, JITTargetAddress TargetAddr) const
Map section addresses for the object associated with the VModuleKey K.
void emit(MaterializationResponsibility R, VModuleKey K, std::unique_ptr< MemoryBuffer > O) override
Emit the object.
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
Symbol resolution interface.
std::function< std::shared_ptr< RuntimeDyld::MemoryManager >(VModuleKey)> GetMemoryManagerFunction
std::function< void(VModuleKey)> NotifyFinalizedFunction
Functor for receiving finalization notifications.
void resolve(const SymbolMap &Symbols)
Resolves the given symbols.
std::map< VSO *, SymbolNameSet > SymbolDependenceMap
A base class for materialization failures that allows the failing symbols to be obtained for logging...
Expected< SymbolMap > lookup(const VSOList &VSOs, SymbolNameSet Names)
Look up the given names in the given VSOs.
std::vector< VSO * > VSOList
A list of VSO pointers.
An ExecutionSession represents a running JIT program.
void finalize()
Finalizes all symbols tracked by this instance.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void failMaterialization()
Notify all unfinalized symbols that an error has occurred.
Interface for Layers that accept object files.
std::function< void(VModuleKey, const object::ObjectFile &Obj, const RuntimeDyld::LoadedObjectInfo &)> NotifyLoadedFunction
Functor for receiving object-loaded notifications.
std::set< SymbolStringPtr > SymbolNameSet
A set of symbol names (represented by SymbolStringPtrs for.
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...