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 bootstrapPipelineRecordRuntimeFunctions(jitlink::LinkGraph &
G);
244 Error bootstrapPipelineEnd(jitlink::LinkGraph &
G);
246 Error associateJITDylibHeaderSymbol(jitlink::LinkGraph &
G,
247 MaterializationResponsibility &MR);
249 Error preserveImportantSections(jitlink::LinkGraph &
G,
250 MaterializationResponsibility &MR);
252 Error processObjCImageInfo(jitlink::LinkGraph &
G,
253 MaterializationResponsibility &MR);
254 Error mergeImageInfoFlags(jitlink::LinkGraph &
G,
255 MaterializationResponsibility &MR,
258 Error fixTLVSectionsAndEdges(jitlink::LinkGraph &
G, JITDylib &JD);
260 std::optional<UnwindSections> findUnwindSectionInfo(jitlink::LinkGraph &
G);
261 Error registerObjectPlatformSections(jitlink::LinkGraph &
G, JITDylib &JD,
262 bool InBootstrapPhase);
264 Error createObjCRuntimeObject(jitlink::LinkGraph &
G);
265 Error populateObjCRuntimeObject(jitlink::LinkGraph &
G,
266 MaterializationResponsibility &MR);
268 Error prepareSymbolTableRegistration(jitlink::LinkGraph &
G,
269 JITSymTabVector &JITSymTabInfo);
270 Error addSymbolTableRegistration(jitlink::LinkGraph &
G,
271 MaterializationResponsibility &MR,
272 JITSymTabVector &JITSymTabInfo,
273 bool InBootstrapPhase);
275 std::mutex PluginMutex;
280 DenseMap<JITDylib *, ObjCImageInfo> ObjCImageInfos;
281 DenseMap<JITDylib *, ExecutorAddr> HeaderAddrs;
284 using GetJITDylibHeaderSendResultFn =
285 unique_function<void(Expected<ExecutorAddr>)>;
286 using GetJITDylibNameSendResultFn =
287 unique_function<void(Expected<StringRef>)>;
288 using PushInitializersSendResultFn =
289 unique_function<void(Expected<MachOJITDylibDepInfoMap>)>;
290 using SendSymbolAddressFn = unique_function<void(Expected<ExecutorAddr>)>;
291 using PushSymbolsInSendResultFn = unique_function<void(Error)>;
293 static bool supportedTarget(
const Triple &TT);
299 MachOPlatform(ObjectLinkingLayer &ObjLinkingLayer, JITDylib &PlatformJD,
300 std::unique_ptr<DefinitionGenerator> OrcRuntimeGenerator,
301 HeaderOptions PlatformJDOpts,
305 Error associateRuntimeSupportFunctions();
310 void pushInitializersLoop(PushInitializersSendResultFn SendResult,
314 void rt_pushInitializers(PushInitializersSendResultFn SendResult,
315 ExecutorAddr JDHeaderAddr);
321 void rt_pushSymbols(PushSymbolsInSendResultFn SendResult, ExecutorAddr Handle,
322 const std::vector<std::pair<StringRef, bool>> &Symbols);
325 Expected<uint64_t> createPThreadKey();
327 ExecutionSession &ES;
328 JITDylib &PlatformJD;
329 ObjectLinkingLayer &ObjLinkingLayer;
332 SymbolStringPtr MachOHeaderStartSymbol = ES.intern(
"___dso_handle");
336 SymbolStringPtr
Name;
341 ES.intern(
"___orc_rt_macho_platform_bootstrap")};
343 ES.intern(
"___orc_rt_macho_platform_shutdown")};
345 ES.intern(
"___orc_rt_macho_register_ehframe_section")};
347 ES.intern(
"___orc_rt_macho_deregister_ehframe_section")};
349 ES.intern(
"___orc_rt_macho_register_jitdylib")};
351 ES.intern(
"___orc_rt_macho_deregister_jitdylib")};
353 ES.intern(
"___orc_rt_macho_register_object_symbol_table")};
355 ES.intern(
"___orc_rt_macho_deregister_object_symbol_table")};
357 ES.intern(
"___orc_rt_macho_register_object_platform_sections")};
359 ES.intern(
"___orc_rt_macho_deregister_object_platform_sections")};
361 ES.intern(
"___orc_rt_macho_create_pthread_key")};
363 ES.intern(
"___orc_rt_macho_register_objc_runtime_object")};
365 ES.intern(
"___orc_rt_macho_deregister_objc_runtime_object")};
367 DenseMap<JITDylib *, SymbolLookupSet> RegisteredInitSymbols;
369 std::mutex PlatformMutex;
370 BootstrapInfo *Bootstrap =
nullptr;
371 DenseMap<JITDylib *, ExecutorAddr> JITDylibToHeaderAddr;
372 DenseMap<ExecutorAddr, JITDylib *> HeaderAddrToJITDylib;
373 DenseMap<JITDylib *, uint64_t> JITDylibToPThreadKey;
382 void materialize(std::unique_ptr<MaterializationResponsibility> R)
override;
393 struct HeaderSymbol {
398 static constexpr HeaderSymbol AdditionalHeaderSymbols[] = {
399 {
"___mh_executable_header", 0}};
401 void addMachOHeader(
JITDylib &JD, jitlink::LinkGraph &
G,
402 const SymbolStringPtr &InitializerSymbol);
403 static MaterializationUnit::Interface
404 createHeaderInterface(MachOPlatform &
MOP,
405 const SymbolStringPtr &HeaderStartSymbol);
409inline std::unique_ptr<MaterializationUnit>
412 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.