Add an /FS flag to the ASan RTL CMake to make it buildable with VS2013
[blocksruntime.git] / lib / asan / CMakeLists.txt
blobf9d2eeefff5f2e3f2bc85731d7c3807350106adb
1 # Build for the AddressSanitizer runtime support library.
3 set(ASAN_SOURCES
4   asan_allocator2.cc
5   asan_activation.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)
25 include_directories(..)
27 if (NOT MSVC)
28   set(ASAN_CFLAGS
29     ${SANITIZER_COMMON_CFLAGS}
30     -fno-rtti)
31 else()
32   set(ASAN_CFLAGS
33     ${SANITIZER_COMMON_CFLAGS}
34     /GR- /FS)
35 endif()
37 set(ASAN_COMMON_DEFINITIONS
38   ASAN_HAS_EXCEPTIONS=1)
40 if(ANDROID)
41   list(APPEND ASAN_COMMON_DEFINITIONS
42     ASAN_LOW_MEMORY=1)
43 endif()
45 # Architectures supported by ASan.
46 filter_available_targets(ASAN_SUPPORTED_ARCH
47   x86_64 i386 powerpc64)
49 # Compile ASan sources into an object library.
50 if(APPLE)
51   foreach(os ${SANITIZER_COMMON_SUPPORTED_DARWIN_OS})
52     add_compiler_rt_darwin_object_library(RTAsan ${os}
53       ARCH ${ASAN_SUPPORTED_ARCH}
54       SOURCES ${ASAN_SOURCES}
55       CFLAGS ${ASAN_CFLAGS}
56       DEFS ${ASAN_COMMON_DEFINITIONS})
57   endforeach()
58 elseif(ANDROID)
59   add_library(RTAsan.arm.android OBJECT ${ASAN_SOURCES})
60   set_target_compile_flags(RTAsan.arm.android ${ASAN_CFLAGS})
61   set_property(TARGET RTAsan.arm.android APPEND PROPERTY
62     COMPILE_DEFINITIONS ${ASAN_COMMON_DEFINITIONS})
63 else()
64   foreach(arch ${ASAN_SUPPORTED_ARCH})
65     add_compiler_rt_object_library(RTAsan ${arch}
66       SOURCES ${ASAN_SOURCES} CFLAGS ${ASAN_CFLAGS}
67       DEFS ${ASAN_COMMON_DEFINITIONS})
68   endforeach()
69 endif()
71 # Build ASan runtimes shipped with Clang.
72 set(ASAN_RUNTIME_LIBRARIES)
73 if(APPLE)
74   foreach (os ${SANITIZER_COMMON_SUPPORTED_DARWIN_OS})
75     # Dynamic lookup is needed because shadow scale and offset are
76     # provided by the instrumented modules.
77     set(ASAN_RUNTIME_LDFLAGS
78         "-undefined dynamic_lookup")
79     add_compiler_rt_darwin_dynamic_runtime(clang_rt.asan_${os}_dynamic ${os}
80       ARCH ${ASAN_SUPPORTED_ARCH}
81       SOURCES $<TARGET_OBJECTS:RTAsan.${os}>
82               $<TARGET_OBJECTS:RTInterception.${os}>
83               $<TARGET_OBJECTS:RTSanitizerCommon.${os}>
84               $<TARGET_OBJECTS:RTLSanCommon.${os}>
85       CFLAGS ${ASAN_CFLAGS}
86       DEFS ${ASAN_COMMON_DEFINITIONS}
87       LINKFLAGS ${ASAN_RUNTIME_LDFLAGS})
88     list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan_${os}_dynamic)
89   endforeach()
91 elseif(ANDROID)
92   add_library(clang_rt.asan-arm-android SHARED
93     $<TARGET_OBJECTS:RTAsan.arm.android>
94     $<TARGET_OBJECTS:RTInterception.arm.android>
95     $<TARGET_OBJECTS:RTSanitizerCommon.arm.android>)
96   set_target_compile_flags(clang_rt.asan-arm-android
97     ${ASAN_CFLAGS})
98   set_property(TARGET clang_rt.asan-arm-android APPEND PROPERTY
99     COMPILE_DEFINITIONS ${ASAN_COMMON_DEFINITIONS})
100   target_link_libraries(clang_rt.asan-arm-android dl log)
101   list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-arm-android)
102 else()
103   # Build separate libraries for each target.
104   foreach(arch ${ASAN_SUPPORTED_ARCH})
105     set(ASAN_RUNTIME_OBJECTS
106       $<TARGET_OBJECTS:RTAsan.${arch}>
107       $<TARGET_OBJECTS:RTInterception.${arch}>
108       $<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
109       $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>)
110     if (NOT WIN32)
111       # We can't build Leak Sanitizer on Windows yet.
112       list(APPEND ASAN_RUNTIME_OBJECTS $<TARGET_OBJECTS:RTLSanCommon.${arch}>)
113     endif()
115     add_compiler_rt_static_runtime(clang_rt.asan-${arch} ${arch}
116       SOURCES ${ASAN_RUNTIME_OBJECTS}
117       CFLAGS ${ASAN_CFLAGS}
118       DEFS ${ASAN_COMMON_DEFINITIONS})
119     list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-${arch})
120     if (UNIX AND NOT ${arch} STREQUAL "i386")
121       add_sanitizer_rt_symbols(clang_rt.asan-${arch} asan.syms.extra)
122       list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-${arch}-symbols)
123     endif()
125     if (WIN32)
126       add_compiler_rt_static_runtime(clang_rt.asan_dll_thunk-${arch} ${arch}
127       SOURCES asan_dll_thunk.cc
128       CFLAGS ${ASAN_CFLAGS} -DASAN_DLL_THUNK
129       DEFS ${ASAN_COMMON_DEFINITIONS})
130       list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan_dll_thunk-${arch})
131     endif()
132   endforeach()
133 endif()
135 add_compiler_rt_resource_file(asan_blacklist asan_blacklist.txt)
137 # All ASan runtime dependencies.
138 add_custom_target(asan_runtime_libraries
139   DEPENDS asan_blacklist ${ASAN_RUNTIME_LIBRARIES})
141 if(LLVM_INCLUDE_TESTS)
142   add_subdirectory(tests)
143 endif()
145 add_subdirectory(lit_tests)