* modules/largefile-required, modules/year2038-required: New modules. * MODULES.html.sh, doc/largefile.texi, doc/posix-headers/time.texi: * doc/year2038.texi: Document this. * m4/largefile.m4: Sync from Autoconf master. Conditionalize the workaround on AC_SYS_LARGEFILE_REQUIRED rather than on AC_SYS_YEAR2038 so that we replace older but still unreleased Autoconf. (AC_SYS_LARGEFILE_REQUIRED, AC_SYS_YEAR2038_REQUIRED): New macros. --- ChangeLog | 5 ++ MODULES.html.sh | 2 + doc/largefile.texi | 19 +++++- doc/posix-headers/time.texi | 8 ++- doc/year2038.texi | 54 +++++++++++------ m4/largefile.m4 | 118 +++++++++++++++++++++++------------- modules/largefile-required | 28 +++++++++ modules/year2038-required | 26 ++++++++ 8 files changed, 195 insertions(+), 65 deletions(-) create mode 100644 modules/largefile-required create mode 100644 modules/year2038-required
diff --git a/ChangeLog b/ChangeLog index bb49b16cf0..05b11d9f50 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2023-04-09 Paul Eggert <egg...@cs.ucla.edu> + largefile: sync from Autoconf master + * m4/largefile.m4 (_AC_SYS_LARGEFILE_TEST_INCLUDES): + Now an alias for _AC_SYS_LARGEFILE_TEST_CODE. + (AC_SYS_LARGEFILE_REQUIRED, AC_SYS_YEAR2038_REQUIRED): New macros. + year2038: configure earlier * modules/year2038: Put AC_SYS_YEAR2038 in configure.ac-early since it can affect CPPFLAGS with _TIME_BITS=64. diff --git a/MODULES.html.sh b/MODULES.html.sh index 714aedd308..2eeffb690f 100755 --- a/MODULES.html.sh +++ b/MODULES.html.sh @@ -1733,6 +1733,7 @@ func_all_modules () func_module time-h func_module time_rz func_module year2038 + func_module year2038-required func_end_table element="Extra functions based on ANSI C 89" @@ -2781,6 +2782,7 @@ func_all_modules () func_module fts func_module isdir func_module largefile + func_module largefile-required func_module lchmod func_module lchown func_module mkancesdirs diff --git a/doc/largefile.texi b/doc/largefile.texi index 13572b47e5..b5bfa5116a 100644 --- a/doc/largefile.texi +++ b/doc/largefile.texi @@ -1,9 +1,22 @@ @node Large File Support @section Large File Support -The module provides support for files larger than 2 GB, or with device -or inode numbers or timestamps exceeding 32 bits. To this effect, it -ensures that types like @code{off_t} and @code{time_t} are 64-bit when possible, +The Gnulib @samp{largefile-required} module provides support for files +2 GiB and larger, or with device or inode numbers exceeding 32 bits. +To this effect, it ensures that types like @code{off_t} and +@code{ino_t} are 64-bit, at least on the following platforms: glibc, Mac OS X, FreeBSD, NetBSD, OpenBSD, AIX, HP-UX, IRIX, Solaris, Cygwin, mingw, MSVC. + +The Gnulib @samp{largefile} module is similar, except that it gives +@command{configure} an option @samp{--disable-largefile} that +suppresses support for large files. This may be useful if the package +links to other libraries whose user-facing ABIs still require +@code{off_t} or most other file-related types to be 32-bit on your +platform. + +Both modules also add to @command{configure} an option +@code{--enable-year2038}, needed on some platforms to access files +with timestamps past the year 2038. @xref{Avoiding the year 2038 +problem}. diff --git a/doc/posix-headers/time.texi b/doc/posix-headers/time.texi index 5ecebbfdda..a506ec640c 100644 --- a/doc/posix-headers/time.texi +++ b/doc/posix-headers/time.texi @@ -18,14 +18,16 @@ expressions: NetBSD 5.0. @end itemize -Portability problems fixed by the Gnulib module @code{year2038}: +Portability problems fixed by the Gnulib modules +@code{year2038-required} and @code{year-2038}: @itemize @item On some platforms where @code{time_t} defaults to 32-bit but can be changed to 64-bit, functions like @code{stat} can fail with @code{errno == EOVERFLOW} when a 32-bit timestamp is out of range, such as with a file timestamp in the far future or past: -glibc 2.34. +glibc 2.34+ atop 32-bit x86 or ARM Linux. +@xref{Avoiding the year 2038 problem}. @end itemize Portability problems not fixed by Gnulib: @@ -39,6 +41,8 @@ the functions silently return the low-order 32 bits of the correct timestamp. These platforms will be obsolete when 32-bit @code{time_t} rolls around, which will occur in 2038 for the typical case when @code{time_t} is signed. +@xref{Avoiding the year 2038 problem}. + @item On some platforms the @code{tv_nsec} member of @code{struct timespec} is not of type @code{long}, but is of type @code{long long} instead: diff --git a/doc/year2038.texi b/doc/year2038.texi index 213fda235f..d98753101e 100644 --- a/doc/year2038.texi +++ b/doc/year2038.texi @@ -1,25 +1,43 @@ @node Avoiding the year 2038 problem @section Avoiding the year 2038 problem -The ``year 2038 problem'' denotes unpredictable behaviour of programs -that will likely occur in the year 2038, for programs that use a 32-bit -@samp{time_t} type. See @url{https://en.wikipedia.org/wiki/Year_2038_problem} -for details. +The ``year 2038 problem'' denotes unpredictable behaviour that will +likely occur in the year 2038, for programs that use a 32-bit signed +integer @samp{time_t} type that cannot represent timestamps on or +after 2038-01-19 03:14:08 UTC@. See +@url{https://en.wikipedia.org/wiki/Year_2038_problem, Year 2038 +problem} for details. -The Gnulib module @samp{year2038} attempts to avoid this problem, by -ensuring that @code{time_t} is a 64-bit type and by causing -@code{configure} to fail otherwise. +The Gnulib module @samp{year2038-required} fixes this problem, by +making @code{time_t} wide enough to represent timestamps after 2038. +This has no effect on most current systems, which have timestamps that +are already wide enough. However, @samp{year2038-required} arranges +for builds on legacy 32-bit x86 and ARM Linux kernels running glibc +2.34 and later to compile with @samp{_TIME_BITS=64} to get wider +timestamps. On older platforms that do not support timestamps after +the year 2038, @samp{year2038-required} causes @command{configure} to +fail. -The Gnulib module @samp{largefile} also attempts to avoid this problem -when possible, because @samp{largefile} enables the widest -file-related types supported by the system and @code{time_t} is one of -those types. However, @code{largefile} does not cause -@code{configure} to fail when the year 2038 problem is not avoidable. +The Gnulib module @samp{year2038} is like @samp{year2038-required}, +except that it causes @command{configure} to fail only when it appears +that the current system should support post-2038 timestamps but +something prevents that from working. Also, @samp{year2038} gives +@command{configure} a @option{--disable-year2038} option, which +suppresses support for post-2038 timestamps. This may be useful if +the package links to other libraries whose user-facing ABIs still +require @code{time_t} to be 32-bit on your platform. -The Gnulib @samp{largefile} and @samp{year2038} modules are +The Gnulib module @samp{year2038-required} is recommended for any package that might be used after the year 2038 on -32-bit platforms. However, if you build such a package you can -disable its use of 64-bit @code{time_t} by giving the -@code{--disable-year2038} option to @code{configure}. This may be -useful if the package links to other libraries whose user-facing ABIs -still require @code{time_t} to be 32-bit on your platform. +32-bit platforms. However, if your package needs to support +platforms that will not be used after the year 2038, +you can use the @samp{year2038} module instead. + +If the Gnulib module @samp{largefile} is used but neither +@samp{year2038} nor @samp{year2038-required} is used, +@command{configure} will have an option @option{--enable-year2038} +that causes @code{configure} to behave as if @samp{year2038} was used. +This is for packages that have long used @samp{largefile} but have not +gotten around to upgrade their Gnulib module list to include +@samp{year2038-required} or @samp{year2038}. +@xref{Large File Support}. diff --git a/m4/largefile.m4 b/m4/largefile.m4 index b128e24353..4bfff0d076 100644 --- a/m4/largefile.m4 +++ b/m4/largefile.m4 @@ -24,29 +24,9 @@ AC_DEFUN([gl_SET_LARGEFILE_SOURCE], ]]) ) -# Work around a problem in autoconf <= 2.69: -# AC_SYS_LARGEFILE does not configure for large inodes on Mac OS X 10.5, -# or configures them incorrectly in some cases. -m4_version_prereq([2.70], [], [ - -# _AC_SYS_LARGEFILE_TEST_INCLUDES -# ------------------------------- -m4_define([_AC_SYS_LARGEFILE_TEST_INCLUDES], -[#include <sys/types.h> - /* Check that off_t can represent 2**63 - 1 correctly. - We can't simply define LARGE_OFF_T to be 9223372036854775807, - since some C++ compilers masquerading as C compilers - incorrectly reject 9223372036854775807. */ -#define LARGE_OFF_T (((off_t) 1 << 31 << 31) - 1 + ((off_t) 1 << 31 << 31)) - int off_t_is_large[[(LARGE_OFF_T % 2147483629 == 721 - && LARGE_OFF_T % 2147483647 == 1) - ? 1 : -1]];[]dnl -]) -])# m4_version_prereq 2.70 - -# Support AC_SYS_YEAR2038, even if Autoconf 2.71 or earlier. -# This code is taken from Autoconf master. -m4_ifndef([AC_SYS_YEAR2038], [ +m4_ifndef([AC_SYS_LARGEFILE_REQUIRED], [ +# Support AC_SYS_LARGEFILE_REQUIRED and Y2038 macros, even if +# Autoconf 2.71 or earlier. This code is taken from Autoconf master. # _AC_SYS_YEAR2038_TEST_CODE # -------------------------- @@ -118,8 +98,10 @@ AS_CASE([$ac_cv_sys_year2038_opts], ["none needed"], [], ["support not detected"], [ac_have_year2038=no - AS_CASE([$enable_year2038], - [yes], + AS_CASE([$ac_year2038_required,$enable_year2038], + [yes,*], + [AC_MSG_FAILURE([support for timestamps after Jan 2038 is required])], + [*,yes], [# If we're not cross compiling and 'touch' works with a large # timestamp, then we can presume the system supports wider time_t # *somehow* and we just weren't able to detect it. One common @@ -165,19 +147,24 @@ AS_CASE([$ac_cv_sys_year2038_opts], # --enable-year2038, or a --disable-year2038, or no option at all to # the configure script. Note that this is expanded very late and # therefore there cannot be any code in the AC_ARG_ENABLE. The -# default value for enable_year2038 is emitted unconditionally +# default value for 'enable_year2038' is emitted unconditionally # because the generated code always looks at this variable. m4_define([_AC_SYS_YEAR2038_ENABLE], [m4_divert_text([DEFAULTS], + m4_provide_if([AC_SYS_YEAR2038_REQUIRED], + [ac_year2038_required=yes], + [ac_year2038_required=no]))dnl +m4_divert_text([DEFAULTS], m4_provide_if([AC_SYS_YEAR2038], [enable_year2038=yes], [enable_year2038=no]))]dnl +[m4_provide_if([AC_SYS_YEAR2038_REQUIRED], [], [AC_ARG_ENABLE([year2038], m4_provide_if([AC_SYS_YEAR2038], [AS_HELP_STRING([--disable-year2038], - [do not support timestamps after 2038])], + [omit support for dates after Jan 2038])], [AS_HELP_STRING([--enable-year2038], - [support timestamps after 2038])]))]) + [include support for dates after Jan 2038])]))])]) # _AC_SYS_YEAR2038_OPT_IN # ----------------------- @@ -189,7 +176,8 @@ m4_define([_AC_SYS_YEAR2038_ENABLE], # documented macro. AC_DEFUN([_AC_SYS_YEAR2038_OPT_IN], [m4_provide_if([_AC_SYS_YEAR2038_PROBE], [], [dnl - AS_IF([test "$enable_year2038" != no], [_AC_SYS_YEAR2038_PROBE]) + AS_IF([test "$ac_year2038_required,$enable_year2038" != no,no], + [_AC_SYS_YEAR2038_PROBE]) AC_CONFIG_COMMANDS_PRE([_AC_SYS_YEAR2038_ENABLE]) ])]) @@ -199,9 +187,26 @@ AC_DEFUN([_AC_SYS_YEAR2038_OPT_IN], # On systems where time_t is not always 64 bits, this probe can be # skipped by passing the --disable-year2038 option to configure. AC_DEFUN([AC_SYS_YEAR2038], -[AC_REQUIRE([AC_SYS_LARGEFILE])]dnl +[m4_provide_if([AC_SYS_LARGEFILE_REQUIRED], [], + [AC_REQUIRE([AC_SYS_LARGEFILE])])]dnl +[m4_provide_if([_AC_SYS_YEAR2038_PROBE], [], [dnl + AS_IF([test "$ac_year2038_required,$enable_year2038" != no,no], + [_AC_SYS_YEAR2038_PROBE]) + AC_CONFIG_COMMANDS_PRE([_AC_SYS_YEAR2038_ENABLE]) +])]) + +# AC_SYS_YEAR2038_REQUIRED +# ------------------------ +# Same as AC_SYS_YEAR2038, but declares that this program *requires* +# support for large time_t. If we cannot find any way to make time_t +# capable of representing values larger than 2**31 - 1, configure will +# error out. Furthermore, no --enable-year2038 nor --disable-year2038 +# option will be available. +AC_DEFUN([AC_SYS_YEAR2038_REQUIRED], +[m4_provide_if([AC_SYS_LARGEFILE_REQUIRED], [], + [AC_REQUIRE([AC_SYS_LARGEFILE])])]dnl [m4_provide_if([_AC_SYS_YEAR2038_PROBE], [], [dnl - AS_IF([test "$enable_year2038" != no], [_AC_SYS_YEAR2038_PROBE]) + _AC_SYS_YEAR2038_PROBE AC_CONFIG_COMMANDS_PRE([_AC_SYS_YEAR2038_ENABLE]) ])]) @@ -219,6 +224,8 @@ m4_define([_AC_SYS_LARGEFILE_TEST_CODE], && LARGE_OFF_T % 2147483647 == 1) ? 1 : -1]];[]dnl ]) +# Defined by Autoconf 2.71 and circa 2022 Gnulib unwisely depended on it. +m4_define([_AC_SYS_LARGEFILE_TEST_INCLUDES], [_AC_SYS_LARGEFILE_TEST_CODE]) # _AC_SYS_LARGEFILE_OPTIONS # ------------------------- @@ -228,8 +235,8 @@ m4_define([_AC_SYS_LARGEFILE_TEST_CODE], m4_define([_AC_SYS_LARGEFILE_OPTIONS], m4_normalize( ["none needed"] dnl Most current systems ["-D_FILE_OFFSET_BITS=64"] dnl X/Open LFS spec - ["-D_LARGE_FILES=1"] dnl AIX (which versions?) - ["-n32"] dnl Irix 6.2 w/ SGI compiler + ["-D_LARGE_FILES=1"] dnl 32-bit AIX 4.2.1+, 32-bit z/OS + ["-n32"] dnl 32-bit IRIX 6, SGI cc (obsolete) )) # _AC_SYS_LARGEFILE_PROBE @@ -265,7 +272,9 @@ ac_have_largefile=yes AS_CASE([$ac_cv_sys_largefile_opts], ["none needed"], [], ["support not detected"], - [ac_have_largefile=no], + [ac_have_largefile=no + AS_IF([test $ac_largefile_required,$ac_year2038_required != no,no], + [AC_MSG_FAILURE([support for large files is required])])], ["-D_FILE_OFFSET_BITS=64"], [AC_DEFINE([_FILE_OFFSET_BITS], [64], @@ -286,16 +295,25 @@ _AC_SYS_YEAR2038_OPT_IN # _AC_SYS_LARGEFILE_ENABLE # ------------------------ -# Subroutine of AC_SYS_LARGEFILE. Note that this +# Subroutine of AC_SYS_LARGEFILE. If AC_SYS_LARGEFILE_REQUIRED was +# not used at any point in this configure script, add a +# --disable-largefile option to the configure script. Note that this # is expanded very late and therefore there cannot be any code in the -# AC_ARG_ENABLE. The default value for enable_largefile is emitted +# AC_ARG_ENABLE. The default value for 'enable_largefile' is emitted # unconditionally because the generated shell code always looks at # this variable. m4_define([_AC_SYS_LARGEFILE_ENABLE], [m4_divert_text([DEFAULTS], - enable_largefile=yes)]dnl -[AC_ARG_ENABLE([largefile], - [AS_HELP_STRING([--disable-largefile], [omit support for large files])])]) + m4_provide_if([AC_SYS_LARGEFILE_REQUIRED], + [ac_largefile_required=yes], + [ac_largefile_required=no]))dnl +m4_divert_text([DEFAULTS], + [enable_largefile=yes])]dnl +[m4_provide_if([AC_SYS_LARGEFILE_REQUIRED], [], + [m4_provide_if([AC_SYS_YEAR2038_REQUIRED], [], + [AC_ARG_ENABLE([largefile], + [AS_HELP_STRING([--disable-largefile], + [omit support for large files])])])])]) # AC_SYS_LARGEFILE # ---------------- @@ -307,13 +325,29 @@ m4_define([_AC_SYS_LARGEFILE_ENABLE], # to have a 64-bit inode number cannot be accessed by 32-bit applications on # Linux x86/x86_64. This can occur with file systems such as XFS and NFS. # This macro allows configuration to continue if the system doesn't support -# large files. +# large files; see also AC_SYS_LARGEFILE_REQUIRED. AC_DEFUN([AC_SYS_LARGEFILE], [m4_provide_if([_AC_SYS_LARGEFILE_PROBE], [], [dnl - AS_IF([test "$enable_largefile" != no], [_AC_SYS_LARGEFILE_PROBE]) + AS_IF([test "$ac_largefile_required,$enable_largefile,$ac_year2038_required" != no,no,no], + [_AC_SYS_LARGEFILE_PROBE]) + AC_CONFIG_COMMANDS_PRE([_AC_SYS_LARGEFILE_ENABLE]) +])]) + +# AC_SYS_LARGEFILE_REQUIRED +# ------------------------- +# Same as AC_SYS_LARGEFILE, but declares that this program *requires* +# support for large files. If we cannot find a combination of compiler +# options and #defines that makes 'off_t' capable of representing 2**63 - 1, +# 'configure' will error out. Furthermore, 'configure' will not offer a +# --disable-largefile command line option. +# If both AC_SYS_LARGEFILE and AC_SYS_LARGEFILE_REQUIRED are used in the +# same configure script -- in either order -- AC_SYS_LARGEFILE_REQUIRED wins. +AC_DEFUN([AC_SYS_LARGEFILE_REQUIRED], +[m4_provide_if([_AC_SYS_LARGEFILE_PROBE], [], [dnl + _AC_SYS_LARGEFILE_PROBE AC_CONFIG_COMMANDS_PRE([_AC_SYS_LARGEFILE_ENABLE]) ])]) -])# m4_ifndef AC_SYS_YEAR2038 +])# m4_ifndef AC_SYS_LARGEFILE_REQUIRED # Enable large files on systems where this is implemented by Gnulib, not by the # system headers. diff --git a/modules/largefile-required b/modules/largefile-required new file mode 100644 index 0000000000..eea5ecf4fc --- /dev/null +++ b/modules/largefile-required @@ -0,0 +1,28 @@ +Description: +Require support for files 2 GiB and larger. + +Comment: +This module should not be used as a dependency from a test module, +otherwise when this module occurs as a tests-related module, it will +have side effects on the compilation of the main modules in lib/. + +Files: +m4/largefile.m4 + +Depends-on: +largefile + +configure.ac: +AC_REQUIRE([AC_SYS_LARGEFILE_REQUIRED]) + +configure.ac: + +Makefile.am: + +Include: + +License: +LGPLv2+ + +Maintainer: +all diff --git a/modules/year2038-required b/modules/year2038-required new file mode 100644 index 0000000000..29dd556410 --- /dev/null +++ b/modules/year2038-required @@ -0,0 +1,26 @@ +Description: +Ensure that 'time_t' can go past the year 2038. + +Comment: +This module should not be used as a dependency from a test module, +otherwise when this module occurs as a tests-related module, it will +have side effects on the compilation of the main modules in lib/. + +Files: +m4/largefile.m4 + +Depends-on: +largefile-required + +configure.ac-early: +AC_REQUIRE([AC_SYS_YEAR2038_REQUIRED]) + +Makefile.am: + +Include: + +License: +LGPLv2+ + +Maintainer: +all -- 2.37.2