13#ifndef LLVM_EXECUTIONENGINE_ORC_MACHOPLATFORM_H
14#define LLVM_EXECUTIONENGINE_ORC_MACHOPLATFORM_H
40 std::vector<std::pair<ExecutorAddr, MachOJITDylibDepInfo>>;
82 JITDylib &PlatformJD, std::unique_ptr<DefinitionGenerator> OrcRuntime,
83 std::optional<SymbolAliasMap> RuntimeAliases = std::nullopt);
88 JITDylib &PlatformJD,
const char *OrcRuntimePath,
89 std::optional<SymbolAliasMap> RuntimeAliases = std::nullopt);
114 struct BootstrapInfo {
116 std::condition_variable CV;
117 size_t ActiveGraphs = 0;
125 class MachOPlatformPlugin :
public ObjectLinkingLayer::Plugin {
127 MachOPlatformPlugin(MachOPlatform &MP) : MP(MP) {}
129 void modifyPassConfig(MaterializationResponsibility &MR,
130 jitlink::LinkGraph &
G,
131 jitlink::PassConfiguration &
Config)
override;
134 getSyntheticSymbolDependencies(MaterializationResponsibility &MR)
override;
138 Error notifyFailed(MaterializationResponsibility &MR)
override {
146 void notifyTransferringResources(JITDylib &JD,
ResourceKey DstKey,
150 using InitSymbolDepMap =
151 DenseMap<MaterializationResponsibility *, JITLinkSymbolSet>;
153 struct UnwindSections {
154 SmallVector<ExecutorAddrRange> CodeRanges;
155 ExecutorAddrRange DwarfSection;
156 ExecutorAddrRange CompactUnwindSection;
159 struct ObjCImageInfo {
164 Error bootstrapPipelineStart(jitlink::LinkGraph &
G);
165 Error bootstrapPipelineRecordRuntimeFunctions(jitlink::LinkGraph &
G);
166 Error bootstrapPipelineEnd(jitlink::LinkGraph &
G);
168 Error associateJITDylibHeaderSymbol(jitlink::LinkGraph &
G,
169 MaterializationResponsibility &MR);
171 Error preserveImportantSections(jitlink::LinkGraph &
G,
172 MaterializationResponsibility &MR);
174 Error processObjCImageInfo(jitlink::LinkGraph &
G,
175 MaterializationResponsibility &MR);
177 Error fixTLVSectionsAndEdges(jitlink::LinkGraph &
G, JITDylib &JD);
179 std::optional<UnwindSections> findUnwindSectionInfo(jitlink::LinkGraph &
G);
181 Error registerObjectPlatformSections(jitlink::LinkGraph &
G, JITDylib &JD,
182 bool InBootstrapPhase);
184 Error createObjCRuntimeObject(jitlink::LinkGraph &
G);
185 Error populateObjCRuntimeObject(jitlink::LinkGraph &
G,
186 MaterializationResponsibility &MR);
188 std::mutex PluginMutex;
193 DenseMap<JITDylib *, ObjCImageInfo> ObjCImageInfos;
194 DenseMap<JITDylib *, ExecutorAddr> HeaderAddrs;
195 InitSymbolDepMap InitSymbolDeps;
198 using GetJITDylibHeaderSendResultFn =
199 unique_function<void(Expected<ExecutorAddr>)>;
200 using GetJITDylibNameSendResultFn =
201 unique_function<void(Expected<StringRef>)>;
202 using PushInitializersSendResultFn =
203 unique_function<void(Expected<MachOJITDylibDepInfoMap>)>;
204 using SendSymbolAddressFn = unique_function<void(Expected<ExecutorAddr>)>;
206 static bool supportedTarget(
const Triple &TT);
208 MachOPlatform(ExecutionSession &ES, ObjectLinkingLayer &ObjLinkingLayer,
209 JITDylib &PlatformJD,
210 std::unique_ptr<DefinitionGenerator> OrcRuntimeGenerator,
214 Error associateRuntimeSupportFunctions();
219 void pushInitializersLoop(PushInitializersSendResultFn SendResult,
223 void rt_pushInitializers(PushInitializersSendResultFn SendResult,
224 ExecutorAddr JDHeaderAddr);
227 void rt_lookupSymbol(SendSymbolAddressFn SendResult, ExecutorAddr Handle,
228 StringRef SymbolName);
231 Expected<uint64_t> createPThreadKey();
233 ExecutionSession &ES;
234 JITDylib &PlatformJD;
235 ObjectLinkingLayer &ObjLinkingLayer;
237 SymbolStringPtr MachOHeaderStartSymbol = ES.intern(
"___dso_handle");
241 SymbolStringPtr
Name;
246 ES.intern(
"___orc_rt_macho_platform_bootstrap")};
248 ES.intern(
"___orc_rt_macho_platform_shutdown")};
250 ES.intern(
"___orc_rt_macho_register_ehframe_section")};
252 ES.intern(
"___orc_rt_macho_deregister_ehframe_section")};
254 ES.intern(
"___orc_rt_macho_register_jitdylib")};
256 ES.intern(
"___orc_rt_macho_deregister_jitdylib")};
258 ES.intern(
"___orc_rt_macho_register_object_platform_sections")};
260 ES.intern(
"___orc_rt_macho_deregister_object_platform_sections")};
262 ES.intern(
"___orc_rt_macho_create_pthread_key")};
264 ES.intern(
"___orc_rt_macho_register_objc_runtime_object")};
266 ES.intern(
"___orc_rt_macho_deregister_objc_runtime_object")};
268 DenseMap<JITDylib *, SymbolLookupSet> RegisteredInitSymbols;
270 std::mutex PlatformMutex;
271 DenseMap<JITDylib *, ExecutorAddr> JITDylibToHeaderAddr;
272 DenseMap<ExecutorAddr, JITDylib *> HeaderAddrToJITDylib;
273 DenseMap<JITDylib *, uint64_t> JITDylibToPThreadKey;
275 std::atomic<BootstrapInfo *> Bootstrap;
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.
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,...
DenseMap< SymbolStringPtr, JITLinkSymbolSet > SyntheticSymbolDependenciesMap
An ObjectLayer implementation built on JITLink.
API to remove / transfer ownership of JIT resources.
SPS tag type for sequences.
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
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.