Skip to content

Fix symbol collision with other native gems using libzstd #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

SpringMT
Copy link
Owner

@SpringMT SpringMT commented Jul 6, 2025

This PR fixes the symbol collision issue reported in #102 when using zstd-ruby alongside other gems that dynamically link to system libzstd (e.g., rdkafka-ruby).

Changes Made

  1. Symbol Visibility Control: Added flag to hide all ZSTD symbols by default
  2. Explicit Export List: Created file to explicitly control which symbols are exported
  3. macOS Compatibility: Added flag for macOS to use the export list
  4. Ruby Extension Initialization: Added macro to function

Root Cause

The issue was caused by zstd-ruby exporting all ZSTD symbols globally, which created conflicts when other gems expected to use system libzstd. This resulted in memory corruption and segmentation faults.

Solution

With this fix, only the function is exported, preventing symbol collisions while maintaining full compatibility with existing functionality.

Testing

  • All 53 existing tests pass
  • Basic compression/decompression functionality verified
  • Symbol visibility confirmed using command

Fixes #102

- Hide all ZSTD symbols by default using -fvisibility=hidden
- Use exported_symbols_list on macOS to explicitly control exported symbols
- Only export Init_zstdruby function required for Ruby extension initialization
- Add RUBY_FUNC_EXPORTED macro to Init_zstdruby function

This resolves symbol collision issues when using zstd-ruby alongside other
gems that dynamically link to system libzstd (e.g., rdkafka-ruby).

Fixes #102
Copy link

@dmariassy dmariassy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @SpringMT , thanks for the quick turnaround on this! I'd be happy to soak this branch in prod for a few days to see whether the segfaults return

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Symbol collision when using other native gems that depend on libzstd
2 participants