https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101692
Bug ID: 101692 Summary: Program crushes at unpredictable moment of time Product: gcc Version: 8.4.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: d Assignee: ibuclaw at gdcproject dot org Reporter: zed at lab127 dot karelia.ru Target Milestone: --- I am not sure this is really a gdc issue, but a program behaves very strange - it works normally for some time, and then receives SIGSEGV at unpredictable moment (but always at the same place of code). Here is code snippet, where the crush occurs struct EpollEvent { align(1): uint event_mask; EventSource es; // EventSource is a class /* just do not want to use that union, epoll_data_t */ } bool wait() { EpollEvent event; if (done) return false; int n = epoll_wait(id, &event, 1, -1); if (-1 == n) return false; writefln("%s, n = %d", __FUNCTION__, n); writefln("%s", event); // <<< crashes here EventSource s = event.es; ulong ecode = s.eventCode(event.event_mask); mq.putMsg(null, s.owner, ecode, s); return true; } Crush occurs when program is accessing 'event' variable after return from epoll_wait(). And it does not depend on the type of this variable - I tried dynamic array EpollEvent[], static array EpollEvent[MAX], no matter, after some period of normal functioning program gets SIGSEGV at the indicated line. gdb says the following: Core was generated by `./echod'. Program terminated with signal SIGSEGV, Segmentation fault. #0 0x00007f312ed79380 in ?? () (gdb) bt #0 0x00007f312ed79380 in ?? () #1 0x0000555f33107071 in std.format.formatObject!(std.stdio.File.LockingTextWriter, esrc.EventSource, char).formatObject(ref std.stdio.File.LockingTextWriter, ref esrc.EventSource, ref const(std.format.FormatSpec!(char).FormatSpec)) (w=..., val=@0x7ffec19ab610: 0x7f312edb6300, f=...) at /usr/lib/gcc/x86_64-linux-gnu/8/include/d/std/format.d:3353 #2 0x0000555f33106fc9 in std.format.formatValue!(std.stdio.File.LockingTextWriter, esrc.EventSource, char).formatValue(ref std.stdio.File.LockingTextWriter, esrc.EventSource, ref const(std.format.FormatSpec!(char).FormatSpec)) (w=..., val=0x7f312edb6300, f=...) at /usr/lib/gcc/x86_64-linux-gnu/8/include/d/std/format.d:3450 #3 0x0000555f33106f39 in std.format.formatElement!(std.stdio.File.LockingTextWriter, esrc.EventSource, char).formatElement(ref std.stdio.File.LockingTextWriter, ref esrc.EventSource, ref const(std.format.FormatSpec!(char).FormatSpec)) (w=..., val=@0x7ffec19ab6b0: 0x7f312edb6300, f=...) at /usr/lib/gcc/x86_64-linux-gnu/8/include/d/std/format.d:3180 #4 0x0000555f3310683a in std.format.formatValue!(std.stdio.File.LockingTextWriter, ecap.EpollEvent, char).formatValue(ref std.stdio.File.LockingTextWriter, ref ecap.EpollEvent, ref const(std.format.FormatSpec!(char).FormatSpec)) (w=..., val=..., f=...) at /usr/lib/gcc/x86_64-linux-gnu/8/include/d/std/format.d:3702 #5 0x0000555f3310634b in std.format.formattedWrite!(std.stdio.File.LockingTextWriter, char, ecap.EpollEvent).formattedWrite(ref std.stdio.File.LockingTextWriter, const(char[]), ecap.EpollEvent) (w=..., fmt=..., _param_2=...) at /usr/lib/gcc/x86_64-linux-gnu/8/include/d/std/format.d:568 #6 0x0000555f33105dc5 in std.stdio.File.writefln!(char, ecap.EpollEvent).writefln(const(char[]), ecap.EpollEvent) (this=..., fmt=..., _param_1=...) at /usr/lib/gcc/x86_64-linux-gnu/8/include/d/std/stdio.d:1496 #7 0x0000555f330f49ad in std.stdio.writefln!(char, ecap.EpollEvent).writefln(const(char[]), ecap.EpollEvent) (fmt=..., _param_1=...) at /usr/lib/gcc/x86_64-linux-gnu/8/include/d/std/stdio.d:3797 #8 0x0000555f330eca63 in ecap.EventQueue.wait() (this=0x7f312ed76000) at engine/ecap.d:113 #9 0x0000555f330f472a in D main (args=...) at echod.d:46 engine/ecap.d:113 is that 'writefln("%s", event);' Also it seemed to me, that crash is more probable when compiling with -Os. Also 2, i tried dmd instead of gdc - crushes also occurs, but much less frequently. gdc --version gdc (Ubuntu 8.4.0-1ubuntu1~18.04) 8.4.0 (Linux Mint 19.1 actually) uname -a Linux HP-Laptop 4.15.0-151-generic #157-Ubuntu SMP Fri Jul 9 23:07:57 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux