[compiler-rt] r374977 - [CMake] Disable building all Darwin libraries (except builtins) for macOS i386 when the SDK is >= 10.15.

Dan Liew via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 15 22:48:40 PDT 2019


Author: delcypher
Date: Tue Oct 15 22:48:39 2019
New Revision: 374977

URL: http://llvm.org/viewvc/llvm-project?rev=374977&view=rev
Log:
[CMake] Disable building all Darwin libraries (except builtins) for macOS i386 when the SDK is >= 10.15.

Summary:
In the macOS 10.15 SDK the ability to link i386 binaries was removed and
in the corresponding OS it is not possible to run macOS i386 binaries.

The consequence of these changes meant that targets like `check-asan`
would fail because:

* Unit tests could not be linked for i386
* Lit tests for i386 would fail due to not being able to execute
  compiled binaries.

The simplest fix to this is to simply disable building for i386 for
macOS when using the 10.15 SDK (or newer). This disables building the
i386 slice for most compiler-rt libraries and consequently disables the
unit and lit tests for macOS i386.

Note that because the `DARWIN_osx_ARCHS` CMake variable is a cache
variable this patch will have no affect on existing builds unless
the existing cache variable is deleted. The simplest way to deal with
this is delete existing builds and just do a fresh configure.

Note this should not affect the builtins which are managed with
the `DARWIN_osx_BUILTIN_ARCHS` CMake cache variable.

For those who wish to force using a particular set of architectures when
using newer SDKs passing `-DDARWIN_osx_ARCHS=i386;x86_64;x86_64h` to
CMake should provide a usable (but completely unsupported) workaround.

rdar://problem/55668535
rdar://problem/47939978

Reviewers: kubamracek, yln, azhar, kcc, dvyukov, vitalybuka, cryptoad, eugenis, thakis, phosek

Subscribers: mgorny, #sanitizers, llvm-commits

Tags: #llvm, #sanitizers

Differential Revision: https://reviews.llvm.org/D68292

Modified:
    compiler-rt/trunk/cmake/Modules/CompilerRTDarwinUtils.cmake

Modified: compiler-rt/trunk/cmake/Modules/CompilerRTDarwinUtils.cmake
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/Modules/CompilerRTDarwinUtils.cmake?rev=374977&r1=374976&r2=374977&view=diff
==============================================================================
--- compiler-rt/trunk/cmake/Modules/CompilerRTDarwinUtils.cmake (original)
+++ compiler-rt/trunk/cmake/Modules/CompilerRTDarwinUtils.cmake Tue Oct 15 22:48:39 2019
@@ -41,6 +41,41 @@ function(find_darwin_sdk_dir var sdk_nam
   set(DARWIN_${sdk_name}_CACHED_SYSROOT ${var_internal} CACHE STRING "Darwin SDK path for SDK ${sdk_name}." FORCE)
 endfunction()
 
+function(find_darwin_sdk_version var sdk_name)
+  # We deliberately don't cache the result here because
+  # CMake's caching causes too many problems.
+  set(result_process 1)
+  if(NOT DARWIN_PREFER_PUBLIC_SDK)
+    # Let's first try the internal SDK, otherwise use the public SDK.
+    execute_process(
+      COMMAND xcodebuild -version -sdk ${sdk_name}.internal SDKVersion
+      RESULT_VARIABLE result_process
+      OUTPUT_VARIABLE var_internal
+      OUTPUT_STRIP_TRAILING_WHITESPACE
+      ERROR_FILE /dev/null
+    )
+  endif()
+  if((NOT ${result_process} EQUAL 0) OR "" STREQUAL "${var_internal}")
+    execute_process(
+      COMMAND xcodebuild -version -sdk ${sdk_name} SDKVersion
+      RESULT_VARIABLE result_process
+      OUTPUT_VARIABLE var_internal
+      OUTPUT_STRIP_TRAILING_WHITESPACE
+      ERROR_FILE /dev/null
+    )
+  endif()
+  if(NOT result_process EQUAL 0)
+    message(FATAL_ERROR
+      "Failed to determine SDK version for \"${sdk_name}\" SDK")
+  endif()
+  # Check reported version looks sane.
+  if (NOT "${var_internal}" MATCHES "^[0-9]+\\.[0-9]+(\\.[0-9]+)?$")
+    message(FATAL_ERROR
+      "Reported SDK version \"${var_internal}\" does not look like a version")
+  endif()
+  set(${var} ${var_internal} PARENT_SCOPE)
+endfunction()
+
 # There isn't a clear mapping of what architectures are supported with a given
 # target platform, but ld's version output does list the architectures it can
 # link for.
@@ -77,11 +112,22 @@ function(darwin_test_archs os valid_arch
     message(STATUS "Finding valid architectures for ${os}...")
     set(SIMPLE_C ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/src.c)
     file(WRITE ${SIMPLE_C} "#include <stdio.h>\nint main() { printf(__FILE__); return 0; }\n")
-  
+
     set(os_linker_flags)
     foreach(flag ${DARWIN_${os}_LINK_FLAGS})
       set(os_linker_flags "${os_linker_flags} ${flag}")
     endforeach()
+
+    # Disable building for i386 for macOS SDK >= 10.15. The SDK doesn't support
+    # linking for i386 and the corresponding OS doesn't allow running macOS i386
+    # binaries.
+    if ("${os}" STREQUAL "osx")
+      find_darwin_sdk_version(macosx_sdk_version "macosx")
+      if ("${macosx_sdk_version}" VERSION_GREATER 10.15 OR "${macosx_sdk_version}" VERSION_EQUAL 10.15)
+        message(STATUS "Disabling i386 slice for ${valid_archs}")
+        list(REMOVE_ITEM archs "i386")
+      endif()
+    endif()
   endif()
 
   # The simple program will build for x86_64h on the simulator because it is 




More information about the llvm-commits mailing list