aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Puchert <aaronpuchert@alice-dsl.net>2024-11-19 23:58:33 +0100
committerGitHub <noreply@github.com>2024-11-19 23:58:33 +0100
commit944478dd62a78f6bb43d4da210643affcc4584b6 (patch)
tree6671f8dcdc16505754ac2c6404d8cafce8b06370
parent3c8818cf2deaa050817ecec1c99cf939295feced (diff)
downloadllvm-944478dd62a78f6bb43d4da210643affcc4584b6.zip
llvm-944478dd62a78f6bb43d4da210643affcc4584b6.tar.gz
llvm-944478dd62a78f6bb43d4da210643affcc4584b6.tar.bz2
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.
-rw-r--r--clang/tools/clang-shlib/CMakeLists.txt8
-rw-r--r--clang/tools/clang-shlib/simple_version_script.map.in1
-rw-r--r--llvm/CMakeLists.txt2
3 files changed, 10 insertions, 1 deletions
diff --git a/clang/tools/clang-shlib/CMakeLists.txt b/clang/tools/clang-shlib/CMakeLists.txt
index 298d3a9..830f2b13 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 0000000..cb2306d
--- /dev/null
+++ b/clang/tools/clang-shlib/simple_version_script.map.in
@@ -0,0 +1 @@
+@LLVM_SHLIB_SYMBOL_VERSION@ { global: *; };
diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index 74b72c9..cfcf140 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()