r242905 - [mingw] Add support for -rtlib option and -stdlib option to the mingw driver
Reid Kleckner
reid at kleckner.net
Wed Jul 22 09:01:39 PDT 2015
Author: rnk
Date: Wed Jul 22 11:01:38 2015
New Revision: 242905
URL: http://llvm.org/viewvc/llvm-project?rev=242905&view=rev
Log:
[mingw] Add support for -rtlib option and -stdlib option to the mingw driver
Now clang should be able to use compiler-rt and libc++ on mingw.
Based on a patch by Martell Malone.
Differential Revision: http://reviews.llvm.org/D11237
Modified:
cfe/trunk/lib/Driver/MinGWToolChain.cpp
cfe/trunk/lib/Driver/Tools.cpp
Modified: cfe/trunk/lib/Driver/MinGWToolChain.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/MinGWToolChain.cpp?rev=242905&r1=242904&r2=242905&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/MinGWToolChain.cpp (original)
+++ cfe/trunk/lib/Driver/MinGWToolChain.cpp Wed Jul 22 11:01:38 2015
@@ -192,16 +192,18 @@ void MinGW::AddClangSystemIncludeArgs(co
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, IncludeDir.c_str());
+ }
addSystemInclude(DriverArgs, CC1Args, Base + Arch + "include");
addSystemInclude(DriverArgs, CC1Args, Base + "include");
}
@@ -212,19 +214,29 @@ void MinGW::AddClangCXXStdlibIncludeArgs
DriverArgs.hasArg(options::OPT_nostdincxx))
return;
- llvm::SmallVector<llvm::SmallString<1024>, 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:
+ llvm::SmallVector<llvm::SmallString<1024>, 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;
}
}
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=242905&r1=242904&r2=242905&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Wed Jul 22 11:01:38 2015
@@ -2247,8 +2247,7 @@ static void CollectArgsForIntegratedAsse
// 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)
@@ -2274,10 +2273,12 @@ SmallString<128> tools::getCompilerRT(co
: "";
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 + "-" +
@@ -7840,6 +7841,7 @@ void gnutools::Assembler::ConstructJob(C
static void AddLibgcc(const llvm::Triple &Triple, const Driver &D,
ArgStringList &CmdArgs, const ArgList &Args) {
bool isAndroid = Triple.getEnvironment() == llvm::Triple::Android;
+ bool isCygMing = Triple.isOSCygMing();
bool StaticLibgcc = Args.hasArg(options::OPT_static_libgcc) ||
Args.hasArg(options::OPT_static);
if (!D.CCCIsCXX())
@@ -7849,10 +7851,10 @@ static void AddLibgcc(const llvm::Triple
if (D.CCCIsCXX())
CmdArgs.push_back("-lgcc");
} else {
- if (!D.CCCIsCXX())
+ if (!D.CCCIsCXX() && !isCygMing)
CmdArgs.push_back("--as-needed");
CmdArgs.push_back("-lgcc_s");
- if (!D.CCCIsCXX())
+ if (!D.CCCIsCXX() && !isCygMing)
CmdArgs.push_back("--no-as-needed");
}
@@ -8934,15 +8936,10 @@ void MinGW::Linker::AddLibGCC(const ArgL
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");
- }
+
+ // Add libgcc or compiler-rt.
+ AddRunTimeLibs(getToolChain(), getToolChain().getDriver(), CmdArgs, Args);
+
CmdArgs.push_back("-lmoldname");
CmdArgs.push_back("-lmingwex");
CmdArgs.push_back("-lmsvcrt");
More information about the cfe-commits
mailing list