bug-gnulib
[Top][All Lists]
Advanced

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

Re: [PATCH] sigsegv: Fix build on ppc/musl


From: Bruno Haible
Subject: Re: [PATCH] sigsegv: Fix build on ppc/musl
Date: Sun, 13 Mar 2022 15:17:27 +0100

Eric Blake wrote:
> On Wed, Mar 09, 2022 at 11:37:14PM -0800, Khem Raj wrote:
> > mcontext is not a standard layout so glibc and musl differ sadly.
> > 
> > Fixes
> > ../../m4-1.4.19/lib/sigsegv.c: In function 'sigsegv_handler':               
> >                                                                             
> >                                     ../../m4-1.4.19/lib/sigsegv.c:223:75: 
> > error: 'mcontext_t' has no member named 'uc_regs'; did you mean 'gregs'?    
> >                                                                             
> > 223 | #    define SIGSEGV_FAULT_STACKPOINTER  ((ucontext_t *) 
> > ucp)->uc_mcontext.uc_regs->gregs[1]                                         
> >                                                       |                     
> >                                                       ^~~~~~~
> 
> Thanks for the report.  As this file comes from gnulib, the fix needs
> to go there first.

Thanks for the report. I'm adding this patch to GNU libsigsegv:
https://git.savannah.gnu.org/gitweb/?p=libsigsegv.git;a=commitdiff;h=a6ff69873110c0a8ba6f7fd90532dbc11224828c

and then this (derived) patch to Gnulib.

I couldn't verify that it works, since there is no Linux distro that is based
on musl libc and is ported to Linux/powerpc (32-bit).


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.

diff --git a/lib/sigsegv.c b/lib/sigsegv.c
index da70ffa5fd..da64d7d0b6 100644
--- a/lib/sigsegv.c
+++ b/lib/sigsegv.c
@@ -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
 
diff --git a/modules/sigsegv b/modules/sigsegv
index b723bd6814..eedce3a9d9 100644
--- a/modules/sigsegv
+++ b/modules/sigsegv
@@ -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)






reply via email to

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