[Bug libstdc++/65343] New: unexpected exception thrown during destruction of static object in debug mode

frankhb1989 at gmail dot com gcc-bugzilla@gcc.gnu.org
Sat Mar 7 13:29:00 GMT 2015


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.



More information about the Gcc-bugs mailing list