CMakeLists.txt revision 7c2a3bbabc7d3bcc66ad7a076bed9a4b86a3626d
1# Build for the AddressSanitizer runtime support library. 2 3set(ASAN_SOURCES 4 asan_allocator.cc 5 asan_allocator2.cc 6 asan_fake_stack.cc 7 asan_globals.cc 8 asan_interceptors.cc 9 asan_linux.cc 10 asan_mac.cc 11 asan_malloc_linux.cc 12 asan_malloc_mac.cc 13 asan_malloc_win.cc 14 asan_new_delete.cc 15 asan_poisoning.cc 16 asan_posix.cc 17 asan_report.cc 18 asan_rtl.cc 19 asan_stack.cc 20 asan_stats.cc 21 asan_thread.cc 22 asan_thread_registry.cc 23 asan_win.cc 24 ) 25 26set(ASAN_DYLIB_SOURCES 27 ${ASAN_SOURCES} 28 ) 29 30include_directories(..) 31 32set(ASAN_CFLAGS ${SANITIZER_COMMON_CFLAGS}) 33 34set(ASAN_COMMON_DEFINITIONS 35 ASAN_HAS_EXCEPTIONS=1) 36 37if(ANDROID) 38 list(APPEND ASAN_COMMON_DEFINITIONS 39 ASAN_FLEXIBLE_MAPPING_AND_OFFSET=0 40 ASAN_NEEDS_SEGV=0 41 ASAN_LOW_MEMORY=1) 42else() 43 list(APPEND ASAN_COMMON_DEFINITIONS 44 ASAN_FLEXIBLE_MAPPING_AND_OFFSET=1 45 ASAN_NEEDS_SEGV=1) 46endif() 47 48# Architectures supported by ASan. 49filter_available_targets(ASAN_SUPPORTED_ARCH 50 x86_64 i386 powerpc64 powerpc) 51 52set(ASAN_RUNTIME_LIBRARIES) 53if(APPLE) 54 # Build universal binary on APPLE. 55 add_compiler_rt_osx_dynamic_runtime(clang_rt.asan_osx_dynamic 56 ARCH ${ASAN_SUPPORTED_ARCH} 57 SOURCES ${ASAN_DYLIB_SOURCES} 58 $<TARGET_OBJECTS:RTInterception.osx> 59 $<TARGET_OBJECTS:RTSanitizerCommon.osx> 60 CFLAGS ${ASAN_CFLAGS} 61 DEFS ${ASAN_COMMON_DEFINITIONS} 62 # Dynamic lookup is needed because shadow scale and offset are 63 # provided by the instrumented modules. 64 LINKFLAGS "-framework Foundation" 65 "-undefined dynamic_lookup") 66 list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan_osx_dynamic) 67elseif(ANDROID) 68 add_library(clang_rt.asan-arm-android SHARED 69 ${ASAN_SOURCES} 70 $<TARGET_OBJECTS:RTInterception.arm.android> 71 $<TARGET_OBJECTS:RTSanitizerCommon.arm.android> 72 ) 73 set_target_compile_flags(clang_rt.asan-arm-android 74 ${ASAN_CFLAGS}) 75 set_property(TARGET clang_rt.asan-arm-android APPEND PROPERTY 76 COMPILE_DEFINITIONS ${ASAN_COMMON_DEFINITIONS}) 77 target_link_libraries(clang_rt.asan-arm-android dl) 78 list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-arm-android) 79else() 80 # Otherwise, build separate libraries for each target. 81 foreach(arch ${ASAN_SUPPORTED_ARCH}) 82 add_compiler_rt_static_runtime(clang_rt.asan-${arch} ${arch} 83 SOURCES ${ASAN_SOURCES} 84 $<TARGET_OBJECTS:RTInterception.${arch}> 85 $<TARGET_OBJECTS:RTSanitizerCommon.${arch}> 86 CFLAGS ${ASAN_CFLAGS} 87 DEFS ${ASAN_COMMON_DEFINITIONS}) 88 list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-${arch}) 89 endforeach() 90endif() 91 92if(LLVM_INCLUDE_TESTS) 93 add_subdirectory(tests) 94endif() 95 96add_subdirectory(lit_tests) 97