Bug 243292 - Program that works otherwise segfaults when enabling libstdc++ debug defines
Program that works otherwise segfaults when enabling libstdc++ debug defines
Product: Fedora
Classification: Fedora
Component: gcc (Show other bugs)
x86_64 Linux
low Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Depends On:
  Show dependency treegraph
Reported: 2007-06-08 08:24 EDT by Albert Strasheim
Modified: 2007-11-30 17:12 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2007-06-12 16:48:04 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Albert Strasheim 2007-06-08 08:24:29 EDT
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061003 Firefox/2.0

Description of problem:
I'm trying to compile the ActiveMQ++ library with libstdc++ debug defines enabled. When I run the unit tests, they segfault. Without the debug defines, the unit tests run without problems. The unit tests also run under Valgrind without any errors being reported, so it looks like the segfault might be due to a bug in the libstdc++ debug code.

Running the activemq-test program causes an immediate segfault. The backtrace from gdb says:

#0  0x0000003d01658d5d in __gnu_debug::_Safe_iterator_base::_M_detach () from /usr/lib64/libstdc++.so.6
#1  0x0000003d01658e06 in __gnu_debug::_Safe_iterator_base::_M_attach () from /usr/lib64/libstdc++.so.6
#2  0x0000003d01658f73 in __gnu_debug::_Safe_sequence_base::_M_detach_all () from /usr/lib64/libstdc++.so.6
#3  0x0000000000450a7f in ~_Safe_sequence_base (this=0x7fff95e21e38) at /usr/lib/gcc/x86_64-redhat-linux/4.1.1/../../../../include/c++/4.1.1/debug/safe_base.h:170
#4  0x0000000000450bd1 in ~_Safe_sequence (this=0x7fff95e21e38) at /usr/lib/gcc/x86_64-redhat-linux/4.1.1/../../../../include/c++/4.1.1/debug/safe_sequence.h:99
#5  0x0000000000450bf2 in ~deque (this=0x7fff95e21de8) at /usr/lib/gcc/x86_64-redhat-linux/4.1.1/../../../../include/c++/4.1.1/debug/deque:85
#6  0x0000000000450c4c in ~Message (this=0x7fff95e21de0) at /usr/include/cppunit/Message.h:39
#7  0x0000000000453f5b in activemq::concurrent::MutexTest::test (this=0xabeaf0) at activemq/concurrent/MutexTest.h:433
#8  0x000000000044ec0e in CppUnit::TestCaller<activemq::concurrent::MutexTest>::runTest (this=0xabeb10) at /usr/include/cppunit/TestCaller.h:166
... more CppUnit stuff here ...
#22 0x00000000005b7e90 in main (argc=1, argv=0x7fff95e22598) at main.cpp:34

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
To get this code to build, do the following:

0. yum install automake autoconf libtool cppunit-devel
1. svn co http://svn.apache.org/repos/asf/activemq/activemq-cpp/trunk activemq-cpp
2. Apply the following patch:

Index: src/test/activemq/util/StringTokenizerTest.cpp
--- src/test/activemq/util/StringTokenizerTest.cpp      (revision 545488)
+++ src/test/activemq/util/StringTokenizerTest.cpp      (working copy)
@@ -87,7 +87,9 @@
     std::vector<std::string> myArray;
     StringTokenizer tokenizer6("the:quick:brown:fox", ":");
     CPPUNIT_ASSERT( tokenizer6.countTokens() == 4 );
+#if 0
     CPPUNIT_ASSERT( tokenizer6.toArray(myArray) == 4 );
     CPPUNIT_ASSERT( tokenizer6.countTokens() == 0 );
     CPPUNIT_ASSERT( tokenizer6.countTokens() == 4 );
Index: configure.ac
--- configure.ac        (revision 545488)
+++ configure.ac        (working copy)
@@ -86,7 +86,7 @@
 AM_PATH_CPPUNIT(1.10.2, cppunit=yes, cppunit=no; AC_MSG_RESULT([no. Unit and Integration tests disabled]))
-CXXFLAGS="$CXXFLAGS -W -Wall -fPIC -fstrict-aliasing -Wstrict-aliasing=2 -Wno-long-long"
+CXXFLAGS="$CXXFLAGS -W -Wall -fPIC -fstrict-aliasing -Wstrict-aliasing=2 -Wno-long-long -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_GLIBCXX_CONCEPT_CHECKS"
 case "${host_os}" in

The change to StringTokenizerTest.cpp is to avoid a strange link error that is also caused by the debug defines.

3. cd activemq-cpp ; ./autogen.sh && ./configure && make && make check

This build the activemq-test binary in src/test.

Actual Results:

Expected Results:

Additional info:
Comment 1 Benjamin Kosnik 2007-06-11 09:37:17 EDT
From looking at the stack trace, I think this is probably an issue with debug
mode's thread safety. There have been improvements to support for threads in
debug mode, and it looks like gcc-4_1-branch is lagging mainline and gcc-4_2-branch.

The relevant file is gcc/libstdc++-v3/src/debug.cc. See the added mutexes.

I would ask the reporter to do one of the following things:

1) try to use the FSF gcc-4.2.0 compiler (which has these mt fixes), instead of
gcc-4.1.x, and see if you still have this issue. If it goes away, we'll try to
backport the fixes to 4.1.x.

2) try to come up with a single file that we can use to reproduce your issue,
and attach it to this bug report. Then, we can tell you if this is indeed the issue.


Comment 2 Albert Strasheim 2007-06-12 16:48:04 EDT
I suspect this is a false alarm. The stack trace contains a hint as to what I
did wrong: link "normal" CppUnit against my debug code. This causes the
CppUnit::Message destructor segfault when it tries to deallocate a debug string,
thinking it's a normal string.

It would be really handy if there were a way to make mixing of debug and normal
code cause a link error or something.

Anyway, this bug can be resolved as invalid.

Note You need to log in before you can comment on or make changes to this bug.