MISC-TN-033: How to cope with Y2038 problem

From DAVE Developer's Wiki
Jump to: navigation, search
Info Box


History
Issue Date Notes
2025/03/28 First release


Introduction[edit | edit source]

The Y2038 problem is a time computing problem on Linux types of equipment that renders them unable to represent times after 03:14:07 UTC on 19 January 2038.

The problem exists in systems that measure Unix time in the number of seconds elapsed since the Unix epoch (00:00:00 UTC on 1 January 1970) and store it in a signed 32-bit integer.

One of the possible solutions is to add support for using 64-bit time_t on 32-bit platforms with appropriate Linux versions. To fix this issue at user space level, the solution is a combination of build options and applications source code modifications, including Makefile.


200px-Emblem-important.svg.png

In any case softwares that use time_t may potentially have Y2038 issues. Y2038 issues may still exist in applications, device drivers, databases, storage systems, and network protocols. Every software layer should take care of time management and proper application re-compile should be taken into account

DAVE BSPs[edit | edit source]

As an example, this Technical Note shows how the forthcoming DESK-MX6-L-6.0.0/DESK-MX6UL-L-6.0.0 and DESK-XZ7-L-2.0.0 BSPs will be compliant against the Y2038 issue.

Even if the native 64-bit support, aarch64 processor's BSP may suffer this issue, but nativelly DESK-MX8M-L BSPs are already compliant with Y2038 support.

Linux kernel[edit | edit source]

Starting from kernel version 5.6 the Year 2038 fix for 32-bit systems has been introduced.

GLIBC[edit | edit source]

The GNU C Library since version 2.34 (released August 2021) added support for using 64-bit time_t on 32-bit platforms with appropriate Linux versions.

Yocto[edit | edit source]

Yocto Nanbield 4.3 reports the capability to:

..this allows 64-bit time support even on 32-bit platforms and resolves Y2038 issues.

Buildroot[edit | edit source]

Even if less popular than Yocto, for smaller system (without GPU or other hardware cell) Buildroot introduced the compatibility with Y2038:

With glibc, 64-bit time_t on 32-bit architectures is enabled by the Buildroot option BR2_TIME_BITS_64. With this option enabled, systems using glibc on 32-bit platforms are Y2038 compatible

since release 2023.11

Userspace application[edit | edit source]

Below is a simple program that allows to test the behaviour using a time_t 32-bit size and the new 64-bit structure:

// Code based on https://www.blaess.fr/christophe/2038/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main(void)
{
	time_t now;
	struct tm *tm_now;
	char line[1024];

	printf("sizeof(int): %d\n",sizeof(int));
	printf("sizeof(long long int): %d\n",sizeof(long long int));
	printf("sizeof(time_t): %d\n",sizeof(time_t));

	time(&now);
	tm_now = gmtime(&now);
	strftime(line, 1023, "%x %X", tm_now);
	printf("%s\n", line);

	return 0;
}

userspace application build[edit | edit source]

A standard build used to produce the ELF executable file is the following one:

$CC get_date.c -o get_date_32b

while the 64-bit has to be generated with the correct compiler defines:

$CC -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64 get_date.c -o get_date_64b

Y2038 distro support[edit | edit source]

For the sake of convenience, the forthcoming releases for DAVE BSPs are used :

  • DESK-MX6-L-6.0.0 and DESK-MX6UL-L-6.0.0 BSPs version
  • DESK-XZ7-L-2.0.0 BSP version

These BSPs have not been released, but they are planned for 2025.

Test Yocto distro on a real system[edit | edit source]

The Yocto BSP will use:

  • kernel version 6.6.52
  • glibc version 2.39
  • Yocto build system Scarthgap

sub-systems versions[edit | edit source]

  • Yocto
NXP i.MX Release Distro 6.6-scarthgap desk-mx6 ttymxc2

desk-mx6 login:
  • kernel
