Skip to content

Commit

Permalink
build: add test for 64-bit time support
Browse files Browse the repository at this point in the history
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 <[email protected]>
Link: openwrt#15799
Signed-off-by: Robert Marko <[email protected]>
  • Loading branch information
mcprat authored and robimarko committed Jun 27, 2024
1 parent f637cf5 commit 39e8ef3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/host-build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)" \
Expand Down
14 changes: 14 additions & 0 deletions rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 39e8ef3

Please sign in to comment.