blob: fc1944b02fa57ab725180af6fd5d48dda9eaaf05 [file] [log] [blame]
Alexey Samsonov79c68262012-09-13 12:18:41 +00001# Build for the ThreadSanitizer runtime support library.
Kostya Serebryany4026c2c2012-05-15 15:17:35 +00002
Alexey Samsonov79c68262012-09-13 12:18:41 +00003include_directories(..)
Kostya Serebryany4026c2c2012-05-15 15:17:35 +00004
Alexander Potapenko76030b32013-03-29 09:44:11 +00005# SANITIZER_COMMON_CFLAGS contains -fPIC, but it's performance-critical for
6# TSan runtime to be built with -fPIE to reduce the number of register spills.
Alexey Samsonova7e5db92013-03-13 09:18:30 +00007set(TSAN_CFLAGS
8 ${SANITIZER_COMMON_CFLAGS}
Alexander Potapenko76030b32013-03-29 09:44:11 +00009 -fPIE
Alexey Samsonova7e5db92013-03-13 09:18:30 +000010 -fno-rtti)
Alexey Samsonov0bc4a0b2013-08-29 12:08:36 +000011
12set(TSAN_RTL_CFLAGS
13 ${TSAN_CFLAGS}
14 -Wframe-larger-than=512)
15if(SUPPORTS_GLOBAL_CONSTRUCTORS_FLAG)
16 list(APPEND TSAN_RTL_CFLAGS -Wglobal-constructors)
17endif()
18# FIXME: Add support for --sysroot=. compile flag:
Alexey Samsonov79c68262012-09-13 12:18:41 +000019
20if("${CMAKE_BUILD_TYPE}" EQUAL "Release")
21 set(TSAN_COMMON_DEFINITIONS DEBUG=0)
22else()
23 set(TSAN_COMMON_DEFINITIONS DEBUG=1)
Kostya Serebryany4026c2c2012-05-15 15:17:35 +000024endif()
Alexey Samsonov79c68262012-09-13 12:18:41 +000025
Alexey Samsonovd9760ab2013-08-29 11:53:11 +000026set(TSAN_SOURCES
27 rtl/tsan_clock.cc
28 rtl/tsan_flags.cc
29 rtl/tsan_fd.cc
30 rtl/tsan_interceptors.cc
31 rtl/tsan_interface_ann.cc
32 rtl/tsan_interface_atomic.cc
33 rtl/tsan_interface.cc
34 rtl/tsan_interface_java.cc
35 rtl/tsan_md5.cc
36 rtl/tsan_mman.cc
37 rtl/tsan_mutex.cc
38 rtl/tsan_mutexset.cc
39 rtl/tsan_report.cc
40 rtl/tsan_rtl.cc
41 rtl/tsan_rtl_mutex.cc
42 rtl/tsan_rtl_report.cc
43 rtl/tsan_rtl_thread.cc
44 rtl/tsan_stat.cc
45 rtl/tsan_suppressions.cc
46 rtl/tsan_symbolize.cc
47 rtl/tsan_sync.cc)
48
49if(APPLE)
50 list(APPEND TSAN_SOURCES rtl/tsan_platform_mac.cc)
51elseif(UNIX)
52 # Assume Linux
53 list(APPEND TSAN_SOURCES
54 rtl/tsan_platform_linux.cc
55 rtl/tsan_symbolize_addr2line_linux.cc)
56endif()
57
58set(TSAN_RUNTIME_LIBRARIES)
59# TSan is currently supported on 64-bit Linux only.
60if(CAN_TARGET_x86_64 AND UNIX AND NOT APPLE)
61 set(TSAN_ASM_SOURCES rtl/tsan_rtl_amd64.S)
62 # Pass ASM file directly to the C++ compiler.
63 set_source_files_properties(${TSAN_ASM_SOURCES} PROPERTIES
64 LANGUAGE C)
65 set(arch "x86_64")
66 add_compiler_rt_static_runtime(clang_rt.tsan-${arch} ${arch}
67 SOURCES ${TSAN_SOURCES} ${TSAN_ASM_SOURCES}
68 $<TARGET_OBJECTS:RTInterception.${arch}>
69 $<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
70 $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>
Alexey Samsonov0bc4a0b2013-08-29 12:08:36 +000071 CFLAGS ${TSAN_RTL_CFLAGS}
Alexey Samsonovd9760ab2013-08-29 11:53:11 +000072 DEFS ${TSAN_COMMON_DEFINITIONS})
73 add_sanitizer_rt_symbols(clang_rt.tsan-${arch} rtl/tsan.syms.extra)
74 list(APPEND TSAN_RUNTIME_LIBRARIES clang_rt.tsan-${arch}
75 clang_rt.tsan-${arch}-symbols)
76endif()
Alexey Samsonov484db992012-09-13 14:04:57 +000077
78if(LLVM_INCLUDE_TESTS)
Alexey Samsonovf548ef82012-09-17 10:02:17 +000079 add_subdirectory(tests)
Alexey Samsonov484db992012-09-13 14:04:57 +000080endif()
Alexey Samsonovf548ef82012-09-17 10:02:17 +000081add_subdirectory(lit_tests)