13#ifndef LLVM_EXECUTIONENGINE_ORC_ELFNIXPLATFORM_H
14#define LLVM_EXECUTIONENGINE_ORC_ELFNIXPLATFORM_H
24#include <unordered_map>
37 std::vector<std::pair<ExecutorAddr, ELFNixJITDylibDepInfo>>;
47 operator()(
const std::pair<RuntimeFunction *, RuntimeFunction *> &key)
const {
48 return std::hash<void *>()(key.first->Addr.toPtr<
void *>()) ^
49 std::hash<void *>()(key.second->Addr.toPtr<
void *>());
55 operator()(
const std::pair<RuntimeFunction *, RuntimeFunction *> &lhs,
56 const std::pair<RuntimeFunction *, RuntimeFunction *> &rhs)
const {
57 return lhs.first == rhs.first && lhs.second == rhs.second;
62 std::pair<RuntimeFunction *, RuntimeFunction *>,
110 std::unique_ptr<DefinitionGenerator> OrcRuntime,
111 std::optional<SymbolAliasMap> RuntimeAliases = std::nullopt);
116 const char *OrcRuntimePath,
117 std::optional<SymbolAliasMap> RuntimeAliases = std::nullopt);
148 struct BootstrapInfo {
150 std::condition_variable CV;
151 size_t ActiveGraphs = 0;
155 void addArgumentsToRTFnMap(
159 std::lock_guard<std::mutex> Lock(
Mutex);
160 auto &argList = DeferredRTFnMap[std::make_pair(func1, func2)];
161 argList.emplace_back(arg1, arg2);
168 class ELFNixPlatformPlugin :
public ObjectLinkingLayer::Plugin {
170 ELFNixPlatformPlugin(ELFNixPlatform &MP) : MP(MP) {}
172 void modifyPassConfig(MaterializationResponsibility &MR,
173 jitlink::LinkGraph &
G,
174 jitlink::PassConfiguration &
Config)
override;
178 Error notifyFailed(MaterializationResponsibility &MR)
override {
186 void notifyTransferringResources(JITDylib &JD,
ResourceKey DstKey,
190 Error bootstrapPipelineStart(jitlink::LinkGraph &
G);
191 Error bootstrapPipelineRecordRuntimeFunctions(jitlink::LinkGraph &
G);
192 Error bootstrapPipelineEnd(jitlink::LinkGraph &
G);
194 void addDSOHandleSupportPasses(MaterializationResponsibility &MR,
195 jitlink::PassConfiguration &
Config);
197 void addEHAndTLVSupportPasses(MaterializationResponsibility &MR,
198 jitlink::PassConfiguration &
Config,
199 bool IsBootstrapping);
201 Error preserveInitSections(jitlink::LinkGraph &
G,
202 MaterializationResponsibility &MR);
204 Error registerInitSections(jitlink::LinkGraph &
G, JITDylib &JD,
205 bool IsBootstrapping);
207 Error fixTLVSectionsAndEdges(jitlink::LinkGraph &
G, JITDylib &JD);
209 std::mutex PluginMutex;
213 using PushInitializersSendResultFn =
214 unique_function<void(Expected<ELFNixJITDylibDepInfoMap>)>;
216 using SendSymbolAddressFn = unique_function<void(Expected<ExecutorAddr>)>;
218 static bool supportedTarget(
const Triple &TT);
220 ELFNixPlatform(ObjectLinkingLayer &ObjLinkingLayer, JITDylib &PlatformJD,
221 std::unique_ptr<DefinitionGenerator> OrcRuntimeGenerator,
225 Error associateRuntimeSupportFunctions(JITDylib &PlatformJD);
227 void pushInitializersLoop(PushInitializersSendResultFn SendResult,
230 void rt_recordInitializers(PushInitializersSendResultFn SendResult,
231 ExecutorAddr JDHeader);
233 void rt_lookupSymbol(SendSymbolAddressFn SendResult, ExecutorAddr Handle,
234 StringRef SymbolName);
236 Error registerPerObjectSections(jitlink::LinkGraph &
G,
237 const ELFPerObjectSectionsToRegister &POSR,
238 bool IsBootstrapping);
240 Expected<uint64_t> createPThreadKey();
242 ExecutionSession &ES;
243 JITDylib &PlatformJD;
244 ObjectLinkingLayer &ObjLinkingLayer;
246 SymbolStringPtr DSOHandleSymbol;
249 ES.intern(
"__orc_rt_elfnix_platform_bootstrap")};
251 ES.intern(
"__orc_rt_elfnix_platform_shutdown")};
253 ES.intern(
"__orc_rt_elfnix_register_jitdylib")};
255 ES.intern(
"__orc_rt_elfnix_deregister_jitdylib")};
257 ES.intern(
"__orc_rt_elfnix_register_object_sections")};
259 ES.intern(
"__orc_rt_elfnix_deregister_object_sections")};
261 ES.intern(
"__orc_rt_elfnix_register_init_sections")};
263 ES.intern(
"__orc_rt_elfnix_deregister_init_sections")};
265 ES.intern(
"__orc_rt_elfnix_create_pthread_key")};
267 DenseMap<JITDylib *, SymbolLookupSet> RegisteredInitSymbols;
271 std::mutex PlatformMutex;
272 std::vector<ELFPerObjectSectionsToRegister> BootstrapPOSRs;
274 DenseMap<ExecutorAddr, JITDylib *> HandleAddrToJITDylib;
275 DenseMap<JITDylib *, ExecutorAddr> JITDylibToHandleAddr;
276 DenseMap<JITDylib *, uint64_t> JITDylibToPThreadKey;
278 std::atomic<BootstrapInfo *> Bootstrap;
292 return SPSELFPerObjectSectionsToRegister::AsArgList::size(
298 return SPSELFPerObjectSectionsToRegister::AsArgList::serialize(
304 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.
static ErrorSuccess success()
Create a success value.
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.
IntrusiveRefCntPtr< JITDylib > JITDylibSP
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)