Source code

Revision control

Other Tools

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/.
4
5
AC_DEFUN([MOZ_CONFIG_SANITIZE], [
6
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
15
else
16
MOZ_CLANG_RT_ASAN_LIB=clang_rt.asan_dynamic-i386.dll
17
fi
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.])
22
fi
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"
28
fi
29
fi
30
CFLAGS="-fsanitize=address $CFLAGS"
31
CXXFLAGS="-fsanitize=address $CXXFLAGS"
32
if test -z "$CLANG_CL"; then
33
LDFLAGS="-fsanitize=address -rdynamic $LDFLAGS"
34
fi
35
AC_DEFINE(MOZ_ASAN)
36
MOZ_PATH_PROG(LLVM_SYMBOLIZER, llvm-symbolizer)
37
fi
38
AC_SUBST(MOZ_ASAN)
39
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"
48
fi
49
AC_DEFINE(MOZ_MSAN)
50
MOZ_PATH_PROG(LLVM_SYMBOLIZER, llvm-symbolizer)
51
fi
52
AC_SUBST(MOZ_MSAN)
53
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"
62
fi
63
AC_DEFINE(MOZ_TSAN)
64
MOZ_PATH_PROG(LLVM_SYMBOLIZER, llvm-symbolizer)
65
fi
66
AC_SUBST(MOZ_TSAN)
67
68
dnl ========================================================
69
dnl = Use UndefinedBehavior Sanitizer (with custom checks)
70
dnl ========================================================
71
if test -n "$MOZ_UBSAN_CHECKS"; then
72
MOZ_UBSAN=1
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"
80
fi
81
AC_DEFINE(MOZ_UBSAN)
82
MOZ_PATH_PROG(LLVM_SYMBOLIZER, llvm-symbolizer)
83
fi
84
AC_SUBST(MOZ_UBSAN)
85
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
90
MOZ_UBSAN=1
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"
98
fi
99
AC_DEFINE(MOZ_SIGNED_OVERFLOW_SANITIZE)
100
fi
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"
107
fi
108
AC_DEFINE(MOZ_UNSIGNED_OVERFLOW_SANITIZE)
109
fi
110
CFLAGS="$SANITIZER_BLACKLISTS $CFLAGS"
111
CXXFLAGS="$SANITIZER_BLACKLISTS $CXXFLAGS"
112
AC_DEFINE(MOZ_UBSAN)
113
MOZ_PATH_PROG(LLVM_SYMBOLIZER, llvm-symbolizer)
114
fi
115
AC_SUBST(MOZ_SIGNED_OVERFLOW_SANITIZE)
116
AC_SUBST(MOZ_UNSIGNED_OVERFLOW_SANITIZE)
117
AC_SUBST(MOZ_UBSAN)
118
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"
124
fi
125
126
# The LLVM symbolizer is used by all sanitizers
127
AC_SUBST(LLVM_SYMBOLIZER)
128
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]))
134
135
])