From 255f6a5f1a99afbf6110d67119754febb8016e88 Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Thu, 13 Sep 2012 12:18:41 +0000 Subject: [PATCH] [TSan] Add initial support for buidling ThreadSanitizer runtime library with CMake (currently the only supported platfrom is 64-bit Linux). This patch makes 'clang++ -fthread-sanitizer' work for both clang in the build tree and installed clang llvm-svn: 163789 --- compiler-rt/lib/CMakeLists.txt | 2 +- compiler-rt/lib/tsan/CMakeLists.txt | 20 ++++++--- compiler-rt/lib/tsan/rtl/CMakeLists.txt | 56 +++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 compiler-rt/lib/tsan/rtl/CMakeLists.txt diff --git a/compiler-rt/lib/CMakeLists.txt b/compiler-rt/lib/CMakeLists.txt index 1249aa00e7e8..02d58de0af5c 100644 --- a/compiler-rt/lib/CMakeLists.txt +++ b/compiler-rt/lib/CMakeLists.txt @@ -3,8 +3,8 @@ add_subdirectory(asan) add_subdirectory(interception) add_subdirectory(sanitizer_common) +add_subdirectory(tsan) -# FIXME: Add support for tsan library. # FIXME: Add support for the profile library. # The top-level lib directory contains a large amount of C code which provides diff --git a/compiler-rt/lib/tsan/CMakeLists.txt b/compiler-rt/lib/tsan/CMakeLists.txt index acfb854d2606..fc20cd88b0d6 100644 --- a/compiler-rt/lib/tsan/CMakeLists.txt +++ b/compiler-rt/lib/tsan/CMakeLists.txt @@ -1,8 +1,18 @@ -# Build for the AddressSanitizer runtime support library. +# Build for the ThreadSanitizer runtime support library. -file(GLOB TSAN_SOURCES "*.cc") +include_directories(..) -if(CAN_TARGET_X86_64) - add_library(clang_rt.tsan-x86_64 STATIC ${TSAN_SOURCES}) - set_target_properties(clang_rt.tsan-x86_64 PROPERTIES COMPILE_FLAGS "${TARGET_X86_64_CFLAGS}") +set(TSAN_CFLAGS ${SANITIZER_COMMON_CFLAGS}) +# FIXME: Add support for compile flags: +# -Wframe-larger-than=512, +# -Wglobal-constructors, +# --sysroot=. + +if("${CMAKE_BUILD_TYPE}" EQUAL "Release") + set(TSAN_COMMON_DEFINITIONS DEBUG=0) +else() + set(TSAN_COMMON_DEFINITIONS DEBUG=1) endif() + +add_subdirectory(rtl) +# FIXME: Support TSan runtime tests, unit tests and output tests. diff --git a/compiler-rt/lib/tsan/rtl/CMakeLists.txt b/compiler-rt/lib/tsan/rtl/CMakeLists.txt new file mode 100644 index 000000000000..267c02a42397 --- /dev/null +++ b/compiler-rt/lib/tsan/rtl/CMakeLists.txt @@ -0,0 +1,56 @@ +set(TSAN_SOURCES + tsan_clock.cc + tsan_flags.cc + tsan_interceptors.cc + tsan_interface_ann.cc + tsan_interface_atomic.cc + tsan_interface.cc + tsan_md5.cc + tsan_mman.cc + tsan_mutex.cc + tsan_printf.cc + tsan_report.cc + tsan_rtl.cc + tsan_rtl_mutex.cc + tsan_rtl_report.cc + tsan_rtl_thread.cc + tsan_stat.cc + tsan_suppressions.cc + tsan_symbolize.cc + tsan_sync.cc + ) + +if(APPLE) + list(APPEND TSAN_SOURCES tsan_platform_mac.cc) +elseif(UNIX) + # Assume Linux + list(APPEND TSAN_SOURCES + tsan_platform_linux.cc + tsan_symbolize_addr2line_linux.cc) +endif() + +set(TSAN_RUNTIME_LIBRARIES) +# TSan is currently supported on 64-bit Linux only. +if(CAN_TARGET_X86_64 AND UNIX AND NOT APPLE) + set(TSAN_ASM_SOURCES tsan_rtl_amd64.S) + # Pass ASM file directly to the C++ compiler. + set_source_files_properties(${TSAN_ASM_SOURCES} PROPERTIES + LANGUAGE CXX + ) + add_library(clang_rt.tsan-x86_64 STATIC + ${TSAN_SOURCES} + ${TSAN_ASM_SOURCES} + $ + $ + ) + set_target_compile_flags(clang_rt.tsan-x86_64 + ${TSAN_CFLAGS} ${TARGET_X864_64_CFLAGS} + ) + list(APPEND TSAN_RUNTIME_LIBRARIES clang_rt.tsan-x86_64) +endif() + +if(TSAN_RUNTIME_LIBRARIES) + set_property(TARGET ${TSAN_RUNTIME_LIBRARIES} APPEND PROPERTY + COMPILE_DEFINITIONS ${TSAN_COMMON_DEFINITIONS}) + add_clang_compiler_rt_libraries(${TSAN_RUNTIME_LIBRARIES}) +endif()