1 # Build for the AddressSanitizer runtime support library.
4 # Don't set rpath for the ASan libraries. Developers are encouraged to ship
5 # their binaries together with the corresponding ASan runtime libraries,
6 # so they'll anyway need to fix the rpath and the install name.
7 set(CMAKE_BUILD_WITH_INSTALL_RPATH OFF)
32 include_directories(..)
35 include_directories(${COMPILER_RT_EXTRA_ANDROID_HEADERS})
38 set(ASAN_CFLAGS ${SANITIZER_COMMON_CFLAGS})
39 append_no_rtti_flag(ASAN_CFLAGS)
41 set(ASAN_COMMON_DEFINITIONS
42 ASAN_HAS_EXCEPTIONS=1)
45 list(APPEND ASAN_COMMON_DEFINITIONS
50 set(ASAN_ASM_SOURCES asan_asm_instrumentation.S)
51 set_source_files_properties(${ASAN_ASM_SOURCES} PROPERTIES LANGUAGE C)
52 list(APPEND ASAN_SOURCES ${ASAN_ASM_SOURCES})
55 # Compile ASan sources into an object library.
57 foreach(os ${SANITIZER_COMMON_SUPPORTED_DARWIN_OS})
58 add_compiler_rt_darwin_object_library(RTAsan ${os}
59 ARCH ${ASAN_SUPPORTED_ARCH}
60 SOURCES ${ASAN_SOURCES}
62 DEFS ${ASAN_COMMON_DEFINITIONS})
65 add_library(RTAsan.arm.android OBJECT ${ASAN_SOURCES})
66 set_target_compile_flags(RTAsan.arm.android ${ASAN_CFLAGS})
67 set_property(TARGET RTAsan.arm.android APPEND PROPERTY
68 COMPILE_DEFINITIONS ${ASAN_COMMON_DEFINITIONS})
70 foreach(arch ${ASAN_SUPPORTED_ARCH})
71 add_compiler_rt_object_library(RTAsan ${arch}
72 SOURCES ${ASAN_SOURCES} CFLAGS ${ASAN_CFLAGS}
73 DEFS ${ASAN_COMMON_DEFINITIONS})
77 # Build ASan runtimes shipped with Clang.
78 add_custom_target(asan)
80 foreach (os ${SANITIZER_COMMON_SUPPORTED_DARWIN_OS})
81 add_compiler_rt_darwin_dynamic_runtime(clang_rt.asan_${os}_dynamic ${os}
82 ARCH ${ASAN_SUPPORTED_ARCH}
83 SOURCES $<TARGET_OBJECTS:RTAsan.${os}>
84 $<TARGET_OBJECTS:RTInterception.${os}>
85 $<TARGET_OBJECTS:RTSanitizerCommon.${os}>
86 $<TARGET_OBJECTS:RTLSanCommon.${os}>
88 DEFS ${ASAN_COMMON_DEFINITIONS})
89 add_dependencies(asan clang_rt.asan_${os}_dynamic)
93 add_library(clang_rt.asan-arm-android SHARED
94 $<TARGET_OBJECTS:RTAsan.arm.android>
95 $<TARGET_OBJECTS:RTInterception.arm.android>
96 $<TARGET_OBJECTS:RTSanitizerCommon.arm.android>)
97 set_target_compile_flags(clang_rt.asan-arm-android
99 set_property(TARGET clang_rt.asan-arm-android APPEND PROPERTY
100 COMPILE_DEFINITIONS ${ASAN_COMMON_DEFINITIONS})
101 target_link_libraries(clang_rt.asan-arm-android dl log)
102 add_dependencies(asan clang_rt.asan-arm-android)
104 # Build separate libraries for each target.
105 foreach(arch ${ASAN_SUPPORTED_ARCH})
106 set(ASAN_RUNTIME_OBJECTS
107 $<TARGET_OBJECTS:RTAsan.${arch}>
108 $<TARGET_OBJECTS:RTInterception.${arch}>
109 $<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
110 $<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>)
112 # We can't build Leak Sanitizer on Windows yet.
113 list(APPEND ASAN_RUNTIME_OBJECTS $<TARGET_OBJECTS:RTLSanCommon.${arch}>)
116 add_compiler_rt_static_runtime(clang_rt.asan-${arch} ${arch}
117 SOURCES ${ASAN_RUNTIME_OBJECTS}
118 CFLAGS ${ASAN_CFLAGS}
119 DEFS ${ASAN_COMMON_DEFINITIONS})
120 add_dependencies(asan clang_rt.asan-${arch})
121 if (UNIX AND NOT ${arch} STREQUAL "i386")
122 add_sanitizer_rt_symbols(clang_rt.asan-${arch} asan.syms.extra)
123 add_dependencies(asan clang_rt.asan-${arch}-symbols)
127 add_compiler_rt_static_runtime(clang_rt.asan_dll_thunk-${arch} ${arch}
128 SOURCES asan_dll_thunk.cc
129 CFLAGS ${ASAN_CFLAGS} -DASAN_DLL_THUNK
130 DEFS ${ASAN_COMMON_DEFINITIONS})
131 add_dependencies(asan clang_rt.asan_dll_thunk-${arch})
136 add_compiler_rt_resource_file(asan_blacklist asan_blacklist.txt)
137 add_dependencies(asan asan_blacklist)
138 add_dependencies(compiler-rt asan)
140 add_subdirectory(scripts)
142 if(COMPILER_RT_INCLUDE_TESTS)
143 add_subdirectory(tests)