]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
busybox: Fix build on architectures without SYS_settimeofday
authorKhem Raj <raj.khem@gmail.com>
Wed, 21 May 2025 06:20:02 +0000 (23:20 -0700)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Thu, 22 May 2025 13:36:18 +0000 (14:36 +0100)
Fixes following errors on riscv32/musl

| util-linux/hwclock.c:143:20: error: use of undeclared identifier 'SYS_settimeofday'
|   143 |         int ret = syscall(SYS_settimeofday, NULL, tz);
|       |                           ^
| 1 error generated.

Signed-off-by: Khem Raj <raj.khem@gmail.com>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/recipes-core/busybox/busybox/0001-hwclock-Check-for-SYS_settimeofday-before-calling-sy.patch [new file with mode: 0644]
meta/recipes-core/busybox/busybox_1.37.0.bb

diff --git a/meta/recipes-core/busybox/busybox/0001-hwclock-Check-for-SYS_settimeofday-before-calling-sy.patch b/meta/recipes-core/busybox/busybox/0001-hwclock-Check-for-SYS_settimeofday-before-calling-sy.patch
new file mode 100644 (file)
index 0000000..11ef2b6
--- /dev/null
@@ -0,0 +1,52 @@
+From 4e1eafc6e0de3e58cac9f62e57b552eddb50ca8e Mon Sep 17 00:00:00 2001
+From: Khem Raj <raj.khem@gmail.com>
+Date: Sun, 7 Mar 2021 17:30:24 -0800
+Subject: [PATCH] hwclock: Check for SYS_settimeofday before calling syscall
+
+Some newer architectures e.g. RISCV32 have 64bit time_t from get go and
+thusly do not have gettimeofday_time64/settimeofday_time64 implemented
+therefore check for SYS_settimeofday definition before making the
+syscall. Fixes build for riscv32 and it will bail out at runtime.
+
+This issue has been discussed on the musl mailing list, and
+the musl developers' opinion is that Busybox is wrong:
+
+https://www.openwall.com/lists/musl/2024/03/03/2
+https://www.openwall.com/lists/musl/2024/04/07/2
+
+The correct fix isn't clear, and in the mean time, the patch
+turns the build issue into a runtime error only on the problematic
+architecture (riscv32), which seems like a reasonable trade-off
+
+Upstream-Status: Submitted [http://lists.busybox.net/pipermail/busybox/2021-March/088583.html]]
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+---
+ util-linux/hwclock.c | 7 +++++--
+ 1 file changed, 5 insertions(+), 2 deletions(-)
+
+diff --git a/util-linux/hwclock.c b/util-linux/hwclock.c
+index c3fd0eb57..dea9c9a55 100644
+--- a/util-linux/hwclock.c
++++ b/util-linux/hwclock.c
+@@ -132,6 +132,7 @@ static void show_clock(const char **pp_rtcname, int utc)
+ static void set_kernel_tz(const struct timezone *tz)
+ {
++      int ret = 1;
+ #if LIBC_IS_MUSL
+       /* musl libc does not pass tz argument to syscall
+        * because "it's deprecated by POSIX, therefore it's fine
+@@ -140,9 +141,11 @@ static void set_kernel_tz(const struct timezone *tz)
+ #if !defined(SYS_settimeofday) && defined(SYS_settimeofday_time32)
+ # define SYS_settimeofday SYS_settimeofday_time32
+ #endif
+-      int ret = syscall(SYS_settimeofday, NULL, tz);
++#if defined(SYS_settimeofday)
++      ret = syscall(SYS_settimeofday, NULL, tz);
++#endif
+ #else
+-      int ret = settimeofday(NULL, tz);
++      ret = settimeofday(NULL, tz);
+ #endif
+       if (ret)
+               bb_simple_perror_msg_and_die("settimeofday");
index 85f22ada5338c419907666a7616cc19efe7565ab..9f7ded3354d91868900eab496708c41144cc3f1b 100644 (file)
@@ -54,6 +54,7 @@ SRC_URI = "https://busybox.net/downloads/busybox-${PV}.tar.bz2;name=tarball \
            file://0002-start-stop-daemon-fix-tests.patch \
            file://0003-start-stop-false.patch \
            file://0001-archival-disallow-path-traversals-CVE-2023-39810.patch \
+           file://0001-hwclock-Check-for-SYS_settimeofday-before-calling-sy.patch \
            "
 SRC_URI:append:libc-musl = " file://musl.cfg"
 SRC_URI:append:x86-64 = " file://sha_accel.cfg"