aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrent Cook <busterb@gmail.com>2015-05-01 07:18:12 -0500
committerBrent Cook <busterb@gmail.com>2015-05-23 19:27:57 -0500
commitd3771a41cb106c945e0f538073d0a6e7b35d145b (patch)
tree0ec81fcb0eae37fc7f1f89e2a7d1de26e54d35d2
parent28353c1df15c3d0482a10ffe33fa34c053af2c2e (diff)
downloadportable-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--.gitignore3
-rw-r--r--configure.ac295
-rw-r--r--m4/check-hardening-options.m4109
-rw-r--r--m4/check-libc.m465
-rw-r--r--m4/check-os-options.m477
-rw-r--r--m4/disable-compiler-warnings.m429
6 files changed, 314 insertions, 264 deletions
diff --git a/.gitignore b/.gitignore
index 5c62f55..290088b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -68,7 +68,8 @@ autom4te.cache
68# Libtool adds these, at least sometimes 68# Libtool adds these, at least sometimes
69INSTALL 69INSTALL
70COPYING 70COPYING
71m4 71m4/l*
72!m4/check*.m4
72 73
73aclocal.m4 74aclocal.m4
74compile 75compile
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
1AC_INIT([libressl], m4_esyscmd([tr -d '\n' < VERSION])) 15AC_INIT([libressl], m4_esyscmd([tr -d '\n' < VERSION]))
2AC_SUBST([LIBCRYPTO_VERSION], m4_esyscmd([tr -d '\n' < crypto/VERSION])) 16AC_SUBST([LIBCRYPTO_VERSION], m4_esyscmd([tr -d '\n' < crypto/VERSION]))
3AC_SUBST([LIBSSL_VERSION], m4_esyscmd([tr -d '\n' < ssl/VERSION])) 17AC_SUBST([LIBSSL_VERSION], m4_esyscmd([tr -d '\n' < ssl/VERSION]))
@@ -9,7 +23,7 @@ AC_CONFIG_MACRO_DIR([m4])
9 23
10m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) 24m4_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
13USER_CFLAGS="$CFLAGS" 27USER_CFLAGS="$CFLAGS"
14 28
15AC_PROG_CC 29AC_PROG_CC
@@ -18,272 +32,25 @@ AM_PROG_CC_C_O
18AC_PROG_LIBTOOL 32AC_PROG_LIBTOOL
19LT_INIT 33LT_INIT
20 34
21CFLAGS="$CFLAGS -Wall -std=gnu99" 35CHECK_OS_OPTIONS
22
23case $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 *) ;;
83esac
84
85AM_CONDITIONAL([HOST_AIX], [test x$HOST_OS = xaix])
86AM_CONDITIONAL([HOST_CYGWIN], [test x$HOST_OS = xcygwin])
87AM_CONDITIONAL([HOST_DARWIN], [test x$HOST_OS = xdarwin])
88AM_CONDITIONAL([HOST_FREEBSD], [test x$HOST_OS = xfreebsd])
89AM_CONDITIONAL([HOST_HPUX], [test x$HOST_OS = xhpux])
90AM_CONDITIONAL([HOST_LINUX], [test x$HOST_OS = xlinux])
91AM_CONDITIONAL([HOST_NETBSD], [test x$HOST_OS = xnetbsd])
92AM_CONDITIONAL([HOST_SOLARIS], [test x$HOST_OS = xsolaris])
93AM_CONDITIONAL([HOST_WIN], [test x$HOST_OS = xwin])
94
95AC_CHECK_FUNC([clock_gettime],,
96 [AC_SEARCH_LIBS([clock_gettime],[rt posix4])])
97
98AC_CHECK_FUNC([dl_iterate_phdr],,
99 [AC_SEARCH_LIBS([dl_iterate_phdr],[dl])])
100
101AC_MSG_CHECKING([if compiling with clang])
102AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
103#ifndef __clang__
104 not clang
105#endif
106 ]])],
107 [CLANG=yes],
108 [CLANG=no]
109)
110AC_MSG_RESULT([$CLANG])
111AS_IF([test "x$CLANG" = "xyes"], [CLANG_FLAGS=-Qunused-arguments])
112
113CFLAGS="$CFLAGS $CLANG_FLAGS"
114LDFLAGS="$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.
119saved_CC="$CC"
120saved_LD="$LD"
121flag_wrap="$srcdir/scripts/wrap-compiler-for-flag-check"
122CC="$flag_wrap $CC"
123LD="$flag_wrap $LD"
124
125AC_ARG_ENABLE([hardening],
126 [AS_HELP_STRING([--disable-hardening],
127 [Disable options to frustrate memory corruption exploits])],
128 [], [enable_hardening=yes])
129
130AC_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
135AC_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
152AC_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
169AS_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
37CHECK_C_HARDENING_OPTIONS
201 38
202# Restore CC, LD 39DISABLE_AS_EXECUTABLE_STACK
203CC="$saved_CC"
204LD="$saved_LD"
205
206CFLAGS="$CFLAGS $HARDEN_CFLAGS"
207LDFLAGS="$LDFLAGS $HARDEN_LDFLAGS"
208
209# Removing the dependency on -Wno-pointer-sign should be a goal
210save_cflags="$CFLAGS"
211CFLAGS=-Wno-pointer-sign
212AC_MSG_CHECKING([whether CC supports -Wno-pointer-sign])
213AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
214 [AC_MSG_RESULT([yes])]
215 [AM_CFLAGS=-Wno-pointer-sign],
216 [AC_MSG_RESULT([no])]
217)
218CFLAGS="$save_cflags $AM_CFLAGS"
219
220save_cflags="$CFLAGS"
221CFLAGS=
222AC_MSG_CHECKING([whether AS supports .note.GNU-stack])
223AC_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)
229CFLAGS="$save_cflags $AM_CFLAGS"
230AM_PROG_AS 40AM_PROG_AS
231 41
232AC_CHECK_FUNCS([arc4random_buf asprintf explicit_bzero funopen getauxval]) 42DISABLE_COMPILER_WARNINGS
233AC_CHECK_FUNCS([getentropy memmem poll reallocarray])
234AC_CHECK_FUNCS([strlcat strlcpy strndup strnlen strsep strtonum])
235AC_CHECK_FUNCS([symlink])
236AC_CHECK_FUNCS([timingsafe_bcmp timingsafe_memcmp])
237 43
238# Share test results with automake 44# Check if the certhash command should be built
239AM_CONDITIONAL([HAVE_ARC4RANDOM_BUF], [test "x$ac_cv_func_arc4random_buf" = xyes]) 45AC_CHECK_FUNCS([symlink])
240AM_CONDITIONAL([HAVE_ASPRINTF], [test "x$ac_cv_func_asprintf" = xyes])
241AM_CONDITIONAL([HAVE_EXPLICIT_BZERO], [test "x$ac_cv_func_explicit_bzero" = xyes])
242AM_CONDITIONAL([HAVE_GETENTROPY], [test "x$ac_cv_func_getentropy" = xyes])
243AM_CONDITIONAL([HAVE_MEMMEM], [test "x$ac_cv_func_memmem" = xyes])
244AM_CONDITIONAL([HAVE_POLL], [test "x$ac_cv_func_poll" = xyes])
245AM_CONDITIONAL([HAVE_REALLOCARRAY], [test "x$ac_cv_func_reallocarray" = xyes])
246AM_CONDITIONAL([HAVE_STRLCAT], [test "x$ac_cv_func_strlcat" = xyes])
247AM_CONDITIONAL([HAVE_STRLCPY], [test "x$ac_cv_func_strlcpy" = xyes])
248AM_CONDITIONAL([HAVE_STRNDUP], [test "x$ac_cv_func_strndup" = xyes])
249AM_CONDITIONAL([HAVE_STRNLEN], [test "x$ac_cv_func_strnlen" = xyes])
250AM_CONDITIONAL([HAVE_STRSEP], [test "x$ac_cv_func_strsep" = xyes])
251AM_CONDITIONAL([HAVE_STRTONUM], [test "x$ac_cv_func_strtonum" = xyes])
252AM_CONDITIONAL([HAVE_TIMINGSAFE_BCMP], [test "x$ac_cv_func_timingsafe_bcmp" = xyes])
253AM_CONDITIONAL([HAVE_TIMINGSAFE_MEMCMP], [test "x$ac_cv_func_timingsafe_memcmp" = xyes])
254AM_CONDITIONAL([BUILD_CERTHASH], [test "x$ac_cv_func_symlink" = xyes]) 46AM_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
257AM_CONDITIONAL([HAVE_ARC4RANDOM_BUF], 49AC_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
263AC_CACHE_CHECK([whether va_copy exists], ac_cv_have_va_copy, [
264 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
265#include <stdarg.h>
266va_list x,y;
267 ]], [[ va_copy(x,y); ]])],
268 [ ac_cv_have_va_copy="yes" ],
269 [ ac_cv_have_va_copy="no"
270 ])
271])
272if test "x$ac_cv_have_va_copy" = "xyes" ; then
273 AC_DEFINE([HAVE_VA_COPY], [1], [Define if va_copy exists])
274fi
275 50
276AC_CACHE_CHECK([whether __va_copy exists], ac_cv_have___va_copy, [ 51CHECK_LIBC_COMPAT
277 AC_LINK_IFELSE([AC_LANG_PROGRAM([[ 52CHECK_LIBC_CRYPTO_COMPAT
278#include <stdarg.h> 53CHECK_VA_COPY
279va_list x,y;
280 ]], [[ __va_copy(x,y); ]])],
281 [ ac_cv_have___va_copy="yes" ], [ ac_cv_have___va_copy="no"
282 ])
283])
284if test "x$ac_cv_have___va_copy" = "xyes" ; then
285 AC_DEFINE([HAVE___VA_COPY], [1], [Define if __va_copy exists])
286fi
287 54
288AC_CHECK_HEADERS([err.h]) 55AC_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
302AC_ARG_ENABLE([asm],
303 AS_HELP_STRING([--disable-asm], [Disable assembly]))
304AM_CONDITIONAL([OPENSSL_NO_ASM], [test "x$enable_asm" = "xno"])
305
306AC_ARG_ENABLE([extratests], 69AC_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]))
308AM_CONDITIONAL([ENABLE_EXTRATESTS], [test "x$enable_extratests" = xyes]) 71AM_CONDITIONAL([ENABLE_EXTRATESTS], [test "x$enable_extratests" = xyes])
309 72
73# Add CPU-specific alignment flags
310old_cflags=$CFLAGS 74old_cflags=$CFLAGS
311CFLAGS="$CFLAGS -I$srcdir/include" 75CFLAGS="$CFLAGS -I$srcdir/include"
312AC_MSG_CHECKING([if BSWAP4 builds without __STRICT_ALIGNMENT]) 76AC_MSG_CHECKING([if BSWAP4 builds without __STRICT_ALIGNMENT])
@@ -328,6 +92,11 @@ case $host_cpu in
328 ;; 92 ;;
329esac 93esac
330 94
95AC_ARG_ENABLE([asm],
96 AS_HELP_STRING([--disable-asm], [Disable assembly]))
97AM_CONDITIONAL([OPENSSL_NO_ASM], [test "x$enable_asm" = "xno"])
98
99# Conditionally enable assembly by default
331AM_CONDITIONAL([HOST_ASM_ELF_X86_64], 100AM_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"])
333AM_CONDITIONAL([HOST_ASM_MACOSX_X86_64], 102AM_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
2AC_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
19AC_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
36AC_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
50AC_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 @@
1AC_DEFUN([CHECK_LIBC_COMPAT], [
2# Check for general libc functions
3AC_CHECK_FUNCS([asprintf memmem poll reallocarray])
4AC_CHECK_FUNCS([strlcat strlcpy strndup strnlen strsep strtonum])
5AM_CONDITIONAL([HAVE_ASPRINTF], [test "x$ac_cv_func_asprintf" = xyes])
6AM_CONDITIONAL([HAVE_MEMMEM], [test "x$ac_cv_func_memmem" = xyes])
7AM_CONDITIONAL([HAVE_POLL], [test "x$ac_cv_func_poll" = xyes])
8AM_CONDITIONAL([HAVE_REALLOCARRAY], [test "x$ac_cv_func_reallocarray" = xyes])
9AM_CONDITIONAL([HAVE_STRLCAT], [test "x$ac_cv_func_strlcat" = xyes])
10AM_CONDITIONAL([HAVE_STRLCPY], [test "x$ac_cv_func_strlcpy" = xyes])
11AM_CONDITIONAL([HAVE_STRNDUP], [test "x$ac_cv_func_strndup" = xyes])
12AM_CONDITIONAL([HAVE_STRNLEN], [test "x$ac_cv_func_strnlen" = xyes])
13AM_CONDITIONAL([HAVE_STRSEP], [test "x$ac_cv_func_strsep" = xyes])
14AM_CONDITIONAL([HAVE_STRTONUM], [test "x$ac_cv_func_strtonum" = xyes])
15])
16
17AC_DEFUN([CHECK_LIBC_CRYPTO_COMPAT], [
18# Check crypto-related libc functions
19AC_CHECK_FUNCS([arc4random_buf explicit_bzero getauxval getentropy])
20AC_CHECK_FUNCS([timingsafe_bcmp timingsafe_memcmp])
21AM_CONDITIONAL([HAVE_ARC4RANDOM_BUF], [test "x$ac_cv_func_arc4random_buf" = xyes])
22AM_CONDITIONAL([HAVE_EXPLICIT_BZERO], [test "x$ac_cv_func_explicit_bzero" = xyes])
23AM_CONDITIONAL([HAVE_GETENTROPY], [test "x$ac_cv_func_getentropy" = xyes])
24AM_CONDITIONAL([HAVE_TIMINGSAFE_BCMP], [test "x$ac_cv_func_timingsafe_bcmp" = xyes])
25AM_CONDITIONAL([HAVE_TIMINGSAFE_MEMCMP], [test "x$ac_cv_func_timingsafe_memcmp" = xyes])
26
27# Override arc4random_buf implementations with known issues
28AM_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
35AC_CHECK_FUNC([getauxval])
36AC_CHECK_FUNC([clock_gettime],, [AC_SEARCH_LIBS([clock_gettime],[rt posix4])])
37AC_CHECK_FUNC([dl_iterate_phdr],, [AC_SEARCH_LIBS([dl_iterate_phdr],[dl])])
38])
39
40AC_DEFUN([CHECK_VA_COPY], [
41AC_CACHE_CHECK([whether va_copy exists], ac_cv_have_va_copy, [
42 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
43#include <stdarg.h>
44va_list x,y;
45 ]], [[ va_copy(x,y); ]])],
46 [ ac_cv_have_va_copy="yes" ],
47 [ ac_cv_have_va_copy="no"
48 ])
49])
50if test "x$ac_cv_have_va_copy" = "xyes" ; then
51 AC_DEFINE([HAVE_VA_COPY], [1], [Define if va_copy exists])
52fi
53
54AC_CACHE_CHECK([whether __va_copy exists], ac_cv_have___va_copy, [
55 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
56#include <stdarg.h>
57va_list x,y;
58 ]], [[ __va_copy(x,y); ]])],
59 [ ac_cv_have___va_copy="yes" ], [ ac_cv_have___va_copy="no"
60 ])
61])
62if test "x$ac_cv_have___va_copy" = "xyes" ; then
63 AC_DEFINE([HAVE___VA_COPY], [1], [Define if __va_copy exists])
64fi
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
2AC_DEFUN([CHECK_OS_OPTIONS], [
3
4CFLAGS="$CFLAGS -Wall -std=gnu99"
5
6case $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 *) ;;
66esac
67
68AM_CONDITIONAL([HOST_AIX], [test x$HOST_OS = xaix])
69AM_CONDITIONAL([HOST_CYGWIN], [test x$HOST_OS = xcygwin])
70AM_CONDITIONAL([HOST_DARWIN], [test x$HOST_OS = xdarwin])
71AM_CONDITIONAL([HOST_FREEBSD], [test x$HOST_OS = xfreebsd])
72AM_CONDITIONAL([HOST_HPUX], [test x$HOST_OS = xhpux])
73AM_CONDITIONAL([HOST_LINUX], [test x$HOST_OS = xlinux])
74AM_CONDITIONAL([HOST_NETBSD], [test x$HOST_OS = xnetbsd])
75AM_CONDITIONAL([HOST_SOLARIS], [test x$HOST_OS = xsolaris])
76AM_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 @@
1AC_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.
4AC_MSG_CHECKING([if compiling with clang])
5AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
6#ifndef __clang__
7 not clang
8#endif
9 ]])],
10 [CLANG=yes],
11 [CLANG=no]
12)
13AC_MSG_RESULT([$CLANG])
14AS_IF([test "x$CLANG" = "xyes"], [CLANG_FLAGS=-Qunused-arguments])
15CFLAGS="$CFLAGS $CLANG_FLAGS"
16LDFLAGS="$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.
20save_cflags="$CFLAGS"
21CFLAGS=-Wno-pointer-sign
22AC_MSG_CHECKING([whether CC supports -Wno-pointer-sign])
23AC_COMPILE_IFELSE([AC_LANG_PROGRAM([])],
24 [AC_MSG_RESULT([yes])]
25 [AM_CFLAGS=-Wno-pointer-sign],
26 [AC_MSG_RESULT([no])]
27)
28CFLAGS="$save_cflags $AM_CFLAGS"
29])