SQLite User Forum

Fix build on riscv32
Login

Fix build on riscv32

(1) By bkuhls on 2026-04-26 11:41:01 [source]

https://github.com/sqlite/sqlite/commit/db84cdb747ac926d3f272933386fc6196c40cb19

added the usage off __uint128_t with a dependency on, among others, __riscv. This matches riscv32 and riscv64 but only riscv64 has __uint128_t defined.

On riscv32 the autobuilders of the buildroot project reported build errors:

/home/vincent/autobuild/instance-3/output-1/build/sqlite-3.53.0/sqlite3.c: In function 'sqlite3Multiply128':
/home/vincent/autobuild/instance-3/output-1/build/sqlite-3.53.0/sqlite3.c:36804:3: error: unknown type name '__uint128_t'; did you mean '__uint32_t'?
36804 |   __uint128_t r = (__uint128_t)a * b;

Sent PR to fix the problem: https://github.com/sqlite/sqlite/pull/44

(2) By Stephan Beal (stephan) on 2026-04-26 14:31:25 in reply to 1 [link] [source]

Sent PR to fix the problem:

This project does not accept PRs, nor do we have access to a 32-bit riscv system to test this one. Can you confirm whether this slight reformulation of your patch resolves the problem?

Index: src/util.c
==================================================================
--- src/util.c	
+++ src/util.c	
@@ -466,4 +466,8 @@
 }
 
+#if defined(__risc) && defined(__riscv_xlen) && (__riscv_xlen>32)
+#define SQLITE_RISCV64
+#endif
+
 /*
 ** Two inputs are multiplied to get a 128-bit result.  Write the
@@ -473,5 +477,5 @@
 static u64 sqlite3Multiply128(u64 a, u64 b, u64 *pLo){
 #if (defined(__GNUC__) || defined(__clang__)) \
-        && (defined(__x86_64__) || defined(__aarch64__) || defined(__riscv)) \
+  && (defined(__x86_64__) || defined(__aarch64__) || defined(SQLITE_RISCV64)) \
         && !defined(SQLITE_DISABLE_INTRINSIC)
   __uint128_t r = (__uint128_t)a * b;
@@ -509,5 +513,5 @@
 static u64 sqlite3Multiply160(u64 a, u32 aLo, u64 b, u32 *pLo){
 #if (defined(__GNUC__) || defined(__clang__)) \
-        && (defined(__x86_64__) || defined(__aarch64__) || defined(__riscv)) \
+        && (defined(__x86_64__) || defined(__aarch64__) || defined(SQLITE_RISCV64)) \
         && !defined(SQLITE_DISABLE_INTRINSIC)
   __uint128_t r = (__uint128_t)a * b;

(3) By bkuhls on 2026-04-26 19:32:31 in reply to 2 [link] [source]

The if-clause should read

#if defined(__riscv) && defined(__riscv_xlen) && (__riscv_xlen>32)

__risc -> __riscv

Your patch also fixes the problem with riscv32.

I cross-checked with a riscv64 toolchain that the 128-bit code path is used.

(4.1) By Stephan Beal (stephan) on 2026-04-27 06:49:49 edited from 4.0 in reply to 3 [link] [source]

I cross-checked with a riscv64 toolchain that the 128-bit code path is used.

Thank you for the typo fix and confirmation. That's now checked in at src:c4a2c20839 (edit: and refactored somewhat at src:362ef7bc00).