swiftlang / swift-package-manager

The Package Manager for the Swift Programming Language
Apache License 2.0
9.74k stars 1.34k forks source link

[SR-8735] Swift Package Manager Error - Illegal Instruction: 4 #4893

Closed swift-ci closed 5 years ago

swift-ci commented 6 years ago
Previous ID SR-8735
Radar None
Original Reporter Nasamura (JIRA User)
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Package Manager | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 0842e2da00764c3483315336388fb8e0

Issue Description:

Running

swift package update 

Last log before receiving the error:

sandbox-exec -p '(version 1)
(deny default)
(import "system.sb")
(allow file-read*)
(allow process*)
(allow sysctl*)
(allow file-write*
    (regex #"^/private/var/tmp/org\.llvm\.clang.*")
    (regex #"^/var/folders/t1/ql5g8dkd2rd5g6yf85fkrm3r0000gn/T/org\.llvm\.clang.*")
    (regex #"^/private/var/folders/t1/ql5g8dkd2rd5g6yf85fkrm3r0000gn/T/org\.llvm\.clang.*")
    (regex #"^/private/var/folders/t1/ql5g8dkd2rd5g6yf85fkrm3r0000gn/C/org\.llvm\.clang.*")
)
' /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc --driver-mode=swift -L /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/4 -lPackageDescription -suppress-warnings -swift-version 4 -I /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/4 -target x86_64-apple-macosx10.10 -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk /var/folders/t1/ql5g8dkd2rd5g6yf85fkrm3r0000gn/T/TemporaryFile.MgFBKH.swift -fileno 6
Illegal instruction: 4
$ swift package --version
Apple Swift Package Manager - Swift 4.2.0 (swiftpm-14248)

On the latest MacOS Mojave beta.

swift-ci commented 6 years ago

Comment by Nasamura (JIRA)

Strange thing I noticed about this bug is that it does not occur every time. I would estimate 9/10 runs of 'swift package update". My workaround at the moment is to keep running until it works...not ideal 🙂 Which must mean that the bug is not deterministic which is pretty odd, any idea why that would be?

Looks quite similar to https://bugs.swift.org/browse/SR-5595. Was this ever fixed?

swift-ci commented 6 years ago

Comment by Nasamura (JIRA)

Also I'm fairly sure I haven't duplicated a dependency, at least within the same Package.swift file.

swift-ci commented 6 years ago

Comment by Nasamura (JIRA)

Manually swiftc'd the Package.swift it appears to be failing on. Works fine.

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc --driver-mode=swift -L /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/4 -lPackageDescription -suppress-warnings -swift-version 4 -I /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/pm/4 -target x86_64-apple-macosx10.10 -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk Package.swift -fileno 1

{"errors": [], "package": {"cLanguageStandard": null, "cxxLanguageStandard": null, "dependencies": [{"requirement": {"lowerBound": "3.0.0", "type": "range", "upperBound": "4.0.0"}, "url": "https://github.com/vapor/core.git"}, {"requirement": {"lowerBound": "3.0.0", "type": "range", "upperBound": "4.0.0"}, "url": "https://github.com/vapor/crypto.git"}, {"requirement": {"lowerBound": "1.2.0", "type": "range", "upperBound": "2.0.0"}, "url": "https://github.com/vapor/database-kit.git"}, {"requirement": {"lowerBound": "1.0.0", "type": "range", "upperBound": "2.0.0"}, "url": "https://github.com/vapor/service.git"}, {"requirement": {"lowerBound": "1.0.0", "type": "range", "upperBound": "2.0.0"}, "url": "https://github.com/apple/swift-nio.git"}, {"requirement": {"lowerBound": "2.0.2", "type": "range", "upperBound": "3.0.0"}, "url": "https://github.com/vapor/sql.git"}], "name": "PostgreSQL", "products": [{"name": "PostgreSQL", "product_type": "library", "targets": ["PostgreSQL"], "type": null}], "targets": [{"dependencies": [{"name": "Async", "type": "byname"}, {"name": "Bits", "type": "byname"}, {"name": "Core", "type": "byname"}, {"name": "Crypto", "type": "byname"}, {"name": "DatabaseKit", "type": "byname"}, {"name": "NIO", "type": "byname"}, {"name": "Service", "type": "byname"}, {"name": "SQL", "type": "byname"}], "exclude": [], "name": "PostgreSQL", "path": null, "publicHeadersPath": null, "sources": null, "type": "regular"}, {"dependencies": [{"name": "Core", "type": "byname"}, {"name": "PostgreSQL", "type": "byname"}, {"name": "SQLBenchmark", "type": "byname"}], "exclude": [], "name": "PostgreSQLTests", "path": null, "publicHeadersPath": null, "sources": null, "type": "test"}]}}

aciidgh commented 6 years ago

This is probably due to the non-determinism issue that was surfaced recently. It was fixed in https://github.com/apple/swift-package-manager/pull/1759. Do you have any branch or revision based dependencies?

swift-ci commented 6 years ago

Comment by Nasamura (JIRA)

There is one repo that I need the "master" branch on that another dependancy has a versioned dependancy of the same repo. .i.e.

.package(url: "https://github.com/vapor/crypto.git", .branch("master")), // in my repo

and

.package(url: "https://github.com/vapor/crypto.git", from: "3.0.0"), // in a dependancy

So that bug could be very well related.

Separately, the error reporting here could obviously be a lot more descriptive. Do you know what is causing the Illegal Instruction: 4 and where it could be caught/handled better?

aciidgh commented 6 years ago

Yep, that case will triggering the crash. Note that there is no error in your package. This is a runtime crash due to a bug in SwiftPM code. The bug is fixed on trunk but was unfortunately shipped with the latest release of SwiftPM. This is mentioned in the Xcode 10's GM release notes:


The package manager might crash if a package graph contains shared dependencies with versioned and revision based requirements. Consider the following example package graph:
Root package:
PackageA@master
PackageA:
PackageB@master
PackageC@master
PackageB:
PackageC@1.0.0..\<2.0.0

According to the package manager’s dependency resolution rules, this should resolve to: PackageA @ master, PackageB @ master and PackageC @ master. However, since the shared dependency PackageC is referenced with 1.0.0..\<2.0.0 requirement, it may result in a crash.

Workaround: Use either versioned or revisioned based requirement for the shared package dependencies.


swift-ci commented 6 years ago

Comment by Nasamura (JIRA)

Thanks, unfortunately I can't fix this without forking the repo (currently at least) as the code I need exists in an unversioned commit. I guess I'll have to do that.

Out of curiosity I'm still not understanding how exactly an unordered dictionary could cause a runtime crash?