CMakeLists.txt revision 34fc56c43f60be0b85a0e3ce30658fd98951f0b8
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 33if(ANDROID) 34 set(ASAN_COMMON_DEFINITIONS 35 ASAN_HAS_EXCEPTIONS=1 36 ASAN_FLEXIBLE_MAPPING_AND_OFFSET=0 37 ASAN_NEEDS_SEGV=0 38 ASAN_LOW_MEMORY=1 39 ) 40else() 41 set(ASAN_COMMON_DEFINITIONS 42 ASAN_HAS_EXCEPTIONS=1 43 ASAN_FLEXIBLE_MAPPING_AND_OFFSET=0 44 ASAN_NEEDS_SEGV=1 45 ) 46endif() 47 48set(ASAN_DYLIB_DEFINITIONS 49 ${ASAN_COMMON_DEFINITIONS} 50 MAC_INTERPOSE_FUNCTIONS=1 51 ) 52 53set(ASAN_RUNTIME_LIBRARIES) 54if(APPLE) 55 # Build universal binary on APPLE. 56 add_library(clang_rt.asan_osx STATIC 57 ${ASAN_SOURCES} 58 $<TARGET_OBJECTS:RTInterception.osx> 59 $<TARGET_OBJECTS:RTSanitizerCommon.osx> 60 ) 61 set_target_compile_flags(clang_rt.asan_osx ${ASAN_CFLAGS}) 62 filter_available_targets(ASAN_TARGETS x86_64 i386) 63 set_target_properties(clang_rt.asan_osx PROPERTIES 64 OSX_ARCHITECTURES "${ASAN_TARGETS}") 65 list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan_osx) 66elseif(ANDROID) 67 add_library(clang_rt.asan-arm-android SHARED 68 ${ASAN_SOURCES} 69 $<TARGET_OBJECTS:RTInterception.arm.android> 70 $<TARGET_OBJECTS:RTSanitizerCommon.arm.android> 71 ) 72 set_target_compile_flags(clang_rt.asan-arm-android 73 ${ASAN_CFLAGS} 74 ) 75 target_link_libraries(clang_rt.asan-arm-android dl) 76 list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-arm-android) 77else() 78 # Otherwise, build separate libraries for each target. 79 if(CAN_TARGET_X86_64) 80 add_library(clang_rt.asan-x86_64 STATIC 81 ${ASAN_SOURCES} 82 $<TARGET_OBJECTS:RTInterception.x86_64> 83 $<TARGET_OBJECTS:RTSanitizerCommon.x86_64> 84 ) 85 set_target_compile_flags(clang_rt.asan-x86_64 86 ${ASAN_CFLAGS} ${TARGET_X86_64_CFLAGS} 87 ) 88 list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-x86_64) 89 endif() 90 if(CAN_TARGET_I386) 91 add_library(clang_rt.asan-i386 STATIC 92 ${ASAN_SOURCES} 93 $<TARGET_OBJECTS:RTInterception.i386> 94 $<TARGET_OBJECTS:RTSanitizerCommon.i386> 95 ) 96 set_target_compile_flags(clang_rt.asan-i386 97 ${ASAN_CFLAGS} ${TARGET_I386_CFLAGS} 98 ) 99 list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-i386) 100 endif() 101endif() 102 103set_property(TARGET ${ASAN_RUNTIME_LIBRARIES} APPEND PROPERTY 104 COMPILE_DEFINITIONS ${ASAN_COMMON_DEFINITIONS}) 105add_clang_compiler_rt_libraries(${ASAN_RUNTIME_LIBRARIES}) 106 107set(ASAN_DYNAMIC_RUNTIME_LIBRARIES) 108if(APPLE) 109 # Build universal binary on APPLE. 110 add_library(clang_rt.asan_osx_dynamic SHARED 111 ${ASAN_DYLIB_SOURCES} 112 $<TARGET_OBJECTS:RTInterception.osx> 113 $<TARGET_OBJECTS:RTSanitizerCommon.osx> 114 ) 115 set_target_compile_flags(clang_rt.asan_osx_dynamic ${ASAN_CFLAGS}) 116 filter_available_targets(ASAN_TARGETS x86_64 i386) 117 set_target_properties(clang_rt.asan_osx_dynamic PROPERTIES 118 COMPILE_DEFINITIONS "${ASAN_DYLIB_DEFINITIONS}" 119 OSX_ARCHITECTURES "${ASAN_TARGETS}" 120 LINK_FLAGS "-framework Foundation") 121 list(APPEND ASAN_DYNAMIC_RUNTIME_LIBRARIES clang_rt.asan_osx_dynamic) 122endif() 123add_clang_compiler_rt_libraries(${ASAN_DYNAMIC_RUNTIME_LIBRARIES}) 124 125 126if(LLVM_INCLUDE_TESTS) 127 add_subdirectory(tests) 128endif() 129 130# ASan output tests. 131# FIXME: move all output tests from output_tests/ to lit_tests/ and get rid 132# of the first directory. 133add_subdirectory(lit_tests) 134