From: Daniel Dunbar Date: Wed, 7 Dec 2011 23:03:15 +0000 (+0000) Subject: Driver: Add a --rtlib={compiler-rt,libgcc} argument which I plan to use to allow X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c24767c9dd869ba0e78c2d4c86d86ed24b8e401e;p=clang Driver: Add a --rtlib={compiler-rt,libgcc} argument which I plan to use to allow dual support for compiler-rt on Linux, during bringup. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146094 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticDriverKinds.td b/include/clang/Basic/DiagnosticDriverKinds.td index fdf1e4a539..943d54b206 100644 --- a/include/clang/Basic/DiagnosticDriverKinds.td +++ b/include/clang/Basic/DiagnosticDriverKinds.td @@ -18,6 +18,10 @@ def err_drv_unknown_stdin_type : Error< def err_drv_unknown_language : Error<"language not recognized: '%0'">; def err_drv_invalid_arch_name : Error< "invalid arch name '%0'">; +def err_drv_invalid_rtlib_name : Error< + "invalid runtime library name in argument '%0'">; +def err_drv_unsupported_rtlib_for_platform : Error< + "unsupported runtime library '%0' for platform '%1'">; def err_drv_invalid_stdlib_name : Error< "invalid library name in argument '%0'">; def err_drv_invalid_opt_with_multiple_archs : Error< diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td index 8cdf700943..41240273e0 100644 --- a/include/clang/Driver/Options.td +++ b/include/clang/Driver/Options.td @@ -679,6 +679,7 @@ def rewrite_objc : Flag<"-rewrite-objc">, Flags<[DriverOption]>, HelpText<"Rewrite Objective-C source to C++">; def rdynamic : Flag<"-rdynamic">; def rpath : Separate<"-rpath">, Flags<[LinkerInput]>; +def rtlib_EQ : Joined<"-rtlib=">; def r : Flag<"-r">; def save_temps : Flag<"-save-temps">, Flags<[DriverOption]>, HelpText<"Save intermediate compilation results">; @@ -851,6 +852,8 @@ def _relocatable_pch : Flag<"--relocatable-pch">, HelpText<"Build a relocatable precompiled header">; def _resource_EQ : Joined<"--resource=">, Alias; def _resource : Separate<"--resource">, Alias; +def _rtlib_EQ : Joined<"--rtlib=">, Alias; +def _rtlib : Separate<"--rtlib">, Alias; def _save_temps : Flag<"--save-temps">, Alias; def _serialize_diags : Separate<"--serialize-diagnostics">, Flags<[DriverOption]>, HelpText<"Serialize compiler diagnostics to a file">; diff --git a/include/clang/Driver/ToolChain.h b/include/clang/Driver/ToolChain.h index 75ee5741d4..56dbad7dd1 100644 --- a/include/clang/Driver/ToolChain.h +++ b/include/clang/Driver/ToolChain.h @@ -39,6 +39,11 @@ public: CST_Libstdcxx }; + enum RuntimeLibType { + RLT_CompilerRT, + RLT_Libgcc + }; + private: const HostInfo &Host; const llvm::Triple Triple; @@ -143,6 +148,11 @@ public: return 0; } + /// GetDefaultRuntimeLibType - Get the default runtime library variant to use. + virtual RuntimeLibType GetDefaultRuntimeLibType() const { + return ToolChain::RLT_Libgcc; + } + /// IsUnwindTablesDefault - Does this tool chain use -funwind-tables /// by default. virtual bool IsUnwindTablesDefault() const = 0; @@ -202,6 +212,10 @@ public: virtual void AddClangSystemIncludeArgs(const ArgList &DriverArgs, ArgStringList &CC1Args) const; + // GetRuntimeLibType - Determine the runtime library type to use with the + // given compilation arguments. + virtual RuntimeLibType GetRuntimeLibType(const ArgList &Args) const; + // GetCXXStdlibType - Determine the C++ standard library type to use with the // given compilation arguments. virtual CXXStdlibType GetCXXStdlibType(const ArgList &Args) const; diff --git a/lib/Driver/ToolChain.cpp b/lib/Driver/ToolChain.cpp index 9453848ec0..83c918ea64 100644 --- a/lib/Driver/ToolChain.cpp +++ b/lib/Driver/ToolChain.cpp @@ -216,6 +216,22 @@ void ToolChain::AddClangSystemIncludeArgs(const ArgList &DriverArgs, // Each toolchain should provide the appropriate include flags. } +ToolChain::RuntimeLibType ToolChain::GetRuntimeLibType( + const ArgList &Args) const +{ + if (Arg *A = Args.getLastArg(options::OPT_rtlib_EQ)) { + StringRef Value = A->getValue(Args); + if (Value == "compiler-rt") + return ToolChain::RLT_CompilerRT; + if (Value == "libgcc") + return ToolChain::RLT_Libgcc; + getDriver().Diag(diag::err_drv_invalid_rtlib_name) + << A->getAsString(Args); + } + + return GetDefaultRuntimeLibType(); +} + ToolChain::CXXStdlibType ToolChain::GetCXXStdlibType(const ArgList &Args) const{ if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { StringRef Value = A->getValue(Args); diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp index fa4cf41889..29559a6ae2 100644 --- a/lib/Driver/ToolChains.cpp +++ b/lib/Driver/ToolChains.cpp @@ -440,6 +440,16 @@ void DarwinClang::AddLinkRuntimeLib(const ArgList &Args, void DarwinClang::AddLinkRuntimeLibArgs(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(Args) << "darwin"; + return; + } + // Darwin doesn't support real static executables, don't link any runtime // libraries with -static. if (Args.hasArg(options::OPT_static)) diff --git a/lib/Driver/ToolChains.h b/lib/Driver/ToolChains.h index d150a97693..f3a26e6e11 100644 --- a/lib/Driver/ToolChains.h +++ b/lib/Driver/ToolChains.h @@ -347,6 +347,9 @@ public: (!isMacosxVersionLT(10, 6) || (!isMacosxVersionLT(10, 5) && !KernelOrKext)); } + virtual RuntimeLibType GetDefaultRuntimeLibType() const { + return ToolChain::RLT_CompilerRT; + } virtual const char *GetDefaultRelocationModel() const; virtual const char *GetForcedPicModel() const;