diff options
| author | Brent Cook <busterb@gmail.com> | 2015-05-01 07:18:12 -0500 |
|---|---|---|
| committer | Brent Cook <busterb@gmail.com> | 2015-05-23 19:27:57 -0500 |
| commit | d3771a41cb106c945e0f538073d0a6e7b35d145b (patch) | |
| tree | 0ec81fcb0eae37fc7f1f89e2a7d1de26e54d35d2 | |
| parent | 28353c1df15c3d0482a10ffe33fa34c053af2c2e (diff) | |
| download | portable-d3771a41cb106c945e0f538073d0a6e7b35d145b.tar.gz portable-d3771a41cb106c945e0f538073d0a6e7b35d145b.tar.bz2 portable-d3771a41cb106c945e0f538073d0a6e7b35d145b.zip | |
refactor configure into separate m4 macros
this allows for some reusability with libtls
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | configure.ac | 295 | ||||
| -rw-r--r-- | m4/check-hardening-options.m4 | 109 | ||||
| -rw-r--r-- | m4/check-libc.m4 | 65 | ||||
| -rw-r--r-- | m4/check-os-options.m4 | 77 | ||||
| -rw-r--r-- | m4/disable-compiler-warnings.m4 | 29 |
6 files changed, 314 insertions, 264 deletions
| @@ -68,7 +68,8 @@ autom4te.cache | |||
| 68 | # Libtool adds these, at least sometimes | 68 | # Libtool adds these, at least sometimes |
| 69 | INSTALL | 69 | INSTALL |
| 70 | COPYING | 70 | COPYING |
| 71 | m4 | 71 | m4/l* |
| 72 | !m4/check*.m4 | ||
| 72 | 73 | ||
| 73 | aclocal.m4 | 74 | aclocal.m4 |
| 74 | compile | 75 | compile |
diff --git a/configure.ac b/configure.ac index 42b1189..0c71d91 100644 --- a/configure.ac +++ b/configure.ac | |||
| @@ -1,3 +1,17 @@ | |||
| 1 | # Copyright (c) 2014-2015 Brent Cook | ||
| 2 | # | ||
| 3 | # Permission to use, copy, modify, and distribute this software for any | ||
| 4 | # purpose with or without fee is hereby granted, provided that the above | ||
| 5 | # copyright notice and this permission notice appear in all copies. | ||
| 6 | # | ||
| 7 | # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 8 | # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 9 | # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 10 | # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 11 | # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 12 | # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 13 | # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 14 | |||
| 1 | AC_INIT([libressl], m4_esyscmd([tr -d '\n' < VERSION])) | 15 | AC_INIT([libressl], m4_esyscmd([tr -d '\n' < VERSION])) |
| 2 | AC_SUBST([LIBCRYPTO_VERSION], m4_esyscmd([tr -d '\n' < crypto/VERSION])) | 16 | AC_SUBST([LIBCRYPTO_VERSION], m4_esyscmd([tr -d '\n' < crypto/VERSION])) |
| 3 | AC_SUBST([LIBSSL_VERSION], m4_esyscmd([tr -d '\n' < ssl/VERSION])) | 17 | AC_SUBST([LIBSSL_VERSION], m4_esyscmd([tr -d '\n' < ssl/VERSION])) |
| @@ -9,7 +23,7 @@ AC_CONFIG_MACRO_DIR([m4]) | |||
| 9 | 23 | ||
| 10 | m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) | 24 | m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) |
| 11 | 25 | ||
| 12 | # This must be called before AC_PROG_CC | 26 | # This must be saved before AC_PROG_CC |
| 13 | USER_CFLAGS="$CFLAGS" | 27 | USER_CFLAGS="$CFLAGS" |
| 14 | 28 | ||
| 15 | AC_PROG_CC | 29 | AC_PROG_CC |
| @@ -18,272 +32,25 @@ AM_PROG_CC_C_O | |||
| 18 | AC_PROG_LIBTOOL | 32 | AC_PROG_LIBTOOL |
| 19 | LT_INIT | 33 | LT_INIT |
| 20 | 34 | ||
| 21 | CFLAGS="$CFLAGS -Wall -std=gnu99" | 35 | CHECK_OS_OPTIONS |
| 22 | |||
| 23 | case $host_os in | ||
| 24 | *aix*) | ||
| 25 | HOST_OS=aix | ||
| 26 | if test "`echo $CC | cut -d ' ' -f 1`" != "gcc" ; then | ||
| 27 | CFLAGS="$USER_CFLAGS" | ||
| 28 | fi | ||
| 29 | AC_SUBST([PLATFORM_LDADD], ['-lperfstat -lpthread']) | ||
| 30 | ;; | ||
| 31 | *cygwin*) | ||
| 32 | HOST_OS=cygwin | ||
| 33 | ;; | ||
| 34 | *darwin*) | ||
| 35 | HOST_OS=darwin | ||
| 36 | HOST_ABI=macosx | ||
| 37 | ;; | ||
| 38 | *freebsd*) | ||
| 39 | HOST_OS=freebsd | ||
| 40 | HOST_ABI=elf | ||
| 41 | AC_SUBST([PROG_LDADD], ['-lthr']) | ||
| 42 | ;; | ||
| 43 | *hpux*) | ||
| 44 | HOST_OS=hpux; | ||
| 45 | if test "`echo $CC | cut -d ' ' -f 1`" = "gcc" ; then | ||
| 46 | CFLAGS="$CFLAGS -mlp64" | ||
| 47 | else | ||
| 48 | CFLAGS="-g -O2 +DD64 $USER_CFLAGS" | ||
| 49 | fi | ||
| 50 | CPPFLAGS="$CPPFLAGS -D_XOPEN_SOURCE=600 -D__STRICT_ALIGNMENT" | ||
| 51 | AC_SUBST([PLATFORM_LDADD], ['-lpthread']) | ||
| 52 | ;; | ||
| 53 | *linux*) | ||
| 54 | HOST_OS=linux | ||
| 55 | HOST_ABI=elf | ||
| 56 | CPPFLAGS="$CPPFLAGS -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_SOURCE -D_GNU_SOURCE" | ||
| 57 | ;; | ||
| 58 | *netbsd*) | ||
| 59 | HOST_OS=netbsd | ||
| 60 | CPPFLAGS="$CPPFLAGS -D_OPENBSD_SOURCE" | ||
| 61 | ;; | ||
| 62 | *openbsd* | *bitrig*) | ||
| 63 | HOST_ABI=elf | ||
| 64 | AC_DEFINE([HAVE_ATTRIBUTE__BOUNDED__], [1], [OpenBSD gcc has bounded]) | ||
| 65 | ;; | ||
| 66 | *mingw*) | ||
| 67 | HOST_OS=win | ||
| 68 | CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE -D_POSIX -D_POSIX_SOURCE -D__USE_MINGW_ANSI_STDIO" | ||
| 69 | CPPFLAGS="$CPPFLAGS -D_REENTRANT -D_POSIX_THREAD_SAFE_FUNCTIONS" | ||
| 70 | CPPFLAGS="$CPPFLAGS -DWIN32_LEAN_AND_MEAN -D_WIN32_WINNT=0x0600" | ||
| 71 | CPPFLAGS="$CPPFLAGS -DOPENSSL_NO_SPEED -DNO_SYSLOG" | ||
| 72 | CFLAGS="$CFLAGS -static-libgcc" | ||
| 73 | LDFLAGS="$LDFLAGS -static-libgcc" | ||
| 74 | AC_SUBST([PLATFORM_LDADD], ['-lws2_32']) | ||
| 75 | ;; | ||
| 76 | *solaris*) | ||
| 77 | HOST_OS=solaris | ||
| 78 | HOST_ABI=elf | ||
| 79 | CPPFLAGS="$CPPFLAGS -D__EXTENSIONS__ -D_XOPEN_SOURCE=600 -DBSD_COMP" | ||
| 80 | AC_SUBST([PLATFORM_LDADD], ['-lnsl -lsocket']) | ||
| 81 | ;; | ||
| 82 | *) ;; | ||
| 83 | esac | ||
| 84 | |||
| 85 | AM_CONDITIONAL([HOST_AIX], [test x$HOST_OS = xaix]) | ||
| 86 | AM_CONDITIONAL([HOST_CYGWIN], [test x$HOST_OS = xcygwin]) | ||
| 87 | AM_CONDITIONAL([HOST_DARWIN], [test x$HOST_OS = xdarwin]) | ||
| 88 | AM_CONDITIONAL([HOST_FREEBSD], [test x$HOST_OS = xfreebsd]) | ||
| 89 | AM_CONDITIONAL([HOST_HPUX], [test x$HOST_OS = xhpux]) | ||
| 90 | AM_CONDITIONAL([HOST_LINUX], [test x$HOST_OS = xlinux]) | ||
| 91 | AM_CONDITIONAL([HOST_NETBSD], [test x$HOST_OS = xnetbsd]) | ||
| 92 | AM_CONDITIONAL([HOST_SOLARIS], [test x$HOST_OS = xsolaris]) | ||
| 93 | AM_CONDITIONAL([HOST_WIN], [test x$HOST_OS = xwin]) | ||
| 94 | |||
| 95 | AC_CHECK_FUNC([clock_gettime],, | ||
| 96 | [AC_SEARCH_LIBS([clock_gettime],[rt posix4])]) | ||
| 97 | |||
| 98 | AC_CHECK_FUNC([dl_iterate_phdr],, | ||
| 99 | [AC_SEARCH_LIBS([dl_iterate_phdr],[dl])]) | ||
| 100 | |||
| 101 | AC_MSG_CHECKING([if compiling with clang]) | ||
| 102 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[ | ||
| 103 | #ifndef __clang__ | ||
| 104 | not clang | ||
| 105 | #endif | ||
| 106 | ]])], | ||
| 107 | [CLANG=yes], | ||
| 108 | [CLANG=no] | ||
| 109 | ) | ||
| 110 | AC_MSG_RESULT([$CLANG]) | ||
| 111 | AS_IF([test "x$CLANG" = "xyes"], [CLANG_FLAGS=-Qunused-arguments]) | ||
| 112 | |||
| 113 | CFLAGS="$CFLAGS $CLANG_FLAGS" | ||
| 114 | LDFLAGS="$LDFLAGS $CLANG_FLAGS" | ||
| 115 | |||
| 116 | # We want to check for compiler flag support. Prior to clang v5.1, there was no | ||
| 117 | # way to make clang's "argument unused" warning fatal. So we invoke the | ||
| 118 | # compiler through a wrapper script that greps for this message. | ||
| 119 | saved_CC="$CC" | ||
| 120 | saved_LD="$LD" | ||
| 121 | flag_wrap="$srcdir/scripts/wrap-compiler-for-flag-check" | ||
| 122 | CC="$flag_wrap $CC" | ||
| 123 | LD="$flag_wrap $LD" | ||
| 124 | |||
| 125 | AC_ARG_ENABLE([hardening], | ||
| 126 | [AS_HELP_STRING([--disable-hardening], | ||
| 127 | [Disable options to frustrate memory corruption exploits])], | ||
| 128 | [], [enable_hardening=yes]) | ||
| 129 | |||
| 130 | AC_ARG_ENABLE([windows-ssp], | ||
| 131 | [AS_HELP_STRING([--enable-windows-ssp], | ||
| 132 | [Enable building the stack smashing protection on | ||
| 133 | Windows. This currently distributing libssp-0.dll.])]) | ||
| 134 | |||
| 135 | AC_DEFUN([CHECK_CFLAG], [ | ||
| 136 | AC_LANG_ASSERT(C) | ||
| 137 | AC_MSG_CHECKING([if $saved_CC supports "$1"]) | ||
| 138 | old_cflags="$CFLAGS" | ||
| 139 | CFLAGS="$1 -Wall -Werror" | ||
| 140 | AC_TRY_LINK([ | ||
| 141 | #include <stdio.h> | ||
| 142 | ], | ||
| 143 | [printf("Hello")], | ||
| 144 | AC_MSG_RESULT([yes]) | ||
| 145 | CFLAGS=$old_cflags | ||
| 146 | HARDEN_CFLAGS="$HARDEN_CFLAGS $1", | ||
| 147 | AC_MSG_RESULT([no]) | ||
| 148 | CFLAGS=$old_cflags | ||
| 149 | [$2]) | ||
| 150 | ]) | ||
| 151 | |||
| 152 | AC_DEFUN([CHECK_LDFLAG], [ | ||
| 153 | AC_LANG_ASSERT(C) | ||
| 154 | AC_MSG_CHECKING([if $saved_LD supports "$1"]) | ||
| 155 | old_ldflags="$LDFLAGS" | ||
| 156 | LDFLAGS="$1 -Wall -Werror" | ||
| 157 | AC_TRY_LINK([ | ||
| 158 | #include <stdio.h> | ||
| 159 | ], | ||
| 160 | [printf("Hello")], | ||
| 161 | AC_MSG_RESULT([yes]) | ||
| 162 | LDFLAGS=$old_ldflags | ||
| 163 | HARDEN_LDFLAGS="$HARDEN_LDFLAGS $1", | ||
| 164 | AC_MSG_RESULT([no]) | ||
| 165 | LDFLAGS=$old_ldflags | ||
| 166 | [$2]) | ||
| 167 | ]) | ||
| 168 | |||
| 169 | AS_IF([test "x$enable_hardening" = "xyes"], [ | ||
| 170 | # Tell GCC to NOT optimize based on signed arithmetic overflow | ||
| 171 | CHECK_CFLAG([[-fno-strict-overflow]]) | ||
| 172 | |||
| 173 | # _FORTIFY_SOURCE replaces builtin functions with safer versions. | ||
| 174 | CHECK_CFLAG([[-D_FORTIFY_SOURCE=2]]) | ||
| 175 | |||
| 176 | # Enable read only relocations | ||
| 177 | CHECK_LDFLAG([[-Wl,-z,relro]]) | ||
| 178 | CHECK_LDFLAG([[-Wl,-z,now]]) | ||
| 179 | |||
| 180 | # Windows security flags | ||
| 181 | AS_IF([test "x$HOST_OS" = "xwin"], [ | ||
| 182 | CHECK_LDFLAG([[-Wl,--nxcompat]]) | ||
| 183 | CHECK_LDFLAG([[-Wl,--dynamicbase]]) | ||
| 184 | CHECK_LDFLAG([[-Wl,--high-entropy-va]]) | ||
| 185 | ]) | ||
| 186 | |||
| 187 | # Use stack-protector-strong if available; if not, fallback to | ||
| 188 | # stack-protector-all which is considered to be overkill | ||
| 189 | AS_IF([test "x$enable_windows_ssp" = "xyes" -o "x$HOST_OS" != "xwin"], [ | ||
| 190 | CHECK_CFLAG([[-fstack-protector-strong]], | ||
| 191 | CHECK_CFLAG([[-fstack-protector-all]], | ||
| 192 | AC_MSG_WARN([compiler does not appear to support stack protection]) | ||
| 193 | ) | ||
| 194 | ) | ||
| 195 | AS_IF([test "x$HOST_OS" = "xwin"], [ | ||
| 196 | AC_SEARCH_LIBS([__stack_chk_guard],[ssp]) | ||
| 197 | ]) | ||
| 198 | ]) | ||
| 199 | ]) | ||
| 200 | 36 | ||
| 37 | CHECK_C_HARDENING_OPTIONS | ||
| 201 | 38 | ||
| 202 | # Restore CC, LD | 39 | DISABLE_AS_EXECUTABLE_STACK |
| 203 | CC="$saved_CC" | ||
| 204 | LD="$saved_LD" | ||
| 205 | |||
| 206 | CFLAGS="$CFLAGS $HARDEN_CFLAGS" | ||
| 207 | LDFLAGS="$LDFLAGS $HARDEN_LDFLAGS" | ||
| 208 | |||
| 209 | # Removing the dependency on -Wno-pointer-sign should be a goal | ||
| 210 | save_cflags="$CFLAGS" | ||
| 211 | CFLAGS=-Wno-pointer-sign | ||
| 212 | AC_MSG_CHECKING([whether CC supports -Wno-pointer-sign]) | ||
| 213 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], | ||
| 214 | [AC_MSG_RESULT([yes])] | ||
| 215 | [AM_CFLAGS=-Wno-pointer-sign], | ||
| 216 | [AC_MSG_RESULT([no])] | ||
| 217 | ) | ||
| 218 | CFLAGS="$save_cflags $AM_CFLAGS" | ||
| 219 | |||
| 220 | save_cflags="$CFLAGS" | ||
| 221 | CFLAGS= | ||
| 222 | AC_MSG_CHECKING([whether AS supports .note.GNU-stack]) | ||
| 223 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ | ||
| 224 | __asm__(".section .note.GNU-stack,\"\",@progbits");]])], | ||
| 225 | [AC_MSG_RESULT([yes])] | ||
| 226 | [AM_CFLAGS=-DHAVE_GNU_STACK], | ||
| 227 | [AC_MSG_RESULT([no])] | ||
| 228 | ) | ||
| 229 | CFLAGS="$save_cflags $AM_CFLAGS" | ||
| 230 | AM_PROG_AS | 40 | AM_PROG_AS |
| 231 | 41 | ||
| 232 | AC_CHECK_FUNCS([arc4random_buf asprintf explicit_bzero funopen getauxval]) | 42 | DISABLE_COMPILER_WARNINGS |
| 233 | AC_CHECK_FUNCS([getentropy memmem poll reallocarray]) | ||
| 234 | AC_CHECK_FUNCS([strlcat strlcpy strndup strnlen strsep strtonum]) | ||
| 235 | AC_CHECK_FUNCS([symlink]) | ||
| 236 | AC_CHECK_FUNCS([timingsafe_bcmp timingsafe_memcmp]) | ||
| 237 | 43 | ||
| 238 | # Share test results with automake | 44 | # Check if the certhash command should be built |
| 239 | AM_CONDITIONAL([HAVE_ARC4RANDOM_BUF], [test "x$ac_cv_func_arc4random_buf" = xyes]) | 45 | AC_CHECK_FUNCS([symlink]) |
| 240 | AM_CONDITIONAL([HAVE_ASPRINTF], [test "x$ac_cv_func_asprintf" = xyes]) | ||
| 241 | AM_CONDITIONAL([HAVE_EXPLICIT_BZERO], [test "x$ac_cv_func_explicit_bzero" = xyes]) | ||
| 242 | AM_CONDITIONAL([HAVE_GETENTROPY], [test "x$ac_cv_func_getentropy" = xyes]) | ||
| 243 | AM_CONDITIONAL([HAVE_MEMMEM], [test "x$ac_cv_func_memmem" = xyes]) | ||
| 244 | AM_CONDITIONAL([HAVE_POLL], [test "x$ac_cv_func_poll" = xyes]) | ||
| 245 | AM_CONDITIONAL([HAVE_REALLOCARRAY], [test "x$ac_cv_func_reallocarray" = xyes]) | ||
| 246 | AM_CONDITIONAL([HAVE_STRLCAT], [test "x$ac_cv_func_strlcat" = xyes]) | ||
| 247 | AM_CONDITIONAL([HAVE_STRLCPY], [test "x$ac_cv_func_strlcpy" = xyes]) | ||
| 248 | AM_CONDITIONAL([HAVE_STRNDUP], [test "x$ac_cv_func_strndup" = xyes]) | ||
| 249 | AM_CONDITIONAL([HAVE_STRNLEN], [test "x$ac_cv_func_strnlen" = xyes]) | ||
| 250 | AM_CONDITIONAL([HAVE_STRSEP], [test "x$ac_cv_func_strsep" = xyes]) | ||
| 251 | AM_CONDITIONAL([HAVE_STRTONUM], [test "x$ac_cv_func_strtonum" = xyes]) | ||
| 252 | AM_CONDITIONAL([HAVE_TIMINGSAFE_BCMP], [test "x$ac_cv_func_timingsafe_bcmp" = xyes]) | ||
| 253 | AM_CONDITIONAL([HAVE_TIMINGSAFE_MEMCMP], [test "x$ac_cv_func_timingsafe_memcmp" = xyes]) | ||
| 254 | AM_CONDITIONAL([BUILD_CERTHASH], [test "x$ac_cv_func_symlink" = xyes]) | 46 | AM_CONDITIONAL([BUILD_CERTHASH], [test "x$ac_cv_func_symlink" = xyes]) |
| 255 | 47 | ||
| 256 | # overrides for arc4random_buf implementations with known issues | 48 | # Check if funopen exists |
| 257 | AM_CONDITIONAL([HAVE_ARC4RANDOM_BUF], | 49 | AC_CHECK_FUNC([funopen]) |
| 258 | [test "x$HOST_OS" != xdarwin \ | ||
| 259 | -a "x$HOST_OS" != xfreebsd \ | ||
| 260 | -a "x$HOST_OS" != xnetbsd \ | ||
| 261 | -a "x$ac_cv_func_arc4random_buf" = xyes]) | ||
| 262 | |||
| 263 | AC_CACHE_CHECK([whether va_copy exists], ac_cv_have_va_copy, [ | ||
| 264 | AC_LINK_IFELSE([AC_LANG_PROGRAM([[ | ||
| 265 | #include <stdarg.h> | ||
| 266 | va_list x,y; | ||
| 267 | ]], [[ va_copy(x,y); ]])], | ||
| 268 | [ ac_cv_have_va_copy="yes" ], | ||
| 269 | [ ac_cv_have_va_copy="no" | ||
| 270 | ]) | ||
| 271 | ]) | ||
| 272 | if test "x$ac_cv_have_va_copy" = "xyes" ; then | ||
| 273 | AC_DEFINE([HAVE_VA_COPY], [1], [Define if va_copy exists]) | ||
| 274 | fi | ||
| 275 | 50 | ||
| 276 | AC_CACHE_CHECK([whether __va_copy exists], ac_cv_have___va_copy, [ | 51 | CHECK_LIBC_COMPAT |
| 277 | AC_LINK_IFELSE([AC_LANG_PROGRAM([[ | 52 | CHECK_LIBC_CRYPTO_COMPAT |
| 278 | #include <stdarg.h> | 53 | CHECK_VA_COPY |
| 279 | va_list x,y; | ||
| 280 | ]], [[ __va_copy(x,y); ]])], | ||
| 281 | [ ac_cv_have___va_copy="yes" ], [ ac_cv_have___va_copy="no" | ||
| 282 | ]) | ||
| 283 | ]) | ||
| 284 | if test "x$ac_cv_have___va_copy" = "xyes" ; then | ||
| 285 | AC_DEFINE([HAVE___VA_COPY], [1], [Define if __va_copy exists]) | ||
| 286 | fi | ||
| 287 | 54 | ||
| 288 | AC_CHECK_HEADERS([err.h]) | 55 | AC_CHECK_HEADERS([err.h]) |
| 289 | 56 | ||
| @@ -299,14 +66,11 @@ AC_ARG_WITH([enginesdir], | |||
| 299 | AC_DEFINE_UNQUOTED(ENGINESDIR, "$withval") | 66 | AC_DEFINE_UNQUOTED(ENGINESDIR, "$withval") |
| 300 | ) | 67 | ) |
| 301 | 68 | ||
| 302 | AC_ARG_ENABLE([asm], | ||
| 303 | AS_HELP_STRING([--disable-asm], [Disable assembly])) | ||
| 304 | AM_CONDITIONAL([OPENSSL_NO_ASM], [test "x$enable_asm" = "xno"]) | ||
| 305 | |||
| 306 | AC_ARG_ENABLE([extratests], | 69 | AC_ARG_ENABLE([extratests], |
| 307 | AS_HELP_STRING([--enable-extratests], [Enable extra tests that may be unreliable on some platforms])) | 70 | AS_HELP_STRING([--enable-extratests], [Enable extra tests that may be unreliable on some platforms])) |
| 308 | AM_CONDITIONAL([ENABLE_EXTRATESTS], [test "x$enable_extratests" = xyes]) | 71 | AM_CONDITIONAL([ENABLE_EXTRATESTS], [test "x$enable_extratests" = xyes]) |
| 309 | 72 | ||
| 73 | # Add CPU-specific alignment flags | ||
| 310 | old_cflags=$CFLAGS | 74 | old_cflags=$CFLAGS |
| 311 | CFLAGS="$CFLAGS -I$srcdir/include" | 75 | CFLAGS="$CFLAGS -I$srcdir/include" |
| 312 | AC_MSG_CHECKING([if BSWAP4 builds without __STRICT_ALIGNMENT]) | 76 | AC_MSG_CHECKING([if BSWAP4 builds without __STRICT_ALIGNMENT]) |
| @@ -328,6 +92,11 @@ case $host_cpu in | |||
| 328 | ;; | 92 | ;; |
| 329 | esac | 93 | esac |
| 330 | 94 | ||
| 95 | AC_ARG_ENABLE([asm], | ||
| 96 | AS_HELP_STRING([--disable-asm], [Disable assembly])) | ||
| 97 | AM_CONDITIONAL([OPENSSL_NO_ASM], [test "x$enable_asm" = "xno"]) | ||
| 98 | |||
| 99 | # Conditionally enable assembly by default | ||
| 331 | AM_CONDITIONAL([HOST_ASM_ELF_X86_64], | 100 | AM_CONDITIONAL([HOST_ASM_ELF_X86_64], |
| 332 | [test "x$HOST_ABI" = "xelf" -a "$host_cpu" = "x86_64" -a "x$enable_asm" != "xno"]) | 101 | [test "x$HOST_ABI" = "xelf" -a "$host_cpu" = "x86_64" -a "x$enable_asm" != "xno"]) |
| 333 | AM_CONDITIONAL([HOST_ASM_MACOSX_X86_64], | 102 | AM_CONDITIONAL([HOST_ASM_MACOSX_X86_64], |
diff --git a/m4/check-hardening-options.m4 b/m4/check-hardening-options.m4 new file mode 100644 index 0000000..255038e --- /dev/null +++ b/m4/check-hardening-options.m4 | |||
| @@ -0,0 +1,109 @@ | |||
| 1 | |||
| 2 | AC_DEFUN([CHECK_CFLAG], [ | ||
| 3 | AC_LANG_ASSERT(C) | ||
| 4 | AC_MSG_CHECKING([if $saved_CC supports "$1"]) | ||
| 5 | old_cflags="$CFLAGS" | ||
| 6 | CFLAGS="$1 -Wall -Werror" | ||
| 7 | AC_TRY_LINK([ | ||
| 8 | #include <stdio.h> | ||
| 9 | ], | ||
| 10 | [printf("Hello")], | ||
| 11 | AC_MSG_RESULT([yes]) | ||
| 12 | CFLAGS=$old_cflags | ||
| 13 | HARDEN_CFLAGS="$HARDEN_CFLAGS $1", | ||
| 14 | AC_MSG_RESULT([no]) | ||
| 15 | CFLAGS=$old_cflags | ||
| 16 | [$2]) | ||
| 17 | ]) | ||
| 18 | |||
| 19 | AC_DEFUN([CHECK_LDFLAG], [ | ||
| 20 | AC_LANG_ASSERT(C) | ||
| 21 | AC_MSG_CHECKING([if $saved_LD supports "$1"]) | ||
| 22 | old_ldflags="$LDFLAGS" | ||
| 23 | LDFLAGS="$1 -Wall -Werror" | ||
| 24 | AC_TRY_LINK([ | ||
| 25 | #include <stdio.h> | ||
| 26 | ], | ||
| 27 | [printf("Hello")], | ||
| 28 | AC_MSG_RESULT([yes]) | ||
| 29 | LDFLAGS=$old_ldflags | ||
| 30 | HARDEN_LDFLAGS="$HARDEN_LDFLAGS $1", | ||
| 31 | AC_MSG_RESULT([no]) | ||
| 32 | LDFLAGS=$old_ldflags | ||
| 33 | [$2]) | ||
| 34 | ]) | ||
| 35 | |||
| 36 | AC_DEFUN([DISABLE_AS_EXECUTABLE_STACK] [ | ||
| 37 | save_cflags="$CFLAGS" | ||
| 38 | CFLAGS= | ||
| 39 | AC_MSG_CHECKING([whether AS supports .note.GNU-stack]) | ||
| 40 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ | ||
| 41 | __asm__(".section .note.GNU-stack,\"\",@progbits");]])], | ||
| 42 | [AC_MSG_RESULT([yes])] | ||
| 43 | [AM_CFLAGS=-DHAVE_GNU_STACK], | ||
| 44 | [AC_MSG_RESULT([no])] | ||
| 45 | ) | ||
| 46 | CFLAGS="$save_cflags $AM_CFLAGS" | ||
| 47 | ]) | ||
| 48 | |||
| 49 | |||
| 50 | AC_DEFUN([CHECK_C_HARDENING_OPTIONS], [ | ||
| 51 | |||
| 52 | AC_ARG_ENABLE([hardening], | ||
| 53 | [AS_HELP_STRING([--disable-hardening], | ||
| 54 | [Disable options to frustrate memory corruption exploits])], | ||
| 55 | [], [enable_hardening=yes]) | ||
| 56 | |||
| 57 | AC_ARG_ENABLE([windows-ssp], | ||
| 58 | [AS_HELP_STRING([--enable-windows-ssp], | ||
| 59 | [Enable building the stack smashing protection on | ||
| 60 | Windows. This currently distributing libssp-0.dll.])]) | ||
| 61 | |||
| 62 | # We want to check for compiler flag support. Prior to clang v5.1, there was no | ||
| 63 | # way to make clang's "argument unused" warning fatal. So we invoke the | ||
| 64 | # compiler through a wrapper script that greps for this message. | ||
| 65 | saved_CC="$CC" | ||
| 66 | saved_LD="$LD" | ||
| 67 | flag_wrap="$srcdir/scripts/wrap-compiler-for-flag-check" | ||
| 68 | CC="$flag_wrap $CC" | ||
| 69 | LD="$flag_wrap $LD" | ||
| 70 | |||
| 71 | AS_IF([test "x$enable_hardening" = "xyes"], [ | ||
| 72 | # Tell GCC to NOT optimize based on signed arithmetic overflow | ||
| 73 | CHECK_CFLAG([[-fno-strict-overflow]]) | ||
| 74 | |||
| 75 | # _FORTIFY_SOURCE replaces builtin functions with safer versions. | ||
| 76 | CHECK_CFLAG([[-D_FORTIFY_SOURCE=2]]) | ||
| 77 | |||
| 78 | # Enable read only relocations | ||
| 79 | CHECK_LDFLAG([[-Wl,-z,relro]]) | ||
| 80 | CHECK_LDFLAG([[-Wl,-z,now]]) | ||
| 81 | |||
| 82 | # Windows security flags | ||
| 83 | AS_IF([test "x$HOST_OS" = "xwin"], [ | ||
| 84 | CHECK_LDFLAG([[-Wl,--nxcompat]]) | ||
| 85 | CHECK_LDFLAG([[-Wl,--dynamicbase]]) | ||
| 86 | CHECK_LDFLAG([[-Wl,--high-entropy-va]]) | ||
| 87 | ]) | ||
| 88 | |||
| 89 | # Use stack-protector-strong if available; if not, fallback to | ||
| 90 | # stack-protector-all which is considered to be overkill | ||
| 91 | AS_IF([test "x$enable_windows_ssp" = "xyes" -o "x$HOST_OS" != "xwin"], [ | ||
| 92 | CHECK_CFLAG([[-fstack-protector-strong]], | ||
| 93 | CHECK_CFLAG([[-fstack-protector-all]], | ||
| 94 | AC_MSG_WARN([compiler does not appear to support stack protection]) | ||
| 95 | ) | ||
| 96 | ) | ||
| 97 | AS_IF([test "x$HOST_OS" = "xwin"], [ | ||
| 98 | AC_SEARCH_LIBS([__stack_chk_guard],[ssp]) | ||
| 99 | ]) | ||
| 100 | ]) | ||
| 101 | ]) | ||
| 102 | |||
| 103 | # Restore CC, LD | ||
| 104 | CC="$saved_CC" | ||
| 105 | LD="$saved_LD" | ||
| 106 | |||
| 107 | CFLAGS="$CFLAGS $HARDEN_CFLAGS" | ||
| 108 | LDFLAGS="$LDFLAGS $HARDEN_LDFLAGS" | ||
| 109 | ]) | ||
diff --git a/m4/check-libc.m4 b/m4/check-libc.m4 new file mode 100644 index 0000000..2bbfb81 --- /dev/null +++ b/m4/check-libc.m4 | |||
| @@ -0,0 +1,65 @@ | |||
| 1 | AC_DEFUN([CHECK_LIBC_COMPAT], [ | ||
| 2 | # Check for general libc functions | ||
| 3 | AC_CHECK_FUNCS([asprintf memmem poll reallocarray]) | ||
| 4 | AC_CHECK_FUNCS([strlcat strlcpy strndup strnlen strsep strtonum]) | ||
| 5 | AM_CONDITIONAL([HAVE_ASPRINTF], [test "x$ac_cv_func_asprintf" = xyes]) | ||
| 6 | AM_CONDITIONAL([HAVE_MEMMEM], [test "x$ac_cv_func_memmem" = xyes]) | ||
| 7 | AM_CONDITIONAL([HAVE_POLL], [test "x$ac_cv_func_poll" = xyes]) | ||
| 8 | AM_CONDITIONAL([HAVE_REALLOCARRAY], [test "x$ac_cv_func_reallocarray" = xyes]) | ||
| 9 | AM_CONDITIONAL([HAVE_STRLCAT], [test "x$ac_cv_func_strlcat" = xyes]) | ||
| 10 | AM_CONDITIONAL([HAVE_STRLCPY], [test "x$ac_cv_func_strlcpy" = xyes]) | ||
| 11 | AM_CONDITIONAL([HAVE_STRNDUP], [test "x$ac_cv_func_strndup" = xyes]) | ||
| 12 | AM_CONDITIONAL([HAVE_STRNLEN], [test "x$ac_cv_func_strnlen" = xyes]) | ||
| 13 | AM_CONDITIONAL([HAVE_STRSEP], [test "x$ac_cv_func_strsep" = xyes]) | ||
| 14 | AM_CONDITIONAL([HAVE_STRTONUM], [test "x$ac_cv_func_strtonum" = xyes]) | ||
| 15 | ]) | ||
| 16 | |||
| 17 | AC_DEFUN([CHECK_LIBC_CRYPTO_COMPAT], [ | ||
| 18 | # Check crypto-related libc functions | ||
| 19 | AC_CHECK_FUNCS([arc4random_buf explicit_bzero getauxval getentropy]) | ||
| 20 | AC_CHECK_FUNCS([timingsafe_bcmp timingsafe_memcmp]) | ||
| 21 | AM_CONDITIONAL([HAVE_ARC4RANDOM_BUF], [test "x$ac_cv_func_arc4random_buf" = xyes]) | ||
| 22 | AM_CONDITIONAL([HAVE_EXPLICIT_BZERO], [test "x$ac_cv_func_explicit_bzero" = xyes]) | ||
| 23 | AM_CONDITIONAL([HAVE_GETENTROPY], [test "x$ac_cv_func_getentropy" = xyes]) | ||
| 24 | AM_CONDITIONAL([HAVE_TIMINGSAFE_BCMP], [test "x$ac_cv_func_timingsafe_bcmp" = xyes]) | ||
| 25 | AM_CONDITIONAL([HAVE_TIMINGSAFE_MEMCMP], [test "x$ac_cv_func_timingsafe_memcmp" = xyes]) | ||
| 26 | |||
| 27 | # Override arc4random_buf implementations with known issues | ||
| 28 | AM_CONDITIONAL([HAVE_ARC4RANDOM_BUF], | ||
| 29 | [test "x$HOST_OS" != xdarwin \ | ||
| 30 | -a "x$HOST_OS" != xfreebsd \ | ||
| 31 | -a "x$HOST_OS" != xnetbsd \ | ||
| 32 | -a "x$ac_cv_func_arc4random_buf" = xyes]) | ||
| 33 | |||
| 34 | # Check for getentropy fallback dependencies | ||
| 35 | AC_CHECK_FUNC([getauxval]) | ||
| 36 | AC_CHECK_FUNC([clock_gettime],, [AC_SEARCH_LIBS([clock_gettime],[rt posix4])]) | ||
| 37 | AC_CHECK_FUNC([dl_iterate_phdr],, [AC_SEARCH_LIBS([dl_iterate_phdr],[dl])]) | ||
| 38 | ]) | ||
| 39 | |||
| 40 | AC_DEFUN([CHECK_VA_COPY], [ | ||
| 41 | AC_CACHE_CHECK([whether va_copy exists], ac_cv_have_va_copy, [ | ||
| 42 | AC_LINK_IFELSE([AC_LANG_PROGRAM([[ | ||
| 43 | #include <stdarg.h> | ||
| 44 | va_list x,y; | ||
| 45 | ]], [[ va_copy(x,y); ]])], | ||
| 46 | [ ac_cv_have_va_copy="yes" ], | ||
| 47 | [ ac_cv_have_va_copy="no" | ||
| 48 | ]) | ||
| 49 | ]) | ||
| 50 | if test "x$ac_cv_have_va_copy" = "xyes" ; then | ||
| 51 | AC_DEFINE([HAVE_VA_COPY], [1], [Define if va_copy exists]) | ||
| 52 | fi | ||
| 53 | |||
| 54 | AC_CACHE_CHECK([whether __va_copy exists], ac_cv_have___va_copy, [ | ||
| 55 | AC_LINK_IFELSE([AC_LANG_PROGRAM([[ | ||
| 56 | #include <stdarg.h> | ||
| 57 | va_list x,y; | ||
| 58 | ]], [[ __va_copy(x,y); ]])], | ||
| 59 | [ ac_cv_have___va_copy="yes" ], [ ac_cv_have___va_copy="no" | ||
| 60 | ]) | ||
| 61 | ]) | ||
| 62 | if test "x$ac_cv_have___va_copy" = "xyes" ; then | ||
| 63 | AC_DEFINE([HAVE___VA_COPY], [1], [Define if __va_copy exists]) | ||
| 64 | fi | ||
| 65 | ]) | ||
diff --git a/m4/check-os-options.m4 b/m4/check-os-options.m4 new file mode 100644 index 0000000..e4e5364 --- /dev/null +++ b/m4/check-os-options.m4 | |||
| @@ -0,0 +1,77 @@ | |||
| 1 | # This must be called before AC_PROG_CC | ||
| 2 | AC_DEFUN([CHECK_OS_OPTIONS], [ | ||
| 3 | |||
| 4 | CFLAGS="$CFLAGS -Wall -std=gnu99" | ||
| 5 | |||
| 6 | case $host_os in | ||
| 7 | *aix*) | ||
| 8 | HOST_OS=aix | ||
| 9 | if test "`echo $CC | cut -d ' ' -f 1`" != "gcc" ; then | ||
| 10 | CFLAGS="$USER_CFLAGS" | ||
| 11 | fi | ||
| 12 | AC_SUBST([PLATFORM_LDADD], ['-lperfstat -lpthread']) | ||
| 13 | ;; | ||
| 14 | *cygwin*) | ||
| 15 | HOST_OS=cygwin | ||
| 16 | ;; | ||
| 17 | *darwin*) | ||
| 18 | HOST_OS=darwin | ||
| 19 | HOST_ABI=macosx | ||
| 20 | ;; | ||
| 21 | *freebsd*) | ||
| 22 | HOST_OS=freebsd | ||
| 23 | HOST_ABI=elf | ||
| 24 | AC_SUBST([PROG_LDADD], ['-lthr']) | ||
| 25 | ;; | ||
| 26 | *hpux*) | ||
| 27 | HOST_OS=hpux; | ||
| 28 | if test "`echo $CC | cut -d ' ' -f 1`" = "gcc" ; then | ||
| 29 | CFLAGS="$CFLAGS -mlp64" | ||
| 30 | else | ||
| 31 | CFLAGS="-g -O2 +DD64 $USER_CFLAGS" | ||
| 32 | fi | ||
| 33 | CPPFLAGS="$CPPFLAGS -D_XOPEN_SOURCE=600 -D__STRICT_ALIGNMENT" | ||
| 34 | AC_SUBST([PLATFORM_LDADD], ['-lpthread']) | ||
| 35 | ;; | ||
| 36 | *linux*) | ||
| 37 | HOST_OS=linux | ||
| 38 | HOST_ABI=elf | ||
| 39 | CPPFLAGS="$CPPFLAGS -D_DEFAULT_SOURCE -D_BSD_SOURCE -D_POSIX_SOURCE -D_GNU_SOURCE" | ||
| 40 | ;; | ||
| 41 | *netbsd*) | ||
| 42 | HOST_OS=netbsd | ||
| 43 | CPPFLAGS="$CPPFLAGS -D_OPENBSD_SOURCE" | ||
| 44 | ;; | ||
| 45 | *openbsd* | *bitrig*) | ||
| 46 | HOST_ABI=elf | ||
| 47 | AC_DEFINE([HAVE_ATTRIBUTE__BOUNDED__], [1], [OpenBSD gcc has bounded]) | ||
| 48 | ;; | ||
| 49 | *mingw*) | ||
| 50 | HOST_OS=win | ||
| 51 | CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE -D_POSIX -D_POSIX_SOURCE -D__USE_MINGW_ANSI_STDIO" | ||
| 52 | CPPFLAGS="$CPPFLAGS -D_REENTRANT -D_POSIX_THREAD_SAFE_FUNCTIONS" | ||
| 53 | CPPFLAGS="$CPPFLAGS -DWIN32_LEAN_AND_MEAN -D_WIN32_WINNT=0x0600" | ||
| 54 | CPPFLAGS="$CPPFLAGS -DOPENSSL_NO_SPEED -DNO_SYSLOG" | ||
| 55 | CFLAGS="$CFLAGS -static-libgcc" | ||
| 56 | LDFLAGS="$LDFLAGS -static-libgcc" | ||
| 57 | AC_SUBST([PLATFORM_LDADD], ['-lws2_32']) | ||
| 58 | ;; | ||
| 59 | *solaris*) | ||
| 60 | HOST_OS=solaris | ||
| 61 | HOST_ABI=elf | ||
| 62 | CPPFLAGS="$CPPFLAGS -D__EXTENSIONS__ -D_XOPEN_SOURCE=600 -DBSD_COMP" | ||
| 63 | AC_SUBST([PLATFORM_LDADD], ['-lnsl -lsocket']) | ||
| 64 | ;; | ||
| 65 | *) ;; | ||
| 66 | esac | ||
| 67 | |||
| 68 | AM_CONDITIONAL([HOST_AIX], [test x$HOST_OS = xaix]) | ||
| 69 | AM_CONDITIONAL([HOST_CYGWIN], [test x$HOST_OS = xcygwin]) | ||
| 70 | AM_CONDITIONAL([HOST_DARWIN], [test x$HOST_OS = xdarwin]) | ||
| 71 | AM_CONDITIONAL([HOST_FREEBSD], [test x$HOST_OS = xfreebsd]) | ||
| 72 | AM_CONDITIONAL([HOST_HPUX], [test x$HOST_OS = xhpux]) | ||
| 73 | AM_CONDITIONAL([HOST_LINUX], [test x$HOST_OS = xlinux]) | ||
| 74 | AM_CONDITIONAL([HOST_NETBSD], [test x$HOST_OS = xnetbsd]) | ||
| 75 | AM_CONDITIONAL([HOST_SOLARIS], [test x$HOST_OS = xsolaris]) | ||
| 76 | AM_CONDITIONAL([HOST_WIN], [test x$HOST_OS = xwin]) | ||
| 77 | ]) | ||
diff --git a/m4/disable-compiler-warnings.m4 b/m4/disable-compiler-warnings.m4 new file mode 100644 index 0000000..2792722 --- /dev/null +++ b/m4/disable-compiler-warnings.m4 | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | AC_DEFUN([DISABLE_COMPILER_WARNINGS], [ | ||
| 2 | # Clang throws a lot of warnings when it does not understand a flag. Disable | ||
| 3 | # this warning for now so other warnings are visible. | ||
| 4 | AC_MSG_CHECKING([if compiling with clang]) | ||
| 5 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[ | ||
| 6 | #ifndef __clang__ | ||
| 7 | not clang | ||
| 8 | #endif | ||
| 9 | ]])], | ||
| 10 | [CLANG=yes], | ||
| 11 | [CLANG=no] | ||
| 12 | ) | ||
| 13 | AC_MSG_RESULT([$CLANG]) | ||
| 14 | AS_IF([test "x$CLANG" = "xyes"], [CLANG_FLAGS=-Qunused-arguments]) | ||
| 15 | CFLAGS="$CFLAGS $CLANG_FLAGS" | ||
| 16 | LDFLAGS="$LDFLAGS $CLANG_FLAGS" | ||
| 17 | |||
| 18 | # Removing the dependency on -Wno-pointer-sign should be a goal. These are | ||
| 19 | # largely unsigned char */char* mismatches in asn1 functions. | ||
| 20 | save_cflags="$CFLAGS" | ||
| 21 | CFLAGS=-Wno-pointer-sign | ||
| 22 | AC_MSG_CHECKING([whether CC supports -Wno-pointer-sign]) | ||
| 23 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])], | ||
| 24 | [AC_MSG_RESULT([yes])] | ||
| 25 | [AM_CFLAGS=-Wno-pointer-sign], | ||
| 26 | [AC_MSG_RESULT([no])] | ||
| 27 | ) | ||
| 28 | CFLAGS="$save_cflags $AM_CFLAGS" | ||
| 29 | ]) | ||
