summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJohann <johannkoenig@google.com>2018-03-27 12:59:15 -0700
committerJohann <johannkoenig@google.com>2018-03-29 06:58:30 -0700
commit20521c394c7d5424c9638e2596d9818bac7b42a3 (patch)
tree5c84397c3bc7d7a0a7c0c49cc2e812109c46acfd /tools
parent239511fad877863b7b8fdfba2c83449e753e679a (diff)
downloadlibvpx-20521c394c7d5424c9638e2596d9818bac7b42a3.tar.gz
libvpx-20521c394c7d5424c9638e2596d9818bac7b42a3.tar.bz2
libvpx-20521c394c7d5424c9638e2596d9818bac7b42a3.zip
helper script for sanitizer testing
source tools/set_analyzer_env.sh <sanitizer> will set the compiler, flag, and sanitizer variables necessary to build and run a variety of sanitizers. Change-Id: I5dd2ae947cb337d5ccf2a11e9fe87991bc8ba0c8
Diffstat (limited to 'tools')
-rw-r--r--tools/set_analyzer_env.sh120
1 files changed, 120 insertions, 0 deletions
diff --git a/tools/set_analyzer_env.sh b/tools/set_analyzer_env.sh
new file mode 100644
index 000000000..17869ee89
--- /dev/null
+++ b/tools/set_analyzer_env.sh
@@ -0,0 +1,120 @@
+## Copyright (c) 2018 The WebM project authors. All Rights Reserved.
+##
+## Use of this source code is governed by a BSD-style license
+## that can be found in the LICENSE file in the root of the source
+## tree. An additional intellectual property rights grant can be found
+## in the file PATENTS. All contributing project authors may
+## be found in the AUTHORS file in the root of the source tree.
+##
+## Sourcing this file sets environment variables to simplify setting up
+## sanitizer builds and testing.
+
+sanitizer="${1}"
+
+case "${sanitizer}" in
+ address) ;;
+ integer) ;;
+ memory) ;;
+ thread) ;;
+ undefined) ;;
+ clear)
+ echo "Clearing environment:"
+ set -x
+ unset CC CXX LD
+ unset CFLAGS CXXFLAGS LDFLAGS
+ unset ASAN_OPTIONS MSAN_OPTIONS TSAN_OPTIONS UBSAN_OPTIONS
+ set +x
+ return
+ ;;
+ *)
+ echo "Usage: source set_analyzer_env.sh [<sanitizer>|clear]"
+ echo " Supported sanitizers:"
+ echo " address integer memory thread undefined"
+ return 1
+ ;;
+esac
+
+if [ ! $(which clang) ]; then
+ # TODO(johannkoenig): Support gcc analyzers.
+ echo "ERROR: 'clang' must be in your PATH"
+ return 1
+fi
+
+# Warnings.
+if [ "${sanitizer}" = "undefined" -o "${sanitizer}" = "integer" ]; then
+ echo "WARNING: When building the ${sanitizer} sanitizer for 32 bit targets"
+ echo "you must run:"
+ echo "export LDFLAGS=\"\${LDFLAGS} --rtlib=compiler-rt -lgcc_s\""
+ echo "See http://llvm.org/bugs/show_bug.cgi?id=17693 for details."
+fi
+
+if [ "${sanitizer}" = "undefined" ]; then
+ major_version=$(clang --version | head -n 1 \
+ | grep -o -E "[[:digit:]]\.[[:digit:]]\.[[:digit:]]" | cut -f1 -d.)
+ if [ ${major_version} -eq 5 ]; then
+ echo "WARNING: clang v5 has a problem with vp9 x86_64 high bit depth"
+ echo "configurations. It can take ~40 minutes to compile"
+ echo "vpx_dsp/x86/fwd_txfm_sse2.c"
+ echo "clang v4 did not have this issue."
+ fi
+fi
+
+echo "It is recommended to configure with '--enable-debug' to improve stack"
+echo "traces. On mac builds, run 'dysmutil' on the output binaries (vpxenc,"
+echo "test_libvpx, etc) to link the stack traces to source code lines."
+
+# Build configuration.
+cflags="-fsanitize=${sanitizer}"
+ldflags="-fsanitize=${sanitizer}"
+
+# http://code.google.com/p/webm/issues/detail?id=570
+cflags="${cflags} -fno-strict-aliasing"
+# Useful backtraces.
+cflags="${cflags} -fno-omit-frame-pointer"
+# Exact backtraces.
+cflags="${cflags} -fno-optimize-sibling-calls"
+
+set -x
+export CC="clang"
+export CXX="clang++"
+export LD="clang++"
+
+export CFLAGS="${cflags}"
+export CXXFLAGS="${cflags}"
+export LDFLAGS="${ldflags}"
+set +x
+
+# Execution configuration.
+sanitizer_options=""
+sanitizer_options="${sanitizer_options}:handle_segv=1"
+sanitizer_options="${sanitizer_options}:handle_abort=1"
+sanitizer_options="${sanitizer_options}:handle_sigfpe=1"
+sanitizer_options="${sanitizer_options}:fast_unwind_on_fatal=1"
+sanitizer_options="${sanitizer_options}:allocator_may_return_null=1"
+
+case "${sanitizer}" in
+ address)
+ sanitizer_options="${sanitizer_options}:detect_stack_use_after_return=1"
+ sanitizer_options="${sanitizer_options}:max_uar_stack_size_log=17"
+ set -x
+ export ASAN_OPTIONS="${sanitizer_options}"
+ set +x
+ ;;
+ memory)
+ set -x
+ export MSAN_OPTIONS="${sanitizer_options}"
+ set +x
+ ;;
+ thread)
+ # The thread sanitizer uses an entirely independent set of options.
+ set -x
+ export TSAN_OPTIONS="halt_on_error=1"
+ set +x
+ ;;
+ undefined|integer)
+ sanitizer_options="${sanitizer_options}:print_stacktrace=1"
+ set -x
+ export UBSAN_OPTIONS="${sanitizer_options}"
+ set +x
+ ;;
+esac