Skip to content

Commit d736a1b

Browse files
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.
1 parent 8aab896 commit d736a1b

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

lib/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ if (BUILD_DYNAMIC_LIB)
9090
target_include_directories(pulsarShared PRIVATE ${dlfcn-win32_INCLUDE_DIRS})
9191
target_link_options(pulsarShared PRIVATE $<$<CONFIG:DEBUG>:/NODEFAULTLIB:MSVCRT>)
9292
endif()
93+
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
94+
target_link_options(pulsarShared PRIVATE -Wl,-Bsymbolic)
95+
endif ()
9396
check_cxx_symbol_exists(__GLIBCXX__ iostream GLIBCXX)
9497
if (GLIBCXX)
9598
target_link_libraries(pulsarShared PUBLIC -static-libgcc -static-libstdc++)

0 commit comments

Comments
 (0)