CMakeLists.txt revision a7e5db966299a50c0e68cf9d35e1130b6c024c94
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_preinit.cc
18  asan_report.cc
19  asan_rtl.cc
20  asan_stack.cc
21  asan_stats.cc
22  asan_thread.cc
23  asan_thread_registry.cc
24  asan_win.cc
25  )
26
27set(ASAN_DYLIB_SOURCES
28  ${ASAN_SOURCES}
29  )
30
31include_directories(..)
32
33set(ASAN_CFLAGS
34  ${SANITIZER_COMMON_CFLAGS}
35  -fno-rtti)
36
37set(ASAN_COMMON_DEFINITIONS
38  ASAN_HAS_EXCEPTIONS=1)
39
40if(ANDROID)
41  list(APPEND ASAN_COMMON_DEFINITIONS
42    ASAN_FLEXIBLE_MAPPING_AND_OFFSET=0
43    ASAN_NEEDS_SEGV=0
44    ASAN_LOW_MEMORY=1)
45else()
46  list(APPEND ASAN_COMMON_DEFINITIONS
47    ASAN_FLEXIBLE_MAPPING_AND_OFFSET=1
48    ASAN_NEEDS_SEGV=1)
49endif()
50
51# Architectures supported by ASan.
52filter_available_targets(ASAN_SUPPORTED_ARCH
53  x86_64 i386 powerpc64 powerpc)
54
55set(ASAN_RUNTIME_LIBRARIES)
56if(APPLE)
57  # Build universal binary on APPLE.
58  add_compiler_rt_osx_dynamic_runtime(clang_rt.asan_osx_dynamic
59    ARCH ${ASAN_SUPPORTED_ARCH}
60    SOURCES ${ASAN_DYLIB_SOURCES}
61            $<TARGET_OBJECTS:RTInterception.osx>
62            $<TARGET_OBJECTS:RTSanitizerCommon.osx>
63    CFLAGS ${ASAN_CFLAGS}
64    DEFS ${ASAN_COMMON_DEFINITIONS}
65    # Dynamic lookup is needed because shadow scale and offset are
66    # provided by the instrumented modules.
67    LINKFLAGS "-framework Foundation"
68              "-undefined dynamic_lookup")
69  list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan_osx_dynamic)
70elseif(ANDROID)
71  add_library(clang_rt.asan-arm-android SHARED
72    ${ASAN_SOURCES}
73    $<TARGET_OBJECTS:RTInterception.arm.android>
74    $<TARGET_OBJECTS:RTSanitizerCommon.arm.android>
75    )
76  set_target_compile_flags(clang_rt.asan-arm-android
77    ${ASAN_CFLAGS})
78  set_property(TARGET clang_rt.asan-arm-android APPEND PROPERTY
79    COMPILE_DEFINITIONS ${ASAN_COMMON_DEFINITIONS})
80  target_link_libraries(clang_rt.asan-arm-android dl)
81  list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-arm-android)
82else()
83  # Otherwise, build separate libraries for each target.
84  foreach(arch ${ASAN_SUPPORTED_ARCH})
85    add_compiler_rt_static_runtime(clang_rt.asan-${arch} ${arch}
86      SOURCES ${ASAN_SOURCES}
87              $<TARGET_OBJECTS:RTInterception.${arch}>
88              $<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
89      CFLAGS ${ASAN_CFLAGS}
90      DEFS ${ASAN_COMMON_DEFINITIONS})
91    list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-${arch})
92  endforeach()
93endif()
94
95if(LLVM_INCLUDE_TESTS)
96  add_subdirectory(tests)
97endif()
98
99add_subdirectory(lit_tests)
100