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 | |
Alexander Potapenko | 0ef5310 | 2012-08-17 09:00:08 +0000 | [diff] [blame] | 24 | set(ASAN_DYLIB_SOURCES |
Alexey Samsonov | c3b30b3 | 2013-06-22 16:33:52 +0000 | [diff] [blame] | 25 | ${ASAN_SOURCES}) |
Alexander Potapenko | 0ef5310 | 2012-08-17 09:00:08 +0000 | [diff] [blame] | 26 | |
Chandler Carruth | 821f21b | 2012-06-25 12:57:43 +0000 | [diff] [blame] | 27 | include_directories(..) |
| 28 | |
Hans Wennborg | c1f1af7 | 2013-08-27 01:24:01 +0000 | [diff] [blame] | 29 | if (NOT MSVC) |
| 30 | set(ASAN_CFLAGS |
| 31 | ${SANITIZER_COMMON_CFLAGS} |
| 32 | -fno-rtti) |
| 33 | else() |
| 34 | set(ASAN_CFLAGS |
| 35 | ${SANITIZER_COMMON_CFLAGS} |
| 36 | /GR-) |
| 37 | endif() |
Alexey Samsonov | 0f7d4a4 | 2012-09-05 09:00:03 +0000 | [diff] [blame] | 38 | |
Alexey Samsonov | 2aed040 | 2013-01-21 08:24:19 +0000 | [diff] [blame] | 39 | set(ASAN_COMMON_DEFINITIONS |
Alexey Samsonov | 5e5be21 | 2013-01-22 07:21:24 +0000 | [diff] [blame] | 40 | ASAN_HAS_EXCEPTIONS=1) |
Alexey Samsonov | 2aed040 | 2013-01-21 08:24:19 +0000 | [diff] [blame] | 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 | 5e5be21 | 2013-01-22 07:21:24 +0000 | [diff] [blame] | 44 | ASAN_FLEXIBLE_MAPPING_AND_OFFSET=0 |
Evgeniy Stepanov | 34fc56c | 2012-09-11 11:55:45 +0000 | [diff] [blame] | 45 | ASAN_NEEDS_SEGV=0 |
Alexey Samsonov | 2aed040 | 2013-01-21 08:24:19 +0000 | [diff] [blame] | 46 | ASAN_LOW_MEMORY=1) |
Hans Wennborg | c1f1af7 | 2013-08-27 01:24:01 +0000 | [diff] [blame] | 47 | elseif(MSVC) |
| 48 | list(APPEND ASAN_COMMON_DEFINITIONS |
| 49 | ASAN_FLEXIBLE_MAPPING_AND_OFFSET=0 |
| 50 | ASAN_NEEDS_SEGV=0) |
Evgeniy Stepanov | 34fc56c | 2012-09-11 11:55:45 +0000 | [diff] [blame] | 51 | else() |
Alexey Samsonov | 2aed040 | 2013-01-21 08:24:19 +0000 | [diff] [blame] | 52 | list(APPEND ASAN_COMMON_DEFINITIONS |
Alexey Samsonov | 5e5be21 | 2013-01-22 07:21:24 +0000 | [diff] [blame] | 53 | ASAN_FLEXIBLE_MAPPING_AND_OFFSET=1 |
Alexey Samsonov | 2aed040 | 2013-01-21 08:24:19 +0000 | [diff] [blame] | 54 | ASAN_NEEDS_SEGV=1) |
Evgeniy Stepanov | 34fc56c | 2012-09-11 11:55:45 +0000 | [diff] [blame] | 55 | endif() |
Alexander Potapenko | 0ef5310 | 2012-08-17 09:00:08 +0000 | [diff] [blame] | 56 | |
Alexey Samsonov | 43b4b9c | 2013-01-18 16:51:07 +0000 | [diff] [blame] | 57 | # Architectures supported by ASan. |
| 58 | filter_available_targets(ASAN_SUPPORTED_ARCH |
Alexey Samsonov | b957d9f | 2013-06-07 09:44:43 +0000 | [diff] [blame] | 59 | x86_64 i386 powerpc64) |
Alexey Samsonov | 43b4b9c | 2013-01-18 16:51:07 +0000 | [diff] [blame] | 60 | |
Alexey Samsonov | fe51abb | 2012-08-10 14:45:52 +0000 | [diff] [blame] | 61 | set(ASAN_RUNTIME_LIBRARIES) |
| 62 | if(APPLE) |
| 63 | # Build universal binary on APPLE. |
Alexander Potapenko | eba4803 | 2013-01-22 09:14:54 +0000 | [diff] [blame] | 64 | add_compiler_rt_osx_dynamic_runtime(clang_rt.asan_osx_dynamic |
| 65 | ARCH ${ASAN_SUPPORTED_ARCH} |
| 66 | SOURCES ${ASAN_DYLIB_SOURCES} |
| 67 | $<TARGET_OBJECTS:RTInterception.osx> |
| 68 | $<TARGET_OBJECTS:RTSanitizerCommon.osx> |
Alexey Samsonov | c3b30b3 | 2013-06-22 16:33:52 +0000 | [diff] [blame] | 69 | $<TARGET_OBJECTS:RTLSanCommon.osx> |
Alexander Potapenko | eba4803 | 2013-01-22 09:14:54 +0000 | [diff] [blame] | 70 | CFLAGS ${ASAN_CFLAGS} |
Alexander Potapenko | 6956398 | 2013-02-05 15:57:12 +0000 | [diff] [blame] | 71 | DEFS ${ASAN_COMMON_DEFINITIONS} |
Alexander Potapenko | eba4803 | 2013-01-22 09:14:54 +0000 | [diff] [blame] | 72 | # Dynamic lookup is needed because shadow scale and offset are |
| 73 | # provided by the instrumented modules. |
| 74 | LINKFLAGS "-framework Foundation" |
| 75 | "-undefined dynamic_lookup") |
| 76 | list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan_osx_dynamic) |
Evgeniy Stepanov | 34fc56c | 2012-09-11 11:55:45 +0000 | [diff] [blame] | 77 | elseif(ANDROID) |
| 78 | add_library(clang_rt.asan-arm-android SHARED |
| 79 | ${ASAN_SOURCES} |
| 80 | $<TARGET_OBJECTS:RTInterception.arm.android> |
| 81 | $<TARGET_OBJECTS:RTSanitizerCommon.arm.android> |
| 82 | ) |
| 83 | set_target_compile_flags(clang_rt.asan-arm-android |
Alexey Samsonov | 2aad7c1 | 2013-01-21 08:12:20 +0000 | [diff] [blame] | 84 | ${ASAN_CFLAGS}) |
| 85 | set_property(TARGET clang_rt.asan-arm-android APPEND PROPERTY |
| 86 | COMPILE_DEFINITIONS ${ASAN_COMMON_DEFINITIONS}) |
Evgeniy Stepanov | 34fc56c | 2012-09-11 11:55:45 +0000 | [diff] [blame] | 87 | target_link_libraries(clang_rt.asan-arm-android dl) |
| 88 | list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-arm-android) |
Alexey Samsonov | fe51abb | 2012-08-10 14:45:52 +0000 | [diff] [blame] | 89 | else() |
| 90 | # Otherwise, build separate libraries for each target. |
Hans Wennborg | c1f1af7 | 2013-08-27 01:24:01 +0000 | [diff] [blame] | 91 | |
Alexey Samsonov | 43b4b9c | 2013-01-18 16:51:07 +0000 | [diff] [blame] | 92 | foreach(arch ${ASAN_SUPPORTED_ARCH}) |
Hans Wennborg | c1f1af7 | 2013-08-27 01:24:01 +0000 | [diff] [blame] | 93 | set(ASAN_SOURCE_LIBS |
| 94 | $<TARGET_OBJECTS:RTInterception.${arch}> |
| 95 | $<TARGET_OBJECTS:RTSanitizerCommon.${arch}> |
| 96 | $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>) |
| 97 | if (NOT MSVC) |
| 98 | # We can't build Leak Sanitizer on Windows yet. |
| 99 | list(APPEND ASAN_SOURCE_LIBS $<TARGET_OBJECTS:RTLSanCommon.${arch}>) |
| 100 | endif() |
| 101 | |
Alexey Samsonov | 2aad7c1 | 2013-01-21 08:12:20 +0000 | [diff] [blame] | 102 | add_compiler_rt_static_runtime(clang_rt.asan-${arch} ${arch} |
Hans Wennborg | c1f1af7 | 2013-08-27 01:24:01 +0000 | [diff] [blame] | 103 | SOURCES ${ASAN_SOURCES} ${ASAN_SOURCE_LIBS} |
Alexey Samsonov | 2aad7c1 | 2013-01-21 08:12:20 +0000 | [diff] [blame] | 104 | CFLAGS ${ASAN_CFLAGS} |
Alexey Samsonov | e5fa243 | 2013-08-27 15:08:02 +0000 | [diff] [blame] | 105 | DEFS ${ASAN_COMMON_DEFINITIONS}) |
Alexey Samsonov | 544bdfb | 2013-08-28 08:07:04 +0000 | [diff] [blame] | 106 | list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-${arch}) |
| 107 | if (UNIX AND NOT ${arch} STREQUAL "i386") |
| 108 | add_sanitizer_rt_symbols(clang_rt.asan-${arch} asan.syms.extra) |
| 109 | list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-${arch}-symbols) |
| 110 | endif() |
Hans Wennborg | c1f1af7 | 2013-08-27 01:24:01 +0000 | [diff] [blame] | 111 | |
| 112 | if (WIN32) |
| 113 | add_compiler_rt_static_runtime(clang_rt.asan_dll_thunk-${arch} ${arch} |
| 114 | SOURCES asan_dll_thunk.cc |
| 115 | CFLAGS ${ASAN_CFLAGS} -DASAN_DLL_THUNK |
Alexey Samsonov | e5fa243 | 2013-08-27 15:08:02 +0000 | [diff] [blame] | 116 | DEFS ${ASAN_COMMON_DEFINITIONS}) |
Hans Wennborg | c1f1af7 | 2013-08-27 01:24:01 +0000 | [diff] [blame] | 117 | list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan_dll_thunk-${arch}) |
| 118 | endif() |
Alexey Samsonov | 43b4b9c | 2013-01-18 16:51:07 +0000 | [diff] [blame] | 119 | endforeach() |
Alexey Samsonov | fe51abb | 2012-08-10 14:45:52 +0000 | [diff] [blame] | 120 | endif() |
Alexey Samsonov | 4d57f44 | 2012-07-25 11:15:00 +0000 | [diff] [blame] | 121 | |
Alexey Samsonov | c1caace | 2013-05-21 13:48:27 +0000 | [diff] [blame] | 122 | add_compiler_rt_resource_file(asan_blacklist asan_blacklist.txt) |
| 123 | |
Chandler Carruth | 821f21b | 2012-06-25 12:57:43 +0000 | [diff] [blame] | 124 | if(LLVM_INCLUDE_TESTS) |
| 125 | add_subdirectory(tests) |
| 126 | endif() |
Alexey Samsonov | 7274ff8 | 2012-07-31 15:43:11 +0000 | [diff] [blame] | 127 | |
Alexey Samsonov | 7274ff8 | 2012-07-31 15:43:11 +0000 | [diff] [blame] | 128 | add_subdirectory(lit_tests) |