Skip to content

Commit f4382d4

Browse files
committed
[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
1 parent 1ac2d19 commit f4382d4

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
@@ -251,7 +251,35 @@ function(get_test_cflags_for_apple_platform platform arch cflags_out)
251251
endif()
252252
set(test_cflags "")
253253
get_target_flags_for_arch(${arch} test_cflags)
254-
list(APPEND test_cflags ${DARWIN_${platform}_CFLAGS})
254+
255+
if (NOT "${arch}" STREQUAL "arm64e")
256+
list(APPEND test_cflags ${DARWIN_${platform}_CFLAGS})
257+
else()
258+
# arm64e is not currently ABI stable so we need to build for the
259+
# OS version being tested. Rather than querying the device under test
260+
# we use the SDK version which "should" be the same as the
261+
# device under test (it is a configuration error for these not to match).
262+
# FIXME(dliew): We can remove this if we build the runtimes with the appropriate
263+
# deployment target for arm64e.
264+
foreach (flag ${DARWIN_${platform}_CFLAGS})
265+
if ("${flag}" MATCHES "^${DARWIN_${platform}_MIN_VER_FLAG}=.+")
266+
# Find the SDK version
267+
get_xcrun_platform_from_apple_platform("${platform}" xcrun_platform_name)
268+
# TODO(dliew): Remove this check once get_xcrun_platform_from_apple_platform
269+
# emits a fatal error for unrecognised platforms.
270+
if (NOT "${xcrun_platform_name}" STREQUAL "")
271+
find_darwin_sdk_version(platform_sdk_version "${xcrun_platform_name}")
272+
# Patch flag with correct deployment target
273+
set(replacement_flag "${DARWIN_${platform}_MIN_VER_FLAG}=${platform_sdk_version}")
274+
list(APPEND test_cflags "${replacement_flag}")
275+
endif()
276+
else()
277+
# Copy through
278+
list(APPEND test_cflags "${flag}")
279+
endif()
280+
endforeach()
281+
endif()
282+
255283
string(REPLACE ";" " " test_cflags_str "${test_cflags}")
256284
string(APPEND test_cflags_str "${COMPILER_RT_TEST_COMPILER_CFLAGS}")
257285
set(${cflags_out} "${test_cflags_str}" PARENT_SCOPE)
@@ -280,6 +308,31 @@ function(is_valid_apple_platform platform is_valid_out)
280308
set(${is_valid_out} ${is_valid} PARENT_SCOPE)
281309
endfunction()
282310

311+
# Maps the Apple platform name used in Compiler-rt's CMake code
312+
# to the name recognised by xcrun's `--sdk` argument
313+
function(get_xcrun_platform_from_apple_platform platform out_var)
314+
set(xcrun_platform "")
315+
if ("${platform}" STREQUAL "osx")
316+
set(xcrun_platform "macosx")
317+
elseif ("${platform}" STREQUAL "iossim")
318+
set(xcrun_platform "iphonesimulator")
319+
elseif ("${platform}" STREQUAL "ios")
320+
set(xcrun_platform "iphoneos")
321+
elseif ("${platform}" STREQUAL "watchossim")
322+
set(xcrun_platform "watchsimulator")
323+
elseif ("${platform}" STREQUAL "watchos")
324+
set(xcrun_platform "watchos")
325+
elseif ("${platform}" STREQUAL "tvossim")
326+
set(xcrun_platform "appletvsimulator")
327+
elseif ("${platform}" STREQUAL "tvos")
328+
set(xcrun_platform "appletvos")
329+
else()
330+
# TODO(dliew): Make this an error.
331+
message(WARNING "\"${platform}\" is not a handled apple platform")
332+
endif()
333+
set(${out_var} ${xcrun_platform} PARENT_SCOPE)
334+
endfunction()
335+
283336
include(AllSupportedArchDefs)
284337

285338
if(APPLE)

0 commit comments

Comments
 (0)