Building GLibc in the Cygwin VM

  1. Before building glibc, you must remove the following folders:
    /opt/crosstool/gcc-8.3.0-glibc-2.28/i586-linux-gnu/include
    /opt/crosstool/gcc-8.3.0-glibc-2.28/x86_64-linux-gnu/include
               
  2. Update C:\Cygwin\opt\crosstool\src\build_gcc_cross.sh :
    #!/bin/bash
    export TARGET=i586-linux-gnu
    export PREFIX=/opt/crosstool/gcc-8.3.0-glibc-2.28/$TARGET
    export PATH=$PATH:$PREFIX/bin
    
    cd /opt/crosstool/src/build-glibc
    find . -delete
    ../glibc-2.28/configure --prefix=/usr \
        --with-headers=$PREFIX/usr/include \
        --enable-add-ons=nptl --enable-kernel=4.0.0 \
        --with-binutils=$PREFIX --build=x86_64-pc-cygwin \
        --host=$TARGET --enable-shared --disable-profile \
        --with-tls --with-__thread --without-gd --without-cvs \
        libc_cv_forced_unwind=yes libc_cv_c_cleanup=yes \
        libc_cv_ssp=no
    if [ "$?" -ne "0" ]; then
        echo "=== build script: failed to configure glibc ==="
        exit 1
    fi
    make
    if [ "$?" -ne "0" ]; then
        echo "=== build script: failed to make glibc ==="
        exit 1
    fi
    make install_root=$PREFIX install
    if [ "$?" -ne "0" ]; then
        echo "=== build script: failed to install glibc ==="
        exit 1
    fi
    
    echo "=== build script: OK ==="
  3. Run C:\Cygwin\opt\crosstool\src\build_gcc_cross.cmd and wait until it completes.
  4. If there are no errors, shutdown Cygwin VM and make snapshot "SNAP-6".
  5. Replace TARGET=i586-linux-gnu with TARGET=x86_64-linux-gnu, then run C:\Cygwin\opt\crosstool\src\build_gcc_cross.cmd and wait until it completes.
  6. If there are no errors, shutdown Cygwin VM and make snapshot "SNAP-7".

Notes:

  • Glibc build will take a lot of time, 4-5 times more than binutils + gcc.
  • "--enable-kernel" sets minimum version of Linux kernel for this glibc to run on. 4.0.0 should be good enough these days.
  • "--prefix=/usr" is not dangerous and will not hurt your /usr in host system, unless you call "make install" in plain and wrong way. This is an old glibc joke.
  • If you get the following error messages during build:
    In file included from ../sysdeps/unix/sysv/linux/i386/sysdep.h:27,
                     from <stdin>:1:
    ../sysdeps/i386/nptl/tls.h:24:11: fatal error: stdbool.h: No such file or directory
     # include <stdbool.h>
               ^~~~~~~~~~~
    compilation terminated.
    make[2]: *** [../Makerules:287: /opt/crosstool/src/build-glibc/tcb-offsets.h] Error 1
    make[2]: Leaving directory '/opt/crosstool/src/glibc-2.28/csu'
    make[1]: *** [Makefile:258: csu/subdir_lib] Error 2
    make[1]: Leaving directory '/opt/crosstool/src/glibc-2.28'
    make: *** [Makefile:9: all] Error 2

    then you forgot to delete the following folders before running the script:
    /opt/crosstool/gcc-8.3.0-glibc-2.28/i586-linux-gnu/include
    /opt/crosstool/gcc-8.3.0-glibc-2.28/x86_64-linux-gnu/include
  • Also you may get error message about various missing syscalls (__-prefixed) if you forgot to replace .oS with .oZ in makefiles (Cygwin case-insensitive filesystem).


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