1include_directories(..) 2 3# Runtime library sources and build flags. 4set(HWASAN_RTL_SOURCES 5 hwasan.cpp 6 hwasan_allocator.cpp 7 hwasan_allocation_functions.cpp 8 hwasan_dynamic_shadow.cpp 9 hwasan_exceptions.cpp 10 hwasan_fuchsia.cpp 11 hwasan_globals.cpp 12 hwasan_interceptors.cpp 13 hwasan_interceptors_vfork.S 14 hwasan_linux.cpp 15 hwasan_memintrinsics.cpp 16 hwasan_poisoning.cpp 17 hwasan_report.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 23 hwasan_thread.cpp 24 hwasan_thread_list.cpp 25 hwasan_type_test.cpp 26 ) 27 28set(HWASAN_RTL_CXX_SOURCES 29 hwasan_new_delete.cpp 30 ) 31 32set(HWASAN_RTL_PREINIT_SOURCES 33 hwasan_preinit.cpp 34 ) 35 36set(HWASAN_RTL_HEADERS 37 hwasan.h 38 hwasan_allocator.h 39 hwasan_dynamic_shadow.h 40 hwasan_flags.h 41 hwasan_flags.inc 42 hwasan_globals.h 43 hwasan_interface_internal.h 44 hwasan_malloc_bisect.h 45 hwasan_mapping.h 46 hwasan_poisoning.h 47 hwasan_report.h 48 hwasan_thread.h 49 hwasan_thread_list.h 50 ) 51 52set(HWASAN_DEFINITIONS) 53append_list_if(COMPILER_RT_HWASAN_WITH_INTERCEPTORS HWASAN_WITH_INTERCEPTORS=1 HWASAN_DEFINITIONS) 54 55if(FUCHSIA) 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) 58endif() 59 60set(HWASAN_RTL_CFLAGS ${SANITIZER_COMMON_CFLAGS}) 61append_rtti_flag(OFF HWASAN_RTL_CFLAGS) 62append_list_if(COMPILER_RT_HAS_FPIC_FLAG -fPIC HWASAN_RTL_CFLAGS) 63# Prevent clang from generating libc calls. 64append_list_if(COMPILER_RT_HAS_FFREESTANDING_FLAG -ffreestanding HWASAN_RTL_CFLAGS) 65 66# Too many existing bugs, needs cleanup. 67append_list_if(COMPILER_RT_HAS_WNO_FORMAT -Wno-format HWASAN_RTL_CFLAGS) 68 69set(HWASAN_DYNAMIC_LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS}) 70 71if(ANDROID) 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) 76 endif() 77endif() 78 79set(HWASAN_DYNAMIC_CFLAGS ${HWASAN_RTL_CFLAGS}) 80append_list_if(COMPILER_RT_HAS_FTLS_MODEL_INITIAL_EXEC 81 -ftls-model=initial-exec HWASAN_DYNAMIC_CFLAGS) 82append_list_if(MSVC /DEBUG HWASAN_DYNAMIC_LINK_FLAGS) 83 84set(HWASAN_DYNAMIC_LIBS 85 ${COMPILER_RT_UNWINDER_LINK_LIBS} 86 ${SANITIZER_CXX_ABI_LIBRARIES} 87 ${SANITIZER_COMMON_LINK_LIBS}) 88 89append_list_if(COMPILER_RT_HAS_LIBDL dl HWASAN_DYNAMIC_LIBS) 90append_list_if(COMPILER_RT_HAS_LIBRT rt HWASAN_DYNAMIC_LIBS) 91append_list_if(COMPILER_RT_HAS_LIBM m HWASAN_DYNAMIC_LIBS) 92append_list_if(COMPILER_RT_HAS_LIBPTHREAD pthread HWASAN_DYNAMIC_LIBS) 93 94# Static runtime library. 95add_compiler_rt_component(hwasan) 96 97add_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}) 103add_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}) 109add_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}) 115add_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}) 121 122file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp "") 123add_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}) 128 129# If use_aliases is TRUE, adds the HWASan runtime built with alias support. 130# Otherwise adds the runtime without alias support. 131function(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}) 137 if(use_aliases) 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 141 ARCHS ${arch} 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 147 ARCHS ${arch} 148 SOURCES ${HWASAN_RTL_SOURCES} ${HWASAN_RTL_CXX_SOURCES} 149 ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS} 150 CFLAGS ${hwasan_dyn_flags} 151 DEFS ${HWASAN_DEFINITIONS}) 152 153 set(hwasan_object_lib RTHwasanAliases) 154 set(hwasan_object_dyn_lib RTHwasanAliases_dynamic) 155 set(hwasan_runtime clang_rt.hwasan_aliases) 156 endif() 157 add_compiler_rt_runtime(${hwasan_runtime} 158 STATIC 159 ARCHS ${arch} 160 OBJECT_LIBS ${hwasan_object_lib} 161 RTHwasan_preinit 162 RTInterception 163 RTSanitizerCommon 164 RTSanitizerCommonLibc 165 RTSanitizerCommonCoverage 166 RTSanitizerCommonSymbolizer 167 RTLSanCommon 168 RTUbsan 169 CFLAGS ${hwasan_rtl_flags} 170 PARENT_TARGET hwasan) 171 add_compiler_rt_runtime(${hwasan_runtime}_cxx 172 STATIC 173 ARCHS ${arch} 174 OBJECT_LIBS RTHwasan_cxx 175 RTUbsan_cxx 176 CFLAGS ${hwasan_rtl_flags} 177 PARENT_TARGET hwasan) 178 179 if (UNIX) 180 add_sanitizer_rt_version_list(${hwasan_runtime}-dynamic-${arch} 181 LIBS ${hwasan_runtime}-${arch} ${hwasan_runtime}_cxx-${arch} 182 EXTRA hwasan.syms.extra) 183 set(VERSION_SCRIPT_FLAG 184 -Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/${hwasan_runtime}-dynamic-${arch}.vers) 185 set_property(SOURCE 186 ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp 187 APPEND PROPERTY 188 OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${hwasan_runtime}-dynamic-${arch}.vers) 189 else() 190 set(VERSION_SCRIPT_FLAG) 191 endif() 192 193 194 add_compiler_rt_runtime(${hwasan_runtime} 195 SHARED 196 ARCHS ${arch} 197 OBJECT_LIBS 198 ${hwasan_object_dyn_lib} 199 RTInterception 200 RTSanitizerCommon 201 RTSanitizerCommonLibc 202 RTSanitizerCommonCoverage 203 RTSanitizerCommonSymbolizer 204 RTLSanCommon 205 RTUbsan 206 RTUbsan_cxx 207 # The only purpose of RTHWAsan_dynamic_version_script_dummy is to 208 # carry a dependency of the shared runtime on the version script. 209 # Replacing it with a straightforward 210 # add_dependencies(clang_rt.asan-dynamic-${arch} clang_rt.asan-dynamic-${arch}-version-list) 211 # generates an order-only dependency in ninja. 212 RTHwasan_dynamic_version_script_dummy 213 CFLAGS ${hwasan_dyn_flags} 214 LINK_FLAGS ${HWASAN_DYNAMIC_LINK_FLAGS} 215 ${VERSION_SCRIPT_FLAG} 216 LINK_LIBS ${HWASAN_DYNAMIC_LIBS} 217 DEFS ${ASAN_DYNAMIC_DEFINITIONS} 218 PARENT_TARGET hwasan) 219 220 if(SANITIZER_USE_SYMBOLS) 221 add_sanitizer_rt_symbols(${hwasan_runtime} 222 ARCHS ${arch} 223 EXTRA hwasan.syms.extra) 224 add_sanitizer_rt_symbols(${hwasan_runtime}_cxx 225 ARCHS ${arch} 226 EXTRA hwasan.syms.extra) 227 add_dependencies(hwasan ${hwasan_runtime}-${arch}-symbols 228 ${hwasan_runtime}_cxx-${arch}-symbols) 229 endif() 230endfunction() 231 232foreach(arch ${HWASAN_SUPPORTED_ARCH}) 233 add_hwasan_runtimes(${arch} FALSE) 234 if(${arch} MATCHES "x86_64") 235 add_hwasan_runtimes(${arch} TRUE) 236 endif() 237endforeach() 238 239add_compiler_rt_runtime(clang_rt.hwasan-preinit 240 STATIC 241 ARCHS ${HWASAN_SUPPORTED_ARCH} 242 OBJECT_LIBS RTHwasan_preinit 243 CFLAGS ${HWASAN_RTL_CFLAGS} 244 PARENT_TARGET hwasan) 245 246add_compiler_rt_resource_file(hwasan_ignorelist hwasan_ignorelist.txt hwasan) 247 248add_subdirectory("scripts") 249 250# if(COMPILER_RT_INCLUDE_TESTS) 251# add_subdirectory(tests) 252# endif() 253