Index: lib/Driver/ToolChains/MinGW.h =================================================================== --- lib/Driver/ToolChains/MinGW.h +++ lib/Driver/ToolChains/MinGW.h @@ -96,6 +96,7 @@ mutable std::unique_ptr Compiler; void findGccLibDir(); llvm::ErrorOr findGcc(); + llvm::ErrorOr findClangRelativeSysroot(); }; } // end namespace toolchains Index: lib/Driver/ToolChains/MinGW.cpp =================================================================== --- lib/Driver/ToolChains/MinGW.cpp +++ lib/Driver/ToolChains/MinGW.cpp @@ -275,7 +275,8 @@ Archs.emplace_back(getTriple().getArchName()); Archs[0] += "-w64-mingw32"; Archs.emplace_back("mingw32"); - Arch = Archs[0].str(); + if (Arch.empty()) + Arch = Archs[0].str(); // lib: Arch Linux, Ubuntu, Windows // lib64: openSUSE Linux for (StringRef CandidateLib : {"lib", "lib64"}) { @@ -302,6 +303,23 @@ return make_error_code(std::errc::no_such_file_or_directory); } +llvm::ErrorOr toolchains::MinGW::findClangRelativeSysroot() { + llvm::SmallVector, 2> Subdirs; + Subdirs.emplace_back(getTriple().str()); + Subdirs.emplace_back(getTriple().getArchName()); + Subdirs[1] += "-w64-mingw32"; + Twine ClangRoot = llvm::sys::path::parent_path(getDriver().getInstalledDir()) + + llvm::sys::path::get_separator(); + for (StringRef CandidateSubdir : Subdirs) { + Twine Subdir = ClangRoot + CandidateSubdir; + if (llvm::sys::fs::is_directory(Subdir)) { + Arch = CandidateSubdir; + return Subdir.str(); + } + } + return make_error_code(std::errc::no_such_file_or_directory); +} + toolchains::MinGW::MinGW(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) : ToolChain(D, Triple, Args), CudaInstallation(D, Triple, Args) { @@ -309,6 +327,10 @@ if (getDriver().SysRoot.size()) Base = getDriver().SysRoot; + // Look for /../; if found, use /.. as the + // base as it could still be a base for a gcc setup with libgcc. + else if (llvm::ErrorOr TargetSubdir = findClangRelativeSysroot()) + Base = llvm::sys::path::parent_path(TargetSubdir.get()); else if (llvm::ErrorOr GPPName = findGcc()) Base = llvm::sys::path::parent_path( llvm::sys::path::parent_path(GPPName.get()));