Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

64-bit time_t in Linux Kernel

I have compiled kernel 3.19.1 but still have a problem with time_t. Just a simple program with cout << sizeof (time_t); gives size of 4 bytes, not 8 bytes as was my intention.

Should I switch on a particular option during make menuconfig?

like image 701
user2425502 Avatar asked Sep 22 '26 13:09

user2425502


1 Answers

64-bit time support on 32-bit Linux was first introduced in the 5.1 kernel so if you're older than that, sorry. Because changing the return type of the old system calls breaks old applications, new *time64 syscalls had to be added instead. Check this table and you'll see that those syscalls are only available on 32-bit platforms.

Now if you're writing code for 32-bit systems you can call clock_gettime64 directly (from inline assembly, or from C with syscall() function) to get the current time. However after that you're completely on your own. For full userspace support you must be on Linux 5.6 or higher along with musl 1.2+ or glibc 2.32+. Just rebuild your code and time_t will become 64-bit long

  • All user space must be compiled with a 64-bit time_t, which will be supported in the coming musl-1.2 and glibc-2.32 releases, along with installed kernel headers from linux-5.6 or higher.

  • Applications that use the system call interfaces directly need to be ported to use the time64 syscalls added in linux-5.1 in place of the existing system calls. This impacts most users of futex() and seccomp() as well as programming languages that have their own runtime environment not based on libc.

https://lkml.org/lkml/2020/1/29/355?anz=web

For more information read

  • Approaching the kernel year-2038 end game
  • Discussion on how to solve Y2038 problem: 2038 is closer than it seems
  • 64-bit time symbol handling in the GNU C Library
  • glibc Y2038 Proofness Design
  • Change time_t and clock_t to 64 bit
like image 166
phuclv Avatar answered Sep 26 '26 11:09

phuclv