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
|
2014-12-17 08:26:50 +08:00
|
|
|
asan_allocator.cc
|
2014-01-16 20:31:50 +08:00
|
|
|
asan_activation.cc
|
2014-07-16 01:33:23 +08:00
|
|
|
asan_debugging.cc
|
2012-12-10 22:19:15 +08:00
|
|
|
asan_fake_stack.cc
|
2014-12-18 03:31:39 +08:00
|
|
|
asan_flags.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_poisoning.cc
|
|
|
|
asan_posix.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
|
2014-12-06 04:26:09 +08:00
|
|
|
asan_suppressions.cc
|
2012-06-20 18:18:43 +08:00
|
|
|
asan_thread.cc
|
2013-06-23 00:33:52 +08:00
|
|
|
asan_win.cc)
|
2012-04-05 06:12:04 +08:00
|
|
|
|
2014-05-13 02:39:22 +08:00
|
|
|
set(ASAN_CXX_SOURCES
|
|
|
|
asan_new_delete.cc)
|
|
|
|
|
2014-04-01 21:16:30 +08:00
|
|
|
set(ASAN_PREINIT_SOURCES
|
|
|
|
asan_preinit.cc)
|
|
|
|
|
2012-06-25 20:57:43 +08:00
|
|
|
include_directories(..)
|
|
|
|
|
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
|
|
|
|
2015-05-06 04:13:39 +08:00
|
|
|
set(ASAN_DYNAMIC_LINK_FLAGS)
|
|
|
|
|
2014-01-28 22:17:16 +08:00
|
|
|
if(ANDROID)
|
|
|
|
list(APPEND ASAN_COMMON_DEFINITIONS
|
|
|
|
ASAN_LOW_MEMORY=1)
|
2015-05-06 04:13:39 +08:00
|
|
|
# On Android, -z global does not do what it is documented to do.
|
|
|
|
# On Android, -z global moves the library ahead in the lookup order,
|
|
|
|
# placing it right after the LD_PRELOADs. This is used to compensate for the fact
|
|
|
|
# that Android linker does not look at the dependencies of the main executable
|
|
|
|
# that aren't dependencies of the current DSO when resolving symbols from said DSO.
|
|
|
|
# As a net result, this allows running ASan executables without LD_PRELOAD-ing the
|
|
|
|
# ASan runtime library.
|
|
|
|
# The above is applicable to L MR1 or newer.
|
|
|
|
if (COMPILER_RT_HAS_Z_GLOBAL)
|
|
|
|
list(APPEND ASAN_DYNAMIC_LINK_FLAGS -Wl,-z,global)
|
|
|
|
endif()
|
2014-01-28 22:17:16 +08:00
|
|
|
endif()
|
|
|
|
|
2014-04-01 21:16:30 +08:00
|
|
|
set(ASAN_DYNAMIC_DEFINITIONS
|
|
|
|
${ASAN_COMMON_DEFINITIONS} ASAN_DYNAMIC=1)
|
2014-10-16 06:47:54 +08:00
|
|
|
append_list_if(WIN32 INTERCEPTION_DYNAMIC_CRT ASAN_DYNAMIC_DEFINITIONS)
|
2014-08-25 21:19:05 +08:00
|
|
|
|
2014-04-01 21:16:30 +08:00
|
|
|
set(ASAN_DYNAMIC_CFLAGS ${ASAN_CFLAGS})
|
2014-10-16 06:47:54 +08:00
|
|
|
append_list_if(COMPILER_RT_HAS_FTLS_MODEL_INITIAL_EXEC
|
2014-04-01 21:16:30 +08:00
|
|
|
-ftls-model=initial-exec ASAN_DYNAMIC_CFLAGS)
|
2014-10-16 06:47:54 +08:00
|
|
|
append_list_if(MSVC /DEBUG ASAN_DYNAMIC_CFLAGS)
|
2014-04-01 21:16:30 +08:00
|
|
|
|
2014-10-16 06:47:54 +08:00
|
|
|
append_list_if(COMPILER_RT_HAS_LIBC c ASAN_DYNAMIC_LIBS)
|
|
|
|
append_list_if(COMPILER_RT_HAS_LIBDL dl ASAN_DYNAMIC_LIBS)
|
2015-05-30 06:31:28 +08:00
|
|
|
append_list_if(COMPILER_RT_HAS_LIBRT rt ASAN_DYNAMIC_LIBS)
|
2014-10-16 06:47:54 +08:00
|
|
|
append_list_if(COMPILER_RT_HAS_LIBM m ASAN_DYNAMIC_LIBS)
|
|
|
|
append_list_if(COMPILER_RT_HAS_LIBPTHREAD pthread ASAN_DYNAMIC_LIBS)
|
|
|
|
append_list_if(COMPILER_RT_HAS_LIBSTDCXX stdc++ ASAN_DYNAMIC_LIBS)
|
2015-07-25 03:00:16 +08:00
|
|
|
append_list_if(COMPILER_RT_HAS_LIBLOG log ASAN_DYNAMIC_LIBS)
|
2014-09-29 21:18:55 +08:00
|
|
|
|
2013-09-16 23:50:53 +08:00
|
|
|
# Compile ASan sources into an object library.
|
2015-08-27 02:33:51 +08:00
|
|
|
|
|
|
|
add_compiler_rt_object_libraries(RTAsan_dynamic
|
|
|
|
OS ${SANITIZER_COMMON_SUPPORTED_OS}
|
|
|
|
ARCHS ${ASAN_SUPPORTED_ARCH}
|
|
|
|
SOURCES ${ASAN_SOURCES} ${ASAN_CXX_SOURCES}
|
|
|
|
CFLAGS ${ASAN_DYNAMIC_CFLAGS}
|
|
|
|
DEFS ${ASAN_DYNAMIC_DEFINITIONS})
|
|
|
|
|
|
|
|
if(NOT APPLE)
|
2015-06-11 07:55:07 +08:00
|
|
|
add_compiler_rt_object_libraries(RTAsan
|
2015-06-19 11:39:24 +08:00
|
|
|
ARCHS ${ASAN_SUPPORTED_ARCH}
|
2015-06-11 07:55:07 +08:00
|
|
|
SOURCES ${ASAN_SOURCES} CFLAGS ${ASAN_CFLAGS}
|
|
|
|
DEFS ${ASAN_COMMON_DEFINITIONS})
|
|
|
|
add_compiler_rt_object_libraries(RTAsan_cxx
|
2015-06-19 11:39:24 +08:00
|
|
|
ARCHS ${ASAN_SUPPORTED_ARCH}
|
2015-06-11 07:55:07 +08:00
|
|
|
SOURCES ${ASAN_CXX_SOURCES} CFLAGS ${ASAN_CFLAGS}
|
|
|
|
DEFS ${ASAN_COMMON_DEFINITIONS})
|
|
|
|
add_compiler_rt_object_libraries(RTAsan_preinit
|
2015-06-19 11:39:24 +08:00
|
|
|
ARCHS ${ASAN_SUPPORTED_ARCH}
|
2015-06-11 07:55:07 +08:00
|
|
|
SOURCES ${ASAN_PREINIT_SOURCES} CFLAGS ${ASAN_CFLAGS}
|
|
|
|
DEFS ${ASAN_COMMON_DEFINITIONS})
|
2015-05-28 06:38:01 +08:00
|
|
|
|
2015-06-11 07:55:07 +08:00
|
|
|
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy.cc "")
|
|
|
|
add_compiler_rt_object_libraries(RTAsan_dynamic_version_script_dummy
|
2015-06-19 11:39:24 +08:00
|
|
|
ARCHS ${ASAN_SUPPORTED_ARCH}
|
2015-06-11 07:55:07 +08:00
|
|
|
SOURCES ${CMAKE_CURRENT_BINARY_DIR}/dummy.cc
|
|
|
|
CFLAGS ${ASAN_DYNAMIC_CFLAGS}
|
|
|
|
DEFS ${ASAN_DYNAMIC_DEFINITIONS})
|
2013-09-16 23:50:53 +08:00
|
|
|
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)
|
2015-08-27 02:33:51 +08:00
|
|
|
add_compiler_rt_runtime(clang_rt.asan
|
|
|
|
SHARED
|
|
|
|
OS ${SANITIZER_COMMON_SUPPORTED_OS}
|
|
|
|
ARCHS ${ASAN_SUPPORTED_ARCH}
|
|
|
|
OBJECT_LIBS RTAsan_dynamic
|
|
|
|
RTInterception
|
|
|
|
RTSanitizerCommon
|
|
|
|
RTLSanCommon
|
|
|
|
RTUbsan
|
|
|
|
CFLAGS ${ASAN_DYNAMIC_CFLAGS}
|
|
|
|
DEFS ${ASAN_DYNAMIC_DEFINITIONS}
|
|
|
|
PARENT_TARGET asan)
|
2012-08-10 22:45:52 +08:00
|
|
|
else()
|
2013-09-16 23:50:53 +08:00
|
|
|
# Build separate libraries for each target.
|
2015-08-27 02:33:51 +08:00
|
|
|
|
|
|
|
set(ASAN_COMMON_RUNTIME_OBJECT_LIBS
|
|
|
|
RTInterception
|
|
|
|
RTSanitizerCommon
|
|
|
|
RTSanitizerCommonLibc
|
|
|
|
RTLSanCommon
|
|
|
|
RTUbsan)
|
2013-08-27 09:24:01 +08:00
|
|
|
|
2015-08-26 03:53:09 +08:00
|
|
|
add_compiler_rt_runtime(clang_rt.asan
|
|
|
|
STATIC
|
2015-08-27 02:33:51 +08:00
|
|
|
ARCHS ${ASAN_SUPPORTED_ARCH}
|
|
|
|
OBJECT_LIBS RTAsan_preinit
|
|
|
|
RTAsan
|
|
|
|
${ASAN_COMMON_RUNTIME_OBJECT_LIBS}
|
2013-01-21 16:12:20 +08:00
|
|
|
CFLAGS ${ASAN_CFLAGS}
|
2015-08-26 03:53:09 +08:00
|
|
|
DEFS ${ASAN_COMMON_DEFINITIONS}
|
|
|
|
PARENT_TARGET asan)
|
2014-04-01 21:16:30 +08:00
|
|
|
|
2015-08-26 03:53:09 +08:00
|
|
|
add_compiler_rt_runtime(clang_rt.asan_cxx
|
|
|
|
STATIC
|
2015-08-27 02:33:51 +08:00
|
|
|
ARCHS ${ASAN_SUPPORTED_ARCH}
|
|
|
|
OBJECT_LIBS RTAsan_cxx
|
|
|
|
RTUbsan_cxx
|
2014-05-13 02:39:22 +08:00
|
|
|
CFLAGS ${ASAN_CFLAGS}
|
2015-08-26 03:53:09 +08:00
|
|
|
DEFS ${ASAN_COMMON_DEFINITIONS}
|
|
|
|
PARENT_TARGET asan)
|
2014-05-13 02:39:22 +08:00
|
|
|
|
2015-08-26 03:53:09 +08:00
|
|
|
add_compiler_rt_runtime(clang_rt.asan-preinit
|
|
|
|
STATIC
|
2015-08-27 02:33:51 +08:00
|
|
|
ARCHS ${ASAN_SUPPORTED_ARCH}
|
|
|
|
OBJECT_LIBS RTAsan_preinit
|
2014-12-18 07:14:01 +08:00
|
|
|
CFLAGS ${ASAN_CFLAGS}
|
2015-08-26 03:53:09 +08:00
|
|
|
DEFS ${ASAN_COMMON_DEFINITIONS}
|
|
|
|
PARENT_TARGET asan)
|
2014-12-18 07:14:01 +08:00
|
|
|
|
2015-08-27 02:33:51 +08:00
|
|
|
foreach(arch ${ASAN_SUPPORTED_ARCH})
|
2015-05-06 06:51:35 +08:00
|
|
|
if (UNIX AND NOT ${arch} MATCHES "i386|i686")
|
|
|
|
add_sanitizer_rt_version_list(clang_rt.asan-dynamic-${arch}
|
2015-06-19 11:39:24 +08:00
|
|
|
LIBS clang_rt.asan-${arch} clang_rt.asan_cxx-${arch}
|
2015-05-06 06:51:35 +08:00
|
|
|
EXTRA asan.syms.extra)
|
2015-05-06 07:13:50 +08:00
|
|
|
set(VERSION_SCRIPT_FLAG
|
2015-05-06 06:51:35 +08:00
|
|
|
-Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/clang_rt.asan-dynamic-${arch}.vers)
|
2015-05-28 06:38:01 +08:00
|
|
|
set_source_files_properties(
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/dummy.cc
|
|
|
|
PROPERTIES
|
|
|
|
OBJECT_DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/clang_rt.asan-dynamic-${arch}.vers)
|
2015-05-06 07:13:50 +08:00
|
|
|
else()
|
|
|
|
set(VERSION_SCRIPT_FLAG)
|
2015-05-06 06:51:35 +08:00
|
|
|
endif()
|
|
|
|
|
2015-08-26 03:53:09 +08:00
|
|
|
add_compiler_rt_runtime(clang_rt.asan
|
|
|
|
SHARED
|
|
|
|
ARCHS ${arch}
|
2015-08-27 02:33:51 +08:00
|
|
|
OBJECT_LIBS ${ASAN_COMMON_RUNTIME_OBJECT_LIBS}
|
|
|
|
RTAsan_dynamic
|
2015-05-28 06:38:01 +08:00
|
|
|
# The only purpose of RTAsan_dynamic_version_script_dummy is to carry
|
|
|
|
# a dependency of the shared runtime on the version script. With CMake
|
|
|
|
# 3.1 or later it can be replaced with a straightforward
|
|
|
|
# add_dependencies(clang_rt.asan-dynamic-${arch} clang_rt.asan-dynamic-${arch}-version-list)
|
2015-08-27 02:33:51 +08:00
|
|
|
RTAsan_dynamic_version_script_dummy
|
|
|
|
RTUbsan_cxx
|
2014-12-18 07:14:01 +08:00
|
|
|
CFLAGS ${ASAN_DYNAMIC_CFLAGS}
|
2015-05-06 04:13:39 +08:00
|
|
|
LINKFLAGS ${ASAN_DYNAMIC_LINK_FLAGS}
|
2015-05-06 07:13:50 +08:00
|
|
|
${VERSION_SCRIPT_FLAG}
|
2015-08-26 04:00:35 +08:00
|
|
|
LINK_LIBS ${ASAN_DYNAMIC_LIBS}
|
2015-08-26 03:53:09 +08:00
|
|
|
DEFS ${ASAN_DYNAMIC_DEFINITIONS}
|
|
|
|
PARENT_TARGET asan)
|
2014-04-01 21:16:30 +08:00
|
|
|
|
2015-02-27 05:03:41 +08:00
|
|
|
if (UNIX AND NOT ${arch} MATCHES "i386|i686")
|
2014-05-13 02:39:22 +08:00
|
|
|
add_sanitizer_rt_symbols(clang_rt.asan_cxx-${arch})
|
|
|
|
add_dependencies(asan clang_rt.asan_cxx-${arch}-symbols)
|
2013-08-28 16:07:04 +08:00
|
|
|
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)
|
2015-08-26 03:53:09 +08:00
|
|
|
add_compiler_rt_runtime(clang_rt.asan_dll_thunk
|
|
|
|
STATIC
|
|
|
|
ARCHS ${arch}
|
2014-08-26 18:21:37 +08:00
|
|
|
SOURCES asan_win_dll_thunk.cc
|
2014-05-20 22:26:19 +08:00
|
|
|
$<TARGET_OBJECTS:RTInterception.${arch}>
|
2014-07-15 16:16:04 +08:00
|
|
|
CFLAGS ${ASAN_CFLAGS} -DASAN_DLL_THUNK
|
2015-08-26 03:53:09 +08:00
|
|
|
DEFS ${ASAN_COMMON_DEFINITIONS}
|
|
|
|
PARENT_TARGET asan)
|
|
|
|
add_compiler_rt_runtime(clang_rt.asan_dynamic_runtime_thunk
|
2014-09-12 21:21:02 +08:00
|
|
|
STATIC
|
2015-08-26 03:53:09 +08:00
|
|
|
ARCHS ${arch}
|
2014-09-12 21:21:02 +08:00
|
|
|
SOURCES asan_win_dynamic_runtime_thunk.cc
|
|
|
|
CFLAGS ${ASAN_CFLAGS} -DASAN_DYNAMIC_RUNTIME_THUNK -Zl
|
2015-08-26 03:53:09 +08:00
|
|
|
DEFS ${ASAN_COMMON_DEFINITIONS}
|
|
|
|
PARENT_TARGET asan)
|
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-27 16:41:40 +08:00
|
|
|
add_subdirectory(scripts)
|
|
|
|
|
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()
|