root@desk-mx6:~# uname -a
Linux desk-mx6 6.6.52-lts-next-ge0f9e2afd4cf #1 SMP PREEMPT Tue Nov 19 23:01:49 UTC 2024 armv7l GNU/Linux
root@desk-mx6:~# 
  • glibc
root@desk-mx6:~# ldd --version
ldd (GNU libc) 2.39
...
root@desk-mx6:~# 

get_date[edit | edit source]

  • set date after 19 January 2038
root@desk-mx6:~# date 032510272038
Thu Mar 25 10:27:00 UTC 2038
root@desk-mx6:~#
  • get_date at 32-bit timer resolution
root@desk-mx6:~# ./get_date_32b
sizeof(int): 4
sizeof(long long int): 8
sizeof(time_t): 4
01/01/70 00:30:48
root@desk-mx6:~# 
  • get_date at 64-bit timer resolution
root@desk-mx6:~# ./get_date_64b
sizeof(int): 4
sizeof(long long int): 8
sizeof(time_t): 8
03/25/38 10:27:51
root@desk-mx6:~# 

Test Petalinux distro on a real system[edit | edit source]

The Petalinux BSP will use:

  • kernel version 6.6.40
  • glibc version 2.39
  • Yocto build system Scarthgap

sub-systems versions[edit | edit source]

  • Petalinux 2024.2
PetaLinux 2024.2+release-S11061705 boralite ttyPS0

boralite login:
  • kernel
root@boralite:~# uname -a
Linux boralite 6.6.40-xilinx-g2b7f6f70a62a #1 SMP PREEMPT Tue Oct 29 11:52:30 UTC 2024 armv7l GNU/Linux
root@boralite:~# 
  • glibc
root@boralite:~# /lib/libc.so.6
GNU C Library (GNU libc) stable release version 2.39.
...
root@boralite:~# 

get_date[edit | edit source]

  • set date after 19 January 2038
root@boralite:~# date 032716522038
Sat Mar 27 16:52:00 UTC 2038
root@boralite:~# date
Sat Mar 27 16:52:02 UTC 2038
root@boralite:~#
  • get_date at 32-bit timer resolution
root@boralite:~# ./get_date_32b
sizeof(int): 4
sizeof(long long int): 8
sizeof(time_t): 4
01/01/70 00:30:48
root@boralite:~#
  • get_date at 64-bit timer resolution
root@boralite:~# ./get_date_64b
sizeof(int): 4
sizeof(long long int): 8
sizeof(time_t): 8
03/27/38 16:52:13
root@boralite:~#

Test Buildroot distro on a real system[edit | edit source]

The Buildroot test system uses:

  • kernel version 5.15.71
  • glibc version 2.40
  • Buildroot version 2024.11

sub-systems versions[edit | edit source]

  • Buildroot 2024.11
Welcome to Buildroot 2024.11!
buildroot login:
  • kernel
root@axelulite:~# uname -a
Linux axelulite 5.15.71-desk-mx6ul-l-4.0.0-00003-g284f37067f6d-dirty #13 SMP PREEMPT Wed Apr 10 12:14:49 CEST 2024 armv7l GNU/Linux
root@axelulite:~# 
  • glibc
root@axelulite:~# /lib/libc.so.6
GNU C Library (Buildroot) stable release version 2.40.
...
root@axelulite:~# 

get_date[edit | edit source]

  • set date after 19 January 2038
root@axelulite:~# date
Wed Mar 24 12:49:30 UTC 2038
root@axelulite:~# 
  • get_date at 32-bit timer resolution
root@axelulite:~# ./get_date_32b
sizeof(int): 4
sizeof(long long int): 8
sizeof(time_t): 4
04/03/33 08:45:28
root@axelulite:~# 
  • get_date at 64-bit timer resolution
root@axelulite:~# ./get_date_64b
sizeof(int): 4
sizeof(long long int): 8
sizeof(time_t): 8
03/24/38 12:49:36
root@axelulite:~#


Conclusion[edit | edit source]

200px-Emblem-important.svg.png

The Y2038 issue can be overcome for the 32-bit Linux Embedded systems with the appropriate fixes at every software stack level