Skip to content

Using LLD

LLD is installed as ld.lld. On Unix, linkers are invoked by compiler drivers, so you are not expected to use that command directly. There are a few ways to tell compiler drivers to use ld.lld instead of the default linker.

The easiest way to do that is to overwrite the default linker. After installing LLD to somewhere on your disk, you can create a symbolic link by doing ln -s /path/to/ld.lld /usr/bin/ld so that /usr/bin/ld is resolved to LLD.

If you don’t want to change the system setting, you can use clang’s -fuse-ld option. In this way, you want to set -fuse-ld=lld to LDFLAGS when building your programs.

LLD leaves its name and version number to a .comment section in an output. If you are in doubt whether you are successfully using LLD or not, run readelf --string-dump .comment <output-file> and examine the output. If the string “Linker: LLD” is included in the output, you are using LLD.

option 1: Rebuild FreeBSD

# /etc/make.conf
WITH_LLD = yes

then rebuild FreeBSD

option 2: set LDFLAGS

# Makefile
LDFLAGS += -fuse-ld=lld

LDFLAGS can be set in /etc/make.conf globally or set per Makefile.

option 3: clang command line option

prog.cpp: cpp (c++) example

// prog.cpp
#include <algorithm>
#include <cmath>
#include <vector>
#include <iostream>

int main() {
        std::vector<int> v1 {3, 7, 5, 9, 2, 4, 1};
        std::vector<int> v2 {9, 8, 7, 6, 5, 4, 3};
        std::vector<double> v3;
        std::transform(v1.begin(), v1.end(), v2.begin(), 
                std::back_inserter(v3), [] (const int & x, const int & y) {
                        return std::sqrt(x*x+y*y);
        for (const auto & val: v3) std::cout << val << " ";
        std::cout << std::endl;

Compile prog.cpp command line.

$ clang++ prog.cpp -std=c++17 -stdlib=libc++ -fuse-ld=lld -o prog                        
$ ./prog
9.48683 10.6301 8.60233 10.8167 5.38516 5.65685 3.16228 

dump the .comment section of the elf file

$ readelf --version
readelf (elftoolchain r3561M)
$ ld.lld --version
LLD 6.0.0 (FreeBSD 324090) (compatible with GNU linkers)
$ readelf --string-dump .comment prog

String dump of section '.comment':
  [     0]  $FreeBSD$
  [     a]  Linker: LLD 6.0.0 (FreeBSD 324090)
  [    2e]  FreeBSD clang version 6.0.0 (branches/release_60 324090) (based on LLVM 6.0.0)



No Trackbacks


Display comments as Linear | Threaded

No comments

Add Comment

E-Mail addresses will not be displayed and will only be used for E-Mail notifications.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.

Form options

Submitted comments will be subject to moderation before being displayed.