Search code examples
gcccompilationcompiler-constructioncross-compilingporting

Getting a segmentation fault when trying to build my GCC backend


I am currently trying to write a GCC backend for a new architecture, but when I try to compile it I get the following error message:

xgcc: internal compiler error: Segmentation fault signal terminated program cc1

The build is configured with the following command:

../gcc/configure --prefix=--prefix=$HOME/GCC-10.0.1 --disable-bootstrap --target=arch_name --enable-languages=c

How would I go about fixing this error so that I can build my backend?

As far as I am aware, I have implemented the target macro's, functions and insn patterns required to get GCC to build.

Sorry that the question is a bit vague, I am not sure what extra information I can provide. If more specific information is needed please let me know and I will edit the question.

Thanks in advance.


Solution

  • How would I go about fixing this error so that I can build my backend?

    Debug cc1.

    1. xgcc is located in $builddir/gcc. Hence run $builddir/xgcc -B$builddir -v -save-temps <options-that-crash-cc1>.

    2. xgcc -v ... will print the sub-commands it is calling, record the options it supplies to the crashing cc1 call.

    3. Run a debugger against that cc1 call, supply the right options and put a breakpoint at abort (will be fancy_abort) actually.

    4. Build the compiler without optimization. It's enough to run make in $builddir/gcc for that. You can supply additional option if you like, e.g. make -j4 cc1 CXXFLAGS='<flags-to-pass>'.

    5. $builddir/gcc provides .gdbinit to augment gdb with additional hooks to improve debugging experience.