Skip to contentSkip to conversation

redis: Fix build with clang on riscv32

PATCH New Khem Raj 1 participant 1 message Oct 27, 2020 RISC-V

lore
Share & tools
lore

Khem Raj

author
#0 lore raw

PATCH 1/1 redis: Fix build with clang on riscv32

clang defines __ILP32__ for rv32 but gcc does not as a result backtracing gets enabled when using clang but not when using gcc so clang build exposes a porting error. Therefore add code to return correct mcontext on rv32

---
 .../redis/redis/riscv32.patch                 | 47 +++++++++++++++++++
 meta-oe/recipes-extended/redis/redis_6.0.8.bb |  2 +
 2 files changed, 49 insertions(+)
 create mode 100644 meta-oe/recipes-extended/redis/redis/riscv32.patch
meta-oe/recipes-extended/redis/redis/riscv32.patch new file +47 -0
new file mode 100644
index 0000000000..79ec7423da
@@ -0,0 +1,47 @@
+Define correct gregs for RISCV32
+
+Upstream-Status: Pending
+Signed-off-by: Khem Raj <[email protected]>
+--- a/src/debug.c
++++ b/src/debug.c
+@@ -942,7 +942,9 @@ static void *getMcontextEip(ucontext_t *
+     #endif
+ #elif defined(__linux__)
+     /* Linux */
+-    #if defined(__i386__) || defined(__ILP32__)
++    #if defined(__riscv) && __riscv_xlen == 32
++    return (void*) uc->uc_mcontext.__gregs[REG_PC];
++    #elif defined(__i386__) || defined(__ILP32__)
+     return (void*) uc->uc_mcontext.gregs[14]; /* Linux 32 */
+     #elif defined(__X86_64__) || defined(__x86_64__)
+     return (void*) uc->uc_mcontext.gregs[16]; /* Linux 64 */
+@@ -1102,8 +1104,28 @@ void logRegisters(ucontext_t *uc) {
+     #endif
+ /* Linux */
+ #elif defined(__linux__)
++    /* Linux RISCV32 */
++    #if defined(__riscv) && __riscv_xlen == 32
++    serverLog(LL_WARNING,
++    "\n"
++    "RA:%08lx S0:%08lx S1:%08lx S2:%08lx\n"
++    "SP:%08lx PC:%08lx A0:%08lx A1:%08lx\n"
++    "A2 :%08lx A3:%08lx A4:%08lx",
++        (unsigned long) uc->uc_mcontext.__gregs[REG_RA],
++        (unsigned long) uc->uc_mcontext.__gregs[REG_S0],
++        (unsigned long) uc->uc_mcontext.__gregs[REG_S1],
++        (unsigned long) uc->uc_mcontext.__gregs[REG_S2],
++        (unsigned long) uc->uc_mcontext.__gregs[REG_SP],
++        (unsigned long) uc->uc_mcontext.__gregs[REG_PC],
++        (unsigned long) uc->uc_mcontext.__gregs[REG_A0 + 0],
++        (unsigned long) uc->uc_mcontext.__gregs[REG_A0 + 1],
++        (unsigned long) uc->uc_mcontext.__gregs[REG_A0 + 2],
++        (unsigned long) uc->uc_mcontext.__gregs[REG_A0 + 3],
++        (unsigned long) uc->uc_mcontext.__gregs[REG_A0 + 4]
++    );
++    logStackContent((void**)uc->uc_mcontext.__gregs[REG_SP]);
+     /* Linux x86 */
+-    #if defined(__i386__) || defined(__ILP32__)
++    #elif defined(__i386__) || defined(__ILP32__)
+     serverLog(LL_WARNING,
+     "\n"
+     "EAX:%08lx EBX:%08lx ECX:%08lx EDX:%08lx\n"
meta-oe/recipes-extended/redis/redis_6.0.8.bb +2 -0
index 64b137c1be..546332851c 100644
@@ -15,6 +15,7 @@ SRC_URI = "http://download.redis.io/releases/${BP}.tar.gz \
            file://oe-use-libc-malloc.patch \
            file://0001-src-Do-not-reset-FINAL_LIBS.patch \
            file://GNU_SOURCE.patch \
+           file://riscv32.patch \
            "
 
 SRC_URI[md5sum] = "70113b4b8ea7ee4c7e148be62b5d1e0b"
@@ -23,6 +24,7 @@ SRC_URI[sha256sum] = "04fa1fddc39bd1aecb6739dd5dd73858a3515b427acd1e2947a66dadce
 inherit autotools-brokensep update-rc.d systemd useradd
 
 FINAL_LIBS_x86_toolchain-clang = "-latomic"
+FINAL_LIBS_riscv32_toolchain-clang = "-latomic"
 FINAL_LIBS_mips = "-latomic"
 FINAL_LIBS_arm = "-latomic"
 FINAL_LIBS_powerpc = "-latomic"
Signature · 1 line
2.29.1