2012-04-05 06:12:04 +08:00
|
|
|
# Build for the AddressSanitizer runtime support library.
|
|
|
|
|
2014-02-25 19:54:25 +08:00
|
|
|
if(APPLE)
|
|
|
|
# Don't set rpath for the ASan libraries. Developers are encouraged to ship
|
|
|
|
# their binaries together with the corresponding ASan runtime libraries,
|
|
|
|
# so they'll anyway need to fix the rpath and the install name.
|
|
|
|
set(CMAKE_BUILD_WITH_INSTALL_RPATH OFF)
|
|
|
|
endif()
|
|
|
|
|
2012-06-20 18:18:43 +08:00
|
|
|
set(ASAN_SOURCES
|
2012-12-10 21:52:55 +08:00
|
|
|
asan_allocator2.cc
|
2014-01-16 20:31:50 +08:00
|
|
|
asan_activation.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(..)
|
|
|
|
|
2014-02-10 21:34:43 +08:00
|
|
|
if(ANDROID)
|
|
|
|
include_directories(${COMPILER_RT_EXTRA_ANDROID_HEADERS})
|
|
|
|
endif()
|
|
|
|
|
2014-02-18 15:52:40 +08:00
|
|
|
set(ASAN_CFLAGS ${SANITIZER_COMMON_CFLAGS})
|
|
|
|
append_no_rtti_flag(ASAN_CFLAGS)
|
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
|
|
|
|
2014-01-28 22:17:16 +08:00
|
|
|
if(ANDROID)
|
|
|
|
list(APPEND ASAN_COMMON_DEFINITIONS
|
|
|
|
ASAN_LOW_MEMORY=1)
|
|
|
|
endif()
|
|
|
|
|
2014-02-19 16:30:39 +08:00
|
|
|
if (NOT MSVC)
|
|
|
|
set(ASAN_ASM_SOURCES asan_asm_instrumentation.S)
|
|
|
|
set_source_files_properties(${ASAN_ASM_SOURCES} PROPERTIES LANGUAGE C)
|
|
|
|
list(APPEND ASAN_SOURCES ${ASAN_ASM_SOURCES})
|
|
|
|
endif()
|
|
|
|
|
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.
|
2014-02-14 22:45:13 +08:00
|
|
|
add_custom_target(asan)
|
2012-08-10 22:45:52 +08:00
|
|
|
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})
|
2014-02-14 22:45:13 +08:00
|
|
|
add_dependencies(asan clang_rt.asan_${os}_dynamic)
|
2013-11-07 18:08:19 +08:00
|
|
|
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})
|
2014-01-23 19:34:41 +08:00
|
|
|
target_link_libraries(clang_rt.asan-arm-android dl log)
|
2014-02-14 22:45:13 +08:00
|
|
|
add_dependencies(asan 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}>)
|
2013-11-17 18:12:23 +08:00
|
|
|
if (NOT WIN32)
|
2013-08-27 09:24:01 +08:00
|
|
|
# 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})
|
2014-02-14 22:45:13 +08:00
|
|
|
add_dependencies(asan clang_rt.asan-${arch})
|
2013-08-28 16:07:04 +08:00
|
|
|
if (UNIX AND NOT ${arch} STREQUAL "i386")
|
|
|
|
add_sanitizer_rt_symbols(clang_rt.asan-${arch} asan.syms.extra)
|
2014-02-14 22:45:13 +08:00
|
|
|
add_dependencies(asan clang_rt.asan-${arch}-symbols)
|
2013-08-28 16:07:04 +08:00
|
|
|
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})
|
2014-02-14 22:45:13 +08:00
|
|
|
add_dependencies(asan clang_rt.asan_dll_thunk-${arch})
|
2013-08-27 09:24:01 +08:00
|
|
|
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)
|
2014-02-14 22:45:13 +08:00
|
|
|
add_dependencies(asan asan_blacklist)
|
2014-02-18 17:33:45 +08:00
|
|
|
add_dependencies(compiler-rt asan)
|
2013-11-14 20:24:12 +08:00
|
|
|
|
2014-02-19 19:18:47 +08:00
|
|
|
if(COMPILER_RT_INCLUDE_TESTS)
|
2012-06-25 20:57:43 +08:00
|
|
|
add_subdirectory(tests)
|
|
|
|
endif()
|