From d196fa524fa483a6195f6f079b0ee82dba03db1f Mon Sep 17 00:00:00 2001 From: Jonas Hahnfeld Date: Wed, 27 Jul 2016 08:15:54 +0000 Subject: Support setting default value for -rtlib at build time This patch introduces a new cmake variable: CLANG_DEFAULT_RTLIB, thru which we can specify a default value for -rtlib (libgcc or compiler-rt) at build time, just like how we set the default C++ stdlib thru CLANG_DEFAULT_CXX_STDLIB. With these two options, we can configure clang to build binaries on Linux that have no runtime dependence on any gcc libs (libstdc++ or libgcc_s). Patch by Lei Zhang! Differential Revision: https://reviews.llvm.org/D22663 llvm-svn: 276848 --- clang/lib/Driver/ToolChains.cpp | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'clang/lib/Driver/ToolChains.cpp') diff --git a/clang/lib/Driver/ToolChains.cpp b/clang/lib/Driver/ToolChains.cpp index f05261aef30..610285e1f40 100644 --- a/clang/lib/Driver/ToolChains.cpp +++ b/clang/lib/Driver/ToolChains.cpp @@ -403,18 +403,23 @@ void DarwinClang::AddLinkSanitizerLibArgs(const ArgList &Args, /*AddRPath*/ true); } +ToolChain::RuntimeLibType DarwinClang::GetRuntimeLibType( + const ArgList &Args) const { + if (Arg* A = Args.getLastArg(options::OPT_rtlib_EQ)) { + StringRef Value = A->getValue(); + if (Value != "compiler-rt") + getDriver().Diag(diag::err_drv_unsupported_rtlib_for_platform) + << Value << "darwin"; + } + + return ToolChain::RLT_CompilerRT; +} + void DarwinClang::AddLinkRuntimeLibArgs(const llvm::Triple &EffectiveTriple, const ArgList &Args, ArgStringList &CmdArgs) const { - // Darwin only supports the compiler-rt based runtime libraries. - switch (GetRuntimeLibType(Args)) { - case ToolChain::RLT_CompilerRT: - break; - default: - getDriver().Diag(diag::err_drv_unsupported_rtlib_for_platform) - << Args.getLastArg(options::OPT_rtlib_EQ)->getValue() << "darwin"; - return; - } + // Call once to ensure diagnostic is printed if wrong value was specified + GetRuntimeLibType(Args); // Darwin doesn't support real static executables, don't link any runtime // libraries with -static. -- cgit v1.2.3