Koan Y2038
Time management on 32bit Linux machines has always been done with signed 32bit type.
These type present a problem that in 2038 the 32bit space will run out and the time count will return to 13/12/1901 (see Y2038 problem).
For this reason, 64bit time management was introduced starting from kernel 5.1.
Obviously this also required changes at the user space level in glibc, to add support for the new 64bit variables and functions.
Starting from glibc 2.32 and from kernel 5.6 the 64bit time management has taken its definitive aspect.
In detail, in versions >= 2.32 the glibc declares the new data type `__time64_t` and defines a new set of functions named __FNNAME64 (e.g.__clock_gettime64),
in addition to the time_t type and the functions already present to operate on time.
Now the glibc can be configured in two different ways, via the define __TIMESIZE:
– if the define is 32, the glibc is configured in dual-time mode, therefore in this case time_t and related functions work using 32bit and __time64_t and related functions work using 64bit.
– if the define is 64, the glibc is configured in single-time mode, therefore both the time_t and __time64_t types (and related functions) work only using 64bit.
Usually on 32bit systems the library is compiled with __TIMESIZE == 32, while on 64bit systems it is compiled with __TIMESIZE == 64.
For further information see here.
When glibc is built in dual-time mode, you can obtain for a specific source code the definition of time_t (and related functions) using 64bit by setting the _TIME_BITS flag to 64 during the compilation.
In this case it is also necessary to pass the _FILE_OFFSET_BITS flag with a 64bit value:

-D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64

for further information see here.
A simple test code to check the actual configuration of a system is:

int main () {
  printf("__TIMESIZE value is: %d\n", __TIMESIZE);
  printf("time_t size is: %d bit\n", sizeof(time_t) *8);
  printf("__time64_t size is: %d bit\n", sizeof(__time64_t) *8);
  return 0;
}

A simple test code to check the actual configuration of a system is:

On a system with __TIMESIZE == 32 the output will be:


__TIMESIZE value is: 32
time_t size is: 32 bits
__time64_t size is: 64 bit

Compiling the code with -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64 will give:


__TIMESIZE value is: 32
time_t size is: 64 bit
__time64_t size is: 64 bit

Conclusion

The Y2038 issue is is important but not yet a big problem but would be a wise idea to start planning, triaging, and testing before it becomes urgent.

Share this post: