2 dnl # Enabled -fsanitize=address if supported by gcc.
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 -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 # Check if gcc supports -Wframe-larger-than=<size> option.
51 AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_FRAME_LARGER_THAN], [
52 AC_MSG_CHECKING([whether $CC supports -Wframe-larger-than=<size>])
55 CFLAGS="$CFLAGS -Wframe-larger-than=4096"
57 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
58 FRAME_LARGER_THAN="-Wframe-larger-than=4096"
66 AC_SUBST([FRAME_LARGER_THAN])
70 dnl # Check if gcc supports -Wno-format-truncation option.
72 AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_NO_FORMAT_TRUNCATION], [
73 AC_MSG_CHECKING([whether $CC supports -Wno-format-truncation])
76 CFLAGS="$CFLAGS -Wno-format-truncation"
78 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
79 NO_FORMAT_TRUNCATION=-Wno-format-truncation
87 AC_SUBST([NO_FORMAT_TRUNCATION])
92 dnl # Check if gcc supports -Wno-bool-compare option.
94 dnl # We actually invoke gcc with the -Wbool-compare option
95 dnl # and infer the 'no-' version does or doesn't exist based upon
96 dnl # the results. This is required because when checking any of
97 dnl # no- prefixed options gcc always returns success.
99 AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_NO_BOOL_COMPARE], [
100 AC_MSG_CHECKING([whether $CC supports -Wno-bool-compare])
102 saved_flags="$CFLAGS"
103 CFLAGS="$CFLAGS -Wbool-compare"
105 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
106 NO_BOOL_COMPARE=-Wno-bool-compare
113 CFLAGS="$saved_flags"
114 AC_SUBST([NO_BOOL_COMPARE])
118 dnl # Check if gcc supports -Wno-unused-but-set-variable option.
120 dnl # We actually invoke gcc with the -Wunused-but-set-variable option
121 dnl # and infer the 'no-' version does or doesn't exist based upon
122 dnl # the results. This is required because when checking any of
123 dnl # no- prefixed options gcc always returns success.
125 AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_NO_UNUSED_BUT_SET_VARIABLE], [
126 AC_MSG_CHECKING([whether $CC supports -Wno-unused-but-set-variable])
128 saved_flags="$CFLAGS"
129 CFLAGS="$CFLAGS -Wunused-but-set-variable"
131 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
132 NO_UNUSED_BUT_SET_VARIABLE=-Wno-unused-but-set-variable
135 NO_UNUSED_BUT_SET_VARIABLE=
139 CFLAGS="$saved_flags"
140 AC_SUBST([NO_UNUSED_BUT_SET_VARIABLE])
144 dnl # Check if gcc supports -fno-omit-frame-pointer option.
146 AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_NO_OMIT_FRAME_POINTER], [
147 AC_MSG_CHECKING([whether $CC supports -fno-omit-frame-pointer])
149 saved_flags="$CFLAGS"
150 CFLAGS="$CFLAGS -fno-omit-frame-pointer"
152 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
153 NO_OMIT_FRAME_POINTER=-fno-omit-frame-pointer
156 NO_OMIT_FRAME_POINTER=
160 CFLAGS="$saved_flags"
161 AC_SUBST([NO_OMIT_FRAME_POINTER])