1dnl #
2dnl # Enabled -fsanitize=address if supported by gcc.
3dnl #
4dnl # LDFLAGS needs -fsanitize=address at all times so libraries compiled with
5dnl # it will be linked successfully. CFLAGS will vary by binary being built.
6dnl #
7dnl # The ASAN_OPTIONS environment variable can be used to further control
8dnl # the behavior of binaries and libraries build with -fsanitize=address.
9dnl #
10AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_ASAN], [
11	AC_MSG_CHECKING([whether to build with -fsanitize=address support])
12	AC_ARG_ENABLE([asan],
13		[AS_HELP_STRING([--enable-asan],
14		[Enable -fsanitize=address support  @<:@default=no@:>@])],
15		[],
16		[enable_asan=no])
17
18	AM_CONDITIONAL([ASAN_ENABLED], [test x$enable_asan = xyes])
19	AC_SUBST([ASAN_ENABLED], [$enable_asan])
20	AC_MSG_RESULT($enable_asan)
21
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"
26		AC_LINK_IFELSE([
27			AC_LANG_SOURCE([[ int main() { return 0; } ]])
28		], [
29			ASAN_CFLAGS="-fsanitize=address"
30			ASAN_LDFLAGS="-fsanitize=address"
31			ASAN_ZFS="_with_asan"
32			AC_MSG_RESULT([yes])
33		], [
34			AC_MSG_ERROR([$CC does not support -fsanitize=address])
35		])
36		CFLAGS="$saved_cflags"
37	], [
38		ASAN_CFLAGS=""
39		ASAN_LDFLAGS=""
40		ASAN_ZFS="_without_asan"
41	])
42
43	AC_SUBST([ASAN_CFLAGS])
44	AC_SUBST([ASAN_LDFLAGS])
45	AC_SUBST([ASAN_ZFS])
46])
47
48dnl #
49dnl # Check if gcc supports -Wframe-larger-than=<size> option.
50dnl #
51AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_FRAME_LARGER_THAN], [
52	AC_MSG_CHECKING([whether $CC supports -Wframe-larger-than=<size>])
53
54	saved_flags="$CFLAGS"
55	CFLAGS="$CFLAGS -Werror -Wframe-larger-than=4096"
56
57	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
58		FRAME_LARGER_THAN="-Wframe-larger-than=4096"
59		AC_MSG_RESULT([yes])
60	], [
61		FRAME_LARGER_THAN=""
62		AC_MSG_RESULT([no])
63	])
64
65	CFLAGS="$saved_flags"
66	AC_SUBST([FRAME_LARGER_THAN])
67])
68
69dnl #
70dnl # Check if gcc supports -Wno-format-truncation option.
71dnl #
72AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_NO_FORMAT_TRUNCATION], [
73	AC_MSG_CHECKING([whether $CC supports -Wno-format-truncation])
74
75	saved_flags="$CFLAGS"
76	CFLAGS="$CFLAGS -Werror -Wno-format-truncation"
77
78	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
79		NO_FORMAT_TRUNCATION=-Wno-format-truncation
80		AC_MSG_RESULT([yes])
81	], [
82		NO_FORMAT_TRUNCATION=
83		AC_MSG_RESULT([no])
84	])
85
86	CFLAGS="$saved_flags"
87	AC_SUBST([NO_FORMAT_TRUNCATION])
88])
89
90dnl #
91dnl # Check if gcc supports -Wno-format-truncation option.
92dnl #
93AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_NO_FORMAT_ZERO_LENGTH], [
94	AC_MSG_CHECKING([whether $CC supports -Wno-format-zero-length])
95
96	saved_flags="$CFLAGS"
97	CFLAGS="$CFLAGS -Werror -Wno-format-zero-length"
98
99	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
100		NO_FORMAT_ZERO_LENGTH=-Wno-format-zero-length
101		AC_MSG_RESULT([yes])
102	], [
103		NO_FORMAT_ZERO_LENGTH=
104		AC_MSG_RESULT([no])
105	])
106
107	CFLAGS="$saved_flags"
108	AC_SUBST([NO_FORMAT_ZERO_LENGTH])
109])
110
111
112dnl #
113dnl # Check if gcc supports -Wno-bool-compare option.
114dnl #
115dnl # We actually invoke gcc with the -Wbool-compare option
116dnl # and infer the 'no-' version does or doesn't exist based upon
117dnl # the results.  This is required because when checking any of
118dnl # no- prefixed options gcc always returns success.
119dnl #
120AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_NO_BOOL_COMPARE], [
121	AC_MSG_CHECKING([whether $CC supports -Wno-bool-compare])
122
123	saved_flags="$CFLAGS"
124	CFLAGS="$CFLAGS -Werror -Wbool-compare"
125
126	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
127		NO_BOOL_COMPARE=-Wno-bool-compare
128		AC_MSG_RESULT([yes])
129	], [
130		NO_BOOL_COMPARE=
131		AC_MSG_RESULT([no])
132	])
133
134	CFLAGS="$saved_flags"
135	AC_SUBST([NO_BOOL_COMPARE])
136])
137
138dnl #
139dnl # Check if gcc supports -Wno-unused-but-set-variable option.
140dnl #
141dnl # We actually invoke gcc with the -Wunused-but-set-variable option
142dnl # and infer the 'no-' version does or doesn't exist based upon
143dnl # the results.  This is required because when checking any of
144dnl # no- prefixed options gcc always returns success.
145dnl #
146AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_NO_UNUSED_BUT_SET_VARIABLE], [
147	AC_MSG_CHECKING([whether $CC supports -Wno-unused-but-set-variable])
148
149	saved_flags="$CFLAGS"
150	CFLAGS="$CFLAGS -Werror -Wunused-but-set-variable"
151
152	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
153		NO_UNUSED_BUT_SET_VARIABLE=-Wno-unused-but-set-variable
154		AC_MSG_RESULT([yes])
155	], [
156		NO_UNUSED_BUT_SET_VARIABLE=
157		AC_MSG_RESULT([no])
158	])
159
160	CFLAGS="$saved_flags"
161	AC_SUBST([NO_UNUSED_BUT_SET_VARIABLE])
162])
163
164dnl #
165dnl # Check if gcc supports -Wimplicit-fallthrough option.
166dnl #
167AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_IMPLICIT_FALLTHROUGH], [
168	AC_MSG_CHECKING([whether $CC supports -Wimplicit-fallthrough])
169
170	saved_flags="$CFLAGS"
171	CFLAGS="$CFLAGS -Werror -Wimplicit-fallthrough"
172
173	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
174		IMPLICIT_FALLTHROUGH=-Wimplicit-fallthrough
175		AC_DEFINE([HAVE_IMPLICIT_FALLTHROUGH], 1,
176			[Define if compiler supports -Wimplicit-fallthrough])
177		AC_MSG_RESULT([yes])
178	], [
179		IMPLICIT_FALLTHROUGH=
180		AC_MSG_RESULT([no])
181	])
182
183	CFLAGS="$saved_flags"
184	AC_SUBST([IMPLICIT_FALLTHROUGH])
185])
186
187dnl #
188dnl # Check if gcc supports -fno-omit-frame-pointer option.
189dnl #
190AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_NO_OMIT_FRAME_POINTER], [
191	AC_MSG_CHECKING([whether $CC supports -fno-omit-frame-pointer])
192
193	saved_flags="$CFLAGS"
194	CFLAGS="$CFLAGS -Werror -fno-omit-frame-pointer"
195
196	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
197		NO_OMIT_FRAME_POINTER=-fno-omit-frame-pointer
198		AC_MSG_RESULT([yes])
199	], [
200		NO_OMIT_FRAME_POINTER=
201		AC_MSG_RESULT([no])
202	])
203
204	CFLAGS="$saved_flags"
205	AC_SUBST([NO_OMIT_FRAME_POINTER])
206])
207
208dnl #
209dnl # Check if cc supports -fno-ipa-sra option.
210dnl #
211AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_NO_IPA_SRA], [
212	AC_MSG_CHECKING([whether $CC supports -fno-ipa-sra])
213
214	saved_flags="$CFLAGS"
215	CFLAGS="$CFLAGS -Werror -fno-ipa-sra"
216
217	AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
218		NO_IPA_SRA=-fno-ipa-sra
219		AC_MSG_RESULT([yes])
220	], [
221		NO_IPA_SRA=
222		AC_MSG_RESULT([no])
223	])
224
225	CFLAGS="$saved_flags"
226	AC_SUBST([NO_IPA_SRA])
227])
228