2012-09-13 20:18:41 +08:00
|
|
|
# Build for the ThreadSanitizer runtime support library.
|
2012-05-15 23:17:35 +08:00
|
|
|
|
2012-09-13 20:18:41 +08:00
|
|
|
include_directories(..)
|
2012-05-15 23:17:35 +08:00
|
|
|
|
2014-02-18 16:07:09 +08:00
|
|
|
set(TSAN_CFLAGS ${SANITIZER_COMMON_CFLAGS})
|
2013-03-29 17:44:11 +08:00
|
|
|
# SANITIZER_COMMON_CFLAGS contains -fPIC, but it's performance-critical for
|
|
|
|
# TSan runtime to be built with -fPIE to reduce the number of register spills.
|
2014-03-13 17:31:36 +08:00
|
|
|
append_if(COMPILER_RT_HAS_FPIE_FLAG -fPIE TSAN_CFLAGS)
|
2014-02-18 15:52:40 +08:00
|
|
|
append_no_rtti_flag(TSAN_CFLAGS)
|
2013-08-29 20:08:36 +08:00
|
|
|
|
2014-02-12 15:26:40 +08:00
|
|
|
set(TSAN_RTL_CFLAGS ${TSAN_CFLAGS})
|
2014-03-13 17:31:36 +08:00
|
|
|
append_if(COMPILER_RT_HAS_WFRAME_LARGER_THAN_FLAG -Wframe-larger-than=512 TSAN_RTL_CFLAGS)
|
|
|
|
append_if(COMPILER_RT_HAS_WGLOBAL_CONSTRUCTORS_FLAG -Wglobal-constructors TSAN_RTL_CFLAGS)
|
2013-08-29 20:08:36 +08:00
|
|
|
# FIXME: Add support for --sysroot=. compile flag:
|
2012-09-13 20:18:41 +08:00
|
|
|
|
|
|
|
if("${CMAKE_BUILD_TYPE}" EQUAL "Release")
|
|
|
|
set(TSAN_COMMON_DEFINITIONS DEBUG=0)
|
|
|
|
else()
|
|
|
|
set(TSAN_COMMON_DEFINITIONS DEBUG=1)
|
2012-05-15 23:17:35 +08:00
|
|
|
endif()
|
2012-09-13 20:18:41 +08:00
|
|
|
|
2013-08-29 19:53:11 +08:00
|
|
|
set(TSAN_SOURCES
|
|
|
|
rtl/tsan_clock.cc
|
|
|
|
rtl/tsan_flags.cc
|
|
|
|
rtl/tsan_fd.cc
|
2013-11-27 19:30:28 +08:00
|
|
|
rtl/tsan_ignoreset.cc
|
2013-08-29 19:53:11 +08:00
|
|
|
rtl/tsan_interceptors.cc
|
|
|
|
rtl/tsan_interface_ann.cc
|
|
|
|
rtl/tsan_interface_atomic.cc
|
|
|
|
rtl/tsan_interface.cc
|
|
|
|
rtl/tsan_interface_java.cc
|
|
|
|
rtl/tsan_md5.cc
|
|
|
|
rtl/tsan_mman.cc
|
|
|
|
rtl/tsan_mutex.cc
|
|
|
|
rtl/tsan_mutexset.cc
|
|
|
|
rtl/tsan_report.cc
|
|
|
|
rtl/tsan_rtl.cc
|
|
|
|
rtl/tsan_rtl_mutex.cc
|
|
|
|
rtl/tsan_rtl_report.cc
|
|
|
|
rtl/tsan_rtl_thread.cc
|
|
|
|
rtl/tsan_stat.cc
|
|
|
|
rtl/tsan_suppressions.cc
|
|
|
|
rtl/tsan_symbolize.cc
|
|
|
|
rtl/tsan_sync.cc)
|
|
|
|
|
|
|
|
if(APPLE)
|
|
|
|
list(APPEND TSAN_SOURCES rtl/tsan_platform_mac.cc)
|
|
|
|
elseif(UNIX)
|
|
|
|
# Assume Linux
|
|
|
|
list(APPEND TSAN_SOURCES
|
2014-02-12 16:37:09 +08:00
|
|
|
rtl/tsan_platform_linux.cc)
|
2013-08-29 19:53:11 +08:00
|
|
|
endif()
|
|
|
|
|
2014-02-20 20:03:56 +08:00
|
|
|
set(TSAN_HEADERS
|
|
|
|
rtl/tsan_clock.h
|
|
|
|
rtl/tsan_defs.h
|
|
|
|
rtl/tsan_fd.h
|
|
|
|
rtl/tsan_flags.h
|
|
|
|
rtl/tsan_ignoreset.h
|
|
|
|
rtl/tsan_interface_ann.h
|
|
|
|
rtl/tsan_interface.h
|
|
|
|
rtl/tsan_interface_inl.h
|
|
|
|
rtl/tsan_interface_java.h
|
|
|
|
rtl/tsan_mman.h
|
|
|
|
rtl/tsan_mutex.h
|
|
|
|
rtl/tsan_mutexset.h
|
|
|
|
rtl/tsan_platform.h
|
|
|
|
rtl/tsan_report.h
|
|
|
|
rtl/tsan_rtl.h
|
|
|
|
rtl/tsan_stat.h
|
|
|
|
rtl/tsan_suppressions.h
|
|
|
|
rtl/tsan_symbolize.h
|
|
|
|
rtl/tsan_sync.h
|
|
|
|
rtl/tsan_trace.h
|
|
|
|
rtl/tsan_update_shadow_word_inl.h
|
|
|
|
rtl/tsan_vector.h)
|
|
|
|
|
2014-05-14 06:30:16 +08:00
|
|
|
set(TSAN_RUNTIME_LIBRARIES)
|
2014-02-14 22:35:48 +08:00
|
|
|
add_custom_target(tsan)
|
2013-08-29 19:53:11 +08:00
|
|
|
# TSan is currently supported on 64-bit Linux only.
|
|
|
|
if(CAN_TARGET_x86_64 AND UNIX AND NOT APPLE)
|
|
|
|
set(TSAN_ASM_SOURCES rtl/tsan_rtl_amd64.S)
|
|
|
|
# Pass ASM file directly to the C++ compiler.
|
|
|
|
set_source_files_properties(${TSAN_ASM_SOURCES} PROPERTIES
|
|
|
|
LANGUAGE C)
|
|
|
|
set(arch "x86_64")
|
2014-03-31 21:45:36 +08:00
|
|
|
add_compiler_rt_runtime(clang_rt.tsan-${arch} ${arch} STATIC
|
2013-08-29 19:53:11 +08:00
|
|
|
SOURCES ${TSAN_SOURCES} ${TSAN_ASM_SOURCES}
|
|
|
|
$<TARGET_OBJECTS:RTInterception.${arch}>
|
|
|
|
$<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
|
|
|
|
$<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>
|
2013-08-29 20:08:36 +08:00
|
|
|
CFLAGS ${TSAN_RTL_CFLAGS}
|
2013-08-29 19:53:11 +08:00
|
|
|
DEFS ${TSAN_COMMON_DEFINITIONS})
|
2014-05-14 06:30:16 +08:00
|
|
|
list(APPEND TSAN_RUNTIME_LIBRARIES clang_rt.tsan-${arch})
|
2013-08-29 19:53:11 +08:00
|
|
|
add_sanitizer_rt_symbols(clang_rt.tsan-${arch} rtl/tsan.syms.extra)
|
2014-02-14 22:35:48 +08:00
|
|
|
add_dependencies(tsan clang_rt.tsan-${arch}
|
2013-08-29 19:53:11 +08:00
|
|
|
clang_rt.tsan-${arch}-symbols)
|
|
|
|
endif()
|
2012-09-13 22:04:57 +08:00
|
|
|
|
2014-02-18 17:33:45 +08:00
|
|
|
add_dependencies(compiler-rt tsan)
|
|
|
|
|
2014-05-14 06:30:16 +08:00
|
|
|
# Build libcxx instrumented with TSan.
|
2014-05-17 02:22:04 +08:00
|
|
|
if(COMPILER_RT_HAS_LIBCXX_SOURCES AND
|
|
|
|
COMPILER_RT_TEST_COMPILER STREQUAL "Clang")
|
2014-05-14 06:30:16 +08:00
|
|
|
set(LIBCXX_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/libcxx_tsan)
|
|
|
|
add_custom_libcxx(libcxx_tsan ${LIBCXX_PREFIX}
|
|
|
|
DEPS ${TSAN_RUNTIME_LIBRARIES}
|
|
|
|
CFLAGS -fsanitize=thread)
|
|
|
|
endif()
|
|
|
|
|
2014-02-19 19:18:47 +08:00
|
|
|
if(COMPILER_RT_INCLUDE_TESTS)
|
2012-09-17 18:02:17 +08:00
|
|
|
add_subdirectory(tests)
|
2012-09-13 22:04:57 +08:00
|
|
|
endif()
|