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.
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 @@
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++)