Index: compiler-rt/trunk/cmake/Modules/CompilerRTDarwinUtils.cmake =================================================================== --- compiler-rt/trunk/cmake/Modules/CompilerRTDarwinUtils.cmake +++ compiler-rt/trunk/cmake/Modules/CompilerRTDarwinUtils.cmake @@ -77,3 +77,25 @@ 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() Index: compiler-rt/trunk/cmake/config-ix.cmake =================================================================== --- compiler-rt/trunk/cmake/config-ix.cmake +++ compiler-rt/trunk/cmake/config-ix.cmake @@ -238,7 +238,14 @@ 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() Index: compiler-rt/trunk/lib/asan/tests/CMakeLists.txt =================================================================== --- compiler-rt/trunk/lib/asan/tests/CMakeLists.txt +++ compiler-rt/trunk/lib/asan/tests/CMakeLists.txt @@ -116,6 +116,9 @@ 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 @@ 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) Index: compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt =================================================================== --- compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt +++ compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt @@ -4,6 +4,9 @@ # 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 Index: compiler-rt/trunk/test/asan/CMakeLists.txt =================================================================== --- compiler-rt/trunk/test/asan/CMakeLists.txt +++ compiler-rt/trunk/test/asan/CMakeLists.txt @@ -24,7 +24,12 @@ 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 @@ # 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() Index: compiler-rt/trunk/test/sanitizer_common/CMakeLists.txt =================================================================== --- compiler-rt/trunk/test/sanitizer_common/CMakeLists.txt +++ compiler-rt/trunk/test/sanitizer_common/CMakeLists.txt @@ -19,14 +19,19 @@ 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()