[clang] 944478d - Introduce symbol versioning for clang-cpp (#116556)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 19 14:58:37 PST 2024
Author: Aaron Puchert
Date: 2024-11-19T23:58:33+01:00
New Revision: 944478dd62a78f6bb43d4da210643affcc4584b6
URL: https://github.com/llvm/llvm-project/commit/944478dd62a78f6bb43d4da210643affcc4584b6
DIFF: https://github.com/llvm/llvm-project/commit/944478dd62a78f6bb43d4da210643affcc4584b6.diff
LOG: Introduce symbol versioning for clang-cpp (#116556)
The situation that required symbol versions on the LLVM shared library
can also happen for clang-cpp, although it is less common: different
tools require different versions of the library, and through transitive
dependencies a process ends up with multiple copies of clang-cpp. This
causes havoc with ELF, because calls meant to go one version of the
library end up with another.
I've also considered introducing a symbol version globally, but for
example the clang (C) library and other targets outside of LLVM/Clang,
e.g. libc++, would not want that. So it's probably best if we keep it to
those libraries.
Added:
clang/tools/clang-shlib/simple_version_script.map.in
Modified:
clang/tools/clang-shlib/CMakeLists.txt
llvm/CMakeLists.txt
Removed:
################################################################################
diff --git a/clang/tools/clang-shlib/CMakeLists.txt b/clang/tools/clang-shlib/CMakeLists.txt
index 298d3a9d18fec8..830f2b138ffa16 100644
--- a/clang/tools/clang-shlib/CMakeLists.txt
+++ b/clang/tools/clang-shlib/CMakeLists.txt
@@ -48,6 +48,14 @@ add_clang_library(clang-cpp
${_OBJECTS}
LINK_LIBS
${_DEPS})
+
+configure_file(simple_version_script.map.in simple_version_script.map)
+
+if (NOT LLVM_LINKER_IS_SOLARISLD AND NOT MINGW)
+ # Solaris ld does not accept global: *; so there is no way to version *all* global symbols
+ target_link_options(clang-cpp PRIVATE LINKER:--version-script,${CMAKE_CURRENT_BINARY_DIR}/simple_version_script.map)
+endif()
+
# Optimize function calls for default visibility definitions to avoid PLT and
# reduce dynamic relocations.
if (NOT APPLE AND NOT MINGW AND NOT LLVM_LINKER_IS_SOLARISLD_ILLUMOS)
diff --git a/clang/tools/clang-shlib/simple_version_script.map.in b/clang/tools/clang-shlib/simple_version_script.map.in
new file mode 100644
index 00000000000000..cb2306d1f59682
--- /dev/null
+++ b/clang/tools/clang-shlib/simple_version_script.map.in
@@ -0,0 +1 @@
+ at LLVM_SHLIB_SYMBOL_VERSION@ { global: *; };
diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index 74b72c98253413..cfcf1404d82b7c 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -27,7 +27,7 @@ if (NOT PACKAGE_VERSION)
endif()
if(NOT DEFINED LLVM_SHLIB_SYMBOL_VERSION)
- # "Symbol version prefix for libLLVM.so"
+ # "Symbol version prefix for libLLVM.so and libclang-cpp.so"
set(LLVM_SHLIB_SYMBOL_VERSION "LLVM_${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}")
endif()
More information about the cfe-commits
mailing list