13#ifndef LLVM_EXECUTIONENGINE_ORC_MACHOPLATFORM_H
14#define LLVM_EXECUTIONENGINE_ORC_MACHOPLATFORM_H
40 std::vector<std::pair<ExecutorAddr, MachOJITDylibDepInfo>>;
90 JITDylib &PlatformJD, std::unique_ptr<DefinitionGenerator> OrcRuntime,
91 std::optional<SymbolAliasMap> RuntimeAliases = std::nullopt);
96 JITDylib &PlatformJD,
const char *OrcRuntimePath,
97 std::optional<SymbolAliasMap> RuntimeAliases = std::nullopt);
122 std::tuple<ExecutorAddr, ExecutorAddr, MachOExecutorSymbolFlags>>;
125 struct BootstrapInfo {
127 std::condition_variable CV;
128 size_t ActiveGraphs = 0;
131 SymbolTableVector SymTab;
137 class MachOPlatformPlugin :
public ObjectLinkingLayer::Plugin {
139 MachOPlatformPlugin(MachOPlatform &MP) : MP(MP) {}
141 void modifyPassConfig(MaterializationResponsibility &MR,
142 jitlink::LinkGraph &
G,
143 jitlink::PassConfiguration &
Config)
override;
146 getSyntheticSymbolDependencies(MaterializationResponsibility &MR)
override;
150 Error notifyFailed(MaterializationResponsibility &MR)
override {
158 void notifyTransferringResources(JITDylib &JD,
ResourceKey DstKey,
162 using InitSymbolDepMap =
163 DenseMap<MaterializationResponsibility *, JITLinkSymbolSet>;
165 struct UnwindSections {
166 SmallVector<ExecutorAddrRange> CodeRanges;
167 ExecutorAddrRange DwarfSection;
168 ExecutorAddrRange CompactUnwindSection;
171 struct ObjCImageInfo {
176 bool Finalized =
false;
179 struct SymbolTablePair {
180 jitlink::Symbol *OriginalSym =
nullptr;
181 jitlink::Symbol *NameSym =
nullptr;
183 using JITSymTabVector = SmallVector<SymbolTablePair>;
185 Error bootstrapPipelineStart(jitlink::LinkGraph &
G);
186 Error bootstrapPipelineRecordRuntimeFunctions(jitlink::LinkGraph &
G);
187 Error bootstrapPipelineEnd(jitlink::LinkGraph &
G);
189 Error associateJITDylibHeaderSymbol(jitlink::LinkGraph &
G,
190 MaterializationResponsibility &MR);
192 Error preserveImportantSections(jitlink::LinkGraph &
G,
193 MaterializationResponsibility &MR);
195 Error processObjCImageInfo(jitlink::LinkGraph &
G,
196 MaterializationResponsibility &MR);
197 Error mergeImageInfoFlags(jitlink::LinkGraph &
G,
198 MaterializationResponsibility &MR,
201 Error fixTLVSectionsAndEdges(jitlink::LinkGraph &
G, JITDylib &JD);
203 std::optional<UnwindSections> findUnwindSectionInfo(jitlink::LinkGraph &
G);
204 Error registerObjectPlatformSections(jitlink::LinkGraph &
G, JITDylib &JD,
205 bool InBootstrapPhase);
207 Error createObjCRuntimeObject(jitlink::LinkGraph &
G);
208 Error populateObjCRuntimeObject(jitlink::LinkGraph &
G,
209 MaterializationResponsibility &MR);
211 Error prepareSymbolTableRegistration(jitlink::LinkGraph &
G,
212 JITSymTabVector &JITSymTabInfo);
213 Error addSymbolTableRegistration(jitlink::LinkGraph &
G,
214 MaterializationResponsibility &MR,
215 JITSymTabVector &JITSymTabInfo,
216 bool InBootstrapPhase);
218 std::mutex PluginMutex;
223 DenseMap<JITDylib *, ObjCImageInfo> ObjCImageInfos;
224 DenseMap<JITDylib *, ExecutorAddr> HeaderAddrs;
225 InitSymbolDepMap InitSymbolDeps;
228 using GetJITDylibHeaderSendResultFn =
229 unique_function<void(Expected<ExecutorAddr>)>;
230 using GetJITDylibNameSendResultFn =
231 unique_function<void(Expected<StringRef>)>;
232 using PushInitializersSendResultFn =
233 unique_function<void(Expected<MachOJITDylibDepInfoMap>)>;
234 using SendSymbolAddressFn = unique_function<void(Expected<ExecutorAddr>)>;
235 using PushSymbolsInSendResultFn = unique_function<void(Error)>;
237 static bool supportedTarget(
const Triple &TT);
243 MachOPlatform(ExecutionSession &ES, ObjectLinkingLayer &ObjLinkingLayer,
244 JITDylib &PlatformJD,
245 std::unique_ptr<DefinitionGenerator> OrcRuntimeGenerator,
249 Error associateRuntimeSupportFunctions();
254 void pushInitializersLoop(PushInitializersSendResultFn SendResult,
258 void rt_pushInitializers(PushInitializersSendResultFn SendResult,
259 ExecutorAddr JDHeaderAddr);
265 void rt_pushSymbols(PushSymbolsInSendResultFn SendResult, ExecutorAddr Handle,
266 const std::vector<std::pair<StringRef, bool>> &Symbols);
269 Expected<uint64_t> createPThreadKey();
271 ExecutionSession &ES;
272 JITDylib &PlatformJD;
273 ObjectLinkingLayer &ObjLinkingLayer;
275 SymbolStringPtr MachOHeaderStartSymbol = ES.intern(
"___dso_handle");
279 SymbolStringPtr
Name;
284 ES.intern(
"___orc_rt_macho_platform_bootstrap")};
286 ES.intern(
"___orc_rt_macho_platform_shutdown")};
288 ES.intern(
"___orc_rt_macho_register_ehframe_section")};
290 ES.intern(
"___orc_rt_macho_deregister_ehframe_section")};
292 ES.intern(
"___orc_rt_macho_register_jitdylib")};
294 ES.intern(
"___orc_rt_macho_deregister_jitdylib")};
296 ES.intern(
"___orc_rt_macho_register_object_symbol_table")};
298 ES.intern(
"___orc_rt_macho_deregister_object_symbol_table")};
300 ES.intern(
"___orc_rt_macho_register_object_platform_sections")};
302 ES.intern(
"___orc_rt_macho_deregister_object_platform_sections")};
304 ES.intern(
"___orc_rt_macho_create_pthread_key")};
306 ES.intern(
"___orc_rt_macho_register_objc_runtime_object")};
308 ES.intern(
"___orc_rt_macho_deregister_objc_runtime_object")};
310 DenseMap<JITDylib *, SymbolLookupSet> RegisteredInitSymbols;
312 std::mutex PlatformMutex;
313 DenseMap<JITDylib *, ExecutorAddr> JITDylibToHeaderAddr;
314 DenseMap<ExecutorAddr, JITDylib *> HeaderAddrToJITDylib;
315 DenseMap<JITDylib *, uint64_t> JITDylibToPThreadKey;
317 std::atomic<BootstrapInfo *> Bootstrap;
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.
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.
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.
@ 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.