Building Binutils & GCC in the MinGW VM
Now it's time to replace second bootstrapping compiler with full-featured compiler tied to glibc and capable of building hosted code, not only freestanding code. Also new compiler will be independent from cygwin1.dll, unlike the old one.
Update C:\MinGW\msys\1.0\opt\crosstool\src\build_cross_toolchain.sh as follows:
#!/bin/bash export PATH=.:/usr/local/bin:/mingw/bin:/bin export PATH=$PATH:/c/WINDOWS/system32:/c/WINDOWS export PATH=$PATH:/c/WINDOWS/System32/Wbem export TARGET=arm-linux-gnueabihf export PREFIX=/opt/crosstool/gcc-8.3.0-glibc-2.28/$TARGET cd /opt/crosstool/src/build-binutils find . -delete LDFLAGS="-Wl,-s -Wl,-static -static -static-libgcc" \ ../binutils-2.31.1/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 LDFLAGS="-Wl,-s -Wl,-static -static -static-libgcc" \ ../gcc-8.3.0/configure --target=$TARGET --prefix=$PREFIX \ --with-sysroot=$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,c++ \ --with-headers --enable-shared --enable-threads=posix \ --disable-multilib -enable-__cxa_atexit \ --disable-fixed-point \ --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 if [ "$?" -ne "0" ]; then echo "=== build script: failed to make gcc ===" exit 1 fi make install if [ "$?" -ne "0" ]; then echo "=== build script: failed to install gcc ===" exit 1 fi echo "=== build script: OK ==="
- Run C:\MinGW\msys\1.0\opt\crosstool\src\build_cross_toolchain.cmd and wait until it completes.
- If there are no errors, shutdown the MinGW VM and make snapshot "SNAP-D".
Notes:
- Multilib is a special feature of GCC to allow building 32-bit targets on x86_64 platform. It's useless on ARM.
- LDFLAGS="-Wl,-s -Wl,-static -static -static-libgcc" option prevents dynamic linking to libgcc_s_dw2-1.dll (runtime library of MinGW) and also automatically strips EXE files at build time.
Additional steps to support SoftFP ABI:
- Replace TARGET=arm-linux-gnueabihf with TARGET=arm-linux-gnueabi in build_cross_toolchain.sh
- binutils configure flags: --with-arch=armv4t
- gcc configure flags: --with-arch=armv4t --with-float=soft. Also remove --with-fpu=vfp.
- Run C:\MinGW\msys\1.0\opt\crosstool\src\build_cross_toolchain.cmd and wait until it completes.
- If there are no errors, shutdown the MinGW VM and make snapshot "SNAP-E".
>> Read next section or
buy already prepared
cross-compiler (€10) to save your time.