1 # Build for the ThreadSanitizer runtime support library.
3 set(TSAN_CFLAGS ${SANITIZER_COMMON_CFLAGS})
4 # SANITIZER_COMMON_CFLAGS contains -fPIC, but it's performance-critical for
5 # TSan runtime to be built with -fPIE to reduce the number of register spills.
6 # On FreeBSD however it provokes linkage issue thus we disable it.
7 if(NOT CMAKE_SYSTEM MATCHES "FreeBSD")
8 append_list_if(COMPILER_RT_HAS_FPIE_FLAG -fPIE TSAN_CFLAGS)
10 append_rtti_flag(OFF TSAN_CFLAGS)
12 if(COMPILER_RT_TSAN_DEBUG_OUTPUT)
13 # Add extra debug information to TSan runtime. This configuration is rarely
14 # used, but we need to support it so that debug output will not bitrot.
15 list(APPEND TSAN_CFLAGS -DTSAN_DEBUG_OUTPUT=2)
18 # Add the actual runtime library.
21 # Build libcxx instrumented with TSan.
22 if(COMPILER_RT_LIBCXX_PATH AND
23 COMPILER_RT_LIBCXXABI_PATH AND
24 COMPILER_RT_TEST_COMPILER_ID STREQUAL "Clang" AND
27 foreach(arch ${TSAN_SUPPORTED_ARCH})
28 get_target_flags_for_arch(${arch} TARGET_CFLAGS)
29 set(LIBCXX_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/libcxx_tsan_${arch})
30 add_custom_libcxx(libcxx_tsan_${arch} ${LIBCXX_PREFIX}
31 DEPS ${TSAN_RUNTIME_LIBRARIES}
32 CFLAGS ${TARGET_CFLAGS} -fsanitize=thread
34 list(APPEND libcxx_tsan_deps libcxx_tsan_${arch}-build)
37 add_custom_target(libcxx_tsan DEPENDS ${libcxx_tsan_deps})
38 set_target_properties(libcxx_tsan PROPERTIES FOLDER "Compiler-RT Misc")
41 if(COMPILER_RT_INCLUDE_TESTS)
42 add_subdirectory(tests)