diff options
Diffstat (limited to 'tools/lli')
-rw-r--r-- | tools/lli/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tools/lli/Makefile | 2 | ||||
-rw-r--r-- | tools/lli/RecordingMemoryManager.cpp | 47 | ||||
-rw-r--r-- | tools/lli/RecordingMemoryManager.h | 8 | ||||
-rw-r--r-- | tools/lli/lli.cpp | 6 |
5 files changed, 50 insertions, 15 deletions
diff --git a/tools/lli/CMakeLists.txt b/tools/lli/CMakeLists.txt index ed479f5323..356233f397 100644 --- a/tools/lli/CMakeLists.txt +++ b/tools/lli/CMakeLists.txt @@ -11,7 +11,9 @@ endif( LLVM_USE_OPROFILE ) if( LLVM_USE_INTEL_JITEVENTS ) set(LLVM_LINK_COMPONENTS ${LLVM_LINK_COMPONENTS} + DebugInfo IntelJITEvents + Object ) endif( LLVM_USE_INTEL_JITEVENTS ) diff --git a/tools/lli/Makefile b/tools/lli/Makefile index 31f3ab8a1e..85ac6b46bb 100644 --- a/tools/lli/Makefile +++ b/tools/lli/Makefile @@ -17,7 +17,7 @@ LINK_COMPONENTS := mcjit jit interpreter nativecodegen bitreader asmparser selec # If Intel JIT Events support is confiured, link against the LLVM Intel JIT # Events interface library ifeq ($(USE_INTEL_JITEVENTS), 1) - LINK_COMPONENTS += inteljitevents + LINK_COMPONENTS += debuginfo inteljitevents object endif # If oprofile support is confiured, link against the LLVM oprofile interface diff --git a/tools/lli/RecordingMemoryManager.cpp b/tools/lli/RecordingMemoryManager.cpp index 75cb978130..e4d992d3d4 100644 --- a/tools/lli/RecordingMemoryManager.cpp +++ b/tools/lli/RecordingMemoryManager.cpp @@ -15,16 +15,26 @@ #include "RecordingMemoryManager.h" using namespace llvm; +RecordingMemoryManager::~RecordingMemoryManager() { + for (SmallVectorImpl<Allocation>::iterator + I = AllocatedCodeMem.begin(), E = AllocatedCodeMem.end(); + I != E; ++I) + sys::Memory::releaseMappedMemory(I->first); + for (SmallVectorImpl<Allocation>::iterator + I = AllocatedDataMem.begin(), E = AllocatedDataMem.end(); + I != E; ++I) + sys::Memory::releaseMappedMemory(I->first); +} + uint8_t *RecordingMemoryManager:: allocateCodeSection(uintptr_t Size, unsigned Alignment, unsigned SectionID) { // The recording memory manager is just a local copy of the remote target. // The alignment requirement is just stored here for later use. Regular - // heap storage is sufficient here. - void *Addr = malloc(Size); - assert(Addr && "malloc() failure!"); - sys::MemoryBlock Block(Addr, Size); + // heap storage is sufficient here, but we're using mapped memory to work + // around a bug in MCJIT. + sys::MemoryBlock Block = allocateSection(Size); AllocatedCodeMem.push_back(Allocation(Block, Alignment)); - return (uint8_t*)Addr; + return (uint8_t*)Block.base(); } uint8_t *RecordingMemoryManager:: @@ -32,13 +42,30 @@ allocateDataSection(uintptr_t Size, unsigned Alignment, unsigned SectionID, bool IsReadOnly) { // The recording memory manager is just a local copy of the remote target. // The alignment requirement is just stored here for later use. Regular - // heap storage is sufficient here. - void *Addr = malloc(Size); - assert(Addr && "malloc() failure!"); - sys::MemoryBlock Block(Addr, Size); + // heap storage is sufficient here, but we're using mapped memory to work + // around a bug in MCJIT. + sys::MemoryBlock Block = allocateSection(Size); AllocatedDataMem.push_back(Allocation(Block, Alignment)); - return (uint8_t*)Addr; + return (uint8_t*)Block.base(); +} + +sys::MemoryBlock RecordingMemoryManager::allocateSection(uintptr_t Size) { + error_code ec; + sys::MemoryBlock MB = sys::Memory::allocateMappedMemory(Size, + &Near, + sys::Memory::MF_READ | + sys::Memory::MF_WRITE, + ec); + assert(!ec && MB.base()); + + // FIXME: This is part of a work around to keep sections near one another + // when MCJIT performs relocations after code emission but before + // the generated code is moved to the remote target. + // Save this address as the basis for our next request + Near = MB; + return MB; } + void RecordingMemoryManager::setMemoryWritable() { llvm_unreachable("Unexpected!"); } void RecordingMemoryManager::setMemoryExecutable() { llvm_unreachable("Unexpected!"); } void RecordingMemoryManager::setPoisonMemory(bool poison) { llvm_unreachable("Unexpected!"); } diff --git a/tools/lli/RecordingMemoryManager.h b/tools/lli/RecordingMemoryManager.h index 20fd0c2e6e..991f535fd4 100644 --- a/tools/lli/RecordingMemoryManager.h +++ b/tools/lli/RecordingMemoryManager.h @@ -31,9 +31,15 @@ private: SmallVector<Allocation, 16> AllocatedDataMem; SmallVector<Allocation, 16> AllocatedCodeMem; + // FIXME: This is part of a work around to keep sections near one another + // when MCJIT performs relocations after code emission but before + // the generated code is moved to the remote target. + sys::MemoryBlock Near; + sys::MemoryBlock allocateSection(uintptr_t Size); + public: RecordingMemoryManager() {} - virtual ~RecordingMemoryManager() {} + virtual ~RecordingMemoryManager(); typedef SmallVectorImpl<Allocation>::const_iterator const_data_iterator; typedef SmallVectorImpl<Allocation>::const_iterator const_code_iterator; diff --git a/tools/lli/lli.cpp b/tools/lli/lli.cpp index 5135d5041f..332660fc1e 100644 --- a/tools/lli/lli.cpp +++ b/tools/lli/lli.cpp @@ -14,7 +14,7 @@ //===----------------------------------------------------------------------===// #define DEBUG_TYPE "lli" -#include "llvm/LLVMContext.h" +#include "llvm/IR/LLVMContext.h" #include "RecordingMemoryManager.h" #include "RemoteTarget.h" #include "llvm/ADT/Triple.h" @@ -27,7 +27,8 @@ #include "llvm/ExecutionEngine/JITMemoryManager.h" #include "llvm/ExecutionEngine/MCJIT.h" #include "llvm/ExecutionEngine/SectionMemoryManager.h" -#include "llvm/Module.h" +#include "llvm/IR/Module.h" +#include "llvm/IR/Type.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" #include "llvm/Support/DynamicLibrary.h" @@ -43,7 +44,6 @@ #include "llvm/Support/Signals.h" #include "llvm/Support/TargetSelect.h" #include "llvm/Support/raw_ostream.h" -#include "llvm/Type.h" #include <cerrno> #ifdef __CYGWIN__ |