GCC 8交叉编译器输出ARMv7可执行文件而不是ARMv6 [英] GCC 8 Cross Compiler outputs ARMv7 executable instead of ARMv6

查看:179
本文介绍了GCC 8交叉编译器输出ARMv7可执行文件而不是ARMv6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用

I'm trying to compile a C++ application for a Raspberry Pi Zero using GCC 8.2.1.
I'm using this for a relatively large C++17 project that is being built using CMake, and I'm trying to cross-compile it on my x86-64 laptop.

即使使用最简单的代码,我也无法针对ARMv6对其进行编译:

Even with the simplest code possible, I'm not able to compile it for ARMv6:

int main() {}

$ arm-linux-gnueabihf-g++ test.cpp -static -march=armv6 -mfpu=vfp -mfloat-abi=hard

在Pi上运行文件时,出现Illegal instruction错误,readelf返回以下内容:

When running the file on the Pi, I get an Illegal instruction error, and readelf returns the following:

$ arm-linux-gnueabihf-readelf -A a.out
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
  Tag_Advanced_SIMD_arch: NEONv1
  Tag_ABI_PCS_wchar_t: 4
  Tag_ABI_FP_rounding: Needed
  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_VFP_args: VFP registers
  Tag_CPU_unaligned_access: v6

GCC似乎忽略了我的体系结构标记.

GCC seems to ignore my architecture flags.

当简单地将其编译为目标文件时,它似乎可以正常工作,但是链接阶段始终使用ARMv7:

When simply compiling it into an object file, it seems to work just fine, but the linking stage always uses ARMv7:

$ arm-linux-gnueabihf-g++ test.cpp -static -march=armv6 -mfpu=vfp -mfloat-abi=hard -c
$ arm-linux-gnueabihf-readelf -A test.o
Attribute Section: aeabi
File Attributes
  Tag_CPU_name: "6"
  Tag_CPU_arch: v6
  Tag_ARM_ISA_use: Yes
  Tag_THUMB_ISA_use: Thumb-1
  Tag_FP_arch: VFPv2
  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_VFP_args: VFP registers
  Tag_ABI_optimization_goals: Aggressive Debug
  Tag_CPU_unaligned_access: v6

我在做什么错了?

推荐答案

我最终按照

I ended up compiling GCC from source, following this post. I didn't need all of the steps (I compiled everything using GCC 8 instead of compiling GCC 6.3 first, and I didn't edit any source files.)

我在 GitHub 上发布了一个包含所有构建步骤的Dockerfile.

I posted a Dockerfile with all build steps on GitHub.

现在生成的可执行文件的体系结构是正确的,但是我无法在目标上对其进行测试以检查其是否真正运行.

The architecture of the executables produced is correct now, but I can't test it on target yet to check if it actually runs.

这篇关于GCC 8交叉编译器输出ARMv7可执行文件而不是ARMv6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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