Skip to content

Fix segfault when loading multiple Charm gems together#5

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#5
marcoroth merged 1 commit intomarcoroth:mainfrom
khasinski:fix/hide-go-runtime-symbols

Conversation

@khasinski
Copy link
Contributor

@khasinski khasinski commented Feb 16, 2026

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

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

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

@khasinski khasinski force-pushed the fix/hide-go-runtime-symbols branch 2 times, most recently from 0c1cbd8 to a4ede0d Compare February 17, 2026 00:46
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.
@khasinski khasinski force-pushed the fix/hide-go-runtime-symbols branch from a4ede0d to c71c83d Compare February 17, 2026 00:53
Copy link
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.

Thanks @khasinski, this is so much appreciated! 🙏🏼

@marcoroth marcoroth merged commit 3ad0bfb into marcoroth:main Feb 17, 2026
4 checks passed
@marcoroth
Copy link
Owner

This might fix #1

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