14 #ifndef LLVM_EXECUTIONENGINE_ORC_RTDYLDOBJECTLINKINGLAYER_H
15 #define LLVM_EXECUTIONENGINE_ORC_RTDYLDOBJECTLINKINGLAYER_H
40 std::shared_ptr<object::OwningBinary<object::ObjectFile>>;
70 if (!SymEntry->second.getFlags().isExported() && ExportedSymbolsOnly)
74 SymEntry->second.getFlags());
111 template <
typename MemoryManagerPtrT,
typename SymbolResolverPtrT,
112 typename FinalizerFtor>
115 ConcreteLinkedObject(
ObjectPtr Obj, MemoryManagerPtrT MemMgr,
116 SymbolResolverPtrT Resolver,
117 FinalizerFtor Finalizer,
118 bool ProcessAllSections)
119 : MemMgr(std::move(MemMgr)),
120 PFC(llvm::make_unique<PreFinalizeContents>(std::move(Obj),
122 std::move(Finalizer),
123 ProcessAllSections)) {
124 buildInitialSymbolTable(PFC->Obj);
127 ~ConcreteLinkedObject()
override {
128 MemMgr->deregisterEHFrames();
135 void finalize()
override {
136 assert(PFC &&
"mapSectionAddress called on finalized LinkedObject");
140 PFC->RTDyld = &RTDyld;
142 this->Finalized =
true;
143 PFC->Finalizer(PFC->Handle, RTDyld, std::move(PFC->Obj),
145 this->updateSymbolTable(RTDyld);
157 if (!this->Finalized)
159 return this->
getSymbol(Name,
false).getAddress();
165 assert(PFC &&
"mapSectionAddress called on finalized LinkedObject");
166 assert(PFC->RTDyld &&
"mapSectionAddress called on raw LinkedObject");
167 PFC->RTDyld->mapSectionAddress(LocalAddress, TargetAddr);
172 void buildInitialSymbolTable(
const ObjectPtr &Obj) {
173 for (
auto &
Symbol : Obj->getBinary()->symbols()) {
176 Expected<StringRef> SymbolName =
Symbol.getName();
184 std::make_pair(*SymbolName, JITEvaluatedSymbol(0,
Flags)));
188 void updateSymbolTable(
const RuntimeDyld &RTDyld) {
189 for (
auto &SymEntry : SymbolTable)
190 SymEntry.second = RTDyld.getSymbol(SymEntry.first());
195 struct PreFinalizeContents {
196 PreFinalizeContents(
ObjectPtr Obj, SymbolResolverPtrT Resolver,
197 FinalizerFtor Finalizer,
bool ProcessAllSections)
198 : Obj(std::move(Obj)), Resolver(std::move(Resolver)),
199 Finalizer(std::move(Finalizer)),
200 ProcessAllSections(ProcessAllSections) {}
203 SymbolResolverPtrT Resolver;
204 FinalizerFtor Finalizer;
205 bool ProcessAllSections;
210 MemoryManagerPtrT MemMgr;
211 std::unique_ptr<PreFinalizeContents> PFC;
214 template <
typename MemoryManagerPtrT,
typename SymbolResolverPtrT,
215 typename FinalizerFtor>
217 ConcreteLinkedObject<MemoryManagerPtrT, SymbolResolverPtrT, FinalizerFtor>>
218 createLinkedObject(ObjectPtr Obj, MemoryManagerPtrT MemMgr,
219 SymbolResolverPtrT Resolver,
220 FinalizerFtor Finalizer,
221 bool ProcessAllSections) {
222 using LOS = ConcreteLinkedObject<MemoryManagerPtrT, SymbolResolverPtrT,
224 return llvm::make_unique<LOS>(std::move(Obj), std::move(MemMgr),
225 std::move(Resolver), std::move(Finalizer),
232 using MemoryManagerGetter =
233 std::function<std::shared_ptr<RuntimeDyld::MemoryManager>()>;
241 : GetMemMgr(GetMemMgr),
242 NotifyLoaded(std::move(NotifyLoaded)),
243 NotifyFinalized(std::move(NotifyFinalized)),
244 ProcessAllSections(
false) {}
253 this->ProcessAllSections = ProcessAllSections;
262 std::shared_ptr<JITSymbolResolver> Resolver) {
265 std::function<void()> LOSHandleLoad) {
266 std::unique_ptr<RuntimeDyld::LoadedObjectInfo> Info =
267 RTDyld.loadObject(*ObjToLoad->getBinary());
271 if (this->NotifyLoaded)
272 this->NotifyLoaded(H, ObjToLoad, *Info);
274 RTDyld.finalizeWithMemoryManagerLocking();
276 if (this->NotifyFinalized)
277 this->NotifyFinalized(H);
281 createLinkedObject(std::move(Obj), GetMemMgr(),
282 std::move(Resolver), std::move(Finalizer),
286 auto *LOPtr =
LO.get();
288 ObjHandleT Handle = LinkedObjList.insert(LinkedObjList.end(), std::move(
LO));
289 LOPtr->setHandle(Handle);
304 LinkedObjList.erase(H);
313 for (
auto I = LinkedObjList.begin(),
E = LinkedObjList.end();
I !=
E;
329 bool ExportedSymbolsOnly) {
330 return (*H)->getSymbol(Name, ExportedSymbolsOnly);
336 (*H)->mapSectionAddress(LocalAddress, TargetAddr);
349 LinkedObjectListT LinkedObjList;
350 MemoryManagerGetter GetMemMgr;
351 NotifyLoadedFtor NotifyLoaded;
352 NotifyFinalizedFtor NotifyFinalized;
353 bool ProcessAllSections =
false;
359 #endif // LLVM_EXECUTIONENGINE_ORC_RTDYLDOBJECTLINKINGLAYER_H
Error emitAndFinalize(ObjHandleT H)
Immediately emit and finalize the object set represented by the given handle.
Represents a symbol in the JIT.
std::shared_ptr< object::OwningBinary< object::ObjectFile >> ObjectPtr
JITSymbol getSymbol(StringRef Name, bool ExportedSymbolsOnly)
Holds a set of objects to be allocated/linked as a unit in the JIT.
std::list< std::unique_ptr< LinkedObject >> LinkedObjectListT
Bare bones object linking layer.
virtual void finalize()=0
LinkedObjectListT::iterator ObjHandleT
Handle to a set of loaded objects.
void mapSectionAddress(ObjHandleT H, const void *LocalAddress, JITTargetAddress TargetAddr)
Map section addresses for the objects associated with the handle H.
StringMap< JITEvaluatedSymbol > SymbolTable
std::function< std::shared_ptr< RuntimeDyld::MemoryManager >()> MemoryManagerGetter
Functor for creating memory managers.
Tagged union holding either a T or a Error.
Error removeObject(ObjHandleT H)
Remove the set of objects associated with handle H.
JITSymbol findSymbolIn(ObjHandleT H, StringRef Name, bool ExportedSymbolsOnly)
Search for the given named symbol in the context of the set of loaded objects represented by the hand...
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)
void setProcessAllSections(bool ProcessAllSections)
By default, only sections that are "required for execution" are passed to the RTDyldMemoryManager, and other sections are discarded.
Function Alias Analysis false
virtual ~LinkedObject()=default
virtual void mapSectionAddress(const void *LocalAddress, JITTargetAddress TargetAddr) const =0
static JITSymbolFlags fromObjectSymbol(const object::BasicSymbolRef &Symbol)
Construct a JITSymbolFlags value based on the flags of the given libobject symbol.
void consumeError(Error Err)
Consume a Error without doing anything.
static ErrorSuccess success()
Create a success value.
JITSymbol findSymbolIn(ModuleHandleT H, const std::string &Name, bool ExportedSymbolsOnly)
std::function< void(ObjHandleT, const ObjectPtr &Obj, const LoadedObjectInfo &)> NotifyLoadedFtor
Functor for receiving object-loaded notifications.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
An inferface for inquiring the load address of a loaded object file to be used by the DIContext imple...
void setProcessAllSections(bool ProcessAllSections)
Set the 'ProcessAllSections' flag.
virtual JITSymbol::GetAddressFtor getSymbolMaterializer(std::string Name)=0
std::function< Expected< JITTargetAddress >()> GetAddressFtor
static std::vector< std::string > Flags
JITSymbol findSymbol(StringRef Name, bool ExportedSymbolsOnly)
Search for the given named symbol.
RTDyldObjectLinkingLayer(MemoryManagerGetter GetMemMgr, NotifyLoadedFtor NotifyLoaded=NotifyLoadedFtor(), NotifyFinalizedFtor NotifyFinalized=NotifyFinalizedFtor())
Construct an ObjectLinkingLayer with the given NotifyLoaded, and NotifyFinalized functors.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Expected< ObjHandleT > addObject(ObjectPtr Obj, std::shared_ptr< JITSymbolResolver > Resolver)
Add a set of objects (or archives) that will be treated as a unit for the purposes of symbol lookup a...
Lightweight error class with error context and mandatory checking.
print Print MemDeps of function
StringRef - Represent a constant reference to a string, i.e.
std::function< void(ObjHandleT)> NotifyFinalizedFtor
Functor for receiving finalization notifications.
void operator=(const LinkedObject &)=delete