From 1c277a88509fbab3a2184a1e772ae9a5d90d9660 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Thu, 13 Jul 2017 14:13:01 +0200 Subject: [PATCH] configure: check for hardening compiler options If no CFLAGS are specified, check if common security hardening options are supported and add them to the CFLAGS/LDFLAGS. These are typically enabled in downstream packages, but users compiling chrony from sources with default CFLAGS should get hardened binaries too. --- configure | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/configure b/configure index 5d2ed7a..b762e0d 100755 --- a/configure +++ b/configure @@ -518,6 +518,22 @@ fi if [ "x$MYCFLAGS" = "x" ]; then MYCFLAGS="-O2 -g" + + TESTCFLAGS="-D_FORTIFY_SOURCE=2 -fPIE" + TESTLDFLAGS="-pie -Wl,-z,relro,-z,now" + if test_code 'hardening compiler options' '' "$TESTCFLAGS" "$TESTLDFLAGS" ''; then + MYCFLAGS="$MYCFLAGS $TESTCFLAGS" + MYLDFLAGS="$MYLDFLAGS $TESTLDFLAGS" + fi + TESTCFLAGS="-fstack-protector-strong --param=ssp-buffer-size=4" + if test_code '-fstack-protector-strong' '' "$TESTCFLAGS" '' ''; then + MYCFLAGS="$MYCFLAGS $TESTCFLAGS" + else + TESTCFLAGS="-fstack-protector --param=ssp-buffer-size=4" + if test_code '-fstack-protector' '' "$TESTCFLAGS" '' ''; then + MYCFLAGS="$MYCFLAGS $TESTCFLAGS" + fi + fi fi if [ "x$MYCC" = "xgcc" ] || [ "x$MYCC" = "xclang" ]; then