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 std::unique_ptr<DefinitionGenerator> OrcRuntime,
140 std::optional<SymbolAliasMap> RuntimeAliases = std::nullopt);
145 const char *OrcRuntimePath, HeaderOptions PlatformJDOpts = {},
147 std::optional<SymbolAliasMap> RuntimeAliases = std::nullopt);
186 std::tuple<ExecutorAddr, ExecutorAddr, MachOExecutorSymbolFlags>>;
189 struct BootstrapInfo {
191 std::condition_variable CV;
192 size_t ActiveGraphs = 0;
195 SymbolTableVector SymTab;
201 class MachOPlatformPlugin :
public ObjectLinkingLayer::Plugin {
203 MachOPlatformPlugin(MachOPlatform &MP) : MP(MP) {}
205 void modifyPassConfig(MaterializationResponsibility &MR,
206 jitlink::LinkGraph &
G,
207 jitlink::PassConfiguration &
Config)
override;
211 Error notifyFailed(MaterializationResponsibility &MR)
override {
219 void notifyTransferringResources(JITDylib &JD,
ResourceKey DstKey,
223 struct UnwindSections {
224 SmallVector<ExecutorAddrRange> CodeRanges;
225 ExecutorAddrRange DwarfSection;
226 ExecutorAddrRange CompactUnwindSection;
229 struct ObjCImageInfo {
234 bool Finalized =
false;
237 struct SymbolTablePair {
238 jitlink::Symbol *OriginalSym =
nullptr;
239 jitlink::Symbol *NameSym =
nullptr;
241 using JITSymTabVector = SmallVector<SymbolTablePair>;
243 Error bootstrapPipelineStart(jitlink::LinkGraph &
G);
244 Error bootstrapPipelineRecordRuntimeFunctions(jitlink::LinkGraph &
G);
245 Error bootstrapPipelineEnd(jitlink::LinkGraph &
G);
247 Error associateJITDylibHeaderSymbol(jitlink::LinkGraph &
G,
248 MaterializationResponsibility &MR);
250 Error preserveImportantSections(jitlink::LinkGraph &
G,
251 MaterializationResponsibility &MR);
253 Error processObjCImageInfo(jitlink::LinkGraph &
G,
254 MaterializationResponsibility &MR);
255 Error mergeImageInfoFlags(jitlink::LinkGraph &
G,
256 MaterializationResponsibility &MR,
259 Error fixTLVSectionsAndEdges(jitlink::LinkGraph &
G, JITDylib &JD);
261 std::optional<UnwindSections> findUnwindSectionInfo(jitlink::LinkGraph &
G);
262 Error registerObjectPlatformSections(jitlink::LinkGraph &
G, JITDylib &JD,
263 bool InBootstrapPhase);
265 Error createObjCRuntimeObject(jitlink::LinkGraph &
G);
266 Error populateObjCRuntimeObject(jitlink::LinkGraph &
G,
267 MaterializationResponsibility &MR);
269 Error prepareSymbolTableRegistration(jitlink::LinkGraph &
G,
270 JITSymTabVector &JITSymTabInfo);
271 Error addSymbolTableRegistration(jitlink::LinkGraph &
G,
272 MaterializationResponsibility &MR,
273 JITSymTabVector &JITSymTabInfo,
274 bool InBootstrapPhase);
276 std::mutex PluginMutex;
281 DenseMap<JITDylib *, ObjCImageInfo> ObjCImageInfos;
282 DenseMap<JITDylib *, ExecutorAddr> HeaderAddrs;
285 using GetJITDylibHeaderSendResultFn =
286 unique_function<void(Expected<ExecutorAddr>)>;
287 using GetJITDylibNameSendResultFn =
288 unique_function<void(Expected<StringRef>)>;
289 using PushInitializersSendResultFn =
290 unique_function<void(Expected<MachOJITDylibDepInfoMap>)>;
291 using SendSymbolAddressFn = unique_function<void(Expected<ExecutorAddr>)>;
292 using PushSymbolsInSendResultFn = unique_function<void(Error)>;
294 static bool supportedTarget(
const Triple &TT);
300 MachOPlatform(ObjectLinkingLayer &ObjLinkingLayer, JITDylib &PlatformJD,
301 std::unique_ptr<DefinitionGenerator> OrcRuntimeGenerator,
302 HeaderOptions PlatformJDOpts,
306 Error associateRuntimeSupportFunctions();
311 void pushInitializersLoop(PushInitializersSendResultFn SendResult,
315 void rt_pushInitializers(PushInitializersSendResultFn SendResult,
316 ExecutorAddr JDHeaderAddr);
322 void rt_pushSymbols(PushSymbolsInSendResultFn SendResult, ExecutorAddr Handle,
323 const std::vector<std::pair<StringRef, bool>> &Symbols);
326 Expected<uint64_t> createPThreadKey();
328 ExecutionSession &ES;
329 JITDylib &PlatformJD;
330 ObjectLinkingLayer &ObjLinkingLayer;
333 SymbolStringPtr MachOHeaderStartSymbol = ES.intern(
"___dso_handle");
337 SymbolStringPtr
Name;
342 ES.intern(
"___orc_rt_macho_platform_bootstrap")};
344 ES.intern(
"___orc_rt_macho_platform_shutdown")};
346 ES.intern(
"___orc_rt_macho_register_ehframe_section")};
348 ES.intern(
"___orc_rt_macho_deregister_ehframe_section")};
350 ES.intern(
"___orc_rt_macho_register_jitdylib")};
352 ES.intern(
"___orc_rt_macho_deregister_jitdylib")};
354 ES.intern(
"___orc_rt_macho_register_object_symbol_table")};
356 ES.intern(
"___orc_rt_macho_deregister_object_symbol_table")};
358 ES.intern(
"___orc_rt_macho_register_object_platform_sections")};
360 ES.intern(
"___orc_rt_macho_deregister_object_platform_sections")};
362 ES.intern(
"___orc_rt_macho_create_pthread_key")};
364 ES.intern(
"___orc_rt_macho_register_objc_runtime_object")};
366 ES.intern(
"___orc_rt_macho_deregister_objc_runtime_object")};
368 DenseMap<JITDylib *, SymbolLookupSet> RegisteredInitSymbols;
370 std::mutex PlatformMutex;
371 DenseMap<JITDylib *, ExecutorAddr> JITDylibToHeaderAddr;
372 DenseMap<ExecutorAddr, JITDylib *> HeaderAddrToJITDylib;
373 DenseMap<JITDylib *, uint64_t> JITDylibToPThreadKey;
375 std::atomic<BootstrapInfo *> Bootstrap;
384 void materialize(std::unique_ptr<MaterializationResponsibility> R)
override;
395 struct HeaderSymbol {
400 static constexpr HeaderSymbol AdditionalHeaderSymbols[] = {
401 {
"___mh_executable_header", 0}};
403 void addMachOHeader(
JITDylib &JD, jitlink::LinkGraph &
G,
404 const SymbolStringPtr &InitializerSymbol);
405 static MaterializationUnit::Interface
406 createHeaderInterface(MachOPlatform &
MOP,
407 const SymbolStringPtr &HeaderStartSymbol);
411inline std::unique_ptr<MaterializationUnit>
414 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.
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.
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.