aboutsummaryrefslogtreecommitdiffstats
path: root/lib/ExecutionEngine
diff options
context:
space:
mode:
authorNuno Lopes <nunoplopes@sapo.pt>2008-10-21 11:42:16 +0000
committerNuno Lopes <nunoplopes@sapo.pt>2008-10-21 11:42:16 +0000
commitcef7527a85d026aeb17a4dacca73c70c0ab5da40 (patch)
tree0a85fcdb02a052b1f08c226af631021cab95fc2c /lib/ExecutionEngine
parente06e91122fefcadd252ddd2f2591e181683fc2f1 (diff)
downloadexternal_llvm-cef7527a85d026aeb17a4dacca73c70c0ab5da40.zip
external_llvm-cef7527a85d026aeb17a4dacca73c70c0ab5da40.tar.gz
external_llvm-cef7527a85d026aeb17a4dacca73c70c0ab5da40.tar.bz2
fix a tricky bug in the JIT global variable emitter, that was triggered when JITing a variable independently of a function. This lead to sharing memory memory between functions and GVs thus changing the value of a GV could change the code in execution. more details on the ML.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@57900 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine')
-rw-r--r--lib/ExecutionEngine/JIT/JITEmitter.cpp27
-rw-r--r--lib/ExecutionEngine/JIT/JITMemoryManager.cpp19
2 files changed, 40 insertions, 6 deletions
diff --git a/lib/ExecutionEngine/JIT/JITEmitter.cpp b/lib/ExecutionEngine/JIT/JITEmitter.cpp
index a90a6a5..688d498 100644
--- a/lib/ExecutionEngine/JIT/JITEmitter.cpp
+++ b/lib/ExecutionEngine/JIT/JITEmitter.cpp
@@ -518,6 +518,10 @@ namespace {
unsigned Alignment = 1);
virtual void* finishFunctionStub(const GlobalValue *F);
+ /// allocateSpace - Reserves space in the current block if any, or
+ /// allocate a new one of the given size.
+ virtual void *allocateSpace(intptr_t Size, unsigned Alignment);
+
virtual void addRelocation(const MachineRelocation &MR) {
Relocations.push_back(MR);
}
@@ -915,11 +919,6 @@ bool JITEmitter::finishFunction(MachineFunction &F) {
Relocations.size(), MemMgr->getGOTBase());
}
- unsigned char *FnEnd = CurBufferPtr;
-
- MemMgr->endFunctionBody(F.getFunction(), BufferBegin, FnEnd);
- NumBytes += FnEnd-FnStart;
-
// Update the GOT entry for F to point to the new code.
if (MemMgr->isManagingGOT()) {
unsigned idx = Resolver.getGOTIndexForAddr((void*)BufferBegin);
@@ -930,6 +929,12 @@ bool JITEmitter::finishFunction(MachineFunction &F) {
}
}
+ unsigned char *FnEnd = CurBufferPtr;
+
+ MemMgr->endFunctionBody(F.getFunction(), BufferBegin, FnEnd);
+ BufferBegin = CurBufferPtr = 0;
+ NumBytes += FnEnd-FnStart;
+
// Invalidate the icache if necessary.
sys::Memory::InvalidateInstructionCache(FnStart, FnEnd-FnStart);
@@ -993,6 +998,18 @@ bool JITEmitter::finishFunction(MachineFunction &F) {
return false;
}
+void* JITEmitter::allocateSpace(intptr_t Size, unsigned Alignment) {
+ if (BufferBegin)
+ return MachineCodeEmitter::allocateSpace(Size, Alignment);
+
+ // create a new memory block if there is no active one.
+ // care must be taken so that BufferBegin is invalidated when a
+ // block is trimmed
+ BufferBegin = CurBufferPtr = MemMgr->allocateSpace(Size, Alignment);
+ BufferEnd = BufferBegin+Size;
+ return CurBufferPtr;
+}
+
void JITEmitter::emitConstantPool(MachineConstantPool *MCP) {
const std::vector<MachineConstantPoolEntry> &Constants = MCP->getConstants();
if (Constants.empty()) return;
diff --git a/lib/ExecutionEngine/JIT/JITMemoryManager.cpp b/lib/ExecutionEngine/JIT/JITMemoryManager.cpp
index 618f144..cc072a8 100644
--- a/lib/ExecutionEngine/JIT/JITMemoryManager.cpp
+++ b/lib/ExecutionEngine/JIT/JITMemoryManager.cpp
@@ -298,7 +298,24 @@ namespace {
// Release the memory at the end of this block that isn't needed.
FreeMemoryList =CurBlock->TrimAllocationToSize(FreeMemoryList, BlockSize);
}
-
+
+ /// allocateSpace - Allocate a memory block of the given size.
+ unsigned char *allocateSpace(intptr_t Size, unsigned Alignment) {
+ CurBlock = FreeMemoryList;
+ FreeMemoryList = FreeMemoryList->AllocateBlock();
+
+ unsigned char *result = (unsigned char *)CurBlock+1;
+
+ if (Alignment == 0) Alignment = 1;
+ result = (unsigned char*)(((intptr_t)result+Alignment-1) &
+ ~(intptr_t)(Alignment-1));
+
+ uintptr_t BlockSize = result + Size - (unsigned char *)CurBlock;
+ FreeMemoryList =CurBlock->TrimAllocationToSize(FreeMemoryList, BlockSize);
+
+ return result;
+ }
+
/// startExceptionTable - Use startFunctionBody to allocate memory for the
/// function's exception table.
unsigned char* startExceptionTable(const Function* F,