[clang] [llvm] Introduce symbol versioning for clang-cpp (PR #116556)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 17 12:26:36 PST 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Aaron Puchert (aaronpuchert)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/116556.diff
3 Files Affected:
- (modified) clang/tools/clang-shlib/CMakeLists.txt (+8)
- (added) clang/tools/clang-shlib/simple_version_script.map.in (+1)
- (modified) llvm/CMakeLists.txt (+1-1)
``````````diff
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 cde4a999ea2e74..304197667dad6e 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()
``````````
</details>
https://github.com/llvm/llvm-project/pull/116556
More information about the cfe-commits
mailing list