Swift: segmentation fault when compiling for Archive from iOS 7
Asked Answered
C

5

12

I've always had this issue so I started creating a new single-view application, in Swift, for both iPhone and iPad. When the target is iOS 8.1 everything works fine, but if I set iOS 7.1 (or 7), i get a Segmentation fault. This happens when i go to Product > Archive, when i Run the project in the simulator or my device, everything is fine. I tried with both iOS 7 and 8 simulators and it compiles. As I said, the problem is not in the code since it behaves this way even with a newly created project.

CompileSwift normal armv7 /Users/francesco/Documents/XCode Projects/Prova/Prova/ViewController.swift
cd /Users/francesco/Documents/XCode Projects/Prova
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file "/Users/francesco/Documents/XCode Projects/Prova/Prova/ViewController.swift" "/Users/francesco/Documents/XCode Projects/Prova/Prova/AppDelegate.swift" -target armv7-apple-ios7.1 -target-cpu cortex-a8 -target-abi apcs-gnu -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk -I /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/BuildProductsPath/Release-iphoneos -F /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/BuildProductsPath/Release-iphoneos -g -module-cache-path /Users/francesco/Library/Developer/Xcode/DerivedData/ModuleCache -Xcc -I/Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Prova-generated-files.hmap -Xcc -I/Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Prova-own-target-headers.hmap -Xcc -I/Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Prova-all-target-headers.hmap -Xcc -iquote -Xcc /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Prova-project-headers.hmap -Xcc -I/Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/BuildProductsPath/Release-iphoneos/include -Xcc -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -Xcc -I/Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/DerivedSources/armv7 -Xcc -I/Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/DerivedSources -emit-module-doc-path /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Objects-normal/armv7/ViewController~partial.swiftdoc -O -module-name Prova -emit-module-path /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Objects-normal/armv7/ViewController~partial.swiftmodule -serialize-diagnostics-path /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Objects-normal/armv7/ViewController.dia -emit-dependencies-path /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Objects-normal/armv7/ViewController.d -o /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Objects-normal/armv7/ViewController.o

Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/francesco/Documents/XCode Projects/Prova/Prova/ViewController.swift /Users/francesco/Documents/XCode Projects/Prova/Prova/AppDelegate.swift -target armv7-apple-ios7.1 -target-cpu cortex-a8 -target-abi apcs-gnu -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS8.1.sdk -I /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/BuildProductsPath/Release-iphoneos -F /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/BuildProductsPath/Release-iphoneos -g -module-cache-path /Users/francesco/Library/Developer/Xcode/DerivedData/ModuleCache -Xcc -I/Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Prova-generated-files.hmap -Xcc -I/Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Prova-own-target-headers.hmap -Xcc -I/Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Prova-all-target-headers.hmap -Xcc -iquote -Xcc /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Prova-project-headers.hmap -Xcc -I/Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/BuildProductsPath/Release-iphoneos/include -Xcc -I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -Xcc -I/Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/DerivedSources/armv7 -Xcc -I/Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/DerivedSources -emit-module-doc-path /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Objects-normal/armv7/ViewController~partial.swiftdoc -O -module-name Prova -emit-module-path /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Objects-normal/armv7/ViewController~partial.swiftmodule -serialize-diagnostics-path /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Objects-normal/armv7/ViewController.dia -emit-dependencies-path /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Objects-normal/armv7/ViewController.d -o /Users/francesco/Library/Developer/Xcode/DerivedData/Prova-argzihphsooyijfpeustrrhxmfmk/Build/Intermediates/ArchiveIntermediates/Prova/IntermediateBuildFilesPath/Prova.build/Release-iphoneos/Prova.build/Objects-normal/armv7/ViewController.o 
1.  While type-checking 'ViewController' at /Users/francesco/Documents/XCode Projects/Prova/Prova/ViewController.swift:11:1

Command failed due to signal: Segmentation fault: 11

Does anybody have any idea about this issue?

UPDATE: I can target armv7s and arm64 to iOS 7, armv7 is what causes the issue; if armv7 is targeted to iOS 8 and others to iOS 7, everything works. That's not a good solution since it's more important to support older OSs on older devices, in my opinion.

Compliance answered 4/11, 2014 at 9:5 Comment(0)
C
2

Closing Xcode and opening another project, then loading back this one, solved the issue. It was a bug, I guess.

Compliance answered 5/11, 2014 at 0:55 Comment(0)
E
3

I had the same problem until someone told me that it's a problem with the certificates. Go to the Dev Center and regenerate your Certificates & Provisioning Profiles. After that it should work!

Eckmann answered 4/11, 2014 at 9:36 Comment(3)
It was all set to automatic, so Xcode would find and (try to) fix issues, right?Compliance
No, this won't help. You have to renew your certificates as well (upload a new code signing request (.csr) file and recreate all provisioning profiles).Eckmann
Oh my god. This was absolutely it for me. I went to preferences>account>details and hit the refresh button on my certificates. No more segment 11 fault. The stack trace is crazy misleading--talks about an error with type checking. I was moving potentially ambiguous TypeAlias' around, all kinds of things. Thanks @Hannes!Leandroleaning
C
2

Closing Xcode and opening another project, then loading back this one, solved the issue. It was a bug, I guess.

Compliance answered 5/11, 2014 at 0:55 Comment(0)
K
2

I had the same issue on Xcode 6.1. Building and running the Swift project was no problem, archiving led to an error:

Command failed due to signal: Segmentation fault: 11
1.  While type-checking <my Swift class>

Changing the project's Deployment Target from 7.0 to 7.1 solved the problem, the app can now be archived.

Kayser answered 21/11, 2014 at 8:32 Comment(0)
D
0

I ran into the same issue, and trying the selected answer (i.e. closing and re-opening Xcode etc) as well as other experiments did not help. Based on the stack trace the following code was failing:

var cell = self.tableView.cellForRowAtIndexPath(NSIndexPath(forRow: row, inSection: 0)) as UITableViewCell
var cell2 = self.tableView.cellForRowAtIndexPath(NSIndexPath(forRow: row2, inSection: 0)) as UITableViewCell

In subsequent code I was treating both cell and cell2 as optionals, so I did not bother unwrapping these assignments. Apparently Swift hated it enough to Seg-fault on me. After some experimentation I changed the code to

var cell = self.tableView.cellForRowAtIndexPath(NSIndexPath(forRow: row, inSection: 0)) as UITableViewCell!
var cell2 = self.tableView.cellForRowAtIndexPath(NSIndexPath(forRow: row2, inSection: 0)) as UITableViewCell!

and the Swift Segmentation fault stopped. The issue was with Xcode 6.1.1 (6A2008A).

If you are still having this issue you should look at where the stack trace mentions the crash is occurring. It will say something about emitting code and should be locatable.

Dukedom answered 14/2, 2015 at 21:1 Comment(0)
C
0

I had the same problem – compilation would run fine in the simulator and on the device, but I would get seg fault 11 during archiving. I tried some of the other solutions here but was still getting the error.

I isolated the cause to a method that used generics and the NSCoding protocol. Removing the protocol fixed the problem.

This was causing the seg fault:

 func saveToDefaults<T: NSCoding>(objectToSave : T?, key : String)

But changing it to this fixed it:

 func saveToDefaults<T>(objectToSave : T?, key : String){
     if let objectToSave = objectToSave as? NSCoding {
          ...

It's not as robust as the original, but it compiles.

Cypress answered 1/7, 2015 at 15:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.