I get a SEGFAULT every time I try log in to my MySQL server using mysql-native and vibe.d.
If I compile with GDC I do not have this problem, and I never used to have this problem with previous versions of dmd, not sure which version etc yet.
Just logging this issue in the meantime so that I don't forget.
Backtrace:
Program received signal SIGSEGV, Segmentation fault.
0x0000000000000000 in ?? ()
(gdb) by
Undefined command: "by". Try "help".
(gdb) bt
#0 0x0000000000000000 in ?? ()
#1 0x0000000000712eea in std.digest.sha.SHA!(512, 160).SHA.put(scope const(ubyte)[]...) (this=0x7fffffffd160, input=...) at /usr/include/dmd/phobos/std/digest/sha.d:723
#2 0x0000000000713072 in std.digest.sha.SHA!(512, 160).SHA.finish() (this=0x7fffffffd160, __HID34=0x7fffffffd1d0) at /usr/include/dmd/phobos/std/digest/sha.d:768
#3 0x000000000076f54a in std.digest.digest.digest!(std.digest.sha.SHA!(512, 160).SHA, const(ubyte)[]).digest(scope const(ubyte[])) (__HID42=0x7fffffffd228, _param_0=...)
at /usr/include/dmd/phobos/std/digest/digest.d:433
#4 0x000000000076f4c1 in std.digest.sha.sha1Of!(const(ubyte)[]).sha1Of(const(ubyte)[]) (__HID41=0x7fffffffd298, _param_0=...) at /usr/include/dmd/phobos/std/digest/sha.d:1102
#5 0x000000000076c13f in mysql.connection.Connection.makeToken(ubyte[]) (this=0x7ffff7ec0c00, authBuf=...)
at ../../../../../../.dub/packages/mysql-native-0.0.15/source/mysql/connection.d:2615
#6 0x000000000076c3c8 in mysql.connection.Connection.authenticate(ubyte[]) (this=0x7ffff7ec0c00, greeting=...)
at ../../../../../../.dub/packages/mysql-native-0.0.15/source/mysql/connection.d:2664
#7 0x000000000076c5f6 in mysql.connection.Connection.connect(mysql.connection.SvrCapFlags) (this=0x7ffff7ec0c00, clientCapabilities=33293)
at ../../../../../../.dub/packages/mysql-native-0.0.15/source/mysql/connection.d:2693
#8 0x000000000076c9ad in mysql.connection.Connection.this(mysql.connection.MySQLSocketType, std.socket.TcpSocket(immutable(char)[], ushort) function*, vibe.core.net.TCPConnection(immutable(char)[], ushort) function*, immutable(char)[], immutable(char)[], immutable(char)[], immutable(char)[], ushort, mysql.connection.SvrCapFlags) (this=0x7ffff7ec0c00, capFlags=33293,
port=3306, db=..., pwd=..., user=..., host=..., openSocketVibeD=0x76bfb8 <mysql.connection.Connection.defaultOpenSocketVibeD(immutable(char)[], ushort)>,
openSocketPhobos=0x76bf40 <mysql.connection.Connection.defaultOpenSocketPhobos(immutable(char)[], ushort)>, socketType=<incomplete type>)
at ../../../../../../.dub/packages/mysql-native-0.0.15/source/mysql/connection.d:2788
#9 0x000000000076c786 in mysql.connection.Connection.this(mysql.connection.MySQLSocketType, immutable(char)[], immutable(char)[], immutable(char)[], immutable(char)[], ushort, mysql.connection.SvrCapFlags) (this=0x7ffff7ec0c00, capFlags=33293, port=3306, db=..., pwd=..., user=..., host=..., socketType=<incomplete type>)
at ../../../../../../.dub/packages/mysql-native-0.0.15/source/mysql/connection.d:2741
#10 0x000000000076c710 in mysql.connection.Connection.this(immutable(char)[], immutable(char)[], immutable(char)[], immutable(char)[], ushort, mysql.connection.SvrCapFlags) (
this=0x7ffff7ec0c00, capFlags=33293, port=3306, db=..., pwd=..., user=..., host=...) at ../../../../../../.dub/packages/mysql-native-0.0.15/source/mysql/connection.d:2732
#11 0x0000000000772430 in mysql.db.MysqlDB.createConnection() (this=0x7ffff7eca100) at ../../../../../../.dub/packages/mysql-native-0.0.15/source/mysql/db.d:48
#12 0x000000000072d3db in vibe.core.connectionpool.ConnectionPool!(mysql.connection.Connection).ConnectionPool.lockConnection() (this=0x7ffff7ec7ac0, __HID44=0x7fffffffd838)
at ../../../../../../.dub/packages/vibe-d-0.7.23/source/vibe/core/connectionpool.d:54
#13 0x00000000007723bf in mysql.db.MysqlDB.lockConnection() (this=0x7ffff7eca100, __HID149=0x7fffffffd8c0) at ../../../../../../.dub/packages/mysql-native-0.0.15/source/mysql/db.d:44
#14 0x00000000007687f5 in db.mysql_test() () at source/db.d:17
#15 0x00000000006f525e in app._sharedStaticCtor1() () at source/app.d:16
#16 0x0000000000768799 in app.__modsharedctor() ()
#17 0x000000000090cd51 in _D2rt5minfo67__T14runModuleFuncsS442rt5minfo11ModuleGroup8runCtorsMFZ9__lambda2Z14runModuleFuncsMFAxPyS6object10ModuleInfoZv ()
#18 0x000000000090ca7d in rt.minfo.ModuleGroup.runCtors() ()
#19 0x00000000008cebe9 in rt.minfo.rt_moduleCtor().__foreachbody1(ref rt.sections_elf_shared.DSO) ()
#20 0x00000000008cef7e in rt.sections_elf_shared.DSO.opApply(scope int(ref rt.sections_elf_shared.DSO) delegate) ()
#21 0x00000000008cebb5 in rt_moduleCtor ()
#22 0x00000000008ca993 in rt_init ()
#23 0x00000000008cad5a in rt.dmain2._d_run_main(int, char**, extern(C) int(char[][]) function*).runAll() ()
#24 0x00000000008cad16 in rt.dmain2._d_run_main(int, char**, extern(C) int(char[][]) function*).tryExec(scope void() delegate) ()
#25 0x00000000008cac90 in _d_run_main ()
#26 0x0000000000768a0d in main ()
#27 0x00007ffff6873a40 in __libc_start_main (main=0x7689e8 <main>, argc=1, argv=0x7fffffffdd98, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>,
stack_end=0x7fffffffdd88) at libc-start.c:289
#28 0x00000000006f4279 in _start ()
(gdb) q
Comment #1 by rjmcguire — 2015-06-12T19:45:01Z
I'm guessing its wrong code if its crashing in DMD and not GDC.
Comment #2 by dlang-bugzilla — 2015-06-13T21:44:47Z
Issue 9279 ?
Comment #3 by rjmcguire — 2015-06-15T07:21:32Z
(In reply to Vladimir Panteleev from comment #2)
> Issue 9279 ?
Perhaps it is, how could I check that? Why would the code work fine in GDC then?
Comment #4 by dlang-bugzilla — 2015-06-15T07:24:10Z
(In reply to Rory from comment #3)
> Perhaps it is, how could I check that?
Try D from git master.
> Why would the code work fine in GDC then?
Why wouldn't (or would) it?
Comment #5 by rjmcguire — 2015-07-30T09:01:18Z
This is still an issue in dmd.2.068.0-b2.linux.zip
0x0000000000000000 in ?? ()
(gdb) bt
#0 0x0000000000000000 in ?? ()
#1 0x000000000074f117 in std.digest.sha.SHA!(512, 160).SHA.put(scope const(ubyte)[]...) (this=..., input=...) at /usr/include/dmd/phobos/std/digest/sha.d:723
#2 0x000000000074f2b6 in std.digest.sha.SHA!(512, 160).SHA.finish() (
this=..., __HID3=0x7fffffffd190)
at /usr/include/dmd/phobos/std/digest/sha.d:768
#3 0x0000000000778275 in std.digest.digest.digest!(std.digest.sha.SHA!(512, 160).SHA, const(ubyte)[]).digest(scope const(ubyte[])) (__HID62=0x7fffffffd1e8,
_param_0=...) at /usr/include/dmd/phobos/std/digest/digest.d:435
#4 0x00000000007781ed in std.digest.sha.sha1Of!(const(ubyte)[]).sha1Of(const(ubyte)[]) (__HID61=0x7fffffffd410, _param_0=...)
at /usr/include/dmd/phobos/std/digest/sha.d:1102
#5 0x00000000007a1c1a in mysql.connection.Connection!(mysql.socket.VibeSocket).Connection.eatHandshake(mysql.packet.InputPacket) (this=..., packet=...)
at ../../../../../../.dub/packages/mysql-lited-0.2.14/src/mysql/connection.d:471
#6 0x00000000007a14e5 in mysql.connection.Connection!(mysql.socket.VibeSocket).Connection.connect() (this=...)
at ../../../../../../.dub/packages/mysql-lited-0.2.14/src/mysql/connection.d:336
#7 0x00000000007a06ee in mysql.connection.Connection!(mysql.socket.VibeSocket).Connection.connect(immutable(char)[]) (this=..., connectionString=...)
at ../../../../../../.dub/packages/mysql-lited-0.2.14/src/mysql/connection.d---Type <return> to continue, or q <return> to quit---
:77
#8 0x00000000007a036b in mysql.client.MySQLClientT!(mysql.socket.VibeSocket).MySQLClientT.this(immutable(char)[]).__lambda2() (this=0x7ffff7ec2900)
at ../../../../../../.dub/packages/mysql-lited-0.2.14/src/mysql/client.d:13
#9 0x00000000007a3802 in vibe.core.connectionpool.ConnectionPool!(mysql.connection.Connection!(mysql.socket.VibeSocket).Connection*).ConnectionPool.lockConnection() (this=0x7ffff7ec3700, __HID128=0x7fffffffd8d8)
at ../../../../../../.dub/packages/vibe-d-0.7.24-rc.1/source/vibe/core/connectionpool.d:54
#10 0x00000000007a0612 in mysql.client.MySQLClientT!(mysql.socket.VibeSocket).MySQLClientT.lockConnection() (this=0x7ffff7ec28a0, __HID126=0x7fffffffd8d8)
at ../../../../../../.dub/packages/mysql-lited-0.2.14/src/mysql/client.d:31
#11 0x00000000007a023d in mysql.client.MySQLClientT!(mysql.socket.VibeSocket).MySQLClientT.this(immutable(char)[]) (this=0x7ffff7ec28a0, connectionString=...)
at ../../../../../../.dub/packages/mysql-lited-0.2.14/src/mysql/client.d:17
#12 0x000000000078de22 in db._sharedStaticCtor6() () at source/db.d:13
#13 0x000000000081f8d1 in db.__modsharedctor() ()
#14 0x00000000009b1200 in _D2rt5minfo67__T14runModuleFuncsS442rt5minfo11ModuleGroup8runCtorsMFZ9__lambda2Z14runModuleFuncsMFAxPyS6object10ModuleInfoZv ()
#15 0x00000000009b0f45 in rt.minfo.ModuleGroup.runCtors() ()
#16 0x000000000096c5c9 in rt.minfo.rt_moduleCtor().__foreachbody1(ref rt.sections_elf_shared.DSO) ()
#17 0x000000000096cafd in rt.sections_elf_shared.DSO.opApply(scope int(ref rt.se---Type <return> to continue, or q <return> to quit---
ctions_elf_shared.DSO) delegate) ()
#18 0x000000000096c597 in rt_moduleCtor ()
#19 0x000000000096828c in rt_init ()
#20 0x000000000096865e in rt.dmain2._d_run_main(int, char**, extern(C) int(char[][]) function*).runAll() ()
#21 0x000000000096861a in rt.dmain2._d_run_main(int, char**, extern(C) int(char[][]) function*).tryExec(scope void() delegate) ()
#22 0x000000000096859a in _d_run_main ()
#23 0x00000000008218f0 in main ()
#24 0x00007ffff6873a40 in __libc_start_main (main=0x8218d0 <main>, argc=1,
argv=0x7fffffffdd88, init=<optimized out>, fini=<optimized out>,
rtld_fini=<optimized out>, stack_end=0x7fffffffdd78) at libc-start.c:289
#25 0x000000000074c529 in _start ()
(gdb)
Comment #6 by rjmcguire — 2015-08-07T12:45:11Z
More brain dump stuff, because I've run out of time looking at this for now:
From what I can tell it appears that transform() is invalid in DMD and LDC.
I do not have this problem in GDC which has an outdated frontend.
This is the code at #2 0x0000000000713072 in std.digest.sha.SHA!(512, 160).SHA.finish() (this=0x7fffffffd160, __HID34=0x7fffffffd1d0) at /usr/include/dmd/phobos/std/digest/sha.d:768
transform (&state, &buffer);
Seems it calls into no where.
transform is supposed to be setup in line 235:
alias transform = transformSHA2!ulong;
Comment #7 by dlang-bugzilla — 2015-08-31T07:06:52Z
We're going to need a self-contained reproducible testcase. Please check out Dustmite if you haven't already.
Since this problem doesn't manifest in GDC, your Dustmite test script can try compiling the program with GDC and DMD, and return 0 only if the program segfaults with DMD but not GDC.
Comment #8 by pro.mathias.lang — 2022-02-23T04:18:57Z
Looking into this, I noticed the code is triggered from a module constructor:
> #14 0x00000000007687f5 in db.mysql_test() () at source/db.d:17
> #15 0x00000000006f525e in app._sharedStaticCtor1() () at source/app.d:16
> #16 0x0000000000768799 in app.__modsharedctor() ()
The report doesn't mention what version of DMD is being used, but according to the time of the report, I assume circa 2.068, in which case the line segfaulting would be https://github.com/dlang/phobos/blob/v2.068.0/std/digest/sha.d#L723
The stack trace seems to match, and since SHA doesn't change much, I'm pretty confident this is correct.
The jump to 0x00[...]00 seems to indicate that `transform` is `null`.
Looking into the module, there is indeed a case where it could be `null`: If `digestSize == 160`, `version = USE_SSSE3`, and the module constructor of your application was to run before SHA's module ctor (https://github.com/dlang/phobos/blob/v2.068.0/std/digest/sha.d#L216-L231).
`version = SSSE3` is true on amd64 (https://github.com/dlang/phobos/blob/b82986e64fbb2950af118f4711e1558a4134c803/std/digest/sha.d#L118-L121), and the first line indicates that `digestSize == 160`:
> #1 0x0000000000712eea in std.digest.sha.SHA!(512, 160).SHA.put(scope const(ubyte)[]...) (this=0x7fffffffd160, input=...) at /usr/include/dmd/phobos/std/digest/sha.d:723
Based on this, I am going to assume the missing piece (order of module ctor) is indeed the issue. It would also explain why a different version of the compiler/runtime and a different backend would work (different order of ctor running).
Hence, the best way forward to fix this issue is to move your code to the `main`, so that all modules ctor have a chance to run.