GCC Build Defaults to Debug Mode?

Nick nospam@codesniffer.com
Wed Jan 11 16:25:00 GMT 2017


I've been building GCC for many years.  Just recently I've noticed that
it seems to build with debugging information (-g) by default.  Is this
true?

Info:
GCC version: 4.9.4
Platform:  Linux (CentOS)

My environment variables have no *FLAGS (ie. CFLAGS, CXXFLAGS, etc)
defined:
===================================================
[build@rhel6bm1 build]$ env | grep -i flags
[build@rhel6bm1 build]$ 
===================================================

Build procedure (pseudo):
1. Extract src
2. Create "build" directory & cd to it
3. configure --prefix=... --enable-threads=posix --enable-tls
--enable-languages=c,c++ 
4. make
5. make install


Relevant (?) snippet from config.log:
===================================================

<snip>
## ----------------- ##
## Output variables. ##
## ----------------- ##

AR='ar'
AR_FOR_BUILD='$(AR)'
AR_FOR_TARGET='$(AR)'
AS='as'
AS_FOR_BUILD='$(AS)'
AS_FOR_TARGET='$(AS)'
AWK='gawk'
BISON='bison'
BUILD_CONFIG='bootstrap-debug'
CC='gcc'
CC_FOR_BUILD='$(CC)'
CC_FOR_TARGET='$$r/$(HOST_SUBDIR)/gcc/xgcc -B$$r/$(HOST_SUBDIR)/gcc/'
CFLAGS='-g -O2'
CFLAGS_FOR_BUILD='-g -O2'
CFLAGS_FOR_TARGET='-g -O2'
COMPILER_AS_FOR_TARGET='$$r/$(HOST_SUBDIR)/gcc/as'
COMPILER_LD_FOR_TARGET='$$r/$(HOST_SUBDIR)/gcc/collect-ld'
COMPILER_NM_FOR_TARGET='$$r/$(HOST_SUBDIR)/gcc/nm'
CONFIGURE_GDB_TK=''
CPPFLAGS=''
CXX='g++'
CXXFLAGS='-g -O2'
CXXFLAGS_FOR_BUILD='-g -O2'
CXXFLAGS_FOR_TARGET='-g -O2'
CXX_FOR_BUILD='$(CXX)'
</snip>
===================================================


And I've confirmed that compilations are in fact including "-g".
Example from the build output:

===================================================
<snip>
/bin/sh ../../libtool --tag CXX --tag disable-shared
--mode=compile /home/build/wc/n/dev/3rdParty/gcc/build/./gcc/xgcc
-shared-libgcc -B/home/build/wc/n/dev/3rdParty/gcc/build/./gcc -nostdinc
++
-L/home/build/wc/n/dev/3rdParty/gcc/build/x86_64-unknown-linux-gnu/libstdc++-v3/src -L/home/build/wc/n/dev/3rdParty/gcc/build/x86_64-unknown-linux-gnu/libstdc++-v3/src/.libs -L/home/build/wc/n/dev/3rdParty/gcc/build/x86_64-unknown-linux-gnu/libstdc++-v3/libsupc++/.libs -B/home/build/wc/n/dev/3rdParty/gcc/gcc_build_prefix/x86_64-unknown-linux-gnu/bin/ -B/home/build/wc/n/dev/3rdParty/gcc/gcc_build_prefix/x86_64-unknown-linux-gnu/lib/ -isystem /home/build/wc/n/dev/3rdParty/gcc/gcc_build_prefix/x86_64-unknown-linux-gnu/include -isystem /home/build/wc/n/dev/3rdParty/gcc/gcc_build_prefix/x86_64-unknown-linux-gnu/sys-include    -I/home/build/wc/n/dev/3rdParty/gcc/gcc-4.9.4/libstdc++-v3/../libgcc -I/home/build/wc/n/dev/3rdParty/gcc/build/x86_64-unknown-linux-gnu/libstdc++-v3/include/x86_64-unknown-linux-gnu -I/home/build/wc/n/dev/3rdParty/gcc/build/x86_64-unknown-linux-gnu/libstdc++-v3/include -I/home/build/wc/n/dev/3rdParty/gcc/gcc-4.9.4/libstdc++-v3/libsupc++  -prefer-pic -D_GLIBCXX_SHARED -fno-implicit-templates  -Wall -Wextra -Wwrite-strings -Wcast-qual -Wabi  -fdiagnostics-show-location=once   -ffunction-sections -fdata-sections  -frandom-seed=ios_failure.lo -g -O2 -D_GNU_SOURCE  -c -o ios_failure.lo ../../../../../gcc-4.9.4/libstdc++-v3/src/c++98/ios_failure.cc
</snip>
===================================================


So a few questions:
1.  Why does it do this by default?
2.  Does it make sense for me to turn that off?  (I don't want it
because static analysis is picking up a ton of false positives in
various GCC modules which get linked into my app).
3.  How best to turn it off?




More information about the Gcc-help mailing list