nominanza
nominanza

Reputation: 201

Xcode - Compile Swift Segmentation Fault 11

Project configuration: Xcode 7.3.1 min iOS version 7.1 iOS SDK 9.3 cocoapods

While trying to compile mixed Objective-C/Swift project - getting error Segmentation Fault 11, with the next build log:

Compile *.swift 
Command failed due to signal: Segmentation Fault 11

In details of, error I can see really long output with some useful info:

CompileSwift normal arm64 filePath/*.swift

0  swift                    0x000000010b73266b llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 43
1  swift                    0x000000010b731956 llvm::sys::RunSignalHandlers() + 70
2  swift                    0x000000010b732ccf SignalHandler(int) + 287
3  libsystem_platform.dylib 0x00007fff8b49e52a _sigtramp + 26
4  libsystem_platform.dylib 0x00007fa8f989d5e0 _sigtramp + 1849684176
5  swift                    0x000000010994d737 swift::ClangImporter::Implementation::addEntryToLookupTable(clang::Sema&, swift::SwiftLookupTable&, clang::NamedDecl*) + 151
6  swift                    0x000000010994d802 swift::ClangImporter::Implementation::addEntryToLookupTable(clang::Sema&, swift::SwiftLookupTable&, clang::NamedDecl*) + 354
7  swift                    0x000000010994e44c swift::ClangImporter::Implementation::importHeader(swift::ModuleDecl*, llvm::StringRef, swift::SourceLoc, bool, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer> >) + 1468
8  swift                    0x000000010994ebc6 swift::ClangImporter::importBridgingHeader(llvm::StringRef, swift::ModuleDecl*, swift::SourceLoc, bool) + 502
9  swift                    0x000000010993ef2d swift::CompilerInstance::performSema() + 605
10 swift                    0x0000000109482596 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&) + 934
11 swift                    0x000000010948168d frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 2781
12 swift                    0x000000010947d0ac main + 1932
13 libdyld.dylib            0x00007fff887b05ad start + 1
14 libdyld.dylib            0x000000000000026b start + 2005204159

And architecture compile error changes, if I switch from device to simulator and backwards, so shouldn't be architecture problem.

Reading Mac Console output I can see, crashes in SourceKit Service, at the same moment:

Thread 4 Crashed:: Dispatch queue: com.apple.root.default-qos
0   com.apple.SourceKitService.703.0.18.8   0x0000000106f1ca63 swift::ClangNode::getLocation() const + 19
1   com.apple.SourceKitService.703.0.18.8   0x0000000106c22a0f swift::ClangImporter::lookupBridgingHeaderDecls(llvm::function_ref<bool (swift::ClangNode)>, llvm::function_ref<void (swift::Decl*)>) const + 111
2   com.apple.SourceKitService.703.0.18.8   0x0000000106c22cb8 swift::ClangImporter::lookupDeclsFromHeader(llvm::StringRef, llvm::function_ref<bool (swift::ClangNode)>, llvm::function_ref<void (swift::Decl*)>) const + 216
3   com.apple.SourceKitService.703.0.18.8   0x00000001069a9034 swift::ide::printHeaderInterface(llvm::StringRef, swift::ASTContext&, swift::ASTPrinter&, swift::PrintOptions const&) + 852
4   com.apple.SourceKitService.703.0.18.8   0x00000001068bf368 SourceKit::SwiftInterfaceGenContext::create(llvm::StringRef, bool, llvm::StringRef, swift::CompilerInvocation, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) + 1992
5   com.apple.SourceKitService.703.0.18.8   0x00000001068c1de8 SourceKit::SwiftLangSupport::editorOpenHeaderInterface(SourceKit::EditorConsumer&, llvm::StringRef, llvm::StringRef, llvm::ArrayRef<char const*>) + 1704
6   com.apple.SourceKitService.703.0.18.8   0x00000001068d7895 handleRequestImpl(void*, std::__1::function<void (void*)>) + 6773
7   com.apple.SourceKitService.703.0.18.8   0x00000001068d5dc4 sourcekitd::handleRequest(void*, std::__1::function<void (void*)>) + 420

Problem has occurred absolutely randomly project was always working fine, and at one point just stopped running on simulator, but continued running fine on device. After that it just stopped running anyway. Going back commit by commit, I can see, that this problem existed during the last couple of weeks, and checking every change it is quite a bit job and doesn't give any results.

Apparently it is some Xcode issue, but cleaning, removing derived data, module caches, Xcode settings, reinstalling Xcode, using beta version and previous version of Xcode, removing Source Kit Service, disabling/enabling modules support, bitcode, increasing/decreasing deployment target and any other suggestions, that can be googled - give the same result.

Reading internet comments - the problem should be in some part of the code, related with swift, but completely commenting or removing all swift related code gives another error:

cyclic dependency in module 'darwin'

And this way any of the frameworks like Foundation or UIKit, cannot be compiled, and I'm getting hundreds of errors, related to unknown classes.

Creating new project and adding files there one by one, didn't give any result as well - after adding all files and installing cocoapods, project has worked fine for some time, but after that - the same problem has started again.

So I see no way, how to find the exact part of code, which causes the problem (which really is Xcode bug, but there is almost no hope, that it will be fixed in Xcode 8, because it still exists in Beta version).

Will be glad to hear any help regarding this issue, I just can't sleep for a couple of days because of it :)

Upvotes: 3

Views: 1082

Answers (1)

nominanza
nominanza

Reputation: 201

Found what has caused my issue:

I've had "Math.h" custom file and class in project, importing and using it caused an issue.

The strangest thing, that this file was in project during last 18 days, but everything worked fine. I guess, that it depends on how I'm using it, using it in Objective-C project, doesn't cause any issue.

Upvotes: 1

Related Questions