set_analyzer_env.sh 4.3 KB

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