gc: prevent LTO from eliminating rb_gc_before_fork#968
Open
ianks wants to merge 1 commit intov4.0.2-pshopify2from
Open
gc: prevent LTO from eliminating rb_gc_before_fork#968ianks wants to merge 1 commit intov4.0.2-pshopify2from
ianks wants to merge 1 commit intov4.0.2-pshopify2from
Conversation
GCC LTO with -flto=auto creates a constprop clone of rb_fork_ruby where rb_multi_ractor_p() is constant false. In that clone, rb_gc_vm_barrier() and RB_GC_VM_LOCK() are both no-ops, so rb_gc_impl_before_fork reduces to a trivial store and GCC eliminates the entire call chain. This leaves no GC barrier before fork(2). RBIMPL_ATTR_NOINLINE() on rb_gc_before_fork prevents GCC from inlining it into the constprop clone, forcing it to treat the call as having unknown side effects. Additionally, call gc_rest() at the top of rb_gc_impl_before_fork to complete any in-progress incremental GC cycle before forking. This ensures the child does not inherit a mid-cycle heap.
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.
GCC LTO (
-flto=auto) eliminatesrb_gc_before_fork()via constprop cloning. The call is completely absent from the binary, meaning fork children can inherit an uncoordinated GC heap.the problem
objdump -dofrb_fork_ruby.constprop.0shows no GC barrier beforefork@plt:after this patch
RBIMPL_ATTR_NOINLINE()prevents GCC from inliningrb_gc_before_forkinto the constprop clone.gc_rest()completes any in-progress incremental GC cycle before forking.