我想为 MIPS 机器交叉编译 C src,但编译失败。在目标机器上执行交叉编译的二进制文件会输出“非法指令”。你能告诉我如何为 MIPS 机器编译 C src 吗?
详情如下:
执行“readelf -h host.bin”(host.bin 是在 HOST 机器上运行的二进制程序)输出:
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: Intel 80386
Version: 0x1
Entry point address: 0x8048aac
Start of program headers: 52 (bytes into file)
Start of section headers: 8628 (bytes into file)
Flags: 0x0
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 9
Size of section headers: 40 (bytes)
Number of section headers: 30
Section header string table index: 27
执行“readelf -h target.bin”(target.bin 是目标机器上运行的二进制程序)输出:
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: MIPS R3000
Version: 0x1
Entry point address: 0x403570
Start of program headers: 52 (bytes into file)
Start of section headers: 114040 (bytes into file)
Flags: 0x5, noreorder, cpic, mips1
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 6
Size of section headers: 40 (bytes)
Number of section headers: 23
Section header string table index: 22
执行“readelf -h cross_compiled.bin”输出(cross_compiled.bin 是目标机器交叉编译的二进制文件):
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: MIPS R3000
Version: 0x1
Entry point address: 0x400170
Start of program headers: 52 (bytes into file)
Start of section headers: 16444 (bytes into file)
Flags: 0x1007, noreorder, pic, cpic, o32, mips1
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 5
Size of section headers: 40 (bytes)
Number of section headers: 21
Section header string table index: 20
对于交叉编译,我使用了支持 MIPS1 交叉编译的 buildroot。
我预计 cross_compiled.bin 在目标机器上正常执行。但是,当我在目标机器上执行“cross_compiled.bin”时,它会输出“非法指令”。
你能告诉我如何解决上述问题吗?由于我是交叉编译的新手,我无法找到问题的确切原因。
任何意见将不胜感激。
更新:
在目标上,执行“cat /proc/cpuinfo”输出:
system type : Broadcom BCM5354 chip rev 3
processor : 0
cpu model : BCM3302 V2.9
BogoMIPS : 237.56
wait instruction : no
microsecond timers : yes
tlb_entries : 32
extra interrupt vector : no
hardware watchpoint : no
VCED exceptions : not available
VCEI exceptions : not available
unaligned_instructions : 1
dcache hits : 0
dcache misses : 0
icache hits : 0
icache misses : 0
instructions : 0
在目标上,执行“cat /proc/version”输出:
Linux version 2.4.20 (ronger@ronger-linux.sh.deltagroup.com) (gcc version 3.2.3 with Broadcom modifications) #1 Tue May 22 17:40:19 EDT 2007
我用于交叉编译的命令行(cross_compiled.bin):
mipsel-linux-gcc -static -o cross_compiled.bin cross_compiled.c
cross_compiled.c:
#include <stdio.h>
int main()
{
printf("Hello World\n");
return 0;
}
由于我的 cross_compiled.c 非常简单,我相信没有与使用的库相关的问题。