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.S 19 hwasan_tag_mismatch_aarch64.S 20 hwasan_thread.cpp 21 hwasan_thread_list.cpp 22 hwasan_type_test.cpp 23 ) 24 25set(HWASAN_RTL_CXX_SOURCES 26 hwasan_new_delete.cpp 27 ) 28 29set(HWASAN_RTL_HEADERS 30 hwasan.h 31 hwasan_allocator.h 32 hwasan_dynamic_shadow.h 33 hwasan_flags.h 34 hwasan_flags.inc 35 hwasan_globals.h 36 hwasan_interface_internal.h 37 hwasan_malloc_bisect.h 38 hwasan_mapping.h 39 hwasan_poisoning.h 40 hwasan_report.h 41 hwasan_thread.h 42 hwasan_thread_list.h 43 ) 44 45set(HWASAN_DEFINITIONS) 46append_list_if(COMPILER_RT_HWASAN_WITH_INTERCEPTORS HWASAN_WITH_INTERCEPTORS=1 HWASAN_DEFINITIONS) 47 48if(FUCHSIA) 49 # Set this explicitly on Fuchsia, otherwise the default value is set to HWASAN_WITH_INTERCEPTORS. 50 list(APPEND HWASAN_DEFINITIONS HWASAN_REPLACE_OPERATORS_NEW_AND_DELETE=1) 51endif() 52 53set(HWASAN_RTL_CFLAGS ${SANITIZER_COMMON_CFLAGS}) 54append_rtti_flag(OFF HWASAN_RTL_CFLAGS) 55append_list_if(COMPILER_RT_HAS_FPIC_FLAG -fPIC HWASAN_RTL_CFLAGS) 56# Prevent clang from generating libc calls. 57append_list_if(COMPILER_RT_HAS_FFREESTANDING_FLAG -ffreestanding HWASAN_RTL_CFLAGS) 58 59set(HWASAN_DYNAMIC_LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS}) 60 61if(ANDROID) 62# Put most Sanitizer shared libraries in the global group. For more details, see 63# android-changes-for-ndk-developers.md#changes-to-library-search-order 64 if (COMPILER_RT_HAS_Z_GLOBAL) 65 list(APPEND HWASAN_DYNAMIC_LINK_FLAGS -Wl,-z,global) 66 endif() 67endif() 68 69set(HWASAN_DYNAMIC_CFLAGS ${HWASAN_RTL_CFLAGS}) 70append_list_if(COMPILER_RT_HAS_FTLS_MODEL_INITIAL_EXEC 71 -ftls-model=initial-exec HWASAN_DYNAMIC_CFLAGS) 72append_list_if(MSVC /DEBUG HWASAN_DYNAMIC_LINK_FLAGS) 73 74set(HWASAN_DYNAMIC_LIBS ${SANITIZER_CXX_ABI_LIBRARIES} ${SANITIZER_COMMON_LINK_LIBS}) 75 76append_list_if(COMPILER_RT_HAS_LIBDL dl HWASAN_DYNAMIC_LIBS) 77append_list_if(COMPILER_RT_HAS_LIBRT rt HWASAN_DYNAMIC_LIBS) 78append_list_if(COMPILER_RT_HAS_LIBM m HWASAN_DYNAMIC_LIBS) 79append_list_if(COMPILER_RT_HAS_LIBPTHREAD pthread HWASAN_DYNAMIC_LIBS) 80 81# Static runtime library. 82add_compiler_rt_component(hwasan) 83 84add_compiler_rt_object_libraries(RTHwasan 85 ARCHS ${HWASAN_SUPPORTED_ARCH} 86 SOURCES ${HWASAN_RTL_SOURCES} 87 ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS} 88 CFLAGS ${HWASAN_RTL_CFLAGS} 89 DEFS ${HWASAN_DEFINITIONS}) 90add_compiler_rt_object_libraries(RTHwasan_cxx 91 ARCHS ${HWASAN_SUPPORTED_ARCH} 92 SOURCES ${HWASAN_RTL_CXX_SOURCES} 93 ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS} 94 CFLAGS ${HWASAN_RTL_CFLAGS} 95 DEFS ${HWASAN_DEFINITIONS}) 96add_compiler_rt_object_libraries(RTHwasan_dynamic 97 ARCHS ${HWASAN_SUPPORTED_ARCH} 98 SOURCES ${HWASAN_RTL_SOURCES} ${HWASAN_RTL_CXX_SOURCES} 99 ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS} 100 CFLAGS ${HWASAN_DYNAMIC_CFLAGS} 101 DEFS ${HWASAN_DEFINITIONS}) 102 103file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp "") 104add_compiler_rt_object_libraries(RTHwasan_dynamic_version_script_dummy 105 ARCHS ${HWASAN_SUPPORTED_ARCH} 106 SOURCES ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp 107 CFLAGS ${HWASAN_DYNAMIC_CFLAGS} 108 DEFS ${HWASAN_DEFINITIONS}) 109 110# If use_aliases is TRUE, adds the HWASan runtime built with alias support. 111# Otherwise adds the runtime without alias support. 112function(add_hwasan_runtimes arch use_aliases) 113 set(hwasan_object_lib RTHwasan) 114 set(hwasan_object_dyn_lib RTHwasan_dynamic) 115 set(hwasan_runtime clang_rt.hwasan) 116 set(hwasan_rtl_flags ${HWASAN_RTL_CFLAGS}) 117 set(hwasan_dyn_flags ${HWASAN_DYNAMIC_CFLAGS}) 118 if(use_aliases) 119 list(APPEND hwasan_rtl_flags -DHWASAN_ALIASING_MODE) 120 list(APPEND hwasan_dyn_flags -DHWASAN_ALIASING_MODE) 121 add_compiler_rt_object_libraries(RTHwasanAliases 122 ARCHS ${arch} 123 SOURCES ${HWASAN_RTL_SOURCES} 124 ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS} 125 CFLAGS ${hwasan_rtl_flags} 126 DEFS ${HWASAN_DEFINITIONS}) 127 add_compiler_rt_object_libraries(RTHwasanAliases_dynamic 128 ARCHS ${arch} 129 SOURCES ${HWASAN_RTL_SOURCES} ${HWASAN_RTL_CXX_SOURCES} 130 ADDITIONAL_HEADERS ${HWASAN_RTL_HEADERS} 131 CFLAGS ${hwasan_dyn_flags} 132 DEFS ${HWASAN_DEFINITIONS}) 133 134 set(hwasan_object_lib RTHwasanAliases) 135 set(hwasan_object_dyn_lib RTHwasanAliases_dynamic) 136 set(hwasan_runtime clang_rt.hwasan_aliases) 137 endif() 138 add_compiler_rt_runtime(${hwasan_runtime} 139 STATIC 140 ARCHS ${arch} 141 OBJECT_LIBS ${hwasan_object_lib} 142 RTInterception 143 RTSanitizerCommon 144 RTSanitizerCommonLibc 145 RTSanitizerCommonCoverage 146 RTSanitizerCommonSymbolizer 147 RTUbsan 148 CFLAGS ${hwasan_rtl_flags} 149 PARENT_TARGET hwasan) 150 add_compiler_rt_runtime(${hwasan_runtime}_cxx 151 STATIC 152 ARCHS ${arch} 153 OBJECT_LIBS RTHwasan_cxx 154 RTUbsan_cxx 155 CFLAGS ${hwasan_rtl_flags} 156 PARENT_TARGET hwasan) 157 158 if (UNIX) 159 add_sanitizer_rt_version_list(${hwasan_runtime}-dynamic-${arch} 160 LIBS ${hwasan_runtime}-${arch} ${hwasan_runtime}_cxx-${arch} 161 EXTRA hwasan.syms.extra) 162 set(VERSION_SCRIPT_FLAG 163 -Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/${hwasan_runtime}-dynamic-${arch}.vers) 164 set_property(SOURCE 165 ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp 166 APPEND PROPERTY 167 OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${hwasan_runtime}-dynamic-${arch}.vers) 168 else() 169 set(VERSION_SCRIPT_FLAG) 170 endif() 171 172 173 add_compiler_rt_runtime(${hwasan_runtime} 174 SHARED 175 ARCHS ${arch} 176 OBJECT_LIBS 177 ${hwasan_object_dyn_lib} 178 RTInterception 179 RTSanitizerCommon 180 RTSanitizerCommonLibc 181 RTSanitizerCommonCoverage 182 RTSanitizerCommonSymbolizer 183 RTUbsan 184 RTUbsan_cxx 185 # The only purpose of RTHWAsan_dynamic_version_script_dummy is to 186 # carry a dependency of the shared runtime on the version script. 187 # Replacing it with a straightforward 188 # add_dependencies(clang_rt.asan-dynamic-${arch} clang_rt.asan-dynamic-${arch}-version-list) 189 # generates an order-only dependency in ninja. 190 RTHwasan_dynamic_version_script_dummy 191 CFLAGS ${hwasan_dyn_flags} 192 LINK_FLAGS ${HWASAN_DYNAMIC_LINK_FLAGS} 193 ${VERSION_SCRIPT_FLAG} 194 LINK_LIBS ${HWASAN_DYNAMIC_LIBS} 195 DEFS ${ASAN_DYNAMIC_DEFINITIONS} 196 PARENT_TARGET hwasan) 197 198 if(SANITIZER_USE_SYMBOLS) 199 add_sanitizer_rt_symbols(${hwasan_runtime} 200 ARCHS ${arch} 201 EXTRA hwasan.syms.extra) 202 add_sanitizer_rt_symbols(${hwasan_runtime}_cxx 203 ARCHS ${arch} 204 EXTRA hwasan.syms.extra) 205 add_dependencies(hwasan ${hwasan_runtime}-${arch}-symbols 206 ${hwasan_runtime}_cxx-${arch}-symbols) 207 endif() 208endfunction() 209 210foreach(arch ${HWASAN_SUPPORTED_ARCH}) 211 add_hwasan_runtimes(${arch} FALSE) 212 if(${arch} MATCHES "x86_64") 213 add_hwasan_runtimes(${arch} TRUE) 214 endif() 215endforeach() 216 217add_compiler_rt_resource_file(hwasan_ignorelist hwasan_ignorelist.txt hwasan) 218 219add_subdirectory("scripts") 220 221# if(COMPILER_RT_INCLUDE_TESTS) 222# add_subdirectory(tests) 223# endif() 224