GCC ICE reporting guide

If you have crashing when building some gentoo package this page is for you!

To extract useful information from the crash to report a bug requires a few steps. This article lists the steps and provides a few real-world debugging sessions.

Check if an ICE is reproducible
Sometimes crashes due to external reasons not directly related to gcc:


 * out-of-memory condition (check )
 * bad RAM modules

Make sure the above is not your case.

Look at with ICE and try to resume the build to see if the same command causes the same ICE. Usually command looks something like .

Go to  (specified in as well) and rerun build command. You should see exact command and the failure.

Our running example will be ICE on :

{{Cmd|cd '/dev/shm/portage/dev-lang/python-3.6.5/work/Python-3.6.5'|LANG{{=}}C make|output= running build running build_ext INFO: Can't locate Tcl/Tk libs and/or headers building 'cmath' extension gcc-7.3.0 -pthread -fPIC -Wno-unused-result -Wsign-compare -DNDEBUG -march=prescott -mfpmath=sse -O2 -pipe -fomit-frame-pointer -fwrapv -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -I./Include -I. -I/dev/shm/portage/dev-lang/python-3.6.5/work/Python-3.6.5/Include -I/dev/shm/portage/dev-lang/python-3.6.5/work/Python-3.6.5 -c /dev/shm/portage/dev-lang/python-3.6.5/work/Python-3.6.5/Modules/cmathmodule.c -o build/temp.linux-i686-3.6/dev/shm/portage/dev-lang/python-3.6.5/work/Python-3.6.5/Modules/cmathmodule.o In file included from /dev/shm/portage/dev-lang/python-3.6.5/work/Python-3.6.5/Modules/cmathmodule.c:11:0: /dev/shm/portage/dev-lang/python-3.6.5/work/Python-3.6.5/Modules/clinic/cmathmodule.c.h: In function 'cmath_acos': /dev/shm/portage/dev-lang/python-3.6.5/work/Python-3.6.5/Modules/clinic/cmathmodule.c.h:45:1: internal compiler error: Segmentation fault } ^ Please submit a full bug report, with preprocessed source if appropriate. See  for instructions. }}

The build fails every time  is reran. Yay!

Extract exact command
If build system already prints exact command just re-execute it (make sure you are in correct directory). If build system does not print the command you will have to use other methods of getting command like running  or passing verbose flags manually.

In case of python command is printed as-is:

{{Cmd|LANG{{=}}C gcc-7.3.0 -pthread -fPIC -Wno-unused-result -Wsign-compare -DNDEBUG -march{{=}}prescott -mfpmath{{=}}sse -O2 -pipe -fomit-frame-pointer -fwrapv -std{{=}}c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -I./Include -I. -I/dev/shm/portage/dev-lang/python-3.6.5/work/Python-3.6.5/Include -I/dev/shm/portage/dev-lang/python-3.6.5/work/Python-3.6.5 -c /dev/shm/portage/dev-lang/python-3.6.5/work/Python-3.6.5/Modules/cmathmodule.c -o build/temp.linux-i686-3.6/dev/shm/portage/dev-lang/python-3.6.5/work/Python-3.6.5/Modules/cmathmodule.o|output= In file included from /dev/shm/portage/dev-lang/python-3.6.5/work/Python-3.6.5/Modules/cmathmodule.c:11:0: /dev/shm/portage/dev-lang/python-3.6.5/work/Python-3.6.5/Modules/clinic/cmathmodule.c.h: In function 'cmath_acos': /dev/shm/portage/dev-lang/python-3.6.5/work/Python-3.6.5/Modules/clinic/cmathmodule.c.h:45:1: internal compiler error: Segmentation fault } ^ Please submit a full bug report, with preprocessed source if appropriate. See  for instructions. }}

Extract self-contained source (use -save-temps)
Add  to  command on a previous step to extract preprocessed sample. will create  (or   for  ).

Obligatory python example:

The preprocessed file is in  now. You can get more tips at https://gcc.gnu.org/bugs/

Expand -march=native, exact gcc version and other system-specific options
Some compiler options like  are depend on the environment. You need to resolve them into exact options. One way to do it is to query for expansion:

Here  is substituted for. Make sure bug is reproducible after substitution as well.

Report bug on bugs.gentoo.org
File a bug at https://bugs.gentoo.org/ against toolchain@gentoo.org and provide a few details:


 * output
 * attach  reproducer

[bonus] minimize needed flags to reproduce failure
You can do similar expansion for optimizer options as well:

To expand  into   you can use

Try to find minimal set of flags needed to trigger the crash by removing some expanded options.

[bonus] minimize self-contained source using creduce
Now to the fun part! Let's shrink  down to a manageable size with help of https://embed.cs.utah.edu/creduce/.

{{Cmd|creduce test.sh cmathmodule.i|output=
 * 1) write a  tester:
 * 2) validate tester
 * 3) Reduce!
 * 1) Reduce!

running 4 interestingness tests in parallel

< pass_blank :: 0 >
(1.2 %, 733906 bytes) (27.4 %, 539234 bytes)

< pass_clang_binsrch :: replace-function-def-with-decl >
(29.5 %, 523834 bytes) (30.2 %, 518466 bytes) (32.0 %, 505350 bytes) ...         ******** cmathmodule.i ********

typedef struct { double a } b; b c; d, e, f; g { _setjmp; b h; if (e) h.a = copysign(f, d); c = h; } }}

Done!

contains the same shrunk example.

[bonus] Check if bug still exists on vanilla gcc master
Building gcc locally could look like that:

Look at configure options of gentoo's to get more options to add to defaults. Be careful: some configure options like can change code generation enough to trigger or hide a bug.

[bonus] Report bug on gcc.gnu.org/bugzilla
File the bug at https://gcc.gnu.org/bugzilla/ with attached minimal reproducer and  detals.

[bonus] Extract gcc backtrace
Example session would be:

[bonus] Fix gcc bug
By now you have a source tree and command how to build it!

A few starting points for you:
 * https://gcc.gnu.org/contribute.html for general notes on coding tips and guidelines
 * https://gcc.gnu.org/onlinedocs/

Good luck!