Chandler Carruth | d51e0a0 | 2012-04-04 22:12:04 +0000 | [diff] [blame] | 1 | # Build for the AddressSanitizer runtime support library. |
| 2 | |
Chandler Carruth | 479d47f | 2012-06-20 10:18:43 +0000 | [diff] [blame] | 3 | set(ASAN_SOURCES |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 4 | asan_allocator.cc |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 5 | asan_activation.cc |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 6 | asan_debugging.cc |
Kostya Serebryany | 2679f19 | 2012-12-10 14:19:15 +0000 | [diff] [blame] | 7 | asan_fake_stack.cc |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 8 | asan_flags.cc |
Chandler Carruth | 479d47f | 2012-06-20 10:18:43 +0000 | [diff] [blame] | 9 | asan_globals.cc |
| 10 | asan_interceptors.cc |
| 11 | asan_linux.cc |
| 12 | asan_mac.cc |
| 13 | asan_malloc_linux.cc |
| 14 | asan_malloc_mac.cc |
| 15 | asan_malloc_win.cc |
Chandler Carruth | 479d47f | 2012-06-20 10:18:43 +0000 | [diff] [blame] | 16 | asan_poisoning.cc |
| 17 | asan_posix.cc |
Alexey Samsonov | f7c1d18 | 2012-08-09 08:15:46 +0000 | [diff] [blame] | 18 | asan_report.cc |
Chandler Carruth | 479d47f | 2012-06-20 10:18:43 +0000 | [diff] [blame] | 19 | asan_rtl.cc |
| 20 | asan_stack.cc |
| 21 | asan_stats.cc |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 22 | asan_suppressions.cc |
Chandler Carruth | 479d47f | 2012-06-20 10:18:43 +0000 | [diff] [blame] | 23 | asan_thread.cc |
Alexey Samsonov | c3b30b3 | 2013-06-22 16:33:52 +0000 | [diff] [blame] | 24 | asan_win.cc) |
Chandler Carruth | d51e0a0 | 2012-04-04 22:12:04 +0000 | [diff] [blame] | 25 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 26 | set(ASAN_CXX_SOURCES |
| 27 | asan_new_delete.cc) |
| 28 | |
| 29 | set(ASAN_PREINIT_SOURCES |
| 30 | asan_preinit.cc) |
| 31 | |
Chandler Carruth | 821f21b | 2012-06-25 12:57:43 +0000 | [diff] [blame] | 32 | include_directories(..) |
| 33 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 34 | set(ASAN_CFLAGS ${SANITIZER_COMMON_CFLAGS}) |
| 35 | append_no_rtti_flag(ASAN_CFLAGS) |
| 36 | |
Alexey Samsonov | 2aed040 | 2013-01-21 08:24:19 +0000 | [diff] [blame] | 37 | set(ASAN_COMMON_DEFINITIONS |
Alexey Samsonov | 5e5be21 | 2013-01-22 07:21:24 +0000 | [diff] [blame] | 38 | ASAN_HAS_EXCEPTIONS=1) |
Alexey Samsonov | 2aed040 | 2013-01-21 08:24:19 +0000 | [diff] [blame] | 39 | |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 40 | set(ASAN_DYNAMIC_LINK_FLAGS) |
| 41 | |
Evgeniy Stepanov | 34fc56c | 2012-09-11 11:55:45 +0000 | [diff] [blame] | 42 | if(ANDROID) |
Alexey Samsonov | 2aed040 | 2013-01-21 08:24:19 +0000 | [diff] [blame] | 43 | list(APPEND ASAN_COMMON_DEFINITIONS |
Alexey Samsonov | 2aed040 | 2013-01-21 08:24:19 +0000 | [diff] [blame] | 44 | ASAN_LOW_MEMORY=1) |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 45 | # On Android, -z global does not do what it is documented to do. |
| 46 | # On Android, -z global moves the library ahead in the lookup order, |
| 47 | # placing it right after the LD_PRELOADs. This is used to compensate for the fact |
| 48 | # that Android linker does not look at the dependencies of the main executable |
| 49 | # that aren't dependencies of the current DSO when resolving symbols from said DSO. |
| 50 | # As a net result, this allows running ASan executables without LD_PRELOAD-ing the |
| 51 | # ASan runtime library. |
| 52 | # The above is applicable to L MR1 or newer. |
| 53 | if (COMPILER_RT_HAS_Z_GLOBAL) |
| 54 | list(APPEND ASAN_DYNAMIC_LINK_FLAGS -Wl,-z,global) |
| 55 | endif() |
Evgeniy Stepanov | 34fc56c | 2012-09-11 11:55:45 +0000 | [diff] [blame] | 56 | endif() |
Alexander Potapenko | 0ef5310 | 2012-08-17 09:00:08 +0000 | [diff] [blame] | 57 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 58 | set(ASAN_DYNAMIC_DEFINITIONS |
| 59 | ${ASAN_COMMON_DEFINITIONS} ASAN_DYNAMIC=1) |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 60 | append_list_if(WIN32 INTERCEPTION_DYNAMIC_CRT ASAN_DYNAMIC_DEFINITIONS) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 61 | |
| 62 | set(ASAN_DYNAMIC_CFLAGS ${ASAN_CFLAGS}) |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 63 | append_list_if(COMPILER_RT_HAS_FTLS_MODEL_INITIAL_EXEC |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 64 | -ftls-model=initial-exec ASAN_DYNAMIC_CFLAGS) |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 65 | append_list_if(MSVC /DEBUG ASAN_DYNAMIC_CFLAGS) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 66 | |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 67 | append_list_if(COMPILER_RT_HAS_LIBC c ASAN_DYNAMIC_LIBS) |
| 68 | append_list_if(COMPILER_RT_HAS_LIBDL dl ASAN_DYNAMIC_LIBS) |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 69 | append_list_if(COMPILER_RT_HAS_LIBRT rt ASAN_DYNAMIC_LIBS) |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 70 | append_list_if(COMPILER_RT_HAS_LIBM m ASAN_DYNAMIC_LIBS) |
| 71 | append_list_if(COMPILER_RT_HAS_LIBPTHREAD pthread ASAN_DYNAMIC_LIBS) |
| 72 | append_list_if(COMPILER_RT_HAS_LIBSTDCXX stdc++ ASAN_DYNAMIC_LIBS) |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 73 | append_list_if(COMPILER_RT_HAS_LIBLOG log ASAN_DYNAMIC_LIBS) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 74 | |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 75 | # Compile ASan sources into an object library. |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 76 | |
| 77 | add_compiler_rt_object_libraries(RTAsan_dynamic |
| 78 | OS ${SANITIZER_COMMON_SUPPORTED_OS} |
| 79 | ARCHS ${ASAN_SUPPORTED_ARCH} |
| 80 | SOURCES ${ASAN_SOURCES} ${ASAN_CXX_SOURCES} |
| 81 | CFLAGS ${ASAN_DYNAMIC_CFLAGS} |
| 82 | DEFS ${ASAN_DYNAMIC_DEFINITIONS}) |
| 83 | |
| 84 | if(NOT APPLE) |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 85 | add_compiler_rt_object_libraries(RTAsan |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 86 | ARCHS ${ASAN_SUPPORTED_ARCH} |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 87 | SOURCES ${ASAN_SOURCES} CFLAGS ${ASAN_CFLAGS} |
| 88 | DEFS ${ASAN_COMMON_DEFINITIONS}) |
| 89 | add_compiler_rt_object_libraries(RTAsan_cxx |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 90 | ARCHS ${ASAN_SUPPORTED_ARCH} |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 91 | SOURCES ${ASAN_CXX_SOURCES} CFLAGS ${ASAN_CFLAGS} |
| 92 | DEFS ${ASAN_COMMON_DEFINITIONS}) |
| 93 | add_compiler_rt_object_libraries(RTAsan_preinit |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 94 | ARCHS ${ASAN_SUPPORTED_ARCH} |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 95 | SOURCES ${ASAN_PREINIT_SOURCES} CFLAGS ${ASAN_CFLAGS} |
| 96 | DEFS ${ASAN_COMMON_DEFINITIONS}) |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 97 | |
| 98 | file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy.cc "") |
| 99 | add_compiler_rt_object_libraries(RTAsan_dynamic_version_script_dummy |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 100 | ARCHS ${ASAN_SUPPORTED_ARCH} |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 101 | SOURCES ${CMAKE_CURRENT_BINARY_DIR}/dummy.cc |
| 102 | CFLAGS ${ASAN_DYNAMIC_CFLAGS} |
| 103 | DEFS ${ASAN_DYNAMIC_DEFINITIONS}) |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 104 | endif() |
| 105 | |
| 106 | # Build ASan runtimes shipped with Clang. |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 107 | add_custom_target(asan) |
Alexey Samsonov | fe51abb | 2012-08-10 14:45:52 +0000 | [diff] [blame] | 108 | if(APPLE) |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 109 | add_compiler_rt_runtime(clang_rt.asan |
| 110 | SHARED |
| 111 | OS ${SANITIZER_COMMON_SUPPORTED_OS} |
| 112 | ARCHS ${ASAN_SUPPORTED_ARCH} |
| 113 | OBJECT_LIBS RTAsan_dynamic |
| 114 | RTInterception |
| 115 | RTSanitizerCommon |
| 116 | RTSanitizerCommonLibc |
| 117 | RTLSanCommon |
| 118 | RTUbsan |
| 119 | CFLAGS ${ASAN_DYNAMIC_CFLAGS} |
| 120 | DEFS ${ASAN_DYNAMIC_DEFINITIONS} |
| 121 | PARENT_TARGET asan) |
Alexey Samsonov | fe51abb | 2012-08-10 14:45:52 +0000 | [diff] [blame] | 122 | else() |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 123 | # Build separate libraries for each target. |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 124 | |
| 125 | set(ASAN_COMMON_RUNTIME_OBJECT_LIBS |
| 126 | RTInterception |
| 127 | RTSanitizerCommon |
| 128 | RTSanitizerCommonLibc |
| 129 | RTLSanCommon |
| 130 | RTUbsan) |
| 131 | |
| 132 | add_compiler_rt_runtime(clang_rt.asan |
| 133 | STATIC |
| 134 | ARCHS ${ASAN_SUPPORTED_ARCH} |
| 135 | OBJECT_LIBS RTAsan_preinit |
| 136 | RTAsan |
| 137 | ${ASAN_COMMON_RUNTIME_OBJECT_LIBS} |
| 138 | CFLAGS ${ASAN_CFLAGS} |
| 139 | DEFS ${ASAN_COMMON_DEFINITIONS} |
| 140 | PARENT_TARGET asan) |
| 141 | |
| 142 | add_compiler_rt_runtime(clang_rt.asan_cxx |
| 143 | STATIC |
| 144 | ARCHS ${ASAN_SUPPORTED_ARCH} |
| 145 | OBJECT_LIBS RTAsan_cxx |
| 146 | RTUbsan_cxx |
| 147 | CFLAGS ${ASAN_CFLAGS} |
| 148 | DEFS ${ASAN_COMMON_DEFINITIONS} |
| 149 | PARENT_TARGET asan) |
| 150 | |
| 151 | add_compiler_rt_runtime(clang_rt.asan-preinit |
| 152 | STATIC |
| 153 | ARCHS ${ASAN_SUPPORTED_ARCH} |
| 154 | OBJECT_LIBS RTAsan_preinit |
| 155 | CFLAGS ${ASAN_CFLAGS} |
| 156 | DEFS ${ASAN_COMMON_DEFINITIONS} |
| 157 | PARENT_TARGET asan) |
| 158 | |
Alexey Samsonov | 43b4b9c | 2013-01-18 16:51:07 +0000 | [diff] [blame] | 159 | foreach(arch ${ASAN_SUPPORTED_ARCH}) |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 160 | if (UNIX AND NOT ${arch} MATCHES "i386|i686") |
| 161 | add_sanitizer_rt_version_list(clang_rt.asan-dynamic-${arch} |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 162 | LIBS clang_rt.asan-${arch} clang_rt.asan_cxx-${arch} |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 163 | EXTRA asan.syms.extra) |
| 164 | set(VERSION_SCRIPT_FLAG |
| 165 | -Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/clang_rt.asan-dynamic-${arch}.vers) |
| 166 | set_source_files_properties( |
| 167 | ${CMAKE_CURRENT_BINARY_DIR}/dummy.cc |
| 168 | PROPERTIES |
| 169 | OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/clang_rt.asan-dynamic-${arch}.vers) |
| 170 | else() |
| 171 | set(VERSION_SCRIPT_FLAG) |
| 172 | endif() |
| 173 | |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 174 | add_compiler_rt_runtime(clang_rt.asan |
| 175 | SHARED |
| 176 | ARCHS ${arch} |
| 177 | OBJECT_LIBS ${ASAN_COMMON_RUNTIME_OBJECT_LIBS} |
| 178 | RTAsan_dynamic |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 179 | # The only purpose of RTAsan_dynamic_version_script_dummy is to carry |
| 180 | # a dependency of the shared runtime on the version script. With CMake |
| 181 | # 3.1 or later it can be replaced with a straightforward |
| 182 | # add_dependencies(clang_rt.asan-dynamic-${arch} clang_rt.asan-dynamic-${arch}-version-list) |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 183 | RTAsan_dynamic_version_script_dummy |
| 184 | RTUbsan_cxx |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 185 | CFLAGS ${ASAN_DYNAMIC_CFLAGS} |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 186 | LINKFLAGS ${ASAN_DYNAMIC_LINK_FLAGS} |
| 187 | ${VERSION_SCRIPT_FLAG} |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 188 | LINK_LIBS ${ASAN_DYNAMIC_LIBS} |
| 189 | DEFS ${ASAN_DYNAMIC_DEFINITIONS} |
| 190 | PARENT_TARGET asan) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 191 | |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 192 | if (UNIX AND NOT ${arch} MATCHES "i386|i686") |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 193 | add_sanitizer_rt_symbols(clang_rt.asan_cxx |
| 194 | ARCHS ${arch}) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 195 | add_dependencies(asan clang_rt.asan_cxx-${arch}-symbols) |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 196 | add_sanitizer_rt_symbols(clang_rt.asan |
| 197 | ARCHS ${arch} |
| 198 | EXTRA asan.syms.extra) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 199 | add_dependencies(asan clang_rt.asan-${arch}-symbols) |
Alexey Samsonov | 544bdfb | 2013-08-28 08:07:04 +0000 | [diff] [blame] | 200 | endif() |
Hans Wennborg | c1f1af7 | 2013-08-27 01:24:01 +0000 | [diff] [blame] | 201 | |
| 202 | if (WIN32) |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 203 | add_compiler_rt_runtime(clang_rt.asan_dll_thunk |
| 204 | STATIC |
| 205 | ARCHS ${arch} |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 206 | SOURCES asan_win_dll_thunk.cc |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 207 | $<TARGET_OBJECTS:RTInterception.${arch}> |
| 208 | CFLAGS ${ASAN_CFLAGS} -DASAN_DLL_THUNK |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 209 | DEFS ${ASAN_COMMON_DEFINITIONS} |
| 210 | PARENT_TARGET asan) |
| 211 | add_compiler_rt_runtime(clang_rt.asan_dynamic_runtime_thunk |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 212 | STATIC |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 213 | ARCHS ${arch} |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 214 | SOURCES asan_win_dynamic_runtime_thunk.cc |
| 215 | CFLAGS ${ASAN_CFLAGS} -DASAN_DYNAMIC_RUNTIME_THUNK -Zl |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 216 | DEFS ${ASAN_COMMON_DEFINITIONS} |
| 217 | PARENT_TARGET asan) |
Hans Wennborg | c1f1af7 | 2013-08-27 01:24:01 +0000 | [diff] [blame] | 218 | endif() |
Alexey Samsonov | 43b4b9c | 2013-01-18 16:51:07 +0000 | [diff] [blame] | 219 | endforeach() |
Alexey Samsonov | fe51abb | 2012-08-10 14:45:52 +0000 | [diff] [blame] | 220 | endif() |
Alexey Samsonov | 4d57f44 | 2012-07-25 11:15:00 +0000 | [diff] [blame] | 221 | |
Alexey Samsonov | c1caace | 2013-05-21 13:48:27 +0000 | [diff] [blame] | 222 | add_compiler_rt_resource_file(asan_blacklist asan_blacklist.txt) |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 223 | add_dependencies(asan asan_blacklist) |
| 224 | add_dependencies(compiler-rt asan) |
Alexey Samsonov | c1caace | 2013-05-21 13:48:27 +0000 | [diff] [blame] | 225 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 226 | add_subdirectory(scripts) |
Alexey Samsonov | 8c6e485 | 2013-11-14 12:24:12 +0000 | [diff] [blame] | 227 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 228 | if(COMPILER_RT_INCLUDE_TESTS) |
Chandler Carruth | 821f21b | 2012-06-25 12:57:43 +0000 | [diff] [blame] | 229 | add_subdirectory(tests) |
| 230 | endif() |