2 dnl # Enabled -fsanitize=address if supported by $CC.
4 dnl # LDFLAGS needs -fsanitize=address at all times so libraries compiled with
5 dnl # it will be linked successfully. CFLAGS will vary by binary being built.
7 dnl # The ASAN_OPTIONS environment variable can be used to further control
8 dnl # the behavior of binaries and libraries build with -fsanitize=address.
10 AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_ASAN], [
11 AC_MSG_CHECKING([whether to build with -fsanitize=address support])
13 [AS_HELP_STRING([--enable-asan],
14 [Enable -fsanitize=address support @<:@default=no@:>@])],
18 AM_CONDITIONAL([ASAN_ENABLED], [test x$enable_asan = xyes])
19 AC_SUBST([ASAN_ENABLED], [$enable_asan])
20 AC_MSG_RESULT($enable_asan)
22 AS_IF([ test "$enable_asan" = "yes" ], [
23 AC_MSG_CHECKING([whether $CC supports -fsanitize=address])
24 saved_cflags="$CFLAGS"
25 CFLAGS="$CFLAGS -Werror -fsanitize=address"
27 AC_LANG_SOURCE([[ int main() { return 0; } ]])
29 ASAN_CFLAGS="-fsanitize=address"
30 ASAN_LDFLAGS="-fsanitize=address"
34 AC_MSG_ERROR([$CC does not support -fsanitize=address])
36 CFLAGS="$saved_cflags"
40 ASAN_ZFS="_without_asan"
43 AC_SUBST([ASAN_CFLAGS])
44 AC_SUBST([ASAN_LDFLAGS])
49 dnl # Enabled -fsanitize=undefined if supported by cc.
51 dnl # LDFLAGS needs -fsanitize=undefined at all times so libraries compiled with
52 dnl # it will be linked successfully. CFLAGS will vary by binary being built.
54 dnl # The UBSAN_OPTIONS environment variable can be used to further control
55 dnl # the behavior of binaries and libraries build with -fsanitize=undefined.
57 AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_UBSAN], [
58 AC_MSG_CHECKING([whether to build with -fsanitize=undefined support])
59 AC_ARG_ENABLE([ubsan],
60 [AS_HELP_STRING([--enable-ubsan],
61 [Enable -fsanitize=undefined support @<:@default=no@:>@])],
65 AM_CONDITIONAL([UBSAN_ENABLED], [test x$enable_ubsan = xyes])
66 AC_SUBST([UBSAN_ENABLED], [$enable_ubsan])
67 AC_MSG_RESULT($enable_ubsan)
69 AS_IF([ test "$enable_ubsan" = "yes" ], [
70 AC_MSG_CHECKING([whether $CC supports -fsanitize=undefined])
71 saved_cflags="$CFLAGS"
72 CFLAGS="$CFLAGS -Werror -fsanitize=undefined"
74 AC_LANG_SOURCE([[ int main() { return 0; } ]])
76 UBSAN_CFLAGS="-fsanitize=undefined"
77 UBSAN_LDFLAGS="-fsanitize=undefined"
78 UBSAN_ZFS="_with_ubsan"
81 AC_MSG_ERROR([$CC does not support -fsanitize=undefined])
83 CFLAGS="$saved_cflags"
87 UBSAN_ZFS="_without_ubsan"
90 AC_SUBST([UBSAN_CFLAGS])
91 AC_SUBST([UBSAN_LDFLAGS])
96 dnl # Check if cc supports -Wframe-larger-than=<size> option.
98 AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_FRAME_LARGER_THAN], [
99 AC_MSG_CHECKING([whether $CC supports -Wframe-larger-than=<size>])
101 saved_flags="$CFLAGS"
102 CFLAGS="$CFLAGS -Werror -Wframe-larger-than=4096"
104 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
105 FRAME_LARGER_THAN="-Wframe-larger-than=4096"
112 CFLAGS="$saved_flags"
113 AC_SUBST([FRAME_LARGER_THAN])
117 dnl # Check if cc supports -Wno-format-truncation option.
119 AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_NO_FORMAT_TRUNCATION], [
120 AC_MSG_CHECKING([whether $CC supports -Wno-format-truncation])
122 saved_flags="$CFLAGS"
123 CFLAGS="$CFLAGS -Werror -Wno-format-truncation"
125 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
126 NO_FORMAT_TRUNCATION=-Wno-format-truncation
129 NO_FORMAT_TRUNCATION=
133 CFLAGS="$saved_flags"
134 AC_SUBST([NO_FORMAT_TRUNCATION])
138 dnl # Check if cc supports -Wno-format-zero-length option.
140 AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_NO_FORMAT_ZERO_LENGTH], [
141 AC_MSG_CHECKING([whether $CC supports -Wno-format-zero-length])
143 saved_flags="$CFLAGS"
144 CFLAGS="$CFLAGS -Werror -Wno-format-zero-length"
146 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
147 NO_FORMAT_ZERO_LENGTH=-Wno-format-zero-length
150 NO_FORMAT_ZERO_LENGTH=
154 CFLAGS="$saved_flags"
155 AC_SUBST([NO_FORMAT_ZERO_LENGTH])
159 dnl # Check if cc supports -Wno-clobbered option.
161 dnl # We actually invoke it with the -Wclobbered option
162 dnl # and infer the 'no-' version does or doesn't exist based upon
163 dnl # the results. This is required because when checking any of
164 dnl # no- prefixed options gcc always returns success.
166 AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_NO_CLOBBERED], [
167 AC_MSG_CHECKING([whether $CC supports -Wno-clobbered])
169 saved_flags="$CFLAGS"
170 CFLAGS="$CFLAGS -Werror -Wclobbered"
172 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
173 NO_CLOBBERED=-Wno-clobbered
180 CFLAGS="$saved_flags"
181 AC_SUBST([NO_CLOBBERED])
185 dnl # Check if cc supports -Wimplicit-fallthrough option.
187 AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_IMPLICIT_FALLTHROUGH], [
188 AC_MSG_CHECKING([whether $CC supports -Wimplicit-fallthrough])
190 saved_flags="$CFLAGS"
191 CFLAGS="$CFLAGS -Werror -Wimplicit-fallthrough"
193 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
194 IMPLICIT_FALLTHROUGH=-Wimplicit-fallthrough
195 AC_DEFINE([HAVE_IMPLICIT_FALLTHROUGH], 1,
196 [Define if compiler supports -Wimplicit-fallthrough])
199 IMPLICIT_FALLTHROUGH=
203 CFLAGS="$saved_flags"
204 AC_SUBST([IMPLICIT_FALLTHROUGH])
208 dnl # Check if cc supports -Winfinite-recursion option.
210 AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_INFINITE_RECURSION], [
211 AC_MSG_CHECKING([whether $CC supports -Winfinite-recursion])
213 saved_flags="$CFLAGS"
214 CFLAGS="$CFLAGS -Werror -Winfinite-recursion"
216 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
217 INFINITE_RECURSION=-Winfinite-recursion
218 AC_DEFINE([HAVE_INFINITE_RECURSION], 1,
219 [Define if compiler supports -Winfinite-recursion])
226 CFLAGS="$saved_flags"
227 AC_SUBST([INFINITE_RECURSION])
231 dnl # Check if cc supports -fno-omit-frame-pointer option.
233 AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_NO_OMIT_FRAME_POINTER], [
234 AC_MSG_CHECKING([whether $CC supports -fno-omit-frame-pointer])
236 saved_flags="$CFLAGS"
237 CFLAGS="$CFLAGS -Werror -fno-omit-frame-pointer"
239 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
240 NO_OMIT_FRAME_POINTER=-fno-omit-frame-pointer
243 NO_OMIT_FRAME_POINTER=
247 CFLAGS="$saved_flags"
248 AC_SUBST([NO_OMIT_FRAME_POINTER])
252 dnl # Check if cc supports -fno-ipa-sra option.
254 AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_NO_IPA_SRA], [
255 AC_MSG_CHECKING([whether $CC supports -fno-ipa-sra])
257 saved_flags="$CFLAGS"
258 CFLAGS="$CFLAGS -Werror -fno-ipa-sra"
260 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
261 NO_IPA_SRA=-fno-ipa-sra
268 CFLAGS="$saved_flags"
269 AC_SUBST([NO_IPA_SRA])