4 echo "Script for enabling CLang sanitizers for debug builds."
5 echo "*Only tested on Ubuntu x64."
6 echo "*This script must be 'sourced' (via dot+space) so that changes to environment variables are preserved. Run like this:"
7 if [ "$(dirname $0)" = "." ]; then
8 echo " . enablesanitizers.sh [options]"
10 echo " cd $(dirname $0);. enablesanitizers.sh [options]; cd -"
12 echo "Usage: [asan] [ubsan] [lsan] [all] [off] [clangx.y]"
13 echo " asan: optional argument to enable Address Sanitizer."
14 echo " ubsan: optional argument to enable Undefined Behavior Sanitizer."
15 echo " lsan - optional argument to enable memory Leak Sanitizer."
16 echo " all - optional argument to enable asan, ubsan and lsan."
17 echo " off - optional argument to turn off all sanitizers."
18 echo " clangx.y - optional argument to specify clang version x.y. which is used to resolve stack traces. Default is 3.6"
20 # default to clang 3.6 instead of 3.5 because it supports print_stacktrace (otherwise only one stack frame)
32 lowerI="$(echo $i | awk '{print tolower($0)}')"
65 echo "Unknown arg: $i"
70 if [ $__TurnOff == 1 ]; then
71 unset DEBUG_SANITIZERS
72 echo "Setting DEBUG_SANITIZERS="
74 # for now, specify alloc_dealloc_mismatch=0 as there are too many error reports that are not an issue
75 ASAN_OPTIONS="symbolize=1 alloc_dealloc_mismatch=0"
76 # when Clang 3.8 available, add: suppressions=$(readlink -f sanitizersuppressions.txt)
77 UBSAN_OPTIONS="print_stacktrace=1"
79 if [ $__EnableASan == 1 ]; then
80 __Options="$__Options asan"
82 if [ $__EnableUBSan == 1 ]; then
83 __Options="$__Options ubsan"
85 if [ $__EnableLSan == 1 ]; then
86 ASAN_OPTIONS="$ASAN_OPTIONS detect_leaks"
90 DEBUG_SANITIZERS="$__Options"
91 export DEBUG_SANITIZERS
92 echo "Setting DEBUG_SANITIZERS=$DEBUG_SANITIZERS"
94 # used by ASan at run-time
95 ASAN_OPTIONS="\"$ASAN_OPTIONS\""
97 echo "Setting ASAN_OPTIONS=$ASAN_OPTIONS"
99 UBSAN_OPTIONS="\"$UBSAN_OPTIONS\""
101 echo "Setting UBSAN_OPTIONS=$UBSAN_OPTIONS"
103 # used by ASan at run-time
104 ASAN_SYMBOLIZER_PATH="/usr/bin/llvm-symbolizer-$__ClangMajorVersion.$__ClangMinorVersion"
105 export ASAN_SYMBOLIZER_PATH
106 echo "Setting ASAN_SYMBOLIZER_PATH=$ASAN_SYMBOLIZER_PATH"
107 echo "Done. You can now run: build.sh Debug clang$__ClangMajorVersion.$__ClangMinorVersion"
110 unset __ClangMajorVersion
111 unset __ClangMinorVersion