Skip to contentSkip to conversation

package/Makefile.in: year2038 makes time_t 64-bit for glibc toolchains

PATCH In review Romain Naour 3 participants 6 messages Feb 25, 2022 – Mar 8, 2022 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 package/Makefile.in: year2038 makes time_t 64-bit for glibc toolchains

To use time_t 64-bit for glibc >= 2.34 toolchains we have to set both _FILE_OFFSET_BITS=64 and _TIME_BITS=64 for glibc toolchains. Buildroot already define _FILE_OFFSET_BITS=64 since 2008 [1] before the first release tag 2009.02.

_TIME_BITS is not needed for musl libc since it already year2038 ready [2].

The uclibc-ng libc only support time_t 32-bit (long int) so it will be affected by the year2038 issue [3].

Fixes (in French, chapter Buildroot 2022 and GlibC):
https://www.blaess.fr/christophe/2038

Runtime tested with qemu_arm_vexpress_defconfig and the Bootlin glibc bleeding-edge 2021.11-1 toolchain.

Before:

 # date
 Tue Jan 19 03:14:07 UTC 2038
 # date
 Thu Jan  1 00:00:00 UTC 1970

After:

 # date
 Tue Jan 19 03:14:07 UTC 2038
 # date
 Tue Jan 19 03:14:08 UTC 2038
 # date
 Tue Jan 19 03:14:09 UTC 2038

[1] 60b5eee76edfa153ef118d2788c74ac8da1497a0
[2] https://git.musl-libc.org/cgit/musl/tree/include/alltypes.h.in?h=v1.2.2#n3
[3] https://cgit.uclibc-ng.org/cgi/cgit/uclibc-ng.git/tree/include/time.h?h=v1.0.40#n75

    https://cgit.uclibc-ng.org/cgi/cgit/uclibc-ng.git/tree/libc/sysdeps/linux/common/bits/types.h?h=v1.0.40#n106
Cc Christophe Blaess <[email protected]>
---
 package/Makefile.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
package/Makefile.in +1 -1
index 508ea7c366..cde050ca82 100644
@@ -167,7 +167,7 @@ else ifeq ($(BR2_FORTIFY_SOURCE_2),y)
 TARGET_HARDENED += -D_FORTIFY_SOURCE=2
 endif
 
-TARGET_CPPFLAGS += -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
+TARGET_CPPFLAGS += -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64
 TARGET_CFLAGS = $(TARGET_CPPFLAGS) $(TARGET_ABI) $(TARGET_OPTIMIZATION) $(TARGET_DEBUGGING) $(TARGET_HARDENED)
 TARGET_CXXFLAGS = $(TARGET_CFLAGS)
 TARGET_FCFLAGS = $(TARGET_ABI) $(TARGET_OPTIMIZATION) $(TARGET_DEBUGGING)
Signature · 6 lines
2.35.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw
Quoted 25 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Romain" == Romain Naour <[email protected]> writes:

To use time_t 64-bit for glibc >= 2.34 toolchains we have to set both _FILE_OFFSET_BITS=64 and _TIME_BITS=64 for glibc toolchains. Buildroot already define _FILE_OFFSET_BITS=64 since 2008 [1] before the first release tag 2009.02.

_TIME_BITS is not needed for musl libc since it already year2038 ready [2].

The uclibc-ng libc only support time_t 32-bit (long int) so it will be affected by the year2038 issue [3].

Fixes (in French, chapter Buildroot 2022 and GlibC):
https://www.blaess.fr/christophe/2038

Runtime tested with qemu_arm_vexpress_defconfig and the Bootlin glibc bleeding-edge 2021.11-1 toolchain.

Before:

 # date
 Tue Jan 19 03:14:07 UTC 2038
 # date
 Thu Jan  1 00:00:00 UTC 1970
Quoted 7 lines

After:

 # date
 Tue Jan 19 03:14:07 UTC 2038
 # date
 Tue Jan 19 03:14:08 UTC 2038
 # date
 Tue Jan 19 03:14:09 UTC 2038

Ahh, good catch. Maybe something to add a runtime test for?

Committed, thanks.

Quoted 32 lines

[1] 60b5eee76edfa153ef118d2788c74ac8da1497a0
[2] https://git.musl-libc.org/cgit/musl/tree/include/alltypes.h.in?h=v1.2.2#n3
[3] https://cgit.uclibc-ng.org/cgi/cgit/uclibc-ng.git/tree/include/time.h?h=v1.0.40#n75

    https://cgit.uclibc-ng.org/cgi/cgit/uclibc-ng.git/tree/libc/sysdeps/linux/common/bits/types.h?h=v1.0.40#n106
Cc Christophe Blaess <[email protected]>
---
 package/Makefile.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
package/Makefile.in +1 -1
index 508ea7c366..cde050ca82 100644
@@ -167,7 +167,7 @@ else ifeq ($(BR2_FORTIFY_SOURCE_2),y)
 TARGET_HARDENED += -D_FORTIFY_SOURCE=2
 endif
 
-TARGET_CPPFLAGS += -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
+TARGET_CPPFLAGS += -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64
 TARGET_CFLAGS = $(TARGET_CPPFLAGS) $(TARGET_ABI) $(TARGET_OPTIMIZATION) $(TARGET_DEBUGGING) $(TARGET_HARDENED)
 TARGET_CXXFLAGS = $(TARGET_CFLAGS)
 TARGET_FCFLAGS = $(TARGET_ABI) $(TARGET_OPTIMIZATION) $(TARGET_DEBUGGING)
Signature · 6 lines
2.35.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
Signature · 5 lines
Bye, Peter Korsgaard
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#2 lore raw

Hello Peter,

Le 07/03/2022 à 20:54, Peter Korsgaard a écrit :

Quoted 33 lines
Quoted 25 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Romain" == Romain Naour <[email protected]> writes:

To use time_t 64-bit for glibc >= 2.34 toolchains we have to set both _FILE_OFFSET_BITS=64 and _TIME_BITS=64 for glibc toolchains. Buildroot already define _FILE_OFFSET_BITS=64 since 2008 [1] before the first release tag 2009.02.

_TIME_BITS is not needed for musl libc since it already year2038 ready [2].

The uclibc-ng libc only support time_t 32-bit (long int) so it will be affected by the year2038 issue [3].

Fixes (in French, chapter Buildroot 2022 and GlibC):
https://www.blaess.fr/christophe/2038

Runtime tested with qemu_arm_vexpress_defconfig and the Bootlin glibc bleeding-edge 2021.11-1 toolchain.

Before:

 # date
 Tue Jan 19 03:14:07 UTC 2038
 # date
 Thu Jan  1 00:00:00 UTC 1970
Quoted 7 lines

After:

 # date
 Tue Jan 19 03:14:07 UTC 2038
 # date
 Tue Jan 19 03:14:08 UTC 2038
 # date
 Tue Jan 19 03:14:09 UTC 2038
Quoted 3 lines

Ahh, good catch. Maybe something to add a runtime test for?

Committed, thanks.

Sorry but I guess this patch needs more testing.

Quoted 20 lines
Quoted 19 lines

[1] 60b5eee76edfa153ef118d2788c74ac8da1497a0
[2] https://git.musl-libc.org/cgit/musl/tree/include/alltypes.h.in?h=v1.2.2#n3
[3] https://cgit.uclibc-ng.org/cgi/cgit/uclibc-ng.git/tree/include/time.h?h=v1.0.40#n75

    https://cgit.uclibc-ng.org/cgi/cgit/uclibc-ng.git/tree/libc/sysdeps/linux/common/bits/types.h?h=v1.0.40#n106
Cc Christophe Blaess <[email protected]>
---
 package/Makefile.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
package/Makefile.in +0 -0
index 508ea7c366..cde050ca82 100644
@@ -167,7 +167,7 @@ else ifeq ($(BR2_FORTIFY_SOURCE_2),y)
 TARGET_HARDENED += -D_FORTIFY_SOURCE=2
 endif
