SQLite User Forum

sqlite 3.50.3 core dump on Solaris sparc
Login

sqlite 3.50.3 core dump on Solaris sparc

(1.1) By Marcel Hofstetter (jomasoftmarcel) on 2025-07-28 12:18:57 edited from 1.0 [source]

# ./sqlite3.50.3 /var/opt/jomasoft/vdcf/db/infra.db
SQLite version 3.50.3 2025-07-17 13:25:10
Enter ".help" for usage hints.
sqlite> select count(*) from server;
Bus Error (core dumped)

# uname -a
SunOS g0049 5.11 11.4.83.195.1 sun4v sparc sun4v logical-domain

# pstack /var/cores/core.sqlite3.50.3.15039
core '/var/cores/core.sqlite3.50.3.15039' of 15039:     ./sqlite3.50.3 /var/opt/jomasoft/vdcf/db/infra.db
 000000010011379c sqlite3ResolveSelfReference (0xffffffff7fffc240?, 0x1002e52a8?, 0x20?, 0x1002e5378?, 0x0?, 0x1002e5516?) + 7c
 000000010013b2fc sqlite3CreateIndex (0xffffffff7fffc240?, 0x0?, 0x0?, 0x0?, 0x0?, 0xb?) + c3c
 00000001001a6478 yy_reduce (0xffffffff7fffb798?, 0x28?, 0x19?, 0x1002d961a?, 0x100000000?, 0xffffffff7fffc240?) + 908
 00000001001ab998 sqlite3Parser (0xffffffff7fffb798?, 0x19?, 0x1002d961a?, 0x100000000?, 0x0?, 0xffffffff7fffc3bf?) + 108
 00000001001ad848 sqlite3RunParser (0xffffffff7fffc240?, 0x1002d95e8?, 0x0?, 0xffffffff7fffc3e0?, 0x0?, 0x0?) + 348
 000000010015eff0 sqlite3Prepare (0x1002ced48?, 0x1002d95e8?, 0xffffffffffffffff?, 0x0?, 0x0?, 0xffffffff7fffc500?) + 380
 000000010015da88 sqlite3InitCallback (0xffffffff7fffc768?, 0x5?, 0x1002dbd80?, 0x1002dbd58?, 0x10015d860?, 0x0?) + 228
 0000000100154518 sqlite3_exec (0x1002ced48?, 0x1002dc058?, 0x10015d860?, 0xffffffff7fffc768?, 0x0?, 0x0?) + 378
 000000010015e2cc sqlite3InitOne (0x1002ced48?, 0x0?, 0xffffffff7fffdf88?, 0x0?, 0x0?, 0x0?) + 57c
 000000010015e528 sqlite3Init (0x1002ced48?, 0xffffffff7fffdf88?, 0xffff0000?, 0x1?, 0x1?, 0x0?) + 88
 000000010015e670 sqlite3ReadSchema (0xffffffff7fffdf80?, 0x0?, 0xffffffff7fffdf80?, 0xce?, 0xffffffff7fffd4d8?, 0x0?) + 40
 00000001001a6a5c yy_reduce (0xffffffff7fffd4d8?, 0x54?, 0x1?, 0x1002deb8b?, 0x100000000?, 0xffffffff7fffdf80?) + eec
 00000001001ab998 sqlite3Parser (0xffffffff7fffd4d8?, 0x1?, 0x1002deb8b?, 0x100000000?, 0x0?, 0xffffffff7fffe0ff?) + 108
 00000001001ad848 sqlite3RunParser (0xffffffff7fffdf80?, 0x1002deb70?, 0x0?, 0xffffffff7fffe120?, 0x0?, 0x0?) + 348
 000000010015eff0 sqlite3Prepare (0x1002ced48?, 0x1002deb70?, 0xffffffffffffffff?, 0x80?, 0x0?, 0xffffffff7fffe418?) + 380
 000000010015f2a8 sqlite3LockAndPrepare (0x1002ced48?, 0x1002deb70?, 0xffffffffffffffff?, 0x80?, 0x0?, 0xffffffff7fffe418?) + c8
 000000010015f52c sqlite3_prepare_v2 (0x1002ced48?, 0x1002deb70?, 0xffffffffffffffff?, 0xffffffff7fffe418?, 0xffffffff7fffe408?, 0x0?) + 2c
 000000010007abe4 shell_exec (0xffffffff7ffff1b0?, 0x1002deb70?, 0xffffffff7fffed50?, 0x0?, 0x0?, 0x0?) + e4
 000000010009474c runOneSqlLine (0xffffffff7ffff1b0?, 0x1002deb70?, 0x0?, 0x1?, 0x5?, 0x1002deb8c?) + 8c
 0000000100095198 process_input (0xffffffff7ffff1b0?, 0x1002cd5d0?, 0x10003f928?, 0x1002cfcf0?, 0x1002cfcf0?, 0x49?) + 6a8
 00000001000989ac main (0x2?, 0xffffffff7ffff928?, 0xffffffff7ffff940?, 0xffffffff7f5c0100?, 0xffffffff7f5c0140?, 0x0?) + 2bac
 0000000100046970 _start (0x0?, 0x0?, 0x0?, 0x0?, 0x0?, 0x1002c6ef0?) + 110


