]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Fix std::future::wait_until for subsecond negative times [PR118093]
authorJonathan Wakely <jwakely@redhat.com>
Tue, 17 Dec 2024 21:32:19 +0000 (21:32 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Wed, 8 Jan 2025 12:45:37 +0000 (12:45 +0000)
commit8ade3c3ea77e166f2873fb7ae57f9690e2b8d0e0
tree94eeaa00951c3b95a00164e16344ed8b69d5e9bb
parent5f44b1776e748a7528020557036740905a11b1df
libstdc++: Fix std::future::wait_until for subsecond negative times [PR118093]

The current check for negative times (i.e. before the epoch) only checks
for a negative number of seconds. For a time 1ms before the epoch the
seconds part will be zero, but the futex syscall will still fail with an
EINVAL error. Extend the check to handle this case.

This change adds a redundant check in the headers too, so that we avoid
even calling into the library for negative times. Both checks can be
marked [[unlikely]]. The check in the headers avoids the cost of
splitting the time into seconds and nanoseconds and then making a PLT
call. The check inside the library matches where we were checking
already, and fixes existing binaries that were compiled against older
headers but use a newer libstdc++.so.6 at runtime.

libstdc++-v3/ChangeLog:

PR libstdc++/118093
* include/bits/atomic_futex.h (_M_load_and_test_until_impl):
Return false for times before the epoch.
* src/c++11/futex.cc (_M_futex_wait_until): Extend check for
negative times to check for subsecond times. Add unlikely
attribute.
(_M_futex_wait_until_steady): Likewise.
* testsuite/30_threads/future/members/118093.cc: New test.
libstdc++-v3/include/bits/atomic_futex.h
libstdc++-v3/src/c++11/futex.cc
libstdc++-v3/testsuite/30_threads/future/members/118093.cc [new file with mode: 0644]