Skip to content

Commit 05107ed

Browse files
nickdesaulniersshuahkh
authored andcommitted
selftests: sigaltstack: fix -Wuninitialized
Building sigaltstack with clang via: $ ARCH=x86 make LLVM=1 -C tools/testing/selftests/sigaltstack/ produces the following warning: warning: variable 'sp' is uninitialized when used here [-Wuninitialized] if (sp < (unsigned long)sstack || ^~ Clang expects these to be declared at global scope; we've fixed this in the kernel proper by using the macro `current_stack_pointer`. This is defined in different headers for different target architectures, so just create a new header that defines the arch-specific register names for the stack pointer register, and define it for more targets (at least the ones that support current_stack_pointer/ARCH_HAS_CURRENT_STACK_POINTER). Reported-by: Linux Kernel Functional Testing <[email protected]> Link: https://lore.kernel.org/lkml/CA+G9fYsi3OOu7yCsMutpzKDnBMAzJBCPimBp86LhGBa0eCnEpA@mail.gmail.com/ Signed-off-by: Nick Desaulniers <[email protected]> Reviewed-by: Kees Cook <[email protected]> Tested-by: Linux Kernel Functional Testing <[email protected]> Tested-by: Anders Roxell <[email protected]> Signed-off-by: Shuah Khan <[email protected]>
1 parent 624c60f commit 05107ed

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
3+
#if __alpha__
4+
register unsigned long sp asm("$30");
5+
#elif __arm__ || __aarch64__ || __csky__ || __m68k__ || __mips__ || __riscv
6+
register unsigned long sp asm("sp");
7+
#elif __i386__
8+
register unsigned long sp asm("esp");
9+
#elif __loongarch64
10+
register unsigned long sp asm("$sp");
11+
#elif __ppc__
12+
register unsigned long sp asm("r1");
13+
#elif __s390x__
14+
register unsigned long sp asm("%15");
15+
#elif __sh__
16+
register unsigned long sp asm("r15");
17+
#elif __x86_64__
18+
register unsigned long sp asm("rsp");
19+
#elif __XTENSA__
20+
register unsigned long sp asm("a1");
21+
#else
22+
#error "implement current_stack_pointer equivalent"
23+
#endif

tools/testing/selftests/sigaltstack/sas.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <sys/auxv.h>
2121

2222
#include "../kselftest.h"
23+
#include "current_stack_pointer.h"
2324

2425
#ifndef SS_AUTODISARM
2526
#define SS_AUTODISARM (1U << 31)
@@ -46,12 +47,6 @@ void my_usr1(int sig, siginfo_t *si, void *u)
4647
stack_t stk;
4748
struct stk_data *p;
4849

49-
#if __s390x__
50-
register unsigned long sp asm("%15");
51-
#else
52-
register unsigned long sp asm("sp");
53-
#endif
54-
5550
if (sp < (unsigned long)sstack ||
5651
sp >= (unsigned long)sstack + stack_size) {
5752
ksft_exit_fail_msg("SP is not on sigaltstack\n");

0 commit comments

Comments
 (0)