[clang] [clang-shlib] Add symbol versioning to all symbols (PR #110758)

via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 1 15:51:52 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Tom Stellard (tstellar)

<details>
<summary>Changes</summary>

We do the same thing for libLLVM.so.  This should help avoid issues when an applications loads two different versions of the library at the same time.

---
Full diff: https://github.com/llvm/llvm-project/pull/110758.diff


2 Files Affected:

- (modified) clang/tools/clang-shlib/CMakeLists.txt (+7) 
- (added) clang/tools/clang-shlib/simple_version_script.map.in (+1) 


``````````diff
diff --git a/clang/tools/clang-shlib/CMakeLists.txt b/clang/tools/clang-shlib/CMakeLists.txt
index 298d3a9d18fec8..004ce2897960ca 100644
--- a/clang/tools/clang-shlib/CMakeLists.txt
+++ b/clang/tools/clang-shlib/CMakeLists.txt
@@ -61,3 +61,10 @@ if (MINGW OR CYGWIN)
   # make sure we export all symbols despite potential dllexports.
   target_link_options(clang-cpp PRIVATE LINKER:--export-all-symbols)
 endif()
+
+# Solaris ld does not accept global: *; so there is no way to version *all* global symbols
+if (NOT LLVM_LINKER_IS_SOLARISLD AND NOT MINGW)
+  configure_file(${CMAKE_CURRENT_SOURCE_DIR}/simple_version_script.map.in
+	         ${CMAKE_CURRENT_BINARY_DIR}/simple_version_script.map)
+  target_link_options(clang-cpp PRIVATE -Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/simple_version_script.map)
+endif()
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: *; };

``````````

</details>


https://github.com/llvm/llvm-project/pull/110758


More information about the cfe-commits mailing list