1 dnl This Source Code Form is subject to the terms of the Mozilla Public
2 dnl License, v. 2.0. If a copy of the MPL was not distributed with this
3 dnl file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 AC_DEFUN([MOZ_CONFIG_SANITIZE], [
7 dnl ========================================================
8 dnl = Use Address Sanitizer
9 dnl ========================================================
10 if test -n "$MOZ_ASAN"; then
11 if test -n "$CLANG_CL"; then
12 # Look for the ASan runtime binary
13 if test "$CPU_ARCH" = "x86_64"; then
14 MOZ_CLANG_RT_ASAN_LIB=clang_rt.asan_dynamic-x86_64.dll
16 MOZ_CLANG_RT_ASAN_LIB=clang_rt.asan_dynamic-i386.dll
18 # We use MOZ_PATH_PROG in order to get a Windows style path.
19 MOZ_PATH_PROG(MOZ_CLANG_RT_ASAN_LIB_PATH, $MOZ_CLANG_RT_ASAN_LIB)
20 if test -z "$MOZ_CLANG_RT_ASAN_LIB_PATH"; then
21 AC_MSG_ERROR([Couldn't find $MOZ_CLANG_RT_ASAN_LIB. It should be available in the same location as clang-cl.])
23 AC_SUBST(MOZ_CLANG_RT_ASAN_LIB_PATH)
24 # Suppressing errors in recompiled code.
25 if test "$OS_ARCH" = "WINNT"; then
26 CFLAGS="-fsanitize-blacklist=$_topsrcdir/build/sanitizers/asan_blacklist_win.txt $CFLAGS"
27 CXXFLAGS="-fsanitize-blacklist=$_topsrcdir/build/sanitizers/asan_blacklist_win.txt $CXXFLAGS"
30 CFLAGS="-fsanitize=address $CFLAGS"
31 CXXFLAGS="-fsanitize=address $CXXFLAGS"
32 if test -z "$CLANG_CL"; then
33 LDFLAGS="-fsanitize=address -rdynamic $LDFLAGS"
36 MOZ_PATH_PROG(LLVM_SYMBOLIZER, llvm-symbolizer)
40 dnl ========================================================
41 dnl = Use Memory Sanitizer
42 dnl ========================================================
43 if test -n "$MOZ_MSAN"; then
44 CFLAGS="-fsanitize=memory -fsanitize-memory-track-origins $CFLAGS"
45 CXXFLAGS="-fsanitize=memory -fsanitize-memory-track-origins $CXXFLAGS"
46 if test -z "$CLANG_CL"; then
47 LDFLAGS="-fsanitize=memory -fsanitize-memory-track-origins -rdynamic $LDFLAGS"
50 MOZ_PATH_PROG(LLVM_SYMBOLIZER, llvm-symbolizer)
54 dnl ========================================================
55 dnl = Use Thread Sanitizer
56 dnl ========================================================
57 if test -n "$MOZ_TSAN"; then
58 CFLAGS="-fsanitize=thread $CFLAGS"
59 CXXFLAGS="-fsanitize=thread $CXXFLAGS"
60 if test -z "$CLANG_CL"; then
61 LDFLAGS="-fsanitize=thread -rdynamic $LDFLAGS"
64 MOZ_PATH_PROG(LLVM_SYMBOLIZER, llvm-symbolizer)
68 dnl ========================================================
69 dnl = Use UndefinedBehavior Sanitizer (with custom checks)
70 dnl ========================================================
71 if test -n "$MOZ_UBSAN_CHECKS"; then
73 UBSAN_TXT="$_objdir/ubsan_blacklist.txt"
74 cat $_topsrcdir/build/sanitizers/ubsan_*_blacklist.txt > $UBSAN_TXT
75 UBSAN_FLAGS="-fsanitize=$MOZ_UBSAN_CHECKS -fno-sanitize-recover=$MOZ_UBSAN_CHECKS -fsanitize-blacklist=$UBSAN_TXT"
76 CFLAGS="$UBSAN_FLAGS $CFLAGS"
77 CXXFLAGS="$UBSAN_FLAGS $CXXFLAGS"
78 if test -z "$CLANG_CL"; then
79 LDFLAGS="-fsanitize=undefined -rdynamic $LDFLAGS"
82 MOZ_PATH_PROG(LLVM_SYMBOLIZER, llvm-symbolizer)
86 dnl ========================================================
87 dnl = Use UndefinedBehavior Sanitizer to find integer overflows
88 dnl ========================================================
89 if test -n "$MOZ_SIGNED_OVERFLOW_SANITIZE$MOZ_UNSIGNED_OVERFLOW_SANITIZE"; then
91 SANITIZER_BLACKLISTS=""
92 if test -n "$MOZ_SIGNED_OVERFLOW_SANITIZE"; then
93 SANITIZER_BLACKLISTS="-fsanitize-blacklist=$_topsrcdir/build/sanitizers/ubsan_signed_overflow_blacklist.txt $SANITIZER_BLACKLISTS"
94 CFLAGS="-fsanitize=signed-integer-overflow $CFLAGS"
95 CXXFLAGS="-fsanitize=signed-integer-overflow $CXXFLAGS"
96 if test -z "$CLANG_CL"; then
97 LDFLAGS="-fsanitize=signed-integer-overflow -rdynamic $LDFLAGS"
99 AC_DEFINE(MOZ_SIGNED_OVERFLOW_SANITIZE)
101 if test -n "$MOZ_UNSIGNED_OVERFLOW_SANITIZE"; then
102 SANITIZER_BLACKLISTS="-fsanitize-blacklist=$_topsrcdir/build/sanitizers/ubsan_unsigned_overflow_blacklist.txt $SANITIZER_BLACKLISTS"
103 CFLAGS="-fsanitize=unsigned-integer-overflow $CFLAGS"
104 CXXFLAGS="-fsanitize=unsigned-integer-overflow $CXXFLAGS"
105 if test -z "$CLANG_CL"; then
106 LDFLAGS="-fsanitize=unsigned-integer-overflow -rdynamic $LDFLAGS"
108 AC_DEFINE(MOZ_UNSIGNED_OVERFLOW_SANITIZE)
110 CFLAGS="$SANITIZER_BLACKLISTS $CFLAGS"
111 CXXFLAGS="$SANITIZER_BLACKLISTS $CXXFLAGS"
113 MOZ_PATH_PROG(LLVM_SYMBOLIZER, llvm-symbolizer)
115 AC_SUBST(MOZ_SIGNED_OVERFLOW_SANITIZE)
116 AC_SUBST(MOZ_UNSIGNED_OVERFLOW_SANITIZE)
119 dnl =======================================================
120 dnl = Required for stand-alone (sanitizer-less) libFuzzer.
121 dnl =======================================================
122 if test -n "$LIBFUZZER"; then
123 LDFLAGS="$LIBFUZZER_FLAGS -rdynamic $LDFLAGS"
126 # The LLVM symbolizer is used by all sanitizers
127 AC_SUBST(LLVM_SYMBOLIZER)
129 dnl ========================================================
130 dnl = Test for whether the compiler is compatible with the
131 dnl = given sanitize options.
132 dnl ========================================================
133 AC_TRY_LINK(,,,AC_MSG_ERROR([compiler is incompatible with sanitize options]))