diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp --- a/lld/COFF/Driver.cpp +++ b/lld/COFF/Driver.cpp @@ -1509,9 +1509,17 @@ 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(); + } else { + if (args.hasArg(OPT_vctoolsdir, OPT_winsysroot)) + warn("ignoring /vctoolsdir or /winsysroot flags in MinGW mode"); + } // Handle /ignore for (auto *arg : args.filtered(OPT_ignore)) { diff --git a/lld/test/COFF/winsysroot.test b/lld/test/COFF/winsysroot.test --- a/lld/test/COFF/winsysroot.test +++ b/lld/test/COFF/winsysroot.test @@ -13,5 +13,12 @@ # 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 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