[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / compiler-rt / lib / tsan / rtl / CMakeLists.txt
blob791c0596f65abf7301d591fbe052ec9bba8ea8bb
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
6                TSAN_RTL_CFLAGS)
7 append_list_if(COMPILER_RT_HAS_WGLOBAL_CONSTRUCTORS_FLAG -Wglobal-constructors
8                TSAN_RTL_CFLAGS)
9 append_list_if(COMPILER_RT_INTERCEPT_LIBDISPATCH ${COMPILER_RT_LIBDISPATCH_CFLAGS}
10                TSAN_RTL_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)
24 set(TSAN_SOURCES
25   tsan_debugging.cpp
26   tsan_external.cpp
27   tsan_fd.cpp
28   tsan_flags.cpp
29   tsan_ignoreset.cpp
30   tsan_interceptors_memintrinsics.cpp
31   tsan_interceptors_posix.cpp
32   tsan_interface.cpp
33   tsan_interface_ann.cpp
34   tsan_interface_atomic.cpp
35   tsan_interface_java.cpp
36   tsan_malloc_mac.cpp
37   tsan_md5.cpp
38   tsan_mman.cpp
39   tsan_mutexset.cpp
40   tsan_report.cpp
41   tsan_rtl.cpp
42   tsan_rtl_access.cpp
43   tsan_rtl_mutex.cpp
44   tsan_rtl_proc.cpp
45   tsan_rtl_report.cpp
46   tsan_rtl_thread.cpp
47   tsan_stack_trace.cpp
48   tsan_suppressions.cpp
49   tsan_symbolize.cpp
50   tsan_sync.cpp
51   tsan_vector_clock.cpp
52   )
54 set(TSAN_CXX_SOURCES
55   tsan_new_delete.cpp
56   )
58 set(TSAN_PREINIT_SOURCES
59   tsan_preinit.cpp
60   )
62 if(APPLE)
63   list(APPEND TSAN_SOURCES
64     tsan_interceptors_mac.cpp
65     tsan_interceptors_mach_vm.cpp
66     tsan_platform_mac.cpp
67     tsan_platform_posix.cpp
68     )
69 elseif(UNIX)
70   # Assume Linux
71   list(APPEND TSAN_SOURCES
72     tsan_platform_linux.cpp
73     tsan_platform_posix.cpp
74     )
75 endif()
77 if(COMPILER_RT_INTERCEPT_LIBDISPATCH)
78   list(APPEND TSAN_SOURCES
79     tsan_interceptors_libdispatch.cpp
80     )
81 endif()
83 set(TSAN_HEADERS
84   tsan_defs.h
85   tsan_dense_alloc.h
86   tsan_fd.h
87   tsan_flags.h
88   tsan_flags.inc
89   tsan_ignoreset.h
90   tsan_ilist.h
91   tsan_interceptors.h
92   tsan_interface.h
93   tsan_interface.inc
94   tsan_interface_ann.h
95   tsan_interface_java.h
96   tsan_mman.h
97   tsan_mutexset.h
98   tsan_platform.h
99   tsan_ppc_regs.h
100   tsan_report.h
101   tsan_rtl.h
102   tsan_shadow.h
103   tsan_stack_trace.h
104   tsan_suppressions.h
105   tsan_symbolize.h
106   tsan_sync.h
107   tsan_trace.h
108   tsan_vector_clock.h
109   )
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}")
116 endif()
118 if(APPLE)
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)")
125   endif()
127   set(TSAN_ASM_SOURCES
128     tsan_rtl_amd64.S
129     tsan_rtl_aarch64.S
130     )
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
138     SHARED
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
144                 RTSanitizerCommon
145                 RTSanitizerCommonLibc
146                 RTSanitizerCommonCoverage
147                 RTSanitizerCommonSymbolizer
148                 RTUbsan
149     CFLAGS ${TSAN_RTL_CFLAGS}
150     LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS} ${WEAK_SYMBOL_LINK_FLAGS}
151     LINK_LIBS ${TSAN_LINK_LIBS} objc
152     PARENT_TARGET tsan)
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..."
169     VERBATIM)
170   set_target_properties(GotsanRuntimeCheck PROPERTIES FOLDER "Compiler-RT Misc")
171 else()
172   foreach(arch ${TSAN_SUPPORTED_ARCH})
173     if(arch STREQUAL "x86_64")
174       set(TSAN_ASM_SOURCES
175         tsan_rtl_amd64.S
176         )
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..."
186         VERBATIM)
187     elseif(arch STREQUAL "aarch64")
188       set(TSAN_ASM_SOURCES
189         tsan_rtl_aarch64.S
190         )
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..."
200         VERBATIM)
201     elseif(arch MATCHES "powerpc64|powerpc64le")
202       set(TSAN_ASM_SOURCES
203         tsan_rtl_ppc64.S
204         )
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..."
214         VERBATIM)
215     elseif(arch MATCHES "loongarch64")
216       set(TSAN_ASM_SOURCES
217         tsan_rtl_loongarch64.S
218         )
219     elseif(arch MATCHES "mips64|mips64le")
220       set(TSAN_ASM_SOURCES
221         tsan_rtl_mips64.S
222         )
223     elseif(arch MATCHES "riscv64")
224       set(TSAN_ASM_SOURCES
225         tsan_rtl_riscv64.S
226         )
227     elseif(arch MATCHES "s390x")
228       set(TSAN_ASM_SOURCES
229         tsan_rtl_s390x.S
230         )
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..."
240         VERBATIM)
241     else()
242       set(TSAN_ASM_SOURCES)
243     endif()
244     add_compiler_rt_runtime(clang_rt.tsan
245       STATIC
246       ARCHS ${arch}
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}
257       PARENT_TARGET tsan)
258     add_compiler_rt_runtime(clang_rt.tsan_cxx
259       STATIC
260       ARCHS ${arch}
261       SOURCES ${TSAN_CXX_SOURCES}
262               $<TARGET_OBJECTS:RTUbsan_cxx.${arch}>
263       ADDITIONAL_HEADERS ${TSAN_HEADERS}
264       CFLAGS ${TSAN_RTL_CFLAGS}
265       PARENT_TARGET tsan)
266     list(APPEND TSAN_RUNTIME_LIBRARIES clang_rt.tsan-${arch}
267                                        clang_rt.tsan_cxx-${arch})
268     add_compiler_rt_runtime(clang_rt.tsan
269       SHARED
270       ARCHS ${arch}
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}
284       PARENT_TARGET tsan)
285     add_sanitizer_rt_symbols(clang_rt.tsan
286       ARCHS ${arch}
287       EXTRA tsan.syms.extra)
288     add_sanitizer_rt_symbols(clang_rt.tsan_cxx
289       ARCHS ${arch}
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)
295   endforeach()
296 endif()