21 void lookup(
const LookupSet &Symbols, OnResolvedFunction OnResolved) {
22 auto &ES = MR.getTargetJITDylib().getExecutionSession();
26 for (
auto &S : Symbols)
27 InternedSymbols.
add(ES.intern(S));
31 auto OnResolvedWithUnwrap =
32 [OnResolved = std::move(OnResolved)](
34 if (!InternedResult) {
35 OnResolved(InternedResult.takeError());
40 for (
auto &KV : *InternedResult)
41 Result[*KV.first] = std::move(KV.second);
47 MR.addDependenciesForAll(Deps);
51 MR.getTargetJITDylib().withSearchOrderDo(
55 RegisterDependencies);
61 for (
auto &KV : MR.getSymbols()) {
62 if (Symbols.count(*KV.first))
63 Result.insert(*KV.first);
80 :
ObjectLayer(ES), GetMemoryManager(GetMemoryManager) {}
83 std::lock_guard<std::mutex>
Lock(RTDyldLayerMutex);
84 for (
auto &MemMgr : MemMgrs)
85 MemMgr->deregisterEHFrames();
89 std::unique_ptr<MemoryBuffer>
O) {
90 assert(O &&
"Object must not be null");
96 auto SharedR = std::make_shared<MaterializationResponsibility>(std::move(R));
110 SharedR->failMaterialization();
116 auto InternalSymbols = std::make_shared<std::set<StringRef>>();
118 for (
auto &Sym : (*Obj)->symbols()) {
120 if (
auto SymName = Sym.getName())
121 InternalSymbols->insert(*SymName);
123 ES.reportError(SymName.takeError());
136 auto Tmp = GetMemoryManager();
137 std::lock_guard<std::mutex>
Lock(RTDyldLayerMutex);
138 MemMgrs.push_back(std::move(Tmp));
139 MemMgr = MemMgrs.back().get();
142 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, O = std::move(O)](
Error Err)
mutable {
153 onObjEmit(K, std::move(O), *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) {
167 if (
auto *COFFObj = dyn_cast<object::COFFObjectFile>(&Obj)) {
173 for (
auto &Sym : COFFObj->symbols()) {
176 auto Name = Sym.getName();
178 return Name.takeError();
179 auto I = Resolved.find(*
Name);
183 if (
I == Resolved.end() || InternalSymbols.count(*
Name) ||
186 auto Sec = Sym.getSection();
188 return Sec.takeError();
189 if (*Sec == COFFObj->section_end())
191 auto &COFFSec = *COFFObj->getCOFFSection(**Sec);
197 for (
auto &KV : Resolved) {
201 if (InternalSymbols.count(KV.first))
205 auto Flags = KV.second.getFlags();
209 if (OverrideObjectFlags || AutoClaimObjectSymbols) {
215 ExtraSymbolsToClaim[InternedName] = Flags;
221 if (!ExtraSymbolsToClaim.
empty()) {
227 for (
auto &KV : ExtraSymbolsToClaim)
229 Symbols.
erase(KV.first);
238 NotifyLoaded(K, Obj, *LoadedObjInfo);
243 void RTDyldObjectLinkingLayer::onObjEmit(
244 VModuleKey K, std::unique_ptr<MemoryBuffer> ObjBuffer,
259 NotifyEmitted(K, std::move(ObjBuffer));
264 NotifyLoadedFtor NotifyLoaded, NotifyFinalizedFtor NotifyFinalized,
265 NotifyFreedFtor NotifyFreed)
266 : ES(ES), GetResources(std::move(GetResources)),
267 NotifyLoaded(std::move(NotifyLoaded)),
268 NotifyFinalized(std::move(NotifyFinalized)),
269 NotifyFreed(std::move(NotifyFreed)), ProcessAllSections(
false) {}
static Expected< OwningBinary< ObjectFile > > createObjectFile(StringRef ObjectPath)
Queried, materialization begun.
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.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
void jitLinkForORC(object::ObjectFile &Obj, std::unique_ptr< MemoryBuffer > UnderlyingBuffer, RuntimeDyld::MemoryManager &MemMgr, JITSymbolResolver &Resolver, bool ProcessAllSections, unique_function< Error(std::unique_ptr< RuntimeDyld::LoadedObjectInfo >, std::map< StringRef, JITEvaluatedSymbol >)> OnLoaded, unique_function< void(Error)> OnEmitted)
static std::unique_ptr< MemoryBuffer > getMemBuffer(StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true)
Open the specified memory range as a MemoryBuffer.
static bool lookup(const GsymReader &GR, DataExtractor &Data, uint64_t &Offset, uint64_t BaseAddr, uint64_t Addr, SourceLocations &SrcLocs, llvm::Error &Err)
A Lookup helper functions.
std::vector< std::pair< JITDylib *, JITDylibLookupFlags > > JITDylibSearchOrder
A list of (JITDylib*, JITDylibLookupFlags) pairs to be used as a search order during symbol lookup...
This class is the base class for all object file types.
SymbolStringPtr intern(StringRef SymName)
Add a symbol name to the SymbolStringPool and return a pointer to it.
RTDyldObjectLinkingLayer(ExecutionSession &ES, GetMemoryManagerFunction GetMemoryManager)
Construct an ObjectLinkingLayer with the given NotifyLoaded, and NotifyEmitted functors.
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.
iterator find(const_arg_type_t< KeyT > Val)
bool erase(const KeyT &Val)
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
LegacyRTDyldObjectLinkingLayer(ORCv1DeprecationAcknowledgement, ExecutionSession &ES, ResourcesGetter GetResources, NotifyLoadedFtor NotifyLoaded=NotifyLoadedFtor(), NotifyFinalizedFtor NotifyFinalized=NotifyFinalizedFtor(), NotifyFreedFtor NotifyFreed=NotifyFreedFtor())
VModuleKey getVModuleKey() const
Returns the VModuleKey for this instance.
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
Symbol resolution interface.
void add(SymbolStringPtr Name, SymbolLookupFlags Flags=SymbolLookupFlags::RequiredSymbol)
Add an element to the set.
Error notifyResolved(const SymbolMap &Symbols)
Notifies the target JITDylib that the given symbols have been resolved.
static ErrorSuccess success()
Create a success value.
std::function< std::unique_ptr< RuntimeDyld::MemoryManager >()> GetMemoryManagerFunction
A set of symbols to look up, each associated with a SymbolLookupFlags value.
An ExecutionSession represents a running JIT program.
const SymbolFlagsMap & getSymbols() const
Returns the symbol flags map for this responsibility instance.
Represents a symbol that has been evaluated to an address already.
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.
Error defineMaterializing(SymbolFlagsMap SymbolFlags)
Attempt to claim responsibility for new definitions.
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
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void failMaterialization()
Notify all not-yet-emitted covered by this MaterializationResponsibility instance that an error has o...
Lightweight error class with error context and mandatory checking.
Interface for Layers that accept object files.
void emit(MaterializationResponsibility R, std::unique_ptr< MemoryBuffer > O) override
Emit the object.
~RTDyldObjectLinkingLayer()