交叉编译的ARMv5,但它创建V7二进制 [英] cross compile for armv5, but it creates v7 binary

查看:1794
本文介绍了交叉编译的ARMv5,但它创建V7二进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设法为克雷娅察ARM926EJ-S搜索目标文件
我使用的debian QEMU手臂

I managed to creata an object file for arm926ej-s
I am using debian arm on qemu

arm-linux-gnueabi-gcc-4.4 -static -O -c -mcpu=arm926ej-s  hello.c -o hello
root@at0012-ubuntu:/qemu-deb-squeeze/mnt/package# readelf -A hello
Attribute Section: aeabi
File Attributes
  Tag_CPU_name: "ARM926EJ-S"
  Tag_CPU_arch: v5TEJ
  Tag_ARM_ISA_use: Yes
  Tag_THUMB_ISA_use: Thumb-1
  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_ABI_optimization_goals: Prefer Speed
  Tag_DIV_use: Not allowed

不过当我编译与我们的-c的Ubuntu它为ARMv7的可执行文件,而不是这种结果的
因此,如何编译正确的CPU ??结果
我试过$臂Linux的gnueabi-GCC-4.4 -static -mcpu = ARM926EJ-S的hello.c -o打招呼
它创建结果
Tag_CPU_name:7-A结果
Tag_CPU_arch:V7

but in ubuntu when I compile with our the -c it creates the executable for armv7 instead of this
So how to compile for the right cpu??
I tried $ arm-linux-gnueabi-gcc-4.4 -static -mcpu=arm926ej-s hello.c -o hello it creates
Tag_CPU_name: "7-A"
Tag_CPU_arch: v7

推荐答案

海合会的 LD 的试图尽最大努力找到正确的库来链接。据我所知,它认为的 -mcpu -mthumb -mfpu -mfloat-ABI 的(见下面例子)。该列表可能不完整, -mthumb-互通的可能是考虑。如果的 -mcpu 的指定,该架构从该值的。

GCC's ld tries its best to find the correct library to link against. As far as I know, it considers -mcpu, -mthumb, -mfpu, and -mfloat-abi (see examples below). This list may not be complete, -mthumb-interwork is probably considered as well. If -mcpu is specified, the architecture is derived from that value.

因此​​,这些选项应传递到的 LD 的,你应该检查了 LD 的真正挑选出正确的multilib的。

So these options should be passed down to ld, and you ought to checked that ld really picks the correct multilib.

有关各选项有内置的默认值,这可能不是在正确的方向引导。

For each of these options there are built-in default values which may not lead in the right direction.

如果 LD 的不能找到匹配的图书馆,它属于回默认值。没有错误消息。

If ld cannot find a matching library, it falls back to the default one. There is no error message.

所以你的情况 - 假设你已经通过的 -mcpu 的到的 LD 的和你的工具链的安装是正确的 - 有可能是没有匹配multilib的,而 LD 的使用默认的。连接过程在技术上成功,但你没有得到你想要的。

So in your case - assuming that you have passed -mcpu to ld and your toolchain installation is correct - there is possibly no matching multilib, and ld uses the default one. The linking process technically succeeds, but you do not get what you want.

一些例子(臂无 - EABI-GCC 4.6.2)

Some examples (arm-none-eabi-gcc 4.6.2)

可用一个multilib:

Available multilibs:

$ arm-none-eabi-gcc -print-multi-lib
.;
thumb/arm7tdmi-s;@mthumb@mcpu=arm7tdmi-s
thumb/cortex-m0;@mthumb@mcpu=cortex-m0
thumb/cortex-m3;@mthumb@mcpu=cortex-m3
thumb/cortex-m4;@mthumb@mcpu=cortex-m4
thumb/cortex-m4/float-abi-hard/fpuv4-sp-d16;@mthumb@mcpu=cortex-m4@mfloat-abi=hard@mfpu=fpv4-sp-d16

默认

$ arm-none-eabi-gcc -print-multi-directory
.

如果未找到一个给定的CPU一个multilib的,它使用默认,以及 - 没有错误消息:

If a multilib for a given cpu is not found, it uses the default as well - there is no error message:

$ arm-none-eabi-gcc -print-multi-directory -mcpu=arm926ej-s 
.

有没有错误消息,即使的 -mcpu 的是明明错误(也就是CPU不在已知的ARM CPU的列表,你可以看到用的设防无 - EABI - 海合会--target-帮助的):

There is no error message, even if the -mcpu is "obviously" wrong (that is the cpu is not in the list of known ARM CPUs which you can see with arm-none-eabi-gcc --target-help):

$ arm-none-eabi-gcc -print-multi-directory -mcpu=xxx
.

即使 -mcpu =的Cortex-M4 的,无效的multilib的选择。 CM4仅支持拇指,所以这个值可以从的 -mcpu 的衍生,但内置的默认胜:

Even with -mcpu=cortex-m4, the invalid multilib is chosen. cm4 only supports thumb, so this value could be derived from -mcpu, but the built-in default wins:

$ arm-none-eabi-gcc -print-multi-directory -mcpu=cortex-m4
.

要得到CM4正确multlib, -mthumb 的是必要的,也是,这是必要的覆盖指令集的默认值:

To get the correct multlib for cm4, -mthumb is necessary as well, this is necessary to override the default value for the instruction set:

$ arm-none-eabi-gcc -print-multi-directory -mcpu=cortex-m4 -mthumb
thumb/cortex-m4

要获得与硬件支持CM4正确multilib的浮点运算, -mfpu 的可能是不够的:

To get the correct multilib for cm4 with HW support for floating point operations, -mfpu may not be enough:

$ arm-none-eabi-gcc -print-multi-directory -mcpu=cortex-m4 -mthumb -mfloat-abi=hard
.

它需要

$ arm-none-eabi-gcc -print-multi-directory -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16
thumb/cortex-m4/float-abi-hard/fpuv4-sp-d16

找到有关multilib的rel=\"nofollow\">细节在<一个href=\"http://stackoverflow.com/questions/12963209/why-does-arm-linux-gnueabi-g-4-4-always-build-a-7-a-binary\">auselen's回答

由于auselen已经评论,为解决这个最简单的方法是找到合适的工具链,为建设一个ARM工具链是另一回事。

As auselen already commented, the easiest way to resolve this is to find the right toolchain, as building an ARM toolchain is another story.

这篇关于交叉编译的ARMv5,但它创建V7二进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