LLVM 20.0.0git
|
This is a simple memory manager which implements the methods called by the RuntimeDyld class to allocate memory for section-based loading of objects, usually those generated by the MCJIT execution engine. More...
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
Classes | |
class | MemoryMapper |
Implementations of this interface are used by SectionMemoryManager to request pages from the operating system. More... | |
Public Types | |
enum class | AllocationPurpose { Code , ROData , RWData } |
This enum describes the various reasons to allocate pages from allocateMappedMemory. More... | |
Public Types inherited from llvm::JITSymbolResolver | |
using | LookupSet = std::set< StringRef > |
using | LookupResult = std::map< StringRef, JITEvaluatedSymbol > |
using | OnResolvedFunction = unique_function< void(Expected< LookupResult >)> |
Public Member Functions | |
SectionMemoryManager (MemoryMapper *MM=nullptr) | |
Creates a SectionMemoryManager instance with MM as the associated memory mapper. | |
SectionMemoryManager (const SectionMemoryManager &)=delete | |
void | operator= (const SectionMemoryManager &)=delete |
~SectionMemoryManager () override | |
uint8_t * | allocateCodeSection (uintptr_t Size, unsigned Alignment, unsigned SectionID, StringRef SectionName) override |
Allocates a memory block of (at least) the given size suitable for executable code. | |
uint8_t * | allocateDataSection (uintptr_t Size, unsigned Alignment, unsigned SectionID, StringRef SectionName, bool isReadOnly) override |
Allocates a memory block of (at least) the given size suitable for executable code. | |
bool | finalizeMemory (std::string *ErrMsg=nullptr) override |
Update section-specific memory permissions and other attributes. | |
virtual void | invalidateInstructionCache () |
Invalidate instruction cache for code sections. | |
Public Member Functions inherited from llvm::RTDyldMemoryManager | |
RTDyldMemoryManager ()=default | |
RTDyldMemoryManager (const RTDyldMemoryManager &)=delete | |
void | operator= (const RTDyldMemoryManager &)=delete |
~RTDyldMemoryManager () override | |
void | registerEHFrames (uint8_t *Addr, uint64_t LoadAddr, size_t Size) override |
Register the EH frames with the runtime so that c++ exceptions work. | |
void | deregisterEHFrames () override |
virtual uint64_t | getSymbolAddress (const std::string &Name) |
Legacy symbol lookup - DEPRECATED! Please override findSymbol instead. | |
JITSymbol | findSymbol (const std::string &Name) override |
This method returns a RuntimeDyld::SymbolInfo for the specified function or variable. | |
virtual uint64_t | getSymbolAddressInLogicalDylib (const std::string &Name) |
Legacy symbol lookup – DEPRECATED! Please override findSymbolInLogicalDylib instead. | |
JITSymbol | findSymbolInLogicalDylib (const std::string &Name) override |
Default to treating all modules as separate. | |
virtual void * | getPointerToNamedFunction (const std::string &Name, bool AbortOnFailure=true) |
This method returns the address of the specified function. | |
Public Member Functions inherited from llvm::MCJITMemoryManager | |
virtual void | notifyObjectLoaded (ExecutionEngine *EE, const object::ObjectFile &) |
This method is called after an object has been loaded into memory but before relocations are applied to the loaded sections. | |
Public Member Functions inherited from llvm::RuntimeDyld::MemoryManager | |
MemoryManager ()=default | |
virtual | ~MemoryManager ()=default |
virtual uint8_t * | allocateCodeSection (uintptr_t Size, unsigned Alignment, unsigned SectionID, StringRef SectionName)=0 |
Allocate a memory block of (at least) the given size suitable for executable code. | |
virtual uint8_t * | allocateDataSection (uintptr_t Size, unsigned Alignment, unsigned SectionID, StringRef SectionName, bool IsReadOnly)=0 |
Allocate a memory block of (at least) the given size suitable for data. | |
virtual TLSSection | allocateTLSSection (uintptr_t Size, unsigned Alignment, unsigned SectionID, StringRef SectionName) |
Allocate a memory block of (at least) the given size to be used for thread-local storage (TLS). | |
virtual void | reserveAllocationSpace (uintptr_t CodeSize, Align CodeAlign, uintptr_t RODataSize, Align RODataAlign, uintptr_t RWDataSize, Align RWDataAlign) |
Inform the memory manager about the total amount of memory required to allocate all sections to be loaded: CodeSize - the total size of all code sections DataSizeRO - the total size of all read-only data sections DataSizeRW - the total size of all read-write data sections. | |
virtual bool | needsToReserveAllocationSpace () |
Override to return true to enable the reserveAllocationSpace callback. | |
virtual bool | allowStubAllocation () const |
Override to return false to tell LLVM no stub space will be needed. | |
virtual void | registerEHFrames (uint8_t *Addr, uint64_t LoadAddr, size_t Size)=0 |
Register the EH frames with the runtime so that c++ exceptions work. | |
virtual void | deregisterEHFrames ()=0 |
virtual bool | finalizeMemory (std::string *ErrMsg=nullptr)=0 |
This method is called when object loading is complete and section page permissions can be applied. | |
virtual void | notifyObjectLoaded (RuntimeDyld &RTDyld, const object::ObjectFile &Obj) |
This method is called after an object has been loaded into memory but before relocations are applied to the loaded sections. | |
Public Member Functions inherited from llvm::LegacyJITSymbolResolver | |
void | lookup (const LookupSet &Symbols, OnResolvedFunction OnResolved) final |
Performs lookup by, for each symbol, first calling findSymbolInLogicalDylib and if that fails calling findSymbol. | |
Expected< LookupSet > | getResponsibilitySet (const LookupSet &Symbols) final |
Performs flags lookup by calling findSymbolInLogicalDylib and returning the flags value for that symbol. | |
virtual JITSymbol | findSymbolInLogicalDylib (const std::string &Name)=0 |
This method returns the address of the specified symbol if it exists within the logical dynamic library represented by this JITSymbolResolver. | |
virtual JITSymbol | findSymbol (const std::string &Name)=0 |
This method returns the address of the specified function or variable. | |
Public Member Functions inherited from llvm::JITSymbolResolver | |
virtual | ~JITSymbolResolver ()=default |
virtual void | lookup (const LookupSet &Symbols, OnResolvedFunction OnResolved)=0 |
Returns the fully resolved address and flags for each of the given symbols. | |
virtual Expected< LookupSet > | getResponsibilitySet (const LookupSet &Symbols)=0 |
Returns the subset of the given symbols that should be materialized by the caller. | |
virtual bool | allowsZeroSymbols () |
Specify if this resolver can return valid symbols with zero value. | |
Additional Inherited Members | |
Static Public Member Functions inherited from llvm::RTDyldMemoryManager | |
static void | registerEHFramesInProcess (uint8_t *Addr, size_t Size) |
Register EH frames in the current process. | |
static void | deregisterEHFramesInProcess (uint8_t *Addr, size_t Size) |
Deregister EH frames in the current process. | |
static uint64_t | getSymbolAddressInProcess (const std::string &Name) |
This method returns the address of the specified function or variable in the current process. | |
Protected Types inherited from llvm::RTDyldMemoryManager | |
typedef std::vector< EHFrame > | EHFrameInfos |
Protected Attributes inherited from llvm::RTDyldMemoryManager | |
EHFrameInfos | EHFrames |
This is a simple memory manager which implements the methods called by the RuntimeDyld class to allocate memory for section-based loading of objects, usually those generated by the MCJIT execution engine.
This memory manager allocates all section memory as read-write. The RuntimeDyld will copy JITed section memory into these allocated blocks and perform any necessary linking and relocations.
Any client using this memory manager MUST ensure that section-specific page permissions have been applied before attempting to execute functions in the JITed object. Permissions can be applied either by calling MCJIT::finalizeObject or by calling SectionMemoryManager::finalizeMemory directly. Clients of MCJIT should call MCJIT::finalizeObject.
Definition at line 39 of file SectionMemoryManager.h.
|
strong |
This enum describes the various reasons to allocate pages from allocateMappedMemory.
Enumerator | |
---|---|
Code | |
ROData | |
RWData |
Definition at line 43 of file SectionMemoryManager.h.
llvm::SectionMemoryManager::SectionMemoryManager | ( | MemoryMapper * | MM = nullptr | ) |
Creates a SectionMemoryManager instance with MM
as the associated memory mapper.
If MM
is nullptr then a default memory mapper is used that directly calls into the operating system.
Definition at line 268 of file SectionMemoryManager.cpp.
|
delete |
|
override |
Definition at line 234 of file SectionMemoryManager.cpp.
References llvm::Block, and llvm::SectionMemoryManager::MemoryMapper::releaseMappedMemory().
|
overridevirtual |
Allocates a memory block of (at least) the given size suitable for executable code.
The value of Alignment
must be a power of two. If Alignment
is zero a default alignment of 16 will be used.
Implements llvm::RuntimeDyld::MemoryManager.
Definition at line 33 of file SectionMemoryManager.cpp.
|
overridevirtual |
Allocates a memory block of (at least) the given size suitable for executable code.
The value of Alignment
must be a power of two. If Alignment
is zero a default alignment of 16 will be used.
Implements llvm::RuntimeDyld::MemoryManager.
Definition at line 21 of file SectionMemoryManager.cpp.
|
overridevirtual |
Update section-specific memory permissions and other attributes.
This method is called when object loading is complete and section page permissions can be applied. It is up to the memory manager implementation to decide whether or not to act on this method. The memory manager will typically allocate all sections as read-write and then apply specific permissions when this method is called. Code sections cannot be executed until this function has been called. In addition, any cache coherency operations needed to reliably use the memory are also performed.
Implements llvm::RuntimeDyld::MemoryManager.
Definition at line 149 of file SectionMemoryManager.cpp.
References invalidateInstructionCache(), llvm::sys::Memory::MF_EXEC, and llvm::sys::Memory::MF_READ.
|
virtual |
Invalidate instruction cache for code sections.
Some platforms with separate data cache and instruction cache require explicit cache flush, otherwise JIT code manipulations (like resolved relocations) will get to the data cache but not to the instruction cache.
This method is called from finalizeMemory.
Definition at line 228 of file SectionMemoryManager.cpp.
References llvm::Block, and llvm::sys::Memory::InvalidateInstructionCache().
Referenced by finalizeMemory().
|
delete |
References llvm::Free.