Based on glibc 2.33 -> 2.34, there is one new feature:
NEWS for version 2.34
=====================
Major new features:
* Add _SC_MINSIGSTKSZ and _SC_SIGSTKSZ. When _DYNAMIC_STACK_SIZE_SOURCE
or _GNU_SOURCE are defined, MINSIGSTKSZ and SIGSTKSZ are no longer
constant on Linux. MINSIGSTKSZ is redefined to sysconf(_SC_MINSIGSTKSZ)
and SIGSTKSZ is redefined to sysconf (_SC_SIGSTKSZ). This supports
dynamic sized register sets for modern architectural features like
Arm SVE.
Build error with the GNU C Library 2.34:
DEBUG: | sigreturn.c:150:13: error: variably modified 'altstack_data' at file scope
| sigreturn.c:150:13: error: variably modified 'altstack_data' at file scope
DEBUG: | 150 | static char altstack_data[SIGSTKSZ];
| 150 | static char altstack_data[SIGSTKSZ];
DEBUG: | | ^~~~~~~~~~~~~
Signed-off-by: Jun Miao <[email protected]>
---
tools/testing/selftests/x86/mov_ss_trap.c | 4 ++--
tools/testing/selftests/x86/sigreturn.c | 7 +++----
tools/testing/selftests/x86/single_step_syscall.c | 4 ++--
tools/testing/selftests/x86/syscall_arg_fault.c | 7 +++----
4 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/tools/testing/selftests/x86/mov_ss_trap.c b/tools/testing/selftests/x86/mov_ss_trap.c
index 6da0ac3f0135..1ebf5f3f0fcf 100644
--- a/tools/testing/selftests/x86/mov_ss_trap.c
+++ b/tools/testing/selftests/x86/mov_ss_trap.c
@@ -47,7 +47,6 @@
unsigned short ss;
extern unsigned char breakpoint_insn[];
sigjmp_buf jmpbuf;
-static unsigned char altstack_data[SIGSTKSZ];
static void enable_watchpoint(void)
{
@@ -250,7 +249,7 @@ int main()
if (sigsetjmp(jmpbuf, 1) == 0) {
printf("[RUN]\tMOV SS; SYSENTER\n");
stack_t stack = {
- .ss_sp = altstack_data,
+ .ss_sp = malloc(sizeof(char) * SIGSTKSZ),
.ss_size = SIGSTKSZ,
};
if (sigaltstack(&stack, NULL) != 0)
@@ -282,5 +281,6 @@ int main()
}
printf("[OK]\tI aten't dead\n");
+ free(stack.ss_sp);
return 0;
}
diff --git a/tools/testing/selftests/x86/sigreturn.c b/tools/testing/selftests/x86/sigreturn.c
index 57c4f67f16ef..5d7961a5f7f6 100644
--- a/tools/testing/selftests/x86/sigreturn.c
+++ b/tools/testing/selftests/x86/sigreturn.c
@@ -138,9 +138,6 @@ static unsigned short LDT3(int idx)
return (idx << 3) | 7;
}
-/* Our sigaltstack scratch space. */
-static char altstack_data[SIGSTKSZ];
-
static void sethandler(int sig, void (*handler)(int, siginfo_t *, void *),
int flags)
{
@@ -771,7 +768,8 @@ int main()
setup_ldt();
stack_t stack = {
- .ss_sp = altstack_data,
+ /* Our sigaltstack scratch space. */
+ .ss_sp = malloc(sizeof(char) * SIGSTKSZ),
.ss_size = SIGSTKSZ,
};
if (sigaltstack(&stack, NULL) != 0)
@@ -872,5 +870,6 @@ int main()
total_nerrs += test_nonstrict_ss();
#endif
+ free(stack.ss_sp);
return total_nerrs ? 1 : 0;
}
diff --git a/tools/testing/selftests/x86/single_step_syscall.c b/tools/testing/selftests/x86/single_step_syscall.c
index 120ac741fe44..158b2bb1474c 100644
--- a/tools/testing/selftests/x86/single_step_syscall.c
+++ b/tools/testing/selftests/x86/single_step_syscall.c
@@ -57,7 +57,6 @@ static void clearhandler(int sig)
static volatile sig_atomic_t sig_traps, sig_eflags;
sigjmp_buf jmpbuf;
-static unsigned char altstack_data[SIGSTKSZ];
#ifdef __x86_64__
# define REG_IP REG_RIP
@@ -210,7 +209,7 @@ int main()
unsigned long nr = SYS_getpid;
printf("[RUN]\tSet TF and check SYSENTER\n");
stack_t stack = {
- .ss_sp = altstack_data,
+ .ss_sp = malloc(sizeof(char) * SIGSTKSZ),
.ss_size = SIGSTKSZ,
};
if (sigaltstack(&stack, NULL) != 0)
@@ -228,6 +227,7 @@ int main()
/* We're unreachable here. SYSENTER forgets RIP. */
}
+ free(stack.ss_sp);
clearhandler(SIGSEGV);
clearhandler(SIGILL);
if (!(sig_eflags & X86_EFLAGS_TF)) {
diff --git a/tools/testing/selftests/x86/syscall_arg_fault.c b/tools/testing/selftests/x86/syscall_arg_fault.c
index bff474b5efc6..461fa41a4d02 100644
--- a/tools/testing/selftests/x86/syscall_arg_fault.c
+++ b/tools/testing/selftests/x86/syscall_arg_fault.c
@@ -17,9 +17,6 @@
#include "helpers.h"
-/* Our sigaltstack scratch space. */
-static unsigned char altstack_data[SIGSTKSZ];
-
static void sethandler(int sig, void (*handler)(int, siginfo_t *, void *),
int flags)
{
@@ -104,7 +101,8 @@ static void sigill(int sig, siginfo_t *info, void *ctx_void)
int main()
{
stack_t stack = {
- .ss_sp = altstack_data,
+ /* Our sigaltstack scratch space. */
+ .ss_sp = malloc(sizeof(char) * SIGSTKSZ),
.ss_size = SIGSTKSZ,
};
if (sigaltstack(&stack, NULL) != 0)
@@ -233,5 +231,6 @@ int main()
set_eflags(get_eflags() & ~X86_EFLAGS_TF);
#endif
+ free(stack.ss_sp);
return 0;
}
--
2.32.0
On 8/23/21 7:56 AM, Jun Miao wrote:
> Based on glibc 2.33 -> 2.34, there is one new feature:
>
> NEWS for version 2.34
> =====================
> Major new features:
> * Add _SC_MINSIGSTKSZ and _SC_SIGSTKSZ. When _DYNAMIC_STACK_SIZE_SOURCE
> or _GNU_SOURCE are defined, MINSIGSTKSZ and SIGSTKSZ are no longer
> constant on Linux. MINSIGSTKSZ is redefined to sysconf(_SC_MINSIGSTKSZ)
> and SIGSTKSZ is redefined to sysconf (_SC_SIGSTKSZ). This supports
> dynamic sized register sets for modern architectural features like
> Arm SVE.
>
> Build error with the GNU C Library 2.34:
> DEBUG: | sigreturn.c:150:13: error: variably modified 'altstack_data' at file scope
> | sigreturn.c:150:13: error: variably modified 'altstack_data' at file scope
> DEBUG: | 150 | static char altstack_data[SIGSTKSZ];
> | 150 | static char altstack_data[SIGSTKSZ];
> DEBUG: | | ^~~~~~~~~~~~~
>
Please give more context on why this change is needed?
Doesn't look like you tried to compile this patch before
sending this to me.
> Signed-off-by: Jun Miao <[email protected]>
thanks,
-- Shuah
Hi Jun,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on kselftest/next]
[also build test ERROR on v5.14-rc7 next-20210823]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Jun-Miao/selftests-x86-Fix-error-variably-modified-altstack_data-at-file-scope/20210823-215819
base: https://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest.git next
config: x86_64-rhel-8.3-kselftests (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
# https://github.com/0day-ci/linux/commit/3752736483bd2f09d350c5d3a42460d74ea9c53a
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Jun-Miao/selftests-x86-Fix-error-variably-modified-altstack_data-at-file-scope/20210823-215819
git checkout 3752736483bd2f09d350c5d3a42460d74ea9c53a
# save the attached .config to linux build tree
mkdir build_dir
make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash -C tools/testing/selftests install
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>
All errors (new ones prefixed by >>):
single_step_syscall.c: In function 'main':
>> single_step_syscall.c:230:7: error: 'stack' undeclared (first use in this function); did you mean 'stack_t'?
230 | free(stack.ss_sp);
| ^~~~~
| stack_t
single_step_syscall.c:230:7: note: each undeclared identifier is reported only once for each function it appears in
--
mov_ss_trap.c: In function 'main':
>> mov_ss_trap.c:284:7: error: 'stack' undeclared (first use in this function); did you mean 'obstack'?
284 | free(stack.ss_sp);
| ^~~~~
| obstack
mov_ss_trap.c:284:7: note: each undeclared identifier is reported only once for each function it appears in
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]