[cfe-dev] Small patches to allow fully independent clang/llvm/compiler-rt/libc++
C Bergström via cfe-dev
cfe-dev at lists.llvm.org
Wed Oct 14 03:56:10 PDT 2015
I've sent these patches to some people privately to get their feedback
and now feel it's time to get a broader review.
#1 I really apologize if this stirs things up like the other libc++
thread (somewhat related)
----------
I don't know if this approach is acceptable to upstream, but I'd like
to build "pure" clang packages without any system GNU dependency.
These patches allow that by making it a compile time option, but
shouldn't impact any current defaults.
I'm willing to do any additional work which may be required to get
these upstream.
Thanks
-------------- next part --------------
diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp
index 93e6db8..bd4cf64 100644
--- a/lib/Driver/ToolChains.cpp
+++ b/lib/Driver/ToolChains.cpp
@@ -2989,6 +2989,25 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
const std::string OSLibDir = getOSLibDir(Triple, Args);
const std::string MultiarchTriple = getMultiarchTriple(Triple, SysRoot);
+ // Similar to the logic for GCC above, if we currently running Clang inside
+ // of the requested system root, add its parent library paths to
+ // those searched.
+ // FIXME: It's not clear whether we should use the driver's installed
+ // directory ('Dir' below) or the ResourceDir.
+ if (StringRef(D.Dir).startswith(SysRoot)) {
+ path_list RPaths;
+ addPathIfExists(D.Dir + "/../lib/" + MultiarchTriple, RPaths);
+ addPathIfExists(D.Dir + "/../" + OSLibDir, RPaths);
+ addPathIfExists(D.Dir + "/../lib", RPaths);
+
+ for (const auto &Path : RPaths)
+ Paths.push_back(Path);
+
+ // Add -rpath to installation lib dirs
+ for (const auto &Path : RPaths)
+ ExtraOpts.push_back("-rpath=" + Path);
+ }
+
// Add the multilib suffixed paths where they are available.
if (GCCInstallation.isValid()) {
const llvm::Triple &GCCTriple = GCCInstallation.getTriple();
@@ -3038,16 +3057,6 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
}
}
- // Similar to the logic for GCC above, if we currently running Clang inside
- // of the requested system root, add its parent library paths to
- // those searched.
- // FIXME: It's not clear whether we should use the driver's installed
- // directory ('Dir' below) or the ResourceDir.
- if (StringRef(D.Dir).startswith(SysRoot)) {
- addPathIfExists(D.Dir + "/../lib/" + MultiarchTriple, Paths);
- addPathIfExists(D.Dir + "/../" + OSLibDir, Paths);
- }
-
addPathIfExists(SysRoot + "/lib/" + MultiarchTriple, Paths);
addPathIfExists(SysRoot + "/lib/../" + OSLibDir, Paths);
addPathIfExists(SysRoot + "/usr/lib/" + MultiarchTriple, Paths);
@@ -3080,14 +3089,6 @@ Linux::Linux(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
addPathIfExists(LibPath, Paths);
}
- // Similar to the logic for GCC above, if we are currently running Clang
- // inside of the requested system root, add its parent library path to those
- // searched.
- // FIXME: It's not clear whether we should use the driver's installed
- // directory ('Dir' below) or the ResourceDir.
- if (StringRef(D.Dir).startswith(SysRoot))
- addPathIfExists(D.Dir + "/../lib", Paths);
-
addPathIfExists(SysRoot + "/lib", Paths);
addPathIfExists(SysRoot + "/usr/lib", Paths);
}
-------------- next part --------------
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 75b8075..264cdef 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -414,6 +414,9 @@ install(DIRECTORY include/clang-c
add_definitions( -D_GNU_SOURCE )
+set(CLANG_CXX_ABI "${CLANG_CXX_ABI}" CACHE STRING
+ "Specify C++ ABI library to use" FORCE)
+
option(CLANG_ENABLE_ARCMT "Build ARCMT." ON)
if (CLANG_ENABLE_ARCMT)
set(ENABLE_CLANG_ARCMT "1")
diff --git a/lib/Driver/CMakeLists.txt b/lib/Driver/CMakeLists.txt
index 412840b..4c7f4ca 100644
--- a/lib/Driver/CMakeLists.txt
+++ b/lib/Driver/CMakeLists.txt
@@ -3,6 +3,11 @@ set(LLVM_LINK_COMPONENTS
Support
)
+
+if("${CLANG_CXX_ABI}" STREQUAL "libcxxrt")
+ add_definitions(-DCLANG_CXX_ABI_LIBCXXRT)
+endif()
+
add_clang_library(clangDriver
Action.cpp
Compilation.cpp
diff --git a/lib/Driver/ToolChain.cpp b/lib/Driver/ToolChain.cpp
index 5feeda4..3046af3 100644
--- a/lib/Driver/ToolChain.cpp
+++ b/lib/Driver/ToolChain.cpp
@@ -445,6 +445,11 @@ void ToolChain::AddCXXStdlibLibArgs(const ArgList &Args,
switch (Type) {
case ToolChain::CST_Libcxx:
CmdArgs.push_back("-lc++");
+
+#ifdef CLANG_CXX_ABI_LIBCXXRT
+ CmdArgs.push_back("-lcxxrt");
+#endif // CLANG_CXX_ABI_LIBCXXRT
+
break;
case ToolChain::CST_Libstdcxx:
-------------- next part --------------
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 264cdef..dbddbce 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -417,6 +417,12 @@ add_definitions( -D_GNU_SOURCE )
set(CLANG_CXX_ABI "${CLANG_CXX_ABI}" CACHE STRING
"Specify C++ ABI library to use" FORCE)
+if("${CLANG_DEFAULT_CXX_STDLIB}" STREQUAL "")
+ set(CLANG_DEFAULT_CXX_STDLIB "libstdc++")
+endif()
+set(CLANG_DEFAULT_CXX_STDLIB "${CLANG_DEFAULT_CXX_STDLIB}" CACHE STRING
+ "Specify default C++ standard library" FORCE)
+
option(CLANG_ENABLE_ARCMT "Build ARCMT." ON)
if (CLANG_ENABLE_ARCMT)
set(ENABLE_CLANG_ARCMT "1")
diff --git a/lib/Driver/CMakeLists.txt b/lib/Driver/CMakeLists.txt
index 4c7f4ca..4de7778 100644
--- a/lib/Driver/CMakeLists.txt
+++ b/lib/Driver/CMakeLists.txt
@@ -8,6 +8,12 @@ if("${CLANG_CXX_ABI}" STREQUAL "libcxxrt")
add_definitions(-DCLANG_CXX_ABI_LIBCXXRT)
endif()
+if("${CLANG_DEFAULT_CXX_STDLIB}" STREQUAL "libc++")
+ add_definitions(-DCLANG_DEFAULT_CXX_STDLIB_LIBCXX)
+elseif("${CLANG_DEFAULT_CXX_STDLIB}" STREQUAL "libstdc++")
+ add_definitions(-DCLANG_DEFAULT_CXX_STDLIB_LIBSTDCXX)
+endif()
+
add_clang_library(clangDriver
Action.cpp
Compilation.cpp
diff --git a/lib/Driver/ToolChain.cpp b/lib/Driver/ToolChain.cpp
index 3046af3..33abe0d 100644
--- a/lib/Driver/ToolChain.cpp
+++ b/lib/Driver/ToolChain.cpp
@@ -380,7 +380,11 @@ ToolChain::CXXStdlibType ToolChain::GetCXXStdlibType(const ArgList &Args) const{
<< A->getAsString(Args);
}
+#if defined(CLANG_DEFAULT_CXX_STDLIB_LIBCXX)
+ return ToolChain::CST_Libcxx;
+#elif defined(CLANG_DEFAULT_CXX_STDLIB_LIBSTDCXX)
return ToolChain::CST_Libstdcxx;
+#endif // defined(CLANG_DEFAULT_CXX_STDLIB_LIBSTDCXX)
}
/// \brief Utility function to add a system include directory to CC1 arguments.
-------------- next part --------------
diff --git a/CMakeLists.txt b/CMakeLists.txt
index dbddbce..0c5045f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -414,6 +414,12 @@ install(DIRECTORY include/clang-c
add_definitions( -D_GNU_SOURCE )
+if("${CLANG_DEFAULT_RTLIB}" STREQUAL "")
+ set(CLANG_DEFAULT_RTLIB "libgcc")
+endif()
+set(CLANG_DEFAULT_RTLIB "${CLANG_DEFAULT_RTLIB}" CACHE STRING
+ "Specify default C runtime library" FORCE)
+
set(CLANG_CXX_ABI "${CLANG_CXX_ABI}" CACHE STRING
"Specify C++ ABI library to use" FORCE)
diff --git a/include/clang/Driver/ToolChain.h b/include/clang/Driver/ToolChain.h
index 560df19..39aff50 100644
--- a/include/clang/Driver/ToolChain.h
+++ b/include/clang/Driver/ToolChain.h
@@ -228,9 +228,7 @@ class ToolChain {
}
/// GetDefaultRuntimeLibType - Get the default runtime library variant to use.
- virtual RuntimeLibType GetDefaultRuntimeLibType() const {
- return ToolChain::RLT_Libgcc;
- }
+ virtual RuntimeLibType GetDefaultRuntimeLibType() const;
/// IsUnwindTablesDefault - Does this tool chain use -funwind-tables
/// by default.
diff --git a/lib/Driver/CMakeLists.txt b/lib/Driver/CMakeLists.txt
index 4de7778..a864201 100644
--- a/lib/Driver/CMakeLists.txt
+++ b/lib/Driver/CMakeLists.txt
@@ -4,6 +4,10 @@ set(LLVM_LINK_COMPONENTS
)
+if("${CLANG_DEFAULT_RTLIB}" STREQUAL "compiler-rt")
+ add_definitions(-DCLANG_DEFAULT_RTLIB_COMPILER_RT)
+endif()
+
if("${CLANG_CXX_ABI}" STREQUAL "libcxxrt")
add_definitions(-DCLANG_CXX_ABI_LIBCXXRT)
endif()
diff --git a/lib/Driver/ToolChain.cpp b/lib/Driver/ToolChain.cpp
index 33abe0d..db91b84 100644
--- a/lib/Driver/ToolChain.cpp
+++ b/lib/Driver/ToolChain.cpp
@@ -105,6 +105,14 @@ StringRef ToolChain::getDefaultUniversalArchName() const {
}
}
+ToolChain::RuntimeLibType ToolChain::GetDefaultRuntimeLibType() const {
+#ifdef CLANG_DEFAULT_RTLIB_COMPILER_RT
+ return ToolChain::RLT_CompilerRT;
+#else // !CLANG_DEFAULT_RTLIB_COMPILER_RT
+ return ToolChain::RLT_Libgcc;
+#endif // !CLANG_DEFAULT_RTLIB_COMPILER_RT
+}
+
bool ToolChain::IsUnwindTablesDefault() const {
return false;
}
More information about the cfe-dev
mailing list