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 | |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 11 | if(COMPILER_RT_TSAN_DEBUG_OUTPUT) |
| 12 | # Add extra debug information to TSan runtime. This configuration is rarely |
| 13 | # used, but we need to support it so that debug output will not bitrot. |
| 14 | list(APPEND TSAN_CFLAGS -DTSAN_COLLECT_STATS=1 |
| 15 | -DTSAN_DEBUG_OUTPUT=2) |
| 16 | endif() |
| 17 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 18 | set(TSAN_RTL_CFLAGS ${TSAN_CFLAGS}) |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 19 | append_list_if(COMPILER_RT_HAS_MSSE3_FLAG -msse3 TSAN_RTL_CFLAGS) |
| 20 | append_list_if(SANITIZER_LIMIT_FRAME_SIZE -Wframe-larger-than=512 |
| 21 | TSAN_RTL_CFLAGS) |
| 22 | append_list_if(COMPILER_RT_HAS_WGLOBAL_CONSTRUCTORS_FLAG -Wglobal-constructors |
| 23 | TSAN_RTL_CFLAGS) |
Alexey Samsonov | 79c6826 | 2012-09-13 12:18:41 +0000 | [diff] [blame] | 24 | |
Alexey Samsonov | d9760ab | 2013-08-29 11:53:11 +0000 | [diff] [blame] | 25 | set(TSAN_SOURCES |
| 26 | rtl/tsan_clock.cc |
| 27 | rtl/tsan_flags.cc |
| 28 | rtl/tsan_fd.cc |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 29 | rtl/tsan_ignoreset.cc |
Alexey Samsonov | d9760ab | 2013-08-29 11:53:11 +0000 | [diff] [blame] | 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 |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 35 | rtl/tsan_malloc_mac.cc |
Alexey Samsonov | d9760ab | 2013-08-29 11:53:11 +0000 | [diff] [blame] | 36 | rtl/tsan_md5.cc |
| 37 | rtl/tsan_mman.cc |
| 38 | rtl/tsan_mutex.cc |
| 39 | rtl/tsan_mutexset.cc |
| 40 | rtl/tsan_report.cc |
| 41 | rtl/tsan_rtl.cc |
| 42 | rtl/tsan_rtl_mutex.cc |
| 43 | rtl/tsan_rtl_report.cc |
| 44 | rtl/tsan_rtl_thread.cc |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 45 | rtl/tsan_stack_trace.cc |
Alexey Samsonov | d9760ab | 2013-08-29 11:53:11 +0000 | [diff] [blame] | 46 | rtl/tsan_stat.cc |
| 47 | rtl/tsan_suppressions.cc |
| 48 | rtl/tsan_symbolize.cc |
| 49 | rtl/tsan_sync.cc) |
| 50 | |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 51 | set(TSAN_CXX_SOURCES |
| 52 | rtl/tsan_new_delete.cc) |
| 53 | |
Alexey Samsonov | d9760ab | 2013-08-29 11:53:11 +0000 | [diff] [blame] | 54 | if(APPLE) |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 55 | list(APPEND TSAN_SOURCES |
| 56 | rtl/tsan_interceptors_mac.cc |
| 57 | rtl/tsan_libdispatch_mac.cc |
| 58 | rtl/tsan_platform_mac.cc |
| 59 | rtl/tsan_platform_posix.cc) |
Alexey Samsonov | d9760ab | 2013-08-29 11:53:11 +0000 | [diff] [blame] | 60 | elseif(UNIX) |
| 61 | # Assume Linux |
| 62 | list(APPEND TSAN_SOURCES |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 63 | rtl/tsan_platform_linux.cc |
| 64 | rtl/tsan_platform_posix.cc) |
Alexey Samsonov | d9760ab | 2013-08-29 11:53:11 +0000 | [diff] [blame] | 65 | endif() |
| 66 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 67 | set(TSAN_HEADERS |
| 68 | rtl/tsan_clock.h |
| 69 | rtl/tsan_defs.h |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 70 | rtl/tsan_dense_alloc.h |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 71 | rtl/tsan_fd.h |
| 72 | rtl/tsan_flags.h |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 73 | rtl/tsan_flags.inc |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 74 | rtl/tsan_ignoreset.h |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 75 | rtl/tsan_interceptors.h |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 76 | rtl/tsan_interface_ann.h |
| 77 | rtl/tsan_interface.h |
| 78 | rtl/tsan_interface_inl.h |
| 79 | rtl/tsan_interface_java.h |
| 80 | rtl/tsan_mman.h |
| 81 | rtl/tsan_mutex.h |
| 82 | rtl/tsan_mutexset.h |
| 83 | rtl/tsan_platform.h |
| 84 | rtl/tsan_report.h |
| 85 | rtl/tsan_rtl.h |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 86 | rtl/tsan_stack_trace.h |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 87 | rtl/tsan_stat.h |
| 88 | rtl/tsan_suppressions.h |
| 89 | rtl/tsan_symbolize.h |
| 90 | rtl/tsan_sync.h |
| 91 | rtl/tsan_trace.h |
| 92 | rtl/tsan_update_shadow_word_inl.h |
| 93 | rtl/tsan_vector.h) |
| 94 | |
Alexey Samsonov | d9760ab | 2013-08-29 11:53:11 +0000 | [diff] [blame] | 95 | set(TSAN_RUNTIME_LIBRARIES) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 96 | add_custom_target(tsan) |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 97 | |
| 98 | if(APPLE) |
| 99 | set(TSAN_ASM_SOURCES rtl/tsan_rtl_amd64.S) |
| 100 | # Xcode will try to compile this file as C ('clang -x c'), and that will fail. |
| 101 | if (${CMAKE_GENERATOR} STREQUAL "Xcode") |
| 102 | enable_language(ASM) |
| 103 | else() |
| 104 | # Pass ASM file directly to the C++ compiler. |
| 105 | set_source_files_properties(${TSAN_ASM_SOURCES} PROPERTIES LANGUAGE C) |
| 106 | endif() |
| 107 | add_compiler_rt_runtime(clang_rt.tsan |
| 108 | SHARED |
| 109 | OS ${TSAN_SUPPORTED_OS} |
| 110 | ARCHS ${TSAN_SUPPORTED_ARCH} |
| 111 | SOURCES ${TSAN_SOURCES} ${TSAN_CXX_SOURCES} ${TSAN_ASM_SOURCES} |
| 112 | OBJECT_LIBS RTInterception |
| 113 | RTSanitizerCommon |
| 114 | RTSanitizerCommonLibc |
| 115 | RTUbsan |
| 116 | CFLAGS ${TSAN_RTL_CFLAGS} |
| 117 | PARENT_TARGET tsan) |
| 118 | add_compiler_rt_object_libraries(RTTsan_dynamic |
| 119 | OS ${TSAN_SUPPORTED_OS} |
| 120 | ARCHS ${TSAN_SUPPORTED_ARCH} |
| 121 | SOURCES ${TSAN_SOURCES} ${TSAN_CXX_SOURCES} ${TSAN_ASM_SOURCES} |
| 122 | CFLAGS ${TSAN_RTL_CFLAGS}) |
| 123 | |
| 124 | # Build and check Go runtime. |
| 125 | set(BUILDGO_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/go/buildgo.sh) |
| 126 | add_custom_target(GotsanRuntimeCheck |
| 127 | COMMAND env "CC=${CMAKE_C_COMPILER} ${OSX_SYSROOT_FLAG}" |
| 128 | IN_TMPDIR=1 SILENT=1 ${BUILDGO_SCRIPT} |
| 129 | DEPENDS tsan ${BUILDGO_SCRIPT} |
| 130 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/go |
| 131 | COMMENT "Checking TSan Go runtime..." |
| 132 | VERBATIM) |
| 133 | else() |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 134 | foreach(arch ${TSAN_SUPPORTED_ARCH}) |
| 135 | if(arch STREQUAL "x86_64") |
| 136 | set(TSAN_ASM_SOURCES rtl/tsan_rtl_amd64.S) |
| 137 | # Pass ASM file directly to the C++ compiler. |
| 138 | set_source_files_properties(${TSAN_ASM_SOURCES} PROPERTIES |
| 139 | LANGUAGE C) |
| 140 | # Sanity check for Go runtime. |
| 141 | set(BUILDGO_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/go/buildgo.sh) |
| 142 | add_custom_target(GotsanRuntimeCheck |
| 143 | COMMAND env "CC=${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}" |
| 144 | IN_TMPDIR=1 SILENT=1 ${BUILDGO_SCRIPT} |
| 145 | DEPENDS clang_rt.tsan-${arch} ${BUILDGO_SCRIPT} |
| 146 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/go |
| 147 | COMMENT "Checking TSan Go runtime..." |
| 148 | VERBATIM) |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 149 | elseif(arch STREQUAL "aarch64") |
| 150 | set(TSAN_ASM_SOURCES rtl/tsan_rtl_aarch64.S) |
| 151 | # Pass ASM file directly to the C++ compiler. |
| 152 | set_source_files_properties(${TSAN_ASM_SOURCES} PROPERTIES |
| 153 | LANGUAGE C) |
| 154 | elseif(arch MATCHES "powerpc64|powerpc64le") |
| 155 | set(TSAN_ASM_SOURCES rtl/tsan_rtl_ppc64.S) |
| 156 | # Pass ASM file directly to the C++ compiler. |
| 157 | set_source_files_properties(${TSAN_ASM_SOURCES} PROPERTIES |
| 158 | LANGUAGE C) |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 159 | else() |
| 160 | set(TSAN_ASM_SOURCES) |
| 161 | endif() |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 162 | add_compiler_rt_runtime(clang_rt.tsan |
| 163 | STATIC |
| 164 | ARCHS ${arch} |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 165 | SOURCES ${TSAN_SOURCES} ${TSAN_ASM_SOURCES} |
| 166 | $<TARGET_OBJECTS:RTInterception.${arch}> |
| 167 | $<TARGET_OBJECTS:RTSanitizerCommon.${arch}> |
| 168 | $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}> |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 169 | $<TARGET_OBJECTS:RTUbsan.${arch}> |
| 170 | CFLAGS ${TSAN_RTL_CFLAGS}) |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 171 | add_compiler_rt_runtime(clang_rt.tsan_cxx |
| 172 | STATIC |
| 173 | ARCHS ${arch} |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 174 | SOURCES ${TSAN_CXX_SOURCES} |
| 175 | $<TARGET_OBJECTS:RTUbsan_cxx.${arch}> |
| 176 | CFLAGS ${TSAN_RTL_CFLAGS}) |
| 177 | list(APPEND TSAN_RUNTIME_LIBRARIES clang_rt.tsan-${arch} |
| 178 | clang_rt.tsan_cxx-${arch}) |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 179 | add_sanitizer_rt_symbols(clang_rt.tsan |
| 180 | ARCHS ${arch} |
| 181 | EXTRA rtl/tsan.syms.extra) |
| 182 | add_sanitizer_rt_symbols(clang_rt.tsan_cxx |
| 183 | ARCHS ${arch} |
| 184 | EXTRA rtl/tsan.syms.extra) |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 185 | add_dependencies(tsan clang_rt.tsan-${arch} |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 186 | clang_rt.tsan_cxx-${arch} |
| 187 | clang_rt.tsan-${arch}-symbols |
| 188 | clang_rt.tsan_cxx-${arch}-symbols) |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 189 | endforeach() |
Alexey Samsonov | d9760ab | 2013-08-29 11:53:11 +0000 | [diff] [blame] | 190 | endif() |
Alexey Samsonov | 484db99 | 2012-09-13 14:04:57 +0000 | [diff] [blame] | 191 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 192 | add_dependencies(compiler-rt tsan) |
| 193 | |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 194 | # Make sure that non-platform-specific files don't include any system headers. |
| 195 | if(COMPILER_RT_HAS_SYSROOT_FLAG) |
| 196 | file(GLOB _tsan_generic_sources rtl/tsan*) |
| 197 | file(GLOB _tsan_platform_sources rtl/tsan*posix* rtl/tsan*mac* |
| 198 | rtl/tsan*linux*) |
| 199 | list(REMOVE_ITEM _tsan_generic_sources ${_tsan_platform_sources}) |
| 200 | set_source_files_properties(${_tsan_generic_sources} |
| 201 | PROPERTIES COMPILE_FLAGS "--sysroot=.") |
| 202 | endif() |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 203 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 204 | # Build libcxx instrumented with TSan. |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 205 | if(COMPILER_RT_HAS_LIBCXX_SOURCES AND |
Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 206 | COMPILER_RT_TEST_COMPILER_ID STREQUAL "Clang") |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 207 | set(LIBCXX_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/libcxx_tsan) |
| 208 | add_custom_libcxx(libcxx_tsan ${LIBCXX_PREFIX} |
| 209 | DEPS ${TSAN_RUNTIME_LIBRARIES} |
| 210 | CFLAGS -fsanitize=thread) |
| 211 | endif() |
| 212 | |
| 213 | if(COMPILER_RT_INCLUDE_TESTS) |
Alexey Samsonov | f548ef8 | 2012-09-17 10:02:17 +0000 | [diff] [blame] | 214 | add_subdirectory(tests) |
Alexey Samsonov | 484db99 | 2012-09-13 14:04:57 +0000 | [diff] [blame] | 215 | endif() |