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

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

问题描述

我设法为 arm926ej-s 创建了一个目标文件
我在 qemu 上使用 debian arm

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

但是在 ubuntu 中,当我使用 -c 进行编译时,它会为 armv7 创建可执行文件而不是此
那么如何编译合适的cpu??
我试过 $ arm-linux-gnueabi-gcc-4.4 -static -mcpu=arm926ej-s hello.c -o hello它创建
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

推荐答案

GCC 的 ld 尽力找到要链接的正确库.据我所知,它考虑了 -mcpu-mthumb-mfpu-mfloat-abi(见下面的例子).这个列表可能不完整,-mthumb-interwork 也可能被考虑.如果指定了 -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.

一些例子(arm-none-eabi-gcc 4.6.2)

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

可用的多库:

$ 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 列表中,您可以使用 arm-none-eabi-gcc --target-help):

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只支持thumb,所以这个值可以派生自-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 获得正确的多库,-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 的详细信息 和在 auselen 的回答

正如 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天全站免登陆