简体   繁体   English

Linux上的这个GCC错误是什么,我该如何解决? gcc:内部编译器错误:非法指令(程序为)

[英]What is this GCC error on Linux, and how do I solve it? gcc: internal compiler error: Illegal instruction (program as)

I type gcc hello.c and this appears: 我输入gcc hello.c ,这会出现:

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: hello.c只是:

int main()
{
 return 0;
}

I can't think of any way to make it simpler! 我想不出有什么方法可以让它变得更简单! (The same happened with printf in there.) (那里的printf也是如此。)

So: how do you fix this? 那么:你怎么解决这个问题? I'm on Raspian, on Raspberry Pi. 我在Raspberry Pi上的Raspian上。

Edit 编辑

gcc -v gives gcc -v给出

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 至于更新, sudo apt-get install gcc给出

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. 是的,你可以运行as ,它说, Illegal instruction不带任何参数。

I have no idea what swap space is. 我不知道交换空间是什么。

gcc -O0 -g hello.c gives the same error. gcc -O0 -g hello.c给出了同样的错误。

gcc does not recognise --enable-debug . gcc无法识别--enable-debug

Got it! 得到它了! I uninstalled gcc, installed gcc-4.7, and ... nothing. 我卸载了gcc,安装了gcc-4.7,并且......没有。

I cleared out the end of gcc-4.6 and re-ran sudo apt-get install gcc-4.7 and ... nothing. 我清除了gcc-4.6的结束并重新运行了sudo apt-get install gcc-4.7并且......没有。

I updated binutils and ... it worked! 我更新了binutils并且...它工作了!

So, as didn't appear to be affected by updating GCC, but updating it more directly did it for me. 因此, as没有出现通过更新GCC,但在更新它更直接地为我做的影响。

(It was from 2.22-7.1 to 2.22-8, if that helps anyone.) (这是从2.22-7.1到2.22-8,如果这有助于任何人。)

I can only shed some light on the error message: 我只能对错误信息有所了解:

gcc: internal compiler error: Illegal instruction (program as) gcc:内部编译器错误:非法指令(程序为)

gcc does several things when compiling. gcc在编译时做了几件事。 It first translates your C program into assembler and then converts the assembler into machine code. 它首先将您的C程序转换为汇编程序,然后将汇编程序转换为机器代码。

The name of the assembler program with gcc is just as . 使用gcc的汇编程序的名称也是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: 去检查:

  1. Does gcc -S hello.c work ? gcc -S hello.c吗? That should create a "hello.s" containing the C code compiled to assembler 这应该创建一个“hello.s”,其中包含编译为汇编程序的C代码
  2. You might try with gcc -v -c hello.c to find out what happens exactly. 您可以尝试使用gcc -v -c hello.c来找出确切的结果。

Found on raspberryPi forums: 在raspberryPi论坛上找到:

Grabbed the sources and tried a cross-compile on an x86-64 box for a generic arm target. 抓取源代码并尝试在x86-64盒子上进行交叉编译,以获得通用臂目标。 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. filter / hq2x.cpp中的一些东西导致GCC疯狂并消耗内存和交换,所以如果它在Pi上触发致命错误,我不会感到惊讶。 Some sources suggest that it is the compiler's (cc1plus) internal stack overflowing. 一些消息来源表明编译器(cc1plus)内部堆栈溢出。

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. 一个可能的解决方法是使用--enable-debug运行configure脚本 - 这应该将优化降至最低,并以增加二进制大小为代价避免堆栈溢出。

So you can try to set compiler flags to 所以你可以尝试设置编译器标志

-O0 -g

and check whether it helps. 并检查它是否有帮助。

Got similar problem. 有类似的问题。

But it happened after move of VirtualBox image (with Xubuntu 16.04/gcc-5) from Haswell based machine to Sandy Bridge. 但它发生在将VirtualBox图像(使用Xubuntu 16.04 / gcc-5)从基于Haswell的机器移动到Sandy Bridge之后。 Problem was somewhere in build-essential / gcc / binutils packages. 问题出现在build-essential / gcc / binutils包中。 I reinstalled all of them (with apt remove and apt install - no oneshot reinstall) - it helped. 我重新安装了所有这些(使用apt删除和apt安装 - 没有oneshot重新安装) - 它帮助。

Try updating the compiler and try 尝试更新编译器并尝试

sudo apt-get install build-essential

That might solve the problem. 这可能会解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM