fix(relinker): reject core and untyped ELF conversion inputs #5812
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5812"
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 NumberGuan on 2026-10-14T11:56:28Z.
What
Linux conversion accepts an image whose ELF object type is
ET_NONEorET_CORE, returns success and writes an executable and registry. Changing onlye_typeon the existing executable fixture reproduces both cases, including with--to-intel. Windows and macOS already reject them during image construction.Reject these types in the shared relinking stage before output generation. The ELF gABI object-type table defines
ET_NONEas having no file type andET_COREas a core file. Each rejection names the type. The existingET_RELdiagnostic is preserved.Extend the registered
elf_headertest with 54 rejection cases across the three non-executable types and 60 valid controls. The matrix covers all six target/conversion modes and all three unused-import filter levels. Rejected inputs must return 2, keep their bytes unchanged and write neither executable nor registry. Controls cover LinuxET_EXECand the existing position-independent typesET_DYN,0xFE10and0xFE18, with the expected ELF, PE or Mach-O output magic. The strict-filter fixture includes a complete SysV hash table. The header-only fixture now declaresET_DYN, preserving its missing-dynamic-segment check.The branch combines cleanly with #5116's pipeline optimization, verified with
git merge-tree; no dependency.Tested
Windows x64, WinLibs MinGW-w64 GCC 15.2.0 UCRT POSIX SEH r7, CMake 4.3.1, Ninja Release, Python 3.12.14. Based on upstream
344afad05; contributionba131dea7.The complete relinker-only build passed. The initial version passed 153 tests in 139.38 seconds, with
long_pathsskipped because the host does not enable long paths. The existingconventions_function_bodiestest took 32.07 seconds locally; no timeout was changed. After adjusting the guard placement to combine with #5116, five focused groups passed in 15.08 seconds:elf_header,relinker_conversion,elf_reader_bounds,input_magicandinput_file. After rebasing onmainat96dd647, the same five groups passed in 13.54 seconds. Registration, conventions (including the title and body) and whitespace checks passed;git range-diffconfirms the contribution is unchanged.With only the regression added to upstream
145cb82f3,elf_headerfails ontype-0-0-0: conversion returns 0 and writes the executable and registry. An independent probe confirms the same behavior forET_COREin Linux output, both with and without--to-intel.Hosted relinker CI passed on Windows, Linux and macOS for
4d00d5f69. Hosted conventions and intake also passed. The workflow skipped full system-library builds and the unrelated register-context and write-watch jobs.No game/homebrew execution or PS5 hardware test. Windows and macOS output formats were checked on the Windows host; execution of the resulting binaries is outside the local tests. Optional Intel/Rosetta instruction lowering still precedes the pipeline's type check.
Revalidated on current main
Rebased onto
63fb0cd92. The full relinker-only build passed, and the complete CTest suite finished with 157 passing tests, onelong_pathsskip because Windows long paths are disabled, and no failures. The updatedelf_headertest passed in 13.78 s. Test registration, conventions and whitespace checks passed. Hosted relinker CI passed on Windows, Linux and macOS; hosted conventions also passed. No game, homebrew or PS5 hardware test was run.Checklist
main; no other open PR implements the same functionsImported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-14T13:46:09Z.
Validated at head
35b337eb4(base63fb0cd92; merges cleanly with current main5a6ad0ed3). Windows 11, WinLibs GCC 15.2.0 UCRT, Ninja Release, relinker-only, Python 3.13.test_elf_header.pyagainst the base binary: it fails attype-0-0-0(rc 0, executable written). Against the head binary it passes (12.1 s standalone).-j 2: base 158/158, head 158/158;elf_headertook 9.9 s on head.e_typeonmain_fixture(), run throughrelinker --skip-sce-module:--to-intelreturned 0 and wrote output on base; on head they return 2 with the new ET_NONE / ET_CORE messages and write nothing. Windows and macOS already returned 2 on base ("requires a position-independent ELF image"); on head the pipeline's message comes first.GuestImageReader.cpp, so only the main executable path needed this.check_conventions.pypasses.Optional nits, not blocking:
ReadHeader()is now called twice inRelink()(the ET_REL check could reuseinputType). Linux output still accepts any other value (e.g. 5 or 0xFFFF convert), unlike the Windows/macOS allowlist; that could be a separate follow-up.Not tested: Linux or macOS hosts, real titles or homebrew, PS5 hardware.
AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-14T15:46:23Z.
macOS data point for the
--macosside of the description.Apple M2 Max, macOS 27.2 (26B5091g), AppleClang, Ninja Release, relinker-only. Head
35b337eb4merged without conflicts intomain84b01f9cd.ctest --parallel 8 --timeout 30156/156 pass;elf_header1.4 s.-DCMAKE_OSX_ARCHITECTURES=x86_64, x86_64 Python):elf_headerpasses in 6.0 s. 6 other tests fail (pr_overlap_encoding,progress_history,stubgen_stdout_newlines,release_package,linux_fixed_base,guest_module_args), the same 6 that fail on unmodifiedmainon this machine (five are Python 3.9 incompatibilities of the only x86_64 Python here;guest_module_argsis the fixture #5362 fixes).test_elf_header.pyagainst amainrelinker fails attype-0-0-0, as on Windows.Hand-patched
e_typeonmain_fixture(),--skip-sce-module:e_typemainET_NONE inputs do not specify an ELF object type--macos/--windowsWindows output requires a position-independent ELF imageET_NONE ...ET_CORE core dumps are not executable images--macos/--windowsWindows output requires ...ET_CORE ...No output is written in any rejected case. This confirms that
--macosalready rejected both types onmain. Separately, and not from this PR: the--macosrejection onmain(and still forET_EXEChere) readsWindows output requires a position-independent ELF image, because the Mach-O path goes throughWindowsLoadImage.cpp:13.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T13:05:20Z.
Checked: with the
src/pipeline/RelinkerPipeline.cppchange reverted,elf_headerfails (rejected types are accepted and output is written); with it,elf_headerand the rest of the relinker ctest (134/134) pass. The ET_NONE/ET_CORE rejection happens before any output, the ET_REL diagnostic is unchanged, and the matrix covers all modes and filter levels. Windows and macOS runs from @wachi35676 and @jotitadev agree. Merging once the full build is green.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T13:34:46Z.
Checked:
RelinkerPipeline.cpprejectsET_NONEandET_COREbefore any output,ET_RELdiagnostic unchanged. Relinker ctest 134/134 on the merged tree; with the pipeline change revertedelf_headerfails. Windows (@wachi35676) and macOS (@jotitadev) runs agree; merging once CI is green.