Building Binutils & GCC1 in the Cygwin VM

  1. Update C:\Cygwin\opt\crosstool\src\build_gcc_cross.sh :

    #!/bin/bash
    
    export TARGET=arm-linux-gnueabihf
    export PREFIX=/opt/crosstool/gcc-4.6.3-eglibc-2.13/$TARGET
    
    cd /opt/crosstool/src/build-binutils
    find . -delete
    ../binutils-2.22/configure --target=$TARGET \
        --prefix=$PREFIX --with-sysroot=$TARGET \
        --disable-nls --with-arch=armv6
    if [ "$?" -ne "0" ]; then
        echo "=== build script: failed to configure binutils ==="
        exit 1
    fi
    make all
    if [ "$?" -ne "0" ]; then
        echo "=== build script: failed to make binutils ==="
        exit 1
    fi
    make install
    if [ "$?" -ne "0" ]; then
        echo "=== build script: failed to install binutils ==="
        exit 1
    fi
    
    
    export PATH=$PATH:$PREFIX/bin
    cd /opt/crosstool/src/build-gcc
    find . -delete
    ../gcc-4.6.3/configure --target=$TARGET --prefix=$PREFIX \
        --with-arch=armv6 --with-fpu=vfp --with-float=hard \
        --disable-sjlj-exceptions --enable-checking=release \
        --enable-linker-build-id --enable-gnu-unique-object \
        --disable-nls --enable-languages=c \
        --without-headers --disable-shared --disable-threads \
        --disable-multilib --disable-decimal-float \
        --disable-libmudflap --disable-libssp \
        --disable-libgomp --without-ppl --without-cloog \
        --with-gmp=/usr/local --with-mpfr=/usr/local \
        --with-mpc=/usr/local
    if [ "$?" -ne "0" ]; then
        echo "=== build script: failed to configure gcc ==="
        exit 1
    fi
    make all-gcc
    if [ "$?" -ne "0" ]; then
        echo "=== build script: failed to make gcc ==="
        exit 1
    fi
    make install-gcc
    if [ "$?" -ne "0" ]; then
        echo "=== build script: failed to install gcc ==="
        exit 1
    fi
    make all-target-libgcc
    if [ "$?" -ne "0" ]; then
        echo "=== build script: failed to make libgcc ==="
        exit 1
    fi
    make install-target-libgcc
    if [ "$?" -ne "0" ]; then
        echo "=== build script: failed to install libgcc ==="
        exit 1
    fi
    
    echo "=== build script: OK ==="
    

  2. You may need to reapply dos2unix to build_gcc_cross.sh if your text editor does not preserve DOS/Unix line endings.
  3. Run C:\Cygwin\opt\crosstool\src\build_gcc_cross.cmd and wait until it completes.
  4. If there are no errors, shudown the Cygwin VM and make snapshot "SNAP-4".

Notes:

  • If there's complaint about missing file fenv.h, then you forgot to specify "--disable-decimal-float" when configuring gcc.
  • "--without-headers" means freestanding-mode only compiler without libc dependency.
  • Multilib is a special feature of GCC to allow building 32-bit targets on x86_64 platform. It's useless on ARM.
  • If you didn't apply gcc--armhf-triplet.diff and other patches from this tutorial for gcc, you will get the following error during build:
    configure: error: cannot compute suffix of object files: cannot compile
    See `config.log' for more details.
    and config.log will contain the following error message:
    sorry, unimplemented: -mfloat-abi=hard and VFP
    Reason: *-gnueabihf architecture is Debian/Raspbian specific thing and vanilla GCC doesn't recognize it (vanilla GCC expects *-gnueabi). gcc--armhf-triplet.diff patch adds support for *-gnueabihf.
  • If you didn't apply all patches from this tutorial for gcc and eglibc, then gcc may generate HardFP ABI executable files bound to ld-linux.so.3 instead of ld-linux-armhf.so.3 and they will crash when executed on Raspberry PI.

Additional steps to support SoftFP ABI:

  1. Replace TARGET=arm-linux-gnueabihf with TARGET=arm-linux-gnueabi and ../gcc-4.6.3/configure with ../gcc-4.6.3.noarmhf/configure in build_gcc_cross.sh
  2. binutils configure flags: --with-arch=armv4t
  3. gcc configure flags: --with-arch=armv4t --with-float=soft. Also remove --with-fpu=vfp.
  4. You may need to reapply dos2unix to build_gcc_cross.sh if your text editor does not preserve DOS/Unix line endings.
  5. Run C:\Cygwin\opt\crosstool\src\build_gcc_cross.cmd and wait until it completes.
  6. If there are no errors, shudown the Cygwin VM and make snapshot "SNAP-5".


>> Read next section or buy already prepared cross-compiler ($10) to save your time.