bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* sigsegv, c-stack: Avoid compilation error with glibc >= 2.34
@ 2021-05-17  0:33 Bruno Haible
  2021-05-17  2:45 ` Paul Eggert
  0 siblings, 1 reply; 11+ messages in thread
From: Bruno Haible @ 2021-05-17  0:33 UTC (permalink / raw)
  To: bug-gnulib

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



^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-05-24 10:37 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-17  0:33 sigsegv, c-stack: Avoid compilation error with glibc >= 2.34 Bruno Haible
2021-05-17  2:45 ` Paul Eggert
2021-05-18 17:34   ` Bruno Haible
2021-05-21 22:49     ` Paul Eggert
2021-05-22 22:59       ` Bruno Haible
2021-05-23  5:12         ` Paul Eggert
2021-05-23 12:14           ` Bruno Haible
2021-05-24  2:40             ` Paul Eggert
2021-05-24 10:37               ` Bruno Haible
2021-05-23  0:00       ` sigsegv.h interface Bruno Haible
2021-05-23  5:14         ` Paul Eggert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).