BT

LLD, LLVM’s New Linker, Coming to LLVM 4

| by Sergio De Simone Follow 21 Followers on Feb 21, 2017. Estimated reading time: 2 minutes |

LLD, which touts great performance improvements over GCC ld, will be included in LLVM 4 rc1 and enabled by default. Although the new linker is already able to build a running FreeBSD/amd64 base system, its inclusion in LLVM is still experimental and could be set back in rc2 if it causes problems.

The progress made by LLD and its level of maturity are best exemplified through the following quote from the recently released FreeBSD project quarterly status report:

LLD developers made significant progress over the last quarter. With changes committed to both LLD and FreeBSD we reached a major milestone: it is now possible to link the entire FreeBSD/amd64 base system (kernel and userland) with LLD.

Additionally, the BSD project has contributed a number of patches that allow LLD to link approximately 95% of the BSD ports, meaning more than 25 thousands packages.

Work on LLD started in May 2015, with the aim to rewrite the ELF (Unix) and COFF (Windows) system linkers to provide higher performance. According to LLD developers, the new linker is overall 1.2x to 2x faster than GNU gold linker, which was itself created within Google to make a linker faster than ld. In fact, LDD can be much faster than both ld and gold, especially when compiling large code bases. On the other hand, its advantage may not be so large for smaller programs or programs that make heavy use of shared libraries. Similarly to gold, LLD does not use the BFD format to abstract over different binary file formats.

Remarkably, LLD is extremely small – 7k lines for the COFF linker and 18K lines for the ELF linker – in comparison with gold, which amounts to 165k lines. Furthermore, it can also be embedded into a program as a static library and used calling its lld::elf::link entry point.

If you want to experiment with LLD before LLVM 4 is available, you can do so by building it from sources:

  $svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
  $cd llvm/tools
  $svn co http://llvm.org/svn/llvm-project/lld/trunk lld
  $cd ../../..
  $mkdir build
  $cd build
  $cmake -G “Ninja” -DCMAKE_BUILD_TYPE=”Release” -DCMAKE_INSTALL_PREFIX=”your_preferred_location” ../llvm
  $ninja lld
  $ninja install

Once LDD is compiled, the most reliable way to use it is symlinking ld to ld.lld, which would work with GCC as well, or use the LLVM -fuse-ld=lld option, which does not require symlinking.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread
Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Discuss
BT