Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SwiftPM built with Swift 6.0 and later snapshots crashes on macOS 14 #73327

Open
1 task done
kateinoigakukun opened this issue Apr 14, 2024 · 5 comments
Open
1 task done
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. run-time crash Bug → crash: Swift code crashed during execution swift 6.0

Comments

@kateinoigakukun
Copy link
Member

kateinoigakukun commented Apr 14, 2024

Is it reproducible with SwiftPM command-line tools: swift build, swift test, swift package etc?

  • Confirmed reproduction steps with SwiftPM CLI.

Description

You can reproduce the crash by running the following simple command on macOS 14 and later with swift-DEVELOPMENT-SNAPSHOT-2024-04-09-a or later.

$ /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2024-04-09-a.xctoolchain/usr/bin/swift package --version
zsh: segmentation fault   package --version

The segmentation fault is caused by trying to dereference an async function pointer $ss23withCheckedContinuation9isolation8function_xScA_pSgYi_SSyScCyxs5NeverOGXEtYalFTu, which is introduced by #72578 and only available in toolchain stdlib but unavailable in OS stdlib yet.

Note that #72578 itself is not wrong, but it just revealed a long-living issue.

Solution?

All images compiled with snapshot toolchains should use toolchain stdlib instead of OS stdlib because:

  1. _stdlib_isOSVersionAtLeast(9999._builtinWordValue, 0._builtinWordValue, 0._builtinWordValue) always returns true after [Stdlib] Special-case major version 9999 as always available. #22658
  2. All new stdlib APIs introduced in the next release are marked with @available(macOS 9999, ...) until the version is fixed to be a concrete OS version.
  3. if #available and @backDeploy check the running OS version by using _stdlib_isOSVersionAtLeast, and it leads to referencing symbols with @available(macOS 9999) at runtime.

So as long as we use the availability placeholder, executables built with such stdlib must link exactly the same stdlib library at runtime.

Why it doesn't happen on macOS 13 or earlier?

It looks like the /usr/lib/swift/libswiftCore.dylib in the version did not include #22658, so _stdlib_isOSVersionAtLeast(9999._builtinWordValue, 0._builtinWordValue, 0._builtinWordValue) returns false.

Alternative Consideration

You might think we can revert #22658 not to make APIs marked with the placeholder always available and adjust test suites. However the implementation is already shipped as a part of macOS 14, so the issue remains as long as we use macOS 14.

Expected behavior

Not crash

Swift & OS version (output of swift --version ; uname -a)

Apple Swift version 6.0-dev (LLVM 6bf0f1dbf510217, Swift f36060f01135902)
Target: arm64-apple-macosx14.0
Darwin Yutas-Mac-mini.local 23.4.0 Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:41 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T8103 arm64
@kateinoigakukun kateinoigakukun added the bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. label Apr 14, 2024
@kateinoigakukun
Copy link
Member Author

Hmm, due to the absolute install_name specified by LC_ID_DYLIB in libswiftCore.dylib in toolchains, Swift executables always load libswiftCore.dylib from absolute /usr/lib/swift/libswiftCore.dylib without checking @rpath.
So just adding -rpath linker option did not work unfortunately.

@kateinoigakukun
Copy link
Member Author

Another approach might be reverting #22658 and making _stdlib_isOSVersionAtLeast @_alwaysEmitIntoClient.

@kateinoigakukun
Copy link
Member Author

#72801 seems trying to solve the same issue for typed throws

@rauhul
Copy link
Contributor

rauhul commented Apr 29, 2024

+1 I'm hitting this locally on my Mac running 14.0

@MaxDesiatov
Copy link
Member

MaxDesiatov commented Apr 29, 2024

The issue only seems to reproduce when SwiftPM is built with 6.0 toolchains. I can't reproduce these crashes when building SwiftPM itself with Swift 5.10. IMO this should be moved to the toolchain repository.

@MaxDesiatov MaxDesiatov transferred this issue from apple/swift-package-manager Apr 29, 2024
@MaxDesiatov MaxDesiatov added run-time crash Bug → crash: Swift code crashed during execution swift 6.0 labels Apr 29, 2024
@MaxDesiatov MaxDesiatov changed the title Invoking SwiftPM in OSS toolchain crashes on macOS 14 SwiftPM built with Swift 6.0 crashes on macOS 14 Apr 29, 2024
@MaxDesiatov MaxDesiatov changed the title SwiftPM built with Swift 6.0 crashes on macOS 14 SwiftPM built with Swift 6.0 snapshots crashes on macOS 14 Apr 29, 2024
@MaxDesiatov MaxDesiatov changed the title SwiftPM built with Swift 6.0 snapshots crashes on macOS 14 SwiftPM built with Swift 6.0 and later snapshots crashes on macOS 14 Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. run-time crash Bug → crash: Swift code crashed during execution swift 6.0
Projects
None yet
Development

No branches or pull requests

3 participants