| 1 |
import("//compiler-rt/target.gni") |
| 2 |
|
| 3 |
source_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 |
|
| 9 |
if (current_os == "mac") { |
| 10 |
tsan_target_type = "shared_library" |
| 11 |
} else { |
| 12 |
tsan_target_type = "static_library" |
| 13 |
} |
| 14 |
|
| 15 |
target(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_memintrinsics.cpp", |
| 63 |
"tsan_interceptors_posix.cpp", |
| 64 |
"tsan_interface.cpp", |
| 65 |
"tsan_interface.h", |
| 66 |
"tsan_interface.inc", |
| 67 |
"tsan_interface_ann.cpp", |
| 68 |
"tsan_interface_ann.h", |
| 69 |
"tsan_interface_atomic.cpp", |
| 70 |
"tsan_interface_java.cpp", |
| 71 |
"tsan_interface_java.h", |
| 72 |
"tsan_malloc_mac.cpp", |
| 73 |
"tsan_md5.cpp", |
| 74 |
"tsan_mman.cpp", |
| 75 |
"tsan_mman.h", |
| 76 |
"tsan_mutexset.cpp", |
| 77 |
"tsan_mutexset.h", |
| 78 |
"tsan_platform.h", |
| 79 |
"tsan_ppc_regs.h", |
| 80 |
"tsan_preinit.cpp", |
| 81 |
"tsan_report.cpp", |
| 82 |
"tsan_report.h", |
| 83 |
"tsan_rtl.cpp", |
| 84 |
"tsan_rtl.h", |
| 85 |
"tsan_rtl_access.cpp", |
| 86 |
"tsan_rtl_mutex.cpp", |
| 87 |
"tsan_rtl_proc.cpp", |
| 88 |
"tsan_rtl_report.cpp", |
| 89 |
"tsan_rtl_thread.cpp", |
| 90 |
"tsan_shadow.h", |
| 91 |
"tsan_stack_trace.cpp", |
| 92 |
"tsan_stack_trace.h", |
| 93 |
"tsan_suppressions.cpp", |
| 94 |
"tsan_suppressions.h", |
| 95 |
"tsan_symbolize.cpp", |
| 96 |
"tsan_symbolize.h", |
| 97 |
"tsan_sync.cpp", |
| 98 |
"tsan_sync.h", |
| 99 |
"tsan_trace.h", |
| 100 |
"tsan_update_shadow_word.inc", |
| 101 |
"tsan_vector_clock.cpp", |
| 102 |
"tsan_vector_clock.h", |
| 103 |
] |
| 104 |
if (target_os == "mac") { |
| 105 |
sources += [ |
| 106 |
"tsan_interceptors_libdispatch.cpp", |
| 107 |
"tsan_interceptors_mac.cpp", |
| 108 |
"tsan_interceptors_mach_vm.cpp", |
| 109 |
"tsan_platform_mac.cpp", |
| 110 |
"tsan_platform_posix.cpp", |
| 111 |
] |
| 112 |
cflags += [ "-fblocks" ] |
| 113 |
} else { |
| 114 |
# Assume Linux |
| 115 |
sources += [ |
| 116 |
"tsan_platform_linux.cpp", |
| 117 |
"tsan_platform_posix.cpp", |
| 118 |
] |
| 119 |
} |
| 120 |
if (target_cpu == "x64") { |
| 121 |
sources += [ "tsan_rtl_amd64.S" ] |
| 122 |
} else if (target_cpu == "arm64") { |
| 123 |
sources += [ "tsan_rtl_aarch64.S" ] |
| 124 |
} else if (target_cpu == "loongarch64") { |
| 125 |
sources += [ "tsan_rtl_loongarch64.S" ] |
| 126 |
} else if (target_cpu == "mips64") { |
| 127 |
sources += [ "tsan_rtl_mips64.S" ] |
| 128 |
} else if (target_cpu == "powerpc64") { |
| 129 |
sources += [ "tsan_rtl_ppc64.S" ] |
| 130 |
} else if (target_cpu == "riscv64") { |
| 131 |
sources += [ "tsan_rtl_riscv64.S" ] |
| 132 |
} else if (target_cpu == "s390x") { |
| 133 |
sources += [ "tsan_rtl_s390x.S" ] |
| 134 |
} |
| 135 |
|
| 136 |
# FIXME: link rt dl m pthread log |
| 137 |
# FIXME: dep on libcxx-headers? |
| 138 |
# FIXME: add_sanitizer_rt_version_list (cf hwasan) |
| 139 |
# FIXME: need libclang_rt.tsan*.a.syms? |
| 140 |
# FIXME: tsan_ignorelist.txt |
| 141 |
|
| 142 |
if (target_os == "mac") { |
| 143 |
# The -U flags below correspond to the add_weak_symbols() calls in CMake. |
| 144 |
ldflags = [ |
| 145 |
"-lc++", |
| 146 |
"-lc++abi", |
| 147 |
"-lobjc", |
| 148 |
|
| 149 |
# sanitizer_common |
| 150 |
"-Wl,-U,___sanitizer_free_hook", |
| 151 |
"-Wl,-U,___sanitizer_malloc_hook", |
| 152 |
"-Wl,-U,___sanitizer_report_error_summary", |
| 153 |
"-Wl,-U,___sanitizer_sandbox_on_notify", |
| 154 |
"-Wl,-U,___sanitizer_symbolize_code", |
| 155 |
"-Wl,-U,___sanitizer_symbolize_data", |
| 156 |
"-Wl,-U,___sanitizer_symbolize_frame", |
| 157 |
"-Wl,-U,___sanitizer_symbolize_demangle", |
| 158 |
"-Wl,-U,___sanitizer_symbolize_flush", |
| 159 |
"-Wl,-U,___sanitizer_symbolize_set_demangle", |
| 160 |
"-Wl,-U,___sanitizer_symbolize_set_inline_frames", |
| 161 |
|
| 162 |
# FIXME: better |
| 163 |
"-Wl,-install_name,@rpath/libclang_rt.tsan_osx_dynamic.dylib", |
| 164 |
] |
| 165 |
# FIXME: -Wl,-rpath |
| 166 |
# FIXME: codesign (??) |
| 167 |
} |
| 168 |
} |
| 169 |
|
| 170 |
if (tsan_target_type == "static_library") { |
| 171 |
static_library("tsan_cxx") { |
| 172 |
assert(current_os != "win", "FIXME") |
| 173 |
output_dir = crt_current_out_dir |
| 174 |
output_name = "clang_rt.tsan_cxx$crt_current_target_suffix" |
| 175 |
complete_static_lib = true |
| 176 |
configs -= [ "//llvm/utils/gn/build:thin_archive" ] |
| 177 |
deps = [ |
| 178 |
":cxx_sources", |
| 179 |
"//compiler-rt/lib/ubsan:cxx_sources", |
| 180 |
] |
| 181 |
} |
| 182 |
} |
| 183 |
# FIXME: |
| 184 |
# Build libcxx instrumented with TSan. |