13#ifndef LLVM_EXECUTIONENGINE_ORC_ELFNIXPLATFORM_H
14#define LLVM_EXECUTIONENGINE_ORC_ELFNIXPLATFORM_H
25#include <unordered_map>
38 std::vector<std::pair<ExecutorAddr, ELFNixJITDylibDepInfo>>;
48 operator()(
const std::pair<RuntimeFunction *, RuntimeFunction *> &key)
const {
49 return std::hash<void *>()(key.first->Addr.toPtr<
void *>()) ^
50 std::hash<void *>()(key.second->Addr.toPtr<
void *>());
56 operator()(
const std::pair<RuntimeFunction *, RuntimeFunction *> &lhs,
57 const std::pair<RuntimeFunction *, RuntimeFunction *> &rhs)
const {
58 return lhs.first == rhs.first && lhs.second == rhs.second;
63 std::pair<RuntimeFunction *, RuntimeFunction *>,
111 std::unique_ptr<DefinitionGenerator> OrcRuntime,
112 std::optional<SymbolAliasMap> RuntimeAliases = std::nullopt);
117 const char *OrcRuntimePath,
118 std::optional<SymbolAliasMap> RuntimeAliases = std::nullopt);
140 standardRuntimeUtilityAliases();
145 standardLazyCompilationAliases();
149 struct BootstrapInfo {
151 std::condition_variable CV;
152 size_t ActiveGraphs = 0;
156 void addArgumentsToRTFnMap(
160 std::lock_guard<std::mutex> Lock(
Mutex);
161 auto &argList = DeferredRTFnMap[std::make_pair(func1, func2)];
162 argList.emplace_back(arg1, arg2);
169 class LLVM_ABI ELFNixPlatformPlugin :
public ObjectLinkingLayer::Plugin {
171 ELFNixPlatformPlugin(ELFNixPlatform &MP) : MP(MP) {}
173 void modifyPassConfig(MaterializationResponsibility &MR,
174 jitlink::LinkGraph &
G,
175 jitlink::PassConfiguration &
Config)
override;
179 Error notifyFailed(MaterializationResponsibility &MR)
override {
180 return Error::success();
183 Error notifyRemovingResources(JITDylib &JD, ResourceKey K)
override {
184 return Error::success();
187 void notifyTransferringResources(JITDylib &JD, ResourceKey DstKey,
188 ResourceKey SrcKey)
override {}
191 Error bootstrapPipelineStart(jitlink::LinkGraph &
G);
192 Error bootstrapPipelineRecordRuntimeFunctions(jitlink::LinkGraph &
G);
193 Error bootstrapPipelineEnd(jitlink::LinkGraph &
G);
195 void addDSOHandleSupportPasses(MaterializationResponsibility &MR,
196 jitlink::PassConfiguration &
Config);
198 void addEHAndTLVSupportPasses(MaterializationResponsibility &MR,
199 jitlink::PassConfiguration &
Config,
200 bool IsBootstrapping);
202 Error preserveInitSections(jitlink::LinkGraph &
G,
203 MaterializationResponsibility &MR);
205 Error registerInitSections(jitlink::LinkGraph &
G, JITDylib &JD,
206 bool IsBootstrapping);
208 Error fixTLVSectionsAndEdges(jitlink::LinkGraph &
G, JITDylib &JD);
210 std::mutex PluginMutex;
214 using PushInitializersSendResultFn =
215 unique_function<void(Expected<ELFNixJITDylibDepInfoMap>)>;
217 using SendSymbolAddressFn = unique_function<void(Expected<ExecutorAddr>)>;
219 static bool supportedTarget(
const Triple &TT);
221 ELFNixPlatform(ObjectLinkingLayer &ObjLinkingLayer, JITDylib &PlatformJD,
222 std::unique_ptr<DefinitionGenerator> OrcRuntimeGenerator,
226 Error associateRuntimeSupportFunctions(JITDylib &PlatformJD);
228 void pushInitializersLoop(PushInitializersSendResultFn SendResult,
231 void rt_recordInitializers(PushInitializersSendResultFn SendResult,
232 ExecutorAddr JDHeader);
234 void rt_lookupSymbol(SendSymbolAddressFn SendResult, ExecutorAddr Handle,
235 StringRef SymbolName);
237 Error registerPerObjectSections(jitlink::LinkGraph &
G,
238 const ELFPerObjectSectionsToRegister &POSR,
239 bool IsBootstrapping);
241 Expected<uint64_t> createPThreadKey();
243 ExecutionSession &ES;
244 JITDylib &PlatformJD;
245 ObjectLinkingLayer &ObjLinkingLayer;
247 SymbolStringPtr DSOHandleSymbol;
250 ES.intern(
"__orc_rt_elfnix_platform_bootstrap")};
252 ES.intern(
"__orc_rt_elfnix_platform_shutdown")};
254 ES.intern(
"__orc_rt_elfnix_register_jitdylib")};
256 ES.intern(
"__orc_rt_elfnix_deregister_jitdylib")};
258 ES.intern(
"__orc_rt_elfnix_register_object_sections")};
260 ES.intern(
"__orc_rt_elfnix_deregister_object_sections")};
262 ES.intern(
"__orc_rt_elfnix_register_init_sections")};
264 ES.intern(
"__orc_rt_elfnix_deregister_init_sections")};
266 ES.intern(
"__orc_rt_elfnix_create_pthread_key")};
268 DenseMap<JITDylib *, SymbolLookupSet> RegisteredInitSymbols;
272 std::mutex PlatformMutex;
273 std::vector<ELFPerObjectSectionsToRegister> BootstrapPOSRs;
275 DenseMap<ExecutorAddr, JITDylib *> HandleAddrToJITDylib;
276 DenseMap<JITDylib *, ExecutorAddr> JITDylibToHandleAddr;
277 DenseMap<JITDylib *, uint64_t> JITDylibToPThreadKey;
279 std::atomic<BootstrapInfo *> Bootstrap;
293 return SPSELFPerObjectSectionsToRegister::AsArgList::size(
299 return SPSELFPerObjectSectionsToRegister::AsArgList::serialize(
305 return SPSELFPerObjectSectionsToRegister::AsArgList::deserialize(
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Lightweight error class with error context and mandatory checking.
Tagged union holding either a T or a Error.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An ExecutionSession represents a running JIT program.
Represents an address in the executor process.
Represents a JIT'd dynamic library.
A MaterializationUnit represents a set of symbol definitions that can be materialized as a group,...
An ObjectLayer implementation built on JITLink.
API to remove / transfer ownership of JIT resources.
Pointer to a pooled string representing a symbol name.
Output char buffer with overflow check.
SPS tag type for sequences.
static bool serialize(SPSOutputBuffer &OB, const ELFPerObjectSectionsToRegister &MOPOSR)
static size_t size(const ELFPerObjectSectionsToRegister &MOPOSR)
static bool deserialize(SPSInputBuffer &IB, ELFPerObjectSectionsToRegister &MOPOSR)
Specialize to describe how to serialize/deserialize to/from the given concrete type.
SmallVector< char, 24 > ArgDataBufferType
RuntimeFunction
IDs for all omp runtime library (RTL) functions.
std::vector< std::pair< ExecutorAddr, ELFNixJITDylibDepInfo > > ELFNixJITDylibDepInfoMap
std::vector< ExecutorAddr > ELFNixJITDylibDepInfo
std::unordered_map< std::pair< RuntimeFunction *, RuntimeFunction * >, SmallVector< std::pair< shared::WrapperFunctionCall::ArgDataBufferType, shared::WrapperFunctionCall::ArgDataBufferType > >, FunctionPairKeyHash, FunctionPairKeyEqual > DeferredRuntimeFnMap
This is an optimization pass for GlobalISel generic memory operations.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Implement std::hash so that hash_code can be used in STL containers.
ExecutorAddrRange EHFrameSection
ExecutorAddrRange ThreadDataSection
Represents an address range in the exceutor process.
std::size_t operator()(const std::pair< RuntimeFunction *, RuntimeFunction * > &lhs, const std::pair< RuntimeFunction *, RuntimeFunction * > &rhs) const
std::size_t operator()(const std::pair< RuntimeFunction *, RuntimeFunction * > &key) const
RuntimeFunction(SymbolStringPtr Name)