cgccraspberry-piarmcross-compiling

sorry, unimplemented: Thumb-1 ‘hard-float’ VFP ABI - arm-linux-gnueabihf-gcc - targeting armv6


Example code (people seem to require it no matter what the question is):

#include <stdio.h>

int main() {
    printf("Hello, World!\n");
    return 0;
}

The actual problem I have is I am trying to cross compile for armv6 (Raspberry PI Zero V1) from Ubuntu x86 64bit (WSL). The project I am trying to compile is Node.js, but I can reproduce the error with the simple file above.

To set the architecture I have tried both -march=armv6+fp (my CPU does have a HW floating point compute) and also the more specific -mcpu=arm1176jzf-s. I am forcing these for compilation because otherwise the arm-linux-gnueabihf-gcc defaults to target armv7, which won't work on my raspberry.

This is my test script for compiling. test.c refers to the code above.



OUT_PATH=./test.o
C_FILE_PATH=./test.c
# I don't know what this is, I got it from verbose output of my failing build
RAW_FILE_PATH=./test.raw

arm-linux-gnueabihf-gcc -march=armv6+fp -o $OUT_PATH $C_FILE_PATH  -pthread -Wall -Wextra -Wno-unused-parameter -Wa,--noexecstack -Wall -O3 -pthread -Wall -O3 -Wno-missing-field-initializers -Wno-old-style-declaration -O3 -fno-omit-frame-pointer  -MMD -MF $RAW_FILE_PATH -c

This is my full output:

ME@COMPUTER:/mnt/e/test-armv6-compile$ ./compile.sh
In file included from /usr/arm-linux-gnueabihf/include/stdio.h:976,
                 from ./test.c:1:
/usr/arm-linux-gnueabihf/include/bits/stdio.h: In function ‘getchar’:
/usr/arm-linux-gnueabihf/include/bits/stdio.h:48:1: sorry, unimplemented: Thumb-1 ‘hard-float’ VFP ABI
   48 | {
      | ^

Output of arm-linux-gnueabihf-gcc -v:

ME@COMPUTER:/mnt/e/test-armv6-compile$ arm-linux-gnueabihf-gcc -v
Using built-in specs.
COLLECT_GCC=arm-linux-gnueabihf-gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc-cross/arm-linux-gnueabihf/13/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 13.3.0-6ubuntu2~24.04' --with-bugurl=file:///usr/share/doc/gcc-13/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-13 --enable-shared --enable-linker-build-id --libexecdir=/usr/libexec --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-libstdcxx-backtrace --enable-gnu-unique-object --disable-libitm --disable-libquadmath --disable-libquadmath-support --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --without-target-system-zlib --enable-multiarch --disable-sjlj-exceptions --with-arch=armv7-a+fp --with-float=hard --with-mode=thumb --disable-werror --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 --with-build-config=bootstrap-lto-lean --enable-link-serialization=2
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.3.0 (Ubuntu 13.3.0-6ubuntu2~24.04)

I find it odd that the HW floating point was not supported by the compiler at all, since I have used gcc to target android ARMs with no issue. What is my mistake? How can I compile the sample above to run on ARMv6?


Solution

  • While there might be a way to get this to work, all I found is simply that the currently distributed arm-linux-gnueabihf-gcc simply isn't compiled with armv6 support.

    You can see that in the output of the -v in my question too:

    --with-arch=armv7-a+fp
    

    No mention of armv6. So what you have to do is compile the compiler yourself. I found this repo: https://github.com/Pro/raspi-toolchain

    Without any additional work, this will give you GCC 8, either by downloading a release, or by compiling it yourself. To compile newer version, I edited the docker file. I entered the exact versions of binutils, gcc and glibc that were on my freshly installed Raspberry Zero. Here is my edit, the rest is the same as the dockerfile in the repo:

    # This should match the one on your raspi
    ENV GCC_VERSION gcc-12.2.0
    ENV GLIBC_VERSION glibc-2.36
    ENV BINUTILS_VERSION binutils-2.40
    ARG DEBIAN_FRONTEND=noninteractive
    
    
    # Install some tools and compilers + clean up
    RUN apt-get update && \
        apt-get install -y rsync git wget gcc g++ cmake gdb gdbserver bzip2 texinfo && \
        apt-get clean autoclean && \
        apt-get autoremove -y && \
        rm -rf /var/lib/apt/lists/*
    
    # Use GCC 8 as the default
    # RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-8 999 \
    #  && update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-8 999 \
    #  && update-alternatives --install /usr/bin/cc  cc  /usr/bin/gcc-8 999 \
    #  && update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++-8 999
    
    

    After that, I was able to compile my own arm-linux-gnueabihf-gcc and friends form armV6 and ultimately compile Node.js for the Pi.