LLVM
8.0.1
|
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 | AllocationPurpose { AllocationPurpose::Code, AllocationPurpose::ROData, AllocationPurpose::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 = std::function< void(Expected< LookupResult >)> |
Public Member Functions | |
SectionMemoryManager (MemoryMapper *MM=nullptr) | |
Creates a SectionMemoryManager instance with MM as the associated memory mapper. More... | |
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. More... | |
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. More... | |
bool | finalizeMemory (std::string *ErrMsg=nullptr) override |
Update section-specific memory permissions and other attributes. More... | |
virtual void | invalidateInstructionCache () |
Invalidate instruction cache for code sections. More... | |
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. More... | |
void | deregisterEHFrames () override |
virtual uint64_t | getSymbolAddress (const std::string &Name) |
Legacy symbol lookup - DEPRECATED! Please override findSymbol instead. More... | |
JITSymbol | findSymbol (const std::string &Name) override |
This method returns a RuntimeDyld::SymbolInfo for the specified function or variable. More... | |
virtual uint64_t | getSymbolAddressInLogicalDylib (const std::string &Name) |
Legacy symbol lookup – DEPRECATED! Please override findSymbolInLogicalDylib instead. More... | |
JITSymbol | findSymbolInLogicalDylib (const std::string &Name) override |
Default to treating all modules as separate. More... | |
virtual void * | getPointerToNamedFunction (const std::string &Name, bool AbortOnFailure=true) |
This method returns the address of the specified function. More... | |
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. More... | |
Public Member Functions inherited from llvm::RuntimeDyld::MemoryManager | |
MemoryManager ()=default | |
virtual | ~MemoryManager ()=default |
virtual void | reserveAllocationSpace (uintptr_t CodeSize, uint32_t CodeAlign, uintptr_t RODataSize, uint32_t RODataAlign, uintptr_t RWDataSize, uint32_t 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. More... | |
virtual bool | needsToReserveAllocationSpace () |
Override to return true to enable the reserveAllocationSpace callback. More... | |
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. More... | |
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. More... | |
Expected< LookupSet > | getResponsibilitySet (const LookupSet &Symbols) final |
Performs flags lookup by calling findSymbolInLogicalDylib and returning the flags value for that symbol. More... | |
Public Member Functions inherited from llvm::JITSymbolResolver | |
virtual | ~JITSymbolResolver ()=default |
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. More... | |
static void | deregisterEHFramesInProcess (uint8_t *Addr, size_t Size) |
Deregister EH frames in the current proces. More... | |
static uint64_t | getSymbolAddressInProcess (const std::string &Name) |
This method returns the address of the specified function or variable in the current process. More... | |
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 41 of file SectionMemoryManager.h.
|
strong |
This enum describes the various reasons to allocate pages from allocateMappedMemory.
Enumerator | |
---|---|
Code | |
ROData | |
RWData |
Definition at line 45 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 262 of file SectionMemoryManager.cpp.
|
delete |
|
override |
Definition at line 226 of file SectionMemoryManager.cpp.
References 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 34 of file SectionMemoryManager.cpp.
References llvm::SectionMemoryManager::MemoryMapper::allocateMappedMemory(), assert(), llvm::sys::MemoryBlock::base(), Code, llvm_unreachable, llvm::sys::Memory::MF_READ, llvm::sys::Memory::MF_WRITE, ROData, RWData, llvm::sys::MemoryBlock::size(), and Size.
|
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 22 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 141 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 221 of file SectionMemoryManager.cpp.
References llvm::sys::MemoryBlock::base(), llvm::sys::Memory::InvalidateInstructionCache(), and llvm::sys::MemoryBlock::size().
Referenced by finalizeMemory().
|
delete |