4

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

3

Since January 2017, the LLVM apt repository includes lld, as do the the snapshot packages available in Debian (4.0 in unstable, 5.0 in experimental). Presumably the release packages for 4.0 and 5.0 will include ldd.

To install the upstream packages on Debian or Ubuntu, follow the instructions for your distribution. (Readers tracking Debian unstable can simply install lld-4.0 from the Debian repositories.)

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.

1

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.
  • Thanks for the link. However, I get the feeling that llvm-ld, which has been superseded by llvm-link, is different from lld. The former is bitcode linker, but the later works on object files (.o and .a). – Albert Netymk Jul 30 '15 at 12:12
  • Wait... I was assuming lld and llvm-ld were the same thing. Yes, llvm-link is for LLVM bitcode only, and is included in my 3.6 installation. The llvm-ld page says: "The llvm-ld tools attempts to mimic the interface provided by the default system linker so that it can act as a drop-in replacement." Which sounds like it outputs both LLVM bitcode (like llvm-link) as well as executable programs (like the system linker). This question is old, but suggests there is no binary executable linker: stackoverflow.com/questions/13528474/… – Jetski S-type Jul 31 '15 at 0:26
  • Quoting from their home page: lld "Reads standard Object Files (e.g. ELF, Mach-O, PE/COFF)" and "Writes standard Executable Files (e.g. ELF, Mach-O, PE)", while llvm-link " takes several LLVM bitcode files and links them together into a single LLVM bitcode file". Therefore, the two don't work on the same level. Possibly lld invokes llvm-link behind the sence. – Albert Netymk Jul 31 '15 at 19:58
  • This is a bit confusing to have three linkers in LLVM, and it's not easy to see what's what, except that llvm-link is current and for LLVM bitcode. llvm-ld sounds like a mix of llvm-link and lld (system linker), as I said before. We also know that in Nov 2012, there was no system linker in LLVM: stackoverflow.com/questions/13528474/… (it uses the word 'yet'). I wonder when lld came along. LLVM documentation could be improved to help clear up such confusions! – Jetski S-type Aug 3 '15 at 0:11
  • lld looks like an actively developed project, so it is likely to have arisen after llvm-ld got removed. This answer from May 2014 uses future tense to imply future development for lld: stackoverflow.com/questions/23657132/… – Jetski S-type Aug 3 '15 at 4:47
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.