Scripts: match record_writers lea length against the stored cursor #1482

Open
microwave805 wants to merge 1 commit from upstream-pr/1492 into main
microwave805 commented 2026-11-24 16:54:18 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by microwave805 on 2026-11-24T16:54:18Z.


When a command-writer site in an objdump AT&T listing advances the record cursor via lea instead of add, scripts/re/record_writers.py ignored which register was written back to 0x18(%L) and matched any lea 0xN(%reg),%reg in the site body. An unrelated lea (for example off %rsp, or into a different register), or a lea whose destination or base pointer was modified before the store (e.g. add %r8,%rdx after lea 0x20(%rax),%rdx), silently overwrote the record length or fabricated a length on variable-length sites.

What is in it

  • scripts/re/record_writers.py: capture the destination register %dst stored by mov %dst,0x18(%L), match only lea 0xN(%P),%dst when %P is untouched beforehand and %dst (including its sub-register aliases) is not overwritten before the store, and drop the unused lea alternation in the add regex.
  • scripts/test_record_writers.py: add synthetic AT&T listing tests covering unrelated lea instructions, intervening register and sub-register writes to %dst (add %r8,%rdx, add $0x8,%edx), earlier mutations of %P, and harmless memory stores through %dst (movl $0x1,-0x4(%rdx)).

Tested

  • NVIDIA GeForce RTX 3070 (driver 32.0.16.1742), AMD Ryzen 5 5600X, Windows 11 Pro (build 22631), DXC 1.9.2602.17 (Windows SDK 10.0.26100.0), Rust 1.100.0 (stable-x86_64-pc-windows-msvc, debug), Python 3.11.3
  • On PR head 424b819:
    • python -I -m unittest discover -s scripts -p "test_*.py" -v: 17 passed, 0 failed
    • .\scripts\test.ps1 (with XCL_DXIL_CACHE=%TEMP%\xcl-test-dxil-cache): 770 passed, 0 failed, 41 ignored
    • SKIPPED GPU tests: gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask, gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware (no wave64)

Regression run

  • Not needed: changes only scripts/re/record_writers.py and scripts/test_record_writers.py (no runtime or build-input files).

Not tested

  • Real XboxBvhBuilder.dll disassembly dump (no console binaries)
  • AMD / wave64 GPUs and retail titles

AI use

  • Antigravity (Gemini 4 Neon): identified the lea matching bug in scripts/re/record_writers.py, added the conservative intervening-write guard per review feedback, wrote the unit tests and PR description, and ran the verification commands above.
