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
This commit is contained in:
parent
239511fad8
commit
20521c394c
13
README
13
README
@ -45,7 +45,16 @@ COMPILING THE APPLICATIONS/LIBRARIES:
|
||||
used to get a list of supported options:
|
||||
$ ../libvpx/configure --help
|
||||
|
||||
4. Cross development
|
||||
4. Compiler analyzers
|
||||
Compilers have added sanitizers which instrument binaries with information
|
||||
about address calculation, memory usage, threading, undefined behavior, and
|
||||
other common errors. To simplify building libvpx with some of these features
|
||||
use tools/set_analyzer_env.sh before running configure. It will set the
|
||||
compiler and necessary flags for building as well as environment variables
|
||||
read by the analyzer when testing the binaries.
|
||||
$ source ../libvpx/tools/set_analyzer_env.sh address
|
||||
|
||||
5. Cross development
|
||||
For cross development, the most notable option is the --target option. The
|
||||
most up-to-date list of supported targets can be found at the bottom of the
|
||||
--help output of the configure script. As of this writing, the list of
|
||||
@ -127,7 +136,7 @@ COMPILING THE APPLICATIONS/LIBRARIES:
|
||||
environment variables: CC, AR, LD, AS, STRIP, NM. Additional flags can be
|
||||
passed to these executables with CFLAGS, LDFLAGS, and ASFLAGS.
|
||||
|
||||
5. Configuration errors
|
||||
6. Configuration errors
|
||||
If the configuration step fails, the first step is to look in the error log.
|
||||
This defaults to config.log. This should give a good indication of what went
|
||||
wrong. If not, contact us for support.
|
||||
|
120
tools/set_analyzer_env.sh
Normal file
120
tools/set_analyzer_env.sh
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user