From 3111c741a101e51919d38873868cbc9442211de5 Mon Sep 17 00:00:00 2001 From: Jarvis Date: Sun, 4 Oct 2026 20:13:42 +1100 Subject: [PATCH] Hide statically linked libstdc++ symbols from the extension Precompiled gems are built with CB_STATIC_STDLIB, which links libstdc++ and libgcc statically into libcouchbase.so, but every symbol from those archives is still exported (8423 std:: symbols, 745 STB_GNU_UNIQUE). Ruby loads extensions with RTLD_GLOBAL, so this private GCC 11 runtime interposes on the system libstdc++ used by other C++ extensions and crashes them, e.g. mini_racer (rubyjs/mini_racer#422). Link with --exclude-libs,ALL on ELF platforms so archive symbols stay local to the extension. --- ext/CMakeLists.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ext/CMakeLists.txt b/ext/CMakeLists.txt index 95b0ad0f..7c4a4e38 100644 --- a/ext/CMakeLists.txt +++ b/ext/CMakeLists.txt @@ -92,3 +92,11 @@ endif() if(APPLE) target_link_libraries(couchbase PRIVATE -Wl,-undefined,dynamic_lookup) endif() + +if(UNIX AND NOT APPLE) + # Keep symbols from statically linked archives (libstdc++/libgcc when + # COUCHBASE_CXX_CLIENT_STATIC_STDLIB is on, BoringSSL, etc.) private to this + # extension. Ruby loads extensions with RTLD_GLOBAL, so exporting them lets a + # second copy of libstdc++ interpose on other C++ extensions in the process. + target_link_options(couchbase PRIVATE "LINKER:--exclude-libs,ALL") +endif()