fix(relinker): write registries after the executable #4346
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4346"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by SandstromPL on 2026-10-12T07:20:10Z.
What
With
--registry,main.cppwrites<stem>.registry.json, and one<stem>.<module>.registry.jsonper converted bundled module, beforePatch.Patchcan still fail. With--windows, two inputs make it fail:sce_sys/icon0.pngthat fails the Windows icon check (Invalid Windows icon PNG);--rpath '${ORIGIN}/libs'.The relink exits with an error, but by then the registries describe the new input. The previous executable and
app0/are still beside them, and a module registry exists for a module that was never converted. These are the filestools/import_audit.pyreads (USAGE.md, "pass all of them"), so the audit then reports on a binary that is not there.The registry paths and their collision checks stay where they were, before
Patch. Collisions therefore still fail before any output is written (USAGE.md:38). The files themselves are now written after the executable, and before the desktop entry. This follows the rule ofca330dfef: a malformed icon0.png leaves no output behind.Registry contents do not change. They come from
RegistryEntriesand the modules' imports, whichPatchdoes not receive.One side effect:
--registryinto an output directory that does not exist yet now works when there are guest modules, the same as without--registry. The guest module writes create the directories. Without modules it still fails, but the error now names the executable instead of the registry.Tested
Ubuntu 24.04, GCC 13.3, relinker-only build: 127/127 tests pass.
test_input_preservation.pygains a case:--windows --registrywith a malformedsce_sys/icon0.png, a bundled module, and a previous executable and previous registries in place. It requires exit code 2 withInvalid Windows icon PNG, both registries and the executable unchanged, and noapp0/. On main the relink fails the same way but has already overwritten both registries, so the case fails. It passes here.--registrywrite byte-identical registry files on main and on this branch, for both Linux and Windows output.core/relinker/main.cpp(#4338, #4140, #4194).tools/check_conventions.pyfrom main passes with this title and body.Not covered: a failure while writing a registry itself, after the new executable is written. Any write order without temporary files leaves that case.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-12T13:40:31Z.
Review: COMMENTED
Verified on the PR head, with the implementation isolated. Head
70f03dc5e, base2ca6198e9— its parent (70f03dc5e^) and merge-base.upstream/mainhas since moved to57dc13602, which changes a different region ofcore/relinker/main.cpp(c763a78b6, the--to-intelsubstitution block around line 74);git merge-tree --write-tree 57dc13602 70f03dc5eexits 0 with no conflict, and the test file is untouched upstream.The suite on the head. Relinker-only build (GCC 16.2.1, Release):
100% tests passed out of 127,input_preservationamong them.The added check bites. With
core/relinker/main.cppat2ca6198e9and the PR's tests kept:The move shows up by line position, not by presence:
fileWriter.Write(Io::Utf8Path(registryPaths.front()), …WriteCallRegistry(…))sits at line 140 in the base, before the executable write at 176, and at line 174 in the head, after the executable write at 171. Restoring the head file reproduces the PR blob byte-for-byte (d557614c) and the test passes again (exit 0). On the reverted arm the suite reads99% tests passed, 1 tests failed out of 127—input_preservationonly, so nothing else in the tree asserts where the registries are written.End to end, both triggers the body names. Fixture from the PR's own test helpers (
main_fixture(),guest_fixture(PLAIN_SITE)), with a previousoutput.exeand previous registries planted:The body's third clause holds too: with only the call registry planted and the module registry absent, the base creates
output.sample.prx.guest.prx.registry.json— a registry for a module that was never converted — and the head does not.Two behaviour changes, both real. With a valid icon,
--registry, and an output path inside a directory that does not exist yet:The guest module lands under
newdir/app0/sce_module/, and this reproduces on a plain Linux run, so it is not a--windowseffect: the guest-module writes'create_directoriesnow runs before the first writer that touches the output directory (the base's registry write came first, andFileWriterdoes not create directories). With--skip-sce-moduleinto a missing directory, the failure line now names the executable instead of the registry: baseCannot open output file: …/newdir/out.registry.json, head…/newdir/out.elf— exit 2 and nothing created in both.One window the move opens, which I did not find in the body. Registries written after the executable means a registry write that fails now leaves the executable already replaced — the opposite direction to the state this PR removes. Demonstrated on the head, with the executable and registries present and
output.registry.jsonmade read-only (0444), and again with the registry path occupied by a directory:So exit 2 no longer implies "the executable was left alone" for a post-
Patchfailure. The Patch-failure case this PR fixes is much the likelier one, which is presumably why the order was chosen, but the trade-off is worth a line in the body — and the added test covers Patch failures only, not a registry write failing after one. An order that closes both would write the registries afterPatchand before the executable, leaving a fresh-registry/old-executable window only if the executable write itself fails.The collision checks still precede the write.
registryPathsis built at the same place with the same expressions under the sameargs.writeRegistryguard, thecheckOutputInputs(path, "Registry")loop is still beforePatch(main.cpp:137vs:161), and the paths are unchanged — sodocs/user/USAGE.md:38's "These collisions fail before any output is written" still holds.What I could not verify. A Windows host: every row above is a PE image produced by a Linux build, never executed on Windows. And the body's consequence claim that
tools/import_audit.py"reports on a binary that is not there" —import_audittakes only registry JSONs plus--libs/--modulesand no executable argument, so a stale registry is a stale input describing an older build; I could not run it here either (the relinker-only tree has no builtcore/libs).No merge rights on my side — this is a comment, not an approval.
Written with AI assistance.
Hermes Agent 🤖 at your service
Imported from boykopovar/AnyPS5. Originally posted by SandstromPL on 2026-10-12T16:47:08Z.
Thanks for the review, and for checking that the new test fails without the change.
The registry-write window is in the body, at the end of Tested: "Not covered: a failure while writing a registry itself, after the new executable is written."
FileWriterwrites each file in place, one after another, so every order leaves some window. I kept the registries after the executable because the executable has a failure the registries do not: relinking while the previous build is still running getsETXTBSYon Linux, and the file is locked on Windows. With the registries before it, that run leaves new registries next to the old executable. That run isn't clean with the merged order either when there are guest modules on Linux: they are written first, and a loaded module can still be overwritten. Narrowing this further needs temporary files and renames, which is a separate change.On
import_audit: you're right that it only reads registries. Before this PR, a failedPatchleft new registries, listing the imports of a build that was never written, beside the previous executable. They weren't stale; that's what "a binary that is not there" meant.