Xcode - 编译Swift时出现“Segmentation Fault 11”错误

3

项目配置:
Xcode 7.3.1
最低iOS版本7.1
iOS SDK 9.3
cocoapods

在尝试编译混合的Objective-C/Swift项目时,出现错误Segmentation Fault 11,并伴随着以下构建日志:

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

在错误详情中,我可以看到非常长的输出,并包含一些有用的信息:

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

当我从设备切换到模拟器,然后再切回来时,架构编译错误会发生变化,因此不应该是架构问题。

通过阅读Mac控制台输出,我可以看到,在同一时刻,SourceKit服务崩溃了:

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

出现了一个完全随机的问题,项目一直运行正常,在某个时刻突然在模拟器上停止运行,但在设备上继续正常运行。之后它就无法运行了。回溯每一个提交,我可以看到这个问题在过去几周中存在,检查每一个变化是相当繁琐的工作,并且没有任何结果。

显然这是一些Xcode问题,但清理、删除派生数据、模块缓存、Xcode设置、重新安装Xcode、使用beta版本和先前版本的Xcode、删除源代码服务、禁用/启用模块支持、位码、增加/减少部署目标以及其他可谷歌到的建议 - 都会得到同样的结果。

阅读互联网评论 - 问题应该在与Swift相关的某个代码部分,但是完全注释或删除所有与Swift相关的代码会产生另一个错误:

cyclic dependency in module 'darwin'

任何框架,如Foundation或UIKit,都无法编译,我得到了数百个与未知类相关的错误。逐个创建新项目并添加文件也没有结果-在添加所有文件并安装cocoapods之后,项目一段时间内运行良好,但之后-同样的问题再次出现。因此,我看不到找到导致问题的确切代码部分的方法(这实际上是Xcode的错误,但几乎没有希望它会在Xcode 8中修复,因为它仍然存在于Beta版本中)。非常感谢任何有关此问题的帮助,我因此已经几天没睡好:)

你有桥接头文件吗? - mike vorisis
问题是在你放置 obj c 代码之后开始的还是之前?(所有 .h 必须在桥接文件中,不要注释任何内容) - mike vorisis
主要问题在于检测这个问题发生的确切时刻:项目以前一直运行良好,但现在当我回顾最近几周提交的代码时,它们仍然显示同样的错误,以同样随机的方式 - 有时可以正常工作,有时无法存档或在设备上运行。 - nominanza
我也看到了,但我不够幸运,所以它没有帮助。 - nominanza
构建阶段 > 复制捆绑资源到此处,如果有任何 .bundle 文件,请将其删除(为了更安全起见,请复制您的项目以解决此问题,这样您就不会失去任何东西) - mike vorisis
显示剩余4条评论
1个回答

1

我找到了导致问题的原因:

我在项目中有一个自定义的“Math.h”文件和类,导入并使用它会导致问题。

最奇怪的是,这个文件在过去的18天里一直在项目中,但一切都运行良好。我猜想这取决于我如何使用它,在Objective-C项目中使用它不会引起任何问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接