Skip to content

Commit 3672975

Browse files
danliew-appledelcypher
authored andcommitted
[Compiler-RT] For arm64e test suites use the SDK version as the minimum deployment target.
Previously we used the minimum deployment target used for the platform (e.g. iOS is 9.0). Unfortunately this leads to ABI incompatibilities with arm64e devices running newer OSs. In particular the following TSan test cases that used libcxx would fail due to the ABI mismatch. * Darwin/libcxx-shared-ptr-recursive.mm * Darwin/libcxx-shared-ptr-stress.mm * Darwin/libcxx-shared-ptr.mm * libcxx/std_shared_ptr.cpp Given that arm64e is not ABI stable we should ideally match the deployment target for sanitizer runtimes and their tests cases to the device when building for arm64e. Unfortunately having a mixed deployment target (based on architecture) isn't currently supported by the build system and is non-trivial to implement. As a stop-gap measure this patch changes the sanitizer test suites (but not the sanitizer runtimes themselves) to use a newer deployment target when targetting arm64e. The deployment target used for arm64e is the SDK version because this "should" match the OS version running on the target device (it is a configuration error to not match them). rdar://83080611 (cherry picked from commit f4382d4)
1 parent 2888998 commit 3672975

File tree

1 file changed

+54
-1
lines changed

1 file changed

+54
-1
lines changed

compiler-rt/cmake/config-ix.cmake

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,35 @@ function(get_test_cflags_for_apple_platform platform arch cflags_out)
242242
endif()
243243
set(test_cflags "")
244244
get_target_flags_for_arch(${arch} test_cflags)
245-
list(APPEND test_cflags ${DARWIN_${platform}_CFLAGS})
245+
246+
if (NOT "${arch}" STREQUAL "arm64e")
247+
list(APPEND test_cflags ${DARWIN_${platform}_CFLAGS})
248+
else()
249+
# arm64e is not currently ABI stable so we need to build for the
250+
# OS version being tested. Rather than querying the device under test
251+
# we use the SDK version which "should" be the same as the
252+
# device under test (it is a configuration error for these not to match).
253+
# FIXME(dliew): We can remove this if we build the runtimes with the appropriate
254+
# deployment target for arm64e.
255+
foreach (flag ${DARWIN_${platform}_CFLAGS})
256+
if ("${flag}" MATCHES "^${DARWIN_${platform}_MIN_VER_FLAG}=.+")
257+
# Find the SDK version
258+
get_xcrun_platform_from_apple_platform("${platform}" xcrun_platform_name)
259+
# TODO(dliew): Remove this check once get_xcrun_platform_from_apple_platform
260+
# emits a fatal error for unrecognised platforms.
261+
if (NOT "${xcrun_platform_name}" STREQUAL "")
262+
find_darwin_sdk_version(platform_sdk_version "${xcrun_platform_name}")
263+
# Patch flag with correct deployment target
264+
set(replacement_flag "${DARWIN_${platform}_MIN_VER_FLAG}=${platform_sdk_version}")
265+
list(APPEND test_cflags "${replacement_flag}")
266+
endif()
267+
else()
268+
# Copy through
269+
list(APPEND test_cflags "${flag}")
270+
endif()
271+
endforeach()
272+
endif()
273+
246274
string(REPLACE ";" " " test_cflags_str "${test_cflags}")
247275
string(APPEND test_cflags_str "${COMPILER_RT_TEST_COMPILER_CFLAGS}")
248276
set(${cflags_out} "${test_cflags_str}" PARENT_SCOPE)
@@ -271,6 +299,31 @@ function(is_valid_apple_platform platform is_valid_out)
271299
set(${is_valid_out} ${is_valid} PARENT_SCOPE)
272300
endfunction()
273301

302+
# Maps the Apple platform name used in Compiler-rt's CMake code
303+
# to the name recognised by xcrun's `--sdk` argument
304+
function(get_xcrun_platform_from_apple_platform platform out_var)
305+
set(xcrun_platform "")
306+
if ("${platform}" STREQUAL "osx")
307+
set(xcrun_platform "macosx")
308+
elseif ("${platform}" STREQUAL "iossim")
309+
set(xcrun_platform "iphonesimulator")
310+
elseif ("${platform}" STREQUAL "ios")
311+
set(xcrun_platform "iphoneos")
312+
elseif ("${platform}" STREQUAL "watchossim")
313+
set(xcrun_platform "watchsimulator")
314+
elseif ("${platform}" STREQUAL "watchos")
315+
set(xcrun_platform "watchos")
316+
elseif ("${platform}" STREQUAL "tvossim")
317+
set(xcrun_platform "appletvsimulator")
318+
elseif ("${platform}" STREQUAL "tvos")
319+
set(xcrun_platform "appletvos")
320+
else()
321+
# TODO(dliew): Make this an error.
322+
message(WARNING "\"${platform}\" is not a handled apple platform")
323+
endif()
324+
set(${out_var} ${xcrun_platform} PARENT_SCOPE)
325+
endfunction()
326+
274327
set(ARM64 aarch64)
275328
set(ARM32 arm armhf)
276329
set(HEXAGON hexagon)

0 commit comments

Comments
 (0)