Thread overview
[Issue 14692] SIGSEGV during SHA.put
Jun 12, 2015
Rory
Jun 13, 2015
Vladimir Panteleev
Jun 15, 2015
Rory
Jun 15, 2015
Vladimir Panteleev
Jul 30, 2015
Rory
Aug 07, 2015
Rory
Aug 31, 2015
Vladimir Panteleev
Aug 29, 2020
Walter Bright
Feb 23, 2022
Mathias LANG
June 12, 2015
https://issues.dlang.org/show_bug.cgi?id=14692

Rory <rjmcguire@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
           Severity|blocker                     |major

--- Comment #1 from Rory <rjmcguire@gmail.com> ---
I'm guessing its wrong code if its crashing in DMD and not GDC.

--
June 13, 2015
https://issues.dlang.org/show_bug.cgi?id=14692

Vladimir Panteleev <thecybershadow@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |thecybershadow@gmail.com

--- Comment #2 from Vladimir Panteleev <thecybershadow@gmail.com> ---
Issue 9279 ?

--
June 15, 2015
https://issues.dlang.org/show_bug.cgi?id=14692

--- Comment #3 from Rory <rjmcguire@gmail.com> ---
(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?

--
June 15, 2015
https://issues.dlang.org/show_bug.cgi?id=14692

--- Comment #4 from Vladimir Panteleev <thecybershadow@gmail.com> ---
(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?

--
July 30, 2015
https://issues.dlang.org/show_bug.cgi?id=14692

--- Comment #5 from Rory <rjmcguire@gmail.com> ---
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)

--
August 07, 2015
https://issues.dlang.org/show_bug.cgi?id=14692

--- Comment #6 from Rory <rjmcguire@gmail.com> ---
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;

--
August 31, 2015
https://issues.dlang.org/show_bug.cgi?id=14692

--- Comment #7 from Vladimir Panteleev <thecybershadow@gmail.com> ---
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.

--
August 29, 2020
https://issues.dlang.org/show_bug.cgi?id=14692

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |backend
                 CC|                            |bugzilla@digitalmars.com

--
February 23, 2022
https://issues.dlang.org/show_bug.cgi?id=14692

Mathias LANG <pro.mathias.lang@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |pro.mathias.lang@gmail.com
         Resolution|---                         |INVALID

--- Comment #8 from Mathias LANG <pro.mathias.lang@gmail.com> ---
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.

--