[compiler-rt] r245580 - [CMake] Fix building unit tests on Darwin

Chris Bieneman via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 20 10:32:07 PDT 2015


Author: cbieneman
Date: Thu Aug 20 12:32:06 2015
New Revision: 245580

URL: http://llvm.org/viewvc/llvm-project?rev=245580&view=rev
Log:
[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

Modified:
    compiler-rt/trunk/cmake/Modules/CompilerRTDarwinUtils.cmake
    compiler-rt/trunk/cmake/config-ix.cmake
    compiler-rt/trunk/lib/asan/tests/CMakeLists.txt
    compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt
    compiler-rt/trunk/test/asan/CMakeLists.txt
    compiler-rt/trunk/test/sanitizer_common/CMakeLists.txt

Modified: compiler-rt/trunk/cmake/Modules/CompilerRTDarwinUtils.cmake
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/Modules/CompilerRTDarwinUtils.cmake?rev=245580&r1=245579&r2=245580&view=diff
==============================================================================
--- compiler-rt/trunk/cmake/Modules/CompilerRTDarwinUtils.cmake (original)
+++ compiler-rt/trunk/cmake/Modules/CompilerRTDarwinUtils.cmake Thu Aug 20 12:32:06 2015
@@ -77,3 +77,25 @@ function(darwin_test_archs os valid_arch
   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()

Modified: compiler-rt/trunk/cmake/config-ix.cmake
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/config-ix.cmake?rev=245580&r1=245579&r2=245580&view=diff
==============================================================================
--- compiler-rt/trunk/cmake/config-ix.cmake (original)
+++ compiler-rt/trunk/cmake/config-ix.cmake Thu Aug 20 12:32:06 2015
@@ -238,7 +238,14 @@ function(get_target_flags_for_arch arch
   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()
 

Modified: compiler-rt/trunk/lib/asan/tests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/tests/CMakeLists.txt?rev=245580&r1=245579&r2=245580&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/tests/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/asan/tests/CMakeLists.txt Thu Aug 20 12:32:06 2015
@@ -116,6 +116,9 @@ macro(asan_compile obj_list source arch
   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 a
 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)

Modified: compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt?rev=245580&r1=245579&r2=245580&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/CMakeLists.txt Thu Aug 20 12:32:06 2015
@@ -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

Modified: compiler-rt/trunk/test/asan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/CMakeLists.txt?rev=245580&r1=245579&r2=245580&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/CMakeLists.txt (original)
+++ compiler-rt/trunk/test/asan/CMakeLists.txt Thu Aug 20 12:32:06 2015
@@ -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()

Modified: compiler-rt/trunk/test/sanitizer_common/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/CMakeLists.txt?rev=245580&r1=245579&r2=245580&view=diff
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/CMakeLists.txt (original)
+++ compiler-rt/trunk/test/sanitizer_common/CMakeLists.txt Thu Aug 20 12:32:06 2015
@@ -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()




More information about the llvm-commits mailing list