From 48f79c11890f23f47fbe89ec54a57d5cd485a7b1 Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sat, 13 Feb 2016 14:59:55 +0000 Subject: [PATCH 1/2] Vendor import of compiler-rt release_38 branch r260756: https://llvm.org/svn/llvm-project/compiler-rt/branches/release_38@260756 --- CMakeLists.txt | 3 +++ cmake/Modules/AddCompilerRT.cmake | 3 ++- lib/tsan/CMakeLists.txt | 15 +++++++++++---- lib/tsan/rtl/tsan_suppressions.cc | 4 ++-- test/msan/fork.cc | 5 +++++ test/tsan/CMakeLists.txt | 32 +++++++++++++++++++++++++++---- test/tsan/lit.cfg | 12 +++++++----- test/tsan/lit.site.cfg.in | 3 +++ 8 files changed, 61 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5f8b4d1bd269..c60c246efa74 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,8 +66,10 @@ if (NOT COMPILER_RT_STANDALONE_BUILD) # Windows where we need to use clang-cl instead. if(NOT MSVC) set(COMPILER_RT_TEST_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang) + set(COMPILER_RT_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++) else() set(COMPILER_RT_TEST_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang.exe) + set(COMPILER_RT_TEST_CXX_COMPILER ${LLVM_RUNTIME_OUTPUT_INTDIR}/clang++.exe) endif() else() # Take output dir and install path from the user. @@ -81,6 +83,7 @@ else() option(COMPILER_RT_ENABLE_WERROR "Fail and stop if warning is triggered" OFF) # Use a host compiler to compile/link tests. set(COMPILER_RT_TEST_COMPILER ${CMAKE_C_COMPILER} CACHE PATH "Compiler to use for testing") + set(COMPILER_RT_TEST_CXX_COMPILER ${CMAKE_CXX_COMPILER} CACHE PATH "C++ Compiler to use for testing") if (NOT LLVM_CONFIG_PATH) find_program(LLVM_CONFIG_PATH "llvm-config" diff --git a/cmake/Modules/AddCompilerRT.cmake b/cmake/Modules/AddCompilerRT.cmake index 3c5845f2a2c1..1ab590e34a88 100644 --- a/cmake/Modules/AddCompilerRT.cmake +++ b/cmake/Modules/AddCompilerRT.cmake @@ -290,11 +290,12 @@ macro(add_custom_libcxx name prefix) SOURCE_DIR ${COMPILER_RT_LIBCXX_PATH} CMAKE_ARGS -DCMAKE_MAKE_PROGRAM:STRING=${CMAKE_MAKE_PROGRAM} -DCMAKE_C_COMPILER=${COMPILER_RT_TEST_COMPILER} - -DCMAKE_CXX_COMPILER=${COMPILER_RT_TEST_COMPILER} + -DCMAKE_CXX_COMPILER=${COMPILER_RT_TEST_CXX_COMPILER} -DCMAKE_C_FLAGS=${LIBCXX_CFLAGS} -DCMAKE_CXX_FLAGS=${LIBCXX_CFLAGS} -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX:PATH= + -DLLVM_PATH=${LLVM_MAIN_SRC_DIR} LOG_BUILD 1 LOG_CONFIGURE 1 LOG_INSTALL 1 diff --git a/lib/tsan/CMakeLists.txt b/lib/tsan/CMakeLists.txt index 0e60cd3464d8..c185cfa16407 100644 --- a/lib/tsan/CMakeLists.txt +++ b/lib/tsan/CMakeLists.txt @@ -204,10 +204,17 @@ endif() # Build libcxx instrumented with TSan. if(COMPILER_RT_HAS_LIBCXX_SOURCES AND COMPILER_RT_TEST_COMPILER_ID STREQUAL "Clang") - set(LIBCXX_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/libcxx_tsan) - add_custom_libcxx(libcxx_tsan ${LIBCXX_PREFIX} - DEPS ${TSAN_RUNTIME_LIBRARIES} - CFLAGS -fsanitize=thread) + set(libcxx_tsan_deps) + foreach(arch ${TSAN_SUPPORTED_ARCH}) + get_target_flags_for_arch(${arch} TARGET_CFLAGS) + set(LIBCXX_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/libcxx_tsan_${arch}) + add_custom_libcxx(libcxx_tsan_${arch} ${LIBCXX_PREFIX} + DEPS ${TSAN_RUNTIME_LIBRARIES} + CFLAGS ${TARGET_CFLAGS} -fsanitize=thread) + list(APPEND libcxx_tsan_deps libcxx_tsan_${arch}) + endforeach() + + add_custom_target(libcxx_tsan DEPENDS ${libcxx_tsan_deps}) endif() if(COMPILER_RT_INCLUDE_TESTS) diff --git a/lib/tsan/rtl/tsan_suppressions.cc b/lib/tsan/rtl/tsan_suppressions.cc index 8754b61c60cd..b992d78f8cb5 100644 --- a/lib/tsan/rtl/tsan_suppressions.cc +++ b/lib/tsan/rtl/tsan_suppressions.cc @@ -159,8 +159,8 @@ void PrintMatchedSuppressions() { Printf("ThreadSanitizer: Matched %d suppressions (pid=%d):\n", hit_count, (int)internal_getpid()); for (uptr i = 0; i < matched.size(); i++) { - Printf("%d %s:%s\n", matched[i]->hit_count, matched[i]->type, - matched[i]->templ); + Printf("%d %s:%s\n", atomic_load_relaxed(&matched[i]->hit_count), + matched[i]->type, matched[i]->templ); } } } // namespace __tsan diff --git a/test/msan/fork.cc b/test/msan/fork.cc index 78a62d549ec3..38c3616ec164 100644 --- a/test/msan/fork.cc +++ b/test/msan/fork.cc @@ -4,6 +4,11 @@ // RUN: %clangxx_msan -std=c++11 -fsanitize-memory-track-origins=2 -g -O3 %s -o %t // RUN: MSAN_OPTIONS=store_context_size=1000,origin_history_size=0,origin_history_per_stack_limit=0 %run %t |& FileCheck %s +// +// Big-endian mips64 currently hangs on this test. Mark it unsupported to allow +// llvm-lit to finish. This also marks mips unsupported in most cases but msan +// is already unsupported for 32-bit mips. +// UNSUPPORTED: mips64-supported-target // Fun fact: if test output is redirected to a file (as opposed to // being piped directly to FileCheck), we may lose some "done"s due to diff --git a/test/tsan/CMakeLists.txt b/test/tsan/CMakeLists.txt index 01e80388bb95..f45a6fc59121 100644 --- a/test/tsan/CMakeLists.txt +++ b/test/tsan/CMakeLists.txt @@ -14,9 +14,33 @@ else() set(TSAN_HAS_LIBCXX False) endif() -configure_lit_site_cfg( - ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in - ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg) +set(TSAN_TESTSUITES) + +set(TSAN_TEST_ARCH ${TSAN_SUPPORTED_ARCH}) +if(APPLE) + darwin_filter_host_archs(TSAN_SUPPORTED_ARCH TSAN_TEST_ARCH) +endif() + +foreach(arch ${TSAN_TEST_ARCH}) + string(TOLOWER "-${arch}" TSAN_TEST_CONFIG_SUFFIX) + if(ANDROID OR ${arch} MATCHES "arm|aarch64") + # This is only true if we are cross-compiling. + # Build all tests with host compiler and use host tools. + set(TSAN_TEST_TARGET_CC ${COMPILER_RT_TEST_COMPILER}) + set(TSAN_TEST_TARGET_CFLAGS ${COMPILER_RT_TEST_COMPILER_CFLAGS}) + else() + get_target_flags_for_arch(${arch} TSAN_TEST_TARGET_CFLAGS) + string(REPLACE ";" " " TSAN_TEST_TARGET_CFLAGS "${TSAN_TEST_TARGET_CFLAGS}") + endif() + + string(TOUPPER ${arch} ARCH_UPPER_CASE) + set(CONFIG_NAME ${ARCH_UPPER_CASE}Config) + + configure_lit_site_cfg( + ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in + ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg) + list(APPEND TSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}) +endforeach() if(COMPILER_RT_INCLUDE_TESTS) configure_lit_site_cfg( @@ -26,6 +50,6 @@ if(COMPILER_RT_INCLUDE_TESTS) endif() add_lit_testsuite(check-tsan "Running ThreadSanitizer tests" - ${CMAKE_CURRENT_BINARY_DIR} + ${TSAN_TESTSUITES} DEPENDS ${TSAN_TEST_DEPS}) set_target_properties(check-tsan PROPERTIES FOLDER "TSan tests") diff --git a/test/tsan/lit.cfg b/test/tsan/lit.cfg index 2be10dae1c85..d141fc228512 100644 --- a/test/tsan/lit.cfg +++ b/test/tsan/lit.cfg @@ -12,7 +12,7 @@ def get_required_attr(config, attr_name): return attr_value # Setup config name. -config.name = 'ThreadSanitizer' +config.name = 'ThreadSanitizer' + config.name_suffix # Setup source root. config.test_source_root = os.path.dirname(__file__) @@ -39,16 +39,18 @@ else: extra_cflags = [] # Setup default compiler flags used with -fsanitize=thread option. -clang_tsan_cflags = ["-fsanitize=thread", - "-Wall", - "-m64"] + config.debug_info_flags + extra_cflags +clang_tsan_cflags = (["-fsanitize=thread", + "-Wall"] + + [config.target_cflags] + + config.debug_info_flags + + extra_cflags) clang_tsan_cxxflags = config.cxx_mode_flags + clang_tsan_cflags # Add additional flags if we're using instrumented libc++. # Instrumented libcxx currently not supported on Darwin. if config.has_libcxx and config.host_os != 'Darwin': # FIXME: Dehardcode this path somehow. libcxx_path = os.path.join(config.compiler_rt_obj_root, "lib", - "tsan", "libcxx_tsan") + "tsan", "libcxx_tsan_" + config.arch) libcxx_incdir = os.path.join(libcxx_path, "include", "c++", "v1") libcxx_libdir = os.path.join(libcxx_path, "lib") libcxx_so = os.path.join(libcxx_libdir, "libc++.so") diff --git a/test/tsan/lit.site.cfg.in b/test/tsan/lit.site.cfg.in index 5190b211177d..08d4c1e00c7b 100644 --- a/test/tsan/lit.site.cfg.in +++ b/test/tsan/lit.site.cfg.in @@ -1,7 +1,10 @@ ## Autogenerated by LLVM/Clang configuration. # Do not edit! +config.name_suffix = "@TSAN_TEST_CONFIG_SUFFIX@" +config.arch = "@arch@" config.has_libcxx = @TSAN_HAS_LIBCXX@ +config.target_cflags = "@TSAN_TEST_TARGET_CFLAGS@" # Load common config for all compiler-rt lit tests. lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured") From c003a57e2e4a1ad9be0338806bc1038b6987155f Mon Sep 17 00:00:00 2001 From: Dimitry Andric Date: Sun, 21 Feb 2016 13:53:12 +0000 Subject: [PATCH 2/2] Vendor import of compiler-rt release_38 branch r261369: https://llvm.org/svn/llvm-project/compiler-rt/branches/release_38@261369 --- lib/msan/msan_interceptors.cc | 4 +-- .../sanitizer_linux_libcdep.cc | 9 +++++-- lib/tsan/go/buildgo.sh | 27 ++++++++++--------- test/asan/TestCases/throw_catch.cc | 3 --- test/tsan/CMakeLists.txt | 1 + test/tsan/ignore_lib0.cc | 4 +-- test/tsan/printf-1.c | 4 +-- 7 files changed, 28 insertions(+), 24 deletions(-) diff --git a/lib/msan/msan_interceptors.cc b/lib/msan/msan_interceptors.cc index fc28e080f262..0db2ac5b226c 100644 --- a/lib/msan/msan_interceptors.cc +++ b/lib/msan/msan_interceptors.cc @@ -1408,12 +1408,12 @@ int OnExit() { __msan_unpoison(ptr, size) #define COMMON_INTERCEPTOR_ENTER(ctx, func, ...) \ if (msan_init_is_running) return REAL(func)(__VA_ARGS__); \ + ENSURE_MSAN_INITED(); \ MSanInterceptorContext msan_ctx = {IsInInterceptorScope()}; \ ctx = (void *)&msan_ctx; \ (void)ctx; \ InterceptorScope interceptor_scope; \ - __msan_unpoison(__errno_location(), sizeof(int)); /* NOLINT */ \ - ENSURE_MSAN_INITED(); + __msan_unpoison(__errno_location(), sizeof(int)); /* NOLINT */ #define COMMON_INTERCEPTOR_DIR_ACQUIRE(ctx, path) \ do { \ } while (false) diff --git a/lib/sanitizer_common/sanitizer_linux_libcdep.cc b/lib/sanitizer_common/sanitizer_linux_libcdep.cc index 8cf2c73b1d53..04031d25528c 100644 --- a/lib/sanitizer_common/sanitizer_linux_libcdep.cc +++ b/lib/sanitizer_common/sanitizer_linux_libcdep.cc @@ -222,6 +222,11 @@ uptr ThreadDescriptorSize() { char *end; int minor = internal_simple_strtoll(buf + 8, &end, 10); if (end != buf + 8 && (*end == '\0' || *end == '.')) { + int patch = 0; + if (*end == '.') + // strtoll will return 0 if no valid conversion could be performed + patch = internal_simple_strtoll(end + 1, nullptr, 10); + /* sizeof(struct pthread) values from various glibc versions. */ if (SANITIZER_X32) val = 1728; // Assume only one particular version for x32. @@ -235,9 +240,9 @@ uptr ThreadDescriptorSize() { val = FIRST_32_SECOND_64(1136, 1712); else if (minor == 10) val = FIRST_32_SECOND_64(1168, 1776); - else if (minor <= 12) + else if (minor == 11 || (minor == 12 && patch == 1)) val = FIRST_32_SECOND_64(1168, 2288); - else if (minor == 13) + else if (minor <= 13) val = FIRST_32_SECOND_64(1168, 2304); else val = FIRST_32_SECOND_64(1216, 2304); diff --git a/lib/tsan/go/buildgo.sh b/lib/tsan/go/buildgo.sh index fdbd4056959c..668530c5f40e 100755 --- a/lib/tsan/go/buildgo.sh +++ b/lib/tsan/go/buildgo.sh @@ -50,19 +50,20 @@ if [ "`uname -a | grep Linux`" != "" ]; then ../../sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc " elif [ "`uname -a | grep FreeBSD`" != "" ]; then - SUFFIX="freebsd_amd64" - OSCFLAGS="-fno-strict-aliasing -fPIC -Werror" - OSLDFLAGS="-lpthread -fPIC -fpie" - SRCS=" - $SRCS - ../rtl/tsan_platform_linux.cc - ../../sanitizer_common/sanitizer_posix.cc - ../../sanitizer_common/sanitizer_posix_libcdep.cc - ../../sanitizer_common/sanitizer_procmaps_common.cc - ../../sanitizer_common/sanitizer_procmaps_freebsd.cc - ../../sanitizer_common/sanitizer_linux.cc - ../../sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc - " + SUFFIX="freebsd_amd64" + OSCFLAGS="-fno-strict-aliasing -fPIC -Werror" + OSLDFLAGS="-lpthread -fPIC -fpie" + SRCS=" + $SRCS + ../rtl/tsan_platform_linux.cc + ../../sanitizer_common/sanitizer_posix.cc + ../../sanitizer_common/sanitizer_posix_libcdep.cc + ../../sanitizer_common/sanitizer_procmaps_common.cc + ../../sanitizer_common/sanitizer_procmaps_freebsd.cc + ../../sanitizer_common/sanitizer_linux.cc + ../../sanitizer_common/sanitizer_linux_libcdep.cc + ../../sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc + " elif [ "`uname -a | grep Darwin`" != "" ]; then SUFFIX="darwin_amd64" OSCFLAGS="-fPIC -Wno-unused-const-variable -Wno-unknown-warning-option" diff --git a/test/asan/TestCases/throw_catch.cc b/test/asan/TestCases/throw_catch.cc index bce48199dbf7..01083510c32f 100644 --- a/test/asan/TestCases/throw_catch.cc +++ b/test/asan/TestCases/throw_catch.cc @@ -1,8 +1,5 @@ // RUN: %clangxx_asan -O %s -o %t && %run %t -// Clang doesn't support exceptions on Windows yet. -// XFAIL: win32 - #include #include #include diff --git a/test/tsan/CMakeLists.txt b/test/tsan/CMakeLists.txt index f45a6fc59121..a058602659c1 100644 --- a/test/tsan/CMakeLists.txt +++ b/test/tsan/CMakeLists.txt @@ -47,6 +47,7 @@ if(COMPILER_RT_INCLUDE_TESTS) ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.in ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg) list(APPEND TSAN_TEST_DEPS TsanUnitTests) + list(APPEND TSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit) endif() add_lit_testsuite(check-tsan "Running ThreadSanitizer tests" diff --git a/test/tsan/ignore_lib0.cc b/test/tsan/ignore_lib0.cc index c72aa496a1cd..d6ae72f31638 100644 --- a/test/tsan/ignore_lib0.cc +++ b/test/tsan/ignore_lib0.cc @@ -1,9 +1,9 @@ // RUN: %clangxx_tsan -O1 %s -DLIB -fPIC -fno-sanitize=thread -shared -o %T/libignore_lib0.so // RUN: %clangxx_tsan -O1 %s -L%T -lignore_lib0 -o %t // RUN: echo running w/o suppressions: -// RUN: LD_LIBRARY_PATH=%T${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} %deflake %run %t | FileCheck %s --check-prefix=CHECK-NOSUPP +// RUN: env LD_LIBRARY_PATH=%T${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} %deflake %run %t | FileCheck %s --check-prefix=CHECK-NOSUPP // RUN: echo running with suppressions: -// RUN: LD_LIBRARY_PATH=%T${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} %env_tsan_opts=suppressions='%s.supp' %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-WITHSUPP +// RUN: env LD_LIBRARY_PATH=%T${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} %env_tsan_opts=suppressions='%s.supp' %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-WITHSUPP // Tests that interceptors coming from a library specified in called_from_lib // suppression are ignored. diff --git a/test/tsan/printf-1.c b/test/tsan/printf-1.c index 9116c956e30e..c8414f834b44 100644 --- a/test/tsan/printf-1.c +++ b/test/tsan/printf-1.c @@ -1,6 +1,6 @@ // RUN: %clang_tsan -O2 %s -o %t -// RUN: ASAN_OPTIONS=check_printf=1 %run %t 2>&1 | FileCheck %s -// RUN: ASAN_OPTIONS=check_printf=0 %run %t 2>&1 | FileCheck %s +// RUN: %env_tsan_opts=check_printf=1 %run %t 2>&1 | FileCheck %s +// RUN: %env_tsan_opts=check_printf=0 %run %t 2>&1 | FileCheck %s // RUN: %run %t 2>&1 | FileCheck %s #include