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-10-16 06:47:54 +08:00
|
|
|
append_list_if(COMPILER_RT_HAS_FPIE_FLAG -fPIE TSAN_CFLAGS)
|
2016-03-05 18:01:04 +08:00
|
|
|
append_rtti_flag(OFF TSAN_CFLAGS)
|
2013-08-29 20:08:36 +08:00
|
|
|
|
2015-12-05 09:37:17 +08:00
|
|
|
if(COMPILER_RT_TSAN_DEBUG_OUTPUT)
|
|
|
|
# Add extra debug information to TSan runtime. This configuration is rarely
|
|
|
|
# used, but we need to support it so that debug output will not bitrot.
|
|
|
|
list(APPEND TSAN_CFLAGS -DTSAN_COLLECT_STATS=1
|
|
|
|
-DTSAN_DEBUG_OUTPUT=2)
|
|
|
|
endif()
|
|
|
|
|
2014-02-12 15:26:40 +08:00
|
|
|
set(TSAN_RTL_CFLAGS ${TSAN_CFLAGS})
|
2015-02-03 04:37:25 +08:00
|
|
|
append_list_if(COMPILER_RT_HAS_MSSE3_FLAG -msse3 TSAN_RTL_CFLAGS)
|
2016-09-02 04:43:59 +08:00
|
|
|
append_list_if(SANITIZER_LIMIT_FRAME_SIZE -Wframe-larger-than=530
|
2015-01-03 12:29:12 +08:00
|
|
|
TSAN_RTL_CFLAGS)
|
|
|
|
append_list_if(COMPILER_RT_HAS_WGLOBAL_CONSTRUCTORS_FLAG -Wglobal-constructors
|
|
|
|
TSAN_RTL_CFLAGS)
|
2012-09-13 20:18:41 +08:00
|
|
|
|
2013-08-29 19:53:11 +08:00
|
|
|
set(TSAN_SOURCES
|
|
|
|
rtl/tsan_clock.cc
|
2016-03-11 01:00:29 +08:00
|
|
|
rtl/tsan_debugging.cc
|
2013-08-29 19:53:11 +08:00
|
|
|
rtl/tsan_fd.cc
|
2016-05-27 01:05:36 +08:00
|
|
|
rtl/tsan_flags.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
|
2016-05-27 01:05:36 +08:00
|
|
|
rtl/tsan_interface.cc
|
2013-08-29 19:53:11 +08:00
|
|
|
rtl/tsan_interface_ann.cc
|
|
|
|
rtl/tsan_interface_atomic.cc
|
|
|
|
rtl/tsan_interface_java.cc
|
2015-11-05 18:31:21 +08:00
|
|
|
rtl/tsan_malloc_mac.cc
|
2013-08-29 19:53:11 +08:00
|
|
|
rtl/tsan_md5.cc
|
|
|
|
rtl/tsan_mman.cc
|
|
|
|
rtl/tsan_mutex.cc
|
|
|
|
rtl/tsan_mutexset.cc
|
2016-05-27 01:05:36 +08:00
|
|
|
rtl/tsan_preinit.cc
|
2013-08-29 19:53:11 +08:00
|
|
|
rtl/tsan_report.cc
|
|
|
|
rtl/tsan_rtl.cc
|
|
|
|
rtl/tsan_rtl_mutex.cc
|
2016-04-27 16:23:02 +08:00
|
|
|
rtl/tsan_rtl_proc.cc
|
2016-05-27 01:05:36 +08:00
|
|
|
rtl/tsan_rtl_report.cc
|
2013-08-29 19:53:11 +08:00
|
|
|
rtl/tsan_rtl_thread.cc
|
2014-05-29 21:50:54 +08:00
|
|
|
rtl/tsan_stack_trace.cc
|
2013-08-29 19:53:11 +08:00
|
|
|
rtl/tsan_stat.cc
|
|
|
|
rtl/tsan_suppressions.cc
|
|
|
|
rtl/tsan_symbolize.cc
|
|
|
|
rtl/tsan_sync.cc)
|
|
|
|
|
2015-04-28 06:08:09 +08:00
|
|
|
set(TSAN_CXX_SOURCES
|
|
|
|
rtl/tsan_new_delete.cc)
|
|
|
|
|
2013-08-29 19:53:11 +08:00
|
|
|
if(APPLE)
|
2015-11-04 19:39:40 +08:00
|
|
|
list(APPEND TSAN_SOURCES
|
2015-12-03 23:10:52 +08:00
|
|
|
rtl/tsan_interceptors_mac.cc
|
2015-11-19 18:35:35 +08:00
|
|
|
rtl/tsan_libdispatch_mac.cc
|
2015-11-04 19:39:40 +08:00
|
|
|
rtl/tsan_platform_mac.cc
|
|
|
|
rtl/tsan_platform_posix.cc)
|
2013-08-29 19:53:11 +08:00
|
|
|
elseif(UNIX)
|
|
|
|
# Assume Linux
|
|
|
|
list(APPEND TSAN_SOURCES
|
2015-11-04 19:39:40 +08:00
|
|
|
rtl/tsan_platform_linux.cc
|
|
|
|
rtl/tsan_platform_posix.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
|
2014-05-29 21:50:54 +08:00
|
|
|
rtl/tsan_dense_alloc.h
|
2014-02-20 20:03:56 +08:00
|
|
|
rtl/tsan_fd.h
|
|
|
|
rtl/tsan_flags.h
|
2015-01-07 08:38:00 +08:00
|
|
|
rtl/tsan_flags.inc
|
2014-02-20 20:03:56 +08:00
|
|
|
rtl/tsan_ignoreset.h
|
2015-04-28 03:33:55 +08:00
|
|
|
rtl/tsan_interceptors.h
|
2014-02-20 20:03:56 +08:00
|
|
|
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
|
2014-05-29 21:50:54 +08:00
|
|
|
rtl/tsan_stack_trace.h
|
2014-02-20 20:03:56 +08:00
|
|
|
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)
|
2016-08-27 04:52:22 +08:00
|
|
|
add_compiler_rt_component(tsan)
|
2012-09-13 22:04:57 +08:00
|
|
|
|
2015-11-03 22:13:59 +08:00
|
|
|
if(APPLE)
|
2015-11-28 20:44:23 +08:00
|
|
|
set(TSAN_ASM_SOURCES rtl/tsan_rtl_amd64.S)
|
2016-08-19 16:03:26 +08:00
|
|
|
# Xcode will try to compile this file as C ('clang -x c'), and that will fail.
|
|
|
|
if (${CMAKE_GENERATOR} STREQUAL "Xcode")
|
|
|
|
enable_language(ASM)
|
|
|
|
else()
|
|
|
|
# Pass ASM file directly to the C++ compiler.
|
|
|
|
set_source_files_properties(${TSAN_ASM_SOURCES} PROPERTIES LANGUAGE C)
|
|
|
|
endif()
|
2015-08-26 03:53:09 +08:00
|
|
|
add_compiler_rt_runtime(clang_rt.tsan
|
2015-11-03 22:13:59 +08:00
|
|
|
SHARED
|
|
|
|
OS ${TSAN_SUPPORTED_OS}
|
|
|
|
ARCHS ${TSAN_SUPPORTED_ARCH}
|
2015-11-28 20:44:23 +08:00
|
|
|
SOURCES ${TSAN_SOURCES} ${TSAN_CXX_SOURCES} ${TSAN_ASM_SOURCES}
|
2015-11-03 22:13:59 +08:00
|
|
|
OBJECT_LIBS RTInterception
|
|
|
|
RTSanitizerCommon
|
|
|
|
RTSanitizerCommonLibc
|
|
|
|
RTUbsan
|
|
|
|
CFLAGS ${TSAN_RTL_CFLAGS}
|
|
|
|
PARENT_TARGET tsan)
|
2016-05-27 01:05:36 +08:00
|
|
|
add_compiler_rt_object_libraries(RTTsan_dynamic
|
2015-11-29 16:48:47 +08:00
|
|
|
OS ${TSAN_SUPPORTED_OS}
|
|
|
|
ARCHS ${TSAN_SUPPORTED_ARCH}
|
|
|
|
SOURCES ${TSAN_SOURCES} ${TSAN_CXX_SOURCES} ${TSAN_ASM_SOURCES}
|
|
|
|
CFLAGS ${TSAN_RTL_CFLAGS})
|
2015-12-04 22:29:11 +08:00
|
|
|
|
|
|
|
# Build and check Go runtime.
|
|
|
|
set(BUILDGO_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/go/buildgo.sh)
|
|
|
|
add_custom_target(GotsanRuntimeCheck
|
|
|
|
COMMAND env "CC=${CMAKE_C_COMPILER} ${OSX_SYSROOT_FLAG}"
|
|
|
|
IN_TMPDIR=1 SILENT=1 ${BUILDGO_SCRIPT}
|
|
|
|
DEPENDS tsan ${BUILDGO_SCRIPT}
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/go
|
|
|
|
COMMENT "Checking TSan Go runtime..."
|
|
|
|
VERBATIM)
|
2015-11-03 22:13:59 +08:00
|
|
|
else()
|
|
|
|
foreach(arch ${TSAN_SUPPORTED_ARCH})
|
|
|
|
if(arch STREQUAL "x86_64")
|
|
|
|
set(TSAN_ASM_SOURCES rtl/tsan_rtl_amd64.S)
|
2016-08-19 16:03:26 +08:00
|
|
|
# Pass ASM file directly to the C++ compiler.
|
|
|
|
set_source_files_properties(${TSAN_ASM_SOURCES} PROPERTIES
|
|
|
|
LANGUAGE C)
|
2015-11-03 22:13:59 +08:00
|
|
|
# Sanity check for Go runtime.
|
|
|
|
set(BUILDGO_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/go/buildgo.sh)
|
|
|
|
add_custom_target(GotsanRuntimeCheck
|
|
|
|
COMMAND env "CC=${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}"
|
|
|
|
IN_TMPDIR=1 SILENT=1 ${BUILDGO_SCRIPT}
|
|
|
|
DEPENDS clang_rt.tsan-${arch} ${BUILDGO_SCRIPT}
|
|
|
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/go
|
|
|
|
COMMENT "Checking TSan Go runtime..."
|
|
|
|
VERBATIM)
|
2015-11-16 21:55:19 +08:00
|
|
|
elseif(arch STREQUAL "aarch64")
|
|
|
|
set(TSAN_ASM_SOURCES rtl/tsan_rtl_aarch64.S)
|
2016-08-19 16:03:26 +08:00
|
|
|
# Pass ASM file directly to the C++ compiler.
|
|
|
|
set_source_files_properties(${TSAN_ASM_SOURCES} PROPERTIES
|
|
|
|
LANGUAGE C)
|
2015-12-09 06:14:34 +08:00
|
|
|
elseif(arch MATCHES "powerpc64|powerpc64le")
|
|
|
|
set(TSAN_ASM_SOURCES rtl/tsan_rtl_ppc64.S)
|
2016-08-19 16:03:26 +08:00
|
|
|
# Pass ASM file directly to the C++ compiler.
|
|
|
|
set_source_files_properties(${TSAN_ASM_SOURCES} PROPERTIES
|
|
|
|
LANGUAGE C)
|
2016-08-16 13:06:56 +08:00
|
|
|
elseif(arch MATCHES "mips64|mips64le")
|
|
|
|
set(TSAN_ASM_SOURCES rtl/tsan_rtl_mips64.S)
|
2016-08-19 16:03:26 +08:00
|
|
|
# Pass ASM file directly to the C++ compiler.
|
|
|
|
set_source_files_properties(${TSAN_ASM_SOURCES} PROPERTIES
|
|
|
|
LANGUAGE C)
|
2015-11-03 22:13:59 +08:00
|
|
|
else()
|
|
|
|
set(TSAN_ASM_SOURCES)
|
|
|
|
endif()
|
|
|
|
add_compiler_rt_runtime(clang_rt.tsan
|
|
|
|
STATIC
|
|
|
|
ARCHS ${arch}
|
|
|
|
SOURCES ${TSAN_SOURCES} ${TSAN_ASM_SOURCES}
|
|
|
|
$<TARGET_OBJECTS:RTInterception.${arch}>
|
|
|
|
$<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
|
|
|
|
$<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>
|
|
|
|
$<TARGET_OBJECTS:RTUbsan.${arch}>
|
|
|
|
CFLAGS ${TSAN_RTL_CFLAGS})
|
|
|
|
add_compiler_rt_runtime(clang_rt.tsan_cxx
|
|
|
|
STATIC
|
|
|
|
ARCHS ${arch}
|
|
|
|
SOURCES ${TSAN_CXX_SOURCES}
|
|
|
|
$<TARGET_OBJECTS:RTUbsan_cxx.${arch}>
|
|
|
|
CFLAGS ${TSAN_RTL_CFLAGS})
|
|
|
|
list(APPEND TSAN_RUNTIME_LIBRARIES clang_rt.tsan-${arch}
|
|
|
|
clang_rt.tsan_cxx-${arch})
|
|
|
|
add_sanitizer_rt_symbols(clang_rt.tsan
|
|
|
|
ARCHS ${arch}
|
|
|
|
EXTRA rtl/tsan.syms.extra)
|
|
|
|
add_sanitizer_rt_symbols(clang_rt.tsan_cxx
|
|
|
|
ARCHS ${arch}
|
|
|
|
EXTRA rtl/tsan.syms.extra)
|
|
|
|
add_dependencies(tsan clang_rt.tsan-${arch}
|
|
|
|
clang_rt.tsan_cxx-${arch}
|
|
|
|
clang_rt.tsan-${arch}-symbols
|
|
|
|
clang_rt.tsan_cxx-${arch}-symbols)
|
|
|
|
endforeach()
|
|
|
|
endif()
|
2014-02-18 17:33:45 +08:00
|
|
|
|
2015-12-08 07:21:36 +08:00
|
|
|
# Make sure that non-platform-specific files don't include any system headers.
|
2016-02-19 01:35:30 +08:00
|
|
|
# FreeBSD does not install a number of Clang-provided headers for the compiler
|
|
|
|
# in the base system due to incompatibilities between FreeBSD's and Clang's
|
|
|
|
# versions. As a workaround do not use --sysroot=. on FreeBSD until this is
|
2016-05-27 01:05:36 +08:00
|
|
|
# addressed.
|
2016-02-19 01:35:30 +08:00
|
|
|
if(COMPILER_RT_HAS_SYSROOT_FLAG AND NOT CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
|
2015-12-08 07:21:36 +08:00
|
|
|
file(GLOB _tsan_generic_sources rtl/tsan*)
|
|
|
|
file(GLOB _tsan_platform_sources rtl/tsan*posix* rtl/tsan*mac*
|
|
|
|
rtl/tsan*linux*)
|
|
|
|
list(REMOVE_ITEM _tsan_generic_sources ${_tsan_platform_sources})
|
|
|
|
set_source_files_properties(${_tsan_generic_sources}
|
|
|
|
PROPERTIES COMPILE_FLAGS "--sysroot=.")
|
|
|
|
endif()
|
|
|
|
|
2014-05-14 06:30:16 +08:00
|
|
|
# Build libcxx instrumented with TSan.
|
2015-06-18 06:24:49 +08:00
|
|
|
if(COMPILER_RT_HAS_LIBCXX_SOURCES AND
|
2014-07-11 02:17:51 +08:00
|
|
|
COMPILER_RT_TEST_COMPILER_ID STREQUAL "Clang")
|
2016-02-03 02:43:53 +08:00
|
|
|
set(libcxx_tsan_deps)
|
|
|
|
foreach(arch ${TSAN_SUPPORTED_ARCH})
|
|
|
|
get_target_flags_for_arch(${arch} TARGET_CFLAGS)
|
|
|
|
set(LIBCXX_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/libcxx_tsan_${arch})
|
|
|
|
add_custom_libcxx(libcxx_tsan_${arch} ${LIBCXX_PREFIX}
|
|
|
|
DEPS ${TSAN_RUNTIME_LIBRARIES}
|
|
|
|
CFLAGS ${TARGET_CFLAGS} -fsanitize=thread)
|
|
|
|
list(APPEND libcxx_tsan_deps libcxx_tsan_${arch})
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
add_custom_target(libcxx_tsan DEPENDS ${libcxx_tsan_deps})
|
2014-05-14 06:30:16 +08:00
|
|
|
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()
|