Bug 1929458 - support setting OS version to use in failure annotations generated...
[gecko.git] / security / nss / coreconf / sanitizers.sh
blob6d7b617734f24b1239d08a21f4ce1933389170b1
1 #!/usr/bin/env bash
2 # This file is used by build.sh to setup sanitizers.
4 sanitizer_flags=""
5 sanitizers=()
7 # This tracks what sanitizers are enabled so they don't get enabled twice. This
8 # means that doing things that enable the same sanitizer twice (such as enabling
9 # both --asan and --fuzz) is order-dependent: only the first is used.
10 enable_sanitizer()
12 local san="$1"
13 for i in "${sanitizers[@]}"; do
14 [ "$san" = "$i" ] && return
15 done
16 sanitizers+=("$san")
18 if [ -z "$sanitizer_flags" ]; then
19 gyp_params+=(-Dno_zdefs=1)
22 local cflags=$(python $cwd/coreconf/sanitizers.py "$@")
23 sanitizer_flags="$sanitizer_flags $cflags"
26 enable_sancov()
28 local clang_version=$($CC --version | grep -oE '([0-9]{1,}\.)+[0-9]{1,}')
29 if [[ ${clang_version:0:1} -lt 4 && ${clang_version:0:1} -eq 3 && ${clang_version:2:1} -lt 9 ]]; then
30 echo "Need at least clang-3.9 (better 4.0) for sancov." 1>&2
31 exit 1
34 local sancov
35 if [ -n "$1" ]; then
36 sancov="$1"
37 elif [ "${clang_version:0:3}" = "3.9" ]; then
38 sancov=edge,indirect-calls,8bit-counters
39 else
40 sancov=trace-pc-guard,trace-cmp
42 enable_sanitizer sancov "$sancov"
45 enable_sourcecov()
47 enable_sanitizer sourcecov
50 enable_ubsan()
52 local ubsan
53 if [ -n "$1" ]; then
54 ubsan="$1"
55 else
56 ubsan=undefined,local-bounds
58 enable_sanitizer ubsan "$ubsan"
61 # Not strictly a sanitizer, but the pattern fits
62 scanbuild=()
63 enable_scanbuild()
65 [ "${#scanbuild[@]}" -gt 0 ] && return
67 scanbuild=(scan-build)
68 if [ -n "$1" ]; then
69 scanbuild+=(-o "$1")
71 # pass on CC and CCC to scanbuild
72 if [ -n "$CC" ]; then
73 scanbuild+=(--use-cc="$CC")
75 if [ -n "$CCC" ]; then
76 scanbuild+=(--use-c++="$CCC")
80 run_scanbuild()
82 "${scanbuild[@]}" "$@"