Explorar el Código

busybox: Fix y2038 64-bit time_t build failures

Fix the build failures on 32-bit RISC-V.

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
Alistair Francis hace 4 años
padre
commit
b5443214a2

+ 7 - 0
recipes-core/busybox/busybox_1.31%.bbappend

@@ -0,0 +1,7 @@
+FILESEXTRAPATHS_prepend := "${THISDIR}/files:"
+
+SRC_URI_append_riscv32 = " \
+        file://0001-date-Use-64-prefix-syscall-if-we-have-to.patch \
+        file://0002-time-Use-64-prefix-syscall-if-we-have-to.patch \
+        file://0003-runsv-Use-64-prefix-syscall-if-we-have-to.patch \
+    "

+ 57 - 0
recipes-core/busybox/files/0001-date-Use-64-prefix-syscall-if-we-have-to.patch

@@ -0,0 +1,57 @@
+From 6c200cd3c9b4884036cda011d8db8b67763c41d3 Mon Sep 17 00:00:00 2001
+From: Alistair Francis <alistair.francis@wdc.com>
+Date: Tue, 27 Aug 2019 16:17:57 -0700
+Subject: [PATCH 1/3] date: Use 64 prefix syscall if we have to
+
+Some 32-bit architectures no longer have the 32-bit time_t syscalls.
+Instead they have suffixed syscalls that returns a 64-bit time_t. If
+the architecture doesn't have the non-suffixed syscall and is using a
+64-bit time_t let's use the suffixed syscall instead.
+
+This fixes build issues when building for RISC-V 32-bit with 5.1+ kernel
+headers.
+
+If an architecture only supports the suffixed syscalls, but is still
+using a 32-bit time_t fall back to the libc call.
+
+Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
+Upstream-Status: Submitted
+---
+ coreutils/date.c | 11 +++++++++--
+ 1 file changed, 9 insertions(+), 2 deletions(-)
+
+diff --git a/coreutils/date.c b/coreutils/date.c
+index feb400430..4ef1cbf4a 100644
+--- a/coreutils/date.c
++++ b/coreutils/date.c
+@@ -36,7 +36,7 @@
+ //config:# defaults to "no": stat's nanosecond field is a bit non-portable
+ //config:config FEATURE_DATE_NANO
+ //config:	bool "Support %[num]N nanosecond format specifier"
+-//config:	default n  # syscall(__NR_clock_gettime)
++//config:	default n  # syscall(__NR_clock_gettime) or syscall(__NR_clock_gettime64)
+ //config:	depends on DATE
+ //config:	select PLATFORM_LINUX
+ //config:	help
+@@ -271,10 +271,17 @@ int date_main(int argc UNUSED_PARAM, char **argv)
+ 		 */
+ #endif
+ 	} else {
+-#if ENABLE_FEATURE_DATE_NANO
++#if ENABLE_FEATURE_DATE_NANO && defined(__NR_clock_gettime)
+ 		/* libc has incredibly messy way of doing this,
+ 		 * typically requiring -lrt. We just skip all this mess */
+ 		syscall(__NR_clock_gettime, CLOCK_REALTIME, &ts);
++#elif ENABLE_FEATURE_DATE_NANO && __TIMESIZE == 64
++		/* Let's only suppor the 64 suffix syscalls for 64-bit time_t.
++		 * This simplifies the code for us as we don't need to convert
++		 * between 64-bit and 32-bit. We also don't have a way to
++		 * report overflow errors here.
++		 */
++		syscall(__NR_clock_gettime64, CLOCK_REALTIME, &ts);
+ #else
+ 		time(&ts.tv_sec);
+ #endif
+-- 
+2.22.0
+

+ 46 - 0
recipes-core/busybox/files/0002-time-Use-64-prefix-syscall-if-we-have-to.patch

@@ -0,0 +1,46 @@
+From b18253c4fe09f80906ac996c148035d8731cef60 Mon Sep 17 00:00:00 2001
+From: Alistair Francis <alistair.francis@wdc.com>
+Date: Tue, 27 Aug 2019 17:15:09 -0700
+Subject: [PATCH 2/3] time: Use 64 prefix syscall if we have to
+
+Some 32-bit architectures no longer have the 32-bit time_t syscalls.
+Instead they have suffixed syscalls that returns a 64-bit time_t. If
+the architecture doesn't have the non-suffixed syscall and is using a
+64-bit time_t let's use the suffixed syscall instead.
+
+This fixes build issues when building for RISC-V 32-bit with 5.1+ kernel
+headers.
+
+If an architecture only supports the suffixed syscalls, but is still
+using a 32-bit time_t report a compilation error. This avoids us have to
+deal with converting between 64-bit and 32-bit values. There are
+currently no architectures where this is the case.
+
+Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
+Upstream-Status: Submitted
+---
+ libbb/time.c | 7 +++++++
+ 1 file changed, 7 insertions(+)
+
+diff --git a/libbb/time.c b/libbb/time.c
+index cab0ad602..b6fcae28b 100644
+--- a/libbb/time.c
++++ b/libbb/time.c
+@@ -257,7 +257,14 @@ char* FAST_FUNC strftime_YYYYMMDDHHMMSS(char *buf, unsigned len, time_t *tp)
+  * typically requiring -lrt. We just skip all this mess */
+ static void get_mono(struct timespec *ts)
+ {
++#if defined(__NR_clock_gettime)
+ 	if (syscall(__NR_clock_gettime, CLOCK_MONOTONIC, ts))
++#elif __TIMESIZE == 64
++	if (syscall(__NR_clock_gettime64, CLOCK_MONOTONIC, ts))
++#else
++# error "We currently don't support architectures without " \
++	"the __NR_clock_gettime syscall and 32-bit time_t"
++#endif
+ 		bb_error_msg_and_die("clock_gettime(MONOTONIC) failed");
+ }
+ unsigned long long FAST_FUNC monotonic_ns(void)
+-- 
+2.22.0
+

+ 46 - 0
recipes-core/busybox/files/0003-runsv-Use-64-prefix-syscall-if-we-have-to.patch

@@ -0,0 +1,46 @@
+From 8c7419649d6e6fda8fa7d0e863084c78ac728628 Mon Sep 17 00:00:00 2001
+From: Alistair Francis <alistair.francis@wdc.com>
+Date: Wed, 28 Aug 2019 10:54:15 -0700
+Subject: [PATCH 3/3] runsv: Use 64 prefix syscall if we have to
+
+Some 32-bit architectures no longer have the 32-bit time_t syscalls.
+Instead they have suffixed syscalls that returns a 64-bit time_t. If
+the architecture doesn't have the non-suffixed syscall and is using a
+64-bit time_t let's use the suffixed syscall instead.
+
+This fixes build issues when building for RISC-V 32-bit with 5.1+ kernel
+headers.
+
+If an architecture only supports the suffixed syscalls, but is still
+using a 32-bit time_t report a compilation error. This avoids us have to
+deal with converting between 64-bit and 32-bit values. There are
+currently no architectures where this is the case.
+
+Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
+Upstream-Status: Submitted
+---
+ runit/runsv.c | 7 +++++++
+ 1 file changed, 7 insertions(+)
+
+diff --git a/runit/runsv.c b/runit/runsv.c
+index ccc762d78..737909b0e 100644
+--- a/runit/runsv.c
++++ b/runit/runsv.c
+@@ -55,7 +55,14 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+  * typically requiring -lrt. We just skip all this mess */
+ static void gettimeofday_ns(struct timespec *ts)
+ {
++#if defined(__NR_clock_gettime)
+ 	syscall(__NR_clock_gettime, CLOCK_REALTIME, ts);
++#elif __TIMESIZE == 64
++	syscall(__NR_clock_gettime64, CLOCK_REALTIME, ts);
++#else
++# error "We currently don't support architectures without " \
++	"the __NR_clock_gettime syscall and 32-bit time_t"
++#endif
+ }
+ #else
+ static void gettimeofday_ns(struct timespec *ts)
+-- 
+2.22.0
+