LLVM  3.7.0
Classes | Public Member Functions | List of all members
llvm::SectionMemoryManager Class Reference

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 <SectionMemoryManager.h>

Inheritance diagram for llvm::SectionMemoryManager:
[legend]
Collaboration diagram for llvm::SectionMemoryManager:
[legend]

Public Member Functions

 SectionMemoryManager ()
 
 ~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 ()
 
 ~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 (uint8_t *Addr, uint64_t LoadAddr, size_t Size) override
 
virtual uint64_t getSymbolAddress (const std::string &Name)
 Legacy symbol lookup - DEPRECATED! Please override findSymbol instead. More...
 
RuntimeDyld::SymbolInfo 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...
 
RuntimeDyld::SymbolInfo 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
virtual ~MemoryManager ()
 
virtual void reserveAllocationSpace (uintptr_t CodeSize, uintptr_t DataSizeRO, uintptr_t DataSizeRW)
 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...
 
- Public Member Functions inherited from llvm::RuntimeDyld::SymbolResolver
virtual ~SymbolResolver ()
 

Additional Inherited Members

- Static Public Member Functions inherited from llvm::RTDyldMemoryManager
static uint64_t getSymbolAddressInProcess (const std::string &Name)
 This method returns the address of the specified function or variable in the current process. More...
 

Detailed Description

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 37 of file SectionMemoryManager.h.

Constructor & Destructor Documentation

llvm::SectionMemoryManager::SectionMemoryManager ( )
inline

Definition at line 42 of file SectionMemoryManager.h.

llvm::SectionMemoryManager::~SectionMemoryManager ( )
override

Member Function Documentation

uint8_t * llvm::SectionMemoryManager::allocateCodeSection ( uintptr_t  Size,
unsigned  Alignment,
unsigned  SectionID,
StringRef  SectionName 
)
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 31 of file SectionMemoryManager.cpp.

uint8_t * llvm::SectionMemoryManager::allocateDataSection ( uintptr_t  Size,
unsigned  Alignment,
unsigned  SectionID,
StringRef  SectionName,
bool  isReadOnly 
)
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.

bool llvm::SectionMemoryManager::finalizeMemory ( std::string *  ErrMsg = nullptr)
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.

Returns
true if an error occurred, false otherwise.

Implements llvm::RuntimeDyld::MemoryManager.

Definition at line 105 of file SectionMemoryManager.cpp.

References invalidateInstructionCache(), llvm::sys::Memory::MF_EXEC, and llvm::sys::Memory::MF_READ.

void llvm::SectionMemoryManager::invalidateInstructionCache ( )
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 162 of file SectionMemoryManager.cpp.

References llvm::sys::Memory::InvalidateInstructionCache().

Referenced by finalizeMemory().


The documentation for this class was generated from the following files: