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 auto &argList = DeferredRTFnMap[std::make_pair(func1, func2)];
160 argList.emplace_back(arg1, arg2);
167 class ELFNixPlatformPlugin :
public ObjectLinkingLayer::Plugin {
169 ELFNixPlatformPlugin(ELFNixPlatform &MP) : MP(MP) {}
171 void modifyPassConfig(MaterializationResponsibility &MR,
172 jitlink::LinkGraph &
G,
173 jitlink::PassConfiguration &
Config)
override;
177 Error notifyFailed(MaterializationResponsibility &MR)
override {
185 void notifyTransferringResources(JITDylib &JD,
ResourceKey DstKey,
189 Error bootstrapPipelineStart(jitlink::LinkGraph &
G);
190 Error bootstrapPipelineRecordRuntimeFunctions(jitlink::LinkGraph &
G);
191 Error bootstrapPipelineEnd(jitlink::LinkGraph &
G);
193 void addDSOHandleSupportPasses(MaterializationResponsibility &MR,
194 jitlink::PassConfiguration &
Config);
196 void addEHAndTLVSupportPasses(MaterializationResponsibility &MR,
197 jitlink::PassConfiguration &
Config,
198 bool IsBootstrapping);
200 Error preserveInitSections(jitlink::LinkGraph &
G,
201 MaterializationResponsibility &MR);
203 Error registerInitSections(jitlink::LinkGraph &
G, JITDylib &JD,
204 bool IsBootstrapping);
206 Error fixTLVSectionsAndEdges(jitlink::LinkGraph &
G, JITDylib &JD);
208 std::mutex PluginMutex;
212 using PushInitializersSendResultFn =
213 unique_function<void(Expected<ELFNixJITDylibDepInfoMap>)>;
215 using SendSymbolAddressFn = unique_function<void(Expected<ExecutorAddr>)>;
217 static bool supportedTarget(
const Triple &TT);
219 ELFNixPlatform(ObjectLinkingLayer &ObjLinkingLayer, JITDylib &PlatformJD,
220 std::unique_ptr<DefinitionGenerator> OrcRuntimeGenerator,
224 Error associateRuntimeSupportFunctions(JITDylib &PlatformJD);
226 void pushInitializersLoop(PushInitializersSendResultFn SendResult,
229 void rt_recordInitializers(PushInitializersSendResultFn SendResult,
230 ExecutorAddr JDHeader);
232 void rt_lookupSymbol(SendSymbolAddressFn SendResult, ExecutorAddr Handle,
233 StringRef SymbolName);
235 Error registerPerObjectSections(jitlink::LinkGraph &
G,
236 const ELFPerObjectSectionsToRegister &POSR,
237 bool IsBootstrapping);
239 Expected<uint64_t> createPThreadKey();
241 ExecutionSession &ES;
242 JITDylib &PlatformJD;
243 ObjectLinkingLayer &ObjLinkingLayer;
245 SymbolStringPtr DSOHandleSymbol;
248 ES.intern(
"__orc_rt_elfnix_platform_bootstrap")};
250 ES.intern(
"__orc_rt_elfnix_platform_shutdown")};
252 ES.intern(
"__orc_rt_elfnix_register_jitdylib")};
254 ES.intern(
"__orc_rt_elfnix_deregister_jitdylib")};
256 ES.intern(
"__orc_rt_elfnix_register_object_sections")};
258 ES.intern(
"__orc_rt_elfnix_deregister_object_sections")};
260 ES.intern(
"__orc_rt_elfnix_register_init_sections")};
262 ES.intern(
"__orc_rt_elfnix_deregister_init_sections")};
264 ES.intern(
"__orc_rt_elfnix_create_pthread_key")};
266 DenseMap<JITDylib *, SymbolLookupSet> RegisteredInitSymbols;
270 std::mutex PlatformMutex;
271 std::vector<ELFPerObjectSectionsToRegister> BootstrapPOSRs;
273 DenseMap<ExecutorAddr, JITDylib *> HandleAddrToJITDylib;
274 DenseMap<JITDylib *, ExecutorAddr> JITDylibToHandleAddr;
275 DenseMap<JITDylib *, uint64_t> JITDylibToPThreadKey;
277 std::atomic<BootstrapInfo *> Bootstrap;
291 return SPSELFPerObjectSectionsToRegister::AsArgList::size(
297 return SPSELFPerObjectSectionsToRegister::AsArgList::serialize(
303 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)