Skip to contentSkip to conversation

tools/nolibc: make time_t robust if __kernel_old_time_t is missing in host headers

PATCH Superseded Zhouyi Zhou 2 participants 2 messages Sep 18, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/nolibc: make time_t robust if __kernel_old_time_t is missing in host headers

Commit
d5094bcb5bfd ("tools/nolibc: define time_t in terms of __kernel_old_time_t") made nolibc use the kernel's time type so that time_t matches timespec::tv_sec on all ABIs (notably x32).

Some distributions (e.g. Ubuntu 20.04 on ppc64le with older exported headers under /usr/include) do not expose __kernel_old_time_t, causing nolibc builds that rely on host headers to fail (I discovered this when doing RCU torture test in PPC VM of Open Source Lab of Oregon State University).

Keep the new behavior, but add a small compatibility shim:
if __kernel_old_time_t is not available, fall back to
signed long

This preserves the intent of d5094bcb5bfd while letting nolibc build on systems with older exported headers.

Fixes d5094bcb5bfd ("tools/nolibc: define time_t in terms of __kernel_old_time_t")
---
 tools/include/nolibc/std.h | 4 ++++
 1 file changed, 4 insertions(+)
tools/include/nolibc/std.h +4 -0
index ba950f0e7338..ea225a0b16e9 100644
@@ -29,6 +29,10 @@ typedef unsigned long       nlink_t;
 typedef   signed long         off_t;
 typedef   signed long     blksize_t;
 typedef   signed long      blkcnt_t;
+#ifndef __kernel_old_time_t
+typedef   signed long        time_t;
+#else
 typedef __kernel_old_time_t  time_t;
+#endif
 
 #endif /* _NOLIBC_STD_H */
Signature · 1 line
2.25.1
#1 lore raw

Hi Zhouyi,

thanks for your report and patch!

Quoted 4 lines · Zhouyi Zhou

Commit
d5094bcb5bfd ("tools/nolibc: define time_t in terms of __kernel_old_time_t") made nolibc use the kernel's time type so that time_t matches timespec::tv_sec on all ABIs (notably x32).

FYI you don't need to keep the referenced commit message on a single line and should reflow it like regular text:

Commit d5094bcb5bfd ("tools/nolibc: define time_t in terms of __kernel_old_time_t") made nolibc use the kernel's time type so that time_t matches timespec::tv_sec on all ABIs (notably x32).

(Source: I did the same thing as you until Linus told me to stop)

Quoted 5 lines

Some distributions (e.g. Ubuntu 20.04 on ppc64le with older exported headers under /usr/include) do not expose __kernel_old_time_t, causing nolibc builds that rely on host headers to fail (I discovered this when doing RCU torture test in PPC VM of Open Source Lab of Oregon State University).

Instead of mentioning Ubuntu 20.04, just explain that __kernel_old_time_t is fairly new, notably from 2020 in commit 94c467ddb273 ("y2038: add __kernel_old_timespec and __kernel_old_time_t")

Quoted 18 lines

Keep the new behavior, but add a small compatibility shim:
if __kernel_old_time_t is not available, fall back to
signed long

This preserves the intent of d5094bcb5bfd while letting nolibc build on systems with older exported headers.

Fixes d5094bcb5bfd ("tools/nolibc: define time_t in terms of __kernel_old_time_t")
---
 tools/include/nolibc/std.h | 4 ++++
 1 file changed, 4 insertions(+)
tools/include/nolibc/std.h +0 -0
index ba950f0e7338..ea225a0b16e9 100644

tools/include/nolibc/std.h typedef unsigned long nlink_t; · line 36

Quoted 8 lines
tools/include/nolibc/std.h +4 -0
@@ -29,6 +29,10 @@ typedef unsigned long       nlink_t;
 typedef   signed long         off_t;
 typedef   signed long     blksize_t;
 typedef   signed long      blkcnt_t;
+#ifndef __kernel_old_time_t
+typedef   signed long        time_t;
+#else
 typedef __kernel_old_time_t  time_t;
+#endif

I don't think this works as __kernel_old_time_t is never defined. Instead we could switch to __kernel_time_t, which is the same as __kernel_old_time_t and has existed for longer.

tools/include/nolibc/std.h typedef unsigned long nlink_t; · line 38

Quoted 2 lines
tools/include/nolibc/std.h +0 -0
 #endif /* _NOLIBC_STD_H */

Thomas