bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

sigsegv, c-stack: Avoid compilation error with glibc >= 2.34


From: Bruno Haible
Subject: sigsegv, c-stack: Avoid compilation error with glibc >= 2.34
Date: Mon, 17 May 2021 02:33:36 +0200
User-agent: KMail/5.1.3 (Linux/4.4.0-206-generic; KDE/5.18.0; x86_64; ; )

With the glibc header files from a current glibc (post 2.33) and
CC="gcc -I$GLIBC_INSTALL_PREFIX/include -D_GNU_SOURCE", I get this
compilation error in a test of module 'sigsegv':

In file included from ../../gltests/test-sigsegv-catch-stackoverflow1.c:44:0:
../../gltests/altstack-util.h:32:6: error: variably modified ‘mystack_storage’ 
at file scope
 char mystack_storage[SIGSTKSZ + 2 * MYSTACK_CRUMPLE_ZONE + 31];
      ^

Similarly, the autoconf tests of the modules 'sigsegv' and 'c-stack'
have guessed wrong.

The cause is that in glibc, SIGSTKSZ is no longer a compile-time constant.
The discussion in March 2021
<https://sourceware.org/pipermail/libc-alpha/2021-March/123553.html>
only had the effect that the change was limited to the case that _GNU_SOURCE
is enabled. But we are compiling nearly all programs with _GNU_SOURCE=1.

I don't have time to rewrite all these unit tests and autoconf tests.
(Additionally, if we were to use malloc() as a replacement, watch out
that malloc()ed memory may not be executable, but some programs need
an executable stack.)

Instead, just use a constant. Which constant is appropriate? glibc-2.33
has these definitions:

glibc-2.33/sysdeps/unix/sysv/linux/sparc/bits/sigstack.h:#define SIGSTKSZ       
16384
glibc-2.33/sysdeps/unix/sysv/linux/powerpc/bits/sigstack.h:#define SIGSTKSZ     
16384
glibc-2.33/sysdeps/unix/sysv/linux/ia64/bits/sigstack.h:#define SIGSTKSZ        
262144
glibc-2.33/sysdeps/unix/sysv/linux/bits/sigstack.h:#define SIGSTKSZ     8192
glibc-2.33/sysdeps/unix/sysv/linux/alpha/bits/sigstack.h:#define SIGSTKSZ       
16384
glibc-2.33/sysdeps/unix/sysv/linux/aarch64/bits/sigstack.h:#define SIGSTKSZ     
16384
glibc-2.33/bits/sigstack.h:#define SIGSTKSZ     (MINSIGSTKSZ + 32768)
glibc-2.33/bits/sigstack.h:#define MINSIGSTKSZ  8192

So, basically, 256 KB on ia64 and 40 KB (or 64 KB) on all other architectures
should be sufficient. Although there never can be a true guarantee regarding
future processors.

This patch fixes the things from the gnulib side.


2021-05-16  Bruno Haible  <bruno@clisp.org>

        sigsegv, c-stack: Avoid compilation error with glibc >= 2.34.
        * lib/sigsegv.in.h (SIGSTKSZ): On glibc systems, redefine to a suitable
        constant.
        * m4/sigaltstack.m4 (SV_SIGALTSTACK): Likewise.
        * m4/c-stack.m4 (AC_SYS_XSI_STACK_OVERFLOW_HEURISTIC): Likewise.

diff --git a/lib/sigsegv.in.h b/lib/sigsegv.in.h
index 1c87acc..e442f4d 100644
--- a/lib/sigsegv.in.h
+++ b/lib/sigsegv.in.h
@@ -37,16 +37,25 @@
 #endif
 
 /* Correct the value of SIGSTKSZ on some systems.
+   glibc >= 2.34: When _GNU_SOURCE is defined, SIGSTKSZ is no longer a
+   compile-time constant.  But most programs need a simple constant.
    AIX 64-bit: original value 4096 is too small.
    HP-UX: original value 8192 is too small.
    Solaris 11/x86_64: original value 8192 is too small.  */
+#include <signal.h>
+#if __GLIBC__ >= 2
+# undef SIGSTKSZ
+# if defined __ia64__
+#  define SIGSTKSZ 262144
+# else
+#  define SIGSTKSZ 65536
+# endif
+#endif
 #if defined _AIX && defined _ARCH_PPC64
-# include <signal.h>
 # undef SIGSTKSZ
 # define SIGSTKSZ 8192
 #endif
 #if defined __hpux || (defined __sun && (defined __x86_64__ || defined 
