what's the name of ubuntu package contains llvm linker lld

Would like to try this lld from LLVM. The doc on apt could be found here, but I don’t know which package contains the lld executable.

It seems the purpose of lld is to remove the system dependency, but clang doesn’t have lld built-in. (Not yet?)

Using the following example to test if lld is used. GNU-ld places some constraint on the order of archive files appear, but lld seems to be more tolerate on this (if I understand it correctly), so this example should build successfully, if lld is used. However, it fails on my box.

# one.c
extern int two();
int main(int argc, char *argv[])
{
    two();
    return 0;
}

# two.c
void two(){}

$ clang -c two.c; ar cr two.a two.o ; clang -c one.c ; clang two.a one.o
one.o: In function `main':
one.c:(.text+0x19): undefined reference to `two'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

If we use -v:

$ clang -c two.c; ar cr two.a two.o ; clang -c one.c ; clang -v two.a one.o
Ubuntu clang version 3.4-1ubuntu3 (tags/RELEASE_34/final) (based on LLVM 3.4)
Target: x86_64-pc-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/4.9
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/4.9.0
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8.2
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.9.0
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.9
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.9.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.8.2
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/4.9.0
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8
 "/usr/bin/ld" -z relro --hash-style=gnu --build-id --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crt1.o /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crti.o /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/crtbegin.o -L/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8 -L/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../.. -L/lib -L/usr/lib two.a one.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/crtend.o /usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/crtn.o
one.o: In function `main':
one.c:(.text+0x19): undefined reference to `two'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

ENV

Ubuntu clang version 3.4-1ubuntu3 (tags/RELEASE_34/final) (based on LLVM 3.4)
Target: x86_64-pc-linux-gnu
Thread model: posix

Asked By: Albert Netymk

||

Since January 2017, the LLVM apt repository includes lld, as do the snapshot packages available in Debian (starting with 4.0 in unstable, 5.0 in experimental). Since version 5, lld packages are available in Debian (lld-5.0 in stretch-backports, lld-6.0 in stretch-backports and Debian 10, lld-7 in Debian 9 and 10, lld-8 in buster-backports, and later packages in releases currently in preparation).

To install the upstream packages on Debian or Ubuntu, follow the instructions for your distribution.

Back in February 2015 when this answer was originally written, the LLVM apt repository stated that it included LLVM, Clang, compiler-rt, polly and LLDB. lld wasn’t included. Even the latest snapshot packages in Debian (which are maintained by the same team as the LLVM packages) didn’t include lld.

Answered By: Stephen Kitt

By the sounds of it, lld has not matched the maturity of Clang/LLVM yet, so it isn’t included in the main packages.

There is some confusion around the linkers in LLVM (I was quite confused myself). The rest of this answer (while not directly answering the original question) helps clear up the confusion to define what it is we are talking about! There are three that could be called linkers:

  1. llvm-ld – this sounds like it was both a linker for LLVM bitfiles and executable binary object files. However, the answer here (and provided links) suggest that lld was removed back in LLVM 3.2. At that point, there was no substitute linker, and the system ld linker would have to be used.
  2. llvm-link – this is the current linker for LLVM bitfiles.
  3. lld – this sounds like an actively developed replacement for ld that only links executable binary object files. This answer here suggests it was in active development in May 2014. It is listed in the main LLVM list of projects as #13. I’m guessing it can only get better over time, and mature to a point where it is viable to include in the main LLVM package as a replacement for GNU ld / gold.
Answered By: Jetski S-type

Using Ubuntu package search website shows one package is named “lld-4.0”. There are other packages probably containing lld, especially “lld-5.0” in the development branch of Ubuntu (artful.)

The package “lld-4.0” installs executables NOT named “lld”. For example it installs “lld-4.0”, a generic driver. Invoking it will tell you to invoke “ld.lld-4.0” on linux.

On Ubuntu, to test the package installed:

which ld.lld-4.0
ld.lld-4.0 --version
Answered By: bootchk
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.