[cfe-dev] LLD to be the default linker in Clang

Hans Wennborg via cfe-dev cfe-dev at lists.llvm.org
Fri Oct 28 09:41:16 PDT 2016


On Fri, Oct 28, 2016 at 9:17 AM, Renato Golin via cfe-dev
<cfe-dev at lists.llvm.org> wrote:
> I'm creating a bootstrap buildbot on AArch64 with LLD and I just
> realised the "accepted" way to make clang call lld is to "symlink lld
> -> ld". I understand that's how every Linux system "chooses" the
> linker, but that makes deployment and validation quite cumbersome on
> GNU systems.

There's also -fuse-ld=

That's how I usually do it.

> I'd like to suggest a change in behaviour:
>
> // Some flag like --linker=<full path / bin on path>
> if (LinkerFlag) {
>   linker = Flag (linker);
>
> // triple != host
> } else if (CROSS_COMPILE) {
>   if (LLDSupports(triple))
>     linker = Find (LLD);
>   if (!linker)
>     linker = Find (triple-ld);
>   if (!linker)
>     ERROR; // *NOT* the system linker!
>
> // triple = host
> } else {
>   linker = Find (LLD);
>   if (!linker)
>     linker = Find (SYSLD); // OS-specific
>   if (!linker)
>     ERROR; // We tried!
> }
>
>
>   Rationale
>
> My reason is that, if you just build Clang, with or without LLD,
> everything works out of the box as you expect: Former uses LLD, latter
> uses the system's linker. If LLD is able to cross-compile to the
> target triple, and it's available, try that. Cross compilers should
> never use the system linker, as that's just silly.
>
> However, if you didn't build Clang or LLD and still want to force the
> linker (cross when clang gets it wrong, lld installed somewhere else,
> some non-sysroot alternative, ld when you have built lld), you'll need
> a flag. It doesn't really matter if GCC will ever use LLD, but it
> would be good to have Clang be able to specify which linker to use.
>
> We already have library flags, and we don't need an assembler flag, so
> the linker seems like the last option missing.
>
>
>   Use Case
>
> For example, it's perfectly reasonable to have GCC and Clang on the
> same system and to have LD and LLD installed / accessible. It's also
> perfectly reasonable to have GCC using LD and Clang using LLD on the
> same system. Today, that's not possible without changing the path for
> Clang and not GCC (cumbersome, to say the least).
>
> The environment above is *exactly* that of any buildbot trying to
> bootstrap Clang+LLD using GCC+LD. Iwant to have at least one for
> AArch64 and one for ARM, but it would be good to have the same thing
> for x86_64, too at the very least.
>
> I don't know much about FreeBSD, but they're moving LLD as the
> official linker in multiple platforms and they still have GCC/LD in
> ports. There will probably be corner cases...
>
>
>   Conclusion
>
> I think LLD is mature enough to be preferred over LD on the platforms
> it support, if available.
>
> Since it's not available by default in most of them, its existence
> means intention.
>
> Once it becomes available, having it means you should really use it.
>
> Looks like a no-brainer to me. Am I missing something?
>
> cheers,
> --renato
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev



More information about the cfe-dev mailing list