This is an automated email from the ASF dual-hosted git repository.
xyz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/pulsar-client-cpp.git
The following commit(s) were added to refs/heads/main by this push:
new d736a1b Add -Bsymbolic link option to avoid symbol interposition
(#432)
d736a1b is described below
commit d736a1b68fac6d1d5bd9f785aabf8f952580a597
Author: Yunze Xu <[email protected]>
AuthorDate: Thu Jul 4 09:52:36 2024 +0800
Add -Bsymbolic link option to avoid symbol interposition (#432)
### Motivation
There is a case that `libpulsar.so` could unexpectedly call functions from
other dependencies.
For example, assuming the application depends on two libraries:
- `libpulsar.so`, which includes the symbols from `libcurl.a` 8.4.0
- `libfoo.so`, which includes the symbols from `libcurl.a` 7.82.0
If the link order is `libfoo.so` first, then the libcurl definitions from
7.82.0 will also be used by `libpulsar.so` and then the application might crash
due to the incompatibility. This is an issue specifically with Linux ELF format.
### Modifications
Add the `-Wl,-Bsymbolic` link option for GCC.
---
lib/CMakeLists.txt | 3 +++
1 file changed, 3 insertions(+)
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 33694a6..f578c29 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -90,6 +90,9 @@ if (BUILD_DYNAMIC_LIB)
target_include_directories(pulsarShared PRIVATE
${dlfcn-win32_INCLUDE_DIRS})
target_link_options(pulsarShared PRIVATE
$<$<CONFIG:DEBUG>:/NODEFAULTLIB:MSVCRT>)
endif()
+ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
+ target_link_options(pulsarShared PRIVATE -Wl,-Bsymbolic)
+ endif ()
check_cxx_symbol_exists(__GLIBCXX__ iostream GLIBCXX)
if (GLIBCXX)
target_link_libraries(pulsarShared PUBLIC -static-libgcc
-static-libstdc++)