13 #ifndef LLVM_EXECUTIONENGINE_ORC_RTDYLDOBJECTLINKINGLAYER_H 14 #define LLVM_EXECUTIONENGINE_ORC_RTDYLDOBJECTLINKINGLAYER_H 47 std::function<void(VModuleKey, std::unique_ptr<MemoryBuffer>)>;
50 std::function<std::unique_ptr<RuntimeDyld::MemoryManager>()>;
61 std::unique_ptr<MemoryBuffer>
O)
override;
65 this->NotifyLoaded = std::move(NotifyLoaded);
72 this->NotifyEmitted = std::move(NotifyEmitted);
83 this->ProcessAllSections = ProcessAllSections;
97 this->OverrideObjectFlags = OverrideObjectFlags;
114 this->AutoClaimObjectSymbols = AutoClaimObjectSymbols;
121 std::unique_ptr<RuntimeDyld::LoadedObjectInfo> LoadedObjInfo,
122 std::map<StringRef, JITEvaluatedSymbol>
Resolved,
123 std::set<StringRef> &InternalSymbols);
125 void onObjEmit(
VModuleKey K, std::unique_ptr<MemoryBuffer> ObjBuffer,
128 mutable std::mutex RTDyldLayerMutex;
132 bool ProcessAllSections =
false;
133 bool OverrideObjectFlags =
false;
134 bool AutoClaimObjectSymbols =
false;
135 std::vector<std::unique_ptr<RuntimeDyld::MemoryManager>> MemMgrs;
161 getSymbolMaterializer(std::string
Name) = 0;
163 virtual void mapSectionAddress(
const void *LocalAddress,
167 auto SymEntry = SymbolTable.find(Name);
168 if (SymEntry == SymbolTable.end())
170 if (!SymEntry->second.getFlags().isExported() && ExportedSymbolsOnly)
173 return JITSymbol(getSymbolMaterializer(Name),
174 SymEntry->second.getFlags());
180 bool Finalized =
false;
206 using NotifyFreedFtor = std::function<void(VModuleKey, const object::ObjectFile &Obj)>;
211 template <
typename MemoryManagerPtrT>
212 class ConcreteLinkedObject :
public LinkedObject {
216 std::shared_ptr<SymbolResolver>
Resolver,
217 bool ProcessAllSections)
220 MemMgr(std::move(MemMgr)),
221 PFC(std::make_unique<PreFinalizeContents>(
222 std::move(Obj), std::move(Resolver),
223 ProcessAllSections)) {
224 buildInitialSymbolTable(PFC->Obj);
227 ~ConcreteLinkedObject()
override {
228 if (this->Parent.NotifyFreed && ObjForNotify.getBinary())
229 this->Parent.NotifyFreed(K, *ObjForNotify.getBinary());
231 MemMgr->deregisterEHFrames();
235 assert(PFC &&
"mapSectionAddress called on finalized LinkedObject");
239 PFC->RTDyld = std::make_unique<RuntimeDyld>(*MemMgr, ResolverAdapter);
240 PFC->RTDyld->setProcessAllSections(PFC->ProcessAllSections);
244 std::unique_ptr<RuntimeDyld::LoadedObjectInfo>
Info =
245 PFC->RTDyld->loadObject(*PFC->Obj.getBinary());
249 auto SymTab = PFC->RTDyld->getSymbolTable();
250 for (
auto &KV : SymTab)
251 SymbolTable[KV.first] = KV.second;
254 if (Parent.NotifyLoaded)
255 Parent.NotifyLoaded(K, *PFC->Obj.getBinary(), *
Info);
257 PFC->RTDyld->finalizeWithMemoryManagerLocking();
259 if (PFC->RTDyld->hasError())
260 return make_error<StringError>(PFC->RTDyld->getErrorString(),
263 if (Parent.NotifyFinalized)
264 Parent.NotifyFinalized(K, *PFC->Obj.getBinary(), *
Info);
267 if (this->Parent.NotifyFreed)
268 ObjForNotify = std::move(PFC->Obj);
277 if (!this->Finalized)
279 return std::move(Err);
280 return this->getSymbol(Name,
false).getAddress();
284 void mapSectionAddress(
const void *LocalAddress,
286 assert(PFC &&
"mapSectionAddress called on finalized LinkedObject");
287 assert(PFC->RTDyld &&
"mapSectionAddress called on raw LinkedObject");
288 PFC->RTDyld->mapSectionAddress(LocalAddress, TargetAddr);
292 void buildInitialSymbolTable(
const OwnedObject &Obj) {
315 struct PreFinalizeContents {
317 std::shared_ptr<SymbolResolver> Resolver,
318 bool ProcessAllSections)
319 : Obj(std::move(Obj)),
320 Resolver(std::move(Resolver)),
321 ProcessAllSections(ProcessAllSections) {}
324 std::shared_ptr<SymbolResolver> Resolver;
325 bool ProcessAllSections;
326 std::unique_ptr<RuntimeDyld> RTDyld;
331 MemoryManagerPtrT MemMgr;
333 std::unique_ptr<PreFinalizeContents> PFC;
336 template <
typename MemoryManagerPtrT>
337 std::unique_ptr<ConcreteLinkedObject<MemoryManagerPtrT>>
340 std::shared_ptr<SymbolResolver>
Resolver,
341 bool ProcessAllSections) {
342 using LOS = ConcreteLinkedObject<MemoryManagerPtrT>;
343 return std::make_unique<LOS>(Parent, std::move(K), std::move(Obj),
344 std::move(MemMgr), std::move(Resolver),
350 std::shared_ptr<RuntimeDyld::MemoryManager>
MemMgr;
364 "ORCv1 layers (layers with the 'Legacy' prefix) are deprecated. Please " 366 "ORCv2 (see docs/ORCv2.rst)");
375 : ES(ES), GetResources(
std::move(GetResources)),
376 NotifyLoaded(
std::move(NotifyLoaded)),
377 NotifyFinalized(
std::move(NotifyFinalized)),
378 NotifyFreed(
std::move(NotifyFreed)), ProcessAllSections(
false) {}
387 this->ProcessAllSections = ProcessAllSections;
396 return Obj.takeError();
398 assert(!LinkedObjects.count(K) &&
"VModuleKey already in use");
400 auto R = GetResources(K);
402 LinkedObjects[K] = createLinkedObject(
403 *
this, K,
OwnedObject(std::move(*Obj), std::move(ObjBuffer)),
404 std::move(R.MemMgr), std::move(R.Resolver), ProcessAllSections);
418 assert(LinkedObjects.count(K) &&
"VModuleKey not associated with object");
420 LinkedObjects.erase(K);
429 for (
auto &KV : LinkedObjects)
430 if (
auto Sym = KV.second->getSymbol(Name, ExportedSymbolsOnly))
432 else if (
auto Err = Sym.takeError())
433 return std::move(Err);
446 bool ExportedSymbolsOnly) {
447 assert(LinkedObjects.count(K) &&
"VModuleKey not associated with object");
448 return LinkedObjects[K]->getSymbol(Name, ExportedSymbolsOnly);
455 assert(LinkedObjects.count(K) &&
"VModuleKey not associated with object");
456 LinkedObjects[K]->mapSectionAddress(LocalAddress, TargetAddr);
463 assert(LinkedObjects.count(K) &&
"VModuleKey not associated with object");
464 return LinkedObjects[K]->finalize();
477 std::map<VModuleKey, std::unique_ptr<LinkedObject>> LinkedObjects;
478 bool ProcessAllSections =
false;
484 #endif // LLVM_EXECUTIONENGINE_ORC_RTDYLDOBJECTLINKINGLAYER_H static Expected< OwningBinary< ObjectFile > > createObjectFile(StringRef ObjectPath)
Queried, materialization begun.
Information about the loaded object.
Represents a symbol in the JIT.
std::function< void(VModuleKey, std::unique_ptr< MemoryBuffer >)> NotifyEmittedFunction
Functor for receiving finalization notifications.
RTDyldObjectLinkingLayer & setNotifyEmitted(NotifyEmittedFunction NotifyEmitted)
Set the NotifyEmitted callback.
This class represents lattice values for constants.
Error removeObject(VModuleKey K)
Remove the object associated with VModuleKey K.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
RTDyldObjectLinkingLayer & setProcessAllSections(bool ProcessAllSections)
Set the 'ProcessAllSections' flag.
std::function< Resources(VModuleKey)> ResourcesGetter
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.
static Expected< JITSymbolFlags > fromObjectSymbol(const object::SymbolRef &Symbol)
Construct a JITSymbolFlags value based on the flags of the given libobject symbol.
Error takeError()
Take ownership of the stored error.
JITSymbol getSymbol(StringRef Name, bool ExportedSymbolsOnly)
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
RTDyldObjectLinkingLayer(ExecutionSession &ES, GetMemoryManagerFunction GetMemoryManager)
Construct an ObjectLinkingLayer with the given NotifyLoaded, and NotifyEmitted functors.
Tagged union holding either a T or a Error.
std::unique_ptr< MemoryBuffer > ObjectPtr
JITSymbol findSymbolIn(VModuleKey K, StringRef Name, bool ExportedSymbolsOnly)
Search for the given named symbol in the context of the loaded object represented by the VModuleKey K...
Tracks responsibility for materialization, and mediates interactions between MaterializationUnits and...
std::function< void(VModuleKey, const object::ObjectFile &Obj)> NotifyFreedFtor
Functor for receiving deallocation notifications.
ORCv1DeprecationAcknowledgement
Legacy adapter. Remove once we kill off the old ORC layers.
uint64_t JITTargetAddress
Represents an address in the target process's address space.
Analysis containing CSE Info
std::shared_ptr< SymbolResolver > Resolver
LegacyRTDyldObjectLinkingLayer(ORCv1DeprecationAcknowledgement, ExecutionSession &ES, ResourcesGetter GetResources, NotifyLoadedFtor NotifyLoaded=NotifyLoadedFtor(), NotifyFinalizedFtor NotifyFinalized=NotifyFinalizedFtor(), NotifyFreedFtor NotifyFreed=NotifyFreedFtor())
StringMap< JITEvaluatedSymbol > SymbolTable
void mapSectionAddress(VModuleKey K, const void *LocalAddress, JITTargetAddress TargetAddr)
Map section addresses for the object associated with the VModuleKey K.
Interface for looking up the initializer for a variable name, used by Init::resolveReferences.
void consumeError(Error Err)
Consume a Error without doing anything.
RTDyldObjectLinkingLayer & setAutoClaimResponsibilityForObjectSymbols(bool AutoClaimObjectSymbols)
If set, this RTDyldObjectLinkingLayer instance will claim responsibility for any symbols provided by ...
std::shared_ptr< RuntimeDyld::MemoryManager > MemMgr
#define LLVM_ATTRIBUTE_DEPRECATED(decl, message)
static ErrorSuccess success()
Create a success value.
std::function< void(VModuleKey, const object::ObjectFile &Obj, const RuntimeDyld::LoadedObjectInfo &)> NotifyLoadedFtor
Functor for receiving object-loaded notifications.
Error addObject(VModuleKey K, ObjectPtr ObjBuffer)
Add an object to the JIT.
std::function< std::unique_ptr< RuntimeDyld::MemoryManager >()> GetMemoryManagerFunction
JITSymbol findSymbol(StringRef Name, bool ExportedSymbolsOnly)
Search for the given named symbol.
An ExecutionSession represents a running JIT program.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
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...
symbol_iterator_range symbols() const
RTDyldObjectLinkingLayer & setNotifyLoaded(NotifyLoadedFunction NotifyLoaded)
Set the NotifyLoaded callback.
void setProcessAllSections(bool ProcessAllSections)
Set the 'ProcessAllSections' flag.
Holds an object to be allocated/linked as a unit in the JIT.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
std::function< void(VModuleKey, const object::ObjectFile &Obj, const RuntimeDyld::LoadedObjectInfo &)> NotifyFinalizedFtor
Functor for receiving finalization notifications.
Lightweight error class with error context and mandatory checking.
Interface for Layers that accept object files.
print Print MemDeps of function
StringRef - Represent a constant reference to a string, i.e.
Bare bones object linking layer.
RTDyldObjectLinkingLayer & setOverrideObjectFlagsWithResponsibilityFlags(bool OverrideObjectFlags)
Instructs this RTDyldLinkingLayer2 instance to override the symbol flags returned by RuntimeDyld for ...
void emit(MaterializationResponsibility R, std::unique_ptr< MemoryBuffer > O) override
Emit the object.
~RTDyldObjectLinkingLayer()
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Error emitAndFinalize(VModuleKey K)
Immediately emit and finalize the object represented by the given VModuleKey.