This is an old revision of the document!
Introduction
lld, part of the LLVM family of projects, is a high-performance linker for the ELF, COFF, and Mach-O object formats. This page describes the ongoing project to use lld as FreeBSD's base system linker.
LLD in Base
LLD is currently the default system linker on amd64, arm*, aarch64, and powerpc64. On i386 LLD is /usr/bin/ld.lld but /usr/bin/ld is still GNU BFD ld.
On other architectures, to build world and kernel with LLD and install LLD as /usr/bin/ld, add to /etc/src.conf:
WITH_LLD_IS_LD=yes WITH_LLD_BOOTSTRAP=yes
WITH_LLD_BOOTSTRAP=yes uses lld as the linker for building the FreeBSD world, and has no effect on the linker installed in /usr/bin/ld. WITH_LLD_IS_LD=yes installes lld as /usr/bin/ld, and has no effect on the linker used for building world.
Upstream LLD
Building
git clone https://github.com/llvm-mirror/llvm cd llvm/tools git clone https://github.com/llvm-mirror/lld mkdir ../build && cd ../build cmake -G "Unix Makefiles" ../ make -j8
LLD as default linker
cd build/bin ln -s lld ld setenv PATH /path/to/llvm/build/bin:$PATH setenv LD /path/to/llvm/build/bin rehash
To check if the changes took effect:
davide@rabbit1:/home/davide/llvm/build/bin $ ld --help | head -n 1 OVERVIEW: LLVM Linker
Per-arch status (in HEAD)
| Architecture | World | Kernel | Bootstrap linker | /usr/bin/ld |
|---|---|---|---|---|
| amd64 | OK | OK | lld | lld |
| arm64 | OK | OK | lld | lld |
| i386 | OK | OK | lld | bfd |
| arm | libc fails to link | LLD targets v7l+ | bfd | bfd |
| armv6 | libc fails to link | LLD targets v7l+ | bfd | bfd |
| armv7 | OK | OK | lld | bfd |
| mips64 | Most links, untested | Link fails | bfd | bfd |
| mips | Most links, untested | Link fails | bfd | bfd |
| powerpc64 | OK | OK | lld | lld |
| powerpc | libc fails to link | Untested | bfd | bfd |
| sparc64 | no support | no support | bfd | bfd |
| riscv | OK | OK | lld | lld |
TODO
WIP patches
lld
MIPS
MIPS Multi-GOT implementation (2017-03-31)
ARM
Introduce range extension thunks for ARM (2017-06-27)Add support for multiple passes to createThunks (2017-06-27)
FreeBSD
Known Issues
A FreeBSD ports exp-run is tracked in PR214864.
- go crashes on startup go Github issue 19018
- print/gl2ps needs explicit -L/usr/lib PR218399.
Common issues in ports
- Passing compiler flags, such as
-fPIC, to the linker. - lld has no built-in search paths (
/lib, /usr/lib). Normally the linker is invoked from the compiler driver, which adds the library search paths. If lld is invoked directly then library search paths must be explicitly specified, with-L/lib -L/usr/lib. - Shared library protected symbol preemption.
- lld does not have a built-in default output target. For the most common use of the linker (linking individual .o objects in to an executable or shared object) lld infers the target from the first object file. However, when the linker is used to convert an arbitrary binary file into an ELF object (via -r -b binary) lld must have the output target specified explicitly with -m.
Resources
- Rui Ueyama's New LLD linker for ELF talk
- Linking the FreeBSD base system with LLD status update from March 2016
- lld as the FreeBSD base system linker Google Doc