1 # Build for the AddressSanitizer runtime support library. 2 3 set(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 set(ASAN_DYLIB_SOURCES 25 ${ASAN_SOURCES}) 26 27 include_directories(..) 28 29 set(ASAN_CFLAGS 30 ${SANITIZER_COMMON_CFLAGS} 31 -fno-rtti) 32 33 set(ASAN_COMMON_DEFINITIONS 34 ASAN_HAS_EXCEPTIONS=1) 35 36 if(ANDROID) 37 list(APPEND ASAN_COMMON_DEFINITIONS 38 ASAN_FLEXIBLE_MAPPING_AND_OFFSET=0 39 ASAN_NEEDS_SEGV=0 40 ASAN_LOW_MEMORY=1) 41 else() 42 list(APPEND ASAN_COMMON_DEFINITIONS 43 ASAN_FLEXIBLE_MAPPING_AND_OFFSET=1 44 ASAN_NEEDS_SEGV=1) 45 endif() 46 47 # Architectures supported by ASan. 48 filter_available_targets(ASAN_SUPPORTED_ARCH 49 x86_64 i386 powerpc64) 50 51 set(ASAN_RUNTIME_LIBRARIES) 52 if(APPLE) 53 # Build universal binary on APPLE. 54 add_compiler_rt_osx_dynamic_runtime(clang_rt.asan_osx_dynamic 55 ARCH ${ASAN_SUPPORTED_ARCH} 56 SOURCES ${ASAN_DYLIB_SOURCES} 57 $<TARGET_OBJECTS:RTInterception.osx> 58 $<TARGET_OBJECTS:RTSanitizerCommon.osx> 59 $<TARGET_OBJECTS:RTLSanCommon.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) 67 elseif(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) 79 else() 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 $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}> 87 $<TARGET_OBJECTS:RTLSanCommon.${arch}> 88 CFLAGS ${ASAN_CFLAGS} 89 DEFS ${ASAN_COMMON_DEFINITIONS} 90 SYMS asan.syms) 91 list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-${arch}) 92 endforeach() 93 endif() 94 95 add_compiler_rt_resource_file(asan_blacklist asan_blacklist.txt) 96 97 if(LLVM_INCLUDE_TESTS) 98 add_subdirectory(tests) 99 endif() 100 101 add_subdirectory(lit_tests) 102