diff mbox series

selftests/x86/sigreturn: Fix error: variably modified 'altstack_data' at file scope

Message ID 20210823093026.3839645-1-jun.miao@windriver.com
State New
Headers show
Series selftests/x86/sigreturn: Fix error: variably modified 'altstack_data' at file scope | expand

Commit Message

Jun Miao Aug. 23, 2021, 9:30 a.m. UTC
Based on glibc 2.33 -> 2.34, there is one new feature:

NEWS for version 2.34

Comments

Shuah Khan Aug. 23, 2021, 10:19 p.m. UTC | #1
On 8/23/21 3:30 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:	|       |             ^~~~~~~~~~~~~
> 
> Signed-off-by: Jun Miao <jun.miao@windriver.com>
> ---
>   tools/testing/selftests/x86/sigreturn.c | 7 +++----
>   1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/tools/testing/selftests/x86/sigreturn.c b/tools/testing/selftests/x86/sigreturn.c
> index 57c4f67f16ef..e32ffcc7053d 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;
>   }
>

Please see comments on your v2 that includes this change.

thanks,
-- Shuah
diff mbox series

Patch

=====================

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 <jun.miao@windriver.com>
---
 tools/testing/selftests/x86/sigreturn.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/x86/sigreturn.c b/tools/testing/selftests/x86/sigreturn.c
index 57c4f67f16ef..e32ffcc7053d 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;
 }