public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/65343] New: unexpected exception thrown during destruction of static object in debug mode
@ 2015-03-07 13:29 frankhb1989 at gmail dot com
  2015-03-10 12:25 ` [Bug libstdc++/65343] " frankhb1989 at gmail dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: frankhb1989 at gmail dot com @ 2015-03-07 13:29 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 65343
           Summary: unexpected exception thrown during destruction of
                    static object in debug mode
           Product: gcc
           Version: 4.9.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: frankhb1989 at gmail dot com

Recently I found one of my program unexpected aborted by unhandled exception.
The program is compliled with '-std=c++11 -D_GLIBCXX_DEBUG
-D_GLIBCXX_DEBUG_PEDANTIC'. The corresponding release build (i.e. "no
-D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC") does not behave like this.

GDB tells me there is something wrong happened during destruction of some
global container objects:

#2  0x00454b09 in __cxxabiv1::__terminate(void (*)()) ()
#3  0x00635d99 in __cxa_call_terminate ()
#4  0x006366df in __gxx_personality_v0 ()
#5  0x6e952cd2 in ?? () from F:\msys\mingw\bin\libgcc_s_dw2-1.dll
#6  0x6e95332b in ?? () from F:\msys\mingw\bin\libgcc_s_dw2-1.dll
#7  0x00636435 in __cxa_throw ()
#8  0x005021ea in __gnu_cxx::__throw_concurrence_lock_error ()
    at F:/msys/mingw/include/c++/4.9.1/ext/concurrence.h:102
#9  0x00470a15 in __gnu_debug::_Safe_sequence_base::_M_detach_all() ()

I searched the source of libstdc++, then I found, in "C++11/debug.cc", there
were mutexes used by the debug mode containers, which was some static
__gnu_cxx::__mutex objects. This was probably the direct reason: the order
destruction of static objects among translation units are unspecified, so the
mutexes could be destroyed before the sequences contained by some other static
objects (certainly in different translation units). Then, during the
desturction of the sequence, "_M_detach_all" was called. In that function,
"__gnu_cxx::__scoped_lock sentry(_M_get_mutex());" tried using the (already
destroyed) mutex to lock the resources, which failed and threw.

Since the documentation says, "all functional and exception-handling guarantees
made by the normal library also hold for the debug mode library, with one
exception: performance guarantees made by the normal library may not hold in
the debug mode library", and ISO C++ effectively forbids destructors in
standard library to throw, this should be a bug.


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-02-08 12:40 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).