ARM cross-compiled
I have installed the ARM cross-compiler toolchain on my x86 Ubuntu 12.04 linux.
Now I have the arm-linux-gnueabi-gcc cross-compiler.
I wrote the following simple hello world program
#include <stdio.h>
int main(){
printf("hello world\n");
return 0;
}
I cross-compiled
this program
arm-linux-gnueabi-gcc -o a.c -static
The compiled binary result is as follows
$ file one
a: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically lined, for GNU/Linux 2.6.31, not stripped
IF I RUN THIS BINARY ON ARM DEBIAN LINUX ON QEMU
It reads “Illegal Directives”
BUT IF I COMPILE THE SAME SOURCE CODE WITH GCC ON MY ARM DEBIAN LINUX, IT WORKS FINE.
The result is the same for both binaries.
What’s wrong with my cross-compiled ARM binary?
Thanks in advance.
[email protected]:/var/www$ arm-linux-gnueabi-readelf --file-header --arch-specific a
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: 0x8881
Start of program headers: 52 (bytes into file)
Start of section headers: 368052 (bytes into file)
Flags: 0x5000002, has entry point, Version5 EABI
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: 27
Attribute Section: aeabi
File Attributes
Tag_CPU_name: "7-A"
Tag_CPU_arch: v7
Tag_CPU_arch_profile: Application
Tag_ARM_ISA_use: Yes
Tag_THUMB_ISA_use: Thumb-2
Tag_FP_arch: VFPv3-D16
Tag_ABI_PCS_wchar_t: 4
Tag_ABI_FP_denormal: Needed
Tag_ABI_FP_exceptions: Needed
Tag_ABI_FP_number_model: IEEE 754
Tag_ABI_align_needed: 8-byte
Tag_ABI_align_preserved: 8-byte, except leaf SP
Tag_ABI_enum_size: int
Tag_ABI_HardFP_use: SP and DP
Tag_CPU_unaligned_access: v6
Tag_DIV_use: Not allowed
Solution
Can you run the readelf command to determine which ARM architecture your cross-compiler is targeting? We need to see if Qemu supports this goal.
arm-linux-gnueabi-readelf --file-header --arch-specific a
In addition, you can check the output of DMEG
in your analog system. It should contain a description of the illegal instruction.
In addition, you can run your program in the debugger to see which instruction fails.