From 48b436da9ed8214b70cf259ef2afa66904a567c9 Mon Sep 17 00:00:00 2001 From: Derek Bruening Date: Fri, 30 Aug 2024 14:41:19 -0400 Subject: [PATCH] i#6953: Fix sigcontext test AVX error (#6954) Replaces a kill() with an inlined system call in the linux.sigcontext test to avoid failure when compiled for AVX only, as the compiler inserts VZEROUPPER there (VZEROUPPER is recommended by Intel to avoid a performance penalty when switching between upper-zeroing VEX-encoded XMM operations and legacy upper-preserving SSE* operations: so doing it at transitions to code you don't control makes sense). Tested on a toolchain targeting AVX. Fixes #6953 --- suite/tests/linux/sigcontext.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/suite/tests/linux/sigcontext.c b/suite/tests/linux/sigcontext.c index 8df3685ae5d..c165d3203fa 100644 --- a/suite/tests/linux/sigcontext.c +++ b/suite/tests/linux/sigcontext.c @@ -35,6 +35,7 @@ #include "tools.h" /* we want the latest defs so we can get at ymm state */ #include "../../../core/unix/include/sigcontext.h" +#include "../../../core/unix/include/syscall.h" #include #include #include @@ -183,6 +184,7 @@ main(int argc, char *argv[]) int buf[INTS_PER_XMM * NUM_SIMD_SSE_AVX_REGS]; char *ptr = (char *)buf; int i, j; + pid_t pid = getpid(); /* do this first to avoid messing w/ xmm state */ intercept_signal(SIGUSR1, signal_handler, false); @@ -323,8 +325,21 @@ main(int argc, char *argv[]) MOVE_TO_YMM(buf, 15) # endif # endif - /* now make sure they show up in signal context */ - kill(getpid(), SIGUSR2); + /* Now make sure they show up in the signal context. + * But, it's not safe to make a regular call, as the compiler will + * insert VZEROUPPER for some configurations. + */ +# ifdef X64 + __asm__ __volatile__("mov %0, %%rdi; mov %1, %%rsi; mov %2, %%rax; syscall" + : + : "m"(pid), "i"(SIGUSR2), "i"(SYS_kill) + : "rdi", "rsi", "rax"); +# else + __asm__ __volatile__("mov %0, %%ebx; mov %1, %%ecx; mov %2, %%eax; int $0x80" + : + : "m"(pid), "i"(SIGUSR2), "i"(SYS_kill) + : "ebx", "ecx", "eax"); +# endif /* Ensure they are preserved across the sigreturn (xref i#3812). */ # ifdef __AVX512F__