| Summary: | [Y2038] Build failure with !HAVE_WORKING_STAT | ||
|---|---|---|---|
| Product: | gcc | Reporter: | Richard Biener <rguenth> |
| Component: | libfortran | Assignee: | Not yet assigned to anyone <unassigned> |
| Status: | UNCONFIRMED --- | ||
| Severity: | normal | CC: | jakub, sjames |
| Priority: | P3 | Keywords: | build |
| Version: | 14.0 | ||
| Target Milestone: | --- | ||
| See Also: |
https://bugzilla.suse.com/show_bug.cgi?id=1223169 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103886 |
||
| Host: | Target: | ||
| Build: | Known to work: | ||
| Known to fail: | 14.3.0, 15.1.1 | Last reconfirmed: | 2025-06-20 00:00:00 |
| Attachments: | conftest.c | ||
|
Description
Richard Biener
2024-04-30 06:54:31 UTC
So since this is for the 32bit multilib and the test below doens't seem to
enforce LFS we get a large inode number in the build setup and fail the
stat(), mis-detecting the feature.
libgfortran configure.ac misses AC_SYS_LARGEFILE it seems.
dnl Check whether the st_ino and st_dev stat fields taken together uniquely
dnl identify the file within the system. This is should be true for POSIX
dnl systems; it is known to be false on mingw32.
AC_DEFUN([LIBGFOR_CHECK_WORKING_STAT], [
AC_CACHE_CHECK([whether the target stat is reliable],
libgfor_cv_have_working_stat, [
AC_RUN_IFELSE([AC_LANG_SOURCE([[
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
int main ()
{
FILE *f, *g;
struct stat st1, st2;
f = fopen ("foo", "w");
g = fopen ("bar", "w");
if (stat ("foo", &st1) != 0 || stat ("bar", &st2))
return 1;
if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino)
return 1;
fclose(f);
fclose(g);
return 0;
}]])], libgfor_cv_have_working_stat=yes, libgfor_cv_have_working_stat=no, [
case "${target}" in
*mingw*) libgfor_cv_have_working_stat=no ;;
*) libgfor_cv_have_working_stat=yes;;
esac])])
if test x"$libgfor_cv_have_working_stat" = xyes; then
AC_DEFINE(HAVE_WORKING_STAT, 1, [Define if target has a reliable stat.])
fi])
Hmm, no, that's there. The logfile shows [31010s] checking for special C compiler options needed for large files... no [31010s] checking for _FILE_OFFSET_BITS value needed for large files... 64 ... [31035s] checking whether the target stat is reliable... no so the individual test has to use -D_FILE_OFFSET_BITS=64? That is really weird.
Because the
checking for _FILE_OFFSET_BITS value needed for large files... 64
test should add
#define _FILE_OFFSET_BITS 64
line to confdefs.h and I believe the working stat testing should use that:
if test "$cross_compiling" = yes; then :
case "${target}" in
*mingw*) libgfor_cv_have_working_stat=no ;;
*) libgfor_cv_have_working_stat=yes;;
esac
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
int main ()
{
FILE *f, *g;
struct stat st1, st2;
f = fopen ("foo", "w");
g = fopen ("bar", "w");
if (stat ("foo", &st1) != 0 || stat ("bar", &st2))
return 1;
if (st1.st_dev == st2.st_dev && st1.st_ino == st2.st_ino)
return 1;
fclose(f);
fclose(g);
return 0;
}
_ACEOF
The cat should source in all of confdefs.h so far.
Created attachment 58075 [details]
conftest.c
I've hacked up my libgfortran/configure, added there sleep 60s after writing conftest.c for working stat check, and then rm -f config.cache; ./config.status --recheck in the x86*/32/libgfortran directory and the above conftest.c is what I saw. So besides maybe no way to reproduce the failure the source still has the issue described. (In reply to Richard Biener from comment #7) > So besides maybe no way to reproduce the failure the source still has the > issue > described. Sorry, not following -- jakub's attached one has #define _FILE_OFFSET_BITS 64, so we should be fine? (In reply to Sam James from comment #8) > (In reply to Richard Biener from comment #7) > > So besides maybe no way to reproduce the failure the source still has the > > issue > > described. > > Sorry, not following -- jakub's attached one has #define _FILE_OFFSET_BITS > 64, so we should be fine? Iff !HAVE_WORKING_STAT (for whatever reason) but also !defined(__MINGW32__) then the source will fail to build. It looks like the key is !HAVE_WORKING_STAT, not sure why defined(__MINGW32__) is checked here. Ah, sorry, you meant GCC sources, not configure test source. ack So the trigger is Y2038, aka missing -D_TIME_BITS=64 - reproducible in a qemu environment with -rtc base=2038-01-20T00:00:00 Re-confirmed with GCC 15. The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>: https://gcc.gnu.org/g:c91a6b8ec7cedb8949675c6855f2f35cfe4100e5 commit r17-5917-gc91a6b8ec7cedb8949675c6855f2f35cfe4100e5 Author: Richard Biener <rguenther@suse.de> Date: Sat Oct 31 15:52:47 2026 +0100 libgfortran/103886 - enable 64-bit time_t on 32-bit glibc targets PR114895 reports that on 32-bit glibc targets with 32-bit time_t, stat() fails with EOVERFLOW once file timestamps are past 2038-01-19. The LIBGFOR_CHECK_WORKING_STAT configure test then fails, HAVE_WORKING_STAT is left undefined, and the build of io/unix.c breaks, since the !HAVE_WORKING_STAT code path there is only usable on MinGW. This can be reproduced e.g. by building the 32-bit multilib in a VM whose clock is set past 2038. Fix this by building libgfortran with 64-bit time_t where the C library supports it as requested by PR103886. A new LIBGFOR_CHECK_TIME_BITS64 check, run right after AC_SYS_LARGEFILE, tests whether time_t is already 64 bits wide and, if not, whether defining _TIME_BITS to 64 makes it so; in that case _TIME_BITS is defined to 64 in config.h. glibc only accepts _TIME_BITS=64 together with _FILE_OFFSET_BITS=64, so the check relies on the _FILE_OFFSET_BITS setting from AC_SYS_LARGEFILE and does nothing when configured with --disable-largefile. No exported libgfortran interface uses time_t, struct stat or other time-related C types; the time_t uses are all in internal helpers, so the library ABI does not change. Note that intrinsics returning or taking default-kind INTEGER values (e.g. TIME, or STAT with an INTEGER(4) array) still truncate to 32 bits; this change only makes the internal handling and the 64-bit variants correct past 2038. PR libfortran/103886 PR libfortran/114895 libgfortran/ * acinclude.m4 (LIBGFOR_CHECK_TIME_BITS64): New check for 64-bit time_t support. * configure.ac: Invoke LIBGFOR_CHECK_TIME_BITS64. * configure: Regenerate. * config.h.in: Regenerate. The failure condition remains but the issue on glibc targets after Y2038 has been mitigated by using 64bit time_t. With explicitly disabling large-file support it can be still reproduced. |