Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 359fb9d

Browse files
committed
[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 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@374977 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 19db581 commit 359fb9d

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

cmake/Modules/CompilerRTDarwinUtils.cmake

+47-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,41 @@ function(find_darwin_sdk_dir var sdk_name)
4141
set(DARWIN_${sdk_name}_CACHED_SYSROOT ${var_internal} CACHE STRING "Darwin SDK path for SDK ${sdk_name}." FORCE)
4242
endfunction()
4343

44+
function(find_darwin_sdk_version var sdk_name)
45+
# We deliberately don't cache the result here because
46+
# CMake's caching causes too many problems.
47+
set(result_process 1)
48+
if(NOT DARWIN_PREFER_PUBLIC_SDK)
49+
# Let's first try the internal SDK, otherwise use the public SDK.
50+
execute_process(
51+
COMMAND xcodebuild -version -sdk ${sdk_name}.internal SDKVersion
52+
RESULT_VARIABLE result_process
53+
OUTPUT_VARIABLE var_internal
54+
OUTPUT_STRIP_TRAILING_WHITESPACE
55+
ERROR_FILE /dev/null
56+
)
57+
endif()
58+
if((NOT ${result_process} EQUAL 0) OR "" STREQUAL "${var_internal}")
59+
execute_process(
60+
COMMAND xcodebuild -version -sdk ${sdk_name} SDKVersion
61+
RESULT_VARIABLE result_process
62+
OUTPUT_VARIABLE var_internal
63+
OUTPUT_STRIP_TRAILING_WHITESPACE
64+
ERROR_FILE /dev/null
65+
)
66+
endif()
67+
if(NOT result_process EQUAL 0)
68+
message(FATAL_ERROR
69+
"Failed to determine SDK version for \"${sdk_name}\" SDK")
70+
endif()
71+
# Check reported version looks sane.
72+
if (NOT "${var_internal}" MATCHES "^[0-9]+\\.[0-9]+(\\.[0-9]+)?$")
73+
message(FATAL_ERROR
74+
"Reported SDK version \"${var_internal}\" does not look like a version")
75+
endif()
76+
set(${var} ${var_internal} PARENT_SCOPE)
77+
endfunction()
78+
4479
# There isn't a clear mapping of what architectures are supported with a given
4580
# target platform, but ld's version output does list the architectures it can
4681
# link for.
@@ -77,11 +112,22 @@ function(darwin_test_archs os valid_archs)
77112
message(STATUS "Finding valid architectures for ${os}...")
78113
set(SIMPLE_C ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/src.c)
79114
file(WRITE ${SIMPLE_C} "#include <stdio.h>\nint main() { printf(__FILE__); return 0; }\n")
80-
115+
81116
set(os_linker_flags)
82117
foreach(flag ${DARWIN_${os}_LINK_FLAGS})
83118
set(os_linker_flags "${os_linker_flags} ${flag}")
84119
endforeach()
120+
121+
# Disable building for i386 for macOS SDK >= 10.15. The SDK doesn't support
122+
# linking for i386 and the corresponding OS doesn't allow running macOS i386
123+
# binaries.
124+
if ("${os}" STREQUAL "osx")
125+
find_darwin_sdk_version(macosx_sdk_version "macosx")
126+
if ("${macosx_sdk_version}" VERSION_GREATER 10.15 OR "${macosx_sdk_version}" VERSION_EQUAL 10.15)
127+
message(STATUS "Disabling i386 slice for ${valid_archs}")
128+
list(REMOVE_ITEM archs "i386")
129+
endif()
130+
endif()
85131
endif()
86132

87133
# The simple program will build for x86_64h on the simulator because it is

0 commit comments

Comments
 (0)