test(relinker): run the Windows TLS cases on Linux x86-64 #1234

Merged
hashaam1217 merged 1 commit from upstream-pr/1234 into main 2026-10-08 05:21:34 +00:00
hashaam1217 commented 2026-10-07 18:52:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hashaam1217 on 2026-10-07T18:52:58Z.


What

tls_function_coverage builds execution cases (the ALU reads from #767, the displacement loads from #340 and others) that return 42 when every value, register and flag is right. They only run where os.name == "nt"; on Linux the test checks stub bytes, so a stub that is byte-correct but wrong at run time passes the Linux job.

windows_image_runner.py runs a relinked PE on Linux x86-64:

  • maps the image and copies the sections to their RVAs;
  • writes TLS index 0 and gives the thread a block copied from the TLS template plus the zero fill;
  • points GS at a TEB whose ThreadLocalStoragePointer (+0x58) holds that block (arch_prctl(ARCH_SET_GS); glibc does not use GS on x86-64);
  • calls each TLS callback for DLL_PROCESS_ATTACH with the Windows argument registers (rcx, rdx, r8);
  • calls the guest entry (SysV, as on the console) and exits with its result.

convert() runs it on Linux x86-64 where it already runs the .exe on Windows, and expects 42 the same way. Other hosts are unchanged.

Tested

Ubuntu 24.04.5, Python 3.12.3, relinker from main (cea1ef13).

  • test_tls_function_coverage.py passes and now executes every case convert() relinks: 4.9 s, was 0.7 s.
  • Checked that the runner is what makes it pass: with the runner's exit code forced to 0 the test fails (('unwind-table', 0, b'')), and with a wrong TLS index the first case crashes (-11).
  • With #1233 merged on top, its 26 new cases also run and pass this way. That is where the runner came from: the first version of #1233 passed every byte check and crashed on 3- and 4-byte TLS sites.
  • tools/check_conventions.py --base origin/main: passed.
  • Windows was not run; nothing changes there.

#1117 and #1233 also edit this test; both merge without conflict.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4777053870 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1234). Originally posted by [hashaam1217](https://github.com/hashaam1217) on 2026-10-07T18:52:58Z. --- ### What `tls_function_coverage` builds execution cases (the ALU reads from #767, the displacement loads from #340 and others) that return 42 when every value, register and flag is right. They only run where `os.name == "nt"`; on Linux the test checks stub bytes, so a stub that is byte-correct but wrong at run time passes the Linux job. `windows_image_runner.py` runs a relinked PE on Linux x86-64: - maps the image and copies the sections to their RVAs; - writes TLS index 0 and gives the thread a block copied from the TLS template plus the zero fill; - points `GS` at a TEB whose `ThreadLocalStoragePointer` (`+0x58`) holds that block (`arch_prctl(ARCH_SET_GS)`; glibc does not use `GS` on x86-64); - calls each TLS callback for `DLL_PROCESS_ATTACH` with the Windows argument registers (`rcx`, `rdx`, `r8`); - calls the guest entry (SysV, as on the console) and exits with its result. `convert()` runs it on Linux x86-64 where it already runs the `.exe` on Windows, and expects 42 the same way. Other hosts are unchanged. ### Tested Ubuntu 24.04.5, Python 3.12.3, relinker from `main` (`cea1ef13`). - `test_tls_function_coverage.py` passes and now executes every case `convert()` relinks: 4.9 s, was 0.7 s. - Checked that the runner is what makes it pass: with the runner's exit code forced to 0 the test fails (`('unwind-table', 0, b'')`), and with a wrong TLS index the first case crashes (`-11`). - With #1233 merged on top, its 26 new cases also run and pass this way. That is where the runner came from: the first version of #1233 passed every byte check and crashed on 3- and 4-byte TLS sites. - `tools/check_conventions.py --base origin/main`: passed. - Windows was not run; nothing changes there. #1117 and #1233 also edit this test; both merge without conflict. ### Checklist - [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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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!1234
No description provided.