tools: compare relocated jump-table destinations alongside ctxdiff #676

Merged
coah80 merged 1 commits from agent/bittle/audit-jump-relocations into main 2026-10-01 23:58:25 +00:00
coah80 commented 2026-10-01 23:55:22 +00:00 (Migrated from github.com)

Scope

Add an optional, standalone jump_table_diff.py and 20 focused tests. No game source, symbol sizes, splits, report metrics, CI, or existing tool exit codes change.

The SD dispatch corrections in #623 showed why instruction-exact functions still need their jump-table relocations checked. This helper follows corresponding function-relative code relocations to locate the source table, rather than assuming equal data-section offsets. It normalizes section-relative/function-relative destinations and checks entry counts, relocation kinds and destinations. Ambiguous or unsupported input is rejected.

Usage: python tools/decomp-assist/jump_table_diff.py <unit> <function> [--table <reference-symbol>]

Exit 0: all selected tables match, including an explicitly reported zero-table result. Exit 1: destination/count mismatch. Exit 2: invalid or ambiguous input. Only local jumptable_* tables wholly targeting the selected function are automatically selected; callback tables and vtables are outside its scope. This does not establish behavioral equivalence or instruction correctness: run ctxdiff separately. No existing consumers are changed.

Verification

Rebased and built on fbecedd948. Connector tree exactly matches the locally tested tree 9c3dd215c36b9be1ec9387a171a54bebd01ea4f9.

  • New tests: 20/20, including shifted source layouts, section-relative relocations, missing/extra entries, ambiguous extents, and CLI exit statuses
  • Existing pool_diff tests: 8/8; workflow guards: 7/7
  • Historical pre-#623 SDChannelSelect calcNormal object: 0/30 entries, correctly exits 1 despite instruction-exact code
  • Fixed SDChannelSelect calcNormal: 30/30; GCWindow onMemEvent: 22/22; tiInputForm setLanguage: 10/10; corrected SDTitle calcNormal: 31/31
  • Full 43U all_source, progress/report and build/43U/ok pass
  • main.dol SHA1: 26116613f624061ba99c8d1a299aaa6efa85670d
  • git diff --check and both worktree checks pass

This is a verification-tool PR, not a new decompilation or claim of whole-project completion. No original binaries or extracted assembly are included.

Note

Add jump_table_diff CLI tool for comparing relocated jump-table destinations

Adds a new decomp-assist tool that compares relocated jump-table destinations between source and reference PowerPC ELF32 objects under build/43U/src and build/43U/obj.

  • The tool takes a unit and function, optionally restricts comparison to one reference table, and otherwise auto-selects all jumptable_ symbols whose entries resolve into the selected function.
  • Source jump-table locations are inferred from matching function relocations rather than assumed section layouts; ambiguous or inconsistent mappings are rejected.
  • Comparison detects differing destinations, unresolved entries, and source/reference length mismatches. See jump_table_diff.py and the test suite in test_jump_table_diff.py.
  • Behavioral Change: CLI exits 0 for matches, 1 for mismatches, and 2 for invalid input or parse errors.

Macroscope summarized 4ce9979.

