summaryrefslogtreecommitdiff
path: root/tools/llvm-rtdyld
diff options
context:
space:
mode:
authorDanil Malyshev <dmalyshev@accesssoftek.com>2012-05-16 18:50:11 +0000
committerDanil Malyshev <dmalyshev@accesssoftek.com>2012-05-16 18:50:11 +0000
commit068c65b22d50c265b51886062b2b9c1cb696d67d (patch)
tree291d4c251d82265b2a45db53727414c6dee2abe0 /tools/llvm-rtdyld
parentab53f8ea6a8aa616b2ae153a5ff941e4a855a07d (diff)
downloadllvm-068c65b22d50c265b51886062b2b9c1cb696d67d.tar.gz
llvm-068c65b22d50c265b51886062b2b9c1cb696d67d.tar.bz2
llvm-068c65b22d50c265b51886062b2b9c1cb696d67d.tar.xz
Added LLIMCJITMemoryManager to the lli. This manager will be used for MCJIT instead of DefaultJIMMemoryManager.
It's more flexible for MCJIT tasks, in addition it's provides a invalidation instruction cache for code sections which will be used before JIT code will be executed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@156933 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-rtdyld')
-rw-r--r--tools/llvm-rtdyld/llvm-rtdyld.cpp25
1 files changed, 23 insertions, 2 deletions
diff --git a/tools/llvm-rtdyld/llvm-rtdyld.cpp b/tools/llvm-rtdyld/llvm-rtdyld.cpp
index 01a7d15807..95de8d8a4d 100644
--- a/tools/llvm-rtdyld/llvm-rtdyld.cpp
+++ b/tools/llvm-rtdyld/llvm-rtdyld.cpp
@@ -63,18 +63,37 @@ public:
return 0;
}
+ // Invalidate instruction cache for sections with execute permissions.
+ // 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.
+ virtual void invalidateInstructionCache();
};
uint8_t *TrivialMemoryManager::allocateCodeSection(uintptr_t Size,
unsigned Alignment,
unsigned SectionID) {
- return (uint8_t*)sys::Memory::AllocateRWX(Size, 0, 0).base();
+ sys::MemoryBlock MB = sys::Memory::AllocateRWX(Size, 0, 0);
+ FunctionMemory.push_back(MB);
+ return (uint8_t*)MB.base();
}
uint8_t *TrivialMemoryManager::allocateDataSection(uintptr_t Size,
unsigned Alignment,
unsigned SectionID) {
- return (uint8_t*)sys::Memory::AllocateRWX(Size, 0, 0).base();
+ sys::MemoryBlock MB = sys::Memory::AllocateRWX(Size, 0, 0);
+ DataMemory.push_back(MB);
+ return (uint8_t*)MB.base();
+}
+
+void TrivialMemoryManager::invalidateInstructionCache() {
+ for (int i = 0, e = FunctionMemory.size(); i != e; ++i)
+ sys::Memory::InvalidateInstructionCache(FunctionMemory[i].base(),
+ FunctionMemory[i].size());
+
+ for (int i = 0, e = DataMemory.size(); i != e; ++i)
+ sys::Memory::InvalidateInstructionCache(DataMemory[i].base(),
+ DataMemory[i].size());
}
static const char *ProgramName;
@@ -113,6 +132,8 @@ static int executeInput() {
// Resolve all the relocations we can.
Dyld.resolveRelocations();
+ // Clear instruction cache before code will be executed.
+ MemMgr->invalidateInstructionCache();
// FIXME: Error out if there are unresolved relocations.