]> Savannah Git Hosting - gnulib.git/commitdiff
sigsegv tests: Avoid a crash on NetBSD 10.0/i386.
authorBruno Haible <bruno@clisp.org>
Sun, 7 Apr 2024 14:53:02 +0000 (16:53 +0200)
committerBruno Haible <bruno@clisp.org>
Mon, 8 Apr 2024 11:21:11 +0000 (13:21 +0200)
* tests/test-sigsegv-catch-stackoverflow1.c
(stackoverflow_handler_continuation): On NetBSD/i386, align the stack
pointer before calling longjmp.

ChangeLog
tests/test-sigsegv-catch-stackoverflow1.c

index 920e0a6a887557c442e234634c0db868e0580db6..539ce071818c76e920af827eeae82319e2d04b15 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-04-07  Bruno Haible  <bruno@clisp.org>
+
+       sigsegv tests: Avoid a crash on NetBSD 10.0/i386.
+       * tests/test-sigsegv-catch-stackoverflow1.c
+       (stackoverflow_handler_continuation): On NetBSD/i386, align the stack
+       pointer before calling longjmp.
+
 2024-04-06  Bruno Haible  <bruno@clisp.org>
 
        expm1l: Work around a NetBSD 10.0/i386 bug.
index 0c4f1d495ac616a888305f83c7f61d1b4ffd8cf0..46b120686c99ace589fbc63f85ef8ffa5e3709d8 100644 (file)
@@ -1,5 +1,5 @@
 /* Test the stack overflow handler.
-   Copyright (C) 2002-2023 Free Software Foundation, Inc.
+   Copyright (C) 2002-2024 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -55,7 +55,26 @@ static volatile char *stack_upper_bound;
 static void
 stackoverflow_handler_continuation (void *arg1, void *arg2, void *arg3)
 {
+#if defined __NetBSD__ && defined __i386__
+  /* On NetBSD 10.0/i386, when built as part of a testdir-all (but not as part
+     of a testdir for just the module 'sigsegv'!) this program crashes.  The
+     cause is that:
+       - The alternate stack is not aligned (which is intentional, see
+         altstack-util.h) and NetBSD does not align the stack pointer while
+         switching to the alternate stack.
+       - When %esp is not aligned, the dynamic linker crashes in function
+         _rtld_bind while resolving the symbol 'longjmp'.
+     We would around this by aligning the stack pointer, to a multiple of 8.  */
+  int *argp;
+  __asm__ __volatile__ ("movl %1,%0" : "=r" (argp) : "r" (&arg1));
+  unsigned long sp;
+  __asm__ __volatile__ ("movl %%esp,%0" : "=r" (sp));
+  sp &= ~7UL;
+  __asm__ __volatile__ ("movl %0,%%esp" : : "r" (sp));
+  int arg = *argp;
+#else
   int arg = (int) (long) arg1;
+#endif
   longjmp (mainloop, arg);
 }