1 # Build for the ThreadSanitizer runtime support library.
3 include_directories(..)
5 set(TSAN_CFLAGS ${SANITIZER_COMMON_CFLAGS})
6 # SANITIZER_COMMON_CFLAGS contains -fPIC, but it's performance-critical for
7 # TSan runtime to be built with -fPIE to reduce the number of register spills.
8 append_if(COMPILER_RT_HAS_FPIE_FLAG -fPIE TSAN_CFLAGS)
9 append_no_rtti_flag(TSAN_CFLAGS)
11 set(TSAN_RTL_CFLAGS ${TSAN_CFLAGS})
12 append_if(COMPILER_RT_HAS_WFRAME_LARGER_THAN_FLAG -Wframe-larger-than=512 TSAN_RTL_CFLAGS)
13 append_if(COMPILER_RT_HAS_WGLOBAL_CONSTRUCTORS_FLAG -Wglobal-constructors TSAN_RTL_CFLAGS)
14 # FIXME: Add support for --sysroot=. compile flag:
16 if("${CMAKE_BUILD_TYPE}" EQUAL "Release")
17 set(TSAN_COMMON_DEFINITIONS DEBUG=0)
19 set(TSAN_COMMON_DEFINITIONS DEBUG=1)
27 rtl/tsan_interceptors.cc
28 rtl/tsan_interface_ann.cc
29 rtl/tsan_interface_atomic.cc
31 rtl/tsan_interface_java.cc
39 rtl/tsan_rtl_report.cc
40 rtl/tsan_rtl_thread.cc
41 rtl/tsan_stack_trace.cc
43 rtl/tsan_suppressions.cc
48 list(APPEND TSAN_SOURCES rtl/tsan_platform_mac.cc)
51 list(APPEND TSAN_SOURCES
52 rtl/tsan_platform_linux.cc)
58 rtl/tsan_dense_alloc.h
62 rtl/tsan_interface_ann.h
64 rtl/tsan_interface_inl.h
65 rtl/tsan_interface_java.h
72 rtl/tsan_stack_trace.h
74 rtl/tsan_suppressions.h
78 rtl/tsan_update_shadow_word_inl.h
81 set(TSAN_RUNTIME_LIBRARIES)
82 add_custom_target(tsan)
83 # TSan is currently supported on 64-bit Linux only.
84 if(CAN_TARGET_x86_64 AND UNIX AND NOT APPLE)
85 set(TSAN_ASM_SOURCES rtl/tsan_rtl_amd64.S)
86 # Pass ASM file directly to the C++ compiler.
87 set_source_files_properties(${TSAN_ASM_SOURCES} PROPERTIES
90 add_compiler_rt_runtime(clang_rt.tsan-${arch} ${arch} STATIC
91 SOURCES ${TSAN_SOURCES} ${TSAN_ASM_SOURCES}
92 $<TARGET_OBJECTS:RTInterception.${arch}>
93 $<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
94 $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>
95 CFLAGS ${TSAN_RTL_CFLAGS}
96 DEFS ${TSAN_COMMON_DEFINITIONS})
97 list(APPEND TSAN_RUNTIME_LIBRARIES clang_rt.tsan-${arch})
98 add_sanitizer_rt_symbols(clang_rt.tsan-${arch} rtl/tsan.syms.extra)
99 add_dependencies(tsan clang_rt.tsan-${arch}
100 clang_rt.tsan-${arch}-symbols)
103 add_dependencies(compiler-rt tsan)
105 # Build libcxx instrumented with TSan.
106 if(COMPILER_RT_HAS_LIBCXX_SOURCES AND
107 COMPILER_RT_TEST_COMPILER STREQUAL "Clang")
108 set(LIBCXX_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/libcxx_tsan)
109 add_custom_libcxx(libcxx_tsan ${LIBCXX_PREFIX}
110 DEPS ${TSAN_RUNTIME_LIBRARIES}
111 CFLAGS -fsanitize=thread)
114 if(COMPILER_RT_INCLUDE_TESTS)
115 add_subdirectory(tests)