[AArch64] Fix SDNode type mismatches between *.td files and ISel (#116523)
[llvm-project.git] / compiler-rt / lib / ubsan / CMakeLists.txt
blob5d45a53d02dbd3ff5e3209cdc09d91908077e6c3
1 # Build for the undefined behavior sanitizer runtime support library.
3 set(UBSAN_SOURCES
4   ubsan_diag.cpp
5   ubsan_init.cpp
6   ubsan_flags.cpp
7   ubsan_handlers.cpp
8   ubsan_monitor.cpp
9   ubsan_value.cpp
10   )
12 set(UBSAN_STANDALONE_SOURCES
13   ubsan_diag_standalone.cpp
14   ubsan_init_standalone.cpp
15   ubsan_signals_standalone.cpp
16   )
18 set(UBSAN_CXXABI_SOURCES
19   ubsan_handlers_cxx.cpp
20   ubsan_type_hash.cpp
21   ubsan_type_hash_itanium.cpp
22   ubsan_type_hash_win.cpp
23  )
25 set(UBSAN_HEADERS
26   ubsan_checks.inc
27   ubsan_diag.h
28   ubsan_flags.h
29   ubsan_flags.inc
30   ubsan_handlers.h
31   ubsan_handlers_cxx.h
32   ubsan_init.h
33   ubsan_interface.inc
34   ubsan_monitor.h
35   ubsan_platform.h
36   ubsan_signals_standalone.h
37   ubsan_type_hash.h
38   ubsan_value.h
39   )
41 include_directories(..)
43 set(UBSAN_CFLAGS ${SANITIZER_COMMON_CFLAGS})
44 append_list_if(MSVC /Zl UBSAN_CFLAGS)
45 append_rtti_flag(OFF UBSAN_CFLAGS)
46 append_list_if(SANITIZER_CAN_USE_CXXABI -DUBSAN_CAN_USE_CXXABI UBSAN_CFLAGS)
48 # Too many existing bugs, needs cleanup.
49 append_list_if(COMPILER_RT_HAS_WNO_FORMAT -Wno-format UBSAN_CFLAGS)
51 set(UBSAN_STANDALONE_CFLAGS ${SANITIZER_COMMON_CFLAGS})
52 append_rtti_flag(OFF UBSAN_STANDALONE_CFLAGS)
53 append_list_if(SANITIZER_CAN_USE_CXXABI -DUBSAN_CAN_USE_CXXABI UBSAN_STANDALONE_CFLAGS)
55 set(UBSAN_CXXFLAGS ${SANITIZER_COMMON_CFLAGS})
56 append_rtti_flag(ON UBSAN_CXXFLAGS)
57 append_list_if(SANITIZER_CAN_USE_CXXABI -DUBSAN_CAN_USE_CXXABI UBSAN_CXXFLAGS)
59 # Silence warnings in system headers with MSVC.
60 if(NOT CLANG_CL)
61   append_list_if(COMPILER_RT_HAS_EXTERNAL_FLAG "/experimental:external;/external:W0;/external:anglebrackets" UBSAN_CXXFLAGS)
62 endif()
64 set(UBSAN_LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS})
66 set(UBSAN_DYNAMIC_LIBS
67   ${COMPILER_RT_UNWINDER_LINK_LIBS}
68   ${SANITIZER_CXX_ABI_LIBRARIES}
69   ${SANITIZER_COMMON_LINK_LIBS})
71 append_list_if(COMPILER_RT_HAS_LIBDL dl UBSAN_DYNAMIC_LIBS)
72 append_list_if(COMPILER_RT_HAS_LIBLOG log UBSAN_DYNAMIC_LIBS)
73 append_list_if(COMPILER_RT_HAS_LIBRT rt UBSAN_DYNAMIC_LIBS)
74 append_list_if(COMPILER_RT_HAS_LIBPTHREAD pthread UBSAN_DYNAMIC_LIBS)
75 if (COMPILER_RT_ENABLE_INTERNAL_SYMBOLIZER)
76   append_list_if(COMPILER_RT_HAS_LIBM m UBSAN_DYNAMIC_LIBS)
77 endif()
79 add_compiler_rt_component(ubsan)
81 if(APPLE)
82   set(UBSAN_COMMON_SOURCES ${UBSAN_SOURCES})
83   if(SANITIZER_CAN_USE_CXXABI)
84     list(APPEND UBSAN_COMMON_SOURCES ${UBSAN_CXXABI_SOURCES})
85   endif()
87   # Common parts of UBSan runtime.
88   add_compiler_rt_object_libraries(RTUbsan
89     OS ${SANITIZER_COMMON_SUPPORTED_OS}
90     ARCHS ${UBSAN_COMMON_SUPPORTED_ARCH}
91     SOURCES ${UBSAN_COMMON_SOURCES}
92     ADDITIONAL_HEADERS ${UBSAN_HEADERS}
93     CFLAGS ${UBSAN_CXXFLAGS})
95   if(COMPILER_RT_HAS_UBSAN)
96     # Initializer of standalone UBSan runtime.
97     add_compiler_rt_object_libraries(RTUbsan_standalone
98       OS ${UBSAN_SUPPORTED_OS}
99       ARCHS ${UBSAN_SUPPORTED_ARCH}
100       SOURCES ${UBSAN_STANDALONE_SOURCES}
101       ADDITIONAL_HEADERS ${UBSAN_HEADERS}
102       CFLAGS ${UBSAN_STANDALONE_CFLAGS})
104     add_weak_symbols("ubsan" WEAK_SYMBOL_LINK_FLAGS)
105     add_weak_symbols("sanitizer_common" WEAK_SYMBOL_LINK_FLAGS)
107     add_compiler_rt_runtime(clang_rt.ubsan
108       SHARED
109       OS ${UBSAN_SUPPORTED_OS}
110       ARCHS ${UBSAN_SUPPORTED_ARCH}
111       OBJECT_LIBS RTUbsan
112                   RTUbsan_standalone
113                   RTSanitizerCommon
114                   RTSanitizerCommonLibc
115                   RTSanitizerCommonCoverage
116                   RTSanitizerCommonSymbolizer
117                   RTInterception
118       LINK_FLAGS ${WEAK_SYMBOL_LINK_FLAGS}
119       PARENT_TARGET ubsan)
121     if (NOT APPLE)
122       add_compiler_rt_runtime(clang_rt.ubsan
123         STATIC
124         OS ${UBSAN_SUPPORTED_OS}
125         ARCHS ${UBSAN_SUPPORTED_ARCH}
126         OBJECT_LIBS RTUbsan
127                     RTUbsan_standalone
128                     RTSanitizerCommonNoHooks
129                     RTSanitizerCommonLibcNoHooks
130                     RTSanitizerCommonCoverage
131                     RTSanitizerCommonSymbolizerNoHooks
132                     RTInterception
133         LINK_FLAGS ${WEAK_SYMBOL_LINK_FLAGS}
134         PARENT_TARGET ubsan)
135     endif()
136   endif()
138 else()
139   # Common parts of UBSan runtime.
140   add_compiler_rt_object_libraries(RTUbsan
141     ARCHS ${UBSAN_COMMON_SUPPORTED_ARCH}
142     SOURCES ${UBSAN_SOURCES}
143     ADDITIONAL_HEADERS ${UBSAN_HEADERS}
144     CFLAGS ${UBSAN_CFLAGS})
146   if(SANITIZER_CAN_USE_CXXABI)
147     # C++-specific parts of UBSan runtime. Requires a C++ ABI library.
148     set(UBSAN_CXX_SOURCES ${UBSAN_CXXABI_SOURCES})
149   else()
150     # Dummy target if we don't have C++ ABI library.
151     file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cxx_dummy.cpp "")
152     set(UBSAN_CXX_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/cxx_dummy.cpp)
153   endif()
155   add_compiler_rt_object_libraries(RTUbsan_cxx
156     ARCHS ${UBSAN_COMMON_SUPPORTED_ARCH}
157     SOURCES ${UBSAN_CXX_SOURCES}
158     ADDITIONAL_HEADERS ${UBSAN_HEADERS}
159     CFLAGS ${UBSAN_CXXFLAGS})
161   if (WIN32)
162     set(RUNTIME_THUNK_CFLAGS -DSANITIZER_DYNAMIC_RUNTIME_THUNK -DSANITIZER_STATIC_RUNTIME_THUNK)
163     add_compiler_rt_object_libraries(UbsanRuntimeThunk
164       ${SANITIZER_COMMON_SUPPORTED_OS}
165       ARCHS ${UBSAN_SUPPORTED_ARCH}
166       SOURCES
167         ubsan_win_runtime_thunk.cpp
168       CFLAGS ${UBSAN_CFLAGS} ${DYNAMIC_RUNTIME_THUNK_CFLAGS}
169       DEFS ${UBSAN_COMMON_DEFINITIONS})
170   endif()
172   if(COMPILER_RT_HAS_UBSAN)
173     add_compiler_rt_object_libraries(RTUbsan_standalone
174       ARCHS ${UBSAN_SUPPORTED_ARCH}
175       SOURCES ${UBSAN_STANDALONE_SOURCES}
176       ADDITIONAL_HEADERS ${UBSAN_HEADERS}
177       CFLAGS ${UBSAN_STANDALONE_CFLAGS})
179     # Standalone UBSan runtimes.
180     add_compiler_rt_runtime(clang_rt.ubsan_standalone
181       STATIC
182       ARCHS ${UBSAN_SUPPORTED_ARCH}
183       SOURCES
184         ubsan_init_standalone_preinit.cpp
185       ADDITIONAL_HEADERS ${UBSAN_HEADERS}
186       OBJECT_LIBS RTSanitizerCommon
187               RTSanitizerCommonLibc
188               RTSanitizerCommonCoverage
189               RTSanitizerCommonSymbolizer
190               RTSanitizerCommonSymbolizerInternal
191               RTUbsan
192               RTUbsan_standalone
193               RTInterception
194       CFLAGS ${UBSAN_CFLAGS}
195       PARENT_TARGET ubsan)
197     add_compiler_rt_runtime(clang_rt.ubsan_standalone_cxx
198       STATIC
199       ARCHS ${UBSAN_SUPPORTED_ARCH}
200       OBJECT_LIBS RTUbsan_cxx
201       CFLAGS ${UBSAN_CXXFLAGS}
202       PARENT_TARGET ubsan)
204     if (COMPILER_RT_HAS_VERSION_SCRIPT)
205       file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp "")
206       add_compiler_rt_object_libraries(RTUbsan_dynamic_version_script_dummy
207         ARCHS ${UBSAN_SUPPORTED_ARCH}
208         SOURCES ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp
209         CFLAGS ${UBSAN_CFLAGS})
211       foreach(arch ${UBSAN_SUPPORTED_ARCH})
212         add_sanitizer_rt_version_list(clang_rt.ubsan_standalone-dynamic-${arch}
213                                       LIBS clang_rt.ubsan_standalone-${arch}
214                                            clang_rt.ubsan_standalone_cxx-${arch}
215                                       EXTRA ubsan.syms.extra)
216         set(VERSION_SCRIPT_FLAG
217             -Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/clang_rt.ubsan_standalone-dynamic-${arch}.vers)
218         # The Solaris 11.4 linker supports a subset of GNU ld version scripts,
219         # but requires a special option to enable it.
220         if (COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT)
221             list(APPEND VERSION_SCRIPT_FLAG -Wl,-z,gnu-version-script-compat)
222         endif()
223         set_property(SOURCE
224           ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp
225           APPEND PROPERTY
226           OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/clang_rt.ubsan_standalone-dynamic-${arch}.vers)
228         add_compiler_rt_runtime(clang_rt.ubsan_standalone
229           SHARED
230           ARCHS ${arch}
231           OBJECT_LIBS RTSanitizerCommon
232                 RTSanitizerCommonLibc
233                 RTSanitizerCommonCoverage
234                 RTSanitizerCommonSymbolizer
235                 RTSanitizerCommonSymbolizerInternal
236                 RTUbsan
237                 RTUbsan_cxx
238                 RTUbsan_standalone
239                 RTInterception
240                 RTUbsan_dynamic_version_script_dummy
241           CFLAGS ${UBSAN_CFLAGS}
242           LINK_FLAGS ${UBSAN_LINK_FLAGS} ${VERSION_SCRIPT_FLAG}
243           LINK_LIBS ${UBSAN_DYNAMIC_LIBS}
244           PARENT_TARGET ubsan)
245       endforeach()
247       set(ARCHS_FOR_SYMBOLS ${UBSAN_SUPPORTED_ARCH})
248       list(REMOVE_ITEM ARCHS_FOR_SYMBOLS i386)
249       add_sanitizer_rt_symbols(clang_rt.ubsan_standalone
250         ARCHS ${ARCHS_FOR_SYMBOLS}
251         PARENT_TARGET ubsan
252         EXTRA ubsan.syms.extra)
253       add_sanitizer_rt_symbols(clang_rt.ubsan_standalone_cxx
254         ARCHS ${ARCHS_FOR_SYMBOLS}
255         PARENT_TARGET ubsan
256         EXTRA ubsan.syms.extra)
257     endif()
258   endif()
259 endif()