Skip to content

Commit 4ad83ef

Browse files
committed
Merge bitcoin/bitcoin#29205: build: always set -g -O2 in CORE_CXXFLAGS
00c1e2a build: fix optimisation flags used for --coverage (fanquake) 1dc2c9b ci: cleanup C*FLAG usage in Valgrind jobs (fanquake) 6cc2a38 build: add sanitizer flags to configure output (fanquake) 08cd5ac build: always set -g -O2 in CORE_CXXFLAGS (fanquake) Pull request description: Rather than trying to sporadically rely on / override Autoconf default behaviour. Just always override (if unset), and always set the flags we want (which are the same as the Autoconf defaults). Removes the need for duplicate code to clear (if not overridden) `CXXFLAGS`. Fixes cases of "missing" `-O2`. i.e this PR when running a Valgrind CI job with changes here: ```bash CXXFLAGS = -g -O2 -fdebug-prefix-map=$(abs_top_srcdir)=. -Wstack-protector -fstack-protector-all -mbranch-protection=bti -Werror -fsanitize=fuzzer -gdwarf-4 ``` Fixes configure output to reflect actual compilation flag ordering, so it's useful. Note that if we do still end up with a duplicate "-g -O2" when compiling, that has no effect, and I don't really thinks it's something worth trying to optimize. ACKs for top commit: TheCharlatan: lgtm ACK 00c1e2a hebasto: ACK 00c1e2a, I have reviewed the code and it looks OK. Also tested `ci/test/00_setup_env_native_valgrind.sh`. theuni: ACK 00c1e2a Tree-SHA512: cf6c7acf813ba10b198561e83eb72e9b2532a39cb1767c452d031e82921dcd42a47b129735b24c4e36131fd0c8fe7457f7cae870c1e011cdfdd430bdc4d4912b
2 parents 207220c + 00c1e2a commit 4ad83ef

File tree

4 files changed

+15
-18
lines changed

4 files changed

+15
-18
lines changed

ci/test/00_setup_env_native_fuzz_with_valgrind.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ export RUN_FUZZ_TESTS=true
1616
export FUZZ_TESTS_CONFIG="--valgrind"
1717
export GOAL="install"
1818
# Temporarily pin dwarf 4, until using Valgrind 3.20 or later
19-
export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer CC='clang -gdwarf-4' CXX='clang++ -gdwarf-4'"
19+
export BITCOIN_CONFIG="--enable-fuzz --with-sanitizers=fuzzer CC=clang CXX=clang++ CFLAGS=-gdwarf-4 CXXFLAGS=-gdwarf-4"
2020
export CCACHE_MAXSIZE=200M

ci/test/00_setup_env_native_valgrind.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ export NO_DEPENDS=1
1414
export TEST_RUNNER_EXTRA="--exclude feature_init,rpc_bind,feature_bind_extra" # Excluded for now, see https://github.com/bitcoin/bitcoin/issues/17765#issuecomment-602068547
1515
export GOAL="install"
1616
# Temporarily pin dwarf 4, until using Valgrind 3.20 or later
17-
export BITCOIN_CONFIG="--enable-zmq --with-incompatible-bdb --with-gui=no CC='clang -gdwarf-4' CXX='clang++ -gdwarf-4'" # TODO enable GUI
17+
export BITCOIN_CONFIG="--enable-zmq --with-incompatible-bdb --with-gui=no CC=clang CXX=clang++ CFLAGS=-gdwarf-4 CXXFLAGS=-gdwarf-4" # TODO enable GUI

