Skip to content

Fix segfault when loading multiple Charm gems together#4

Merged
marcoroth merged 1 commit intomarcoroth:mainfrom
khasinski:fix/hide-go-runtime-symbols
Feb 17, 2026
Merged

Fix segfault when loading multiple Charm gems together#4
marcoroth merged 1 commit intomarcoroth:mainfrom
khasinski:fix/hide-go-runtime-symbols

Conversation

@khasinski
Copy link
Copy Markdown
Contributor

@khasinski khasinski commented Feb 16, 2026

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

  • macOS: Use -load_hidden to link the Go static archive with all symbols hidden, and -exported_symbols_list to export only _Init_bubbletea.
  • Linux: Use a linker --version-script to achieve the same: export only Init_bubbletea, hide everything else.

This reduces exported symbols from ~60 to 1, eliminating all clashes between gems.

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.
@khasinski khasinski force-pushed the fix/hide-go-runtime-symbols branch from fb1255f to 1a20fd8 Compare February 17, 2026 00:53
@marcoroth
Copy link
Copy Markdown
Owner

This might fix #1

Copy link
Copy Markdown
Owner

@marcoroth marcoroth left a comment

Choose a reason for hiding this comment

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

Thank you so much for looking into this @khasinski! 🙏🏼

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.

2 participants