fix(relinker): reject core and untyped ELF conversion inputs #5812

Merged
NumberGuan merged 2 commits from upstream-pr/5812 into main 2026-10-16 19:23:31 +00:00
NumberGuan commented 2026-10-14 11:56:28 +00:00 (Migrated from github.com)

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_NONE or ET_CORE, returns success and writes an executable and registry. Changing only e_type on 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_NONE as having no file type and ET_CORE as a core file. Each rejection names the type. The existing ET_REL diagnostic is preserved.

Extend the registered elf_header test 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 Linux ET_EXEC and the existing position-independent types ET_DYN, 0xFE10 and 0xFE18, 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 declares ET_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; contribution ba131dea7.

cmake -S . -B build-relinker -G Ninja -DCMAKE_BUILD_TYPE=Release -DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON
cmake --build build-relinker --parallel 4
ctest --test-dir build-relinker --output-on-failure --no-tests=error --parallel 2
python tools/check_test_registration.py build-relinker
python tools/check_conventions.py --base origin/main
git diff origin/main --check

The complete relinker-only build passed. The initial version passed 153 tests in 139.38 seconds, with long_paths skipped because the host does not enable long paths. The existing conventions_function_bodies test 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_magic and input_file. After rebasing on main at 96dd647, the same five groups passed in 13.54 seconds. Registration, conventions (including the title and body) and whitespace checks passed; git range-diff confirms the contribution is unchanged.

