Fix segfault when loading multiple Charm gems together#5
Merged
marcoroth merged 1 commit intomarcoroth:mainfrom Feb 17, 2026
Merged
Conversation
0c1cbd8 to
a4ede0d
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_lipgloss is exported. The Go API symbols (lipgloss_*) remain accessible within the bundle since they're resolved at link time. Tested: bubbletea + lipgloss loaded together in Ruby 4.0 — no segfault.
a4ede0d to
c71c83d
Compare
marcoroth
approved these changes
Feb 17, 2026
Owner
marcoroth
left a comment
There was a problem hiding this comment.
Thanks @khasinski, this is so much appreciated! 🙏🏼
Owner
|
This might fix #1 |
Closed
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 lipgloss and bubbletea 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_lipgloss.--version-scriptto achieve the same: export onlyInit_lipgloss, hide everything else.This reduces exported symbols from ~60 to 1, eliminating all clashes between gems.