summaryrefslogtreecommitdiffstats
path: root/llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp
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
commit94844e2054e2e1aac911292cf041525f77725484 (patch)
treed7d0e33416349f17a1633596d0b1efe2e5784217 /llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp
parent9ebc050ca7b2af404d3e46f48e527c930ee7281f (diff)
downloadbcm5719-llvm-94844e2054e2e1aac911292cf041525f77725484.tar.gz
bcm5719-llvm-94844e2054e2e1aac911292cf041525f77725484.zip
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.
llvm-svn: 57900
Diffstat (limited to 'llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp')
-rw-r--r--llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp27
1 files changed, 22 insertions, 5 deletions
diff --git a/llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp b/llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp
index a90a6a52fa9..688d4984c20 100644
--- a/llvm/lib/ExecutionEngine/JIT/JITEmitter.cpp
+++ b/llvm/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;
OpenPOWER on IntegriCloud