Open
Description
Problem Description
zstd-ruby currently exports all ZSTD symbols with default visibility, which causes symbol collisions when used alongside other gems that dynamically link to system libzstd (e.g., rdkafka-ruby).
Reproduction Steps
- Install both
zstd-ruby
andrdkafka-ruby
in the same application - Run code that triggers ZSTD compression in rdkafka
- Observe intermittent segmentation faults
Root Cause
zstd-ruby statically links libzstd but exports all ZSTD functions globally due to:
// In ext/zstdruby/libzstd/zstd.h
#define ZSTDLIB_VISIBLE __attribute__ ((visibility ("default")))
#define ZSTDLIB_API ZSTDLIB_VISIBLE
This creates a symbol collision where:
- rdkafka-ruby expects to use system libzstd (/lib/x86_64-linux-gnu/libzstd.so.1)
- Dynamic linker resolves ZSTD function calls to zstd-ruby's symbols instead
- Memory allocated by system libzstd gets freed by zstd-ruby's libzstd implementation
- Results in segfaults like:
#0 edata_szind_set (szind=36, edata=0x0) at include/jemalloc/internal/edata.h:472 ... #8 0x00007a1243a49528 in ZSTD_freeCCtx () from zstd-ruby/zstdruby.so #9 0x00007a125eace71d in rd_kafka_zstd_compress (...) at rdkafka_zstd.c:220
Proposed solution
- Modify the build configuration to hide ZSTD symbols
- Add
RUBY_FUNC_EXPORTED
macro toInit_zstdruby
to explicitly mark it as publicly visible
Metadata
Metadata
Assignees
Labels
No labels