Unable to use LLD?

Hello. I have installed Clang and LLD v9
(9~svn355950-1~exp1+0~20190312185014.855~1.gbp505100 to be precise)
from the Apt packages on Kubuntu Bionic LTS with latest updates.

This is the first time I am trying to use LLD. The installed binary
path is /usr/bin/ld.lld-9 and it is accessible as just ‘ld.lld-9’ from
the command line.

So with the following hello.c:

#include <stdio.h>
int main() { printf("Hello!\n"); }

This is what happens:

$ clang-9 -fuse-ld=ld.lld-9 -o hello hello.c
clang: error: invalid linker name in argument '-fuse-ld=ld.lld-9'

Please indicate what I am doing wrong?!

Curiously:

$ clang-9 -fuse-ld=lld -o hello hello.c
$ ./hello
Hello!
$ readelf --string-dump .comment hello
String dump of section '.comment':
  [ 0] Linker: LLD 9.0.0

Why is it a problem if I give the explicit linker with version? I had
rather suspected that it would use some other default lld on my system
which is why I was hypercorrecting…

> $ clang-9 -fuse-ld=ld.lld-9 -o hello hello.c
> clang: error: invalid linker name in argument '-fuse-ld=ld.lld-9'

Curiously:

$ clang-9 -fuse-ld=lld -o hello hello.c
$ ./hello
Hello!
$ readelf --string-dump .comment hello
String dump of section '.comment':
  [ 0] Linker: LLD 9.0.0

Why is it a problem if I give the explicit linker with version? I had
rather suspected that it would use some other default lld on my system
which is why I was hypercorrecting…

The -fuse-ld=<linker> accepts three forms, the first is one of the
recognised linkers lld, gold and bfd. The driver prefixes this with
"ld." to make ld.lld, ld.gold and ld.bfd. The second form is the
absolute path to the linker, the third is ld (the default system
linker). In your case I think the driver did not interpret ld.lld-9 as
an absolute path.

It is an open question as to whether clang-9 should actually look for
a matching ld.lld-9 rather than ld.lld . There is always the
possibility that this will break someones expectations though. See
https://bugs.llvm.org/show_bug.cgi?id=40659 for an example of ld.lld
matching something other than a symlink to ld.lld-9.

Peter

Unless this has changed since I last looked at the code, we don't special case any of the known linkers. We simply look for ld.{argument name} in the search paths (either $PATH or something specified with -B). -fuse-ld=lld9.0 will find ld.lld9.0. -fuse-ld=magicld92 will find lld.magicld92.

David

Thanks all for your reply.

FWIW I think the current behaviour of automatically choosing the lld
version is correct and simplest and it was I who unneededly
complicated the experience by trying to specify the lld version.

Now I tried installing parallelly both clang+lld 8 and 9 from the
bionic repos, and was pleased to note that by just giving -fuse-ld=lld
clang-8 selects lld-8 and clang-9 selects lld-9. This is the most
natural and expected behaviour and I sincerely request to retain this.
If anyone wants another linker to be used then they should specify
using full path as you have mentioned.

Session transcript:

$ clang-8 -fuse-ld=lld -Wall -Wextra -o hello.8.elf hello.c
$ clang-9 -fuse-ld=lld -Wall -Wextra -o hello.9.elf hello.c
$ alias elfcomment='readelf --string-dump .comment'
$ elfcomment hello.8.elf

String dump of section '.comment':
  [ 0] Linker: LLD 8.0.0
  [ 12] clang version 8.0.0-svn356034-1~exp1~20190313093039.54
(branches/release_80)
  [ 5f] GCC: (Ubuntu 8.2.0-1ubuntu2~18.04) 8.2.0

$ elfcomment hello.9.elf

String dump of section '.comment':
  [ 0] clang version
9.0.0-svn356096-1~exp1+0~20190313201923.857~1.gbp505100 (trunk)
  [ 4e] Linker: LLD 9.0.0
  [ 60] GCC: (Ubuntu 8.2.0-1ubuntu2~18.04) 8.2.0

Shriramana Sharma.