diff --git a/lld/MachO/InputFiles.cpp b/lld/MachO/InputFiles.cpp index cc7eae51175b..73b2d47d69a7 100644 --- a/lld/MachO/InputFiles.cpp +++ b/lld/MachO/InputFiles.cpp @@ -1858,15 +1858,6 @@ constexpr std::array skipPlatformChecks{ "/usr/lib/system/libsystem_platform.dylib", "/usr/lib/system/libsystem_pthread.dylib"}; -static bool skipPlatformCheckForCatalyst(const InterfaceFile &interface, - bool explicitlyLinked) { - // Catalyst outputs can link against implicitly linked macOS-only libraries. - if (config->platform() != PLATFORM_MACCATALYST || explicitlyLinked) - return false; - return is_contained(interface.targets(), - MachO::Target(config->arch(), PLATFORM_MACOS)); -} - static bool isArchABICompatible(ArchitectureSet archSet, Architecture targetArch) { uint32_t cpuType; @@ -1879,6 +1870,18 @@ static bool isArchABICompatible(ArchitectureSet archSet, }); } +static bool skipPlatformCheckForCatalyst(const InterfaceFile &interface, + bool explicitlyLinked) { + // Catalyst outputs can link against implicitly linked macOS-only libraries. + if (config->platform() != PLATFORM_MACCATALYST || explicitlyLinked) + return false; + ArchitectureSet macOSArchs; + for (const auto &target : interface.targets()) + if (target.Platform == PLATFORM_MACOS) + macOSArchs.set(target.Arch); + return isArchABICompatible(macOSArchs, config->arch()); +} + static bool isTargetPlatformArchCompatible( InterfaceFile::const_target_range interfaceTargets, Target target) { if (is_contained(interfaceTargets, target)) diff --git a/lld/test/MachO/catalyst-arm64e-reexport.s b/lld/test/MachO/catalyst-arm64e-reexport.s new file mode 100644 index 000000000000..037d61ac847f --- /dev/null +++ b/lld/test/MachO/catalyst-arm64e-reexport.s @@ -0,0 +1,50 @@ +# REQUIRES: aarch64 + +## When linking a macCatalyst arm64 output, lld should tolerate implicitly +## linked re-exported dylibs that only declare arm64e-macos targets, even if targeting arm64. +# arm64 and arm64e are ABI compatible (same CPU type), and ld64 accepts this. + +# RUN: rm -rf %t; split-file --no-leading-lines %s %t + +# RUN: llvm-mc -filetype=obj -triple=arm64-apple-ios13.15.0-macabi -o %t/test.o /dev/null + +# RUN: %no-arg-lld -syslibroot %t/sdk -lSystem -dylib -arch arm64 \ +# RUN: -platform_version mac-catalyst 13.15.0 14.0 %t/test.o -o /dev/null + +## Explicitly linking an arm64e-macos-only library should still be an error. +# RUN: not %no-arg-lld -syslibroot %t/sdk -lSystem -dylib -arch arm64 \ +# RUN: -platform_version mac-catalyst 13.15.0 14.0 %t/test.o -o /dev/null \ +# RUN: -L %t/explicit -larm64e_only 2>&1 | FileCheck %s +# CHECK: libarm64e_only.dylib) is incompatible with arm64 (macCatalyst13.15.0) + +#--- sdk/usr/lib/libSystem.tbd +--- !tapi-tbd +tbd-version: 4 +targets: [ arm64-macos, arm64-maccatalyst ] +install-name: '/usr/lib/libSystem.dylib' +current-version: 0001.001.1 +reexported-libraries: + - targets: [ arm64-macos, arm64-maccatalyst ] + libraries: [ '/usr/lib/system/libsystem_eligibility.dylib' ] +--- !tapi-tbd +tbd-version: 4 +targets: [ x86_64-macos, arm64e-macos ] +install-name: '/usr/lib/system/libsystem_eligibility.dylib' +current-version: 0001.001.1 +parent-umbrella: + - targets: [ x86_64-macos, arm64e-macos ] + umbrella: System +exports: + - targets: [ x86_64-macos, arm64e-macos ] + symbols: [ _os_eligibility_get_domain_answer ] +... +#--- explicit/libarm64e_only.tbd +--- !tapi-tbd +tbd-version: 4 +targets: [ x86_64-macos, arm64e-macos ] +install-name: '/usr/lib/libarm64e_only.dylib' +current-version: 0001.001.1 +exports: + - targets: [ x86_64-macos, arm64e-macos ] + symbols: [ _arm64e_only_func ] +...