[lld] 241c290 - Reland [LLD] [COFF] Don't try to detect MSVC installations in mingw mode
Martin Storsjö via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 21 12:54:17 PDT 2023
Author: Martin Storsjö
Date: 2023-10-21T22:36:11+03:00
New Revision: 241c290ad73f57ee12a6d1c3ee3fe38d79405c3a
URL: https://github.com/llvm/llvm-project/commit/241c290ad73f57ee12a6d1c3ee3fe38d79405c3a
DIFF: https://github.com/llvm/llvm-project/commit/241c290ad73f57ee12a6d1c3ee3fe38d79405c3a.diff
LOG: Reland [LLD] [COFF] Don't try to detect MSVC installations in mingw mode
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.
Reland this after https://github.com/llvm/llvm-project/pull/68077 and
https://github.com/llvm/llvm-project/pull/69781 - the compiler-rt test
that used -lldmingw in MSVC environments has been updated to use a more
specific option.
Differential Revision: https://reviews.llvm.org/D144084
Added:
Modified:
lld/COFF/Driver.cpp
lld/test/COFF/winsysroot.test
Removed:
################################################################################
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 1d9a7e498f151f0..5613c2e6993a5af 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -1588,13 +1588,25 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
{
llvm::TimeTraceScope timeScope2("Search paths");
searchPaths.emplace_back("");
- // Prefer the Clang provided builtins over the ones bundled with MSVC.
- addClangLibSearchPaths(argsArr[0]);
+ if (!config->mingw) {
+ // Prefer the Clang provided builtins over the ones bundled with MSVC.
+ // In MinGW mode, the compiler driver passes the necessary libpath
+ // options explicitly.
+ addClangLibSearchPaths(argsArr[0]);
+ }
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();
+ } else {
+ if (args.hasArg(OPT_vctoolsdir, OPT_winsysroot))
+ warn("ignoring /vctoolsdir or /winsysroot flags in MinGW mode");
+ }
}
// Handle /ignore
diff --git a/lld/test/COFF/winsysroot.test b/lld/test/COFF/winsysroot.test
index 29df204fa96e0f3..e29e6ca115c89dc 100644
--- a/lld/test/COFF/winsysroot.test
+++ b/lld/test/COFF/winsysroot.test
@@ -49,5 +49,12 @@ NO64: could not open 'std64.lib'
NO32: could not open 'std32.lib'
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 2>&1 | FileCheck -check-prefix=LIBIGNORED_MINGW %s
+LIBIGNORED_MINGW: could not open 'libstd32.a'
+
+# RUN: not lld-link -lldmingw %t.obj /defaultlib:std32 /winsysroot:%t.dir/sysroot 2>&1 | FileCheck -check-prefix=IGNORED_ARG %s
+IGNORED_ARG: warning: ignoring /vctoolsdir or /winsysroot flags in MinGW mode
More information about the llvm-commits
mailing list