我有一个带arm920t cpu(AT91RM9200)的板。 在目标Linux上:
int revisedStrcmp(char *s1, char *s2) {
int i = 0, n = 0, p = 0;
if (s1[i] == '\0' && s2[i] != '\0') //s1 shorter than s2
return -1;
else if (s1[i] != '\0' && s2[i] == '\0') //s1 longer than s2
return 1;
else if (s1[i] != '\0' && s2[i] != '\0') //both not equal to null
{
if (s1[i] > s2[i]) n += 1; //s1
else if (s1[i] < s2[i]) p += 1; //s2
else
{
n += 1; //s1
p += 1; //s2
}
i += 1;
return revisedStrcmp(s1, s2);
}
else //if s1[i] & s2[i] are null
{
if (n > p) //s1 > s2
return 1;
else if (n < p)
return -1;
else
return 0;
}
}
在我的主机上,我使用虚拟机Ubuntu 18.04作为系统进行交叉编译。 在我的Ubuntu上,我有2个用于交叉编译的软件包:
尝试构建简单的问候世界
root@test-device:/home/andy # uname -a
Linux test-device 2.6.21.201509.01 #13 Wed Jun 22 11:06:51 EEST 2016 armv4tl unknown
我在每个包装中都这样做
int main()
{
printf("Hello world\n");
return 0;
}
在两种情况下,我都有2个二进制可执行文件 readelf和文件工具说:
1. supersonic@ubuntu-vBox:~$ arm-linux-gnueabi-gcc -o hello_arm hello.c -static
2. supersonic@ubuntu-vBox:~$ arm-none-eabi-gcc -o hello_arm_none-eabi hello.c --specs=nosys.specs
将两个文件都上传到目标计算机,设置了执行权限
1. (arm-linux-gnueabi)
supersonic@ubuntu-vBox:~$ readelf -h hello_arm
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: ARM
Version: 0x1
Entry point address: 0x101a0
Start of program headers: 52 (bytes into file)
Start of section headers: 501788 (bytes into file)
Flags: 0x5000200, Version5 EABI, soft-float ABI
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 7
Size of section headers: 40 (bytes)
Number of section headers: 30
Section header string table index: 29
supersonic@ubuntu-vBox:~$
supersonic@ubuntu-vBox:~$ file hello_arm
hello_arm: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, for GNU/Linux 3.2.0, BuildID[sha1]=15d06e43de8c8d13d7e0110e311532a9187ca9e5, not stripped
2. (arm-none-eabi)
supersonic@ubuntu-vBox:~$ readelf -h hello_arm_none-eabi
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: ARM
Version: 0x1
Entry point address: 0x8148
Start of program headers: 52 (bytes into file)
Start of section headers: 186056 (bytes into file)
Flags: 0x5000200, Version5 EABI, soft-float ABI
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 3
Size of section headers: 40 (bytes)
Number of section headers: 27
Section header string table index: 24
supersonic@ubuntu-vBox:~$ file hello_arm_none-eabi
hello_arm_none-eabi: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, with debug_info, not stripped
当我尝试启动每个二进制文件时,得到以下结果
(arm-linux-gnueabi)
root @ test-device:/ home / andy#./hello_arm 非法指示
(arm-none-eabi)
root @ test-device:/ home / andy#./hello_arm_none-eabi 分割错误
在目标计算机上,找到旧的工作二进制文件,但开发人员在当前时间完成了工作 无法使用,他的联系丢失了
这是工作二进制文件 readelf和文件工具对此进行了说明:
root@test-device:/home/andy # chmod +x hello_arm
root@test-device:/home/andy # chmod +x hello_arm_none-eabi
也可以尝试使用选项构建我的“ hello world”
1. supersonic@ubuntu-vBox:~$ readelf -h /media/share_rw/MTXReader
ELF Header:
Magic: 7f 45 4c 46 01 01 01 61 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: ARM
ABI Version: 0
Type: EXEC (Executable file)
Machine: ARM
Version: 0x1
Entry point address: 0xab1c
Start of program headers: 52 (bytes into file)
Start of section headers: 681968 (bytes into file)
Flags: 0x2, GNU EABI, <unknown>
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 8
Size of section headers: 40 (bytes)
Number of section headers: 38
Section header string table index: 35
supersonic@ubuntu-vBox:~$ file /media/share_rw/MTXReader
/media/share_rw/MTXReader: ELF 32-bit LSB executable, ARM, version 1 (ARM), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.0.10, with debug_info, not stripped
2. supersonic@ubuntu-vBox:~$ arm-linux-gnueabi-gcc -o hello_arm hello.c -static -mcpu=arm920t -march=armv4t
但结果相同
有人知道为什么会这样吗?怎么办?