fix(relinker): detect output aliases with a filesystem probe outside Windows #6927

Merged
jotitadev merged 1 commit from upstream-pr/6927 into main 2026-10-19 13:54:05 +00:00
jotitadev commented 2026-10-16 19:29:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-16T19:29:17Z.


What

Follow-up from #4802 (listed there by the maintainer): fresh outputs that the volume treats as the same name are not detected outside Windows. The default macOS volume (APFS) is case-insensitive and normalization-insensitive, but the probe in SameOutputDestination and its OutputIdentityDirectory were under #ifdef _WIN32. On macOS, in an empty directory:

relinker --windows --windows-diagnostics --skip-sce-module input.elf WINDOWS-DIAGNOSTICS-IMPORTS.TXT

returned 0 and left one file, windows-diagnostics-imports.txt, holding the PE: the diagnostics were lost. The same happens with --executable outputs named Ä/ä, Ω/ω, Ж/ж and é in NFC/NFD: one executable overwrites the other.

Outside Windows, a text fold cannot match APFS (Unicode case and canonical equivalence), so this asks the filesystem instead: when two not-yet-existing outputs share a directory, it creates the first name inside an OutputIdentityDirectory next to them and checks whether the second name resolves to the same entry, then removes the probe. Case-sensitive volumes report distinct names. The Windows branch is unchanged, so this does not overlap with #6715 (CompareStringOrdinal under _WIN32); the two merge cleanly. OutputIdentityDirectory is now built on every host; the hard-link identity check in SameOutputFile stays Windows-only.

test_output_collisions.py checks the ASCII case-variant collision whenever the work directory is case-insensitive, not only on Windows, and adds a filesystem-probed alias test (A/a, Ä/ä, Ω/ω, Ж/ж, é NFC/NFD, and an Ä/a control) for Linux and Windows output formats. It skips on Windows, where #6715 covers the Unicode cases.

Tested

Apple M2 Max, macOS 27.2, Apple clang, Release relinker-only build on main 5d9dcc42d:

  • Full suite: arm64 173/173 (same as main); x86_64 under Rosetta with Python 3.9.6, 170/173, the same three failures as main (pr_overlap_tools, release_package, linux_fixed_base).
  • tools/check_conventions.py --base origin/main passes.
  • Default APFS: output_collisions fails with main's relinker (exit 0, one output written for every alias pair) and passes with this change on arm64 and x86_64. All five alias pairs now fail with "Output paths collide" and leave no outputs; Ä/a still writes two outputs.
  • Case-sensitive APFS volume (hdiutil create -fs "Case-sensitive APFS", TMPDIR on it): output_collisions, secondary_output_collisions, input_preservation and relinker_executables pass. A/a, Ä/ä, Ω/ω and Ж/ж produce two distinct outputs; é NFC/NFD is still reported as a collision, because APFS stays normalization-insensitive on case-sensitive volumes.
  • Merged with #6715 head 46cafca20: no conflicts; the same four tests pass on macOS.
  • Linux and Windows not run locally. On Linux the probe runs for outputs in the same directory and reports distinct names unless the directory is casefolded, which is what the case-sensitive APFS run checks.

Rebased onto main 1b1f8483c; the files this changes are unchanged since the tested base.

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 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: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4893275946 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6927). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-16T19:29:17Z. --- ### What Follow-up from #4802 (listed there by the maintainer): fresh outputs that the volume treats as the same name are not detected outside Windows. The default macOS volume (APFS) is case-insensitive and normalization-insensitive, but the probe in `SameOutputDestination` and its `OutputIdentityDirectory` were under `#ifdef _WIN32`. On macOS, in an empty directory: ``` relinker --windows --windows-diagnostics --skip-sce-module input.elf WINDOWS-DIAGNOSTICS-IMPORTS.TXT ``` returned 0 and left one file, `windows-diagnostics-imports.txt`, holding the PE: the diagnostics were lost. The same happens with `--executable` outputs named `Ä`/`ä`, `Ω`/`ω`, `Ж`/`ж` and `é` in NFC/NFD: one executable overwrites the other. Outside Windows, a text fold cannot match APFS (Unicode case and canonical equivalence), so this asks the filesystem instead: when two not-yet-existing outputs share a directory, it creates the first name inside an `OutputIdentityDirectory` next to them and checks whether the second name resolves to the same entry, then removes the probe. Case-sensitive volumes report distinct names. The Windows branch is unchanged, so this does not overlap with #6715 (`CompareStringOrdinal` under `_WIN32`); the two merge cleanly. `OutputIdentityDirectory` is now built on every host; the hard-link identity check in `SameOutputFile` stays Windows-only. `test_output_collisions.py` checks the ASCII case-variant collision whenever the work directory is case-insensitive, not only on Windows, and adds a filesystem-probed alias test (A/a, Ä/ä, Ω/ω, Ж/ж, é NFC/NFD, and an Ä/a control) for Linux and Windows output formats. It skips on Windows, where #6715 covers the Unicode cases. ### Tested Apple M2 Max, macOS 27.2, Apple clang, Release relinker-only build on `main` `5d9dcc42d`: - Full suite: arm64 173/173 (same as `main`); x86_64 under Rosetta with Python 3.9.6, 170/173, the same three failures as `main` (`pr_overlap_tools`, `release_package`, `linux_fixed_base`). - `tools/check_conventions.py --base origin/main` passes. - Default APFS: `output_collisions` fails with `main`'s relinker (exit 0, one output written for every alias pair) and passes with this change on arm64 and x86_64. All five alias pairs now fail with "Output paths collide" and leave no outputs; Ä/a still writes two outputs. - Case-sensitive APFS volume (`hdiutil create -fs "Case-sensitive APFS"`, `TMPDIR` on it): `output_collisions`, `secondary_output_collisions`, `input_preservation` and `relinker_executables` pass. A/a, Ä/ä, Ω/ω and Ж/ж produce two distinct outputs; é NFC/NFD is still reported as a collision, because APFS stays normalization-insensitive on case-sensitive volumes. - Merged with #6715 head `46cafca20`: no conflicts; the same four tests pass on macOS. - Linux and Windows not run locally. On Linux the probe runs for outputs in the same directory and reports distinct names unless the directory is casefolded, which is what the case-sensitive APFS run checks. Rebased onto `main` `1b1f8483c`; the files this changes are unchanged since the tested base. ### 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 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: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
simonbbby commented 2026-10-17 00:23:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-17T00:23:39Z.


Independent native Linux coverage for the gap in Tested, plus an APFS before/after control, on exact head 0a8ec7d15a32f960a2b3d78a8f87136a211ff1ef.

Built the real CLI in Release relinker-only mode on Ubuntu 24.04 x86-64 / GCC 13.3 and macOS 27.2 arm64 / AppleClang 21.0.0. The four focused CTests (output_collisions, secondary_output_collisions, input_preservation, relinker_executables) pass on both hosts: 4/4 Linux, 4/4 Mac.

Also ran a parent/fixed conversion matrix, using the synthetic ELF fixture and measuring the filesystem's identity behavior first. The parent control substitutes only the parent's main.cpp object; all other production objects are identical. Each pair is tested for both ELF and PE output:

Names macOS APFS Linux test directory
A/a, Ä/ä, Ω/ω, Ж/ж, é NFC/NFD Same filesystem entry Distinct entries
Ä/a Distinct entries Distinct entries
  • APFS: the parent exits 0 and collapses the outputs in all ten alias cases. The fix exits 2 with Output paths collide and writes no output in all ten. Both distinct-name controls succeed with two separate valid outputs.
  • Linux: all twelve distinct-name cases succeed on both parent and fix, including NFC/NFD; both outputs exist, have the expected ELF/PE signatures, and are different files. Thus the new probe does not impose APFS's Unicode equivalences on the Linux directory.
  • Every matrix case preserves both input hashes and leaves no .anyps5-output-identity-* directory.

No Linux casefold-enabled directory, case-sensitive APFS volume, Windows host, or converted guest execution was tested in this run. These are actual CLI/filesystem checks, not a modeled name comparison.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6227286859 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6927#issuecomment-6227286859). Originally posted by [simonbbby](https://github.com/simonbbby) on 2026-10-17T00:23:39Z. --- Independent native Linux coverage for the gap in **Tested**, plus an APFS before/after control, on exact head `0a8ec7d15a32f960a2b3d78a8f87136a211ff1ef`. Built the real CLI in Release relinker-only mode on Ubuntu 24.04 x86-64 / GCC 13.3 and macOS 27.2 arm64 / AppleClang 21.0.0. The four focused CTests (`output_collisions`, `secondary_output_collisions`, `input_preservation`, `relinker_executables`) pass on both hosts: **4/4 Linux, 4/4 Mac**. Also ran a parent/fixed conversion matrix, using the synthetic ELF fixture and measuring the filesystem's identity behavior first. The parent control substitutes only the parent's `main.cpp` object; all other production objects are identical. Each pair is tested for both ELF and PE output: | Names | macOS APFS | Linux test directory | |---|---|---| | A/a, Ä/ä, Ω/ω, Ж/ж, é NFC/NFD | Same filesystem entry | Distinct entries | | Ä/a | Distinct entries | Distinct entries | - **APFS:** the parent exits 0 and collapses the outputs in all ten alias cases. The fix exits 2 with `Output paths collide` and writes no output in all ten. Both distinct-name controls succeed with two separate valid outputs. - **Linux:** all twelve distinct-name cases succeed on both parent and fix, including NFC/NFD; both outputs exist, have the expected ELF/PE signatures, and are different files. Thus the new probe does not impose APFS's Unicode equivalences on the Linux directory. - Every matrix case preserves both input hashes and leaves no `.anyps5-output-identity-*` directory. No Linux casefold-enabled directory, case-sensitive APFS volume, Windows host, or converted guest execution was tested in this run. These are actual CLI/filesystem checks, not a modeled name comparison.
adriadam10 commented 2026-10-19 13:55:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T13:55:06Z.


Checked the filesystem probe in SameOutputDestination (non-Windows branch), its cleanup and the new alias test against the relinker CI on macOS (arm64 and x86_64), Linux and Windows, plus @simonbbby's independent Linux/macOS run; merged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6268920334 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6927#issuecomment-6268920334). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-19T13:55:06Z. --- Checked the filesystem probe in `SameOutputDestination` (non-Windows branch), its cleanup and the new alias test against the relinker CI on macOS (arm64 and x86_64), Linux and Windows, plus @simonbbby's independent Linux/macOS run; merged.
github-actions[bot] commented 2026-10-19 13:58:57 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T13:58:57Z.


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 7332 core/relinker/main.cpp
core/relinker/relinker/tests/test_output_collisions.py
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6268999817 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6927#issuecomment-6268999817). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-19T13:58:57Z. --- <!-- 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 7332](https://www.github.com/boykopovar/AnyPS5/pull/7332) | `core/relinker/main.cpp`<br>`core/relinker/relinker/tests/test_output_collisions.py` |
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!6927
No description provided.