fix(relinker): collect reachable branch targets without signed overflow #11033

Merged
mzaeemnasir merged 1 commit from upstream-pr/11033 into main 2026-10-27 07:40:37 +00:00
mzaeemnasir commented 2026-10-25 14:38:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mzaeemnasir on 2026-10-25T14:38:37Z.


What

CodeInstructionCollector::Collect adds a reachable instruction's branch displacement to the next instruction's address as std::int64_t (CodeInstructionCollector.cpp:499). For a code segment mapped across 2^63 the sum overflows, which is undefined behaviour. The target is now added as an unsigned value, as the function-symbol sweep in the same collector (line 396) and ControlFlowGraph already do. Without a sanitizer the computed target is unchanged.

This is the same class as #10653, at a site #10680 does not touch. #10861 also rewrites this line as part of a larger change. Order: this PR first, proposed to #10861's author here; #10861 then resolves the conflict by keeping its own version of the hunk. If its author prefers to land first, this PR is cut down to the test.

relinker_conversion gains branchAcrossSignedBoundary: a segment at 0x7ffffffffffffff0 whose entry at 0x8000000000000000 jumps back below the boundary.

Tested

Windows 11 Home build 26300, MSYS2 UCRT64 GCC 14.2.0, CMake 4.0.0, relinker-only build.

  • ctest --test-dir build-relinker: 292/292 pass on main 3a2c51afd and with this change; 295/295 after rebasing onto main 5a2744c55e.
  • Composition with #10861: its head merged on top of this branch, the conflict resolved to #10861's side: 298/298 pass, and relinker_conversion passes in the signed-overflow trap build.
  • Built with -fsanitize=signed-integer-overflow -fsanitize-trap=undefined: relinker_conversion with the new test traps (ILLEGAL) without the fix and passes with it.
  • python3 tools/check_conventions.py --base origin/main passes.
  • tools/pr_overlap.py reports #10861 (same line, see above) and #8076 (not comparable, conflicts with main; it adds new signed branch-target sums elsewhere in this file but does not change line 499).
  • Not reproduced from the command line with an ELF; no title tested.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5005682968 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11033). Originally posted by [mzaeemnasir](https://github.com/mzaeemnasir) on 2026-10-25T14:38:37Z. --- ### What `CodeInstructionCollector::Collect` adds a reachable instruction's branch displacement to the next instruction's address as `std::int64_t` (`CodeInstructionCollector.cpp:499`). For a code segment mapped across 2^63 the sum overflows, which is undefined behaviour. The target is now added as an unsigned value, as the function-symbol sweep in the same collector (line 396) and `ControlFlowGraph` already do. Without a sanitizer the computed target is unchanged. This is the same class as #10653, at a site #10680 does not touch. #10861 also rewrites this line as part of a larger change. Order: this PR first, proposed to #10861's author [here](https://github.com/boykopovar/AnyPS5/pull/10861#issuecomment-6402921592); #10861 then resolves the conflict by keeping its own version of the hunk. If its author prefers to land first, this PR is cut down to the test. `relinker_conversion` gains `branchAcrossSignedBoundary`: a segment at `0x7ffffffffffffff0` whose entry at `0x8000000000000000` jumps back below the boundary. ### Tested Windows 11 Home build 26300, MSYS2 UCRT64 GCC 14.2.0, CMake 4.0.0, relinker-only build. - `ctest --test-dir build-relinker`: 292/292 pass on `main` 3a2c51afd and with this change; 295/295 after rebasing onto `main` 5a2744c55e. - Composition with #10861: its head merged on top of this branch, the conflict resolved to #10861's side: 298/298 pass, and `relinker_conversion` passes in the signed-overflow trap build. - Built with `-fsanitize=signed-integer-overflow -fsanitize-trap=undefined`: `relinker_conversion` with the new test traps (`ILLEGAL`) without the fix and passes with it. - `python3 tools/check_conventions.py --base origin/main` passes. - `tools/pr_overlap.py` reports #10861 (same line, see above) and #8076 (not comparable, conflicts with `main`; it adds new signed branch-target sums elsewhere in this file but does not change line 499). - Not reproduced from the command line with an ELF; no title tested. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
copilot-pull-request-reviewer[bot] commented 2026-10-25 14:38:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-10-25T14:38:47Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5643698619 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11033#pullrequestreview-5643698619). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-10-25T14:38:47Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
MarcZX10 commented 2026-10-25 14:40:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T14:40:55Z.

Review: CHANGES_REQUESTED


Requesting merge-order coordination for the confirmed open-PR conflict with #10861 before approval. I fetched both current heads and git merge-tree --write-tree reports a content conflict in core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp, the line changed here. CONTRIBUTING.md requires agreeing the order with the other PR author and declaring a dependency when this PR needs that PR first. The body currently says either can rebase, but does not record an agreed order. Please coordinate with #10861’s author, then update this PR and rebase/test the chosen composition as needed. The exact-head local diff and conventions checks pass; the focused relinker test is still building, and the author-reported Windows test is not independently verified here.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5643705426 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11033#pullrequestreview-5643705426). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T14:40:55Z. **Review:** CHANGES_REQUESTED --- Requesting merge-order coordination for the confirmed open-PR conflict with #10861 before approval. I fetched both current heads and `git merge-tree --write-tree` reports a content conflict in `core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp`, the line changed here. CONTRIBUTING.md requires agreeing the order with the other PR author and declaring a dependency when this PR needs that PR first. The body currently says either can rebase, but does not record an agreed order. Please coordinate with #10861’s author, then update this PR and rebase/test the chosen composition as needed. The exact-head local diff and conventions checks pass; the focused relinker test is still building, and the author-reported Windows test is not independently verified here.
MarcZX10 commented 2026-10-25 15:19:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T15:19:11Z.

Review: APPROVED


Reviewed exact head 90a62a9f191c332612bb9a20ca4205fa34c2ab67. The unsigned addition implements x86-64 modulo address arithmetic for a signed branch displacement and avoids signed overflow. The regression places the instruction and target across the 2^63 boundary and checks both roots are collected. I compiled the changed collector and test translation units with GCC 12.2 syntax-only. The author reports the full relinker suite passing and a signed-overflow sanitizer negative control. Hosted conventions, intake, and labels pass; I did not independently run the full suite.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5643834116 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11033#pullrequestreview-5643834116). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T15:19:11Z. **Review:** APPROVED --- Reviewed exact head 90a62a9f191c332612bb9a20ca4205fa34c2ab67. The unsigned addition implements x86-64 modulo address arithmetic for a signed branch displacement and avoids signed overflow. The regression places the instruction and target across the 2^63 boundary and checks both roots are collected. I compiled the changed collector and test translation units with GCC 12.2 syntax-only. The author reports the full relinker suite passing and a signed-overflow sanitizer negative control. Hosted conventions, intake, and labels pass; I did not independently run the full suite.
MarcZX10 commented 2026-10-25 15:35:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T15:35:52Z.

Review: CHANGES_REQUESTED


The focused regression passes locally: I configured the relinker-only Release build, built relinker_conversion_tests, and ran ctest -R '^relinker_conversion$' (1/1 passed). The code change and its boundary test look sound in isolation.

The overlap blocker remains unresolved, so I cannot approve this PR yet. I fetched current heads for #11033 and #10861 and reran git merge-tree --write-tree refs/review/11033 refs/review/10861; the composition still has a content conflict in core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp. This PR's body says either branch can rebase over the other, but it does not record an agreed order or a Depends on entry. Please coordinate the order with #10861's author, declare the resulting dependency, then rebase and run the focused test on the chosen composition. This is the only blocker I found; it is a repository coordination requirement, not a defect in the unsigned-address change.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5643892239 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11033#pullrequestreview-5643892239). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T15:35:52Z. **Review:** CHANGES_REQUESTED --- The focused regression passes locally: I configured the relinker-only Release build, built `relinker_conversion_tests`, and ran `ctest -R '^relinker_conversion$'` (1/1 passed). The code change and its boundary test look sound in isolation. The overlap blocker remains unresolved, so I cannot approve this PR yet. I fetched current heads for #11033 and #10861 and reran `git merge-tree --write-tree refs/review/11033 refs/review/10861`; the composition still has a content conflict in `core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp`. This PR's body says either branch can rebase over the other, but it does not record an agreed order or a `Depends on` entry. Please coordinate the order with #10861's author, declare the resulting dependency, then rebase and run the focused test on the chosen composition. This is the only blocker I found; it is a repository coordination requirement, not a defect in the unsigned-address change.
MarcZX10 commented 2026-10-25 15:36:00 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T15:36:00Z.

Review: DISMISSED


The focused regression passes locally: I configured the relinker-only Release build, built relinker_conversion_tests, and ran ctest -R '^relinker_conversion$' (1/1 passed). The code change and its boundary test look sound in isolation.

The overlap blocker remains unresolved, so I cannot approve this PR yet. I fetched current heads for #11033 and #10861 and reran git merge-tree --write-tree refs/review/11033 refs/review/10861; the composition still has a content conflict in core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp. This PR's body says either branch can rebase over the other, but it does not record an agreed order or a Depends on entry. Please coordinate the order with #10861's author, declare the resulting dependency, then rebase and run the focused test on the chosen composition. This is the only blocker I found; it is a repository coordination requirement, not a defect in the unsigned-address change.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5643893039 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11033#pullrequestreview-5643893039). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-25T15:36:00Z. **Review:** DISMISSED --- The focused regression passes locally: I configured the relinker-only Release build, built `relinker_conversion_tests`, and ran `ctest -R '^relinker_conversion$'` (1/1 passed). The code change and its boundary test look sound in isolation. The overlap blocker remains unresolved, so I cannot approve this PR yet. I fetched current heads for #11033 and #10861 and reran `git merge-tree --write-tree refs/review/11033 refs/review/10861`; the composition still has a content conflict in `core/relinker/relinker/src/analysis/CodeInstructionCollector.cpp`. This PR's body says either branch can rebase over the other, but it does not record an agreed order or a `Depends on` entry. Please coordinate the order with #10861's author, declare the resulting dependency, then rebase and run the focused test on the chosen composition. This is the only blocker I found; it is a repository coordination requirement, not a defect in the unsigned-address change.
copilot-pull-request-reviewer[bot] commented 2026-10-25 20:56:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-10-25T20:56:55Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5645266388 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11033#pullrequestreview-5645266388). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-10-25T20:56:55Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!11033
No description provided.