Skip to content

Commit 944478d

Browse files
authored
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.
1 parent 3c8818c commit 944478d

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

clang/tools/clang-shlib/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ add_clang_library(clang-cpp
4848
${_OBJECTS}
4949
LINK_LIBS
5050
${_DEPS})
51+
52+
configure_file(simple_version_script.map.in simple_version_script.map)
53+
54+
if (NOT LLVM_LINKER_IS_SOLARISLD AND NOT MINGW)
55+
# Solaris ld does not accept global: *; so there is no way to version *all* global symbols
56+
target_link_options(clang-cpp PRIVATE LINKER:--version-script,${CMAKE_CURRENT_BINARY_DIR}/simple_version_script.map)
57+
endif()
58+
5159
# Optimize function calls for default visibility definitions to avoid PLT and
5260
# reduce dynamic relocations.
5361
if (NOT APPLE AND NOT MINGW AND NOT LLVM_LINKER_IS_SOLARISLD_ILLUMOS)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@LLVM_SHLIB_SYMBOL_VERSION@ { global: *; };

llvm/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ if (NOT PACKAGE_VERSION)
2727
endif()
2828

2929
if(NOT DEFINED LLVM_SHLIB_SYMBOL_VERSION)
30-
# "Symbol version prefix for libLLVM.so"
30+
# "Symbol version prefix for libLLVM.so and libclang-cpp.so"
3131
set(LLVM_SHLIB_SYMBOL_VERSION "LLVM_${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}")
3232
endif()
3333

0 commit comments

Comments
 (0)