1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
dnl This Source Code Form is subject to the terms of the Mozilla Public
dnl License, v. 2.0. If a copy of the MPL was not distributed with this
dnl file, You can obtain one at http://mozilla.org/MPL/2.0/.
AC_DEFUN([MOZ_CONFIG_SANITIZE], [
dnl ========================================================
dnl = Use Address Sanitizer
dnl ========================================================
if test -n "$MOZ_ASAN"; then
if test -n "$CLANG_CL"; then
# Look for the ASan runtime binary
if test "$TARGET_CPU" = "x86_64"; then
MOZ_CLANG_RT_ASAN_LIB=clang_rt.asan_dynamic-x86_64.dll
else
MOZ_CLANG_RT_ASAN_LIB=clang_rt.asan_dynamic-i386.dll
fi
# We use MOZ_PATH_PROG in order to get a Windows style path.
MOZ_PATH_PROG(MOZ_CLANG_RT_ASAN_LIB_PATH, $MOZ_CLANG_RT_ASAN_LIB)
if test -z "$MOZ_CLANG_RT_ASAN_LIB_PATH"; then
AC_MSG_ERROR([Couldn't find $MOZ_CLANG_RT_ASAN_LIB. It should be available in the same location as clang-cl.])
fi
AC_SUBST(MOZ_CLANG_RT_ASAN_LIB_PATH)
# Suppressing errors in recompiled code.
if test "$OS_ARCH" = "WINNT"; then
CFLAGS="-fsanitize-blacklist=$_topsrcdir/build/sanitizers/asan_blacklist_win.txt $CFLAGS"
CXXFLAGS="-fsanitize-blacklist=$_topsrcdir/build/sanitizers/asan_blacklist_win.txt $CXXFLAGS"
fi
fi
ASAN_FLAGS="-fsanitize=address"
if test "$OS_TARGET" = Linux; then
# -fno-sanitize-address-globals-dead-stripping is used to work around
# https://github.com/rust-lang/rust/issues/113404
# It forces clang not to use __asan_register_elf_globals/__asan_globals_registered,
# avoiding the conflict with rust.
ASAN_FLAGS="$ASAN_FLAGS -fno-sanitize-address-globals-dead-stripping"
fi
CFLAGS="$ASAN_FLAGS $CFLAGS"
CXXFLAGS="$ASAN_FLAGS $CXXFLAGS"
if test -z "$CLANG_CL"; then
LDFLAGS="-fsanitize=address -rdynamic $LDFLAGS"
fi
AC_DEFINE(MOZ_ASAN)
MOZ_PATH_PROG(LLVM_SYMBOLIZER, llvm-symbolizer)
fi
AC_SUBST(MOZ_ASAN)
dnl ========================================================
dnl = Use Memory Sanitizer
dnl ========================================================
if test -n "$MOZ_MSAN"; then
CFLAGS="-fsanitize=memory -fsanitize-memory-track-origins $CFLAGS"
CXXFLAGS="-fsanitize=memory -fsanitize-memory-track-origins $CXXFLAGS"
if test -z "$CLANG_CL"; then
LDFLAGS="-fsanitize=memory -fsanitize-memory-track-origins -rdynamic $LDFLAGS"
fi
AC_DEFINE(MOZ_MSAN)
MOZ_PATH_PROG(LLVM_SYMBOLIZER, llvm-symbolizer)
fi
AC_SUBST(MOZ_MSAN)
dnl ========================================================
dnl = Use Thread Sanitizer
dnl ========================================================
if test -n "$MOZ_TSAN"; then
CFLAGS="-fsanitize=thread $CFLAGS"
CXXFLAGS="-fsanitize=thread $CXXFLAGS"
if test -z "$CLANG_CL"; then
LDFLAGS="-fsanitize=thread -rdynamic $LDFLAGS"
fi
AC_DEFINE(MOZ_TSAN)
MOZ_PATH_PROG(LLVM_SYMBOLIZER, llvm-symbolizer)
fi
AC_SUBST(MOZ_TSAN)
dnl ========================================================
dnl = Use UndefinedBehavior Sanitizer (with custom checks)
dnl ========================================================
if test -n "$MOZ_UBSAN_CHECKS"; then
MOZ_UBSAN=1
UBSAN_TXT="$_objdir/ubsan_blacklist.txt"
cat $_topsrcdir/build/sanitizers/ubsan_*_blacklist.txt > $UBSAN_TXT
UBSAN_FLAGS="-fsanitize=$MOZ_UBSAN_CHECKS -fno-sanitize-recover=$MOZ_UBSAN_CHECKS -fsanitize-blacklist=$UBSAN_TXT"
CFLAGS="$UBSAN_FLAGS $CFLAGS"
CXXFLAGS="$UBSAN_FLAGS $CXXFLAGS"
if test -z "$CLANG_CL"; then
LDFLAGS="-fsanitize=undefined -rdynamic $LDFLAGS"
fi
AC_DEFINE(MOZ_UBSAN)
MOZ_PATH_PROG(LLVM_SYMBOLIZER, llvm-symbolizer)
fi
AC_SUBST(MOZ_UBSAN)
dnl ========================================================
dnl = Use UndefinedBehavior Sanitizer to find integer overflows
dnl ========================================================
if test -n "$MOZ_SIGNED_OVERFLOW_SANITIZE$MOZ_UNSIGNED_OVERFLOW_SANITIZE"; then
MOZ_UBSAN=1
SANITIZER_BLACKLISTS=""
if test -n "$MOZ_SIGNED_OVERFLOW_SANITIZE"; then
SANITIZER_BLACKLISTS="-fsanitize-blacklist=$_topsrcdir/build/sanitizers/ubsan_signed_overflow_blacklist.txt $SANITIZER_BLACKLISTS"
CFLAGS="-fsanitize=signed-integer-overflow $CFLAGS"
CXXFLAGS="-fsanitize=signed-integer-overflow $CXXFLAGS"
if test -z "$CLANG_CL"; then
LDFLAGS="-fsanitize=signed-integer-overflow -rdynamic $LDFLAGS"
fi
AC_DEFINE(MOZ_SIGNED_OVERFLOW_SANITIZE)
fi
if test -n "$MOZ_UNSIGNED_OVERFLOW_SANITIZE"; then
SANITIZER_BLACKLISTS="-fsanitize-blacklist=$_topsrcdir/build/sanitizers/ubsan_unsigned_overflow_blacklist.txt $SANITIZER_BLACKLISTS"
CFLAGS="-fsanitize=unsigned-integer-overflow $CFLAGS"
CXXFLAGS="-fsanitize=unsigned-integer-overflow $CXXFLAGS"
if test -z "$CLANG_CL"; then
LDFLAGS="-fsanitize=unsigned-integer-overflow -rdynamic $LDFLAGS"
fi
AC_DEFINE(MOZ_UNSIGNED_OVERFLOW_SANITIZE)
fi
CFLAGS="$SANITIZER_BLACKLISTS $CFLAGS"
CXXFLAGS="$SANITIZER_BLACKLISTS $CXXFLAGS"
AC_DEFINE(MOZ_UBSAN)
MOZ_PATH_PROG(LLVM_SYMBOLIZER, llvm-symbolizer)
fi
AC_SUBST(MOZ_SIGNED_OVERFLOW_SANITIZE)
AC_SUBST(MOZ_UNSIGNED_OVERFLOW_SANITIZE)
AC_SUBST(MOZ_UBSAN)
dnl =======================================================
dnl = Required for stand-alone (sanitizer-less) libFuzzer.
dnl =======================================================
if test -n "$LIBFUZZER"; then
LDFLAGS="$LIBFUZZER_FLAGS -rdynamic $LDFLAGS"
fi
# The LLVM symbolizer is used by all sanitizers
AC_SUBST(LLVM_SYMBOLIZER)
dnl ========================================================
dnl = Test for whether the compiler is compatible with the
dnl = given sanitize options.
dnl ========================================================
AC_TRY_LINK(,,,AC_MSG_ERROR([compiler is incompatible with sanitize options]))
])
|