[ASan/Win tests] Add a PR reference for the FileCheck bug
[blocksruntime.git] / lib / tsan / CMakeLists.txt
blobabb047649d26a161651345e09b699d318026645e
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(COMPILER_RT_HAS_FPIE_FLAG -fPIE TSAN_CFLAGS)
9 append_no_rtti_flag(TSAN_CFLAGS)
11 set(TSAN_RTL_CFLAGS ${TSAN_CFLAGS})
12 append_if(COMPILER_RT_HAS_WFRAME_LARGER_THAN_FLAG -Wframe-larger-than=512 TSAN_RTL_CFLAGS)
13 append_if(COMPILER_RT_HAS_WGLOBAL_CONSTRUCTORS_FLAG -Wglobal-constructors TSAN_RTL_CFLAGS)
14 # FIXME: Add support for --sysroot=. compile flag:
16 if("${CMAKE_BUILD_TYPE}" EQUAL "Release")
17   set(TSAN_COMMON_DEFINITIONS DEBUG=0)
18 else()
19   set(TSAN_COMMON_DEFINITIONS DEBUG=1)
20 endif()
22 set(TSAN_SOURCES
23   rtl/tsan_clock.cc
24   rtl/tsan_flags.cc
25   rtl/tsan_fd.cc
26   rtl/tsan_ignoreset.cc
27   rtl/tsan_interceptors.cc
28   rtl/tsan_interface_ann.cc
29   rtl/tsan_interface_atomic.cc
30   rtl/tsan_interface.cc
31   rtl/tsan_interface_java.cc
32   rtl/tsan_md5.cc
33   rtl/tsan_mman.cc
34   rtl/tsan_mutex.cc
35   rtl/tsan_mutexset.cc
36   rtl/tsan_report.cc
37   rtl/tsan_rtl.cc
38   rtl/tsan_rtl_mutex.cc
39   rtl/tsan_rtl_report.cc
40   rtl/tsan_rtl_thread.cc
41   rtl/tsan_stat.cc
42   rtl/tsan_suppressions.cc
43   rtl/tsan_symbolize.cc
44   rtl/tsan_sync.cc)
46 if(APPLE)
47   list(APPEND TSAN_SOURCES rtl/tsan_platform_mac.cc)
48 elseif(UNIX)
49   # Assume Linux
50   list(APPEND TSAN_SOURCES
51     rtl/tsan_platform_linux.cc)
52 endif()
54 set(TSAN_HEADERS
55   rtl/tsan_clock.h
56   rtl/tsan_defs.h
57   rtl/tsan_fd.h
58   rtl/tsan_flags.h
59   rtl/tsan_ignoreset.h
60   rtl/tsan_interface_ann.h
61   rtl/tsan_interface.h
62   rtl/tsan_interface_inl.h
63   rtl/tsan_interface_java.h
64   rtl/tsan_mman.h
65   rtl/tsan_mutex.h
66   rtl/tsan_mutexset.h
67   rtl/tsan_platform.h
68   rtl/tsan_report.h
69   rtl/tsan_rtl.h
70   rtl/tsan_stat.h
71   rtl/tsan_suppressions.h
72   rtl/tsan_symbolize.h
73   rtl/tsan_sync.h
74   rtl/tsan_trace.h
75   rtl/tsan_update_shadow_word_inl.h
76   rtl/tsan_vector.h)
78 set(TSAN_RUNTIME_LIBRARIES)
79 add_custom_target(tsan)
80 # TSan is currently supported on 64-bit Linux only.
81 if(CAN_TARGET_x86_64 AND UNIX AND NOT APPLE)
82   set(TSAN_ASM_SOURCES rtl/tsan_rtl_amd64.S)
83   # Pass ASM file directly to the C++ compiler.
84   set_source_files_properties(${TSAN_ASM_SOURCES} PROPERTIES
85     LANGUAGE C)
86   set(arch "x86_64")
87   add_compiler_rt_runtime(clang_rt.tsan-${arch} ${arch} STATIC
88     SOURCES ${TSAN_SOURCES} ${TSAN_ASM_SOURCES}
89             $<TARGET_OBJECTS:RTInterception.${arch}>
90             $<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
91             $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>
92     CFLAGS ${TSAN_RTL_CFLAGS}
93     DEFS ${TSAN_COMMON_DEFINITIONS})
94   list(APPEND TSAN_RUNTIME_LIBRARIES clang_rt.tsan-${arch})
95   add_sanitizer_rt_symbols(clang_rt.tsan-${arch} rtl/tsan.syms.extra)
96   add_dependencies(tsan clang_rt.tsan-${arch}
97     clang_rt.tsan-${arch}-symbols)
98 endif()
100 add_dependencies(compiler-rt tsan)
102 # Build libcxx instrumented with TSan.
103 if(COMPILER_RT_HAS_LIBCXX_SOURCES)
104   set(LIBCXX_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/libcxx_tsan)
105   add_custom_libcxx(libcxx_tsan ${LIBCXX_PREFIX}
106     DEPS ${TSAN_RUNTIME_LIBRARIES}
107     CFLAGS -fsanitize=thread)
108 endif()
110 if(COMPILER_RT_INCLUDE_TESTS)
111   add_subdirectory(tests)
112 endif()