Bug 103886

Summary: Use 64-bit time_t on 32-bit glibc targets
Product: gcc Reporter: Janne Blomqvist <jb>
Component: libfortranAssignee: Not yet assigned to anyone <unassigned>
Status: NEW ---    
Severity: enhancement CC: rguenth, sjames
Priority: P3    
Version: 16.0   
Target Milestone: ---   
See Also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114895
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120832
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114065
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2025-06-26 00:00:00

Description Janne Blomqvist 2022-01-01 19:24:53 UTC
In order to solve the Y2038 problem glibc now supports 64-bit time_t on 32-bit platforms. As this is an ABI change, it has to be explicitly enabled through setting the _TIME_BITS=64 preprocessor macro (similar to _FILE_OFFSET_BITS=64 to enable support for files larger than 2 GB).

See https://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html and https://sourceware.org/glibc/wiki/Y2038ProofnessDesign

I don't think any time_t (or structs containing time_t members) are part of the libgfortran ABI, so this should be an internal change not requiring any ABI bumping.

Some other 32-bit targets already have 64-bit time_t; At least NetBSD, OpenBSD and Linux with musl libc 1.2+, https://musl.libc.org/time64.html .
Comment 1 Drea Pinski 2022-01-01 22:50:08 UTC
Is there anything to be done as the time_t is now defaults to 64bit on the trunk of glibc?
Comment 2 Janne Blomqvist 2022-01-01 23:05:32 UTC
(In reply to Andrew Pinski from comment #1)
> Is there anything to be done as the time_t is now defaults to 64bit on the
> trunk of glibc?

AFAIU it's not the default, you need to explicitly opt-in by setting the _TIME_BITS preprocessor macro to 64 (64-bit time_t is the default on musl, and {Net,Open}BSD ).

Or are you saying that since the _TIME_BITS thing was introduced (with glibc 2.34), the upcoming 2.35/trunk has changed the default?
Comment 3 Drea Pinski 2022-01-01 23:08:50 UTC
(In reply to Janne Blomqvist from comment #2)
> (In reply to Andrew Pinski from comment #1)
> > Is there anything to be done as the time_t is now defaults to 64bit on the
> > trunk of glibc?
> 
> AFAIU it's not the default, you need to explicitly opt-in by setting the
> _TIME_BITS preprocessor macro to 64 (64-bit time_t is the default on musl,
> and {Net,Open}BSD ).
> 
> Or are you saying that since the _TIME_BITS thing was introduced (with glibc
> 2.34), the upcoming 2.35/trunk has changed the default?

Yes, the upcoming 2.35 has changed the default:
https://sourceware.org/pipermail/libc-alpha/2021-December/134576.html

Sorry I was not clear about that.
Comment 4 Janne Blomqvist 2022-01-01 23:31:33 UTC
(In reply to Andrew Pinski from comment #3)
> (In reply to Janne Blomqvist from comment #2)
> > (In reply to Andrew Pinski from comment #1)
> > > Is there anything to be done as the time_t is now defaults to 64bit on the
> > > trunk of glibc?
> > 
> > AFAIU it's not the default, you need to explicitly opt-in by setting the
> > _TIME_BITS preprocessor macro to 64 (64-bit time_t is the default on musl,
> > and {Net,Open}BSD ).
> > 
> > Or are you saying that since the _TIME_BITS thing was introduced (with glibc
> > 2.34), the upcoming 2.35/trunk has changed the default?
> 
> Yes, the upcoming 2.35 has changed the default:
> https://sourceware.org/pipermail/libc-alpha/2021-December/134576.html

I'm not super-familiar with glibc, but it seems that this changes the default (in ./bits/timesize.h) to 64 for targets not overriding it, however it adds/modifies a number of target-specific overrides to retain the previous behavior? In particular for x86 there is ./sysdeps/unix/sysv/linux/x86/bits/timesize.h which says:

#if defined __x86_64__ && defined __ILP32__
/* For x32, time is 64-bit even though word size is 32-bit.  */
# define __TIMESIZE	64
#else
/* For others, time size is word size.  */
# define __TIMESIZE	__WORDSIZE
#endif


If my reading of the above is correct, on 32-bit x86 __TIMESIZE is set to __WORDSIZE, that is, 32.

Similarly for ./sysdeps/unix/sysv/linux/arm/bits/timesize.h it says

#define __TIMESIZE	32
Comment 5 jsm-csl@polyomino.org.uk 2022-01-04 20:50:38 UTC
On Sat, 1 Jan 2022, jb at gcc dot gnu.org via Gcc-bugs wrote:

> I'm not super-familiar with glibc, but it seems that this changes the default
> (in ./bits/timesize.h) to 64 for targets not overriding it, however it
> adds/modifies a number of target-specific overrides to retain the previous
> behavior?

Exactly.  "Default" here means "default for architectures that don't 
provide their own bits/timesize.h header"; there is no change to the 
default for any existing architecture.  It was already required that new 
glibc ports must use 64-bit time_t; the effect of this change is that new 
glibc ports to 32-bit architectures no longer need to have a 
bits/timesize.h header of their own (in general, we want the defaults to 
be such that new ports need as few sysdeps files as possible).
Comment 6 Richard Biener 2025-06-26 07:24:15 UTC
Confirmed.
Comment 7 Richard Biener 2026-02-27 13:42:46 UTC
autoconf 2.71 has AC_SYS_LARGEFILE support for 64bit time_t where we'd need to
add AC_SYS_YEAR2038 to flip a default (otherwise it's conditional on a --configure option).

This means we'll have to update from 2.69 to at least 2.71.