https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98586
Bug ID: 98586
Summary: libgccjit crashes with segmentation fault on failed
gcc_assert
Product: gcc
Version: 9.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: jit
Assignee: dmalcolm at gcc dot gnu.org
Reporter: keith.marshall at mailinator dot com
Target Milestone: ---
In response to a feature request by Eli Zaretskii, with my follow-up as
detailed at https://osdn.net/projects/mingw/ticket/41070, I have been
evaluating the feasibility of providing a libgccjit.dll implementation for
mingw32. Since GCC-9.2.0 is the most recent version, for which I have a
successful build of GCC itself, my initial efforts have been focussed on a
libgccjit implementation for that version.
With a series of patches, as attached to the OSDN ticket, I have successfully
compiled the shared library, as libgccjit-0.dll; I am even able to successfully
compile, and link, the tut01-hello-world.c example from your own online manual,
at https://gcc.gnu.org/onlinedocs/jit/intro/tutorial01.html. Unfortunately
however, when attempting to run this program, it crashes with a segmentation
fault, and no useful diagnostic message.
I have traced the origin of the crash to a failing assertion, at line 54 in
gcc/jit/jit-tempdir.c. The failure of the assertion, as explained in the OSDN
ticket, is due to it testing an invalid assumption — on MS-Windows, both '/'
and '\\' are valid directory name separator characters, but the assertion
requires '/', whereas the libiberty.a choose_tmpdir() function returns a path
containing, and ending with, only '\\'.
While I can easily, and will, correct the invalid assumption, on which the
assertion fails, that the failed assertion terminates in a segmentation fault,
rather than a graceful termination, with an appropriate diagnostic message,
indicates that there is a deeper seated underlying defect. The segmentation
fault actually occurs in function pp_format(), from gcc/pretty-print.c, when it
attempts to dereference a NULL pointer, passed as the printer member of the
global_dc structure. I guess that this structure has not been initialized;
perhaps a call to diagnostic_initialize() has been omitted, but I have no idea
where to insert it.