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 | |
Alexander Potapenko | 76030b3 | 2013-03-29 09:44:11 +0000 | [diff] [blame] | 5 | # 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 Samsonov | a7e5db9 | 2013-03-13 09:18:30 +0000 | [diff] [blame] | 7 | set(TSAN_CFLAGS |
| 8 | ${SANITIZER_COMMON_CFLAGS} |
Alexander Potapenko | 76030b3 | 2013-03-29 09:44:11 +0000 | [diff] [blame] | 9 | -fPIE |
Alexey Samsonov | a7e5db9 | 2013-03-13 09:18:30 +0000 | [diff] [blame] | 10 | -fno-rtti) |
Alexey Samsonov | 0bc4a0b | 2013-08-29 12:08:36 +0000 | [diff] [blame] | 11 | |
| 12 | set(TSAN_RTL_CFLAGS |
| 13 | ${TSAN_CFLAGS} |
| 14 | -Wframe-larger-than=512) |
| 15 | if(SUPPORTS_GLOBAL_CONSTRUCTORS_FLAG) |
| 16 | list(APPEND TSAN_RTL_CFLAGS -Wglobal-constructors) |
| 17 | endif() |
| 18 | # FIXME: Add support for --sysroot=. compile flag: |
Alexey Samsonov | 79c6826 | 2012-09-13 12:18:41 +0000 | [diff] [blame] | 19 | |
| 20 | if("${CMAKE_BUILD_TYPE}" EQUAL "Release") |
| 21 | set(TSAN_COMMON_DEFINITIONS DEBUG=0) |
| 22 | else() |
| 23 | set(TSAN_COMMON_DEFINITIONS DEBUG=1) |
Kostya Serebryany | 4026c2c | 2012-05-15 15:17:35 +0000 | [diff] [blame] | 24 | endif() |
Alexey Samsonov | 79c6826 | 2012-09-13 12:18:41 +0000 | [diff] [blame] | 25 | |
Alexey Samsonov | d9760ab | 2013-08-29 11:53:11 +0000 | [diff] [blame] | 26 | set(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 | |
| 49 | if(APPLE) |
| 50 | list(APPEND TSAN_SOURCES rtl/tsan_platform_mac.cc) |
| 51 | elseif(UNIX) |
| 52 | # Assume Linux |
| 53 | list(APPEND TSAN_SOURCES |
| 54 | rtl/tsan_platform_linux.cc |
| 55 | rtl/tsan_symbolize_addr2line_linux.cc) |
| 56 | endif() |
| 57 | |
| 58 | set(TSAN_RUNTIME_LIBRARIES) |
| 59 | # TSan is currently supported on 64-bit Linux only. |
| 60 | if(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 Samsonov | 0bc4a0b | 2013-08-29 12:08:36 +0000 | [diff] [blame] | 71 | CFLAGS ${TSAN_RTL_CFLAGS} |
Alexey Samsonov | d9760ab | 2013-08-29 11:53:11 +0000 | [diff] [blame] | 72 | 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) |
| 76 | endif() |
Alexey Samsonov | 484db99 | 2012-09-13 14:04:57 +0000 | [diff] [blame] | 77 | |
| 78 | if(LLVM_INCLUDE_TESTS) |
Alexey Samsonov | f548ef8 | 2012-09-17 10:02:17 +0000 | [diff] [blame] | 79 | add_subdirectory(tests) |
Alexey Samsonov | 484db99 | 2012-09-13 14:04:57 +0000 | [diff] [blame] | 80 | endif() |
Alexey Samsonov | f548ef8 | 2012-09-17 10:02:17 +0000 | [diff] [blame] | 81 | add_subdirectory(lit_tests) |