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 |
Kostya Serebryany | 8b0a7ce | 2012-12-10 13:52:55 +0000 | [diff] [blame] | 4 | asan_allocator2.cc |
Kostya Serebryany | 2679f19 | 2012-12-10 14:19:15 +0000 | [diff] [blame] | 5 | asan_fake_stack.cc |
Chandler Carruth | 479d47f | 2012-06-20 10:18:43 +0000 | [diff] [blame] | 6 | asan_globals.cc |
| 7 | asan_interceptors.cc |
| 8 | asan_linux.cc |
| 9 | asan_mac.cc |
| 10 | asan_malloc_linux.cc |
| 11 | asan_malloc_mac.cc |
| 12 | asan_malloc_win.cc |
| 13 | asan_new_delete.cc |
| 14 | asan_poisoning.cc |
| 15 | asan_posix.cc |
Kostya Serebryany | 33934ff | 2013-02-22 07:51:26 +0000 | [diff] [blame] | 16 | asan_preinit.cc |
Alexey Samsonov | f7c1d18 | 2012-08-09 08:15:46 +0000 | [diff] [blame] | 17 | asan_report.cc |
Chandler Carruth | 479d47f | 2012-06-20 10:18:43 +0000 | [diff] [blame] | 18 | asan_rtl.cc |
| 19 | asan_stack.cc |
| 20 | asan_stats.cc |
| 21 | asan_thread.cc |
Alexey Samsonov | c3b30b3 | 2013-06-22 16:33:52 +0000 | [diff] [blame] | 22 | asan_win.cc) |
Chandler Carruth | d51e0a0 | 2012-04-04 22:12:04 +0000 | [diff] [blame] | 23 | |
Chandler Carruth | 821f21b | 2012-06-25 12:57:43 +0000 | [diff] [blame] | 24 | include_directories(..) |
| 25 | |
Hans Wennborg | c1f1af7 | 2013-08-27 01:24:01 +0000 | [diff] [blame] | 26 | if (NOT MSVC) |
| 27 | set(ASAN_CFLAGS |
| 28 | ${SANITIZER_COMMON_CFLAGS} |
| 29 | -fno-rtti) |
| 30 | else() |
| 31 | set(ASAN_CFLAGS |
| 32 | ${SANITIZER_COMMON_CFLAGS} |
| 33 | /GR-) |
| 34 | endif() |
Alexey Samsonov | 0f7d4a4 | 2012-09-05 09:00:03 +0000 | [diff] [blame] | 35 | |
Alexey Samsonov | 2aed040 | 2013-01-21 08:24:19 +0000 | [diff] [blame] | 36 | set(ASAN_COMMON_DEFINITIONS |
Alexey Samsonov | 5e5be21 | 2013-01-22 07:21:24 +0000 | [diff] [blame] | 37 | ASAN_HAS_EXCEPTIONS=1) |
Alexey Samsonov | 2aed040 | 2013-01-21 08:24:19 +0000 | [diff] [blame] | 38 | |
Evgeniy Stepanov | 34fc56c | 2012-09-11 11:55:45 +0000 | [diff] [blame] | 39 | if(ANDROID) |
Alexey Samsonov | 2aed040 | 2013-01-21 08:24:19 +0000 | [diff] [blame] | 40 | list(APPEND ASAN_COMMON_DEFINITIONS |
Alexey Samsonov | 5e5be21 | 2013-01-22 07:21:24 +0000 | [diff] [blame] | 41 | ASAN_FLEXIBLE_MAPPING_AND_OFFSET=0 |
Evgeniy Stepanov | 34fc56c | 2012-09-11 11:55:45 +0000 | [diff] [blame] | 42 | ASAN_NEEDS_SEGV=0 |
Alexey Samsonov | 2aed040 | 2013-01-21 08:24:19 +0000 | [diff] [blame] | 43 | ASAN_LOW_MEMORY=1) |
Hans Wennborg | c1f1af7 | 2013-08-27 01:24:01 +0000 | [diff] [blame] | 44 | elseif(MSVC) |
| 45 | list(APPEND ASAN_COMMON_DEFINITIONS |
| 46 | ASAN_FLEXIBLE_MAPPING_AND_OFFSET=0 |
| 47 | ASAN_NEEDS_SEGV=0) |
Evgeniy Stepanov | 34fc56c | 2012-09-11 11:55:45 +0000 | [diff] [blame] | 48 | else() |
Alexey Samsonov | 2aed040 | 2013-01-21 08:24:19 +0000 | [diff] [blame] | 49 | list(APPEND ASAN_COMMON_DEFINITIONS |
Alexey Samsonov | 5e5be21 | 2013-01-22 07:21:24 +0000 | [diff] [blame] | 50 | ASAN_FLEXIBLE_MAPPING_AND_OFFSET=1 |
Alexey Samsonov | 2aed040 | 2013-01-21 08:24:19 +0000 | [diff] [blame] | 51 | ASAN_NEEDS_SEGV=1) |
Evgeniy Stepanov | 34fc56c | 2012-09-11 11:55:45 +0000 | [diff] [blame] | 52 | endif() |
Alexander Potapenko | 0ef5310 | 2012-08-17 09:00:08 +0000 | [diff] [blame] | 53 | |
Alexey Samsonov | 43b4b9c | 2013-01-18 16:51:07 +0000 | [diff] [blame] | 54 | # Architectures supported by ASan. |
| 55 | filter_available_targets(ASAN_SUPPORTED_ARCH |
Alexey Samsonov | b957d9f | 2013-06-07 09:44:43 +0000 | [diff] [blame] | 56 | x86_64 i386 powerpc64) |
Alexey Samsonov | 43b4b9c | 2013-01-18 16:51:07 +0000 | [diff] [blame] | 57 | |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 58 | # Compile ASan sources into an object library. |
| 59 | if(APPLE) |
Alexander Potapenko | 4949674 | 2013-11-07 10:08:19 +0000 | [diff] [blame] | 60 | foreach(os ${SANITIZER_COMMON_SUPPORTED_DARWIN_OS}) |
| 61 | add_compiler_rt_darwin_object_library(RTAsan ${os} |
| 62 | ARCH ${ASAN_SUPPORTED_ARCH} |
| 63 | SOURCES ${ASAN_SOURCES} |
| 64 | CFLAGS ${ASAN_CFLAGS} |
| 65 | DEFS ${ASAN_COMMON_DEFINITIONS}) |
| 66 | endforeach() |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 67 | elseif(ANDROID) |
| 68 | add_library(RTAsan.arm.android OBJECT ${ASAN_SOURCES}) |
| 69 | set_target_compile_flags(RTAsan.arm.android ${ASAN_CFLAGS}) |
| 70 | set_property(TARGET RTAsan.arm.android APPEND PROPERTY |
| 71 | COMPILE_DEFINITIONS ${ASAN_COMMON_DEFINITIONS}) |
| 72 | else() |
| 73 | foreach(arch ${ASAN_SUPPORTED_ARCH}) |
| 74 | add_compiler_rt_object_library(RTAsan ${arch} |
| 75 | SOURCES ${ASAN_SOURCES} CFLAGS ${ASAN_CFLAGS} |
| 76 | DEFS ${ASAN_COMMON_DEFINITIONS}) |
| 77 | endforeach() |
| 78 | endif() |
| 79 | |
| 80 | # Build ASan runtimes shipped with Clang. |
Alexey Samsonov | fe51abb | 2012-08-10 14:45:52 +0000 | [diff] [blame] | 81 | set(ASAN_RUNTIME_LIBRARIES) |
| 82 | if(APPLE) |
Alexander Potapenko | 4949674 | 2013-11-07 10:08:19 +0000 | [diff] [blame] | 83 | foreach (os ${SANITIZER_COMMON_SUPPORTED_DARWIN_OS}) |
Alexander Potapenko | eba4803 | 2013-01-22 09:14:54 +0000 | [diff] [blame] | 84 | # Dynamic lookup is needed because shadow scale and offset are |
| 85 | # provided by the instrumented modules. |
Alexander Potapenko | 4949674 | 2013-11-07 10:08:19 +0000 | [diff] [blame] | 86 | set(ASAN_RUNTIME_LDFLAGS |
| 87 | "-undefined dynamic_lookup") |
Alexander Potapenko | 4949674 | 2013-11-07 10:08:19 +0000 | [diff] [blame] | 88 | add_compiler_rt_darwin_dynamic_runtime(clang_rt.asan_${os}_dynamic ${os} |
| 89 | ARCH ${ASAN_SUPPORTED_ARCH} |
| 90 | SOURCES $<TARGET_OBJECTS:RTAsan.${os}> |
| 91 | $<TARGET_OBJECTS:RTInterception.${os}> |
| 92 | $<TARGET_OBJECTS:RTSanitizerCommon.${os}> |
| 93 | $<TARGET_OBJECTS:RTLSanCommon.${os}> |
| 94 | CFLAGS ${ASAN_CFLAGS} |
| 95 | DEFS ${ASAN_COMMON_DEFINITIONS} |
| 96 | LINKFLAGS ${ASAN_RUNTIME_LDFLAGS}) |
| 97 | list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan_${os}_dynamic) |
| 98 | endforeach() |
| 99 | |
Evgeniy Stepanov | 34fc56c | 2012-09-11 11:55:45 +0000 | [diff] [blame] | 100 | elseif(ANDROID) |
| 101 | add_library(clang_rt.asan-arm-android SHARED |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 102 | $<TARGET_OBJECTS:RTAsan.arm.android> |
Evgeniy Stepanov | 34fc56c | 2012-09-11 11:55:45 +0000 | [diff] [blame] | 103 | $<TARGET_OBJECTS:RTInterception.arm.android> |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 104 | $<TARGET_OBJECTS:RTSanitizerCommon.arm.android>) |
Evgeniy Stepanov | 34fc56c | 2012-09-11 11:55:45 +0000 | [diff] [blame] | 105 | set_target_compile_flags(clang_rt.asan-arm-android |
Alexey Samsonov | 2aad7c1 | 2013-01-21 08:12:20 +0000 | [diff] [blame] | 106 | ${ASAN_CFLAGS}) |
| 107 | set_property(TARGET clang_rt.asan-arm-android APPEND PROPERTY |
| 108 | COMPILE_DEFINITIONS ${ASAN_COMMON_DEFINITIONS}) |
Evgeniy Stepanov | 34fc56c | 2012-09-11 11:55:45 +0000 | [diff] [blame] | 109 | target_link_libraries(clang_rt.asan-arm-android dl) |
| 110 | list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-arm-android) |
Alexey Samsonov | fe51abb | 2012-08-10 14:45:52 +0000 | [diff] [blame] | 111 | else() |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 112 | # Build separate libraries for each target. |
Alexey Samsonov | 43b4b9c | 2013-01-18 16:51:07 +0000 | [diff] [blame] | 113 | foreach(arch ${ASAN_SUPPORTED_ARCH}) |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 114 | set(ASAN_RUNTIME_OBJECTS |
| 115 | $<TARGET_OBJECTS:RTAsan.${arch}> |
Hans Wennborg | c1f1af7 | 2013-08-27 01:24:01 +0000 | [diff] [blame] | 116 | $<TARGET_OBJECTS:RTInterception.${arch}> |
| 117 | $<TARGET_OBJECTS:RTSanitizerCommon.${arch}> |
| 118 | $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>) |
Alexey Samsonov | 3125de9 | 2013-11-17 10:12:23 +0000 | [diff] [blame] | 119 | if (NOT WIN32) |
Hans Wennborg | c1f1af7 | 2013-08-27 01:24:01 +0000 | [diff] [blame] | 120 | # We can't build Leak Sanitizer on Windows yet. |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 121 | list(APPEND ASAN_RUNTIME_OBJECTS $<TARGET_OBJECTS:RTLSanCommon.${arch}>) |
Hans Wennborg | c1f1af7 | 2013-08-27 01:24:01 +0000 | [diff] [blame] | 122 | endif() |
| 123 | |
Alexey Samsonov | 2aad7c1 | 2013-01-21 08:12:20 +0000 | [diff] [blame] | 124 | add_compiler_rt_static_runtime(clang_rt.asan-${arch} ${arch} |
Alexey Samsonov | 05fa380 | 2013-09-16 15:50:53 +0000 | [diff] [blame] | 125 | SOURCES ${ASAN_RUNTIME_OBJECTS} |
Alexey Samsonov | 2aad7c1 | 2013-01-21 08:12:20 +0000 | [diff] [blame] | 126 | CFLAGS ${ASAN_CFLAGS} |
Alexey Samsonov | e5fa243 | 2013-08-27 15:08:02 +0000 | [diff] [blame] | 127 | DEFS ${ASAN_COMMON_DEFINITIONS}) |
Alexey Samsonov | 544bdfb | 2013-08-28 08:07:04 +0000 | [diff] [blame] | 128 | list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-${arch}) |
| 129 | if (UNIX AND NOT ${arch} STREQUAL "i386") |
| 130 | add_sanitizer_rt_symbols(clang_rt.asan-${arch} asan.syms.extra) |
| 131 | list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-${arch}-symbols) |
| 132 | endif() |
Hans Wennborg | c1f1af7 | 2013-08-27 01:24:01 +0000 | [diff] [blame] | 133 | |
| 134 | if (WIN32) |
| 135 | add_compiler_rt_static_runtime(clang_rt.asan_dll_thunk-${arch} ${arch} |
| 136 | SOURCES asan_dll_thunk.cc |
| 137 | CFLAGS ${ASAN_CFLAGS} -DASAN_DLL_THUNK |
Alexey Samsonov | e5fa243 | 2013-08-27 15:08:02 +0000 | [diff] [blame] | 138 | DEFS ${ASAN_COMMON_DEFINITIONS}) |
Hans Wennborg | c1f1af7 | 2013-08-27 01:24:01 +0000 | [diff] [blame] | 139 | list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan_dll_thunk-${arch}) |
| 140 | endif() |
Alexey Samsonov | 43b4b9c | 2013-01-18 16:51:07 +0000 | [diff] [blame] | 141 | endforeach() |
Alexey Samsonov | fe51abb | 2012-08-10 14:45:52 +0000 | [diff] [blame] | 142 | endif() |
Alexey Samsonov | 4d57f44 | 2012-07-25 11:15:00 +0000 | [diff] [blame] | 143 | |
Alexey Samsonov | c1caace | 2013-05-21 13:48:27 +0000 | [diff] [blame] | 144 | add_compiler_rt_resource_file(asan_blacklist asan_blacklist.txt) |
| 145 | |
Alexey Samsonov | 8c6e485 | 2013-11-14 12:24:12 +0000 | [diff] [blame] | 146 | # All ASan runtime dependencies. |
| 147 | add_custom_target(asan_runtime_libraries |
| 148 | DEPENDS asan_blacklist ${ASAN_RUNTIME_LIBRARIES}) |
| 149 | |
Chandler Carruth | 821f21b | 2012-06-25 12:57:43 +0000 | [diff] [blame] | 150 | if(LLVM_INCLUDE_TESTS) |
| 151 | add_subdirectory(tests) |
| 152 | endif() |
Alexey Samsonov | 7274ff8 | 2012-07-31 15:43:11 +0000 | [diff] [blame] | 153 | |
Alexey Samsonov | 7274ff8 | 2012-07-31 15:43:11 +0000 | [diff] [blame] | 154 | add_subdirectory(lit_tests) |