Skip to content

Rewriter: follow register copies back to a jump table's far base - #90

Closed
v0lumehi wants to merge 1 commit into
seedds:mainfrom
v0lumehi:rewriter-far-base
Closed

v0lumehi wants to merge 1 commit into
seedds:mainfrom
v0lumehi:rewriter-far-base

Conversation

@v0lumehi

Copy link
Copy Markdown
Contributor

This came up while bringing up Super Smash Bros. Ultimate (#65). It is a general rewriter fix.

Problem

patch_nso.py asserted "jump table 2b74458" on Smash 13.0.5's main:

ldrb w18,[x14]; sub w18,w18,#1; cmp w18,#6; b.hi …
ldrsw x18,[x7,x18,lsl #2]; add x18,x18,x7; br x18

The table base x7 is built by an adrp + add 688 instructions earlier and parked in x30 around a loop (mov x30,x7 … mov x7,x30). The far-base chain met that mov and gave up. The function-wide fallback then found a second adrp x7 + add pair, another table further on, whose targets also lie inside the function.

Change

jump_offsets' last attempt now follows register copies back to the adrp + add (copied_base):

  • It walks in address order back to the function's start.
  • It never crosses a call while the register it follows is caller-saved.
  • Every target must be an instruction of the function.

It only runs where the rewriter asserted before. The survey note also changes: a game that imports nn::ro and ships NRRs but no loose NRO keeps its NROs inside an archive, so the host's empty nn::ro is not "enough" there.

Checked

  • That site was the only unhandled one in Smash's main.
  • Mario Kart 8 Deluxe's main, subsdk0 and sdk, and Smash's sdk and movie module, come out byte-identical with the previous rewriter (build_src.sha256 aside).
  • dm/tools/tests pass, and the Mac host builds.

…gisters (Super Smash Bros. Ultimate 13.0.5 main+0x2b74458: ldrb w18,[x14]; sub w18,w18,#1; cmp w18,seedds#6; b.hi; ldrsw x18,[x7,x18,lsl #2]; add x18,x18,x7; br x18). x7 is built by adrp + add 688 instructions before and parked in x30 around a loop (mov x30,x7 ... mov x7,x30), so the far chain (table_base far) met a mov and patch_nso.py asserted "jump table 2b74458"; the function-wide search jump_adr_offsets uses finds a second adrp x7 + add pair there (another table further on) whose seven targets also lie in the function. jump_offsets' last attempt (far_base) now follows register copies back to the adrp + add (copied_base: address order to the function's start, through no call while the register followed is caller-saved; every target an instruction of the function). It was that main's only unhandled site, and it runs only where the rewriter asserted before: Mario Kart 8 Deluxe's main, subsdk0 and sdk and Smash's sdk and movie module come out byte-identical with the previous rewriter (build_src.sha256 aside); dm/tools/tests pass. Survey: a game that imports nn::ro and ships NRRs but no loose NRO keeps its NROs inside an archive (Smash: 14 NRRs, 98 NROs in data.arc whose exports main imports), so the note no longer says the host's empty nn::ro "is enough" there. docs/agents/03-bringup.md has the rewriter case
seedds added a commit that referenced this pull request Oct 24, 2026
Integrate PRs #75, #90 and #91 with focused correctness fixes:
- Prioritize demanded render pipelines and bound speculative compilation.
- Follow copied jump-table bases and reject W/X register clobbers.
- Collect and rewrite registered NROs, load them on the Mac, and preserve
  runtime activation order through unload/reload and symbol rebinding.
- Preserve refused-only manifests and invalidate collection caches when
  archive readers or symbol parsing change.

Add pipeline scheduling, register tracing, NRO packaging and loader
lifecycle regression coverage. Document that executable NRO embedding
on iOS remains outside this integration.

Validation: 41 Python tests; 48 pipeline scheduling, 102 NVN and 95
geometry checks; three pipeline-key serialization cases; full host test
suite; Mac host build; iOS loader syntax checks; git diff --check.
Gameplay and controlled performance A/B measurements were not run.

Co-authored-by: blindlight86 <[email protected]>
Co-authored-by: v0lumehi <[email protected]>
@seedds

seedds commented Oct 24, 2026

Copy link
Copy Markdown
Owner

Integrated into main in d979c34, with coauthor attribution. Thanks for the contribution.

The integration also fixes W/X clobber detection: a write to wN invalidates the traced xN base. Added regression coverage using real AArch64 instructions for far copies, register aliases, 32-bit clobbers, and call-clobbered registers. All 41 Python tools tests passed; the Mac host build and full host test suite also passed.

Closing as integrated. No new gameplay validation was performed during this integration.

@seedds seedds closed this Oct 24, 2026
@v0lumehi
v0lumehi deleted the rewriter-far-base branch October 24, 2026 07:53
Know-It-All-Brother pushed a commit to Know-It-All-Brother/nxnative that referenced this pull request Nov 9, 2026
Integrate PRs seedds#75, seedds#90 and seedds#91 with focused correctness fixes:
- Prioritize demanded render pipelines and bound speculative compilation.
- Follow copied jump-table bases and reject W/X register clobbers.
- Collect and rewrite registered NROs, load them on the Mac, and preserve
  runtime activation order through unload/reload and symbol rebinding.
- Preserve refused-only manifests and invalidate collection caches when
  archive readers or symbol parsing change.

Add pipeline scheduling, register tracing, NRO packaging and loader
lifecycle regression coverage. Document that executable NRO embedding
on iOS remains outside this integration.

Validation: 41 Python tests; 48 pipeline scheduling, 102 NVN and 95
geometry checks; three pipeline-key serialization cases; full host test
suite; Mac host build; iOS loader syntax checks; git diff --check.
Gameplay and controlled performance A/B measurements were not run.

Co-authored-by: blindlight86 <[email protected]>
Co-authored-by: v0lumehi <[email protected]>
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