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