Skip to content

Commit 8beb230

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 llvm-svn: 374977 (cherry picked from commit 8a5bfbe)
1 parent 5a87c0c commit 8beb230

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,41 @@ function(find_darwin_sdk_dir var sdk_name)
3939
set(DARWIN_${sdk_name}_CACHED_SYSROOT ${var_internal} CACHE STRING "Darwin SDK path for SDK ${sdk_name}." FORCE)
4040
endfunction()
4141

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

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

0 commit comments

Comments
 (0)