[PATCH] D144084: [LLD] [COFF] Don't try to detect MSVC installations in mingw mode

Martin Storsjö via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 15 02:12:49 PST 2023


mstorsjo created this revision.
mstorsjo added reviewers: alvinhochun, mati865, hans, thakis, pkasting.
Herald added a project: All.
mstorsjo requested review of this revision.
Herald added a project: LLVM.

In mingw mode, all linker paths are passed explicitly to the linker
by the compiler driver. Don't try to implicitly add linker paths
from the LIB environment variable or by detecting an MSVC
installation directory.

If the /winsysroot command line parameter is explicitly passed to
lld-link while /lldmingw is specified, it could be considered reasonable
to actually include those paths. However, modifying the code to
handle only the /winsysroot case but not the other ones, when the
mingw mode has been enabled, seems like much more code complexity
for a mostly hypothetical case.

Add a test for this when case when using LIB. (The code paths for
trying to detect an MSVC installation aren't really regression tested.)

Also fix an issue in the existing test for "Check that when /winsysroot
is specified, %LIB% is ignored.", where the LIB variable pointed
to a nonexistent directory, so the test would pass even if /winsysroot
wouldn't be specified.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144084

Files:
  lld/COFF/Driver.cpp
  lld/test/COFF/winsysroot.test


Index: lld/test/COFF/winsysroot.test
===================================================================
--- lld/test/COFF/winsysroot.test
+++ lld/test/COFF/winsysroot.test
@@ -13,5 +13,9 @@
 # RUN:          /defaultlib:std64 /entry:main
 
 Check that when /winsysroot is specified, %LIB% is ignored.
-# RUN: env LIB=foo.dir/sysroot/VC/Tools/MSVC/1.1.1.1/lib/x86 not lld-link %t.obj /winsysroot:%t.dir/doesnotexist /defaultlib:std32 2>&1 | FileCheck -check-prefix=LIBIGNORED %s
+# RUN: env LIB=%t.dir/sysroot/VC/Tools/MSVC/1.1.1.1/lib/x86 not lld-link %t.obj /winsysroot:%t.dir/doesnotexist /defaultlib:std32 2>&1 | FileCheck -check-prefix=LIBIGNORED %s
 LIBIGNORED: could not open 'std32.lib'
+
+Check that when -lldmingw is specified, %LIB% is ignored.
+# RUN: env LIB=%t.dir/sysroot/VC/Tools/MSVC/1.1.1.1/lib/x86 not lld-link -lldmingw %t.obj /defaultlib:std32 -libpath:%t.dir/sysroot/VC/Tools/MSVC/1.1.1./lib/x86 2>&1 | FileCheck -check-prefix=LIBIGNORED_MINGW %s
+LIBIGNORED_MINGW: could not open 'libstd32.a'
Index: lld/COFF/Driver.cpp
===================================================================
--- lld/COFF/Driver.cpp
+++ lld/COFF/Driver.cpp
@@ -1509,9 +1509,14 @@
   searchPaths.emplace_back("");
   for (auto *arg : args.filtered(OPT_libpath))
     searchPaths.push_back(arg->getValue());
-  detectWinSysRoot(args);
-  if (!args.hasArg(OPT_lldignoreenv) && !args.hasArg(OPT_winsysroot))
-    addLibSearchPaths();
+  if (!config->mingw) {
+    // Don't automatically deduce the lib path from the environment or MSVC
+    // installations when operating in mingw mode. (This also makes LLD ignore
+    // winsysroot and vctoolsdir arguments.)
+    detectWinSysRoot(args);
+    if (!args.hasArg(OPT_lldignoreenv) && !args.hasArg(OPT_winsysroot))
+      addLibSearchPaths();
+  }
 
   // Handle /ignore
   for (auto *arg : args.filtered(OPT_ignore)) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144084.497597.patch
Type: text/x-patch
Size: 1866 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230215/78df6373/attachment.bin>


More information about the llvm-commits mailing list