From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2140) id 1E5B43857C55; Thu, 16 Feb 2023 11:13:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1E5B43857C55 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676546027; bh=cRX6E0+1wyWkUB5d7GY52+YS4i7vVkkFabGmgXxijqE=; h=From:To:Subject:Date:From; b=t89XW8dFc/m/FZyARYvAUsrVNNEK68rCtfn4v2LIsKMSCpa7e+GzQGo8UPNnH9RqC w7XVI9oKPLZzLCNOZqEBlcsUqLtYl1iJCyZbr8gnxwmpI0eRGR1EQP4OAjl1dAqKzW LKLh+w66dbq0Gkp2FPahSRUMGJIDry93/znP7Tow= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Alexandre Oliva To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc(refs/users/aoliva/heads/testme)] [libstdc++] ensure mutex_pool survives _Safe_sequence_base X-Act-Checkin: gcc X-Git-Author: Alexandre Oliva X-Git-Refname: refs/users/aoliva/heads/testme X-Git-Oldrev: 1d816abbae684c2ef0082c15d37953fc78058bfc X-Git-Newrev: e298c760cab78f831cd25d398636f4b8befc88a7 Message-Id: <20230216111347.1E5B43857C55@sourceware.org> Date: Thu, 16 Feb 2023 11:13:47 +0000 (GMT) List-Id: https://gcc.gnu.org/g:e298c760cab78f831cd25d398636f4b8befc88a7 commit e298c760cab78f831cd25d398636f4b8befc88a7 Author: Alexandre Oliva Date: Thu Feb 16 07:45:40 2023 -0300 [libstdc++] ensure mutex_pool survives _Safe_sequence_base On vxworks, after destroying the semaphore used to implement a mutex, __gthread_mutex_lock fails and __gnu_cxx::__mutex::lock calls __throw_concurrence_lock_error. Nothing ensures the mutex_pool mutexes survive init-once objects containing _Safe_sequence_base. If such an object completes construction before mutex_pool initialization, it will be registered for atexit destruction after the mutex_pool mutexes, so the _M_detach_all() call in the _Safe_sequence_base dtor will use already-destructed mutexes, and basic_string/requirements/citerators_cc fails calling terminate. This patch fixes this problem by ensuring the mutex pool completes construction before any _Safe_sequence_base-containing object, so that the mutex pool survives them all. for libstdc++-v3/ChangeLog * include/debug/safe_base.h (_Safe_sequence_base): Ensure the mutex pool survives *this. Diff: --- libstdc++-v3/include/debug/safe_base.h | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/debug/safe_base.h b/libstdc++-v3/include/debug/safe_base.h index 1dfa9f68b65..d4ba404cdac 100644 --- a/libstdc++-v3/include/debug/safe_base.h +++ b/libstdc++-v3/include/debug/safe_base.h @@ -203,7 +203,15 @@ namespace __gnu_debug // Initialize with a version number of 1 and no iterators _Safe_sequence_base() _GLIBCXX_NOEXCEPT : _M_iterators(0), _M_const_iterators(0), _M_version(1) - { } + { + // Make sure the mutex_pool machinery is initialized before any + // full object containing a _Safe_sequence_base completes + // construction, so that any local static mutexes in the mutex + // pool won't be destructed before our destructor runs; + // _M_detach_all could fail otherwise, on targets whose mutexes + // stop working after being destroyed. + (void)this->_M_get_mutex(); + } #if __cplusplus >= 201103L _Safe_sequence_base(const _Safe_sequence_base&) noexcept