zdb: show bp in uberblock dump
[zfs.git] / config / always-compiler-options.m4
blob6383b12506ee992b998bfc3592820c995abd3f23
1 dnl #
2 dnl # Enabled -fsanitize=address if supported by $CC.
3 dnl #
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.
6 dnl #
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.
9 dnl #
10 AC_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])
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"
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         ])
43         AC_SUBST([ASAN_CFLAGS])
44         AC_SUBST([ASAN_LDFLAGS])
45         AC_SUBST([ASAN_ZFS])
48 dnl #
49 dnl # Enabled -fsanitize=undefined if supported by cc.
50 dnl #
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.
53 dnl #
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.
56 dnl #
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@:>@])],
62                 [],
63                 [enable_ubsan=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"
73                 AC_LINK_IFELSE([
74                         AC_LANG_SOURCE([[ int main() { return 0; } ]])
75                 ], [
76                         UBSAN_CFLAGS="-fsanitize=undefined"
77                         UBSAN_LDFLAGS="-fsanitize=undefined"
78                         UBSAN_ZFS="_with_ubsan"
79                         AC_MSG_RESULT([yes])
80                 ], [
81                         AC_MSG_ERROR([$CC does not support -fsanitize=undefined])
82                 ])
83                 CFLAGS="$saved_cflags"
84         ], [
85                 UBSAN_CFLAGS=""
86                 UBSAN_LDFLAGS=""
87                 UBSAN_ZFS="_without_ubsan"
88         ])
90         AC_SUBST([UBSAN_CFLAGS])
91         AC_SUBST([UBSAN_LDFLAGS])
92         AC_SUBST([UBSAN_ZFS])
95 dnl #
96 dnl # Check if cc supports -Wframe-larger-than=<size> option.
97 dnl #
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"
106                 AC_MSG_RESULT([yes])
107         ], [
108                 FRAME_LARGER_THAN=""
109                 AC_MSG_RESULT([no])
110         ])
112         CFLAGS="$saved_flags"
113         AC_SUBST([FRAME_LARGER_THAN])
116 dnl #
117 dnl # Check if cc supports -Wno-format-truncation option.
118 dnl #
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
127                 AC_MSG_RESULT([yes])
128         ], [
129                 NO_FORMAT_TRUNCATION=
130                 AC_MSG_RESULT([no])
131         ])
133         CFLAGS="$saved_flags"
134         AC_SUBST([NO_FORMAT_TRUNCATION])
137 dnl #
138 dnl # Check if cc supports -Wno-format-zero-length option.
139 dnl #
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
148                 AC_MSG_RESULT([yes])
149         ], [
150                 NO_FORMAT_ZERO_LENGTH=
151                 AC_MSG_RESULT([no])
152         ])
154         CFLAGS="$saved_flags"
155         AC_SUBST([NO_FORMAT_ZERO_LENGTH])
158 dnl #
159 dnl # Check if cc supports -Wno-clobbered option.
160 dnl #
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.
165 dnl #
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
174                 AC_MSG_RESULT([yes])
175         ], [
176                 NO_CLOBBERED=
177                 AC_MSG_RESULT([no])
178         ])
180         CFLAGS="$saved_flags"
181         AC_SUBST([NO_CLOBBERED])
184 dnl #
185 dnl # Check if cc supports -Wimplicit-fallthrough option.
186 dnl #
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])
197                 AC_MSG_RESULT([yes])
198         ], [
199                 IMPLICIT_FALLTHROUGH=
200                 AC_MSG_RESULT([no])
201         ])
203         CFLAGS="$saved_flags"
204         AC_SUBST([IMPLICIT_FALLTHROUGH])
207 dnl #
208 dnl # Check if cc supports -Winfinite-recursion option.
209 dnl #
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])
220                 AC_MSG_RESULT([yes])
221         ], [
222                 INFINITE_RECURSION=
223                 AC_MSG_RESULT([no])
224         ])
226         CFLAGS="$saved_flags"
227         AC_SUBST([INFINITE_RECURSION])
230 dnl #
231 dnl # Check if kernel cc supports -Winfinite-recursion option.
232 dnl #
233 AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_KERNEL_CC_INFINITE_RECURSION], [
234         AC_MSG_CHECKING([whether $KERNEL_CC supports -Winfinite-recursion])
236         saved_cc="$CC"
237         saved_flags="$CFLAGS"
238         CC="gcc"
239         CFLAGS="$CFLAGS -Werror -Winfinite-recursion"
241         AS_IF([ test -n "$KERNEL_CC" ], [
242                 CC="$KERNEL_CC"
243         ])
244         AS_IF([ test -n "$KERNEL_LLVM" ], [
245                 CC="clang"
246         ])
248         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
249                 KERNEL_INFINITE_RECURSION=-Winfinite-recursion
250                 AC_DEFINE([HAVE_KERNEL_INFINITE_RECURSION], 1,
251                         [Define if compiler supports -Winfinite-recursion])
252                 AC_MSG_RESULT([yes])
253         ], [
254                 KERNEL_INFINITE_RECURSION=
255                 AC_MSG_RESULT([no])
256         ])
258         CC="$saved_cc"
259         CFLAGS="$saved_flags"
260         AC_SUBST([KERNEL_INFINITE_RECURSION])
263 dnl #
264 dnl # Check if cc supports -Wformat-overflow option.
265 dnl #
266 AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_FORMAT_OVERFLOW], [
267         AC_MSG_CHECKING([whether $CC supports -Wformat-overflow])
269         saved_flags="$CFLAGS"
270         CFLAGS="$CFLAGS -Werror -Wformat-overflow"
272         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
273                 FORMAT_OVERFLOW=-Wformat-overflow
274                 AC_DEFINE([HAVE_FORMAT_OVERFLOW], 1,
275                         [Define if compiler supports -Wformat-overflow])
276                 AC_MSG_RESULT([yes])
277         ], [
278                 FORMAT_OVERFLOW=
279                 AC_MSG_RESULT([no])
280         ])
282         CFLAGS="$saved_flags"
283         AC_SUBST([FORMAT_OVERFLOW])
286 dnl #
287 dnl # Check if cc supports -fno-omit-frame-pointer option.
288 dnl #
289 AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_NO_OMIT_FRAME_POINTER], [
290         AC_MSG_CHECKING([whether $CC supports -fno-omit-frame-pointer])
292         saved_flags="$CFLAGS"
293         CFLAGS="$CFLAGS -Werror -fno-omit-frame-pointer"
295         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
296                 NO_OMIT_FRAME_POINTER=-fno-omit-frame-pointer
297                 AC_MSG_RESULT([yes])
298         ], [
299                 NO_OMIT_FRAME_POINTER=
300                 AC_MSG_RESULT([no])
301         ])
303         CFLAGS="$saved_flags"
304         AC_SUBST([NO_OMIT_FRAME_POINTER])
307 dnl #
308 dnl # Check if cc supports -fno-ipa-sra option.
309 dnl #
310 AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_CC_NO_IPA_SRA], [
311         AC_MSG_CHECKING([whether $CC supports -fno-ipa-sra])
313         saved_flags="$CFLAGS"
314         CFLAGS="$CFLAGS -Werror -fno-ipa-sra"
316         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
317                 NO_IPA_SRA=-fno-ipa-sra
318                 AC_MSG_RESULT([yes])
319         ], [
320                 NO_IPA_SRA=
321                 AC_MSG_RESULT([no])
322         ])
324         CFLAGS="$saved_flags"
325         AC_SUBST([NO_IPA_SRA])
328 dnl #
329 dnl # Check if kernel cc supports -fno-ipa-sra option.
330 dnl #
331 AC_DEFUN([ZFS_AC_CONFIG_ALWAYS_KERNEL_CC_NO_IPA_SRA], [
332         AC_MSG_CHECKING([whether $KERNEL_CC supports -fno-ipa-sra])
334         saved_cc="$CC"
335         saved_flags="$CFLAGS"
336         CC="gcc"
337         CFLAGS="$CFLAGS -Werror -fno-ipa-sra"
339         AS_IF([ test -n "$KERNEL_CC" ], [
340                 CC="$KERNEL_CC"
341         ])
342         AS_IF([ test -n "$KERNEL_LLVM" ], [
343                 CC="clang"
344         ])
346         AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [])], [
347                 KERNEL_NO_IPA_SRA=-fno-ipa-sra
348                 AC_MSG_RESULT([yes])
349         ], [
350                 KERNEL_NO_IPA_SRA=
351                 AC_MSG_RESULT([no])
352         ])
354         CC="$saved_cc"
355         CFLAGS="$saved_flags"
356         AC_SUBST([KERNEL_NO_IPA_SRA])