Alexey Samsonov | 79c6826 | 2012-09-13 12:18:41 +0000 | [diff] [blame] | 1 | # Build for the ThreadSanitizer runtime support library. |
Kostya Serebryany | 4026c2c | 2012-05-15 15:17:35 +0000 | [diff] [blame] | 2 | |
Alexey Samsonov | 79c6826 | 2012-09-13 12:18:41 +0000 | [diff] [blame] | 3 | include_directories(..) |
Kostya Serebryany | 4026c2c | 2012-05-15 15:17:35 +0000 | [diff] [blame] | 4 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 5 | set(TSAN_CFLAGS ${SANITIZER_COMMON_CFLAGS}) |
Alexander Potapenko | 76030b3 | 2013-03-29 09:44:11 +0000 | [diff] [blame] | 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. |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 8 | append_list_if(COMPILER_RT_HAS_FPIE_FLAG -fPIE TSAN_CFLAGS) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 9 | append_no_rtti_flag(TSAN_CFLAGS) |
Alexey Samsonov | 0bc4a0b | 2013-08-29 12:08:36 +0000 | [diff] [blame] | 10 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 11 | set(TSAN_RTL_CFLAGS ${TSAN_CFLAGS}) |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 12 | append_list_if(COMPILER_RT_HAS_MSSE3_FLAG -msse3 TSAN_RTL_CFLAGS) |
| 13 | append_list_if(SANITIZER_LIMIT_FRAME_SIZE -Wframe-larger-than=512 |
| 14 | TSAN_RTL_CFLAGS) |
| 15 | append_list_if(COMPILER_RT_HAS_WGLOBAL_CONSTRUCTORS_FLAG -Wglobal-constructors |
| 16 | TSAN_RTL_CFLAGS) |
Alexey Samsonov | 0bc4a0b | 2013-08-29 12:08:36 +0000 | [diff] [blame] | 17 | # FIXME: Add support for --sysroot=. compile flag: |
Alexey Samsonov | 79c6826 | 2012-09-13 12:18:41 +0000 | [diff] [blame] | 18 | |
Alexey Samsonov | d9760ab | 2013-08-29 11:53:11 +0000 | [diff] [blame] | 19 | set(TSAN_SOURCES |
| 20 | rtl/tsan_clock.cc |
| 21 | rtl/tsan_flags.cc |
| 22 | rtl/tsan_fd.cc |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 23 | rtl/tsan_ignoreset.cc |
Alexey Samsonov | d9760ab | 2013-08-29 11:53:11 +0000 | [diff] [blame] | 24 | rtl/tsan_interceptors.cc |
| 25 | rtl/tsan_interface_ann.cc |
| 26 | rtl/tsan_interface_atomic.cc |
| 27 | rtl/tsan_interface.cc |
| 28 | rtl/tsan_interface_java.cc |
| 29 | rtl/tsan_md5.cc |
| 30 | rtl/tsan_mman.cc |
| 31 | rtl/tsan_mutex.cc |
| 32 | rtl/tsan_mutexset.cc |
| 33 | rtl/tsan_report.cc |
| 34 | rtl/tsan_rtl.cc |
| 35 | rtl/tsan_rtl_mutex.cc |
| 36 | rtl/tsan_rtl_report.cc |
| 37 | rtl/tsan_rtl_thread.cc |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 38 | rtl/tsan_stack_trace.cc |
Alexey Samsonov | d9760ab | 2013-08-29 11:53:11 +0000 | [diff] [blame] | 39 | rtl/tsan_stat.cc |
| 40 | rtl/tsan_suppressions.cc |
| 41 | rtl/tsan_symbolize.cc |
| 42 | rtl/tsan_sync.cc) |
| 43 | |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 44 | set(TSAN_CXX_SOURCES |
| 45 | rtl/tsan_new_delete.cc) |
| 46 | |
Alexey Samsonov | d9760ab | 2013-08-29 11:53:11 +0000 | [diff] [blame] | 47 | if(APPLE) |
| 48 | list(APPEND TSAN_SOURCES rtl/tsan_platform_mac.cc) |
| 49 | elseif(UNIX) |
| 50 | # Assume Linux |
| 51 | list(APPEND TSAN_SOURCES |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 52 | rtl/tsan_platform_linux.cc) |
Alexey Samsonov | d9760ab | 2013-08-29 11:53:11 +0000 | [diff] [blame] | 53 | endif() |
| 54 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 55 | set(TSAN_HEADERS |
| 56 | rtl/tsan_clock.h |
| 57 | rtl/tsan_defs.h |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 58 | rtl/tsan_dense_alloc.h |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 59 | rtl/tsan_fd.h |
| 60 | rtl/tsan_flags.h |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 61 | rtl/tsan_flags.inc |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 62 | rtl/tsan_ignoreset.h |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 63 | rtl/tsan_interceptors.h |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 64 | rtl/tsan_interface_ann.h |
| 65 | rtl/tsan_interface.h |
| 66 | rtl/tsan_interface_inl.h |
| 67 | rtl/tsan_interface_java.h |
| 68 | rtl/tsan_mman.h |
| 69 | rtl/tsan_mutex.h |
| 70 | rtl/tsan_mutexset.h |
| 71 | rtl/tsan_platform.h |
| 72 | rtl/tsan_report.h |
| 73 | rtl/tsan_rtl.h |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 74 | rtl/tsan_stack_trace.h |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 75 | rtl/tsan_stat.h |
| 76 | rtl/tsan_suppressions.h |
| 77 | rtl/tsan_symbolize.h |
| 78 | rtl/tsan_sync.h |
| 79 | rtl/tsan_trace.h |
| 80 | rtl/tsan_update_shadow_word_inl.h |
| 81 | rtl/tsan_vector.h) |
| 82 | |
Alexey Samsonov | d9760ab | 2013-08-29 11:53:11 +0000 | [diff] [blame] | 83 | set(TSAN_RUNTIME_LIBRARIES) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 84 | add_custom_target(tsan) |
Alexey Samsonov | d9760ab | 2013-08-29 11:53:11 +0000 | [diff] [blame] | 85 | # TSan is currently supported on 64-bit Linux only. |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 86 | if(UNIX AND NOT APPLE) |
| 87 | foreach(arch ${TSAN_SUPPORTED_ARCH}) |
| 88 | if(arch STREQUAL "x86_64") |
| 89 | set(TSAN_ASM_SOURCES rtl/tsan_rtl_amd64.S) |
| 90 | # Pass ASM file directly to the C++ compiler. |
| 91 | set_source_files_properties(${TSAN_ASM_SOURCES} PROPERTIES |
| 92 | LANGUAGE C) |
| 93 | # Sanity check for Go runtime. |
| 94 | set(BUILDGO_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/go/buildgo.sh) |
| 95 | add_custom_target(GotsanRuntimeCheck |
| 96 | COMMAND env "CC=${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}" |
| 97 | IN_TMPDIR=1 SILENT=1 ${BUILDGO_SCRIPT} |
| 98 | DEPENDS clang_rt.tsan-${arch} ${BUILDGO_SCRIPT} |
| 99 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/go |
| 100 | COMMENT "Checking TSan Go runtime..." |
| 101 | VERBATIM) |
| 102 | else() |
| 103 | set(TSAN_ASM_SOURCES) |
| 104 | endif() |
| 105 | add_compiler_rt_runtime(clang_rt.tsan-${arch} ${arch} STATIC |
| 106 | SOURCES ${TSAN_SOURCES} ${TSAN_ASM_SOURCES} |
| 107 | $<TARGET_OBJECTS:RTInterception.${arch}> |
| 108 | $<TARGET_OBJECTS:RTSanitizerCommon.${arch}> |
| 109 | $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}> |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 110 | $<TARGET_OBJECTS:RTUbsan.${arch}> |
| 111 | CFLAGS ${TSAN_RTL_CFLAGS}) |
| 112 | add_compiler_rt_runtime(clang_rt.tsan_cxx-${arch} ${arch} STATIC |
| 113 | SOURCES ${TSAN_CXX_SOURCES} |
| 114 | $<TARGET_OBJECTS:RTUbsan_cxx.${arch}> |
| 115 | CFLAGS ${TSAN_RTL_CFLAGS}) |
| 116 | list(APPEND TSAN_RUNTIME_LIBRARIES clang_rt.tsan-${arch} |
| 117 | clang_rt.tsan_cxx-${arch}) |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 118 | add_sanitizer_rt_symbols(clang_rt.tsan-${arch} rtl/tsan.syms.extra) |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 119 | add_sanitizer_rt_symbols(clang_rt.tsan_cxx-${arch} rtl/tsan.syms.extra) |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 120 | add_dependencies(tsan clang_rt.tsan-${arch} |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 121 | clang_rt.tsan_cxx-${arch} |
| 122 | clang_rt.tsan-${arch}-symbols |
| 123 | clang_rt.tsan_cxx-${arch}-symbols) |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 124 | endforeach() |
Alexey Samsonov | d9760ab | 2013-08-29 11:53:11 +0000 | [diff] [blame] | 125 | endif() |
Alexey Samsonov | 484db99 | 2012-09-13 14:04:57 +0000 | [diff] [blame] | 126 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 127 | add_dependencies(compiler-rt tsan) |
| 128 | |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 129 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 130 | # Build libcxx instrumented with TSan. |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 131 | if(TSAN_SUPPORTED_ARCH AND |
| 132 | COMPILER_RT_HAS_LIBCXX_SOURCES AND |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 133 | COMPILER_RT_TEST_COMPILER_ID STREQUAL "Clang") |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 134 | set(LIBCXX_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/libcxx_tsan) |
| 135 | add_custom_libcxx(libcxx_tsan ${LIBCXX_PREFIX} |
| 136 | DEPS ${TSAN_RUNTIME_LIBRARIES} |
| 137 | CFLAGS -fsanitize=thread) |
| 138 | endif() |
| 139 | |
| 140 | if(COMPILER_RT_INCLUDE_TESTS) |
Alexey Samsonov | f548ef8 | 2012-09-17 10:02:17 +0000 | [diff] [blame] | 141 | add_subdirectory(tests) |
Alexey Samsonov | 484db99 | 2012-09-13 14:04:57 +0000 | [diff] [blame] | 142 | endif() |