Skip to content

fix(relinker): reject needed companion output collisions - #6115

Merged
adriadam10 merged 1 commit into
boykopovar:mainfrom
ArjenS-LA:fix/relinker-needed-output-collisions
Oct 18, 2026
Merged

adriadam10 merged 1 commit into
boykopovar:mainfrom
ArjenS-LA:fix/relinker-needed-output-collisions

Conversation

@ArjenS-LA

@ArjenS-LA ArjenS-LA commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

What

Include .needed.json companion files in the relinker's existing output collision preflight. With --registry --executable output.needed input.elf output.json, the secondary executable and the main dependency companion both target output.needed.json. Current main returns success and replaces the converted executable with JSON. Existing hard-linked companion destinations can likewise overwrite other outputs.

The collision check now rejects these destinations before writing any executable, module or companion. The existing regression suites cover new and existing direct collisions, every main/module companion hard-link pairing, secondary executable companion collisions, unchanged inputs and existing outputs, and successful distinct-file controls.

Depends on: none. Unblocks: none; synthetic regressions and the disclosed Mari0 conversion reproduction below. AI-assisted: yes (Codex).

Tested

Windows x86-64, OS build 10.0.26200.0; supported WinLibs MinGW-w64 GCC 15.2.0, CMake/Ninja Release. Synthetic Linux ELF and Windows PE conversion, plus the Mari0 package conversion below. No game, generated executable, GPU or Linux/macOS host execution was performed locally.

Baseline: eea428ca855fb59a3edd394bab9abf99165590f1. Branch: fix/relinker-needed-output-collisions. Tested commit: 62b09018d4676bf385d4744e982f13e330416359.

  • Separate baseline build: updated output_collisions and secondary_output_collisions fail because colliding conversions return 0; standalone reproducer confirms secondary output bytes are an empty JSON array instead of an executable.
  • Fixed build: all 127 relinker CTests completed with 126 passed, 1 skipped (long_paths, LongPathsEnabled is not 1), 0 failures. output_collisions passed in 3.57 s (49 hard-link pairs plus direct-name checks); secondary_output_collisions passed in 5.98 s (48 hard-link pairs). Suite wall time 28.66 s with four workers. input_magic was registered. Standalone reproducer now exits 2 with Output paths collide and creates no output.
  • git diff --check: passed. python tools/check_conventions.py --base origin/main: passed on the committed change.

Commands (toolchain bin prepended to PATH; explicit Python points to the working local interpreter):

cmake -S . -B build-relinker-baseline -G Ninja -DCMAKE_BUILD_TYPE=Release -DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON -DPython3_EXECUTABLE=C:/Users/arjen/AppData/Local/Temp/anyps5-toolchain/python/python.exe
cmake --build build-relinker-baseline --parallel 4
ctest --test-dir build-relinker-baseline -R '^(output_collisions|secondary_output_collisions)$' --output-on-failure
cmake -S . -B build-relinker -G Ninja -DCMAKE_BUILD_TYPE=Release -DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON -DPython3_EXECUTABLE=C:/Users/arjen/AppData/Local/Temp/anyps5-toolchain/python/python.exe
cmake --build build-relinker --parallel 4
ctest --test-dir build-relinker/core/relinker -N
ctest --test-dir build-relinker/core/relinker --output-on-failure -j 4

An additional 26 root CTests passed (6.75 s), selected after inspecting all 40 root registrations. Aggregate: 152 passed, one whole-test skipped, and 14 commit-producing tooling suites excluded from 167 registered tests. Internal subcase skips include one registration check, two hardware-oracle checks, and five release-packaging checks. The excluded suites are pr_overlap_encoding, pr_overlap_tools, pr_overlap_own_branch, progress_history, import_audit, conventions_function_bodies, conventions_wrapped_declarations, conventions_ci_gate, conventions_bom_shebang, conventions_body_bom, conventions_blob_reads, check_main_sync, debt_split, and check_compile. Full library/shader builds were not applicable. Distinct case-variant controls skipped on the case-insensitive Windows test directory. Input-preservation symlink cases skipped because Windows symlink privilege is unavailable; Linux-only execution portions skipped on this Windows host.

