Skip to content

Commit 719f58c

Browse files
author
Zachary Turner
committedDec 1, 2014
Make -fuse-ld=lld work properly on Windows.
Using lld on Windows requires calling link-lld.exe instead of lld.exe. This patch puts this knowledge into clang so that when using the GCC style clang driver, it can properly delegate to lld. Differential Revision: http://reviews.llvm.org/D6428 Reviewed by: Reid Kleckner, Rui Ueyama llvm-svn: 223086
1 parent 0365f1a commit 719f58c

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed
 

‎clang/lib/Driver/MSVCToolChain.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ using namespace llvm::opt;
4343
MSVCToolChain::MSVCToolChain(const Driver &D, const llvm::Triple& Triple,
4444
const ArgList &Args)
4545
: ToolChain(D, Triple, Args) {
46+
getProgramPaths().push_back(getDriver().getInstalledDir());
47+
if (getDriver().getInstalledDir() != getDriver().Dir)
48+
getProgramPaths().push_back(getDriver().Dir);
4649
}
4750

4851
Tool *MSVCToolChain::buildLinker() const {

‎clang/lib/Driver/Tools.cpp

+20-4
Original file line numberDiff line numberDiff line change
@@ -7982,10 +7982,26 @@ void visualstudio::Link::ConstructJob(Compilation &C, const JobAction &JA,
79827982
A.renderAsInput(Args, CmdArgs);
79837983
}
79847984

7985-
// It's not sufficient to just use link from the program PATH, because other
7986-
// environments like GnuWin32 install their own link.exe which may come first.
7987-
llvm::SmallString<128> linkPath(FindVisualStudioExecutable(
7988-
getToolChain(), "link.exe", C.getDriver().getClangProgramPath()));
7985+
// We need to special case some linker paths. In the case of lld, we need to
7986+
// translate 'lld' into 'lld-link', and in the case of the regular msvc
7987+
// linker, we need to use a special search algorithm.
7988+
llvm::SmallString<128> linkPath;
7989+
StringRef Linker = Args.getLastArgValue(options::OPT_fuse_ld_EQ, "link");
7990+
if (Linker.equals_lower("lld"))
7991+
Linker = "lld-link";
7992+
7993+
if (Linker.equals_lower("link")) {
7994+
// If we're using the MSVC linker, it's not sufficient to just use link
7995+
// from the program PATH, because other environments like GnuWin32 install
7996+
// their own link.exe which may come first.
7997+
linkPath = FindVisualStudioExecutable(getToolChain(), "link.exe",
7998+
C.getDriver().getClangProgramPath());
7999+
} else {
8000+
linkPath = Linker;
8001+
llvm::sys::path::replace_extension(linkPath, "exe");
8002+
linkPath = getToolChain().GetProgramPath(linkPath.c_str());
8003+
}
8004+
79898005
const char *Exec = Args.MakeArgString(linkPath);
79908006
C.addCommand(llvm::make_unique<Command>(JA, *this, Exec, CmdArgs));
79918007
}

0 commit comments

Comments
 (0)
Please sign in to comment.