1 include_directories(..)
3 # Runtime library sources and build flags.
7 hwasan_allocation_functions.cpp
8 hwasan_dynamic_shadow.cpp
12 hwasan_interceptors.cpp
13 hwasan_interceptors_vfork.S
15 hwasan_memintrinsics.cpp
18 hwasan_setjmp_aarch64.S
19 hwasan_setjmp_riscv64.S
20 hwasan_setjmp_x86_64.S
21 hwasan_tag_mismatch_aarch64.S
22 hwasan_tag_mismatch_riscv64.S
24 hwasan_thread_list.cpp
28 set(HWASAN_RTL_CXX_SOURCES
32 set(HWASAN_RTL_PREINIT_SOURCES
36 set(HWASAN_RTL_HEADERS
39 hwasan_dynamic_shadow.h
43 hwasan_interface_internal.h
44 hwasan_malloc_bisect.h
52 set(HWASAN_DEFINITIONS)
53 append_list_if(COMPILER_RT_HWASAN_WITH_INTERCEPTORS HWASAN_WITH_INTERCEPTORS=1 HWASAN_DEFINITIONS)
56 # Set this explicitly on Fuchsia, otherwise the default value is set to HWASAN_WITH_INTERCEPTORS.
57 list(APPEND HWASAN_DEFINITIONS HWASAN_REPLACE_OPERATORS_NEW_AND_DELETE=1)
60 set(HWASAN_RTL_CFLAGS ${SANITIZER_COMMON_CFLAGS})
61 append_rtti_flag(OFF HWASAN_RTL_CFLAGS)
62 append_list_if(COMPILER_RT_HAS_FPIC_FLAG -fPIC HWASAN_RTL_CFLAGS)
63 # Prevent clang from generating libc calls.
64 append_list_if(COMPILER_RT_HAS_FFREESTANDING_FLAG -ffreestanding HWASAN_RTL_CFLAGS)
66 # Too many existing bugs, needs cleanup.
67 append_list_if(COMPILER_RT_HAS_WNO_FORMAT -Wno-format HWASAN_RTL_CFLAGS)
69 set(HWASAN_DYNAMIC_LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS})
72 # Put most Sanitizer shared libraries in the global group. For more details, see
73 # android-changes-for-ndk-developers.md#changes-to-library-search-order
74 if (COMPILER_RT_HAS_Z_GLOBAL)
75 list(APPEND HWASAN_DYNAMIC_LINK_FLAGS -Wl,-z,global)
79 set(HWASAN_DYNAMIC_CFLAGS ${HWASAN_RTL_CFLAGS})
80 append_list_if(COMPILER_RT_HAS_FTLS_MODEL_INITIAL_EXEC
81 -ftls-model=initial-exec HWASAN_DYNAMIC_CFLAGS)
82 append_list_if(MSVC /DEBUG HWASAN_DYNAMIC_LINK_FLAGS)
84 set(HWASAN_DYNAMIC_LIBS
85 ${COMPILER_RT_UNWINDER_LINK_LIBS}
86 ${SANITIZER_CXX_ABI_LIBRARIES}
87 ${SANITIZER_COMMON_LINK_LIBS})
89 append_list_if(COMPILER_RT_HAS_LIBDL dl HWASAN_DYNAMIC_LIBS)
90 append_list_if(COMPILER_RT_HAS_LIBRT rt HWASAN_DYNAMIC_LIBS)
91 append_list_if(COMPILER_RT_HAS_LIBM m HWASAN_DYNAMIC_LIBS)
92 append_list_if(COMPILER_RT_HAS_LIBPTHREAD pthread HWASAN_DYNAMIC_LIBS)
94 # Static runtime library.
95 add_compiler_rt_component(hwasan)
97 add_compiler_rt_object_libraries(RTHwasan
98 ARCHS ${HWASAN_SUPPORTED_ARCH}
99 SOURCES ${HWASAN_RTL_SOURCES}
100 ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS}
101 CFLAGS ${HWASAN_RTL_CFLAGS}
102 DEFS ${HWASAN_DEFINITIONS})
103 add_compiler_rt_object_libraries(RTHwasan_cxx
104 ARCHS ${HWASAN_SUPPORTED_ARCH}
105 SOURCES ${HWASAN_RTL_CXX_SOURCES}
106 ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS}
107 CFLAGS ${HWASAN_RTL_CFLAGS}
108 DEFS ${HWASAN_DEFINITIONS})
109 add_compiler_rt_object_libraries(RTHwasan_dynamic
110 ARCHS ${HWASAN_SUPPORTED_ARCH}
111 SOURCES ${HWASAN_RTL_SOURCES} ${HWASAN_RTL_CXX_SOURCES}
112 ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS}
113 CFLAGS ${HWASAN_DYNAMIC_CFLAGS}
114 DEFS ${HWASAN_DEFINITIONS})
115 add_compiler_rt_object_libraries(RTHwasan_preinit
116 ARCHS ${HWASAN_SUPPORTED_ARCH}
117 SOURCES ${HWASAN_RTL_PREINIT_SOURCES}
118 ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS}
119 CFLAGS ${HWASAN_RTL_CFLAGS}
120 DEFS ${HWASAN_DEFINITIONS})
122 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp "")
123 add_compiler_rt_object_libraries(RTHwasan_dynamic_version_script_dummy
124 ARCHS ${HWASAN_SUPPORTED_ARCH}
125 SOURCES ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp
126 CFLAGS ${HWASAN_DYNAMIC_CFLAGS}
127 DEFS ${HWASAN_DEFINITIONS})
129 # If use_aliases is TRUE, adds the HWASan runtime built with alias support.
130 # Otherwise adds the runtime without alias support.
131 function(add_hwasan_runtimes arch use_aliases)
132 set(hwasan_object_lib RTHwasan)
133 set(hwasan_object_dyn_lib RTHwasan_dynamic)
134 set(hwasan_runtime clang_rt.hwasan)
135 set(hwasan_rtl_flags ${HWASAN_RTL_CFLAGS})
136 set(hwasan_dyn_flags ${HWASAN_DYNAMIC_CFLAGS})
138 list(APPEND hwasan_rtl_flags -DHWASAN_ALIASING_MODE)
139 list(APPEND hwasan_dyn_flags -DHWASAN_ALIASING_MODE)
140 add_compiler_rt_object_libraries(RTHwasanAliases
142 SOURCES ${HWASAN_RTL_SOURCES}
143 ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS}
144 CFLAGS ${hwasan_rtl_flags}
145 DEFS ${HWASAN_DEFINITIONS})
146 add_compiler_rt_object_libraries(RTHwasanAliases_dynamic
148 SOURCES ${HWASAN_RTL_SOURCES} ${HWASAN_RTL_CXX_SOURCES}
149 ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS}
150 CFLAGS ${hwasan_dyn_flags}
151 DEFS ${HWASAN_DEFINITIONS})
153 set(hwasan_object_lib RTHwasanAliases)
154 set(hwasan_object_dyn_lib RTHwasanAliases_dynamic)
155 set(hwasan_runtime clang_rt.hwasan_aliases)
157 add_compiler_rt_runtime(${hwasan_runtime}
160 OBJECT_LIBS ${hwasan_object_lib}
164 RTSanitizerCommonLibc
165 RTSanitizerCommonCoverage
166 RTSanitizerCommonSymbolizer
167 RTSanitizerCommonSymbolizerInternal
170 CFLAGS ${hwasan_rtl_flags}
171 PARENT_TARGET hwasan)
172 add_compiler_rt_runtime(${hwasan_runtime}_cxx
175 OBJECT_LIBS RTHwasan_cxx
177 CFLAGS ${hwasan_rtl_flags}
178 PARENT_TARGET hwasan)
181 add_sanitizer_rt_version_list(${hwasan_runtime}-dynamic-${arch}
182 LIBS ${hwasan_runtime}-${arch} ${hwasan_runtime}_cxx-${arch}
183 EXTRA hwasan.syms.extra)
184 set(VERSION_SCRIPT_FLAG
185 -Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/${hwasan_runtime}-dynamic-${arch}.vers)
187 ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp
189 OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${hwasan_runtime}-dynamic-${arch}.vers)
191 set(VERSION_SCRIPT_FLAG)
195 add_compiler_rt_runtime(${hwasan_runtime}
199 ${hwasan_object_dyn_lib}
202 RTSanitizerCommonLibc
203 RTSanitizerCommonCoverage
204 RTSanitizerCommonSymbolizer
205 RTSanitizerCommonSymbolizerInternal
209 # The only purpose of RTHWAsan_dynamic_version_script_dummy is to
210 # carry a dependency of the shared runtime on the version script.
211 # Replacing it with a straightforward
212 # add_dependencies(clang_rt.asan-dynamic-${arch} clang_rt.asan-dynamic-${arch}-version-list)
213 # generates an order-only dependency in ninja.
214 RTHwasan_dynamic_version_script_dummy
215 CFLAGS ${hwasan_dyn_flags}
216 LINK_FLAGS ${HWASAN_DYNAMIC_LINK_FLAGS}
217 ${VERSION_SCRIPT_FLAG}
218 LINK_LIBS ${HWASAN_DYNAMIC_LIBS}
219 DEFS ${ASAN_DYNAMIC_DEFINITIONS}
220 PARENT_TARGET hwasan)
222 if(SANITIZER_USE_SYMBOLS)
223 add_sanitizer_rt_symbols(${hwasan_runtime}
225 EXTRA hwasan.syms.extra)
226 add_sanitizer_rt_symbols(${hwasan_runtime}_cxx
228 EXTRA hwasan.syms.extra)
229 add_dependencies(hwasan ${hwasan_runtime}-${arch}-symbols
230 ${hwasan_runtime}_cxx-${arch}-symbols)
234 foreach(arch ${HWASAN_SUPPORTED_ARCH})
235 add_hwasan_runtimes(${arch} FALSE)
236 if(${arch} MATCHES "x86_64")
237 add_hwasan_runtimes(${arch} TRUE)
241 add_compiler_rt_runtime(clang_rt.hwasan-preinit
243 ARCHS ${HWASAN_SUPPORTED_ARCH}
244 OBJECT_LIBS RTHwasan_preinit
245 CFLAGS ${HWASAN_RTL_CFLAGS}
246 PARENT_TARGET hwasan)
248 add_compiler_rt_resource_file(hwasan_ignorelist hwasan_ignorelist.txt hwasan)
250 add_subdirectory("scripts")
252 # if(COMPILER_RT_INCLUDE_TESTS)
253 # add_subdirectory(tests)