perf/signal: rewrite code in assembly to avoid compiler optimizations

Without this change, the assembly code of this test compiled without
optimizations:

mov    -0x150(%rbp),%rax
movl   $0x77777777,(%rax)
lea    -0x128(%rbp),%rax

with optimizations:

movl   $0x77777777,0x0

This code doesn't work properly, because the test changes rax in the segv
handler.

PiperOrigin-RevId: 299896117
This commit is contained in:
Andrei Vagin
2020-03-09 11:53:28 -07:00
committed by gVisor bot
parent ddfc7239be
commit 2446161b3f
+6 -4
View File
@@ -43,11 +43,13 @@ void BM_FaultSignalFixup(benchmark::State& state) {
// Fault, fault, fault.
for (auto _ : state) {
register volatile unsigned int* ptr asm("rax");
// Trigger the segfault.
ptr = nullptr;
*ptr = 0;
asm volatile(
"movq $0, %%rax\n"
"movq $0x77777777, (%%rax)\n"
:
:
: "rax");
}
}