blob: ad3f05488ebf9864560c774942efe24c579a94f2 [file] [log] [blame]
Chandler Carruthd51e0a02012-04-04 22:12:04 +00001# Build for the AddressSanitizer runtime support library.
2
Chandler Carruth479d47f2012-06-20 10:18:43 +00003set(ASAN_SOURCES
Kostya Serebryany8b0a7ce2012-12-10 13:52:55 +00004 asan_allocator2.cc
Kostya Serebryany2679f192012-12-10 14:19:15 +00005 asan_fake_stack.cc
Chandler Carruth479d47f2012-06-20 10:18:43 +00006 asan_globals.cc
7 asan_interceptors.cc
8 asan_linux.cc
9 asan_mac.cc
10 asan_malloc_linux.cc
11 asan_malloc_mac.cc
12 asan_malloc_win.cc
13 asan_new_delete.cc
14 asan_poisoning.cc
15 asan_posix.cc
Kostya Serebryany33934ff2013-02-22 07:51:26 +000016 asan_preinit.cc
Alexey Samsonovf7c1d182012-08-09 08:15:46 +000017 asan_report.cc
Chandler Carruth479d47f2012-06-20 10:18:43 +000018 asan_rtl.cc
19 asan_stack.cc
20 asan_stats.cc
21 asan_thread.cc
Alexey Samsonovc3b30b32013-06-22 16:33:52 +000022 asan_win.cc)
Chandler Carruthd51e0a02012-04-04 22:12:04 +000023
Chandler Carruth821f21b2012-06-25 12:57:43 +000024include_directories(..)
25
Hans Wennborgc1f1af72013-08-27 01:24:01 +000026if (NOT MSVC)
27 set(ASAN_CFLAGS
28 ${SANITIZER_COMMON_CFLAGS}
29 -fno-rtti)
30else()
31 set(ASAN_CFLAGS
32 ${SANITIZER_COMMON_CFLAGS}
33 /GR-)
34endif()
Alexey Samsonov0f7d4a42012-09-05 09:00:03 +000035
Alexey Samsonov2aed0402013-01-21 08:24:19 +000036set(ASAN_COMMON_DEFINITIONS
Alexey Samsonov5e5be212013-01-22 07:21:24 +000037 ASAN_HAS_EXCEPTIONS=1)
Alexey Samsonov2aed0402013-01-21 08:24:19 +000038
Evgeniy Stepanov34fc56c2012-09-11 11:55:45 +000039if(ANDROID)
Alexey Samsonov2aed0402013-01-21 08:24:19 +000040 list(APPEND ASAN_COMMON_DEFINITIONS
Alexey Samsonov5e5be212013-01-22 07:21:24 +000041 ASAN_FLEXIBLE_MAPPING_AND_OFFSET=0
Evgeniy Stepanov34fc56c2012-09-11 11:55:45 +000042 ASAN_NEEDS_SEGV=0
Alexey Samsonov2aed0402013-01-21 08:24:19 +000043 ASAN_LOW_MEMORY=1)
Hans Wennborgc1f1af72013-08-27 01:24:01 +000044elseif(MSVC)
45 list(APPEND ASAN_COMMON_DEFINITIONS
46 ASAN_FLEXIBLE_MAPPING_AND_OFFSET=0
47 ASAN_NEEDS_SEGV=0)
Evgeniy Stepanov34fc56c2012-09-11 11:55:45 +000048else()
Alexey Samsonov2aed0402013-01-21 08:24:19 +000049 list(APPEND ASAN_COMMON_DEFINITIONS
Alexey Samsonov5e5be212013-01-22 07:21:24 +000050 ASAN_FLEXIBLE_MAPPING_AND_OFFSET=1
Alexey Samsonov2aed0402013-01-21 08:24:19 +000051 ASAN_NEEDS_SEGV=1)
Evgeniy Stepanov34fc56c2012-09-11 11:55:45 +000052endif()
Alexander Potapenko0ef53102012-08-17 09:00:08 +000053
Alexey Samsonov43b4b9c2013-01-18 16:51:07 +000054# Architectures supported by ASan.
55filter_available_targets(ASAN_SUPPORTED_ARCH
Alexey Samsonovb957d9f2013-06-07 09:44:43 +000056 x86_64 i386 powerpc64)
Alexey Samsonov43b4b9c2013-01-18 16:51:07 +000057
Alexey Samsonov05fa3802013-09-16 15:50:53 +000058# Compile ASan sources into an object library.
59if(APPLE)
Alexander Potapenko49496742013-11-07 10:08:19 +000060 foreach(os ${SANITIZER_COMMON_SUPPORTED_DARWIN_OS})
61 add_compiler_rt_darwin_object_library(RTAsan ${os}
62 ARCH ${ASAN_SUPPORTED_ARCH}
63 SOURCES ${ASAN_SOURCES}
64 CFLAGS ${ASAN_CFLAGS}
65 DEFS ${ASAN_COMMON_DEFINITIONS})
66 endforeach()
Alexey Samsonov05fa3802013-09-16 15:50:53 +000067elseif(ANDROID)
68 add_library(RTAsan.arm.android OBJECT ${ASAN_SOURCES})
69 set_target_compile_flags(RTAsan.arm.android ${ASAN_CFLAGS})
70 set_property(TARGET RTAsan.arm.android APPEND PROPERTY
71 COMPILE_DEFINITIONS ${ASAN_COMMON_DEFINITIONS})
72else()
73 foreach(arch ${ASAN_SUPPORTED_ARCH})
74 add_compiler_rt_object_library(RTAsan ${arch}
75 SOURCES ${ASAN_SOURCES} CFLAGS ${ASAN_CFLAGS}
76 DEFS ${ASAN_COMMON_DEFINITIONS})
77 endforeach()
78endif()
79
80# Build ASan runtimes shipped with Clang.
Alexey Samsonovfe51abb2012-08-10 14:45:52 +000081set(ASAN_RUNTIME_LIBRARIES)
82if(APPLE)
Alexander Potapenko49496742013-11-07 10:08:19 +000083 foreach (os ${SANITIZER_COMMON_SUPPORTED_DARWIN_OS})
Alexander Potapenkoeba48032013-01-22 09:14:54 +000084 # Dynamic lookup is needed because shadow scale and offset are
85 # provided by the instrumented modules.
Alexander Potapenko49496742013-11-07 10:08:19 +000086 set(ASAN_RUNTIME_LDFLAGS
87 "-undefined dynamic_lookup")
Alexander Potapenko49496742013-11-07 10:08:19 +000088 add_compiler_rt_darwin_dynamic_runtime(clang_rt.asan_${os}_dynamic ${os}
89 ARCH ${ASAN_SUPPORTED_ARCH}
90 SOURCES $<TARGET_OBJECTS:RTAsan.${os}>
91 $<TARGET_OBJECTS:RTInterception.${os}>
92 $<TARGET_OBJECTS:RTSanitizerCommon.${os}>
93 $<TARGET_OBJECTS:RTLSanCommon.${os}>
94 CFLAGS ${ASAN_CFLAGS}
95 DEFS ${ASAN_COMMON_DEFINITIONS}
96 LINKFLAGS ${ASAN_RUNTIME_LDFLAGS})
97 list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan_${os}_dynamic)
98 endforeach()
99
Evgeniy Stepanov34fc56c2012-09-11 11:55:45 +0000100elseif(ANDROID)
101 add_library(clang_rt.asan-arm-android SHARED
Alexey Samsonov05fa3802013-09-16 15:50:53 +0000102 $<TARGET_OBJECTS:RTAsan.arm.android>
Evgeniy Stepanov34fc56c2012-09-11 11:55:45 +0000103 $<TARGET_OBJECTS:RTInterception.arm.android>
Alexey Samsonov05fa3802013-09-16 15:50:53 +0000104 $<TARGET_OBJECTS:RTSanitizerCommon.arm.android>)
Evgeniy Stepanov34fc56c2012-09-11 11:55:45 +0000105 set_target_compile_flags(clang_rt.asan-arm-android
Alexey Samsonov2aad7c12013-01-21 08:12:20 +0000106 ${ASAN_CFLAGS})
107 set_property(TARGET clang_rt.asan-arm-android APPEND PROPERTY
108 COMPILE_DEFINITIONS ${ASAN_COMMON_DEFINITIONS})
Evgeniy Stepanov34fc56c2012-09-11 11:55:45 +0000109 target_link_libraries(clang_rt.asan-arm-android dl)
110 list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-arm-android)
Alexey Samsonovfe51abb2012-08-10 14:45:52 +0000111else()
Alexey Samsonov05fa3802013-09-16 15:50:53 +0000112 # Build separate libraries for each target.
Alexey Samsonov43b4b9c2013-01-18 16:51:07 +0000113 foreach(arch ${ASAN_SUPPORTED_ARCH})
Alexey Samsonov05fa3802013-09-16 15:50:53 +0000114 set(ASAN_RUNTIME_OBJECTS
115 $<TARGET_OBJECTS:RTAsan.${arch}>
Hans Wennborgc1f1af72013-08-27 01:24:01 +0000116 $<TARGET_OBJECTS:RTInterception.${arch}>
117 $<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
118 $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>)
Alexey Samsonov3125de92013-11-17 10:12:23 +0000119 if (NOT WIN32)
Hans Wennborgc1f1af72013-08-27 01:24:01 +0000120 # We can't build Leak Sanitizer on Windows yet.
Alexey Samsonov05fa3802013-09-16 15:50:53 +0000121 list(APPEND ASAN_RUNTIME_OBJECTS $<TARGET_OBJECTS:RTLSanCommon.${arch}>)
Hans Wennborgc1f1af72013-08-27 01:24:01 +0000122 endif()
123
Alexey Samsonov2aad7c12013-01-21 08:12:20 +0000124 add_compiler_rt_static_runtime(clang_rt.asan-${arch} ${arch}
Alexey Samsonov05fa3802013-09-16 15:50:53 +0000125 SOURCES ${ASAN_RUNTIME_OBJECTS}
Alexey Samsonov2aad7c12013-01-21 08:12:20 +0000126 CFLAGS ${ASAN_CFLAGS}
Alexey Samsonove5fa2432013-08-27 15:08:02 +0000127 DEFS ${ASAN_COMMON_DEFINITIONS})
Alexey Samsonov544bdfb2013-08-28 08:07:04 +0000128 list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-${arch})
129 if (UNIX AND NOT ${arch} STREQUAL "i386")
130 add_sanitizer_rt_symbols(clang_rt.asan-${arch} asan.syms.extra)
131 list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-${arch}-symbols)
132 endif()
Hans Wennborgc1f1af72013-08-27 01:24:01 +0000133
134 if (WIN32)
135 add_compiler_rt_static_runtime(clang_rt.asan_dll_thunk-${arch} ${arch}
136 SOURCES asan_dll_thunk.cc
137 CFLAGS ${ASAN_CFLAGS} -DASAN_DLL_THUNK
Alexey Samsonove5fa2432013-08-27 15:08:02 +0000138 DEFS ${ASAN_COMMON_DEFINITIONS})
Hans Wennborgc1f1af72013-08-27 01:24:01 +0000139 list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan_dll_thunk-${arch})
140 endif()
Alexey Samsonov43b4b9c2013-01-18 16:51:07 +0000141 endforeach()
Alexey Samsonovfe51abb2012-08-10 14:45:52 +0000142endif()
Alexey Samsonov4d57f442012-07-25 11:15:00 +0000143
Alexey Samsonovc1caace2013-05-21 13:48:27 +0000144add_compiler_rt_resource_file(asan_blacklist asan_blacklist.txt)
145
Alexey Samsonov8c6e4852013-11-14 12:24:12 +0000146# All ASan runtime dependencies.
147add_custom_target(asan_runtime_libraries
148 DEPENDS asan_blacklist ${ASAN_RUNTIME_LIBRARIES})
149
Chandler Carruth821f21b2012-06-25 12:57:43 +0000150if(LLVM_INCLUDE_TESTS)
151 add_subdirectory(tests)
152endif()
Alexey Samsonov7274ff82012-07-31 15:43:11 +0000153
Alexey Samsonov7274ff82012-07-31 15:43:11 +0000154add_subdirectory(lit_tests)