Index: tools/clang/lib/Driver/MinGWToolChain.cpp =================================================================== --- tools/clang/lib/Driver/MinGWToolChain.cpp +++ tools/clang/lib/Driver/MinGWToolChain.cpp @@ -137,18 +137,20 @@ if (DriverArgs.hasArg(options::OPT_nostdlibinc)) return; - llvm::SmallString<1024> IncludeDir(GccLibDir); - llvm::sys::path::append(IncludeDir, "include"); - addSystemInclude(DriverArgs, CC1Args, IncludeDir.c_str()); - IncludeDir += "-fixed"; + if (GetRuntimeLibType(DriverArgs) == ToolChain::RLT_Libgcc) { + llvm::SmallString<1024> IncludeDir(GccLibDir); + llvm::sys::path::append(IncludeDir, "include"); + addSystemInclude(DriverArgs, CC1Args, IncludeDir.c_str()); + IncludeDir += "-fixed"; #ifdef LLVM_ON_UNIX - // openSUSE - addSystemInclude(DriverArgs, CC1Args, - "/usr/x86_64-w64-mingw32/sys-root/mingw/include"); + // openSUSE + addSystemInclude(DriverArgs, CC1Args, + "/usr/x86_64-w64-mingw32/sys-root/mingw/include"); #endif - addSystemInclude(DriverArgs, CC1Args, IncludeDir.c_str()); - addSystemInclude(DriverArgs, CC1Args, Base + Arch + "include"); - addSystemInclude(DriverArgs, CC1Args, Base + "include"); + addSystemInclude(DriverArgs, CC1Args, IncludeDir.c_str()); + } + addSystemInclude(DriverArgs, CC1Args, Base + Arch + "include"); + addSystemInclude(DriverArgs, CC1Args, Base + "include"); } void MinGW::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, @@ -157,32 +159,42 @@ DriverArgs.hasArg(options::OPT_nostdincxx)) return; - // C++ includes locations are different with almost every mingw distribution. - // - // Windows - // ------- - // mingw-w64 mingw-builds: $sysroot/i686-w64-mingw32/include/c++ - // mingw-w64 msys2: $sysroot/include/c++/4.9.2 - // mingw.org: GccLibDir/include/c++ - // - // Linux - // ----- - // openSUSE: GccLibDir/include/c++ - // Arch: $sysroot/i686-w64-mingw32/include/c++/5.1.0 - // - llvm::SmallVector, 4> CppIncludeBases; - CppIncludeBases.emplace_back(Base); - llvm::sys::path::append(CppIncludeBases[0], Arch, "include", "c++"); - CppIncludeBases.emplace_back(Base); - llvm::sys::path::append(CppIncludeBases[1], Arch, "include", "c++", Ver); - CppIncludeBases.emplace_back(Base); - llvm::sys::path::append(CppIncludeBases[2], "include", "c++", Ver); - CppIncludeBases.emplace_back(GccLibDir); - llvm::sys::path::append(CppIncludeBases[3], "include", "c++"); - for (auto &CppIncludeBase : CppIncludeBases) { - CppIncludeBase += llvm::sys::path::get_separator(); - addSystemInclude(DriverArgs, CC1Args, CppIncludeBase); - addSystemInclude(DriverArgs, CC1Args, CppIncludeBase + Arch); - addSystemInclude(DriverArgs, CC1Args, CppIncludeBase + "backward"); + switch (GetCXXStdlibType(DriverArgs)) { + case ToolChain::CST_Libcxx: + addSystemInclude(DriverArgs, CC1Args, Base + "include" + + llvm::sys::path::get_separator() + "c++" + + llvm::sys::path::get_separator() + "v1"); + break; + + case ToolChain::CST_Libstdcxx: + // C++ includes locations are different with almost every mingw distribution. + // + // Windows + // ------- + // mingw-w64 mingw-builds: $sysroot/i686-w64-mingw32/include/c++ + // mingw-w64 msys2: $sysroot/include/c++/4.9.2 + // mingw.org: GccLibDir/include/c++ + // + // Linux + // ----- + // openSUSE: GccLibDir/include/c++ + // Arch: $sysroot/i686-w64-mingw32/include/c++/5.1.0 + // + llvm::SmallVector, 4> CppIncludeBases; + CppIncludeBases.emplace_back(Base); + llvm::sys::path::append(CppIncludeBases[0], Arch, "include", "c++"); + CppIncludeBases.emplace_back(Base); + llvm::sys::path::append(CppIncludeBases[1], Arch, "include", "c++", Ver); + CppIncludeBases.emplace_back(Base); + llvm::sys::path::append(CppIncludeBases[2], "include", "c++", Ver); + CppIncludeBases.emplace_back(GccLibDir); + llvm::sys::path::append(CppIncludeBases[3], "include", "c++"); + for (auto &CppIncludeBase : CppIncludeBases) { + CppIncludeBase += llvm::sys::path::get_separator(); + addSystemInclude(DriverArgs, CC1Args, CppIncludeBase); + addSystemInclude(DriverArgs, CC1Args, CppIncludeBase + Arch); + addSystemInclude(DriverArgs, CC1Args, CppIncludeBase + "backward"); + } + break; } } Index: tools/clang/lib/Driver/Tools.h =================================================================== --- tools/clang/lib/Driver/Tools.h +++ tools/clang/lib/Driver/Tools.h @@ -702,9 +702,6 @@ const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override; - -private: - void AddLibGCC(const llvm::opt::ArgList &Args, ArgStringList &CmdArgs) const; }; } // end namespace MinGW Index: tools/clang/lib/Driver/Tools.cpp =================================================================== --- tools/clang/lib/Driver/Tools.cpp +++ tools/clang/lib/Driver/Tools.cpp @@ -2248,8 +2248,7 @@ // Until ARM libraries are build separately, we have them all in one library static StringRef getArchNameForCompilerRTLib(const ToolChain &TC) { - if (TC.getTriple().isOSWindows() && - !TC.getTriple().isWindowsItaniumEnvironment() && + if (TC.getTriple().isWindowsMSVCEnvironment() && TC.getArch() == llvm::Triple::x86) return "i386"; if (TC.getArch() == llvm::Triple::arm || TC.getArch() == llvm::Triple::armeb) @@ -2275,10 +2274,12 @@ : ""; bool IsOSWindows = TC.getTriple().isOSWindows(); + bool IsITANMSVCWindows = TC.getTriple().isWindowsMSVCEnvironment() || + TC.getTriple().isWindowsItaniumEnvironment(); StringRef Arch = getArchNameForCompilerRTLib(TC); - const char *Prefix = IsOSWindows ? "" : "lib"; + const char *Prefix = IsITANMSVCWindows ? "" : "lib"; const char *Suffix = - Shared ? (IsOSWindows ? ".dll" : ".so") : (IsOSWindows ? ".lib" : ".a"); + Shared ? (IsOSWindows ? ".dll" : ".so") : (IsITANMSVCWindows ? ".lib" : ".a"); SmallString<128> Path = getCompilerRTLibDir(TC); llvm::sys::path::append(Path, Prefix + Twine("clang_rt.") + Component + "-" + @@ -2300,6 +2301,11 @@ if (TC.getDriver().CCCIsCXX()) CmdArgs.push_back("-lgcc_eh"); } + + if (TC.getTriple().isOSCygMing()) { + if (TC.getDriver().CCCIsCXX()) + CmdArgs.push_back("-lgcc_eh"); + } } static void addProfileRT(const ToolChain &TC, const ArgList &Args, @@ -7837,6 +7843,7 @@ static void AddLibgcc(const llvm::Triple &Triple, const Driver &D, ArgStringList &CmdArgs, const ArgList &Args) { bool isAndroid = Triple.getEnvironment() == llvm::Triple::Android; + bool isWindows = Triple.getOS() == llvm::Triple::Win32; bool StaticLibgcc = Args.hasArg(options::OPT_static_libgcc) || Args.hasArg(options::OPT_static); if (!D.CCCIsCXX()) @@ -7846,10 +7853,10 @@ if (D.CCCIsCXX()) CmdArgs.push_back("-lgcc"); } else { - if (!D.CCCIsCXX()) + if (!D.CCCIsCXX() && !isWindows) CmdArgs.push_back("--as-needed"); CmdArgs.push_back("-lgcc_s"); - if (!D.CCCIsCXX()) + if (!D.CCCIsCXX() && !isWindows) CmdArgs.push_back("--no-as-needed"); } @@ -8926,25 +8933,6 @@ SplitDebugName(Args, Inputs[0])); } -void MinGW::Linker::AddLibGCC(const ArgList &Args, - ArgStringList &CmdArgs) const { - if (Args.hasArg(options::OPT_mthreads)) - CmdArgs.push_back("-lmingwthrd"); - CmdArgs.push_back("-lmingw32"); - if (Args.hasArg(options::OPT_shared) || - Args.hasArg(options::OPT_shared_libgcc) || - !Args.hasArg(options::OPT_static_libgcc)) { - CmdArgs.push_back("-lgcc_s"); - CmdArgs.push_back("-lgcc"); - } else { - CmdArgs.push_back("-lgcc"); - CmdArgs.push_back("-lgcc_eh"); - } - CmdArgs.push_back("-lmoldname"); - CmdArgs.push_back("-lmingwex"); - CmdArgs.push_back("-lmsvcrt"); -} - void MinGW::Linker::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, @@ -9072,7 +9060,15 @@ if (Args.hasArg(options::OPT_fopenmp)) CmdArgs.push_back("-lgomp"); - AddLibGCC(Args, CmdArgs); + if (Args.hasArg(options::OPT_mthreads)) + CmdArgs.push_back("-lmingwthrd"); + CmdArgs.push_back("-lmingw32"); + + AddRunTimeLibs(TC, D, CmdArgs, Args); + + CmdArgs.push_back("-lmoldname"); + CmdArgs.push_back("-lmingwex"); + CmdArgs.push_back("-lmsvcrt"); if (Args.hasArg(options::OPT_pg)) CmdArgs.push_back("-lgmon"); @@ -9092,8 +9088,19 @@ if (Args.hasArg(options::OPT_static)) CmdArgs.push_back("--end-group"); - else if (!LinkerName.equals_lower("lld")) - AddLibGCC(Args, CmdArgs); + else if (!LinkerName.equals_lower("lld")) { + + if (Args.hasArg(options::OPT_mthreads)) + CmdArgs.push_back("-lmingwthrd"); + CmdArgs.push_back("-lmingw32"); + + AddRunTimeLibs(TC, D, CmdArgs, Args); + + CmdArgs.push_back("-lmoldname"); + CmdArgs.push_back("-lmingwex"); + CmdArgs.push_back("-lmsvcrt"); + + } } if (!Args.hasArg(options::OPT_nostartfiles)) {