Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"unexpected signal during runtime execution" when setting compile time options #1153

Open
bprosnitz opened this issue Apr 14, 2023 · 3 comments

Comments

@bprosnitz
Copy link

When I run go build with sqlite compile time flags such as CGO_CFLAGS="-DSQLITE_OMIT_AUTOINIT", go panics with unexpected signal during runtime execution.

Is it possible to set sqlite compile time flags? Is there another way that this should be done?

Partial stack trace:

fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x0]

runtime stack:
runtime.throw({0x2432e3d?, 0xffffffff000036b9?})
        /usr/local/go/src/runtime/panic.go:1047 +0x5d fp=0x7f183fffeee0 sp=0x7f183fffeeb0 pc=0x43b0dd
runtime.sigpanic()
        /usr/local/go/src/runtime/signal_unix.go:821 +0x3e9 fp=0x7f183fffef40 sp=0x7f183fffeee0 pc=0x452129

goroutine 1 [syscall]:
runtime.cgocall(0x1caddb0, 0xc000daf030)
        /usr/local/go/src/runtime/cgocall.go:157 +0x5c fp=0xc000daf008 sp=0xc000daefd0 pc=0x405edc
github.com/mattn/go-sqlite3._Cfunc__sqlite3_open_v2(0x7f1838000dd0, 0xc001309e90, 0x10006, 0x0)
        _cgo_gotypes.go:305 +0x4c fp=0xc000daf030 sp=0xc000daf008 pc=0xce7ccc
github.com/mattn/go-sqlite3.(*SQLiteDriver).Open.func3(0x7f1838000dd0?, 0x23?, 0x10000, 0x3?)
        /home/circleci/go/pkg/mod/github.com/mattn/go-sqlite3@v1.14.15/sqlite3.go:1456 +0x72 fp=0xc000daf080 sp=0xc000daf030 pc=0xcf9152
github.com/mattn/go-sqlite3.(*SQLiteDriver).Open(0xc0001a4a40, {0xc000d81ce0, 0x2c})
        /home/circleci/go/pkg/mod/github.com/mattn/go-sqlite3@v1.14.15/sqlite3.go:1456 +0x27b4 fp=0xc000daf6b0 sp=0xc000daf080 pc=0xcf67b4
database/sql.dsnConnector.Connect(...)
        /usr/local/go/src/database/sql/sql.go:758
database/sql.(*dsnConnector).Connect(0x26?, {0x800?, 0x1c58540?})
        <autogenerated>:1 +0x3a fp=0xc000daf6d8 sp=0xc000daf6b0 pc=0xca749a
database/sql.(*DB).conn(0xc000ddaf70, {0x29ec228, 0xc00018a000}, 0x1)
        /usr/local/go/src/database/sql/sql.go:1387 +0x763 fp=0xc000daf850 sp=0xc000daf6d8 pc=0xc9b343
database/sql.(*DB).exec(0xc0011780d0?, {0x29ec228, 0xc00018a000}, {0x23f52d7, 0x19}, {0x0, 0x0, 0x0}, 0x78?)
        /usr/local/go/src/database/sql/sql.go:1651 +0x5d fp=0xc000daf8c8 sp=0xc000daf850 pc=0xc9cd7d
database/sql.(*DB).ExecContext.func1(0x16?)
        /usr/local/go/src/database/sql/sql.go:1634 +0x55 fp=0xc000daf930 sp=0xc000daf8c8 pc=0xc9cbf5
database/sql.(*DB).retry(0x40fd28?, 0xc000daf9a8)
        /usr/local/go/src/database/sql/sql.go:1538 +0x47 fp=0xc000daf978 sp=0xc000daf930 pc=0xc9c167
database/sql.(*DB).ExecContext(0x2406e20?, {0x29ec228?, 0xc00018a000?}, {0x23f52d7?, 0x1?}, {0x0?, 0x24?, 0x0?})
        /usr/local/go/src/database/sql/sql.go:1633 +0xcc fp=0xc000dafa10 sp=0xc000daf978 pc=0xc9cb0c
database/sql.(*DB).Exec(...)
        /usr/local/go/src/database/sql/sql.go:1647

[...]

goroutine 86 [select]:
runtime.gopark(0xc000081f88?, 0x2?, 0x28?, 0xfd?, 0xc000081f84?)
        /usr/local/go/src/runtime/proc.go:381 +0xd6 fp=0xc000081e10 sp=0xc000081df0 pc=0x43ddf6
runtime.selectgo(0xc000081f88, 0xc000081f80, 0xc0011b6c60?, 0x0, 0x0?, 0x1)
        /usr/local/go/src/runtime/select.go:327 +0x7be fp=0xc000081f50 sp=0xc000081e10 pc=0x44e0be
database/sql.(*DB).connectionOpener(0xc000ddaf70, {0x29ec1f0, 0xc0012e5680})
        /usr/local/go/src/database/sql/sql.go:1218 +0x8d fp=0xc000081fb8 sp=0xc000081f50 pc=0xc9a66d
database/sql.OpenDB.func1()
        /usr/local/go/src/database/sql/sql.go:791 +0x2e fp=0xc000081fe0 sp=0xc000081fb8 pc=0xc989ee
runtime.goexit()
        /usr/local/go/src/runtime/asm_amd64.s:1598 +0x1 fp=0xc000081fe8 sp=0xc000081fe0 pc=0x4724a1
created by database/sql.OpenDB
        /usr/local/go/src/database/sql/sql.go:791 +0x18d

@rittneje
Copy link
Collaborator

Some SQLITE_OMIT_* options might work, or appear to work, when used with the amalgamation. But this is not guaranteed. In general, always compile from canonical sources in order to take advantage of SQLITE_OMIT_* options.

You likely need to build your own version of SQLite from scratch if you want such customization.

@bprosnitz
Copy link
Author

Is there a better way to build a custom SQLite for use with go-sqlite3?

Since the c code is in the go-sqlite3 repo and appears to be built with cgo, I assumed that directly changing the code in the repo or setting CGO_CFLAGS would be the way to do it. I also tried adding this flag to sqlite3.go in the repo with the same result.

@rittneje
Copy link
Collaborator

The C code in this repo is the aforementioned amalgamation. Therefore, as per the SQLite docs, just setting CFLAGS alone is insufficient.

Either you will have to fork this repo to replace it with your own custom build amalgamation, or you may be able to get it to work with the libsqlite3 build tag by directing it to link against your custom library. I've never done it, so I cannot offer any further detail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants