-
-
Notifications
You must be signed in to change notification settings - Fork 155
gc: native roots beyond aarch64-macOS — x86-64, iOS, iPadOS, tvOS #7349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
af79d1a
gc: native roots on x86-64 — derive the SP base from the CFA
3541f68
ci(gc): make x86-64 a real arm instead of a refusal assertion
dd93ef5
gc: native roots on iOS, iPadOS and tvOS — widen the Apple gates
30c32f2
gc: per-arch CFA adjustment, and a pointer-sized address field for wa…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| ### Native GC roots reach iOS, iPadOS and tvOS | ||
|
|
||
| iOS and iPadOS are aarch64 + Mach-O — the same shape as macOS, which already | ||
| worked. They did not work, and the reason was gating rather than anything | ||
| architectural: the Mach-O stack-map loader, the unwinder module, the fp-chain | ||
| walker and `stack_top` were each `#[cfg(target_os = "macos")]`. | ||
|
|
||
| On any other Apple platform that sent the runtime to the no-section stub, so | ||
| `loaded_stack_map_section()` returned `None`, the index came out empty, and the | ||
| collector ran **with no native roots at all** — silently, on the platforms that | ||
| are hardest to debug. The compiler would happily emit the map; nothing read it. | ||
|
|
||
| All four gates are now the same predicate: 64-bit Apple, or Linux. | ||
| `pthread_get_stackaddr_np` is Apple-wide, not macOS-only, and the `mach2` | ||
| dependency was widened to match the code that uses it — declaring it for fewer | ||
| targets than the loader compiles on is how this stayed hidden. | ||
|
|
||
| **watchOS is refused, deliberately.** `arm64_32` has 32-bit pointers while the | ||
| map stores function addresses as `u64` and the runtime does `usize` arithmetic | ||
| on them. The compiler rejects the target before emitting a map nothing can | ||
| read, and the check is ordered before the `arm64` prefix test so it actually | ||
| fires. | ||
|
|
||
| Verified by compiling `perry-runtime` for each target: `aarch64-apple-ios`, | ||
| `aarch64-apple-ios-sim` and `aarch64-apple-tvos` all build. That is what found | ||
| the hole — `stack_top` did not exist on iOS, so the build failed outright | ||
| rather than quietly selecting the stub. `aarch64-apple-visionos` still fails in | ||
| the third-party `psm` build script, unrelated to this change. | ||
|
|
||
| Running on a device or simulator is the verification this does not yet have. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| ### Native GC roots work on x86-64 | ||
|
|
||
| `PERRY_RS4GC=1` was refused on anything but aarch64 (#7324). The refusal was | ||
| correct — the runtime could not resolve x86-64 frame bases, and the collector | ||
| segfaulted rather than reporting anything — but the cause was one unsupported | ||
| call, not anything architectural. | ||
|
|
||
| On x86-64 every root is `Indirect [RSP + off]`, DWARF register 7. The unwinder | ||
| path resolved bases with `_Unwind_GetGR(context, reg)`, and **`_Unwind_GetGR` | ||
| is not a supported query for the stack-pointer column** — it returned garbage | ||
| that the collector then wrote through. `_Unwind_GetCFA` is the supported way. | ||
|
|
||
| SP-relative roots now derive their base from the CFA, and the arithmetic is | ||
| **architecture-specific** rather than shared: | ||
|
|
||
| * **x86-64** — `call` pushes the return address, so the CFA is the caller's | ||
| stack pointer before the call and the body stack pointer is | ||
| `CFA - 8 - stack_size`. | ||
| * **aarch64** — `bl` writes the return address to `x30`; nothing is pushed, so | ||
| the body stack pointer is `CFA - stack_size`. | ||
|
|
||
| Subtracting a return-address slot on aarch64 shifts every SP-relative root by a | ||
| word. It would have stayed latent there because `chain_walkable` is true on | ||
| aarch64, so the fast x29 walker runs and this path is only the fallback — the | ||
| error would surface only once the fast walk bailed. The architecture's SP register number is a **runtime-local** | ||
| constant, deliberately separate from the format's base tags — those stay | ||
| aarch64-literal so the compiler's idea of the target and the runtime's | ||
| `target_arch` can never disagree (see `gc_map.rs`). | ||
|
|
||
| Measured on real x86-64 Linux hardware: **all ten gc-ratchet probes byte-match | ||
| the pinned Node oracle** under `PERRY_RS4GC=1 PERRY_GC_FORCE_EVACUATE=1 | ||
| PERRY_GC_VERIFY_EVACUATION=1`, with `.perry_gcmap` present in every binary. | ||
|
|
||
| The walker demonstrably ran rather than passing vacuously — root-source | ||
| telemetry on x86-64 reports `walks=1, frames_visited=10, records_matched=1, | ||
| locations_visited=2` on `02_survivor_promotion`, with `fp_walks=0` and | ||
| `fallback_walks=1` (the fp-chain walker is aarch64-only, so the unwinder is the | ||
| correct path there), and the evacuation moved objects | ||
| (`retained_forwarded_stub_objects=5`). | ||
|
|
||
| **The same telemetry on aarch64 has the same shape** (`7/0/1/1` vs `10/0/1/1` | ||
| on the same probes, `2` locations on `09_try_catch_roots` on both), which is | ||
| what makes this an equivalence result rather than a green light of unknown | ||
| provenance. | ||
|
|
||
| Caveat worth recording: those location counts are low **on both platforms**. | ||
| The probes end in an explicit `gc()`, a manual collection from a shallow stack, | ||
| so precise native roots are lightly exercised by this suite regardless of | ||
| architecture. That is a pre-existing gate weakness, not something this change | ||
| introduces, and it means "x86-64 matches aarch64" is a stronger claim here than | ||
| "x86-64 is heavily exercised". |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Fix the incomplete documentation sentence.
Line 55 omits the action before “binary that crashes under collection.”
Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents