简体   繁体   English

使用gnueabihf为ARMv6构建

[英]build for ARMv6 with gnueabihf

I try to build an app for ARMv6 but, fail. 我尝试为ARMv6构建应用程序,但是失败了。

I guess the problem is the Toolchain which supports Hard Float but, ARMv6 does not. 我猜问题出在工具链上,它支持Hard Float,但ARMv6不支持。

Well, first i set -march=armv6, where compilation fails. 好吧,首先我设置-march = armv6,其中编译失败。

/opt/gcc-linaro-arm-linux-gnueabihf-4.8-2014.03_linux/arm-linux-gnueabihf/libc/usr/include/bits/byteswap.h: In function '__bswap_32': /opt/gcc-linaro-arm-linux-gnueabihf-4.8-2014.03_linux/arm-linux-gnueabihf/libc/usr/include/bits/byteswap.h:45:1: sorry, unimplemented: Thumb-1 hard-float VFP ABI

Additionally, i set -mfloat-abi=soft which make the Linker complain: 另外,我设置了-mfloat-abi = soft,这使链接程序抱怨:

/opt/gcc-linaro-arm-linux-gnueabihf-4.8-2014.03_linux/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: error: prog uses VFP register arguments, prog.o does not /opt/gcc-linaro-arm-linux-gnueabihf-4.8-2014.03_linux/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: failed to merge target specific data of file prog.o

Well, how do i actually build for ARMv6? 好吧,我实际上是如何为ARMv6构建的? Or is there a bug in the Toolchain? 还是工具链中存在错误?

Your toolchain is configured to emit Thumb code by default. 默认情况下,您的工具链配置为发出Thumb代码。 The issue with that is that the only Thumb encodings of floating-point instructions are 32-bit Thumb-2 ones, which to all intents and purposes only exist on ARMv7 or later * , and certainly aren't available on plain ARMv6. 这样做的问题在于,浮点指令的唯一Thumb编码是32位Thumb-2编码,就所有目的和目的而言,它们仅在ARMv7或更高版本*上存在,并且肯定在普通ARMv6上不可用。

To target pre-v7 architectures, you're best off compiling with -marm to generate ARM code instead of the relatively limited set of 16-bit Thumb instructions. 要针对v7之前的体系结构,最好-marm使用-marm进行编译以生成ARM代码,而不要使用相对有限的16位Thumb指令集。

* I suspect most people will never knowingly encounter an ARM1156. *我怀疑大多数人永远不会有意识地遇到ARM1156。

The ARM1176JZF-S core found in the BCM2835 SoC (as used on some Raspberry Pi models) is ARMv6z architecture, which includes hard-float support via VFPv2, so this is definitely a valid config to target. 在BCM2835 SoC中找到的ARM1176JZF-S内核(在某些Raspberry Pi型号上使用)是ARMv6z架构,它包括通过VFPv2的硬浮动支持,因此,这绝对是一个有效的配置目标。

The problem is that the maintainers of the Linaro toolchain specify ARMv7A as the minimum supported architecture. 问题是Linaro工具链的维护者将ARMv7A指定为最低支持的体系结构。 It makes cross-compiling for Raspberry Pi using the Debian cross-compiler packages rather hopeless, since various builtins will fail if you correctly configure your build for BCM2835 with -march=armv6z -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard 这使得使用Debian交叉编译器软件包对Raspberry Pi进行交叉编译非常无望,因为如果使用-march=armv6z -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard正确配置BCM2835的内部版本,则各种内建-march=armv6z -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard

This is gcc -v on Raspbian Stretch: 这是Raspbian Stretch上的gcc -v

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabihf/6/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: ../src/configure -v --with-pkgversion='Raspbian 6.3.0-18+rpi1+deb9u1' --with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-6 --program-prefix=arm-linux-gnueabihf- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm --disable-libquadmath --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-6-armhf/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-6-armhf --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-6-armhf --with-arch-directory=arm --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-sjlj-exceptions --with-arch=armv6 --with-fpu=vfp --with-float=hard --enable-checking=release --build=arm-linux-gnueabihf --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf
Thread model: posix
gcc version 6.3.0 20170516 (Raspbian 6.3.0-18+rpi1+deb9u1) 

Compare to arm-linux-gnueabi-gcc-6 -v on Ubuntu 18.04: 与Ubuntu 18.04上的arm-linux-gnueabi-gcc-6 -v进行比较:

$ arm-linux-gnueabihf-gcc-6 -v
Using built-in specs.
COLLECT_GCC=arm-linux-gnueabihf-gcc-6
COLLECT_LTO_WRAPPER=/usr/lib/gcc-cross/arm-linux-gnueabihf/6/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 6.4.0-17ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++ --prefix=/usr --with-as=/usr/bin/arm-linux-gnueabihf-as --with-ld=/usr/bin/arm-linux-gnueabihf-ld --program-suffix=-6 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm --disable-libquadmath --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-multiarch --enable-multilib --disable-sjlj-exceptions --with-arch=armv7-a --with-fpu=vfpv3-d16 --with-float=hard --with-mode=thumb --disable-werror --enable-multilib --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=arm-linux-gnueabihf --program-prefix=arm-linux-gnueabihf- --includedir=/usr/arm-linux-gnueabihf/include
Thread model: posix
gcc version 6.4.0 20180424 (Ubuntu/Linaro 6.4.0-17ubuntu1)

and note that the former has --with-arch=armv6 --with-fpu=vfp --with-float=hard whereas the latter has --with-arch=armv7-a --with-fpu=vfpv3-d16 --with-float=hard This blog post provides one solution (basically using Clang and self-building the binutils): 并请注意,前者具有--with-arch=armv6 --with-fpu=vfp --with-float=hard而后者具有--with-arch=armv7-a --with-fpu=vfpv3-d16 --with-float=hard 此博客文章提供了一种解决方案(基本上使用Clang并自行构建binutils):

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

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