[CMake] Fix building unit tests on Darwin

Summary:
There are a number of issues with unit tests on Darwin. These patches address the following:
* Unit tests should be passed -arch (-m32/-m64 isn't sufficient)
* Unit tests should be passed ${DARWIN_osx_CFLAGS} because they're being built for OS X
* Test architectures should be filtered based on base system capabilities (i.e. don't try running x86_64h tests on pre-haswell hardware).

Reviewers: bogner, filcab, kubabrecka

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D12174

llvm-svn: 245580
This commit is contained in:
Chris Bieneman 2015-08-20 17:32:06 +00:00
parent e48134093d
commit 5eae197ab0
6 changed files with 55 additions and 6 deletions

View File

@ -77,3 +77,25 @@ function(darwin_test_archs os valid_archs)
endforeach()
set(${valid_archs} ${working_archs} PARENT_SCOPE)
endfunction()
# This function checks the host cpusubtype to see if it is post-haswell. Haswell
# and later machines can run x86_64h binaries. Haswell is cpusubtype 8.
function(darwin_filter_host_archs input output)
list_union(tmp_var DARWIN_osx_ARCHS ${input})
execute_process(
COMMAND sysctl hw.cpusubtype
OUTPUT_VARIABLE SUBTYPE)
string(REGEX MATCH "hw.cpusubtype: ([0-9]*)"
SUBTYPE_MATCHED "${SUBTYPE}")
set(HASWELL_SUPPORTED Off)
if(ARCHES_MATCHED)
if(CMAKE_MATCH_1 GREATER_OR_EQUAL_TO 8)
set(HASWELL_SUPPORTED On)
endif()
endif()
if(NOT HASWELL_SUPPORTED)
list(REMOVE_ITEM tmp_var x86_64h)
endif()
set(${output} ${tmp_var} PARENT_SCOPE)
endfunction()

View File

@ -238,7 +238,14 @@ function(get_target_flags_for_arch arch out_var)
if(ARCH_INDEX EQUAL -1)
message(FATAL_ERROR "Unsupported architecture: ${arch}")
else()
set(${out_var} ${TARGET_${arch}_CFLAGS} PARENT_SCOPE)
if (NOT APPLE)
set(${out_var} ${TARGET_${arch}_CFLAGS} PARENT_SCOPE)
else()
# This is only called in constructing cflags for tests executing on the
# host. This will need to all be cleaned up to support building tests
# for cross-targeted hardware (i.e. iOS).
set(${out_var} -arch ${arch} PARENT_SCOPE)
endif()
endif()
endfunction()

View File

@ -116,6 +116,9 @@ macro(asan_compile obj_list source arch kind)
get_filename_component(basename ${source} NAME)
set(output_obj "${obj_list}.${basename}.${arch}${kind}.o")
get_target_flags_for_arch(${arch} TARGET_CFLAGS)
if(APPLE)
set(TARGET_CFLAGS ${DARWIN_osx_CFLAGS} -arch ${arch})
endif()
set(COMPILE_DEPS ${ASAN_UNITTEST_HEADERS} ${ASAN_BLACKLIST_FILE})
if(NOT COMPILER_RT_STANDALONE_BUILD)
list(APPEND COMPILE_DEPS gtest asan)
@ -261,7 +264,11 @@ macro(add_asan_tests_for_arch_and_kind arch kind)
endmacro()
if(COMPILER_RT_CAN_EXECUTE_TESTS AND NOT ANDROID)
foreach(arch ${ASAN_SUPPORTED_ARCH})
set(ASAN_TEST_ARCH ${ASAN_SUPPORTED_ARCH})
if(APPLE)
darwin_filter_host_archs(ASAN_SUPPORTED_ARCH ASAN_TEST_ARCH)
endif()
foreach(arch ${ASAN_TEST_ARCH})
add_asan_tests_for_arch_and_kind(${arch} "-inline")
add_asan_tests_for_arch_and_kind(${arch} "-with-calls"
-mllvm -asan-instrumentation-with-call-threshold=0)

View File

@ -4,6 +4,9 @@ clang_compiler_add_cxx_check()
# FIXME: use SANITIZER_COMMON_SUPPORTED_ARCH here
filter_available_targets(SANITIZER_UNITTEST_SUPPORTED_ARCH x86_64 i386 mips64 mips64el)
if(APPLE)
darwin_filter_host_archs(SANITIZER_UNITTEST_SUPPORTED_ARCH SANITIZER_COMMON_SUPPORTED_ARCH)
endif()
set(SANITIZER_UNITTESTS
sanitizer_allocator_test.cc

View File

@ -24,7 +24,12 @@ if(NOT COMPILER_RT_STANDALONE_BUILD)
endif()
set(ASAN_DYNAMIC_TEST_DEPS ${ASAN_TEST_DEPS})
foreach(arch ${ASAN_SUPPORTED_ARCH})
set(ASAN_TEST_ARCH ${ASAN_SUPPORTED_ARCH})
if(APPLE)
darwin_filter_host_archs(ASAN_SUPPORTED_ARCH ASAN_TEST_ARCH)
endif()
foreach(arch ${ASAN_TEST_ARCH})
if(ANDROID)
set(ASAN_TEST_TARGET_ARCH ${arch}-android)
else()
@ -37,7 +42,7 @@ foreach(arch ${ASAN_SUPPORTED_ARCH})
# Build all tests with host compiler and use host tools.
set(ASAN_TEST_TARGET_CC ${COMPILER_RT_TEST_COMPILER})
set(ASAN_TEST_TARGET_CFLAGS ${COMPILER_RT_TEST_COMPILER_CFLAGS})
else()
elseif(NOT APPLE)
get_target_flags_for_arch(${arch} ASAN_TEST_TARGET_CFLAGS)
string(REPLACE ";" " " ASAN_TEST_TARGET_CFLAGS "${ASAN_TEST_TARGET_CFLAGS}")
endif()

View File

@ -19,14 +19,19 @@ foreach(tool ${SUPPORTED_TOOLS})
if(${tool_toupper}_SUPPORTED_ARCH AND NOT COMPILER_RT_STANDALONE_BUILD)
list(APPEND SANITIZER_COMMON_TEST_DEPS ${tool})
endif()
foreach(arch ${${tool_toupper}_SUPPORTED_ARCH})
set(TEST_ARCH ${${tool_toupper}_SUPPORTED_ARCH})
if(APPLE)
darwin_filter_host_archs(${tool_toupper}_SUPPORTED_ARCH TEST_ARCH)
endif()
foreach(arch ${TEST_ARCH})
set(SANITIZER_COMMON_LIT_TEST_MODE ${tool})
set(SANITIZER_COMMON_TEST_TARGET_ARCH ${arch})
if(${arch} MATCHES "arm|aarch64")
# This is only true if we're cross-compiling.
set(SANITIZER_COMMON_TEST_TARGET_CFLAGS
${COMPILER_RT_TEST_COMPILER_CFLAGS})
else()
elseif(NOT APPLE)
get_target_flags_for_arch(${arch} SANITIZER_COMMON_TEST_TARGET_CFLAGS)
string(REPLACE ";" " " SANITIZER_COMMON_TEST_TARGET_CFLAGS "${SANITIZER_COMMON_TEST_TARGET_CFLAGS}")
endif()