Repository navigation
fix(relinker): write registries after the executable - #4346
oneandonlydean merged 1 commit into
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dextroid17
left a comment
There was a problem hiding this comment.
Verified on the PR head, with the implementation isolated. Head 70f03dc5e, base 2ca6198e9 — its parent (70f03dc5e^) and merge-base. upstream/main has since moved to 57dc13602, which changes a different region of core/relinker/main.cpp (c763a78b6, the --to-intel substitution block around line 74); git merge-tree --write-tree 57dc13602 70f03dc5e exits 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_preservation among them.
The added check bites. With core/relinker/main.cpp at 2ca6198e9 and the PR's tests kept:
File "…/test_input_preservation.py", line 75, in check_registry_after_failed_patch
assert all(registry.read_bytes() == previous_registry for registry in registries)
AssertionError
exit=1
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 reads 99% tests passed, 1 tests failed out of 127 — input_preservation only, 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 previous output.exe and previous registries planted:
invalid sce_sys/icon0.png, --windows --registry
base exit 2 "Invalid Windows icon PNG …" output.exe unchanged registry -> "[\n]\n"
PR exit 2 same error output.exe unchanged registry -> "previous registry"
--rpath '${ORIGIN}/libs' (icon valid, so the run-path check is what fires)
base exit 2 "Unsupported variable in Windows run path" registry -> "[\n]\n"
PR exit 2 same error registry -> "previous registry"
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:
base exit 2 "Cannot open output file: …/newdir/out.registry.json" nothing created
PR exit 0 stderr empty newdir/ -> out.exe, out.registry.json, out.sample.prx.guest.prx.registry.json,
app0/sce_module/sample.prx.guest.prx
The guest module lands under newdir/app0/sce_module/, and this reproduces on a plain Linux run, so it is not a --windows effect: the guest-module writes' create_directories now runs before the first writer that touches the output directory (the base's registry write came first, and FileWriter does not create directories). With --skip-sce-module into a missing directory, the failure line now names the executable instead of the registry: base Cannot 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.json made read-only (0444), and again with the registry path occupied by a directory:
head exit 2 "Cannot open output file: …/output.registry.json"
output.elf is now the new ELF (7f 45 4c 46), app0/sce_module/sample.prx.guest.prx written,
while the registries are still the previous ones
base exit 2 same message, but output.elf is still the previous bytes and no app0/ exists
So exit 2 no longer implies "the executable was left alone" for a post-Patch failure. 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 after Patch and before the executable, leaving a fresh-registry/old-executable window only if the executable write itself fails.
The collision checks still precede the write. registryPaths is built at the same place with the same expressions under the same args.writeRegistry guard, the checkOutputInputs(path, "Registry") loop is still before Patch (main.cpp:137 vs :161), and the paths are unchanged — so docs/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_audit takes only registry JSONs plus --libs/--modules and 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 built core/libs).
No merge rights on my side — this is a comment, not an approval.
Written with AI assistance.
Hermes Agent 🤖 at your service
|
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." On |
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(fix(relinker): preserve inputs when writing Windows diagnostics #4338, feat(relinker): support fixed Windows guest image bases #4140, feat(relinker): split unaligned 256-bit stores for Rosetta #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