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(TSAN_CFLAGS COMPILER_RT_HAS_FPIE_FLAG -fPIE)
9 append_no_rtti_flag(TSAN_CFLAGS)
11 set(TSAN_RTL_CFLAGS ${TSAN_CFLAGS})
12 append_if(TSAN_RTL_CFLAGS COMPILER_RT_HAS_WFRAME_LARGER_THAN_FLAG -Wframe-larger-than=512)
13 append_if(TSAN_RTL_CFLAGS COMPILER_RT_HAS_WGLOBAL_CONSTRUCTORS_FLAG -Wglobal-constructors)
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
42 rtl/tsan_suppressions.cc
47 list(APPEND TSAN_SOURCES rtl/tsan_platform_mac.cc)
50 list(APPEND TSAN_SOURCES
51 rtl/tsan_platform_linux.cc)
54 add_custom_target(tsan)
55 # TSan is currently supported on 64-bit Linux only.
56 if(CAN_TARGET_x86_64 AND UNIX AND NOT APPLE)
57 set(TSAN_ASM_SOURCES rtl/tsan_rtl_amd64.S)
58 # Pass ASM file directly to the C++ compiler.
59 set_source_files_properties(${TSAN_ASM_SOURCES} PROPERTIES
62 add_compiler_rt_static_runtime(clang_rt.tsan-${arch} ${arch}
63 SOURCES ${TSAN_SOURCES} ${TSAN_ASM_SOURCES}
64 $<TARGET_OBJECTS:RTInterception.${arch}>
65 $<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
66 $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>
67 CFLAGS ${TSAN_RTL_CFLAGS}
68 DEFS ${TSAN_COMMON_DEFINITIONS})
69 add_sanitizer_rt_symbols(clang_rt.tsan-${arch} rtl/tsan.syms.extra)
70 add_dependencies(tsan clang_rt.tsan-${arch}
71 clang_rt.tsan-${arch}-symbols)
74 if(LLVM_INCLUDE_TESTS)
75 add_subdirectory(tests)