Hello,

On Mon, Nov 23, 2026 at 07:30:42PM +0300, Sergey Bugaev wrote:
> > +
> > +  * __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)".
> 

Indeed, those were just packages. I'll extend a bit on the name of the
projects and leave as a comment the Debian package.

> > +## 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...
>

Ok, I'll see what can be made plain shell variables to avoid polluting
the environment.

> > +
> > +    $ export BINUTILS_VERSION=2.39
> > +    $ export GCC_VERSION=12.2.0
> 
> Nor here. Also let's use a newer version :)

Yes, I'll also add the committish of the Git based sources later.

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

Noted.

> 
> > +
> > +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.

:( Noted.

> > +
> > +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

:( Noted again.


> > +    $ 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?

No, it's a typo of libatomic.

> > +            --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.

I couldn't follow your guide completely, at some point it found errors.
Then, I asked the AI about the issues and this was the result :P

Right now I don't remember clearly what triggered errors, maybe it was
the file format in the log below.

    i686-gnu-gcc 
-Wl,-rpath-link=/home/demo/hurd/bugaev-cross-gnu/gnu/src/glibc/build:/home/demo/hurd/bugaev-cross-gnu/gnu/src/glibc/build/math:/home/demo/hurd/bugaev-cross-gnu/gnu/src/glibc/build/elf:/home/demo/hurd/bugaev-cross-gnu/gnu/src/glibc/build/dlfcn:/home/demo/hurd/bugaev-cross-gnu/gnu/src/glibc/build/nss:/home/demo/hurd/bugaev-cross-gnu/gnu/src/glibc/build/nis:/home/demo/hurd/bugaev-cross-gnu/gnu/src/glibc/build/rt:/home/demo/hurd/bugaev-cross-gnu/gnu/src/glibc/build/resolv:/home/demo/hurd/bugaev-cross-gnu/gnu/src/glibc/build/mathvec:/home/demo/hurd/bugaev-cross-gnu/gnu/src/glibc/build/support:/home/demo/hurd/bugaev-cross-gnu/gnu/src/glibc/build/misc:/home/demo/hurd/bugaev-cross-gnu/gnu/src/glibc/build/debug:/home/demo/hurd/bugaev-cross-gnu/gnu/src/glibc/build/htl:/home/demo/hurd/bugaev-cross-gnu/gnu/src/glibc/build/mach:/home/demo/hurd/bugaev-cross-gnu/gnu/src/glibc/build/hurd:./
 -o 
/home/demo/hurd/bugaev-cross-gnu/gnu/src/glibc/build/support/links-dso-program 
-pie -Wl,-z,pack-relative-relocs -Wl,-O1 -nostdlib -nostartfiles -Wl,-z,relro 
/home/demo/hurd/bugaev-cross-gnu/gnu/src/glibc/build/csu/Scrt1.o 
/home/demo/hurd/bugaev-cross-gnu/gnu/src/glibc/build/csu/crti.o `i686-gnu-gcc 
--print-file-name=crtbeginS.o` 
/home/demo/hurd/bugaev-cross-gnu/gnu/src/glibc/build/support/links-dso-program.o
 -lstdc++ -lgcc 
-Wl,-dynamic-linker=/home/demo/hurd/bugaev-cross-gnu/gnu/lib/ld.so.1 
/home/demo/hurd/bugaev-cross-gnu/gnu/src/glibc/build/libc.so.0.3 
/home/demo/hurd/bugaev-cross-gnu/gnu/src/glibc/build/libc_nonshared.a 
-Wl,--as-needed /home/demo/hurd/bugaev-cross-gnu/gnu/src/glibc/build/elf/ld.so 
-Wl,--no-as-needed -lgcc `i686-gnu-gcc --print-file-name=crtendS.o` 
/home/demo/hurd/bugaev-cross-gnu/gnu/src/glibc/build/csu/crtn.o
    
/home/demo/hurd/bugaev-cross-gnu/gnu/src/glibc/build/support/links-dso-program.o:
 file not recognized: file format not recognized
    collect2: error: ld returned 1 exit status

Eventually, I'll try again your approach to see if I can get further.

> > +#### 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.

Ok.

> 
> > +  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?
> 

Hmmm, probably? I need to investigate the newlib flag more thoroughly.

> > +##### 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?
>

I'm not sure, but if I leave the arguments out, a bunch of configure
errors pop up:

    checking for file_exec_paths...
    configure: error: link tests are not allowed after AC_NO_EXECUTABLES

> > +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.
>

Ok.

> > +
> > +#### 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?

Without /lib/ld.so, I get this boot error.

    start ext2fs: Hurd server bootstrap: ext2fs[device:hd0s1] exec 
startupFailed to execute startup
    ext2fs: Executing '/hurd/startup': No such file or directory

And when I inpect "$SYSROOT/hurd/startup", I get the following.

    $ "$TARGET"-readelf -l $SYSROOT/hurd/startup | grep interpreter
          [Requesting program interpreter: /lib/ld.so]

So, it seems to me that /lib/ld.so needs to be present. And indeed,
after linking the startup error is gone.

This is the AI slop that said the link was not there for historical
reasons and that gcc still uses /lib/ld.so for i386. [1]

Thanks
Diego

--
[1] https://pastebin.support.one/view/6cd45610

Reply via email to