[swift-users] Segfault importing sqlite3.h from a system module

Michael Buhot m.buhot at gmail.com
Sat Dec 5 06:29:04 CST 2015


Hello,

I’m getting a segfault when importing sqlite using a swift system module and the package manager.
I have the following directory structure with a trivial system module and application:

CSqlite3/
  Package.swift
  module.modulemap
  .git/

app/
  Package.swift
  main.swift
  .git/

CSqlite3 is a system module I created with an empty Package.swift file, and module.modulemap: 

module CSqlite3 [system] {
    header "/usr/include/sqlite3.h"
    link "sqlite3"
    export *
}

app/Package.swift contains:
import PackageDescription

let package = Package(
    dependencies: [
        .Package(url: "../CSqlite3", majorVersion: 1)
    ]
)

And main.swift contains:
import CSqlite3
print("hello world”)

The error I’m getting is:
$ swift build
Compiling Swift Module 'app' (1 sources)
0  swift                    0x00000001026ea47b llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 43
1  swift                    0x00000001026e9916 llvm::sys::RunSignalHandlers() + 70
2  swift                    0x00000001026eaaa3 SignalHandler(int) + 243
3  libsystem_platform.dylib 0x00007fff8d25852a _sigtramp + 26
4  libsystem_platform.dylib 0x0000000000003c00 _sigtramp + 1926936304
5  swift                    0x0000000100f0502d clang::Preprocessor::MacroState::getModuleInfo(clang::Preprocessor&, clang::IdentifierInfo const*) const + 189
6  swift                    0x0000000100f04a76 clang::Preprocessor::getMacroDefinition(clang::IdentifierInfo const*) + 326
7  swift                    0x0000000101872e50 clang::Preprocessor::HandleIdentifier(clang::Token&) + 320
8  swift                    0x000000010181c4f4 clang::Lexer::LexIdentifier(clang::Token&, char const*) + 932
9  swift                    0x0000000101822312 clang::Lexer::LexTokenInternal(clang::Token&, bool) + 8562
10 swift                    0x00000001018734c4 clang::Preprocessor::Lex(clang::Token&) + 68
11 swift                    0x00000001018442b7 clang::Preprocessor::ReadMacroName(clang::Token&, clang::MacroUse, bool*) + 55
12 swift                    0x0000000101847630 clang::Preprocessor::HandleIfdefDirective(clang::Token&, bool, bool) + 48
13 swift                    0x00000001018464f4 clang::Preprocessor::HandleDirective(clang::Token&) + 1124
14 swift                    0x0000000101822966 clang::Lexer::LexTokenInternal(clang::Token&, bool) + 10182
15 swift                    0x00000001018734c4 clang::Preprocessor::Lex(clang::Token&) + 68
16 swift                    0x00000001011598bf clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&) + 287
17 swift                    0x00000001010db875 clang::ParseAST(clang::Sema&, bool, bool) + 501
18 swift                    0x0000000100f2eb72 clang::FrontendAction::Execute() + 66
19 swift                    0x0000000100efaf43 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 979
20 swift                    0x000000010268e98d llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) + 269
21 swift                    0x000000010268ead0 RunSafelyOnThread_Dispatch(void*) + 48
22 swift                    0x00000001026ebaed ExecuteOnThread_Dispatch(void*) + 13
23 libsystem_pthread.dylib  0x00007fff8ea2a9b1 _pthread_body + 131
24 libsystem_pthread.dylib  0x00007fff8ea2a92e _pthread_body + 0
25 libsystem_pthread.dylib  0x00007fff8ea28385 thread_start + 13
Stack dump:
0.	/usr/include/sqlite3.h:76:2: current parser token 'ifndef'
<unknown>:0: error: unable to execute command: Segmentation fault: 11
<unknown>:0: error: compile command failed due to signal (use -v to see invocation)
<unknown>:0: error: build had 1 command failures
swift-build: exit(1): ["/Library/Developer/Toolchains/swift-2.2-SNAPSHOT-2015-12-01-a.xctoolchain/usr/bin/swift-build-tool", "-f", "/Users/mbuhot/source/app/.build/debug/app.o/llbuild.yaml”]

Is this a bug or have I messed something up?
Help much appreciated!


Mike Buhot



More information about the swift-users mailing list