__amd64__))
-# include <signal.h>
 # undef SIGSTKSZ
 # define SIGSTKSZ 16384
 #endif
diff --git a/m4/c-stack.m4 b/m4/c-stack.m4
index 06b2594..3131dd5 100644
--- a/m4/c-stack.m4
+++ b/m4/c-stack.m4
@@ -7,7 +7,7 @@
 
 # Written by Paul Eggert.
 
-# serial 21
+# serial 22
 
 AC_DEFUN([AC_SYS_XSI_STACK_OVERFLOW_HEURISTIC],
   [
@@ -44,6 +44,17 @@ AC_DEFUN([AC_SYS_XSI_STACK_OVERFLOW_HEURISTIC],
             # include <sys/time.h>
             # include <sys/resource.h>
             #endif
+            /* In glibc >= 2.34, when _GNU_SOURCE is defined, SIGSTKSZ is
+               no longer a compile-time constant.  But we need a simple
+               constant here.  */
+            #if __GLIBC__ >= 2
+            # undef SIGSTKSZ
+            # if defined __ia64__
+            #  define SIGSTKSZ 262144
+            # else
+            #  define SIGSTKSZ 16384
+            # endif
+            #endif
             #ifndef SIGSTKSZ
             # define SIGSTKSZ 16384
             #endif
@@ -149,6 +160,16 @@ AC_DEFUN([AC_SYS_XSI_STACK_OVERFLOW_HEURISTIC],
 #if HAVE_SYS_SIGNAL_H
 # include <sys/signal.h>
 #endif
+/* In glibc >= 2.34, when _GNU_SOURCE is defined, SIGSTKSZ is no longer a
+   compile-time constant.  But we need a simple constant here.  */
+#if __GLIBC__ >= 2
+# undef SIGSTKSZ
+# if defined __ia64__
+#  define SIGSTKSZ 262144
+# else
+#  define SIGSTKSZ 16384
+# endif
+#endif
 #ifndef SIGSTKSZ
 # define SIGSTKSZ 16384
 #endif
@@ -233,6 +254,17 @@ int main ()
                 # include <sys/time.h>
                 # include <sys/resource.h>
                 #endif
+                /* In glibc >= 2.34, when _GNU_SOURCE is defined, SIGSTKSZ is
+                   no longer a compile-time constant.  But we need a simple
+                   constant here.  */
+                #if __GLIBC__ >= 2
+                # undef SIGSTKSZ
+                # if defined __ia64__
+                #  define SIGSTKSZ 262144
+                # else
+                #  define SIGSTKSZ 16384
+                # endif
+                #endif
                 #ifndef SIGSTKSZ
                 # define SIGSTKSZ 16384
                 #endif
diff --git a/m4/sigaltstack.m4 b/m4/sigaltstack.m4
index 212e9d3..837191e 100644
--- a/m4/sigaltstack.m4
+++ b/m4/sigaltstack.m4
@@ -1,4 +1,4 @@
-# sigaltstack.m4 serial 12
+# sigaltstack.m4 serial 13
 dnl Copyright (C) 2002-2021 Bruno Haible <bruno@clisp.org>
 dnl Copyright (C) 2008 Eric Blake <ebb9@byu.net>
 dnl This file is free software, distributed under the terms of the GNU
@@ -53,6 +53,16 @@ AC_DEFUN([SV_SIGALTSTACK],
 # include <sys/time.h>
 # include <sys/resource.h>
 #endif
+/* In glibc >= 2.34, when _GNU_SOURCE is defined, SIGSTKSZ is no longer a
+   compile-time constant.  But we need a simple constant here.  */
+#if __GLIBC__ >= 2
+# undef SIGSTKSZ
+# if defined __ia64__
+#  define SIGSTKSZ 262144
+# else
+#  define SIGSTKSZ 16384
+# endif
+#endif
 #ifndef SIGSTKSZ
 # define SIGSTKSZ 16384
 #endif
@@ -138,6 +148,16 @@ int main ()
 #if HAVE_SYS_SIGNAL_H
 # include <sys/signal.h>
 #endif
+/* In glibc >= 2.34, when _GNU_SOURCE is defined, SIGSTKSZ is no longer a
+   compile-time constant.  But we need a simple constant here.  */
+#if __GLIBC__ >= 2
+# undef SIGSTKSZ
+# if defined __ia64__
+#  define SIGSTKSZ 262144
+# else
+#  define SIGSTKSZ 16384
+# endif
+#endif
 #ifndef SIGSTKSZ
 # define SIGSTKSZ 16384
 #endif




reply via email to

[Prev in Thread] Current Thread [Next in Thread]