configure.ac

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,15 @@ AC_ARG_ENABLE([external-signer],
323323

324324
AC_LANG_PUSH([C++])
325325

326+
dnl Always set -g -O2 in our CXXFLAGS. Autoconf will try and set CXXFLAGS to "-g -O2" by default,
327+
dnl so we suppress that (if CXXFLAGS hasn't been overridden by the user), given we are adding it
328+
dnl ourselves.
329+
CORE_CXXFLAGS="$CORE_CXXFLAGS -g -O2"
330+
331+
if test "$CXXFLAGS_overridden" = "no"; then
332+
CXXFLAGS=""
333+
fi
334+
326335
dnl Check for a flag to turn compiler warnings into errors. This is helpful for checks which may
327336
dnl appear to succeed because by default they merely emit warnings when they fail.
328337
dnl
@@ -347,12 +356,6 @@ case $host in
347356
esac
348357

349358
if test "$enable_debug" = "yes"; then
350-
dnl If debugging is enabled, and the user hasn't overridden CXXFLAGS, clear
351-
dnl them, to prevent autoconfs "-g -O2" being added. Otherwise we'd end up
352-
dnl with "-O0 -g3 -g -O2".
353-
if test "$CXXFLAGS_overridden" = "no"; then
354-
CXXFLAGS=""
355-
fi
356359

357360
dnl Disable all optimizations
358361
AX_CHECK_COMPILE_FLAG([-O0], [DEBUG_CXXFLAGS="$DEBUG_CXXFLAGS -O0"], [], [$CXXFLAG_WERROR])
@@ -859,13 +862,7 @@ if test "$use_lcov" = "yes"; then
859862
[AC_MSG_ERROR([lcov testing requested but --coverage linker flag does not work])])
860863
AX_CHECK_COMPILE_FLAG([--coverage],[CORE_CXXFLAGS="$CORE_CXXFLAGS --coverage"],
861864
[AC_MSG_ERROR([lcov testing requested but --coverage flag does not work])])
862-
dnl If coverage is enabled, and the user hasn't overridden CXXFLAGS, clear
863-
dnl them, to prevent autoconfs "-g -O2" being added. Otherwise we'd end up
864-
dnl with "--coverage -Og -O0 -g -O2".
865-
if test "$CXXFLAGS_overridden" = "no"; then
866-
CXXFLAGS=""
867-
fi
868-
CORE_CXXFLAGS="$CORE_CXXFLAGS -Og -O0"
865+
CORE_CXXFLAGS="$CORE_CXXFLAGS -Og"
869866
fi
870867

871868
if test "$use_lcov_branch" != "no"; then
@@ -1996,8 +1993,8 @@ echo " CC = $CC"
19961993
echo " CFLAGS = $PTHREAD_CFLAGS $CFLAGS"
19971994
echo " CPPFLAGS = $DEBUG_CPPFLAGS $HARDENED_CPPFLAGS $CORE_CPPFLAGS $CPPFLAGS"
19981995
echo " CXX = $CXX"
1999-
echo " CXXFLAGS = $DEBUG_CXXFLAGS $HARDENED_CXXFLAGS $WARN_CXXFLAGS $NOWARN_CXXFLAGS $ERROR_CXXFLAGS $GPROF_CXXFLAGS $CORE_CXXFLAGS $CXXFLAGS"
2000-
echo " LDFLAGS = $PTHREAD_LIBS $HARDENED_LDFLAGS $GPROF_LDFLAGS $CORE_LDFLAGS $LDFLAGS"
1996+
echo " CXXFLAGS = $CORE_CXXFLAGS $DEBUG_CXXFLAGS $HARDENED_CXXFLAGS $WARN_CXXFLAGS $NOWARN_CXXFLAGS $ERROR_CXXFLAGS $GPROF_CXXFLAGS $SANITIZER_CXXFLAGS $CXXFLAGS"
1997+
echo " LDFLAGS = $PTHREAD_LIBS $HARDENED_LDFLAGS $GPROF_LDFLAGS $SANITIZER_LDFLAGS $CORE_LDFLAGS $LDFLAGS"
20011998
echo " AR = $AR"
20021999
echo " ARFLAGS = $ARFLAGS"
20032000
echo

src/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ print-%: FORCE
99
DIST_SUBDIRS = secp256k1
1010

1111
AM_LDFLAGS = $(LIBTOOL_LDFLAGS) $(HARDENED_LDFLAGS) $(GPROF_LDFLAGS) $(SANITIZER_LDFLAGS) $(CORE_LDFLAGS)
12-
AM_CXXFLAGS = $(DEBUG_CXXFLAGS) $(HARDENED_CXXFLAGS) $(WARN_CXXFLAGS) $(NOWARN_CXXFLAGS) $(ERROR_CXXFLAGS) $(GPROF_CXXFLAGS) $(SANITIZER_CXXFLAGS) $(CORE_CXXFLAGS)
12+
AM_CXXFLAGS = $(CORE_CXXFLAGS) $(DEBUG_CXXFLAGS) $(HARDENED_CXXFLAGS) $(WARN_CXXFLAGS) $(NOWARN_CXXFLAGS) $(ERROR_CXXFLAGS) $(GPROF_CXXFLAGS) $(SANITIZER_CXXFLAGS)
1313
AM_CPPFLAGS = $(DEBUG_CPPFLAGS) $(HARDENED_CPPFLAGS) $(CORE_CPPFLAGS)
1414
AM_LIBTOOLFLAGS = --preserve-dup-deps
1515
PTHREAD_FLAGS = $(PTHREAD_CFLAGS) $(PTHREAD_LIBS)

0 commit comments

Comments
 (0)