libstdc++: Avoid recursion in __nothrow_wait_cv::wait [PR105730]
authorJonathan Wakely <jwakely@redhat.com>
Thu, 22 Dec 2022 09:56:47 +0000 (09:56 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 22 Dec 2022 23:34:27 +0000 (23:34 +0000)
commitee4af2ed0b7322884ec4ff537564683c3749b813
treef735e74fcd64757a2e6a282f2014251cf0dbd77f
parentf99b94865fa629cc2cc937128a812b6a23038446
libstdc++: Avoid recursion in __nothrow_wait_cv::wait [PR105730]

The commit r12-5877-g9e18a25331fa25 removed the incorrect
noexcept-specifier from std::condition_variable::wait and gave the new
symbol version @@GLIBCXX_3.4.30. It also redefined the original symbol
std::condition_variable::wait(unique_lock<mutex>&)@GLIBCXX_3.4.11 as an
alias for a new symbol, __gnu_cxx::__nothrow_wait_cv::wait, which still
has the incorrect noexcept guarantee. That __nothrow_wait_cv::wait is
just a wrapper around the real condition_variable::wait which adds
noexcept and so terminates on a __forced_unwind exception.

This doesn't work on uclibc, possibly due to a dynamic linker bug. When
__nothrow_wait_cv::wait calls the condition_variable::wait function it
binds to the alias symbol, which means it just calls itself recursively
until the stack overflows.

This change avoids the possibility of a recursive call by changing the
__nothrow_wait_cv::wait function so that instead of calling
condition_variable::wait it re-implements it. This requires accessing
the private _M_cond member of condition_variable, so we need to use the
trick of instantiating a template with the member-pointer of the private
member.

libstdc++-v3/ChangeLog:

PR libstdc++/105730
* src/c++11/compatibility-condvar.cc (__nothrow_wait_cv::wait):
Access private data member of base class and call its wait
member.
libstdc++-v3/src/c++11/compatibility-condvar.cc