Thanks for looking into it! :)

On Mon, Nov 23, 2026 at 4:47 PM <[email protected]> wrote:
> +To start building a toolchain that allows to cross compile the
> +GNU/Hurd some system libraries must be installed in the host OS.
> +
> +  * __bison__
> +  * __flex__
> +  * the three libraries GCC needs.
> +      * __libgmp-dev__
> +      * __libmpfr-dev__
> +      * __libmpc-dev__
> +  * __texinfo__ (for makeinfo command)
> +  * packages for making bootable images
> +      * __grub-pc-bin__
> +      * __grub2-common__
> +      * __parted__

These appear to be something like Debian package names? It would be
better to name the relevant *projects* (e.g. GRUB, GNU MPFR), and then
specify, perhaps in parentheses: "(package libfoo-dev in Debian)".

> +## Setup Environment
> +
> +To support the build process a few environment variables need to be defined.

In my guide at least, these weren't necessarily *envirnment*
variables, merely shell variables...

> +They are used in the commands that have to be run during the compilation
> +process.
> +
> +    $ export DEV_DIR=~/dev/hurd/cross-gnu
> +    $ export TARGET=i686-gnu
> +    $ export PREFIX=$DEV_DIR/gnu
> +    $ export SYSROOT=$DEV_DIR/sysroot
> +    $ export PATH="$PREFIX/bin:$PATH"

...hence no need to "export", except perhaps for PATH.

> +The `TARGET` variable is the system architecture we are building a cross
> +toolchain for.
> +Finally, some version variables are defined that will be used to download
> +the required sources.
> +
> +    $ export BINUTILS_VERSION=2.39
> +    $ export GCC_VERSION=12.2.0

Nor here. Also let's use a newer version :)

> +### Compiling binutils
> +
> +The binutils package provides utilities to work with the target system
> +binaries and assembling and linking for it.
> +
> +    $ cd $DEV_DIR/src
> +    $ wget https://ftp.gnu.org/gnu/binutils/binutils-$BINUTILS_VERSION.tar.gz
> +    $ tar xf binutils-$BINUTILS_VESION.tar.gz
> +    $ cd binutils-$BINUTILS_VERSION
> +    $ mkdir build && cd build
> +    $ ../configure --target=$TARGET \
> +                   --prefix=$PREFIX \
> +                   --with-sysroot=$SYSROOT \
> +                   --disable-nls \
> +                   --disable-werror
> +    $ make -j$(nproc)
> +    $ make install

Better quote the variables, especially paths, e.g. "$SYSROOT".

> +
> +The `--with-sysroot` parameter sets the prefix for target system
> +paths, for instance, `i686-gnu-ld` will look `/lib/libc.so` under

Missed a word: look *for* libc.

> +### GCC and GLIBC
> +
> +Building a cross-compiler is multi stage process since there is no
> +C library available for the target system yet.
> +
> +    GCC Stage 1 -> glibc -> GCC Stage 2
> +
> +#### GCC Stage 1
> +
> +For the first stage of `GCC` compilation, a minimal compiler is needed
> +that is just capable of hanlding the bootstraping process by compiling

Typos here as well: handling and bootstrapping

> +    $ cd $DEV_DIR/src
> +    $ wget 
> https://ftp.gnu.org/gnu/gcc/gcc-$GCC_VERSION/gcc-$GCC_VERSION.tar.gz
> +    $ tar xf gcc-$GCC_VERSION.tar.gz
> +    $ cd gcc-$GCC_VERSION
> +    $ mkdir build-stage1 && cd build-stage1
> +    $ ../configure \
> +            --target=$TARGET \
> +            --prefix=$PREFIX \
> +            --with-sysroot=$SYSROOT \
> +            --with-newlib \
> +            --without-headers \
> +            --enable-initfini-array \
> +            --disable-nls \
> +            --disable-shared \
> +            --disable-multilib \
> +            --disable-decimal-float \
> +            --disable-threads \
> +            --disable-libatocim \
Is the 'm' intended?
> +            --disable-libgomp \
> +            --disable-libquadmath \
> +            --disable-libssp \
> +            --disable-libvtv \
> +            --disable-libstdcxx \
> +            --enable-languages=c
> +    $ make -j$(nproc) all-gcc all-target-libgcc
> +    $ make install-gcc install-target-libgcc
> +
> +With the `--with-newlib` and `--without-headers` we tell the GCC
> +buildsystem to avoid including headers of the target system that
> +don't yet exist. `--disable-shared` and `--disable-threads` prevents
> +the `libgcc_s.so` from being built.

My guide, I think, tried to avoid ever building with newlib.
Consequently, we avoided libgcc until later.

> +#### GLIBC prerequisites on GNU/Hurd
> +
> +To ultimately build `glibc` under _GNU/Hurd_ some header files
> +and tools need to be installed before compilation succeeds.
> +
> +  1. `gnumach` headers are required for Hurd and MIG to be able
> +     to refer to RPC provided by the kernel.

RPCs, plural.

> +  2. `mig`, the Mach Interface Generator, needs to be compiled
> +     as a host tool that produces output for `$TARGET` getting
> +     _.defs_ files as input.
> +  3. `Hurd` headers must be installed before glibc can be built.
> +     `mig` is used to generate headers for the IPC interfaces of
> +     the system.
> +
> +##### gnumach
> +
> +    $ cd $DEV_DIR/src
> +    $ git clone git://git.savannah.gnu.org/hurd/gnumach.git
> +    $ cd gnumach
> +    $ autoreconf -i
> +    $ mkdir build && cd build
> +    $ ../configure --host=$TARGET --prefix=
> +    $ make DESTDIR=$SYSROOT install-data

And here, you've "contaminated" a gnumach build with a newlib-based libgcc, no?

> +##### Hurd
> +
> +    $ cd $DEV_DIR/src
> +    $ git clone git://git.savannah.gnu.org/hurd/hurd.git
> +    $ cd hurd
> +    $ autoreconf -i
> +    $ mkdir build && cd build
> +    $ ../configure --host=$TARGET --prefix= --without-parted \
> +        --without-libbz2 --without-libz --without-rump \
> +        --disable-profile \
> +        ac_cv_func_file_exec_paths=no \
> +        ac_cv_func_exec_exec_paths=no \
> +        ac_cv_func__hurd_exec_paths=no \
> +        ac_cv_func__hurd_libc_proc_init=no \
> +        ac_cv_func_mach_port_set_ktype=no \
> +        ac_cv_func_file_utimens=no \
> +        ac_cv_lib_crypt_crypt=no \
> +        ac_cv_lib_ncursesw_initscr=no
> +    $ make DESTDIR=$SYSROOT no_deps=t install-headers

This is weird by the way: why is Hurd's configure testing for
file_exec_paths/exec_exec_paths/file_utimens, if it's the Hurd project
that supplies them?

> +The few `ac_cv_*` arguments disable the production of some
> +test executables that will inevitably fail as there's no glibc
> +for the target system yet.
> +
> +#### glibc
> +
> +Finally, `glibc` can be configured and built against the produced
> +headers.
> +
> +    $ cd $DEV_DIR/src/glibc
> +    $ git clone https://sourceware.org/git/glibc.git
> +    $ cd glibc
> +    $ mkdir build && cd build
> +    $ ../configure \
> +          --host=$TARGET \
> +          --build=$(../scripts/config.guess) \
> +          --prefix= \
> +          --with-headers=$SYSROOT/include \
> +          --disable-werror \
> +          libc_cv_forced_unwind=yes \
> +          libc_cv_c_cleanup=yes \
> +          CXX=false
> +    $ make install-bootstrap-headers=yes install-headers DESTDIR=$SYSROOT
> +
> +`--host=$TARGET` indicates on what architecture the built code will run.

You could move this comment to where we encounter --host earlier, in
glibc and gnumach.

> +`CXX=false` prevents the build process from using the host's g++ compiler
> +to build test programs like `links-dso-program`.
> +
> +Now the full `glibc` is built and installed at the `$SYSROOT`.
> +
> +    $ make -j$(nproc)
> +    $ make install DESTDIR=$SYSROOT
> +
> +#### GCC Stage 2
> +
> +Once `glibc` is built, the process can continue with the preparation of
> +a fully capable `GCC` that can be used for building programs for the target
> +system or even building `gnumach` and `Hurd`.
> +
> +    $ cd $DEV_DIR/src/gcc-$GCC_VERSION
> +    $ mkdir build-stage2 && cd build-stage2
> +    $ ../configure \
> +            --target=$TARGET \
> +            --prefix=$PREFIX \
> +            --with-sysroot=$SYSROOT \
> +            --enable-initfini-array \
> +            --disable-nls \
> +            --disable-multilib \
> +            --enable-shared \
> +            --enable-threads=posix \
> +            --enable-languages=c,c++
> +    $ make -j$(nproc)
> +    $ make install
> +
> +At this point it should be possible to cross-compile simple C
> +programs for the Hurd with no ceremony:
> +
> +    $ $TARGET-gcc hello.c -o hello
> +    $ file hello
> +    hello: ELF 32-bit LSB executable, Intel i386, version 1 (SYSV),
> +    dynamically linked, interpreter /lib/ld.so, for GNU/Hurd 0.0.0,
> +    with debug_info, not stripped
> +
> +### (BONUS) Making a bootable image
> +
> +To make a bootable image first a full build of `gnumach` and
> +`Hurd` need to be done.
> +
> +For `Hurd`, the linker must be told about the libmachuser.so and
> +libhurduser.so libraries.
> +
> +    $ cd $SYSROOT/lib
> +    $ cat libc.so
> +    /* GNU ld script
> +       Use the shared library, but some functions are only in
> +       the static library, so try that secondarily.  */
> +    OUTPUT_FORMAT(elf32-i386)
> +    GROUP ( /lib/libc.so.0.3 /lib/libcrt_nonshared.a /lib/libhurduser.so 
> /lib/libmachuser.so AS_NEEDED ( /lib/ld.so.1 ) )
> +
> +Make sure /lib/libhurduser.so and /lib/libmachuser.so is listed
> +inthe GROUP section.
> +
> +#### Making the image
> +
> +For programs to be able to run in the target system, the `$SYSROOT` libr
> +directory must contain a link namead ld.so.
> +
> +    $ ln -s ld.so.1 "$SYSROOT/lib/ld.so"

I wonder why; what uses it at runtime?

Sergey

Reply via email to