13#ifndef LLVM_EXECUTIONENGINE_ORC_MACHOPLATFORM_H
14#define LLVM_EXECUTIONENGINE_ORC_MACHOPLATFORM_H
40 std::vector<std::pair<ExecutorAddr, MachOJITDylibDepInfo>>;
64 static std::optional<BuildVersionOpts>
94 static inline std::unique_ptr<MaterializationUnit>
137 JITDylib &PlatformJD, std::unique_ptr<DefinitionGenerator> OrcRuntime,
140 std::optional<SymbolAliasMap> RuntimeAliases = std::nullopt);
145 JITDylib &PlatformJD,
const char *OrcRuntimePath,
146 HeaderOptions PlatformJDOpts = {},
148 std::optional<SymbolAliasMap> RuntimeAliases = std::nullopt);
182 std::tuple<ExecutorAddr, ExecutorAddr, MachOExecutorSymbolFlags>>;
185 struct BootstrapInfo {
187 std::condition_variable CV;
188 size_t ActiveGraphs = 0;
191 SymbolTableVector SymTab;
197 class MachOPlatformPlugin :
public ObjectLinkingLayer::Plugin {
199 MachOPlatformPlugin(MachOPlatform &MP) : MP(MP) {}
201 void modifyPassConfig(MaterializationResponsibility &MR,
202 jitlink::LinkGraph &
G,
203 jitlink::PassConfiguration &
Config)
override;
206 getSyntheticSymbolDependencies(MaterializationResponsibility &MR)
override;
210 Error notifyFailed(MaterializationResponsibility &MR)
override {
218 void notifyTransferringResources(JITDylib &JD,
ResourceKey DstKey,
222 using InitSymbolDepMap =
223 DenseMap<MaterializationResponsibility *, JITLinkSymbolSet>;
225 struct UnwindSections {
226 SmallVector<ExecutorAddrRange> CodeRanges;
227 ExecutorAddrRange DwarfSection;
228 ExecutorAddrRange CompactUnwindSection;
231 struct ObjCImageInfo {
236 bool Finalized =
false;
239 struct SymbolTablePair {
240 jitlink::Symbol *OriginalSym =
nullptr;
241 jitlink::Symbol *NameSym =
nullptr;
243 using JITSymTabVector = SmallVector<SymbolTablePair>;
245 Error bootstrapPipelineStart(jitlink::LinkGraph &
G);
246 Error bootstrapPipelineRecordRuntimeFunctions(jitlink::LinkGraph &
G);
247 Error bootstrapPipelineEnd(jitlink::LinkGraph &
G);
249 Error associateJITDylibHeaderSymbol(jitlink::LinkGraph &
G,
250 MaterializationResponsibility &MR);
252 Error preserveImportantSections(jitlink::LinkGraph &
G,
253 MaterializationResponsibility &MR);
255 Error processObjCImageInfo(jitlink::LinkGraph &
G,
256 MaterializationResponsibility &MR);
257 Error mergeImageInfoFlags(jitlink::LinkGraph &
G,
258 MaterializationResponsibility &MR,
261 Error fixTLVSectionsAndEdges(jitlink::LinkGraph &
G, JITDylib &JD);
263 std::optional<UnwindSections> findUnwindSectionInfo(jitlink::LinkGraph &
G);
264 Error registerObjectPlatformSections(jitlink::LinkGraph &
G, JITDylib &JD,
265 bool InBootstrapPhase);
267 Error createObjCRuntimeObject(jitlink::LinkGraph &
G);
268 Error populateObjCRuntimeObject(jitlink::LinkGraph &
G,
269 MaterializationResponsibility &MR);
271 Error prepareSymbolTableRegistration(jitlink::LinkGraph &
G,
272 JITSymTabVector &JITSymTabInfo);
273 Error addSymbolTableRegistration(jitlink::LinkGraph &
G,
274 MaterializationResponsibility &MR,
275 JITSymTabVector &JITSymTabInfo,
276 bool InBootstrapPhase);
278 std::mutex PluginMutex;
283 DenseMap<JITDylib *, ObjCImageInfo> ObjCImageInfos;
284 DenseMap<JITDylib *, ExecutorAddr> HeaderAddrs;
285 InitSymbolDepMap InitSymbolDeps;
288 using GetJITDylibHeaderSendResultFn =
289 unique_function<void(Expected<ExecutorAddr>)>;
290 using GetJITDylibNameSendResultFn =
291 unique_function<void(Expected<StringRef>)>;
292 using PushInitializersSendResultFn =
293 unique_function<void(Expected<MachOJITDylibDepInfoMap>)>;
294 using SendSymbolAddressFn = unique_function<void(Expected<ExecutorAddr>)>;
295 using PushSymbolsInSendResultFn = unique_function<void(Error)>;
297 static bool supportedTarget(
const Triple &TT);
303 MachOPlatform(ExecutionSession &ES, ObjectLinkingLayer &ObjLinkingLayer,
304 JITDylib &PlatformJD,
305 std::unique_ptr<DefinitionGenerator> OrcRuntimeGenerator,
306 HeaderOptions PlatformJDOpts,
310 Error associateRuntimeSupportFunctions();
315 void pushInitializersLoop(PushInitializersSendResultFn SendResult,
319 void rt_pushInitializers(PushInitializersSendResultFn SendResult,
320 ExecutorAddr JDHeaderAddr);
326 void rt_pushSymbols(PushSymbolsInSendResultFn SendResult, ExecutorAddr Handle,
327 const std::vector<std::pair<StringRef, bool>> &Symbols);
330 Expected<uint64_t> createPThreadKey();
332 ExecutionSession &ES;
333 JITDylib &PlatformJD;
334 ObjectLinkingLayer &ObjLinkingLayer;
337 SymbolStringPtr MachOHeaderStartSymbol = ES.
intern(
"___dso_handle");
341 SymbolStringPtr
Name;
346 ES.
intern(
"___orc_rt_macho_platform_bootstrap")};
348 ES.
intern(
"___orc_rt_macho_platform_shutdown")};
350 ES.
intern(
"___orc_rt_macho_register_ehframe_section")};
352 ES.
intern(
"___orc_rt_macho_deregister_ehframe_section")};
354 ES.
intern(
"___orc_rt_macho_register_jitdylib")};
356 ES.
intern(
"___orc_rt_macho_deregister_jitdylib")};
358 ES.
intern(
"___orc_rt_macho_register_object_symbol_table")};
360 ES.
intern(
"___orc_rt_macho_deregister_object_symbol_table")};
362 ES.
intern(
"___orc_rt_macho_register_object_platform_sections")};
364 ES.
intern(
"___orc_rt_macho_deregister_object_platform_sections")};
366 ES.
intern(
"___orc_rt_macho_create_pthread_key")};
368 ES.
intern(
"___orc_rt_macho_register_objc_runtime_object")};
370 ES.
intern(
"___orc_rt_macho_deregister_objc_runtime_object")};
372 DenseMap<JITDylib *, SymbolLookupSet> RegisteredInitSymbols;
374 std::mutex PlatformMutex;
375 DenseMap<JITDylib *, ExecutorAddr> JITDylibToHeaderAddr;
376 DenseMap<ExecutorAddr, JITDylib *> HeaderAddrToJITDylib;
377 DenseMap<JITDylib *, uint64_t> JITDylibToPThreadKey;
379 std::atomic<BootstrapInfo *> Bootstrap;
388 void materialize(std::unique_ptr<MaterializationResponsibility> R)
override;
399 struct HeaderSymbol {
404 static constexpr HeaderSymbol AdditionalHeaderSymbols[] = {
405 {
"___mh_executable_header", 0}};
407 void addMachOHeader(
JITDylib &JD, jitlink::LinkGraph &
G,
408 const SymbolStringPtr &InitializerSymbol);
409 static MaterializationUnit::Interface
410 createHeaderInterface(MachOPlatform &
MOP,
411 const SymbolStringPtr &HeaderStartSymbol);
415inline std::unique_ptr<MaterializationUnit>
418 return std::make_unique<SimpleMachOHeaderMU>(MOP, MOP.MachOHeaderStartSymbol,
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
Analysis containing CSE Info
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.
StringRef - Represent a constant reference to a string, i.e.
Triple - Helper class for working with autoconf configuration names.
An Addressable with content and edges.
Represents an object file section.
An ExecutionSession represents a running JIT program.
SymbolStringPtr intern(StringRef SymName)
Add a symbol name to the SymbolStringPool and return a pointer to it.
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,...
Non-owning SymbolStringPool entry pointer.
DenseMap< SymbolStringPtr, JITLinkSymbolSet > SyntheticSymbolDependenciesMap
An ObjectLayer implementation built on JITLink.
API to remove / transfer ownership of JIT resources.
Pointer to a pooled string representing a symbol name.
RuntimeFunction
IDs for all omp runtime library (RTL) functions.
std::vector< AllocActionCallPair > AllocActions
A vector of allocation actions to be run for this allocation.
IntrusiveRefCntPtr< JITDylib > JITDylibSP
MachOHeaderInfo getMachOHeaderInfoFromTriple(const Triple &TT)
This is an optimization pass for GlobalISel generic memory operations.
@ LLVM_MARK_AS_BITMASK_ENUM
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.