druntime: stop hiding lr/d8-d15 from GC in AArch64 fiber switch - #15
Merged
ljmf00-wekaio merged 2 commits intoAug 11, 2026
Merged
Conversation
fiber_switchContext saves x19-x28, fp, lr and d8-d15 on the fiber's stack, but reported sp + 9*8 as the stack top (tstack), deliberately hiding the saved lr and d8-d15 from the GC scan. On AArch64, d8-d15 are callee-saved, so the compiler is free to keep a live GC pointer in one of them across a suspension point (e.g. a cheap fmov d8, x0 spill). If that saved register holds the only reference to a heap object, a collection while the fiber is suspended frees memory that is still reachable, corrupting the program when the fiber resumes (WEKAPP-581124: weka stats SwitchError on ARM clients). Report the true sp instead, so the whole save area is scanned, and adjust initStack to the new convention: reserve the lr/d8-d15 words below tstack and zero them (they are now GC-scanned, so stale data on fiber reuse must not be misread as pointers). Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Luís Ferreira <luis.ferreira@weka.io>
Parks the sole reference to a canary object in d8 (all other copies XOR-obfuscated, stack spills and scratch registers scrubbed), yields, forces collections plus heap churn from the main context, then resumes and asserts the canary survived. Fails against the old fiber_switchContext convention (canary collected because the saved d8 was hidden from the GC scan) and passes with the true-sp convention. No-op on non-AArch64 or non-LDC builds. Co-Authored-By: Claude <noreply@anthropic.com> Signed-off-by: Luís Ferreira <luis.ferreira@weka.io>
BaruchWeka
approved these changes
Aug 11, 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.
No description provided.