14 #ifndef LLVM_EXECUTIONENGINE_ORC_OBJECTLINKINGLAYER_H
15 #define LLVM_EXECUTIONENGINE_ORC_OBJECTLINKINGLAYER_H
66 if (!
SymEntry->second.getFlags().isExported() && ExportedSymbolsOnly)
89 template <
typename ObjSetT,
typename LoadResult>
91 const LoadResult &) {}
100 template <
typename NotifyLoadedFtor = DoNothingOnNotifyLoaded>
107 template <
typename ObjSetT,
typename MemoryManagerPtrT,
108 typename SymbolResolverPtrT,
typename FinalizerFtor>
111 ConcreteLinkedObjectSet(ObjSetT Objects, MemoryManagerPtrT MemMgr,
112 SymbolResolverPtrT Resolver,
113 FinalizerFtor Finalizer,
114 bool ProcessAllSections)
115 : MemMgr(std::move(MemMgr)),
116 PFC(llvm::make_unique<PreFinalizeContents>(std::move(Objects),
118 std::move(Finalizer),
119 ProcessAllSections)) {
120 buildInitialSymbolTable(PFC->Objects);
127 void finalize()
override {
128 assert(PFC &&
"mapSectionAddress called on finalized LinkedObjectSet");
132 PFC->RTDyld = &RTDyld;
134 this->Finalized =
true;
135 PFC->Finalizer(PFC->Handle, RTDyld, std::move(PFC->Objects),
137 this->updateSymbolTable(RTDyld);
149 if (!this->Finalized)
151 return this->
getSymbol(Name,
false).getAddress();
157 assert(PFC &&
"mapSectionAddress called on finalized LinkedObjectSet");
158 assert(PFC->RTDyld &&
"mapSectionAddress called on raw LinkedObjectSet");
159 PFC->RTDyld->mapSectionAddress(LocalAddress, TargetAddr);
163 void buildInitialSymbolTable(
const ObjSetT &Objects) {
164 for (
const auto &Obj : Objects)
168 Expected<StringRef> SymbolName =
Symbol.getName();
176 std::make_pair(*SymbolName, JITEvaluatedSymbol(0,
Flags)));
180 void updateSymbolTable(
const RuntimeDyld &RTDyld) {
181 for (
auto &SymEntry : SymbolTable)
182 SymEntry.second = RTDyld.getSymbol(SymEntry.first());
187 struct PreFinalizeContents {
188 PreFinalizeContents(ObjSetT Objects, SymbolResolverPtrT Resolver,
189 FinalizerFtor Finalizer,
bool ProcessAllSections)
190 : Objects(std::move(Objects)), Resolver(std::move(Resolver)),
191 Finalizer(std::move(Finalizer)),
192 ProcessAllSections(ProcessAllSections) {}
195 SymbolResolverPtrT Resolver;
196 FinalizerFtor Finalizer;
197 bool ProcessAllSections;
202 MemoryManagerPtrT MemMgr;
203 std::unique_ptr<PreFinalizeContents> PFC;
206 template <
typename ObjSetT,
typename MemoryManagerPtrT,
207 typename SymbolResolverPtrT,
typename FinalizerFtor>
209 ConcreteLinkedObjectSet<ObjSetT, MemoryManagerPtrT,
210 SymbolResolverPtrT, FinalizerFtor>>
211 createLinkedObjectSet(ObjSetT Objects, MemoryManagerPtrT MemMgr,
212 SymbolResolverPtrT Resolver,
213 FinalizerFtor Finalizer,
214 bool ProcessAllSections) {
215 typedef ConcreteLinkedObjectSet<ObjSetT, MemoryManagerPtrT,
216 SymbolResolverPtrT, FinalizerFtor> LOS;
217 return llvm::make_unique<LOS>(std::move(Objects), std::move(MemMgr),
218 std::move(Resolver), std::move(Finalizer),
225 typedef std::vector<std::unique_ptr<RuntimeDyld::LoadedObjectInfo>>
231 NotifyLoadedFtor NotifyLoaded = NotifyLoadedFtor(),
233 : NotifyLoaded(std::move(NotifyLoaded)),
234 NotifyFinalized(std::move(NotifyFinalized)),
235 ProcessAllSections(
false) {}
244 this->ProcessAllSections = ProcessAllSections;
252 template <
typename ObjSetT,
253 typename MemoryManagerPtrT,
254 typename SymbolResolverPtrT>
256 MemoryManagerPtrT MemMgr,
257 SymbolResolverPtrT Resolver) {
260 std::function<void()> LOSHandleLoad) {
263 for (
auto &Obj : Objs)
264 LoadedObjInfos.push_back(RTDyld.loadObject(this->getObject(*Obj)));
268 this->NotifyLoaded(H, Objs, LoadedObjInfos);
270 RTDyld.finalizeWithMemoryManagerLocking();
272 if (this->NotifyFinalized)
273 this->NotifyFinalized(H);
277 createLinkedObjectSet(std::move(Objects), std::move(MemMgr),
278 std::move(Resolver), std::move(Finalizer),
282 auto *LOSPtr = LOS.get();
284 ObjSetHandleT Handle = LinkedObjSetList.insert(LinkedObjSetList.end(),
286 LOSPtr->setHandle(Handle);
301 LinkedObjSetList.erase(H);
309 for (
auto I = LinkedObjSetList.begin(),
E = LinkedObjSetList.end();
I !=
E;
311 if (
auto Symbol = findSymbolIn(
I, Name, ExportedSymbolsOnly))
325 bool ExportedSymbolsOnly) {
326 return (*H)->getSymbol(Name, ExportedSymbolsOnly);
332 (*H)->mapSectionAddress(LocalAddress, TargetAddr);
347 template <
typename ObjT>
353 LinkedObjectSetListT LinkedObjSetList;
354 NotifyLoadedFtor NotifyLoaded;
355 NotifyFinalizedFtor NotifyFinalized;
356 bool ProcessAllSections;
362 #endif // LLVM_EXECUTIONENGINE_ORC_OBJECTLINKINGLAYER_H
virtual void finalize()=0
Represents a symbol in the JIT.
ObjectLinkingLayer(NotifyLoadedFtor NotifyLoaded=NotifyLoadedFtor(), NotifyFinalizedFtor NotifyFinalized=NotifyFinalizedFtor())
Construct an ObjectLinkingLayer with the given NotifyLoaded, and NotifyFinalized functors.
ObjSetHandleT addObjectSet(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...
JITSymbol findSymbol(StringRef Name, bool ExportedSymbolsOnly)
Search for the given named symbol.
static std::error_code getObject(const T *&Obj, MemoryBufferRef M, const void *Ptr, const uint64_t Size=sizeof(T))
symbol_iterator_range symbols() const
This class is the base class for all object file types.
struct fuzzer::@269 Flags
virtual ~LinkedObjectSet()=default
Bare bones object linking layer.
Function Alias Analysis false
StringMap< JITEvaluatedSymbol > SymbolTable
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.
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
JITSymbol getSymbol(StringRef Name, bool ExportedSymbolsOnly)
std::function< JITTargetAddress()> GetAddressFtor
std::list< std::unique_ptr< LinkedObjectSet > > LinkedObjectSetListT
virtual void mapSectionAddress(const void *LocalAddress, JITTargetAddress TargetAddr) const =0
void removeObjectSet(ObjSetHandleT H)
Remove the set of objects associated with handle H.
void mapSectionAddress(ObjSetHandleT H, const void *LocalAddress, JITTargetAddress TargetAddr)
Map section addresses for the objects associated with the handle H.
Holds a set of objects to be allocated/linked as a unit in the JIT.
static JITSymbolFlags fromObjectSymbol(const object::BasicSymbolRef &Symbol)
Construct a JITSymbolFlags value based on the flags of the given libobject symbol.
uint64_t JITTargetAddress
Represents an address in the target process's address space.
void operator=(const LinkedObjectSet &)=delete
void consumeError(Error Err)
Consume a Error without doing anything.
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...
LinkedObjectSet()=default
Default (no-op) action to perform when loading objects.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
virtual JITSymbol::GetAddressFtor getSymbolMaterializer(std::string Name)=0
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 &)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
std::vector< std::unique_ptr< RuntimeDyld::LoadedObjectInfo > > LoadedObjInfoList
LoadedObjectInfo list.
void setProcessAllSections(bool ProcessAllSections)
Set the 'ProcessAllSections' flag.
StringRef - Represent a constant reference to a string, i.e.
LinkedObjectSetListT::iterator ObjSetHandleT
Handle to a set of loaded objects.