https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123165

--- Comment #3 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-16 branch has been updated by Tomasz Kaminski
<[email protected]>:

https://gcc.gnu.org/g:5b5acdcec86102b6b39cb7afbf3a90be82751ca0

commit r16-9323-g5b5acdcec86102b6b39cb7afbf3a90be82751ca0
Author: Jonathan Wakely <[email protected]>
Date:   Tue Apr 28 13:15:22 2026 +0100

    libstdc++: Improve handling of leap second expiry time [PR123165]

    This change allows the hardcoded list of leap seconds in <chrono> to be
    used even when the program is executing after the hardcoded expiry date
    in that header.

    For times after the hardcoded expiry, the inline __get_leap_second_info
    function calls a new library function which compares the number of
    hardcoded leap seconds in the header with the number of leap seconds
    defined in the tzdata leapseconds file (usually provided by the OS).

    There are three leap second lists that are relevant here. The first is
    the hardcoded list (and its expiry time) in the <chrono> header. That is
    fixed when the user code is compiled, and might be out of date by the
    time the application runs. The second list (and its expiry time) is
    hardcoded in tzdb.cc in the libstdc++.so library. If the application
    uses a newer libstdc++.so at runtime than the <chrono> header used at
    compile time, we can still avoid going to the filesystem for dates
    within the expiry time of the list in libstdc++.so. The third list is
    the most up-to-date one which is read from the leapseconds file.

    The code added by this commit tries to avoid reading the file when
    possible (because that's slower than using the in-memory lists), and if
    it does have to go to the file system, it tries to avoid doing so again
    next time the leap seconds are needed. The later is handled by storing
    the number of recently know leaps seconds in num_leap_seconds of struct
    NumLeapSeconds, which decides whether to use std::atomic_ref<unsigned>
    or perform all accesses while holding a lock on the pre-existing mutex
    used for the tzdb_list singleton. Two set_locked/set functions are used
    to differentiate #if/#else branches of _Node::_S_replace_head that
    already held corresponding mutex and use atomic respectively.

    libstdc++-v3/ChangeLog:

            PR libstdc++/123165
            * acinclude.m4 (libtool_VERSION): Bump version.
            * config/abi/pre/gnu.ver (GLIBCXX_3.4.36): Add new symbol
            version and export new symbol.
            * configure: Regenerate.
            * include/std/chrono (__detail::__recent_leap_second_info):
            Declare new function and make it a friend of various classes.
            (leap_second): Make private constructor constexpr. Remove friend
            declaration for get_leap_second_info.
            (__detail::__get_leap_second_info): Use new function for times
            past the hardcoded expiry.
            * src/c++20/tzdb.cc (tzdb_list::_Node::fixed_leaps): Move array
            of leap seconds here from _S_read_leap_seconds.
            (_Node::NumLeapSeconds): New class.
            (_Node::num_leap_seconds): New static variable.
            (__detail::__recent_leap_second_info): Define new function.
            (tzdb_list::_Node::_S_read_leap_seconds): Populate vector from
            _Node::fixed_leaps. Rename bool variable to clarify meaning.
            (tzdb_list::_Node::_S_replace_head): Update num_leap_seconds
            when updating the tzdb_list.
            * testsuite/util/testsuite_abi.cc: Update known_versions and
            latestp.
            * testsuite/std/time/clock/utc/leap_second_info-2.cc: New test.

    Co-authored-by: Tomasz KamiÅski <[email protected]>
    Signed-off-by: Tomasz KamiÅski <[email protected]>

            (cherry-picked from commits
e79f0f818c0e42d0d84c90a54684dfb269ac388c)
            (b12fdd952511786bf8d285e7080e94deeb32aa1d)
            (adb4f4a064c009cd616106fa4c648182c18f96d9)
            (a7ad4bee6fe7cd77aceb6e86380dcaeb6da82791)
  • [Bug libstdc++/123165] Optimize... cvs-commit at gcc dot gnu.org via Gcc-bugs

Reply via email to