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_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
|
|
|
|
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-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-04-01 21:16:30 +08:00
|
|
|
set(ASAN_DYNAMIC_DEFINITIONS
|
|
|
|
${ASAN_COMMON_DEFINITIONS} ASAN_DYNAMIC=1)
|
|
|
|
|
|
|
|
set(ASAN_DYNAMIC_CFLAGS ${ASAN_CFLAGS})
|
|
|
|
append_if(COMPILER_RT_HAS_FTLS_MODEL_INITIAL_EXEC
|
|
|
|
-ftls-model=initial-exec ASAN_DYNAMIC_CFLAGS)
|
|
|
|
|
|
|
|
set(ASAN_DYNAMIC_LIBS stdc++ m c)
|
|
|
|
append_if(COMPILER_RT_HAS_LIBPTHREAD pthread ASAN_DYNAMIC_LIBS)
|
|
|
|
append_if(COMPILER_RT_HAS_LIBDL dl ASAN_DYNAMIC_LIBS)
|
|
|
|
|
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}
|
2014-05-13 02:39:22 +08:00
|
|
|
SOURCES ${ASAN_SOURCES} ${ASAN_CXX_SOURCES}
|
2013-11-07 18:08:19 +08:00
|
|
|
CFLAGS ${ASAN_CFLAGS}
|
|
|
|
DEFS ${ASAN_COMMON_DEFINITIONS})
|
|
|
|
endforeach()
|
2013-09-16 23:50:53 +08:00
|
|
|
elseif(ANDROID)
|
2014-05-13 02:39:22 +08:00
|
|
|
add_library(RTAsan.arm.android OBJECT ${ASAN_SOURCES} ${ASAN_CXX_SOURCES})
|
2013-09-16 23:50:53 +08:00
|
|
|
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})
|
2014-05-13 02:39:22 +08:00
|
|
|
add_compiler_rt_object_library(RTAsan_cxx ${arch}
|
|
|
|
SOURCES ${ASAN_CXX_SOURCES} CFLAGS ${ASAN_CFLAGS}
|
|
|
|
DEFS ${ASAN_COMMON_DEFINITIONS})
|
2014-04-01 21:16:30 +08:00
|
|
|
add_compiler_rt_object_library(RTAsan_preinit ${arch}
|
|
|
|
SOURCES ${ASAN_PREINIT_SOURCES} CFLAGS ${ASAN_CFLAGS}
|
|
|
|
DEFS ${ASAN_COMMON_DEFINITIONS})
|
|
|
|
if (COMPILER_RT_BUILD_SHARED_ASAN)
|
|
|
|
add_compiler_rt_object_library(RTAsan_dynamic ${arch}
|
2014-05-13 02:39:22 +08:00
|
|
|
SOURCES ${ASAN_SOURCES} ${ASAN_CXX_SOURCES}
|
|
|
|
CFLAGS ${ASAN_DYNAMIC_CFLAGS}
|
2014-04-01 21:16:30 +08:00
|
|
|
DEFS ${ASAN_DYNAMIC_DEFINITIONS})
|
|
|
|
endif()
|
2013-09-16 23:50:53 +08:00
|
|
|
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})
|
|
|
|
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}
|
2014-03-14 18:16:59 +08:00
|
|
|
DEFS ${ASAN_COMMON_DEFINITIONS})
|
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})
|
2014-04-01 21:16:30 +08:00
|
|
|
set(ASAN_COMMON_RUNTIME_OBJECTS
|
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.
|
2014-04-01 21:16:30 +08:00
|
|
|
list(APPEND ASAN_COMMON_RUNTIME_OBJECTS
|
|
|
|
$<TARGET_OBJECTS:RTLSanCommon.${arch}>)
|
2013-08-27 09:24:01 +08:00
|
|
|
endif()
|
|
|
|
|
2014-03-31 21:45:36 +08:00
|
|
|
add_compiler_rt_runtime(clang_rt.asan-${arch} ${arch} STATIC
|
2014-04-01 21:16:30 +08:00
|
|
|
SOURCES $<TARGET_OBJECTS:RTAsan_preinit.${arch}>
|
|
|
|
$<TARGET_OBJECTS:RTAsan.${arch}>
|
|
|
|
${ASAN_COMMON_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})
|
2014-04-01 21:16:30 +08:00
|
|
|
|
2014-05-13 02:39:22 +08:00
|
|
|
add_compiler_rt_runtime(clang_rt.asan_cxx-${arch} ${arch} STATIC
|
|
|
|
SOURCES $<TARGET_OBJECTS:RTAsan_cxx.${arch}>
|
|
|
|
CFLAGS ${ASAN_CFLAGS}
|
|
|
|
DEFS ${ASAN_COMMON_DEFINITIONS})
|
|
|
|
add_dependencies(asan clang_rt.asan_cxx-${arch})
|
|
|
|
|
2014-04-01 21:16:30 +08:00
|
|
|
if (COMPILER_RT_BUILD_SHARED_ASAN)
|
|
|
|
add_compiler_rt_runtime(clang_rt.asan-preinit-${arch} ${arch} STATIC
|
|
|
|
SOURCES $<TARGET_OBJECTS:RTAsan_preinit.${arch}>
|
|
|
|
CFLAGS ${ASAN_CFLAGS}
|
|
|
|
DEFS ${ASAN_COMMON_DEFINITIONS})
|
|
|
|
add_dependencies(asan clang_rt.asan-preinit-${arch})
|
|
|
|
|
|
|
|
add_compiler_rt_runtime(clang_rt.asan-dynamic-${arch} ${arch} SHARED
|
|
|
|
OUTPUT_NAME clang_rt.asan-${arch}
|
|
|
|
SOURCES $<TARGET_OBJECTS:RTAsan_dynamic.${arch}>
|
|
|
|
${ASAN_COMMON_RUNTIME_OBJECTS}
|
|
|
|
CFLAGS ${ASAN_DYNAMIC_CFLAGS}
|
|
|
|
DEFS ${ASAN_DYNAMIC_DEFINITIONS})
|
|
|
|
target_link_libraries(clang_rt.asan-dynamic-${arch} ${ASAN_DYNAMIC_LIBS})
|
|
|
|
add_dependencies(asan clang_rt.asan-dynamic-${arch})
|
|
|
|
endif()
|
|
|
|
|
2013-08-28 16:07:04 +08:00
|
|
|
if (UNIX AND NOT ${arch} STREQUAL "i386")
|
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)
|
2014-03-31 21:45:36 +08:00
|
|
|
add_compiler_rt_runtime(clang_rt.asan_dll_thunk-${arch} ${arch} STATIC
|
|
|
|
SOURCES asan_dll_thunk.cc
|
2014-05-20 22:26:19 +08:00
|
|
|
$<TARGET_OBJECTS:RTInterception.${arch}>
|
2014-03-31 21:45:36 +08:00
|
|
|
CFLAGS ${ASAN_CFLAGS} -DASAN_DLL_THUNK
|
|
|
|
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-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()
|