1import("//compiler-rt/target.gni") 2 3source_set("cxx_sources") { 4 configs -= [ "//llvm/utils/gn/build:llvm_code" ] 5 configs += [ "//llvm/utils/gn/build:crt_code" ] 6 sources = [ "tsan_new_delete.cpp" ] 7} 8 9if (current_os == "mac") { 10 tsan_target_type = "shared_library" 11} else { 12 tsan_target_type = "static_library" 13} 14 15target(tsan_target_type, "rtl") { 16 configs -= [ "//llvm/utils/gn/build:llvm_code" ] 17 configs += [ "//llvm/utils/gn/build:crt_code" ] 18 19 output_dir = crt_current_out_dir 20 if (current_os == "mac") { 21 output_name = "clang_rt.tsan_osx_dynamic" 22 } else { 23 assert(current_os != "win", "Tsan does not work on Windows") 24 output_name = "clang_rt.tsan$crt_current_target_suffix" 25 } 26 27 deps = [ 28 "//compiler-rt/lib/interception:sources", 29 "//compiler-rt/lib/sanitizer_common:sources", 30 "//compiler-rt/lib/ubsan:sources", 31 ] 32 33 if (tsan_target_type == "static_library") { 34 complete_static_lib = true 35 configs -= [ "//llvm/utils/gn/build:thin_archive" ] 36 deps += [ ":tsan_cxx" ] 37 } else { 38 deps += [ 39 ":cxx_sources", 40 "//compiler-rt/lib/ubsan:cxx_sources", 41 ] 42 } 43 44 # It's performance-critical for TSan runtime to be built with -fPIE to reduce 45 # the number of register spills. 46 cflags = [ "-fPIE" ] 47 48 sources = [ 49 "tsan_debugging.cpp", 50 "tsan_defs.h", 51 "tsan_dense_alloc.h", 52 "tsan_external.cpp", 53 "tsan_fd.cpp", 54 "tsan_fd.h", 55 "tsan_flags.cpp", 56 "tsan_flags.h", 57 "tsan_flags.inc", 58 "tsan_ignoreset.cpp", 59 "tsan_ignoreset.h", 60 "tsan_ilist.h", 61 "tsan_interceptors.h", 62 "tsan_interceptors_posix.cpp", 63 "tsan_interface.cpp", 64 "tsan_interface.h", 65 "tsan_interface.inc", 66 "tsan_interface_ann.cpp", 67 "tsan_interface_ann.h", 68 "tsan_interface_atomic.cpp", 69 "tsan_interface_java.cpp", 70 "tsan_interface_java.h", 71 "tsan_malloc_mac.cpp", 72 "tsan_md5.cpp", 73 "tsan_mman.cpp", 74 "tsan_mman.h", 75 "tsan_mutexset.cpp", 76 "tsan_mutexset.h", 77 "tsan_platform.h", 78 "tsan_ppc_regs.h", 79 "tsan_preinit.cpp", 80 "tsan_report.cpp", 81 "tsan_report.h", 82 "tsan_rtl.cpp", 83 "tsan_rtl.h", 84 "tsan_rtl_access.cpp", 85 "tsan_rtl_mutex.cpp", 86 "tsan_rtl_proc.cpp", 87 "tsan_rtl_report.cpp", 88 "tsan_rtl_thread.cpp", 89 "tsan_shadow.h", 90 "tsan_stack_trace.cpp", 91 "tsan_stack_trace.h", 92 "tsan_suppressions.cpp", 93 "tsan_suppressions.h", 94 "tsan_symbolize.cpp", 95 "tsan_symbolize.h", 96 "tsan_sync.cpp", 97 "tsan_sync.h", 98 "tsan_trace.h", 99 "tsan_update_shadow_word.inc", 100 "tsan_vector_clock.cpp", 101 "tsan_vector_clock.h", 102 ] 103 if (target_os == "mac") { 104 sources += [ 105 "tsan_interceptors_libdispatch.cpp", 106 "tsan_interceptors_mac.cpp", 107 "tsan_interceptors_mach_vm.cpp", 108 "tsan_platform_mac.cpp", 109 "tsan_platform_posix.cpp", 110 ] 111 cflags += [ "-fblocks" ] 112 } else { 113 # Assume Linux 114 sources += [ 115 "tsan_platform_linux.cpp", 116 "tsan_platform_posix.cpp", 117 ] 118 } 119 if (target_cpu == "x64") { 120 sources += [ "tsan_rtl_amd64.S" ] 121 } else if (target_cpu == "arm64") { 122 sources += [ "tsan_rtl_aarch64.S" ] 123 } else if (target_cpu == "loongarch64") { 124 sources += [ "tsan_rtl_loongarch64.S" ] 125 } else if (target_cpu == "mips64") { 126 sources += [ "tsan_rtl_mips64.S" ] 127 } else if (target_cpu == "powerpc64") { 128 sources += [ "tsan_rtl_ppc64.S" ] 129 } else if (target_cpu == "s390x") { 130 sources += [ "tsan_rtl_s390x.S" ] 131 } 132 133 # FIXME: link rt dl m pthread log 134 # FIXME: dep on libcxx-headers? 135 # FIXME: add_sanitizer_rt_version_list (cf hwasan) 136 # FIXME: need libclang_rt.tsan*.a.syms? 137 # FIXME: tsan_ignorelist.txt 138 139 if (target_os == "mac") { 140 # The -U flags below correspond to the add_weak_symbols() calls in CMake. 141 ldflags = [ 142 "-lc++", 143 "-lc++abi", 144 "-lobjc", 145 146 # sanitizer_common 147 "-Wl,-U,___sanitizer_free_hook", 148 "-Wl,-U,___sanitizer_malloc_hook", 149 "-Wl,-U,___sanitizer_report_error_summary", 150 "-Wl,-U,___sanitizer_sandbox_on_notify", 151 "-Wl,-U,___sanitizer_symbolize_code", 152 "-Wl,-U,___sanitizer_symbolize_data", 153 "-Wl,-U,___sanitizer_symbolize_demangle", 154 "-Wl,-U,___sanitizer_symbolize_flush", 155 "-Wl,-U,___sanitizer_symbolize_set_demangle", 156 "-Wl,-U,___sanitizer_symbolize_set_inline_frames", 157 158 # FIXME: better 159 "-Wl,-install_name,@rpath/libclang_rt.tsan_osx_dynamic.dylib", 160 ] 161 # FIXME: -Wl,-rpath 162 # FIXME: codesign (??) 163 } 164} 165 166if (tsan_target_type == "static_library") { 167 static_library("tsan_cxx") { 168 assert(current_os != "win", "FIXME") 169 output_dir = crt_current_out_dir 170 output_name = "clang_rt.tsan_cxx$crt_current_target_suffix" 171 complete_static_lib = true 172 configs -= [ "//llvm/utils/gn/build:thin_archive" ] 173 deps = [ 174 ":cxx_sources", 175 "//compiler-rt/lib/ubsan:cxx_sources", 176 ] 177 } 178} 179# FIXME: 180# Build libcxx instrumented with TSan. 181