14 #ifndef LLVM_EXECUTIONENGINE_ORC_RTDYLDOBJECTLINKINGLAYER_H 15 #define LLVM_EXECUTIONENGINE_ORC_RTDYLDOBJECTLINKINGLAYER_H 50 std::function<std::unique_ptr<RuntimeDyld::MemoryManager>()>;
61 std::unique_ptr<MemoryBuffer>
O)
override;
70 this->ProcessAllSections = ProcessAllSections;
84 this->OverrideObjectFlags = OverrideObjectFlags;
101 this->AutoClaimObjectSymbols = AutoClaimObjectSymbols;
108 std::unique_ptr<RuntimeDyld::LoadedObjectInfo> LoadedObjInfo,
109 std::map<StringRef, JITEvaluatedSymbol> Resolved,
110 std::set<StringRef> &InternalSymbols);
114 mutable std::mutex RTDyldLayerMutex;
118 bool ProcessAllSections =
false;
119 bool OverrideObjectFlags =
false;
120 bool AutoClaimObjectSymbols =
false;
121 std::vector<std::unique_ptr<RuntimeDyld::MemoryManager>> MemMgrs;
147 getSymbolMaterializer(std::string
Name) = 0;
149 virtual void mapSectionAddress(
const void *LocalAddress,
153 auto SymEntry = SymbolTable.find(Name);
154 if (SymEntry == SymbolTable.end())
156 if (!SymEntry->second.getFlags().isExported() && ExportedSymbolsOnly)
159 return JITSymbol(getSymbolMaterializer(Name),
160 SymEntry->second.getFlags());
166 bool Finalized =
false;
192 using NotifyFreedFtor = std::function<void(VModuleKey, const object::ObjectFile &Obj)>;
197 template <
typename MemoryManagerPtrT>
202 std::shared_ptr<SymbolResolver>
Resolver,
203 bool ProcessAllSections)
206 MemMgr(std::move(MemMgr)),
207 PFC(llvm::make_unique<PreFinalizeContents>(
208 std::move(Obj), std::move(Resolver),
209 ProcessAllSections)) {
210 buildInitialSymbolTable(PFC->Obj);
213 ~ConcreteLinkedObject()
override {
214 if (this->Parent.NotifyFreed && ObjForNotify.getBinary())
215 this->Parent.NotifyFreed(K, *ObjForNotify.getBinary());
217 MemMgr->deregisterEHFrames();
221 assert(PFC &&
"mapSectionAddress called on finalized LinkedObject");
225 PFC->RTDyld = llvm::make_unique<RuntimeDyld>(*MemMgr, ResolverAdapter);
226 PFC->RTDyld->setProcessAllSections(PFC->ProcessAllSections);
230 std::unique_ptr<RuntimeDyld::LoadedObjectInfo>
Info =
231 PFC->RTDyld->loadObject(*PFC->Obj.getBinary());
235 auto SymTab = PFC->RTDyld->getSymbolTable();
236 for (
auto &KV : SymTab)
237 SymbolTable[KV.first] = KV.second;
240 if (Parent.NotifyLoaded)
241 Parent.NotifyLoaded(K, *PFC->Obj.getBinary(), *
Info);
243 PFC->RTDyld->finalizeWithMemoryManagerLocking();
245 if (PFC->RTDyld->hasError())
246 return make_error<StringError>(PFC->RTDyld->getErrorString(),
249 if (Parent.NotifyFinalized)
250 Parent.NotifyFinalized(K, *PFC->Obj.getBinary(), *
Info);
253 if (this->Parent.NotifyFreed)
254 ObjForNotify = std::move(PFC->Obj);
263 if (!this->Finalized)
265 return std::move(Err);
266 return this->
getSymbol(Name,
false).getAddress();
270 void mapSectionAddress(
const void *LocalAddress,
272 assert(PFC &&
"mapSectionAddress called on finalized LinkedObject");
273 assert(PFC->RTDyld &&
"mapSectionAddress called on raw LinkedObject");
274 PFC->RTDyld->mapSectionAddress(LocalAddress, TargetAddr);
278 void buildInitialSymbolTable(
const OwnedObject &Obj) {
301 struct PreFinalizeContents {
303 std::shared_ptr<SymbolResolver> Resolver,
304 bool ProcessAllSections)
305 : Obj(std::move(Obj)),
306 Resolver(std::move(Resolver)),
307 ProcessAllSections(ProcessAllSections) {}
310 std::shared_ptr<SymbolResolver> Resolver;
311 bool ProcessAllSections;
312 std::unique_ptr<RuntimeDyld> RTDyld;
317 MemoryManagerPtrT MemMgr;
319 std::unique_ptr<PreFinalizeContents> PFC;
322 template <
typename MemoryManagerPtrT>
323 std::unique_ptr<ConcreteLinkedObject<MemoryManagerPtrT>>
326 std::shared_ptr<SymbolResolver>
Resolver,
327 bool ProcessAllSections) {
328 using LOS = ConcreteLinkedObject<MemoryManagerPtrT>;
329 return llvm::make_unique<LOS>(Parent, std::move(K), std::move(Obj),
330 std::move(MemMgr), std::move(Resolver),
336 std::shared_ptr<RuntimeDyld::MemoryManager>
MemMgr;
349 : ES(ES), GetResources(
std::move(GetResources)),
350 NotifyLoaded(
std::move(NotifyLoaded)),
351 NotifyFinalized(
std::move(NotifyFinalized)),
352 NotifyFreed(
std::move(NotifyFreed)),
353 ProcessAllSections(
false) {
363 this->ProcessAllSections = ProcessAllSections;
372 return Obj.takeError();
374 assert(!LinkedObjects.count(K) &&
"VModuleKey already in use");
376 auto R = GetResources(K);
378 LinkedObjects[K] = createLinkedObject(
379 *
this, K,
OwnedObject(std::move(*Obj), std::move(ObjBuffer)),
380 std::move(R.MemMgr), std::move(R.Resolver), ProcessAllSections);
394 assert(LinkedObjects.count(K) &&
"VModuleKey not associated with object");
396 LinkedObjects.erase(K);
405 for (
auto &KV : LinkedObjects)
406 if (
auto Sym = KV.second->getSymbol(Name, ExportedSymbolsOnly))
408 else if (
auto Err = Sym.takeError())
409 return std::move(Err);
422 bool ExportedSymbolsOnly) {
423 assert(LinkedObjects.count(K) &&
"VModuleKey not associated with object");
424 return LinkedObjects[K]->getSymbol(Name, ExportedSymbolsOnly);
431 assert(LinkedObjects.count(K) &&
"VModuleKey not associated with object");
432 LinkedObjects[K]->mapSectionAddress(LocalAddress, TargetAddr);
439 assert(LinkedObjects.count(K) &&
"VModuleKey not associated with object");
440 return LinkedObjects[K]->finalize();
453 std::map<VModuleKey, std::unique_ptr<LinkedObject>> LinkedObjects;
454 bool ProcessAllSections =
false;
460 #endif // LLVM_EXECUTIONENGINE_ORC_RTDYLDOBJECTLINKINGLAYER_H static Expected< OwningBinary< ObjectFile > > createObjectFile(StringRef ObjectPath)
Information about the loaded object.
Represents a symbol in the JIT.
This class represents lattice values for constants.
Error removeObject(VModuleKey K)
Remove the object associated with VModuleKey K.
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.
uint64_t VModuleKey
VModuleKey provides a unique identifier (allocated and managed by ExecutionSessions) for a module add...
JITSymbol getSymbol(StringRef Name, bool ExportedSymbolsOnly)
amdgpu Simplify well known AMD library false Value Value const Twine & Name
constexpr char SymbolName[]
Key for Kernel::Metadata::mSymbolName.
Tagged union holding either a T or a Error.
std::unique_ptr< MemoryBuffer > ObjectPtr
RTDyldObjectLinkingLayer(ExecutionSession &ES, GetMemoryManagerFunction GetMemoryManager, NotifyLoadedFunction NotifyLoaded=NotifyLoadedFunction(), NotifyEmittedFunction NotifyEmitted=NotifyEmittedFunction())
Construct an ObjectLinkingLayer with the given NotifyLoaded, and NotifyEmitted functors.
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...
LegacyRTDyldObjectLinkingLayer(ExecutionSession &ES, ResourcesGetter GetResources, NotifyLoadedFtor NotifyLoaded=NotifyLoadedFtor(), NotifyFinalizedFtor NotifyFinalized=NotifyFinalizedFtor(), NotifyFreedFtor NotifyFreed=NotifyFreedFtor())
Construct an ObjectLinkingLayer with the given NotifyLoaded, and NotifyFinalized functors.
std::function< void(VModuleKey, const object::ObjectFile &Obj)> NotifyFreedFtor
Functor for receiving deallocation notifications.
Legacy adapter. Remove once we kill off the old ORC layers.
uint64_t JITTargetAddress
Represents an address in the target process's address space.
Expected< const typename ELFT::Sym * > getSymbol(typename ELFT::SymRange Symbols, uint32_t Index)
Analysis containing CSE Info
std::shared_ptr< SymbolResolver > Resolver
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.
std::function< void(VModuleKey)> NotifyEmittedFunction
Functor for receiving finalization notifications.
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
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.
std::function< Expected< JITTargetAddress >()> GetAddressFtor
symbol_iterator_range symbols() const
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.
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.