@@ -142,6 +142,10 @@ ARMJITInfo::getLazyResolverFunction(JITCompilerFn F) {
142
142
void *ARMJITInfo::emitGlobalValueIndirectSym (const GlobalValue *GV, void *Ptr,
143
143
JITCodeEmitter &JCE) {
144
144
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
+ }
145
149
JCE.emitWordLE ((intptr_t )Ptr);
146
150
void *PtrAddr = JCE.finishGVStub (GV);
147
151
addIndirectSymAddr (Ptr, (intptr_t )PtrAddr);
@@ -169,18 +173,30 @@ void *ARMJITInfo::emitFunctionStub(const Function* F, void *Fn,
169
173
}
170
174
JCE.startGVStub (F, 16 , 4 );
171
175
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
+ }
172
179
JCE.emitWordLE (0xe59fc004 ); // ldr pc, [pc, #+4]
173
180
JCE.emitWordLE (0xe08fc00c ); // L_func$scv: add ip, pc, ip
174
181
JCE.emitWordLE (0xe59cf000 ); // ldr pc, [ip]
175
182
JCE.emitWordLE (LazyPtr - (Addr+4 +8 )); // func - (L_func$scv+8)
176
183
sys::Memory::InvalidateInstructionCache ((void *)Addr, 16 );
184
+ if (!sys::Memory::setRangeExecutable ((void *)Addr, 16 )) {
185
+ llvm_unreachable (" ERROR: Unable to mark stub executable" );
186
+ }
177
187
} else {
178
188
// The stub is 8-byte size and 4-aligned.
179
189
JCE.startGVStub (F, 8 , 4 );
180
190
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
+ }
181
194
JCE.emitWordLE (0xe51ff004 ); // ldr pc, [pc, #-4]
182
195
JCE.emitWordLE ((intptr_t )Fn); // addr of function
183
196
sys::Memory::InvalidateInstructionCache ((void *)Addr, 8 );
197
+ if (!sys::Memory::setRangeExecutable ((void *)Addr, 8 )) {
198
+ llvm_unreachable (" ERROR: Unable to mark stub executable" );
199
+ }
184
200
}
185
201
} else {
186
202
// The compilation callback will overwrite the first two words of this
@@ -192,6 +208,9 @@ void *ARMJITInfo::emitFunctionStub(const Function* F, void *Fn,
192
208
// The stub is 16-byte size and 4-byte aligned.
193
209
JCE.startGVStub (F, 16 , 4 );
194
210
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
+ }
195
214
// Save LR so the callback can determine which stub called it.
196
215
// The compilation callback is responsible for popping this prior
197
216
// to returning.
@@ -203,6 +222,9 @@ void *ARMJITInfo::emitFunctionStub(const Function* F, void *Fn,
203
222
// The address of the compilation callback.
204
223
JCE.emitWordLE ((intptr_t )ARMCompilationCallback);
205
224
sys::Memory::InvalidateInstructionCache ((void *)Addr, 16 );
225
+ if (!sys::Memory::setRangeExecutable ((void *)Addr, 16 )) {
226
+ llvm_unreachable (" ERROR: Unable to mark stub executable" );
227
+ }
206
228
}
207
229
208
230
return JCE.finishGVStub (F);
0 commit comments