Skip to contentSkip to conversation

package/libsigsegv: fix macro expansion error for RISC-V with musl

PATCH New Mark Corbin 2 participants 3 messages Oct 25, 2019 – Oct 26, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 package/libsigsegv: fix macro expansion error for RISC-V with musl

The expansion of the SIGSEGV_FAULT_STACKPOINTER macro fails when building for RISC-V with musl because REG_SP is not defined (it is defined for glibc). This patch just replaces REG_SP with the numerical register offset (which is 2 for the stack pointer).

Fixes:
http://autobuild.buildroot.net/results/8d6cade2562404b9800736a3b9a2beada98bda88

---
 ...ion-error-when-building-for-RISC-V-w.patch | 29 +++++++++++++++++++
 1 file changed, 29 insertions(+)
 create mode 100644 package/libsigsegv/0005-Fix-macro-expansion-error-when-building-for-RISC-V-w.patch
package/libsigsegv/0005-Fix-macro-expansion-error-when-building-for-RISC-V-w.patch new file +29 -0
new file mode 100644
index 0000000000..6906e04b1d
@@ -0,0 +1,29 @@
+From 3da9e4a8aea252143ab567678722c739793cfeb7 Mon Sep 17 00:00:00 2001
+From: Mark Corbin <[email protected]>
+Date: Fri, 25 Oct 2019 10:16:54 +0100
+Subject: [PATCH] Fix macro expansion error when building for RISC-V with
+ musl
+
+The expansion of the SIGSEGV_FAULT_STACKPOINTER macro fails when
+building for RISC-V with musl because REG_SP is not defined (it is
+defined for glibc). This patch just replaces REG_SP with the
+numerical register offset (which is 2 for the stack pointer).
+
+Signed-off-by: Mark Corbin <[email protected]>
+---
+ src/fault-linux-riscv64.h | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/fault-linux-riscv64.h b/src/fault-linux-riscv64.h
+index 14831bf..7fee4d3 100644
+--- a/src/fault-linux-riscv64.h
++++ b/src/fault-linux-riscv64.h
+@@ -26,4 +26,4 @@
+    glibc/sysdeps/unix/sysv/linux/riscv/bits/sigcontext.h
+    start with the same block of 32 general-purpose registers.  */
+ 
+-#define SIGSEGV_FAULT_STACKPOINTER  ((ucontext_t *) ucp)->uc_mcontext.__gregs[REG_SP]
++#define SIGSEGV_FAULT_STACKPOINTER  ((ucontext_t *) ucp)->uc_mcontext.__gregs[2]
+-- 
+2.19.1
+
Signature · 1 line
2.19.1
#1 lore raw

PATCH 1/1 package/libsigsegv: fix macro expansion error for RISC-V with musl

Quoted 4 lines · On Fri, 25 Oct 2019 10:56:05 +0100 Mark Corbin <[email protected]> wrote:

The expansion of the SIGSEGV_FAULT_STACKPOINTER macro fails when building for RISC-V with musl because REG_SP is not defined (it is defined for glibc). This patch just replaces REG_SP with the numerical register offset (which is 2 for the stack pointer).

REG_SP is defined in musl in:

https://git.musl-libc.org/cgit/musl/tree/arch/riscv64/bits/reg.h

So I'm not sure I'm following the reasoning here.

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#2 lore raw

PATCH 1/1 package/libsigsegv: fix macro expansion error for RISC-V with musl

Hello Thomas

Quoted 7 lines · Thomas Petazzoni
Quoted 4 lines · On Fri, 25 Oct 2019 10:56:05 +0100 Mark Corbin <[email protected]> wrote:

The expansion of the SIGSEGV_FAULT_STACKPOINTER macro fails when building for RISC-V with musl because REG_SP is not defined (it is defined for glibc). This patch just replaces REG_SP with the numerical register offset (which is 2 for the stack pointer).

Quoted 5 lines

REG_SP is defined in musl in:

https://git.musl-libc.org/cgit/musl/tree/arch/riscv64/bits/reg.h

So I'm not sure I'm following the reasoning here.

There are register definitions in reg.h, but these are not the ones used by the signal header files in musl (arch/<build arch>/bits/signal.h). If you want to index the registers array in the ucontext_t or mcontext_t structures using a register name it needs to be defined at the top of bits/signal.h (see the musl i386, m68k, x32 and x86_64 architectures). Alternatively, for architectures that do not define register names in the musl signal.h file, the registers array is indexed in libsigsegv using a numeric offset (see libsigsegv-2.12/src/fault-linux-mips.h for example).

There are two options to fix the current libsigsegv build issue for RISC-V with musl (REG_SP undefined), either a) patch musl to add a definition for REG_SP to signal.h or b) change REG_SP to a numeric value of 2 in libsigsegv-2.12/src/fault-linux-riscv64.h (as proposed by this patch).

Mark

Signature · 4 lines
-- 
Mark Corbin
Embecosm Ltd.
https://www.embecosm.com