diff options
author | Jim Grosbach <grosbach@apple.com> | 2008-10-03 16:17:20 +0000 |
---|---|---|
committer | Jim Grosbach <grosbach@apple.com> | 2008-10-03 16:17:20 +0000 |
commit | cce6c297c54b4c9c8615c77e97cd64e70812ea60 (patch) | |
tree | 2a65c3ce20bd2065ace4af4a03507d11dcbc03a0 /lib/ExecutionEngine | |
parent | 48b828fdb467655fa630fed41e49e2a481fb6dab (diff) | |
download | external_llvm-cce6c297c54b4c9c8615c77e97cd64e70812ea60.zip external_llvm-cce6c297c54b4c9c8615c77e97cd64e70812ea60.tar.gz external_llvm-cce6c297c54b4c9c8615c77e97cd64e70812ea60.tar.bz2 |
On Darwin ARM, memory needs special handling to do JIT. This patch expands
this handling to work properly for modifying stub functions, relocations
back to entry points after JIT compilation, etc..
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@57013 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/ExecutionEngine')
-rw-r--r-- | lib/ExecutionEngine/JIT/JITEmitter.cpp | 12 | ||||
-rw-r--r-- | lib/ExecutionEngine/JIT/JITMemoryManager.cpp | 15 |
2 files changed, 26 insertions, 1 deletions
diff --git a/lib/ExecutionEngine/JIT/JITEmitter.cpp b/lib/ExecutionEngine/JIT/JITEmitter.cpp index ffaeb1c..a90a6a5 100644 --- a/lib/ExecutionEngine/JIT/JITEmitter.cpp +++ b/lib/ExecutionEngine/JIT/JITEmitter.cpp @@ -560,6 +560,10 @@ namespace { if (ExceptionHandling) DE->setModuleInfo(Info); } + void setMemoryExecutable(void) { + MemMgr->setMemoryExecutable(); + } + private: void *getPointerToGlobal(GlobalValue *GV, void *Reference, bool NoNeedStub); void *getPointerToGVLazyPtr(GlobalValue *V, void *Reference, @@ -791,6 +795,8 @@ unsigned JITEmitter::GetSizeOfGlobalsInBytes(MachineFunction &MF) { void JITEmitter::startFunction(MachineFunction &F) { uintptr_t ActualSize = 0; + // Set the memory writable, if it's not already + MemMgr->setMemoryWritable(); if (MemMgr->NeedsExactSize()) { DOUT << "ExactSize\n"; const TargetInstrInfo* TII = F.getTarget().getInstrInfo(); @@ -938,7 +944,7 @@ bool JITEmitter::finishFunction(MachineFunction &F) { Relocations.clear(); // Mark code region readable and executable if it's not so already. - sys::Memory::SetRXPrivilege(FnStart, FnEnd-FnStart); + MemMgr->setMemoryExecutable(); #ifndef NDEBUG { @@ -1086,6 +1092,10 @@ void JITEmitter::startFunctionStub(const GlobalValue* F, unsigned StubSize, void *JITEmitter::finishFunctionStub(const GlobalValue* F) { NumBytes += getCurrentPCOffset(); + + // Invalidate the icache if necessary. + sys::Memory::InvalidateInstructionCache(BufferBegin, NumBytes); + std::swap(SavedBufferBegin, BufferBegin); BufferEnd = SavedBufferEnd; CurBufferPtr = SavedCurBufferPtr; diff --git a/lib/ExecutionEngine/JIT/JITMemoryManager.cpp b/lib/ExecutionEngine/JIT/JITMemoryManager.cpp index 804e88d..0ffc779 100644 --- a/lib/ExecutionEngine/JIT/JITMemoryManager.cpp +++ b/lib/ExecutionEngine/JIT/JITMemoryManager.cpp @@ -365,6 +365,21 @@ namespace { // Finally, remove this entry from TableBlocks. TableBlocks.erase(I); } + + /// setMemoryWritable - When code generation is in progress, + /// the code pages may need permissions changed. + void setMemoryWritable(void) + { + for (unsigned i = 0, e = Blocks.size(); i != e; ++i) + sys::Memory::setWritable(Blocks[i]); + } + /// setMemoryExecutable - When code generation is done and we're ready to + /// start execution, the code pages may need permissions changed. + void setMemoryExecutable(void) + { + for (unsigned i = 0, e = Blocks.size(); i != e; ++i) + sys::Memory::setExecutable(Blocks[i]); + } }; } |