Skip to the text
KDOS
Menu
kdos.dev KDOS from Scratch KDOS 0.2 · 4dd4a10 · 2026-11-30 Contents Index

6. Cross binutils

The first step of the build compiles GNU binutils, the assembler, the linker and the tools that read and rewrite object files, to run in the container and write code for x86_64-kdos-linux-musl. It is the step the cross GCC needs before it can be built, and it is the unit of build time this book measures in (see Build times and the SBU). This page shows the commands of script/phases/00_cross/00_binutils.sh, explains each configure switch, lists what it installs, and compares it with the two later builds of the same source.

Source: the archive of the binutils port
Installs into: build/cross
Approximate build time: 1 SBU, by definition; 43 seconds on the machine that measured this book’s build times

Installation of cross binutils

BINUTILS_SRC=$(extract_port_source binutils)
cd "$BINUTILS_SRC"

mkdir build && cd build
../configure \
    --target=$KDOS_TARGET \
    --with-sysroot=$SYSROOT \
    --prefix=$CROSS_SYSROOT \
    --disable-nls \
    --disable-werror \
    --disable-multilib \
    --enable-new-dtags \
    --enable-gprofng=no \
    --enable-default-hash-style=gnu
make
make install

script/phases/00_cross/00_binutils.sh, lines 24–39

extract_port_source unpacks the port’s archive into build/tmp and prints the directory it made; Part III describes it. binutils is built in a build directory of its own, as its documentation asks, so the source tree stays clean.

The meaning of the configure options

--target=$KDOS_TARGET
Build tools that run here and write for x86_64-kdos-linux-musl. Every program is installed as build/cross/bin/x86_64-kdos-linux-musl-ld and the like, the names a configure script given --host looks for. Ten of them, as, ld and ar among them, are installed a second time under their plain names in build/cross/x86_64-kdos-linux-musl/bin, which is where the cross GCC looks for its assembler and linker.
--with-sysroot=$SYSROOT
Make build/fs the linker’s root. Its default library directories, /usr/lib among them, and every absolute path in a linker script are looked up under build/fs, so -lc finds build/fs/usr/lib/libc.so and never the container’s.
--prefix=$CROSS_SYSROOT
Install under build/cross.
--disable-nls
Build no message catalogues. A build log is read in English, and nothing in this toolchain outlives the bootstrap.
--disable-werror
Keep the warnings that the container’s compiler raises in binutils’ sources as warnings, so a newer warning does not stop the build.
--disable-multilib
KDOS has one ABI, 64-bit x86. The switch belongs to the top-level configure that binutils shares with GCC, where it governs the libraries built for the target. binutils builds none, so it changes nothing here; it keeps this line saying what the GCC line beside it says.
--enable-new-dtags
Make the linker write a -rpath as DT_RUNPATH rather than the older DT_RPATH. The dynamic linker searches DT_RUNPATH after LD_LIBRARY_PATH, so a run path never overrides the environment.
--enable-gprofng=no
Do not build gprofng, the newer profiler. binutils’ configure already leaves it out for every *-musl* target, so this states the result rather than changing it.
--enable-default-hash-style=gnu
Write only the GNU symbol hash table, .gnu.hash, into shared objects and dynamic executables. On a Linux target the linker otherwise writes the classic SysV .hash as well. musl’s dynamic linker reads .gnu.hash when it is present, so the second table is never used.

make and make install take no options. The job count comes from MAKEFLAGS, which common.env sets (see Part II).

Contents of cross binutils

Installed programs, in build/cross/bin, each prefixed x86_64-kdos-linux-musl-: addr2line, ar, as, c++filt, elfedit, gprof, ld, ld.bfd, nm, objcopy, objdump, ranlib, readelf, size, strings and strip.

Installed directory: build/cross/x86_64-kdos-linux-musl, with unprefixed copies of ar, as, ld, ld.bfd, nm, objcopy, objdump, ranlib, readelf and strip in bin, and the linker scripts in lib/ldscripts. build/cross/lib/bfd-plugins holds libdep.so, the linker plugin that links the libraries an archive records in its __.LIBDEP member.

as
The assembler: turns the assembly GCC writes into object files.
ld, ld.bfd
The linker, under its generic name and its implementation’s name. It joins object files and libraries into an executable or a shared object.
ar, ranlib
Make static archives and index them.
nm, objdump, readelf, size, strings, addr2line, c++filt
Read object files: symbols, sections, headers, sizes, printable strings, the source line of an address, and demangled C++ names.
objcopy, strip, elfedit
Rewrite object files: copy and convert sections, remove symbols, change ELF header fields.
gprof
The call-graph profiler.

Built again later

The same source is built twice more, and each build replaces this one in its own place.

Native binutils, in 10_bootstrap, is compiled by the cross GCC to run on KDOS. It keeps every switch above except the three that make a cross toolchain: --target and --with-sysroot go, --prefix becomes /usr, and --host=$KDOS_TARGET comes in. It installs into build/fs/usr through DESTDIR.

The binutils port, in 20_selfhost, is the one KDOS ships. It is built inside the chroot with no triplet, and it adds what a system’s binutils needs: shared libbfd and libopcodes (--enable-shared), the linker plugin interface and LTO support (--enable-plugins, --enable-lto), deterministic archives (--enable-deterministic-archives), 64-bit BFD on every host (--enable-64-bit-bfd), and the system zlib and xxHash (--with-system-zlib, --with-xxhash). It leaves out --disable-multilib, --enable-new-dtags, --enable-gprofng=no and --enable-default-hash-style=gnu.

The last of these has a visible effect. A program linked by the shipped linker carries both .hash and .gnu.hash; one linked by the bootstrap toolchain carries only .gnu.hash. In a built root, build/fs/usr/bin/ls, built by a port, has both tables, and build/fs/usr/bin/kpkg, which is always compiled by the cross toolchain, has only the GNU one. readelf -S lists a file’s sections and shows which tables it has.

See also