CMakeLists.txt revision 69563986ca570ce750111a82264d51ddbf4107ba
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 dynamic/asan_interceptors_dynamic.cc 29 ) 30 31include_directories(..) 32 33set(ASAN_CFLAGS ${SANITIZER_COMMON_CFLAGS}) 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 list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-${arch}) 90 endforeach() 91endif() 92 93if(LLVM_INCLUDE_TESTS) 94 add_subdirectory(tests) 95endif() 96 97add_subdirectory(lit_tests) 98