test(relinker): verify entry-stub bounds before allocation #7704

Closed
rajvveer wants to merge 2 commits from upstream-pr/7704 into main
rajvveer commented 2026-10-19 01:49:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rajvveer on 2026-10-19T01:49:55Z.


What

The runtime boundary test in #6204 passes with and without its allocation guard. The separate CMake test searches for literal source strings, so it cannot establish that the guard runs before resize.

Depends on #6204 (included). The first commit, 26375a30ef, is @vrebel11's production guard rebased onto main, with authorship preserved. My contribution is the second commit, 36eeec6bb5: test coverage and registration only. This remains a draft for coordinating the follow-up while #6204 is open; the test commit can also be cherry-picked into #6204.

  • Replace the source-text guard with a runtime check. A test-only operator new records the largest allocation, following UseRewriteAllocation.cpp. With 4096 bytes left below INT32_MAX, the builder must reject the 64 KiB startup buffer before allocating it.
  • Keep successful controls at a low RVA and within 1 MiB of INT32_MAX. Use WindowsImportBuilder for the imports instead of a second list of function names.
  • Register windows_entry_stub_bounds on every host, with a 20-second timeout. Remove WindowsEntryStubEndpointGuard.cmake and its registration; fix the trailing newline and spacing.

This addresses the review on #6204. It does not establish a fix for the intermittent GCC crash in #5927.

Tested

Windows x64, WinLibs GCC 15.2.0 r7 UCRT/POSIX, Ninja 1.13.2, Python 3.14.2; relinker-only builds with BUILD_TESTING=ON.

  • Fresh full Release run: PR head 3a416dd952 merged with main 25648aa121 in a separate checkout (8b378bd976). Fresh configure and full build passed without compiler warnings. Serial CTest completed in 304.53 s: 203 passed, 0 failed, 1 skipped out of 204. No concurrent build/test job was started. windows_dependency_diagnostics, guest_module_identity and windows_import_modules all passed in this run.
  • Regression controls: unchanged main fails with The entry stub allocated past the RVA limit before rejecting it. Moving the endpoint check after resize also fails with that message. Restoring the guard passes, including the high-RVA control. Debug with _GLIBCXX_ASSERTIONS passes entry_stub and windows_entry_stub_bounds, 2/2. Both new source files pass -Wall -Wextra -Wpedantic -Werror syntax checks.
  • Unchanged successful output: a synthetic Windows PE conversion is byte-identical before and after the guard, SHA256 8c1c8a24b8fb57d62a2ea0b06ab9551d848e1f1f5fa4e9828b4edb7c40b7783f.
  • Publication rebase: head 36eeec6bb5 is based on main 8a526d4495. Compared with the fully tested integration, core/relinker, root CMake, cmake, tools and the build workflow are unchanged. The exact rebased commit has not received another full suite run. Conventions and whitespace checks pass.
  • Independent review: a separate AI review agent inspected the guard, connected PE caller, allocator instrumentation, test registration and recorded evidence. It found no blocking defect. It did not rerun tests; the 203-pass result above is the actual full run.

Earlier, on base 017f2151ca, a parallel 204-test run that overlapped a Debug build had 200 passes, three timeouts and one skip. The three tests named above then passed serially on both unchanged main and the fix, and passed again in the fresh full serial run. The cause of the parallel failures remains unestablished, so parallel CI stability is not claimed.

long_paths skips because this host's LongPathsEnabled is not 1. No Windows or antivirus settings were changed. Linux/macOS execution and upstream build checks remain pending. No full runtime, title, GPU, performance or exhaustive PE-validation claim is made; the vector-capacity branch was inspected, not forced through an impractically large public input.

Overlap review: the required tools/pr_overlap.py run completed serially after refreshing a partial-clone object fetch. It reported the expected overlap with included #6204. The shared-file diffs it could not compare were inspected for #2780, #5021, #5138, #6044, #6802, #6879, #6977, #7173, #7332, #7450, #7531 and #7594; #6586 was inspected when the bot subsequently added it. They add other sources/tests or change test registration. #6044 would require adapting the new registration if its add_component_test conversion lands first. #7594 changes MXCSR handling around the guest entry call, away from the allocation guard. #6586 adds a separate guest_zero_initializer registration. No additional prerequisite was identified; no combined runtime result is claimed.

