Repository navigation
fix(relinker): guard length-changing rewrites around truncated branches - #7822
Conversation
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
Windows data point for
Not tested: relinking a real title, Linux. AI-assisted (Claude Code). |
Thank you for testing this on Windows and providing the regression comparison! I really appreciate you taking the time to verify that the test passes with the fix and fails when the change is reverted. This is valuable evidence that the fix addresses the issue. Thanks again for the detailed test results! 🙏 |
jotitadev
left a comment
There was a problem hiding this comment.
Linux run of 554691a0b, next to xXPBSXx's Windows data, plus one question about how wide the guard is.
Machine: Linux x86_64, i7-8700, Ubuntu 26.04, GCC 15.2, Release, BUILD_TESTING=ON, full build. Head 554691a0b merged onto main 8816fd772 (clean merge), together with #7363 and #7820 (no shared files).
rewrite_boundariespasses, the PR'sRewriteBoundaryTests.cpponmain(rewriter unchanged) fails, and the non-GPU suite is 775/775, same asmain.
The guard decodes every instruction in the section and throws as soon as any truncated branch is outside the cut, without looking at where it sits. With a local probe on this head, {66 EB 00, 90, 90, C3} rewritten at offset 4 (90 -> 66 90) is rejected, although that branch starts before the cut and its target (offset 3) is before it too, so neither moves. So any length-changing rewrite now fails in a section that contains a 66 EB/66 E9 anywhere, including bytes that only decode that way. If that is the intended conservative choice, fine. Otherwise the before/after-cut test that the relocation adjustment above already uses (instrShifts/targetShifts) would narrow it to branches whose source or target moves. I did not relink a real title.
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Thank you for testing this on Linux and for the detailed review! I appreciate you checking the unaffected case as well.
Thanks again for catching this! |
jotitadev
left a comment
There was a problem hiding this comment.
Revalidated the new head on Apple Silicon (M2 Max, macOS 27.2), arm64 native, relinker-only build (-DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON).
Head: 1e30c5a6c
The narrowed guard now distinguishes a truncated relative branch that moves with the cut from one that stays put. rewrite_boundaries covers it (19/19): the two new moving-branch cases (66 EB 01 90 C3, 90 66 EB FC C3) are rejected, and the new unaffected case (66 EB 00 90 90 C3 rewritten past the branch) is now accepted, producing 66 EB 00 90 66 90 C3. That resolves the question from my earlier note — a length change beyond an unaffected truncated branch no longer errors.
Full relinker suite: 209/209.
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Thanks for taking the time to test this on your machine and verify the fix! Really appreciate the thorough review and for confirming that all 209 tests pass. Query: Are you a Bot ? |
a7904a0 to
db35f9a
Compare
db35f9a to
6e8f9dc
Compare
|
Windows run of the current head: 6e8f9dc merged into AI-assisted: yes (Claude Code) |
Thanks for testing the current head on Windows and sharing the detailed results. Glad to see all 235 tests passing, including |
6e8f9dc to
eb3d0b1
Compare
…uard Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
eb3d0b1 to
e1fea2e
Compare
|
Checked the guard against the rewriter (displacement decode for rel8/rel16, moving vs unaffected branch, 16-bit range) and the new Added on top as our own commit:
Rebased onto current |
What
The fix for 16-bit-truncated relative branch targets adds
TruncatesBranchTargetmetadata and deliberately leavesHasBranchTargetfalse when the decoder cannot safely provide a relocatable target.X64InstructionRewriter::Rewrite()could still perform length-changing edits without accounting for a surviving truncated relative branch. If the edit shifts code before or after that branch, its effective destination may change even though the rewriter cannot update the branch target.This change conservatively rejects length-changing rewrites when a truncated relative branch survives outside the instruction being replaced.
Changes:
X64InstructionRewriter.cpp: reject length-changing edits when a surviving truncated relative branch cannot be safely preserved.RewriteBoundaryTests.cpp: add regression cases covering truncated branches whose source or destination would be affected by resizing.docs/dev/debt/relinker.md: document the rewriter limitation and safeguard.Tested
Windows 10 (10.0.19045), MinGW-w64 (WinLibs) GCC 15.2.0, Release
Independent review validation
ctest -R '^rewrite_boundaries$'on the combined tree at5563156935, including #7817 and #7746:X64InstructionRewriter.cpprestored tomainatfb0dc118f, while retaining the regression test: fails 3 of 3 withLength-changing rewrite accepted a section with a truncated relative branch.The comparison confirms that the regression test detects the unsafe behaviour when the fix is removed.
GitHub Actions
clang++, x86-64 and native), Ubuntu (g++) and Windows (g++) — successful.Not tested: relinking a real title or running the regression test manually on Linux.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with ChatGPT