[PATCH] D22663: Support setting default value for -rtlib at build time
Lei Zhang via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 21 20:02:45 PDT 2016
zlei created this revision.
zlei added reviewers: cfe-commits, ddunbar, Hahnfeld.
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).
https://reviews.llvm.org/D22663
Files:
CMakeLists.txt
include/clang/Config/config.h.cmake
lib/Driver/ToolChain.cpp
Index: lib/Driver/ToolChain.cpp
===================================================================
--- lib/Driver/ToolChain.cpp
+++ lib/Driver/ToolChain.cpp
@@ -526,16 +526,16 @@
ToolChain::RuntimeLibType ToolChain::GetRuntimeLibType(
const ArgList &Args) const {
- if (Arg *A = Args.getLastArg(options::OPT_rtlib_EQ)) {
- StringRef Value = A->getValue();
- 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);
- }
+ const Arg* A = Args.getLastArg(options::OPT_rtlib_EQ);
+ StringRef LibName = A ? A->getValue() : CLANG_DEFAULT_RTLIB;
+ if (LibName == "compiler-rt")
+ return ToolChain::RLT_CompilerRT;
+ if (LibName == "libgcc")
+ return ToolChain::RLT_Libgcc;
+ if (A)
+ getDriver().Diag(diag::err_drv_invalid_rtlib_name) << A->getAsString(Args);
+
return GetDefaultRuntimeLibType();
}
Index: include/clang/Config/config.h.cmake
===================================================================
--- include/clang/Config/config.h.cmake
+++ include/clang/Config/config.h.cmake
@@ -11,6 +11,9 @@
/* Default C++ stdlib to use. */
#define CLANG_DEFAULT_CXX_STDLIB "${CLANG_DEFAULT_CXX_STDLIB}"
+/* Default runtime library to use. */
+#define CLANG_DEFAULT_RTLIB "${CLANG_DEFAULT_RTLIB}"
+
/* Default OpenMP runtime used by -fopenmp. */
#define CLANG_DEFAULT_OPENMP_RUNTIME "${CLANG_DEFAULT_OPENMP_RUNTIME}"
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -201,6 +201,15 @@
set(CLANG_DEFAULT_CXX_STDLIB "")
endif()
+set(CLANG_DEFAULT_RTLIB "" CACHE STRING
+ "Default runtime library to use (libgcc or compiler-rt)")
+if (NOT(CLANG_DEFAULT_RTLIB STREQUAL "" OR
+ CLANG_DEFAULT_RTLIB STREQUAL "libgcc" OR
+ CLANG_DEFAULT_RTLIB STREQUAL "compiler-rt"))
+ message(WARNING "Resetting default rtlib to use platform default")
+ set(CLANG_DEFAULT_RTLIB "")
+endif()
+
set(CLANG_DEFAULT_OPENMP_RUNTIME "libomp" CACHE STRING
"Default OpenMP runtime used by -fopenmp.")
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22663.65016.patch
Type: text/x-patch
Size: 2185 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160722/baa802c3/attachment.bin>
More information about the cfe-commits
mailing list