13#ifndef LLVM_EXECUTIONENGINE_ORC_EXECUTIONUTILS_H
14#define LLVM_EXECUTIONENGINE_ORC_EXECUTIONUTILS_H
107 : I(M.global_values().begin()), E(M.global_values().end()),
108 ObjFmt(M.getTargetTriple().getObjectFormat()) {
110 if (!isStaticInitGlobal(*I))
111 moveToNextStaticInitGlobal();
120 assert(I != E &&
"Increment past end of range");
121 moveToNextStaticInitGlobal();
129 void moveToNextStaticInitGlobal() {
131 while (
I !=
E && !isStaticInitGlobal(*
I))
154 using CtorDtorList = std::vector<SymbolStringPtr>;
155 using CtorDtorPriorityMap = std::map<unsigned, CtorDtorList>;
158 CtorDtorPriorityMap CtorDtorsByPriority;
208 std::mutex AtExitsMutex;
240 Load(
const char *FileName,
char GlobalPrefix,
250 return Load(
nullptr, GlobalPrefix, std::move(Allow),
251 std::move(AddAbsoluteSymbols));
260 SymbolPredicate Allow;
261 AddAbsoluteSymbolsFn AddAbsoluteSymbols;
301 static std::unique_ptr<MemoryBuffer>
318 std::unique_ptr<object::Archive> Archive,
339 StaticLibraryDefinitionGenerator(
340 ObjectLayer &L, std::unique_ptr<MemoryBuffer> ArchiveBuffer,
341 std::unique_ptr<object::Archive> Archive,
347 std::unique_ptr<MemoryBuffer> ArchiveBuffer;
348 std::unique_ptr<object::Archive> Archive;
362 static std::unique_ptr<DLLImportDefinitionGenerator>
378 static StringRef getImpPrefix() {
return "__imp_"; }
380 static StringRef getSectionName() {
return "$__DLLIMPORT_STUBS"; }
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
ConstantArray - Constant Array Declarations.
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
A Module instance is used to store all the information related to an LLVM module.
concat_iterator< GlobalValue, iterator, global_iterator, alias_iterator, ifunc_iterator > global_value_iterator
StringRef - Represent a constant reference to a string, i.e.
Triple - Helper class for working with autoconf configuration names.
LLVM Value Representation.
A range adaptor for a pair of iterators.
LLVM_ABI bool operator!=(const CtorDtorIterator &Other) const
Test iterators for inequality.
LLVM_ABI Element operator*() const
Dereference iterator.
LLVM_ABI CtorDtorIterator(const GlobalVariable *GV, bool End)
Construct an iterator instance.
LLVM_ABI CtorDtorIterator & operator++()
Pre-increment iterator.
LLVM_ABI bool operator==(const CtorDtorIterator &Other) const
Test iterators for equality.
CtorDtorRunner(JITDylib &JD)
LLVM_ABI void add(iterator_range< CtorDtorIterator > CtorDtors)
static std::unique_ptr< DLLImportDefinitionGenerator > Create(ExecutionSession &ES, ObjectLinkingLayer &L)
Creates a DLLImportDefinitionGenerator instance.
Error tryToGenerate(LookupState &LS, LookupKind K, JITDylib &JD, JITDylibLookupFlags JDLookupFlags, const SymbolLookupSet &Symbols) override
DefinitionGenerators should override this method to insert new definitions into the parent JITDylib.
Definition generators can be attached to JITDylibs to generate new definitions for otherwise unresolv...
friend class ExecutionSession
std::function< bool(const SymbolStringPtr &)> SymbolPredicate
unique_function< Error(JITDylib &, SymbolMap)> AddAbsoluteSymbolsFn
DynamicLibrarySearchGenerator(sys::DynamicLibrary Dylib, char GlobalPrefix, SymbolPredicate Allow=SymbolPredicate(), AddAbsoluteSymbolsFn AddAbsoluteSymbols=nullptr)
Create a DynamicLibrarySearchGenerator that searches for symbols in the given sys::DynamicLibrary.
static Expected< std::unique_ptr< DynamicLibrarySearchGenerator > > Load(const char *FileName, char GlobalPrefix, SymbolPredicate Allow=SymbolPredicate(), AddAbsoluteSymbolsFn AddAbsoluteSymbols=nullptr)
Permanently loads the library at the given path and, on success, returns a DynamicLibrarySearchGenera...
static Expected< std::unique_ptr< DynamicLibrarySearchGenerator > > GetForCurrentProcess(char GlobalPrefix, SymbolPredicate Allow=SymbolPredicate(), AddAbsoluteSymbolsFn AddAbsoluteSymbols=nullptr)
Creates a DynamicLibrarySearchGenerator that searches for symbols in the current process.
An interface for Itanium __cxa_atexit interposer implementations.
LLVM_ABI void runAtExits(void *DSOHandle)
LLVM_ABI void registerAtExit(void(*F)(void *), void *Ctx, void *DSOHandle)
Represents a JIT'd dynamic library.
Support class for static dtor execution.
void(*)(void *) DestructorPtr
static LLVM_ABI int CXAAtExitOverride(DestructorPtr Destructor, void *Arg, void *DSOHandle)
std::vector< CXXDestructorDataPair > CXXDestructorDataPairList
CXXDestructorDataPairList DSOHandleOverride
std::pair< DestructorPtr, void * > CXXDestructorDataPair
LLVM_ABI void runDestructors()
Run any destructors recorded by the overriden __cxa_atexit function (CXAAtExitOverride).
LLVM_ABI Error enable(JITDylib &JD, MangleAndInterner &Mangler)
Wraps state for a lookup-in-progress.
Mangles symbol names then uniques them in the context of an ExecutionSession.
Interface for Layers that accept object files.
An ObjectLayer implementation built on JITLink.
This iterator provides a convenient way to iterate over GlobalValues that have initialization effects...
StaticInitGVIterator()=default
GlobalValue & operator*()
StaticInitGVIterator & operator++()
bool operator!=(const StaticInitGVIterator &O) const
bool operator==(const StaticInitGVIterator &O) const
StaticInitGVIterator(Module &M)
static VisitMembersFunction loadAllObjectFileMembers(ObjectLayer &L, JITDylib &JD)
A VisitMembersFunction that unconditionally loads all object files from the archive.
unique_function< Expected< MaterializationUnit::Interface >( ExecutionSession &ES, MemoryBufferRef ObjBuffer)> GetObjectFileInterface
Interface builder function for objects loaded from this archive.
unique_function< Expected< bool >( object::Archive &, MemoryBufferRef, size_t)> VisitMembersFunction
Callback for visiting archive members at construction time.
Error tryToGenerate(LookupState &LS, LookupKind K, JITDylib &JD, JITDylibLookupFlags JDLookupFlags, const SymbolLookupSet &Symbols) override
DefinitionGenerators should override this method to insert new definitions into the parent JITDylib.
static Expected< std::unique_ptr< StaticLibraryDefinitionGenerator > > Create(ObjectLayer &L, std::unique_ptr< MemoryBuffer > ArchiveBuffer, std::unique_ptr< object::Archive > Archive, VisitMembersFunction VisitMembers=VisitMembersFunction(), GetObjectFileInterface GetObjFileInterface=GetObjectFileInterface())
Try to create a StaticLibrarySearchGenerator from the given memory buffer and Archive object.
static Expected< std::unique_ptr< StaticLibraryDefinitionGenerator > > Load(ObjectLayer &L, const char *FileName, VisitMembersFunction VisitMembers=VisitMembersFunction(), GetObjectFileInterface GetObjFileInterface=GetObjectFileInterface())
Try to create a StaticLibraryDefinitionGenerator from the given path.
static std::unique_ptr< MemoryBuffer > createMemberBuffer(object::Archive &A, MemoryBufferRef BufRef, size_t Index)
A set of symbols to look up, each associated with a SymbolLookupFlags value.
Pointer to a pooled string representing a symbol name.
This class provides a portable interface to dynamic libraries which also might be known as shared lib...
unique_function is a type-erasing functor similar to std::function.
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
LLVM_ABI iterator_range< CtorDtorIterator > getDestructors(const Module &M)
Create an iterator range over the entries of the llvm.global_ctors array.
iterator_range< StaticInitGVIterator > getStaticInitGVs(Module &M)
Create an iterator range over the GlobalValues that contribute to static initialization.
LLVM_ABI iterator_range< CtorDtorIterator > getConstructors(const Module &M)
Create an iterator range over the entries of the llvm.global_ctors array.
JITDylibLookupFlags
Lookup flags that apply to each dylib in the search order for a lookup.
DenseMap< SymbolStringPtr, ExecutorSymbolDef > SymbolMap
A map from symbol names (as SymbolStringPtrs) to JITSymbols (address/flags pairs).
LookupKind
Describes the kind of lookup being performed.
@ Resolved
Queried, materialization begun.
This is an optimization pass for GlobalISel generic memory operations.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Accessor for an element of the global_ctors/global_dtors array.
Element(unsigned Priority, Function *Func, Value *Data)