## Scope Add an optional, standalone jump_table_diff.py and 20 focused tests. No game source, symbol sizes, splits, report metrics, CI, or existing tool exit codes change. The SD dispatch corrections in #623 showed why instruction-exact functions still need their jump-table relocations checked. This helper follows corresponding function-relative code relocations to locate the source table, rather than assuming equal data-section offsets. It normalizes section-relative/function-relative destinations and checks entry counts, relocation kinds and destinations. Ambiguous or unsupported input is rejected. Usage: `python tools/decomp-assist/jump_table_diff.py <unit> <function> [--table <reference-symbol>]` Exit 0: all selected tables match, including an explicitly reported zero-table result. Exit 1: destination/count mismatch. Exit 2: invalid or ambiguous input. Only local jumptable_* tables wholly targeting the selected function are automatically selected; callback tables and vtables are outside its scope. This does not establish behavioral equivalence or instruction correctness: run ctxdiff separately. No existing consumers are changed. ## Verification Rebased and built on fbecedd9488df1b88689afb2cc06a70677c6ee8e. Connector tree exactly matches the locally tested tree 9c3dd215c36b9be1ec9387a171a54bebd01ea4f9. - New tests: 20/20, including shifted source layouts, section-relative relocations, missing/extra entries, ambiguous extents, and CLI exit statuses - Existing pool_diff tests: 8/8; workflow guards: 7/7 - Historical pre-#623 SDChannelSelect calcNormal object: 0/30 entries, correctly exits 1 despite instruction-exact code - Fixed SDChannelSelect calcNormal: 30/30; GCWindow onMemEvent: 22/22; tiInputForm setLanguage: 10/10; corrected SDTitle calcNormal: 31/31 - Full 43U all_source, progress/report and build/43U/ok pass - main.dol SHA1: 26116613f624061ba99c8d1a299aaa6efa85670d - git diff --check and both worktree checks pass This is a verification-tool PR, not a new decompilation or claim of whole-project completion. No original binaries or extracted assembly are included. <!-- Macroscope's pull request summary starts here --> <!-- Macroscope will only edit the content between these invisible markers, and the markers themselves will not be visible in the GitHub rendered markdown. --> <!-- If you delete either of the start / end markers from your PR's description, Macroscope will append its summary at the bottom of the description. --> > [!NOTE] > ### Add `jump_table_diff` CLI tool for comparing relocated jump-table destinations > Adds a new decomp-assist tool that compares relocated jump-table destinations between source and reference PowerPC ELF32 objects under `build/43U/src` and `build/43U/obj`. > - The tool takes a unit and function, optionally restricts comparison to one reference table, and otherwise auto-selects all `jumptable_` symbols whose entries resolve into the selected function. > - Source jump-table locations are inferred from matching function relocations rather than assumed section layouts; ambiguous or inconsistent mappings are rejected. > - Comparison detects differing destinations, unresolved entries, and source/reference length mismatches. See [jump_table_diff.py](https://github.com/coah80/wii-ipl/pull/676/files#diff-58967cd7d07e8e7441f49e90a728a4f1022e788bc80b0d14968edbdf21c5d3da) and the test suite in [test_jump_table_diff.py](https://github.com/coah80/wii-ipl/pull/676/files#diff-58b4189fe59bdf46f2408e06fb743321e7caf69b28ecb166d2b777ff2e5000fb). > - Behavioral Change: CLI exits 0 for matches, 1 for mismatches, and 2 for invalid input or parse errors. > > <!-- Macroscope's review summary starts here --> > > <sup><a href="https://app.macroscope.com">Macroscope</a> summarized 4ce9979.</sup> > <!-- Macroscope's review summary ends here --> > <!-- Macroscope's pull request summary ends here -->
coah80 commented 2026-10-01 23:57:26 +00:00 (Migrated from github.com)

Rebased the same two-file patch onto d4cdae2177 after main advanced during publication. New head 4ce997995d16a366cc5994a79bb1d40da4da1044; remote tree 618ab2e060 matches the tested local tree. Re-ran all_source/progress/report/ok and 20 tests; DOL SHA1 remains 26116613f624061ba99c8d1a299aaa6efa85670d. Broader inferred-location audit now checks 139 eligible jump tables across 62 table-containing units with no remaining mismatch or inference error among exact-name-100% functions. This audit is selective, not a claim that all data is exact.

Rebased the same two-file patch onto d4cdae21779d437d6c23a9e4e6b26e67f271eb47 after main advanced during publication. New head 4ce997995d16a366cc5994a79bb1d40da4da1044; remote tree 618ab2e060f9a4e35cf90a360406c00ba81169aa matches the tested local tree. Re-ran all_source/progress/report/ok and 20 tests; DOL SHA1 remains 26116613f624061ba99c8d1a299aaa6efa85670d. Broader inferred-location audit now checks 139 eligible jump tables across 62 table-containing units with no remaining mismatch or inference error among exact-name-100% functions. This audit is selective, not a claim that all data is exact.
coah80 commented 2026-10-01 23:58:22 +00:00 (Migrated from github.com)

Reviewed and merged: rebased on main, full build ok, DOL sha1 26116613f624061ba99c8d1a299aaa6efa85670d, 0 regressions, 0 forbidden patterns.

Reviewed and merged: rebased on main, full build ok, DOL sha1 26116613f624061ba99c8d1a299aaa6efa85670d, 0 regressions, 0 forbidden patterns.
Sign in to join this conversation.