1 # Build for the AddressSanitizer runtime support library.
25 include_directories(..)
29 ${SANITIZER_COMMON_CFLAGS}
33 ${SANITIZER_COMMON_CFLAGS}
37 set(ASAN_COMMON_DEFINITIONS
38 ASAN_HAS_EXCEPTIONS=1)
41 list(APPEND ASAN_COMMON_DEFINITIONS
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.
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}
56 DEFS ${ASAN_COMMON_DEFINITIONS})
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})
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})
71 # Build ASan runtimes shipped with Clang.
72 set(ASAN_RUNTIME_LIBRARIES)
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}>
86 DEFS ${ASAN_COMMON_DEFINITIONS}
87 LINKFLAGS ${ASAN_RUNTIME_LDFLAGS})
88 list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan_${os}_dynamic)
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
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)
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}>)
111 # We can't build Leak Sanitizer on Windows yet.
112 list(APPEND ASAN_RUNTIME_OBJECTS $<TARGET_OBJECTS:RTLSanCommon.${arch}>)
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)
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})
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)
145 add_subdirectory(lit_tests)