[openwrt/openwrt] build: add test for 64-bit time support
LEDE Commits
lede-commits at lists.infradead.org
Thu Jun 27 00:31:57 PDT 2024
robimarko pushed a commit to openwrt/openwrt.git, branch main:
https://git.openwrt.org/39e8ef33bfd9cf52f84957f0212dbc2f3e10bece
commit 39e8ef33bfd9cf52f84957f0212dbc2f3e10bece
Author: Michael Pratt <mcpratt at pm.me>
AuthorDate: Tue Jun 25 01:48:45 2024 -0400
build: add test for 64-bit time support
Several GNU tools such as tar, coreutils, and findutils
now build with support for 64-bit time by default
and otherwise require reconfiguring with a flag
--disable-year2038 in order to build without 64-bit time.
Some standard C libraries, for example,
certain older versions of glibc such as 2.31
have large file support but not long time bits support:
checking for ... option to enable large file support... -D_FILE_OFFSET_BITS=64
checking for ... option for timestamps after 2038... support not detected
This test using C code taken from largefile.m4 in gnulib
uses math and casting to check for overflow
with a macro and array pair that can only be defined
when 64-bit time support is present, and otherwise errors.
It is the exact same code used to test for 64-bit time
during the configure stage of building these tools,
so the results of this test before configure takes place
will always be in concordance with the results of
the test that takes place during the configure script.
Based on the test, the configure flag --disable-year2038
is added to every host tool build depending on the host system.
When the year 2038 problem finally comes around,
the effect of the test can be converted
from the toggling of a configure option into a build prerequisite,
requiring it to pass in order to continue building.
Signed-off-by: Michael Pratt <mcpratt at pm.me>
Link: https://github.com/openwrt/openwrt/pull/15799
Signed-off-by: Robert Marko <robimarko at gmail.com>
---
include/host-build.mk | 4 ++++
rules.mk | 14 ++++++++++++++
2 files changed, 18 insertions(+)
diff --git a/include/host-build.mk b/include/host-build.mk
index 235caaa6fb..246f248e26 100644
--- a/include/host-build.mk
+++ b/include/host-build.mk
@@ -67,6 +67,10 @@ HOST_CONFIGURE_ARGS = \
--localstatedir=$(HOST_BUILD_PREFIX)/var \
--sbindir=$(HOST_BUILD_PREFIX)/bin
+ifneq ($(YEAR_2038),y)
+ HOST_CONFIGURE_ARGS += --disable-year2038
+endif
+
HOST_MAKE_VARS = \
CFLAGS="$(HOST_CFLAGS)" \
CPPFLAGS="$(HOST_CPPFLAGS)" \
diff --git a/rules.mk b/rules.mk
index 66297565cb..91ed9b2085 100644
--- a/rules.mk
+++ b/rules.mk
@@ -26,6 +26,7 @@ qstrip=$(strip $(subst ",,$(1)))
empty:=
space:= $(empty) $(empty)
comma:=,
+pound:=\#
merge=$(subst $(space),,$(1))
confvar=$(shell echo '$(foreach v,$(1),$(v)=$(subst ','\'',$($(v))))' | $(MKHASH) md5)
strip_last=$(patsubst %.$(lastword $(subst .,$(space),$(1))),%,$(1))
@@ -378,6 +379,19 @@ define shexport
export $(call shvar,$(1))=$$(call $(1))
endef
+# Test support for 64-bit time with C code from largefile.m4 provided by GNU Gnulib
+# the value is 'y' when successful and '' otherwise
+define YEAR_2038
+$(shell \
+ mkdir -p $(TMP_DIR); \
+ echo '$(pound) include <time.h>' > $(TMP_DIR)/year2038.c; \
+ echo '$(pound) define LARGE_TIME_T ((time_t) (((time_t) 1 << 30) - 1 + 3 * ((time_t) 1 << 30)))' >> $(TMP_DIR)/year2038.c; \
+ echo 'int verify_time_t_range[(LARGE_TIME_T / 65537 == 65535 && LARGE_TIME_T % 65537 == 0) ? 1 : -1];' >> $(TMP_DIR)/year2038.c; \
+ echo 'int main (void) {return 0;}' >> $(TMP_DIR)/year2038.c; \
+ $(HOSTCC) $(TMP_DIR)/year2038.c -o /dev/null 2>/dev/null && echo y && rm -f $(TMP_DIR)/year2038.c || rm -f $(TMP_DIR)/year2038.c; \
+)
+endef
+
# Execute commands under flock
# $(1) => The shell expression.
# $(2) => The lock name. If not given, the global lock will be used.
More information about the lede-commits
mailing list