Skip to content

Commit 241c290

Browse files
committed
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 #68077 and #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
1 parent ba87fba commit 241c290

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

lld/COFF/Driver.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,13 +1588,25 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
15881588
{
15891589
llvm::TimeTraceScope timeScope2("Search paths");
15901590
searchPaths.emplace_back("");
1591-
// Prefer the Clang provided builtins over the ones bundled with MSVC.
1592-
addClangLibSearchPaths(argsArr[0]);
1591+
if (!config->mingw) {
1592+
// Prefer the Clang provided builtins over the ones bundled with MSVC.
1593+
// In MinGW mode, the compiler driver passes the necessary libpath
1594+
// options explicitly.
1595+
addClangLibSearchPaths(argsArr[0]);
1596+
}
15931597
for (auto *arg : args.filtered(OPT_libpath))
15941598
searchPaths.push_back(arg->getValue());
1595-
detectWinSysRoot(args);
1596-
if (!args.hasArg(OPT_lldignoreenv) && !args.hasArg(OPT_winsysroot))
1597-
addLibSearchPaths();
1599+
if (!config->mingw) {
1600+
// Don't automatically deduce the lib path from the environment or MSVC
1601+
// installations when operating in mingw mode. (This also makes LLD ignore
1602+
// winsysroot and vctoolsdir arguments.)
1603+
detectWinSysRoot(args);
1604+
if (!args.hasArg(OPT_lldignoreenv) && !args.hasArg(OPT_winsysroot))
1605+
addLibSearchPaths();
1606+
} else {
1607+
if (args.hasArg(OPT_vctoolsdir, OPT_winsysroot))
1608+
warn("ignoring /vctoolsdir or /winsysroot flags in MinGW mode");
1609+
}
15981610
}
15991611

16001612
// Handle /ignore

lld/test/COFF/winsysroot.test

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,12 @@ NO64: could not open 'std64.lib'
4949
NO32: could not open 'std32.lib'
5050

5151
Check that when /winsysroot is specified, %LIB% is ignored.
52-
# 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
52+
# 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
5353
LIBIGNORED: could not open 'std32.lib'
54+
55+
Check that when -lldmingw is specified, %LIB% is ignored.
56+
# 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
57+
LIBIGNORED_MINGW: could not open 'libstd32.a'
58+
59+
# RUN: not lld-link -lldmingw %t.obj /defaultlib:std32 /winsysroot:%t.dir/sysroot 2>&1 | FileCheck -check-prefix=IGNORED_ARG %s
60+
IGNORED_ARG: warning: ignoring /vctoolsdir or /winsysroot flags in MinGW mode

0 commit comments

Comments
 (0)