recomp_census: fix UNW_FLAG_CHAININFO/CountOfCodes and decode .xdata unwind ops (RECOMP-CENSUS-XDATA-UNWIND) #1249
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1249"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by quietfold on 2026-11-24T20:51:56Z.
What changed
Fixes two x64
.xdataUNWIND_INFOheader bugs intools/recomp_census.pyand adds fullUNWIND_CODEdecoding andUNW_FLAG_CHAININFOchain walking to report the SEH / frame-layout breakdown needed bydocs/mobile.mdNext Step #3 (arm64 SEH / unwind translation):Bug fixes in
tools/recomp_census.pyUNW_FLAG_*bitmask (UNW_FLAG_NAMES):UNW_FLAG_CHAININFOis0x4(per Microsoft x64 exception handling / LLVMWin64EH.h), not0x8(0x4was previously mislabelledFHANDLER, so real chained unwind entries were misreported asFHANDLERandCHAINEDwas never reported).CountOfCodes(unwind_flags):UNWIND_INFObyte 1 isSizeOfPrologand byte 2 isCountOfCodes;unwind_flags()previously returned byte 1 ascode_count..xdataunwind decoder & census (tools/recomp_census.py)parse_unwind_info(img, unwind_rva)decoding all 11 x64UNWIND_CODEopcodes (0..10:UWOP_PUSH_NONVOL,UWOP_ALLOC_LARGE2- and 3-slot forms,UWOP_ALLOC_SMALL,UWOP_SET_FPREG,UWOP_SAVE_NONVOL,UWOP_SAVE_NONVOL_FAR, v2UWOP_EPILOG,UWOP_SPARE_CODE,UWOP_SAVE_XMM128,UWOP_SAVE_XMM128_FAR,UWOP_PUSH_MACHFRAME), verified against LLVMWin64EH.h/Win64EHDumper.cppand Microsoft CoreCLRamd64/unwinder.cpp.((CountOfCodes + 1) & ~1) * 2before trailingExceptionHandlerRVA or chainedRUNTIME_FUNCTION.UNW_FLAG_CHAININFOchains with cycle detection and bounded depth (MAX_UNWIND_CHAIN = 64), aggregating fixed stack allocation, saved nonvolatile GPRs/XMMs, frame register/offset, epilog counts, and primary handler RVA..xdatarecords cleanly viaerrorwithout crashing."unwind"breakdown tocensus()JSON output and an## Unwind (.xdata) detailssection toto_markdown()while keeping all existing JSON keys and Markdown headings backwards-compatible.tests/test_recomp_census_unwind.py(17 unit tests using synthetic byte-built PE32+ fixtures, no game data).main(), the file docstring, andtests/test_recomp_census.pyuntouched so this merges cleanly with open PR #1088 (RECOMP-CENSUS-WRONG-INPUT).Item ID
RECOMP-CENSUS-XDATA-UNWINDVerification
Tested on macOS 27.2.1 (Apple M5 arm64), Python 3.14 (no game files, no GPU, standard library only):
python3 -I tests/test_recomp_census.py -v-> 7/7 OKpython3 -I tests/test_recomp_census_unwind.py -v-> 17/17 OKtools/recomp_census.pytoupstream/mainwhile keepingtests/test_recomp_census_unwind.py) -> FAILED (3 failures, 23 errors), directly provingFHANDLER != CHAINED,12 != 0(SizeOfPrologvsCountOfCodes), and0x8falsely flagged asCHAINEDonmain.RECOMP-CENSUS-WRONG-INPUT): auto-merged with 0 conflicts, running 11/11test_recomp_census.py+ 17/17test_recomp_census_unwind.py(28/28 OK).python3 -m compileall -q tools/recomp_census.py tests/test_recomp_census.py tests/test_recomp_census_unwind.py-> OKpython3 -I scripts/check_no_game_data.py tools/recomp_census.py tests/test_recomp_census_unwind.py-> OKpython3 -I tests/test_ci_registration.py-> 15/15 OK (new test file selected by CI stdlib loop)python3 -I tests/test_text_write_line_endings.py-> 3/3 OKChecklist
Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-24T20:52:09Z.
Review: COMMENTED
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
Imported from ubiquitarianism/leonida. Originally posted by kevincommits on 2026-11-26T05:01:32Z.
Independent run. Apple M5 Pro, macOS 27.2.1 (26B131), Python 3.14.2, LLVM from Homebrew. I merged
mainata73a57e13into the branch locally (1,001 commits behind;tools/recomp_census.pyauto-merged, no conflicts). Head tested:db3ea85da.On 12 hand-built version-1 unwind records,
parse_unwind_infodecodes exactly whatllvm-readobj --unwinddecodes.Counts on the merged tree.
tests/test_recomp_census_unwind.py17/17,tests/test_recomp_census.py11/11 (same asmain). Full standalone suite: 514 run, 513 pass; the 1 that fails ismain'stest_mod_pack_output_alias.Checked against an independent decoder. I built one PE32+ image with this PR's own
build_pe_with_xdata(12 functions, 12 unwind records, bytes written by hand from the format; no game file), gavellvm-readobja copy with.text/.pdata/.xdatasection headers over the same bytes (it finds unwind data by section name), and compared operation by operation:push+smallALLOC_SMALL32,PUSH_NONVOLrbxlarge16/large32ALLOC_LARGE256 (scaled 16-bit) / 0x20040 (unscaled 32-bit)fpregSET_FPREGrbp with frame offset 0x20,PUSH_NONVOLrbpsave_nonvol/save_nonvol_farsave_xmm/save_xmm_farmachframePUSH_MACHFRAMEwith error codeehandler_odduhandler_evenall_regsPUSH_NONVOLfor all 16 registersSo slot counts, the ×8 and ×16 scaling, the even-slot padding before the handler RVA and the register numbering all match.
The two header fixes are right by the format.
UNW_FLAG_CHAININFOis 0x4 (mainhas 0x4 asFHANDLERand 0x8 asCHAINED), andCountOfCodesis byte 2 (mainreturns byte 1, the prolog size).Not tested against a reference: version-2 records (
UWOP_EPILOG,UWOP_SPARE_CODE), chained records and the cycle/depth limits, which are covered only by the PR's own tests. No game files used. AI-assisted.Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T22:21:52Z.
#1249 | head
db3ea85daf(merged cleanly with mainc7753ed98a) |python -I tests/test_recomp_census_unwind.py -v+python -I tests/test_recomp_census.py -v| red on main:FAILED (failures=3, errors=23)(recomp_census.unwind_flagsreadSizeOfPrologfrom byte 1 instead ofCountOfCodesfrom byte 2, mapped bit0x4toFHANDLERinstead ofUNW_FLAG_CHAININFO/CHAINED, and lackedparse_unwind_info) | green on PR+main:17 ran, OK(test_recomp_census_unwind.py) +11 ran, OK(test_recomp_census.py) | Windows 11 (10.0.26200.9974), Python 3.12.10 | AI-assisted: yesAudited
db3ea85daf(tools/recomp_census.pyandtests/test_recomp_census_unwind.py) on Windows 11, verifyingUNW_FLAG_CHAININFO = 0x4, byte-2CountOfCodes, all x64.xdataUNWIND_CODEopcodes (0..10, including multi-slotUWOP_ALLOC_LARGE,UWOP_SAVE_NONVOL*,UWOP_SAVE_XMM128*,UWOP_SPARE_CODE, and v2UWOP_EPILOG), even-slot alignment padding before exception-handler RVAs and chainedRUNTIME_FUNCTIONtrailers, and cycle/depth bounds (MAX_UNWIND_CHAIN = 64). Also verifiedtests/test_ci_registration.py(stdlibjob selection),tests/test_text_write_line_endings.py, andscripts/check_no_game_data.py.Imported from ubiquitarianism/leonida. Originally posted by enlight3d on 2026-11-29T00:44:46Z.
Independent run of #1249 (python -I, no build, no game; GPU not used).
db3ea85daf829530dbd0(PR merged into it locally withgit merge --no-ff, clean, onlytools/recomp_census.pyand the new test touched)Commands (one process each, from the repo root):
python -I tests/test_recomp_census_unwind.py,python -I tests/test_recomp_census.py, plustest_ci_registration.py,test_text_write_line_endings.py,test_tool_stdout_encoding.py,test_check_no_game_data.py,test_docs_repo_paths.py.tools/recomp_census.pyreverted to main and the new test kept: FAILED (failures=3, errors=23). The failures are the two header fixes (CHAINEDreported for a record that has no chain flag; aCountOfCodesof 12 where 0 is expected, i.e. byte 1 read instead of byte 2;FHANDLERwhereCHAINEDis expected), the errors are the missingparse_unwind_infoand the missing flag constants. So it is a behaviour red for the two bug fixes plus a new-feature red for the decoder.test_recomp_census_unwind.py17/17 OK,test_recomp_census.py7/7 OK (the head branch is based on an older main, which has 7 tests there).test_recomp_census_unwind.py17/17 OK,test_recomp_census.py11/11 OK, ci_registration 18/18, line endings 3/3, check_no_game_data 21 (2 skipped), docs_repo_paths 5/5.test_tool_stdout_encoding.pyfails identically on plain main and merged (same list:tools/pc_prompt_glyphs.py,tools/xbox_prompt_glyphs.py,scripts/bench_translate.py,scripts/export_old_pr_manifest.py), so it is pre-existing; this PR adds no entry to it.Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-29T00:53:16Z.
Merged after enlight3d's red/green check (check) (RTX 3090, driver 621.40, Windows 11) and a local re-check here. Merged after local re-verification: this PR merged onto
maina3484ceebwithout conflict, and its test file(s) (tests/test_recomp_census_unwind.py) pass there. Earlier today the same tests failed onmainwithout the PR (red/green) and a bundle with other open PRs showed no new failures.check_no_game_data.pyis clean. Windows 11, Python 3.14; no GPU needed for these tests.AI-assisted (Claude Code, Claude Opus 5.5), merged for MoonEyes.