[clang] dce7864 - clang-tblgen build: avoid duplicate inclusion of libLLVMSupport
Nicolai Hähnle via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 28 06:49:01 PDT 2022
Author: Nicolai Hähnle
Date: 2022-10-28T15:48:20+02:00
New Revision: dce78646f07ff67f7d4887525e908dbf47d9e86b
URL: https://github.com/llvm/llvm-project/commit/dce78646f07ff67f7d4887525e908dbf47d9e86b
DIFF: https://github.com/llvm/llvm-project/commit/dce78646f07ff67f7d4887525e908dbf47d9e86b.diff
LOG: clang-tblgen build: avoid duplicate inclusion of libLLVMSupport
TableGen executables are supposed to never be linked against libLLVM-*.so,
even when LLVM_LINK_LLVM_DYLIB=ON, presumably for cross-compilation.
It turns out that clang-tblgen *did* link against libLLVM-*.so,
indirectly so via the clangSupport.
This lead to a regression in what should have been unrelated work of
cleaning up ManagedStatics in LLVMSupport. A running clang-tblgen
process ended up with two copies of a cl::opt static global:
- one from libLLVMSupport linked statically into clang-tblgen as a
direct dependency
- one from libLLVMSupport linked into libLLVM-*.so, which clang-tblgen
linked against due to the clangSupport dependency
For a bit more context, see the discussion at
https://discourse.llvm.org/t/flang-aarch64-dylib-buildbot-need-help-understanding-a-regression-in-clang-tblgen/64871/
None of the potential solutions I could find are perfect. Presumably one
possible solution would be to remove "Support" from the explicit
dependencies of clang-tblgen. However, relying on the transitive
inclusion via clangSupport seems risky, and in any case this wouldn't
address the issue of clang-tblgen surprisingly linking against libLLVM-*.so.
This change instead creates a second version of the clangSupport library
that is explicitly linked statically, to be used by clang-tblgen.
v2:
- define an alias so that clang-tblgen can always link against
"clangSupport_tablegen"
- use add_llvm_library(... BUILDTREE_ONLY ...)
v3:
- use the object library version of clangSupport if available
Differential Revision: https://reviews.llvm.org/D134637
Added:
Modified:
clang/lib/Support/CMakeLists.txt
clang/utils/TableGen/CMakeLists.txt
Removed:
################################################################################
diff --git a/clang/lib/Support/CMakeLists.txt b/clang/lib/Support/CMakeLists.txt
index c24324bd7b0d3..8ea5620052ed8 100644
--- a/clang/lib/Support/CMakeLists.txt
+++ b/clang/lib/Support/CMakeLists.txt
@@ -9,8 +9,24 @@ set(LLVM_LINK_COMPONENTS
Support
)
-add_clang_library(clangSupport
+set(clangSupport_sources
RISCVVIntrinsicUtils.cpp
)
+add_clang_library(clangSupport ${clangSupport_sources})
+
+if (NOT XCODE)
+ add_library(clangSupport_tablegen ALIAS obj.clangSupport)
+elseif (NOT LLVM_LINK_LLVM_DYLIB)
+ add_library(clangSupport_tablegen ALIAS clangSupport)
+else()
+ # Build a version of the support library that does not link against
+ # libLLVM-*.so, to be used by clang-tblgen. This is so clang-tblgen doesn't
+ # link against libLLVMSupport twice (once statically and once via
+ # libLLVM-*.so).
+ add_llvm_library(clangSupport_tablegen
+ BUILDTREE_ONLY STATIC DISABLE_LLVM_LINK_LLVM_DYLIB
+ ${clangSupport_sources})
+endif()
+
set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS_OLD})
diff --git a/clang/utils/TableGen/CMakeLists.txt b/clang/utils/TableGen/CMakeLists.txt
index 4666d4d7aa5ce..f136cbfee5fa1 100644
--- a/clang/utils/TableGen/CMakeLists.txt
+++ b/clang/utils/TableGen/CMakeLists.txt
@@ -25,6 +25,6 @@ add_tablegen(clang-tblgen CLANG
TableGen.cpp
)
-target_link_libraries(clang-tblgen PRIVATE clangSupport)
+target_link_libraries(clang-tblgen PRIVATE clangSupport_tablegen)
set_target_properties(clang-tblgen PROPERTIES FOLDER "Clang tablegenning")
More information about the cfe-commits
mailing list