简体   繁体   English

ARM交叉编译

[英]ARM cross compiling

I have installed ARM cross compiler tool chain on my x86 Ubuntu12.04 linux. 我在我的x86 Ubuntu12.04 linux上安装了ARM交叉编译工具链。

now I have arm-linux-gnueabi-gcc cross compiler. 现在我有arm-linux-gnueabi-gcc交叉编译器。

I have coded simple hello world program as follow 我编写了简单的hello world程序如下

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

and I cross compiled this program using 我用这个程序交叉编译了这个程序

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

the result of compiled binary is as follow 编译二进制的结果如下

$ file aa: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically lined, for GNU/Linux 2.6.31, not stripped $ file aa:ELF 32位LSB可执行文件,ARM,版本1(SYSV),静态内衬,适用于GNU / Linux 2.6.31,未剥离

if I run this binary on my ARM debian linux on QEMU it says 'Illegal Instruction' 如果我在QEMU上的ARM debian linux上运行这个二进制文件就会说“非法指令”

but if I compile the same source code with gcc on my ARM debian linux, it runs fine. 但如果我在我的ARM debian linux上使用gcc编译相同的源代码,它运行正常。

the file result on the two binary are same. 两个二进制文件的文件结果是一样的。 what is wrong with my cross compiled ARM binary?? 我的交叉编译ARM二进制文件出了什么问题?

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? 您是否可以运行readelf命令以确定交叉编译器所针对的ARM体系结构? We need to see if this target is supported by Qemu. 我们需要看看Qemu是否支持此目标。

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

Moreover, you can check the output of dmesg in your emulated system. 此外,您可以在模拟系统中检查dmesg的输出。 It should contain a description of the illegal instruction. 它应包含非法指令的描述。

Also, you can run your program in a debugger to see which intruction fails. 此外,您可以在调试器中运行程序以查看哪些内容失败。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM