* [Bug libstdc++/65343] unexpected exception thrown during destruction of static object in debug mode
2015-03-07 13:29 [Bug libstdc++/65343] New: unexpected exception thrown during destruction of static object in debug mode frankhb1989 at gmail dot com
@ 2015-03-10 12:25 ` frankhb1989 at gmail dot com
2022-01-25 14:52 ` poulhies at adacore dot com
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: frankhb1989 at gmail dot com @ 2015-03-10 12:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65343
--- Comment #2 from frankhb1989 at gmail dot com ---
(In reply to Jonathan Wakely from comment #1)
> Maybe we want to placement-new the mutexes into a buffer so they are never
> destroyed, although on mingw that will show up as leaked resources at
> program shutdown (and this is only really a problem on mingw as we don't
> need to run any destructor on the mutexes for most targets).
This could be an acceptable workaround for MinGW, but I am not sure if there
would be some unexpected side effects. For other targets in future, this can
still be a problem.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/65343] unexpected exception thrown during destruction of static object in debug mode
2015-03-07 13:29 [Bug libstdc++/65343] New: unexpected exception thrown during destruction of static object in debug mode frankhb1989 at gmail dot com
2015-03-10 12:25 ` [Bug libstdc++/65343] " frankhb1989 at gmail dot com
@ 2022-01-25 14:52 ` poulhies at adacore dot com
2022-01-25 17:30 ` ebotcazou at gcc dot gnu.org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: poulhies at adacore dot com @ 2022-01-25 14:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65343
Marc Poulhiès <poulhies at adacore dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |poulhies at adacore dot com
--- Comment #3 from Marc Poulhiès <poulhies at adacore dot com> ---
Hi !
It looks like we are seeing this issue using vxworks7 on gcc-11.
The test "/testsuite/21_strings/basic_string/requirements/citerators.cc" has
been updated since gcc-10 to use __gnu_debug::string:
8<----8<-----8<-----8<-----8<-----8<------
commit 50bb46e4d2543f2a78f97feddcde27e42639dae1
Author: François Dumont <fdumont@gcc.gnu.org>
Date: Fri Mar 5 18:50:22 2021 +0100
libstdc++: Fix and complete __gnu_debug::basic_string implementation
8<----8<-----8<-----8<-----8<-----8<------
Currently, the mutexes are created when __gnu_internal::get_mutex() is first
called, during the construction of " __gnu_test::citerator<__gnu_debug::string>
dtest1;" in main().
#0 __gnu_cxx::__mutex::__mutex (this=0x801a80c0
<__gnu_internal::get_mutex(unsigned char)::m>) at
...libstdc++-v3/include/ext/concurrence.h:132
#1 0x0000000080043188 in __gnu_internal::M::M (this=0x801a80c0
<__gnu_internal::get_mutex(unsigned char)::m>) at
.../libstdc++-v3/src/c++11/shared_ptr.cc:38
#2 0x0000000080043268 in __gnu_internal::get_mutex (i=5 '\005') at
.../libstdc++-v3/src/c++11/shared_ptr.cc:39
...
#14 0x00000000800005b8 in main () at
.../libstdc++-v3/testsuite/21_strings/basic_string/requirements/citerators.cc:29
On vxworks, __GTHREAD_MUTEX_INIT is not defined, so a destructor is defined for
the __mutex object (include/ext/concurrence.h:136) and registered with
__cxa_atexit.
#0 __cxa_atexit (fn=0x800431ac <__tcf_0(void*)>, data=0x0,
dso_handle=0x801a5d40) at cxa_atexit.c:215
#1 0x0000000080043290 in __gnu_internal::get_mutex (i=5 '\005') at
.../libstdc++-v3/src/c++11/shared_ptr.cc:39
#2 0x0000000080010710 in (anonymous namespace)::get_safe_base_mutex
(address=0x801a7f28 <__gnu_test::citerator<__gnu_debug::basic_string<char,
std::char_traits<char>, std::allocator<char> > >::_S_container>)
at .../libstdc++-v3/src/c++11/debug.cc:66
Then, when main() returns, these mutexes' destructors are called, which on
vxworks call semDestroy() that invalidate the mutexes.
#0 __gnu_internal::M::~M (this=0x801a8480 <__gnu_internal::get_mutex(unsigned
char)::m+960>, __in_chrg=<optimized out>) at
.../libstdc++-v3/src/c++11/shared_ptr.cc:38
#1 0x00000000800431e0 in __tcf_0 () at
.../libstdc++-v3/src/c++11/shared_ptr.cc:39
#2 0x00000000800f4ae4 in __cxa_finalize (dso_handle=0x0) at cxa_atexit.c:222
#3 0x00000000800f4cac in __do_atexit_work () at cxa_atexit.c:229
#4 0x00000000800ff274 in exit (status=0) at vxexit.c:49
#5 0x00000000800001d8 in _start ()
A later destructor for the _S_container object then tries to lock the destroyed
and now invalid mutexes, leading to an error.
#0 __gnu_cxx::__mutex::lock (this=0x801a8200
<__gnu_internal::get_mutex(unsigned char)::m+320>)
at .../libstdc++-v3/include/ext/concurrence.h:149
#1 0x0000000080000b1c in __gnu_cxx::__scoped_lock::__scoped_lock
(this=0x600e68, __name=...) at ...p/libstdc++-v3/include/ext/concurrence.h:241
#2 0x00000000800109c4 in __gnu_debug::_Safe_sequence_base::_M_detach_all
(this=0x801a7f28 <__gnu_test::citerator<__gnu_debug::basic_string<char,
std::char_traits<char>, std::allocator<char> > >::_S_container>)
at .../libstdc++-v3/src/c++11/debug.cc:255
...
#7 0x00000000800f4ae4 in __cxa_finalize (dso_handle=0x0) at cxa_atexit.c:222
#8 0x00000000800f4cac in __do_atexit_work () at cxa_atexit.c:229
#9 0x00000000800ff274 in exit (status=0) at vxexit.c:49
#10 0x00000000800001d8 in _start ()
Forcing a call to get_mutex() earlier during the _Safe_sequence_base ctor
forces the mutex destructor to be called in the correct order, but does not
seem like a very robust workaround.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/65343] unexpected exception thrown during destruction of static object in debug mode
2015-03-07 13:29 [Bug libstdc++/65343] New: unexpected exception thrown during destruction of static object in debug mode frankhb1989 at gmail dot com
2015-03-10 12:25 ` [Bug libstdc++/65343] " frankhb1989 at gmail dot com
2022-01-25 14:52 ` poulhies at adacore dot com
@ 2022-01-25 17:30 ` ebotcazou at gcc dot gnu.org
2022-01-25 20:58 ` redi at gcc dot gnu.org
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2022-01-25 17:30 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65343
Eric Botcazou <ebotcazou at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
CC| |ebotcazou at gcc dot gnu.org
Ever confirmed|0 |1
Last reconfirmed| |2022-01-25
--- Comment #4 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
Right, this is problematic on VxWorks and Windows at least.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/65343] unexpected exception thrown during destruction of static object in debug mode
2015-03-07 13:29 [Bug libstdc++/65343] New: unexpected exception thrown during destruction of static object in debug mode frankhb1989 at gmail dot com
` (2 preceding siblings ...)
2022-01-25 17:30 ` ebotcazou at gcc dot gnu.org
@ 2022-01-25 20:58 ` redi at gcc dot gnu.org
2022-01-25 21:35 ` poulhies at adacore dot com
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2022-01-25 20:58 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65343
--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Patch for stage 1:
--- a/libstdc++-v3/src/c++11/shared_ptr.cc
+++ b/libstdc++-v3/src/c++11/shared_ptr.cc
@@ -28,6 +28,11 @@
namespace __gnu_internal _GLIBCXX_VISIBILITY(hidden)
{
+ namespace
+ {
+ alignas(64) unsigned char __mutex_storage[64 * (mask + 1)];
+ }
+
/* Returns different instances of __mutex depending on the passed index
* in order to limit contention.
*/
@@ -36,7 +41,7 @@ namespace __gnu_internal _GLIBCXX_VISIBILITY(hidden)
{
// increase alignment to put each lock on a separate cache line
struct alignas(64) M : __gnu_cxx::__mutex { };
- static M m[mask + 1];
+ static M* m = ::new(__mutex_storage) M[mask + 1];
return m[i];
}
}
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/65343] unexpected exception thrown during destruction of static object in debug mode
2015-03-07 13:29 [Bug libstdc++/65343] New: unexpected exception thrown during destruction of static object in debug mode frankhb1989 at gmail dot com
` (3 preceding siblings ...)
2022-01-25 20:58 ` redi at gcc dot gnu.org
@ 2022-01-25 21:35 ` poulhies at adacore dot com
2022-01-25 21:36 ` redi at gcc dot gnu.org
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: poulhies at adacore dot com @ 2022-01-25 21:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65343
--- Comment #6 from Marc Poulhiès <poulhies at adacore dot com> ---
(In reply to Jonathan Wakely from comment #5)
> Patch for stage 1:
Thank you ! I can confirm this patch fixes the issue we have on vxworks.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/65343] unexpected exception thrown during destruction of static object in debug mode
2015-03-07 13:29 [Bug libstdc++/65343] New: unexpected exception thrown during destruction of static object in debug mode frankhb1989 at gmail dot com
` (4 preceding siblings ...)
2022-01-25 21:35 ` poulhies at adacore dot com
@ 2022-01-25 21:36 ` redi at gcc dot gnu.org
2022-01-25 21:38 ` redi at gcc dot gnu.org
2024-02-08 12:40 ` redi at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2022-01-25 21:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65343
--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Great, thanks for checking it.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/65343] unexpected exception thrown during destruction of static object in debug mode
2015-03-07 13:29 [Bug libstdc++/65343] New: unexpected exception thrown during destruction of static object in debug mode frankhb1989 at gmail dot com
` (5 preceding siblings ...)
2022-01-25 21:36 ` redi at gcc dot gnu.org
@ 2022-01-25 21:38 ` redi at gcc dot gnu.org
2024-02-08 12:40 ` redi at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2022-01-25 21:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65343
--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
We should do something similar in src/c++11/mutex.cc
mutex&
__get_once_mutex()
{
static mutex once_mutex;
return once_mutex;
}
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug libstdc++/65343] unexpected exception thrown during destruction of static object in debug mode
2015-03-07 13:29 [Bug libstdc++/65343] New: unexpected exception thrown during destruction of static object in debug mode frankhb1989 at gmail dot com
` (6 preceding siblings ...)
2022-01-25 21:38 ` redi at gcc dot gnu.org
@ 2024-02-08 12:40 ` redi at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2024-02-08 12:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65343
--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The original bug should be fixed by r13-6282-gd70f49e98245f8
Comment 8 isn't done though.
^ permalink raw reply [flat|nested] 9+ messages in thread