ARM cross compiling

I have installed ARM cross compiler tool chain on my x86 Ubuntu12.04 linux.

now I have arm-linux-gnueabi-gcc cross compiler.

I have coded simple hello world program as follow

#include <stdio.h>
int main(){
  printf("hello worldn");
  return 0;
}

and I cross compiled this program using

arm-linux-gnueabi-gcc -oa ac -static

the result of compiled binary is as follow

$ file a 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 my ARM debian linux on QEMU it says 'Illegal Instruction'

but if I compile the same source code with gcc on my ARM debian linux, it runs fine.

the file result on the two binary are same. what is wrong with my cross compiled ARM binary??

thank you in advance.

meltdown@meltdown-VirtualBox:/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

Could you run the readelf command in order to determine which ARM architecture your cross compiler targets? We need to see if this target is supported by Qemu.

arm-linux-gnueabi-readelf --file-header --arch-specific a

Moreover, you can check the output of dmesg in your emulated system. It should contain a description of the illegal instruction.

Also, you can run your program in a debugger to see which intruction fails.

链接地址: http://www.djcxy.com/p/86930.html

上一篇: arm不能运行arm编译的二进制文件

下一篇: ARM交叉编译