IMPALA-5904: Add full_tsan option and fix several TSAN bugs

This patch adds an additional build flag -full_tsan in addition to the
existing -tsan build flag. -full_tsan is equivalent to the current -tsan
behavior, and -tsan is changed to set the ignore_noninstrumented_modules
flag to true. ignore_noninstrumented_modules causes TSAN to ignore any
modules that are not TSAN-instrumented. This is necessary to get TSAN to
play nicely with Java, since Java is not TSAN-instrumented (see
https://wiki.openjdk.java.net/display/tsan/Main and JDK-8208520). While
this might decrease the number of issues surfaced by TSAN, it drastically
decreases the amount of noise produced by TSAN because the JVM is not
running TSAN-instrumented code. Without this flag set to true, almost
every single backend test fails with the error:

WARNING: ThreadSanitizer: data race (pid=12939)
  Write of size 1 at 0x7fcbe379c4c6 by thread T31:
    #0 strncpy /mnt/source/llvm/llvm-5.0.1.src-p2/projects/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:650 (unifiedbetests+0x1b2a4ad)
    #1 <null> <null> (libjvm.so+0x90e706)

This patch fixes various TSAN bugs (e.g. data races) reported while
running backend tests and E2E against a TSAN build (it does not make
Impala completely TSAN-clean). This patch makes the following changes:
* Fixes several bugs involving issues with updating shared variables
  between threads
* Fixes a few race conditions in test classes
* Where possible, existing locks are used to fix any data races; in cases
  where the locking logic is non-trivial, atomics are used
* There are a few places where variables are marked as 'volatile'
  presumably for synchronization purposes; TSAN flags these 'volatile'
  variables as unsafe, and according to
  https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rconc-volatile
  using 'volatile' for synchronization is dangerous; in these cases, the
  'volatile' variables are changed to 'atomic' variables
* This patch adds a suppression file (bin/tsan-suppresions.txt) similar to
  the UBSAN suppresion file (bin/ubsan-suppresions.txt)

Testing:
* Ran exhaustive tests
* Ran core tests w/ ASAN build
* Manually re-ran backend tests against a TSAN build and made sure the
  reported errors are gone

Change-Id: I3d7ef5c228afd5882e145e6f53885b355d6c25a0
Reviewed-on: http://gerrit.cloudera.org:8080/15116
Reviewed-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
Tested-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
This commit is contained in:
Sahil Takiar
2020-01-20 18:06:32 -08:00
committed by Impala Public Jenkins
parent ebc2c366f5
commit ca6c8d43d7
29 changed files with 240 additions and 121 deletions

View File

@@ -70,6 +70,7 @@ BUILD_TIDY=0
BUILD_UBSAN=0
BUILD_UBSAN_FULL=0
BUILD_TSAN=0
BUILD_TSAN_FULL=0
BUILD_SHARED_LIBS=0
# Export MAKE_CMD so it is visible in scripts that invoke make, e.g. copy-udfs-udas.sh
export MAKE_CMD=make
@@ -141,6 +142,9 @@ do
-tsan)
BUILD_TSAN=1
;;
-full_tsan)
BUILD_TSAN_FULL=1
;;
-testpairwise)
EXPLORATION_STRATEGY=pairwise
;;
@@ -206,10 +210,18 @@ do
echo "[-codecoverage] : Build with code coverage [Default: False]"
echo "[-asan] : Address sanitizer build [Default: False]"
echo "[-tidy] : clang-tidy build [Default: False]"
echo "[-tsan] : Thread sanitizer build, runs with"\
"ignore_noninstrumented_modules=1. When this flag is true, TSAN ignores"\
"memory accesses from non-instrumented libraries. This decreases the number"\
"of false positives, but might miss real issues. -full_tsan disables this"\
"flag [Default: False]"
echo "[-full_tsan] : Thread sanitizer build, runs with"\
"ignore_noninstrumented_modules=0 (see the -tsan description for an"\
"explanation of what this flag does) [Default: False]"
echo "[-ubsan] : Undefined behavior sanitizer build [Default: False]"
echo "[-full_ubsan] : Undefined behavior sanitizer build, including code generated"\
" by cross-compilation to LLVM IR. Much slower queries than plain -ubsan "\
" [Default: False]"
"by cross-compilation to LLVM IR. Much slower queries than plain -ubsan"\
"[Default: False]"
echo "[-skiptests] : Skips execution of all tests"
echo "[-notests] : Skips building and execution of all tests"
echo "[-start_minicluster] : Start test cluster including Impala and all"\
@@ -299,6 +311,10 @@ fi
if [[ ${BUILD_TSAN} -eq 1 ]]; then
CMAKE_BUILD_TYPE_LIST+=(TSAN)
fi
if [[ ${BUILD_TSAN_FULL} -eq 1 ]]; then
CMAKE_BUILD_TYPE_LIST+=(TSAN_FULL)
export TSAN_FULL=1
fi
if [[ -n "${CMAKE_BUILD_TYPE_LIST:+1}" ]]; then
if [[ ${#CMAKE_BUILD_TYPE_LIST[@]} -gt 1 ]]; then
echo "ERROR: more than one CMake build type defined: ${CMAKE_BUILD_TYPE_LIST[@]}"
@@ -433,7 +449,8 @@ generate_cmake_files() {
|| ("$build_type" == "TIDY") \
|| ("$build_type" == "UBSAN") \
|| ("$build_type" == "UBSAN_FULL") \
|| ("$build_type" == "TSAN") ]]; then
|| ("$build_type" == "TSAN") \
|| ("$build_type" == "TSAN_FULL") ]]; then
CMAKE_ARGS+=(-DCMAKE_TOOLCHAIN_FILE=$IMPALA_HOME/cmake_modules/clang_toolchain.cmake)
else
CMAKE_ARGS+=(-DCMAKE_TOOLCHAIN_FILE=$IMPALA_HOME/cmake_modules/toolchain.cmake)