Fix segfault when loading multiple Charm gems together#4
Merged
marcoroth merged 1 commit intomarcoroth:mainfrom Feb 17, 2026
Merged
Conversation
3d783cd to
fb1255f
Compare
When multiple Charm gems (bubbletea, lipgloss, etc.) are loaded in the same Ruby process, each embeds its own Go runtime via c-archive static linking. Ruby loads .bundle files with RTLD_GLOBAL, causing ~1900 Go runtime symbols to clash in the global namespace, resulting in a segfault. Fix this by using -load_hidden (macOS) / --version-script (Linux) to make all Go runtime symbols local to the .bundle. Only Init_bubbletea is exported. The Go API symbols (tea_*) remain accessible within the bundle since they're resolved at link time. Tested: bubbletea + lipgloss loaded together in Ruby 4.0 — no segfault.
fb1255f to
1a20fd8
Compare
Owner
|
This might fix #1 |
marcoroth
approved these changes
Feb 17, 2026
Owner
marcoroth
left a comment
There was a problem hiding this comment.
Thank you so much for looking into this @khasinski! 🙏🏼
This was referenced Feb 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When bubbletea and lipgloss are loaded together in the same Ruby process, calling Go-backed functions causes a segfault due to Go runtime symbol clashes. Each gem embeds a full Go runtime via
c-archive, and the duplicate symbols collide when both runtimes are active.This is especially problematic with cross-compiled gems (via rake-compiler-dock), where Ruby's rbconfig adds
-Wl,-flat_namespace- putting all symbols into a single global pool.Fix
-load_hiddento link the Go static archive with all symbols hidden, and-exported_symbols_listto export only_Init_bubbletea.--version-scriptto achieve the same: export onlyInit_bubbletea, hide everything else.This reduces exported symbols from ~60 to 1, eliminating all clashes between gems.