Quoted 2 lines

package/Makefile.in else ifeq ($(BR2_FORTIFY_SOURCE_2),y) · line 170

Quoted 2 lines
package/Makefile.in +1 -1
-TARGET_CPPFLAGS += -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
+TARGET_CPPFLAGS += -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64

I noticed that glibc 2.34 stop the build if _TIME_BITS is set without _FILE_OFFSET_BITS.
What if something (build system) unset _FILE_OFFSET_BITS ? There is something weird with libzlib package.

I suggest to apply for next first and backport it latter to the stable branch.

Best regards,
Romain

Quoted 5 lines
Quoted 4 lines
package/Makefile.in +0 -0
 TARGET_CFLAGS = $(TARGET_CPPFLAGS) $(TARGET_ABI) $(TARGET_OPTIMIZATION) $(TARGET_DEBUGGING) $(TARGET_HARDENED)
 TARGET_CXXFLAGS = $(TARGET_CFLAGS)
 TARGET_FCFLAGS = $(TARGET_ABI) $(TARGET_OPTIMIZATION) $(TARGET_DEBUGGING)
Quoted 8 lines
Quoted 6 lines

2.35.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#3 lore raw
Quoted 62 lines · Romain Naour

Hello Peter,

Le 07/03/2022 à 20:54, Peter Korsgaard a écrit :

Quoted 33 lines
Quoted 25 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Romain" == Romain Naour <[email protected]> writes:

To use time_t 64-bit for glibc >= 2.34 toolchains we have to set both _FILE_OFFSET_BITS=64 and _TIME_BITS=64 for glibc toolchains. Buildroot already define _FILE_OFFSET_BITS=64 since 2008 [1] before the first release tag 2009.02.

_TIME_BITS is not needed for musl libc since it already year2038 ready [2].

The uclibc-ng libc only support time_t 32-bit (long int) so it will be affected by the year2038 issue [3].

Fixes (in French, chapter Buildroot 2022 and GlibC):
https://www.blaess.fr/christophe/2038

Runtime tested with qemu_arm_vexpress_defconfig and the Bootlin glibc bleeding-edge 2021.11-1 toolchain.

Before:

 # date
 Tue Jan 19 03:14:07 UTC 2038
 # date
 Thu Jan  1 00:00:00 UTC 1970
Quoted 7 lines

After:

 # date
 Tue Jan 19 03:14:07 UTC 2038
 # date
 Tue Jan 19 03:14:08 UTC 2038
 # date
 Tue Jan 19 03:14:09 UTC 2038
Quoted 3 lines

Ahh, good catch. Maybe something to add a runtime test for?

Committed, thanks.

Sorry but I guess this patch needs more testing.

Quoted 20 lines
Quoted 19 lines

[1] 60b5eee76edfa153ef118d2788c74ac8da1497a0
[2] https://git.musl-libc.org/cgit/musl/tree/include/alltypes.h.in?h=v1.2.2#n3
[3] https://cgit.uclibc-ng.org/cgi/cgit/uclibc-ng.git/tree/include/time.h?h=v1.0.40#n75

    https://cgit.uclibc-ng.org/cgi/cgit/uclibc-ng.git/tree/libc/sysdeps/linux/common/bits/types.h?h=v1.0.40#n106
Cc Christophe Blaess <[email protected]>
---
 package/Makefile.in | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
package/Makefile.in +0 -0
index 508ea7c366..cde050ca82 100644
@@ -167,7 +167,7 @@ else ifeq ($(BR2_FORTIFY_SOURCE_2),y)
 TARGET_HARDENED += -D_FORTIFY_SOURCE=2
 endif
Quoted 6 lines
Quoted 2 lines

package/Makefile.in else ifeq ($(BR2_FORTIFY_SOURCE_2),y) · line 170

Quoted 2 lines
package/Makefile.in +1 -1
-TARGET_CPPFLAGS += -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
+TARGET_CPPFLAGS += -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64

