1 # Build for the undefined behavior sanitizer runtime support library.
12 set(UBSAN_STANDALONE_SOURCES
13 ubsan_diag_standalone.cpp
14 ubsan_init_standalone.cpp
15 ubsan_signals_standalone.cpp
18 set(UBSAN_CXXABI_SOURCES
19 ubsan_handlers_cxx.cpp
21 ubsan_type_hash_itanium.cpp
22 ubsan_type_hash_win.cpp
36 ubsan_signals_standalone.h
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.
61 append_list_if(COMPILER_RT_HAS_EXTERNAL_FLAG "/experimental:external;/external:W0;/external:anglebrackets" UBSAN_CXXFLAGS)
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)
79 add_compiler_rt_component(ubsan)
82 set(UBSAN_COMMON_SOURCES ${UBSAN_SOURCES})
83 if(SANITIZER_CAN_USE_CXXABI)
84 list(APPEND UBSAN_COMMON_SOURCES ${UBSAN_CXXABI_SOURCES})
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
109 OS ${UBSAN_SUPPORTED_OS}
110 ARCHS ${UBSAN_SUPPORTED_ARCH}
114 RTSanitizerCommonLibc
115 RTSanitizerCommonCoverage
116 RTSanitizerCommonSymbolizer
118 LINK_FLAGS ${WEAK_SYMBOL_LINK_FLAGS}
122 add_compiler_rt_runtime(clang_rt.ubsan
124 OS ${UBSAN_SUPPORTED_OS}
125 ARCHS ${UBSAN_SUPPORTED_ARCH}
128 RTSanitizerCommonNoHooks
129 RTSanitizerCommonLibcNoHooks
130 RTSanitizerCommonCoverage
131 RTSanitizerCommonSymbolizerNoHooks
133 LINK_FLAGS ${WEAK_SYMBOL_LINK_FLAGS}
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})
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)
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})
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}
167 ubsan_win_runtime_thunk.cpp
168 CFLAGS ${UBSAN_CFLAGS} ${DYNAMIC_RUNTIME_THUNK_CFLAGS}
169 DEFS ${UBSAN_COMMON_DEFINITIONS})
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
182 ARCHS ${UBSAN_SUPPORTED_ARCH}
184 ubsan_init_standalone_preinit.cpp
185 ADDITIONAL_HEADERS ${UBSAN_HEADERS}
186 OBJECT_LIBS RTSanitizerCommon
187 RTSanitizerCommonLibc
188 RTSanitizerCommonCoverage
189 RTSanitizerCommonSymbolizer
190 RTSanitizerCommonSymbolizerInternal
194 CFLAGS ${UBSAN_CFLAGS}
197 add_compiler_rt_runtime(clang_rt.ubsan_standalone_cxx
199 ARCHS ${UBSAN_SUPPORTED_ARCH}
200 OBJECT_LIBS RTUbsan_cxx
201 CFLAGS ${UBSAN_CXXFLAGS}
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)
224 ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp
226 OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/clang_rt.ubsan_standalone-dynamic-${arch}.vers)
228 add_compiler_rt_runtime(clang_rt.ubsan_standalone
231 OBJECT_LIBS RTSanitizerCommon
232 RTSanitizerCommonLibc
233 RTSanitizerCommonCoverage
234 RTSanitizerCommonSymbolizer
235 RTSanitizerCommonSymbolizerInternal
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}
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}
252 EXTRA ubsan.syms.extra)
253 add_sanitizer_rt_symbols(clang_rt.ubsan_standalone_cxx
254 ARCHS ${ARCHS_FOR_SYMBOLS}
256 EXTRA ubsan.syms.extra)