blob: a60c8f842a2d7649d50aca1686e1e37c93037adc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
|
# Build for the ThreadSanitizer runtime support library.
include_directories(..)
set(TSAN_CFLAGS ${SANITIZER_COMMON_CFLAGS})
# SANITIZER_COMMON_CFLAGS contains -fPIC, but it's performance-critical for
# TSan runtime to be built with -fPIE to reduce the number of register spills.
# On FreeBSD however it provokes linkage issue thus we disable it.
if(NOT CMAKE_SYSTEM MATCHES "FreeBSD")
append_list_if(COMPILER_RT_HAS_FPIE_FLAG -fPIE TSAN_CFLAGS)
endif()
append_rtti_flag(OFF TSAN_CFLAGS)
if(COMPILER_RT_TSAN_DEBUG_OUTPUT)
# Add extra debug information to TSan runtime. This configuration is rarely
# used, but we need to support it so that debug output will not bitrot.
list(APPEND TSAN_CFLAGS -DTSAN_DEBUG_OUTPUT=2)
endif()
set(TSAN_RTL_CFLAGS ${TSAN_CFLAGS})
append_list_if(COMPILER_RT_HAS_MSSE3_FLAG -msse3 TSAN_RTL_CFLAGS)
append_list_if(SANITIZER_LIMIT_FRAME_SIZE -Wframe-larger-than=530
TSAN_RTL_CFLAGS)
append_list_if(COMPILER_RT_HAS_WGLOBAL_CONSTRUCTORS_FLAG -Wglobal-constructors
TSAN_RTL_CFLAGS)
set(TSAN_SOURCES
rtl/tsan_clock.cpp
rtl/tsan_debugging.cpp
rtl/tsan_external.cpp
rtl/tsan_fd.cpp
rtl/tsan_flags.cpp
rtl/tsan_ignoreset.cpp
rtl/tsan_interceptors_posix.cpp
rtl/tsan_interface.cpp
rtl/tsan_interface_ann.cpp
rtl/tsan_interface_atomic.cpp
rtl/tsan_interface_java.cpp
rtl/tsan_malloc_mac.cpp
rtl/tsan_md5.cpp
rtl/tsan_mman.cpp
rtl/tsan_mutexset.cpp
rtl/tsan_preinit.cpp
rtl/tsan_report.cpp
rtl/tsan_rtl.cpp
rtl/tsan_rtl_mutex.cpp
rtl/tsan_rtl_proc.cpp
rtl/tsan_rtl_report.cpp
rtl/tsan_rtl_thread.cpp
rtl/tsan_stack_trace.cpp
rtl/tsan_suppressions.cpp
rtl/tsan_symbolize.cpp
rtl/tsan_sync.cpp
)
set(TSAN_CXX_SOURCES
rtl/tsan_new_delete.cpp
)
if(APPLE)
list(APPEND TSAN_SOURCES
rtl/tsan_interceptors_mac.cpp
rtl/tsan_interceptors_mach_vm.cpp
rtl/tsan_platform_mac.cpp
rtl/tsan_platform_posix.cpp
)
elseif(UNIX)
# Assume Linux
list(APPEND TSAN_SOURCES
rtl/tsan_platform_linux.cpp
rtl/tsan_platform_posix.cpp
)
endif()
if(COMPILER_RT_INTERCEPT_LIBDISPATCH)
list(APPEND TSAN_SOURCES
rtl/tsan_interceptors_libdispatch.cpp
)
list(APPEND TSAN_RTL_CFLAGS ${COMPILER_RT_LIBDISPATCH_CFLAGS})
endif()
set(TSAN_HEADERS
rtl/tsan_clock.h
rtl/tsan_defs.h
rtl/tsan_dense_alloc.h
rtl/tsan_fd.h
rtl/tsan_flags.h
rtl/tsan_flags.inc
rtl/tsan_ignoreset.h
rtl/tsan_interceptors.h
rtl/tsan_interface.h
rtl/tsan_interface_ann.h
rtl/tsan_interface_inl.h
rtl/tsan_interface_java.h
rtl/tsan_mman.h
rtl/tsan_mutexset.h
rtl/tsan_platform.h
rtl/tsan_ppc_regs.h
rtl/tsan_report.h
rtl/tsan_rtl.h
rtl/tsan_stack_trace.h
rtl/tsan_suppressions.h
rtl/tsan_symbolize.h
rtl/tsan_sync.h
rtl/tsan_trace.h
rtl/tsan_update_shadow_word_inl.h
)
set(TSAN_RUNTIME_LIBRARIES)
add_compiler_rt_component(tsan)
if("${CMAKE_C_FLAGS}" MATCHES "-Wno-(error=)?unused-command-line-argument")
set(EXTRA_CFLAGS "-Wno-error=unused-command-line-argument ${EXTRA_CFLAGS}")
endif()
if(APPLE)
# Ideally we would check the SDK version for the actual platform we are
# building for here. To make our lifes easier we assume the host SDK setup is
# sane and use the macOS SDK version as a proxy for aligned SDKs.
find_darwin_sdk_version(macosx_sdk_version "macosx")
if ("${macosx_sdk_version}" VERSION_LESS 10.12)
message(FATAL_ERROR "Building the TSan runtime requires at least macOS SDK 10.12 (or aligned SDK on other platforms)")
endif()
add_asm_sources(TSAN_ASM_SOURCES
rtl/tsan_rtl_amd64.S
rtl/tsan_rtl_aarch64.S
)
set(TSAN_LINK_LIBS ${SANITIZER_COMMON_LINK_LIBS})
add_weak_symbols("ubsan" WEAK_SYMBOL_LINK_FLAGS)
add_weak_symbols("sanitizer_common" WEAK_SYMBOL_LINK_FLAGS)
add_compiler_rt_runtime(clang_rt.tsan
SHARED
OS ${TSAN_SUPPORTED_OS}
ARCHS ${TSAN_SUPPORTED_ARCH}
SOURCES ${TSAN_SOURCES} ${TSAN_CXX_SOURCES} ${TSAN_ASM_SOURCES}
ADDITIONAL_HEADERS ${TSAN_HEADERS}
OBJECT_LIBS RTInterception
RTSanitizerCommon
RTSanitizerCommonLibc
RTSanitizerCommonCoverage
RTSanitizerCommonSymbolizer
RTUbsan
CFLAGS ${TSAN_RTL_CFLAGS}
LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS} ${WEAK_SYMBOL_LINK_FLAGS}
LINK_LIBS ${TSAN_LINK_LIBS} objc
PARENT_TARGET tsan)
add_compiler_rt_object_libraries(RTTsan_dynamic
OS ${TSAN_SUPPORTED_OS}
ARCHS ${TSAN_SUPPORTED_ARCH}
SOURCES ${TSAN_SOURCES} ${TSAN_CXX_SOURCES} ${TSAN_ASM_SOURCES}
ADDITIONAL_HEADERS ${TSAN_HEADERS}
CFLAGS ${TSAN_RTL_CFLAGS})
# Build and check Go runtime.
set(BUILDGO_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/go/buildgo.sh)
add_custom_target(GotsanRuntimeCheck
COMMAND env "CC=${CMAKE_C_COMPILER} ${OSX_SYSROOT_FLAG}"
EXTRA_CFLAGS=${EXTRA_CFLAGS}
IN_TMPDIR=1 SILENT=1 ${BUILDGO_SCRIPT}
DEPENDS tsan ${BUILDGO_SCRIPT}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/go
COMMENT "Checking TSan Go runtime..."
VERBATIM)
set_target_properties(GotsanRuntimeCheck PROPERTIES FOLDER "Compiler-RT Misc")
else()
foreach(arch ${TSAN_SUPPORTED_ARCH})
if(arch STREQUAL "x86_64")
add_asm_sources(TSAN_ASM_SOURCES
rtl/tsan_rtl_amd64.S
)
# Sanity check for Go runtime.
set(BUILDGO_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/go/buildgo.sh)
add_custom_target(GotsanRuntimeCheck
COMMAND env "CC=${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}"
EXTRA_CFLAGS=${EXTRA_CFLAGS}
IN_TMPDIR=1 SILENT=1 ${BUILDGO_SCRIPT}
DEPENDS clang_rt.tsan-${arch} ${BUILDGO_SCRIPT}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/go
COMMENT "Checking TSan Go runtime..."
VERBATIM)
elseif(arch STREQUAL "aarch64")
add_asm_sources(TSAN_ASM_SOURCES
rtl/tsan_rtl_aarch64.S
)
# Sanity check for Go runtime.
set(BUILDGO_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/go/buildgo.sh)
add_custom_target(GotsanRuntimeCheck
COMMAND env "CC=${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}"
EXTRA_CFLAGS=${EXTRA_CFLAGS}
IN_TMPDIR=1 SILENT=1 ${BUILDGO_SCRIPT}
DEPENDS clang_rt.tsan-${arch} ${BUILDGO_SCRIPT}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/go
COMMENT "Checking TSan Go runtime..."
VERBATIM)
elseif(arch MATCHES "powerpc64|powerpc64le")
add_asm_sources(TSAN_ASM_SOURCES
rtl/tsan_rtl_ppc64.S
)
# Sanity check for Go runtime.
set(BUILDGO_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/go/buildgo.sh)
add_custom_target(GotsanRuntimeCheck
COMMAND env "CC=${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}"
EXTRA_CFLAGS=${EXTRA_CFLAGS}
IN_TMPDIR=1 SILENT=1 ${BUILDGO_SCRIPT}
DEPENDS clang_rt.tsan-${arch} ${BUILDGO_SCRIPT}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/go
COMMENT "Checking TSan Go runtime..."
VERBATIM)
elseif(arch MATCHES "mips64|mips64le")
add_asm_sources(TSAN_ASM_SOURCES
rtl/tsan_rtl_mips64.S
)
elseif(arch MATCHES "s390x")
add_asm_sources(TSAN_ASM_SOURCES
rtl/tsan_rtl_s390x.S
)
# Sanity check for Go runtime.
set(BUILDGO_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/go/buildgo.sh)
add_custom_target(GotsanRuntimeCheck
COMMAND env "CC=${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}"
EXTRA_CFLAGS=${EXTRA_CFLAGS}
IN_TMPDIR=1 SILENT=1 ${BUILDGO_SCRIPT}
DEPENDS clang_rt.tsan-${arch} ${BUILDGO_SCRIPT}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/go
COMMENT "Checking TSan Go runtime..."
VERBATIM)
else()
set(TSAN_ASM_SOURCES)
endif()
add_compiler_rt_runtime(clang_rt.tsan
STATIC
ARCHS ${arch}
SOURCES ${TSAN_SOURCES} ${TSAN_ASM_SOURCES}
$<TARGET_OBJECTS:RTInterception.${arch}>
$<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
$<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>
$<TARGET_OBJECTS:RTSanitizerCommonCoverage.${arch}>
$<TARGET_OBJECTS:RTSanitizerCommonSymbolizer.${arch}>
$<TARGET_OBJECTS:RTUbsan.${arch}>
ADDITIONAL_HEADERS ${TSAN_HEADERS}
CFLAGS ${TSAN_RTL_CFLAGS}
PARENT_TARGET tsan)
add_compiler_rt_runtime(clang_rt.tsan_cxx
STATIC
ARCHS ${arch}
SOURCES ${TSAN_CXX_SOURCES}
$<TARGET_OBJECTS:RTUbsan_cxx.${arch}>
ADDITIONAL_HEADERS ${TSAN_HEADERS}
CFLAGS ${TSAN_RTL_CFLAGS}
PARENT_TARGET tsan)
list(APPEND TSAN_RUNTIME_LIBRARIES clang_rt.tsan-${arch}
clang_rt.tsan_cxx-${arch})
add_sanitizer_rt_symbols(clang_rt.tsan
ARCHS ${arch}
EXTRA rtl/tsan.syms.extra)
add_sanitizer_rt_symbols(clang_rt.tsan_cxx
ARCHS ${arch}
EXTRA rtl/tsan.syms.extra)
add_dependencies(tsan clang_rt.tsan-${arch}
clang_rt.tsan_cxx-${arch}
clang_rt.tsan-${arch}-symbols
clang_rt.tsan_cxx-${arch}-symbols)
endforeach()
endif()
# Build libcxx instrumented with TSan.
if(COMPILER_RT_LIBCXX_PATH AND
COMPILER_RT_LIBCXXABI_PATH AND
COMPILER_RT_TEST_COMPILER_ID STREQUAL "Clang" AND
NOT ANDROID)
set(libcxx_tsan_deps)
foreach(arch ${TSAN_SUPPORTED_ARCH})
get_target_flags_for_arch(${arch} TARGET_CFLAGS)
set(LIBCXX_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/libcxx_tsan_${arch})
add_custom_libcxx(libcxx_tsan_${arch} ${LIBCXX_PREFIX}
DEPS ${TSAN_RUNTIME_LIBRARIES}
CFLAGS ${TARGET_CFLAGS} -fsanitize=thread
USE_TOOLCHAIN)
list(APPEND libcxx_tsan_deps libcxx_tsan_${arch}-build)
endforeach()
add_custom_target(libcxx_tsan DEPENDS ${libcxx_tsan_deps})
set_target_properties(libcxx_tsan PROPERTIES FOLDER "Compiler-RT Misc")
endif()
if(COMPILER_RT_INCLUDE_TESTS)
add_subdirectory(tests)
endif()
|