Toolchains adventures - Q1 2023

Frederic Cambus March 31, 2023 [LLVM] [Compilers] [Toolchains]

This is the seventh post in my toolchains adventures series. Please check the previous posts in the toolchains category for more context about this journey. There was no Q4 2022 report as there wasn't really anything worthwhile to write about, only some usual Pkgsrc and OpenBSD toolchains related ports updates.

In Pkgsrc land, I updated binutils to the 2.40 version, mold to the 1.9.0, 1.10.0, 1.10.1, and 1.11.0 versions, patchelf to the 0.17.2 version, and finally pax-utils to the 1.3.6 and the 1.3.7 ones. I also updated the NetBSD system call table in GDB to add the eventfd(2) and timerfd(2) syscalls which were added back in 2021.

Regarding OpenBSD, I updated binutils to the 2.40 version and enabled the build of gas, for which I also pushed support for ARM upstream. While there, I added support upstream for the PT_OPENBSD_MUTABLE segment type to readelf. Lastly, I packaged and imported pax-utils into the ports collection.

In early February, I attended FOSDEM 2023 in Brussels and had the opportunity to attend some talks in the LLVM devroom as well as some toolchains related ones in the RISC-V and Binary Tools devrooms.

Lately, I've been exploring using alternative linkers in Pkgsrc. By default, the host system default linker will be used, which happens to be GNU ld on NetBSD and most Linux distributions.

Thanks to work done by pho@ and the instructions he posted on the tech-pkg mailing list, it was already possible to use mold within Pkgsrc, by adding these directives in the etc/mk.conf configuration file:

LD=			/usr/pkg/bin/mold
LDFLAGS+=		-Wl,-L/usr/lib	-B/usr/pkg/libexec/mold
CWRAPPERS_PREPEND.cxx+=	-B/usr/pkg/libexec/mold

I wanted to also try using LLD (the LLVM linker), and modified the devel/lld package to add a symlink in ${PREFIX}/libexec so that it can be used in Pkgsrc.

While mold can be used as a linker when using both GCC and Clang, for LLD one must use Clang as a compiler, using the PKGSRC_COMPILER directive. The reason for this is that LLD does not support the -dc and -dp options.

The following directives must be added in the etc/mk.conf configuration file:


LD=			/usr/pkg/bin/lld
LDFLAGS+=		-Wl,-L/usr/lib	-B/usr/pkg/libexec/lld
CWRAPPERS_PREPEND.cxx+=	-B/usr/pkg/libexec/lld

Verifying that a binary was produced by mold or LLD can be done using readelf.

On the mold binary linked with mold itself:

readelf -p .comment mold

String dump of section '.comment':
  [     0]  mold 1.10.1 (compatible with GNU ld)
  [    25]  GCC: (NetBSD nb1 20220722) 10.4.0
  [    47]  GCC: (nb1 20220722) 10.4.0

And on the lld binary linked with LLD itself:

readelf -p .comment lld

String dump of section '.comment':
  [     0]  clang version 15.0.7
  [    16]  Linker: LLD 15.0.7
  [    29]  GCC: (NetBSD nb1 20220722) 10.4.0

As usual, I’ve also been busy reading different material, and adding new resources to

That’s all for now, happy Spring 2023 everyone!

binutils and GDB commits:

2023-03-2380251d4Add support to readelf for the PT_OPENBSD_MUTABLE segment type
2023-03-17152d9c4Update the NetBSD system call table to add eventfd(2) and timerfd(2)
2023-01-202e17538Add OpenBSD ARM GAS support

LLVM commits

2023-03-198510cf9[compiler-rt] Add missing #else clause to fix the build on NetBSD
2023-03-16245f26a[docs] Document "PGO" (Profile-Guided Optimization) in the lexicon
2023-03-15d8df871[compiler-rt] Point UndefinedBehaviorSanitizer link to its own page
2023-02-105cec69b[clang] Update Clang version from 16 to 17 in scan-build.1

Back to top