问题
I type gcc hello.c
and this appears:
gcc: internal compiler error: Illegal instruction (program as)
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-4.6/README.Bugs> for instructions.
hello.c is just:
int main()
{
return 0;
}
I can't think of any way to make it simpler! (The same happened with printf
in there.)
So: how do you fix this? I'm on Raspian, on Raspberry Pi.
Edit
gcc -v gives
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabihf/4.6/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: ../src/configure -v --with-pkgversion='Debian 4.6.3-14+rpi1' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-sjlj-exceptions --with-arch=armv6 --with-fpu=vfp --with-float=hard --enable-checking=release --build=arm-linux-gnueabihf --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf
Thread model: posix
gcc version 4.6.3 (Debian 4.6.3-14+rpi1)
No I didn't install it.
As for updates, sudo apt-get install gcc
gives
Reading package lists... Done
Building dependency tree
Reading state information... Done
gcc is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Yes, you can run as
, it says Illegal instruction
with no arguments.
I have no idea what swap space is.
gcc -O0 -g hello.c
gives the same error.
gcc does not recognise --enable-debug
.
回答1:
Got it! I uninstalled gcc, installed gcc-4.7, and ... nothing.
I cleared out the end of gcc-4.6 and re-ran sudo apt-get install gcc-4.7
and ... nothing.
I updated binutils and ... it worked!
So, as
didn't appear to be affected by updating GCC, but updating it more directly did it for me.
(It was from 2.22-7.1 to 2.22-8, if that helps anyone.)
回答2:
I can only shed some light on the error message:
gcc: internal compiler error: Illegal instruction (program as)
gcc does several things when compiling. It first translates your C program into assembler and then converts the assembler into machine code.
The name of the assembler program with gcc is just as
. So the error message tells you, that running the assembler fails, because the assembler executable contains an illegal instruction.
This might really be an hardware error, meaning that the executable of the assembler is broken.
To check:
- Does
gcc -S hello.c
work ? That should create a "hello.s" containing the C code compiled to assembler - You might try with
gcc -v -c hello.c
to find out what happens exactly.
回答3:
Found on raspberryPi forums:
Grabbed the sources and tried a cross-compile on an x86-64 box for a generic arm target. Something inside filter/hq2x.cpp is causing GCC to go nuts and consume memory & swap, so I wouldn't be at all surprised if it triggers a fatal error on a Pi. Some sources suggest that it is the compiler's (cc1plus) internal stack overflowing.
One possible fix is to run the configure script with --enable-debug - This should reduce optimization to a minimum and avoid stack overflows at the expense of increased binary size.
So you can try to set compiler flags to
-O0 -g
and check whether it helps.
回答4:
Got similar problem.
But it happened after move of VirtualBox image (with Xubuntu 16.04/gcc-5) from Haswell based machine to Sandy Bridge. Problem was somewhere in build-essential / gcc / binutils packages. I reinstalled all of them (with apt remove and apt install - no oneshot reinstall) - it helped.
回答5:
Try updating the compiler and try
sudo apt-get install build-essential
That might solve the problem.
来源:https://stackoverflow.com/questions/16526493/what-is-this-gcc-error-on-linux-and-how-do-i-solve-it-gcc-internal-compiler-e