1From a6ff69873110c0a8ba6f7fd90532dbc11224828c Mon Sep 17 00:00:00 2001 2From: Bruno Haible <bruno@clisp.org> 3Date: Sun, 13 Mar 2022 15:04:06 +0100 4Subject: [PATCH] Add support for Linux/PowerPC (32-bit) with musl libc. 5 6Reported by Khem Raj <raj.khem@gmail.com> in 7<https://lists.gnu.org/archive/html/m4-patches/2022-03/msg00000.html>. 8 9* autogen.sh: Copy also musl.m4. 10* configure.ac: Invoke gl_MUSL_LIBC. 11* src/fault-linux-powerpc.h (SIGSEGV_FAULT_STACKPOINTER): In the 32-bit 12case, handle musl libc differently. 13* NEWS: Mention it. 14 15Upstream: https://git.savannah.gnu.org/gitweb/?p=libsigsegv.git;a=commit;h=a6ff69873110c0a8ba6f7fd90532dbc11224828c 16Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com> 17--- 18 ChangeLog | 11 +++++++++++ 19 NEWS | 4 ++++ 20 autogen.sh | 3 ++- 21 configure.ac | 2 ++ 22 src/fault-linux-powerpc.h | 27 ++++++++++++++++++++++----- 23 5 files changed, 41 insertions(+), 6 deletions(-) 24 25diff --git a/ChangeLog b/ChangeLog 26index c52b227..7c0a8fa 100644 27--- a/ChangeLog 28+++ b/ChangeLog 29@@ -1,3 +1,14 @@ 30+2022-03-13 Bruno Haible <bruno@clisp.org> 31+ 32+ Add support for Linux/PowerPC (32-bit) with musl libc. 33+ Reported by Khem Raj <raj.khem@gmail.com> in 34+ <https://lists.gnu.org/archive/html/m4-patches/2022-03/msg00000.html>. 35+ * autogen.sh: Copy also musl.m4. 36+ * configure.ac: Invoke gl_MUSL_LIBC. 37+ * src/fault-linux-powerpc.h (SIGSEGV_FAULT_STACKPOINTER): In the 32-bit 38+ case, handle musl libc differently. 39+ * NEWS: Mention it. 40+ 41 2022-01-07 Bruno Haible <bruno@clisp.org> 42 43 Prepare for version 2.14. 44diff --git a/NEWS b/NEWS 45index 4d012f8..82cc0f4 100644 46--- a/NEWS 47+++ b/NEWS 48@@ -1,3 +1,7 @@ 49+New in 2.15: 50+ 51+* Added support for Linux/PowerPC (32-bit) with musl libc. 52+ 53 New in 2.14: 54 55 * Added support for 64-bit Cygwin. 56diff --git a/configure.ac b/configure.ac 57index e87f13b..164786f 100644 58--- a/configure.ac 59+++ b/configure.ac 60@@ -75,6 +75,8 @@ AC_MSG_RESULT([$sv_cv_host]) 61 PLATFORM="$sv_cv_host" 62 AC_SUBST([PLATFORM]) 63 64+gl_MUSL_LIBC 65+ 66 dnl ========================== Done with PLATFORM ========================== 67 68 69diff --git a/src/fault-linux-powerpc.h b/src/fault-linux-powerpc.h 70index cba6ea7..b3f922a 100644 71--- a/src/fault-linux-powerpc.h 72+++ b/src/fault-linux-powerpc.h 73@@ -1,5 +1,5 @@ 74 /* Fault handler information. Linux/PowerPC version when it supports POSIX. 75- Copyright (C) 2002, 2009, 2017 Bruno Haible <bruno@clisp.org> 76+ Copyright (C) 2002, 2009, 2017, 2022 Bruno Haible <bruno@clisp.org> 77 78 This program is free software: you can redistribute it and/or modify 79 it under the terms of the GNU General Public License as published by 80@@ -28,10 +28,27 @@ 81 #if defined(__powerpc64__) || defined(_ARCH_PPC64) /* 64-bit */ 82 # define SIGSEGV_FAULT_STACKPOINTER ((ucontext_t *) ucp)->uc_mcontext.gp_regs[1] 83 #else /* 32-bit */ 84-/* both should be equivalent */ 85-# if 0 86-# define SIGSEGV_FAULT_STACKPOINTER ((ucontext_t *) ucp)->uc_mcontext.regs->gpr[1] 87+# if MUSL_LIBC 88+/* musl libc has a different structure of ucontext_t in 89+ musl/arch/powerpc/bits/signal.h. */ 90+/* The glibc comments say: 91+ "Different versions of the kernel have stored the registers on signal 92+ delivery at different offsets from the ucontext struct. Programs should 93+ thus use the uc_mcontext.uc_regs pointer to find where the registers are 94+ actually stored." */ 95+# if 0 96+# define SIGSEGV_FAULT_STACKPOINTER ((ucontext_t *) ucp)->uc_mcontext.gregs[1] 97+# else 98+# define SIGSEGV_FAULT_STACKPOINTER ((ucontext_t *) ucp)->uc_regs->gregs[1] 99+# endif 100 # else 101-# define SIGSEGV_FAULT_STACKPOINTER ((ucontext_t *) ucp)->uc_mcontext.uc_regs->gregs[1] 102+/* Assume the structure of ucontext_t in 103+ glibc/sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h. */ 104+/* Because of the union, both definitions should be equivalent. */ 105+# if 0 106+# define SIGSEGV_FAULT_STACKPOINTER ((ucontext_t *) ucp)->uc_mcontext.regs->gpr[1] 107+# else 108+# define SIGSEGV_FAULT_STACKPOINTER ((ucontext_t *) ucp)->uc_mcontext.uc_regs->gregs[1] 109+# endif 110 # endif 111 #endif 112-- 1132.17.1 114 115