I noticed that glibc 2.34 stop the build if _TIME_BITS is set without _FILE_OFFSET_BITS.
What if something (build system) unset _FILE_OFFSET_BITS ?

Then there's something wrong with that package and it needs to be fixed.

Quoted 1 line

There is something weird with libzlib package.

gzguts.h has this:

#ifdef _LARGEFILE64_SOURCE
# ifndef _LARGEFILE_SOURCE
# define _LARGEFILE_SOURCE 1
# endif
# ifdef _FILE_OFFSET_BITS
# undef _FILE_OFFSET_BITS
# endif
#endif

Why, I have no idea...

Regards,
Arnout

Quoted 21 lines

I suggest to apply for next first and backport it latter to the stable branch.

Best regards,
Romain

Quoted 5 lines
Quoted 4 lines
package/Makefile.in +0 -1
 TARGET_CFLAGS = $(TARGET_CPPFLAGS) $(TARGET_ABI) $(TARGET_OPTIMIZATION) $(TARGET_DEBUGGING) $(TARGET_HARDENED)
 TARGET_CXXFLAGS = $(TARGET_CFLAGS)
 TARGET_FCFLAGS = $(TARGET_ABI) $(TARGET_OPTIMIZATION) $(TARGET_DEBUGGING)
--
Quoted 8 lines
Quoted 6 lines

2.35.1

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

Quoted 4 lines

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#4 lore raw
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Arnout" == Arnout Vandecappelle <[email protected]> writes:

Hi,

Quoted 17 lines
Quoted 1 line

What if something (build system) unset _FILE_OFFSET_BITS ?

Then there's something wrong with that package and it needs to be fixed.

Quoted 1 line

There is something weird with libzlib package.

gzguts.h has this:

#ifdef _LARGEFILE64_SOURCE
# ifndef _LARGEFILE_SOURCE
# define _LARGEFILE_SOURCE 1
# endif
# ifdef _FILE_OFFSET_BITS
# undef _FILE_OFFSET_BITS
# endif
#endif

Quoted 1 line

Why, I have no idea...

Me neither. It seems to have been added when the file was added to zlib 10 years ago, but given that there is no real public VCS for zlib it is hard to know why:

https://github.com/madler/zlib/commit/d004b047838a7e803818b4973a2e39e0ff8c1fa2

We're not the only ones running into the issue:

https://unix.stackexchange.com/questions/692377/relationship-between-flags-d-file-offset-bits-and-d-largefile64-source

I agree that it simply looks like a bug in zlib, but maybe the best bet is indeed to revert for (the overdue) 2022.02 release? I hesitated when applying it given how late it is, but it indeed fixes a real bug.

Signature · 5 lines
Bye, Peter Korsgaard
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

A message that is not in the archive (sent off-list or not yet received): EqrpQEFyCqF3gsB7R_tVdXsj5TjoB_zERTaX-8bOrxKIU0IRl1YjcLmUOETuZ0poddXoF1yxT_2dV7cYYi-4TT7GgE8yhg9gUt9Q0aLtmZo=@0x53a.de

#6 lore raw
Quoted 16 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Johannes" == Johannes Agricola <[email protected]> writes:

Good Day!
This seems to break the build of gcc-10.3 w/ glibc
2.34-110. libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cpp contains:

Quoted 9 lines

#if SANITIZER_LINUX || SANITIZER_MAC
// Tests in this file assume that off_t-dependent data structures match the // libc ABI. For example, struct dirent here is what readdir() function (as // exported from libc) returns, and not the user-facing "dirent", which // depends on _FILE_OFFSET_BITS setting.
// To get this "true" dirent definition, we undefine _FILE_OFFSET_BITS below. #ifdef _FILE_OFFSET_BITS
#undef _FILE_OFFSET_BITS
#endif

Yes, we'll revert it for now and get it sorted out for 2022.05 instead.

Signature · 5 lines
Bye, Peter Korsgaard
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot