fix(relinker): preserve inputs when writing Windows diagnostics #4338

Merged
ArjenS-LA merged 1 commit from upstream-pr/4338 into main 2026-10-12 15:52:19 +00:00
ArjenS-LA commented 2026-10-12 07:01:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ArjenS-LA on 2026-10-12T07:01:13Z.


What

--windows --windows-diagnostics writes windows-diagnostics-imports.txt in the current directory. If that path names the input executable or aliases a bundled module, conversion currently succeeds after truncating the source file. Add this report to the existing input/output collision preflight, before registry, module or executable output is written. The check uses the same file-identity comparison as other outputs, so hard links and symbolic links are covered.

Reproducer: create the existing main_fixture() ELF as windows-diagnostics-imports.txt, then run from that directory:

relinker --windows --windows-diagnostics --skip-sce-module windows-diagnostics-imports.txt output.exe

Before: exit 0, the 32,768-byte input becomes empty. After: exit 2 with Windows import diagnostics output would overwrite the input executable, and the input remains byte-for-byte unchanged. The regression also covers bundled modules, hard links, optional registry output, and existing outputs that must remain untouched. Separate diagnostics files still get written or replaced; an input named like the report remains valid when diagnostics are disabled.

Checked current open PR file inventory and related issues/PR discussions. #3970, #4140 and #4194 touch other parts of main.cpp; none adds this preflight. Open usage-document changes affect other paragraphs/options. Merged #3495 and #3678 establish the existing registry/desktop collision behavior that this change extends. No dependency on those open PRs.

Branch: fix/diagnostic-input-preservation. Base: d06c06565717961104edecdab46ce61c8cc72a70. Fixed commit: 4b6bb2f05928d8026d89459b22d3cba0a532ac6d.

Tested

Windows 11 x64 (build 26200), supported WinLibs MinGW-w64 GCC 15.2.0 UCRT/POSIX/SEH r7, CMake 4.3.1, Ninja 1.13.2, Python 3.13.7. Synthetic ELF fixtures exercise the relinker executable and actual filesystem writes; no title, GPU, Linux/macOS guest execution or full library build was used for this fix.

Configured unchanged baseline 2ccbd376f86a0ab2dafca98749585e281f37d599 into build-relinker-baseline and built its relinker target before modifying the C++ source. Configured the fixed tree separately into build-relinker:

cmake -S . -B build-relinker -G Ninja -DCMAKE_BUILD_TYPE=Release -DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON -DCMAKE_CXX_COMPILER=g++ -DPython3_EXECUTABLE=C:/Users/arjen/AppData/Local/Temp/anyps5-toolchain/python/python.exe
cmake --build build-relinker --parallel 4
python core/relinker/relinker/tests/test_input_preservation.py build-relinker-baseline/core/relinker/relinker.exe
python core/relinker/relinker/tests/test_input_preservation.py build-relinker/core/relinker/relinker.exe
ctest --test-dir build-relinker -N
ctest --test-dir build-relinker --output-on-failure --parallel 4 -E "pr_overlap_encoding|import_audit|conventions_function_bodies|conventions_wrapped_declarations"
git diff --check
  • The same extended regression fails against the unchanged base: conversion returns 0 and overwrites the input instead of rejecting the collision. It passes against the fix (1.66 seconds standalone, 1.70 seconds under CTest).
  • All 118 selected CTest tests pass (17.64 seconds total); input_magic and input_preservation are registered. Four unrelated tooling tests were excluded because their disposable repository fixtures create Git commits, which this local workflow currently disallows. No test timeout was raised.
  • All eight new direct/hard-link collision cases execute, with executable/module inputs and registry enabled/disabled. Four new symbolic-link cases skip because this Windows session lacks symlink privilege (existing symlink cases also skip). Native Linux/macOS execution paths in other tests remain platform-dependent skips; a passing CTest entry does not establish execution of those paths here.
  • Four successful-conversion controls pass, checking a new/existing separate report and disabled diagnostics. Prior executable and registry bytes remain intact on rejected collisions.
  • git diff --check passes. python tools/check_conventions.py --base origin/main passes on the submitted commit. No CI result is claimed.

