r358778 - [MSVC] If unable to find link.exe from a MSVC installation, look for link.exe next to cl.exe

Martin Storsjo via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 19 12:04:22 PDT 2019


Author: mstorsjo
Date: Fri Apr 19 12:04:22 2019
New Revision: 358778

URL: http://llvm.org/viewvc/llvm-project?rev=358778&view=rev
Log:
[MSVC] If unable to find link.exe from a MSVC installation, look for link.exe next to cl.exe

Previously, if the MSVC installation isn't detected properly, clang
will later just fail to execute link.exe.

This improves using clang in msvc mode on linux, where one intentionally
might not want to point clang to the MSVC installation itself (which
isn't executable as such), but where a link.exe named wine wrapper is
available in the path next to a cl.exe named wine wrapper.

Differential Revision: https://reviews.llvm.org/D60094

Modified:
    cfe/trunk/lib/Driver/ToolChains/MSVC.cpp

Modified: cfe/trunk/lib/Driver/ToolChains/MSVC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/MSVC.cpp?rev=358778&r1=358777&r2=358778&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/MSVC.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/MSVC.cpp Fri Apr 19 12:04:22 2019
@@ -488,8 +488,18 @@ void visualstudio::Linker::ConstructJob(
     // their own link.exe which may come first.
     linkPath = FindVisualStudioExecutable(TC, "link.exe");
 
-    if (!TC.FoundMSVCInstall() && !llvm::sys::fs::can_execute(linkPath))
-      C.getDriver().Diag(clang::diag::warn_drv_msvc_not_found);
+    if (!TC.FoundMSVCInstall() && !llvm::sys::fs::can_execute(linkPath)) {
+      llvm::SmallString<128> ClPath;
+      ClPath = TC.GetProgramPath("cl.exe");
+      if (llvm::sys::fs::can_execute(ClPath)) {
+        linkPath = llvm::sys::path::parent_path(ClPath);
+        llvm::sys::path::append(linkPath, "link.exe");
+        if (!llvm::sys::fs::can_execute(linkPath))
+          C.getDriver().Diag(clang::diag::warn_drv_msvc_not_found);
+      } else {
+        C.getDriver().Diag(clang::diag::warn_drv_msvc_not_found);
+      }
+    }
 
 #ifdef _WIN32
     // When cross-compiling with VS2017 or newer, link.exe expects to have




More information about the cfe-commits mailing list