Building GLibc in the Cygwin VM

  1. Update C:\Cygwin\opt\crosstool\src\build_gcc_cross.sh :
    #!/bin/bash
    
    export TARGET=i486-linux-gnu
    export PREFIX=/opt/crosstool/gcc-4.4.1-glibc-2.10.1/$TARGET
    export PATH=$PATH:$PREFIX/bin
    
    cd /opt/crosstool/src/build-glibc
    ../glibc-2.10.1/configure --prefix=/usr \
        --with-headers=$PREFIX/usr/include \
        --enable-add-ons=nptl --enable-kernel=2.6.0 \
        --with-binutils=$PREFIX --build=i686-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
    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 ==="
  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, shutdown Cygwin VM and make snapshot "SNAP-6".
  5. Replace TARGET=i486-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.
  • libc_cv_forced_unwind=yes libc_cv_c_cleanup=yes options are here to disable linker tests. Because we run glibc build in the cross-environment, these tests create binary files which can't be executed and so fail the test.
  • nptl is a modern library to support POSIX threads in Linux; and it obsoletes linuxthreads, so they should be disabled.
  • "--enable-kernel" sets minimum version of Linux kernel for this glibc to run on. 2.6.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.
  • glibc of old versions when used together with modern binutils (2.20+) might complain about wrong binutils version on configure stage:
    configure: error:
    *** These critical programs are missing or too old: as ld
    *** Check the INSTALL file for required versions.
    This is a minor glitch and can be easily fixed: replace 2.1[3-9]* regexp in configure script and configure.in (in glibc source tree) with 2.2[0-9]*.
  • If glibc build for x86 drops out with complaints about missing __sync_bool_compare_and_swap_4 then you have probably misconfigured gcc on the previous step (forgot about "--with-arch=i486"). Try again!
  • If you want to build glibc for i686-linux-gnu or i686-pc-linux-gnu target, then you're likely to get the following error messages:
    ../sysdeps/i386/fpu/s_frexp.S: Assembler messages:
    ../sysdeps/i386/fpu/s_frexp.S:66: Error: invalid identifier for ".ifdef"
    ../sysdeps/i386/fpu/s_frexp.S:66: Error: junk at end of line, first unrecognized character is `1'
    ../sysdeps/i386/fpu/s_frexp.S:66: Error: junk at end of line, first unrecognized character is `1'
    ../sysdeps/i386/fpu/s_frexp.S:66: Error: junk at end of line, first unrecognized character is `1'
    ../sysdeps/i386/fpu/s_frexp.S:66: Error: unrecognized symbol type ""
    ../sysdeps/i386/fpu/s_frexp.S:66: Error: junk at end of line, first unrecognized character is `1'
    ../sysdeps/i386/fpu/s_frexp.S:66: Error: junk at end of line, first unrecognized character is `1'
    ../sysdeps/i386/fpu/s_frexp.S:66: Error: expected comma after name `' in .size directive
    ../sysdeps/i386/fpu/s_frexp.S:66: Error: ".endif" without ".if"
    ../sysdeps/i386/fpu/s_frexp.S:66: Error: junk `.get_pc_thunk.dx' after expression

    In order to fix or prevent these errors, make the following corrections in the build_gcc_cross.sh:
    make asm-CPPFLAGS="-D __i686=__i686"
    if [ "$?" -ne "0" ]; then
        echo "=== build script: failed to make glibc ==="
        exit 1
    fi
    make asm-CPPFLAGS="-D __i686=__i686" install_root=$PREFIX install
    if [ "$?" -ne "0" ]; then
        echo "=== build script: failed to install glibc ==="
        exit 1
    fi
  • 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.