Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

build for ARMv6 with gnueabihf

I try to build an app for ARMv6 but, fail.

I guess the problem is the Toolchain which supports Hard Float but, ARMv6 does not.

Well, first i set -march=armv6, where compilation fails.

/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:

/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? Or is there a bug in the Toolchain?

like image 477
b-boy Avatar asked Feb 01 '16 13:02

b-boy


2 Answers

Your toolchain is configured to emit Thumb code by default. 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.

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.

* I suspect most people will never knowingly encounter an ARM1156.

like image 134
Notlikethat Avatar answered Oct 07 '22 02:10

Notlikethat


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.

The problem is that the maintainers of the Linaro toolchain specify ARMv7A as the minimum supported architecture. 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

This is gcc -v on Raspbian Stretch:

$ 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:

$ 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):

like image 28
bleater Avatar answered Oct 07 '22 04:10

bleater