Skip to content

Commit ee47461

Browse files
committed
Merge #17033: Disable _FORTIFY_SOURCE when enable-debug
44f7a8d Disable _FORTIFY_SOURCE when enable-debug (Andrew Chow) Pull request description: The `_FORTIFY_SOURCE` macro is enabled by default when hardening is enabled, but it requires optimization in order to be used. Since we disable all optimization with `--enable-debug`, this macro doesn't actually do anything and instead just causes a lot of warnings to be printed. This PR explicitly disables `_FORTIFY_SOURCE` so that these useless warnings aren't printed. ACKs for top commit: laanwj: Thanks. ACK 44f7a8d Tree-SHA512: e9302aef794dfd9ca9d0d032179ecc51d3212a9a0204454419f410011343b27c32e6be05f385051b5b594c607b91b8e0e588f644584d6684429a649a413077d9
2 parents b544eb6 + 44f7a8d commit ee47461

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

configure.ac

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -753,12 +753,17 @@ if test x$use_hardening != xno; then
753753
AX_CHECK_COMPILE_FLAG([-Wstack-protector],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -Wstack-protector"])
754754
AX_CHECK_COMPILE_FLAG([-fstack-protector-all],[HARDENED_CXXFLAGS="$HARDENED_CXXFLAGS -fstack-protector-all"])
755755

756-
AX_CHECK_PREPROC_FLAG([-D_FORTIFY_SOURCE=2],[
757-
AX_CHECK_PREPROC_FLAG([-U_FORTIFY_SOURCE],[
758-
HARDENED_CPPFLAGS="$HARDENED_CPPFLAGS -U_FORTIFY_SOURCE"
756+
# When enable_debug is yes, all optimizations are disabled.
757+
# However, FORTIFY_SOURCE requires that there is some level of optimization, otherwise it does nothing and just creates a compiler warning.
758+
# Since FORTIFY_SOURCE is a no-op without optimizations, do not enable it when enable_debug is yes.
759+
if test x$enable_debug != xyes; then
760+
AX_CHECK_PREPROC_FLAG([-D_FORTIFY_SOURCE=2],[
761+
AX_CHECK_PREPROC_FLAG([-U_FORTIFY_SOURCE],[
762+
HARDENED_CPPFLAGS="$HARDENED_CPPFLAGS -U_FORTIFY_SOURCE"
763+
])
764+
HARDENED_CPPFLAGS="$HARDENED_CPPFLAGS -D_FORTIFY_SOURCE=2"
759765
])
760-
HARDENED_CPPFLAGS="$HARDENED_CPPFLAGS -D_FORTIFY_SOURCE=2"
761-
])
766+
fi
762767

763768
AX_CHECK_LINK_FLAG([[-Wl,--dynamicbase]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,--dynamicbase"])
764769
AX_CHECK_LINK_FLAG([[-Wl,--nxcompat]], [HARDENED_LDFLAGS="$HARDENED_LDFLAGS -Wl,--nxcompat"])

0 commit comments

Comments
 (0)