DeveloperWiki:Toolchain maintenance/Binutils

From ArchWiki

The binutils package provides set of programs to assemble and manipulate binary and object files.

Source

The binutils PKGBUILD is set up to use either release tarballs or git checkouts. As binutils rarely releases bug fix releases, it can be useful to build off the release branch to get important backports. Alternatively, maintainers can select individual patches to include and work with the release tarball which has a PGP signature.

If building from release tarballs, we symlink the release directory to "binutils-gdb" during the prepare() function to unify the build process. Additionally, release branches in git are labelled as developmental builds, so we adjust "bfd/development.sh" to set this as a release build.

Dependencies

TODO: document all dependencies (including make and check)

Preparing the Build

Binutils can only be built outside the source tree, so we create a "binutils-build" directory. Using "mkdir -p" is to allow for incremental builds when testing package changes (and is useless during clean chroot builds).

Libiberty configures using "$CPP $CPPFLAGS" which fails using Arch default flags as FORTIFY_SOURCE requires optimisation provided in CFLAGS. We add -O2 the the relevant line in libiberty/configure.

TODO: A potential better solution is to move -D_FORTIFY_SOURCE=2 to CFLAGS (using -Wp,), either in the PKGBUILD or at Arch level. This may also fix testsuite failures (below)

Configuring the Build

The following configure options are used in the binutils build:

Set the default paths in Arch:

--prefix=/usr
--with-lib-path=/usr/lib:/usr/local/lib

We use our bug tracker as the first point of call for Arch users (and derivatives that distribute out packages...):

--with-bugurl=https://bugs.archlinux.org/

Options added to enable our unified git/tarball PKGBUILD:

--disable-gdb
--disable-werror

We build the gold linker, but still use the bfd linker as our default, and enable threading when using gold. There may be benefits in Arch switching to used gold as default at some stage:

--enable-gold
--enable-ld=default
--enable-threads

Enable link time optimization support:

--enable-lto

Enables plugin support for the linker:

--enable-plugins

Enable -z,relro by default. This is enabled as a security feature.:

--enable-relro

TODO: is -z,relro needed in makepkg.conf?

Try to use only PIC objects:

--with-pic

Create reproducible archives - zero for UIDs, GIDs, timestamps, and use consistent file modes for all files:

--enable-deterministic-archives

Support Intel CET instructions:

--enable-cet

Build the BFD and opcodes libraries as shared libraries, some of which we then delete during packaging...:

--enable-shared

NOTE: currently disabled' See upstream bug

Enable producing EFI binaries - useful for setting up UEFI boot with Xen:

 --enable-targets=x86_64-pep

Enable debuginfo lookups with debuginfod:

--with-debuginfod

Use the system zlib library rather than the copy in the binutils source:

--with-system-zlib

Testsuite

It is important that the Arch LDFLAGS are overridden before running the binutils testsuite. The testsuite makes decisions of which LDFLAGS to include while test various features, and does not ignore values from the build environment.

Failures in the ld.bfd linker testsuite need examined in detail and documented before release of any package. As ld.gold is not the default linker, we allow failures in its testsuite. These failures in the gold testsuite have historically been false positives due to the Arch buildflags.

The following tests are the current (binutils-2.35.1) known to fail in the gold testsuite:

incremental_test_2
incremental_test_3
incremental_test_4
incremental_test_5
incremental_test_6
incremental_copy_test
incremental_common_test_1
incremental_comdat_test_1

TODO: investigate these failures and document reasons. Note testsuite attempts to remove FORTIFY_SOURCE, but assumes it is specified with -Wp in CFLAGS rather than directly in LDFLAGS.

Packaging Notes

We remove man pages for utilities that we do not distribute (Windows/Novell only).

We also prevent programs from dynamically linking against libbfd and libopcodes, as these are rather unstable. Instead, we provide linker scripts to link the static versions (and their dependencies).