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