This is an archive of the discontinued LLVM Phabricator instance.

Allow clang-cl to automatically use lld instead of forcing the MSVC linker
ClosedPublic

Authored by zturner on Nov 26 2014, 5:30 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

zturner updated this revision to Diff 16667.Nov 26 2014, 5:30 PM
zturner retitled this revision from to Allow clang-cl to automatically use lld instead of forcing the MSVC linker.
zturner updated this object.
zturner edited the test plan for this revision. (Show Details)
zturner added reviewers: rnk, ruiu.
zturner added a subscriber: Unknown Object (MLST).
ruiu added inline comments.Nov 26 2014, 5:34 PM
lib/Driver/Tools.cpp
7987 ↗(On Diff #16667)

Why don't you just pass "lld-link" (not "lld") to -fuse-ld option?

zturner added inline comments.Dec 1 2014, 9:38 AM
lib/Driver/Tools.cpp
7987 ↗(On Diff #16667)

Because there should be a consistent syntax for specifying "link with lld" regardless of which platform you're on. I don't want it to be -fuse-ld=lld on Linux, and -fuse-ld=lld-link on Windows, for example.

thakis added a subscriber: thakis.Dec 1 2014, 12:16 PM
thakis added inline comments.
lib/Driver/Tools.cpp
7990 ↗(On Diff #16667)

Somewhat tangential: It would be nice if clang could default to lld-link if link.exe isn't found. If I'm using clang-cl targeting Windows on non-Windows, and lld-link is in the same directory as clang-cl, it'd be great if clang-cl would then transparently use lld-link to link my PE binary instead of telling me "unable to execute command: Executable "link.exe" doesn't exist!"

(Not sure if this should be part of this change, but it's in the same code at least.)

ruiu added inline comments.Dec 1 2014, 12:39 PM
lib/Driver/Tools.cpp
7987 ↗(On Diff #16667)

Got it.

7990 ↗(On Diff #16667)

Besides the issue how to find libraries in the environment where link.exe doesn't exist, lld currently depends on a few external command. rc.exe (resource compiler) and lib.exe (ar command) are needed. In order to make such silent fallback work, we need to eliminate that dependency.

rnk edited edge metadata.Dec 1 2014, 1:53 PM

I'm kind of bummed that we have to special case lld, but I guess that's the spirit of the gcc flag anyway. This seems like the right direction.

lib/Driver/Tools.cpp
7982 ↗(On Diff #16667)

Clang code uses StudlyCaps for variable names. (Yaaay!)

7983 ↗(On Diff #16667)

There are some idioms that can make this code more concise. getLastArgValue() exists and takes a default value, and const char * converts implicitly to StringRef. This can probably be:

StringRef Linker = Args.getLastArgValue(options::OPT_fuse_ld_EQ, "link");
if (Linker.equals_lower("lld"))
  Linker = "lld-link";

if (Linker.equals_lower("link")) {
  ...
zturner updated this revision to Diff 16788.Dec 1 2014, 2:16 PM
zturner edited edge metadata.

Cleaned up the special casing code a little bit. Thanks for the suggestion, this is much cleaner.

rnk accepted this revision.Dec 1 2014, 2:29 PM
rnk edited edge metadata.

lgtm

This revision is now accepted and ready to land.Dec 1 2014, 2:29 PM
zturner closed this revision.Dec 1 2014, 3:07 PM
zturner updated this revision to Diff 16789.

Closed by commit rL223086 (authored by @zturner).