Homebrew evidence: Mari0 conversion

Mari0 1.6.2 from websrv v0.34 reproduces the overwrite during conversion. The original Mari0.zip ships love.elf and libOSMesa.so.8; its packaging script and launcher identify those files.

Tested on Windows 11 x64, build 26200, Python 3.13.7 and WinLibs MinGW-w64 GCC 15.2.0 r7, Release relinker builds. Baseline: eea428ca855fb59a3edd394bab9abf99165590f1. Fixed: 62b09018d4676bf385d4744e982f13e330416359. These are the recorded test builds, not a claim of rerunning on later main.

Output setup Baseline Fixed
Separate destinations Exit 0; Windows executable and converted shipped module produced Exit 0; same artifact types produced
Existing output.exe and output.needed.json hard-linked to one sentinel file Exit 0; both paths contain dependency JSON, destroying the executable Exit 2, Output paths collide; both paths retain their original bytes, no guest module written

Reproduce separately with the baseline and fixed binary, using a fresh output directory for each run. In a separate copy of the extracted package, add an empty sce_module directory; leave the shipped module in the package root. For the collision case, write a sentinel to output.exe and create output.needed.json as a hard link to it. For the control, leave both destinations absent. From that output directory, run:

& $relinker --trap-sdk-syscall-stubs --windows --registry --sce-module-path $package --module-dir . "$package/love.elf" "$PWD/output.exe"

The empty directory, --module-dir ., and --trap-sdk-syscall-stubs are disclosed accommodations needed by this payload homebrew layout. All original input file hashes remained unchanged across all four runs. The hard-link output condition was deliberately constructed; it is not part of Mari0's shipped layout or evidence of a reported user incident. This proves a conversion/output-preservation failure using the real package, not game startup, gameplay, or physical-PS5 behavior. Neither the game nor a generated executable was run.

SHA-256:

Mari0.zip       e0331ed5a22e7fe72843d268cd2c8b297d761a75b7c83d828f5cc58a82a72ce3
love.elf        54bcc91670fd759bbd3488284dce351b6421cb83016e9ad8da6b5186da067a39
libOSMesa.so.8  128d2ab20b980b96decb1f20a9ed57d10cc922605259666b63efa52963920f0a
baseline build  d5683d3f463ef5831702ad3b302b363dfae7d8d4b4f439de41c92e3be9485e01
fixed build     684c2cb1052c08e71a36a9bc336727f918df48c335c05cc9b8e919859982d77e

Separately, coltken95 reports Linux x86-64 before/after validation: both collision regressions pass with this head merged into main ab9a47684 and fail using main's core/relinker/main.cpp. This is third-party validation, not a local Linux run.

Evidence collection and this update were AI-assisted. Unblocks: none remains appropriate: no title bring-up or gameplay claim is made.

Open PR comparison

Refreshed before this evidence-only description update: main e858dbd78dbe87fd372f7097cc7759f2ee01e2a2, complete 517-PR inventory across six pages, and complete paginated changed-file lists. Each head was normalized against that main; pairwise tree-only Git merge previews used that exact main as the explicit merge base. No temporary commits were created. This PR merges cleanly with main; all six comparisons among our four open PRs are clean. This does not claim combined compilation/runtime validation.

#6156 changes guest-module directory identity, #5695 changes executable permissions after writing, and #6127 changes output identity helpers, registry naming and emission/progress. None adds neededPaths to outputPaths. #6127 overlaps behavior despite a clean textual merge: its diff removes needed-companion writes and changes the identity helper. The combined runtime behavior was not validated; merge success alone is not compatibility evidence.

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

@coltken95

Copy link
Copy Markdown

Tested on Linux x86-64 (Release build), with 62b0901 merged into main ab9a476. This covers the Linux execution paths that were skipped on Windows:

  • With the PR: output_collisions and secondary_output_collisions pass.
  • With main's core/relinker/main.cpp: both fail with AssertionError on result.returncode == 2 and "Output paths collide" in result.stderr. The relinker exits 0 and writes output.json next to output.needed.json (and output.elf next to secondary-one.bin.elf / secondary-two.bin.elf) instead of refusing.

AI-assisted: yes (Claude Code)

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 6927 core/relinker/relinker/tests/test_output_collisions.py L55

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 6314 core/relinker/main.cpp

@ArjenS-LA

Copy link
Copy Markdown
Contributor Author

@eliyarson I confirmed the overlap with #6314 using Git tree-only merge previews against main 6ea62f9b407b766c5adca63b37f63c70170f7612. Both branches merge individually with main, but combining this head 62b09018d4676bf385d4744e982f13e330416359 and #6314 head cde39e8e5b2131743331cbf86e805ef69c8a86fd conflicts in core/relinker/main.cpp, immediately after registryPaths are added to outputPaths. This PR adds neededPaths; #6314 adds manifestPath. The resolution needs to retain both additions.

Would #6115 first, followed by rebasing #6314 and retaining both entries, work for you? Neither implementation requires the other. I have left Depends on: none pending agreement on order. This check is source inspection and a merge preview, not a combined build or runtime test.

@MrMha MrMha left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head 62b09018d4676bf385d4744e982f13e330416359 on macOS 27.0.1 arm64, the local case-insensitive filesystem, AppleClang 21, Python 3.12.14, CMake 4.4.4/Ninja 1.13.2; Release relinker-only build.

  • Built the relinker and all targets in the relinker-only configuration. Full CTest run: 163/163 pass.
  • Focused verbose run: output_collisions and secondary_output_collisions pass (49 and 48 hard-link pairs respectively, plus direct paths and identity controls). The distinct case-variant acceptance branch explicitly skips because this filesystem is case-insensitive. The checks cover both ELF and Windows output conversion; this does not mean a Windows binary ran on macOS.
  • Negative control: retained the exact PR tests and restored only core/relinker/main.cpp from HEAD^, then rebuilt the relinker. Both focused tests fail: the direct companion/executable overlap and the needed-companion/secondary-executable hard-link case incorrectly return 0 instead of rejecting the collision.
  • Checked the write ordering: every neededPaths destination now reaches the existing destination-identity collision check before diagnostics, guest modules, executables, registries or companion files are written. The focused tests verify sentinel output bytes and input bytes remain intact on rejection, while distinct-destination controls still convert successfully.

I found no blocking issue in this narrow addition. This validates the exact PR head, not current-main composition with other open PRs. No full system-library build, game/homebrew execution, or GPU test was performed.

AI-assisted review and local testing: OpenAI Codex.

@adriadam10

Copy link
Copy Markdown
Collaborator

Checked on the PR merged onto current main: relinker build, output_collisions and secondary_output_collisions pass; with the neededPaths line removed from main.cpp both fail, so they pin the fix. Linux (@coltken95) and macOS (@MrMha) runs agree; relinker CI jobs are green. Merging.

@ArjenS-LA

Copy link
Copy Markdown
Contributor Author

@jotitadev I confirmed the #6927 overlap against main e09dbc2b4231103552a108b2c582cee52e46be68, with #6115 at 62b09018d4676bf385d4744e982f13e330416359 and #6927 at 0a8ec7d15a32f960a2b3d78a8f87136a211ff1ef. Both merge individually with main, but their normalized trees conflict in core/relinker/relinker/tests/test_output_collisions.py: both insert tests immediately after work = Path(directory). A resolution must keep both the needed-companion cases and the filesystem_aliases(relinker, work) call.

Given the maintainer's #6115-first merge note above, would #6115 first and #6927 rebased afterward work for you? The later branch can then record the agreed order in Depends on. After combining them, the focused checks are output_collisions, secondary_output_collisions, input_preservation and relinker_executables.

This pass used source inspection and Git tree-only merge previews; I did not run a combined build or those tests. The complete 762-PR inventory and changed-file lists were checked; the final refresh had 761 PRs after an unrelated closure, with these heads and main unchanged. AI-assisted: Codex.

@adriadam10
adriadam10 merged commit 889cee5 into boykopovar:main Oct 18, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants