CMake: Generalize build rules for different arches for sanitizer_common, asan, ubsan

llvm-svn: 172829
This commit is contained in:
Alexey Samsonov 2013-01-18 16:51:07 +00:00
parent b4ba995366
commit b068483d4d
6 changed files with 43 additions and 66 deletions

View File

@ -124,6 +124,11 @@ if(APPLE)
list(APPEND SANITIZER_COMMON_CFLAGS -mmacosx-version-min=10.5)
endif()
# Architectures supported by Sanitizer runtimes. Specific sanitizers may
# support only subset of these (e.g. TSan works on x86_64 only).
filter_available_targets(SANITIZER_COMMON_SUPPORTED_ARCH
x86_64 i386)
# Compute the Clang version from the LLVM version.
# FIXME: We should be able to reuse CLANG_VERSION variable calculated
# in Clang cmake files, instead of copying the rules here.

View File

@ -6,9 +6,11 @@ if(CMAKE_SYSTEM_NAME MATCHES "Darwin|Linux")
add_subdirectory(asan)
add_subdirectory(interception)
add_subdirectory(sanitizer_common)
add_subdirectory(ubsan)
if(NOT ANDROID)
add_subdirectory(ubsan)
endif
endif()
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" AND NOT ANDROID)
# ThreadSanitizer and MemorySanitizer are supported on Linux only.
add_subdirectory(tsan)
add_subdirectory(msan)

View File

@ -52,6 +52,10 @@ set(ASAN_DYLIB_DEFINITIONS
MAC_INTERPOSE_FUNCTIONS=1
)
# Architectures supported by ASan.
filter_available_targets(ASAN_SUPPORTED_ARCH
x86_64 i386)
set(ASAN_RUNTIME_LIBRARIES)
if(APPLE)
# Build universal binary on APPLE.
@ -61,9 +65,8 @@ if(APPLE)
$<TARGET_OBJECTS:RTSanitizerCommon.osx>
)
set_target_compile_flags(clang_rt.asan_osx ${ASAN_CFLAGS})
filter_available_targets(ASAN_TARGETS x86_64 i386)
set_target_properties(clang_rt.asan_osx PROPERTIES
OSX_ARCHITECTURES "${ASAN_TARGETS}")
OSX_ARCHITECTURES "${ASAN_SUPPORTED_ARCH}")
list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan_osx)
elseif(ANDROID)
add_library(clang_rt.asan-arm-android SHARED
@ -78,28 +81,15 @@ elseif(ANDROID)
list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-arm-android)
else()
# Otherwise, build separate libraries for each target.
if(CAN_TARGET_x86_64)
add_library(clang_rt.asan-x86_64 STATIC
foreach(arch ${ASAN_SUPPORTED_ARCH})
add_library(clang_rt.asan-${arch} STATIC
${ASAN_SOURCES}
$<TARGET_OBJECTS:RTInterception.x86_64>
$<TARGET_OBJECTS:RTSanitizerCommon.x86_64>
)
set_target_compile_flags(clang_rt.asan-x86_64
${ASAN_CFLAGS} ${TARGET_x86_64_CFLAGS}
)
list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-x86_64)
endif()
if(CAN_TARGET_i386)
add_library(clang_rt.asan-i386 STATIC
${ASAN_SOURCES}
$<TARGET_OBJECTS:RTInterception.i386>
$<TARGET_OBJECTS:RTSanitizerCommon.i386>
)
set_target_compile_flags(clang_rt.asan-i386
${ASAN_CFLAGS} ${TARGET_i386_CFLAGS}
)
list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-i386)
endif()
$<TARGET_OBJECTS:RTInterception.${arch}>
$<TARGET_OBJECTS:RTSanitizerCommon.${arch}>)
set_target_compile_flags(clang_rt.asan-${arch}
${ASAN_CFLAGS} ${TARGET_${arch}_CFLAGS})
list(APPEND ASAN_RUNTIME_LIBRARIES clang_rt.asan-${arch})
endforeach()
endif()
set_property(TARGET ${ASAN_RUNTIME_LIBRARIES} APPEND PROPERTY
@ -115,10 +105,9 @@ if(APPLE)
$<TARGET_OBJECTS:RTSanitizerCommon.osx>
)
set_target_compile_flags(clang_rt.asan_osx_dynamic ${ASAN_CFLAGS})
filter_available_targets(ASAN_TARGETS x86_64 i386)
set_target_properties(clang_rt.asan_osx_dynamic PROPERTIES
COMPILE_DEFINITIONS "${ASAN_DYLIB_DEFINITIONS}"
OSX_ARCHITECTURES "${ASAN_TARGETS}"
OSX_ARCHITECTURES "${ASAN_SUPPORTED_ARCH}"
LINK_FLAGS "-framework Foundation")
list(APPEND ASAN_DYNAMIC_RUNTIME_LIBRARIES clang_rt.asan_osx_dynamic)
endif()

View File

