Skip to content

Commit aea2a46

Browse files
committed
Merge 81311 from mainline.
Make sure to make stub region writable before emission, executable after emission. llvm-svn: 81640
1 parent 2bf6141 commit aea2a46

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

llvm/lib/Target/ARM/ARMJITInfo.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ ARMJITInfo::getLazyResolverFunction(JITCompilerFn F) {
142142
void *ARMJITInfo::emitGlobalValueIndirectSym(const GlobalValue *GV, void *Ptr,
143143
JITCodeEmitter &JCE) {
144144
JCE.startGVStub(GV, 4, 4);
145+
intptr_t Addr = (intptr_t)JCE.getCurrentPCValue();
146+
if (!sys::Memory::setRangeWritable((void*)Addr, 4)) {
147+
llvm_unreachable("ERROR: Unable to mark indirect symbol writable");
148+
}
145149
JCE.emitWordLE((intptr_t)Ptr);
146150
void *PtrAddr = JCE.finishGVStub(GV);
147151
addIndirectSymAddr(Ptr, (intptr_t)PtrAddr);
@@ -169,18 +173,30 @@ void *ARMJITInfo::emitFunctionStub(const Function* F, void *Fn,
169173
}
170174
JCE.startGVStub(F, 16, 4);
171175
intptr_t Addr = (intptr_t)JCE.getCurrentPCValue();
176+
if (!sys::Memory::setRangeWritable((void*)Addr, 16)) {
177+
llvm_unreachable("ERROR: Unable to mark stub writable");
178+
}
172179
JCE.emitWordLE(0xe59fc004); // ldr pc, [pc, #+4]
173180
JCE.emitWordLE(0xe08fc00c); // L_func$scv: add ip, pc, ip
174181
JCE.emitWordLE(0xe59cf000); // ldr pc, [ip]
175182
JCE.emitWordLE(LazyPtr - (Addr+4+8)); // func - (L_func$scv+8)
176183
sys::Memory::InvalidateInstructionCache((void*)Addr, 16);
184+
if (!sys::Memory::setRangeExecutable((void*)Addr, 16)) {
185+
llvm_unreachable("ERROR: Unable to mark stub executable");
186+
}
177187
} else {
178188
// The stub is 8-byte size and 4-aligned.
179189
JCE.startGVStub(F, 8, 4);
180190
intptr_t Addr = (intptr_t)JCE.getCurrentPCValue();
191+
if (!sys::Memory::setRangeWritable((void*)Addr, 8)) {
192+
llvm_unreachable("ERROR: Unable to mark stub writable");
193+
}
181194
JCE.emitWordLE(0xe51ff004); // ldr pc, [pc, #-4]
182195
JCE.emitWordLE((intptr_t)Fn); // addr of function
183196
sys::Memory::InvalidateInstructionCache((void*)Addr, 8);
197+
if (!sys::Memory::setRangeExecutable((void*)Addr, 8)) {
198+
llvm_unreachable("ERROR: Unable to mark stub executable");
199+
}
184200
}
185201
} else {
186202
// The compilation callback will overwrite the first two words of this
@@ -192,6 +208,9 @@ void *ARMJITInfo::emitFunctionStub(const Function* F, void *Fn,
192208
// The stub is 16-byte size and 4-byte aligned.
193209
JCE.startGVStub(F, 16, 4);
194210
intptr_t Addr = (intptr_t)JCE.getCurrentPCValue();
211+
if (!sys::Memory::setRangeWritable((void*)Addr, 16)) {
212+
llvm_unreachable("ERROR: Unable to mark stub writable");
213+
}
195214
// Save LR so the callback can determine which stub called it.
196215
// The compilation callback is responsible for popping this prior
197216
// to returning.
@@ -203,6 +222,9 @@ void *ARMJITInfo::emitFunctionStub(const Function* F, void *Fn,
203222
// The address of the compilation callback.
204223
JCE.emitWordLE((intptr_t)ARMCompilationCallback);
205224
sys::Memory::InvalidateInstructionCache((void*)Addr, 16);
225+
if (!sys::Memory::setRangeExecutable((void*)Addr, 16)) {
226+
llvm_unreachable("ERROR: Unable to mark stub executable");
227+
}
206228
}
207229

208230
return JCE.finishGVStub(F);

0 commit comments

Comments
 (0)