2012-04-05 06:12:04 +08:00
|
|
|
# Build for the AddressSanitizer runtime support library.
|
|
|
|
|
2012-06-20 18:18:43 +08:00
|
|
|
set(ASAN_SOURCES
|
2012-12-10 21:52:55 +08:00
|
|
|
asan_allocator2.cc
|
2012-12-10 22:19:15 +08:00
|
|
|
asan_fake_stack.cc
|
2012-06-20 18:18:43 +08:00
|
|
|
asan_globals.cc
|
|
|
|
asan_interceptors.cc
|
|
|
|
asan_linux.cc
|
|
|
|
asan_mac.cc
|
|
|
|
asan_malloc_linux.cc
|
|
|
|
asan_malloc_mac.cc
|
|
|
|
asan_malloc_win.cc
|
|
|
|
asan_new_delete.cc
|
|
|
|
asan_poisoning.cc
|
|
|
|
asan_posix.cc
|
2013-02-22 15:51:26 +08:00
|
|
|
asan_preinit.cc
|
2012-08-09 16:15:46 +08:00
|
|
|
asan_report.cc
|
2012-06-20 18:18:43 +08:00
|
|
|
asan_rtl.cc
|
|
|
|
asan_stack.cc
|
|
|
|
asan_stats.cc
|
|
|
|
asan_thread.cc
|
2013-06-23 00:33:52 +08:00
|
|
|
asan_win.cc)
|
2012-04-05 06:12:04 +08:00
|
|
|
|
2012-06-25 20:57:43 +08:00
|
|
|
include_directories(..)
|
|
|
|
|
2013-08-27 09:24:01 +08:00
|
|
|
if (NOT MSVC)
|
|
|
|
set(ASAN_CFLAGS
|
|
|
|
${SANITIZER_COMMON_CFLAGS}
|
|
|
|
-fno-rtti)
|
|
|
|
else()
|
|
|
|
set(ASAN_CFLAGS
|
|
|
|
${SANITIZER_COMMON_CFLAGS}
|
|
|
|
/GR-)
|
|
|
|
endif()
|
2012-09-05 17:00:03 +08:00
|
|
|
|
2013-01-21 16:24:19 +08:00
|
|
|
set(ASAN_COMMON_DEFINITIONS
|
2013-01-22 15:21:24 +08:00
|
|
|
ASAN_HAS_EXCEPTIONS=1)
|
2013-01-21 16:24:19 +08:00
|
|
|
|
2012-09-11 19:55:45 +08:00
|
|
|
if(ANDROID)
|
2013-01-21 16:24:19 +08:00
|
|
|
list(APPEND ASAN_COMMON_DEFINITIONS
|
2013-01-22 15:21:24 +08:00
|
|
|
ASAN_FLEXIBLE_MAPPING_AND_OFFSET=0
|
2012-09-11 19:55:45 +08:00
|
|
|
ASAN_NEEDS_SEGV=0
|
2013-01-21 16:24:19 +08:00
|
|
|
ASAN_LOW_MEMORY=1)
|
2013-08-27 09:24:01 +08:00
|
|
|
elseif(MSVC)
|
|
|
|
list(APPEND ASAN_COMMON_DEFINITIONS
|
|
|
|
ASAN_FLEXIBLE_MAPPING_AND_OFFSET=0
|
|
|
|
ASAN_NEEDS_SEGV=0)
|
2012-09-11 19:55:45 +08:00
|
|
|
else()
|
2013-01-21 16:24:19 +08:00
|
|
|
list(APPEND ASAN_COMMON_DEFINITIONS
|
2013-01-22 15:21:24 +08:00
|
|
|
ASAN_FLEXIBLE_MAPPING_AND_OFFSET=1
|
2013-01-21 16:24:19 +08:00
|
|
|
ASAN_NEEDS_SEGV=1)
|
2012-09-11 19:55:45 +08:00
|
|
|
endif()
|
2012-08-17 17:00:08 +08:00
|
|
|
|
2013-01-19 00:51:07 +08:00
|
|
|
# Architectures supported by ASan.
|
|
|
|
filter_available_targets(ASAN_SUPPORTED_ARCH
|
2013-06-07 17:44:43 +08:00
|
|
|
x86_64 i386 powerpc64)
|
2013-01-19 00:51:07 +08:00
|
|
|
|
2013-09-16 23:50:53 +08:00
|
|
|
# Compile ASan sources into an object library.
|
|
|
|
if(APPLE)
|
2013-11-07 18:08:19 +08:00
|
|
|
foreach(os ${SANITIZER_COMMON_SUPPORTED_DARWIN_OS})
|
|
|
|
add_compiler_rt_darwin_object_library(RTAsan ${os}
|
|
|
|
ARCH ${ASAN_SUPPORTED_ARCH}
|
|
|
|
SOURCES ${ASAN_SOURCES}
|
|
|
|
CFLAGS ${ASAN_CFLAGS}
|
|
|
|
DEFS ${ASAN_COMMON_DEFINITIONS})
|
|
|
|
endforeach()
|
2013-09-16 23:50:53 +08:00
|
|
|
elseif(ANDROID)
|
|
|
|
add_library(RTAsan.arm.android OBJECT ${ASAN_SOURCES})
|
|
|
|
set_target_compile_flags(RTAsan.arm.android ${ASAN_CFLAGS})
|
|
|
|
set_property(TARGET RTAsan.arm.android APPEND PROPERTY
|
|
|
|
COMPILE_DEFINITIONS ${ASAN_COMMON_DEFINITIONS})
|
|
|
|
else()
|
|
|
|
foreach(arch ${ASAN_SUPPORTED_ARCH})
|
|
|
|
add_compiler_rt_object_library(RTAsan ${arch}
|
|
|
|
SOURCES ${ASAN_SOURCES} CFLAGS ${ASAN_CFLAGS}
|
|
|
|
DEFS ${ASAN_COMMON_DEFINITIONS})
|
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Build ASan runtimes shipped with Clang.
|
2012-08-10 22:45:52 +08:00
|
|
|
set(ASAN_RUNTIME_LIBRARIES)
|
|
|
|
if(APPLE)
|
2013-11-07 18:08:19 +08:00
|
|
|
foreach (os ${SANITIZER_COMMON_SUPPORTED_DARWIN_OS})
|
2013-01-22 17:14:54 +08:00
|
|
|
# Dynamic lookup is needed because shadow scale and offset are
|
|
|
|
# provided by the instrumented modules.
|
2013-11-07 18:08:19 +08:00
|
|
|
set(ASAN_RUNTIME_LDFLAGS
|
|
|
|
"-undefined dynamic_lookup")
|
|
|
|
add_compiler_rt_darwin_dynamic_runtime(clang_rt.asan_${os}_dynamic ${os}
|
|
|
|
ARCH ${ASAN_SUPPORTED_ARCH}
|
|
|
|
SOURCES $<TARGET_OBJECTS:RTAsan.${os}>
|
|
|
|
$<TARGET_OBJECTS:RTInterception.${os}>
|
|
|
|
$<TARGET_OBJECTS:RTSanitizerCommon.${os}>
|
|
|
|
$<TARGET_OBJECTS:RTLSanCommon.${os}>
|
|
|
|
CFLAGS ${ASAN_CFLAGS}
|
|
|
|
DEFS ${ASAN_COMMON_DEFINITIONS}
|
|
|
|
LINKFLAGS ${ASAN_RUNTIME_LDFLAGS})
|
|
|
|
list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan_${os}_dynamic)
|
|
|
|
endforeach()
|
|
|
|
|
2012-09-11 19:55:45 +08:00
|
|
|
elseif(ANDROID)
|
|
|
|
add_library(clang_rt.asan-arm-android SHARED
|
2013-09-16 23:50:53 +08:00
|
|
|
$<TARGET_OBJECTS:RTAsan.arm.android>
|
2012-09-11 19:55:45 +08:00
|
|
|
$<TARGET_OBJECTS:RTInterception.arm.android>
|
2013-09-16 23:50:53 +08:00
|
|
|
$<TARGET_OBJECTS:RTSanitizerCommon.arm.android>)
|
2012-09-11 19:55:45 +08:00
|
|
|
set_target_compile_flags(clang_rt.asan-arm-android
|
2013-01-21 16:12:20 +08:00
|
|
|
${ASAN_CFLAGS})
|
|
|
|
set_property(TARGET clang_rt.asan-arm-android APPEND PROPERTY
|
|
|
|
COMPILE_DEFINITIONS ${ASAN_COMMON_DEFINITIONS})
|
2012-09-11 19:55:45 +08:00
|
|
|
target_link_libraries(clang_rt.asan-arm-android dl)
|
|
|
|
list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-arm-android)
|
2012-08-10 22:45:52 +08:00
|
|
|
else()
|
2013-09-16 23:50:53 +08:00
|
|
|
# Build separate libraries for each target.
|
2013-01-19 00:51:07 +08:00
|
|
|
foreach(arch ${ASAN_SUPPORTED_ARCH})
|
2013-09-16 23:50:53 +08:00
|
|
|
set(ASAN_RUNTIME_OBJECTS
|
|
|
|
$<TARGET_OBJECTS:RTAsan.${arch}>
|
2013-08-27 09:24:01 +08:00
|
|
|
$<TARGET_OBJECTS:RTInterception.${arch}>
|
|
|
|
$<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
|
|
|
|
$<TARGET_OBJECTS:RTSanitizerCommonLibc.${arch}>)
|
|
|
|
if (NOT MSVC)
|
|
|
|
# We can't build Leak Sanitizer on Windows yet.
|
2013-09-16 23:50:53 +08:00
|
|
|
list(APPEND ASAN_RUNTIME_OBJECTS $<TARGET_OBJECTS:RTLSanCommon.${arch}>)
|
2013-08-27 09:24:01 +08:00
|
|
|
endif()
|
|
|
|
|
2013-01-21 16:12:20 +08:00
|
|
|
add_compiler_rt_static_runtime(clang_rt.asan-${arch} ${arch}
|
2013-09-16 23:50:53 +08:00
|
|
|
SOURCES ${ASAN_RUNTIME_OBJECTS}
|
2013-01-21 16:12:20 +08:00
|
|
|
CFLAGS ${ASAN_CFLAGS}
|
2013-08-27 23:08:02 +08:00
|
|
|
DEFS ${ASAN_COMMON_DEFINITIONS})
|
2013-08-28 16:07:04 +08:00
|
|
|
list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-${arch})
|
|
|
|
if (UNIX AND NOT ${arch} STREQUAL "i386")
|
|
|
|
add_sanitizer_rt_symbols(clang_rt.asan-${arch} asan.syms.extra)
|
|
|
|
list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-${arch}-symbols)
|
|
|
|
endif()
|
2013-08-27 09:24:01 +08:00
|
|
|
|
|
|
|
if (WIN32)
|
|
|
|
add_compiler_rt_static_runtime(clang_rt.asan_dll_thunk-${arch} ${arch}
|
|
|
|
SOURCES asan_dll_thunk.cc
|
|
|
|
CFLAGS ${ASAN_CFLAGS} -DASAN_DLL_THUNK
|
2013-08-27 23:08:02 +08:00
|
|
|
DEFS ${ASAN_COMMON_DEFINITIONS})
|
2013-08-27 09:24:01 +08:00
|
|
|
list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan_dll_thunk-${arch})
|
|
|
|
endif()
|
2013-01-19 00:51:07 +08:00
|
|
|
endforeach()
|
2012-04-05 06:12:04 +08:00
|
|
|
endif()
|
2012-06-25 20:57:43 +08:00
|
|
|
|
2013-05-21 21:48:27 +08:00
|
|
|
add_compiler_rt_resource_file(asan_blacklist asan_blacklist.txt)
|
|
|
|
|
2012-06-25 20:57:43 +08:00
|
|
|
if(LLVM_INCLUDE_TESTS)
|
|
|
|
add_subdirectory(tests)
|
|
|
|
endif()
|
2012-07-31 23:43:11 +08:00
|
|
|
|
|
|
|
add_subdirectory(lit_tests)
|