1 include_directories(../..)
3 set(TSAN_RTL_CFLAGS ${TSAN_CFLAGS})
4 append_list_if(COMPILER_RT_HAS_MSSE4_2_FLAG -msse4.2 TSAN_RTL_CFLAGS)
5 append_list_if(SANITIZER_LIMIT_FRAME_SIZE -Wframe-larger-than=530
7 append_list_if(COMPILER_RT_HAS_WGLOBAL_CONSTRUCTORS_FLAG -Wglobal-constructors
9 append_list_if(COMPILER_RT_INTERCEPT_LIBDISPATCH ${COMPILER_RT_LIBDISPATCH_CFLAGS}
12 set(TSAN_RTL_DYNAMIC_CFLAGS ${TSAN_RTL_CFLAGS})
13 list(REMOVE_ITEM TSAN_RTL_DYNAMIC_CFLAGS -fPIE)
15 set(TSAN_DYNAMIC_LINK_LIBS
16 ${COMPILER_RT_UNWINDER_LINK_LIBS}
17 ${SANITIZER_CXX_ABI_LIBRARIES}
18 ${SANITIZER_COMMON_LINK_LIBS})
20 append_list_if(COMPILER_RT_HAS_LIBDL dl TSAN_DYNAMIC_LINK_LIBS)
21 append_list_if(COMPILER_RT_HAS_LIBM m TSAN_DYNAMIC_LINK_LIBS)
22 append_list_if(COMPILER_RT_HAS_LIBPTHREAD pthread TSAN_DYNAMIC_LINK_LIBS)
30 tsan_interceptors_memintrinsics.cpp
31 tsan_interceptors_posix.cpp
33 tsan_interface_ann.cpp
34 tsan_interface_atomic.cpp
35 tsan_interface_java.cpp
58 set(TSAN_PREINIT_SOURCES
63 list(APPEND TSAN_SOURCES
64 tsan_interceptors_mac.cpp
65 tsan_interceptors_mach_vm.cpp
67 tsan_platform_posix.cpp
71 list(APPEND TSAN_SOURCES
72 tsan_platform_linux.cpp
73 tsan_platform_posix.cpp
77 if(COMPILER_RT_INTERCEPT_LIBDISPATCH)
78 list(APPEND TSAN_SOURCES
79 tsan_interceptors_libdispatch.cpp
111 set(TSAN_RUNTIME_LIBRARIES)
112 add_compiler_rt_component(tsan)
114 if("${CMAKE_C_FLAGS}" MATCHES "-Wno-(error=)?unused-command-line-argument")
115 set(EXTRA_CFLAGS "-Wno-error=unused-command-line-argument ${EXTRA_CFLAGS}")
119 # Ideally we would check the SDK version for the actual platform we are
120 # building for here. To make our lifes easier we assume the host SDK setup is
121 # sane and use the macOS SDK version as a proxy for aligned SDKs.
122 find_darwin_sdk_version(macosx_sdk_version "macosx")
123 if ("${macosx_sdk_version}" VERSION_LESS 10.12)
124 message(FATAL_ERROR "Building the TSan runtime requires at least macOS SDK 10.12 (or aligned SDK on other platforms)")
132 set(TSAN_LINK_LIBS ${SANITIZER_COMMON_LINK_LIBS})
134 add_weak_symbols("ubsan" WEAK_SYMBOL_LINK_FLAGS)
135 add_weak_symbols("sanitizer_common" WEAK_SYMBOL_LINK_FLAGS)
137 add_compiler_rt_runtime(clang_rt.tsan
139 OS ${TSAN_SUPPORTED_OS}
140 ARCHS ${TSAN_SUPPORTED_ARCH}
141 SOURCES ${TSAN_SOURCES} ${TSAN_CXX_SOURCES} ${TSAN_ASM_SOURCES}
142 ADDITIONAL_HEADERS ${TSAN_HEADERS}
143 OBJECT_LIBS RTInterception
145 RTSanitizerCommonLibc
146 RTSanitizerCommonCoverage
147 RTSanitizerCommonSymbolizer
149 CFLAGS ${TSAN_RTL_CFLAGS}
150 LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS} ${WEAK_SYMBOL_LINK_FLAGS}
151 LINK_LIBS ${TSAN_LINK_LIBS} objc
153 add_compiler_rt_object_libraries(RTTsan_dynamic
154 OS ${TSAN_SUPPORTED_OS}
155 ARCHS ${TSAN_SUPPORTED_ARCH}
156 SOURCES ${TSAN_SOURCES} ${TSAN_CXX_SOURCES} ${TSAN_ASM_SOURCES}
157 ADDITIONAL_HEADERS ${TSAN_HEADERS}
158 CFLAGS ${TSAN_RTL_CFLAGS})
160 # Build and check Go runtime.
161 set(BUILDGO_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/../go/buildgo.sh)
162 add_custom_target(GotsanRuntimeCheck
163 COMMAND env "CC=${CMAKE_C_COMPILER} ${OSX_SYSROOT_FLAG}"
164 EXTRA_CFLAGS=${EXTRA_CFLAGS}
165 IN_TMPDIR=1 SILENT=1 ${BUILDGO_SCRIPT}
166 DEPENDS tsan ${BUILDGO_SCRIPT}
167 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../go
168 COMMENT "Checking TSan Go runtime..."
170 set_target_properties(GotsanRuntimeCheck PROPERTIES FOLDER "Compiler-RT Misc")
172 foreach(arch ${TSAN_SUPPORTED_ARCH})
173 if(arch STREQUAL "x86_64")
177 # Check for Go runtime.
178 set(BUILDGO_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/../go/buildgo.sh)
179 add_custom_target(GotsanRuntimeCheck
180 COMMAND env "CC=${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}"
181 EXTRA_CFLAGS=${EXTRA_CFLAGS}
182 IN_TMPDIR=1 SILENT=1 ${BUILDGO_SCRIPT}
183 DEPENDS clang_rt.tsan-${arch} ${BUILDGO_SCRIPT}
184 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../go
185 COMMENT "Checking TSan Go runtime..."
187 elseif(arch STREQUAL "aarch64")
191 # Check for Go runtime.
192 set(BUILDGO_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/../go/buildgo.sh)
193 add_custom_target(GotsanRuntimeCheck
194 COMMAND env "CC=${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}"
195 EXTRA_CFLAGS=${EXTRA_CFLAGS}
196 IN_TMPDIR=1 SILENT=1 ${BUILDGO_SCRIPT}
197 DEPENDS clang_rt.tsan-${arch} ${BUILDGO_SCRIPT}
198 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../go
199 COMMENT "Checking TSan Go runtime..."
201 elseif(arch MATCHES "powerpc64|powerpc64le")
205 # Check for Go runtime.
206 set(BUILDGO_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/../go/buildgo.sh)
207 add_custom_target(GotsanRuntimeCheck
208 COMMAND env "CC=${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}"
209 EXTRA_CFLAGS=${EXTRA_CFLAGS}
210 IN_TMPDIR=1 SILENT=1 ${BUILDGO_SCRIPT}
211 DEPENDS clang_rt.tsan-${arch} ${BUILDGO_SCRIPT}
212 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../go
213 COMMENT "Checking TSan Go runtime..."
215 elseif(arch MATCHES "loongarch64")
217 tsan_rtl_loongarch64.S
219 elseif(arch MATCHES "mips64|mips64le")
223 elseif(arch MATCHES "riscv64")
227 elseif(arch MATCHES "s390x")
231 # Check for Go runtime.
232 set(BUILDGO_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/../go/buildgo.sh)
233 add_custom_target(GotsanRuntimeCheck
234 COMMAND env "CC=${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}"
235 EXTRA_CFLAGS=${EXTRA_CFLAGS}
236 IN_TMPDIR=1 SILENT=1 ${BUILDGO_SCRIPT}
237 DEPENDS clang_rt.tsan-${arch} ${BUILDGO_SCRIPT}
238 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../go
239 COMMENT "Checking TSan Go runtime..."
242 set(TSAN_ASM_SOURCES)
244 add_compiler_rt_runtime(clang_rt.tsan
247 SOURCES ${TSAN_SOURCES} ${TSAN_ASM_SOURCES} ${TSAN_PREINIT_SOURCES}
248 $<TARGET_OBJECTS:RTInterception.${arch}>
249 $<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
250 $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>
251 $<TARGET_OBJECTS:RTSanitizerCommonCoverage.${arch}>
252 $<TARGET_OBJECTS:RTSanitizerCommonSymbolizer.${arch}>
253 $<TARGET_OBJECTS:RTSanitizerCommonSymbolizerInternal.${arch}>
254 $<TARGET_OBJECTS:RTUbsan.${arch}>
255 ADDITIONAL_HEADERS ${TSAN_HEADERS}
256 CFLAGS ${TSAN_RTL_CFLAGS}
258 add_compiler_rt_runtime(clang_rt.tsan_cxx
261 SOURCES ${TSAN_CXX_SOURCES}
262 $<TARGET_OBJECTS:RTUbsan_cxx.${arch}>
263 ADDITIONAL_HEADERS ${TSAN_HEADERS}
264 CFLAGS ${TSAN_RTL_CFLAGS}
266 list(APPEND TSAN_RUNTIME_LIBRARIES clang_rt.tsan-${arch}
267 clang_rt.tsan_cxx-${arch})
268 add_compiler_rt_runtime(clang_rt.tsan
271 SOURCES ${TSAN_SOURCES} ${TSAN_ASM_SOURCES}
272 $<TARGET_OBJECTS:RTInterception.${arch}>
273 $<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
274 $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>
275 $<TARGET_OBJECTS:RTSanitizerCommonCoverage.${arch}>
276 $<TARGET_OBJECTS:RTSanitizerCommonSymbolizer.${arch}>
277 $<TARGET_OBJECTS:RTSanitizerCommonSymbolizerInternal.${arch}>
278 $<TARGET_OBJECTS:RTUbsan.${arch}>
279 ADDITIONAL_HEADERS ${TSAN_HEADERS}
280 CFLAGS ${TSAN_RTL_DYNAMIC_CFLAGS}
281 DEFS SANITIZER_SHARED
282 LINK_LIBS ${TSAN_DYNAMIC_LINK_LIBS}
283 LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS}
285 add_sanitizer_rt_symbols(clang_rt.tsan
287 EXTRA tsan.syms.extra)
288 add_sanitizer_rt_symbols(clang_rt.tsan_cxx
290 EXTRA tsan.syms.extra)
291 add_dependencies(tsan clang_rt.tsan-${arch}
292 clang_rt.tsan_cxx-${arch}
293 clang_rt.tsan-${arch}-symbols
294 clang_rt.tsan_cxx-${arch}-symbols)