]> Savannah Git Hosting - gnulib.git/commitdiff
sigsegv: Add support for Linux/PowerPC (32-bit) with musl libc.
authorBruno Haible <bruno@clisp.org>
Sun, 13 Mar 2022 14:12:46 +0000 (15:12 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 13 Mar 2022 14:12:46 +0000 (15:12 +0100)
Reported by Khem Raj <raj.khem@gmail.com> in
<https://lists.gnu.org/archive/html/m4-patches/2022-03/msg00000.html>.

* src/sigsegv.c (SIGSEGV_FAULT_STACKPOINTER): In the Linux/PowerPC
32-bit case, handle musl libc differently.
* modules/sigsegv (Files): Add m4/musl.m4.
(configure.ac): Invoke gl_MUSL_LIBC.

ChangeLog
lib/sigsegv.c
modules/sigsegv

index 4d49a824e52742f443a8fcde3f26dd21dd662f79..dcdb38f8c8f381f912c972f1a3ec263c0afb6504 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2022-03-13  Bruno Haible  <bruno@clisp.org>
+
+       sigsegv: Add support for Linux/PowerPC (32-bit) with musl libc.
+       Reported by Khem Raj <raj.khem@gmail.com> in
+       <https://lists.gnu.org/archive/html/m4-patches/2022-03/msg00000.html>.
+       * src/sigsegv.c (SIGSEGV_FAULT_STACKPOINTER): In the Linux/PowerPC
+       32-bit case, handle musl libc differently.
+       * modules/sigsegv (Files): Add m4/musl.m4.
+       (configure.ac): Invoke gl_MUSL_LIBC.
+
 2022-03-11  Paul Eggert  <eggert@cs.ucla.edu>
 
        regex: fix double-free
index da70ffa5fda154e00cdef828f8a3173e9b6f563a..da64d7d0b617833fa902aa6c14519f2455cf6836 100644 (file)
@@ -227,11 +227,28 @@ int libsigsegv_version = LIBSIGSEGV_VERSION;
 #  if defined __powerpc64__ || defined __powerpc64_elfv2__ /* 64-bit */
 #   define SIGSEGV_FAULT_STACKPOINTER  ((ucontext_t *) ucp)->uc_mcontext.gp_regs[1]
 #  else /* 32-bit */
-/* both should be equivalent */
-#   if 0
-#    define SIGSEGV_FAULT_STACKPOINTER  ((ucontext_t *) ucp)->uc_mcontext.regs->gpr[1]
+#   if MUSL_LIBC
+/* musl libc has a different structure of ucontext_t in
+   musl/arch/powerpc/bits/signal.h.  */
+/* The glibc comments say:
+     "Different versions of the kernel have stored the registers on signal
+      delivery at different offsets from the ucontext struct.  Programs should
+      thus use the uc_mcontext.uc_regs pointer to find where the registers are
+      actually stored."  */
+#    if 0
+#     define SIGSEGV_FAULT_STACKPOINTER  ((ucontext_t *) ucp)->uc_mcontext.gregs[1]
+#    else
+#     define SIGSEGV_FAULT_STACKPOINTER  ((ucontext_t *) ucp)->uc_regs->gregs[1]
+#    endif
 #   else
-#    define SIGSEGV_FAULT_STACKPOINTER  ((ucontext_t *) ucp)->uc_mcontext.uc_regs->gregs[1]
+/* Assume the structure of ucontext_t in
+   glibc/sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h.  */
+/* Because of the union, both definitions should be equivalent.  */
+#    if 0
+#     define SIGSEGV_FAULT_STACKPOINTER  ((ucontext_t *) ucp)->uc_mcontext.regs->gpr[1]
+#    else
+#     define SIGSEGV_FAULT_STACKPOINTER  ((ucontext_t *) ucp)->uc_mcontext.uc_regs->gregs[1]
+#    endif
 #   endif
 #  endif
 
index b723bd6814b59543cb60c48f8c71b90d0b4bd40c..eedce3a9d91c470f7707412ae25cbde4bdfa01b9 100644 (file)
@@ -17,6 +17,7 @@ lib/sigsegv.c
 lib/stackvma.h
 lib/stackvma.c
 m4/mmap-anon.m4
+m4/musl.m4
 m4/sigaltstack.m4
 m4/stack-direction.m4
 m4/libsigsegv.m4
@@ -46,6 +47,8 @@ if $GL_GENERATE_SIGSEGV_H; then
   dnl Persuade Solaris OpenIndiana <unistd.h> to declare mincore().
   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
 
+  gl_MUSL_LIBC
+
   AC_REQUIRE([AC_CANONICAL_HOST])
   case "$host_os" in
     solaris2.11)