CMakeLists.txt revision 2aed04090856609cdf510b69dd0a1d81b3980b5f
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 ASAN_FLEXIBLE_MAPPING_AND_OFFSET=1) 38 39if(ANDROID) 40 list(APPEND ASAN_COMMON_DEFINITIONS 41 ASAN_NEEDS_SEGV=0 42 ASAN_LOW_MEMORY=1) 43else() 44 list(APPEND ASAN_COMMON_DEFINITIONS 45 ASAN_NEEDS_SEGV=1) 46endif() 47 48set(ASAN_DYLIB_DEFINITIONS 49 ${ASAN_COMMON_DEFINITIONS} 50 MAC_INTERPOSE_FUNCTIONS=1) 51 52# Architectures supported by ASan. 53filter_available_targets(ASAN_SUPPORTED_ARCH 54 x86_64 i386) 55 56set(ASAN_RUNTIME_LIBRARIES) 57if(APPLE) 58 # Build universal binary on APPLE. 59 add_compiler_rt_osx_static_runtime(clang_rt.asan_osx 60 ARCH ${ASAN_SUPPORTED_ARCH} 61 SOURCES ${ASAN_SOURCES} 62 $<TARGET_OBJECTS:RTInterception.osx> 63 $<TARGET_OBJECTS:RTSanitizerCommon.osx> 64 CFLAGS ${ASAN_CFLAGS} 65 DEFS ${ASAN_COMMON_DEFINITIONS}) 66 list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan_osx) 67elseif(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) 79else() 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 CFLAGS ${ASAN_CFLAGS} 87 DEFS ${ASAN_COMMON_DEFINITIONS}) 88 list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-${arch}) 89 endforeach() 90endif() 91 92set(ASAN_DYNAMIC_RUNTIME_LIBRARIES) 93if(APPLE) 94 # Build universal binary on APPLE. 95 add_compiler_rt_osx_dynamic_runtime(clang_rt.asan_osx_dynamic 96 ARCH ${ASAN_SUPPORTED_ARCH} 97 SOURCES ${ASAN_DYLIB_SOURCES} 98 $<TARGET_OBJECTS:RTInterception.osx> 99 $<TARGET_OBJECTS:RTSanitizerCommon.osx> 100 CFLAGS ${ASAN_CFLAGS} 101 DEFS ${ASAN_DYLIB_DEFINITIONS} 102 LINKFLAGS "-framework Foundation") 103 list(APPEND ASAN_DYNAMIC_RUNTIME_LIBRARIES clang_rt.asan_osx_dynamic) 104endif() 105 106if(LLVM_INCLUDE_TESTS) 107 add_subdirectory(tests) 108endif() 109 110add_subdirectory(lit_tests) 111