Skip to content

test(relinker): cover branch targets found by the jump-table gap walk - #12243

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
rooklz:test/gap-walk-branch-targets
Nov 2, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
rooklz:test/gap-walk-branch-targets

Conversation

@rooklz

@rooklz rooklz commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

What

Test-only. FindRelativeJumpTables walks code outside the known functions, starting from branch targets, and collects the branch targets it finds there. A data table that one of those targets lands in is not masked. Nothing in the tests checked which targets this gap walk finds: changing how the walk marks positions, or stopping after the first walk, left every test passing (found while reviewing #12203).

CheckGapWalkBranchTargets in ControlFlowGraphTests.cpp builds one layout: a function that leas a table after its end and calls a stub in the gap before it. Four cases:

  • the stub only returns, so the table is still found (control);
  • the stub jumps into the table, so there is no table;
  • the stub jumps into the table after a one-byte push, so there is no table;
  • the stub jmps to a second stub after a ret (reached only through the first stub's target), and that stub jumps into the table, so there is no table.

Tested

macOS 26.2, Apple M5 (arm64), CMake/Ninja, ANYPS5_RELINKER_ONLY=ON, BUILD_TESTING=ON (Python 3.13). Base 82d5f01f28 (upstream/main), head 8f16928a2c: build OK, ctest -j 8 366/366, control_flow_graph 0.03 s.

Mutation probe on RelativeJumpTables.cpp. Each mutant was rebuilt and run through control_flow_graph_tests:

mutant main tests this PR
M5 gap walk stops after the first walk (main) passes fails (chained)
M6 targets found in the gap are not queued (main) passes fails (chained)
M4 on #12203 head 7849e7f69d: the walk also marks pos + 1 decoded passes fails (one-byte)
M5 / M6 on #12203 head passes fails (chained)
unmutated main / #12203 head passes passes

The first version of the chained case put int3 filler between the two stubs. The walk decodes straight through int3, which made that case pass even under M5 and M6, so the first stub now ends with a ret. git merge-tree is clean against #12203 and #11565. The new call goes after CheckLargeZeroGaps() so it stays clear of #11565's hunk in main().

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

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed the added fixtures and the current-main merge CI results. The control stub confirms the table remains discoverable when the gap target returns; direct, post-one-byte, and chained branch targets each verify that code reached through the gap walk is excluded from table discovery. The reported mutation probes exercise the regression modes this test is intended to catch. git diff --check is clean, and the hosted Ubuntu, Windows, macOS arm64, macOS x86_64 and ASan relinker jobs all pass. I found no blocking issue in this test-only change.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new graph fixture covers the control where the gap stub returns, direct branches into the data table, a branch after a one-byte instruction, and a chained gap stub discovered only through an earlier target. The reported mutation probes show the new test catches otherwise-surviving walk/queue regressions, while main and #12203 pass the unmutated case. All current cross-platform relinker and ASan checks pass. Test-only change; no blocking issue found.

@oneandonlydean oneandonlydean self-assigned this Oct 28, 2026
@babyhuey

Copy link
Copy Markdown
Contributor

Windows run of this head 8f16928a2cb, merged onto main 0cd07dc4ab2 (clean merge, local only), with the selection CI's skipped Windows product job uses: Windows 11, Ryzen 7 5800X, RTX 3080, WinLibs GCC 15.2, Release, BUILD_TESTING=ON. The tree was configured fresh after the merge, then select_tests.py select / ninja -f select.ninja selected / --target libs / select_tests.py ctest --parallel 4 --timeout 120.

  • Selected 444 tests: 437 pass, 1 fails, 6 skip. No failures from this PR. The one failure was conventions_ci_gate timing out at 120 s under --parallel 4; rerun alone on the same merged tree it passed 3 of 3 in 51.6-54.0 s, so it's load.

AI-assisted: yes (Claude Code)

@THEMANnt THEMANnt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 8f16928a2cb54ff26bffa48bb2f1e5989fa1b598 against 82d5f01f28b3d63dd811f4424b3d5e4de5845eca. The new gap-walk fixtures distinguish a returning called stub from direct, instruction-prefixed and chained jumps into the proposed data table. This exercises why those branch targets must prevent table classification. Active Require checks remain in Release; no production implementation changes. No actionable finding.

Windows/GCC 15.3 Release: configured the actual relinker-only project, built control_flow_graph_tests and passed its registered CTest (1/1). Production was source-compared with the author base; the baseline fixture was not separately run. This validates synthetic control-flow/table analysis, not title execution.

@rooklz
rooklz force-pushed the test/gap-walk-branch-targets branch from 8f16928 to bacda83 Compare October 30, 2026 11:17
@rooklz
rooklz force-pushed the test/gap-walk-branch-targets branch from bacda83 to 886010a Compare October 30, 2026 11:26
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

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.

Pull request Shared files not compared
PR 10861 core/relinker/relinker/tests/ControlFlowGraphTests.cpp

@oneandonlydean
oneandonlydean merged commit 2a43ad9 into boykopovar:main Nov 2, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants