bug-gnulib
[Top][All Lists]
Advanced

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

c-stack: Fix for Linux/sparc


From: Bruno Haible
Subject: c-stack: Fix for Linux/sparc
Date: Sun, 16 Dec 2018 23:37:47 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-139-generic; KDE/5.18.0; x86_64; ; )

While testing a 'grep' snapshot on Linux/sparc64, I noticed that this
test failure (both in 32-bit and 64-bit mode):


FAIL: test-c-stack2.sh
======================

cannot tell stack overflow from crash, in spite of libsigsegv
FAIL test-c-stack2.sh (exit status: 1)


The message "in spite of libsigsegv" is a bit misleading: libsigsegv
was available, but c-stack.c was compiled in such a way that it did
not use libsigsegv. configure defined HAVE_XSI_STACK_OVERFLOW_HEURISTIC
to 1; this is what leads to the test failure. If I
  #undef HAVE_XSI_STACK_OVERFLOW_HEURISTIC
in c-stack.c, then libsigsegv gets used, and the test-c-stack2.sh
test succeeds.

SIGSEGV handling on Linux/sparc is special; see
https://git.savannah.gnu.org/gitweb/?p=libsigsegv.git;a=commitdiff;h=0db93a4c0e2a6881ad6781a9746fc112971aab17

Two things are particular:
  - The third argument passed to the SIGSEGV handler is not an 'ucontext_t *'.
  - In 64-bit mode, an offset of 2047 needs to be considered.

Since the problem here occurs also in 32-bit mode, where no offset is
involved, the cause of the issue must be the nature of the third argument.

With this knowledge, it's easy to adjust the Autoconf test. This patch
fixes the test failure in both 32-bit and 64-bit mode; therefore I'm
pushing it.


2018-12-16  Bruno Haible  <address@hidden>

        c-stack: Fix for Linux/sparc.
        * m4/c-stack.m4 (AC_SYS_XSI_STACK_OVERFLOW_HEURISTIC): Set
        ac_cv_sys_xsi_stack_overflow_heuristic to 'no' on Linux/sparc.

(This is a whitespace-insensitive diff.)
diff --git a/m4/c-stack.m4 b/m4/c-stack.m4
index 919f3d3..f210842 100644
--- a/m4/c-stack.m4
+++ b/m4/c-stack.m4
@@ -7,7 +7,7 @@
 
 # Written by Paul Eggert.
 
-# serial 16
+# serial 17
 
 AC_DEFUN([AC_SYS_XSI_STACK_OVERFLOW_HEURISTIC],
   [
@@ -201,7 +201,17 @@ int main ()
 
    AC_CACHE_CHECK([for precise C stack overflow detection],
      [ac_cv_sys_xsi_stack_overflow_heuristic],
-     [AC_RUN_IFELSE([AC_LANG_SOURCE(
+     [dnl On Linux/sparc64 (both in 32-bit and 64-bit mode), it would be wrong
+      dnl to set HAVE_XSI_STACK_OVERFLOW_HEURISTIC to 1, because the third
+      dnl argument passed to the segv_handler is a 'struct sigcontext *', not
+      dnl an 'ucontext_t *'.  It would lead to a failure of test-c-stack2.sh.
+      case "${host_os}--${host_cpu}" in
+        linux*--sparc*)
+          ac_cv_sys_xsi_stack_overflow_heuristic=no
+          ;;
+        *)
+          AC_RUN_IFELSE(
+            [AC_LANG_SOURCE(
                [[
                 #include <unistd.h>
                 #include <signal.h>
@@ -242,9 +252,9 @@ int main ()
                 {
                   if (0 < info->si_code)
                     {
-                  /* For XSI heuristics to work, we need uc_stack to describe
-                     the interrupted stack (as on Solaris), and not the
-                     currently executing stack (as on Linux).  */
+                      /* For XSI heuristics to work, we need uc_stack to
+                         describe the interrupted stack (as on Solaris), and
+                         not the currently executing stack (as on Linux).  */
                       ucontext_t const *user_context = context;
                       char const *stack_min = user_context->uc_stack.ss_sp;
                       size_t stack_size = user_context->uc_stack.ss_size;
@@ -321,7 +331,10 @@ int main ()
                ]])],
             [ac_cv_sys_xsi_stack_overflow_heuristic=yes],
             [ac_cv_sys_xsi_stack_overflow_heuristic=no],
-        [ac_cv_sys_xsi_stack_overflow_heuristic=cross-compiling])])
+            [ac_cv_sys_xsi_stack_overflow_heuristic=cross-compiling])
+          ;;
+      esac
+     ])
 
    if test $ac_cv_sys_xsi_stack_overflow_heuristic = yes; then
      AC_DEFINE([HAVE_XSI_STACK_OVERFLOW_HEURISTIC], [1],




reply via email to

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