错误Illegal instruction 的解决方法

来源:互联网 发布:\windows\syswow64 编辑:程序博客网 时间:2024/06/04 18:26

Illegal instruction 的解决方法

 

最新解决方法:

把/usr/local/arm/compiler/arm-none-linux-gnueabi/libc/armv4t/lib目录(也就是你的编译器的库目录)

的所有文件拷贝到目标板子的根目录的lib目录下就好了。

这样无论你的hello是动态编译还是静态编译,跑起来都不会有Illegal instruction的问题。

////////////////////////////////

老的解决方法:

开发板配置: ARM9 + linux-3.6.30

编译器:arm-linux-4.3.2

在移植好jffs2文件系统以后,当然想写个hello world 来验证一下自己的成果了。好,开始:

1.编辑编译

#vi hello.c

#include <stdio.h>

int main(void)

{

        printf("welcome to my rootfs!/n");

        return 0;

}

#arm-linux-gcc –o hello hello.c

2.把hello复制到用来制作文件系统的文件夹,制作文件系统rootfs.jffs2,下载运行,开发板能够成功启动,能够出现shell交互界面。这点肯定地说明busybox是没有问题的。运行hello

./hello 出现:

Illegal instruction

从网上找了很多资料,大部分把责任归于EABI,但我想想,既然kernel和busybox都能正常启动,那它们都应该是eabi编译的了,hello也肯定是eabi的,因为他们都是用arm-linux-4.3.2编译的(编译内核的时候make menuconfig要选山EABI选项).所以网上大部分资料都不适合解决我遇到的问题。但最终还是找到了一边能够帮我解决问题的文章:

http://hi.baidu.com/caicry/blog/item/ede3b8fa01ebc89059ee908a.html

虽然他还是把问题归咎于EABI,但是却给我指点了解决问题的方向。

既然busybox(这里的busybox是指编译busybox-1.15.2生成的busybox二进制文件)能够成功运行,hello不能运行,那就看看他们的区别:

#file buxybox

busybox: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, for GNU/Linux 2.6.14, stripped

#file hello

# file hello

hello: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, not stripped

这时候恍然大悟了,hello在ram+linux系统上找不到运行所需的动态库,所以Illegal instruction重新编译hello.c

#gcc –static –o hello hello.c

#file hello

hello_static: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically linked, for GNU/Linux 2.6.14, not stripped

重新制作jffs2文件系统,下载运行:

#hello 出现

welcome to my rootfs!

 

完!

 

 

现在EABI已经开始在嵌入式中流行起来,确保软件的EABI匹配性,应该注意下面几点:

1.     编译kernel的时候要选上EABI。

2.     交叉编译的所有的软件都要用支持EABI的编译器(例如arm-linux-4.3.2)来编译。

0 0
原创粉丝点击