`trace trap`/ Xcode crash when adding .binaryTarget with local XCFramework

I've posted the same question on Apple Forums, but didn't get any response. Hope that is ok :)

I've created a sample Swift package which uses binaryTarget to add local XCFramework dependency to a package. XCFramework itself contain two static libraries: One for iOS simulator, and one for iOS device. The result is that Xcode crashes and the package manager fails with zsh: trace trap/ Error 4 on the command line:

Here is sample project download site:

Xcode-Crashes.zip - Google Drive

Here is an output from the M1:

gitlab@Gitlabs-Mac-mini Xcode-Crashes % swift build -Xswiftc "-sdk" -Xswiftc "`xcrun --sdk iphonesimulator --show-sdk-path`" -Xswiftc "-target" -Xswiftc "x86_64-apple-ios15.0-simulator" -v

/usr/bin/xcrun --sdk macosx --show-sdk-platform-path
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc -print-target-info
/usr/bin/xcrun --sdk macosx --find xctest
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc -print-target-info
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -print-target-info -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -print-target-info
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -emit-supported-features /var/folders/vq/_xcbbgg5605dppl019n65nj00000gn/T/TemporaryDirectory.Ga9HOY/dummyInput-1.swift
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc -print-target-info
/usr/bin/xcrun vtool -show-build /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/ManifestAPI/libPackageDescription.dylib
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc -L /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/ManifestAPI -lPackageDescription -Xlinker -rpath -Xlinker /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/ManifestAPI -target arm64-apple-macosx11.0 -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk -F /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -I /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -L /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -swift-version 5 -I /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/ManifestAPI -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk -package-description-version 5.5.0 /Users/gitlab/Downloads/Xcode-Crashes/Package.swift -Xfrontend -disable-implicit-concurrency-module-import -o /var/folders/vq/_xcbbgg5605dppl019n65nj00000gn/T/TemporaryDirectory.m6GXvH/xcode-crashes-manifest
/usr/bin/sandbox-exec -p '(version 1)
(deny default)
(import "system.sb")
(allow file-read*)
(allow process*)
(allow file-write*
    (subpath "/Users/gitlab/Library/Caches/org.swift.swiftpm/manifests")
)
' /var/folders/vq/_xcbbgg5605dppl019n65nj00000gn/T/TemporaryDirectory.m6GXvH/xcode-crashes-manifest -fileno 8
zsh: trace trap  swift build -Xswiftc "-sdk" -Xswiftc  -Xswiftc "-target" -Xswiftc  -v

I've tested it on both M1 and Intel Mac machines and both of them are crashing.

The xcframework I used is consisting from static libraries built for both simulator and device. Tried with device library only but it still not working.

I've posted the same question on Apple Forums

Can you send me a link to that thread?

I've tested it on both M1 and Intel Mac machines and both of them are
crashing.

Xcode should not crash just because you’ve given it bad inputs, so this is clearly bugworthy. I’d appreciate you filing a bug about that, making sure to include:

  • Your test package

  • A sysdiagnose log, which will capture the relevant crash reports

Please post your bug number, just for the record.

I opened your Package.swift on a (virtual) machine here in my office and, yeah, it did indeed crash Xcode (this is on macOS 12.0rc2 with Xcode 13.1rc). The resulting crashing report shows this:

Exception Type:        EXC_BAD_INSTRUCTION (SIGILL)

suggesting that you hit a Swift trap (on Intel we use the ud2 instruction for a trap). And the backtrace is deep in SwiftPM:

Thread 2 Crashed::  Dispatch queue: -[IDEExecutionEnvironment initWithWorkspaceArena:] (QOS: UNSPECIFIED)
0  SwiftPM             … 0x12abe4000 + 4095753
1  SwiftPM             … 0x12abe4000 + 4078658
2  SwiftPM             … 0x12abe4000 + 3795513
3  SwiftPM             … 0x12abe4000 + 3797560
4  SwiftPM             … 0x12abe4000 + 3665141
5  SwiftPM             … 0x12abe4000 + 3690689
6  SwiftPM             … 0x12abe4000 + 32529
7  SwiftPM             … 0x12abe4000 + 128031
8  IDESwiftPackageCore … closure #1 in IDESwiftWorkspace.enqueue(_:) + 426
9  IDESwiftPackageCore … partial apply for closure #1 in IDESwiftWorkspace.enqueue(_:) + 42
10 IDESwiftPackageCore … thunk for @escaping @callee_guaranteed (@guaranteed DVTOperation) -> () + 36
11 DVTFoundation       … -[DVTOperation main] + 232

Unfortunately I’m not able to symbolicate that, so I don’t have any suggestions as to what might be causing it.

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

I actually found my problem

Path of the internal framework was wrong. I was trying to use absolute path in it.
E.g this crashes:

        .binaryTarget(
            name: "Logging",
            path: "/src/libamcl_core.xcframework"
        )

And this is working(path is wrong on previous example):

        .binaryTarget(
            name: "Logging",
            path: "Sources/Crypto-Rado/src/libamcl_core.xcframework"
        )

@eskimo Thanks for the response, I will try to fill the bug today.

And here is the thread in the Apple Forum:
https://developer.apple.com/forums/thread/692290

Update:
Bug is logged: FB9723865

This has been fixed on the main branch of SwiftPM here: Fix crash with absolute path to binary artifact by neonichu · Pull Request #3737 · apple/swift-package-manager · GitHub

3 Likes