summaryrefslogtreecommitdiff
path: root/lib/tsan/CMakeLists.txt
blob: fc1944b02fa57ab725180af6fd5d48dda9eaaf05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# Build for the ThreadSanitizer runtime support library.

include_directories(..)

# 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.
set(TSAN_CFLAGS
  ${SANITIZER_COMMON_CFLAGS}
  -fPIE
  -fno-rtti)

set(TSAN_RTL_CFLAGS
  ${TSAN_CFLAGS}
  -Wframe-larger-than=512)
if(SUPPORTS_GLOBAL_CONSTRUCTORS_FLAG)
  list(APPEND TSAN_RTL_CFLAGS -Wglobal-constructors)
endif()
# FIXME: Add support for --sysroot=. compile flag:

if("${CMAKE_BUILD_TYPE}" EQUAL "Release")
  set(TSAN_COMMON_DEFINITIONS DEBUG=0)
else()
  set(TSAN_COMMON_DEFINITIONS DEBUG=1)
endif()

set(TSAN_SOURCES
  rtl/tsan_clock.cc
  rtl/tsan_flags.cc
  rtl/tsan_fd.cc
  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
    rtl/tsan_platform_linux.cc
    rtl/tsan_symbolize_addr2line_linux.cc)
endif()

set(TSAN_RUNTIME_LIBRARIES)
# 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")
  add_compiler_rt_static_runtime(clang_rt.tsan-${arch} ${arch}
    SOURCES ${TSAN_SOURCES} ${TSAN_ASM_SOURCES}
            $<TARGET_OBJECTS:RTInterception.${arch}>
            $<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
            $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>
    CFLAGS ${TSAN_RTL_CFLAGS}
    DEFS ${TSAN_COMMON_DEFINITIONS})
  add_sanitizer_rt_symbols(clang_rt.tsan-${arch} rtl/tsan.syms.extra)
  list(APPEND TSAN_RUNTIME_LIBRARIES clang_rt.tsan-${arch}
    clang_rt.tsan-${arch}-symbols)
endif()

if(LLVM_INCLUDE_TESTS)
  add_subdirectory(tests)
endif()
add_subdirectory(lit_tests)