With only the regression added to upstream 145cb82f3, elf_header fails on type-0-0-0: conversion returns 0 and writes the executable and registry. An independent probe confirms the same behavior for ET_CORE in 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, one long_paths skip because Windows long paths are disabled, and no failures. The updated elf_header test 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

  • 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; no silent stubs added
  • No notes, investigation files or images added to the repository
  • New third-party code is a submodule built from source; none added
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes, Codex
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4857483833 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5812). Originally posted by [NumberGuan](https://github.com/NumberGuan) on 2026-10-14T11:56:28Z. --- ### What Linux conversion accepts an image whose ELF object type is `ET_NONE` or `ET_CORE`, returns success and writes an executable and registry. Changing only `e_type` on 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](https://gabi.xinuos.com/elf/02-eheader.html#contents-of-the-elf-header) defines `ET_NONE` as having no file type and `ET_CORE` as a core file. Each rejection names the type. The existing `ET_REL` diagnostic is preserved. Extend the registered `elf_header` test 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 Linux `ET_EXEC` and the existing position-independent types `ET_DYN`, `0xFE10` and `0xFE18`, 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 declares `ET_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`; contribution `ba131dea7`. ```text cmake -S . -B build-relinker -G Ninja -DCMAKE_BUILD_TYPE=Release -DANYPS5_RELINKER_ONLY=ON -DBUILD_TESTING=ON cmake --build build-relinker --parallel 4 ctest --test-dir build-relinker --output-on-failure --no-tests=error --parallel 2 python tools/check_test_registration.py build-relinker python tools/check_conventions.py --base origin/main git diff origin/main --check ``` The complete relinker-only build passed. The initial version passed 153 tests in 139.38 seconds, with `long_paths` skipped because the host does not enable long paths. The existing `conventions_function_bodies` test 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_magic` and `input_file`. After rebasing on `main` at `96dd647`, the same five groups passed in 13.54 seconds. Registration, conventions (including the title and body) and whitespace checks passed; `git range-diff` confirms the contribution is unchanged. With only the regression added to upstream `145cb82f3`, `elf_header` fails on `type-0-0-0`: conversion returns 0 and writes the executable and registry. An independent probe confirms the same behavior for `ET_CORE` in Linux output, both with and without `--to-intel`. Hosted [relinker CI](https://github.com/boykopovar/AnyPS5/actions/runs/38567451164) passed on Windows, Linux and macOS for `4d00d5f69`. Hosted [conventions](https://github.com/boykopovar/AnyPS5/actions/runs/38567446046) 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, one `long_paths` skip because Windows long paths are disabled, and no failures. The updated `elf_header` test passed in 13.78 s. Test registration, conventions and whitespace checks passed. Hosted [relinker CI](https://github.com/boykopovar/AnyPS5/actions/runs/38570378332) passed on Windows, Linux and macOS; hosted [conventions](https://github.com/boykopovar/AnyPS5/actions/runs/38570373504) also passed. No game, homebrew or PS5 hardware test was run. ### 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 - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation files or images added to the repository - [x] New third-party code is a submodule built from source; none added - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes, Codex
wachi35676 commented 2026-10-14 13:46:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-14T13:46:09Z.


Validated at head 35b337eb4 (base 63fb0cd92; merges cleanly with current main 5a6ad0ed3). Windows 11, WinLibs GCC 15.2.0 UCRT, Ninja Release, relinker-only, Python 3.13.

  • Ran this PR's test_elf_header.py against the base binary: it fails at type-0-0-0 (rc 0, executable written). Against the head binary it passes (12.1 s standalone).
  • Full relinker ctest -j 2: base 158/158, head 158/158; elf_header took 9.9 s on head.
  • Hand-patched e_type on main_fixture(), run through relinker --skip-sce-module:
    • 0 and 4: Linux and --to-intel returned 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.
    • 1: unchanged, still the #5148 ET_REL message.
    • 2, 3, 0xFE10, 0xFE18: same result on base and head (2 converts on Linux only; 3, 0xFE10 and 0xFE18 convert on all targets), so no valid type is newly rejected.
  • Guest modules are already limited to 3/0xFE18 in GuestImageReader.cpp, so only the main executable path needed this.
  • check_conventions.py passes.

Optional nits, not blocking: ReadHeader() is now called twice in Relink() (the ET_REL check could reuse inputType). 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6169843185 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5812#issuecomment-6169843185). Originally posted by [wachi35676](https://github.com/wachi35676) on 2026-10-14T13:46:09Z. --- Validated at head `35b337eb4` (base `63fb0cd92`; merges cleanly with current main `5a6ad0ed3`). Windows 11, WinLibs GCC 15.2.0 UCRT, Ninja Release, relinker-only, Python 3.13. - Ran this PR's `test_elf_header.py` against the base binary: it fails at `type-0-0-0` (rc 0, executable written). Against the head binary it passes (12.1 s standalone). - Full relinker ctest `-j 2`: base 158/158, head 158/158; `elf_header` took 9.9 s on head. - Hand-patched `e_type` on `main_fixture()`, run through `relinker --skip-sce-module`: - 0 and 4: Linux and `--to-intel` returned 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. - 1: unchanged, still the #5148 ET_REL message. - 2, 3, 0xFE10, 0xFE18: same result on base and head (2 converts on Linux only; 3, 0xFE10 and 0xFE18 convert on all targets), so no valid type is newly rejected. - Guest modules are already limited to 3/0xFE18 in `GuestImageReader.cpp`, so only the main executable path needed this. - `check_conventions.py` passes. Optional nits, not blocking: `ReadHeader()` is now called twice in `Relink()` (the ET_REL check could reuse `inputType`). 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.
jotitadev commented 2026-10-14 15:46:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-14T15:46:23Z.


macOS data point for the --macos side of the description.

Apple M2 Max, macOS 27.2 (26B5091g), AppleClang, Ninja Release, relinker-only. Head 35b337eb4 merged without conflicts into main 84b01f9cd.

  • arm64: ctest --parallel 8 --timeout 30 156/156 pass; elf_header 1.4 s.
  • x86_64 under Rosetta 2 (-DCMAKE_OSX_ARCHITECTURES=x86_64, x86_64 Python): elf_header passes 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 unmodified main on this machine (five are Python 3.9 incompatibilities of the only x86_64 Python here; guest_module_args is the fixture #5362 fixes).
  • test_elf_header.py against a main relinker fails at type-0-0-0, as on Windows.

Hand-patched e_type on main_fixture(), --skip-sce-module:

e_type Output main This PR
0 Linux rc 0, written rc 2, ET_NONE inputs do not specify an ELF object type
0 --macos / --windows rc 2, Windows output requires a position-independent ELF image rc 2, ET_NONE ...
4 Linux rc 0, written rc 2, ET_CORE core dumps are not executable images
4 --macos / --windows rc 2, Windows output requires ... rc 2, ET_CORE ...
2 Linux rc 0 rc 0 (unchanged)

No output is written in any rejected case. This confirms that --macos already rejected both types on main. Separately, and not from this PR: the --macos rejection on main (and still for ET_EXEC here) reads Windows output requires a position-independent ELF image, because the Mach-O path goes through WindowsLoadImage.cpp:13.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6172298664 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5812#issuecomment-6172298664). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-14T15:46:23Z. --- macOS data point for the `--macos` side of the description. Apple M2 Max, macOS 27.2 (26B5091g), AppleClang, Ninja Release, relinker-only. Head `35b337eb4` merged without conflicts into `main` `84b01f9cd`. - arm64: `ctest --parallel 8 --timeout 30` 156/156 pass; `elf_header` 1.4 s. - x86_64 under Rosetta 2 (`-DCMAKE_OSX_ARCHITECTURES=x86_64`, x86_64 Python): `elf_header` passes 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 unmodified `main` on this machine (five are Python 3.9 incompatibilities of the only x86_64 Python here; `guest_module_args` is the fixture #5362 fixes). - `test_elf_header.py` against a `main` relinker fails at `type-0-0-0`, as on Windows. Hand-patched `e_type` on `main_fixture()`, `--skip-sce-module`: | `e_type` | Output | `main` | This PR | |---|---|---|---| | 0 | Linux | rc 0, written | rc 2, `ET_NONE inputs do not specify an ELF object type` | | 0 | `--macos` / `--windows` | rc 2, `Windows output requires a position-independent ELF image` | rc 2, `ET_NONE ...` | | 4 | Linux | rc 0, written | rc 2, `ET_CORE core dumps are not executable images` | | 4 | `--macos` / `--windows` | rc 2, `Windows output requires ...` | rc 2, `ET_CORE ...` | | 2 | Linux | rc 0 | rc 0 (unchanged) | No output is written in any rejected case. This confirms that `--macos` already rejected both types on `main`. Separately, and not from this PR: the `--macos` rejection on `main` (and still for `ET_EXEC` here) reads `Windows output requires a position-independent ELF image`, because the Mach-O path goes through `WindowsLoadImage.cpp:13`. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
adriadam10 commented 2026-10-15 13:05:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T13:05:20Z.


Checked: with the src/pipeline/RelinkerPipeline.cpp change reverted, elf_header fails (rejected types are accepted and output is written); with it, elf_header and 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6192757429 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5812#issuecomment-6192757429). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-15T13:05:20Z. --- Checked: with the `src/pipeline/RelinkerPipeline.cpp` change reverted, `elf_header` fails (rejected types are accepted and output is written); with it, `elf_header` and 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.
adriadam10 commented 2026-10-15 13:34:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T13:34:46Z.


Checked: RelinkerPipeline.cpp rejects ET_NONE and ET_CORE before any output, ET_REL diagnostic unchanged. Relinker ctest 134/134 on the merged tree; with the pipeline change reverted elf_header fails. Windows (@wachi35676) and macOS (@jotitadev) runs agree; merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6193355762 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5812#issuecomment-6193355762). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-15T13:34:46Z. --- Checked: `RelinkerPipeline.cpp` rejects `ET_NONE` and `ET_CORE` before any output, `ET_REL` diagnostic unchanged. Relinker ctest 134/134 on the merged tree; with the pipeline change reverted `elf_header` fails. Windows (@wachi35676) and macOS (@jotitadev) runs agree; merging once CI is green.
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!5812
No description provided.