25. Binutils
GNU binutils is the assembler, the linker and the tools that read and rewrite object files: as, ld, ar, nm, objdump, readelf, strip and the rest. The binutils in build/cross runs only in the container. This step builds a second, native one: compiled by the cross toolchain, it runs on KDOS and produces programs for KDOS, so the GCC of the next step has an assembler and a linker to call once the build moves inside build/fs. 090_binutils.sh builds it from the binutils port’s source tarball, the same source as Part II’s cross binutils.
Source: the archive of the binutils port
Installs into: build/fs/usr
Approximate build time: 1.1 SBU
Installation of binutils
The step unpacks the port’s tarball and builds in a separate build directory, as binutils’ own documentation recommends:
BINUTILS_SRC=$(extract_port_source binutils)
cd "$BINUTILS_SRC"
mkdir build && cd build
../configure \
--host=$KDOS_TARGET \
--prefix=/usr \
--disable-nls \
--disable-werror \
--disable-multilib \
--enable-new-dtags \
--enable-gprofng=no \
--enable-default-hash-style=gnu
make
make DESTDIR=$SYSROOT install
# No libtool archive outlives this step: these are installed outside any
# package, so nothing later removes them, and libtool would copy their
# dependency lists into every library linked against libbfd or libopcodes.
rm -f $SYSROOT/usr/lib/lib{bfd,ctf,ctf-nobfd,opcodes,sframe}.la
# The manual pages of the Windows PE tools, which a Linux target does
# not build; the binutils port deletes them from its package too.
rm -f $SYSROOT/usr/share/man/man1/{dlltool,windres,windmc}.1
script/phases/10_bootstrap/090_binutils.sh, lines 24–47
The meaning of the configure options
--host=$KDOS_TARGET-
The tools run on KDOS. No
--targetis given, so the target defaults to the host, and the tools produce code forx86_64-kdos-linux-muslas well. Because host and target are the same, the programs are installed under their plain names (/usr/bin/ld, notx86_64-kdos-linux-musl-ld). --prefix=/usr-
The programs go to
/usr/bin. binutils also installs a second copy of its main tools, and the linker scripts, under its tool directory,/usr/x86_64-kdos-linux-musl/. --disable-nls- Build no message catalogues.
--disable-werror- Never treat a compiler warning as an error, whatever the source’s own default, so a warning the cross compiler raises does not stop the build.
--disable-multilib-
Build nothing for a second ABI such as
-m32. KDOS has a 64-bit userland only. --enable-new-dtags-
When a link is given a run-time search path,
ldwrites it asDT_RUNPATHinstead of the olderDT_RPATH. glibc’s loader letsLD_LIBRARY_PATHoverride aRUNPATHbut not anRPATH; musl’s, the loader on KDOS, reads the two tags alike and searchesLD_LIBRARY_PATHbefore either. --enable-gprofng=no- Do not build the gprofng profiler. binutils already leaves it out on a musl target; the switch states it.
--enable-default-hash-style=gnu-
The linker writes only the GNU symbol hash table (
.gnu.hash). binutils’ default on Linux isboth, which also writes the older SysV.hash.
--enable-shared is not given, so libbfd, libopcodes, libctf, libctf-nobfd and libsframe are built as static archives, each with a libtool archive (.la) beside it.
Removing the libtool archives
The rm -f line deletes those five .la files. They are installed outside any package, so nothing later removes them, and libtool copies an .la file’s dependency list into every library linked against it. Left in place, every later build that linked libbfd or libopcodes would inherit them.
Removing the Windows tools’ manual pages
The last rm deletes the manual pages of dlltool, windres and windmc, which the install writes although those programs are built only for Windows targets. The binutils port deletes the same three pages from its package, so these copies would be adopted by no package and outlive every install.
The step then removes the source and touches build/mark/bootstrap/binutils.
Built again later
20_selfhost builds the binutils port as its fifth list entry, and 30_foundation names it again so a changed recipe is rebuilt there. The package adopts /usr/bin/ld and the other programs this step installed. The port build differs from this one in several ways:
- It is native to the chroot’s own triple,
x86_64-pc-linux-musl, and installs withtooldir=/usr, so it writes no tree under a target name. Thex86_64-kdos-linux-musltool directory this step created belongs to no package; the gcc package’s install hook deletes it. - It builds shared libraries (
--enable-shared), the LTO plugin and plugin support (--enable-lto,--enable-plugins), and--enable-64-bit-bfd. - It passes
--enable-deterministic-archives, soarwrites zero timestamps and owners, which packages built twice from the same tree need in order to come out byte-identical. - It links the system zlib and xxhash (
--with-system-zlib,--with-xxhash) and turns off zstd, debuginfod and msgpack support. - It passes none of
--enable-new-dtags,--enable-gprofng=noor--enable-default-hash-style=gnu, so the packagedldtakes binutils’ own defaults for them. - It installs the manual pages of the tools by hand from the source’s
docdirectories.
See also
- Bash, the step before this one, and GCC, the step after it
- The binutils port: its version, source and contents
- The toolchain rebuilt as packages: why
20_selfhostbuilds binutils again