14 #ifndef LLVM_EXECUTIONENGINE_ORC_OBJECTLINKINGLAYER_H
15 #define LLVM_EXECUTIONENGINE_ORC_OBJECTLINKINGLAYER_H
48 std::unique_ptr<RuntimeDyld::LoadedObjectInfo>
50 return RTDyld->loadObject(Obj);
54 return RTDyld->getSymbol(Name);
63 "Attempting to remap sections for finalized objects.");
64 RTDyld->mapSectionAddress(LocalAddress, TargetAddr);
90 template <
typename OwningMBSet>
93 (*H)->takeOwnershipOfBuffer(std::move(MB));
101 template <
typename ObjSetT,
typename LoadResult>
103 const LoadResult &) {}
112 template <
typename NotifyLoadedFtor = DoNothingOnNotifyLoaded>
116 template <
typename MemoryManagerPtrT,
typename SymbolResolverPtrT>
119 ConcreteLinkedObjectSet(MemoryManagerPtrT MemMgr,
120 SymbolResolverPtrT Resolver)
122 Resolver(std::move(Resolver)) { }
124 void Finalize()
override {
126 RTDyld->resolveRelocations();
127 RTDyld->registerEHFrames();
128 MemMgr->finalizeMemory();
129 OwnedBuffers.clear();
134 MemoryManagerPtrT MemMgr;
135 SymbolResolverPtrT Resolver;
138 template <
typename MemoryManagerPtrT,
typename SymbolResolverPtrT>
139 std::unique_ptr<LinkedObjectSet>
140 createLinkedObjectSet(MemoryManagerPtrT MemMgr, SymbolResolverPtrT Resolver) {
141 typedef ConcreteLinkedObjectSet<MemoryManagerPtrT, SymbolResolverPtrT> LOS;
142 return llvm::make_unique<LOS>(std::move(MemMgr), std::move(Resolver));
149 typedef std::vector<std::unique_ptr<RuntimeDyld::LoadedObjectInfo>>
158 NotifyLoadedFtor NotifyLoaded = NotifyLoadedFtor(),
160 : NotifyLoaded(std::move(NotifyLoaded)),
161 NotifyFinalized(std::move(NotifyFinalized)) {}
174 template <
typename ObjSetT,
175 typename MemoryManagerPtrT,
176 typename SymbolResolverPtrT>
178 MemoryManagerPtrT MemMgr,
179 SymbolResolverPtrT Resolver) {
181 LinkedObjSetList.insert(
182 LinkedObjSetList.end(),
183 createLinkedObjectSet(std::move(MemMgr), std::move(Resolver)));
188 for (
auto &Obj : Objects)
189 LoadedObjInfos.push_back(LOS.
addObject(*Obj));
191 NotifyLoaded(Handle, Objects, LoadedObjInfos);
206 LinkedObjSetList.erase(H);
214 for (
auto I = LinkedObjSetList.begin(), E = LinkedObjSetList.end();
I != E;
230 bool ExportedSymbolsOnly) {
231 if (
auto Sym = (*H)->getSymbol(Name)) {
232 if (Sym.isExported() || !ExportedSymbolsOnly) {
234 auto Flags = Sym.getFlags();
235 if (!(*H)->NeedsFinalization()) {
246 if ((*H)->NeedsFinalization()) {
263 (*H)->mapSectionAddress(LocalAddress, TargetAddr);
277 NotifyLoadedFtor NotifyLoaded;
284 #endif // LLVM_EXECUTIONENGINE_ORC_OBJECTLINKINGLAYER_H
ObjectLinkingLayer(NotifyLoadedFtor NotifyLoaded=NotifyLoadedFtor(), NotifyFinalizedFtor NotifyFinalized=NotifyFinalizedFtor())
Construct an ObjectLinkingLayer with the given NotifyLoaded, and NotifyFinalized functors.
JITSymbol findSymbol(StringRef Name, bool ExportedSymbolsOnly)
Search for the given named symbol.
TargetAddress getAddress()
Get the address of the symbol in the target address space.
This class is the base class for all object file types.
ObjSetHandleT addObjectSet(const ObjSetT &Objects, MemoryManagerPtrT MemMgr, SymbolResolverPtrT Resolver)
Add a set of objects (or archives) that will be treated as a unit for the purposes of symbol lookup a...
RuntimeDyld::SymbolInfo getSymbol(StringRef Name) const
virtual ~LinkedObjectSet()
void mapSectionAddress(ObjSetHandleT H, const void *LocalAddress, TargetAddress TargetAddr)
Map section addresses for the objects associated with the handle H.
std::vector< std::unique_ptr< MemoryBuffer > > OwnedBuffers
Bare bones object linking layer.
virtual void Finalize()=0
std::unique_ptr< RuntimeDyld::LoadedObjectInfo > addObject(const object::ObjectFile &Obj)
std::enable_if<!std::is_array< T >::value, std::unique_ptr< T > >::type make_unique(Args &&...args)
Constructs a new T() with the given args and returns a unique_ptr<T> which owns the object...
std::list< std::unique_ptr< LinkedObjectSet > > LinkedObjectSetListT
void removeObjectSet(ObjSetHandleT H)
Remove the set of objects associated with handle H.
bool NeedsFinalization() const
Represents a symbol in the JIT.
Holds a set of objects to be allocated/linked as a unit in the JIT.
std::unique_ptr< RuntimeDyld > RTDyld
void takeOwnershipOfBuffers(ObjSetHandleT H, OwningMBSet MBs)
JITSymbol findSymbolIn(ObjSetHandleT H, StringRef Name, bool ExportedSymbolsOnly)
Search for the given named symbol in the context of the set of loaded objects represented by the hand...
Default (no-op) action to perform when loading objects.
uint64_t TargetAddress
Represents an address in the target process's address space.
std::function< void(ObjSetHandleT)> NotifyFinalizedFtor
Functor for receiving finalization notifications.
void emitAndFinalize(ObjSetHandleT H)
Immediately emit and finalize the object set represented by the given handle.
void operator()(ObjectLinkingLayerBase::ObjSetHandleT, const ObjSetT &, const LoadResult &)
Information about a named symbol.
std::vector< std::unique_ptr< RuntimeDyld::LoadedObjectInfo > > LoadedObjInfoList
LoadedObjectInfo list.
void takeOwnershipOfBuffer(std::unique_ptr< MemoryBuffer > B)
enum llvm::orc::ObjectLinkingLayerBase::LinkedObjectSet::@57 State
StringRef - Represent a constant reference to a string, i.e.
void mapSectionAddress(const void *LocalAddress, TargetAddress TargetAddr)
LinkedObjectSet(RuntimeDyld::MemoryManager &MemMgr, RuntimeDyld::SymbolResolver &Resolver)
LinkedObjectSetListT::iterator ObjSetHandleT
Handle to a set of loaded objects.