fix(relinker): preserve inputs behind Windows executable hard links #6328

Merged
aaro56 merged 1 commit from upstream-pr/6328 into main 2026-10-18 23:17:35 +00:00
aaro56 commented 2026-10-15 11:53:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by aaro56 on 2026-10-15T11:53:56Z.


What

On Windows with the supported MinGW-w64 compiler, an output.exe hard link to input.elf passes the relinker's input-overwrite checks. Conversion returns success and replaces the input ELF with the generated PE executable. The same comparison is used for additional executable inputs and bundled modules.

Use the existing SameOutputFile helper for all three input/output comparisons. It already handles the extension-dependent permission mismatch that makes MinGW's std::filesystem::equivalent miss these hard links. Collisions are rejected before any output is written.

Extend the existing input-preservation test with main/secondary outputs aliased to the main executable, a secondary executable, and a bundled module, for Linux and Windows conversion targets. Windows also exercises read-only aliases. Check original bytes, existing outputs, permissions, link counts and temporary-probe cleanup. A positive control confirms that distinct multiply linked files with identical bytes still convert successfully.

The existing helper conservatively rejects ambiguous read-only identities or unwritable probe directories. Record this limitation in relinker technical debt.

Related: #6127 proposes removing the Windows permission-mismatch workaround from SameOutputFile. This fix relies on that workaround; its removal would restore the input-overwrite failure covered by the new regression.

Tested

Windows 11 Home Single Language 10.0.22631, WinLibs MinGW-w64 GCC 15.2.0 x86_64-ucrt-posix-seh r7, Release, relinker-only build, Python 3.13.12.

  • Unmodified main at 5050a23f38ed03e2601804e90e0565b84ca4f1b5: all 167 registered tests passed. The new regression then failed on that original executable; an independent synthetic reproduction returned success and observed the input bytes being overwritten.
  • Fixed build: the input-preservation, primary/secondary output-collision, and additional-executable test groups passed (4/4). The new matrix contains 24 collision cases and one successful distinct-file control on Windows.
  • Updated to main at 6ea62f9b407b766c5adca63b37f63c70170f7612, rebuilt, and passed all 168 registered tests in 50.54 seconds. The input-preservation test completed in 4.06 seconds.
  • Rebased onto fdea36b83667541516affdc8c04fdc39b3496337 before publication. The relinker, its tests and its build inputs are unchanged from the tested tree; the intervening upstream changes concern AGC graphics.
  • tools/check_conventions.py passed against the exact staged tree and PR description. Whitespace and patch applicability checks passed.

Synthetic fixtures only. No retail game, GPU execution, or Linux/macOS host execution. No performance claim.

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; no silent stubs added
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source; no third-party code added
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes — Codex
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4872814767 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6328). Originally posted by [aaro56](https://github.com/aaro56) on 2026-10-15T11:53:56Z. --- ### What On Windows with the supported MinGW-w64 compiler, an `output.exe` hard link to `input.elf` passes the relinker's input-overwrite checks. Conversion returns success and replaces the input ELF with the generated PE executable. The same comparison is used for additional executable inputs and bundled modules. Use the existing `SameOutputFile` helper for all three input/output comparisons. It already handles the extension-dependent permission mismatch that makes MinGW's `std::filesystem::equivalent` miss these hard links. Collisions are rejected before any output is written. Extend the existing input-preservation test with main/secondary outputs aliased to the main executable, a secondary executable, and a bundled module, for Linux and Windows conversion targets. Windows also exercises read-only aliases. Check original bytes, existing outputs, permissions, link counts and temporary-probe cleanup. A positive control confirms that distinct multiply linked files with identical bytes still convert successfully. The existing helper conservatively rejects ambiguous read-only identities or unwritable probe directories. Record this limitation in relinker technical debt. Related: #6127 proposes removing the Windows permission-mismatch workaround from `SameOutputFile`. This fix relies on that workaround; its removal would restore the input-overwrite failure covered by the new regression. ### Tested Windows 11 Home Single Language 10.0.22631, WinLibs MinGW-w64 GCC 15.2.0 `x86_64-ucrt-posix-seh` r7, Release, relinker-only build, Python 3.13.12. - Unmodified `main` at `5050a23f38ed03e2601804e90e0565b84ca4f1b5`: all 167 registered tests passed. The new regression then failed on that original executable; an independent synthetic reproduction returned success and observed the input bytes being overwritten. - Fixed build: the input-preservation, primary/secondary output-collision, and additional-executable test groups passed (4/4). The new matrix contains 24 collision cases and one successful distinct-file control on Windows. - Updated to `main` at `6ea62f9b407b766c5adca63b37f63c70170f7612`, rebuilt, and passed all 168 registered tests in 50.54 seconds. The input-preservation test completed in 4.06 seconds. - Rebased onto `fdea36b83667541516affdc8c04fdc39b3496337` before publication. The relinker, its tests and its build inputs are unchanged from the tested tree; the intervening upstream changes concern AGC graphics. - `tools/check_conventions.py` passed against the exact staged tree and PR description. Whitespace and patch applicability checks passed. Synthetic fixtures only. No retail game, GPU execution, or Linux/macOS host execution. No performance claim. ### 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; no silent stubs added - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source; no third-party code added - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes — Codex
github-actions[bot] commented 2026-10-15 12:18:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T12:18:52Z.


Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5021 docs/dev/debt/relinker.md
PR 6802 core/relinker/main.cpp
PR 6927 core/relinker/main.cpp
PR 6977 docs/dev/debt/relinker.md
PR 7173 docs/dev/debt/relinker.md
PR 7332 core/relinker/main.cpp
docs/dev/debt/relinker.md
PR 7450 core/relinker/main.cpp
docs/dev/debt/relinker.md
PR 7531 docs/dev/debt/relinker.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6191872401 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6328#issuecomment-6191872401). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-15T12:18:52Z. --- <!-- pr-overlap --> Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap. | Pull request | Shared files not compared | |---|---| | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `docs/dev/debt/relinker.md` | | [PR 6802](https://www.github.com/boykopovar/AnyPS5/pull/6802) | `core/relinker/main.cpp` | | [PR 6927](https://www.github.com/boykopovar/AnyPS5/pull/6927) | `core/relinker/main.cpp` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `docs/dev/debt/relinker.md` | | [PR 7173](https://www.github.com/boykopovar/AnyPS5/pull/7173) | `docs/dev/debt/relinker.md` | | [PR 7332](https://www.github.com/boykopovar/AnyPS5/pull/7332) | `core/relinker/main.cpp`<br>`docs/dev/debt/relinker.md` | | [PR 7450](https://www.github.com/boykopovar/AnyPS5/pull/7450) | `core/relinker/main.cpp`<br>`docs/dev/debt/relinker.md` | | [PR 7531](https://www.github.com/boykopovar/AnyPS5/pull/7531) | `docs/dev/debt/relinker.md` |
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!6328
No description provided.