Skip to content

Commit c482331

Browse files
committed
Implement differently logic to strip and copy the tvos libraries
The previous logic could fail silently to copy the library if the i386 slice is not present in the first place (like it is the case for `libclang_rt.tvos.a` in Xcode 13.0 beta 1) -- this will avoid errors like ``` Undefined symbols for architecture arm64: "___isPlatformVersionAtLeast", referenced from: swift::initializeProtocolLookup() in ImageInspectionMachO.cpp.o swift::initializeProtocolConformanceLookup() in ImageInspectionMachO.cpp.o swift::initializeTypeMetadataRecordLookup() in ImageInspectionMachO.cpp.o swift::initializeDynamicReplacementLookup() in ImageInspectionMachO.cpp.o ``` This is a backport of #38262 Addresses rdar://80209915
1 parent b3e9330 commit c482331

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

utils/build-script-impl

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,6 +1423,25 @@ function cmake_config_opt() {
14231423
fi
14241424
}
14251425

1426+
function copy_lib_stripping_architecture() {
1427+
local source="$1"
1428+
local dest="$2"
1429+
local arch="$3"
1430+
1431+
# An alternative approach would be to use || to first
1432+
# attempt the removal of the slice and fall back to the
1433+
# copy when failing.
1434+
# However, this would leave unneeded error messages in the logs
1435+
# that may hinder investigation; in addition, in this scenario
1436+
# the `call` function seems to not propagate correctly failure
1437+
# exit codes.
1438+
if lipo -archs "${source}" | grep -q "${arch}"; then
1439+
call lipo -remove "${arch}" "${source}" -output "${dest}"
1440+
else
1441+
call cp "${source}" "${dest}"
1442+
fi
1443+
}
1444+
14261445
function copy_embedded_compiler_rt_builtins_from_darwin_host_toolchain() {
14271446
local clang_dest_dir="$1"
14281447

@@ -1448,7 +1467,8 @@ function copy_embedded_compiler_rt_builtins_from_darwin_host_toolchain() {
14481467
if [[ ! -f "${DEST_LIB_PATH}" ]]; then
14491468
if [[ -f "${HOST_LIB_PATH}" ]]; then
14501469
if [[ "$OS" == "tvos" ]]; then
1451-
call lipo -remove i386 "${HOST_LIB_PATH}" -output "${DEST_LIB_PATH}" || call cp "${HOST_LIB_PATH}" "${DEST_LIB_PATH}"
1470+
# This is to avoid strip failures when generating a toolchain
1471+
copy_lib_stripping_architecture "${HOST_LIB_PATH}" "${DEST_LIB_PATH}" i386
14521472
else
14531473
call cp "${HOST_LIB_PATH}" "${DEST_LIB_PATH}"
14541474
fi
@@ -1464,7 +1484,8 @@ function copy_embedded_compiler_rt_builtins_from_darwin_host_toolchain() {
14641484
if [[ ! -f "${DEST_SIM_LIB_PATH}" ]]; then
14651485
if [[ -f "${HOST_SIM_LIB_PATH}" ]]; then
14661486
if [[ "$OS" == "tvos" ]]; then
1467-
call lipo -remove i386 "${HOST_SIM_LIB_PATH}" -output "${DEST_SIM_LIB_PATH}" || call cp "${HOST_SIM_LIB_PATH}" "${DEST_SIM_LIB_PATH}"
1487+
# This is to avoid strip failures when generating a toolchain
1488+
copy_lib_stripping_architecture "${HOST_SIM_LIB_PATH}" "${DEST_SIM_LIB_PATH}" i386
14681489
else
14691490
call cp "${HOST_SIM_LIB_PATH}" "${DEST_SIM_LIB_PATH}"
14701491
fi

0 commit comments

Comments
 (0)