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