works well with 3.46.0

./sqlite3.46.0 /var/opt/jomasoft/vdcf/db/infra.db
SQLite version 3.46.0 2024-05-23 13:25:27
Enter ".help" for usage hints.
sqlite> select count(*) from server;
28


Thanks,
Marcel

(2) By Richard Hipp (drh) on 2025-07-28 12:17:38 in reply to 1.0 [link] [source]

Everything works fine (including under valgrind, and various -fsanitize= options) on every other platform we've tried, including systems running on unusual CPUs like PPC and RISC-V. This must be something specific to SunOS and/or Sparc.

Are you able to provide the SQLite developers with an SSH login to a SunOS-Sparc machine so that we can debug it?

(3) By Marcel Hofstetter (jomasoftmarcel) on 2025-07-28 12:21:55 in reply to 2 [link] [source]

yes we can provide login

(4) By Marcel Hofstetter (jomasoftmarcel) on 2025-07-28 12:37:30 in reply to 3 [link] [source]

Issue is since 3.50.0

-bash-5.2$ ./sqlite3.50.0 infra.db
SQLite version 3.50.0 2025-05-29 14:26:00
Enter ".help" for usage hints.
sqlite> select count(*) from server;
Bus Error

last working version

-bash-5.2$ ./sqlite3.49.2 ./infra.db
SQLite version 3.49.2 2025-05-07 10:39:52
Enter ".help" for usage hints.
sqlite> select count(*) from server;
28

(5) By Richard Hipp (drh) on 2025-07-28 14:03:11 in reply to 1.1 [link] [source]

Thank you, Marcel, for the SSH access.

I am unable to reproduce the problem using my own builds of SQLite from sources. I don't have read permission on the /var/opt/jomasoft/vdcf/db/infra.db database, so I cannot test with that. But using other databases, SQLite seems to work just fine. The compiler does give lots of warnings of like this:

warning: array subscript has type 'char'

That's a warning I've never seen before, and which I don't really understand. Is there some issue using a char value as a subscription on Sparc or something? Why do we not see that warning on other platforms?

I'm running "gmail test" on version 3.50.3 on your machine as I type in this response. No issues detected so far...

How are you building SQLite?

(6) By Marcel Hofstetter (jomasoftmarcel) on 2025-07-28 14:36:12 in reply to 5 [link] [source]

we compile using the Solaris Developer Studio compiler

-bash-5.2$ cd sqlite-amalgamation-3500000
-bash-5.2$
-bash-5.2$ /opt/developerstudio12.6/bin/cc shell.c sqlite3.c -mt -m64 -ldl -lm -o sqlite3
shell.c:
"shell.c", line 5160: warning: syntax error:  empty declaration
"shell.c", line 5484: warning: syntax error:  empty declaration
sqlite3.c:
"sqlite3.c", line 36207: warning: conversion to double is out of range
"sqlite3.c", line 60987: warning: statement not reached
"sqlite3.c", line 90068: warning: statement not reached
"sqlite3.c", line 94820: warning: statement not reached
"sqlite3.c", line 98318: warning: statement not reached
"sqlite3.c", line 156958: warning: statement not reached
-bash-5.2$
-bash-5.2$ ./sqlite3 ../../infra.db
SQLite version 3.50.0 2025-05-29 14:26:00
Enter ".help" for usage hints.
sqlite> select count(*) from server;
Bus Error

(7) By ddevienne on 2025-07-28 15:19:26 in reply to 6 [link] [source]

Could it be related to the signed'ness of char?

I read that for this compiler, on SPARC it's unsigned and on Intel/AMD it's signed.
Which platform are you compiling for? (sounded like the former, i.e. SPARC).
Do you have an (GCC style) option like -fsigned-char to force it, for that compiler?

(8) By Richard Hipp (drh) on 2025-07-28 15:36:01 in reply to 7 [link] [source]

We routinely run 100% MC/DC tests in TH3 using both -fsigned-char and -funsigned-char on both Intel and ARM platforms. So SQLite should work the same regardless of whether characters are natively signed or unsigned.

(9) By Sam James (thesamesam) on 2025-07-30 08:02:37 in reply to 7 [link] [source]

SIGBUS generally means an alignment issue.

(10) By Richard Hipp (drh) on 2025-07-30 11:29:38 in reply to 9 [link] [source]

With the cooperation of the OP, we have access to the Sparc machine that demonstrates the problem and what we have found is that SQLite works fine when compiled on that machine using GCC. It only shows the SIGBUS when compiled using the DeveloperStudio 12.6 compiler. We were able to bisect back to the introduction of the Flexible Array syntax by check-in 2025-03-15T19:55z as recommended by forum post 2025-03-13T15:50:54z.

(11) By ddevienne on 2025-07-30 11:45:22 in reply to 10 [link] [source]

Thanks for the update. Wikipedia does state:

Flexible array members were officially standardized in C99.
In practice, compilers (e.g. GCC, MSVC) provided them well before C99 was standardized.

I thought SQLite stuck to C89 (aka ANSI C).

Different compiler, different non-standard extensions (or lack thereof).

Perhaps there's an option to opt-in to C99 for that compiler? Might compile as-is then?

(12.1) By Stephan Beal (stephan) on 2025-07-30 12:52:40 edited from 12.0 in reply to 11 [link] [source]

Perhaps there's an option to opt-in to C99 for that compiler?

That's a great suggestion. That compiler claims to support -std=c99. Trying...

Nope. Same crash.

Also tried with -std=c11 and -std=gnu11, both of which it claims to support.

Might compile as-is then?

It's compiling fine, barring a mountain of warnings about "empty declarations" and "unreachable statements" which we don't otherwise see, but it really doesn't like the flex-array thing.

Edit:

I thought SQLite stuck to C89 (aka ANSI C).

For the most part, yes, but some features require inching outside of that box. A prominent example is the long long type, which is not part of C89 but which is implemented by every known extant compiler.

(13) By Bo Lindbergh (_blgl_) on 2025-07-30 17:33:27 in reply to 10 [link] [source]

In src/resolve.c, function sqlite3ResolveSelfReference, before this commit:

  SrcList sSrc;                   /* Fake SrcList for pParse->pNewTable */

and after this commit:

  SrcList *pSrc;                  /* Fake SrcList for pParse->pNewTable */
  u8 srcSpace[SZ_SRCLIST_1];     /* Memory space for the fake SrcList */
  pSrc = (SrcList*)srcSpace;

This is alignment error bait.

To ensure correct alignment, try using a union:

  union {
    SrcList sSrc;                   /* Fake SrcList for pParse->pNewTable */
    u8 space[SZ_SRCLIST_1];
  } uSrc;

There are similar constructs in these files:

src/trigger.c
src/vdbeInt.h
src/wherecode.c
ext/fts5/fts5_index.c
test/fuzzcheck.c

(14) By Richard Hipp (drh) on 2025-07-30 18:26:55 in reply to 13 [link] [source]

I started working on that, but then I discovered that check-in 2025-07-30T18:23:33z which cases the SQLITE_PTRSIZE macro to be set to 4 instead of 8 for the Developer-Studio compiler is sufficient to clear the problem. One can also work-around the problem by compile with CFLAGS=-DSQLITE_PTRSIZE=4.

(15) By Richard Hipp (drh) on 2025-07-30 19:26:31 in reply to 14 [link] [source]

I spoke too soon. Apparently I was compiling without the -m64 flag, and without that flag, no changes are needed. I have to add Bo's patch (or similar) to get it to work with the -m64 flag on the compiler....

(16) By Richard Hipp (drh) on 2025-07-31 12:27:47 in reply to 15 [link] [source]

Stephan implemented Bo's alignment suggestion and that seems to clear the problem regardless of the presence or absence of the -m64 flag. Those changes are now on trunk. So I think the issue is now resolved.

(17) By Rowan Worth (sqweek) on 2025-08-01 08:59:48 in reply to 9 [link] [source]

I've also seen SIGBUS when an active process's executable file lives on NFS, and the file is replaced while the process is running.

(18.1) By Sam James (thesamesam) on 2025-08-01 13:53:49 edited from 18.0 in reply to 17 [link] [source]

Indeed, but we're talking about SPARC, and the scenario you describe didn't seem likely here ;)

But you are of course right. I was just trying to describe what looks likely here (i.e. alignment) and that signedness of char was surely a red herring.