Commit be721cd
committed
Fix GCC optimization bug eliminating rb_gc_before_fork()
GCC 15.2.0 with -O3 and -fipa-cp-clone completely eliminates
rb_gc_before_fork() because it sees rb_gc_impl_before_fork() is a no-op.
This removes the memory synchronization point before fork(), causing
stale cached heap slot data to persist in child processes, leading to
jemalloc corruption and SIGSEGV crashes.
Add __atomic_thread_fence(RBIMPL_ATOMIC_SEQ_CST) to force GCC to preserve
the function and create a proper memory barrier. Uses Ruby's memory
ordering constant from include/ruby/atomic.h. This generates a
lock-prefixed instruction on x86-64, preventing function elimination
and ensuring memory synchronization across fork boundaries.
Affects: Shopify's +optimized builds with GCC 15, -O3, --disable-shared
Impact: Fixes intermittent crashes in Puma/Unicorn worker processes1 parent 728001c commit be721cd
1 file changed
+1
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5618 | 5618 | | |
5619 | 5619 | | |
5620 | 5620 | | |
| 5621 | + | |
5621 | 5622 | | |
5622 | 5623 | | |
5623 | 5624 | | |
| |||
0 commit comments