Checklist

  • Based on current main; no other open PR implements the same functions (own test-only follow-up; #6204 is the included prerequisite)
  • 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: #6204 (included; production commit credited above)
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (OpenAI Codex)
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4914695220 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7704). Originally posted by [rajvveer](https://github.com/rajvveer) on 2026-10-19T01:49:55Z. --- ### What The runtime boundary test in #6204 passes with and without its allocation guard. The separate CMake test searches for literal source strings, so it cannot establish that the guard runs before `resize`. **Depends on #6204 (included).** The first commit, `26375a30ef`, is @vrebel11's production guard rebased onto `main`, with authorship preserved. My contribution is the second commit, [`36eeec6bb5`](https://github.com/rajvveer/AnyPS5/commit/36eeec6bb5e421a3d705469af90398dc87749830): test coverage and registration only. This remains a draft for coordinating the follow-up while #6204 is open; the test commit can also be cherry-picked into #6204. - Replace the source-text guard with a runtime check. A test-only `operator new` records the largest allocation, following `UseRewriteAllocation.cpp`. With 4096 bytes left below `INT32_MAX`, the builder must reject the 64 KiB startup buffer before allocating it. - Keep successful controls at a low RVA and within 1 MiB of `INT32_MAX`. Use `WindowsImportBuilder` for the imports instead of a second list of function names. - Register `windows_entry_stub_bounds` on every host, with a 20-second timeout. Remove `WindowsEntryStubEndpointGuard.cmake` and its registration; fix the trailing newline and spacing. This addresses the [review on #6204](https://github.com/boykopovar/AnyPS5/pull/6204#pullrequestreview-5564019852). It does not establish a fix for the intermittent GCC crash in #5927. ### Tested Windows x64, WinLibs GCC 15.2.0 r7 UCRT/POSIX, Ninja 1.13.2, Python 3.14.2; relinker-only builds with `BUILD_TESTING=ON`. - **Fresh full Release run:** PR head `3a416dd952` merged with main `25648aa121` in a separate checkout (`8b378bd976`). Fresh configure and full build passed without compiler warnings. Serial CTest completed in 304.53 s: **203 passed, 0 failed, 1 skipped out of 204**. No concurrent build/test job was started. `windows_dependency_diagnostics`, `guest_module_identity` and `windows_import_modules` all passed in this run. - **Regression controls:** unchanged main fails with `The entry stub allocated past the RVA limit before rejecting it`. Moving the endpoint check after `resize` also fails with that message. Restoring the guard passes, including the high-RVA control. Debug with `_GLIBCXX_ASSERTIONS` passes `entry_stub` and `windows_entry_stub_bounds`, 2/2. Both new source files pass `-Wall -Wextra -Wpedantic -Werror` syntax checks. - **Unchanged successful output:** a synthetic Windows PE conversion is byte-identical before and after the guard, SHA256 `8c1c8a24b8fb57d62a2ea0b06ab9551d848e1f1f5fa4e9828b4edb7c40b7783f`. - **Publication rebase:** head `36eeec6bb5` is based on main `8a526d4495`. Compared with the fully tested integration, `core/relinker`, root CMake, `cmake`, `tools` and the build workflow are unchanged. The exact rebased commit has not received another full suite run. Conventions and whitespace checks pass. - **Independent review:** a separate AI review agent inspected the guard, connected PE caller, allocator instrumentation, test registration and recorded evidence. It found no blocking defect. It did not rerun tests; the 203-pass result above is the actual full run. Earlier, on base `017f2151ca`, a parallel 204-test run that overlapped a Debug build had 200 passes, three timeouts and one skip. The three tests named above then passed serially on both unchanged main and the fix, and passed again in the fresh full serial run. The cause of the parallel failures remains unestablished, so parallel CI stability is not claimed. `long_paths` skips because this host's `LongPathsEnabled` is not 1. No Windows or antivirus settings were changed. Linux/macOS execution and upstream build checks remain pending. No full runtime, title, GPU, performance or exhaustive PE-validation claim is made; the vector-capacity branch was inspected, not forced through an impractically large public input. Overlap review: the required `tools/pr_overlap.py` run completed serially after refreshing a partial-clone object fetch. It reported the expected overlap with included #6204. The shared-file diffs it could not compare were inspected for #2780, #5021, #5138, #6044, #6802, #6879, #6977, #7173, #7332, #7450, #7531 and #7594; #6586 was inspected when the bot subsequently added it. They add other sources/tests or change test registration. #6044 would require adapting the new registration if its `add_component_test` conversion lands first. #7594 changes MXCSR handling around the guest entry call, away from the allocation guard. #6586 adds a separate `guest_zero_initializer` registration. No additional prerequisite was identified; no combined runtime result is claimed. <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions (own test-only follow-up; #6204 is the included prerequisite) - [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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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: #6204 (included; production commit credited above) - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes (OpenAI Codex)
MarcZX10 commented 2026-11-18 12:35:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T12:35:03Z.

Review: APPROVED


Reviewed — looks good

The allocation guard and its runtime boundary test are consistent with the described goal at head 36eeec6bb5e421a3d705469af90398dc87749830; no blocking defect was verified.

What I ran

No build or tests were run. I read the prepared diff and changed-file texts, then inspected CheckedRva to confirm the tested error condition.

Results

Check Result Note
Diff and changed files passed Four changed files read
Runtime tests not run Results in the description are author-reported
Wider platform behavior not run Linux and macOS are unverified

Findings

Blocking

None.

Non-blocking

None.

Not verified

I read all four files listed in manifest.json: core/relinker/CMakeLists.txt, core/relinker/elfpatcher/src/windows/WindowsEntryStubBuilder.cpp, core/relinker/elfpatcher/tests/WindowsEntryStubAllocation.cpp, and core/relinker/elfpatcher/tests/WindowsEntryStubBoundsTests.cpp. I also read core/relinker/elfpatcher/src/windows/WindowsPeFormat.cpp for the CheckedRva behavior. No excluded changed files were listed. Builds, tests, Windows runtime behavior, and Linux/macOS execution were not independently verified.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5956627772 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7704#pullrequestreview-5956627772). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-18T12:35:03Z. **Review:** APPROVED --- # Reviewed — looks good The allocation guard and its runtime boundary test are consistent with the described goal at head `36eeec6bb5e421a3d705469af90398dc87749830`; no blocking defect was verified. ## What I ran No build or tests were run. I read the prepared diff and changed-file texts, then inspected `CheckedRva` to confirm the tested error condition. ## Results | Check | Result | Note | |---|---|---| | Diff and changed files | passed | Four changed files read | | Runtime tests | not run | Results in the description are author-reported | | Wider platform behavior | not run | Linux and macOS are unverified | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified I read all four files listed in `manifest.json`: `core/relinker/CMakeLists.txt`, `core/relinker/elfpatcher/src/windows/WindowsEntryStubBuilder.cpp`, `core/relinker/elfpatcher/tests/WindowsEntryStubAllocation.cpp`, and `core/relinker/elfpatcher/tests/WindowsEntryStubBoundsTests.cpp`. I also read `core/relinker/elfpatcher/src/windows/WindowsPeFormat.cpp` for the `CheckedRva` behavior. No excluded changed files were listed. Builds, tests, Windows runtime behavior, and Linux/macOS execution were not independently verified. ## To get this to a good state Nothing is required.
catminou4 commented 2026-11-25 06:20:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by catminou4 on 2026-11-25T06:20:24Z.

Review: COMMENTED


This change is already in main: merging the branch into current main (3cab484efb) leaves no diff. main has WindowsEntryStubBuilder.cpp's bounds check from e8ade52d79 and the same windows_entry_stub_bounds_tests target from 7482a5a700.

On that merge, on Linux x86_64 (relinker-only Release build, GCC), ctest -R '^(windows_entry_stub_bounds|entry_stub)$' passes.

Nothing left to merge; this can be closed as superseded.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6052755485 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7704#pullrequestreview-6052755485). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T06:20:24Z. **Review:** COMMENTED --- This change is already in `main`: merging the branch into current `main` (3cab484efb) leaves no diff. `main` has `WindowsEntryStubBuilder.cpp`'s bounds check from e8ade52d79 and the same `windows_entry_stub_bounds_tests` target from 7482a5a700. On that merge, on Linux x86_64 (relinker-only Release build, GCC), `ctest -R '^(windows_entry_stub_bounds|entry_stub)$'` passes. Nothing left to merge; this can be closed as superseded.
ligmaSec commented 2026-12-03 13:48:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T13:48:18Z.

Review: COMMENTED


The exact branch passed the Windows entry-stub bounds CTest in a Linux relinker-only build.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6171034538 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7704#pullrequestreview-6171034538). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T13:48:18Z. **Review:** COMMENTED --- The exact branch passed the Windows entry-stub bounds CTest in a Linux relinker-only build. AI-assisted: yes.

Pull request closed

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!7704
No description provided.