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_x86_64.S
20 hwasan_tag_mismatch_aarch64.S
22 hwasan_thread_list.cpp
26 set(HWASAN_RTL_CXX_SOURCES
30 set(HWASAN_RTL_PREINIT_SOURCES
34 set(HWASAN_RTL_HEADERS
37 hwasan_dynamic_shadow.h
41 hwasan_interface_internal.h
42 hwasan_malloc_bisect.h
50 set(HWASAN_DEFINITIONS)
51 append_list_if(COMPILER_RT_HWASAN_WITH_INTERCEPTORS HWASAN_WITH_INTERCEPTORS=1 HWASAN_DEFINITIONS)
54 # Set this explicitly on Fuchsia, otherwise the default value is set to HWASAN_WITH_INTERCEPTORS.
55 list(APPEND HWASAN_DEFINITIONS HWASAN_REPLACE_OPERATORS_NEW_AND_DELETE=1)
58 set(HWASAN_RTL_CFLAGS ${SANITIZER_COMMON_CFLAGS})
59 append_rtti_flag(OFF HWASAN_RTL_CFLAGS)
60 append_list_if(COMPILER_RT_HAS_FPIC_FLAG -fPIC HWASAN_RTL_CFLAGS)
61 # Prevent clang from generating libc calls.
62 append_list_if(COMPILER_RT_HAS_FFREESTANDING_FLAG -ffreestanding HWASAN_RTL_CFLAGS)
64 # Too many existing bugs, needs cleanup.
65 append_list_if(COMPILER_RT_HAS_WNO_FORMAT -Wno-format HWASAN_RTL_CFLAGS)
67 set(HWASAN_DYNAMIC_LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS})
70 # Put most Sanitizer shared libraries in the global group. For more details, see
71 # android-changes-for-ndk-developers.md#changes-to-library-search-order
72 if (COMPILER_RT_HAS_Z_GLOBAL)
73 list(APPEND HWASAN_DYNAMIC_LINK_FLAGS -Wl,-z,global)
77 set(HWASAN_DYNAMIC_CFLAGS ${HWASAN_RTL_CFLAGS})
78 append_list_if(COMPILER_RT_HAS_FTLS_MODEL_INITIAL_EXEC
79 -ftls-model=initial-exec HWASAN_DYNAMIC_CFLAGS)
80 append_list_if(MSVC /DEBUG HWASAN_DYNAMIC_LINK_FLAGS)
82 set(HWASAN_DYNAMIC_LIBS ${SANITIZER_CXX_ABI_LIBRARIES} ${SANITIZER_COMMON_LINK_LIBS})
84 append_list_if(COMPILER_RT_HAS_LIBDL dl HWASAN_DYNAMIC_LIBS)
85 append_list_if(COMPILER_RT_HAS_LIBRT rt HWASAN_DYNAMIC_LIBS)
86 append_list_if(COMPILER_RT_HAS_LIBM m HWASAN_DYNAMIC_LIBS)
87 append_list_if(COMPILER_RT_HAS_LIBPTHREAD pthread HWASAN_DYNAMIC_LIBS)
89 # Static runtime library.
90 add_compiler_rt_component(hwasan)
92 add_compiler_rt_object_libraries(RTHwasan
93 ARCHS ${HWASAN_SUPPORTED_ARCH}
94 SOURCES ${HWASAN_RTL_SOURCES}
95 ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS}
96 CFLAGS ${HWASAN_RTL_CFLAGS}
97 DEFS ${HWASAN_DEFINITIONS})
98 add_compiler_rt_object_libraries(RTHwasan_cxx
99 ARCHS ${HWASAN_SUPPORTED_ARCH}
100 SOURCES ${HWASAN_RTL_CXX_SOURCES}
101 ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS}
102 CFLAGS ${HWASAN_RTL_CFLAGS}
103 DEFS ${HWASAN_DEFINITIONS})
104 add_compiler_rt_object_libraries(RTHwasan_dynamic
105 ARCHS ${HWASAN_SUPPORTED_ARCH}
106 SOURCES ${HWASAN_RTL_SOURCES} ${HWASAN_RTL_CXX_SOURCES}
107 ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS}
108 CFLAGS ${HWASAN_DYNAMIC_CFLAGS}
109 DEFS ${HWASAN_DEFINITIONS})
110 add_compiler_rt_object_libraries(RTHwasan_preinit
111 ARCHS ${HWASAN_SUPPORTED_ARCH}
112 SOURCES ${HWASAN_RTL_PREINIT_SOURCES}
113 ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS}
114 CFLAGS ${HWASAN_RTL_CFLAGS}
115 DEFS ${HWASAN_DEFINITIONS})
117 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp "")
118 add_compiler_rt_object_libraries(RTHwasan_dynamic_version_script_dummy
119 ARCHS ${HWASAN_SUPPORTED_ARCH}
120 SOURCES ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp
121 CFLAGS ${HWASAN_DYNAMIC_CFLAGS}
122 DEFS ${HWASAN_DEFINITIONS})
124 # If use_aliases is TRUE, adds the HWASan runtime built with alias support.
125 # Otherwise adds the runtime without alias support.
126 function(add_hwasan_runtimes arch use_aliases)
127 set(hwasan_object_lib RTHwasan)
128 set(hwasan_object_dyn_lib RTHwasan_dynamic)
129 set(hwasan_runtime clang_rt.hwasan)
130 set(hwasan_rtl_flags ${HWASAN_RTL_CFLAGS})
131 set(hwasan_dyn_flags ${HWASAN_DYNAMIC_CFLAGS})
133 list(APPEND hwasan_rtl_flags -DHWASAN_ALIASING_MODE)
134 list(APPEND hwasan_dyn_flags -DHWASAN_ALIASING_MODE)
135 add_compiler_rt_object_libraries(RTHwasanAliases
137 SOURCES ${HWASAN_RTL_SOURCES}
138 ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS}
139 CFLAGS ${hwasan_rtl_flags}
140 DEFS ${HWASAN_DEFINITIONS})
141 add_compiler_rt_object_libraries(RTHwasanAliases_dynamic
143 SOURCES ${HWASAN_RTL_SOURCES} ${HWASAN_RTL_CXX_SOURCES}
144 ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS}
145 CFLAGS ${hwasan_dyn_flags}
146 DEFS ${HWASAN_DEFINITIONS})
148 set(hwasan_object_lib RTHwasanAliases)
149 set(hwasan_object_dyn_lib RTHwasanAliases_dynamic)
150 set(hwasan_runtime clang_rt.hwasan_aliases)
152 add_compiler_rt_runtime(${hwasan_runtime}
155 OBJECT_LIBS ${hwasan_object_lib}
159 RTSanitizerCommonLibc
160 RTSanitizerCommonCoverage
161 RTSanitizerCommonSymbolizer
163 CFLAGS ${hwasan_rtl_flags}
164 PARENT_TARGET hwasan)
165 add_compiler_rt_runtime(${hwasan_runtime}_cxx
168 OBJECT_LIBS RTHwasan_cxx
170 CFLAGS ${hwasan_rtl_flags}
171 PARENT_TARGET hwasan)
174 add_sanitizer_rt_version_list(${hwasan_runtime}-dynamic-${arch}
175 LIBS ${hwasan_runtime}-${arch} ${hwasan_runtime}_cxx-${arch}
176 EXTRA hwasan.syms.extra)
177 set(VERSION_SCRIPT_FLAG
178 -Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/${hwasan_runtime}-dynamic-${arch}.vers)
180 ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp
182 OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${hwasan_runtime}-dynamic-${arch}.vers)
184 set(VERSION_SCRIPT_FLAG)
188 add_compiler_rt_runtime(${hwasan_runtime}
192 ${hwasan_object_dyn_lib}
195 RTSanitizerCommonLibc
196 RTSanitizerCommonCoverage
197 RTSanitizerCommonSymbolizer
200 # The only purpose of RTHWAsan_dynamic_version_script_dummy is to
201 # carry a dependency of the shared runtime on the version script.
202 # Replacing it with a straightforward
203 # add_dependencies(clang_rt.asan-dynamic-${arch} clang_rt.asan-dynamic-${arch}-version-list)
204 # generates an order-only dependency in ninja.
205 RTHwasan_dynamic_version_script_dummy
206 CFLAGS ${hwasan_dyn_flags}
207 LINK_FLAGS ${HWASAN_DYNAMIC_LINK_FLAGS}
208 ${VERSION_SCRIPT_FLAG}
209 LINK_LIBS ${HWASAN_DYNAMIC_LIBS}
210 DEFS ${ASAN_DYNAMIC_DEFINITIONS}
211 PARENT_TARGET hwasan)
213 if(SANITIZER_USE_SYMBOLS)
214 add_sanitizer_rt_symbols(${hwasan_runtime}
216 EXTRA hwasan.syms.extra)
217 add_sanitizer_rt_symbols(${hwasan_runtime}_cxx
219 EXTRA hwasan.syms.extra)
220 add_dependencies(hwasan ${hwasan_runtime}-${arch}-symbols
221 ${hwasan_runtime}_cxx-${arch}-symbols)
225 foreach(arch ${HWASAN_SUPPORTED_ARCH})
226 add_hwasan_runtimes(${arch} FALSE)
227 if(${arch} MATCHES "x86_64")
228 add_hwasan_runtimes(${arch} TRUE)
232 add_compiler_rt_runtime(clang_rt.hwasan-preinit
234 ARCHS ${HWASAN_SUPPORTED_ARCH}
235 OBJECT_LIBS RTHwasan_preinit
236 CFLAGS ${HWASAN_RTL_CFLAGS}
237 PARENT_TARGET hwasan)
239 add_compiler_rt_resource_file(hwasan_ignorelist hwasan_ignorelist.txt hwasan)
241 add_subdirectory("scripts")
243 # if(COMPILER_RT_INCLUDE_TESTS)
244 # add_subdirectory(tests)