13 #ifndef LLVM_EXECUTIONENGINE_ORC_EXECUTIONUTILS_H 14 #define LLVM_EXECUTIONENGINE_ORC_EXECUTIONUTILS_H 51 int runAsMain(
int (*Main)(
int,
char *[]), ArrayRef<std::string>
Args,
52 Optional<StringRef> ProgramName =
None);
67 : Priority(Priority), Func(Func), Data(Data) {}
109 template <
typename JITLayerT>
117 "ORCv1 utilities (utilities with the 'Legacy' prefix) are deprecated. " 118 "Please use the ORCv2 CtorDtorRunner utility instead");
121 std::vector<std::string> CtorDtorNames,
VModuleKey K)
122 : CtorDtorNames(
std::move(CtorDtorNames)), K(K) {}
127 using CtorDtorTy = void (*)();
130 if (
auto CtorDtorSym = JITLayer.findSymbolIn(K,
CtorDtorName,
false)) {
131 if (
auto AddrOrErr = CtorDtorSym.getAddress()) {
132 CtorDtorTy CtorDtor =
133 reinterpret_cast<CtorDtorTy
>(
static_cast<uintptr_t
>(*AddrOrErr));
136 return AddrOrErr.takeError();
138 if (
auto Err = CtorDtorSym.takeError())
148 std::vector<std::string> CtorDtorNames;
152 template <
typename JITLayerT>
154 std::vector<std::string> CtorDtorNames,
VModuleKey K)
155 : CtorDtorNames(std::move(CtorDtorNames)), K(K) {}
164 using CtorDtorList = std::vector<SymbolStringPtr>;
165 using CtorDtorPriorityMap = std::map<unsigned, CtorDtorList>;
168 CtorDtorPriorityMap CtorDtorsByPriority;
190 void runDestructors();
208 template <
typename MangleFtorT>
211 "ORCv1 utilities (utilities with the 'Legacy' prefix) are deprecated. " 212 "Please use the ORCv2 LocalCXXRuntimeOverrides utility instead");
214 template <
typename MangleFtorT>
216 const MangleFtorT &Mangle) {
217 addOverride(Mangle(
"__dso_handle"), toTargetAddress(&DSOHandleOverride));
218 addOverride(Mangle(
"__cxa_atexit"), toTargetAddress(&CXAAtExitOverride));
223 auto I = CXXRuntimeOverrides.find(Name);
224 if (
I != CXXRuntimeOverrides.end())
231 CXXRuntimeOverrides.insert(std::make_pair(Name, Addr));
237 template <
typename MangleFtorT>
239 const MangleFtorT &Mangle) {
240 addOverride(Mangle(
"__dso_handle"), toTargetAddress(&DSOHandleOverride));
241 addOverride(Mangle(
"__cxa_atexit"), toTargetAddress(&CXAAtExitOverride));
271 Load(
const char *FileName,
char GlobalPrefix,
279 return Load(
nullptr, GlobalPrefix, std::move(Allow));
310 Create(
ObjectLayer &L, std::unique_ptr<MemoryBuffer> ArchiveBuffer);
318 std::unique_ptr<MemoryBuffer> ArchiveBuffer,
322 std::unique_ptr<MemoryBuffer> ArchiveBuffer;
323 std::unique_ptr<object::Archive> Archive;
329 #endif // LLVM_EXECUTIONENGINE_ORC_EXECUTIONUTILS_H JITTargetAddress toTargetAddress(PtrTy *P)
Accessor for an element of the global_ctors/global_dtors array.
LookupKind
Describes the kind of lookup being performed.
This class represents lattice values for constants.
bool operator==(const CtorDtorIterator &Other) const
Test iterators for equality.
A Module instance is used to store all the information related to an LLVM module. ...
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
JITEvaluatedSymbol searchOverrides(const std::string &Name)
Search overrided symbols.
Convenience class for recording constructor/destructor names for later execution. ...
std::function< bool(const SymbolStringPtr &)> SymbolPredicate
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
Element(unsigned Priority, Function *Func, Value *Data)
std::vector< CXXDestructorDataPair > CXXDestructorDataPairList
void(*)(void *) DestructorPtr
CtorDtorIterator & operator++()
Pre-increment iterator.
A utility class to expose symbols from a static library.
Mangles symbol names then uniques them in the context of an ExecutionSession.
Tagged union holding either a T or a Error.
This class provides a portable interface to dynamic libraries which also might be known as shared lib...
CXXDestructorDataPairList DSOHandleOverride
iterator_range< CtorDtorIterator > getDestructors(const Module &M)
Create an iterator range over the entries of the llvm.global_ctors array.
CtorDtorIterator(const GlobalVariable *GV, bool End)
Construct an iterator instance.
ORCv1DeprecationAcknowledgement
uint64_t JITTargetAddress
Represents an address in the target process's address space.
CtorDtorRunner(JITDylib &JD)
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Support class for static dtor execution.
Definition generators can be attached to JITDylibs to generate new definitions for otherwise unresolv...
std::pair< DestructorPtr, void * > CXXDestructorDataPair
#define LLVM_ATTRIBUTE_DEPRECATED(decl, message)
static ErrorSuccess success()
Create a success value.
A utility class to expose symbols found via dlsym to the JIT.
static uint64_t add(uint64_t LeftOp, uint64_t RightOp)
This iterator provides a convenient way to iterate over the elements of an llvm.global_ctors/llvm.global_dtors instance.
A set of symbols to look up, each associated with a SymbolLookupFlags value.
LegacyCtorDtorRunner(ORCv1DeprecationAcknowledgement, std::vector< std::string > CtorDtorNames, VModuleKey K)
A range adaptor for a pair of iterators.
ConstantArray - Constant Array Declarations.
Represents a symbol that has been evaluated to an address already.
uint8_t uint64_t VModuleKey
VModuleKey provides a unique identifier (allocated and managed by ExecutionSessions) for a module add...
iterator_range< CtorDtorIterator > getConstructors(const Module &M)
Create an iterator range over the entries of the llvm.global_ctors array.
int runAsMain(int(*Main)(int, char *[]), ArrayRef< std::string > Args, Optional< StringRef > ProgramName=None)
Run a main function, returning the result.
LLVM Value Representation.
Element operator*() const
Dereference iterator.
Lightweight error class with error context and mandatory checking.
Interface for Layers that accept object files.
bool operator!=(const CtorDtorIterator &Other) const
Test iterators for inequality.
LegacyLocalCXXRuntimeOverrides(ORCv1DeprecationAcknowledgement, const MangleFtorT &Mangle)
static Expected< std::unique_ptr< DynamicLibrarySearchGenerator > > GetForCurrentProcess(char GlobalPrefix, SymbolPredicate Allow=SymbolPredicate())
Creates a DynamicLibrarySearchGenerator that searches for symbols in the current process.
JITDylibLookupFlags
Lookup flags that apply to each dylib in the search order for a lookup.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Error runViaLayer(JITLayerT &JITLayer) const
Run the recorded constructors/destructors through the given JIT layer.
A symbol table that supports asynchoronous symbol queries.