<!-- greyfinch-sync:ivall/xcl:issue:5476580761 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1492). Originally posted by [microwave805](https://github.com/microwave805) on 2026-11-24T16:54:18Z. --- When a command-writer site in an objdump AT&T listing advances the record cursor via `lea` instead of `add`, `scripts/re/record_writers.py` ignored which register was written back to `0x18(%L)` and matched any `lea 0xN(%reg),%reg` in the site body. An unrelated `lea` (for example off `%rsp`, or into a different register), or a `lea` whose destination or base pointer was modified before the store (e.g. `add %r8,%rdx` after `lea 0x20(%rax),%rdx`), silently overwrote the record length or fabricated a length on variable-length sites. **What is in it** - `scripts/re/record_writers.py`: capture the destination register `%dst` stored by `mov %dst,0x18(%L)`, match only `lea 0xN(%P),%dst` when `%P` is untouched beforehand and `%dst` (including its sub-register aliases) is not overwritten before the store, and drop the unused `lea` alternation in the `add` regex. - `scripts/test_record_writers.py`: add synthetic AT&T listing tests covering unrelated `lea` instructions, intervening register and sub-register writes to `%dst` (`add %r8,%rdx`, `add $0x8,%edx`), earlier mutations of `%P`, and harmless memory stores through `%dst` (`movl $0x1,-0x4(%rdx)`). **Tested** - NVIDIA GeForce RTX 3070 (driver 32.0.16.1742), AMD Ryzen 5 5600X, Windows 11 Pro (build 22631), DXC 1.9.2602.17 (Windows SDK 10.0.26100.0), Rust 1.100.0 (`stable-x86_64-pc-windows-msvc`, debug), Python 3.11.3 - On PR head `424b819`: - `python -I -m unittest discover -s scripts -p "test_*.py" -v`: 17 passed, 0 failed - `.\scripts\test.ps1` (with `XCL_DXIL_CACHE=%TEMP%\xcl-test-dxil-cache`): 770 passed, 0 failed, 41 ignored - SKIPPED GPU tests: `gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware` (no wave64) **Regression run** - Not needed: changes only `scripts/re/record_writers.py` and `scripts/test_record_writers.py` (no runtime or build-input files). **Not tested** - Real `XboxBvhBuilder.dll` disassembly dump (no console binaries) - AMD / wave64 GPUs and retail titles **AI use** - Antigravity (Gemini 4 Neon): identified the `lea` matching bug in `scripts/re/record_writers.py`, added the conservative intervening-write guard per review feedback, wrote the unit tests and PR description, and ran the verification commands above.
DavidM1911 commented 2026-11-24 19:07:45 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T18:53:30Z.


Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7141297107 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1492#issuecomment-7141297107). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T18:53:30Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified `main`.) Thanks!
RavenCurseBurg commented 2026-11-26 04:31:28 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by RavenCurseBurg on 2026-11-26T04:31:28Z.


Tested 933c7957aa1854b59620444423c6d723c8dc8bfa against a candidate that also includes #1694 and #1730. I passed 16 synthetic AT&T listings to python -B scripts/re/record_writers.py <listing> on each of three revisions. The cases used two register pairs, immediate and list-field headers, and four ways a writer could update or leave its cursor.

The previous combination of #1694/#1730 reported 16 bytes from an unrelated LEA for both a 48-byte record and a variable-length record. The candidate and this PR correctly reported 48 and None respectively. On the candidate, the in-place 40-byte addition still reported 40, both header forms and fallback slot 9 were preserved, and listings with a return before the cursor write produced zero sites.

This head passed its two focused test methods. On the combined candidate, python -B -m unittest discover -s scripts -p "test_*.py" passed all 20 tests with no skips. Windows build 26100, i7-13700, Python 3.14.3. OpenAI Codex (GPT-6) integrated the changes and ran the checks on text inputs. No binary disassembly, game, GPU or Rust run.

Retest of the register-write change on 424b8193c444992e4ac7d45c411fa8519e8fd005

I ran six synthetic CLI fixtures for compare-exchange and ordinary comparison. Four reported a 32-byte length on this head when the stored cursor could have changed. They cover a write to a destination subregister, a memory compare-exchange that can update the accumulator, and both double-width forms that can update the high register. The two controls, a read-only source register and an ordinary comparison, correctly kept the length at 32.

Candidate on this exact PR head. All six cases now return the expected length or None. python -B -m unittest discover -s scripts -p "test_*.py" passed all 18 tests. I also applied the updated register tracking to the existing #1694/#1730 integration branch. All 21 Python tests and the earlier 16 combined CLI cases passed there, including header selection, fallback slot and return-before-store cases.

OpenAI Codex (GPT-6) prepared the candidates and ran these text fixtures on the Windows CPU setup above. No game files, binary disassembly, Rust build or GPU execution were used.

Timestamp-register follow-up

I reproduced the two reported RDTSC cases on 424b8193c444. The synthetic listings covered a clobbered base before the LEA and a clobbered result between the LEA and the cursor store. Across nine RDTSC/RDTSCP cases, the upstream script reported 32 bytes in five cases where the length was unknown. The four positive controls retained their valid 32-byte length.

The updated candidate accounts for both timestamp output registers and RDTSCP’s additional ECX output. All nine CLI cases and all 19 Python tests passed. The updated combined branch passed all 22 Python tests and its earlier 16 CLI checks. OpenAI Codex (GPT-6) ran the checks with synthetic text on the Windows CPU setup above using python -B -m unittest discover -s scripts -p "test_*.py". No title, binary disassembly, GPU or Rust tests were run.

<!-- greyfinch-sync:ivall/xcl:comment:7182669423 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1492#issuecomment-7182669423). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-26T04:31:28Z. --- Tested `933c7957aa1854b59620444423c6d723c8dc8bfa` against [a candidate that also includes #1694 and #1730](https://github.com/RavenCurseBurg/xcl/commit/9782a9ea297496a703829b382056b4613cf3f6af). I passed 16 synthetic AT&T listings to `python -B scripts/re/record_writers.py <listing>` on each of three revisions. The cases used two register pairs, immediate and list-field headers, and four ways a writer could update or leave its cursor. The previous combination of #1694/#1730 reported 16 bytes from an unrelated LEA for both a 48-byte record and a variable-length record. The candidate and this PR correctly reported 48 and `None` respectively. On the candidate, the in-place 40-byte addition still reported 40, both header forms and fallback slot 9 were preserved, and listings with a return before the cursor write produced zero sites. This head passed its two focused test methods. On the combined candidate, `python -B -m unittest discover -s scripts -p "test_*.py"` passed all 20 tests with no skips. Windows build 26100, i7-13700, Python 3.14.3. OpenAI Codex (GPT-6) integrated the changes and ran the checks on text inputs. No binary disassembly, game, GPU or Rust run. **Retest of the register-write change on `424b8193c444992e4ac7d45c411fa8519e8fd005`** I ran six synthetic CLI fixtures for compare-exchange and ordinary comparison. Four reported a 32-byte length on this head when the stored cursor could have changed. They cover a write to a destination subregister, a memory compare-exchange that can update the accumulator, and both double-width forms that can update the high register. The two controls, a read-only source register and an ordinary comparison, correctly kept the length at 32. [Candidate on this exact PR head](https://github.com/RavenCurseBurg/xcl/commit/d0525cf1fac39727f640b2657c2e1efa9d3fd969). All six cases now return the expected length or `None`. `python -B -m unittest discover -s scripts -p "test_*.py"` passed all 18 tests. I also applied the updated register tracking to the [existing #1694/#1730 integration branch](https://github.com/RavenCurseBurg/xcl/commit/d6bb71694f5ea5dfec4ee89394dcbfcbbbea3041). All 21 Python tests and the earlier 16 combined CLI cases passed there, including header selection, fallback slot and return-before-store cases. OpenAI Codex (GPT-6) prepared the candidates and ran these text fixtures on the Windows CPU setup above. No game files, binary disassembly, Rust build or GPU execution were used. **Timestamp-register follow-up** I reproduced [the two reported RDTSC cases](https://github.com/xcl-dev/xcl/pull/1492#issuecomment-7206247925) on `424b8193c444`. The synthetic listings covered a clobbered base before the LEA and a clobbered result between the LEA and the cursor store. Across nine RDTSC/RDTSCP cases, the upstream script reported 32 bytes in five cases where the length was unknown. The four positive controls retained their valid 32-byte length. The [updated candidate](https://github.com/RavenCurseBurg/xcl/commit/0b1cf90b3d3c905f0cc475d30279f3c988c6db8c) accounts for both timestamp output registers and RDTSCP’s additional ECX output. All nine CLI cases and all 19 Python tests passed. The [updated combined branch](https://github.com/RavenCurseBurg/xcl/commit/1dcfa05a1812bf6f23a2120c226620a1717009b4) passed all 22 Python tests and its earlier 16 CLI checks. OpenAI Codex (GPT-6) ran the checks with synthetic text on the Windows CPU setup above using `python -B -m unittest discover -s scripts -p "test_*.py"`. No title, binary disassembly, GPU or Rust tests were run.
luckyteagirl commented 2026-11-26 05:37:54 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by luckyteagirl on 2026-11-26T05:37:54Z.

Review: COMMENTED


Could this trust a matching LEA only if its destination survives unchanged to the cursor store? In the new synthetic AT&T fixture, inserting add %r8,%rdx between lea 0x20(%rax),%rdx and mov %rdx,0x18(%rcx) still reports length 32 B, although the actual cursor advance is 32 + r8 and therefore variable. A conservative guard for intervening writes to %rdx, plus that fixture, would leave the length unknown. Reproduced with the record-writer script at exact head 933c7957aa1854b59620444423c6d723c8dc8bfa; no retail title or GPU run. AI-assisted review with Codex.

<!-- greyfinch-sync:ivall/xcl:review:6069060010 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1492#pullrequestreview-6069060010). Originally posted by [luckyteagirl](https://github.com/luckyteagirl) on 2026-11-26T05:37:54Z. **Review:** COMMENTED --- Could this trust a matching LEA only if its destination survives unchanged to the cursor store? In the new synthetic AT&T fixture, inserting `add %r8,%rdx` between `lea 0x20(%rax),%rdx` and `mov %rdx,0x18(%rcx)` still reports `length 32 B`, although the actual cursor advance is `32 + r8` and therefore variable. A conservative guard for intervening writes to `%rdx`, plus that fixture, would leave the length unknown. Reproduced with the record-writer script at exact head `933c7957aa1854b59620444423c6d723c8dc8bfa`; no retail title or GPU run. AI-assisted review with Codex.
microwave805 commented 2026-11-26 23:44:11 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by microwave805 on 2026-11-26T23:44:11Z.


@luckyteagirl Good point — updated scripts/re/record_writers.py (424b8193c444) to track whether %P was mutated beforehand and whether any instruction between lea 0xN(%P),%dst and mov %dst,0x18(%L) writes %dst (including sub-register aliases, call, xchg/xadd/cmpxchg, and implicit rax/rdx ops while still allowing memory stores through %dst like movl $0x1,-0x4(%rdx)). Added synthetic fixtures for add %r8,%rdx, add $0x8,%edx, pre-lea %P mutation, and memory stores through %dst.

Re-ran python -I -m unittest discover -s scripts -p "test_*.py" -v (17 passed, 0 failed) and .\scripts\test.ps1 (770 passed, 0 failed, 41 ignored, 2 SKIPPED no wave64 on RTX 3070) on 424b819 and updated Tested in the description.

(AI use: Antigravity (Gemini 4 Neon) implemented the guard and tests, ran the suites, and drafted this comment.)

<!-- greyfinch-sync:ivall/xcl:comment:7205807880 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1492#issuecomment-7205807880). Originally posted by [microwave805](https://github.com/microwave805) on 2026-11-26T23:44:11Z. --- @luckyteagirl Good point — updated `scripts/re/record_writers.py` (`424b8193c444`) to track whether `%P` was mutated beforehand and whether any instruction between `lea 0xN(%P),%dst` and `mov %dst,0x18(%L)` writes `%dst` (including sub-register aliases, `call`, `xchg`/`xadd`/`cmpxchg`, and implicit `rax`/`rdx` ops while still allowing memory stores through `%dst` like `movl $0x1,-0x4(%rdx)`). Added synthetic fixtures for `add %r8,%rdx`, `add $0x8,%edx`, pre-`lea` `%P` mutation, and memory stores through `%dst`. Re-ran `python -I -m unittest discover -s scripts -p "test_*.py" -v` (17 passed, 0 failed) and `.\scripts\test.ps1` (770 passed, 0 failed, 41 ignored, 2 `SKIPPED` `no wave64` on RTX 3070) on `424b819` and updated **Tested** in the description. *(AI use: Antigravity (`Gemini 4 Neon`) implemented the guard and tests, ran the suites, and drafted this comment.)*
JJAutoCompare commented 2026-11-27 00:11:21 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by JJAutoCompare on 2026-11-27T00:11:21Z.


Tested: Clean 424b8193c444992e4ac7d45c411fa8519e8fd005 on Windows 11 build 26200, Ryzen 7 3800X and Python 3.13.7 x64. python.exe -I -B -m unittest discover -s scripts -p test_record_writers.py -v: 2 passed, 0 failed, 0 skipped. A supplementary python.exe -I -B verify_cursor.py run compared 11 synthetic AT&T listing cases through the CLI. Head matched 9 expectations and missed 2. Parent b7aa9f3bd212088e0d927439284dc5ed325ce3c7 matched 5 and missed 6. No skips. The candidate corrected the xchg, lock xadd, call, and one-operand mul cases.

Both revisions still reported a 32-byte advance instead of an unknown length in two synthetic controls: rdtsc before a LEA using RAX as its base, and rdtsc after a LEA writing RDX but before the cursor store. The control using R10 and R9 retained 32 bytes, as expected.

Not tested: Rust workspace, GPU, or retail data. Synthetic text fixtures only.

AI use: T3 Code / Codex (gpt-6.2-sol) wrote the supplementary fixtures, ran and reran the checks, and drafted this report.

<!-- greyfinch-sync:ivall/xcl:comment:7206247925 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1492#issuecomment-7206247925). Originally posted by [JJAutoCompare](https://github.com/JJAutoCompare) on 2026-11-27T00:11:21Z. --- **Tested:** Clean `424b8193c444992e4ac7d45c411fa8519e8fd005` on Windows 11 build 26200, Ryzen 7 3800X and Python 3.13.7 x64. `python.exe -I -B -m unittest discover -s scripts -p test_record_writers.py -v`: 2 passed, 0 failed, 0 skipped. A supplementary `python.exe -I -B verify_cursor.py` run compared 11 synthetic AT&T listing cases through the CLI. Head matched 9 expectations and missed 2. Parent `b7aa9f3bd212088e0d927439284dc5ed325ce3c7` matched 5 and missed 6. No skips. The candidate corrected the `xchg`, `lock xadd`, call, and one-operand `mul` cases. Both revisions still reported a 32-byte advance instead of an unknown length in two synthetic controls: `rdtsc` before a LEA using RAX as its base, and `rdtsc` after a LEA writing RDX but before the cursor store. The control using R10 and R9 retained 32 bytes, as expected. **Not tested:** Rust workspace, GPU, or retail data. Synthetic text fixtures only. **AI use:** T3 Code / Codex (`gpt-6.2-sol`) wrote the supplementary fixtures, ran and reran the checks, and drafted this report.
Foniass commented 2026-12-01 05:55:10 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:55:10Z.


Triage (#1607) – head 424b819

No other PR changes the lea length match in scripts/re/record_writers.py. #2049 restructures the same script (CLI handling) but keeps the old lea logic, so the two will conflict but do not overlap.
No problems found in the diff: the lea is now accepted only when it is based on the cursor register, writes the register stored to 0x18(%L), and neither is clobbered in between; the six synthetic cases cover each rule.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7302278184 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1492#issuecomment-7302278184). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T05:55:10Z. --- **Triage (#1607)** – head 424b819 No other PR changes the lea length match in scripts/re/record_writers.py. #2049 restructures the same script (CLI handling) but keeps the old lea logic, so the two will conflict but do not overlap. No problems found in the diff: the lea is now accepted only when it is based on the cursor register, writes the register stored to 0x18(%L), and neither is clobbered in between; the six synthetic cases cover each rule. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1492:upstream-pr/1492'
git switch 'upstream-pr/1492'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1492'
git switch 'upstream-pr/1492'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1492'
git switch 'upstream-pr/1492'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1492'
git switch 'main'
git merge --squash 'upstream-pr/1492'
git switch 'main'
git merge --ff-only 'upstream-pr/1492'
git switch 'main'
git merge 'upstream-pr/1492'
git push origin 'main'
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
xcl-dev/xcl!1482
No description provided.