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_rtti_flag(OFF UBSAN_CFLAGS)
45 append_list_if(SANITIZER_CAN_USE_CXXABI -DUBSAN_CAN_USE_CXXABI UBSAN_CFLAGS)
47 # Too many existing bugs, needs cleanup.
48 append_list_if(COMPILER_RT_HAS_WNO_FORMAT -Wno-format UBSAN_CFLAGS)
50 set(UBSAN_STANDALONE_CFLAGS ${SANITIZER_COMMON_CFLAGS})
51 append_rtti_flag(OFF UBSAN_STANDALONE_CFLAGS)
52 append_list_if(SANITIZER_CAN_USE_CXXABI -DUBSAN_CAN_USE_CXXABI UBSAN_STANDALONE_CFLAGS)
54 set(UBSAN_CXXFLAGS ${SANITIZER_COMMON_CFLAGS})
55 append_rtti_flag(ON UBSAN_CXXFLAGS)
56 append_list_if(SANITIZER_CAN_USE_CXXABI -DUBSAN_CAN_USE_CXXABI UBSAN_CXXFLAGS)
58 # Silence warnings in system headers with MSVC.
60 append_list_if(COMPILER_RT_HAS_EXTERNAL_FLAG "/experimental:external;/external:W0;/external:anglebrackets" UBSAN_CXXFLAGS)
63 set(UBSAN_LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS})
65 set(UBSAN_DYNAMIC_LIBS
66 ${COMPILER_RT_UNWINDER_LINK_LIBS}
67 ${SANITIZER_CXX_ABI_LIBRARIES}
68 ${SANITIZER_COMMON_LINK_LIBS})
70 append_list_if(COMPILER_RT_HAS_LIBDL dl UBSAN_DYNAMIC_LIBS)
71 append_list_if(COMPILER_RT_HAS_LIBLOG log UBSAN_DYNAMIC_LIBS)
72 append_list_if(COMPILER_RT_HAS_LIBRT rt UBSAN_DYNAMIC_LIBS)
73 append_list_if(COMPILER_RT_HAS_LIBPTHREAD pthread UBSAN_DYNAMIC_LIBS)
74 if (COMPILER_RT_ENABLE_INTERNAL_SYMBOLIZER)
75 append_list_if(COMPILER_RT_HAS_LIBM m UBSAN_DYNAMIC_LIBS)
78 add_compiler_rt_component(ubsan)
81 set(UBSAN_COMMON_SOURCES ${UBSAN_SOURCES})
82 if(SANITIZER_CAN_USE_CXXABI)
83 list(APPEND UBSAN_COMMON_SOURCES ${UBSAN_CXXABI_SOURCES})
86 # Common parts of UBSan runtime.
87 add_compiler_rt_object_libraries(RTUbsan
88 OS ${SANITIZER_COMMON_SUPPORTED_OS}
89 ARCHS ${UBSAN_COMMON_SUPPORTED_ARCH}
90 SOURCES ${UBSAN_COMMON_SOURCES}
91 ADDITIONAL_HEADERS ${UBSAN_HEADERS}
92 CFLAGS ${UBSAN_CXXFLAGS})
94 if(COMPILER_RT_HAS_UBSAN)
95 # Initializer of standalone UBSan runtime.
96 add_compiler_rt_object_libraries(RTUbsan_standalone
97 OS ${UBSAN_SUPPORTED_OS}
98 ARCHS ${UBSAN_SUPPORTED_ARCH}
99 SOURCES ${UBSAN_STANDALONE_SOURCES}
100 ADDITIONAL_HEADERS ${UBSAN_HEADERS}
101 CFLAGS ${UBSAN_STANDALONE_CFLAGS})
103 add_weak_symbols("ubsan" WEAK_SYMBOL_LINK_FLAGS)
104 add_weak_symbols("sanitizer_common" WEAK_SYMBOL_LINK_FLAGS)
106 add_compiler_rt_runtime(clang_rt.ubsan
108 OS ${UBSAN_SUPPORTED_OS}
109 ARCHS ${UBSAN_SUPPORTED_ARCH}
113 RTSanitizerCommonLibc
114 RTSanitizerCommonCoverage
115 RTSanitizerCommonSymbolizer
117 LINK_FLAGS ${WEAK_SYMBOL_LINK_FLAGS}
121 add_compiler_rt_runtime(clang_rt.ubsan
123 OS ${UBSAN_SUPPORTED_OS}
124 ARCHS ${UBSAN_SUPPORTED_ARCH}
127 RTSanitizerCommonNoHooks
128 RTSanitizerCommonLibcNoHooks
129 RTSanitizerCommonCoverage
130 RTSanitizerCommonSymbolizerNoHooks
132 LINK_FLAGS ${WEAK_SYMBOL_LINK_FLAGS}
138 # Common parts of UBSan runtime.
139 add_compiler_rt_object_libraries(RTUbsan
140 ARCHS ${UBSAN_COMMON_SUPPORTED_ARCH}
141 SOURCES ${UBSAN_SOURCES}
142 ADDITIONAL_HEADERS ${UBSAN_HEADERS}
143 CFLAGS ${UBSAN_CFLAGS})
145 if(SANITIZER_CAN_USE_CXXABI)
146 # C++-specific parts of UBSan runtime. Requires a C++ ABI library.
147 set(UBSAN_CXX_SOURCES ${UBSAN_CXXABI_SOURCES})
149 # Dummy target if we don't have C++ ABI library.
150 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cxx_dummy.cpp "")
151 set(UBSAN_CXX_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/cxx_dummy.cpp)
154 add_compiler_rt_object_libraries(RTUbsan_cxx
155 ARCHS ${UBSAN_COMMON_SUPPORTED_ARCH}
156 SOURCES ${UBSAN_CXX_SOURCES}
157 ADDITIONAL_HEADERS ${UBSAN_HEADERS}
158 CFLAGS ${UBSAN_CXXFLAGS})
161 add_compiler_rt_object_libraries(UbsanWeakInterception
162 ${SANITIZER_COMMON_SUPPORTED_OS}
163 ARCHS ${UBSAN_SUPPORTED_ARCH}
165 ubsan_win_weak_interception.cpp
166 CFLAGS ${UBSAN_CFLAGS} -DSANITIZER_DYNAMIC
167 DEFS ${UBSAN_COMMON_DEFINITIONS})
169 add_compiler_rt_object_libraries(UbsanDllThunk
170 ${SANITIZER_COMMON_SUPPORTED_OS}
171 ARCHS ${UBSAN_SUPPORTED_ARCH}
173 ubsan_win_dll_thunk.cpp
174 CFLAGS ${UBSAN_CFLAGS} -DSANITIZER_DLL_THUNK
175 DEFS ${UBSAN_COMMON_DEFINITIONS})
177 set(DYNAMIC_RUNTIME_THUNK_CFLAGS "-DSANITIZER_DYNAMIC_RUNTIME_THUNK")
179 list(APPEND DYNAMIC_RUNTIME_THUNK_CFLAGS "-Zl")
180 elseif(CMAKE_C_COMPILER_ID MATCHES Clang)
181 list(APPEND DYNAMIC_RUNTIME_THUNK_CFLAGS "-nodefaultlibs")
183 add_compiler_rt_object_libraries(UbsanDynamicRuntimeThunk
184 ${SANITIZER_COMMON_SUPPORTED_OS}
185 ARCHS ${UBSAN_SUPPORTED_ARCH}
187 ubsan_win_dynamic_runtime_thunk.cpp
188 CFLAGS ${UBSAN_CFLAGS} ${DYNAMIC_RUNTIME_THUNK_CFLAGS}
189 DEFS ${UBSAN_COMMON_DEFINITIONS})
192 if(COMPILER_RT_HAS_UBSAN)
193 add_compiler_rt_object_libraries(RTUbsan_standalone
194 ARCHS ${UBSAN_SUPPORTED_ARCH}
195 SOURCES ${UBSAN_STANDALONE_SOURCES}
196 ADDITIONAL_HEADERS ${UBSAN_HEADERS}
197 CFLAGS ${UBSAN_STANDALONE_CFLAGS})
199 # Standalone UBSan runtimes.
200 add_compiler_rt_runtime(clang_rt.ubsan_standalone
202 ARCHS ${UBSAN_SUPPORTED_ARCH}
204 ubsan_init_standalone_preinit.cpp
205 ADDITIONAL_HEADERS ${UBSAN_HEADERS}
206 OBJECT_LIBS RTSanitizerCommon
207 RTSanitizerCommonLibc
208 RTSanitizerCommonCoverage
209 RTSanitizerCommonSymbolizer
210 RTSanitizerCommonSymbolizerInternal
214 CFLAGS ${UBSAN_CFLAGS}
217 add_compiler_rt_runtime(clang_rt.ubsan_standalone_cxx
219 ARCHS ${UBSAN_SUPPORTED_ARCH}
220 OBJECT_LIBS RTUbsan_cxx
221 CFLAGS ${UBSAN_CXXFLAGS}
224 if (COMPILER_RT_HAS_VERSION_SCRIPT)
225 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp "")
226 add_compiler_rt_object_libraries(RTUbsan_dynamic_version_script_dummy
227 ARCHS ${UBSAN_SUPPORTED_ARCH}
228 SOURCES ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp
229 CFLAGS ${UBSAN_CFLAGS})
231 foreach(arch ${UBSAN_SUPPORTED_ARCH})
232 add_sanitizer_rt_version_list(clang_rt.ubsan_standalone-dynamic-${arch}
233 LIBS clang_rt.ubsan_standalone-${arch}
234 clang_rt.ubsan_standalone_cxx-${arch}
235 EXTRA ubsan.syms.extra)
236 set(VERSION_SCRIPT_FLAG
237 -Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/clang_rt.ubsan_standalone-dynamic-${arch}.vers)
238 # The Solaris 11.4 linker supports a subset of GNU ld version scripts,
239 # but requires a special option to enable it.
240 if (COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT)
241 list(APPEND VERSION_SCRIPT_FLAG -Wl,-z,gnu-version-script-compat)
244 ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp
246 OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/clang_rt.ubsan_standalone-dynamic-${arch}.vers)
248 add_compiler_rt_runtime(clang_rt.ubsan_standalone
251 OBJECT_LIBS RTSanitizerCommon
252 RTSanitizerCommonLibc
253 RTSanitizerCommonCoverage
254 RTSanitizerCommonSymbolizer
255 RTSanitizerCommonSymbolizerInternal
260 RTUbsan_dynamic_version_script_dummy
261 CFLAGS ${UBSAN_CFLAGS}
262 LINK_FLAGS ${UBSAN_LINK_FLAGS} ${VERSION_SCRIPT_FLAG}
263 LINK_LIBS ${UBSAN_DYNAMIC_LIBS}
267 set(ARCHS_FOR_SYMBOLS ${UBSAN_SUPPORTED_ARCH})
268 list(REMOVE_ITEM ARCHS_FOR_SYMBOLS i386)
269 add_sanitizer_rt_symbols(clang_rt.ubsan_standalone
270 ARCHS ${ARCHS_FOR_SYMBOLS}
272 EXTRA ubsan.syms.extra)
273 add_sanitizer_rt_symbols(clang_rt.ubsan_standalone_cxx
274 ARCHS ${ARCHS_FOR_SYMBOLS}
276 EXTRA ubsan.syms.extra)