@ -24,21 +24,16 @@ if(APPLE)
# Build universal binary on APPLE.
add_library(RTInterception.osx OBJECT ${INTERCEPTION_SOURCES})
set_target_compile_flags(RTInterception.osx ${INTERCEPTION_CFLAGS})
filter_available_targets(INTERCEPTION_TARGETS x86_64 i386)
set_target_properties(RTInterception.osx PROPERTIES
OSX_ARCHITECTURES "${INTERCEPTION_TARGETS}")
OSX_ARCHITECTURES "${SANITIZER_COMMON_SUPPORTED_ARCH}")
elseif(ANDROID)
add_library(RTInterception.arm.android OBJECT ${INTERCEPTION_SOURCES})
set_target_compile_flags(RTInterception.arm.android
${INTERCEPTION_CFLAGS})
else()
# Otherwise, build separate libraries for each target.
if(CAN_TARGET_x86_64)
add_compiler_rt_object_library(RTInterception x86_64
foreach(arch ${SANITIZER_COMMON_SUPPORTED_ARCH})
add_compiler_rt_object_library(RTInterception ${arch}
SOURCES ${INTERCEPTION_SOURCES} CFLAGS ${INTERCEPTION_CFLAGS})
endif()
if (CAN_TARGET_i386)
add_compiler_rt_object_library(RTInterception i386
SOURCES ${INTERCEPTION_SOURCES} CFLAGS ${INTERCEPTION_CFLAGS})
endif()
endforeach()
endif()

View File

@ -54,9 +54,8 @@ if(APPLE)
# Build universal binary on APPLE.
add_library(RTSanitizerCommon.osx OBJECT ${SANITIZER_SOURCES})
set_target_compile_flags(RTSanitizerCommon.osx ${SANITIZER_CFLAGS})
filter_available_targets(SANITIZER_TARGETS x86_64 i386)
set_target_properties(RTSanitizerCommon.osx PROPERTIES
OSX_ARCHITECTURES "${SANITIZER_TARGETS}")
OSX_ARCHITECTURES "${SANITIZER_COMMON_SUPPORTED_ARCH}")
list(APPEND SANITIZER_RUNTIME_LIBRARIES RTSanitizerCommon.osx)
elseif(ANDROID)
add_library(RTSanitizerCommon.arm.android OBJECT ${SANITIZER_SOURCES})
@ -65,16 +64,11 @@ elseif(ANDROID)
list(APPEND SANITIZER_RUNTIME_LIBRARIES RTSanitizerCommon.arm.android)
else()
# Otherwise, build separate libraries for each target.
if(CAN_TARGET_x86_64)
add_compiler_rt_object_library(RTSanitizerCommon x86_64
foreach(arch ${SANITIZER_COMMON_SUPPORTED_ARCH})
add_compiler_rt_object_library(RTSanitizerCommon ${arch}
SOURCES ${SANITIZER_SOURCES} CFLAGS ${SANITIZER_CFLAGS})
list(APPEND SANITIZER_RUNTIME_LIBRARIES RTSanitizerCommon.x86_64)
endif()
if(CAN_TARGET_i386)
add_compiler_rt_object_library(RTSanitizerCommon i386
SOURCES ${SANITIZER_SOURCES} CFLAGS ${SANITIZER_CFLAGS})
list(APPEND SANITIZER_RUNTIME_LIBRARIES RTSanitizerCommon.i386)
endif()
list(APPEND SANITIZER_RUNTIME_LIBRARIES RTSanitizerCommon.${arch})
endforeach()
endif()
# Unit tests for common sanitizer runtime.

View File

@ -12,6 +12,9 @@ include_directories(..)
set(UBSAN_CFLAGS ${SANITIZER_COMMON_CFLAGS})
filter_available_targets(UBSAN_SUPPORTED_ARCH
x86_64 i386)
set(UBSAN_RUNTIME_LIBRARIES)
if(APPLE)
@ -21,32 +24,21 @@ if(APPLE)
$<TARGET_OBJECTS:RTSanitizerCommon.osx>
)
set_target_compile_flags(clang_rt.ubsan_osx ${UBSAN_CFLAGS})
filter_available_targets(UBSAN_TARGETS x86_64 i386)
set_target_properties(clang_rt.ubsan_osx PROPERTIES
OSX_ARCHITECTURES "${UBSAN_TARGETS}")
OSX_ARCHITECTURES "${UBSAN_SUPPORTED_ARCH}")
list(APPEND UBSAN_RUNTIME_LIBRARIES clang_rt.ubsan_osx)
else()
# Build separate libraries for each target.
if(CAN_TARGET_x86_64)
add_library(clang_rt.ubsan-x86_64 STATIC
foreach(arch ${UBSAN_SUPPORTED_ARCH})
add_library(clang_rt.ubsan-${arch} STATIC
${UBSAN_SOURCES}
$<TARGET_OBJECTS:RTSanitizerCommon.x86_64>
$<TARGET_OBJECTS:RTSanitizerCommon.${arch}>
)
set_target_compile_flags(clang_rt.ubsan-x86_64
${UBSAN_CFLAGS} ${TARGET_x86_64_CFLAGS}
set_target_compile_flags(clang_rt.ubsan-${arch}
${UBSAN_CFLAGS} ${TARGET_${arch}_CFLAGS}
)
list(APPEND UBSAN_RUNTIME_LIBRARIES clang_rt.ubsan-x86_64)
endif()
if(CAN_TARGET_i386)
add_library(clang_rt.ubsan-i386 STATIC
${UBSAN_SOURCES}
$<TARGET_OBJECTS:RTSanitizerCommon.i386>
)
set_target_compile_flags(clang_rt.ubsan-i386
${UBSAN_CFLAGS} ${TARGET_i386_CFLAGS}
)
list(APPEND UBSAN_RUNTIME_LIBRARIES clang_rt.ubsan-i386)
endif()
list(APPEND UBSAN_RUNTIME_LIBRARIES clang_rt.ubsan-${arch})
endforeach()
endif()