llvm.org GIT mirror llvm / cef7527
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 Nuno Lopes 11 years ago
4 changed file(s) with 44 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
206206 /// allocateSpace - Allocate a block of space in the current output buffer,
207207 /// returning null (and setting conditions to indicate buffer overflow) on
208208 /// failure. Alignment is the alignment in bytes of the buffer desired.
209 void *allocateSpace(intptr_t Size, unsigned Alignment) {
209 virtual void *allocateSpace(intptr_t Size, unsigned Alignment) {
210210 emitAlignment(Alignment);
211211 void *Result = CurBufferPtr;
212212
100100 /// and remember where it is in case the client wants to deallocate it.
101101 virtual void endFunctionBody(const Function *F, unsigned char *FunctionStart,
102102 unsigned char *FunctionEnd) = 0;
103
104 /// allocateSpace - Allocate a memory block of the given size.
105 virtual unsigned char *allocateSpace(intptr_t Size, unsigned Alignment) = 0;
103106
104107 /// deallocateMemForFunction - Free JIT memory for the specified function.
105108 /// This is never called when the JIT is currently emitting a function.
517517 unsigned Alignment = 1);
518518 virtual void* finishFunctionStub(const GlobalValue *F);
519519
520 /// allocateSpace - Reserves space in the current block if any, or
521 /// allocate a new one of the given size.
522 virtual void *allocateSpace(intptr_t Size, unsigned Alignment);
523
520524 virtual void addRelocation(const MachineRelocation &MR) {
521525 Relocations.push_back(MR);
522526 }
914918 Relocations.size(), MemMgr->getGOTBase());
915919 }
916920
917 unsigned char *FnEnd = CurBufferPtr;
918
919 MemMgr->endFunctionBody(F.getFunction(), BufferBegin, FnEnd);
920 NumBytes += FnEnd-FnStart;
921
922921 // Update the GOT entry for F to point to the new code.
923922 if (MemMgr->isManagingGOT()) {
924923 unsigned idx = Resolver.getGOTIndexForAddr((void*)BufferBegin);
928927 ((void**)MemMgr->getGOTBase())[idx] = (void*)BufferBegin;
929928 }
930929 }
930
931 unsigned char *FnEnd = CurBufferPtr;
932
933 MemMgr->endFunctionBody(F.getFunction(), BufferBegin, FnEnd);
934 BufferBegin = CurBufferPtr = 0;
935 NumBytes += FnEnd-FnStart;
931936
932937 // Invalidate the icache if necessary.
933938 sys::Memory::InvalidateInstructionCache(FnStart, FnEnd-FnStart);
992997 return false;
993998 }
994999
1000 void* JITEmitter::allocateSpace(intptr_t Size, unsigned Alignment) {
1001 if (BufferBegin)
1002 return MachineCodeEmitter::allocateSpace(Size, Alignment);
1003
1004 // create a new memory block if there is no active one.
1005 // care must be taken so that BufferBegin is invalidated when a
1006 // block is trimmed
1007 BufferBegin = CurBufferPtr = MemMgr->allocateSpace(Size, Alignment);
1008 BufferEnd = BufferBegin+Size;
1009 return CurBufferPtr;
1010 }
1011
9951012 void JITEmitter::emitConstantPool(MachineConstantPool *MCP) {
9961013 const std::vector &Constants = MCP->getConstants();
9971014 if (Constants.empty()) return;
297297 // Release the memory at the end of this block that isn't needed.
298298 FreeMemoryList =CurBlock->TrimAllocationToSize(FreeMemoryList, BlockSize);
299299 }
300
300
301 /// allocateSpace - Allocate a memory block of the given size.
302 unsigned char *allocateSpace(intptr_t Size, unsigned Alignment) {
303 CurBlock = FreeMemoryList;
304 FreeMemoryList = FreeMemoryList->AllocateBlock();
305
306 unsigned char *result = (unsigned char *)CurBlock+1;
307
308 if (Alignment == 0) Alignment = 1;
309 result = (unsigned char*)(((intptr_t)result+Alignment-1) &
310 ~(intptr_t)(Alignment-1));
311
312 uintptr_t BlockSize = result + Size - (unsigned char *)CurBlock;
313 FreeMemoryList =CurBlock->TrimAllocationToSize(FreeMemoryList, BlockSize);
314
315 return result;
316 }
317
301318 /// startExceptionTable - Use startFunctionBody to allocate memory for the
302319 /// function's exception table.
303320 unsigned char* startExceptionTable(const Function* F,