]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
configure: check for hardening compiler options
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 13 Jul 2017 12:13:01 +0000 (14:13 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 13 Jul 2017 14:12:25 +0000 (16:12 +0200)
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

index 5d2ed7a103405463f1e06acef6996f8f68735513..b762e0da175cadc53b2f887e8599271ead8a1707 100755 (executable)
--- 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