Skip to content

Commit

Permalink
Merge 81311 from mainline.
Browse files Browse the repository at this point in the history
Make sure to make stub region writable before emission, executable after emission.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_26@81640 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
tlattner committed Sep 12, 2009
1 parent b38a312 commit 8a57704
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/Target/ARM/ARMJITInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ ARMJITInfo::getLazyResolverFunction(JITCompilerFn F) {
void *ARMJITInfo::emitGlobalValueIndirectSym(const GlobalValue *GV, void *Ptr,
JITCodeEmitter &JCE) {
JCE.startGVStub(GV, 4, 4);
intptr_t Addr = (intptr_t)JCE.getCurrentPCValue();
if (!sys::Memory::setRangeWritable((void*)Addr, 4)) {
llvm_unreachable("ERROR: Unable to mark indirect symbol writable");
}
JCE.emitWordLE((intptr_t)Ptr);
void *PtrAddr = JCE.finishGVStub(GV);
addIndirectSymAddr(Ptr, (intptr_t)PtrAddr);
Expand Down Expand Up @@ -169,18 +173,30 @@ void *ARMJITInfo::emitFunctionStub(const Function* F, void *Fn,
}
JCE.startGVStub(F, 16, 4);
intptr_t Addr = (intptr_t)JCE.getCurrentPCValue();
if (!sys::Memory::setRangeWritable((void*)Addr, 16)) {
llvm_unreachable("ERROR: Unable to mark stub writable");
}
JCE.emitWordLE(0xe59fc004); // ldr pc, [pc, #+4]
JCE.emitWordLE(0xe08fc00c); // L_func$scv: add ip, pc, ip
JCE.emitWordLE(0xe59cf000); // ldr pc, [ip]
JCE.emitWordLE(LazyPtr - (Addr+4+8)); // func - (L_func$scv+8)
sys::Memory::InvalidateInstructionCache((void*)Addr, 16);
if (!sys::Memory::setRangeExecutable((void*)Addr, 16)) {
llvm_unreachable("ERROR: Unable to mark stub executable");
}
} else {
// The stub is 8-byte size and 4-aligned.
JCE.startGVStub(F, 8, 4);
intptr_t Addr = (intptr_t)JCE.getCurrentPCValue();
if (!sys::Memory::setRangeWritable((void*)Addr, 8)) {
llvm_unreachable("ERROR: Unable to mark stub writable");
}
JCE.emitWordLE(0xe51ff004); // ldr pc, [pc, #-4]
JCE.emitWordLE((intptr_t)Fn); // addr of function
sys::Memory::InvalidateInstructionCache((void*)Addr, 8);
if (!sys::Memory::setRangeExecutable((void*)Addr, 8)) {
llvm_unreachable("ERROR: Unable to mark stub executable");
}
}
} else {
// The compilation callback will overwrite the first two words of this
Expand All @@ -192,6 +208,9 @@ void *ARMJITInfo::emitFunctionStub(const Function* F, void *Fn,
// The stub is 16-byte size and 4-byte aligned.
JCE.startGVStub(F, 16, 4);
intptr_t Addr = (intptr_t)JCE.getCurrentPCValue();
if (!sys::Memory::setRangeWritable((void*)Addr, 16)) {
llvm_unreachable("ERROR: Unable to mark stub writable");
}
// Save LR so the callback can determine which stub called it.
// The compilation callback is responsible for popping this prior
// to returning.
Expand All @@ -203,6 +222,9 @@ void *ARMJITInfo::emitFunctionStub(const Function* F, void *Fn,
// The address of the compilation callback.
JCE.emitWordLE((intptr_t)ARMCompilationCallback);
sys::Memory::InvalidateInstructionCache((void*)Addr, 16);
if (!sys::Memory::setRangeExecutable((void*)Addr, 16)) {
llvm_unreachable("ERROR: Unable to mark stub executable");
}
}

return JCE.finishGVStub(F);
Expand Down

0 comments on commit 8a57704

Please sign in to comment.