aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrent Cook <busterb@gmail.com>2015-01-05 20:31:34 -0600
committerBrent Cook <bcook@openbsd.org>2015-01-05 20:59:53 -0600
commit872ecfd856b120347508bf66c492609d1536d256 (patch)
treefc09bb47bc2844273f096ca1cdc8b4152a5f2363
parent303b972d554493e0be1c63061500f730ca88e4a8 (diff)
downloadportable-872ecfd856b120347508bf66c492609d1536d256.tar.gz
portable-872ecfd856b120347508bf66c492609d1536d256.tar.bz2
portable-872ecfd856b120347508bf66c492609d1536d256.zip
preserve CFLAGS between hardening checks, enable mingw
Allow hardening CFLAGS for mingw that do not cause link-time failures. Add proper quoting on flags for commas Check LDFLAGS for linker-only flags.
-rw-r--r--configure.ac72
1 files changed, 46 insertions, 26 deletions
diff --git a/configure.ac b/configure.ac
index a9f8b6e..bee17af 100644
--- a/configure.ac
+++ b/configure.ac
@@ -95,40 +95,60 @@ AC_ARG_ENABLE([hardening],
95 [], [enable_hardening=yes]) 95 [], [enable_hardening=yes])
96 96
97AC_DEFUN([CHECK_CFLAG], 97AC_DEFUN([CHECK_CFLAG],
98 [AC_LANG_ASSERT(C) 98 AC_LANG_ASSERT(C)
99 AC_MSG_CHECKING([if $saved_CC supports "$1"]) 99 AC_MSG_CHECKING([if $saved_CC supports "$1"])
100 old_cflags="$CFLAGS" 100 old_cflags="$CFLAGS"
101 CFLAGS=[$1] 101 CFLAGS=$1
102 AC_TRY_LINK([#include <stdio.h>], 102 AC_TRY_LINK([
103 [printf("Hello")], 103 #include <stdio.h>
104 AC_MSG_RESULT([yes]) 104 ],
105 HARDEN_CFLAGS="$HARDEN_CFLAGS [$1]", 105 [printf("Hello")],
106 AC_MSG_RESULT([no]) 106 AC_MSG_RESULT([yes])
107 $2 107 HARDEN_CFLAGS="$HARDEN_CFLAGS $1",
108 ) 108 AC_MSG_RESULT([no])
109 ]) 109 $2)
110 CFLAGS=$old_cflags
111)
110 112
111AS_IF([test "x$enable_hardening" == "xyes" -a "x$HOST_OS" != "xwin"], [ 113AC_DEFUN([CHECK_LDFLAG],
114 AC_LANG_ASSERT(C)
115 AC_MSG_CHECKING([if $saved_LD supports "$1"])
116 old_ldflags="$LDFLAGS"
117 LDFLAGS=$1
118 AC_TRY_LINK([
119 #include <stdio.h>
120 ],
121 [printf("Hello")],
122 AC_MSG_RESULT([yes])
123 HARDEN_LDFLAGS="$HARDEN_LDFLAGS $1",
124 AC_MSG_RESULT([no])
125 $2)
126 LDFLAGS=$old_ldflags
127)
128
129AS_IF([test "x$enable_hardening" == "xyes"], [
112 # Tell GCC to NOT optimize based on signed arithmetic overflow 130 # Tell GCC to NOT optimize based on signed arithmetic overflow
113 CHECK_CFLAG([-fno-strict-overflow]) 131 CHECK_CFLAG([[-fno-strict-overflow]])
114 132
115 # _FORTIFY_SOURCE replaces builtin functions with safer versions. 133 # _FORTIFY_SOURCE replaces builtin functions with safer versions.
116 CHECK_CFLAG([-D_FORTIFY_SOURCE=2]) 134 CHECK_CFLAG([[-D_FORTIFY_SOURCE=2]])
117
118 # Use stack-protector-strong if available; if not, fallback to
119 # stack-protector-all which is considered to be overkill
120 CHECK_CFLAG([-fstack-protector-strong],
121 CHECK_CFLAG([-fstack-protector-all],
122 AC_MSG_ERROR([compiler does appear to support stack protection
123 - use --disable-hardening to override])
124 )
125 )
126 135
127 # Enable read only relocations 136 # Enable read only relocations
128 CHECK_CFLAG([-Wl,-z,relro]) 137 CHECK_LDFLAG([[-Wl,-z,relro]])
129 CHECK_CFLAG([-Wl,-z,now]) 138 CHECK_LDFLAG([[-Wl,-z,now]])
130]) 139])
131 140
141# Use stack-protector-strong if available; if not, fallback to
142# stack-protector-all which is considered to be overkill
143AS_IF([test "x$enable_hardening" == "xyes" -a "x$HOST_OS" != "xwin"], [
144 CHECK_CFLAG([[-fstack-protector-strong]],
145 CHECK_CFLAG([[-fstack-protector-all]],
146 AC_MSG_ERROR([compiler does appear to support stack protection - use --disable-hardening to override])
147 )
148 )
149])
150
151
132# Restore CC, LD 152# Restore CC, LD
133CC="$saved_CC" 153CC="$saved_CC"
134LD="$saved_LD" 154LD="$saved_LD"