1# Build for the AddressSanitizer runtime support library. 2 3set(ASAN_SOURCES 4 asan_allocator.cc 5 asan_globals.cc 6 asan_interceptors.cc 7 asan_linux.cc 8 asan_mac.cc 9 asan_malloc_linux.cc 10 asan_malloc_mac.cc 11 asan_malloc_win.cc 12 asan_new_delete.cc 13 asan_poisoning.cc 14 asan_posix.cc 15 asan_report.cc 16 asan_rtl.cc 17 asan_stack.cc 18 asan_stats.cc 19 asan_thread.cc 20 asan_thread_registry.cc 21 asan_win.cc 22 ) 23 24set(ASAN_DYLIB_SOURCES 25 ${ASAN_SOURCES} 26 dynamic/asan_interceptors_dynamic.cc 27 ) 28 29include_directories(..) 30 31set(ASAN_CFLAGS ${SANITIZER_COMMON_CFLAGS}) 32 33set(ASAN_COMMON_DEFINITIONS 34 ASAN_HAS_EXCEPTIONS=1 35 ASAN_FLEXIBLE_MAPPING_AND_OFFSET=0 36 ASAN_NEEDS_SEGV=1 37 ) 38 39set(ASAN_DYLIB_DEFINITIONS 40 ${ASAN_COMMON_DEFINITIONS} 41 MAC_INTERPOSE_FUNCTIONS=1 42 ) 43 44set(ASAN_RUNTIME_LIBRARIES) 45if(APPLE) 46 # Build universal binary on APPLE. 47 add_library(clang_rt.asan_osx STATIC 48 ${ASAN_SOURCES} 49 $<TARGET_OBJECTS:RTInterception.osx> 50 $<TARGET_OBJECTS:RTSanitizerCommon.osx> 51 ) 52 set_target_compile_flags(clang_rt.asan_osx ${ASAN_CFLAGS}) 53 filter_available_targets(ASAN_TARGETS x86_64 i386) 54 set_target_properties(clang_rt.asan_osx PROPERTIES 55 OSX_ARCHITECTURES "${ASAN_TARGETS}") 56 list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan_osx) 57else() 58 # Otherwise, build separate libraries for each target. 59 if(CAN_TARGET_X86_64) 60 add_library(clang_rt.asan-x86_64 STATIC 61 ${ASAN_SOURCES} 62 $<TARGET_OBJECTS:RTInterception.x86_64> 63 $<TARGET_OBJECTS:RTSanitizerCommon.x86_64> 64 ) 65 set_target_compile_flags(clang_rt.asan-x86_64 66 ${ASAN_CFLAGS} ${TARGET_X86_64_CFLAGS} 67 ) 68 list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-x86_64) 69 endif() 70 if(CAN_TARGET_I386) 71 add_library(clang_rt.asan-i386 STATIC 72 ${ASAN_SOURCES} 73 $<TARGET_OBJECTS:RTInterception.i386> 74 $<TARGET_OBJECTS:RTSanitizerCommon.i386> 75 ) 76 set_target_compile_flags(clang_rt.asan-i386 77 ${ASAN_CFLAGS} ${TARGET_I386_CFLAGS} 78 ) 79 list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-i386) 80 endif() 81 if(CAN_TARGET_ARM_ANDROID) 82 add_library(clang_rt.asan-arm-android STATIC 83 ${ASAN_SOURCES} 84 $<TARGET_OBJECTS:RTInterception.arm.android> 85 $<TARGET_OBJECTS:RTSanitizerCommon.arm.android> 86 ) 87 set_target_compile_flags(clang_rt.asan-arm-android 88 ${ASAN_CFLAGS} ${TARGET_ARM_ANDROID_CFLAGS} 89 ) 90 list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-arm-android) 91 endif() 92endif() 93 94set_property(TARGET ${ASAN_RUNTIME_LIBRARIES} APPEND PROPERTY 95 COMPILE_DEFINITIONS ${ASAN_COMMON_DEFINITIONS}) 96add_clang_runtime_static_library(${ASAN_RUNTIME_LIBRARIES}) 97 98set(ASAN_DYNAMIC_RUNTIME_LIBRARIES) 99if(APPLE) 100 # Build universal binary on APPLE. 101 add_library(clang_rt.asan_osx_dynamic SHARED 102 ${ASAN_DYLIB_SOURCES} 103 $<TARGET_OBJECTS:RTInterception.osx> 104 $<TARGET_OBJECTS:RTSanitizerCommon.osx> 105 ) 106 set_target_compile_flags(clang_rt.asan_osx_dynamic ${ASAN_CFLAGS}) 107 filter_available_targets(ASAN_TARGETS x86_64 i386) 108 set_target_properties(clang_rt.asan_osx_dynamic PROPERTIES 109 COMPILE_DEFINITIONS "${ASAN_DYLIB_DEFINITIONS}" 110 OSX_ARCHITECTURES "${ASAN_TARGETS}" 111 LINK_FLAGS "-framework Foundation") 112 list(APPEND ASAN_DYNAMIC_RUNTIME_LIBRARIES clang_rt.asan_osx_dynamic) 113endif() 114add_clang_runtime_shared_library(${ASAN_DYNAMIC_RUNTIME_LIBRARIES}) 115 116 117if(LLVM_INCLUDE_TESTS) 118 add_subdirectory(tests) 119endif() 120 121# ASan output tests. 122# FIXME: move all output tests from output_tests/ to lit_tests/ and get rid 123# of the first directory. 124add_subdirectory(lit_tests) 125