From 1d75cf2cd7204fff4c419f25dbaa4a5da888f9ba Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 13 Mar 2022 15:12:46 +0100 Subject: [PATCH] sigsegv: Add support for Linux/PowerPC (32-bit) with musl libc. Reported by Khem Raj in . * 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 | 10 ++++++++++ lib/sigsegv.c | 25 +++++++++++++++++++++---- modules/sigsegv | 3 +++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3177406264..e0c6ca4c7a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2022-03-13 Bruno Haible + + sigsegv: Add support for Linux/PowerPC (32-bit) with musl libc. + Reported by Khem Raj in + . + * 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 regex: fix double-free 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 to declare mincore(). AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) + gl_MUSL_LIBC + AC_REQUIRE([AC_CANONICAL_HOST]) case "$host_os" in solaris2.11) -- 2.39.5