Cherry-picked (and rebased) 94189645e67f364c4445d62e2b00c282d885cbbf from the "up for grabs" PR: "[build] Make --enable-debug pick better options" (#12695).
See previous review in #12695.
Cherry-picked (and rebased) 94189645e67f364c4445d62e2b00c282d885cbbf from the "up for grabs" PR: "[build] Make --enable-debug pick better options" (#12695).
See previous review in #12695.
Various changes:
* Don't check $GCC and $GXX
* Prefer -Og instead of -O0
* If -g3 isn't available, use -g
This also incidentally fixes compiler warnings with GCC and glibc when using
--enable-debug, as the old default values mixed poorly with the hardening flags.
One small thing that needs to be fixed before merge is that CPPFLAGS, CXXFLAGS and LDFLAGS gets stuffed with redundant spaces when printing which looks a bit messy:
$ ./configure
…
CC = gcc
CFLAGS = -g -O2
CPPFLAGS = -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS
CXX = g++ -std=c++11
CXXFLAGS = -Wstack-protector -fstack-protector-all -g -O2 -Wall -Wextra -Wformat -Wvla -Wformat-security -Wno-unused-parameter
LDFLAGS = -pthread -Wl,-z,relro -Wl,-z,now -pie
ARFLAGS = cr
I'll find a way to fix that.
Added a commit fixing the annoying extra whitespace:
$ ./configure
…
CC = gcc
CFLAGS = -g -O2
CPPFLAGS = -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS
CXX = g++ -std=c++11
CXXFLAGS = -Wstack-protector -fstack-protector-all -g -O2 -Wall -Wextra -Wformat -Wvla -Wformat-security -Wno-unused-parameter
LDFLAGS = -pthread -Wl,-z,relro -Wl,-z,now -pie
ARFLAGS = cr
Please review :-)
utACK 8a0ad1a2333b329d6eb8d34a25277181ee675f23. The first commit is just rebased and has no changes since my previous review in the other PR. The second commit is new and looks ok, though I think the echo_joined function is overkill. I think you should just drop quotes around the variables and let the shell collapse spaces:
echo " CXXFLAGS =" $DEBUG_CXXFLAGS $HARDENED_CXXFLAGS $ERROR_CXXFLAGS $CXXFLAGS
Agree with @ryanofsky about echo_joined. I'd prefer to just drop the second commit. utACK otherwise.
Apologies, I was travelling without access to my laptop while this was put up for grabs. This seems fine but I think we came to the conclusion that we should not try to join the output, which was where my first commit was at. We can fix the whitespace formatting in another pass using AX_APPEND_COMPILE_FLAGS.
@eklitzke Good idea about fixing the whitespace with AX_APPEND_COMPILE_FLAGS. Could you help with a diff for that?
@practicalswift That's worth handling in a separate PR. It will be a pretty huge diff.
@practicalswift From reading the above discussion, and on the original PR, you still need to drop the second commit. Then this can be reviewed, and a follow-up PR can introduce the AX_APPEND_FLAG / AX_APPEND_COMPILE_FLAGS changes.
@fanquake Updated! Please re-review! :-)
re-utACK 9e49db2426cd4508d9dd95c7461e107bab7fd7de
250 | + # Prefer -Og, fall back to -O0 if that is unavailable. 251 | + AX_CHECK_COMPILE_FLAG( 252 | + [-Og], 253 | + [[DEBUG_CXXFLAGS="$DEBUG_CXXFLAGS -Og"]], 254 | + [AX_CHECK_COMPILE_FLAG([-O0],[[DEBUG_CXXFLAGS="$DEBUG_CXXFLAGS -O0"]],,[[$CXXFLAG_WERROR]])], 255 | + [[$CXXFLAG_WERROR]])
What if -Og and -O0 are unavailable? (Both of these may compromise spectre mitigations, so I have my x86 compiler not support them at all)
Good question! @eklitzke, what do you say? :-)
I'd prefer making this -O1. Completely un-optimized code barely resembles anything that ever gets run, and macro/inline expansions make it hard to deal with anyway.