From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 799AC38582B0; Wed, 31 Jan 2024 11:49:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 799AC38582B0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1706701759; bh=eZwhfxPnqrUmP+bPEpoJRyj9DGWjNeE5U1Pmzq3TVWY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Uflj/r9+tZRyXMv+htV6SU+xa5w7h48awmquNP5hD5yGbR+nLWScnsThrQapvyGwt 58l/QMTyt8ys0EwAA70JStb6spItdABSfl3ts9uuFkpSlkaK3l0leBnfMukuj4y3YE B36RtDQYKRAk83rkrfyXo4Owj9X8HhZ2yN5tZ80U= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/99832] std::chrono::system_clock::to_time_t needs ABI tag for 32-bit time_t Date: Wed, 31 Jan 2024 11:49:04 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: ABI X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 14.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99832 --- Comment #1 from Jonathan Wakely --- Maybe something like this: diff --git a/libstdc++-v3/config/os/gnu-linux/os_defines.h b/libstdc++-v3/config/os/gnu-linux/os_defines.h index 0af29325388..f7c73560831 100644 --- a/libstdc++-v3/config/os/gnu-linux/os_defines.h +++ b/libstdc++-v3/config/os/gnu-linux/os_defines.h @@ -84,7 +84,13 @@ // Since glibc 2.34 all pthreads functions are usable without linking to // libpthread. # define _GLIBCXX_GTHREAD_USE_WEAK 0 -# endif +// Since glibc 2.34 using -D_TIME_BITS=3D64 will enable 64-bit time_t +// for "legacy ABIs", i.e. ones that historically used 32-bit time_t. +// This internal glibc macro will be defined iff new 64-bit time_t is in u= se. +# ifdef __USE_TIME_BITS64 +# define _GLIBCXX_TIME_BITS64 1 +# endif +# endif // glibc 2.34 #endif // __linux__ #endif diff --git a/libstdc++-v3/include/bits/chrono.h b/libstdc++-v3/include/bits/chrono.h index 579c5a266be..a63782b92ff 100644 --- a/libstdc++-v3/include/bits/chrono.h +++ b/libstdc++-v3/include/bits/chrono.h @@ -1242,6 +1242,9 @@ _GLIBCXX_BEGIN_INLINE_ABI_NAMESPACE(_V2) now() noexcept; // Map to C API +#ifdef _GLIBCXX_TIME_BITS64 + [[__gnu__::__abi_tag__("__time64")]] +#endif static std::time_t to_time_t(const time_point& __t) noexcept { @@ -1249,6 +1252,9 @@ _GLIBCXX_BEGIN_INLINE_ABI_NAMESPACE(_V2) (__t.time_since_epoch()).count()); } +#ifdef _GLIBCXX_TIME_BITS64 + [[__gnu__::__abi_tag__("__time64")]] +#endif static time_point from_time_t(std::time_t __t) noexcept { Alternatively, in do: #define _GLIBCXX_TIME_BITS64_ABI_TAG and then in config/os/gnu-linux/os_defines.h: # ifdef __USE_TIME_BITS64 # undef _GLIBCXX_TIME_BITS64_ABI_TAG # define _GLIBCXX_TIME_BITS64_ABI_TAG [[__gnu__::__abi_tag__("__time64")]] # endif Then the chrono code can just use that unconditionally instead of using #if= def I think for musl, newer versions use 64-bit time_t unconditionally. I'm not sure if we can (or need to) use the abi_tag there.=