nhaehnle created this revision.
nhaehnle added reviewers: kito-cheng, khchen, MaskRay, aaron.ballman,
DavidSpickett.
Herald added subscribers: StephenFan, kristof.beyls.
Herald added a project: All.
nhaehnle requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D134637
Files:
clang/lib/Support/CMakeLists.txt
clang/utils/TableGen/CMakeLists.txt
Index: clang/utils/TableGen/CMakeLists.txt
===================================================================
--- clang/utils/TableGen/CMakeLists.txt
+++ clang/utils/TableGen/CMakeLists.txt
@@ -25,6 +25,10 @@
TableGen.cpp
)
-target_link_libraries(clang-tblgen PRIVATE clangSupport)
+if(LLVM_LINK_LLVM_DYLIB)
+ target_link_libraries(clang-tblgen PRIVATE clangSupport_tablegen)
+else()
+ target_link_libraries(clang-tblgen PRIVATE clangSupport)
+endif()
set_target_properties(clang-tblgen PROPERTIES FOLDER "Clang tablegenning")
Index: clang/lib/Support/CMakeLists.txt
===================================================================
--- clang/lib/Support/CMakeLists.txt
+++ clang/lib/Support/CMakeLists.txt
@@ -9,8 +9,22 @@
Support
)
-add_clang_library(clangSupport
+set(clangSupport_sources
RISCVVIntrinsicUtils.cpp
)
+add_clang_library(clangSupport ${clangSupport_sources})
+
+if (LLVM_LINK_LLVM_DYLIB)
+ # 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
+ # accidentally link against libLLVMSupport twice (once statically and once
via
+ # libLLVM-*.so).
+ llvm_add_library(clangSupport_tablegen
+ STATIC
+ DISABLE_LLVM_LINK_LLVM_DYLIB
+ ${clangSupport_sources})
+endif()
+
+
set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS_OLD})
Index: clang/utils/TableGen/CMakeLists.txt
===================================================================
--- clang/utils/TableGen/CMakeLists.txt
+++ clang/utils/TableGen/CMakeLists.txt
@@ -25,6 +25,10 @@
TableGen.cpp
)
-target_link_libraries(clang-tblgen PRIVATE clangSupport)
+if(LLVM_LINK_LLVM_DYLIB)
+ target_link_libraries(clang-tblgen PRIVATE clangSupport_tablegen)
+else()
+ target_link_libraries(clang-tblgen PRIVATE clangSupport)
+endif()
set_target_properties(clang-tblgen PROPERTIES FOLDER "Clang tablegenning")
Index: clang/lib/Support/CMakeLists.txt
===================================================================
--- clang/lib/Support/CMakeLists.txt
+++ clang/lib/Support/CMakeLists.txt
@@ -9,8 +9,22 @@
Support
)
-add_clang_library(clangSupport
+set(clangSupport_sources
RISCVVIntrinsicUtils.cpp
)
+add_clang_library(clangSupport ${clangSupport_sources})
+
+if (LLVM_LINK_LLVM_DYLIB)
+ # 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
+ # accidentally link against libLLVMSupport twice (once statically and once via
+ # libLLVM-*.so).
+ llvm_add_library(clangSupport_tablegen
+ STATIC
+ DISABLE_LLVM_LINK_LLVM_DYLIB
+ ${clangSupport_sources})
+endif()
+
+
set(LLVM_COMMON_DEPENDS ${LLVM_COMMON_DEPENDS_OLD})
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits