14 #ifndef LLVM_EXECUTIONENGINE_ORC_EXECUTIONUTILS_H
15 #define LLVM_EXECUTIONENGINE_ORC_EXECUTIONUTILS_H
51 : Priority(Priority), Func(Func), Data(Data) {}
93 template <
typename JITLayerT>
100 : CtorDtorNames(std::move(CtorDtorNames)), H(H) {}
105 using CtorDtorTy = void (*)();
107 for (
const auto &CtorDtorName : CtorDtorNames)
108 if (
auto CtorDtorSym = JITLayer.findSymbolIn(H, CtorDtorName,
false)) {
109 if (
auto AddrOrErr = CtorDtorSym.getAddress()) {
110 CtorDtorTy CtorDtor =
111 reinterpret_cast<CtorDtorTy
>(
static_cast<uintptr_t
>(*AddrOrErr));
114 return AddrOrErr.takeError();
116 if (
auto Err = CtorDtorSym.takeError())
119 return make_error<JITSymbolNotFound>(CtorDtorName);
125 std::vector<std::string> CtorDtorNames;
147 template <
typename MangleFtorT>
149 addOverride(Mangle(
"__dso_handle"), toTargetAddress(&DSOHandleOverride));
150 addOverride(Mangle(
"__cxa_atexit"), toTargetAddress(&CXAAtExitOverride));
155 auto I = CXXRuntimeOverrides.
find(Name);
156 if (
I != CXXRuntimeOverrides.
end())
166 template <
typename PtrTy>
172 CXXRuntimeOverrides.
insert(std::make_pair(Name, Addr));
175 StringMap<JITTargetAddress> CXXRuntimeOverrides;
177 using DestructorPtr = void (*)(
void *);
178 using CXXDestructorDataPair = std::pair<DestructorPtr, void *>;
179 using CXXDestructorDataPairList = std::vector<CXXDestructorDataPair>;
180 CXXDestructorDataPairList DSOHandleOverride;
181 static int CXAAtExitOverride(DestructorPtr Destructor,
void *Arg,
189 #endif // LLVM_EXECUTIONENGINE_ORC_EXECUTIONUTILS_H
Accessor for an element of the global_ctors/global_dtors array.
A Module instance is used to store all the information related to an LLVM module. ...
CtorDtorRunner(std::vector< std::string > CtorDtorNames, typename JITLayerT::ModuleHandleT H)
Construct a CtorDtorRunner for the given range using the given name mangling function.
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
Element(unsigned Priority, Function *Func, Value *Data)
iterator find(StringRef Key)
void runDestructors()
Run any destructors recorded by the overriden __cxa_atexit function (CXAAtExitOverride).
CtorDtorIterator & operator++()
Pre-increment iterator.
JITEvaluatedSymbol searchOverrides(const std::string &Name)
Search overrided symbols.
Support class for static dtor execution.
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.
uint64_t JITTargetAddress
Represents an address in the target process's address space.
Convenience class for recording constructor/destructor names for later execution. ...
static const unsigned End
static ErrorSuccess success()
Create a success value.
This iterator provides a convenient way to iterate over the elements of an llvm.global_ctors/llvm.global_dtors instance.
bool operator!=(const CtorDtorIterator &Other) const
Test iterators for inequality.
bool operator==(const CtorDtorIterator &Other) const
Test iterators for equality.
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
A range adaptor for a pair of iterators.
ConstantArray - Constant Array Declarations.
Element operator*() const
Dereference iterator.
Represents a symbol that has been evaluated to an address already.
LocalCXXRuntimeOverrides(const MangleFtorT &Mangle)
Create a runtime-overrides class.
Error runViaLayer(JITLayerT &JITLayer) const
Run the recorded constructors/destructors through the given JIT layer.
iterator_range< CtorDtorIterator > getConstructors(const Module &M)
Create an iterator range over the entries of the llvm.global_ctors array.
LLVM Value Representation.
Lightweight error class with error context and mandatory checking.