LLVM  14.0.0git
Classes | Public Member Functions | Static Public Member Functions | List of all members
llvm::orc::MachOPlatform Class Reference

Mediates between MachO initialization and ExecutionSession state. More...

#include "llvm/ExecutionEngine/Orc/MachOPlatform.h"

Inheritance diagram for llvm::orc::MachOPlatform:
Inheritance graph
[legend]
Collaboration diagram for llvm::orc::MachOPlatform:
Collaboration graph
[legend]

Public Member Functions

ExecutionSessiongetExecutionSession () const
 
ObjectLinkingLayergetObjectLinkingLayer () const
 
Error setupJITDylib (JITDylib &JD) override
 This method will be called outside the session lock each time a JITDylib is created (unless it is created with EmptyJITDylib set) to allow the Platform to install any JITDylib specific standard symbols (e.g __dso_handle). More...
 
Error notifyAdding (ResourceTracker &RT, const MaterializationUnit &MU) override
 This method will be called under the ExecutionSession lock each time a MaterializationUnit is added to a JITDylib. More...
 
Error notifyRemoving (ResourceTracker &RT) override
 This method will be called under the ExecutionSession lock when a ResourceTracker is removed. More...
 
- Public Member Functions inherited from llvm::orc::Platform
virtual ~Platform ()
 

Static Public Member Functions

static Expected< std::unique_ptr< MachOPlatform > > Create (ExecutionSession &ES, ObjectLinkingLayer &ObjLinkingLayer, JITDylib &PlatformJD, const char *OrcRuntimePath, Optional< SymbolAliasMap > RuntimeAliases=None)
 Try to create a MachOPlatform instance, adding the ORC runtime to the given JITDylib. More...
 
static SymbolAliasMap standardPlatformAliases (ExecutionSession &ES)
 Returns an AliasMap containing the default aliases for the MachOPlatform. More...
 
static ArrayRef< std::pair< const char *, const char * > > requiredCXXAliases ()
 Returns the array of required CXX aliases. More...
 
static ArrayRef< std::pair< const char *, const char * > > standardRuntimeUtilityAliases ()
 Returns the array of standard runtime utility aliases for MachO. More...
 
static bool isInitializerSection (StringRef SegName, StringRef SectName)
 Returns true if the given section name is an initializer section. More...
 
- Static Public Member Functions inherited from llvm::orc::Platform
static Expected< DenseMap< JITDylib *, SymbolMap > > lookupInitSymbols (ExecutionSession &ES, const DenseMap< JITDylib *, SymbolLookupSet > &InitSyms)
 A utility function for looking up initializer symbols. More...
 
static void lookupInitSymbolsAsync (unique_function< void(Error)> OnComplete, ExecutionSession &ES, const DenseMap< JITDylib *, SymbolLookupSet > &InitSyms)
 Performs an async lookup for the the given symbols in each of the given JITDylibs, calling the given handler with the compound result map once all lookups have completed. More...
 

Detailed Description

Mediates between MachO initialization and ExecutionSession state.

Definition at line 51 of file MachOPlatform.h.

Member Function Documentation

◆ Create()

Expected< std::unique_ptr< MachOPlatform > > llvm::orc::MachOPlatform::Create ( ExecutionSession ES,
ObjectLinkingLayer ObjLinkingLayer,
JITDylib PlatformJD,
const char *  OrcRuntimePath,
Optional< SymbolAliasMap RuntimeAliases = None 
)
static

Try to create a MachOPlatform instance, adding the ORC runtime to the given JITDylib.

The ORC runtime requires access to a number of symbols in libc++, and requires access to symbols in libobjc, and libswiftCore to support Objective-C and Swift code. It is up to the caller to ensure that the requried symbols can be referenced by code added to PlatformJD. The standard way to achieve this is to first attach dynamic library search generators for either the given process, or for the specific required libraries, to PlatformJD, then to create the platform instance:

auto &PlatformJD = ES.createBareJITDylib("stdlib");
PlatformJD.addGenerator(
ExitOnErr(EPCDynamicLibrarySearchGenerator
::GetForTargetProcess(EPC)));
ExitOnErr(MachOPlatform::Create(ES, ObjLayer, EPC, PlatformJD,
"/path/to/orc/runtime")));

Alternatively, these symbols could be added to another JITDylib that PlatformJD links against.

Clients are also responsible for ensuring that any JIT'd code that depends on runtime functions (including any code using TLV or static destructors) can reference the runtime symbols. This is usually achieved by linking any JITDylibs containing regular code against PlatformJD.

By default, MachOPlatform will add the set of aliases returned by the standardPlatformAliases function. This includes both required aliases (e.g. __cxa_atexit -> __orc_rt_macho_cxa_atexit for static destructor support), and optional aliases that provide JIT versions of common functions (e.g. dlopen -> __orc_rt_macho_jit_dlopen). Clients can override these defaults by passing a non-None value for the RuntimeAliases function, in which case the client is responsible for setting up all aliases (including the required ones).

Definition at line 155 of file MachOPlatform.cpp.

References llvm::orc::ExecutionSession::getExecutorProcessControl(), and llvm::inconvertibleErrorCode().

◆ getExecutionSession()

ExecutionSession& llvm::orc::MachOPlatform::getExecutionSession ( ) const
inline

Definition at line 96 of file MachOPlatform.h.

◆ getObjectLinkingLayer()

ObjectLinkingLayer& llvm::orc::MachOPlatform::getObjectLinkingLayer ( ) const
inline

Definition at line 97 of file MachOPlatform.h.

◆ isInitializerSection()

bool llvm::orc::MachOPlatform::isInitializerSection ( StringRef  SegName,
StringRef  SectName 
)
static

Returns true if the given section name is an initializer section.

Definition at line 262 of file MachOPlatform.cpp.

Referenced by llvm::orc::getMachOObjectFileSymbolInfo().

◆ notifyAdding()

Error llvm::orc::MachOPlatform::notifyAdding ( ResourceTracker RT,
const MaterializationUnit MU 
)
overridevirtual

◆ notifyRemoving()

Error llvm::orc::MachOPlatform::notifyRemoving ( ResourceTracker RT)
overridevirtual

This method will be called under the ExecutionSession lock when a ResourceTracker is removed.

Implements llvm::orc::Platform.

Definition at line 222 of file MachOPlatform.cpp.

References llvm_unreachable.

◆ requiredCXXAliases()

ArrayRef< std::pair< const char *, const char * > > llvm::orc::MachOPlatform::requiredCXXAliases ( )
static

Returns the array of required CXX aliases.

Definition at line 244 of file MachOPlatform.cpp.

◆ setupJITDylib()

Error llvm::orc::MachOPlatform::setupJITDylib ( JITDylib JD)
overridevirtual

This method will be called outside the session lock each time a JITDylib is created (unless it is created with EmptyJITDylib set) to allow the Platform to install any JITDylib specific standard symbols (e.g __dso_handle).

Implements llvm::orc::Platform.

Definition at line 201 of file MachOPlatform.cpp.

References llvm::orc::JITDylib::define().

◆ standardPlatformAliases()

SymbolAliasMap llvm::orc::MachOPlatform::standardPlatformAliases ( ExecutionSession ES)
static

Returns an AliasMap containing the default aliases for the MachOPlatform.

This can be modified by clients when constructing the platform to add or remove aliases.

Definition at line 236 of file MachOPlatform.cpp.

References llvm::orc::addAliases().

◆ standardRuntimeUtilityAliases()

ArrayRef< std::pair< const char *, const char * > > llvm::orc::MachOPlatform::standardRuntimeUtilityAliases ( )
static

Returns the array of standard runtime utility aliases for MachO.

Definition at line 252 of file MachOPlatform.cpp.


The documentation for this class was generated from the following files:
llvm::orc::MachOPlatform::Create
static Expected< std::unique_ptr< MachOPlatform > > Create(ExecutionSession &ES, ObjectLinkingLayer &ObjLinkingLayer, JITDylib &PlatformJD, const char *OrcRuntimePath, Optional< SymbolAliasMap > RuntimeAliases=None)
Try to create a MachOPlatform instance, adding the ORC runtime to the given JITDylib.
Definition: MachOPlatform.cpp:155
llvm::orc::JITDylib::addGenerator
GeneratorT & addGenerator(std::unique_ptr< GeneratorT > DefGenerator)
Adds a definition generator to this JITDylib and returns a referenece to it.
Definition: Core.h:1775
llvm::orc::ExecutionSession::setPlatform
void setPlatform(std::unique_ptr< Platform > P)
Set the Platform for this ExecutionSession.
Definition: Core.h:1405
llvm::orc::ExecutionSession::createBareJITDylib
JITDylib & createBareJITDylib(std::string Name)
Add a new bare JITDylib to this ExecutionSession.
Definition: Core.cpp:1906