1## Copyright (c) 2018 The WebM project authors. All Rights Reserved. 2## 3## Use of this source code is governed by a BSD-style license 4## that can be found in the LICENSE file in the root of the source 5## tree. An additional intellectual property rights grant can be found 6## in the file PATENTS. All contributing project authors may 7## be found in the AUTHORS file in the root of the source tree. 8## 9## Sourcing this file sets environment variables to simplify setting up 10## sanitizer builds and testing. 11 12sanitizer="${1}" 13 14case "${sanitizer}" in 15 address) ;; 16 cfi) ;; 17 integer) ;; 18 memory) ;; 19 thread) ;; 20 undefined) ;; 21 clear) 22 echo "Clearing environment:" 23 set -x 24 unset CC CXX LD AR 25 unset CFLAGS CXXFLAGS LDFLAGS 26 unset ASAN_OPTIONS MSAN_OPTIONS TSAN_OPTIONS UBSAN_OPTIONS 27 set +x 28 return 29 ;; 30 *) 31 echo "Usage: source set_analyzer_env.sh [<sanitizer>|clear]" 32 echo " Supported sanitizers:" 33 echo " address integer memory thread undefined" 34 return 1 35 ;; 36esac 37 38if [ ! $(which clang) ]; then 39 # TODO(johannkoenig): Support gcc analyzers. 40 echo "ERROR: 'clang' must be in your PATH" 41 return 1 42fi 43 44# Warnings. 45if [ "${sanitizer}" = "undefined" -o "${sanitizer}" = "integer" ]; then 46 echo "WARNING: When building the ${sanitizer} sanitizer for 32 bit targets" 47 echo "you must run:" 48 echo "export LDFLAGS=\"\${LDFLAGS} --rtlib=compiler-rt -lgcc_s\"" 49 echo "See http://llvm.org/bugs/show_bug.cgi?id=17693 for details." 50fi 51 52if [ "${sanitizer}" = "undefined" ]; then 53 major_version=$(clang --version | head -n 1 \ 54 | grep -o -E "[[:digit:]]\.[[:digit:]]\.[[:digit:]]" | cut -f1 -d.) 55 if [ ${major_version} -eq 5 ]; then 56 echo "WARNING: clang v5 has a problem with vp9 x86_64 high bit depth" 57 echo "configurations. It can take ~40 minutes to compile" 58 echo "vpx_dsp/x86/fwd_txfm_sse2.c" 59 echo "clang v4 did not have this issue." 60 fi 61fi 62 63echo "It is recommended to configure with '--enable-debug' to improve stack" 64echo "traces. On mac builds, run 'dysmutil' on the output binaries (vpxenc," 65echo "test_libvpx, etc) to link the stack traces to source code lines." 66 67# Build configuration. 68cflags="-fsanitize=${sanitizer}" 69ldflags="-fsanitize=${sanitizer}" 70 71# http://code.google.com/p/webm/issues/detail?id=570 72cflags="${cflags} -fno-strict-aliasing" 73# Useful backtraces. 74cflags="${cflags} -fno-omit-frame-pointer" 75# Exact backtraces. 76cflags="${cflags} -fno-optimize-sibling-calls" 77 78if [ "${sanitizer}" = "cfi" ]; then 79 # https://clang.llvm.org/docs/ControlFlowIntegrity.html 80 cflags="${cflags} -flto -fvisibility=hidden" 81 ldflags="${ldflags} -flto -fuse-ld=gold" 82 export AR="llvm-ar" 83fi 84 85set -x 86export CC="clang" 87export CXX="clang++" 88export LD="clang++" 89 90export CFLAGS="${cflags}" 91export CXXFLAGS="${cflags}" 92export LDFLAGS="${ldflags}" 93set +x 94 95# Execution configuration. 96sanitizer_options="" 97sanitizer_options="${sanitizer_options}:handle_segv=1" 98sanitizer_options="${sanitizer_options}:handle_abort=1" 99sanitizer_options="${sanitizer_options}:handle_sigfpe=1" 100sanitizer_options="${sanitizer_options}:fast_unwind_on_fatal=1" 101sanitizer_options="${sanitizer_options}:allocator_may_return_null=1" 102 103case "${sanitizer}" in 104 address) 105 sanitizer_options="${sanitizer_options}:detect_stack_use_after_return=1" 106 sanitizer_options="${sanitizer_options}:max_uar_stack_size_log=17" 107 set -x 108 export ASAN_OPTIONS="${sanitizer_options}" 109 set +x 110 ;; 111 cfi) 112 # No environment settings 113 ;; 114 memory) 115 set -x 116 export MSAN_OPTIONS="${sanitizer_options}" 117 set +x 118 ;; 119 thread) 120 # The thread sanitizer uses an entirely independent set of options. 121 set -x 122 export TSAN_OPTIONS="halt_on_error=1" 123 set +x 124 ;; 125 undefined|integer) 126 sanitizer_options="${sanitizer_options}:print_stacktrace=1" 127 set -x 128 export UBSAN_OPTIONS="${sanitizer_options}" 129 set +x 130 ;; 131esac 132