After fast-forwarding to current main, the targeted regression passed again. Relinker builds reported no work because their sources and build configuration were unchanged. No upstream CI result is claimed.

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 new unimplemented paths)
  • 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 (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes, OpenAI Codex assisted investigation, implementation, validation and this description.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4826012673 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4338). Originally posted by [ArjenS-LA](https://github.com/ArjenS-LA) on 2026-10-12T07:01:13Z. --- ### What `--windows --windows-diagnostics` writes `windows-diagnostics-imports.txt` in the current directory. If that path names the input executable or aliases a bundled module, conversion currently succeeds after truncating the source file. Add this report to the existing input/output collision preflight, before registry, module or executable output is written. The check uses the same file-identity comparison as other outputs, so hard links and symbolic links are covered. Reproducer: create the existing `main_fixture()` ELF as `windows-diagnostics-imports.txt`, then run from that directory: ```text relinker --windows --windows-diagnostics --skip-sce-module windows-diagnostics-imports.txt output.exe ``` Before: exit 0, the 32,768-byte input becomes empty. After: exit 2 with `Windows import diagnostics output would overwrite the input executable`, and the input remains byte-for-byte unchanged. The regression also covers bundled modules, hard links, optional registry output, and existing outputs that must remain untouched. Separate diagnostics files still get written or replaced; an input named like the report remains valid when diagnostics are disabled. Checked current open PR file inventory and related issues/PR discussions. #3970, #4140 and #4194 touch other parts of `main.cpp`; none adds this preflight. Open usage-document changes affect other paragraphs/options. Merged #3495 and #3678 establish the existing registry/desktop collision behavior that this change extends. No dependency on those open PRs. Branch: `fix/diagnostic-input-preservation`. Base: `d06c06565717961104edecdab46ce61c8cc72a70`. Fixed commit: `4b6bb2f05928d8026d89459b22d3cba0a532ac6d`. ### Tested Windows 11 x64 (build 26200), supported WinLibs MinGW-w64 GCC 15.2.0 UCRT/POSIX/SEH r7, CMake 4.3.1, Ninja 1.13.2, Python 3.13.7. Synthetic ELF fixtures exercise the relinker executable and actual filesystem writes; no title, GPU, Linux/macOS guest execution or full library build was used for this fix. Configured unchanged baseline `2ccbd376f86a0ab2dafca98749585e281f37d599` into `build-relinker-baseline` and built its `relinker` target before modifying the C++ source. Configured the fixed tree separately into `build-relinker`: ```text cmake -S . -B build-relinker -G Ninja -DCMAKE_BUILD_TYPE=Release -DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON -DCMAKE_CXX_COMPILER=g++ -DPython3_EXECUTABLE=C:/Users/arjen/AppData/Local/Temp/anyps5-toolchain/python/python.exe cmake --build build-relinker --parallel 4 python core/relinker/relinker/tests/test_input_preservation.py build-relinker-baseline/core/relinker/relinker.exe python core/relinker/relinker/tests/test_input_preservation.py build-relinker/core/relinker/relinker.exe ctest --test-dir build-relinker -N ctest --test-dir build-relinker --output-on-failure --parallel 4 -E "pr_overlap_encoding|import_audit|conventions_function_bodies|conventions_wrapped_declarations" git diff --check ``` - The same extended regression fails against the unchanged base: conversion returns 0 and overwrites the input instead of rejecting the collision. It passes against the fix (1.66 seconds standalone, 1.70 seconds under CTest). - All 118 selected CTest tests pass (17.64 seconds total); `input_magic` and `input_preservation` are registered. Four unrelated tooling tests were excluded because their disposable repository fixtures create Git commits, which this local workflow currently disallows. No test timeout was raised. - All eight new direct/hard-link collision cases execute, with executable/module inputs and registry enabled/disabled. Four new symbolic-link cases skip because this Windows session lacks symlink privilege (existing symlink cases also skip). Native Linux/macOS execution paths in other tests remain platform-dependent skips; a passing CTest entry does not establish execution of those paths here. - Four successful-conversion controls pass, checking a new/existing separate report and disabled diagnostics. Prior executable and registry bytes remain intact on rejected collisions. - `git diff --check` passes. `python tools/check_conventions.py --base origin/main` passes on the submitted commit. No CI result is claimed. After fast-forwarding to current main, the targeted regression passed again. Relinker builds reported no work because their sources and build configuration were unchanged. No upstream CI result is claimed. ### 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) (no new unimplemented paths) - [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 (none added) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes, OpenAI Codex assisted investigation, implementation, validation and this description.
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!4338
No description provided.