Skip to content

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

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
ArjenS-LA:fix/diagnostic-input-preservation
Oct 12, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
ArjenS-LA:fix/diagnostic-input-preservation

Conversation

@ArjenS-LA

Copy link
Copy Markdown
Contributor

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.

@oneandonlydean oneandonlydean self-assigned this Oct 12, 2026
@oneandonlydean
oneandonlydean merged commit 57f5ec2 into boykopovar:main Oct 12, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants