diff options
author | Nuno Lopes <nunoplopes@sapo.pt> | 2008-10-21 11:42:16 +0000 |
---|---|---|
committer | Nuno Lopes <nunoplopes@sapo.pt> | 2008-10-21 11:42:16 +0000 |
commit | cef7527a85d026aeb17a4dacca73c70c0ab5da40 (patch) | |
tree | 0a85fcdb02a052b1f08c226af631021cab95fc2c /lib/ExecutionEngine/JIT/JITMemoryManager.cpp | |
parent | e06e91122fefcadd252ddd2f2591e181683fc2f1 (diff) |
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/JIT/JITMemoryManager.cpp')
-rw-r--r-- | lib/ExecutionEngine/JIT/JITMemoryManager.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/ExecutionEngine/JIT/JITMemoryManager.cpp b/lib/ExecutionEngine/JIT/JITMemoryManager.cpp index 618f1442e5..cc072a896c 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, |