Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

why are there __assert_fail() symbols in libstdc++.so?

1,009 views
Skip to first unread message

Scott

unread,
May 22, 2012, 2:06:16 AM5/22/12
to
Hi all,

After building gcc 4.7.0, I found that libstdc++.so has symbol references to __assert_fail(). (This is used by the assert() macro for DEBUG builds.)

I was expecting gcc to build the C++ libraries with -NDEBUG.

Is there some ./configure switch I need to build optimised non-debug libraries?

I ./configure'd the gcc build with:

../configure --prefix=/usr/local/gcc-4.7.0 --enable-cloog-backend --enable-lto --enable-languages=c,c++

More specs:

devaus120>> g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/local/gcc-4.7.0/libexec/gcc/i686-pc-linux-gnu/4.7.0/lto-wrapper
Target: i686-pc-linux-gnu
Configured with: ../configure --prefix=/usr/local/gcc-4.7.0 --enable-cloog-backend --enable-lto --enable-languages=c,c++
Thread model: posix
gcc version 4.7.0 (GCC)
devaus120>> cat /etc/redhat-release
CentOS release 5.5 (Final)
devaus120>> uname -a
Linux devaus120 2.6.18-194.17.1.el5 #1 SMP Wed Sep 29 12:51:33 EDT 2010 i686 athlon i386 GNU/Linux

Scott. :)

Andrew Haley

unread,
May 22, 2012, 4:56:59 AM5/22/12
to
Scott <sc...@smedleyfamily.net> wrote:

> After building gcc 4.7.0, I found that libstdc++.so has symbol
> references to __assert_fail(). (This is used by the assert() macro
> for DEBUG builds.)
>
> I was expecting gcc to build the C++ libraries with -NDEBUG.
>
> Is there some ./configure switch I need to build optimised non-debug libraries?

I don't think so. I'd check the logs and look to see which file is
referring to __assert_fail().

Andrew.

Scott

unread,
May 22, 2012, 7:33:22 PM5/22/12
to
Non sequitur.

The assert() macro is used is many, many places in the gcc code - the actually implementation behind it is the __assert_fail() function. Usually, non-debug releases are compiled with the -DNDEBUG flag which effectively causes assert() statements to be ignored/removed. The fact that the __assert_fail() symbol is referenced in libstdc++.so makes me think that the assertions are NOT disabled - this would obviously be less efficient.

So, I'm trying to understand why there are (what is widely recognised as) debug symbols in a non-debug build!

Any insight would be muchly appreciated.

Scott. :)

Andrew Haley

unread,
May 23, 2012, 6:31:07 AM5/23/12
to
Why don't you just have a look? That's my suggesion. Look in the .o
files to see where the reference to __assert_fail() is, then compile
that file and see where the reference is.

Andrew.

Scott

unread,
May 23, 2012, 7:51:31 PM5/23/12
to
The symbol appears to be coming from: libstdc++-v3/src/c++11/debug.o

Now that I look more closely, there are 48 different __gnu_debug* symbols in libstdc++.so.

Why is debug code being included in production builds?

Scott.

Andrew Haley

unread,
May 24, 2012, 4:30:55 AM5/24/12
to
Scott <sc...@smedleyfamily.net> wrote:
>
> The symbol appears to be coming from: libstdc++-v3/src/c++11/debug.o
>
> Now that I look more closely, there are 48 different __gnu_debug* symbols in libstdc++.so.
>
> Why is debug code being included in production builds?

It's in the book:

Chapter 30. Debug Mode

By default, libstdc++ is built with efficiency in mind, and
therefore performs little or no error checking that is not required
by the C++ standard. This means that programs that incorrectly use
the C++ standard library will exhibit behavior that is not portable
and may not even be predictable, because they tread into
implementation-specific or undefined behavior. To detect some of
these errors before they can become problematic, libstdc++ offers a
debug mode that provides additional checking of library facilities,
and will report errors in the use of libstdc++ as soon as they can
be detected by emitting a description of the problem to standard
error and aborting the program.

Andrew.
0 new messages